Thinkpad: Enable Battery events
[coreboot.git] / src / ec / lenovo / h8 / acpi / battery.asl
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (c) 2011 Sven Schnelle <svens@stackframe.org>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; version 2 of
9  * the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  */
21
22 Field(ERAM, ByteAcc, NoLock, Preserve)
23 {
24         Offset (0x38),
25                         B0ST, 4,        /* Battery 0 state */
26                             , 1,
27                         B0CH, 1,        /* Battery 0 charging */
28                         B0DI, 1,        /* Battery 0 discharging */
29                         B0PR, 1,        /* Battery 0 present */
30         Offset (0x39),
31                         B1ST, 4,        /* Battery 1 state */
32                             , 1,
33                         B1CH, 1,        /* Battery 1 charging, */
34                         B1DI, 1,        /* Battery 1 discharging,*/
35                         B1PR, 1         /* Battery 1 present */
36 }
37
38 /* EC Registers */
39 /* PAGE == 0x00 */
40 Field (ERAM, ByteAcc, NoLock, Preserve)
41 {
42         Offset(0xa0),
43                         BARC, 16,               /* Battery remaining capacity */
44                         BAFC, 16,               /* Battery full charge capacity */
45         Offset(0xa8),
46                         BAPR, 16,               /* Battery present rate */
47                         BAVO, 16,               /* Battery Voltage */
48 }
49
50 /* PAGE == 0x01 */
51 Field (ERAM, ByteAcc, NoLock, Preserve)
52 {
53         Offset(0xa0),
54                             , 15,
55                         BAMA,  1,
56 }
57
58 /* PAGE == 0x02 */
59 Field (ERAM, ByteAcc, NoLock, Preserve)
60 {
61         Offset(0xa0),
62                         BADC, 16,               /* Design Capacity */
63                         BADV, 16,               /* Design voltage */
64                             , 16,
65                             , 16,
66                             , 16,
67                         BASN, 16,
68 }
69
70 /* PAGE == 0x04: Battery type */
71 Field (ERAM, ByteAcc, NoLock, Preserve)
72 {
73         Offset(0xa0),
74                         BATY, 32
75 }
76
77
78 /* PAGE == 0x05: Battery OEM information */
79 Field (ERAM, ByteAcc, NoLock, Preserve)
80 {
81         Offset(0xa0),
82                         BAOE, 128
83 }
84
85 /* PAGE == 0x06: Battery name */
86 Field (ERAM, ByteAcc, NoLock, Preserve)
87 {
88         Offset(0xa0),
89                         BANA, 128
90 }
91
92 /* Arg0: Battery
93  * Arg1: Battery Status Package
94  * Arg2: charging
95  * Arg3: discharging
96  */
97 Method(BSTA, 4, NotSerialized)
98 {
99         Acquire(ECLK, 0xffff)
100         Store(0, Local0)
101         Or(1, Arg0, PAGE)
102         Store(BAMA, Local1)
103         Store(Arg0, PAGE) /* Battery dynamic information */
104
105         Store(BAPR, Local2)
106
107         if (Arg2) // charging
108         {
109                 Or(2, Local0, Local0)
110
111                 If (LGreaterEqual (Local2, 0x8000)) {
112                         Store(0, Local2)
113                 }
114         }
115
116         if (Arg3) // discharging
117         {
118                 Or(1, Local0, Local0)
119                 Subtract(0x10000, Local2, Local2)
120         }
121
122         Store(Local0, Index(Arg1, 0x00))
123
124         if (Local1) {
125                 Multiply (BARC, 10, Index(Arg1, 2))
126                 Multiply (Local2, BAVO, Local2)
127                 Divide (Local2, 1000, Local3, Index(Arg1, 1))
128         } else {
129                 Store(BARC, Index(Arg1, 2))
130                 Store(Local2, Index(Arg1, 1))
131         }
132         Store(BAVO, Index(Arg1, 3))
133         Release(ECLK)
134         Return (Arg1)
135 }
136
137 Method(BINF, 2, NotSerialized)
138 {
139         Acquire(ECLK, 0xffff)
140         Or(1, Arg1, PAGE) /* Battery 0 static information */
141         Xor(BAMA, 1, Index(Arg0, 0))
142         Store(BAMA, Local0)
143         Store(Arg1, PAGE)
144         Store(BAFC, Local2)
145         Or(2, Arg1, PAGE)
146         Store(BADC, Local1)
147
148         if (Local0)
149         {
150                 Multiply (Local1, 10, Local1)
151                 Multiply (Local2, 10, Local2)
152         }
153
154         Store(Local1, Index(Arg0, 1))   // Design Capacity
155         Store(Local2, Index(Arg0, 2))   // Last full charge capacity
156         Store(BADV, Index(Arg0, 4))     // Design Voltage
157         Divide (Local2, 20, Local0, Index(Arg0, 5)) // Warning capacity
158
159         Store (BASN, Local0)
160         Name (SERN, Buffer (0x06) { "     " })
161         Store (4, Local1)
162         While (Local0)
163         {
164                 Divide (Local0, 0x0A, Local2, Local0)
165                 Add (Local2, 48, Index (SERN, Local1))
166                 Decrement (Local1)
167         }
168         Store (SERN, Index (Arg0, 10)) // Serial Number
169
170         Or(4, Arg1, PAGE)
171         Name (TYPE, Buffer() { 0, 0, 0, 0, 0 })
172         Store(BATY, TYPE)
173         Store(TYPE, Index (Arg0, 11)) // Battery type
174         Or(5, Arg1, PAGE)
175         Store(BAOE, Index (Arg0, 12)) // OEM information
176         Or(6, Arg1, PAGE)
177         Store(BANA, Index (Arg0, 9))  // Model number
178         Release(ECLK)
179         Return (Arg0)
180 }
181
182 Device (BAT0)
183 {
184         Name (_HID, EisaId ("PNP0C0A"))
185         Name (_UID, 0x00)
186         Name (_PCL, Package () { \_SB })
187
188         Name (BATS, Package ()
189         {
190                 0x00,                   // 0: PowerUnit: Report in mWh
191                 0xFFFFFFFF,             // 1: Design cap
192                 0xFFFFFFFF,             // 2: Last full charge cap
193                 0x01,                   // 3: Battery Technology
194                 10800,                  // 4: Design Voltage (mV)
195                 0x00,                   // 5: Warning design capacity
196                 200,                    // 6: Low design capacity
197                 1,                      // 7: granularity1
198                 1,                      // 8: granularity2
199                 "",                     // 9: Model number
200                 "",                     // A: Serial number
201                 "",                     // B: Battery Type
202                 ""                      // C: OEM information
203         })
204
205         Method (_BIF, 0, NotSerialized)
206         {
207                 Return (BINF(BATS, 0))
208         }
209
210         Name (BATI, Package ()
211         {
212                 0,                      // Battery State
213                                         // Bit 0 - discharge
214                                         // Bit 1 - charge
215                                         // Bit 2 - critical state
216                 0,                      // Battery present Rate
217                 0,                      // Battery remaining capacity
218                 0                       // Battery present voltage
219         })
220
221         Method (_BST, 0, NotSerialized)
222         {
223                 if (B0PR) {
224                         Return (BSTA(0, BATI, B0CH, B0DI))
225                 } else {
226                         Return (BATS)
227                 }
228         }
229
230         Method (_STA, 0, NotSerialized)
231         {
232                 if (B0PR) {
233                         Return (0x1f)
234                 } else {
235                         Return (0x0f)
236                 }
237         }
238 }
239
240 Device (BAT1)
241 {
242         Name (_HID, EisaId ("PNP0C0A"))
243         Name (_UID, 0x00)
244         Name (_PCL, Package () { \_SB })
245
246         Name (BATS, Package ()
247         {
248                 0x00,                   // 0: PowerUnit: Report in mWh
249                 0xFFFFFFFF,             // 1: Design cap
250                 0xFFFFFFFF,             // 2: Last full charge cap
251                 0x01,                   // 3: Battery Technology
252                 10800,                  // 4: Design Voltage (mV)
253                 0x00,                   // 5: Warning design capacity
254                 200,                    // 6: Low design capacity
255                 1,                      // 7: granularity1
256                 1,                      // 8: granularity2
257                 "",                     // 9: Model number
258                 "",                     // A: Serial number
259                 "",                     // B: Battery Type
260                 ""                      // C: OEM information
261         })
262
263         Method (_BIF, 0, NotSerialized)
264         {
265                 Return (BINF(BATS, 0x10))
266         }
267
268         Name (BATI, Package ()
269         {
270                 0,                      // Battery State
271                                         // Bit 0 - discharge
272                                         // Bit 1 - charge
273                                         // Bit 2 - critical state
274                 0,                      // Battery present Rate
275                 0,                      // Battery remaining capacity
276                 0                       // Battery present voltage
277         })
278
279         Method (_BST, 0, NotSerialized)
280         {
281                 if (B1PR) {
282                         Return (BSTA(0x10, BATI, B1CH, B1DI))
283                 } else {
284                         Return (BATS)
285                 }
286         }
287
288         Method (_STA, 0, NotSerialized)
289         {
290                 if (B1PR) {
291                         Return (0x1f)
292                 } else {
293                         Return (0x0f)
294                 }
295         }
296 }
297
298 /* Battery 0 critical */
299 Method(_Q24, 0, NotSerialized)
300 {
301         Notify(BAT0, 0x80)
302 }
303
304 /* Battery 1 critical */
305 Method(_Q25, 0, NotSerialized)
306 {
307         Notify(BAT1, 0x80)
308 }
309
310 /* Battery 0 attach/detach */
311 Method(_Q4A, 0, NotSerialized)
312 {
313         Notify(BAT0, 0x81)
314 }
315
316 /* Battery 0 state change */
317 Method(_Q4B, 0, NotSerialized)
318 {
319         Notify(BAT0, 0x80)
320 }
321
322 /* Battery 1 attach/detach */
323 Method(_Q4C, 0, NotSerialized)
324 {
325         Notify(BAT1, 0x81)
326 }
327
328 /* Battery 1 state change */
329 Method(_Q4D, 0, NotSerialized)
330 {
331         Notify(BAT1, 0x80)
332 }