1 /* SPDX-License-Identifier: GPL-2.0-only */
5 /* Mutex for EC battery index interface */
8 // Wait for desired battery index to be presented in shared memory
9 // Arg0 = battery index
10 // Returns 0 on success, 1 on error.
13 #ifdef EC_ENABLE_SECOND_BATTERY_DEVICE
20 \_SB.PCI0.LPCB.EC0.BTID = Arg0
21 Local0 = 5 // Timeout 5 msec
39 // _STA implementation.
40 // Arg0 = battery index
41 Method (BSTA, 1, Serialized)
43 If (Acquire (^BATM, 1000)) {
47 If (~BTSW (Arg0) & BTEX) {
57 #if CONFIG(EC_GOOGLE_CHROMEEC_READ_BATTERY_LONG_STRING)
58 // Cached flag for BSRF FIFO readout support from EC.
63 // Cached battery string response indicator
67 // Cached battery string response data to save suspend-resume time
68 Name(BRS1, Buffer(32) {0})
69 Name(BRS2, Buffer(32) {0})
70 Name(BRS3, Buffer(32) {0})
71 // Read extended battery strings from the selected battery.
72 // Arg0 = string index
74 // If supported by the EC, strings of arbitrary length are read using the
75 // FIFO readout method. Otherwise short (no more than 8 bytes) strings are
76 // read from the EC shared memory map. The desired battery index should be
77 // selected with BTSW before calling this method.
79 // Currently supported string indexes:
80 // * 1 = EC_ACPI_MEM_STRINGS_FIFO_ID_BATTERY_MODEL: battery model name,
81 // equivalent to BMOD.
82 // * 2 = EC_ACPI_MEM_STRINGS_FIFO_ID_BATTERY_SERIAL: battery serial number,
83 // equivalent to BSER.
84 // * 3 = EC_ACPI_MEM_STRINGS_FIFO_ID_BATTERY_MANUFACTURER: battery
85 // manufacturer's name, equivalent to BMFG.
87 // These are assumed to be supported if the EC reports at least version 1 of
88 // string readout (it returns an integer greater than 0 and less than 255 when
89 // reading FIFO index 0). Future strings may require higher FIFO versions.
90 Method(BRSX, 1, Serialized)
92 // It doesn't make sense to read the FIFO support indicator.
93 if (Arg0 == 0 || Arg0 > 3)
98 // Check if response is already cached
99 If (Arg0 == 1 && BRI1 == 1)
101 Return (BRS1) /* battery model name */
104 If (Arg0 == 2 && BRI2 == 1)
106 Return (BRS2) /* battery serial number */
109 If (Arg0 == 3 && BRI3 == 1)
111 Return (BRS3) /* battery manufacturer's name */
116 // Write 0 to BSRF to read back a support indicator; nonzero and
117 // non-0xFF if FIFO readout is supported, assuming minimum v1 support
118 // for strings 1 through 3.
122 // 0xff readback also means no support for FIFO readout, when the EC
123 // doesn't even know what this command is.
130 // If FIFO readout through BSRF is not supported, fall back to reading
131 // the short strings in EMEM.
136 Local0 = ToString (Concatenate (BMOD, 0))
140 Local0 = ToString (Concatenate (BSER, 0))
144 Local0 = ToString (Concatenate (BMFG, 0))
149 // Select requested parameter to read
152 // Read to end of string, or up to a reasonable maximum length. Reads of
153 // BSRF consume bytes from the FIFO, so take care to read it only once
157 While (Local1 != 0 && SizeOf (Local0) < 32)
159 Local0 = Concatenate (Local0, ToString (Local1))
164 // Store the result in the cache
186 // _BIF implementation.
187 // Arg0 = battery index
189 Method (BBIF, 2, Serialized)
191 If (Acquire (^BATM, 1000)) {
199 // Last Full Charge Capacity
209 // Design Capacity of Warning
210 Local2 = Local0 * DWRN / 100
213 // Design Capacity of Low
214 Local2 = Local0 * DLOW / 100
217 // Get battery info from mainboard
226 // _BIX implementation.
227 // Arg0 = battery index
229 Method (BBIX, 2, Serialized)
231 If (Acquire (^BATM, 1000)) {
239 // Last Full Charge Capacity
249 // Design Capacity of Warning
250 Local2 = Local0 * DWRN / 100
253 // Design Capacity of Low
254 Local2 = Local0 * DLOW / 100
260 // Get battery info from mainboard
269 // _BST implementation.
270 // Arg0 = battery index
274 Method (BBST, 4, Serialized)
276 If (Acquire (^BATM, 1000)) {
287 // bit 0 = discharging
289 // bit 2 = critical level
293 // Check if AC is present
301 // Always discharging when on battery power
305 // Check for critical battery level
311 // Notify if battery state has changed since last time
312 If (Local1 != DeRefOf (Arg2)) {
317 #ifdef EC_ENABLE_SECOND_BATTERY_DEVICE
325 // 1: BATTERY PRESENT RATE
330 // 2: BATTERY REMAINING CAPACITY
333 If (Arg3 && ACEX && !(BFDC && BFCG)) {
334 // On AC power and battery is neither charging
335 // nor discharging. Linux expects a full battery
336 // to report same capacity as last full charge.
337 // https://bugzilla.kernel.org/show_bug.cgi?id=12632
340 // See if within ~6% of full
342 If (Local1 > Local2 - Local3 && Local1 < Local2 + Local3)
350 // 3: BATTERY PRESENT VOLTAGE
360 Name (_HID, EISAID ("PNP0C0A"))
362 Name (_PCL, Package () { \_SB })
364 Name (PBIF, Package () {
365 0x00000001, // 0x00: Power Unit: mAh
366 0xFFFFFFFF, // 0x01: Design Capacity
367 0xFFFFFFFF, // 0x02: Last Full Charge Capacity
368 0x00000001, // 0x03: Battery Technology: Rechargeable
369 0xFFFFFFFF, // 0x04: Design Voltage
370 0x00000003, // 0x05: Design Capacity of Warning
371 0xFFFFFFFF, // 0x06: Design Capacity of Low
372 0x00000001, // 0x07: Capacity Granularity 1
373 0x00000001, // 0x08: Capacity Granularity 2
374 "", // 0x09: Model Number
375 "", // 0x0a: Serial Number
376 "LION", // 0x0b: Battery Type
377 "" // 0x0c: OEM Information
380 Name (PBIX, Package () {
381 0x00000000, // 0x00: Revision
382 0x00000001, // 0x01: Power Unit: mAh
383 0xFFFFFFFF, // 0x02: Design Capacity
384 0xFFFFFFFF, // 0x03: Last Full Charge Capacity
385 0x00000001, // 0x04: Battery Technology: Rechargeable
386 0xFFFFFFFF, // 0x05: Design Voltage
387 0x00000003, // 0x06: Design Capacity of Warning
388 0xFFFFFFFF, // 0x07: Design Capacity of Low
389 0x00000000, // 0x08: Cycle Count
390 0x00018000, // 0x09: Measurement Accuracy (98.3%?)
391 0x000001F4, // 0x0a: Max Sampling Time (500ms)
392 0x0000000a, // 0x0b: Min Sampling Time (10ms)
393 0xFFFFFFFF, // 0x0c: Max Averaging Interval
394 0xFFFFFFFF, // 0x0d: Min Averaging Interval
395 0x00000001, // 0x0e: Capacity Granularity 1
396 0x00000001, // 0x0f: Capacity Granularity 2
397 "", // 0x10 Model Number
398 "", // 0x11: Serial Number
399 "LION", // 0x12: Battery Type
400 "" // 0x13: OEM Information
403 Name (PBST, Package () {
404 0x00000000, // 0x00: Battery State
405 0xFFFFFFFF, // 0x01: Battery Present Rate
406 0xFFFFFFFF, // 0x02: Battery Remaining Capacity
407 0xFFFFFFFF, // 0x03: Battery Present Voltage
411 // Workaround for full battery status, disabled by default
414 // Method to enable full battery workaround
420 // Method to disable full battery workaround
426 Method (_STA, 0, Serialized)
431 Method (_BIF, 0, Serialized)
433 Return (BBIF (0, PBIF))
436 Method (_BIX, 0, Serialized)
438 Return (BBIX (0, PBIX))
441 Method (_BST, 0, Serialized)
443 Return (BBST (0, PBST, RefOf (BSTP), BFWK))
447 #ifdef EC_ENABLE_SECOND_BATTERY_DEVICE
450 Name (_HID, EISAID ("PNP0C0A"))
452 Name (_PCL, Package () { \_SB })
454 Name (PBIF, Package () {
455 0x00000001, // 0x00: Power Unit: mAh
456 0xFFFFFFFF, // 0x01: Design Capacity
457 0xFFFFFFFF, // 0x02: Last Full Charge Capacity
458 0x00000001, // 0x03: Battery Technology: Rechargeable
459 0xFFFFFFFF, // 0x04: Design Voltage
460 0x00000003, // 0x05: Design Capacity of Warning
461 0xFFFFFFFF, // 0x06: Design Capacity of Low
462 0x00000001, // 0x07: Capacity Granularity 1
463 0x00000001, // 0x08: Capacity Granularity 2
464 "", // 0x09: Model Number
465 "", // 0x0a: Serial Number
466 "LION", // 0x0b: Battery Type
467 "" // 0x0c: OEM Information
470 Name (PBIX, Package () {
471 0x00000000, // 0x00: Revision
472 0x00000001, // 0x01: Power Unit: mAh
473 0xFFFFFFFF, // 0x02: Design Capacity
474 0xFFFFFFFF, // 0x03: Last Full Charge Capacity
475 0x00000001, // 0x04: Battery Technology: Rechargeable
476 0xFFFFFFFF, // 0x05: Design Voltage
477 0x00000003, // 0x06: Design Capacity of Warning
478 0xFFFFFFFF, // 0x07: Design Capacity of Low
479 0x00000000, // 0x08: Cycle Count
480 0x00018000, // 0x09: Measurement Accuracy (98.3%?)
481 0x000001F4, // 0x0a: Max Sampling Time (500ms)
482 0x0000000a, // 0x0b: Min Sampling Time (10ms)
483 0xFFFFFFFF, // 0x0c: Max Averaging Interval
484 0xFFFFFFFF, // 0x0d: Min Averaging Interval
485 0x00000001, // 0x0e: Capacity Granularity 1
486 0x00000001, // 0x0f: Capacity Granularity 2
487 "", // 0x10 Model Number
488 "", // 0x11: Serial Number
489 "LION", // 0x12: Battery Type
490 "" // 0x13: OEM Information
493 Name (PBST, Package () {
494 0x00000000, // 0x00: Battery State
495 0xFFFFFFFF, // 0x01: Battery Present Rate
496 0xFFFFFFFF, // 0x02: Battery Remaining Capacity
497 0xFFFFFFFF, // 0x03: Battery Present Voltage
501 // Workaround for full battery status, disabled by default
504 // Method to enable full battery workaround
510 // Method to disable full battery workaround
516 Method (_STA, 0, Serialized)
521 Method (_BIF, 0, Serialized)
523 Return (BBIF (1, PBIF))
526 Method (_BIX, 0, Serialized)
528 Return (BBIX (1, PBIX))
531 Method (_BST, 0, Serialized)
533 Return (BBST (1, PBST, RefOf (BSTP), BFWK))