77269ad14301cecc03e0485d5da2e940cf89921c
[coreboot.git] / src / mainboard / roda / rk886ex / acpi / battery.asl
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009 coresystems GmbH
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  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  */
21
22 Name(\CBA1, 0x60)
23 Name(\CBA2, 0x60)
24
25 Device (BAT1)
26 {
27         Name(_HID, EisaId("PNP0C0A"))
28         Name(_UID, 1)
29
30         Name(_PCL, Package(){ _SB })
31         Name(PSTA, 0x1f)
32         Name(PBIF, Package() {
33                 0x00,
34                 0x78,
35                 0x64,
36                 0x01,
37                 0x2b5c, // Capacity?
38                 0x05,
39                 0x03,
40                 0x01,
41                 0x01,
42                 "???",  // Name
43                 "???",  // Number
44                 "???",  // Type
45                 "???"   // Vendor
46         })
47         Name(PBST, Package() { 0x01, 0x16, 0x64, 0x2b5c })
48
49         /* Status */
50         Method(_STA, 0)
51         {
52                 If(\_SB.PCI0.LPCB.EC0.ECON) {
53                         If(\_SB.PCI0.LPCB.EC0.P62S) {
54                                 Return(0x0f)
55                         } Else {
56                                 Return(0x1f)
57                         }
58                 } Else {
59                         Return(0x0f)
60                 }
61         }
62
63         /* Battery Info */
64         Method(_BIF, 0)
65         {
66                 If(\_SB.PCI0.LPCB.EC0.ECON) {
67                         If(\_SB.PCI0.LPCB.EC0.P62S) {
68                                 IVBI()
69                                 IVBS()
70                         } Else {
71                                 UPBI()
72                         }
73                 }
74
75                 Return(PBIF)
76         }
77
78         /* Battery Status */
79         Method(_BST, 0)
80         {
81                 If(\_SB.PCI0.LPCB.EC0.ECON) {
82                         UPBS()
83                 }
84
85                 Return(PBST)
86         }
87
88         /* Update Battery Info */
89         Method(UPBI, 0)
90         {
91                 Store (0x78, Index(PBIF, 1))
92                 Store (0x64, Index(PBIF, 2))
93                 Store (0x2b5c, Index(PBIF, 4))
94                 Store ("Bat1", Index(PBIF, 9))
95                 Store ("001", Index(PBIF, 10))
96                 Store ("LION", Index(PBIF, 11))
97                 Store ("Panasonic", Index(PBIF, 12))
98         }
99
100         Method(UPBS, 0)
101         {
102                 Store(\_SB.PCI0.LPCB.EC0.QEVT, Local0)
103                 If (Not(Local0)) {
104                         Store(0, GP38)
105                         Sleep(0x64)
106                         Store(GP38, Local0)
107                         If (Not(Local0)) {
108                                 Store (RDW(0x0d), Local0)
109                                 If (LNotEqual(Local0, 0xeeee)) {
110                                         If (LLessEqual(Local0, 0x64)) {
111                                                 Store(Local0, CBA1)
112                                         }
113                                 }
114                         }
115                 }
116                 
117                 Store (CBA1, Local0)
118                 Store (Local0, Index(PBST, 2))
119                 Store (DerefOf(Index(PBIF, 4)), Index(PBST, 3))
120                 Store (0, Local1)
121
122                 If (PWRS) {
123                         If (LLess(Local0, 0x64)) {
124                                 Store (2, Local1)
125                         }
126                 } Else {
127                         If (LLessEqual(Local0, 0x5)) {
128                                 Store (4, Local1)
129                         } Else {
130                                 Store (1, Local1)
131                         }
132                 }
133                 
134                 Store (Local1, Index(PBST, 0))
135                 If (\_SB.PCI0.LPCB.EC0.P63S) {
136                         Store (0x16, Index(PBST, 1))
137                 } Else  {
138                         Store (0x0b, Index(PBST, 1))
139                 }
140         }
141
142         // Invalidate Battery Info
143         Method(IVBI, 0)
144         {
145                 Store (0xffffffff, Index(PBIF, 1))
146                 Store (0xffffffff, Index(PBIF, 2))
147                 Store (0xffffffff, Index(PBIF, 4))
148                 Store ("Bad", Index(PBIF, 9))
149                 Store ("Bad", Index(PBIF, 10))
150                 Store ("Bad", Index(PBIF, 11))
151                 Store ("Bad", Index(PBIF, 12))
152                 Store (1, PBIF)
153         }
154
155         Method(IVBS, 0)
156         {
157                 Store (0x0, Index(PBST, 0))
158                 Store (0xffffffff, Index(PBST, 1))
159                 Store (0xffffffff, Index(PBST, 2))
160                 Store (0xffffffff, Index(PBST, 3))
161         }
162 }
163
164
165 Device (BAT2)
166 {
167         Name(_HID, EisaId("PNP0C0A"))
168         Name(_UID, 2)
169
170         Name(_PCL, Package(){ _SB })
171         Name(PSTA, 0x1f)
172         Name(PBIF, Package() {
173                 0x00,
174                 0x78,
175                 0x64,
176                 0x01,
177                 0x2b5c, // Capacity?
178                 0x05,
179                 0x03,
180                 0x01,
181                 0x01,
182                 "???",  // Name
183                 "???",  // Number
184                 "???",  // Type
185                 "???"   // Vendor
186         })
187         Name(PBST, Package() { 0x01, 0x16, 0x64, 0x2b5c })
188
189         /* Status */
190         Method(_STA, 0)
191         {
192                 If(\_SB.PCI0.LPCB.EC0.ECON) {
193                         If(\_SB.PCI0.LPCB.EC0.P63S) {
194                                 Return(0x0f)
195                         } Else {
196                                 Return(0x1f)
197                         }
198                 } Else {
199                         Return(0x0f)
200                 }
201         }
202
203         /* Battery Info */
204         Method(_BIF, 0)
205         {
206                 If(\_SB.PCI0.LPCB.EC0.ECON) {
207                         If(\_SB.PCI0.LPCB.EC0.P63S) {
208                                 IVBI()
209                                 IVBS()
210                         } Else {
211                                 UPBI()
212                         }
213                 }
214
215                 Return(PBIF)
216         }
217
218         /* Battery Status */
219         Method(_BST, 0)
220         {
221                 If(\_SB.PCI0.LPCB.EC0.ECON) {
222                         UPBS()
223                 }
224
225                 Return(PBST)
226         }
227
228         /* Update Battery Info */
229         Method(UPBI, 0)
230         {
231                 Store (0x78, Index(PBIF, 1))
232                 Store (0x64, Index(PBIF, 2))
233                 Store (0x2b5c, Index(PBIF, 4))
234                 Store ("Bat2", Index(PBIF, 9))
235                 Store ("002", Index(PBIF, 10))
236                 Store ("LION", Index(PBIF, 11))
237                 Store ("Panasonic", Index(PBIF, 12))
238         }
239
240         Method(UPBS, 0)
241         {
242                 Store(\_SB.PCI0.LPCB.EC0.QEVT, Local0)
243                 If (Not(Local0)) {
244                         Store(0, GP38)
245                         Sleep(0x64)
246                         Store(GP38, Local0)
247                         If (Not(Local0)) {
248                                 Store (RDW(0x0d), Local0)
249                                 If (LNotEqual(Local0, 0xeeee)) {
250                                         If (LLessEqual(Local0, 0x64)) {
251                                                 Store(Local0, CBA2)
252                                         }
253                                 }
254                         }
255                 }
256                 
257                 Store (CBA2, Local0)
258                 Store (Local0, Index(PBST, 2))
259                 Store (DerefOf(Index(PBIF, 4)), Index(PBST, 3))
260                 Store (0, Local1)
261
262                 If (PWRS) {
263                         If (LLess(Local0, 0x64)) {
264                                 Store (2, Local1)
265                         }
266                 } Else {
267                         If (LLessEqual(Local0, 0x5)) {
268                                 Store (4, Local1)
269                         } Else {
270                                 Store (1, Local1)
271                         }
272                 }
273                 
274                 Store (Local1, Index(PBST, 0))
275                 If (\_SB.PCI0.LPCB.EC0.P62S) {
276                         Store (0x16, Index(PBST, 1))
277                 } Else  {
278                         Store (0x0b, Index(PBST, 1))
279                 }
280         }
281
282         // Invalidate Battery Info
283         Method(IVBI, 0)
284         {
285                 Store (0xffffffff, Index(PBIF, 1))
286                 Store (0xffffffff, Index(PBIF, 2))
287                 Store (0xffffffff, Index(PBIF, 4))
288                 Store ("Bad", Index(PBIF, 9))
289                 Store ("Bad", Index(PBIF, 10))
290                 Store ("Bad", Index(PBIF, 11))
291                 Store ("Bad", Index(PBIF, 12))
292                 Store (1, PBIF)
293         }
294
295         Method(IVBS, 0)
296         {
297                 Store (0x0, Index(PBST, 0))
298                 Store (0xffffffff, Index(PBST, 1))
299                 Store (0xffffffff, Index(PBST, 2))
300                 Store (0xffffffff, Index(PBST, 3))
301         }
302 }
303
304 Method (RDW, 1)
305 {
306         Store (0x16, \_SB.PCI0.LPCB.EC0.SMAD)
307         Store (Arg0, \_SB.PCI0.LPCB.EC0.SMCM)
308         Store (0x09, \_SB.PCI0.LPCB.EC0.SMPR)
309         While (LNotEqual(\_SB.PCI0.LPCB.EC0.SMPR, 0x00)) {
310                 Stall (1)
311         }
312
313         Return (\_SB.PCI0.LPCB.EC0.SMW0)
314 }
315
316 Device (ADP1)
317 {
318         Name (_HID, "ACPI0003")
319         Method (_PSR, 0)
320         {
321                 If (\_SB.PCI0.LPCB.EC0.ECON) {
322                         Store (\_SB.PCI0.LPCB.EC0.P60S, Local0)
323                         If (Local0) {
324                                 Store (0, PWRS)
325                         } Else {
326                                 Store (1, PWRS)
327                         }
328                 }
329
330                 Stall (0x02)
331                 Return (PWRS)
332         }
333
334         Method (_PCL, 0)
335         {
336                 Return (_SB)
337         }
338 }
339