sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / power / supply / bq27xxx_battery.c
blob08c36b8e04bd6c804c9a94a421c9b6a2fb1dcab9
1 /*
2 * BQ27xxx battery driver
4 * Copyright (C) 2008 Rodolfo Giometti <giometti@linux.it>
5 * Copyright (C) 2008 Eurotech S.p.A. <info@eurotech.it>
6 * Copyright (C) 2010-2011 Lars-Peter Clausen <lars@metafoo.de>
7 * Copyright (C) 2011 Pali Rohár <pali.rohar@gmail.com>
9 * Based on a previous work by Copyright (C) 2008 Texas Instruments, Inc.
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.
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.
19 * Datasheets:
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
35 * http://www.ti.com/product/bq27425-g1
36 * http://www.ti.com/product/bq27411-g1
37 * http://www.ti.com/product/bq27621-g1
40 #include <linux/device.h>
41 #include <linux/module.h>
42 #include <linux/mutex.h>
43 #include <linux/param.h>
44 #include <linux/jiffies.h>
45 #include <linux/workqueue.h>
46 #include <linux/delay.h>
47 #include <linux/platform_device.h>
48 #include <linux/power_supply.h>
49 #include <linux/slab.h>
50 #include <linux/of.h>
52 #include <linux/power/bq27xxx_battery.h>
54 #define DRIVER_VERSION "1.2.0"
56 #define BQ27XXX_MANUFACTURER "Texas Instruments"
58 /* BQ27XXX Flags */
59 #define BQ27XXX_FLAG_DSC BIT(0)
60 #define BQ27XXX_FLAG_SOCF BIT(1) /* State-of-Charge threshold final */
61 #define BQ27XXX_FLAG_SOC1 BIT(2) /* State-of-Charge threshold 1 */
62 #define BQ27XXX_FLAG_FC BIT(9)
63 #define BQ27XXX_FLAG_OTD BIT(14)
64 #define BQ27XXX_FLAG_OTC BIT(15)
65 #define BQ27XXX_FLAG_UT BIT(14)
66 #define BQ27XXX_FLAG_OT BIT(15)
68 /* BQ27000 has different layout for Flags register */
69 #define BQ27000_FLAG_EDVF BIT(0) /* Final End-of-Discharge-Voltage flag */
70 #define BQ27000_FLAG_EDV1 BIT(1) /* First End-of-Discharge-Voltage flag */
71 #define BQ27000_FLAG_CI BIT(4) /* Capacity Inaccurate flag */
72 #define BQ27000_FLAG_FC BIT(5)
73 #define BQ27000_FLAG_CHGS BIT(7) /* Charge state flag */
75 #define BQ27XXX_RS (20) /* Resistor sense mOhm */
76 #define BQ27XXX_POWER_CONSTANT (29200) /* 29.2 µV^2 * 1000 */
77 #define BQ27XXX_CURRENT_CONSTANT (3570) /* 3.57 µV * 1000 */
79 #define INVALID_REG_ADDR 0xff
82 * bq27xxx_reg_index - Register names
84 * These are indexes into a device's register mapping array.
87 enum bq27xxx_reg_index {
88 BQ27XXX_REG_CTRL = 0, /* Control */
89 BQ27XXX_REG_TEMP, /* Temperature */
90 BQ27XXX_REG_INT_TEMP, /* Internal Temperature */
91 BQ27XXX_REG_VOLT, /* Voltage */
92 BQ27XXX_REG_AI, /* Average Current */
93 BQ27XXX_REG_FLAGS, /* Flags */
94 BQ27XXX_REG_TTE, /* Time-to-Empty */
95 BQ27XXX_REG_TTF, /* Time-to-Full */
96 BQ27XXX_REG_TTES, /* Time-to-Empty Standby */
97 BQ27XXX_REG_TTECP, /* Time-to-Empty at Constant Power */
98 BQ27XXX_REG_NAC, /* Nominal Available Capacity */
99 BQ27XXX_REG_FCC, /* Full Charge Capacity */
100 BQ27XXX_REG_CYCT, /* Cycle Count */
101 BQ27XXX_REG_AE, /* Available Energy */
102 BQ27XXX_REG_SOC, /* State-of-Charge */
103 BQ27XXX_REG_DCAP, /* Design Capacity */
104 BQ27XXX_REG_AP, /* Average Power */
105 BQ27XXX_REG_MAX, /* sentinel */
108 /* Register mappings */
109 static u8 bq27xxx_regs[][BQ27XXX_REG_MAX] = {
110 [BQ27000] = {
111 [BQ27XXX_REG_CTRL] = 0x00,
112 [BQ27XXX_REG_TEMP] = 0x06,
113 [BQ27XXX_REG_INT_TEMP] = INVALID_REG_ADDR,
114 [BQ27XXX_REG_VOLT] = 0x08,
115 [BQ27XXX_REG_AI] = 0x14,
116 [BQ27XXX_REG_FLAGS] = 0x0a,
117 [BQ27XXX_REG_TTE] = 0x16,
118 [BQ27XXX_REG_TTF] = 0x18,
119 [BQ27XXX_REG_TTES] = 0x1c,
120 [BQ27XXX_REG_TTECP] = 0x26,
121 [BQ27XXX_REG_NAC] = 0x0c,
122 [BQ27XXX_REG_FCC] = 0x12,
123 [BQ27XXX_REG_CYCT] = 0x2a,
124 [BQ27XXX_REG_AE] = 0x22,
125 [BQ27XXX_REG_SOC] = 0x0b,
126 [BQ27XXX_REG_DCAP] = 0x76,
127 [BQ27XXX_REG_AP] = 0x24,
129 [BQ27010] = {
130 [BQ27XXX_REG_CTRL] = 0x00,
131 [BQ27XXX_REG_TEMP] = 0x06,
132 [BQ27XXX_REG_INT_TEMP] = INVALID_REG_ADDR,
133 [BQ27XXX_REG_VOLT] = 0x08,
134 [BQ27XXX_REG_AI] = 0x14,
135 [BQ27XXX_REG_FLAGS] = 0x0a,
136 [BQ27XXX_REG_TTE] = 0x16,
137 [BQ27XXX_REG_TTF] = 0x18,
138 [BQ27XXX_REG_TTES] = 0x1c,
139 [BQ27XXX_REG_TTECP] = 0x26,
140 [BQ27XXX_REG_NAC] = 0x0c,
141 [BQ27XXX_REG_FCC] = 0x12,
142 [BQ27XXX_REG_CYCT] = 0x2a,
143 [BQ27XXX_REG_AE] = INVALID_REG_ADDR,
144 [BQ27XXX_REG_SOC] = 0x0b,
145 [BQ27XXX_REG_DCAP] = 0x76,
146 [BQ27XXX_REG_AP] = INVALID_REG_ADDR,
148 [BQ27500] = {
149 [BQ27XXX_REG_CTRL] = 0x00,
150 [BQ27XXX_REG_TEMP] = 0x06,
151 [BQ27XXX_REG_INT_TEMP] = 0x28,
152 [BQ27XXX_REG_VOLT] = 0x08,
153 [BQ27XXX_REG_AI] = 0x14,
154 [BQ27XXX_REG_FLAGS] = 0x0a,
155 [BQ27XXX_REG_TTE] = 0x16,
156 [BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
157 [BQ27XXX_REG_TTES] = 0x1a,
158 [BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
159 [BQ27XXX_REG_NAC] = 0x0c,
160 [BQ27XXX_REG_FCC] = 0x12,
161 [BQ27XXX_REG_CYCT] = 0x2a,
162 [BQ27XXX_REG_AE] = INVALID_REG_ADDR,
163 [BQ27XXX_REG_SOC] = 0x2c,
164 [BQ27XXX_REG_DCAP] = 0x3c,
165 [BQ27XXX_REG_AP] = INVALID_REG_ADDR,
167 [BQ27510] = {
168 [BQ27XXX_REG_CTRL] = 0x00,
169 [BQ27XXX_REG_TEMP] = 0x06,
170 [BQ27XXX_REG_INT_TEMP] = 0x28,
171 [BQ27XXX_REG_VOLT] = 0x08,
172 [BQ27XXX_REG_AI] = 0x14,
173 [BQ27XXX_REG_FLAGS] = 0x0a,
174 [BQ27XXX_REG_TTE] = 0x16,
175 [BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
176 [BQ27XXX_REG_TTES] = 0x1a,
177 [BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
178 [BQ27XXX_REG_NAC] = 0x0c,
179 [BQ27XXX_REG_FCC] = 0x12,
180 [BQ27XXX_REG_CYCT] = 0x1e,
181 [BQ27XXX_REG_AE] = INVALID_REG_ADDR,
182 [BQ27XXX_REG_SOC] = 0x20,
183 [BQ27XXX_REG_DCAP] = 0x2e,
184 [BQ27XXX_REG_AP] = INVALID_REG_ADDR,
186 [BQ27530] = {
187 [BQ27XXX_REG_CTRL] = 0x00,
188 [BQ27XXX_REG_TEMP] = 0x06,
189 [BQ27XXX_REG_INT_TEMP] = 0x32,
190 [BQ27XXX_REG_VOLT] = 0x08,
191 [BQ27XXX_REG_AI] = 0x14,
192 [BQ27XXX_REG_FLAGS] = 0x0a,
193 [BQ27XXX_REG_TTE] = 0x16,
194 [BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
195 [BQ27XXX_REG_TTES] = INVALID_REG_ADDR,
196 [BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
197 [BQ27XXX_REG_NAC] = 0x0c,
198 [BQ27XXX_REG_FCC] = 0x12,
199 [BQ27XXX_REG_CYCT] = 0x2a,
200 [BQ27XXX_REG_AE] = INVALID_REG_ADDR,
201 [BQ27XXX_REG_SOC] = 0x2c,
202 [BQ27XXX_REG_DCAP] = INVALID_REG_ADDR,
203 [BQ27XXX_REG_AP] = 0x24,
205 [BQ27541] = {
206 [BQ27XXX_REG_CTRL] = 0x00,
207 [BQ27XXX_REG_TEMP] = 0x06,
208 [BQ27XXX_REG_INT_TEMP] = 0x28,
209 [BQ27XXX_REG_VOLT] = 0x08,
210 [BQ27XXX_REG_AI] = 0x14,
211 [BQ27XXX_REG_FLAGS] = 0x0a,
212 [BQ27XXX_REG_TTE] = 0x16,
213 [BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
214 [BQ27XXX_REG_TTES] = INVALID_REG_ADDR,
215 [BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
216 [BQ27XXX_REG_NAC] = 0x0c,
217 [BQ27XXX_REG_FCC] = 0x12,
218 [BQ27XXX_REG_CYCT] = 0x2a,
219 [BQ27XXX_REG_AE] = INVALID_REG_ADDR,
220 [BQ27XXX_REG_SOC] = 0x2c,
221 [BQ27XXX_REG_DCAP] = 0x3c,
222 [BQ27XXX_REG_AP] = 0x24,
224 [BQ27545] = {
225 [BQ27XXX_REG_CTRL] = 0x00,
226 [BQ27XXX_REG_TEMP] = 0x06,
227 [BQ27XXX_REG_INT_TEMP] = 0x28,
228 [BQ27XXX_REG_VOLT] = 0x08,
229 [BQ27XXX_REG_AI] = 0x14,
230 [BQ27XXX_REG_FLAGS] = 0x0a,
231 [BQ27XXX_REG_TTE] = 0x16,
232 [BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
233 [BQ27XXX_REG_TTES] = INVALID_REG_ADDR,
234 [BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
235 [BQ27XXX_REG_NAC] = 0x0c,
236 [BQ27XXX_REG_FCC] = 0x12,
237 [BQ27XXX_REG_CYCT] = 0x2a,
238 [BQ27XXX_REG_AE] = INVALID_REG_ADDR,
239 [BQ27XXX_REG_SOC] = 0x2c,
240 [BQ27XXX_REG_DCAP] = INVALID_REG_ADDR,
241 [BQ27XXX_REG_AP] = 0x24,
243 [BQ27421] = {
244 [BQ27XXX_REG_CTRL] = 0x00,
245 [BQ27XXX_REG_TEMP] = 0x02,
246 [BQ27XXX_REG_INT_TEMP] = 0x1e,
247 [BQ27XXX_REG_VOLT] = 0x04,
248 [BQ27XXX_REG_AI] = 0x10,
249 [BQ27XXX_REG_FLAGS] = 0x06,
250 [BQ27XXX_REG_TTE] = INVALID_REG_ADDR,
251 [BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
252 [BQ27XXX_REG_TTES] = INVALID_REG_ADDR,
253 [BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
254 [BQ27XXX_REG_NAC] = 0x08,
255 [BQ27XXX_REG_FCC] = 0x0e,
256 [BQ27XXX_REG_CYCT] = INVALID_REG_ADDR,
257 [BQ27XXX_REG_AE] = INVALID_REG_ADDR,
258 [BQ27XXX_REG_SOC] = 0x1c,
259 [BQ27XXX_REG_DCAP] = 0x3c,
260 [BQ27XXX_REG_AP] = 0x18,
264 static enum power_supply_property bq27000_battery_props[] = {
265 POWER_SUPPLY_PROP_STATUS,
266 POWER_SUPPLY_PROP_PRESENT,
267 POWER_SUPPLY_PROP_VOLTAGE_NOW,
268 POWER_SUPPLY_PROP_CURRENT_NOW,
269 POWER_SUPPLY_PROP_CAPACITY,
270 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
271 POWER_SUPPLY_PROP_TEMP,
272 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
273 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
274 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
275 POWER_SUPPLY_PROP_TECHNOLOGY,
276 POWER_SUPPLY_PROP_CHARGE_FULL,
277 POWER_SUPPLY_PROP_CHARGE_NOW,
278 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
279 POWER_SUPPLY_PROP_CYCLE_COUNT,
280 POWER_SUPPLY_PROP_ENERGY_NOW,
281 POWER_SUPPLY_PROP_POWER_AVG,
282 POWER_SUPPLY_PROP_HEALTH,
283 POWER_SUPPLY_PROP_MANUFACTURER,
286 static enum power_supply_property bq27010_battery_props[] = {
287 POWER_SUPPLY_PROP_STATUS,
288 POWER_SUPPLY_PROP_PRESENT,
289 POWER_SUPPLY_PROP_VOLTAGE_NOW,
290 POWER_SUPPLY_PROP_CURRENT_NOW,
291 POWER_SUPPLY_PROP_CAPACITY,
292 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
293 POWER_SUPPLY_PROP_TEMP,
294 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
295 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
296 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
297 POWER_SUPPLY_PROP_TECHNOLOGY,
298 POWER_SUPPLY_PROP_CHARGE_FULL,
299 POWER_SUPPLY_PROP_CHARGE_NOW,
300 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
301 POWER_SUPPLY_PROP_CYCLE_COUNT,
302 POWER_SUPPLY_PROP_HEALTH,
303 POWER_SUPPLY_PROP_MANUFACTURER,
306 static enum power_supply_property bq27500_battery_props[] = {
307 POWER_SUPPLY_PROP_STATUS,
308 POWER_SUPPLY_PROP_PRESENT,
309 POWER_SUPPLY_PROP_VOLTAGE_NOW,
310 POWER_SUPPLY_PROP_CURRENT_NOW,
311 POWER_SUPPLY_PROP_CAPACITY,
312 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
313 POWER_SUPPLY_PROP_TEMP,
314 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
315 POWER_SUPPLY_PROP_TECHNOLOGY,
316 POWER_SUPPLY_PROP_CHARGE_FULL,
317 POWER_SUPPLY_PROP_CHARGE_NOW,
318 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
319 POWER_SUPPLY_PROP_CYCLE_COUNT,
320 POWER_SUPPLY_PROP_HEALTH,
321 POWER_SUPPLY_PROP_MANUFACTURER,
324 static enum power_supply_property bq27510_battery_props[] = {
325 POWER_SUPPLY_PROP_STATUS,
326 POWER_SUPPLY_PROP_PRESENT,
327 POWER_SUPPLY_PROP_VOLTAGE_NOW,
328 POWER_SUPPLY_PROP_CURRENT_NOW,
329 POWER_SUPPLY_PROP_CAPACITY,
330 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
331 POWER_SUPPLY_PROP_TEMP,
332 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
333 POWER_SUPPLY_PROP_TECHNOLOGY,
334 POWER_SUPPLY_PROP_CHARGE_FULL,
335 POWER_SUPPLY_PROP_CHARGE_NOW,
336 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
337 POWER_SUPPLY_PROP_CYCLE_COUNT,
338 POWER_SUPPLY_PROP_HEALTH,
339 POWER_SUPPLY_PROP_MANUFACTURER,
342 static enum power_supply_property bq27530_battery_props[] = {
343 POWER_SUPPLY_PROP_STATUS,
344 POWER_SUPPLY_PROP_PRESENT,
345 POWER_SUPPLY_PROP_VOLTAGE_NOW,
346 POWER_SUPPLY_PROP_CURRENT_NOW,
347 POWER_SUPPLY_PROP_CAPACITY,
348 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
349 POWER_SUPPLY_PROP_TEMP,
350 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
351 POWER_SUPPLY_PROP_TECHNOLOGY,
352 POWER_SUPPLY_PROP_CHARGE_FULL,
353 POWER_SUPPLY_PROP_CHARGE_NOW,
354 POWER_SUPPLY_PROP_POWER_AVG,
355 POWER_SUPPLY_PROP_HEALTH,
356 POWER_SUPPLY_PROP_CYCLE_COUNT,
357 POWER_SUPPLY_PROP_MANUFACTURER,
360 static enum power_supply_property bq27541_battery_props[] = {
361 POWER_SUPPLY_PROP_STATUS,
362 POWER_SUPPLY_PROP_PRESENT,
363 POWER_SUPPLY_PROP_VOLTAGE_NOW,
364 POWER_SUPPLY_PROP_CURRENT_NOW,
365 POWER_SUPPLY_PROP_CAPACITY,
366 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
367 POWER_SUPPLY_PROP_TEMP,
368 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
369 POWER_SUPPLY_PROP_TECHNOLOGY,
370 POWER_SUPPLY_PROP_CHARGE_FULL,
371 POWER_SUPPLY_PROP_CHARGE_NOW,
372 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
373 POWER_SUPPLY_PROP_CYCLE_COUNT,
374 POWER_SUPPLY_PROP_POWER_AVG,
375 POWER_SUPPLY_PROP_HEALTH,
376 POWER_SUPPLY_PROP_MANUFACTURER,
379 static enum power_supply_property bq27545_battery_props[] = {
380 POWER_SUPPLY_PROP_STATUS,
381 POWER_SUPPLY_PROP_PRESENT,
382 POWER_SUPPLY_PROP_VOLTAGE_NOW,
383 POWER_SUPPLY_PROP_CURRENT_NOW,
384 POWER_SUPPLY_PROP_CAPACITY,
385 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
386 POWER_SUPPLY_PROP_TEMP,
387 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
388 POWER_SUPPLY_PROP_TECHNOLOGY,
389 POWER_SUPPLY_PROP_CHARGE_FULL,
390 POWER_SUPPLY_PROP_CHARGE_NOW,
391 POWER_SUPPLY_PROP_HEALTH,
392 POWER_SUPPLY_PROP_CYCLE_COUNT,
393 POWER_SUPPLY_PROP_POWER_AVG,
394 POWER_SUPPLY_PROP_MANUFACTURER,
397 static enum power_supply_property bq27421_battery_props[] = {
398 POWER_SUPPLY_PROP_STATUS,
399 POWER_SUPPLY_PROP_PRESENT,
400 POWER_SUPPLY_PROP_VOLTAGE_NOW,
401 POWER_SUPPLY_PROP_CURRENT_NOW,
402 POWER_SUPPLY_PROP_CAPACITY,
403 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
404 POWER_SUPPLY_PROP_TEMP,
405 POWER_SUPPLY_PROP_TECHNOLOGY,
406 POWER_SUPPLY_PROP_CHARGE_FULL,
407 POWER_SUPPLY_PROP_CHARGE_NOW,
408 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
409 POWER_SUPPLY_PROP_MANUFACTURER,
412 #define BQ27XXX_PROP(_id, _prop) \
413 [_id] = { \
414 .props = _prop, \
415 .size = ARRAY_SIZE(_prop), \
418 static struct {
419 enum power_supply_property *props;
420 size_t size;
421 } bq27xxx_battery_props[] = {
422 BQ27XXX_PROP(BQ27000, bq27000_battery_props),
423 BQ27XXX_PROP(BQ27010, bq27010_battery_props),
424 BQ27XXX_PROP(BQ27500, bq27500_battery_props),
425 BQ27XXX_PROP(BQ27510, bq27510_battery_props),
426 BQ27XXX_PROP(BQ27530, bq27530_battery_props),
427 BQ27XXX_PROP(BQ27541, bq27541_battery_props),
428 BQ27XXX_PROP(BQ27545, bq27545_battery_props),
429 BQ27XXX_PROP(BQ27421, bq27421_battery_props),
432 static DEFINE_MUTEX(bq27xxx_list_lock);
433 static LIST_HEAD(bq27xxx_battery_devices);
435 static int poll_interval_param_set(const char *val, const struct kernel_param *kp)
437 struct bq27xxx_device_info *di;
438 unsigned int prev_val = *(unsigned int *) kp->arg;
439 int ret;
441 ret = param_set_uint(val, kp);
442 if (ret < 0 || prev_val == *(unsigned int *) kp->arg)
443 return ret;
445 mutex_lock(&bq27xxx_list_lock);
446 list_for_each_entry(di, &bq27xxx_battery_devices, list) {
447 cancel_delayed_work_sync(&di->work);
448 schedule_delayed_work(&di->work, 0);
450 mutex_unlock(&bq27xxx_list_lock);
452 return ret;
455 static const struct kernel_param_ops param_ops_poll_interval = {
456 .get = param_get_uint,
457 .set = poll_interval_param_set,
460 static unsigned int poll_interval = 360;
461 module_param_cb(poll_interval, &param_ops_poll_interval, &poll_interval, 0644);
462 MODULE_PARM_DESC(poll_interval,
463 "battery poll interval in seconds - 0 disables polling");
466 * Common code for BQ27xxx devices
469 static inline int bq27xxx_read(struct bq27xxx_device_info *di, int reg_index,
470 bool single)
472 /* Reports EINVAL for invalid/missing registers */
473 if (!di || di->regs[reg_index] == INVALID_REG_ADDR)
474 return -EINVAL;
476 return di->bus.read(di, di->regs[reg_index], single);
480 * Return the battery State-of-Charge
481 * Or < 0 if something fails.
483 static int bq27xxx_battery_read_soc(struct bq27xxx_device_info *di)
485 int soc;
487 if (di->chip == BQ27000 || di->chip == BQ27010)
488 soc = bq27xxx_read(di, BQ27XXX_REG_SOC, true);
489 else
490 soc = bq27xxx_read(di, BQ27XXX_REG_SOC, false);
492 if (soc < 0)
493 dev_dbg(di->dev, "error reading State-of-Charge\n");
495 return soc;
499 * Return a battery charge value in µAh
500 * Or < 0 if something fails.
502 static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
504 int charge;
506 charge = bq27xxx_read(di, reg, false);
507 if (charge < 0) {
508 dev_dbg(di->dev, "error reading charge register %02x: %d\n",
509 reg, charge);
510 return charge;
513 if (di->chip == BQ27000 || di->chip == BQ27010)
514 charge *= BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS;
515 else
516 charge *= 1000;
518 return charge;
522 * Return the battery Nominal available capacity in µAh
523 * Or < 0 if something fails.
525 static inline int bq27xxx_battery_read_nac(struct bq27xxx_device_info *di)
527 int flags;
529 if (di->chip == BQ27000 || di->chip == BQ27010) {
530 flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true);
531 if (flags >= 0 && (flags & BQ27000_FLAG_CI))
532 return -ENODATA;
535 return bq27xxx_battery_read_charge(di, BQ27XXX_REG_NAC);
539 * Return the battery Full Charge Capacity in µAh
540 * Or < 0 if something fails.
542 static inline int bq27xxx_battery_read_fcc(struct bq27xxx_device_info *di)
544 return bq27xxx_battery_read_charge(di, BQ27XXX_REG_FCC);
548 * Return the Design Capacity in µAh
549 * Or < 0 if something fails.
551 static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di)
553 int dcap;
555 if (di->chip == BQ27000 || di->chip == BQ27010)
556 dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, true);
557 else
558 dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, false);
560 if (dcap < 0) {
561 dev_dbg(di->dev, "error reading initial last measured discharge\n");
562 return dcap;
565 if (di->chip == BQ27000 || di->chip == BQ27010)
566 dcap = (dcap << 8) * BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS;
567 else
568 dcap *= 1000;
570 return dcap;
574 * Return the battery Available energy in µWh
575 * Or < 0 if something fails.
577 static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di)
579 int ae;
581 ae = bq27xxx_read(di, BQ27XXX_REG_AE, false);
582 if (ae < 0) {
583 dev_dbg(di->dev, "error reading available energy\n");
584 return ae;
587 if (di->chip == BQ27000 || di->chip == BQ27010)
588 ae *= BQ27XXX_POWER_CONSTANT / BQ27XXX_RS;
589 else
590 ae *= 1000;
592 return ae;
596 * Return the battery temperature in tenths of degree Kelvin
597 * Or < 0 if something fails.
599 static int bq27xxx_battery_read_temperature(struct bq27xxx_device_info *di)
601 int temp;
603 temp = bq27xxx_read(di, BQ27XXX_REG_TEMP, false);
604 if (temp < 0) {
605 dev_err(di->dev, "error reading temperature\n");
606 return temp;
609 if (di->chip == BQ27000 || di->chip == BQ27010)
610 temp = 5 * temp / 2;
612 return temp;
616 * Return the battery Cycle count total
617 * Or < 0 if something fails.
619 static int bq27xxx_battery_read_cyct(struct bq27xxx_device_info *di)
621 int cyct;
623 cyct = bq27xxx_read(di, BQ27XXX_REG_CYCT, false);
624 if (cyct < 0)
625 dev_err(di->dev, "error reading cycle count total\n");
627 return cyct;
631 * Read a time register.
632 * Return < 0 if something fails.
634 static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg)
636 int tval;
638 tval = bq27xxx_read(di, reg, false);
639 if (tval < 0) {
640 dev_dbg(di->dev, "error reading time register %02x: %d\n",
641 reg, tval);
642 return tval;
645 if (tval == 65535)
646 return -ENODATA;
648 return tval * 60;
652 * Read an average power register.
653 * Return < 0 if something fails.
655 static int bq27xxx_battery_read_pwr_avg(struct bq27xxx_device_info *di)
657 int tval;
659 tval = bq27xxx_read(di, BQ27XXX_REG_AP, false);
660 if (tval < 0) {
661 dev_err(di->dev, "error reading average power register %02x: %d\n",
662 BQ27XXX_REG_AP, tval);
663 return tval;
666 if (di->chip == BQ27000 || di->chip == BQ27010)
667 return (tval * BQ27XXX_POWER_CONSTANT) / BQ27XXX_RS;
668 else
669 return tval;
673 * Returns true if a battery over temperature condition is detected
675 static bool bq27xxx_battery_overtemp(struct bq27xxx_device_info *di, u16 flags)
677 if (di->chip == BQ27500 || di->chip == BQ27510 ||
678 di->chip == BQ27541 || di->chip == BQ27545)
679 return flags & (BQ27XXX_FLAG_OTC | BQ27XXX_FLAG_OTD);
680 if (di->chip == BQ27530 || di->chip == BQ27421)
681 return flags & BQ27XXX_FLAG_OT;
683 return false;
687 * Returns true if a battery under temperature condition is detected
689 static bool bq27xxx_battery_undertemp(struct bq27xxx_device_info *di, u16 flags)
691 if (di->chip == BQ27530 || di->chip == BQ27421)
692 return flags & BQ27XXX_FLAG_UT;
694 return false;
698 * Returns true if a low state of charge condition is detected
700 static bool bq27xxx_battery_dead(struct bq27xxx_device_info *di, u16 flags)
702 if (di->chip == BQ27000 || di->chip == BQ27010)
703 return flags & (BQ27000_FLAG_EDV1 | BQ27000_FLAG_EDVF);
704 else
705 return flags & (BQ27XXX_FLAG_SOC1 | BQ27XXX_FLAG_SOCF);
709 * Read flag register.
710 * Return < 0 if something fails.
712 static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
714 int flags;
715 bool has_singe_flag = di->chip == BQ27000 || di->chip == BQ27010;
717 flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
718 if (flags < 0) {
719 dev_err(di->dev, "error reading flag register:%d\n", flags);
720 return flags;
723 /* Unlikely but important to return first */
724 if (unlikely(bq27xxx_battery_overtemp(di, flags)))
725 return POWER_SUPPLY_HEALTH_OVERHEAT;
726 if (unlikely(bq27xxx_battery_undertemp(di, flags)))
727 return POWER_SUPPLY_HEALTH_COLD;
728 if (unlikely(bq27xxx_battery_dead(di, flags)))
729 return POWER_SUPPLY_HEALTH_DEAD;
731 return POWER_SUPPLY_HEALTH_GOOD;
734 void bq27xxx_battery_update(struct bq27xxx_device_info *di)
736 struct bq27xxx_reg_cache cache = {0, };
737 bool has_ci_flag = di->chip == BQ27000 || di->chip == BQ27010;
738 bool has_singe_flag = di->chip == BQ27000 || di->chip == BQ27010;
740 cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
741 if ((cache.flags & 0xff) == 0xff)
742 cache.flags = -1; /* read error */
743 if (cache.flags >= 0) {
744 cache.temperature = bq27xxx_battery_read_temperature(di);
745 if (has_ci_flag && (cache.flags & BQ27000_FLAG_CI)) {
746 dev_info_once(di->dev, "battery is not calibrated! ignoring capacity values\n");
747 cache.capacity = -ENODATA;
748 cache.energy = -ENODATA;
749 cache.time_to_empty = -ENODATA;
750 cache.time_to_empty_avg = -ENODATA;
751 cache.time_to_full = -ENODATA;
752 cache.charge_full = -ENODATA;
753 cache.health = -ENODATA;
754 } else {
755 if (di->regs[BQ27XXX_REG_TTE] != INVALID_REG_ADDR)
756 cache.time_to_empty = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE);
757 if (di->regs[BQ27XXX_REG_TTECP] != INVALID_REG_ADDR)
758 cache.time_to_empty_avg = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTECP);
759 if (di->regs[BQ27XXX_REG_TTF] != INVALID_REG_ADDR)
760 cache.time_to_full = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTF);
761 cache.charge_full = bq27xxx_battery_read_fcc(di);
762 cache.capacity = bq27xxx_battery_read_soc(di);
763 if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR)
764 cache.energy = bq27xxx_battery_read_energy(di);
765 cache.health = bq27xxx_battery_read_health(di);
767 if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR)
768 cache.cycle_count = bq27xxx_battery_read_cyct(di);
769 if (di->regs[BQ27XXX_REG_AP] != INVALID_REG_ADDR)
770 cache.power_avg = bq27xxx_battery_read_pwr_avg(di);
772 /* We only have to read charge design full once */
773 if (di->charge_design_full <= 0)
774 di->charge_design_full = bq27xxx_battery_read_dcap(di);
777 if (di->cache.capacity != cache.capacity)
778 power_supply_changed(di->bat);
780 if (memcmp(&di->cache, &cache, sizeof(cache)) != 0)
781 di->cache = cache;
783 di->last_update = jiffies;
785 EXPORT_SYMBOL_GPL(bq27xxx_battery_update);
787 static void bq27xxx_battery_poll(struct work_struct *work)
789 struct bq27xxx_device_info *di =
790 container_of(work, struct bq27xxx_device_info,
791 work.work);
793 bq27xxx_battery_update(di);
795 if (poll_interval > 0)
796 schedule_delayed_work(&di->work, poll_interval * HZ);
800 * Return the battery average current in µA
801 * Note that current can be negative signed as well
802 * Or 0 if something fails.
804 static int bq27xxx_battery_current(struct bq27xxx_device_info *di,
805 union power_supply_propval *val)
807 int curr;
808 int flags;
810 curr = bq27xxx_read(di, BQ27XXX_REG_AI, false);
811 if (curr < 0) {
812 dev_err(di->dev, "error reading current\n");
813 return curr;
816 if (di->chip == BQ27000 || di->chip == BQ27010) {
817 flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true);
818 if (flags & BQ27000_FLAG_CHGS) {
819 dev_dbg(di->dev, "negative current!\n");
820 curr = -curr;
823 val->intval = curr * BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS;
824 } else {
825 /* Other gauges return signed value */
826 val->intval = (int)((s16)curr) * 1000;
829 return 0;
832 static int bq27xxx_battery_status(struct bq27xxx_device_info *di,
833 union power_supply_propval *val)
835 int status;
837 if (di->chip == BQ27000 || di->chip == BQ27010) {
838 if (di->cache.flags & BQ27000_FLAG_FC)
839 status = POWER_SUPPLY_STATUS_FULL;
840 else if (di->cache.flags & BQ27000_FLAG_CHGS)
841 status = POWER_SUPPLY_STATUS_CHARGING;
842 else if (power_supply_am_i_supplied(di->bat))
843 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
844 else
845 status = POWER_SUPPLY_STATUS_DISCHARGING;
846 } else {
847 if (di->cache.flags & BQ27XXX_FLAG_FC)
848 status = POWER_SUPPLY_STATUS_FULL;
849 else if (di->cache.flags & BQ27XXX_FLAG_DSC)
850 status = POWER_SUPPLY_STATUS_DISCHARGING;
851 else
852 status = POWER_SUPPLY_STATUS_CHARGING;
855 val->intval = status;
857 return 0;
860 static int bq27xxx_battery_capacity_level(struct bq27xxx_device_info *di,
861 union power_supply_propval *val)
863 int level;
865 if (di->chip == BQ27000 || di->chip == BQ27010) {
866 if (di->cache.flags & BQ27000_FLAG_FC)
867 level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
868 else if (di->cache.flags & BQ27000_FLAG_EDV1)
869 level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
870 else if (di->cache.flags & BQ27000_FLAG_EDVF)
871 level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
872 else
873 level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
874 } else {
875 if (di->cache.flags & BQ27XXX_FLAG_FC)
876 level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
877 else if (di->cache.flags & BQ27XXX_FLAG_SOC1)
878 level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
879 else if (di->cache.flags & BQ27XXX_FLAG_SOCF)
880 level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
881 else
882 level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
885 val->intval = level;
887 return 0;
891 * Return the battery Voltage in millivolts
892 * Or < 0 if something fails.
894 static int bq27xxx_battery_voltage(struct bq27xxx_device_info *di,
895 union power_supply_propval *val)
897 int volt;
899 volt = bq27xxx_read(di, BQ27XXX_REG_VOLT, false);
900 if (volt < 0) {
901 dev_err(di->dev, "error reading voltage\n");
902 return volt;
905 val->intval = volt * 1000;
907 return 0;
910 static int bq27xxx_simple_value(int value,
911 union power_supply_propval *val)
913 if (value < 0)
914 return value;
916 val->intval = value;
918 return 0;
921 static int bq27xxx_battery_get_property(struct power_supply *psy,
922 enum power_supply_property psp,
923 union power_supply_propval *val)
925 int ret = 0;
926 struct bq27xxx_device_info *di = power_supply_get_drvdata(psy);
928 mutex_lock(&di->lock);
929 if (time_is_before_jiffies(di->last_update + 5 * HZ)) {
930 cancel_delayed_work_sync(&di->work);
931 bq27xxx_battery_poll(&di->work.work);
933 mutex_unlock(&di->lock);
935 if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0)
936 return -ENODEV;
938 switch (psp) {
939 case POWER_SUPPLY_PROP_STATUS:
940 ret = bq27xxx_battery_status(di, val);
941 break;
942 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
943 ret = bq27xxx_battery_voltage(di, val);
944 break;
945 case POWER_SUPPLY_PROP_PRESENT:
946 val->intval = di->cache.flags < 0 ? 0 : 1;
947 break;
948 case POWER_SUPPLY_PROP_CURRENT_NOW:
949 ret = bq27xxx_battery_current(di, val);
950 break;
951 case POWER_SUPPLY_PROP_CAPACITY:
952 ret = bq27xxx_simple_value(di->cache.capacity, val);
953 break;
954 case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
955 ret = bq27xxx_battery_capacity_level(di, val);
956 break;
957 case POWER_SUPPLY_PROP_TEMP:
958 ret = bq27xxx_simple_value(di->cache.temperature, val);
959 if (ret == 0)
960 val->intval -= 2731; /* convert decidegree k to c */
961 break;
962 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
963 ret = bq27xxx_simple_value(di->cache.time_to_empty, val);
964 break;
965 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
966 ret = bq27xxx_simple_value(di->cache.time_to_empty_avg, val);
967 break;
968 case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
969 ret = bq27xxx_simple_value(di->cache.time_to_full, val);
970 break;
971 case POWER_SUPPLY_PROP_TECHNOLOGY:
972 val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
973 break;
974 case POWER_SUPPLY_PROP_CHARGE_NOW:
975 ret = bq27xxx_simple_value(bq27xxx_battery_read_nac(di), val);
976 break;
977 case POWER_SUPPLY_PROP_CHARGE_FULL:
978 ret = bq27xxx_simple_value(di->cache.charge_full, val);
979 break;
980 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
981 ret = bq27xxx_simple_value(di->charge_design_full, val);
982 break;
983 case POWER_SUPPLY_PROP_CYCLE_COUNT:
984 ret = bq27xxx_simple_value(di->cache.cycle_count, val);
985 break;
986 case POWER_SUPPLY_PROP_ENERGY_NOW:
987 ret = bq27xxx_simple_value(di->cache.energy, val);
988 break;
989 case POWER_SUPPLY_PROP_POWER_AVG:
990 ret = bq27xxx_simple_value(di->cache.power_avg, val);
991 break;
992 case POWER_SUPPLY_PROP_HEALTH:
993 ret = bq27xxx_simple_value(di->cache.health, val);
994 break;
995 case POWER_SUPPLY_PROP_MANUFACTURER:
996 val->strval = BQ27XXX_MANUFACTURER;
997 break;
998 default:
999 return -EINVAL;
1002 return ret;
1005 static void bq27xxx_external_power_changed(struct power_supply *psy)
1007 struct bq27xxx_device_info *di = power_supply_get_drvdata(psy);
1009 cancel_delayed_work_sync(&di->work);
1010 schedule_delayed_work(&di->work, 0);
1013 int bq27xxx_battery_setup(struct bq27xxx_device_info *di)
1015 struct power_supply_desc *psy_desc;
1016 struct power_supply_config psy_cfg = { .drv_data = di, };
1018 INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll);
1019 mutex_init(&di->lock);
1020 di->regs = bq27xxx_regs[di->chip];
1022 psy_desc = devm_kzalloc(di->dev, sizeof(*psy_desc), GFP_KERNEL);
1023 if (!psy_desc)
1024 return -ENOMEM;
1026 psy_desc->name = di->name;
1027 psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
1028 psy_desc->properties = bq27xxx_battery_props[di->chip].props;
1029 psy_desc->num_properties = bq27xxx_battery_props[di->chip].size;
1030 psy_desc->get_property = bq27xxx_battery_get_property;
1031 psy_desc->external_power_changed = bq27xxx_external_power_changed;
1033 di->bat = power_supply_register_no_ws(di->dev, psy_desc, &psy_cfg);
1034 if (IS_ERR(di->bat)) {
1035 dev_err(di->dev, "failed to register battery\n");
1036 return PTR_ERR(di->bat);
1039 dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);
1041 bq27xxx_battery_update(di);
1043 mutex_lock(&bq27xxx_list_lock);
1044 list_add(&di->list, &bq27xxx_battery_devices);
1045 mutex_unlock(&bq27xxx_list_lock);
1047 return 0;
1049 EXPORT_SYMBOL_GPL(bq27xxx_battery_setup);
1051 void bq27xxx_battery_teardown(struct bq27xxx_device_info *di)
1054 * power_supply_unregister call bq27xxx_battery_get_property which
1055 * call bq27xxx_battery_poll.
1056 * Make sure that bq27xxx_battery_poll will not call
1057 * schedule_delayed_work again after unregister (which cause OOPS).
1059 poll_interval = 0;
1061 cancel_delayed_work_sync(&di->work);
1063 power_supply_unregister(di->bat);
1065 mutex_lock(&bq27xxx_list_lock);
1066 list_del(&di->list);
1067 mutex_unlock(&bq27xxx_list_lock);
1069 mutex_destroy(&di->lock);
1071 EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown);
1073 static int bq27xxx_battery_platform_read(struct bq27xxx_device_info *di, u8 reg,
1074 bool single)
1076 struct device *dev = di->dev;
1077 struct bq27xxx_platform_data *pdata = dev->platform_data;
1078 unsigned int timeout = 3;
1079 int upper, lower;
1080 int temp;
1082 if (!single) {
1083 /* Make sure the value has not changed in between reading the
1084 * lower and the upper part */
1085 upper = pdata->read(dev, reg + 1);
1086 do {
1087 temp = upper;
1088 if (upper < 0)
1089 return upper;
1091 lower = pdata->read(dev, reg);
1092 if (lower < 0)
1093 return lower;
1095 upper = pdata->read(dev, reg + 1);
1096 } while (temp != upper && --timeout);
1098 if (timeout == 0)
1099 return -EIO;
1101 return (upper << 8) | lower;
1104 return pdata->read(dev, reg);
1107 static int bq27xxx_battery_platform_probe(struct platform_device *pdev)
1109 struct bq27xxx_device_info *di;
1110 struct bq27xxx_platform_data *pdata = pdev->dev.platform_data;
1112 if (!pdata) {
1113 dev_err(&pdev->dev, "no platform_data supplied\n");
1114 return -EINVAL;
1117 if (!pdata->read) {
1118 dev_err(&pdev->dev, "no hdq read callback supplied\n");
1119 return -EINVAL;
1122 if (!pdata->chip) {
1123 dev_err(&pdev->dev, "no device supplied\n");
1124 return -EINVAL;
1127 di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
1128 if (!di)
1129 return -ENOMEM;
1131 platform_set_drvdata(pdev, di);
1133 di->dev = &pdev->dev;
1134 di->chip = pdata->chip;
1135 di->name = pdata->name ?: dev_name(&pdev->dev);
1136 di->bus.read = bq27xxx_battery_platform_read;
1138 return bq27xxx_battery_setup(di);
1141 static int bq27xxx_battery_platform_remove(struct platform_device *pdev)
1143 struct bq27xxx_device_info *di = platform_get_drvdata(pdev);
1145 bq27xxx_battery_teardown(di);
1147 return 0;
1150 static const struct platform_device_id bq27xxx_battery_platform_id_table[] = {
1151 { "bq27000-battery", },
1152 { /* sentinel */ }
1154 MODULE_DEVICE_TABLE(platform, bq27xxx_battery_platform_id_table);
1156 #ifdef CONFIG_OF
1157 static const struct of_device_id bq27xxx_battery_platform_of_match_table[] = {
1158 { .compatible = "ti,bq27000" },
1161 MODULE_DEVICE_TABLE(of, bq27xxx_battery_platform_of_match_table);
1162 #endif
1164 static struct platform_driver bq27xxx_battery_platform_driver = {
1165 .probe = bq27xxx_battery_platform_probe,
1166 .remove = bq27xxx_battery_platform_remove,
1167 .driver = {
1168 .name = "bq27000-battery",
1169 .of_match_table = of_match_ptr(bq27xxx_battery_platform_of_match_table),
1171 .id_table = bq27xxx_battery_platform_id_table,
1173 module_platform_driver(bq27xxx_battery_platform_driver);
1175 MODULE_ALIAS("platform:bq27000-battery");
1177 MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
1178 MODULE_DESCRIPTION("BQ27xxx battery monitor driver");
1179 MODULE_LICENSE("GPL");