ec/quanta/it8518/acpi: Replace Multiply(a,b,c) with ASL 2.0 syntax
[coreboot.git] / src / ec / quanta / it8518 / acpi / battery.asl
blob316a3421e762a3aa6a1c2c5f31eb636cc0c203f6
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 // Scope (EC0)
5 Device (BATX)
7         Name (_HID, EISAID ("PNP0C0A"))
8         Name (_UID, 1)
9         Name (_PCL, Package () { \_SB })
11         //
12         // Indicator of BATX attach/detach
13         // Battery X Information
14         // Battery X Status
15         //
16         Name (BXST, Zero)
18         //
19         // Default Static Battery Information
20         //
21         Name (PBIF, Package()
22         {
23                 0,            //  0: Power Unit
24                 0xFFFFFFFF,   //  1: Design Capacity
25                 0xFFFFFFFF,   //  2: Last Full Charge Capacity
26                 1,            //  3: Battery Technology(Rechargeable)
27                 10800,        //  4: Design Voltage 10.8V
28                 0,            //  5: Design capacity of warning
29                 0,            //  6: Design capacity of low
30                 1,            //  7: Battery capacity granularity 1
31                 1,            //  8: Battery capacity granularity 2
32                 "",           //  9: Model Number
33                 "",           // 10: Serial Number
34                 "",           // 11: Battery Type
35                 ""            // 12: OEM Infomration
36         })
38         Name (PBST, Package ()
39         {
40                 0x00000000,  // Battery State
41                 0xFFFFFFFF,  // Battery Present Rate
42                 0xFFFFFFFF,  // Battery Remaining Capacity
43                 0xFFFFFFFF,  // Battery Present Voltage
44         })
46         // Workaround for full battery status, enabled by default
47         Name (BFWK, One)
49         // Method to enable full battery workaround
50         Method (BFWE)
51         {
52                 Store (One, BFWK)
53         }
55         // Method to disable full battery workaround
56         Method (BFWD)
57         {
58                 Store (Zero, BFWK)
59         }
61         // Method to wait for EC to be ready after changing the Battery Info ID
62         // Selector
63         Method (WAEC)
64         {
65                 Store (20, Local0)      // Timeout 100 msec
66                 While (LEqual (HSID, Zero))
67                 {
68                         // EC Is not ready
69                         Sleep (5)
70                         Local0--
71                         If (LEqual (Local0, Zero))
72                         {
73                                 Break
74                         }
75                 }
76         }
78         // Battery Slot Status
79         Method (_STA, 0, Serialized)
80         {
81                 Store (MBTS, BXST)
82                 If (BXST)
83                 {
84                         // Battery is present
85                         Return (0x1F)
86                 }
87                 Else
88                 {
89                         Return (0x0F)
90                 }
91         }
93         Method (_BIF, 0, Serialized)
94         {
95                 // Update fields from EC
97                 //
98                 // Information ID 1 -
99                 //
100                 Store (One, HIID)
101                 WAEC ()
103                 //
104                 //  Power Unit
105                 //   SMART battery : 1 - 10mWh : 0 - mAh
106                 //   ACPI spec     : 0 - mWh   : 1 - mAh
107                 //
108                 Store(SBCM, Local7)
109                 XOr (Local7, One, PBIF[0])
111                 //
112                 // Information ID 0 -
113                 //
114                 Store (Zero, HIID)
115                 WAEC ()
117                 //
118                 //  Last Full Charge Capacity
119                 //
120                 If (Local7)
121                 {
122                         PBIF[2] = SBFC * 10
123                 }
124                 Else
125                 {
126                         Store (SBFC, PBIF[2])
127                 }
129                 //
130                 // Information ID 2 -
131                 //
132                 Store (2, HIID)
133                 WAEC ()
135                 //
136                 //  Design capacity
137                 //
138                 If (Local7)
139                 {
140                         Local0 = SBDC * 10
141                 }
142                 Else
143                 {
144                         Store (SBDC, Local0)
145                 }
146                 Store (Local0, PBIF[1])
148                 //
149                 //  Design capacity of High (5%)
150                 //  Design capacity of Low (1%)
151                 //
152                 Divide (Local0,  20, , PBIF[5])
153                 Divide (Local0, 100, , PBIF[6])
155                 //
156                 //  Design voltage
157                 //
158                 Store (SBDV, PBIF[4])
160                 //
161                 // Serial Number
162                 //
163                 Store (ToHexString (SBSN), PBIF[10])
165                 //
166                 // Information ID 4 -
167                 //
168                 Store (4, HIID)
169                 WAEC ()
171                 //
172                 //  Battery Type - Device Chemistry
173                 //
174                 Store (ToString (Concatenate(SBCH, 0x00)), PBIF[11])
176                 //
177                 // Information ID 5 -
178                 //
179                 Store (5, HIID)
180                 WAEC ()
182                 //
183                 // OEM Information - Manufacturer Name
184                 //
185                 Store (ToString (Concatenate(SBMN, 0x00)), PBIF[12])
187                 //
188                 // Information ID 6 -
189                 //
190                 Store (6, HIID)
191                 WAEC ()
193                 //
194                 // Model Number - Device Name
195                 //
196                 Store (ToString (Concatenate(SBDN, 0x00)), PBIF[9])
198                 Return (PBIF)
199         }
201         Method (_BST, 0, Serialized)
202         {
203                 // Update Battery First Used Date, if requested
204                 If (BFUD)
205                 {
206                         // TODO: Handle First Used Date Request
207                         //\BFUD()
208                 }
210                 //
211                 // 0: BATTERY STATE
212                 //
213                 // bit 0 = discharging
214                 // bit 1 = charging
215                 // bit 2 = critical level
216                 //
218                 // Get battery state from EC
219                 If (And (HB0S, 0x20))
220                 {
221                         Store (2, Local0)
222                 }
223                 Else
224                 {
225                         if (And (HB0S, 0x40))
226                         {
227                                 Store (One, Local0)
228                         }
229                         Else
230                         {
231                                 Store (Zero, Local0)
232                         }
233                 }
235                 // Set critical flag if battery is empty
236                 If (LEqual (And (HB0S, 0x0F), 0))
237                 {
238                         Or (Local0, 4, Local0)
239                 }
241                 Store (Zero, Local1)
243                 // Check if AC is present
244                 If (ACPW)
245                 {
246                         // Set only charging/discharging bits
247                         And (Local0, 0x03, Local1)
248                 }
249                 Else
250                 {
251                         // Always discharging when on battery power
252                         Store (One, Local1)
253                 }
255                 // Flag if the battery level is critical
256                 And (Local0, 0x04, Local4)
257                 Or (Local1, Local4, Local1)
258                 Store (Local1, PBST[0])
260                 //
261                 // 1: BATTERY PRESENT RATE/CURRENT
262                 //
263                 Store (ECAC, Local1)
264                 If (LGreaterEqual (Local1, 0x8000))
265                 {
266                         If (And (Local0, 1))
267                         {
268                                 Local1 = 0x10000 - Local1
269                         }
270                         Else
271                         {
272                                 // Error
273                                 Store (Zero, Local1)
274                         }
275                 }
276                 Else
277                 {
278                         If (!(AND (Local0, 2)))
279                         {
280                                 // Battery is not charging
281                                 Store (Zero, Local1)
282                         }
283                 }
285                 XOr (DerefOf (PBIF[0]), One, Local6)
287                 If (Local6)
288                 {
289                         Local1 *= ECVO
290                         Divide (Local1, 1000, , Local1)
291                 }
292                 Store (Local1, PBST[1])
294                 //
295                 // 2: BATTERY REMAINING CAPACITY
296                 //
297                 // Get Power unit from the battery static information
298                 //   SMART battery : 1 - 10mWh : 0 - mAh
299                 //   ACPI spec     : 0 - mWh   : 1 - mAh
300                 If (Local6)
301                 {
302                         Local1 = ECRC * 10
303                 }
304                 Else
305                 {
306                         Store (ECRC, Local1)
307                 }
309                 If (BFWK && ACPW && !Local0)
310                 {
311                         // On AC power and battery is neither charging
312                         // nor discharging.  Linux expects a full battery
313                         // to report same capacity as last full charge.
314                         // https://bugzilla.kernel.org/show_bug.cgi?id=12632
315                         // TODO: Is SBRS the "battery gas gauge"?
316                         Store (SBRS, Local2)
318                         // See if within ~3% of full
319                         ShiftRight (Local2, 5, Local3)
320                         If (LGreater (Local1, Local2 - Local3) && LLess (Local1, Local2 + Local3))
321                         {
322                                 Store (Local2, Local1)
323                         }
324                 }
325                 Store (Local1, PBST[2])
327                 //
328                 // 3: BATTERY PRESENT VOLTAGE
329                 //
330                 Store (ECVO, PBST[3])
332                 Return (PBST)
333         }