blob: 2ead4c8b817598b43c2d6e1a0f88266c21b264a2 [file] [log] [blame]
Angel Pons210a0082020-04-02 23:48:24 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Laurie4af38d42018-10-15 15:10:21 -07002
3Mutex (BATM, 0)
4
5Method (ESTA, 1, Serialized)
6{
7 /* Check battery presence */
8 If (Arg0 == 1) {
9 Local0 = R (BTEX)
10 } ElseIf (Arg0 == 2) {
11 Local0 = R (P3B2)
12 } Else {
Felix Singer42efd7f2022-12-26 09:38:45 +010013 Local0 = 0
Duncan Laurie4af38d42018-10-15 15:10:21 -070014 }
15
16 /* Indicate battery is present */
17 If (Local0) {
18 Return (0x1f)
19 } Else {
20 Return (0xf)
21 }
22}
23
24Name (BSTM, 0x01) /* Battery Model String */
25Name (BSTC, 0x02) /* Battery Chemistry String */
26Name (BSTG, 0x03) /* Battery Manufacturer String */
27
28/*
29 * Read a battery string from the EC
30 * Arg0 = Battery String ID
31 * BSTM = Model
32 * BSTC = Chemical
33 * BSTG = Manufacturer
34 */
35Method (BSTR, 1, Serialized)
36{
37 /* Max string length */
38 Local0 = 32
39
40 /* Select battery string */
41 W (SSEL, Arg0)
42
43 /* Fill buffer until NUL or max string length is read */
Felix Singerca4b5872022-12-26 08:17:06 +010044 Name (IBUF, Buffer (Local0 + 1) {})
Felix Singer42efd7f2022-12-26 09:38:45 +010045 For (Local1 = 0, Local1 < Local0, Local1++) {
Duncan Laurie4af38d42018-10-15 15:10:21 -070046 Local2 = R (BSBS)
47 If (!Local2) {
48 Break
49 }
50 IBUF[Local1] = Local2
51 }
52
53 /* Truncate and NUL terminate */
54 Local1++
55 Name (OBUF, Buffer (Local1) {})
Felix Singer42efd7f2022-12-26 09:38:45 +010056 OBUF = Concatenate (IBUF, 0)
Duncan Laurie4af38d42018-10-15 15:10:21 -070057
58 Return (OBUF)
59}
60
61/*
62 * Handle Battery Status
63 * Arg0 = Battery Number
64 * Arg1 = _BST package
65 */
66Method (EBST, 2, Serialized)
67{
68 If (Acquire (BATM, 1000)) {
69 Return (Arg1)
70 }
71
72 /* Select battery */
73 W (BSEL, Arg0)
74
75 /* 0: Battery State */
76 Arg1[0] = R (BCST)
77
78 /* 1: Battery Present Rate */
79 Local0 = R (BCCL)
80 If (!Local0) {
81 Local0++
82 } ElseIf (R (ACEX)) {
83 If (Local0 & 0x8000) {
84 Local0 = Ones
85 }
86 } Else {
87 If (Local0 & 0x8000) {
88 Local0 = 0 - Local0
89 Local0 &= 0xffff
90 } Else {
91 Local0 = Ones
92 }
93 }
94 Arg1[1] = Local0
95
96 /* 2: Battery Remaining Capacity */
97 Arg1[2] = R (BCYL)
98
99 /* 3: Battery Present Voltage */
100 Arg1[3] = R (BCVL)
101
102 Release (BATM)
103 Return (Arg1)
104}
105
106/*
107 * Handle Battery Info
108 * Arg0 = Battery Number
109 * Arg1 = _BIF package
110 */
111Method (EBIF, 2, Serialized)
112{
113 If (Acquire (BATM, 1000)) {
114 Return (Arg1)
115 }
116
117 /* Select battery */
118 W (BSEL, Arg0)
119
120 /* Design Capacity */
121 Local0 = R (BSCL)
122 Arg1[1] = Local0
123
124 /* Last Full Charge Capacity */
125 Arg1[2] = R (BSFL)
126
127 /* Design Voltage */
128 Arg1[4] = R (BSVL)
129
130 /* Design Warning Capacity */
131 Arg1[5] = (Local0 * 10) / 100
132
133 /* Design Low Capacity */
134 Arg1[6] = (Local0 * 33) / 100
135
136 /* Granularity */
137 Arg1[7] = Local0 / 100
138 Arg1[8] = Local0 / 100
139
140 /* Battery Model Number */
141 Arg1[9] = BSTR (BSTM)
142
143 /* Battery Serial Number */
144 Arg1[10] = ToDecimalString (R (BSSL))
145
146 /* Battery Type */
147 Arg1[11] = BSTR (BSTC)
148
149 /* Battery Manufacturer Name */
150 Arg1[12] = BSTR (BSTG)
151
152 Release (BATM)
153 Return (Arg1)
154}
155
156/*
157 * Handle Battery Info Extended
158 * Arg0 = Battery Number
159 * Arg1 = _BIX package
160 */
161Method (EBIX, 2, Serialized)
162{
163 If (Acquire (BATM, 1000)) {
164 Return (Arg1)
165 }
166
167 /* Select battery */
168 W (BSEL, Arg0)
169
170 /* Design Capacity */
171 Local0 = R (BSCL)
172 Arg1[2] = Local0
173
174 /* Last Full Charge Capacity */
175 Arg1[3] = R (BSFL)
176
177 /* Design Voltage */
178 Arg1[5] = R (BSVL)
179
180 /* Design Warning Capacity */
181 Arg1[6] = (Local0 * 10) / 100
182
183 /* Design Low Capacity */
184 Arg1[7] = (Local0 * 33) / 100
185
186 /* Cycle Count */
187 Arg1[8] = R (BCCY)
188
189 /* Granularity */
190 Arg1[14] = Local0 / 100
191 Arg1[15] = Local0 / 100
192
193 /* Battery Model Number */
194 Arg1[16] = BSTR (BSTM)
195
196 /* Battery Serial Number */
197 Arg1[17] = ToDecimalString (R (BSSL))
198
199 /* Battery Type */
200 Arg1[18] = BSTR (BSTC)
201
202 /* Battery Manufacturer Name */
203 Arg1[19] = BSTR (BSTG)
204
205 Release (BATM)
206 Return (Arg1)
207}
208
209Device (BAT0)
210{
211 Name (_HID, EisaId ("PNP0C0A"))
212 Name (_UID, 1)
213 Name (_PCL, Package () { \_SB })
214
215 Name (PBIF, Package () {
216 0x00000001, /* 0x00: Power Unit: mAh */
217 0xFFFFFFFF, /* 0x01: Design Capacity */
218 0xFFFFFFFF, /* 0x02: Last Full Charge Capacity */
219 0x00000001, /* 0x03: Battery Technology: Rechargeable */
220 0xFFFFFFFF, /* 0x04: Design Voltage */
221 0x00000003, /* 0x05: Design Capacity of Warning */
222 0xFFFFFFFF, /* 0x06: Design Capacity of Low */
223 0x00000001, /* 0x07: Capacity Granularity 1 */
224 0x00000001, /* 0x08: Capacity Granularity 2 */
225 "", /* 0x09: Model Number */
226 "", /* 0x0a: Serial Number */
227 "LION", /* 0x0b: Battery Type */
228 "" /* 0x0c: OEM Information */
229 })
230
231 Name (PBIX, Package () {
232 0x00000000, /* 0x00: Revision */
233 0x00000001, /* 0x01: Power Unit: mAh */
234 0xFFFFFFFF, /* 0x02: Design Capacity */
235 0xFFFFFFFF, /* 0x03: Last Full Charge Capacity */
236 0x00000001, /* 0x04: Battery Technology: Rechargeable */
237 0xFFFFFFFF, /* 0x05: Design Voltage */
238 0x00000003, /* 0x06: Design Capacity of Warning */
239 0xFFFFFFFF, /* 0x07: Design Capacity of Low */
240 0x00000000, /* 0x08: Cycle Count */
241 0x00018000, /* 0x09: Measurement Accuracy (98.3%?) */
242 0x000001F4, /* 0x0a: Max Sampling Time (500ms) */
243 0x0000000a, /* 0x0b: Min Sampling Time (10ms) */
244 0xFFFFFFFF, /* 0x0c: Max Averaging Interval */
245 0xFFFFFFFF, /* 0x0d: Min Averaging Interval */
246 0x00000001, /* 0x0e: Capacity Granularity 1 */
247 0x00000001, /* 0x0f: Capacity Granularity 2 */
248 "", /* 0x10 Model Number */
249 "", /* 0x11: Serial Number */
250 "LION", /* 0x12: Battery Type */
251 "" /* 0x13: OEM Information */
252 })
253
254 Name (PBST, Package () {
255 0x00000000, /* 0x00: Battery State */
256 0xFFFFFFFF, /* 0x01: Battery Present Rate */
257 0xFFFFFFFF, /* 0x02: Battery Remaining Capacity */
258 0xFFFFFFFF, /* 0x03: Battery Present Voltage */
259 })
260
261 Method (_STA, 0, Serialized)
262 {
Duncan Laurie0f57a2b2019-03-27 19:26:12 -0700263 Return (ESTA (^_UID))
Duncan Laurie4af38d42018-10-15 15:10:21 -0700264 }
265
266 Method (_BST, 0, Serialized)
267 {
Duncan Laurie0f57a2b2019-03-27 19:26:12 -0700268 Return (EBST (^_UID, PBST))
Duncan Laurie4af38d42018-10-15 15:10:21 -0700269 }
270
271 Method (_BIF, 0, Serialized)
272 {
Duncan Laurie0f57a2b2019-03-27 19:26:12 -0700273 Return (EBIF (^_UID, PBIF))
274 }
275
276 Method (_BIX, 0, Serialized)
277 {
278 Return (EBIX (^_UID, PBIX))
Duncan Laurie4af38d42018-10-15 15:10:21 -0700279 }
280}
281
282Device (BAT1)
283{
284 Name (_HID, EisaId ("PNP0C0A"))
285 Name (_UID, 2)
286 Name (_PCL, Package () { \_SB })
287
288 Name (PBIF, Package () {
289 0x00000001, /* 0x00: Power Unit: mAh */
290 0xFFFFFFFF, /* 0x01: Design Capacity */
291 0xFFFFFFFF, /* 0x02: Last Full Charge Capacity */
292 0x00000001, /* 0x03: Battery Technology: Rechargeable */
293 0xFFFFFFFF, /* 0x04: Design Voltage */
294 0x00000003, /* 0x05: Design Capacity of Warning */
295 0xFFFFFFFF, /* 0x06: Design Capacity of Low */
296 0x00000001, /* 0x07: Capacity Granularity 1 */
297 0x00000001, /* 0x08: Capacity Granularity 2 */
298 "", /* 0x09: Model Number */
299 "", /* 0x0a: Serial Number */
300 "LION", /* 0x0b: Battery Type */
301 "" /* 0x0c: OEM Information */
302 })
303
304 Name (PBIX, Package () {
305 0x00000000, /* 0x00: Revision */
306 0x00000001, /* 0x01: Power Unit: mAh */
307 0xFFFFFFFF, /* 0x02: Design Capacity */
308 0xFFFFFFFF, /* 0x03: Last Full Charge Capacity */
309 0x00000001, /* 0x04: Battery Technology: Rechargeable */
310 0xFFFFFFFF, /* 0x05: Design Voltage */
311 0x00000003, /* 0x06: Design Capacity of Warning */
312 0xFFFFFFFF, /* 0x07: Design Capacity of Low */
313 0x00000000, /* 0x08: Cycle Count */
314 0x00018000, /* 0x09: Measurement Accuracy (98.3%?) */
315 0x000001F4, /* 0x0a: Max Sampling Time (500ms) */
316 0x0000000a, /* 0x0b: Min Sampling Time (10ms) */
317 0xFFFFFFFF, /* 0x0c: Max Averaging Interval */
318 0xFFFFFFFF, /* 0x0d: Min Averaging Interval */
319 0x00000001, /* 0x0e: Capacity Granularity 1 */
320 0x00000001, /* 0x0f: Capacity Granularity 2 */
321 "", /* 0x10 Model Number */
322 "", /* 0x11: Serial Number */
323 "LION", /* 0x12: Battery Type */
324 "" /* 0x13: OEM Information */
325 })
326
327 Name (PBST, Package () {
328 0x00000000, /* 0x00: Battery State */
329 0xFFFFFFFF, /* 0x01: Battery Present Rate */
330 0xFFFFFFFF, /* 0x02: Battery Remaining Capacity */
331 0xFFFFFFFF, /* 0x03: Battery Present Voltage */
332 })
333
334 Method (_STA, 0, Serialized)
335 {
336 Return (ESTA (^_UID))
337 }
338
339 Method (_BST, 0, Serialized)
340 {
341 Return (EBST (^_UID, PBST))
342 }
343
344 Method (_BIF, 0, Serialized)
345 {
346 Return (EBIF (^_UID, PBIF))
347 }
Duncan Laurie0f57a2b2019-03-27 19:26:12 -0700348
349 Method (_BIX, 0, Serialized)
350 {
351 Return (EBIX (^_UID, PBIX))
352 }
Duncan Laurie4af38d42018-10-15 15:10:21 -0700353}