1/* SPDX-License-Identifier: GPL-2.0-only */ 2 3Field(ERAM, ByteAcc, NoLock, Preserve) 4{ 5 Offset (0x38), 6 B0ST, 4, /* Battery 0 state */ 7 , 1, 8 B0CH, 1, /* Battery 0 charging */ 9 B0DI, 1, /* Battery 0 discharging */ 10 B0PR, 1, /* Battery 0 present */ 11 Offset (0x39), 12 B1ST, 4, /* Battery 1 state */ 13 , 1, 14 B1CH, 1, /* Battery 1 charging, */ 15 B1DI, 1, /* Battery 1 discharging,*/ 16 B1PR, 1 /* Battery 1 present */ 17} 18 19/* EC Registers */ 20/* PAGE == 0x00 */ 21Field (ERAM, ByteAcc, NoLock, Preserve) 22{ 23 Offset(0xa0), 24 BARC, 16, /* Battery remaining capacity */ 25 BAFC, 16, /* Battery full charge capacity */ 26 Offset(0xa8), 27 BAPR, 16, /* Battery present rate */ 28 BAVO, 16, /* Battery Voltage */ 29} 30 31/* PAGE == 0x01 */ 32Field (ERAM, ByteAcc, NoLock, Preserve) 33{ 34 Offset(0xa0), 35 , 15, 36 BAMA, 1, 37} 38 39/* PAGE == 0x02 */ 40Field (ERAM, ByteAcc, NoLock, Preserve) 41{ 42 Offset(0xa0), 43 BADC, 16, /* Design Capacity */ 44 BADV, 16, /* Design voltage */ 45 , 16, 46 , 16, 47 , 16, 48 BASN, 16, 49} 50 51/* PAGE == 0x04: Battery type */ 52Field (ERAM, ByteAcc, NoLock, Preserve) 53{ 54 Offset(0xa0), 55 BATY, 32 56} 57 58 59/* PAGE == 0x05: Battery OEM information */ 60Field (ERAM, ByteAcc, NoLock, Preserve) 61{ 62 Offset(0xa0), 63 BAOE, 128 64} 65 66/* PAGE == 0x06: Battery name */ 67Field (ERAM, ByteAcc, NoLock, Preserve) 68{ 69 Offset(0xa0), 70 BANA, 128 71} 72 73/* 74 * Switches the battery information page (16 bytes ERAM @0xa0) with an 75 * optional compile-time delay. 76 * 77 * Arg0: 78 * bit7-4: Battery number 79 * bit3-0: Information page number 80 */ 81Method(BPAG, 1, NotSerialized) 82{ 83 PAGE = Arg0 84#ifdef BATTERY_PAGE_DELAY_MS 85 Sleep(BATTERY_PAGE_DELAY_MS) 86#endif 87} 88 89/* Arg0: Battery 90 * Arg1: Battery Status Package 91 * Arg2: charging 92 * Arg3: discharging 93 */ 94Method(BSTA, 4, NotSerialized) 95{ 96 Acquire(ECLK, 0xffff) 97 Local0 = 0 98 ^BPAG(Arg0 | 1) 99 Local1 = BAMA 100 ^BPAG(Arg0) /* Battery dynamic information */ 101 102 /* 103 * Present rate is a 16bit signed int, positive while charging 104 * and negative while discharging. 105 */ 106 Local2 = BAPR 107 108 If (Arg2) // Charging 109 { 110 Local0 |= 2 111 } 112 Else 113 { 114 If (Arg3) // Discharging 115 { 116 Local0 |= 1 117 // Negate present rate 118 Local2 = 0x10000 - Local2 119 } 120 Else // Full battery, force to 0 121 { 122 Local2 = 0 123 } 124 } 125 126 /* 127 * The present rate value must be positive now, if it is not we have an 128 * EC bug or inconsistency and force the value to 0. 129 */ 130 If (Local2 >= 0x8000) { 131 Local2 = 0 132 } 133 134 Arg1 [0] = Local0 135 136 if (Local1) { 137 Arg1 [2] = BARC * 10 138 Local2 *= BAVO 139 Arg1 [1] = Local2 / 1000 140 } else { 141 Arg1 [2] = BARC 142 Arg1 [1] = Local2 143 } 144 Arg1 [3] = BAVO 145 Release(ECLK) 146 Return (Arg1) 147} 148 149Method(BINF, 2, Serialized) 150{ 151 Acquire(ECLK, 0xffff) 152 ^BPAG(1 | Arg1) /* Battery 0 static information */ 153 Arg0 [0] = BAMA ^ 1 154 Local0 = BAMA 155 ^BPAG(Arg1) 156 Local2 = BAFC 157 ^BPAG(Arg1 | 2) 158 Local1 = BADC 159 160 if (Local0) 161 { 162 Local1 *= 10 163 Local2 *= 10 164 } 165 166 Arg0 [1] = Local1 // Design Capacity 167 Arg0 [2] = Local2 // Last full charge capacity 168 Arg0 [4] = BADV // Design Voltage 169 Local0 = Local2 % 20 // FIXME: Local0 not used 170 Arg0 [5] = Local2 / 20 // Warning capacity 171 172 Local0 = BASN 173 Name (SERN, Buffer (0x06) { " " }) 174 Local1 = 4 175 While (Local0) 176 { 177 Local2 = Local0 % 10 178 Local0 /= 10 179 SERN [Local1] = Local2 + 48 180 Local1-- 181 } 182 Arg0 [10] = SERN // Serial Number 183 184 ^BPAG(4 | Arg1) 185 Name (TYPE, Buffer() { 0, 0, 0, 0, 0 }) 186 TYPE = BATY 187 Arg0 [11] = TYPE // Battery type 188 ^BPAG(Arg1 | 5) 189 Arg0 [12] = BAOE // OEM information 190 ^BPAG(Arg1 | 6) 191 Arg0 [9] = BANA // Model number 192 Release(ECLK) 193 Return (Arg0) 194} 195 196Device (BAT0) 197{ 198 Name (_HID, EisaId ("PNP0C0A")) 199 Name (_UID, 0x00) 200 Name (_PCL, Package () { \_SB }) 201 202 Name (BATS, Package () 203 { 204 0x00, // 0: PowerUnit: Report in mWh 205 0xFFFFFFFF, // 1: Design cap 206 0xFFFFFFFF, // 2: Last full charge cap 207 0x01, // 3: Battery Technology 208 10800, // 4: Design Voltage (mV) 209 0x00, // 5: Warning design capacity 210 200, // 6: Low design capacity 211 1, // 7: granularity1 212 1, // 8: granularity2 213 "", // 9: Model number 214 "", // A: Serial number 215 "", // B: Battery Type 216 "" // C: OEM information 217 }) 218 219 Method (_BIF, 0, NotSerialized) 220 { 221 Return (BINF(BATS, 0)) 222 } 223 224 Name (BATI, Package () 225 { 226 0, // Battery State 227 // Bit 0 - discharge 228 // Bit 1 - charge 229 // Bit 2 - critical state 230 0, // Battery present Rate 231 0, // Battery remaining capacity 232 0 // Battery present voltage 233 }) 234 235 Method (_BST, 0, NotSerialized) 236 { 237 if (B0PR) { 238 Return (BSTA(0, BATI, B0CH, B0DI)) 239 } else { 240 Return (Package () { 0, 0, 0, 0 }) 241 } 242 } 243 244 Method (_STA, 0, NotSerialized) 245 { 246 if (B0PR) { 247 Return (0x1f) 248 } else { 249 Return (0x0f) 250 } 251 } 252} 253 254Device (BAT1) 255{ 256 Name (_HID, EisaId ("PNP0C0A")) 257 Name (_UID, 0x00) 258 Name (_PCL, Package () { \_SB }) 259 260 Name (BATS, Package () 261 { 262 0x00, // 0: PowerUnit: Report in mWh 263 0xFFFFFFFF, // 1: Design cap 264 0xFFFFFFFF, // 2: Last full charge cap 265 0x01, // 3: Battery Technology 266 10800, // 4: Design Voltage (mV) 267 0x00, // 5: Warning design capacity 268 200, // 6: Low design capacity 269 1, // 7: granularity1 270 1, // 8: granularity2 271 "", // 9: Model number 272 "", // A: Serial number 273 "", // B: Battery Type 274 "" // C: OEM information 275 }) 276 277 Method (_BIF, 0, NotSerialized) 278 { 279 Return (BINF(BATS, 0x10)) 280 } 281 282 Name (BATI, Package () 283 { 284 0, // Battery State 285 // Bit 0 - discharge 286 // Bit 1 - charge 287 // Bit 2 - critical state 288 0, // Battery present Rate 289 0, // Battery remaining capacity 290 0 // Battery present voltage 291 }) 292 293 Method (_BST, 0, NotSerialized) 294 { 295 if (B1PR) { 296 Return (BSTA(0x10, BATI, B1CH, B1DI)) 297 } else { 298 Return (Package () { 0, 0, 0, 0 }) 299 } 300 } 301 302 Method (_STA, 0, NotSerialized) 303 { 304 if (B1PR) { 305 Return (0x1f) 306 } else { 307 Return (0x0f) 308 } 309 } 310} 311 312/* Battery 0 critical */ 313Method(_Q24, 0, NotSerialized) 314{ 315 Notify(BAT0, 0x80) 316} 317 318/* Battery 1 critical */ 319Method(_Q25, 0, NotSerialized) 320{ 321 Notify(BAT1, 0x80) 322} 323 324/* Battery 0 attach/detach */ 325Method(_Q4A, 0, NotSerialized) 326{ 327 Notify(BAT0, 0x81) 328} 329 330/* Battery 0 state change */ 331Method(_Q4B, 0, NotSerialized) 332{ 333 Notify(BAT0, 0x80) 334} 335 336/* Battery 1 attach/detach */ 337Method(_Q4C, 0, NotSerialized) 338{ 339 Notify(BAT1, 0x81) 340} 341 342/* Battery 1 state change */ 343Method(_Q4D, 0, NotSerialized) 344{ 345 Notify(BAT1, 0x80) 346} 347