xref: /openbsd/sys/dev/acpi/smbus.h (revision a7e2cbad)
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  *	$FreeBSD$
27  */
28 
29 #ifndef _ACPI_SMBUS_H_
30 #define _ACPI_SMBUS_H_
31 
32 enum {
33         SMBUS_WRITE_QUICK = 2,
34         SMBUS_READ_QUICK = 3,
35         SMBUS_SEND_BYTE = 4,
36         SMBUS_RECEIVE_BYTE = 5,
37         SMBUS_WRITE_BYTE = 6,
38         SMBUS_READ_BYTE = 7,
39         SMBUS_WRITE_WORD  = 8,
40         SMBUS_READ_WORD  = 9,
41         SMBUS_WRITE_BLOCK = 0xa,
42         SMBUS_READ_BLOCK = 0xb,
43         SMBUS_PROCESS_CALL = 0xc,
44         SMBUS_BLOCK_PROCESS_CALL = 0xd,
45 };
46 
47 /*
48  * System Management Bus register offsets
49  */
50 #define SMBUS_PRTCL		0
51 #define SMBUS_STS		1
52 #define SMBUS_STS_MASK		0x1f
53 #define SMBUS_ADDR		2
54 #define SMBUS_CMD		3
55 #define SMBUS_DATA		4	/* SMBUS_DATA_SIZE bytes */
56 #define SMBUS_DATA_SIZE		32
57 #define SMBUS_BCNT		36
58 #define SMBUS_ALRM_ADDR		37
59 #define SMBUS_ALRM_DATA		38	/* 2 bytes */
60 
61 /*
62  * Smart-Battery commands and definitions
63  */
64 
65 /* Base address */
66 #define SMBATT_ADDRESS		0x16
67 
68 
69 /* access: READ WRITE WORD */
70 #define SMBATT_CMD_MANUFACTURER_ACCESS		0
71 
72 /*
73  * access: READ WRITE WORD
74  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
75  * range : 0 .. 65535 inclusively
76  */
77 #define SMBATT_CMD_REMAINING_CAPACITY_ALARM	0x1
78 
79 /*
80  * access: READ WRITE WORD
81  * unit  : minutes
82  * range : 0 .. 65535 inclusively
83  */
84 #define SMBATT_CMD_REMAINING_TIME_ALARM		0x2
85 
86 /* access: READ WRITE WORD */
87 #define SMBATT_CMD_BATTERY_MODE			0x3
88 
89 #define SMBATT_BM_INTERNAL_CHARGE_CONTROLLER	(1 <<  0) /* READ */
90 #define SMBATT_BM_PRIMARY_BATTERY_SUPPORT	(1 <<  1) /* READ */
91 #define SMBATT_BM_CONDITION_FLAG		(1 <<  7) /* READ */
92 #define SMBATT_BM_CHARGE_CONTROLLER_ENABLED	(1 <<  8) /* READ WRITE */
93 #define SMBATT_BM_PRIMARY_BATTERY		(1 <<  9) /* READ WRITE */
94 #define SMBATT_BM_ALARM_MODE			(1 << 13) /* READ WRITE */
95 #define SMBATT_BM_CHARGER_MODE			(1 << 14) /* READ WRITE */
96 #define SMBATT_BM_CAPACITY_MODE			(1 << 15) /* READ WRITE */
97 
98 /*
99  * access: READ WRITE WORD
100  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
101  * range : signed WORD
102  */
103 #define SMBATT_CMD_AT_RATE			0x4
104 
105 /*
106  * access: READ WORD
107  * unit  : minutes
108  * range : 0 .. 65534, 65535 has special meaning
109  */
110 #define SMBATT_CMD_AT_RATE_TIME_TO_FULL		0x5
111 
112 /*
113  * access: READ WORD
114  * unit  : minutes
115  * range : 0 .. 65534, 65535 has special meaning
116  */
117 #define SMBATT_CMD_AT_RATE_TIME_TO_EMPTY	0x6
118 
119 /*
120  * access: READ WORD */
121 #define SMBATT_CMD_AT_RATE_OK			0x7
122 
123 /*
124  * access: READ WORD
125  * unit  : 0.1 degrees Kelvin
126  * range : 0 .. 6553.5 Kelvin
127  */
128 #define SMBATT_CMD_TEMPERATURE			0x8
129 
130 /*
131  * access: READ WORD
132  * unit  : mV
133  * range : 0 .. 65535 inclusively
134  */
135 #define SMBATT_CMD_VOLTAGE			0x9
136 
137 /*
138  * access: READ WORD
139  * unit  : mA
140  * range : signed WORD
141  */
142 #define SMBATT_CMD_CURRENT			0xa
143 
144 /*
145  * access: READ WORD
146  * unit  : mA
147  * range : signed WORD
148  */
149 #define SMBATT_CMD_AVERAGE_CURRENT		0xb
150 
151 /*
152  * access: READ WORD
153  * unit  : percent
154  * range : 0..100 inclusively
155  */
156 #define SMBATT_CMD_MAX_ERROR			0xc
157 
158 /*
159  * access: READ WORD
160  * unit  : percent
161  * range : 0..100 inclusively
162  */
163 #define SMBATT_CMD_RELATIVE_STATE_OF_CHARGE	0xd
164 
165 /*
166  * access: READ WORD
167  * unit  : percent
168  * range : 0..100 inclusively
169  */
170 #define SMBATT_CMD_ABSOLUTE_STATE_OF_CHARGE	0xe
171 
172 /*
173  * access: READ WORD
174  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
175  * range : 0..65535 inclusively
176  */
177 #define SMBATT_CMD_REMAINING_CAPACITY		0xf
178 
179 /*
180  * access: READ WORD
181  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
182  * range : 0..65535 inclusively
183  */
184 #define SMBATT_CMD_FULL_CHARGE_CAPACITY		0x10
185 
186 /*
187  * access: READ WORD
188  * unit  : minutes
189  * range : 0..65534, 65535 is reserved
190  */
191 #define SMBATT_CMD_RUN_TIME_TO_EMPTY		0x11
192 
193 /*
194  * access: READ WORD
195  * unit  : minutes
196  * range : 0..65534, 65535 is reserved
197  */
198 #define SMBATT_CMD_AVERAGE_TIME_TO_EMPTY	0x12
199 
200 /*
201  * access: READ WORD
202  * unit  : minutes
203  * range : 0..65534, 65535 is reserved
204  */
205 #define SMBATT_CMD_AVERAGE_TIME_TO_FULL		0x13
206 
207 /*
208  * access: READ WORD
209  * unit  : mA
210  */
211 #define SMBATT_CMD_CHARGING_CURRENT		0x14
212 
213 /*
214  * access: READ WORD
215  * unit  : mV
216  * range : 0 .. 65534, 65535 reserved
217  */
218 #define SMBATT_CMD_CHARGING_VOLTAGE		0x15
219 
220 /* access: READ WORD */
221 #define SMBATT_CMD_BATTERY_STATUS		0x16
222 
223 /* alarm bits */
224 #define SMBATT_BS_OVER_CHARGED_ALARM		(1 << 15)
225 #define SMBATT_BS_TERMINATE_CHARGE_ALARM	(1 << 14)
226 #define SMBATT_BS_RESERVED_2			(1 << 13)
227 #define SMBATT_BS_OVER_TEMP_ALARM		(1 << 12)
228 #define SMBATT_BS_TERMINATE_DISCHARGE_ALARM	(1 << 11)
229 #define SMBATT_BS_RESERVED_1			(1 << 10)
230 #define SMBATT_BS_REMAINING_CAPACITY_ALARM     	(1 << 9)
231 #define SMBATT_BS_REMAINING_TIME_ALARM		(1 << 8)
232 
233 /* status bits */
234 #define SMBATT_BS_INITIALIZED			(1 << 7)
235 #define SMBATT_BS_DISCHARGING			(1 << 6)
236 #define SMBATT_BS_FULLY_CHARGED			(1 << 5)
237 #define SMBATT_BS_FULLY_DISCHARGED		(1 << 4)
238 
239 /* error bits */
240 #define SMBATT_BS_GET_ERROR(x)			((x) & 0xf)
241 #define SMBATT_BS_ERROR_OK			0
242 #define SMBATT_BS_ERROR_BUSY			1
243 #define SMBATT_BS_ERROR_RESERVED_COMMAND	2
244 #define SMBATT_BS_ERROR_UNSUPPORTED_COMMAND	3
245 #define SMBATT_BS_ERROR_ACCESS_DENIED		4
246 #define SMBATT_BS_ERROR_OVER_UNDER_FLOW		5
247 #define SMBATT_BS_ERROR_BADSIZE			6
248 #define SMBATT_BS_ERROR_UNKNOWN			7
249 
250 /*
251  * access: READ WORD
252  * unit  : cycle(s)
253  * range : 0 .. 65534, 65535 reserved
254  */
255 #define SMBATT_CMD_CYCLE_COUNT			0x17
256 
257 /*
258  * access: READ WORD
259  * unit  : mAh (CAPACITY_MODE=0) or 10 mWh (CAPACITY_MODE=1)
260  * range : 0..65535 inclusively
261  */
262 #define SMBATT_CMD_DESIGN_CAPACITY		0x18
263 
264 /*
265  * access: READ WORD
266  * unit  : mV
267  * range : 0..65535 mV
268  */
269 #define SMBATT_CMD_DESIGN_VOLTAGE		0x19
270 
271 /* access: READ WORD */
272 #define SMBATT_CMD_SPECIFICATION_INFO		0x1a
273 
274 #define SMBATT_SI_GET_REVISION(x)	(((x) >>  0) & 0xf)
275 #define SMBATT_SI_GET_VERSION(x)	(((x) >>  4) & 0xf)
276 #define SMBATT_SI_GET_VSCALE(x)		(((x) >>  8) & 0xf)
277 #define SMBATT_SI_GET_IPSCALE(x)	(((x) >> 12) & 0xf)
278 
279 /* access: READ WORD */
280 #define SMBATT_CMD_MANUFACTURE_DATE 		0x1b
281 
282 #define SMBATT_MD_GET_DAY(x)		 (((x) >> 0) & 0x1f)
283 #define SMBATT_MD_GET_MONTH(x)		 (((x) >> 5) & 0xf)
284 #define SMBATT_MD_GET_YEAR(x)		((((x) >> 9) & 0x7f) + 1980)
285 
286 /* access: READ WORD */
287 #define SMBATT_CMD_SERIAL_NUMBER		0x1c
288 
289 /* access: READ BLOCK */
290 #define SMBATT_CMD_MANUFACTURER_NAME		0x20
291 
292 /* access: READ BLOCK */
293 #define SMBATT_CMD_DEVICE_NAME			0x21
294 
295 /* access: READ BLOCK */
296 #define SMBATT_CMD_DEVICE_CHEMISTRY		0x22
297 
298 /* access: READ BLOCK */
299 #define SMBATT_CMD_MANUFACTURER_DATA		0x23
300 
301 #endif /* !_ACPI_SMBUS_H_ */
302