tree: drop last paragraph of GPL copyright header
[coreboot.git] / src / ec / google / chromeec / acpi / battery.asl
blobf61e8822cb03ea8cc6625ac2ceae004b2423b7e7
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
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 (BAT0)
21         Name (_HID, EISAID ("PNP0C0A"))
22         Name (_UID, 1)
23         Name (_PCL, Package () { \_SB })
25         Name (PBIF, Package () {
26                 0x00000001,  // 0x00: Power Unit: mAh
27                 0xFFFFFFFF,  // 0x01: Design Capacity
28                 0xFFFFFFFF,  // 0x02: Last Full Charge Capacity
29                 0x00000001,  // 0x03: Battery Technology: Rechargeable
30                 0xFFFFFFFF,  // 0x04: Design Voltage
31                 0x00000003,  // 0x05: Design Capacity of Warning
32                 0xFFFFFFFF,  // 0x06: Design Capacity of Low
33                 0x00000001,  // 0x07: Capacity Granularity 1
34                 0x00000001,  // 0x08: Capacity Granularity 2
35                 "",          // 0x09: Model Number
36                 "",          // 0x0a: Serial Number
37                 "LION",      // 0x0b: Battery Type
38                 ""           // 0x0c: OEM Information
39         })
41         Name (PBIX, Package () {
42                 0x00000000,  // 0x00: Revision
43                 0x00000001,  // 0x01: Power Unit: mAh
44                 0xFFFFFFFF,  // 0x02: Design Capacity
45                 0xFFFFFFFF,  // 0x03: Last Full Charge Capacity
46                 0x00000001,  // 0x04: Battery Technology: Rechargeable
47                 0xFFFFFFFF,  // 0x05: Design Voltage
48                 0x00000003,  // 0x06: Design Capacity of Warning
49                 0xFFFFFFFF,  // 0x07: Design Capacity of Low
50                 0x00000000,  // 0x08: Cycle Count
51                 0x00018000,  // 0x09: Measurement Accuracy (98.3%?)
52                 0x000001F4,  // 0x0a: Max Sampling Time (500ms)
53                 0x0000000a,  // 0x0b: Min Sampling Time (10ms)
54                 0xFFFFFFFF,  // 0x0c: Max Averaging Interval
55                 0xFFFFFFFF,  // 0x0d: Min Averaging Interval
56                 0x00000001,  // 0x0e: Capacity Granularity 1
57                 0x00000001,  // 0x0f: Capacity Granularity 2
58                 "",          // 0x10 Model Number
59                 "",          // 0x11: Serial Number
60                 "LION",      // 0x12: Battery Type
61                 ""           // 0x13: OEM Information
62         })
64         Name (PBST, Package () {
65                 0x00000000,  // 0x00: Battery State
66                 0xFFFFFFFF,  // 0x01: Battery Present Rate
67                 0xFFFFFFFF,  // 0x02: Battery Remaining Capacity
68                 0xFFFFFFFF,  // 0x03: Battery Present Voltage
69         })
70         Name (BSTP, Zero)
72         // Workaround for full battery status, enabled by default
73         Name (BFWK, One)
75         // Method to enable full battery workaround
76         Method (BFWE)
77         {
78                 Store (One, BFWK)
79         }
81         // Method to disable full battery workaround
82         Method (BFWD)
83         {
84                 Store (Zero, BFWK)
85         }
87         Method (_STA, 0, Serialized)
88         {
89                 If (BTEX) {
90                         Return (0x1F)
91                 } Else {
92                         Return (0x0F)
93                 }
94         }
96         Method (_BIF, 0, Serialized)
97         {
98                 // Last Full Charge Capacity
99                 Store (BTDF, Index (PBIF, 2))
101                 // Design Voltage
102                 Store (BTDV, Index (PBIF, 4))
104                 // Design Capacity
105                 Store (BTDA, Local0)
106                 Store (Local0, Index (PBIF, 1))
108                 // Design Capacity of Warning
109                 Divide (Multiply (Local0, DWRN), 100, , Local2)
110                 Store (Local2, Index (PBIF, 5))
112                 // Design Capacity of Low
113                 Divide (Multiply (Local0, DLOW), 100, , Local2)
114                 Store (Local2, Index (PBIF, 6))
116                 // Get battery info from mainboard
117                 Store (ToString(BMOD), Index (PBIF, 9))
118                 Store (ToString(BSER), Index (PBIF, 10))
119                 Store (ToString(BMFG), Index (PBIF, 12))
121                 Return (PBIF)
122         }
124         Method (_BIX, 0, Serialized)
125         {
126                 // Last Full Charge Capacity
127                 Store (BTDF, Index (PBIX, 3))
129                 // Design Voltage
130                 Store (BTDV, Index (PBIX, 5))
132                 // Design Capacity
133                 Store (BTDA, Local0)
134                 Store (Local0, Index (PBIX, 2))
136                 // Design Capacity of Warning
137                 Divide (Multiply (Local0, DWRN), 100, , Local2)
138                 Store (Local2, Index (PBIX, 6))
140                 // Design Capacity of Low
141                 Divide (Multiply (Local0, DLOW), 100, , Local2)
142                 Store (Local2, Index (PBIX, 7))
144                 // Cycle Count
145                 Store (BTCC, Index (PBIX, 8))
147                 // Get battery info from mainboard
148                 Store (ToString(BMOD), Index (PBIX, 16))
149                 Store (ToString(BSER), Index (PBIX, 17))
150                 Store (ToString(BMFG), Index (PBIX, 19))
152                 Return (PBIX)
153         }
155         Method (_BST, 0, Serialized)
156         {
157                 //
158                 // 0: BATTERY STATE
159                 //
160                 // bit 0 = discharging
161                 // bit 1 = charging
162                 // bit 2 = critical level
163                 //
164                 Store (Zero, Local1)
166                 // Check if AC is present
167                 If (ACEX) {
168                         If (BFCG) {
169                                 Store (0x02, Local1)
170                         } ElseIf (BFDC) {
171                                 Store (0x01, Local1)
172                         }
173                 } Else {
174                         // Always discharging when on battery power
175                         Store (0x01, Local1)
176                 }
178                 // Check for critical battery level
179                 If (BFCR) {
180                         Or (Local1, 0x04, Local1)
181                 }
182                 Store (Local1, Index (PBST, 0))
184                 // Notify if battery state has changed since last time
185                 If (LNotEqual (Local1, BSTP)) {
186                         Store (Local1, BSTP)
187                         Notify (BAT0, 0x80)
188                 }
190                 //
191                 // 1: BATTERY PRESENT RATE
192                 //
193                 Store (BTPR, Index (PBST, 1))
195                 //
196                 // 2: BATTERY REMAINING CAPACITY
197                 //
198                 Store (BTRA, Local1)
199                 If (LAnd (BFWK, LAnd (ACEX, LNot (LAnd (BFDC, BFCG))))) {
200                         // On AC power and battery is neither charging
201                         // nor discharging.  Linux expects a full battery
202                         // to report same capacity as last full charge.
203                         // https://bugzilla.kernel.org/show_bug.cgi?id=12632
204                         Store (BTDF, Local2)
206                         // See if within ~6% of full
207                         ShiftRight (Local2, 4, Local3)
208                         If (LAnd (LGreater (Local1, Subtract (Local2, Local3)),
209                                   LLess (Local1, Add (Local2, Local3))))
210                         {
211                                 Store (Local2, Local1)
212                         }
213                 }
214                 Store (Local1, Index (PBST, 2))
216                 //
217                 // 3: BATTERY PRESENT VOLTAGE
218                 //
219                 Store (BTVO, Index (PBST, 3))
221                 Return (PBST)
222         }