Stefan Reinauer | 020b22a | 2012-03-30 17:06:43 -0700 | [diff] [blame] | 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. |
Stefan Reinauer | 020b22a | 2012-03-30 17:06:43 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * The mainboard must define strings in the root scope to |
| 19 | * report device-specific battery information to the OS. |
| 20 | * |
| 21 | * BATM: Model |
| 22 | * BATS: Serial |
| 23 | * BATV: Vendor |
| 24 | */ |
| 25 | |
| 26 | // Scope (EC0) |
| 27 | |
| 28 | Device (BAT0) |
| 29 | { |
| 30 | Name (_HID, EISAID ("PNP0C0A")) |
| 31 | Name (_UID, 1) |
| 32 | Name (_PCL, Package () { \_SB }) |
| 33 | |
| 34 | Name (PBIF, Package () { |
| 35 | 0x00000001, // Power Unit: mAh |
| 36 | 0xFFFFFFFF, // Design Capacity |
| 37 | 0xFFFFFFFF, // Last Full Charge Capacity |
| 38 | 0x00000001, // Battery Technology: Rechargeable |
| 39 | 0xFFFFFFFF, // Design Voltage |
| 40 | 0x00000003, // Design Capacity of Warning |
| 41 | 0xFFFFFFFF, // Design Capacity of Low |
| 42 | 0x00000001, // Capacity Granularity 1 |
| 43 | 0x00000001, // Capacity Granularity 2 |
| 44 | "", // Model Number |
| 45 | "", // Serial Number |
| 46 | "LION", // Battery Type |
| 47 | "" // OEM Information |
| 48 | }) |
| 49 | |
| 50 | Name (PBST, Package () { |
| 51 | 0x00000000, // Battery State |
| 52 | 0xFFFFFFFF, // Battery Present Rate |
| 53 | 0xFFFFFFFF, // Battery Remaining Capacity |
| 54 | 0xFFFFFFFF, // Battery Present Voltage |
| 55 | }) |
| 56 | Name (BSTP, Zero) |
| 57 | |
| 58 | // Workaround for full battery status, enabled by default |
| 59 | Name (BFWK, One) |
| 60 | |
| 61 | // Method to enable full battery workaround |
| 62 | Method (BFWE) |
| 63 | { |
| 64 | Store (One, BFWK) |
| 65 | } |
| 66 | |
| 67 | // Method to disable full battery workaround |
| 68 | Method (BFWD) |
| 69 | { |
| 70 | Store (Zero, BFWK) |
| 71 | } |
| 72 | |
| 73 | // Swap bytes in a word |
| 74 | Method (SWAB, 1, NotSerialized) |
| 75 | { |
| 76 | ShiftRight (Arg0, 8, Local0) |
| 77 | ShiftLeft (Arg0, 8, Local1) |
| 78 | And (Local1, 0xFF00, Local1) |
| 79 | Or (Local0, Local1, Local0) |
| 80 | If (LEqual (Local0, 0xFFFF)) { |
| 81 | Store (0xFFFFFFFF, Local0) |
| 82 | } |
| 83 | Return (Local0) |
| 84 | } |
| 85 | |
| 86 | Method (_STA, 0, Serialized) |
| 87 | { |
| 88 | If (BTEX) { |
| 89 | Return (0x1F) |
| 90 | } Else { |
| 91 | Return (0x0F) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | Method (_BIF, 0, Serialized) |
| 96 | { |
| 97 | // Update fields from EC |
| 98 | Store (SWAB (BTDA), Index (PBIF, 1)) |
| 99 | Store (SWAB (BTDF), Index (PBIF, 2)) |
| 100 | Store (SWAB (BTDV), Index (PBIF, 4)) |
| 101 | Store (SWAB (BTDL), Index (PBIF, 6)) |
| 102 | |
| 103 | // Get battery info from mainboard |
| 104 | Store (\BATM, Index (PBIF, 9)) |
| 105 | Store (\BATS, Index (PBIF, 10)) |
| 106 | Store (\BATV, Index (PBIF, 12)) |
| 107 | |
| 108 | Return (PBIF) |
| 109 | } |
| 110 | |
| 111 | Method (_BST, 0, Serialized) |
| 112 | { |
| 113 | // |
| 114 | // 0: BATTERY STATE |
| 115 | // |
| 116 | // bit 0 = discharging |
| 117 | // bit 1 = charging |
| 118 | // bit 2 = critical level |
| 119 | // |
| 120 | |
| 121 | // Get battery state from EC |
| 122 | Store (BTST, Local0) |
| 123 | Store (Zero, Local1) |
| 124 | |
| 125 | // Check if AC is present |
| 126 | If (ACEX) { |
| 127 | // Set only charging/discharging bits |
| 128 | And (Local0, 0x03, Local1) |
| 129 | } Else { |
| 130 | // Always discharging when on battery power |
| 131 | Store (0x01, Local1) |
| 132 | } |
| 133 | |
| 134 | // Flag if the battery level is critical |
| 135 | And (Local0, 0x04, Local4) |
| 136 | Or (Local1, Local4, Local1) |
| 137 | Store (Local1, Index (PBST, 0)) |
| 138 | |
| 139 | // Notify if battery state has changed since last time |
| 140 | If (LNotEqual (Local1, BSTP)) { |
| 141 | Store (Local1, BSTP) |
| 142 | Notify (BAT0, 0x80) |
| 143 | } |
| 144 | |
| 145 | // |
| 146 | // 1: BATTERY PRESENT RATE |
| 147 | // |
| 148 | |
| 149 | Store (SWAB (BTPR), Local1) |
| 150 | If (LAnd (LNotEqual (Local1, 0xFFFFFFFF), |
| 151 | LGreaterEqual (Local1, 0x8000))) { |
| 152 | Xor (Local1, 0xFFFF, Local1) |
| 153 | Increment (Local1) |
| 154 | } |
| 155 | Store (Local1, Index (PBST, 1)) |
| 156 | |
| 157 | // |
| 158 | // 2: BATTERY REMAINING CAPACITY |
| 159 | // |
| 160 | Store (SWAB (BTRA), Local1) |
| 161 | If (LAnd (LNotEqual (Local1, 0xFFFFFFFF), |
| 162 | LGreaterEqual (Local1, 0x8000))) { |
| 163 | Xor (Local1, 0xFFFF, Local1) |
| 164 | Increment (Local1) |
| 165 | } |
| 166 | |
| 167 | If (LAnd (BFWK, LAnd (ACEX, LNot (Local0)))) { |
| 168 | // On AC power and battery is neither charging |
| 169 | // nor discharging. Linux expects a full battery |
| 170 | // to report same capacity as last full charge. |
| 171 | // https://bugzilla.kernel.org/show_bug.cgi?id=12632 |
| 172 | Store (SWAB (BTDF), Local2) |
| 173 | |
| 174 | // See if within ~3% of full |
| 175 | ShiftRight (Local2, 5, Local3) |
| 176 | If (LAnd (LGreater (Local1, Subtract (Local2, Local3)), |
| 177 | LLess (Local1, Add (Local2, Local3)))) |
| 178 | { |
| 179 | Store (Local2, Local1) |
| 180 | } |
| 181 | } |
| 182 | Store (Local1, Index (PBST, 2)) |
| 183 | |
| 184 | // |
| 185 | // 3: BATTERY PRESENT VOLTAGE |
| 186 | // |
| 187 | Store (SWAB (BTVO), Index (PBST, 3)) |
| 188 | |
| 189 | Return (PBST) |
| 190 | } |
| 191 | } |