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