1 --- kernel-power-2.6.28/drivers/power/bq27x00_battery.c 2011-02-18 19:36:55.000000000 +0100
2 +++ kernel-power-2.6.28/drivers/power/bq27x00_battery.c 2011-02-18 19:39:01.000000000 +0100
5 * Copyright (C) 2008 Rodolfo Giometti <giometti@linux.it>
6 * Copyright (C) 2008 Eurotech S.p.A. <info@eurotech.it>
7 + * Copyright (C) 2010-2011 Lars-Peter Clausen <lars@metafoo.de>
8 + * Copyright (C) 2011 Pali Rohár <pali.rohar@gmail.com>
10 * Based on a previous work by Copyright (C) 2008 Texas Instruments, Inc.
13 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 + * http://focus.ti.com/docs/prod/folders/print/bq27000.html
20 + * http://focus.ti.com/docs/prod/folders/print/bq27500.html
23 #include <linux/module.h>
24 #include <linux/param.h>
25 #include <linux/jiffies.h>
27 #include <linux/power_supply.h>
28 #include <linux/idr.h>
29 #include <linux/i2c.h>
30 +#include <linux/slab.h>
31 #include <asm/unaligned.h>
33 -#define DRIVER_VERSION "1.0.0"
34 +//#include <linux/power/bq27x00_battery.h>
36 +#define CONFIG_BATTERY_BQ27X00_I2C
38 +struct bq27000_platform_data {
40 + int (*read)(struct device *dev, unsigned int);
43 +#define DRIVER_VERSION "1.2.0"
45 #define BQ27x00_REG_TEMP 0x06
46 #define BQ27x00_REG_VOLT 0x08
47 -#define BQ27x00_REG_RSOC 0x0B /* Relative State-of-Charge */
48 #define BQ27x00_REG_AI 0x14
49 #define BQ27x00_REG_FLAGS 0x0A
50 +#define BQ27x00_REG_TTE 0x16
51 +#define BQ27x00_REG_TTF 0x18
52 +#define BQ27x00_REG_TTECP 0x26
53 +#define BQ27x00_REG_NAC 0x0C /* Nominal available capaciy */
54 +#define BQ27x00_REG_LMD 0x12 /* Last measured discharge */
55 +#define BQ27x00_REG_CYCT 0x2A /* Cycle count total */
56 +#define BQ27x00_REG_AE 0x22 /* Available enery */
58 +#define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */
59 +#define BQ27000_REG_ILMD 0x76 /* Initial last measured discharge */
60 +#define BQ27000_FLAG_CHGS BIT(7)
61 +#define BQ27000_FLAG_FC BIT(5)
63 +#define BQ27500_REG_SOC 0x2C
64 +#define BQ27500_REG_DCAP 0x3C /* Design capacity */
65 +#define BQ27500_FLAG_DSC BIT(0)
66 +#define BQ27500_FLAG_FC BIT(9)
68 -/* If the system has several batteries we need a different name for each
71 -static DEFINE_IDR(battery_id);
72 -static DEFINE_MUTEX(battery_mutex);
73 +#define BQ27000_RS 20 /* Resistor sense */
75 struct bq27x00_device_info;
76 struct bq27x00_access_methods {
77 - int (*read)(u8 reg, int *rt_value, int b_single,
78 - struct bq27x00_device_info *di);
79 + int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
82 +enum bq27x00_chip { BQ27000, BQ27500 };
84 +struct bq27x00_reg_cache {
87 + int time_to_empty_avg;
97 struct bq27x00_device_info {
104 - struct bq27x00_access_methods *bus;
105 + enum bq27x00_chip chip;
107 + struct bq27x00_reg_cache cache;
108 + int charge_design_full;
110 + unsigned long last_update;
111 + struct delayed_work work;
113 struct power_supply bat;
115 - struct i2c_client *client;
116 + struct bq27x00_access_methods bus;
121 static enum power_supply_property bq27x00_battery_props[] = {
122 + POWER_SUPPLY_PROP_STATUS,
123 POWER_SUPPLY_PROP_PRESENT,
124 POWER_SUPPLY_PROP_VOLTAGE_NOW,
125 POWER_SUPPLY_PROP_CURRENT_NOW,
126 POWER_SUPPLY_PROP_CAPACITY,
127 POWER_SUPPLY_PROP_TEMP,
128 + POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
129 + POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
130 + POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
131 + POWER_SUPPLY_PROP_TECHNOLOGY,
132 + POWER_SUPPLY_PROP_CHARGE_FULL,
133 + POWER_SUPPLY_PROP_CHARGE_NOW,
134 + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
135 + POWER_SUPPLY_PROP_CHARGE_COUNTER,
136 +// POWER_SUPPLY_PROP_ENERGY_NOW,
139 +static unsigned int poll_interval = 360;
140 +module_param(poll_interval, uint, 0644);
141 +MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \
142 + "0 disables polling");
145 * Common code for BQ27x00 devices
148 -static int bq27x00_read(u8 reg, int *rt_value, int b_single,
149 - struct bq27x00_device_info *di)
150 +static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg,
154 + return di->bus.read(di, reg, single);
158 + * Return the battery Relative State-of-Charge
159 + * Or < 0 if something fails.
161 +static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di)
165 - ret = di->bus->read(reg, rt_value, b_single, di);
166 - *rt_value = be16_to_cpu(*rt_value);
167 + if (di->chip == BQ27500)
168 + rsoc = bq27x00_read(di, BQ27500_REG_SOC, false);
170 + rsoc = bq27x00_read(di, BQ27000_REG_RSOC, true);
174 + dev_err(di->dev, "error reading relative State-of-Charge\n");
180 - * Return the battery temperature in Celcius degrees
181 + * Return a battery charge value in µAh
182 * Or < 0 if something fails.
184 -static int bq27x00_battery_temperature(struct bq27x00_device_info *di)
185 +static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)
191 - ret = bq27x00_read(BQ27x00_REG_TEMP, &temp, 0, di);
193 - dev_err(di->dev, "error reading temperature\n");
195 + charge = bq27x00_read(di, reg, false);
197 + dev_err(di->dev, "error reading nominal available capacity\n");
201 - return (temp >> 2) - 273;
202 + if (di->chip == BQ27500)
205 + charge = charge * 3570 / BQ27000_RS;
211 - * Return the battery Voltage in milivolts
212 + * Return the battery Nominal available capaciy in µAh
213 * Or < 0 if something fails.
215 -static int bq27x00_battery_voltage(struct bq27x00_device_info *di)
216 +static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di)
220 + return bq27x00_battery_read_charge(di, BQ27x00_REG_NAC);
223 - ret = bq27x00_read(BQ27x00_REG_VOLT, &volt, 0, di);
225 - dev_err(di->dev, "error reading voltage\n");
228 + * Return the battery Last measured discharge in µAh
229 + * Or < 0 if something fails.
231 +static inline int bq27x00_battery_read_lmd(struct bq27x00_device_info *di)
233 + return bq27x00_battery_read_charge(di, BQ27x00_REG_LMD);
237 + * Return the battery Initial last measured discharge in µAh
238 + * Or < 0 if something fails.
240 +static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di)
244 + if (di->chip == BQ27500)
245 + ilmd = bq27x00_read(di, BQ27500_REG_DCAP, false);
247 + ilmd = bq27x00_read(di, BQ27000_REG_ILMD, true);
250 + dev_err(di->dev, "error reading initial last measured discharge\n");
255 + if (di->chip == BQ27500)
258 + ilmd = ilmd * 256 * 3570 / BQ27000_RS;
264 - * Return the battery average current
265 - * Note that current can be negative signed as well
266 - * Or 0 if something fails.
267 + * Return the battery Cycle count total
268 + * Or < 0 if something fails.
270 -static int bq27x00_battery_current(struct bq27x00_device_info *di)
271 +static int bq27x00_battery_read_cyct(struct bq27x00_device_info *di)
278 - ret = bq27x00_read(BQ27x00_REG_AI, &curr, 0, di);
280 - dev_err(di->dev, "error reading current\n");
282 + cyct = bq27x00_read(di, BQ27x00_REG_CYCT, false);
284 + dev_err(di->dev, "error reading cycle count total\n");
290 + * Read a time register.
291 + * Return < 0 if something fails.
293 +static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg)
297 + tval = bq27x00_read(di, reg, false);
299 + dev_err(di->dev, "error reading register %02x: %d\n", reg, tval);
302 - ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
304 - dev_err(di->dev, "error reading flags\n");
313 +static void bq27x00_update(struct bq27x00_device_info *di)
315 + struct bq27x00_reg_cache cache = {0, };
316 + bool is_bq27500 = di->chip == BQ27500;
318 + cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, is_bq27500);
319 + if (cache.flags >= 0) {
320 + cache.capacity = bq27x00_battery_read_rsoc(di);
321 + cache.temperature = bq27x00_read(di, BQ27x00_REG_TEMP, false);
322 + cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE);
323 + cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP);
324 + cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF);
325 + cache.charge_full = bq27x00_battery_read_lmd(di);
326 + cache.charge_counter = bq27x00_battery_read_cyct(di);
329 + cache.current_now = bq27x00_read(di, BQ27x00_REG_AI, false);
331 + /* We only have to read charge design full once */
332 + if (di->charge_design_full <= 0)
333 + di->charge_design_full = bq27x00_battery_read_ilmd(di);
335 - if ((flags & (1 << 7)) != 0) {
336 - dev_dbg(di->dev, "negative current!\n");
339 + /* Ignore current_now which is a snapshot of the current battery state
340 + * and is likely to be different even between two consecutive reads */
341 + if (memcmp(&di->cache, &cache, sizeof(cache) - sizeof(int)) != 0) {
343 + power_supply_changed(&di->bat);
346 + di->last_update = jiffies;
349 +static void bq27x00_battery_poll(struct work_struct *work)
351 + struct bq27x00_device_info *di =
352 + container_of(work, struct bq27x00_device_info, work.work);
354 + bq27x00_update(di);
356 + if (poll_interval > 0) {
357 + /* The timer does not have to be accurate. */
358 +// set_timer_slack(&di->work.timer, poll_interval * HZ / 4);
359 + schedule_delayed_work(&di->work, poll_interval * HZ);
366 - * Return the battery Relative State-of-Charge
367 + * Return the battery temperature in tenths of degree Celsius
368 * Or < 0 if something fails.
370 -static int bq27x00_battery_rsoc(struct bq27x00_device_info *di)
371 +static int bq27x00_battery_temperature(struct bq27x00_device_info *di,
372 + union power_supply_propval *val)
376 + if (di->cache.temperature < 0)
377 + return di->cache.temperature;
379 - ret = bq27x00_read(BQ27x00_REG_RSOC, &rsoc, 1, di);
381 - dev_err(di->dev, "error reading relative State-of-Charge\n");
383 + if (di->chip == BQ27500)
384 + val->intval = di->cache.temperature - 2731;
386 + val->intval = ((di->cache.temperature * 5) - 5463) / 2;
392 + * Return the battery average current in µA
393 + * Note that current can be negative signed as well
394 + * Or 0 if something fails.
396 +static int bq27x00_battery_current(struct bq27x00_device_info *di,
397 + union power_supply_propval *val)
401 + if (di->chip == BQ27500)
402 + curr = bq27x00_read(di, BQ27x00_REG_AI, false);
404 + curr = di->cache.current_now;
409 + if (di->chip == BQ27500) {
410 + /* bq27500 returns signed value */
411 + val->intval = (int)((s16)curr) * 1000;
413 + if (di->cache.flags & BQ27000_FLAG_CHGS) {
414 + dev_dbg(di->dev, "negative current!\n");
418 + val->intval = curr * 3570 / BQ27000_RS;
425 +static int bq27x00_battery_status(struct bq27x00_device_info *di,
426 + union power_supply_propval *val)
430 + if (di->chip == BQ27500) {
431 + if (di->cache.flags & BQ27500_FLAG_FC)
432 + status = POWER_SUPPLY_STATUS_FULL;
433 + else if (di->cache.flags & BQ27500_FLAG_DSC)
434 + status = POWER_SUPPLY_STATUS_DISCHARGING;
436 + status = POWER_SUPPLY_STATUS_CHARGING;
438 + if (di->cache.flags & BQ27000_FLAG_FC)
439 + status = POWER_SUPPLY_STATUS_FULL;
440 + else if (di->cache.flags & BQ27000_FLAG_CHGS)
441 + status = POWER_SUPPLY_STATUS_CHARGING;
442 + else if (power_supply_am_i_supplied(&di->bat))
443 + status = POWER_SUPPLY_STATUS_NOT_CHARGING;
445 + status = POWER_SUPPLY_STATUS_DISCHARGING;
448 + val->intval = status;
454 + * Return the battery Voltage in milivolts
455 + * Or < 0 if something fails.
457 +static int bq27x00_battery_voltage(struct bq27x00_device_info *di,
458 + union power_supply_propval *val)
462 + volt = bq27x00_read(di, BQ27x00_REG_VOLT, false);
466 + val->intval = volt * 1000;
472 + * Return the battery Available energy in µWh
473 + * Or < 0 if something fails.
475 +static int bq27x00_battery_energy(struct bq27x00_device_info *di,
476 + union power_supply_propval *val)
480 + ae = bq27x00_read(di, BQ27x00_REG_AE, false);
482 + dev_err(di->dev, "error reading available energy\n");
486 + if (di->chip == BQ27500)
489 + ae = ae * 29200 / BQ27000_RS;
497 +static int bq27x00_simple_value(int value,
498 + union power_supply_propval *val)
503 + val->intval = value;
508 #define to_bq27x00_device_info(x) container_of((x), \
509 @@ -171,89 +452,164 @@ static int bq27x00_battery_get_property(
510 enum power_supply_property psp,
511 union power_supply_propval *val)
514 struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
516 + mutex_lock(&di->lock);
517 + if (time_is_before_jiffies(di->last_update + 5 * HZ)) {
518 + cancel_delayed_work_sync(&di->work);
519 + bq27x00_battery_poll(&di->work.work);
521 + mutex_unlock(&di->lock);
523 + if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0)
527 + case POWER_SUPPLY_PROP_STATUS:
528 + ret = bq27x00_battery_status(di, val);
530 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
531 + ret = bq27x00_battery_voltage(di, val);
533 case POWER_SUPPLY_PROP_PRESENT:
534 - val->intval = bq27x00_battery_voltage(di);
535 - if (psp == POWER_SUPPLY_PROP_PRESENT)
536 - val->intval = val->intval <= 0 ? 0 : 1;
537 + val->intval = di->cache.flags < 0 ? 0 : 1;
539 case POWER_SUPPLY_PROP_CURRENT_NOW:
540 - val->intval = bq27x00_battery_current(di);
541 + ret = bq27x00_battery_current(di, val);
543 case POWER_SUPPLY_PROP_CAPACITY:
544 - val->intval = bq27x00_battery_rsoc(di);
545 + ret = bq27x00_simple_value(di->cache.capacity, val);
547 case POWER_SUPPLY_PROP_TEMP:
548 - val->intval = bq27x00_battery_temperature(di);
549 + ret = bq27x00_battery_temperature(di, val);
551 + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
552 + ret = bq27x00_simple_value(di->cache.time_to_empty, val);
554 + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
555 + ret = bq27x00_simple_value(di->cache.time_to_empty_avg, val);
557 + case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
558 + ret = bq27x00_simple_value(di->cache.time_to_full, val);
560 + case POWER_SUPPLY_PROP_TECHNOLOGY:
561 + val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
563 + case POWER_SUPPLY_PROP_CHARGE_NOW:
564 + ret = bq27x00_simple_value(bq27x00_battery_read_nac(di), val);
566 + case POWER_SUPPLY_PROP_CHARGE_FULL:
567 + ret = bq27x00_simple_value(di->cache.charge_full, val);
569 + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
570 + ret = bq27x00_simple_value(di->charge_design_full, val);
572 + case POWER_SUPPLY_PROP_CHARGE_COUNTER:
573 + ret = bq27x00_simple_value(di->cache.charge_counter, val);
575 + case POWER_SUPPLY_PROP_ENERGY_NOW:
576 + ret = bq27x00_battery_energy(di, val);
586 -static void bq27x00_powersupply_init(struct bq27x00_device_info *di)
587 +static void bq27x00_external_power_changed(struct power_supply *psy)
589 + struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
591 + cancel_delayed_work_sync(&di->work);
592 + schedule_delayed_work(&di->work, 0);
595 +static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
599 di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
600 di->bat.properties = bq27x00_battery_props;
601 di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props);
602 di->bat.get_property = bq27x00_battery_get_property;
603 - di->bat.external_power_changed = NULL;
604 + di->bat.external_power_changed = bq27x00_external_power_changed;
606 + INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll);
607 + mutex_init(&di->lock);
609 + ret = power_supply_register(di->dev, &di->bat);
611 + dev_err(di->dev, "failed to register battery: %d\n", ret);
615 + dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);
617 + bq27x00_update(di);
623 - * BQ27200 specific code
624 +static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di)
626 + cancel_delayed_work_sync(&di->work);
628 + power_supply_unregister(&di->bat);
630 + mutex_destroy(&di->lock);
634 +/* i2c specific code */
635 +#ifdef CONFIG_BATTERY_BQ27X00_I2C
637 +/* If the system has several batteries we need a different name for each
640 +static DEFINE_IDR(battery_id);
641 +static DEFINE_MUTEX(battery_mutex);
643 -static int bq27200_read(u8 reg, int *rt_value, int b_single,
644 - struct bq27x00_device_info *di)
645 +static int bq27x00_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single)
647 - struct i2c_client *client = di->client;
648 - struct i2c_msg msg[1];
649 + struct i2c_client *client = to_i2c_client(di->dev);
650 + struct i2c_msg msg[2];
651 unsigned char data[2];
655 if (!client->adapter)
658 - msg->addr = client->addr;
664 - err = i2c_transfer(client->adapter, msg, 1);
671 + msg[0].addr = client->addr;
674 + msg[0].len = sizeof(reg);
675 + msg[1].addr = client->addr;
676 + msg[1].flags = I2C_M_RD;
683 - msg->flags = I2C_M_RD;
684 - err = i2c_transfer(client->adapter, msg, 1);
687 - *rt_value = get_unaligned_be16(data);
689 - *rt_value = data[0];
690 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
699 + ret = get_unaligned_le16(data);
706 -static int bq27200_battery_probe(struct i2c_client *client,
707 +static int bq27x00_battery_probe(struct i2c_client *client,
708 const struct i2c_device_id *id)
711 struct bq27x00_device_info *di;
712 - struct bq27x00_access_methods *bus;
716 @@ -267,7 +623,7 @@ static int bq27200_battery_probe(struct
720 - name = kasprintf(GFP_KERNEL, "bq27200-%d", num);
721 + name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);
723 dev_err(&client->dev, "failed to allocate device name\n");
725 @@ -280,37 +636,20 @@ static int bq27200_battery_probe(struct
731 - bus = kzalloc(sizeof(*bus), GFP_KERNEL);
733 - dev_err(&client->dev, "failed to allocate access method "
736 - goto batt_failed_3;
739 - i2c_set_clientdata(client, di);
741 di->dev = &client->dev;
742 + di->chip = id->driver_data;
744 - bus->read = &bq27200_read;
746 - di->client = client;
748 - bq27x00_powersupply_init(di);
749 + di->bus.read = &bq27x00_read_i2c;
751 - retval = power_supply_register(&client->dev, &di->bat);
753 - dev_err(&client->dev, "failed to register battery\n");
754 - goto batt_failed_4;
756 + if (bq27x00_powersupply_init(di))
757 + goto batt_failed_3;
759 - dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION);
760 + i2c_set_clientdata(client, di);
769 @@ -323,11 +662,11 @@ batt_failed_1:
773 -static int bq27200_battery_remove(struct i2c_client *client)
774 +static int bq27x00_battery_remove(struct i2c_client *client)
776 struct bq27x00_device_info *di = i2c_get_clientdata(client);
778 - power_supply_unregister(&di->bat);
779 + bq27x00_powersupply_unregister(di);
783 @@ -340,31 +679,180 @@ static int bq27200_battery_remove(struct
791 -static const struct i2c_device_id bq27200_id[] = {
793 +static const struct i2c_device_id bq27x00_id[] = {
794 + { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */
795 + { "bq27500", BQ27500 },
798 +MODULE_DEVICE_TABLE(i2c, bq27x00_id);
800 +static struct i2c_driver bq27x00_battery_driver = {
802 + .name = "bq27x00-battery",
804 + .probe = bq27x00_battery_probe,
805 + .remove = bq27x00_battery_remove,
806 + .id_table = bq27x00_id,
809 +static inline int bq27x00_battery_i2c_init(void)
811 + int ret = i2c_add_driver(&bq27x00_battery_driver);
813 + printk(KERN_ERR "Unable to register BQ27x00 i2c driver\n");
818 +static inline void bq27x00_battery_i2c_exit(void)
820 + i2c_del_driver(&bq27x00_battery_driver);
825 +static inline int bq27x00_battery_i2c_init(void) { return 0; }
826 +static inline void bq27x00_battery_i2c_exit(void) {};
830 +/* platform specific code */
831 +#ifdef CONFIG_BATTERY_BQ27X00_PLATFORM
833 +static int bq27000_read_platform(struct bq27x00_device_info *di, u8 reg,
836 + struct device *dev = di->dev;
837 + struct bq27000_platform_data *pdata = dev->platform_data;
838 + unsigned int timeout = 3;
843 + /* Make sure the value has not changed in between reading the
844 + * lower and the upper part */
845 + upper = pdata->read(dev, reg + 1);
851 + lower = pdata->read(dev, reg);
855 + upper = pdata->read(dev, reg + 1);
856 + } while (temp != upper && --timeout);
861 + return (upper << 8) | lower;
864 + return pdata->read(dev, reg);
867 +static int __devinit bq27000_battery_probe(struct platform_device *pdev)
869 + struct bq27x00_device_info *di;
870 + struct bq27000_platform_data *pdata = pdev->dev.platform_data;
874 + dev_err(&pdev->dev, "no platform_data supplied\n");
878 + if (!pdata->read) {
879 + dev_err(&pdev->dev, "no hdq read callback supplied\n");
883 + di = kzalloc(sizeof(*di), GFP_KERNEL);
885 + dev_err(&pdev->dev, "failed to allocate device info data\n");
889 + platform_set_drvdata(pdev, di);
891 + di->dev = &pdev->dev;
892 + di->chip = BQ27000;
894 + di->bat.name = pdata->name ?: dev_name(&pdev->dev);
895 + di->bus.read = &bq27000_read_platform;
897 -static struct i2c_driver bq27200_battery_driver = {
898 + ret = bq27x00_powersupply_init(di);
905 + platform_set_drvdata(pdev, NULL);
911 +static int __devexit bq27000_battery_remove(struct platform_device *pdev)
913 + struct bq27x00_device_info *di = platform_get_drvdata(pdev);
915 + bq27x00_powersupply_unregister(di);
917 + platform_set_drvdata(pdev, NULL);
923 +static struct platform_driver bq27000_battery_driver = {
924 + .probe = bq27000_battery_probe,
925 + .remove = __devexit_p(bq27000_battery_remove),
927 - .name = "bq27200-battery",
928 + .name = "bq27000-battery",
929 + .owner = THIS_MODULE,
931 - .probe = bq27200_battery_probe,
932 - .remove = bq27200_battery_remove,
933 - .id_table = bq27200_id,
936 +static inline int bq27x00_battery_platform_init(void)
938 + int ret = platform_driver_register(&bq27000_battery_driver);
940 + printk(KERN_ERR "Unable to register BQ27000 platform driver\n");
945 +static inline void bq27x00_battery_platform_exit(void)
947 + platform_driver_unregister(&bq27000_battery_driver);
952 +static inline int bq27x00_battery_platform_init(void) { return 0; }
953 +static inline void bq27x00_battery_platform_exit(void) {};
961 static int __init bq27x00_battery_init(void)
965 - ret = i2c_add_driver(&bq27200_battery_driver);
966 + ret = bq27x00_battery_i2c_init();
970 + ret = bq27x00_battery_platform_init();
972 - printk(KERN_ERR "Unable to register BQ27200 driver\n");
973 + bq27x00_battery_i2c_exit();
977 @@ -372,7 +860,8 @@ module_init(bq27x00_battery_init);
979 static void __exit bq27x00_battery_exit(void)
981 - i2c_del_driver(&bq27200_battery_driver);
982 + bq27x00_battery_platform_exit();
983 + bq27x00_battery_i2c_exit();
985 module_exit(bq27x00_battery_exit);