Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BQ27x00 battery driver |
| 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 | * |
| 19 | */ |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Datasheets: |
| 23 | * http://focus.ti.com/docs/prod/folders/print/bq27000.html |
| 24 | * http://focus.ti.com/docs/prod/folders/print/bq27500.html |
| 25 | */ |
| 26 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/param.h> |
| 29 | #include <linux/jiffies.h> |
| 30 | #include <linux/workqueue.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/platform_device.h> |
| 33 | #include <linux/power_supply.h> |
| 34 | #include <linux/idr.h> |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 35 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Harvey Harrison | 8aef7e8 | 2008-09-22 14:53:50 -0700 | [diff] [blame] | 37 | #include <asm/unaligned.h> |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 38 | |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 39 | #include <linux/power/bq27x00_battery.h> |
| 40 | |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 41 | #define DRIVER_VERSION "1.2.0" |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 42 | |
| 43 | #define BQ27x00_REG_TEMP 0x06 |
| 44 | #define BQ27x00_REG_VOLT 0x08 |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 45 | #define BQ27x00_REG_AI 0x14 |
| 46 | #define BQ27x00_REG_FLAGS 0x0A |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 47 | #define BQ27x00_REG_TTE 0x16 |
| 48 | #define BQ27x00_REG_TTF 0x18 |
| 49 | #define BQ27x00_REG_TTECP 0x26 |
Thomas Weber | 202e011 | 2012-02-16 08:58:15 +0100 | [diff] [blame] | 50 | #define BQ27x00_REG_NAC 0x0C /* Nominal available capacity */ |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 51 | #define BQ27x00_REG_LMD 0x12 /* Last measured discharge */ |
| 52 | #define BQ27x00_REG_CYCT 0x2A /* Cycle count total */ |
Thomas Weber | 202e011 | 2012-02-16 08:58:15 +0100 | [diff] [blame] | 53 | #define BQ27x00_REG_AE 0x22 /* Available energy */ |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 54 | #define BQ27x00_POWER_AVG 0x24 |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 55 | |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 56 | #define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */ |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 57 | #define BQ27000_REG_ILMD 0x76 /* Initial last measured discharge */ |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 58 | #define BQ27000_FLAG_EDVF BIT(0) /* Final End-of-Discharge-Voltage flag */ |
| 59 | #define BQ27000_FLAG_EDV1 BIT(1) /* First End-of-Discharge-Voltage flag */ |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 60 | #define BQ27000_FLAG_CI BIT(4) /* Capacity Inaccurate flag */ |
Lars-Peter Clausen | c1b9ab6 | 2010-09-18 17:31:16 +0200 | [diff] [blame] | 61 | #define BQ27000_FLAG_FC BIT(5) |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 62 | #define BQ27000_FLAG_CHGS BIT(7) /* Charge state flag */ |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 63 | |
Pali Rohár | bf7d414 | 2011-02-01 00:23:13 +0100 | [diff] [blame] | 64 | #define BQ27500_REG_SOC 0x2C |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 65 | #define BQ27500_REG_DCAP 0x3C /* Design capacity */ |
Anton Vorontsov | b7aaacf | 2012-02-01 21:20:15 +0400 | [diff] [blame] | 66 | #define BQ27500_FLAG_DSC BIT(0) |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 67 | #define BQ27500_FLAG_SOCF BIT(1) /* State-of-Charge threshold final */ |
| 68 | #define BQ27500_FLAG_SOC1 BIT(2) /* State-of-Charge threshold 1 */ |
Anton Vorontsov | b7aaacf | 2012-02-01 21:20:15 +0400 | [diff] [blame] | 69 | #define BQ27500_FLAG_FC BIT(9) |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 70 | #define BQ27500_FLAG_OTC BIT(15) |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 71 | |
Pali Rohár | a2e5118 | 2010-05-24 20:52:13 +0200 | [diff] [blame] | 72 | #define BQ27000_RS 20 /* Resistor sense */ |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 73 | #define BQ27x00_POWER_CONSTANT (256 * 29200 / 1000) |
Pali Rohár | a2e5118 | 2010-05-24 20:52:13 +0200 | [diff] [blame] | 74 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 75 | struct bq27x00_device_info; |
| 76 | struct bq27x00_access_methods { |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 77 | int (*read)(struct bq27x00_device_info *di, u8 reg, bool single); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 80 | enum bq27x00_chip { BQ27000, BQ27500 }; |
| 81 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 82 | struct bq27x00_reg_cache { |
| 83 | int temperature; |
| 84 | int time_to_empty; |
| 85 | int time_to_empty_avg; |
| 86 | int time_to_full; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 87 | int charge_full; |
Pali Rohár | 73c244a | 2011-04-30 23:59:35 +0200 | [diff] [blame] | 88 | int cycle_count; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 89 | int capacity; |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 90 | int energy; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 91 | int flags; |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 92 | int power_avg; |
| 93 | int health; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 94 | }; |
| 95 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 96 | struct bq27x00_device_info { |
| 97 | struct device *dev; |
| 98 | int id; |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 99 | enum bq27x00_chip chip; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 100 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 101 | struct bq27x00_reg_cache cache; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 102 | int charge_design_full; |
| 103 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 104 | unsigned long last_update; |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 105 | struct delayed_work work; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 106 | |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 107 | struct power_supply bat; |
| 108 | |
| 109 | struct bq27x00_access_methods bus; |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 110 | |
| 111 | struct mutex lock; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | static enum power_supply_property bq27x00_battery_props[] = { |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 115 | POWER_SUPPLY_PROP_STATUS, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 116 | POWER_SUPPLY_PROP_PRESENT, |
| 117 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 118 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 119 | POWER_SUPPLY_PROP_CAPACITY, |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 120 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 121 | POWER_SUPPLY_PROP_TEMP, |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 122 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, |
| 123 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, |
| 124 | POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, |
Lars-Peter Clausen | 5661f33 | 2010-05-24 20:36:52 +0200 | [diff] [blame] | 125 | POWER_SUPPLY_PROP_TECHNOLOGY, |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 126 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 127 | POWER_SUPPLY_PROP_CHARGE_NOW, |
| 128 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
Pali Rohár | 73c244a | 2011-04-30 23:59:35 +0200 | [diff] [blame] | 129 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 130 | POWER_SUPPLY_PROP_ENERGY_NOW, |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 131 | POWER_SUPPLY_PROP_POWER_AVG, |
| 132 | POWER_SUPPLY_PROP_HEALTH, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 135 | static unsigned int poll_interval = 360; |
| 136 | module_param(poll_interval, uint, 0644); |
| 137 | MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \ |
| 138 | "0 disables polling"); |
| 139 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 140 | /* |
| 141 | * Common code for BQ27x00 devices |
| 142 | */ |
| 143 | |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 144 | static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg, |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 145 | bool single) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 146 | { |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 147 | return di->bus.read(di, reg, single); |
| 148 | } |
| 149 | |
| 150 | /* |
| 151 | * Return the battery Relative State-of-Charge |
| 152 | * Or < 0 if something fails. |
| 153 | */ |
| 154 | static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di) |
| 155 | { |
| 156 | int rsoc; |
| 157 | |
| 158 | if (di->chip == BQ27500) |
| 159 | rsoc = bq27x00_read(di, BQ27500_REG_SOC, false); |
| 160 | else |
| 161 | rsoc = bq27x00_read(di, BQ27000_REG_RSOC, true); |
| 162 | |
| 163 | if (rsoc < 0) |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 164 | dev_dbg(di->dev, "error reading relative State-of-Charge\n"); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 165 | |
| 166 | return rsoc; |
| 167 | } |
| 168 | |
| 169 | /* |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 170 | * Return a battery charge value in µAh |
| 171 | * Or < 0 if something fails. |
| 172 | */ |
| 173 | static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg) |
| 174 | { |
| 175 | int charge; |
| 176 | |
| 177 | charge = bq27x00_read(di, reg, false); |
| 178 | if (charge < 0) { |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 179 | dev_dbg(di->dev, "error reading charge register %02x: %d\n", |
| 180 | reg, charge); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 181 | return charge; |
| 182 | } |
| 183 | |
| 184 | if (di->chip == BQ27500) |
| 185 | charge *= 1000; |
| 186 | else |
| 187 | charge = charge * 3570 / BQ27000_RS; |
| 188 | |
| 189 | return charge; |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Return the battery Nominal available capaciy in µAh |
| 194 | * Or < 0 if something fails. |
| 195 | */ |
| 196 | static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di) |
| 197 | { |
| 198 | return bq27x00_battery_read_charge(di, BQ27x00_REG_NAC); |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * Return the battery Last measured discharge in µAh |
| 203 | * Or < 0 if something fails. |
| 204 | */ |
| 205 | static inline int bq27x00_battery_read_lmd(struct bq27x00_device_info *di) |
| 206 | { |
| 207 | return bq27x00_battery_read_charge(di, BQ27x00_REG_LMD); |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * Return the battery Initial last measured discharge in µAh |
| 212 | * Or < 0 if something fails. |
| 213 | */ |
| 214 | static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di) |
| 215 | { |
| 216 | int ilmd; |
| 217 | |
| 218 | if (di->chip == BQ27500) |
| 219 | ilmd = bq27x00_read(di, BQ27500_REG_DCAP, false); |
| 220 | else |
| 221 | ilmd = bq27x00_read(di, BQ27000_REG_ILMD, true); |
| 222 | |
| 223 | if (ilmd < 0) { |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 224 | dev_dbg(di->dev, "error reading initial last measured discharge\n"); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 225 | return ilmd; |
| 226 | } |
| 227 | |
| 228 | if (di->chip == BQ27500) |
| 229 | ilmd *= 1000; |
| 230 | else |
| 231 | ilmd = ilmd * 256 * 3570 / BQ27000_RS; |
| 232 | |
| 233 | return ilmd; |
| 234 | } |
| 235 | |
| 236 | /* |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 237 | * Return the battery Available energy in µWh |
| 238 | * Or < 0 if something fails. |
| 239 | */ |
| 240 | static int bq27x00_battery_read_energy(struct bq27x00_device_info *di) |
| 241 | { |
| 242 | int ae; |
| 243 | |
| 244 | ae = bq27x00_read(di, BQ27x00_REG_AE, false); |
| 245 | if (ae < 0) { |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 246 | dev_dbg(di->dev, "error reading available energy\n"); |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 247 | return ae; |
| 248 | } |
| 249 | |
| 250 | if (di->chip == BQ27500) |
| 251 | ae *= 1000; |
| 252 | else |
| 253 | ae = ae * 29200 / BQ27000_RS; |
| 254 | |
| 255 | return ae; |
| 256 | } |
| 257 | |
| 258 | /* |
Pali Rohár | d149e98 | 2011-11-01 01:43:07 +0100 | [diff] [blame] | 259 | * Return the battery temperature in tenths of degree Celsius |
| 260 | * Or < 0 if something fails. |
| 261 | */ |
| 262 | static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di) |
| 263 | { |
| 264 | int temp; |
| 265 | |
| 266 | temp = bq27x00_read(di, BQ27x00_REG_TEMP, false); |
| 267 | if (temp < 0) { |
| 268 | dev_err(di->dev, "error reading temperature\n"); |
| 269 | return temp; |
| 270 | } |
| 271 | |
| 272 | if (di->chip == BQ27500) |
| 273 | temp -= 2731; |
| 274 | else |
| 275 | temp = ((temp * 5) - 5463) / 2; |
| 276 | |
| 277 | return temp; |
| 278 | } |
| 279 | |
| 280 | /* |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 281 | * Return the battery Cycle count total |
| 282 | * Or < 0 if something fails. |
| 283 | */ |
| 284 | static int bq27x00_battery_read_cyct(struct bq27x00_device_info *di) |
| 285 | { |
| 286 | int cyct; |
| 287 | |
| 288 | cyct = bq27x00_read(di, BQ27x00_REG_CYCT, false); |
| 289 | if (cyct < 0) |
| 290 | dev_err(di->dev, "error reading cycle count total\n"); |
| 291 | |
| 292 | return cyct; |
| 293 | } |
| 294 | |
| 295 | /* |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 296 | * Read a time register. |
| 297 | * Return < 0 if something fails. |
| 298 | */ |
| 299 | static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg) |
| 300 | { |
| 301 | int tval; |
| 302 | |
| 303 | tval = bq27x00_read(di, reg, false); |
| 304 | if (tval < 0) { |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 305 | dev_dbg(di->dev, "error reading time register %02x: %d\n", |
| 306 | reg, tval); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 307 | return tval; |
| 308 | } |
| 309 | |
| 310 | if (tval == 65535) |
| 311 | return -ENODATA; |
| 312 | |
| 313 | return tval * 60; |
| 314 | } |
| 315 | |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 316 | /* |
| 317 | * Read a power avg register. |
| 318 | * Return < 0 if something fails. |
| 319 | */ |
| 320 | static int bq27x00_battery_read_pwr_avg(struct bq27x00_device_info *di, u8 reg) |
| 321 | { |
| 322 | int tval; |
| 323 | |
| 324 | tval = bq27x00_read(di, reg, false); |
| 325 | if (tval < 0) { |
| 326 | dev_err(di->dev, "error reading power avg rgister %02x: %d\n", |
| 327 | reg, tval); |
| 328 | return tval; |
| 329 | } |
| 330 | |
| 331 | if (di->chip == BQ27500) |
| 332 | return tval; |
| 333 | else |
| 334 | return (tval * BQ27x00_POWER_CONSTANT) / BQ27000_RS; |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * Read flag register. |
| 339 | * Return < 0 if something fails. |
| 340 | */ |
| 341 | static int bq27x00_battery_read_health(struct bq27x00_device_info *di) |
| 342 | { |
| 343 | int tval; |
| 344 | |
| 345 | tval = bq27x00_read(di, BQ27x00_REG_FLAGS, false); |
| 346 | if (tval < 0) { |
| 347 | dev_err(di->dev, "error reading flag register:%d\n", tval); |
| 348 | return tval; |
| 349 | } |
| 350 | |
| 351 | if ((di->chip == BQ27500)) { |
| 352 | if (tval & BQ27500_FLAG_SOCF) |
| 353 | tval = POWER_SUPPLY_HEALTH_DEAD; |
| 354 | else if (tval & BQ27500_FLAG_OTC) |
| 355 | tval = POWER_SUPPLY_HEALTH_OVERHEAT; |
| 356 | else |
| 357 | tval = POWER_SUPPLY_HEALTH_GOOD; |
| 358 | return tval; |
| 359 | } else { |
| 360 | if (tval & BQ27000_FLAG_EDV1) |
| 361 | tval = POWER_SUPPLY_HEALTH_DEAD; |
| 362 | else |
| 363 | tval = POWER_SUPPLY_HEALTH_GOOD; |
| 364 | return tval; |
| 365 | } |
| 366 | |
| 367 | return -1; |
| 368 | } |
| 369 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 370 | static void bq27x00_update(struct bq27x00_device_info *di) |
| 371 | { |
| 372 | struct bq27x00_reg_cache cache = {0, }; |
| 373 | bool is_bq27500 = di->chip == BQ27500; |
| 374 | |
Grazvydas Ignotas | 4d40365 | 2012-01-14 22:50:49 +0200 | [diff] [blame] | 375 | cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 376 | if (cache.flags >= 0) { |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 377 | if (!is_bq27500 && (cache.flags & BQ27000_FLAG_CI)) { |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 378 | dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n"); |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 379 | cache.capacity = -ENODATA; |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 380 | cache.energy = -ENODATA; |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 381 | cache.time_to_empty = -ENODATA; |
| 382 | cache.time_to_empty_avg = -ENODATA; |
| 383 | cache.time_to_full = -ENODATA; |
| 384 | cache.charge_full = -ENODATA; |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 385 | cache.health = -ENODATA; |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 386 | } else { |
| 387 | cache.capacity = bq27x00_battery_read_rsoc(di); |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 388 | cache.energy = bq27x00_battery_read_energy(di); |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 389 | cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE); |
| 390 | cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP); |
| 391 | cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF); |
| 392 | cache.charge_full = bq27x00_battery_read_lmd(di); |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 393 | cache.health = bq27x00_battery_read_health(di); |
Pali Rohár | 4b226c2 | 2011-11-01 01:43:05 +0100 | [diff] [blame] | 394 | } |
Pali Rohár | d149e98 | 2011-11-01 01:43:07 +0100 | [diff] [blame] | 395 | cache.temperature = bq27x00_battery_read_temperature(di); |
Pali Rohár | 73c244a | 2011-04-30 23:59:35 +0200 | [diff] [blame] | 396 | cache.cycle_count = bq27x00_battery_read_cyct(di); |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 397 | cache.power_avg = |
| 398 | bq27x00_battery_read_pwr_avg(di, BQ27x00_POWER_AVG); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 399 | |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 400 | /* We only have to read charge design full once */ |
| 401 | if (di->charge_design_full <= 0) |
| 402 | di->charge_design_full = bq27x00_battery_read_ilmd(di); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 403 | } |
| 404 | |
Pali Rohár | b68f621 | 2011-11-01 01:43:03 +0100 | [diff] [blame] | 405 | if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) { |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 406 | di->cache = cache; |
| 407 | power_supply_changed(&di->bat); |
| 408 | } |
| 409 | |
| 410 | di->last_update = jiffies; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 413 | static void bq27x00_battery_poll(struct work_struct *work) |
| 414 | { |
| 415 | struct bq27x00_device_info *di = |
| 416 | container_of(work, struct bq27x00_device_info, work.work); |
| 417 | |
| 418 | bq27x00_update(di); |
| 419 | |
| 420 | if (poll_interval > 0) { |
| 421 | /* The timer does not have to be accurate. */ |
| 422 | set_timer_slack(&di->work.timer, poll_interval * HZ / 4); |
| 423 | schedule_delayed_work(&di->work, poll_interval * HZ); |
| 424 | } |
| 425 | } |
| 426 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 427 | /* |
Pali Rohár | bf7d414 | 2011-02-01 00:23:13 +0100 | [diff] [blame] | 428 | * Return the battery average current in µA |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 429 | * Note that current can be negative signed as well |
| 430 | * Or 0 if something fails. |
| 431 | */ |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 432 | static int bq27x00_battery_current(struct bq27x00_device_info *di, |
| 433 | union power_supply_propval *val) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 434 | { |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 435 | int curr; |
Pali Rohár | b68f621 | 2011-11-01 01:43:03 +0100 | [diff] [blame] | 436 | int flags; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 437 | |
Pali Rohár | b68f621 | 2011-11-01 01:43:03 +0100 | [diff] [blame] | 438 | curr = bq27x00_read(di, BQ27x00_REG_AI, false); |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 439 | if (curr < 0) { |
| 440 | dev_err(di->dev, "error reading current\n"); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 441 | return curr; |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 442 | } |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 443 | |
| 444 | if (di->chip == BQ27500) { |
| 445 | /* bq27500 returns signed value */ |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 446 | val->intval = (int)((s16)curr) * 1000; |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 447 | } else { |
Pali Rohár | b68f621 | 2011-11-01 01:43:03 +0100 | [diff] [blame] | 448 | flags = bq27x00_read(di, BQ27x00_REG_FLAGS, false); |
| 449 | if (flags & BQ27000_FLAG_CHGS) { |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 450 | dev_dbg(di->dev, "negative current!\n"); |
Grazvydas Ignotas | afbc74f | 2010-02-27 17:06:44 +0200 | [diff] [blame] | 451 | curr = -curr; |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 452 | } |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 453 | |
| 454 | val->intval = curr * 3570 / BQ27000_RS; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 455 | } |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 456 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 457 | return 0; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 460 | static int bq27x00_battery_status(struct bq27x00_device_info *di, |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 461 | union power_supply_propval *val) |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 462 | { |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 463 | int status; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 464 | |
| 465 | if (di->chip == BQ27500) { |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 466 | if (di->cache.flags & BQ27500_FLAG_FC) |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 467 | status = POWER_SUPPLY_STATUS_FULL; |
Anton Vorontsov | b7aaacf | 2012-02-01 21:20:15 +0400 | [diff] [blame] | 468 | else if (di->cache.flags & BQ27500_FLAG_DSC) |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 469 | status = POWER_SUPPLY_STATUS_DISCHARGING; |
Pali Rohár | 270968c | 2011-11-01 01:43:08 +0100 | [diff] [blame] | 470 | else |
Anton Vorontsov | b7aaacf | 2012-02-01 21:20:15 +0400 | [diff] [blame] | 471 | status = POWER_SUPPLY_STATUS_CHARGING; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 472 | } else { |
Lars-Peter Clausen | c1b9ab6 | 2010-09-18 17:31:16 +0200 | [diff] [blame] | 473 | if (di->cache.flags & BQ27000_FLAG_FC) |
| 474 | status = POWER_SUPPLY_STATUS_FULL; |
| 475 | else if (di->cache.flags & BQ27000_FLAG_CHGS) |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 476 | status = POWER_SUPPLY_STATUS_CHARGING; |
Lars-Peter Clausen | c1b9ab6 | 2010-09-18 17:31:16 +0200 | [diff] [blame] | 477 | else if (power_supply_am_i_supplied(&di->bat)) |
| 478 | status = POWER_SUPPLY_STATUS_NOT_CHARGING; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 479 | else |
| 480 | status = POWER_SUPPLY_STATUS_DISCHARGING; |
| 481 | } |
| 482 | |
| 483 | val->intval = status; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 484 | |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 488 | static int bq27x00_battery_capacity_level(struct bq27x00_device_info *di, |
| 489 | union power_supply_propval *val) |
| 490 | { |
| 491 | int level; |
| 492 | |
| 493 | if (di->chip == BQ27500) { |
| 494 | if (di->cache.flags & BQ27500_FLAG_FC) |
| 495 | level = POWER_SUPPLY_CAPACITY_LEVEL_FULL; |
| 496 | else if (di->cache.flags & BQ27500_FLAG_SOC1) |
| 497 | level = POWER_SUPPLY_CAPACITY_LEVEL_LOW; |
| 498 | else if (di->cache.flags & BQ27500_FLAG_SOCF) |
| 499 | level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; |
| 500 | else |
| 501 | level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; |
| 502 | } else { |
| 503 | if (di->cache.flags & BQ27000_FLAG_FC) |
| 504 | level = POWER_SUPPLY_CAPACITY_LEVEL_FULL; |
| 505 | else if (di->cache.flags & BQ27000_FLAG_EDV1) |
| 506 | level = POWER_SUPPLY_CAPACITY_LEVEL_LOW; |
| 507 | else if (di->cache.flags & BQ27000_FLAG_EDVF) |
| 508 | level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; |
| 509 | else |
| 510 | level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; |
| 511 | } |
| 512 | |
| 513 | val->intval = level; |
| 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 518 | /* |
Thomas Weber | 91fe4d5 | 2012-02-17 17:46:21 +0100 | [diff] [blame] | 519 | * Return the battery Voltage in millivolts |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 520 | * Or < 0 if something fails. |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 521 | */ |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 522 | static int bq27x00_battery_voltage(struct bq27x00_device_info *di, |
| 523 | union power_supply_propval *val) |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 524 | { |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 525 | int volt; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 526 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 527 | volt = bq27x00_read(di, BQ27x00_REG_VOLT, false); |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 528 | if (volt < 0) { |
| 529 | dev_err(di->dev, "error reading voltage\n"); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 530 | return volt; |
Pali Rohár | c6cd4f2 | 2011-11-01 01:43:09 +0100 | [diff] [blame] | 531 | } |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 532 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 533 | val->intval = volt * 1000; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 534 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | static int bq27x00_simple_value(int value, |
| 539 | union power_supply_propval *val) |
| 540 | { |
| 541 | if (value < 0) |
| 542 | return value; |
| 543 | |
| 544 | val->intval = value; |
| 545 | |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 546 | return 0; |
| 547 | } |
| 548 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 549 | #define to_bq27x00_device_info(x) container_of((x), \ |
| 550 | struct bq27x00_device_info, bat); |
| 551 | |
| 552 | static int bq27x00_battery_get_property(struct power_supply *psy, |
| 553 | enum power_supply_property psp, |
| 554 | union power_supply_propval *val) |
| 555 | { |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 556 | int ret = 0; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 557 | struct bq27x00_device_info *di = to_bq27x00_device_info(psy); |
Lars-Peter Clausen | 3413b4e | 2010-05-24 21:57:33 +0200 | [diff] [blame] | 558 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 559 | mutex_lock(&di->lock); |
| 560 | if (time_is_before_jiffies(di->last_update + 5 * HZ)) { |
| 561 | cancel_delayed_work_sync(&di->work); |
| 562 | bq27x00_battery_poll(&di->work.work); |
| 563 | } |
| 564 | mutex_unlock(&di->lock); |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 565 | |
| 566 | if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0) |
Lars-Peter Clausen | 3413b4e | 2010-05-24 21:57:33 +0200 | [diff] [blame] | 567 | return -ENODEV; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 568 | |
| 569 | switch (psp) { |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 570 | case POWER_SUPPLY_PROP_STATUS: |
| 571 | ret = bq27x00_battery_status(di, val); |
| 572 | break; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 573 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 574 | ret = bq27x00_battery_voltage(di, val); |
Lars-Peter Clausen | 3413b4e | 2010-05-24 21:57:33 +0200 | [diff] [blame] | 575 | break; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 576 | case POWER_SUPPLY_PROP_PRESENT: |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 577 | val->intval = di->cache.flags < 0 ? 0 : 1; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 578 | break; |
| 579 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 580 | ret = bq27x00_battery_current(di, val); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 581 | break; |
| 582 | case POWER_SUPPLY_PROP_CAPACITY: |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 583 | ret = bq27x00_simple_value(di->cache.capacity, val); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 584 | break; |
Pali Rohár | d66bab3 | 2011-11-01 01:43:04 +0100 | [diff] [blame] | 585 | case POWER_SUPPLY_PROP_CAPACITY_LEVEL: |
| 586 | ret = bq27x00_battery_capacity_level(di, val); |
| 587 | break; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 588 | case POWER_SUPPLY_PROP_TEMP: |
Pali Rohár | d149e98 | 2011-11-01 01:43:07 +0100 | [diff] [blame] | 589 | ret = bq27x00_simple_value(di->cache.temperature, val); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 590 | break; |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 591 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 592 | ret = bq27x00_simple_value(di->cache.time_to_empty, val); |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 593 | break; |
| 594 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 595 | ret = bq27x00_simple_value(di->cache.time_to_empty_avg, val); |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 596 | break; |
| 597 | case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 598 | ret = bq27x00_simple_value(di->cache.time_to_full, val); |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 599 | break; |
Lars-Peter Clausen | 5661f33 | 2010-05-24 20:36:52 +0200 | [diff] [blame] | 600 | case POWER_SUPPLY_PROP_TECHNOLOGY: |
| 601 | val->intval = POWER_SUPPLY_TECHNOLOGY_LION; |
| 602 | break; |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 603 | case POWER_SUPPLY_PROP_CHARGE_NOW: |
| 604 | ret = bq27x00_simple_value(bq27x00_battery_read_nac(di), val); |
| 605 | break; |
| 606 | case POWER_SUPPLY_PROP_CHARGE_FULL: |
| 607 | ret = bq27x00_simple_value(di->cache.charge_full, val); |
| 608 | break; |
| 609 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: |
| 610 | ret = bq27x00_simple_value(di->charge_design_full, val); |
| 611 | break; |
Pali Rohár | 73c244a | 2011-04-30 23:59:35 +0200 | [diff] [blame] | 612 | case POWER_SUPPLY_PROP_CYCLE_COUNT: |
| 613 | ret = bq27x00_simple_value(di->cache.cycle_count, val); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 614 | break; |
| 615 | case POWER_SUPPLY_PROP_ENERGY_NOW: |
Pali Rohár | a8f6bd2 | 2011-11-01 01:43:06 +0100 | [diff] [blame] | 616 | ret = bq27x00_simple_value(di->cache.energy, val); |
Pali Rohár | 631c17e | 2011-02-01 00:08:02 +0100 | [diff] [blame] | 617 | break; |
Syed Rafiuddin | 9903e62 | 2012-05-17 12:51:15 +0530 | [diff] [blame^] | 618 | case POWER_SUPPLY_PROP_POWER_AVG: |
| 619 | ret = bq27x00_simple_value(di->cache.power_avg, val); |
| 620 | break; |
| 621 | case POWER_SUPPLY_PROP_HEALTH: |
| 622 | ret = bq27x00_simple_value(di->cache.health, val); |
| 623 | break; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 624 | default: |
| 625 | return -EINVAL; |
| 626 | } |
| 627 | |
Grazvydas Ignotas | 4e924a8 | 2010-02-27 17:06:09 +0200 | [diff] [blame] | 628 | return ret; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 631 | static void bq27x00_external_power_changed(struct power_supply *psy) |
| 632 | { |
| 633 | struct bq27x00_device_info *di = to_bq27x00_device_info(psy); |
| 634 | |
| 635 | cancel_delayed_work_sync(&di->work); |
| 636 | schedule_delayed_work(&di->work, 0); |
| 637 | } |
| 638 | |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 639 | static int bq27x00_powersupply_init(struct bq27x00_device_info *di) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 640 | { |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 641 | int ret; |
| 642 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 643 | di->bat.type = POWER_SUPPLY_TYPE_BATTERY; |
| 644 | di->bat.properties = bq27x00_battery_props; |
| 645 | di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props); |
| 646 | di->bat.get_property = bq27x00_battery_get_property; |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 647 | di->bat.external_power_changed = bq27x00_external_power_changed; |
| 648 | |
| 649 | INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll); |
| 650 | mutex_init(&di->lock); |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 651 | |
| 652 | ret = power_supply_register(di->dev, &di->bat); |
| 653 | if (ret) { |
| 654 | dev_err(di->dev, "failed to register battery: %d\n", ret); |
| 655 | return ret; |
| 656 | } |
| 657 | |
| 658 | dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION); |
| 659 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 660 | bq27x00_update(di); |
| 661 | |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 662 | return 0; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 665 | static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di) |
| 666 | { |
Pali Rohár | 8cfaaa8 | 2011-11-01 01:43:11 +0100 | [diff] [blame] | 667 | /* |
| 668 | * power_supply_unregister call bq27x00_battery_get_property which |
| 669 | * call bq27x00_battery_poll. |
| 670 | * Make sure that bq27x00_battery_poll will not call |
| 671 | * schedule_delayed_work again after unregister (which cause OOPS). |
| 672 | */ |
| 673 | poll_interval = 0; |
| 674 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 675 | cancel_delayed_work_sync(&di->work); |
| 676 | |
| 677 | power_supply_unregister(&di->bat); |
| 678 | |
| 679 | mutex_destroy(&di->lock); |
| 680 | } |
| 681 | |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 682 | |
| 683 | /* i2c specific code */ |
| 684 | #ifdef CONFIG_BATTERY_BQ27X00_I2C |
| 685 | |
| 686 | /* If the system has several batteries we need a different name for each |
| 687 | * of them... |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 688 | */ |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 689 | static DEFINE_IDR(battery_id); |
| 690 | static DEFINE_MUTEX(battery_mutex); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 691 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 692 | static int bq27x00_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 693 | { |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 694 | struct i2c_client *client = to_i2c_client(di->dev); |
Grazvydas Ignotas | 9e912f4 | 2011-02-15 23:27:35 +0200 | [diff] [blame] | 695 | struct i2c_msg msg[2]; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 696 | unsigned char data[2]; |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 697 | int ret; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 698 | |
| 699 | if (!client->adapter) |
| 700 | return -ENODEV; |
| 701 | |
Grazvydas Ignotas | 9e912f4 | 2011-02-15 23:27:35 +0200 | [diff] [blame] | 702 | msg[0].addr = client->addr; |
| 703 | msg[0].flags = 0; |
| 704 | msg[0].buf = ® |
| 705 | msg[0].len = sizeof(reg); |
| 706 | msg[1].addr = client->addr; |
| 707 | msg[1].flags = I2C_M_RD; |
| 708 | msg[1].buf = data; |
Lars-Peter Clausen | 2ec523a | 2011-02-02 19:35:07 +0100 | [diff] [blame] | 709 | if (single) |
Grazvydas Ignotas | 9e912f4 | 2011-02-15 23:27:35 +0200 | [diff] [blame] | 710 | msg[1].len = 1; |
Lars-Peter Clausen | 2ec523a | 2011-02-02 19:35:07 +0100 | [diff] [blame] | 711 | else |
Grazvydas Ignotas | 9e912f4 | 2011-02-15 23:27:35 +0200 | [diff] [blame] | 712 | msg[1].len = 2; |
Lars-Peter Clausen | 2ec523a | 2011-02-02 19:35:07 +0100 | [diff] [blame] | 713 | |
Grazvydas Ignotas | 9e912f4 | 2011-02-15 23:27:35 +0200 | [diff] [blame] | 714 | ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); |
Lars-Peter Clausen | 2ec523a | 2011-02-02 19:35:07 +0100 | [diff] [blame] | 715 | if (ret < 0) |
| 716 | return ret; |
| 717 | |
| 718 | if (!single) |
| 719 | ret = get_unaligned_le16(data); |
| 720 | else |
| 721 | ret = data[0]; |
| 722 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 723 | return ret; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 726 | static int bq27x00_battery_probe(struct i2c_client *client, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 727 | const struct i2c_device_id *id) |
| 728 | { |
| 729 | char *name; |
| 730 | struct bq27x00_device_info *di; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 731 | int num; |
| 732 | int retval = 0; |
| 733 | |
| 734 | /* Get new ID for the new battery device */ |
| 735 | retval = idr_pre_get(&battery_id, GFP_KERNEL); |
| 736 | if (retval == 0) |
| 737 | return -ENOMEM; |
| 738 | mutex_lock(&battery_mutex); |
| 739 | retval = idr_get_new(&battery_id, client, &num); |
| 740 | mutex_unlock(&battery_mutex); |
| 741 | if (retval < 0) |
| 742 | return retval; |
| 743 | |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 744 | name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 745 | if (!name) { |
| 746 | dev_err(&client->dev, "failed to allocate device name\n"); |
| 747 | retval = -ENOMEM; |
| 748 | goto batt_failed_1; |
| 749 | } |
| 750 | |
| 751 | di = kzalloc(sizeof(*di), GFP_KERNEL); |
| 752 | if (!di) { |
| 753 | dev_err(&client->dev, "failed to allocate device info data\n"); |
| 754 | retval = -ENOMEM; |
| 755 | goto batt_failed_2; |
| 756 | } |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 757 | |
Lars-Peter Clausen | a40402e | 2010-05-24 19:37:58 +0200 | [diff] [blame] | 758 | di->id = num; |
| 759 | di->dev = &client->dev; |
| 760 | di->chip = id->driver_data; |
| 761 | di->bat.name = name; |
| 762 | di->bus.read = &bq27x00_read_i2c; |
| 763 | |
| 764 | if (bq27x00_powersupply_init(di)) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 765 | goto batt_failed_3; |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 766 | |
| 767 | i2c_set_clientdata(client, di); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 768 | |
| 769 | return 0; |
| 770 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 771 | batt_failed_3: |
| 772 | kfree(di); |
| 773 | batt_failed_2: |
| 774 | kfree(name); |
| 775 | batt_failed_1: |
| 776 | mutex_lock(&battery_mutex); |
| 777 | idr_remove(&battery_id, num); |
| 778 | mutex_unlock(&battery_mutex); |
| 779 | |
| 780 | return retval; |
| 781 | } |
| 782 | |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 783 | static int bq27x00_battery_remove(struct i2c_client *client) |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 784 | { |
| 785 | struct bq27x00_device_info *di = i2c_get_clientdata(client); |
| 786 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 787 | bq27x00_powersupply_unregister(di); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 788 | |
| 789 | kfree(di->bat.name); |
| 790 | |
| 791 | mutex_lock(&battery_mutex); |
| 792 | idr_remove(&battery_id, di->id); |
| 793 | mutex_unlock(&battery_mutex); |
| 794 | |
| 795 | kfree(di); |
| 796 | |
| 797 | return 0; |
| 798 | } |
| 799 | |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 800 | static const struct i2c_device_id bq27x00_id[] = { |
| 801 | { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */ |
| 802 | { "bq27500", BQ27500 }, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 803 | {}, |
| 804 | }; |
Pali Rohár | fd9b958 | 2011-02-01 00:10:41 +0100 | [diff] [blame] | 805 | MODULE_DEVICE_TABLE(i2c, bq27x00_id); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 806 | |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 807 | static struct i2c_driver bq27x00_battery_driver = { |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 808 | .driver = { |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 809 | .name = "bq27x00-battery", |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 810 | }, |
Grazvydas Ignotas | e20908d | 2010-02-12 23:57:23 +0200 | [diff] [blame] | 811 | .probe = bq27x00_battery_probe, |
| 812 | .remove = bq27x00_battery_remove, |
| 813 | .id_table = bq27x00_id, |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 814 | }; |
| 815 | |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 816 | static inline int bq27x00_battery_i2c_init(void) |
| 817 | { |
| 818 | int ret = i2c_add_driver(&bq27x00_battery_driver); |
| 819 | if (ret) |
| 820 | printk(KERN_ERR "Unable to register BQ27x00 i2c driver\n"); |
| 821 | |
| 822 | return ret; |
| 823 | } |
| 824 | |
| 825 | static inline void bq27x00_battery_i2c_exit(void) |
| 826 | { |
| 827 | i2c_del_driver(&bq27x00_battery_driver); |
| 828 | } |
| 829 | |
| 830 | #else |
| 831 | |
| 832 | static inline int bq27x00_battery_i2c_init(void) { return 0; } |
| 833 | static inline void bq27x00_battery_i2c_exit(void) {}; |
| 834 | |
| 835 | #endif |
| 836 | |
| 837 | /* platform specific code */ |
| 838 | #ifdef CONFIG_BATTERY_BQ27X00_PLATFORM |
| 839 | |
| 840 | static int bq27000_read_platform(struct bq27x00_device_info *di, u8 reg, |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 841 | bool single) |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 842 | { |
| 843 | struct device *dev = di->dev; |
| 844 | struct bq27000_platform_data *pdata = dev->platform_data; |
| 845 | unsigned int timeout = 3; |
| 846 | int upper, lower; |
| 847 | int temp; |
| 848 | |
| 849 | if (!single) { |
| 850 | /* Make sure the value has not changed in between reading the |
| 851 | * lower and the upper part */ |
| 852 | upper = pdata->read(dev, reg + 1); |
| 853 | do { |
| 854 | temp = upper; |
| 855 | if (upper < 0) |
| 856 | return upper; |
| 857 | |
| 858 | lower = pdata->read(dev, reg); |
| 859 | if (lower < 0) |
| 860 | return lower; |
| 861 | |
| 862 | upper = pdata->read(dev, reg + 1); |
| 863 | } while (temp != upper && --timeout); |
| 864 | |
| 865 | if (timeout == 0) |
| 866 | return -EIO; |
| 867 | |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 868 | return (upper << 8) | lower; |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 869 | } |
Lars-Peter Clausen | 297a533 | 2011-01-07 20:12:47 +0100 | [diff] [blame] | 870 | |
| 871 | return pdata->read(dev, reg); |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | static int __devinit bq27000_battery_probe(struct platform_device *pdev) |
| 875 | { |
| 876 | struct bq27x00_device_info *di; |
| 877 | struct bq27000_platform_data *pdata = pdev->dev.platform_data; |
| 878 | int ret; |
| 879 | |
| 880 | if (!pdata) { |
| 881 | dev_err(&pdev->dev, "no platform_data supplied\n"); |
| 882 | return -EINVAL; |
| 883 | } |
| 884 | |
| 885 | if (!pdata->read) { |
| 886 | dev_err(&pdev->dev, "no hdq read callback supplied\n"); |
| 887 | return -EINVAL; |
| 888 | } |
| 889 | |
| 890 | di = kzalloc(sizeof(*di), GFP_KERNEL); |
| 891 | if (!di) { |
| 892 | dev_err(&pdev->dev, "failed to allocate device info data\n"); |
| 893 | return -ENOMEM; |
| 894 | } |
| 895 | |
| 896 | platform_set_drvdata(pdev, di); |
| 897 | |
| 898 | di->dev = &pdev->dev; |
| 899 | di->chip = BQ27000; |
| 900 | |
| 901 | di->bat.name = pdata->name ?: dev_name(&pdev->dev); |
| 902 | di->bus.read = &bq27000_read_platform; |
| 903 | |
| 904 | ret = bq27x00_powersupply_init(di); |
| 905 | if (ret) |
| 906 | goto err_free; |
| 907 | |
| 908 | return 0; |
| 909 | |
| 910 | err_free: |
| 911 | platform_set_drvdata(pdev, NULL); |
| 912 | kfree(di); |
| 913 | |
| 914 | return ret; |
| 915 | } |
| 916 | |
| 917 | static int __devexit bq27000_battery_remove(struct platform_device *pdev) |
| 918 | { |
| 919 | struct bq27x00_device_info *di = platform_get_drvdata(pdev); |
| 920 | |
Lars-Peter Clausen | 740b755 | 2011-01-07 20:14:53 +0100 | [diff] [blame] | 921 | bq27x00_powersupply_unregister(di); |
| 922 | |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 923 | platform_set_drvdata(pdev, NULL); |
| 924 | kfree(di); |
| 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | static struct platform_driver bq27000_battery_driver = { |
| 930 | .probe = bq27000_battery_probe, |
| 931 | .remove = __devexit_p(bq27000_battery_remove), |
| 932 | .driver = { |
| 933 | .name = "bq27000-battery", |
| 934 | .owner = THIS_MODULE, |
| 935 | }, |
| 936 | }; |
| 937 | |
| 938 | static inline int bq27x00_battery_platform_init(void) |
| 939 | { |
| 940 | int ret = platform_driver_register(&bq27000_battery_driver); |
| 941 | if (ret) |
| 942 | printk(KERN_ERR "Unable to register BQ27000 platform driver\n"); |
| 943 | |
| 944 | return ret; |
| 945 | } |
| 946 | |
| 947 | static inline void bq27x00_battery_platform_exit(void) |
| 948 | { |
| 949 | platform_driver_unregister(&bq27000_battery_driver); |
| 950 | } |
| 951 | |
| 952 | #else |
| 953 | |
| 954 | static inline int bq27x00_battery_platform_init(void) { return 0; } |
| 955 | static inline void bq27x00_battery_platform_exit(void) {}; |
| 956 | |
| 957 | #endif |
| 958 | |
| 959 | /* |
| 960 | * Module stuff |
| 961 | */ |
| 962 | |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 963 | static int __init bq27x00_battery_init(void) |
| 964 | { |
| 965 | int ret; |
| 966 | |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 967 | ret = bq27x00_battery_i2c_init(); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 968 | if (ret) |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 969 | return ret; |
| 970 | |
| 971 | ret = bq27x00_battery_platform_init(); |
| 972 | if (ret) |
| 973 | bq27x00_battery_i2c_exit(); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 974 | |
| 975 | return ret; |
| 976 | } |
| 977 | module_init(bq27x00_battery_init); |
| 978 | |
| 979 | static void __exit bq27x00_battery_exit(void) |
| 980 | { |
Lars-Peter Clausen | 7fb7ba5 | 2010-05-24 19:55:27 +0200 | [diff] [blame] | 981 | bq27x00_battery_platform_exit(); |
| 982 | bq27x00_battery_i2c_exit(); |
Rodolfo Giometti | b996ad0 | 2008-08-20 16:52:58 -0700 | [diff] [blame] | 983 | } |
| 984 | module_exit(bq27x00_battery_exit); |
| 985 | |
| 986 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); |
| 987 | MODULE_DESCRIPTION("BQ27x00 battery monitor driver"); |
| 988 | MODULE_LICENSE("GPL"); |