2 * BQ27510 battery driver
4 * This package is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 #include <linux/module.h>
14 #include <linux/param.h>
15 #include <linux/jiffies.h>
16 #include <linux/workqueue.h>
17 #include <linux/delay.h>
18 #include <linux/platform_device.h>
19 #include <linux/power_supply.h>
20 #include <linux/idr.h>
21 #include <linux/i2c.h>
22 #include <linux/slab.h>
23 #include <asm/unaligned.h>
24 #include <mach/gpio.h>
25 #include <linux/proc_fs.h>
26 #include <asm/uaccess.h>
27 #include <mach/board.h>
28 #include <linux/irq.h>
29 #include <linux/interrupt.h>
33 #define DRIVER_VERSION "1.1.0"
34 #define BQ27x00_REG_TEMP 0x06
35 #define BQ27x00_REG_VOLT 0x08
36 #define BQ27x00_REG_AI 0x14
37 #define BQ27x00_REG_FLAGS 0x0A
38 #define BQ27x00_REG_TTE 0x16
39 #define BQ27x00_REG_TTF 0x18
40 #define BQ27x00_REG_TTECP 0x26
41 #define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */
42 #define BQ27500_REG_SOC 0x2c
44 #define BQ27500_FLAG_DSC BIT(0)
45 #define BQ27000_FLAG_CHGS BIT(8)
46 #define BQ27500_FLAG_FC BIT(9)
47 #define BQ27500_FLAG_OTD BIT(14)
48 #define BQ27500_FLAG_OTC BIT(15)
50 #define BQ27510_SPEED 100 * 1000
51 #define POWER_ON_PIN RK29_PIN4_PA4
52 //#define CHG_OK RK29_PIN4_PA3
54 //#define BAT_LOW RK29_PIN4_PA2
57 int virtual_battery_enable = 0;
58 extern int dwc_vbus_status(void);
59 static void bq27541_set(void);
63 #define DBG(x...) printk(KERN_INFO x)
65 #define DBG(x...) do { } while (0)
68 /* If the system has several batteries we need a different name for each
71 static DEFINE_MUTEX(battery_mutex);
73 struct bq27541_device_info {
75 struct power_supply bat;
76 struct power_supply ac;
77 struct delayed_work work;
78 struct delayed_work wakeup_work;
79 struct i2c_client *client;
81 unsigned int interval;
82 unsigned int dc_check_pin;
83 unsigned int bat_check_pin;
88 static struct bq27541_device_info *bq27541_di;
89 static enum power_supply_property bq27541_battery_props[] = {
90 POWER_SUPPLY_PROP_STATUS,
91 POWER_SUPPLY_PROP_PRESENT,
92 POWER_SUPPLY_PROP_VOLTAGE_NOW,
93 POWER_SUPPLY_PROP_CURRENT_NOW,
94 POWER_SUPPLY_PROP_CAPACITY,
95 POWER_SUPPLY_PROP_TEMP,
96 POWER_SUPPLY_PROP_TECHNOLOGY,
97 POWER_SUPPLY_PROP_HEALTH,
98 //POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
99 //POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
100 //POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
103 static enum power_supply_property rk29_ac_props[] = {
104 POWER_SUPPLY_PROP_ONLINE,
107 static ssize_t battery_proc_write(struct file *file,const char __user *buffer,
108 unsigned long count,void *data)
113 printk("echo x >/proc/driver/power\n");
114 printk("x=1,means just print log ||x=2,means log and data ||x= other,means close log\n");
116 rc = get_user(c,buffer);
120 //added by zwp,c='8' means check whether we need to download firmware to bq27xxx,return 0 means yes.
122 printk("%s,bq27541 don't need to download firmware\n",__FUNCTION__);
123 return -1;//bq27541 don't need to download firmware.
126 virtual_battery_enable = 1;
128 virtual_battery_enable = 2;
130 virtual_battery_enable = 3;
132 printk("%s:%d>>bq27541 set\n",__FUNCTION__,__LINE__);
136 virtual_battery_enable = 0;
137 printk("%s,count(%d),virtual_battery_enable(%d)\n",__FUNCTION__,(int)count,virtual_battery_enable);
141 static const struct file_operations battery_proc_fops = {
142 .owner = THIS_MODULE,
143 .write = battery_proc_write,
147 * Common code for BQ27510 devices read
149 static int bq27541_read(struct i2c_client *client, u8 reg, u8 buf[], unsigned len)
152 ret = i2c_master_reg8_recv(client, reg, buf, len, BQ27510_SPEED);
156 static int bq27541_write(struct i2c_client *client, u8 reg, u8 const buf[], unsigned len)
159 ret = i2c_master_reg8_send(client, reg, buf, (int)len, BQ27510_SPEED);
164 * Return the battery temperature in tenths of degree Celsius
165 * Or < 0 if something fails.
168 static irqreturn_t bq27541_bat_wakeup(int irq, void *dev_id)
170 struct bq27541_device_info *di = (struct bq27541_device_info *)dev_id;
172 printk("!!! bq27541 bat_low irq low vol !!!\n\n\n");
173 disable_irq_wake(di->wake_irq);
175 schedule_delayed_work(&di->wakeup_work, msecs_to_jiffies(0));
179 static void bq27541_battery_wake_work(struct work_struct *work)
182 struct bq27541_device_info *di =
183 (struct bq27541_device_info *)container_of(work, struct bq27541_device_info, wakeup_work.work);
185 rk28_send_wakeup_key();
187 free_irq(di->wake_irq, di);
188 di->wake_irq = gpio_to_irq(di->bat_check_pin);
190 ret = request_irq(di->wake_irq, bq27541_bat_wakeup, IRQF_TRIGGER_FALLING, "bq27541_battery", di);
192 printk("request faild!\n");
195 enable_irq_wake(di->wake_irq);
199 static int bq27541_battery_temperature(struct bq27541_device_info *di)
205 #if defined (CONFIG_NO_BATTERY_IC)
209 if(virtual_battery_enable == 1)
211 ret = bq27541_read(di->client,BQ27x00_REG_TEMP,buf,2);
213 dev_err(di->dev, "error reading temperature\n");
216 temp = get_unaligned_le16(buf);
217 temp = temp - 2731; //K
218 DBG("Enter:%s %d--temp = %d\n",__FUNCTION__,__LINE__,temp);
220 // rk29_pm_power_off();
225 * Return the battery Voltage in milivolts
226 * Or < 0 if something fails.
231 static int bq27541_battery_voltage(struct bq27541_device_info *di)
237 #if defined (CONFIG_NO_BATTERY_IC)
240 if(virtual_battery_enable == 1)
241 return 2000000/*4000000*/;
243 ret = bq27541_read(di->client,BQ27x00_REG_VOLT,buf,2);
245 dev_err(di->dev, "error reading voltage\n");
246 // gpio_set_value(POWER_ON_PIN, GPIO_LOW);
249 volt = get_unaligned_le16(buf);
251 //bp27510 can only measure one li-lion bat
252 if(di->bat_num == 2){
253 volt = volt * 1000 * 2;
261 if ((volt <= 3400000) && (volt > 0) && gpio_get_value(di->dc_check_pin)){
262 printk("vol smaller then 3.4V, report to android!");
269 DBG("Enter:%s %d--volt = %d\n",__FUNCTION__,__LINE__,volt);
274 * Return the battery average current
275 * Note that current can be negative signed as well
276 * Or 0 if something fails.
278 static int bq27541_battery_current(struct bq27541_device_info *di)
284 #if defined (CONFIG_NO_BATTERY_IC)
287 if(virtual_battery_enable == 1)
288 return 11000/*22000*/;
289 ret = bq27541_read(di->client,BQ27x00_REG_AI,buf,2);
291 dev_err(di->dev, "error reading current\n");
295 curr = get_unaligned_le16(buf);
296 DBG("curr = %x \n",curr);
298 curr = 0xFFFF^(curr-1);
301 DBG("Enter:%s %d--curr = %d\n",__FUNCTION__,__LINE__,curr);
306 * Return the battery Relative State-of-Charge
307 * Or < 0 if something fails.
309 static int bq27541_battery_rsoc(struct bq27541_device_info *di)
314 int nvcap = 0,facap = 0,remcap=0,fccap=0,full=0,cnt=0;
315 int art = 0, artte = 0, ai = 0, tte = 0, ttf = 0, si = 0;
316 int stte = 0, mli = 0, mltte = 0, ae = 0, ap = 0, ttecp = 0, cc = 0;
320 #if defined (CONFIG_NO_BATTERY_IC)
323 if(virtual_battery_enable == 1)
326 ret = bq27541_read(di->client,BQ27500_REG_SOC,buf,2);
328 dev_err(di->dev, "error reading relative State-of-Charge\n");
331 rsoc = get_unaligned_le16(buf);
332 DBG("Enter:%s %d--rsoc = %d\n",__FUNCTION__,__LINE__,rsoc);
334 #if defined (CONFIG_NO_BATTERY_IC)
337 #if 0 //other register information, for debug use
338 ret = bq27541_read(di->client,0x0c,buf,2); //NominalAvailableCapacity
339 nvcap = get_unaligned_le16(buf);
340 DBG("\nEnter:%s %d--nvcap = %d\n",__FUNCTION__,__LINE__,nvcap);
341 ret = bq27541_read(di->client,0x0e,buf,2); //FullAvailableCapacity
342 facap = get_unaligned_le16(buf);
343 DBG("Enter:%s %d--facap = %d\n",__FUNCTION__,__LINE__,facap);
344 ret = bq27541_read(di->client,0x10,buf,2); //RemainingCapacity
345 remcap = get_unaligned_le16(buf);
346 DBG("Enter:%s %d--remcap = %d\n",__FUNCTION__,__LINE__,remcap);
347 ret = bq27541_read(di->client,0x12,buf,2); //FullChargeCapacity
348 fccap = get_unaligned_le16(buf);
349 DBG("Enter:%s %d--fccap = %d\n",__FUNCTION__,__LINE__,fccap);
350 ret = bq27541_read(di->client,0x3c,buf,2); //DesignCapacity
351 full = get_unaligned_le16(buf);
352 DBG("Enter:%s %d--DesignCapacity = %d\n",__FUNCTION__,__LINE__,full);
354 buf[0] = 0x00; //CONTROL_STATUS
356 bq27541_write(di->client,0x00,buf,2);
357 ret = bq27541_read(di->client,0x00,buf,2);
358 cnt = get_unaligned_le16(buf);
359 DBG("Enter:%s %d--Control status = %x\n",__FUNCTION__,__LINE__,cnt);
361 ret = bq27541_read(di->client,0x02,buf,2); //AtRate
362 art = get_unaligned_le16(buf);
363 DBG("Enter:%s %d--AtRate = %d\n",__FUNCTION__,__LINE__,art);
364 ret = bq27541_read(di->client,0x04,buf,2); //AtRateTimeToEmpty
365 artte = get_unaligned_le16(buf);
366 DBG("Enter:%s %d--AtRateTimeToEmpty = %d\n",__FUNCTION__,__LINE__,artte);
367 ret = bq27541_read(di->client,0x14,buf,2); //AverageCurrent
368 ai = get_unaligned_le16(buf);
369 DBG("Enter:%s %d--AverageCurrent = %d\n",__FUNCTION__,__LINE__,ai);
370 ret = bq27541_read(di->client,0x16,buf,2); //TimeToEmpty
371 tte = get_unaligned_le16(buf);
372 DBG("Enter:%s %d--TimeToEmpty = %d\n",__FUNCTION__,__LINE__,tte);
373 ret = bq27541_read(di->client,0x18,buf,2); //TimeToFull
374 ttf = get_unaligned_le16(buf);
375 DBG("Enter:%s %d--TimeToFull = %d\n",__FUNCTION__,__LINE__,ttf);
376 ret = bq27541_read(di->client,0x1a,buf,2); //StandbyCurrent
377 si = get_unaligned_le16(buf);
378 DBG("Enter:%s %d--StandbyCurrent = %d\n",__FUNCTION__,__LINE__,si);
379 ret = bq27541_read(di->client,0x1c,buf,2); //StandbyTimeToEmpty
380 stte = get_unaligned_le16(buf);
381 DBG("Enter:%s %d--StandbyTimeToEmpty = %d\n",__FUNCTION__,__LINE__,stte);
382 ret = bq27541_read(di->client,0x1e,buf,2); //MaxLoadCurrent
383 mli = get_unaligned_le16(buf);
384 DBG("Enter:%s %d--MaxLoadCurrent = %d\n",__FUNCTION__,__LINE__,mli);
385 ret = bq27541_read(di->client,0x20,buf,2); //MaxLoadTimeToEmpty
386 mltte = get_unaligned_le16(buf);
387 DBG("Enter:%s %d--MaxLoadTimeToEmpty = %d\n",__FUNCTION__,__LINE__,mltte);
388 ret = bq27541_read(di->client,0x22,buf,2); //AvailableEnergy
389 ae = get_unaligned_le16(buf);
390 DBG("Enter:%s %d--AvailableEnergy = %d\n",__FUNCTION__,__LINE__,ae);
391 ret = bq27541_read(di->client,0x24,buf,2); //AveragePower
392 ap = get_unaligned_le16(buf);
393 DBG("Enter:%s %d--AveragePower = %d\n",__FUNCTION__,__LINE__,ap);
394 ret = bq27541_read(di->client,0x26,buf,2); //TTEatConstantPower
395 ttecp = get_unaligned_le16(buf);
396 DBG("Enter:%s %d--TTEatConstantPower = %d\n",__FUNCTION__,__LINE__,ttecp);
397 ret = bq27541_read(di->client,0x2a,buf,2); //CycleCount
398 cc = get_unaligned_le16(buf);
399 DBG("Enter:%s %d--CycleCount = %d\n",__FUNCTION__,__LINE__,cc);
404 static int bq27541_battery_status(struct bq27541_device_info *di,
405 union power_supply_propval *val)
412 #if defined (CONFIG_NO_BATTERY_IC)
413 val->intval = POWER_SUPPLY_STATUS_FULL;
417 if(virtual_battery_enable == 1)
419 val->intval = POWER_SUPPLY_STATUS_FULL;
422 ret = bq27541_read(di->client,BQ27x00_REG_FLAGS, buf, 2);
424 dev_err(di->dev, "error reading flags\n");
427 flags = get_unaligned_le16(buf);
428 DBG("Enter:%s %d--status = %x\n",__FUNCTION__,__LINE__,flags);
429 if (flags & BQ27500_FLAG_FC)
430 status = POWER_SUPPLY_STATUS_FULL;
431 else if (flags & BQ27500_FLAG_DSC)
432 status = POWER_SUPPLY_STATUS_DISCHARGING;
434 status = POWER_SUPPLY_STATUS_CHARGING;
436 val->intval = status;
440 static int bq27541_health_status(struct bq27541_device_info *di,
441 union power_supply_propval *val)
448 #if defined (CONFIG_NO_BATTERY_IC)
449 val->intval = POWER_SUPPLY_HEALTH_GOOD;
453 if(virtual_battery_enable == 1)
455 val->intval = POWER_SUPPLY_HEALTH_GOOD;
458 ret = bq27541_read(di->client,BQ27x00_REG_FLAGS, buf, 2);
460 dev_err(di->dev, "error reading flags\n");
463 flags = get_unaligned_le16(buf);
464 DBG("Enter:%s %d--status = %x\n",__FUNCTION__,__LINE__,flags);
466 if ((flags & BQ27500_FLAG_OTD)||(flags & BQ27500_FLAG_OTC))
467 status = POWER_SUPPLY_HEALTH_OVERHEAT;
469 status = POWER_SUPPLY_HEALTH_GOOD;
473 val->intval = status;
479 * Read a time register.
480 * Return < 0 if something fails.
482 static int bq27541_battery_time(struct bq27541_device_info *di, int reg,
483 union power_supply_propval *val)
489 ret = bq27541_read(di->client,reg,buf,2);
491 dev_err(di->dev, "error reading register %02x\n", reg);
494 tval = get_unaligned_le16(buf);
495 DBG("Enter:%s %d--tval=%d\n",__FUNCTION__,__LINE__,tval);
499 val->intval = tval * 60;
500 DBG("Enter:%s %d val->intval = %d\n",__FUNCTION__,__LINE__,val->intval);
504 #define to_bq27541_device_info(x) container_of((x), \
505 struct bq27541_device_info, bat);
507 static int bq27541_battery_get_property(struct power_supply *psy,
508 enum power_supply_property psp,
509 union power_supply_propval *val)
513 struct bq27541_device_info *di = to_bq27541_device_info(psy);
514 DBG("Enter:%s %d psp= %d\n",__FUNCTION__,__LINE__,psp);
518 case POWER_SUPPLY_PROP_STATUS:
519 ret = bq27541_battery_status(di, val);
521 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
522 case POWER_SUPPLY_PROP_PRESENT:
523 val->intval = bq27541_battery_voltage(di);
524 if (psp == POWER_SUPPLY_PROP_PRESENT){
525 val->intval = val->intval <= 0 ? 0 : 1;
528 case POWER_SUPPLY_PROP_CURRENT_NOW:
529 val->intval = bq27541_battery_current(di);
531 case POWER_SUPPLY_PROP_CAPACITY:
532 if (di->power_down == 1){ // < 3.4V power down ,capacity = 0;
535 val->intval = bq27541_battery_rsoc(di);
539 case POWER_SUPPLY_PROP_TEMP:
540 val->intval = bq27541_battery_temperature(di);
543 case POWER_SUPPLY_PROP_TECHNOLOGY:
544 val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
546 case POWER_SUPPLY_PROP_HEALTH:
547 ret = bq27541_health_status(di, val);
549 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
550 ret = bq27541_battery_time(di, BQ27x00_REG_TTE, val);
552 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
553 ret = bq27541_battery_time(di, BQ27x00_REG_TTECP, val);
555 case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
556 ret = bq27541_battery_time(di, BQ27x00_REG_TTF, val);
566 static int rk29_ac_get_property(struct power_supply *psy,
567 enum power_supply_property psp,
568 union power_supply_propval *val)
571 struct bq27541_device_info *di = container_of(psy, struct bq27541_device_info, ac);
574 case POWER_SUPPLY_PROP_ONLINE:
575 if (psy->type == POWER_SUPPLY_TYPE_MAINS){
576 if(gpio_get_value(di->dc_check_pin))
577 val->intval = 0; /*discharging*/
579 val->intval = 1; /*charging*/
581 DBG("%s:%d val->intval = %d\n",__FUNCTION__,__LINE__,val->intval);
591 static void bq27541_powersupply_init(struct bq27541_device_info *di)
593 di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
594 di->bat.properties = bq27541_battery_props;
595 di->bat.num_properties = ARRAY_SIZE(bq27541_battery_props);
596 di->bat.get_property = bq27541_battery_get_property;
600 di->ac.type = POWER_SUPPLY_TYPE_MAINS;
601 di->ac.properties = rk29_ac_props;
602 di->ac.num_properties = ARRAY_SIZE(rk29_ac_props);
603 di->ac.get_property = rk29_ac_get_property;
607 static void bq27541_battery_update_status(struct bq27541_device_info *di)
609 power_supply_changed(&di->bat);
612 static void bq27541_battery_work(struct work_struct *work)
614 struct bq27541_device_info *di = container_of(work, struct bq27541_device_info, work.work);
615 bq27541_battery_update_status(di);
616 /* reschedule for the next time */
617 schedule_delayed_work(&di->work, di->interval);
620 static void bq27541_set(void)
622 struct bq27541_device_info *di;
627 printk("enter 0x41\n");
630 bq27541_write(di->client,0x00,buf,2);
634 printk("enter 0x21\n");
637 bq27541_write(di->client,0x00,buf,2);
641 bq27541_read(di->client,0x00,buf,2);
643 // printk("%s: Enter:BUF[0]= 0X%x BUF[1] = 0X%x\n",__FUNCTION__,buf[0],buf[1]);
645 while((buf[0] & 0x04)&&(i<5))
647 printk("enter more 0x21 times i = %d\n",i);
651 bq27541_write(di->client,0x00,buf,2);
655 bq27541_read(di->client,0x00,buf,2);
660 printk("write 0x21 error\n");
662 printk("bq27541 write 0x21 success\n");
665 static int bq27541_battery_probe(struct i2c_client *client,
666 const struct i2c_device_id *id)
668 struct bq27541_device_info *di;
670 struct bq27541_platform_data *pdata;
674 DBG("********** bq27541_battery_probe************** ");
675 pdata = client->dev.platform_data;
677 di = kzalloc(sizeof(*di), GFP_KERNEL);
679 dev_err(&client->dev, "failed to allocate device info data\n");
683 i2c_set_clientdata(client, di);
684 di->dev = &client->dev;
685 di->bat.name = "bq27541-battery";
687 /* 4 seconds between monotor runs interval */
688 di->interval = msecs_to_jiffies(4 * 1000);
690 di->bat_num = pdata->bat_num;
691 di->dc_check_pin = pdata->dc_check_pin;
692 di->bat_check_pin = pdata->bat_check_pin;
694 if (pdata->init_dc_check_pin)
695 pdata->init_dc_check_pin( );
697 bq27541_powersupply_init(di);
701 retval = power_supply_register(&client->dev, &di->bat);
703 dev_err(&client->dev, "failed to register battery\n");
707 retval = power_supply_register(&client->dev, &di->ac);
709 dev_err(&client->dev, "failed to register ac\n");
712 INIT_DELAYED_WORK(&di->work, bq27541_battery_work);
713 schedule_delayed_work(&di->work, di->interval);
714 dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION);
716 #if !defined (CONFIG_NO_BATTERY_IC)
718 // no battery , no power up
719 gpio_request(POWER_ON_PIN, "poweronpin");
720 gpio_request(pdata->bat_check_pin, NULL);
721 gpio_direction_input(pdata->bat_check_pin);
722 gpio_request(pdata->chgok_check_pin, "CHG_OK");
723 gpio_direction_input(pdata->chgok_check_pin);
725 val = gpio_get_value(pdata->bat_check_pin);
727 printk("\n\n!!! bat_low high !!!\n\n");
728 val = bq27541_read(di->client,BQ27x00_REG_VOLT,buf,2);
730 printk("\n\n!!! bq i2c err! no battery, power down\n!!!\n\n");
731 gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
733 gpio_set_value(POWER_ON_PIN, GPIO_LOW);
740 printk("\n\n!!! bat_low low !!!\n\n");
741 val = gpio_get_value(pdata->chgok_check_pin);
743 printk("no battery, power down \n");
744 gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
746 gpio_set_value(POWER_ON_PIN, GPIO_LOW);
751 val = gpio_get_value(pdata->chgok_check_pin);
753 printk("no battery, power down \n");
754 gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
756 gpio_set_value(POWER_ON_PIN, GPIO_LOW);
764 // gpio_free(POWER_ON_PIN);
765 // gpio_free(pdata->bat_check_pin);
766 gpio_free(pdata->chgok_check_pin);
769 //smaller 3.4V , no power up
770 if (gpio_get_value(di->dc_check_pin) && (gpio_get_value(pdata->bat_check_pin) == 0)){
771 printk("no AC && battery low ,so power down \n");
772 gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
774 printk("no AC && battery low ,so power down \n");
775 gpio_set_value(POWER_ON_PIN, GPIO_LOW);
782 di->wake_irq = gpio_to_irq(pdata->bat_check_pin);
783 retval = request_irq(di->wake_irq, bq27541_bat_wakeup, IRQF_TRIGGER_FALLING, "bq27541_battery", di);
785 printk("failed to request bat det irq\n");
786 goto err_batirq_failed;
789 INIT_DELAYED_WORK(&di->wakeup_work, bq27541_battery_wake_work);
790 enable_irq_wake(di->wake_irq);
802 gpio_free(pdata->bat_check_pin);
807 static int bq27541_battery_remove(struct i2c_client *client)
809 struct bq27541_device_info *di = i2c_get_clientdata(client);
811 power_supply_unregister(&di->bat);
817 static const struct i2c_device_id bq27541_id[] = {
821 static struct i2c_driver bq27541_battery_driver = {
825 .probe = bq27541_battery_probe,
826 .remove = bq27541_battery_remove,
827 .id_table = bq27541_id,
830 static int __init bq27541_battery_init(void)
834 struct proc_dir_entry * battery_proc_entry;
836 ret = i2c_add_driver(&bq27541_battery_driver);
838 printk(KERN_ERR "Unable to register BQ27541 driver\n");
840 battery_proc_entry = proc_create("driver/power",0777,NULL,&battery_proc_fops);
845 //module_init(bq27541_battery_init);
846 //fs_initcall_sync(bq27541_battery_init);
848 fs_initcall(bq27541_battery_init);
849 //arch_initcall(bq27541_battery_init);
851 static void __exit bq27541_battery_exit(void)
853 i2c_del_driver(&bq27541_battery_driver);
855 module_exit(bq27541_battery_exit);
857 MODULE_AUTHOR("clb");
858 MODULE_DESCRIPTION("BQ27541 battery monitor driver");
859 MODULE_LICENSE("GPL");