xref: /illumos-gate/usr/src/uts/sun4u/sys/i2c/clients/adm1031_impl.h (revision 69a119caa6570c7077699161b7c28b6ee9f8b0f4)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _ADM1031_IMPL_H
28 #define	_ADM1031_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 
37 #define	ADM1031_PIL			4
38 #define	ADM1031_MAX_XFER		4
39 
40 #define	ADM1031_WRITE_COMMAND_BASE	30
41 
42 
43 /* This register has the value of fan speeds */
44 #define	ADM1031_FAN_SPEED_INST_REG_1		0x08
45 #define	ADM1031_FAN_SPEED_INST_REG_2		0x09
46 
47 /* This register has the value of temperatures */
48 
49 #define	ADM1031_LOCAL_TEMP_INST_REG		0x0A
50 #define	ADM1031_REMOTE_TEMP_INST_REG_1		0x0B
51 #define	ADM1031_REMOTE_TEMP_INST_REG_2		0x0C
52 
53 
54 #define	ADM1031_STAT_1_REG			0x02
55 #define	ADM1031_STAT_2_REG			0x03
56 #define	ADM1031_DEVICE_ID_REG			0x3D
57 #define	ADM1031_CONFIG_REG_1			0x00
58 #define	ADM1031_CONFIG_REG_2 			0x01
59 #define	ADM1031_FAN_CHAR_1_REG			0x20
60 #define	ADM1031_FAN_CHAR_2_REG			0x21
61 #define	ADM1031_FAN_SPEED_CONFIG_REG		0x22
62 #define	ADM1031_FAN_HIGH_LIMIT_1_REG		0x10
63 #define	ADM1031_FAN_HIGH_LIMIT_2_REG		0x11
64 #define	ADM1031_LOCAL_TEMP_RANGE_REG		0x24
65 #define	ADM1031_REMOTE_TEMP_RANGE_1_REG		0x25
66 #define	ADM1031_REMOTE_TEMP_RANGE_2_REG		0x26
67 #define	ADM1031_EXTD_TEMP_RESL_REG		0x06
68 #define	ADM1031_LOCAL_TEMP_OFFSET_REG		0x0D
69 #define	ADM1031_REMOTE_TEMP_OFFSET_1_REG	0x0E
70 #define	ADM1031_REMOTE_TEMP_OFFSET_2_REG	0x0F
71 #define	ADM1031_LOCAL_TEMP_HIGH_LIMIT_REG	0x14
72 #define	ADM1031_REMOTE_TEMP_HIGH_LIMIT_1_REG    0x18
73 #define	ADM1031_REMOTE_TEMP_HIGH_LIMIT_2_REG    0x1C
74 #define	ADM1031_LOCAL_TEMP_LOW_LIMIT_REG	0x15
75 #define	ADM1031_REMOTE_TEMP_LOW_LIMIT_1_REG	0x19
76 #define	ADM1031_REMOTE_TEMP_LOW_LIMIT_2_REG	0x1D
77 #define	ADM1031_LOCAL_TEMP_THERM_LIMIT_REG	0x16
78 #define	ADM1031_REMOTE_TEMP_THERM_LIMIT_1_REG	0x1A
79 #define	ADM1031_REMOTE_TEMP_THERM_LIMIT_2_REG	0x1E
80 
81 
82 
83 #define	ADM1031_TEMP_CHANS		3
84 #define	ADM1031_FAN_SPEED_CHANS		2
85 
86 #define	ADM1031_TEMPERATURES		0
87 #define	ADM1031_FANS			1
88 #define	ADM1031_CONTROL			2
89 
90 
91 #define	ADM1031_INST_TO_MINOR(x)	((x << 8) & 0xF00)
92 #define	ADM1031_FCN_TO_MINOR(x)		((x << 4) & 0x0F0)
93 #define	ADM1031_FCNINST_TO_MINOR(x)	(x & 0x00F)
94 #define	ADM1031_MINOR_TO_FCNINST(x)	(0x00F & x)
95 #define	ADM1031_MINOR_TO_FCN(x)		((0x0F0 & x) >> 4)
96 #define	ADM1031_MINOR_TO_INST(x)	((x & 0xF00) >> 8)
97 
98 #define	ADM1031_CHECK_FOR_WRITES(x)	 (x > 26)
99 
100 /*
101  * Maximum speed for a fan is 0xf(100% PWM duty cycle) and minimum is
102  * 0x0(0% PWM duty cycle).
103  */
104 #define	ADM1031_CHECK_INVALID_SPEED(x) ((x) > 0x0F)
105 
106 /*
107  * Check if the minor node corresponds with the correct function.
108  */
109 #define	ADM1031_CHECK_FAN_CMD(x)	\
110 	(((x >= 6) && (x < 11)) || ((x >= 36) && (x < 41)))
111 
112 #define	ADM1031_CHECK_TEMPERATURE_CMD(x) 	\
113 	(((x >= 11) && (x < 27)) || ((x >= 41) && (x < 57)))
114 
115 #define	ADM1031_CHECK_CONTROL_CMD(x)	\
116 	(((x >= 1) && (x < 6)) || ((x >= 34) && (x < 36)))
117 
118 
119 #define	MLSN(x)		(x & 0xf0)
120 #define	MMSN(x)		(x & 0x0f)
121 
122 #define	ADM1031_BUSYFLAG	0x1
123 #define	ADM1031_TBUFFLAG	0x2
124 #define	ADM1031_REGFLAG		0x4
125 #define	ADM1031_MUTEXFLAG	0x8
126 #define	ADM1031_INTRFLAG	0x10
127 #define	ADM1031_AUTOFLAG	0x80
128 
129 #define	ADM1031_NODE_TYPE	"ddi_i2c:hardware_monitor"
130 
131 typedef struct adm1031_cpr_state {
132 	uint8_t		config_reg_1;
133 	uint8_t		config_reg_2;
134 	uint8_t		fan_speed_reg;
135 } adm1031_cpr_state_t;
136 
137 typedef struct adm1031_unit {
138 	dev_info_t		*adm1031_dip;
139 	i2c_transfer_t		*adm1031_transfer;
140 	ddi_iblock_cookie_t	adm1031_icookie;
141 	kmutex_t		adm1031_mutex;
142 	kcondvar_t		adm1031_cv;
143 	kmutex_t		adm1031_imutex;
144 	kcondvar_t		adm1031_icv;
145 	int			adm1031_cvwaiting;
146 	int			adm1031_flags;
147 	i2c_client_hdl_t	adm1031_hdl;
148 	char			adm1031_name[12];
149 	int			adm1031_oflag;
150 	adm1031_cpr_state_t	adm1031_cpr_state;
151 } adm1031_unit_t;
152 
153 typedef struct minor_info {
154 	char			*minor_name;
155 	uchar_t			reg;
156 } minor_info;
157 
158 #ifdef	__cplusplus
159 }
160 #endif
161 
162 #endif /* _ADM1031_IMPL_H */
163