blob: 557116005557c5090c3b346ef542ad0d991ce798 [file] [log] [blame]
Angel Pons210a0082020-04-02 23:48:24 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer020b22a2012-03-30 17:06:43 -07002
3/*
4 * The mainboard must define strings in the root scope to
5 * report device-specific battery information to the OS.
6 *
7 * BATM: Model
8 * BATS: Serial
9 * BATV: Vendor
10 */
11
12// Scope (EC0)
13
14Device (BAT0)
15{
16 Name (_HID, EISAID ("PNP0C0A"))
17 Name (_UID, 1)
18 Name (_PCL, Package () { \_SB })
19
20 Name (PBIF, Package () {
21 0x00000001, // Power Unit: mAh
22 0xFFFFFFFF, // Design Capacity
23 0xFFFFFFFF, // Last Full Charge Capacity
24 0x00000001, // Battery Technology: Rechargeable
25 0xFFFFFFFF, // Design Voltage
26 0x00000003, // Design Capacity of Warning
27 0xFFFFFFFF, // Design Capacity of Low
28 0x00000001, // Capacity Granularity 1
29 0x00000001, // Capacity Granularity 2
30 "", // Model Number
31 "", // Serial Number
32 "LION", // Battery Type
33 "" // OEM Information
34 })
35
36 Name (PBST, Package () {
37 0x00000000, // Battery State
38 0xFFFFFFFF, // Battery Present Rate
39 0xFFFFFFFF, // Battery Remaining Capacity
40 0xFFFFFFFF, // Battery Present Voltage
41 })
42 Name (BSTP, Zero)
43
44 // Workaround for full battery status, enabled by default
Felix Singerca4b5872022-12-26 08:17:06 +010045 Name (BFWK, 1)
Stefan Reinauer020b22a2012-03-30 17:06:43 -070046
47 // Method to enable full battery workaround
48 Method (BFWE)
49 {
Felix Singerca4b5872022-12-26 08:17:06 +010050 BFWK = 1
Stefan Reinauer020b22a2012-03-30 17:06:43 -070051 }
52
53 // Method to disable full battery workaround
54 Method (BFWD)
55 {
Felix Singer4da79a72022-12-12 04:57:27 +010056 BFWK = Zero
Stefan Reinauer020b22a2012-03-30 17:06:43 -070057 }
58
59 // Swap bytes in a word
60 Method (SWAB, 1, NotSerialized)
61 {
Felix Singer034920c2022-12-16 02:25:30 +010062 Local0 = Arg0 >> 8
Felix Singer3c9291b2022-12-16 02:43:56 +010063 Local1 = Arg0 << 8
Felix Singer35e65a82022-12-16 07:11:17 +010064 Local1 &= 0xFF00
Felix Singer86bc2e72022-12-16 04:40:39 +010065 Local0 |= Local1
Felix Singer7bf014f2022-01-02 01:26:43 +010066 If (Local0 == 0xFFFF) {
Felix Singer4da79a72022-12-12 04:57:27 +010067 Local0 = 0xFFFFFFFF
Stefan Reinauer020b22a2012-03-30 17:06:43 -070068 }
69 Return (Local0)
70 }
71
72 Method (_STA, 0, Serialized)
73 {
74 If (BTEX) {
75 Return (0x1F)
76 } Else {
77 Return (0x0F)
78 }
79 }
80
81 Method (_BIF, 0, Serialized)
82 {
83 // Update fields from EC
Felix Singer4da79a72022-12-12 04:57:27 +010084 PBIF[1] = SWAB (BTDA)
85 PBIF[2] = SWAB (BTDF)
86 PBIF[4] = SWAB (BTDV)
87 PBIF[6] = SWAB (BTDL)
Stefan Reinauer020b22a2012-03-30 17:06:43 -070088
89 // Get battery info from mainboard
Felix Singer4da79a72022-12-12 04:57:27 +010090 PBIF[9] = \BATM
91 PBIF[10] = \BATS
92 PBIF[12] = \BATV
Stefan Reinauer020b22a2012-03-30 17:06:43 -070093
94 Return (PBIF)
95 }
96
97 Method (_BST, 0, Serialized)
98 {
99 //
100 // 0: BATTERY STATE
101 //
102 // bit 0 = discharging
103 // bit 1 = charging
104 // bit 2 = critical level
105 //
106
107 // Get battery state from EC
Felix Singer4da79a72022-12-12 04:57:27 +0100108 Local0 = BTST
109 Local1 = Zero
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700110
111 // Check if AC is present
112 If (ACEX) {
113 // Set only charging/discharging bits
Felix Singer35e65a82022-12-16 07:11:17 +0100114 Local1 = Local0 & 3
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700115 } Else {
116 // Always discharging when on battery power
Felix Singer4da79a72022-12-12 04:57:27 +0100117 Local1 = 0x01
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700118 }
119
120 // Flag if the battery level is critical
Felix Singer35e65a82022-12-16 07:11:17 +0100121 Local4 = Local0 & 4
Felix Singer86bc2e72022-12-16 04:40:39 +0100122 Local1 |= Local4
Felix Singer4da79a72022-12-12 04:57:27 +0100123 PBST[0] = Local1
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700124
125 // Notify if battery state has changed since last time
Felix Singer69294032022-01-02 02:51:20 +0100126 If (Local1 != BSTP) {
Felix Singer4da79a72022-12-12 04:57:27 +0100127 BSTP = Local1
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700128 Notify (BAT0, 0x80)
129 }
130
131 //
132 // 1: BATTERY PRESENT RATE
133 //
134
Felix Singer4da79a72022-12-12 04:57:27 +0100135 Local1 = SWAB (BTPR)
Felix Singer69294032022-01-02 02:51:20 +0100136 If (Local1 != 0xFFFFFFFF && Local1 >= 0x8000) {
Felix Singerf3649f02022-12-16 04:07:23 +0100137 Local1 ^= 0xFFFF
Felix Singer0e790c62021-12-31 13:57:14 +0100138 Local1++
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700139 }
Felix Singer4da79a72022-12-12 04:57:27 +0100140 PBST[1] = Local1
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700141
142 //
143 // 2: BATTERY REMAINING CAPACITY
144 //
Felix Singer4da79a72022-12-12 04:57:27 +0100145 Local1 = SWAB (BTRA)
Felix Singer69294032022-01-02 02:51:20 +0100146 If (Local1 != 0xFFFFFFFF && Local1 >= 0x8000) {
Felix Singerf3649f02022-12-16 04:07:23 +0100147 Local1 ^= 0xFFFF
Felix Singer0e790c62021-12-31 13:57:14 +0100148 Local1++
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700149 }
150
Felix Singere81d12e2021-12-31 14:36:45 +0100151 If (BFWK && ACEX && !Local0) {
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700152 // On AC power and battery is neither charging
153 // nor discharging. Linux expects a full battery
154 // to report same capacity as last full charge.
155 // https://bugzilla.kernel.org/show_bug.cgi?id=12632
Felix Singer4da79a72022-12-12 04:57:27 +0100156 Local2 = SWAB (BTDF)
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700157
158 // See if within ~3% of full
Felix Singer034920c2022-12-16 02:25:30 +0100159 Local3 = Local2 >> 5
Felix Singer9bfbbe82022-01-02 01:58:20 +0100160 If (Local1 > Local2 - Local3 && Local1 < Local2 + Local3)
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700161 {
Felix Singer4da79a72022-12-12 04:57:27 +0100162 Local1 = Local2
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700163 }
164 }
Felix Singer4da79a72022-12-12 04:57:27 +0100165 PBST[2] = Local1
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700166
167 //
168 // 3: BATTERY PRESENT VOLTAGE
169 //
Felix Singer4da79a72022-12-12 04:57:27 +0100170 PBST[3] = SWAB (BTVO)
Stefan Reinauer020b22a2012-03-30 17:06:43 -0700171
172 Return (PBST)
173 }
174}