2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
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
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.
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,
23 * The mainboard must define strings in the root scope to
24 * report device-specific battery information to the OS.
35 Name (_HID, EISAID ("PNP0C0A"))
37 Name (_PCL, Package () { \_SB })
39 Name (PBIF, Package () {
40 0x00000001, // Power Unit: mAh
41 0xFFFFFFFF, // Design Capacity
42 0xFFFFFFFF, // Last Full Charge Capacity
43 0x00000001, // Battery Technology: Rechargeable
44 0xFFFFFFFF, // Design Voltage
45 0x00000003, // Design Capacity of Warning
46 0xFFFFFFFF, // Design Capacity of Low
47 0x00000001, // Capacity Granularity 1
48 0x00000001, // Capacity Granularity 2
51 "LION", // Battery Type
55 Name (PBST, Package () {
56 0x00000000, // Battery State
57 0xFFFFFFFF, // Battery Present Rate
58 0xFFFFFFFF, // Battery Remaining Capacity
59 0xFFFFFFFF, // Battery Present Voltage
63 // Workaround for full battery status, enabled by default
66 // Method to enable full battery workaround
72 // Method to disable full battery workaround
78 // Swap bytes in a word
79 Method (SWAB, 1, NotSerialized)
81 ShiftRight (Arg0, 8, Local0)
82 ShiftLeft (Arg0, 8, Local1)
83 And (Local1, 0xFF00, Local1)
84 Or (Local0, Local1, Local0)
85 If (LEqual (Local0, 0xFFFF)) {
86 Store (0xFFFFFFFF, Local0)
91 Method (_STA, 0, Serialized)
100 Method (_BIF, 0, Serialized)
102 // Update fields from EC
103 Store (SWAB (BTDA), Index (PBIF, 1))
104 Store (SWAB (BTDF), Index (PBIF, 2))
105 Store (SWAB (BTDV), Index (PBIF, 4))
106 Store (SWAB (BTDL), Index (PBIF, 6))
108 // Get battery info from mainboard
109 Store (\BATM, Index (PBIF, 9))
110 Store (\BATS, Index (PBIF, 10))
111 Store (\BATV, Index (PBIF, 12))
116 Method (_BST, 0, Serialized)
121 // bit 0 = discharging
123 // bit 2 = critical level
126 // Get battery state from EC
130 // Check if AC is present
132 // Set only charging/discharging bits
133 And (Local0, 0x03, Local1)
135 // Always discharging when on battery power
139 // Flag if the battery level is critical
140 And (Local0, 0x04, Local4)
141 Or (Local1, Local4, Local1)
142 Store (Local1, Index (PBST, 0))
144 // Notify if battery state has changed since last time
145 If (LNotEqual (Local1, BSTP)) {
151 // 1: BATTERY PRESENT RATE
154 Store (SWAB (BTPR), Local1)
155 If (LAnd (LNotEqual (Local1, 0xFFFFFFFF),
156 LGreaterEqual (Local1, 0x8000))) {
157 Xor (Local1, 0xFFFF, Local1)
160 Store (Local1, Index (PBST, 1))
163 // 2: BATTERY REMAINING CAPACITY
165 Store (SWAB (BTRA), Local1)
166 If (LAnd (LNotEqual (Local1, 0xFFFFFFFF),
167 LGreaterEqual (Local1, 0x8000))) {
168 Xor (Local1, 0xFFFF, Local1)
172 If (LAnd (BFWK, LAnd (ACEX, LNot (Local0)))) {
173 // On AC power and battery is neither charging
174 // nor discharging. Linux expects a full battery
175 // to report same capacity as last full charge.
176 // https://bugzilla.kernel.org/show_bug.cgi?id=12632
177 Store (SWAB (BTDF), Local2)
179 // See if within ~3% of full
180 ShiftRight (Local2, 5, Local3)
181 If (LAnd (LGreater (Local1, Subtract (Local2, Local3)),
182 LLess (Local1, Add (Local2, Local3))))
184 Store (Local2, Local1)
187 Store (Local1, Index (PBST, 2))
190 // 3: BATTERY PRESENT VOLTAGE
192 Store (SWAB (BTVO), Index (PBST, 3))