blob: f86cb0169eeb2b94591f97a9b6b7fbdd9c37ce2f [file] [log] [blame]
Stefan Reinauerd8a5fd22012-12-11 15:51:47 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011-2012 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.
Stefan Reinauerd8a5fd22012-12-11 15:51:47 -080015 */
16
17// Scope (EC0)
18
19Device (BATX)
20{
21 Name (_HID, EISAID ("PNP0C0A"))
22 Name (_UID, 1)
23 Name (_PCL, Package () { \_SB })
24
25 Name (PBIF, Package () {
26 0x00000001, // Power Unit: mAh
27 0xFFFFFFFF, // Design Capacity
28 0xFFFFFFFF, // Last Full Charge Capacity
29 0x00000001, // Battery Technology: Rechargeable
30 0xFFFFFFFF, // Design Voltage
31 0x00000003, // Design Capacity of Warning
32 0xFFFFFFFF, // Design Capacity of Low
33 0x00000001, // Capacity Granularity 1
34 0x00000001, // Capacity Granularity 2
35 "", // Model Number
36 "", // Serial Number
37 "LION", // Battery Type
38 "" // OEM Information
39 })
40
41 Name (PBST, Package () {
42 0x00000000, // Battery State
43 0xFFFFFFFF, // Battery Present Rate
44 0xFFFFFFFF, // Battery Remaining Capacity
45 0xFFFFFFFF, // Battery Present Voltage
46 })
47 Name (BTNM, Zero) // Battery number
48
49 // Workaround for full battery status, enabled by default
50 Name (BFWK, One)
51
52 // Method to enable full battery workaround
53 Method (BFWE)
54 {
55 Store (One, BFWK)
56 }
57
58 // Method to disable full battery workaround
59 Method (BFWD)
60 {
61 Store (Zero, BFWK)
62 }
63
64 Method (_STA, 0, Serialized)
65 {
66 If (BOL0) {
67 Return (0x1F)
68 } Else {
69 Return (0x0F)
70 }
71 }
72
73 Method (_BIF, 0, Serialized)
74 {
75 // Update fields from EC
76 Store (BAM0, Index (PBIF, 0))
77 Store (BDC0, Index (PBIF, 1))
78 Store (BFC0, Index (PBIF, 2))
79 Store (BDV0, Index (PBIF, 4))
Vladimir Serbinenkoc285b302016-02-07 23:59:34 +010080 Divide(BFC0, 0x64, , Local1)
Stefan Reinauerd8a5fd22012-12-11 15:51:47 -080081 Multiply(Local1, 0x0A, Local1)
82 Store(Local1, Index(PBIF, 5))
Vladimir Serbinenkoc285b302016-02-07 23:59:34 +010083 Divide(BFC0, 0x64, , Local1)
Stefan Reinauerd8a5fd22012-12-11 15:51:47 -080084 Multiply(Local1, 0x03, Local1)
85 Store (Local1, Index (PBIF, 6))
86
Matt DeVillier678923c2016-12-09 18:14:57 -060087 Store (ToString(Concatenate(BATD, 0x00)), Index (PBIF, 9)) // model
Stefan Reinauerd8a5fd22012-12-11 15:51:47 -080088 Store (ToHexString(BSN0), Index (PBIF, 10)) // serial
Matt DeVillier678923c2016-12-09 18:14:57 -060089 Store (ToString(BMFN), Index (PBIF, 12)) // vendor
Stefan Reinauerd8a5fd22012-12-11 15:51:47 -080090
91 Store(BDN0, BTNM) // Save the battery number
92
93 Return (PBIF)
94 }
95
96 Method (_BST, 0, Serialized)
97 {
98 //
99 // 0: BATTERY STATE
100 //
101 // bit 0 = discharging
102 // bit 1 = charging
103 // bit 2 = critical level
104 //
105
106 // Get battery state from EC and save it for the charging workaround
107 Store (BST0, Local0)
108 Store (Local0, Index (PBST, 0))
109
110 //
111 // 1: BATTERY PRESENT RATE/CURRENT
112 //
113
114 Store (BAC0, Local1)
115 Subtract(0xFFFF, Local1, Local1)
116 Store (Local1, Index (PBST, 1))
117
118 //
119 // 2: BATTERY REMAINING CAPACITY
120 //
121 Multiply(BFC0, GAU0, Local1)
122 Divide(Local1, 0x64, Local2, Local1)
123
124 If (LAnd (BFWK, LAnd (ADPT, LNot (Local0)))) {
125 // On AC power and battery is neither charging
126 // nor discharging. Linux expects a full battery
127 // to report same capacity as last full charge.
128 // https://bugzilla.kernel.org/show_bug.cgi?id=12632
129 Store (GAU0, Local2)
130
131 // See if within ~3% of full
132 ShiftRight (Local2, 5, Local3)
133 If (LAnd (LGreater (Local1, Subtract (Local2, Local3)),
134 LLess (Local1, Add (Local2, Local3))))
135 {
136 Store (Local2, Local1)
137 }
138 }
139 Store (Local1, Index (PBST, 2))
140
141 //
142 // 3: BATTERY PRESENT VOLTAGE
143 //
144 Store (BPV0, Index (PBST, 3))
145
146 // Check the Battery Number
147 If(LNotEqual(BDN0, BTNM)) {
148 Notify(BATX, 0x81)
149 }
150
151 Return (PBST)
152 }
153}