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