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;
94 struct bq27x00_device_info {
101 - struct bq27x00_access_methods *bus;
102 + enum bq27x00_chip chip;
104 + struct bq27x00_reg_cache cache;
105 + int charge_design_full;
107 + unsigned long last_update;
108 + struct delayed_work work;
110 struct power_supply bat;
112 - struct i2c_client *client;
113 + struct bq27x00_access_methods bus;
118 static enum power_supply_property bq27x00_battery_props[] = {
119 + POWER_SUPPLY_PROP_STATUS,
120 POWER_SUPPLY_PROP_PRESENT,
121 POWER_SUPPLY_PROP_VOLTAGE_NOW,
122 POWER_SUPPLY_PROP_CURRENT_NOW,
123 POWER_SUPPLY_PROP_CAPACITY,
124 POWER_SUPPLY_PROP_TEMP,
125 + POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
126 + POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
127 + POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
128 + POWER_SUPPLY_PROP_TECHNOLOGY,
129 + POWER_SUPPLY_PROP_CHARGE_FULL,
130 + POWER_SUPPLY_PROP_CHARGE_NOW,
131 + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
134 +static unsigned int poll_interval = 360;
135 +module_param(poll_interval, uint, 0644);
136 +MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \
137 + "0 disables polling");
140 * Common code for BQ27x00 devices
143 -static int bq27x00_read(u8 reg, int *rt_value, int b_single,
144 - struct bq27x00_device_info *di)
145 +static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg,
149 + return di->bus.read(di, reg, single);
153 + * Return the battery Relative State-of-Charge
154 + * Or < 0 if something fails.
156 +static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di)
160 - ret = di->bus->read(reg, rt_value, b_single, di);
161 - *rt_value = be16_to_cpu(*rt_value);
162 + if (di->chip == BQ27500)
163 + rsoc = bq27x00_read(di, BQ27500_REG_SOC, false);
165 + rsoc = bq27x00_read(di, BQ27000_REG_RSOC, true);
169 + dev_err(di->dev, "error reading relative State-of-Charge\n");
175 - * Return the battery temperature in Celcius degrees
176 + * Return a battery charge value in µAh
177 * Or < 0 if something fails.
179 -static int bq27x00_battery_temperature(struct bq27x00_device_info *di)
180 +static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)
186 - ret = bq27x00_read(BQ27x00_REG_TEMP, &temp, 0, di);
188 - dev_err(di->dev, "error reading temperature\n");
190 + charge = bq27x00_read(di, reg, false);
192 + dev_err(di->dev, "error reading nominal available capacity\n");
196 - return (temp >> 2) - 273;
197 + if (di->chip == BQ27500)
200 + charge = charge * 3570 / BQ27000_RS;
206 - * Return the battery Voltage in milivolts
207 + * Return the battery Nominal available capaciy in µAh
208 * Or < 0 if something fails.
210 -static int bq27x00_battery_voltage(struct bq27x00_device_info *di)
211 +static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di)
215 + return bq27x00_battery_read_charge(di, BQ27x00_REG_NAC);
218 - ret = bq27x00_read(BQ27x00_REG_VOLT, &volt, 0, di);
220 - dev_err(di->dev, "error reading voltage\n");
223 + * Return the battery Last measured discharge in µAh
224 + * Or < 0 if something fails.
226 +static inline int bq27x00_battery_read_lmd(struct bq27x00_device_info *di)
228 + return bq27x00_battery_read_charge(di, BQ27x00_REG_LMD);
232 + * Return the battery Initial last measured discharge in µAh
233 + * Or < 0 if something fails.
235 +static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di)
239 + if (di->chip == BQ27500)
240 + ilmd = bq27x00_read(di, BQ27500_REG_DCAP, false);
242 + ilmd = bq27x00_read(di, BQ27000_REG_ILMD, true);
245 + dev_err(di->dev, "error reading initial last measured discharge\n");
250 + if (di->chip == BQ27500)
253 + ilmd = ilmd * 256 * 3570 / BQ27000_RS;
259 - * Return the battery average current
260 - * Note that current can be negative signed as well
261 - * Or 0 if something fails.
262 + * Return the battery Cycle count total
263 + * Or < 0 if something fails.
265 -static int bq27x00_battery_current(struct bq27x00_device_info *di)
266 +static int bq27x00_battery_read_cyct(struct bq27x00_device_info *di)
273 - ret = bq27x00_read(BQ27x00_REG_AI, &curr, 0, di);
275 - dev_err(di->dev, "error reading current\n");
277 + cyct = bq27x00_read(di, BQ27x00_REG_CYCT, false);
279 + dev_err(di->dev, "error reading cycle count total\n");
285 + * Read a time register.
286 + * Return < 0 if something fails.
288 +static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg)
292 + tval = bq27x00_read(di, reg, false);
294 + dev_err(di->dev, "error reading register %02x: %d\n", reg, tval);
297 - ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
299 - dev_err(di->dev, "error reading flags\n");
307 +static void bq27x00_update(struct bq27x00_device_info *di)
309 + struct bq27x00_reg_cache cache = {0, };
310 + bool is_bq27500 = di->chip == BQ27500;
312 + cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, is_bq27500);
313 + if (cache.flags >= 0) {
314 + cache.capacity = bq27x00_battery_read_rsoc(di);
315 + cache.temperature = bq27x00_read(di, BQ27x00_REG_TEMP, false);
316 + cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE);
317 + cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP);
318 + cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF);
319 + cache.charge_full = bq27x00_battery_read_lmd(di);
322 + cache.current_now = bq27x00_read(di, BQ27x00_REG_AI, false);
324 + /* We only have to read charge design full once */
325 + if (di->charge_design_full <= 0)
326 + di->charge_design_full = bq27x00_battery_read_ilmd(di);
328 - if ((flags & (1 << 7)) != 0) {
329 - dev_dbg(di->dev, "negative current!\n");
332 + /* Ignore current_now which is a snapshot of the current battery state
333 + * and is likely to be different even between two consecutive reads */
334 + if (memcmp(&di->cache, &cache, sizeof(cache) - sizeof(int)) != 0) {
336 + power_supply_changed(&di->bat);
339 + di->last_update = jiffies;
342 +static void bq27x00_battery_poll(struct work_struct *work)
344 + struct bq27x00_device_info *di =
345 + container_of(work, struct bq27x00_device_info, work.work);
347 + bq27x00_update(di);
349 + if (poll_interval > 0) {
350 + schedule_delayed_work(&di->work, poll_interval * HZ);
357 - * Return the battery Relative State-of-Charge
358 + * Return the battery temperature in tenths of degree Celsius
359 * Or < 0 if something fails.
361 -static int bq27x00_battery_rsoc(struct bq27x00_device_info *di)
362 +static int bq27x00_battery_temperature(struct bq27x00_device_info *di,
363 + union power_supply_propval *val)
367 + if (di->cache.temperature < 0)
368 + return di->cache.temperature;
370 - ret = bq27x00_read(BQ27x00_REG_RSOC, &rsoc, 1, di);
372 - dev_err(di->dev, "error reading relative State-of-Charge\n");
374 + if (di->chip == BQ27500)
375 + val->intval = di->cache.temperature - 2731;
377 + val->intval = ((di->cache.temperature * 5) - 5463) / 2;
383 + * Return the battery average current in µA
384 + * Note that current can be negative signed as well
385 + * Or 0 if something fails.
387 +static int bq27x00_battery_current(struct bq27x00_device_info *di,
388 + union power_supply_propval *val)
392 + if (di->chip == BQ27500)
393 + curr = bq27x00_read(di, BQ27x00_REG_AI, false);
395 + curr = di->cache.current_now;
400 + if (di->chip == BQ27500) {
401 + /* bq27500 returns signed value */
402 + val->intval = (int)((s16)curr) * 1000;
404 + if (di->cache.flags & BQ27000_FLAG_CHGS) {
405 + dev_dbg(di->dev, "negative current!\n");
409 + val->intval = curr * 3570 / BQ27000_RS;
416 +static int bq27x00_battery_status(struct bq27x00_device_info *di,
417 + union power_supply_propval *val)
421 + if (di->chip == BQ27500) {
422 + if (di->cache.flags & BQ27500_FLAG_FC)
423 + status = POWER_SUPPLY_STATUS_FULL;
424 + else if (di->cache.flags & BQ27500_FLAG_DSC)
425 + status = POWER_SUPPLY_STATUS_DISCHARGING;
427 + status = POWER_SUPPLY_STATUS_CHARGING;
429 + if (di->cache.flags & BQ27000_FLAG_FC)
430 + status = POWER_SUPPLY_STATUS_FULL;
431 + else if (di->cache.flags & BQ27000_FLAG_CHGS)
432 + status = POWER_SUPPLY_STATUS_CHARGING;
433 + else if (power_supply_am_i_supplied(&di->bat))
434 + status = POWER_SUPPLY_STATUS_NOT_CHARGING;
436 + status = POWER_SUPPLY_STATUS_DISCHARGING;
439 + val->intval = status;
445 + * Return the battery Voltage in milivolts
446 + * Or < 0 if something fails.
448 +static int bq27x00_battery_voltage(struct bq27x00_device_info *di,
449 + union power_supply_propval *val)
453 + volt = bq27x00_read(di, BQ27x00_REG_VOLT, false);
457 + val->intval = volt * 1000;
463 + * Return the battery Available energy in µWh
464 + * Or < 0 if something fails.
466 +static int bq27x00_battery_energy(struct bq27x00_device_info *di,
467 + union power_supply_propval *val)
471 + ae = bq27x00_read(di, BQ27x00_REG_AE, false);
473 + dev_err(di->dev, "error reading available energy\n");
477 + if (di->chip == BQ27500)
480 + ae = ae * 29200 / BQ27000_RS;
488 +static int bq27x00_simple_value(int value,
489 + union power_supply_propval *val)
494 + val->intval = value;
499 #define to_bq27x00_device_info(x) container_of((x), \
500 @@ -171,89 +443,161 @@ static int bq27x00_battery_get_property(
501 enum power_supply_property psp,
502 union power_supply_propval *val)
505 struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
507 + mutex_lock(&di->lock);
508 + if (time_is_before_jiffies(di->last_update + 5 * HZ)) {
509 + cancel_delayed_work_sync(&di->work);
510 + bq27x00_battery_poll(&di->work.work);
512 + mutex_unlock(&di->lock);
514 + if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0)
518 + case POWER_SUPPLY_PROP_STATUS:
519 + ret = bq27x00_battery_status(di, val);
521 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
522 + ret = bq27x00_battery_voltage(di, val);
524 case POWER_SUPPLY_PROP_PRESENT:
525 - val->intval = bq27x00_battery_voltage(di);
526 - if (psp == POWER_SUPPLY_PROP_PRESENT)
527 - val->intval = val->intval <= 0 ? 0 : 1;
528 + val->intval = di->cache.flags < 0 ? 0 : 1;
530 case POWER_SUPPLY_PROP_CURRENT_NOW:
531 - val->intval = bq27x00_battery_current(di);
532 + ret = bq27x00_battery_current(di, val);
534 case POWER_SUPPLY_PROP_CAPACITY:
535 - val->intval = bq27x00_battery_rsoc(di);
536 + ret = bq27x00_simple_value(di->cache.capacity, val);
538 case POWER_SUPPLY_PROP_TEMP:
539 - val->intval = bq27x00_battery_temperature(di);
540 + ret = bq27x00_battery_temperature(di, val);
542 + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
543 + ret = bq27x00_simple_value(di->cache.time_to_empty, val);
545 + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
546 + ret = bq27x00_simple_value(di->cache.time_to_empty_avg, val);
548 + case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
549 + ret = bq27x00_simple_value(di->cache.time_to_full, val);
551 + case POWER_SUPPLY_PROP_TECHNOLOGY:
552 + val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
554 + case POWER_SUPPLY_PROP_CHARGE_NOW:
555 + ret = bq27x00_simple_value(bq27x00_battery_read_nac(di), val);
557 + case POWER_SUPPLY_PROP_CHARGE_FULL:
558 + ret = bq27x00_simple_value(di->cache.charge_full, val);
560 + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
561 + ret = bq27x00_simple_value(di->charge_design_full, val);
563 + case POWER_SUPPLY_PROP_ENERGY_NOW:
564 + ret = bq27x00_battery_energy(di, val);
574 -static void bq27x00_powersupply_init(struct bq27x00_device_info *di)
575 +static void bq27x00_external_power_changed(struct power_supply *psy)
577 + struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
579 + cancel_delayed_work_sync(&di->work);
580 + schedule_delayed_work(&di->work, 0);
583 +static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
587 di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
588 di->bat.properties = bq27x00_battery_props;
589 di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props);
590 di->bat.get_property = bq27x00_battery_get_property;
591 - di->bat.external_power_changed = NULL;
592 + di->bat.external_power_changed = bq27x00_external_power_changed;
594 + INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll);
595 + mutex_init(&di->lock);
597 + ret = power_supply_register(di->dev, &di->bat);
599 + dev_err(di->dev, "failed to register battery: %d\n", ret);
603 + dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);
605 + bq27x00_update(di);
611 - * BQ27200 specific code
612 +static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di)
614 + cancel_delayed_work_sync(&di->work);
616 + power_supply_unregister(&di->bat);
618 + mutex_destroy(&di->lock);
622 +/* i2c specific code */
623 +#ifdef CONFIG_BATTERY_BQ27X00_I2C
625 +/* If the system has several batteries we need a different name for each
628 +static DEFINE_IDR(battery_id);
629 +static DEFINE_MUTEX(battery_mutex);
631 -static int bq27200_read(u8 reg, int *rt_value, int b_single,
632 - struct bq27x00_device_info *di)
633 +static int bq27x00_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single)
635 - struct i2c_client *client = di->client;
636 - struct i2c_msg msg[1];
637 + struct i2c_client *client = to_i2c_client(di->dev);
638 + struct i2c_msg msg[2];
639 unsigned char data[2];
643 if (!client->adapter)
646 - msg->addr = client->addr;
652 - err = i2c_transfer(client->adapter, msg, 1);
659 + msg[0].addr = client->addr;
662 + msg[0].len = sizeof(reg);
663 + msg[1].addr = client->addr;
664 + msg[1].flags = I2C_M_RD;
671 - msg->flags = I2C_M_RD;
672 - err = i2c_transfer(client->adapter, msg, 1);
675 - *rt_value = get_unaligned_be16(data);
677 - *rt_value = data[0];
678 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
687 + ret = get_unaligned_le16(data);
694 -static int bq27200_battery_probe(struct i2c_client *client,
695 +static int bq27x00_battery_probe(struct i2c_client *client,
696 const struct i2c_device_id *id)
699 struct bq27x00_device_info *di;
700 - struct bq27x00_access_methods *bus;
704 @@ -267,7 +611,7 @@ static int bq27200_battery_probe(struct
708 - name = kasprintf(GFP_KERNEL, "bq27200-%d", num);
709 + name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);
711 dev_err(&client->dev, "failed to allocate device name\n");
713 @@ -280,37 +624,20 @@ static int bq27200_battery_probe(struct
719 - bus = kzalloc(sizeof(*bus), GFP_KERNEL);
721 - dev_err(&client->dev, "failed to allocate access method "
724 - goto batt_failed_3;
727 - i2c_set_clientdata(client, di);
729 di->dev = &client->dev;
730 + di->chip = id->driver_data;
732 - bus->read = &bq27200_read;
734 - di->client = client;
736 - bq27x00_powersupply_init(di);
737 + di->bus.read = &bq27x00_read_i2c;
739 - retval = power_supply_register(&client->dev, &di->bat);
741 - dev_err(&client->dev, "failed to register battery\n");
742 - goto batt_failed_4;
744 + if (bq27x00_powersupply_init(di))
745 + goto batt_failed_3;
747 - dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION);
748 + i2c_set_clientdata(client, di);
757 @@ -323,11 +650,11 @@ batt_failed_1:
761 -static int bq27200_battery_remove(struct i2c_client *client)
762 +static int bq27x00_battery_remove(struct i2c_client *client)
764 struct bq27x00_device_info *di = i2c_get_clientdata(client);
766 - power_supply_unregister(&di->bat);
767 + bq27x00_powersupply_unregister(di);
771 @@ -340,31 +667,180 @@ static int bq27200_battery_remove(struct
779 -static const struct i2c_device_id bq27200_id[] = {
781 +static const struct i2c_device_id bq27x00_id[] = {
782 + { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */
783 + { "bq27500", BQ27500 },
786 +MODULE_DEVICE_TABLE(i2c, bq27x00_id);
788 +static struct i2c_driver bq27x00_battery_driver = {
790 + .name = "bq27x00-battery",
792 + .probe = bq27x00_battery_probe,
793 + .remove = bq27x00_battery_remove,
794 + .id_table = bq27x00_id,
797 +static inline int bq27x00_battery_i2c_init(void)
799 + int ret = i2c_add_driver(&bq27x00_battery_driver);
801 + printk(KERN_ERR "Unable to register BQ27x00 i2c driver\n");
806 +static inline void bq27x00_battery_i2c_exit(void)
808 + i2c_del_driver(&bq27x00_battery_driver);
813 +static inline int bq27x00_battery_i2c_init(void) { return 0; }
814 +static inline void bq27x00_battery_i2c_exit(void) {};
818 +/* platform specific code */
819 +#ifdef CONFIG_BATTERY_BQ27X00_PLATFORM
821 +static int bq27000_read_platform(struct bq27x00_device_info *di, u8 reg,
824 + struct device *dev = di->dev;
825 + struct bq27000_platform_data *pdata = dev->platform_data;
826 + unsigned int timeout = 3;
831 + /* Make sure the value has not changed in between reading the
832 + * lower and the upper part */
833 + upper = pdata->read(dev, reg + 1);
839 + lower = pdata->read(dev, reg);
843 + upper = pdata->read(dev, reg + 1);
844 + } while (temp != upper && --timeout);
849 + return (upper << 8) | lower;
852 + return pdata->read(dev, reg);
855 +static int __devinit bq27000_battery_probe(struct platform_device *pdev)
857 + struct bq27x00_device_info *di;
858 + struct bq27000_platform_data *pdata = pdev->dev.platform_data;
862 + dev_err(&pdev->dev, "no platform_data supplied\n");
866 + if (!pdata->read) {
867 + dev_err(&pdev->dev, "no hdq read callback supplied\n");
871 + di = kzalloc(sizeof(*di), GFP_KERNEL);
873 + dev_err(&pdev->dev, "failed to allocate device info data\n");
877 + platform_set_drvdata(pdev, di);
879 + di->dev = &pdev->dev;
880 + di->chip = BQ27000;
882 + di->bat.name = pdata->name ?: dev_name(&pdev->dev);
883 + di->bus.read = &bq27000_read_platform;
885 -static struct i2c_driver bq27200_battery_driver = {
886 + ret = bq27x00_powersupply_init(di);
893 + platform_set_drvdata(pdev, NULL);
899 +static int __devexit bq27000_battery_remove(struct platform_device *pdev)
901 + struct bq27x00_device_info *di = platform_get_drvdata(pdev);
903 + bq27x00_powersupply_unregister(di);
905 + platform_set_drvdata(pdev, NULL);
911 +static struct platform_driver bq27000_battery_driver = {
912 + .probe = bq27000_battery_probe,
913 + .remove = __devexit_p(bq27000_battery_remove),
915 - .name = "bq27200-battery",
916 + .name = "bq27000-battery",
917 + .owner = THIS_MODULE,
919 - .probe = bq27200_battery_probe,
920 - .remove = bq27200_battery_remove,
921 - .id_table = bq27200_id,
924 +static inline int bq27x00_battery_platform_init(void)
926 + int ret = platform_driver_register(&bq27000_battery_driver);
928 + printk(KERN_ERR "Unable to register BQ27000 platform driver\n");
933 +static inline void bq27x00_battery_platform_exit(void)
935 + platform_driver_unregister(&bq27000_battery_driver);
940 +static inline int bq27x00_battery_platform_init(void) { return 0; }
941 +static inline void bq27x00_battery_platform_exit(void) {};
949 static int __init bq27x00_battery_init(void)
953 - ret = i2c_add_driver(&bq27200_battery_driver);
954 + ret = bq27x00_battery_i2c_init();
958 + ret = bq27x00_battery_platform_init();
960 - printk(KERN_ERR "Unable to register BQ27200 driver\n");
961 + bq27x00_battery_i2c_exit();
965 @@ -372,7 +848,8 @@ module_init(bq27x00_battery_init);
967 static void __exit bq27x00_battery_exit(void)
969 - i2c_del_driver(&bq27200_battery_driver);
970 + bq27x00_battery_platform_exit();
971 + bq27x00_battery_i2c_exit();
973 module_exit(bq27x00_battery_exit);