1 --- kernel-power-2.6.28/drivers/power/bq27x00_battery.c 2011-05-01 01:48:44.000000000 +0200
2 +++ kernel-power-2.6.28/drivers/power/bq27x00_battery.c 2011-05-01 01:51:12.000000000 +0200
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 +#define CONFIG_BATTERY_BQ27X00_I2C
36 +struct bq27000_platform_data {
38 + int (*read)(struct device *dev, unsigned int);
41 +#define DRIVER_VERSION "1.2.0"
43 #define BQ27x00_REG_TEMP 0x06
44 #define BQ27x00_REG_VOLT 0x08
45 -#define BQ27x00_REG_RSOC 0x0B /* Relative State-of-Charge */
46 #define BQ27x00_REG_AI 0x14
47 #define BQ27x00_REG_FLAGS 0x0A
48 +#define BQ27x00_REG_TTE 0x16
49 +#define BQ27x00_REG_TTF 0x18
50 +#define BQ27x00_REG_TTECP 0x26
51 +#define BQ27x00_REG_NAC 0x0C /* Nominal available capaciy */
52 +#define BQ27x00_REG_LMD 0x12 /* Last measured discharge */
53 +#define BQ27x00_REG_CYCT 0x2A /* Cycle count total */
54 +#define BQ27x00_REG_AE 0x22 /* Available enery */
56 +#define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */
57 +#define BQ27000_REG_ILMD 0x76 /* Initial last measured discharge */
58 +#define BQ27000_FLAG_CHGS BIT(7)
59 +#define BQ27000_FLAG_FC BIT(5)
61 +#define BQ27500_REG_SOC 0x2C
62 +#define BQ27500_REG_DCAP 0x3C /* Design capacity */
63 +#define BQ27500_FLAG_DSC BIT(0)
64 +#define BQ27500_FLAG_FC BIT(9)
66 -/* If the system has several batteries we need a different name for each
69 -static DEFINE_IDR(battery_id);
70 -static DEFINE_MUTEX(battery_mutex);
71 +#define BQ27000_RS 20 /* Resistor sense */
73 struct bq27x00_device_info;
74 struct bq27x00_access_methods {
75 - int (*read)(u8 reg, int *rt_value, int b_single,
76 - struct bq27x00_device_info *di);
77 + int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
80 +enum bq27x00_chip { BQ27000, BQ27500 };
82 +struct bq27x00_reg_cache {
85 + int time_to_empty_avg;
95 struct bq27x00_device_info {
102 - struct bq27x00_access_methods *bus;
103 + enum bq27x00_chip chip;
105 + struct bq27x00_reg_cache cache;
106 + int charge_design_full;
108 + unsigned long last_update;
109 + struct delayed_work work;
111 struct power_supply bat;
113 - struct i2c_client *client;
114 + struct bq27x00_access_methods bus;
119 static enum power_supply_property bq27x00_battery_props[] = {
120 + POWER_SUPPLY_PROP_STATUS,
121 POWER_SUPPLY_PROP_PRESENT,
122 POWER_SUPPLY_PROP_VOLTAGE_NOW,
123 POWER_SUPPLY_PROP_CURRENT_NOW,
124 POWER_SUPPLY_PROP_CAPACITY,
125 POWER_SUPPLY_PROP_TEMP,
126 + POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
127 + POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
128 + POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
129 + POWER_SUPPLY_PROP_TECHNOLOGY,
130 + POWER_SUPPLY_PROP_CHARGE_FULL,
131 + POWER_SUPPLY_PROP_CHARGE_NOW,
132 + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
133 + POWER_SUPPLY_PROP_CYCLE_COUNT,
136 +static unsigned int poll_interval = 360;
137 +module_param(poll_interval, uint, 0644);
138 +MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \
139 + "0 disables polling");
142 * Common code for BQ27x00 devices
145 -static int bq27x00_read(u8 reg, int *rt_value, int b_single,
146 - struct bq27x00_device_info *di)
147 +static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg,
151 + return di->bus.read(di, reg, single);
155 + * Return the battery Relative State-of-Charge
156 + * Or < 0 if something fails.
158 +static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di)
162 - ret = di->bus->read(reg, rt_value, b_single, di);
163 - *rt_value = be16_to_cpu(*rt_value);
164 + if (di->chip == BQ27500)
165 + rsoc = bq27x00_read(di, BQ27500_REG_SOC, false);
167 + rsoc = bq27x00_read(di, BQ27000_REG_RSOC, true);
171 + dev_err(di->dev, "error reading relative State-of-Charge\n");
177 - * Return the battery temperature in Celcius degrees
178 + * Return a battery charge value in µAh
179 * Or < 0 if something fails.
181 -static int bq27x00_battery_temperature(struct bq27x00_device_info *di)
182 +static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)
188 - ret = bq27x00_read(BQ27x00_REG_TEMP, &temp, 0, di);
190 - dev_err(di->dev, "error reading temperature\n");
192 + charge = bq27x00_read(di, reg, false);
194 + dev_err(di->dev, "error reading nominal available capacity\n");
198 - return (temp >> 2) - 273;
199 + if (di->chip == BQ27500)
202 + charge = charge * 3570 / BQ27000_RS;
208 - * Return the battery Voltage in milivolts
209 + * Return the battery Nominal available capaciy in µAh
210 * Or < 0 if something fails.
212 -static int bq27x00_battery_voltage(struct bq27x00_device_info *di)
213 +static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di)
217 + return bq27x00_battery_read_charge(di, BQ27x00_REG_NAC);
220 - ret = bq27x00_read(BQ27x00_REG_VOLT, &volt, 0, di);
222 - dev_err(di->dev, "error reading voltage\n");
225 + * Return the battery Last measured discharge in µAh
226 + * Or < 0 if something fails.
228 +static inline int bq27x00_battery_read_lmd(struct bq27x00_device_info *di)
230 + return bq27x00_battery_read_charge(di, BQ27x00_REG_LMD);
234 + * Return the battery Initial last measured discharge in µAh
235 + * Or < 0 if something fails.
237 +static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di)
241 + if (di->chip == BQ27500)
242 + ilmd = bq27x00_read(di, BQ27500_REG_DCAP, false);
244 + ilmd = bq27x00_read(di, BQ27000_REG_ILMD, true);
247 + dev_err(di->dev, "error reading initial last measured discharge\n");
252 + if (di->chip == BQ27500)
255 + ilmd = ilmd * 256 * 3570 / BQ27000_RS;
261 - * Return the battery average current
262 - * Note that current can be negative signed as well
263 - * Or 0 if something fails.
264 + * Return the battery Cycle count total
265 + * Or < 0 if something fails.
267 -static int bq27x00_battery_current(struct bq27x00_device_info *di)
268 +static int bq27x00_battery_read_cyct(struct bq27x00_device_info *di)
275 - ret = bq27x00_read(BQ27x00_REG_AI, &curr, 0, di);
277 - dev_err(di->dev, "error reading current\n");
279 + cyct = bq27x00_read(di, BQ27x00_REG_CYCT, false);
281 + dev_err(di->dev, "error reading cycle count total\n");
287 + * Read a time register.
288 + * Return < 0 if something fails.
290 +static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg)
294 + tval = bq27x00_read(di, reg, false);
296 + dev_err(di->dev, "error reading register %02x: %d\n", reg, tval);
299 - ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
301 - dev_err(di->dev, "error reading flags\n");
309 +static void bq27x00_update(struct bq27x00_device_info *di)
311 + struct bq27x00_reg_cache cache = {0, };
312 + bool is_bq27500 = di->chip == BQ27500;
314 + cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, is_bq27500);
315 + if (cache.flags >= 0) {
316 + cache.capacity = bq27x00_battery_read_rsoc(di);
317 + cache.temperature = bq27x00_read(di, BQ27x00_REG_TEMP, false);
318 + cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE);
319 + cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP);
320 + cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF);
321 + cache.charge_full = bq27x00_battery_read_lmd(di);
322 + cache.cycle_count = bq27x00_battery_read_cyct(di);
325 + cache.current_now = bq27x00_read(di, BQ27x00_REG_AI, false);
327 + /* We only have to read charge design full once */
328 + if (di->charge_design_full <= 0)
329 + di->charge_design_full = bq27x00_battery_read_ilmd(di);
331 - if ((flags & (1 << 7)) != 0) {
332 - dev_dbg(di->dev, "negative current!\n");
335 + /* Ignore current_now which is a snapshot of the current battery state
336 + * and is likely to be different even between two consecutive reads */
337 + if (memcmp(&di->cache, &cache, sizeof(cache) - sizeof(int)) != 0) {
339 + power_supply_changed(&di->bat);
342 + di->last_update = jiffies;
345 +static void bq27x00_battery_poll(struct work_struct *work)
347 + struct bq27x00_device_info *di =
348 + container_of(work, struct bq27x00_device_info, work.work);
350 + bq27x00_update(di);
352 + if (poll_interval > 0) {
353 + schedule_delayed_work(&di->work, poll_interval * HZ);
360 - * Return the battery Relative State-of-Charge
361 + * Return the battery temperature in tenths of degree Celsius
362 * Or < 0 if something fails.
364 -static int bq27x00_battery_rsoc(struct bq27x00_device_info *di)
365 +static int bq27x00_battery_temperature(struct bq27x00_device_info *di,
366 + union power_supply_propval *val)
370 + if (di->cache.temperature < 0)
371 + return di->cache.temperature;
373 - ret = bq27x00_read(BQ27x00_REG_RSOC, &rsoc, 1, di);
375 - dev_err(di->dev, "error reading relative State-of-Charge\n");
377 + if (di->chip == BQ27500)
378 + val->intval = di->cache.temperature - 2731;
380 + val->intval = ((di->cache.temperature * 5) - 5463) / 2;
386 + * Return the battery average current in µA
387 + * Note that current can be negative signed as well
388 + * Or 0 if something fails.
390 +static int bq27x00_battery_current(struct bq27x00_device_info *di,
391 + union power_supply_propval *val)
395 + if (di->chip == BQ27500)
396 + curr = bq27x00_read(di, BQ27x00_REG_AI, false);
398 + curr = di->cache.current_now;
403 + if (di->chip == BQ27500) {
404 + /* bq27500 returns signed value */
405 + val->intval = (int)((s16)curr) * 1000;
407 + if (di->cache.flags & BQ27000_FLAG_CHGS) {
408 + dev_dbg(di->dev, "negative current!\n");
412 + val->intval = curr * 3570 / BQ27000_RS;
419 +static int bq27x00_battery_status(struct bq27x00_device_info *di,
420 + union power_supply_propval *val)
424 + if (di->chip == BQ27500) {
425 + if (di->cache.flags & BQ27500_FLAG_FC)
426 + status = POWER_SUPPLY_STATUS_FULL;
427 + else if (di->cache.flags & BQ27500_FLAG_DSC)
428 + status = POWER_SUPPLY_STATUS_DISCHARGING;
430 + status = POWER_SUPPLY_STATUS_CHARGING;
432 + if (di->cache.flags & BQ27000_FLAG_FC)
433 + status = POWER_SUPPLY_STATUS_FULL;
434 + else if (di->cache.flags & BQ27000_FLAG_CHGS)
435 + status = POWER_SUPPLY_STATUS_CHARGING;
436 + else if (power_supply_am_i_supplied(&di->bat))
437 + status = POWER_SUPPLY_STATUS_NOT_CHARGING;
439 + status = POWER_SUPPLY_STATUS_DISCHARGING;
442 + val->intval = status;
448 + * Return the battery Voltage in milivolts
449 + * Or < 0 if something fails.
451 +static int bq27x00_battery_voltage(struct bq27x00_device_info *di,
452 + union power_supply_propval *val)
456 + volt = bq27x00_read(di, BQ27x00_REG_VOLT, false);
460 + val->intval = volt * 1000;
466 + * Return the battery Available energy in µWh
467 + * Or < 0 if something fails.
469 +static int bq27x00_battery_energy(struct bq27x00_device_info *di,
470 + union power_supply_propval *val)
474 + ae = bq27x00_read(di, BQ27x00_REG_AE, false);
476 + dev_err(di->dev, "error reading available energy\n");
480 + if (di->chip == BQ27500)
483 + ae = ae * 29200 / BQ27000_RS;
491 +static int bq27x00_simple_value(int value,
492 + union power_supply_propval *val)
497 + val->intval = value;
502 #define to_bq27x00_device_info(x) container_of((x), \
503 @@ -171,89 +446,164 @@ static int bq27x00_battery_get_property(
504 enum power_supply_property psp,
505 union power_supply_propval *val)
508 struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
510 + mutex_lock(&di->lock);
511 + if (time_is_before_jiffies(di->last_update + 5 * HZ)) {
512 + cancel_delayed_work_sync(&di->work);
513 + bq27x00_battery_poll(&di->work.work);
515 + mutex_unlock(&di->lock);
517 + if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0)
521 + case POWER_SUPPLY_PROP_STATUS:
522 + ret = bq27x00_battery_status(di, val);
524 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
525 + ret = bq27x00_battery_voltage(di, val);
527 case POWER_SUPPLY_PROP_PRESENT:
528 - val->intval = bq27x00_battery_voltage(di);
529 - if (psp == POWER_SUPPLY_PROP_PRESENT)
530 - val->intval = val->intval <= 0 ? 0 : 1;
531 + val->intval = di->cache.flags < 0 ? 0 : 1;
533 case POWER_SUPPLY_PROP_CURRENT_NOW:
534 - val->intval = bq27x00_battery_current(di);
535 + ret = bq27x00_battery_current(di, val);
537 case POWER_SUPPLY_PROP_CAPACITY:
538 - val->intval = bq27x00_battery_rsoc(di);
539 + ret = bq27x00_simple_value(di->cache.capacity, val);
541 case POWER_SUPPLY_PROP_TEMP:
542 - val->intval = bq27x00_battery_temperature(di);
543 + ret = bq27x00_battery_temperature(di, val);
545 + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
546 + ret = bq27x00_simple_value(di->cache.time_to_empty, val);
548 + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
549 + ret = bq27x00_simple_value(di->cache.time_to_empty_avg, val);
551 + case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
552 + ret = bq27x00_simple_value(di->cache.time_to_full, val);
554 + case POWER_SUPPLY_PROP_TECHNOLOGY:
555 + val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
557 + case POWER_SUPPLY_PROP_CHARGE_NOW:
558 + ret = bq27x00_simple_value(bq27x00_battery_read_nac(di), val);
560 + case POWER_SUPPLY_PROP_CHARGE_FULL:
561 + ret = bq27x00_simple_value(di->cache.charge_full, val);
563 + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
564 + ret = bq27x00_simple_value(di->charge_design_full, val);
566 + case POWER_SUPPLY_PROP_CYCLE_COUNT:
567 + ret = bq27x00_simple_value(di->cache.cycle_count, val);
569 + case POWER_SUPPLY_PROP_ENERGY_NOW:
570 + ret = bq27x00_battery_energy(di, val);
580 -static void bq27x00_powersupply_init(struct bq27x00_device_info *di)
581 +static void bq27x00_external_power_changed(struct power_supply *psy)
583 + struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
585 + cancel_delayed_work_sync(&di->work);
586 + schedule_delayed_work(&di->work, 0);
589 +static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
593 di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
594 di->bat.properties = bq27x00_battery_props;
595 di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props);
596 di->bat.get_property = bq27x00_battery_get_property;
597 - di->bat.external_power_changed = NULL;
598 + di->bat.external_power_changed = bq27x00_external_power_changed;
600 + INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll);
601 + mutex_init(&di->lock);
603 + ret = power_supply_register(di->dev, &di->bat);
605 + dev_err(di->dev, "failed to register battery: %d\n", ret);
609 + dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);
611 + bq27x00_update(di);
617 - * BQ27200 specific code
618 +static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di)
620 + cancel_delayed_work_sync(&di->work);
622 + power_supply_unregister(&di->bat);
624 + mutex_destroy(&di->lock);
628 +/* i2c specific code */
629 +#ifdef CONFIG_BATTERY_BQ27X00_I2C
631 +/* If the system has several batteries we need a different name for each
634 +static DEFINE_IDR(battery_id);
635 +static DEFINE_MUTEX(battery_mutex);
637 -static int bq27200_read(u8 reg, int *rt_value, int b_single,
638 - struct bq27x00_device_info *di)
639 +static int bq27x00_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single)
641 - struct i2c_client *client = di->client;
642 - struct i2c_msg msg[1];
643 + struct i2c_client *client = to_i2c_client(di->dev);
644 + struct i2c_msg msg[2];
645 unsigned char data[2];
649 if (!client->adapter)
652 - msg->addr = client->addr;
658 - err = i2c_transfer(client->adapter, msg, 1);
665 + msg[0].addr = client->addr;
668 + msg[0].len = sizeof(reg);
669 + msg[1].addr = client->addr;
670 + msg[1].flags = I2C_M_RD;
677 - msg->flags = I2C_M_RD;
678 - err = i2c_transfer(client->adapter, msg, 1);
681 - *rt_value = get_unaligned_be16(data);
683 - *rt_value = data[0];
684 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
693 + ret = get_unaligned_le16(data);
700 -static int bq27200_battery_probe(struct i2c_client *client,
701 +static int bq27x00_battery_probe(struct i2c_client *client,
702 const struct i2c_device_id *id)
705 struct bq27x00_device_info *di;
706 - struct bq27x00_access_methods *bus;
710 @@ -267,7 +617,7 @@ static int bq27200_battery_probe(struct
714 - name = kasprintf(GFP_KERNEL, "bq27200-%d", num);
715 + name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);
717 dev_err(&client->dev, "failed to allocate device name\n");
719 @@ -280,37 +630,20 @@ static int bq27200_battery_probe(struct
725 - bus = kzalloc(sizeof(*bus), GFP_KERNEL);
727 - dev_err(&client->dev, "failed to allocate access method "
730 - goto batt_failed_3;
733 - i2c_set_clientdata(client, di);
735 di->dev = &client->dev;
736 + di->chip = id->driver_data;
738 - bus->read = &bq27200_read;
740 - di->client = client;
742 - bq27x00_powersupply_init(di);
743 + di->bus.read = &bq27x00_read_i2c;
745 - retval = power_supply_register(&client->dev, &di->bat);
747 - dev_err(&client->dev, "failed to register battery\n");
748 - goto batt_failed_4;
750 + if (bq27x00_powersupply_init(di))
751 + goto batt_failed_3;
753 - dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION);
754 + i2c_set_clientdata(client, di);
763 @@ -323,11 +656,11 @@ batt_failed_1:
767 -static int bq27200_battery_remove(struct i2c_client *client)
768 +static int bq27x00_battery_remove(struct i2c_client *client)
770 struct bq27x00_device_info *di = i2c_get_clientdata(client);
772 - power_supply_unregister(&di->bat);
773 + bq27x00_powersupply_unregister(di);
777 @@ -340,31 +673,180 @@ static int bq27200_battery_remove(struct
785 -static const struct i2c_device_id bq27200_id[] = {
787 +static const struct i2c_device_id bq27x00_id[] = {
788 + { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */
789 + { "bq27500", BQ27500 },
792 +MODULE_DEVICE_TABLE(i2c, bq27x00_id);
794 +static struct i2c_driver bq27x00_battery_driver = {
796 + .name = "bq27x00-battery",
798 + .probe = bq27x00_battery_probe,
799 + .remove = bq27x00_battery_remove,
800 + .id_table = bq27x00_id,
803 +static inline int bq27x00_battery_i2c_init(void)
805 + int ret = i2c_add_driver(&bq27x00_battery_driver);
807 + printk(KERN_ERR "Unable to register BQ27x00 i2c driver\n");
812 +static inline void bq27x00_battery_i2c_exit(void)
814 + i2c_del_driver(&bq27x00_battery_driver);
819 +static inline int bq27x00_battery_i2c_init(void) { return 0; }
820 +static inline void bq27x00_battery_i2c_exit(void) {};
824 +/* platform specific code */
825 +#ifdef CONFIG_BATTERY_BQ27X00_PLATFORM
827 +static int bq27000_read_platform(struct bq27x00_device_info *di, u8 reg,
830 + struct device *dev = di->dev;
831 + struct bq27000_platform_data *pdata = dev->platform_data;
832 + unsigned int timeout = 3;
837 + /* Make sure the value has not changed in between reading the
838 + * lower and the upper part */
839 + upper = pdata->read(dev, reg + 1);
845 + lower = pdata->read(dev, reg);
849 + upper = pdata->read(dev, reg + 1);
850 + } while (temp != upper && --timeout);
855 + return (upper << 8) | lower;
858 + return pdata->read(dev, reg);
861 +static int __devinit bq27000_battery_probe(struct platform_device *pdev)
863 + struct bq27x00_device_info *di;
864 + struct bq27000_platform_data *pdata = pdev->dev.platform_data;
868 + dev_err(&pdev->dev, "no platform_data supplied\n");
872 + if (!pdata->read) {
873 + dev_err(&pdev->dev, "no hdq read callback supplied\n");
877 + di = kzalloc(sizeof(*di), GFP_KERNEL);
879 + dev_err(&pdev->dev, "failed to allocate device info data\n");
883 + platform_set_drvdata(pdev, di);
885 + di->dev = &pdev->dev;
886 + di->chip = BQ27000;
888 + di->bat.name = pdata->name ?: dev_name(&pdev->dev);
889 + di->bus.read = &bq27000_read_platform;
891 -static struct i2c_driver bq27200_battery_driver = {
892 + ret = bq27x00_powersupply_init(di);
899 + platform_set_drvdata(pdev, NULL);
905 +static int __devexit bq27000_battery_remove(struct platform_device *pdev)
907 + struct bq27x00_device_info *di = platform_get_drvdata(pdev);
909 + bq27x00_powersupply_unregister(di);
911 + platform_set_drvdata(pdev, NULL);
917 +static struct platform_driver bq27000_battery_driver = {
918 + .probe = bq27000_battery_probe,
919 + .remove = __devexit_p(bq27000_battery_remove),
921 - .name = "bq27200-battery",
922 + .name = "bq27000-battery",
923 + .owner = THIS_MODULE,
925 - .probe = bq27200_battery_probe,
926 - .remove = bq27200_battery_remove,
927 - .id_table = bq27200_id,
930 +static inline int bq27x00_battery_platform_init(void)
932 + int ret = platform_driver_register(&bq27000_battery_driver);
934 + printk(KERN_ERR "Unable to register BQ27000 platform driver\n");
939 +static inline void bq27x00_battery_platform_exit(void)
941 + platform_driver_unregister(&bq27000_battery_driver);
946 +static inline int bq27x00_battery_platform_init(void) { return 0; }
947 +static inline void bq27x00_battery_platform_exit(void) {};
955 static int __init bq27x00_battery_init(void)
959 - ret = i2c_add_driver(&bq27200_battery_driver);
960 + ret = bq27x00_battery_i2c_init();
964 + ret = bq27x00_battery_platform_init();
966 - printk(KERN_ERR "Unable to register BQ27200 driver\n");
967 + bq27x00_battery_i2c_exit();
971 @@ -372,7 +854,8 @@ module_init(bq27x00_battery_init);
973 static void __exit bq27x00_battery_exit(void)
975 - i2c_del_driver(&bq27200_battery_driver);
976 + bq27x00_battery_platform_exit();
977 + bq27x00_battery_i2c_exit();
979 module_exit(bq27x00_battery_exit);