blob: 0a0caec2796dbce0dce640b9510109fadbd15aac [file] [log] [blame]
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
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.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080015 */
16
17// Scope (EC0)
18
Nicolas Boichat07fe6182018-01-26 14:37:16 +080019/* Mutex for EC battery index interface */
Matt DeVillier047b23f2018-02-11 16:07:12 -060020Mutex (BATM, 0)
Nicolas Boichat07fe6182018-01-26 14:37:16 +080021
22// Wait for desired battery index to be presented in shared memory
23// Arg0 = battery index
24// Returns Zero on success, One on error.
25Method (BTSW, 1)
26{
27#ifdef EC_ENABLE_SECOND_BATTERY_DEVICE
28 If (LEqual (BTIX, Arg0)) {
29 Return (Zero)
30 }
31 If (LGreaterEqual (Arg0, BTCN)) {
32 Return (One)
33 }
34 Store (Arg0, \_SB.PCI0.LPCB.EC0.BTID)
35 Store (5, Local0) // Timeout 5 msec
36 While (LNotEqual (BTIX, Arg0))
37 {
38 Sleep (1)
39 Decrement (Local0)
40 If (LEqual (Local0, Zero))
41 {
42 Return (One)
43 }
44 }
Lijian Zhao2db6fbc2018-02-08 12:57:01 -080045#else
46 If (LNotEqual (0, Arg0)) {
47 Return (One)
48 }
Nicolas Boichat07fe6182018-01-26 14:37:16 +080049#endif
50 Return (Zero)
51}
52
53// _STA implementation.
54// Arg0 = battery index
55Method (BSTA, 1, Serialized)
56{
57 If (Acquire (^BATM, 1000)) {
58 Return (Zero)
59 }
60
61 If (And(Not(BTSW (Arg0)), BTEX)) {
62 Store (0x1F, Local0)
63 } Else {
64 Store (0x0F, Local0)
65 }
66
67 Release (^BATM)
68 Return (Local0)
69}
70
71// _BIF implementation.
72// Arg0 = battery index
73// Arg1 = PBIF
74Method (BBIF, 2, Serialized)
75{
76 If (Acquire (^BATM, 1000)) {
77 Return (Arg1)
78 }
79
80 If (BTSW (Arg0)) {
81 Release (^BATM)
82 Return (Arg1)
83 }
84 // Last Full Charge Capacity
85 Store (BTDF, Index (Arg1, 2))
86
87 // Design Voltage
88 Store (BTDV, Index (Arg1, 4))
89
90 // Design Capacity
91 Store (BTDA, Local0)
92 Store (Local0, Index (Arg1, 1))
93
94 // Design Capacity of Warning
95 Divide (Multiply (Local0, DWRN), 100, , Local2)
96 Store (Local2, Index (Arg1, 5))
97
98 // Design Capacity of Low
99 Divide (Multiply (Local0, DLOW), 100, , Local2)
100 Store (Local2, Index (Arg1, 6))
101
102 // Get battery info from mainboard
103 Store (ToString(Concatenate(BMOD, 0x00)), Index (Arg1, 9))
104 Store (ToString(Concatenate(BSER, 0x00)), Index (Arg1, 10))
105 Store (ToString(Concatenate(BMFG, 0x00)), Index (Arg1, 12))
106
107 Release (^BATM)
108 Return (Arg1)
109}
110
111// _BIX implementation.
112// Arg0 = battery index
113// Arg1 = PBIX
114Method (BBIX, 2, Serialized)
115{
116 If (Acquire (^BATM, 1000)) {
117 Return (Arg1)
118 }
119
120 If (BTSW (Arg0)) {
121 Release (^BATM)
122 Return (Arg1)
123 }
124 // Last Full Charge Capacity
125 Store (BTDF, Index (Arg1, 3))
126
127 // Design Voltage
128 Store (BTDV, Index (Arg1, 5))
129
130 // Design Capacity
131 Store (BTDA, Local0)
132 Store (Local0, Index (Arg1, 2))
133
134 // Design Capacity of Warning
135 Divide (Multiply (Local0, DWRN), 100, , Local2)
136 Store (Local2, Index (Arg1, 6))
137
138 // Design Capacity of Low
139 Divide (Multiply (Local0, DLOW), 100, , Local2)
140 Store (Local2, Index (Arg1, 7))
141
142 // Cycle Count
143 Store (BTCC, Index (Arg1, 8))
144
145 // Get battery info from mainboard
146 Store (ToString(Concatenate(BMOD, 0x00)), Index (Arg1, 16))
147 Store (ToString(Concatenate(BSER, 0x00)), Index (Arg1, 17))
148 Store (ToString(Concatenate(BMFG, 0x00)), Index (Arg1, 19))
149
150 Release (^BATM)
151 Return (Arg1)
152}
153
154// _BST implementation.
155// Arg0 = battery index
156// Arg1 = PBST
157// Arg2 = BSTP
158// Arg3 = BFWK
159Method (BBST, 4, Serialized)
160{
161 If (Acquire (^BATM, 1000)) {
162 Return (Arg1)
163 }
164
165 If (BTSW (Arg0)) {
166 Release (^BATM)
167 Return (Arg1)
168 }
169 //
170 // 0: BATTERY STATE
171 //
172 // bit 0 = discharging
173 // bit 1 = charging
174 // bit 2 = critical level
175 //
176 Store (Zero, Local1)
177
178 // Check if AC is present
179 If (ACEX) {
180 If (BFCG) {
181 Store (0x02, Local1)
182 } ElseIf (BFDC) {
183 Store (0x01, Local1)
184 }
185 } Else {
186 // Always discharging when on battery power
187 Store (0x01, Local1)
188 }
189
190 // Check for critical battery level
191 If (BFCR) {
192 Or (Local1, 0x04, Local1)
193 }
194 Store (Local1, Index (Arg1, 0))
195
196 // Notify if battery state has changed since last time
197 If (LNotEqual (Local1, Arg2)) {
198 Store (Local1, Arg2)
199 If (LEqual(Arg0, 0)) {
200 Notify (BAT0, 0x80)
201 }
202#ifdef EC_ENABLE_SECOND_BATTERY_DEVICE
203 Else {
204 Notify (BAT1, 0x80)
205 }
206#endif
207 }
208
209 //
210 // 1: BATTERY PRESENT RATE
211 //
212 Store (BTPR, Index (Arg1, 1))
213
214 //
215 // 2: BATTERY REMAINING CAPACITY
216 //
217 Store (BTRA, Local1)
218 If (LAnd (Arg3, LAnd (ACEX, LNot (LAnd (BFDC, BFCG))))) {
219 // On AC power and battery is neither charging
220 // nor discharging. Linux expects a full battery
221 // to report same capacity as last full charge.
222 // https://bugzilla.kernel.org/show_bug.cgi?id=12632
223 Store (BTDF, Local2)
224
225 // See if within ~6% of full
226 ShiftRight (Local2, 4, Local3)
227 If (LAnd (LGreater (Local1, Subtract (Local2, Local3)),
228 LLess (Local1, Add (Local2, Local3))))
229 {
230 Store (Local2, Local1)
231 }
232 }
233 Store (Local1, Index (Arg1, 2))
234
235 //
236 // 3: BATTERY PRESENT VOLTAGE
237 //
238 Store (BTVO, Index (Arg1, 3))
239
240 Release (^BATM)
241 Return (Arg1)
242}
243
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800244Device (BAT0)
245{
246 Name (_HID, EISAID ("PNP0C0A"))
247 Name (_UID, 1)
248 Name (_PCL, Package () { \_SB })
249
250 Name (PBIF, Package () {
251 0x00000001, // 0x00: Power Unit: mAh
252 0xFFFFFFFF, // 0x01: Design Capacity
253 0xFFFFFFFF, // 0x02: Last Full Charge Capacity
254 0x00000001, // 0x03: Battery Technology: Rechargeable
255 0xFFFFFFFF, // 0x04: Design Voltage
256 0x00000003, // 0x05: Design Capacity of Warning
257 0xFFFFFFFF, // 0x06: Design Capacity of Low
258 0x00000001, // 0x07: Capacity Granularity 1
259 0x00000001, // 0x08: Capacity Granularity 2
260 "", // 0x09: Model Number
261 "", // 0x0a: Serial Number
262 "LION", // 0x0b: Battery Type
263 "" // 0x0c: OEM Information
264 })
265
266 Name (PBIX, Package () {
267 0x00000000, // 0x00: Revision
268 0x00000001, // 0x01: Power Unit: mAh
269 0xFFFFFFFF, // 0x02: Design Capacity
270 0xFFFFFFFF, // 0x03: Last Full Charge Capacity
271 0x00000001, // 0x04: Battery Technology: Rechargeable
272 0xFFFFFFFF, // 0x05: Design Voltage
273 0x00000003, // 0x06: Design Capacity of Warning
274 0xFFFFFFFF, // 0x07: Design Capacity of Low
275 0x00000000, // 0x08: Cycle Count
276 0x00018000, // 0x09: Measurement Accuracy (98.3%?)
277 0x000001F4, // 0x0a: Max Sampling Time (500ms)
278 0x0000000a, // 0x0b: Min Sampling Time (10ms)
279 0xFFFFFFFF, // 0x0c: Max Averaging Interval
280 0xFFFFFFFF, // 0x0d: Min Averaging Interval
281 0x00000001, // 0x0e: Capacity Granularity 1
282 0x00000001, // 0x0f: Capacity Granularity 2
283 "", // 0x10 Model Number
284 "", // 0x11: Serial Number
285 "LION", // 0x12: Battery Type
286 "" // 0x13: OEM Information
287 })
288
289 Name (PBST, Package () {
290 0x00000000, // 0x00: Battery State
291 0xFFFFFFFF, // 0x01: Battery Present Rate
292 0xFFFFFFFF, // 0x02: Battery Remaining Capacity
293 0xFFFFFFFF, // 0x03: Battery Present Voltage
294 })
295 Name (BSTP, Zero)
296
297 // Workaround for full battery status, enabled by default
298 Name (BFWK, One)
299
300 // Method to enable full battery workaround
301 Method (BFWE)
302 {
303 Store (One, BFWK)
304 }
305
306 // Method to disable full battery workaround
307 Method (BFWD)
308 {
309 Store (Zero, BFWK)
310 }
311
312 Method (_STA, 0, Serialized)
313 {
Nicolas Boichat07fe6182018-01-26 14:37:16 +0800314 Return (BSTA (0))
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800315 }
316
317 Method (_BIF, 0, Serialized)
318 {
Nicolas Boichat07fe6182018-01-26 14:37:16 +0800319 Return (BBIF (0, PBIF))
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800320 }
321
Duncan Lauried8401182014-09-29 08:32:19 -0700322 Method (_BIX, 0, Serialized)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800323 {
Nicolas Boichat07fe6182018-01-26 14:37:16 +0800324 Return (BBIX (0, PBIX))
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800325 }
326
327 Method (_BST, 0, Serialized)
328 {
Nicolas Boichat07fe6182018-01-26 14:37:16 +0800329 Return (BBST (0, PBST, BSTP, BFWK))
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800330 }
331}
Nicolas Boichat07fe6182018-01-26 14:37:16 +0800332
333#ifdef EC_ENABLE_SECOND_BATTERY_DEVICE
334Device (BAT1)
335{
336 Name (_HID, EISAID ("PNP0C0A"))
337 Name (_UID, 1)
338 Name (_PCL, Package () { \_SB })
339
340 Name (PBIF, Package () {
341 0x00000001, // 0x00: Power Unit: mAh
342 0xFFFFFFFF, // 0x01: Design Capacity
343 0xFFFFFFFF, // 0x02: Last Full Charge Capacity
344 0x00000001, // 0x03: Battery Technology: Rechargeable
345 0xFFFFFFFF, // 0x04: Design Voltage
346 0x00000003, // 0x05: Design Capacity of Warning
347 0xFFFFFFFF, // 0x06: Design Capacity of Low
348 0x00000001, // 0x07: Capacity Granularity 1
349 0x00000001, // 0x08: Capacity Granularity 2
350 "", // 0x09: Model Number
351 "", // 0x0a: Serial Number
352 "LION", // 0x0b: Battery Type
353 "" // 0x0c: OEM Information
354 })
355
356 Name (PBIX, Package () {
357 0x00000000, // 0x00: Revision
358 0x00000001, // 0x01: Power Unit: mAh
359 0xFFFFFFFF, // 0x02: Design Capacity
360 0xFFFFFFFF, // 0x03: Last Full Charge Capacity
361 0x00000001, // 0x04: Battery Technology: Rechargeable
362 0xFFFFFFFF, // 0x05: Design Voltage
363 0x00000003, // 0x06: Design Capacity of Warning
364 0xFFFFFFFF, // 0x07: Design Capacity of Low
365 0x00000000, // 0x08: Cycle Count
366 0x00018000, // 0x09: Measurement Accuracy (98.3%?)
367 0x000001F4, // 0x0a: Max Sampling Time (500ms)
368 0x0000000a, // 0x0b: Min Sampling Time (10ms)
369 0xFFFFFFFF, // 0x0c: Max Averaging Interval
370 0xFFFFFFFF, // 0x0d: Min Averaging Interval
371 0x00000001, // 0x0e: Capacity Granularity 1
372 0x00000001, // 0x0f: Capacity Granularity 2
373 "", // 0x10 Model Number
374 "", // 0x11: Serial Number
375 "LION", // 0x12: Battery Type
376 "" // 0x13: OEM Information
377 })
378
379 Name (PBST, Package () {
380 0x00000000, // 0x00: Battery State
381 0xFFFFFFFF, // 0x01: Battery Present Rate
382 0xFFFFFFFF, // 0x02: Battery Remaining Capacity
383 0xFFFFFFFF, // 0x03: Battery Present Voltage
384 })
385 Name (BSTP, Zero)
386
387 // Workaround for full battery status, enabled by default
388 Name (BFWK, One)
389
390 // Method to enable full battery workaround
391 Method (BFWE)
392 {
393 Store (One, BFWK)
394 }
395
396 // Method to disable full battery workaround
397 Method (BFWD)
398 {
399 Store (Zero, BFWK)
400 }
401
402 Method (_STA, 0, Serialized)
403 {
404 Return (BSTA (1))
405 }
406
407 Method (_BIF, 0, Serialized)
408 {
409 Return (BBIF (1, PBIF))
410 }
411
412 Method (_BIX, 0, Serialized)
413 {
414 Return (BBIX (1, PBIX))
415 }
416
417 Method (_BST, 0, Serialized)
418 {
419 Return (BBST (1, PBST, BSTP, BFWK))
420 }
421}
422#endif