xref: /titanic_41/usr/src/uts/sun4u/montecarlo/sys/pcf8591_nct.h (revision bfed486ad8de8b8ebc6345a8e10accae08bf2f45)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_PCF8591_H
28 #define	_PCF8591_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * PCF8591 Chip Used for temperature sensors
38  *
39  * Addressing Register definition.
40  * A0-A2 valid range is 0-7
41  *
42  * ------------------------------------------------
43  * | 1 | 0 | 0 | 1 | A2 | A1 | A0 | R/W |
44  * ------------------------------------------------
45  */
46 
47 #define	PCF8591_MAX_DEVS	0x08
48 #define	PCF8591_MAX_CHANS	0x04
49 #define	PCF8591_BUSY		0x01
50 #define	PCF8591_NAMELEN		12
51 
52 #define	PCF8591_MINOR_TO_DEVINST(x) (((x) & 0x700) >> 8)
53 #define	PCF8591_MINOR_TO_CHANNEL(x) ((x) & 0x3)
54 
55 #define	PCF8591_CHANNEL_TO_MINOR(x) ((x) & 0x3)
56 #define	PCF8591_DEVINST_TO_MINOR(x) ((x) << 8)
57 #define	PCF8591_MINOR_NUM(i, c) (((i) << 8)|((c) & 0x3))
58 
59 #define	PCF8591_NODE_TYPE "ddi_i2c:adc"
60 
61 #define	PCF8591_TRAN_SIZE 1
62 #define	I2C_PCF8591_NAME "adc-dac"
63 #define	I2C_KSTAT_CPUTEMP "adc_temp"
64 #define	I2C_TYPE_PCF8591 0
65 
66 #define	ENVC_NETRACT_CPU_SENSOR 0
67 
68 #define	I2C_DEV0	0x00
69 #define	I2C_DEV1	0x02
70 #define	I2C_DEV2	0x04
71 #define	I2C_DEV3	0x06
72 #define	I2C_DEV4	0x08
73 #define	I2C_DEV5	0x0A
74 #define	I2C_DEV6    0x0C
75 #define	I2C_DEV7	0x0E
76 
77 #define	MAX_WLEN	64
78 #define	MAX_RLEN	64
79 
80 #ifndef	I2CDEV_TRAN
81 #define	I2CDEV_TRAN 1
82 #endif
83 #define	I2CDEV_GETTEMP		82
84 #define	I2CDEV_GETTABLES	256
85 
86 #define	ENVC_IOC_GETTEMP	0x10
87 /*
88  * These are now defined in sys/netract_gen.h
89  *
90  * #define	ENVC_IOC_GETMODE	0x1C
91  * #define	ENVC_IOC_SETMODE	0x1D
92  */
93 
94 /*
95  * 		CONTROL OF CHIP
96  * PCF8591 Temp sensing control register definitions
97  *
98  * ---------------------------------------------
99  * | 0 | AOE | X | X | 0 | AIF | X | X |
100  * ---------------------------------------------
101  * AOE = Analog out enable.. not used on out implementation
102  * 5 & 4 = Analog Input Programming.. see data sheet for bits..
103  *
104  * AIF = Auto increment flag
105  * bits 1 & 0 are for the Channel number.
106  */
107 
108 /*
109  * We should be able to select the alalog input
110  * programming of our choice. By default, the
111  * alanog input programming is set to Single
112  * ended. The programmer can issue an ioctl to
113  * set the input programming mode. We will set
114  * the auto increment flag set to off, so the lower
115  * nibble in the control byte will be set to the
116  * channel number.
117  */
118 
119 #define	PCF8591_4SINGLE		0x00	/* 4 single ended inputs */
120 #define	PCF8591_3DIFF		0x10	/* 3 differential inputs */
121 #define	PCF8591_MIXED		0x20	/* single ended and diff mixed */
122 #define	PCF8591_2DIFF		0x30	/* 2 differential inputs */
123 
124 #define	PCF8591_WARNING_TEMP 0x0
125 #define	PCF8591_SHUTDOWN_TEMP 0x3
126 
127 #define	PCF8591_ANALOG_OUTPUT_EN	0x40
128 #define	PCF8591_ANALOG_INPUT_EN		0x00
129 #define	PCF8591_READ_BIT			0x01
130 
131 
132 #define	PCF8591_AUTO_INCR 0x04
133 #define	PCF8591_OSCILATOR 0x40
134 
135 #define	PCF8591_CH_0	0x00
136 #define	PCF8591_CH_1	0x01
137 #define	PCF8591_CH_2	0x02
138 #define	PCF8591_CH_3	0x03
139 
140 /*
141  * Stage of attachment.
142  */
143 #define	PCF8591_SOFT_STATE_ALLOC 0x0001
144 #define	PCF8591_PROPS_READ		0x0002
145 #define	PCF8591_MINORS_CREATED	0x0004
146 #define	PCF8591_ALLOC_TRANSFER	0x0008
147 #define	PCF8591_REGISTER_CLIENT	0x0010
148 #define	PCF8591_LOCK_INIT		0x0020
149 #define	PCF8591_KSTAT_INIT		0x0040
150 
151 #define	MAX_REGS_8591		2
152 
153 struct	pcf8591	{
154 	unsigned int	reg_num;
155 	unsigned int	reg_value;
156 };
157 
158 /*
159  * Following property information taken from the
160  * "SPARCengine ASM Reference Manual"
161  * Property pointers are to DDI allocated space
162  * which must be freed in the detach() routine.
163  */
164 
165 /*
166  * for pcf8591_properties_t.channels_in_use->io_dir
167  */
168 #define	I2C_PROP_IODIR_IN		0
169 #define	I2C_PROP_IODIR_OUT		1
170 #define	I2C_PROP_IODIR_INOUT	2
171 
172 /*
173  * for pcf8591_properties_t.channels_in_use->type
174  */
175 #define	I2C_PROP_TYPE_NOCARE	0
176 #define	I2C_PROP_TYPE_TEMP		1
177 #define	I2C_PROP_TYPE_VOLT		2
178 #define	I2C_PROP_TYPE_FANSTATS	3
179 #define	I2C_PROP_TYPE_FANSPEED	4
180 
181 typedef struct {
182 	uint8_t		port;
183 	uint8_t		io_dir;
184 	uint8_t		type;
185 	uint8_t		last_data;
186 } pcf8591_channel_t;
187 
188 typedef struct {
189 	char		*name;
190 	uint16_t	i2c_bus;
191 	uint16_t	slave_address;
192 	uint_t		num_chans_used;
193 	char		**channels_description;
194 	pcf8591_channel_t		*channels_in_use;
195 } pcf8591_properties_t;
196 
197 struct pcf8591_unit {
198 	int					instance;
199 	kmutex_t			umutex;
200 	dev_info_t			*dip;
201 	kcondvar_t			pcf8591_cv;
202 	uint8_t				pcf8591_flags;
203 	uint8_t				pcf8591_inprog;
204 	struct envctrl_temp temp_kstats;
205 	kstat_t 			*tempksp;
206 	uint_t				attach_flag;
207 	int				pcf8591_oflag[PCF8591_MAX_CHANS];
208 	i2c_transfer_t		*i2c_tran;
209 	i2c_client_hdl_t    pcf8591_hdl;
210 	char				pcf8591_name[PCF8591_NAMELEN];
211 	uint8_t				current_mode;
212 	uint8_t				readmask;
213 	pcf8591_properties_t props;		/* device properties */
214 };
215 
216 #ifdef	__cplusplus
217 }
218 #endif
219 
220 #endif	/* _PCF8591_H */
221