| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
|
| 3 |
/* |
| 4 |
* The mainboard must define strings in the root scope to |
| 5 |
* report device-specific battery information to the OS. |
| 6 |
* |
| 7 |
* BATV: Vendor |
| 8 |
*/ |
| 9 |
|
| 10 |
// Scope (EC0) |
| 11 |
|
| 12 |
Device (BATX) |
| 13 |
{ |
| 14 |
Name (_HID, EISAID ("PNP0C0A")) |
| 15 |
Name (_UID, 1) |
| 16 |
Name (_PCL, Package () { \_SB }) |
| 17 |
|
| 18 |
Name (PBIF, Package () { |
| 19 |
0x00000001, // 0 Power Unit: mAh |
| 20 |
0xFFFFFFFF, // 1 Design Capacity |
| 21 |
0xFFFFFFFF, // 2 Last Full Charge Capacity |
| 22 |
0x00000001, // 3 Battery Technology: Rechargeable |
| 23 |
0xFFFFFFFF, // 4 Design Voltage |
| 24 |
0x000000FA, // 5 Design Capacity of Warning |
| 25 |
0x00000096, // 6 Design Capacity of Low |
| 26 |
0x0000000A, // 7 Capacity Granularity 1 |
| 27 |
0x00000019, // 8 Capacity Granularity 2 |
| 28 |
"", // 9 Model Number |
| 29 |
"", // 10 Serial Number |
| 30 |
"", // 11 Battery Type |
| 31 |
"" // 12 OEM Information |
| 32 |
}) |
| 33 |
|
| 34 |
Name (PBST, Package () { |
| 35 |
0x00000000, // Battery State |
| 36 |
0xFFFFFFFF, // Battery Present Rate |
| 37 |
0xFFFFFFFF, // Battery Remaining Capacity |
| 38 |
0xFFFFFFFF, // Battery Present Voltage |
| 39 |
}) |
| 40 |
|
| 41 |
// Workaround for full battery status, enabled by default |
| 42 |
Name (BFWK, 1) |
| 43 |
|
| 44 |
// Method to enable full battery workaround |
| 45 |
Method (BFWE) |
| 46 |
{ |
| 47 |
BFWK = 1 |
| 48 |
} |
| 49 |
|
| 50 |
// Method to disable full battery workaround |
| 51 |
Method (BFWD) |
| 52 |
{ |
| 53 |
BFWK = 0 |
| 54 |
} |
| 55 |
|
| 56 |
// Device insertion/removal control method that returns a device's status. |
| 57 |
// Power resource object that evaluates to the current on or off state of |
| 58 |
// the Power Resource. |
| 59 |
Method (_STA, 0, Serialized) |
| 60 |
{ |
| 61 |
If (BTIN) { |
| 62 |
Return (0x1F) |
| 63 |
} Else { |
| 64 |
Return (0x0F) |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
Method (_BIF, 0, Serialized) |
| 69 |
{ |
| 70 |
// Update fields from EC |
| 71 |
PBIF [1] = BDC0 // Batt Design Capacity |
| 72 |
PBIF [2] = BFC0 // Batt Last Full Charge Capacity |
| 73 |
PBIF [4] = BDV0 // Batt Design Voltage |
| 74 |
Local1 = BFC0 / 100 |
| 75 |
Local0 = Local1 * 10 |
| 76 |
PBIF [5] = Local0 |
| 77 |
Local0 = Local1 * 5 |
| 78 |
PBIF [6] = Local0 |
| 79 |
PBIF [9] = ToString(Concatenate(BATD, 0x00)) // Model Number |
| 80 |
PBIF [10] = ToDecimalString(BSN0) // Serial Number |
| 81 |
PBIF [11] = ToString(Concatenate(BCHM, 0x00)) // Battery Type |
| 82 |
PBIF [12] = \BATV // OEM information |
| 83 |
|
| 84 |
Return (PBIF) |
| 85 |
} |
| 86 |
|
| 87 |
Method (_BST, 0, Serialized) |
| 88 |
{ |
| 89 |
// |
| 90 |
// 0: BATTERY STATE |
| 91 |
// |
| 92 |
// bit 0 = discharging |
| 93 |
// bit 1 = charging |
| 94 |
// bit 2 = critical level |
| 95 |
// |
| 96 |
|
| 97 |
// Get battery state from EC |
| 98 |
Local0 = BST0 |
| 99 |
PBST [0] = Local0 |
| 100 |
|
| 101 |
// |
| 102 |
// 1: BATTERY PRESENT RATE/CURRENT |
| 103 |
// |
| 104 |
Local1 = BPC0 |
| 105 |
If (Local1 && 0x8000) { |
| 106 |
Local1 ^= 0xffff |
| 107 |
Local1++ |
| 108 |
} |
| 109 |
PBST [1] = Local1 |
| 110 |
|
| 111 |
// |
| 112 |
// 2: BATTERY REMAINING CAPACITY |
| 113 |
// |
| 114 |
Local1 = BRC0 |
| 115 |
|
| 116 |
If (BFWK && ADPT && !Local0) { |
| 117 |
// On AC power and battery is neither charging |
| 118 |
// nor discharging. Linux expects a full battery |
| 119 |
// to report same capacity as last full charge. |
| 120 |
// https://bugzilla.kernel.org/show_bug.cgi?id=12632 |
| 121 |
Local2 = BFC0 |
| 122 |
|
| 123 |
// See if within ~3% of full |
| 124 |
Local3 = Local2 >> 5 |
| 125 |
If (Local1 > (Local2 - Local3) && Local1 < (Local2 + Local3)) |
| 126 |
{ |
| 127 |
Local1 = Local2 |
| 128 |
} |
| 129 |
} |
| 130 |
PBST [2] = Local1 |
| 131 |
|
| 132 |
// |
| 133 |
// 3: BATTERY PRESENT VOLTAGE |
| 134 |
// |
| 135 |
PBST [3] = BPV0 |
| 136 |
|
| 137 |
Return (PBST) |
| 138 |
} |
| 139 |
} |