xref: /freebsd/sys/dev/acpica/acpi_smbus.h (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1 /*-
2  * Copyright (c) 2005 Hans Petter Selasky
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #ifndef _ACPI_SMBUS_H_
28 #define _ACPI_SMBUS_H_
29 
30 /*
31  * System Management Bus register offsets
32  */
33 #define SMBUS_PRTCL		0
34 #define SMBUS_STS		1
35 #define SMBUS_STS_MASK		0x1f
36 #define SMBUS_ADDR		2
37 #define SMBUS_CMD		3
38 #define SMBUS_DATA		4	/* 32 bytes */
39 #define SMBUS_BCNT		36
40 #define SMBUS_ALRM_ADDR		37
41 #define SMBUS_ALRM_DATA		38	/* 2 bytes */
42 
43 /*
44  * Smart-Battery commands and definitions
45  */
46 
47 /* Base address */
48 #define SMBATT_ADDRESS		0x16
49 
50 /* access: READ WRITE WORD */
51 #define SMBATT_CMD_MANUFACTURER_ACCESS		0
52 
53 /*
54  * access: READ WRITE WORD
55  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
56  * range : 0 .. 65535 inclusively
57  */
58 #define SMBATT_CMD_REMAINING_CAPACITY_ALARM	0x1
59 
60 /*
61  * access: READ WRITE WORD
62  * unit  : minutes
63  * range : 0 .. 65535 inclusively
64  */
65 #define SMBATT_CMD_REMAINING_TIME_ALARM		0x2
66 
67 /* access: READ WRITE WORD */
68 #define SMBATT_CMD_BATTERY_MODE			0x3
69 
70 #define SMBATT_BM_INTERNAL_CHARGE_CONTROLLER	(1 <<  0) /* READ */
71 #define SMBATT_BM_PRIMARY_BATTERY_SUPPORT	(1 <<  1) /* READ */
72 #define SMBATT_BM_CONDITION_FLAG		(1 <<  7) /* READ */
73 #define SMBATT_BM_CHARGE_CONTROLLER_ENABLED	(1 <<  8) /* READ WRITE */
74 #define SMBATT_BM_PRIMARY_BATTERY		(1 <<  9) /* READ WRITE */
75 #define SMBATT_BM_ALARM_MODE			(1 << 13) /* READ WRITE */
76 #define SMBATT_BM_CHARGER_MODE			(1 << 14) /* READ WRITE */
77 #define SMBATT_BM_CAPACITY_MODE			(1 << 15) /* READ WRITE */
78 
79 /*
80  * access: READ WRITE WORD
81  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
82  * range : signed WORD
83  */
84 #define SMBATT_CMD_AT_RATE			0x4
85 
86 /*
87  * access: READ WORD
88  * unit  : minutes
89  * range : 0 .. 65534, 65535 has special meaning
90  */
91 #define SMBATT_CMD_AT_RATE_TIME_TO_FULL		0x5
92 
93 /*
94  * access: READ WORD
95  * unit  : minutes
96  * range : 0 .. 65534, 65535 has special meaning
97  */
98 #define SMBATT_CMD_AT_RATE_TIME_TO_EMPTY	0x6
99 
100 /*
101  * access: READ WORD */
102 #define SMBATT_CMD_AT_RATE_OK			0x7
103 
104 /*
105  * access: READ WORD
106  * unit  : 0.1 degrees Kelvin
107  * range : 0 .. 6553.5 Kelvin
108  */
109 #define SMBATT_CMD_TEMPERATURE			0x8
110 
111 /*
112  * access: READ WORD
113  * unit  : mV
114  * range : 0 .. 65535 inclusively
115  */
116 #define SMBATT_CMD_VOLTAGE			0x9
117 
118 /*
119  * access: READ WORD
120  * unit  : mA
121  * range : signed WORD
122  */
123 #define SMBATT_CMD_CURRENT			0xa
124 
125 /*
126  * access: READ WORD
127  * unit  : mA
128  * range : signed WORD
129  */
130 #define SMBATT_CMD_AVERAGE_CURRENT		0xb
131 
132 /*
133  * access: READ WORD
134  * unit  : percent
135  * range : 0..100 inclusively
136  */
137 #define SMBATT_CMD_MAX_ERROR			0xc
138 
139 /*
140  * access: READ WORD
141  * unit  : percent
142  * range : 0..100 inclusively
143  */
144 #define SMBATT_CMD_RELATIVE_STATE_OF_CHARGE	0xd
145 
146 /*
147  * access: READ WORD
148  * unit  : percent
149  * range : 0..100 inclusively
150  */
151 #define SMBATT_CMD_ABSOLUTE_STATE_OF_CHARGE	0xe
152 
153 /*
154  * access: READ WORD
155  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
156  * range : 0..65535 inclusively
157  */
158 #define SMBATT_CMD_REMAINING_CAPACITY		0xf
159 
160 /*
161  * access: READ WORD
162  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
163  * range : 0..65535 inclusively
164  */
165 #define SMBATT_CMD_FULL_CHARGE_CAPACITY		0x10
166 
167 /*
168  * access: READ WORD
169  * unit  : minutes
170  * range : 0..65534, 65535 is reserved
171  */
172 #define SMBATT_CMD_RUN_TIME_TO_EMPTY		0x11
173 
174 /*
175  * access: READ WORD
176  * unit  : minutes
177  * range : 0..65534, 65535 is reserved
178  */
179 #define SMBATT_CMD_AVERAGE_TIME_TO_EMPTY	0x12
180 
181 /*
182  * access: READ WORD
183  * unit  : minutes
184  * range : 0..65534, 65535 is reserved
185  */
186 #define SMBATT_CMD_AVERAGE_TIME_TO_FULL		0x13
187 
188 /*
189  * access: READ WORD
190  * unit  : mA
191  */
192 #define SMBATT_CMD_CHARGING_CURRENT		0x14
193 
194 /*
195  * access: READ WORD
196  * unit  : mV
197  * range : 0 .. 65534, 65535 reserved
198  */
199 #define SMBATT_CMD_CHARGING_VOLTAGE		0x15
200 
201 /* access: READ WORD */
202 #define SMBATT_CMD_BATTERY_STATUS		0x16
203 
204 /* alarm bits */
205 #define SMBATT_BS_OVER_CHARGED_ALARM		(1 << 15)
206 #define SMBATT_BS_TERMINATE_CHARGE_ALARM	(1 << 14)
207 #define SMBATT_BS_RESERVED_2			(1 << 13)
208 #define SMBATT_BS_OVER_TEMP_ALARM		(1 << 12)
209 #define SMBATT_BS_TERMINATE_DISCHARGE_ALARM	(1 << 11)
210 #define SMBATT_BS_RESERVED_1			(1 << 10)
211 #define SMBATT_BS_REMAINING_CAPACITY_ALARM     	(1 << 9)
212 #define SMBATT_BS_REMAINING_TIME_ALARM		(1 << 8)
213 
214 /* status bits */
215 #define SMBATT_BS_INITIALIZED			(1 << 7)
216 #define SMBATT_BS_DISCHARGING			(1 << 6)
217 #define SMBATT_BS_FULLY_CHARGED			(1 << 5)
218 #define SMBATT_BS_FULLY_DISCHARGED		(1 << 4)
219 
220 /* error bits */
221 #define SMBATT_BS_GET_ERROR(x)			((x) & 0xf)
222 #define SMBATT_BS_ERROR_OK			0
223 #define SMBATT_BS_ERROR_BUSY			1
224 #define SMBATT_BS_ERROR_RESERVED_COMMAND	2
225 #define SMBATT_BS_ERROR_UNSUPPORTED_COMMAND	3
226 #define SMBATT_BS_ERROR_ACCESS_DENIED		4
227 #define SMBATT_BS_ERROR_OVER_UNDER_FLOW		5
228 #define SMBATT_BS_ERROR_BADSIZE			6
229 #define SMBATT_BS_ERROR_UNKNOWN			7
230 
231 /*
232  * access: READ WORD
233  * unit  : cycle(s)
234  * range : 0 .. 65534, 65535 reserved
235  */
236 #define SMBATT_CMD_CYCLE_COUNT			0x17
237 
238 /*
239  * access: READ WORD
240  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
241  * range : 0..65535 inclusively
242  */
243 #define SMBATT_CMD_DESIGN_CAPACITY		0x18
244 
245 /*
246  * access: READ WORD
247  * unit  : mV
248  * range : 0..65535 mV
249  */
250 #define SMBATT_CMD_DESIGN_VOLTAGE		0x19
251 
252 /* access: READ WORD */
253 #define SMBATT_CMD_SPECIFICATION_INFO		0x1a
254 
255 #define SMBATT_SI_GET_REVISION(x)	(((x) >>  0) & 0xf)
256 #define SMBATT_SI_GET_VERSION(x)	(((x) >>  4) & 0xf)
257 #define SMBATT_SI_GET_VSCALE(x)		(((x) >>  8) & 0xf)
258 #define SMBATT_SI_GET_IPSCALE(x)	(((x) >> 12) & 0xf)
259 
260 /* access: READ WORD */
261 #define SMBATT_CMD_MANUFACTURE_DATE 		0x1b
262 
263 #define SMBATT_MD_GET_DAY(x)		 (((x) >> 0) & 0x1f)
264 #define SMBATT_MD_GET_MONTH(x)		 (((x) >> 5) & 0xf)
265 #define SMBATT_MD_GET_YEAR(x)		((((x) >> 9) & 0x7f) + 1980)
266 
267 /* access: READ WORD */
268 #define SMBATT_CMD_SERIAL_NUMBER		0x1c
269 
270 /* access: READ BLOCK */
271 #define SMBATT_CMD_MANUFACTURER_NAME		0x20
272 
273 /* access: READ BLOCK */
274 #define SMBATT_CMD_DEVICE_NAME			0x21
275 
276 /* access: READ BLOCK */
277 #define SMBATT_CMD_DEVICE_CHEMISTRY		0x22
278 
279 /* access: READ BLOCK */
280 #define SMBATT_CMD_MANUFACTURER_DATA		0x23
281 
282 #endif /* !_ACPI_SMBUS_H_ */
283