1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
/*
* This file is part of the coreboot project.
*
* Copyright (C) 2013 Google Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
// Scope (EC0)
Device (BATX)
{
Name (_HID, EISAID ("PNP0C0A"))
Name (_UID, 1)
Name (_PCL, Package () { \_SB })
//
// Indicator of BATX attach/detach
// Battery X Information
// Battery X Status
//
Name (BXST, Zero)
//
// Default Static Battery Information
//
Name (PBIF, Package()
{
0, // 0: Power Unit
0xFFFFFFFF, // 1: Design Capacity
0xFFFFFFFF, // 2: Last Full Charge Capacity
1, // 3: Battery Technology(Rechargable)
10800, // 4: Design Voltage 10.8V
0, // 5: Design capacity of warning
0, // 6: Design capacity of low
1, // 7: Battery capacity granularity 1
1, // 8: Battery capacity granularity 2
"", // 9: Model Number
"", // 10: Serial Number
"", // 11: Battery Type
"" // 12: OEM Infomration
})
Name (PBST, Package ()
{
0x00000000, // Battery State
0xFFFFFFFF, // Battery Present Rate
0xFFFFFFFF, // Battery Remaining Capacity
0xFFFFFFFF, // Battery Present Voltage
})
// Workaround for full battery status, enabled by default
Name (BFWK, One)
// Method to enable full battery workaround
Method (BFWE)
{
Store (One, BFWK)
}
// Method to disable full battery workaround
Method (BFWD)
{
Store (Zero, BFWK)
}
// Method to wait for EC to be ready after changing the Battery Info ID
// Selector
Method (WAEC)
{
Store (20, Local0) // Timeout 100 msec
While (LEqual (HSID, Zero))
{
// EC Is not ready
Sleep (5)
Decrement (Local0)
If (LEqual (Local0, Zero))
{
Break
}
}
}
// Battery Slot Status
Method (_STA, 0, Serialized)
{
Store (MBTS, BXST)
If (BXST)
{
// Battery is present
Return (0x1F)
}
Else
{
Return (0x0F)
}
}
Method (_BIF, 0, Serialized)
{
// Update fields from EC
//
// Information ID 1 -
//
Store (One, HIID)
WAEC ()
//
// Power Unit
// SMART battery : 1 - 10mWh : 0 - mAh
// ACPI spec : 0 - mWh : 1 - mAh
//
Store(SBCM, Local7)
XOr (Local7, One, Index (PBIF, 0))
//
// Information ID 0 -
//
Store (Zero, HIID)
WAEC ()
//
// Last Full Charge Capacity
//
If (Local7)
{
Multiply (SBFC, 10, Index (PBIF, 2))
}
Else
{
Store (SBFC, Index (PBIF, 2))
}
//
// Information ID 2 -
//
Store (2, HIID)
WAEC ()
//
// Design capacity
//
If (Local7)
{
Multiply (SBDC, 10, Local0)
}
Else
{
Store (SBDC, Local0)
}
Store (Local0, Index(PBIF, One))
//
// Design capacity of High (5%)
// Design capacity of Low (1%)
//
Divide (Local0, 20, , Index (PBIF, 5))
Divide (Local0, 100, , Index (PBIF, 6))
//
// Design voltage
//
Store (SBDV, Index (PBIF, 4))
//
// Serial Number
//
Store (ToHexString (SBSN), Index (PBIF, 10))
//
// Information ID 4 -
//
Store (4, HIID)
WAEC ()
//
// Battery Type - Device Chemistry
//
Store (ToString (Concatenate(SBCH, 0x00)), Index (PBIF, 11))
//
// Information ID 5 -
//
Store (5, HIID)
WAEC ()
//
// OEM Information - Manufacturer Name
//
Store (ToString (Concatenate(SBMN, 0x00)), Index (PBIF, 12))
//
// Information ID 6 -
//
Store (6, HIID)
WAEC ()
//
// Model Number - Device Name
//
Store (ToString (Concatenate(SBDN, 0x00)), Index (PBIF, 9))
Return (PBIF)
}
Method (_BST, 0, Serialized)
{
// Update Battery First Used Date, if requested
If (BFUD)
{
// TODO: Handle First Used Date Request
//\BFUD()
}
//
// 0: BATTERY STATE
//
// bit 0 = discharging
// bit 1 = charging
// bit 2 = critical level
//
// Get battery state from EC
If (And (HB0S, 0x20))
{
Store (2, Local0)
}
Else
{
if (And (HB0S, 0x40))
{
Store (One, Local0)
}
Else
{
Store (Zero, Local0)
}
}
// Set critical flag if battery is empty
If (LEqual (And (HB0S, 0x0F), 0))
{
Or (Local0, 4, Local0)
}
Store (Zero, Local1)
// Check if AC is present
If (ACPW)
{
// Set only charging/discharging bits
And (Local0, 0x03, Local1)
}
Else
{
// Always discharging when on battery power
Store (One, Local1)
}
// Flag if the battery level is critical
And (Local0, 0x04, Local4)
Or (Local1, Local4, Local1)
Store (Local1, Index (PBST, 0))
//
// 1: BATTERY PRESENT RATE/CURRENT
//
Store (ECAC, Local1)
If (LGreaterEqual (Local1, 0x8000))
{
If (And (Local0, 1))
{
Subtract (0x10000, Local1, Local1)
}
Else
{
// Error
Store (Zero, Local1)
}
}
Else
{
If (LNot (AND (Local0, 2)))
{
// Battery is not charging
Store (Zero, Local1)
}
}
XOr (DerefOf (Index (PBIF, Zero)), One, Local6)
If (Local6)
{
Multiply (ECVO, Local1, Local1)
Divide (Local1, 1000, , Local1)
}
Store (Local1, Index (PBST, One))
//
// 2: BATTERY REMAINING CAPACITY
//
// Get Power unit from the battery static information
// SMART battery : 1 - 10mWh : 0 - mAh
// ACPI spec : 0 - mWh : 1 - mAh
If (Local6)
{
Multiply (ECRC, 10, Local1)
}
Else
{
Store (ECRC, Local1)
}
If (LAnd (BFWK, LAnd (ACPW, LNot (Local0))))
{
// On AC power and battery is neither charging
// nor discharging. Linux expects a full battery
// to report same capacity as last full charge.
// https://bugzilla.kernel.org/show_bug.cgi?id=12632
// TODO: Is SBRS the "battery gas gauge"?
Store (SBRS, Local2)
// See if within ~3% of full
ShiftRight (Local2, 5, Local3)
If (LAnd (LGreater (Local1, Subtract (Local2, Local3)),
LLess (Local1, Add (Local2, Local3))))
{
Store (Local2, Local1)
}
}
Store (Local1, Index (PBST, 2))
//
// 3: BATTERY PRESENT VOLTAGE
//
Store (ECVO, Index (PBST, 3))
Return (PBST)
}
}
|