Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 1 | /* |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 2 | * BQ27xxx battery driver |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2008 Rodolfo Giometti <giometti@linux.it> |
| 5 | * Copyright (C) 2008 Eurotech S.p.A. <info@eurotech.it> |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 6 | * Copyright (C) 2010-2011 Lars-Peter Clausen <lars@metafoo.de> |
Pali Rohár | 73c244a | 2011-04-30 23:59:35 +0200 | [diff] [blame] | 7 | * Copyright (C) 2011 Pali Rohár <pali.rohar@gmail.com> |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 8 | * |
| 9 | * Based on a previous work by Copyright (C) 2008 Texas Instruments, Inc. |
| 10 | * |
| 11 | * This package is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 17 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 18 | * |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 19 | * Datasheets: |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 20 | * http://www.ti.com/product/bq27000 |
| 21 | * http://www.ti.com/product/bq27200 |
| 22 | * http://www.ti.com/product/bq27010 |
| 23 | * http://www.ti.com/product/bq27210 |
| 24 | * http://www.ti.com/product/bq27500 |
| 25 | * http://www.ti.com/product/bq27510-g3 |
| 26 | * http://www.ti.com/product/bq27520-g4 |
| 27 | * http://www.ti.com/product/bq27530-g1 |
| 28 | * http://www.ti.com/product/bq27531-g1 |
| 29 | * http://www.ti.com/product/bq27541-g1 |
| 30 | * http://www.ti.com/product/bq27542-g1 |
| 31 | * http://www.ti.com/product/bq27546-g1 |
| 32 | * http://www.ti.com/product/bq27742-g1 |
| 33 | * http://www.ti.com/product/bq27545-g1 |
| 34 | * http://www.ti.com/product/bq27421-g1 |
Saranya Gopal | a66f59b | 2012-07-13 20:20:07 -0700 | [diff] [blame] | 35 | * http://www.ti.com/product/bq27425-g1 |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 36 | * http://www.ti.com/product/bq27411-g1 |
| 37 | * http://www.ti.com/product/bq27621-g1 |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 38 | */ |
| 39 | |
Himangi Saraogi | 1cb82fd | 2014-05-28 22:58:49 +0530 | [diff] [blame] | 40 | #include <linux/device.h> |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 41 | #include <linux/module.h> |
| 42 | #include <linux/param.h> |
| 43 | #include <linux/jiffies.h> |
| 44 | #include <linux/workqueue.h> |
| 45 | #include <linux/delay.h> |
| 46 | #include <linux/platform_device.h> |
| 47 | #include <linux/power_supply.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 48 | #include <linux/slab.h> |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 49 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 50 | #include <linux/power/bq27xxx_battery.h> |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 51 | |
Andrew F. Davis | 6eb207f | 2015-07-22 16:51:54 -0500 | [diff] [blame] | 52 | #define DRIVER_VERSION "1.2.0" |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 53 | |
Andrew F. Davis | db04fc5 | 2015-07-22 16:51:53 -0500 | [diff] [blame] | 54 | #define BQ27XXX_MANUFACTURER "Texas Instruments" |
| 55 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 56 | /* BQ27XXX Flags */ |
| 57 | #define BQ27XXX_FLAG_DSC BIT(0) |
| 58 | #define BQ27XXX_FLAG_SOCF BIT(1) /* State-of-Charge threshold final */ |
| 59 | #define BQ27XXX_FLAG_SOC1 BIT(2) /* State-of-Charge threshold 1 */ |
| 60 | #define BQ27XXX_FLAG_FC BIT(9) |
| 61 | #define BQ27XXX_FLAG_OTD BIT(14) |
| 62 | #define BQ27XXX_FLAG_OTC BIT(15) |
Andrew F. Davis | 74aab84 | 2015-09-22 14:35:10 -0500 | [diff] [blame] | 63 | #define BQ27XXX_FLAG_UT BIT(14) |
| 64 | #define BQ27XXX_FLAG_OT BIT(15) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 65 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 66 | /* BQ27000 has different layout for Flags register */ |
Andrew F. Davis | 6eb207f | 2015-07-22 16:51:54 -0500 | [diff] [blame] | 67 | #define BQ27000_FLAG_EDVF BIT(0) /* Final End-of-Discharge-Voltage flag */ |
| 68 | #define BQ27000_FLAG_EDV1 BIT(1) /* First End-of-Discharge-Voltage flag */ |
| 69 | #define BQ27000_FLAG_CI BIT(4) /* Capacity Inaccurate flag */ |
| 70 | #define BQ27000_FLAG_FC BIT(5) |
| 71 | #define BQ27000_FLAG_CHGS BIT(7) /* Charge state flag */ |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 72 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 73 | #define BQ27XXX_RS (20) /* Resistor sense mOhm */ |
| 74 | #define BQ27XXX_POWER_CONSTANT (29200) /* 29.2 µV^2 * 1000 */ |
| 75 | #define BQ27XXX_CURRENT_CONSTANT (3570) /* 3.57 µV * 1000 */ |
Pali Rohár | a2e5118 | 2010-05-24 20:52:13 +0200 | [diff] [blame] | 76 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 77 | #define INVALID_REG_ADDR 0xff |
| 78 | |
| 79 | /* |
| 80 | * bq27xxx_reg_index - Register names |
| 81 | * |
| 82 | * These are indexes into a device's register mapping array. |
| 83 | */ |
| 84 | enum bq27xxx_reg_index { |
| 85 | BQ27XXX_REG_CTRL = 0, /* Control */ |
| 86 | BQ27XXX_REG_TEMP, /* Temperature */ |
| 87 | BQ27XXX_REG_INT_TEMP, /* Internal Temperature */ |
| 88 | BQ27XXX_REG_VOLT, /* Voltage */ |
| 89 | BQ27XXX_REG_AI, /* Average Current */ |
| 90 | BQ27XXX_REG_FLAGS, /* Flags */ |
| 91 | BQ27XXX_REG_TTE, /* Time-to-Empty */ |
| 92 | BQ27XXX_REG_TTF, /* Time-to-Full */ |
| 93 | BQ27XXX_REG_TTES, /* Time-to-Empty Standby */ |
| 94 | BQ27XXX_REG_TTECP, /* Time-to-Empty at Constant Power */ |
| 95 | BQ27XXX_REG_NAC, /* Nominal Available Capacity */ |
| 96 | BQ27XXX_REG_FCC, /* Full Charge Capacity */ |
| 97 | BQ27XXX_REG_CYCT, /* Cycle Count */ |
| 98 | BQ27XXX_REG_AE, /* Available Energy */ |
| 99 | BQ27XXX_REG_SOC, /* State-of-Charge */ |
| 100 | BQ27XXX_REG_DCAP, /* Design Capacity */ |
| 101 | BQ27XXX_REG_AP, /* Average Power */ |
| 102 | }; |
| 103 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 104 | /* Register mappings */ |
| 105 | static u8 bq27000_regs[] = { |
| 106 | 0x00, /* CONTROL */ |
| 107 | 0x06, /* TEMP */ |
| 108 | INVALID_REG_ADDR, /* INT TEMP - NA*/ |
| 109 | 0x08, /* VOLT */ |
| 110 | 0x14, /* AVG CURR */ |
| 111 | 0x0a, /* FLAGS */ |
| 112 | 0x16, /* TTE */ |
| 113 | 0x18, /* TTF */ |
| 114 | 0x1c, /* TTES */ |
| 115 | 0x26, /* TTECP */ |
| 116 | 0x0c, /* NAC */ |
| 117 | 0x12, /* LMD(FCC) */ |
| 118 | 0x2a, /* CYCT */ |
| 119 | 0x22, /* AE */ |
| 120 | 0x0b, /* SOC(RSOC) */ |
| 121 | 0x76, /* DCAP(ILMD) */ |
| 122 | 0x24, /* AP */ |
| 123 | }; |
| 124 | |
| 125 | static u8 bq27010_regs[] = { |
| 126 | 0x00, /* CONTROL */ |
| 127 | 0x06, /* TEMP */ |
| 128 | INVALID_REG_ADDR, /* INT TEMP - NA*/ |
| 129 | 0x08, /* VOLT */ |
| 130 | 0x14, /* AVG CURR */ |
| 131 | 0x0a, /* FLAGS */ |
| 132 | 0x16, /* TTE */ |
| 133 | 0x18, /* TTF */ |
| 134 | 0x1c, /* TTES */ |
| 135 | 0x26, /* TTECP */ |
| 136 | 0x0c, /* NAC */ |
| 137 | 0x12, /* LMD(FCC) */ |
| 138 | 0x2a, /* CYCT */ |
| 139 | INVALID_REG_ADDR, /* AE - NA */ |
| 140 | 0x0b, /* SOC(RSOC) */ |
| 141 | 0x76, /* DCAP(ILMD) */ |
| 142 | INVALID_REG_ADDR, /* AP - NA */ |
| 143 | }; |
| 144 | |
| 145 | static u8 bq27500_regs[] = { |
| 146 | 0x00, /* CONTROL */ |
| 147 | 0x06, /* TEMP */ |
| 148 | 0x28, /* INT TEMP */ |
| 149 | 0x08, /* VOLT */ |
| 150 | 0x14, /* AVG CURR */ |
| 151 | 0x0a, /* FLAGS */ |
| 152 | 0x16, /* TTE */ |
| 153 | INVALID_REG_ADDR, /* TTF - NA */ |
| 154 | 0x1a, /* TTES */ |
| 155 | INVALID_REG_ADDR, /* TTECP - NA */ |
| 156 | 0x0c, /* NAC */ |
| 157 | 0x12, /* LMD(FCC) */ |
| 158 | 0x1e, /* CYCT */ |
| 159 | INVALID_REG_ADDR, /* AE - NA */ |
| 160 | 0x20, /* SOC(RSOC) */ |
| 161 | 0x2e, /* DCAP(ILMD) */ |
| 162 | INVALID_REG_ADDR, /* AP - NA */ |
| 163 | }; |
| 164 | |
| 165 | static u8 bq27530_regs[] = { |
| 166 | 0x00, /* CONTROL */ |
| 167 | 0x06, /* TEMP */ |
| 168 | 0x32, /* INT TEMP */ |
| 169 | 0x08, /* VOLT */ |
| 170 | 0x14, /* AVG CURR */ |
| 171 | 0x0a, /* FLAGS */ |
| 172 | 0x16, /* TTE */ |
| 173 | INVALID_REG_ADDR, /* TTF - NA */ |
| 174 | INVALID_REG_ADDR, /* TTES - NA */ |
| 175 | INVALID_REG_ADDR, /* TTECP - NA */ |
| 176 | 0x0c, /* NAC */ |
| 177 | 0x12, /* LMD(FCC) */ |
| 178 | 0x2a, /* CYCT */ |
| 179 | INVALID_REG_ADDR, /* AE - NA */ |
| 180 | 0x2c, /* SOC(RSOC) */ |
| 181 | INVALID_REG_ADDR, /* DCAP - NA */ |
| 182 | 0x24, /* AP */ |
| 183 | }; |
| 184 | |
| 185 | static u8 bq27541_regs[] = { |
| 186 | 0x00, /* CONTROL */ |
| 187 | 0x06, /* TEMP */ |
| 188 | 0x28, /* INT TEMP */ |
| 189 | 0x08, /* VOLT */ |
| 190 | 0x14, /* AVG CURR */ |
| 191 | 0x0a, /* FLAGS */ |
| 192 | 0x16, /* TTE */ |
| 193 | INVALID_REG_ADDR, /* TTF - NA */ |
| 194 | INVALID_REG_ADDR, /* TTES - NA */ |
| 195 | INVALID_REG_ADDR, /* TTECP - NA */ |
| 196 | 0x0c, /* NAC */ |
| 197 | 0x12, /* LMD(FCC) */ |
| 198 | 0x2a, /* CYCT */ |
| 199 | INVALID_REG_ADDR, /* AE - NA */ |
| 200 | 0x2c, /* SOC(RSOC) */ |
| 201 | 0x3c, /* DCAP */ |
| 202 | 0x76, /* AP */ |
| 203 | }; |
| 204 | |
| 205 | static u8 bq27545_regs[] = { |
| 206 | 0x00, /* CONTROL */ |
| 207 | 0x06, /* TEMP */ |
| 208 | 0x28, /* INT TEMP */ |
| 209 | 0x08, /* VOLT */ |
| 210 | 0x14, /* AVG CURR */ |
| 211 | 0x0a, /* FLAGS */ |
| 212 | 0x16, /* TTE */ |
| 213 | INVALID_REG_ADDR, /* TTF - NA */ |
| 214 | INVALID_REG_ADDR, /* TTES - NA */ |
| 215 | INVALID_REG_ADDR, /* TTECP - NA */ |
| 216 | 0x0c, /* NAC */ |
| 217 | 0x12, /* LMD(FCC) */ |
| 218 | 0x2a, /* CYCT */ |
| 219 | INVALID_REG_ADDR, /* AE - NA */ |
| 220 | 0x2c, /* SOC(RSOC) */ |
| 221 | INVALID_REG_ADDR, /* DCAP - NA */ |
| 222 | 0x24, /* AP */ |
| 223 | }; |
| 224 | |
| 225 | static u8 bq27421_regs[] = { |
| 226 | 0x00, /* CONTROL */ |
| 227 | 0x02, /* TEMP */ |
| 228 | 0x1e, /* INT TEMP */ |
| 229 | 0x04, /* VOLT */ |
| 230 | 0x10, /* AVG CURR */ |
| 231 | 0x06, /* FLAGS */ |
| 232 | INVALID_REG_ADDR, /* TTE - NA */ |
| 233 | INVALID_REG_ADDR, /* TTF - NA */ |
| 234 | INVALID_REG_ADDR, /* TTES - NA */ |
| 235 | INVALID_REG_ADDR, /* TTECP - NA */ |
| 236 | 0x08, /* NAC */ |
| 237 | 0x0e, /* FCC */ |
| 238 | INVALID_REG_ADDR, /* CYCT - NA */ |
| 239 | INVALID_REG_ADDR, /* AE - NA */ |
| 240 | 0x1c, /* SOC */ |
| 241 | 0x3c, /* DCAP */ |
| 242 | 0x18, /* AP */ |
| 243 | }; |
| 244 | |
| 245 | static u8 *bq27xxx_regs[] = { |
| 246 | [BQ27000] = bq27000_regs, |
| 247 | [BQ27010] = bq27010_regs, |
| 248 | [BQ27500] = bq27500_regs, |
| 249 | [BQ27530] = bq27530_regs, |
| 250 | [BQ27541] = bq27541_regs, |
| 251 | [BQ27545] = bq27545_regs, |
| 252 | [BQ27421] = bq27421_regs, |
| 253 | }; |
| 254 | |
| 255 | static enum power_supply_property bq27000_battery_props[] = { |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 256 | POWER_SUPPLY_PROP_STATUS, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 257 | POWER_SUPPLY_PROP_PRESENT, |
| 258 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 259 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 260 | POWER_SUPPLY_PROP_CAPACITY, |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 261 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 262 | POWER_SUPPLY_PROP_TEMP, |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 263 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, |
| 264 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, |
| 265 | POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, |
Lars-Peter Clausen | 5661f33 | 2010-05-24 20:36:52 +0200 | [diff] [blame] | 266 | POWER_SUPPLY_PROP_TECHNOLOGY, |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 267 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 268 | POWER_SUPPLY_PROP_CHARGE_NOW, |
| 269 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
Pali Rohár | 73c244a | 2011-04-30 23:59:35 +0200 | [diff] [blame] | 270 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 271 | POWER_SUPPLY_PROP_ENERGY_NOW, |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 272 | POWER_SUPPLY_PROP_POWER_AVG, |
| 273 | POWER_SUPPLY_PROP_HEALTH, |
Andrew F. Davis | db04fc5 | 2015-07-22 16:51:53 -0500 | [diff] [blame] | 274 | POWER_SUPPLY_PROP_MANUFACTURER, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 275 | }; |
| 276 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 277 | static enum power_supply_property bq27010_battery_props[] = { |
Saranya Gopal | a66f59b | 2012-07-13 20:20:07 -0700 | [diff] [blame] | 278 | POWER_SUPPLY_PROP_STATUS, |
| 279 | POWER_SUPPLY_PROP_PRESENT, |
| 280 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 281 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 282 | POWER_SUPPLY_PROP_CAPACITY, |
| 283 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
| 284 | POWER_SUPPLY_PROP_TEMP, |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 285 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, |
| 286 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, |
| 287 | POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, |
Saranya Gopal | a66f59b | 2012-07-13 20:20:07 -0700 | [diff] [blame] | 288 | POWER_SUPPLY_PROP_TECHNOLOGY, |
| 289 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 290 | POWER_SUPPLY_PROP_CHARGE_NOW, |
| 291 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 292 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
| 293 | POWER_SUPPLY_PROP_HEALTH, |
Andrew F. Davis | db04fc5 | 2015-07-22 16:51:53 -0500 | [diff] [blame] | 294 | POWER_SUPPLY_PROP_MANUFACTURER, |
Saranya Gopal | a66f59b | 2012-07-13 20:20:07 -0700 | [diff] [blame] | 295 | }; |
| 296 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 297 | static enum power_supply_property bq27500_battery_props[] = { |
| 298 | POWER_SUPPLY_PROP_STATUS, |
| 299 | POWER_SUPPLY_PROP_PRESENT, |
| 300 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 301 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 302 | POWER_SUPPLY_PROP_CAPACITY, |
| 303 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
| 304 | POWER_SUPPLY_PROP_TEMP, |
| 305 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, |
| 306 | POWER_SUPPLY_PROP_TECHNOLOGY, |
| 307 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 308 | POWER_SUPPLY_PROP_CHARGE_NOW, |
| 309 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
| 310 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
| 311 | POWER_SUPPLY_PROP_HEALTH, |
| 312 | POWER_SUPPLY_PROP_MANUFACTURER, |
| 313 | }; |
| 314 | |
| 315 | static enum power_supply_property bq27530_battery_props[] = { |
| 316 | POWER_SUPPLY_PROP_STATUS, |
| 317 | POWER_SUPPLY_PROP_PRESENT, |
| 318 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 319 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 320 | POWER_SUPPLY_PROP_CAPACITY, |
| 321 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
| 322 | POWER_SUPPLY_PROP_TEMP, |
| 323 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, |
| 324 | POWER_SUPPLY_PROP_TECHNOLOGY, |
| 325 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 326 | POWER_SUPPLY_PROP_CHARGE_NOW, |
| 327 | POWER_SUPPLY_PROP_POWER_AVG, |
| 328 | POWER_SUPPLY_PROP_HEALTH, |
| 329 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
| 330 | POWER_SUPPLY_PROP_MANUFACTURER, |
| 331 | }; |
| 332 | |
| 333 | static enum power_supply_property bq27541_battery_props[] = { |
Puthikorn Voravootivat | 628ef02 | 2014-09-09 12:20:35 -0700 | [diff] [blame] | 334 | POWER_SUPPLY_PROP_STATUS, |
| 335 | POWER_SUPPLY_PROP_PRESENT, |
| 336 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 337 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 338 | POWER_SUPPLY_PROP_CAPACITY, |
| 339 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
| 340 | POWER_SUPPLY_PROP_TEMP, |
| 341 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, |
| 342 | POWER_SUPPLY_PROP_TECHNOLOGY, |
| 343 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 344 | POWER_SUPPLY_PROP_CHARGE_NOW, |
| 345 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
| 346 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
| 347 | POWER_SUPPLY_PROP_POWER_AVG, |
| 348 | POWER_SUPPLY_PROP_HEALTH, |
Andrew F. Davis | db04fc5 | 2015-07-22 16:51:53 -0500 | [diff] [blame] | 349 | POWER_SUPPLY_PROP_MANUFACTURER, |
Puthikorn Voravootivat | 628ef02 | 2014-09-09 12:20:35 -0700 | [diff] [blame] | 350 | }; |
| 351 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 352 | static enum power_supply_property bq27545_battery_props[] = { |
Alexandre Belloni | f46bf82 | 2015-02-28 18:59:28 +0100 | [diff] [blame] | 353 | POWER_SUPPLY_PROP_STATUS, |
| 354 | POWER_SUPPLY_PROP_PRESENT, |
| 355 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 356 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 357 | POWER_SUPPLY_PROP_CAPACITY, |
| 358 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
| 359 | POWER_SUPPLY_PROP_TEMP, |
| 360 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, |
| 361 | POWER_SUPPLY_PROP_TECHNOLOGY, |
| 362 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 363 | POWER_SUPPLY_PROP_CHARGE_NOW, |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 364 | POWER_SUPPLY_PROP_HEALTH, |
Alexandre Belloni | f46bf82 | 2015-02-28 18:59:28 +0100 | [diff] [blame] | 365 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
| 366 | POWER_SUPPLY_PROP_POWER_AVG, |
Andrew F. Davis | db04fc5 | 2015-07-22 16:51:53 -0500 | [diff] [blame] | 367 | POWER_SUPPLY_PROP_MANUFACTURER, |
Alexandre Belloni | f46bf82 | 2015-02-28 18:59:28 +0100 | [diff] [blame] | 368 | }; |
| 369 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 370 | static enum power_supply_property bq27421_battery_props[] = { |
| 371 | POWER_SUPPLY_PROP_STATUS, |
| 372 | POWER_SUPPLY_PROP_PRESENT, |
| 373 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 374 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 375 | POWER_SUPPLY_PROP_CAPACITY, |
| 376 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
| 377 | POWER_SUPPLY_PROP_TEMP, |
| 378 | POWER_SUPPLY_PROP_TECHNOLOGY, |
| 379 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 380 | POWER_SUPPLY_PROP_CHARGE_NOW, |
| 381 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
| 382 | POWER_SUPPLY_PROP_MANUFACTURER, |
| 383 | }; |
| 384 | |
| 385 | #define BQ27XXX_PROP(_id, _prop) \ |
| 386 | [_id] = { \ |
| 387 | .props = _prop, \ |
| 388 | .size = ARRAY_SIZE(_prop), \ |
| 389 | } |
| 390 | |
| 391 | static struct { |
| 392 | enum power_supply_property *props; |
| 393 | size_t size; |
| 394 | } bq27xxx_battery_props[] = { |
| 395 | BQ27XXX_PROP(BQ27000, bq27000_battery_props), |
| 396 | BQ27XXX_PROP(BQ27010, bq27010_battery_props), |
| 397 | BQ27XXX_PROP(BQ27500, bq27500_battery_props), |
| 398 | BQ27XXX_PROP(BQ27530, bq27530_battery_props), |
| 399 | BQ27XXX_PROP(BQ27541, bq27541_battery_props), |
| 400 | BQ27XXX_PROP(BQ27545, bq27545_battery_props), |
| 401 | BQ27XXX_PROP(BQ27421, bq27421_battery_props), |
| 402 | }; |
| 403 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 404 | static unsigned int poll_interval = 360; |
| 405 | module_param(poll_interval, uint, 0644); |
Andrew F. Davis | 6d0a181 | 2015-07-22 16:51:56 -0500 | [diff] [blame] | 406 | MODULE_PARM_DESC(poll_interval, |
| 407 | "battery poll interval in seconds - 0 disables polling"); |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 408 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 409 | /* |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 410 | * Common code for BQ27xxx devices |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 411 | */ |
| 412 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 413 | static inline int bq27xxx_read(struct bq27xxx_device_info *di, int reg_index, |
Andrew F. Davis | ce33edf | 2015-07-22 16:51:55 -0500 | [diff] [blame] | 414 | bool single) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 415 | { |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 416 | /* Reports EINVAL for invalid/missing registers */ |
| 417 | if (!di || di->regs[reg_index] == INVALID_REG_ADDR) |
| 418 | return -EINVAL; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 419 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 420 | return di->bus.read(di, di->regs[reg_index], single); |
Saranya Gopal | a66f59b | 2012-07-13 20:20:07 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* |
Andrew F. Davis | c570903 | 2015-09-22 14:35:08 -0500 | [diff] [blame] | 424 | * Return the battery State-of-Charge |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 425 | * Or < 0 if something fails. |
| 426 | */ |
Andrew F. Davis | c570903 | 2015-09-22 14:35:08 -0500 | [diff] [blame] | 427 | static int bq27xxx_battery_read_soc(struct bq27xxx_device_info *di) |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 428 | { |
Andrew F. Davis | c570903 | 2015-09-22 14:35:08 -0500 | [diff] [blame] | 429 | int soc; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 430 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 431 | soc = bq27xxx_read(di, BQ27XXX_REG_SOC, false); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 432 | |
Andrew F. Davis | c570903 | 2015-09-22 14:35:08 -0500 | [diff] [blame] | 433 | if (soc < 0) |
| 434 | dev_dbg(di->dev, "error reading State-of-Charge\n"); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 435 | |
Andrew F. Davis | c570903 | 2015-09-22 14:35:08 -0500 | [diff] [blame] | 436 | return soc; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 440 | * Return a battery charge value in µAh |
| 441 | * Or < 0 if something fails. |
| 442 | */ |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 443 | static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg) |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 444 | { |
| 445 | int charge; |
| 446 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 447 | charge = bq27xxx_read(di, reg, false); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 448 | if (charge < 0) { |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 449 | dev_dbg(di->dev, "error reading charge register %02x: %d\n", |
| 450 | reg, charge); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 451 | return charge; |
| 452 | } |
| 453 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 454 | if (di->chip == BQ27000 || di->chip == BQ27010) |
| 455 | charge *= BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 456 | else |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 457 | charge *= 1000; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 458 | |
| 459 | return charge; |
| 460 | } |
| 461 | |
| 462 | /* |
Andrew F. Davis | c570903 | 2015-09-22 14:35:08 -0500 | [diff] [blame] | 463 | * Return the battery Nominal available capacity in µAh |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 464 | * Or < 0 if something fails. |
| 465 | */ |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 466 | static inline int bq27xxx_battery_read_nac(struct bq27xxx_device_info *di) |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 467 | { |
Pali Rohár | e59ec4a | 2012-11-10 15:42:48 +0100 | [diff] [blame] | 468 | int flags; |
Pali Rohár | e59ec4a | 2012-11-10 15:42:48 +0100 | [diff] [blame] | 469 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 470 | if (di->chip == BQ27000 || di->chip == BQ27010) { |
| 471 | flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true); |
| 472 | if (flags >= 0 && (flags & BQ27000_FLAG_CI)) |
| 473 | return -ENODATA; |
Andrew F. Davis | 6d0a181 | 2015-07-22 16:51:56 -0500 | [diff] [blame] | 474 | } |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 475 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 476 | return bq27xxx_battery_read_charge(di, BQ27XXX_REG_NAC); |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Return the battery Full Charge Capacity in µAh |
| 481 | * Or < 0 if something fails. |
| 482 | */ |
| 483 | static inline int bq27xxx_battery_read_fcc(struct bq27xxx_device_info *di) |
| 484 | { |
| 485 | return bq27xxx_battery_read_charge(di, BQ27XXX_REG_FCC); |
| 486 | } |
| 487 | |
| 488 | /* |
| 489 | * Return the Design Capacity in µAh |
| 490 | * Or < 0 if something fails. |
| 491 | */ |
| 492 | static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di) |
| 493 | { |
| 494 | int dcap; |
| 495 | |
| 496 | dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, false); |
| 497 | |
| 498 | if (dcap < 0) { |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 499 | dev_dbg(di->dev, "error reading initial last measured discharge\n"); |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 500 | return dcap; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 501 | } |
| 502 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 503 | if (di->chip == BQ27000 || di->chip == BQ27010) |
| 504 | dcap *= BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 505 | else |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 506 | dcap *= 1000; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 507 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 508 | return dcap; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /* |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 512 | * Return the battery Available energy in µWh |
| 513 | * Or < 0 if something fails. |
| 514 | */ |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 515 | static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di) |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 516 | { |
| 517 | int ae; |
| 518 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 519 | ae = bq27xxx_read(di, BQ27XXX_REG_AE, false); |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 520 | if (ae < 0) { |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 521 | dev_dbg(di->dev, "error reading available energy\n"); |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 522 | return ae; |
| 523 | } |
| 524 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 525 | if (di->chip == BQ27000 || di->chip == BQ27010) |
| 526 | ae *= BQ27XXX_POWER_CONSTANT / BQ27XXX_RS; |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 527 | else |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 528 | ae *= 1000; |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 529 | |
| 530 | return ae; |
| 531 | } |
| 532 | |
| 533 | /* |
Pali Rohár | 5dc3443 | 2013-02-02 11:06:09 +0100 | [diff] [blame] | 534 | * Return the battery temperature in tenths of degree Kelvin |
Pali Rohár | d149e98 | 2011-11-01 01:43:07 +0100 | [diff] [blame] | 535 | * Or < 0 if something fails. |
| 536 | */ |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 537 | static int bq27xxx_battery_read_temperature(struct bq27xxx_device_info *di) |
Pali Rohár | d149e98 | 2011-11-01 01:43:07 +0100 | [diff] [blame] | 538 | { |
| 539 | int temp; |
| 540 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 541 | temp = bq27xxx_read(di, BQ27XXX_REG_TEMP, false); |
Pali Rohár | d149e98 | 2011-11-01 01:43:07 +0100 | [diff] [blame] | 542 | if (temp < 0) { |
| 543 | dev_err(di->dev, "error reading temperature\n"); |
| 544 | return temp; |
| 545 | } |
| 546 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 547 | if (di->chip == BQ27000 || di->chip == BQ27010) |
Pali Rohár | 5dc3443 | 2013-02-02 11:06:09 +0100 | [diff] [blame] | 548 | temp = 5 * temp / 2; |
Pali Rohár | d149e98 | 2011-11-01 01:43:07 +0100 | [diff] [blame] | 549 | |
| 550 | return temp; |
| 551 | } |
| 552 | |
| 553 | /* |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 554 | * Return the battery Cycle count total |
| 555 | * Or < 0 if something fails. |
| 556 | */ |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 557 | static int bq27xxx_battery_read_cyct(struct bq27xxx_device_info *di) |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 558 | { |
| 559 | int cyct; |
| 560 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 561 | cyct = bq27xxx_read(di, BQ27XXX_REG_CYCT, false); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 562 | if (cyct < 0) |
| 563 | dev_err(di->dev, "error reading cycle count total\n"); |
| 564 | |
| 565 | return cyct; |
| 566 | } |
| 567 | |
| 568 | /* |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 569 | * Read a time register. |
| 570 | * Return < 0 if something fails. |
| 571 | */ |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 572 | static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg) |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 573 | { |
| 574 | int tval; |
| 575 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 576 | tval = bq27xxx_read(di, reg, false); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 577 | if (tval < 0) { |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 578 | dev_dbg(di->dev, "error reading time register %02x: %d\n", |
| 579 | reg, tval); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 580 | return tval; |
| 581 | } |
| 582 | |
| 583 | if (tval == 65535) |
| 584 | return -ENODATA; |
| 585 | |
| 586 | return tval * 60; |
| 587 | } |
| 588 | |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 589 | /* |
Andrew F. Davis | c570903 | 2015-09-22 14:35:08 -0500 | [diff] [blame] | 590 | * Read an average power register. |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 591 | * Return < 0 if something fails. |
| 592 | */ |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 593 | static int bq27xxx_battery_read_pwr_avg(struct bq27xxx_device_info *di) |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 594 | { |
| 595 | int tval; |
| 596 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 597 | tval = bq27xxx_read(di, BQ27XXX_REG_AP, false); |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 598 | if (tval < 0) { |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 599 | dev_err(di->dev, "error reading average power register %02x: %d\n", |
| 600 | BQ27XXX_REG_AP, tval); |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 601 | return tval; |
| 602 | } |
| 603 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 604 | if (di->chip == BQ27000 || di->chip == BQ27010) |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 605 | return (tval * BQ27XXX_POWER_CONSTANT) / BQ27XXX_RS; |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 606 | else |
| 607 | return tval; |
| 608 | } |
| 609 | |
| 610 | /* |
| 611 | * Returns true if a battery over temperature condition is detected |
| 612 | */ |
Andrew F. Davis | 74aab84 | 2015-09-22 14:35:10 -0500 | [diff] [blame] | 613 | static bool bq27xxx_battery_overtemp(struct bq27xxx_device_info *di, u16 flags) |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 614 | { |
Andrew F. Davis | 74aab84 | 2015-09-22 14:35:10 -0500 | [diff] [blame] | 615 | if (di->chip == BQ27500 || di->chip == BQ27541 || di->chip == BQ27545) |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 616 | return flags & (BQ27XXX_FLAG_OTC | BQ27XXX_FLAG_OTD); |
Andrew F. Davis | 74aab84 | 2015-09-22 14:35:10 -0500 | [diff] [blame] | 617 | if (di->chip == BQ27530 || di->chip == BQ27421) |
| 618 | return flags & BQ27XXX_FLAG_OT; |
| 619 | |
| 620 | return false; |
| 621 | } |
| 622 | |
| 623 | /* |
| 624 | * Returns true if a battery under temperature condition is detected |
| 625 | */ |
| 626 | static bool bq27xxx_battery_undertemp(struct bq27xxx_device_info *di, u16 flags) |
| 627 | { |
| 628 | if (di->chip == BQ27530 || di->chip == BQ27421) |
| 629 | return flags & BQ27XXX_FLAG_UT; |
| 630 | |
| 631 | return false; |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | * Returns true if a low state of charge condition is detected |
| 636 | */ |
| 637 | static bool bq27xxx_battery_dead(struct bq27xxx_device_info *di, u16 flags) |
| 638 | { |
| 639 | if (di->chip == BQ27000 || di->chip == BQ27010) |
| 640 | return flags & (BQ27000_FLAG_EDV1 | BQ27000_FLAG_EDVF); |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 641 | else |
Andrew F. Davis | 74aab84 | 2015-09-22 14:35:10 -0500 | [diff] [blame] | 642 | return flags & (BQ27XXX_FLAG_SOC1 | BQ27XXX_FLAG_SOCF); |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /* |
| 646 | * Read flag register. |
| 647 | * Return < 0 if something fails. |
| 648 | */ |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 649 | static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di) |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 650 | { |
Andrzej Hajda | 2edd69a | 2015-09-28 10:51:27 +0200 | [diff] [blame] | 651 | int flags; |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 652 | |
Andrew F. Davis | 74aab84 | 2015-09-22 14:35:10 -0500 | [diff] [blame] | 653 | flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, false); |
| 654 | if (flags < 0) { |
| 655 | dev_err(di->dev, "error reading flag register:%d\n", flags); |
| 656 | return flags; |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 657 | } |
| 658 | |
Andrew F. Davis | 74aab84 | 2015-09-22 14:35:10 -0500 | [diff] [blame] | 659 | /* Unlikely but important to return first */ |
| 660 | if (unlikely(bq27xxx_battery_overtemp(di, flags))) |
| 661 | return POWER_SUPPLY_HEALTH_OVERHEAT; |
| 662 | if (unlikely(bq27xxx_battery_undertemp(di, flags))) |
| 663 | return POWER_SUPPLY_HEALTH_COLD; |
| 664 | if (unlikely(bq27xxx_battery_dead(di, flags))) |
| 665 | return POWER_SUPPLY_HEALTH_DEAD; |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 666 | |
Andrew F. Davis | 74aab84 | 2015-09-22 14:35:10 -0500 | [diff] [blame] | 667 | return POWER_SUPPLY_HEALTH_GOOD; |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 668 | } |
| 669 | |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 670 | void bq27xxx_battery_update(struct bq27xxx_device_info *di) |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 671 | { |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 672 | struct bq27xxx_reg_cache cache = {0, }; |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 673 | bool has_ci_flag = di->chip == BQ27000 || di->chip == BQ27010; |
| 674 | bool has_singe_flag = di->chip == BQ27000 || di->chip == BQ27010; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 675 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 676 | cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag); |
Marek Belisko | 3dd843e | 2014-06-30 21:49:56 +0200 | [diff] [blame] | 677 | if ((cache.flags & 0xff) == 0xff) |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 678 | cache.flags = -1; /* read error */ |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 679 | if (cache.flags >= 0) { |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 680 | cache.temperature = bq27xxx_battery_read_temperature(di); |
| 681 | if (has_ci_flag && (cache.flags & BQ27000_FLAG_CI)) { |
NeilBrown | 1f94b25 | 2015-10-07 20:42:38 +0200 | [diff] [blame] | 682 | dev_info_once(di->dev, "battery is not calibrated! ignoring capacity values\n"); |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 683 | cache.capacity = -ENODATA; |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 684 | cache.energy = -ENODATA; |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 685 | cache.time_to_empty = -ENODATA; |
| 686 | cache.time_to_empty_avg = -ENODATA; |
| 687 | cache.time_to_full = -ENODATA; |
| 688 | cache.charge_full = -ENODATA; |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 689 | cache.health = -ENODATA; |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 690 | } else { |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 691 | if (di->regs[BQ27XXX_REG_TTE] != INVALID_REG_ADDR) |
| 692 | cache.time_to_empty = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE); |
| 693 | if (di->regs[BQ27XXX_REG_TTECP] != INVALID_REG_ADDR) |
| 694 | cache.time_to_empty_avg = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTECP); |
| 695 | if (di->regs[BQ27XXX_REG_TTF] != INVALID_REG_ADDR) |
| 696 | cache.time_to_full = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTF); |
| 697 | cache.charge_full = bq27xxx_battery_read_fcc(di); |
Andrew F. Davis | c570903 | 2015-09-22 14:35:08 -0500 | [diff] [blame] | 698 | cache.capacity = bq27xxx_battery_read_soc(di); |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 699 | if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR) |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 700 | cache.energy = bq27xxx_battery_read_energy(di); |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 701 | cache.health = bq27xxx_battery_read_health(di); |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 702 | } |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 703 | if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR) |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 704 | cache.cycle_count = bq27xxx_battery_read_cyct(di); |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 705 | if (di->regs[BQ27XXX_REG_AP] != INVALID_REG_ADDR) |
| 706 | cache.power_avg = bq27xxx_battery_read_pwr_avg(di); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 707 | |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 708 | /* We only have to read charge design full once */ |
| 709 | if (di->charge_design_full <= 0) |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 710 | di->charge_design_full = bq27xxx_battery_read_dcap(di); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 711 | } |
| 712 | |
Puthikorn Voravootivat | 90f04a2 | 2014-10-21 18:15:37 -0700 | [diff] [blame] | 713 | if (di->cache.capacity != cache.capacity) |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 714 | power_supply_changed(di->bat); |
Puthikorn Voravootivat | 90f04a2 | 2014-10-21 18:15:37 -0700 | [diff] [blame] | 715 | |
| 716 | if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) |
| 717 | di->cache = cache; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 718 | |
| 719 | di->last_update = jiffies; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 720 | } |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 721 | EXPORT_SYMBOL_GPL(bq27xxx_battery_update); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 722 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 723 | static void bq27xxx_battery_poll(struct work_struct *work) |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 724 | { |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 725 | struct bq27xxx_device_info *di = |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 726 | container_of(work, struct bq27xxx_device_info, |
| 727 | work.work); |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 728 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 729 | bq27xxx_battery_update(di); |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 730 | |
| 731 | if (poll_interval > 0) { |
| 732 | /* The timer does not have to be accurate. */ |
| 733 | set_timer_slack(&di->work.timer, poll_interval * HZ / 4); |
| 734 | schedule_delayed_work(&di->work, poll_interval * HZ); |
| 735 | } |
| 736 | } |
| 737 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 738 | /* |
Pali Rohár | bf7d414 | 2011-02-01 00:23:13 +0100 | [diff] [blame] | 739 | * Return the battery average current in µA |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 740 | * Note that current can be negative signed as well |
| 741 | * Or 0 if something fails. |
| 742 | */ |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 743 | static int bq27xxx_battery_current(struct bq27xxx_device_info *di, |
Andrew F. Davis | ce33edf | 2015-07-22 16:51:55 -0500 | [diff] [blame] | 744 | union power_supply_propval *val) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 745 | { |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 746 | int curr; |
Pali Rohár | b68f621 | 2011-11-01 01:43:03 +0100 | [diff] [blame] | 747 | int flags; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 748 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 749 | curr = bq27xxx_read(di, BQ27XXX_REG_AI, false); |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 750 | if (curr < 0) { |
| 751 | dev_err(di->dev, "error reading current\n"); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 752 | return curr; |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 753 | } |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 754 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 755 | if (di->chip == BQ27000 || di->chip == BQ27010) { |
| 756 | flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, false); |
Pali Rohár | b68f621 | 2011-11-01 01:43:03 +0100 | [diff] [blame] | 757 | if (flags & BQ27000_FLAG_CHGS) { |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 758 | dev_dbg(di->dev, "negative current!\n"); |
Grazvydas Ignotas | afbc74f | 2010-02-27 17:06:44 +0200 | [diff] [blame] | 759 | curr = -curr; |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 760 | } |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 761 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 762 | val->intval = curr * BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS; |
| 763 | } else { |
| 764 | /* Other gauges return signed value */ |
| 765 | val->intval = (int)((s16)curr) * 1000; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 766 | } |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 767 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 768 | return 0; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 771 | static int bq27xxx_battery_status(struct bq27xxx_device_info *di, |
Andrew F. Davis | ce33edf | 2015-07-22 16:51:55 -0500 | [diff] [blame] | 772 | union power_supply_propval *val) |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 773 | { |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 774 | int status; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 775 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 776 | if (di->chip == BQ27000 || di->chip == BQ27010) { |
Lars-Peter Clausen | c1b9ab6 | 2010-09-18 17:31:16 +0200 | [diff] [blame] | 777 | if (di->cache.flags & BQ27000_FLAG_FC) |
| 778 | status = POWER_SUPPLY_STATUS_FULL; |
| 779 | else if (di->cache.flags & BQ27000_FLAG_CHGS) |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 780 | status = POWER_SUPPLY_STATUS_CHARGING; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 781 | else if (power_supply_am_i_supplied(di->bat)) |
Lars-Peter Clausen | c1b9ab6 | 2010-09-18 17:31:16 +0200 | [diff] [blame] | 782 | status = POWER_SUPPLY_STATUS_NOT_CHARGING; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 783 | else |
| 784 | status = POWER_SUPPLY_STATUS_DISCHARGING; |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 785 | } else { |
| 786 | if (di->cache.flags & BQ27XXX_FLAG_FC) |
| 787 | status = POWER_SUPPLY_STATUS_FULL; |
| 788 | else if (di->cache.flags & BQ27XXX_FLAG_DSC) |
| 789 | status = POWER_SUPPLY_STATUS_DISCHARGING; |
| 790 | else |
| 791 | status = POWER_SUPPLY_STATUS_CHARGING; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | val->intval = status; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 795 | |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 796 | return 0; |
| 797 | } |
| 798 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 799 | static int bq27xxx_battery_capacity_level(struct bq27xxx_device_info *di, |
Andrew F. Davis | ce33edf | 2015-07-22 16:51:55 -0500 | [diff] [blame] | 800 | union power_supply_propval *val) |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 801 | { |
| 802 | int level; |
| 803 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 804 | if (di->chip == BQ27000 || di->chip == BQ27010) { |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 805 | if (di->cache.flags & BQ27000_FLAG_FC) |
| 806 | level = POWER_SUPPLY_CAPACITY_LEVEL_FULL; |
| 807 | else if (di->cache.flags & BQ27000_FLAG_EDV1) |
| 808 | level = POWER_SUPPLY_CAPACITY_LEVEL_LOW; |
| 809 | else if (di->cache.flags & BQ27000_FLAG_EDVF) |
| 810 | level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; |
| 811 | else |
| 812 | level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 813 | } else { |
| 814 | if (di->cache.flags & BQ27XXX_FLAG_FC) |
| 815 | level = POWER_SUPPLY_CAPACITY_LEVEL_FULL; |
| 816 | else if (di->cache.flags & BQ27XXX_FLAG_SOC1) |
| 817 | level = POWER_SUPPLY_CAPACITY_LEVEL_LOW; |
| 818 | else if (di->cache.flags & BQ27XXX_FLAG_SOCF) |
| 819 | level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; |
| 820 | else |
| 821 | level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | val->intval = level; |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 829 | /* |
Thomas Weber | 91fe4d5 | 2012-02-17 17:46:21 +0100 | [diff] [blame] | 830 | * Return the battery Voltage in millivolts |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 831 | * Or < 0 if something fails. |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 832 | */ |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 833 | static int bq27xxx_battery_voltage(struct bq27xxx_device_info *di, |
Andrew F. Davis | ce33edf | 2015-07-22 16:51:55 -0500 | [diff] [blame] | 834 | union power_supply_propval *val) |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 835 | { |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 836 | int volt; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 837 | |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 838 | volt = bq27xxx_read(di, BQ27XXX_REG_VOLT, false); |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 839 | if (volt < 0) { |
| 840 | dev_err(di->dev, "error reading voltage\n"); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 841 | return volt; |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 842 | } |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 843 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 844 | val->intval = volt * 1000; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 845 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 846 | return 0; |
| 847 | } |
| 848 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 849 | static int bq27xxx_simple_value(int value, |
Andrew F. Davis | ce33edf | 2015-07-22 16:51:55 -0500 | [diff] [blame] | 850 | union power_supply_propval *val) |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 851 | { |
| 852 | if (value < 0) |
| 853 | return value; |
| 854 | |
| 855 | val->intval = value; |
| 856 | |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 857 | return 0; |
| 858 | } |
| 859 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 860 | static int bq27xxx_battery_get_property(struct power_supply *psy, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 861 | enum power_supply_property psp, |
| 862 | union power_supply_propval *val) |
| 863 | { |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 864 | int ret = 0; |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 865 | struct bq27xxx_device_info *di = power_supply_get_drvdata(psy); |
Lars-Peter Clausen | 3413b4e | 2010-05-24 21:57:33 +0200 | [diff] [blame] | 866 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 867 | mutex_lock(&di->lock); |
| 868 | if (time_is_before_jiffies(di->last_update + 5 * HZ)) { |
| 869 | cancel_delayed_work_sync(&di->work); |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 870 | bq27xxx_battery_poll(&di->work.work); |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 871 | } |
| 872 | mutex_unlock(&di->lock); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 873 | |
| 874 | if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0) |
Lars-Peter Clausen | 3413b4e | 2010-05-24 21:57:33 +0200 | [diff] [blame] | 875 | return -ENODEV; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 876 | |
| 877 | switch (psp) { |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 878 | case POWER_SUPPLY_PROP_STATUS: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 879 | ret = bq27xxx_battery_status(di, val); |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 880 | break; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 881 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 882 | ret = bq27xxx_battery_voltage(di, val); |
Lars-Peter Clausen | 3413b4e | 2010-05-24 21:57:33 +0200 | [diff] [blame] | 883 | break; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 884 | case POWER_SUPPLY_PROP_PRESENT: |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 885 | val->intval = di->cache.flags < 0 ? 0 : 1; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 886 | break; |
| 887 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 888 | ret = bq27xxx_battery_current(di, val); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 889 | break; |
| 890 | case POWER_SUPPLY_PROP_CAPACITY: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 891 | ret = bq27xxx_simple_value(di->cache.capacity, val); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 892 | break; |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 893 | case POWER_SUPPLY_PROP_CAPACITY_LEVEL: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 894 | ret = bq27xxx_battery_capacity_level(di, val); |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 895 | break; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 896 | case POWER_SUPPLY_PROP_TEMP: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 897 | ret = bq27xxx_simple_value(di->cache.temperature, val); |
Pali Rohár | 5dc3443 | 2013-02-02 11:06:09 +0100 | [diff] [blame] | 898 | if (ret == 0) |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 899 | val->intval -= 2731; /* convert decidegree k to c */ |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 900 | break; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 901 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 902 | ret = bq27xxx_simple_value(di->cache.time_to_empty, val); |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 903 | break; |
| 904 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 905 | ret = bq27xxx_simple_value(di->cache.time_to_empty_avg, val); |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 906 | break; |
| 907 | case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 908 | ret = bq27xxx_simple_value(di->cache.time_to_full, val); |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 909 | break; |
Lars-Peter Clausen | 5661f33 | 2010-05-24 20:36:52 +0200 | [diff] [blame] | 910 | case POWER_SUPPLY_PROP_TECHNOLOGY: |
| 911 | val->intval = POWER_SUPPLY_TECHNOLOGY_LION; |
| 912 | break; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 913 | case POWER_SUPPLY_PROP_CHARGE_NOW: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 914 | ret = bq27xxx_simple_value(bq27xxx_battery_read_nac(di), val); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 915 | break; |
| 916 | case POWER_SUPPLY_PROP_CHARGE_FULL: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 917 | ret = bq27xxx_simple_value(di->cache.charge_full, val); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 918 | break; |
| 919 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 920 | ret = bq27xxx_simple_value(di->charge_design_full, val); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 921 | break; |
Pali Rohár | 73c244a | 2011-04-30 23:59:35 +0200 | [diff] [blame] | 922 | case POWER_SUPPLY_PROP_CYCLE_COUNT: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 923 | ret = bq27xxx_simple_value(di->cache.cycle_count, val); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 924 | break; |
| 925 | case POWER_SUPPLY_PROP_ENERGY_NOW: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 926 | ret = bq27xxx_simple_value(di->cache.energy, val); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 927 | break; |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 928 | case POWER_SUPPLY_PROP_POWER_AVG: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 929 | ret = bq27xxx_simple_value(di->cache.power_avg, val); |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 930 | break; |
| 931 | case POWER_SUPPLY_PROP_HEALTH: |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 932 | ret = bq27xxx_simple_value(di->cache.health, val); |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame] | 933 | break; |
Andrew F. Davis | db04fc5 | 2015-07-22 16:51:53 -0500 | [diff] [blame] | 934 | case POWER_SUPPLY_PROP_MANUFACTURER: |
| 935 | val->strval = BQ27XXX_MANUFACTURER; |
| 936 | break; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 937 | default: |
| 938 | return -EINVAL; |
| 939 | } |
| 940 | |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 941 | return ret; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 944 | static void bq27xxx_external_power_changed(struct power_supply *psy) |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 945 | { |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 946 | struct bq27xxx_device_info *di = power_supply_get_drvdata(psy); |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 947 | |
| 948 | cancel_delayed_work_sync(&di->work); |
| 949 | schedule_delayed_work(&di->work, 0); |
| 950 | } |
| 951 | |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 952 | int bq27xxx_battery_setup(struct bq27xxx_device_info *di) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 953 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 954 | struct power_supply_desc *psy_desc; |
| 955 | struct power_supply_config psy_cfg = { .drv_data = di, }; |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 956 | |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 957 | INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll); |
| 958 | mutex_init(&di->lock); |
| 959 | di->regs = bq27xxx_regs[di->chip]; |
| 960 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 961 | psy_desc = devm_kzalloc(di->dev, sizeof(*psy_desc), GFP_KERNEL); |
| 962 | if (!psy_desc) |
| 963 | return -ENOMEM; |
| 964 | |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 965 | psy_desc->name = di->name; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 966 | psy_desc->type = POWER_SUPPLY_TYPE_BATTERY; |
Andrew F. Davis | d74534c | 2015-09-22 14:35:09 -0500 | [diff] [blame] | 967 | psy_desc->properties = bq27xxx_battery_props[di->chip].props; |
| 968 | psy_desc->num_properties = bq27xxx_battery_props[di->chip].size; |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 969 | psy_desc->get_property = bq27xxx_battery_get_property; |
| 970 | psy_desc->external_power_changed = bq27xxx_external_power_changed; |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 971 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 972 | di->bat = power_supply_register_no_ws(di->dev, psy_desc, &psy_cfg); |
| 973 | if (IS_ERR(di->bat)) { |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 974 | dev_err(di->dev, "failed to register battery\n"); |
| 975 | return PTR_ERR(di->bat); |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION); |
| 979 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 980 | bq27xxx_battery_update(di); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 981 | |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 982 | return 0; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 983 | } |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 984 | EXPORT_SYMBOL_GPL(bq27xxx_battery_setup); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 985 | |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 986 | void bq27xxx_battery_teardown(struct bq27xxx_device_info *di) |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 987 | { |
Pali Rohár | 8cfaaa8 | 2011-11-01 01:43:11 +0100 | [diff] [blame] | 988 | /* |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 989 | * power_supply_unregister call bq27xxx_battery_get_property which |
| 990 | * call bq27xxx_battery_poll. |
| 991 | * Make sure that bq27xxx_battery_poll will not call |
Pali Rohár | 8cfaaa8 | 2011-11-01 01:43:11 +0100 | [diff] [blame] | 992 | * schedule_delayed_work again after unregister (which cause OOPS). |
| 993 | */ |
| 994 | poll_interval = 0; |
| 995 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 996 | cancel_delayed_work_sync(&di->work); |
| 997 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 998 | power_supply_unregister(di->bat); |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 999 | |
| 1000 | mutex_destroy(&di->lock); |
| 1001 | } |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 1002 | EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown); |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1003 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 1004 | static int bq27xxx_battery_platform_read(struct bq27xxx_device_info *di, u8 reg, |
| 1005 | bool single) |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1006 | { |
| 1007 | struct device *dev = di->dev; |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 1008 | struct bq27xxx_platform_data *pdata = dev->platform_data; |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1009 | unsigned int timeout = 3; |
| 1010 | int upper, lower; |
| 1011 | int temp; |
| 1012 | |
| 1013 | if (!single) { |
| 1014 | /* Make sure the value has not changed in between reading the |
| 1015 | * lower and the upper part */ |
| 1016 | upper = pdata->read(dev, reg + 1); |
| 1017 | do { |
| 1018 | temp = upper; |
| 1019 | if (upper < 0) |
| 1020 | return upper; |
| 1021 | |
| 1022 | lower = pdata->read(dev, reg); |
| 1023 | if (lower < 0) |
| 1024 | return lower; |
| 1025 | |
| 1026 | upper = pdata->read(dev, reg + 1); |
| 1027 | } while (temp != upper && --timeout); |
| 1028 | |
| 1029 | if (timeout == 0) |
| 1030 | return -EIO; |
| 1031 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 1032 | return (upper << 8) | lower; |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1033 | } |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 1034 | |
| 1035 | return pdata->read(dev, reg); |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1036 | } |
| 1037 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 1038 | static int bq27xxx_battery_platform_probe(struct platform_device *pdev) |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1039 | { |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 1040 | struct bq27xxx_device_info *di; |
| 1041 | struct bq27xxx_platform_data *pdata = pdev->dev.platform_data; |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1042 | |
| 1043 | if (!pdata) { |
| 1044 | dev_err(&pdev->dev, "no platform_data supplied\n"); |
| 1045 | return -EINVAL; |
| 1046 | } |
| 1047 | |
| 1048 | if (!pdata->read) { |
| 1049 | dev_err(&pdev->dev, "no hdq read callback supplied\n"); |
| 1050 | return -EINVAL; |
| 1051 | } |
| 1052 | |
Andrew F. Davis | 424cfde | 2015-09-22 14:35:07 -0500 | [diff] [blame] | 1053 | if (!pdata->chip) { |
| 1054 | dev_err(&pdev->dev, "no device supplied\n"); |
| 1055 | return -EINVAL; |
| 1056 | } |
| 1057 | |
Himangi Saraogi | 1cb82fd | 2014-05-28 22:58:49 +0530 | [diff] [blame] | 1058 | di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL); |
Andrew F. Davis | 6d0a181 | 2015-07-22 16:51:56 -0500 | [diff] [blame] | 1059 | if (!di) |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1060 | return -ENOMEM; |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1061 | |
| 1062 | platform_set_drvdata(pdev, di); |
| 1063 | |
| 1064 | di->dev = &pdev->dev; |
Andrew F. Davis | 424cfde | 2015-09-22 14:35:07 -0500 | [diff] [blame] | 1065 | di->chip = pdata->chip; |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 1066 | di->name = pdata->name ?: dev_name(&pdev->dev); |
| 1067 | di->bus.read = bq27xxx_battery_platform_read; |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1068 | |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 1069 | return bq27xxx_battery_setup(di); |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1070 | } |
| 1071 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 1072 | static int bq27xxx_battery_platform_remove(struct platform_device *pdev) |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1073 | { |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 1074 | struct bq27xxx_device_info *di = platform_get_drvdata(pdev); |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1075 | |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 1076 | bq27xxx_battery_teardown(di); |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 1077 | |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1078 | return 0; |
| 1079 | } |
| 1080 | |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 1081 | static const struct platform_device_id bq27xxx_battery_platform_id_table[] = { |
| 1082 | { "bq27000-battery", }, |
| 1083 | { /* sentinel */ } |
| 1084 | }; |
| 1085 | MODULE_DEVICE_TABLE(platform, bq27xxx_battery_platform_id_table); |
| 1086 | |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 1087 | static struct platform_driver bq27xxx_battery_platform_driver = { |
| 1088 | .probe = bq27xxx_battery_platform_probe, |
| 1089 | .remove = bq27xxx_battery_platform_remove, |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1090 | .driver = { |
| 1091 | .name = "bq27000-battery", |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1092 | }, |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 1093 | .id_table = bq27xxx_battery_platform_id_table, |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 1094 | }; |
Andrew F. Davis | 703df6c | 2015-11-23 10:53:51 -0600 | [diff] [blame^] | 1095 | module_platform_driver(bq27xxx_battery_platform_driver); |
Marek Belisko | 8ebb7e9 | 2015-04-30 22:05:58 +0200 | [diff] [blame] | 1096 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 1097 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); |
Andrew F. Davis | 081bab2 | 2015-09-22 14:35:06 -0500 | [diff] [blame] | 1098 | MODULE_DESCRIPTION("BQ27xxx battery monitor driver"); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 1099 | MODULE_LICENSE("GPL"); |