2 * linux/drivers/power/twl6030_bci_battery.c
4 * OMAP4:TWL6030 battery driver for Linux
6 * Copyright (C) 2008-2009 Texas Instruments, Inc.
7 * Author: Texas Instruments, Inc.
9 * This package is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/device.h>
21 #include <linux/interrupt.h>
22 #include <linux/delay.h>
23 #include <linux/platform_device.h>
24 #include <linux/slab.h>
25 #include <linux/i2c/twl.h>
26 #include <linux/power_supply.h>
27 #include <linux/i2c/twl6030-gpadc.h>
28 #include <linux/i2c/bq2415x.h>
29 #include <linux/wakelock.h>
30 #include <linux/usb/otg.h>
32 #include <mach/gpio.h>
34 #define CONTROLLER_INT_MASK 0x00
35 #define CONTROLLER_CTRL1 0x01
36 #define CONTROLLER_WDG 0x02
37 #define CONTROLLER_STAT1 0x03
38 #define CHARGERUSB_INT_STATUS 0x04
39 #define CHARGERUSB_INT_MASK 0x05
40 #define CHARGERUSB_STATUS_INT1 0x06
41 #define CHARGERUSB_STATUS_INT2 0x07
42 #define CHARGERUSB_CTRL1 0x08
43 #define CHARGERUSB_CTRL2 0x09
44 #define CHARGERUSB_CTRL3 0x0A
45 #define CHARGERUSB_STAT1 0x0B
46 #define CHARGERUSB_VOREG 0x0C
47 #define CHARGERUSB_VICHRG 0x0D
48 #define CHARGERUSB_CINLIMIT 0x0E
49 #define CHARGERUSB_CTRLLIMIT1 0x0F
50 #define CHARGERUSB_CTRLLIMIT2 0x10
51 #define ANTICOLLAPSE_CTRL1 0x11
52 #define ANTICOLLAPSE_CTRL2 0x12
54 /* TWL6032 registers 0xDA to 0xDE - TWL6032_MODULE_CHARGER */
55 #define CONTROLLER_CTRL2 0x00
56 #define CONTROLLER_VSEL_COMP 0x01
57 #define CHARGERUSB_VSYSREG 0x02
58 #define CHARGERUSB_VICHRG_PC 0x03
59 #define LINEAR_CHRG_STS 0x04
61 /* TWL6032 Charger Mode Register */
62 #define CHARGER_MODE_REG 0xD4
63 #define CHARGER_MODE_POWERPATH BIT(3)
64 #define CHARGER_MODE_AUTOCHARGE BIT(6)
66 #define LINEAR_CHRG_STS_CRYSTL_OSC_OK 0x40
67 #define LINEAR_CHRG_STS_END_OF_CHARGE 0x20
68 #define LINEAR_CHRG_STS_VBATOV 0x10
69 #define LINEAR_CHRG_STS_VSYSOV 0x08
70 #define LINEAR_CHRG_STS_DPPM_STS 0x04
71 #define LINEAR_CHRG_STS_CV_STS 0x02
72 #define LINEAR_CHRG_STS_CC_STS 0x01
74 #define FG_REG_00 0x00
75 #define FG_REG_01 0x01
76 #define FG_REG_02 0x02
77 #define FG_REG_03 0x03
78 #define FG_REG_04 0x04
79 #define FG_REG_05 0x05
80 #define FG_REG_06 0x06
81 #define FG_REG_07 0x07
82 #define FG_REG_08 0x08
83 #define FG_REG_09 0x09
84 #define FG_REG_10 0x0A
85 #define FG_REG_11 0x0B
87 /* CONTROLLER_INT_MASK */
88 #define MVAC_FAULT (1 << 7)
89 #define MAC_EOC (1 << 6)
90 #define LINCH_GATED (1 << 5)
91 #define MBAT_REMOVED (1 << 4)
92 #define MFAULT_WDG (1 << 3)
93 #define MBAT_TEMP (1 << 2)
94 #define MVBUS_DET (1 << 1)
95 #define MVAC_DET (1 << 0)
97 /* CONTROLLER_CTRL1 */
98 #define CONTROLLER_CTRL1_EN_LINCH (1 << 5)
99 #define CONTROLLER_CTRL1_EN_CHARGER (1 << 4)
100 #define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3)
102 /* CONTROLLER_STAT1 */
103 #define CONTROLLER_STAT1_EXTCHRG_STATZ (1 << 7)
104 #define CONTROLLER_STAT1_LINCH_GATED (1 << 6)
105 #define CONTROLLER_STAT1_CHRG_DET_N (1 << 5)
106 #define CONTROLLER_STAT1_FAULT_WDG (1 << 4)
107 #define CONTROLLER_STAT1_VAC_DET (1 << 3)
108 #define VAC_DET (1 << 3)
109 #define CONTROLLER_STAT1_VBUS_DET (1 << 2)
110 #define VBUS_DET (1 << 2)
111 #define CONTROLLER_STAT1_BAT_REMOVED (1 << 1)
112 #define CONTROLLER_STAT1_BAT_TEMP_OVRANGE (1 << 0)
114 /* CHARGERUSB_INT_STATUS */
115 #define EN_LINCH (1 << 4)
116 #define CURRENT_TERM_INT (1 << 3)
117 #define CHARGERUSB_STAT (1 << 2)
118 #define CHARGERUSB_THMREG (1 << 1)
119 #define CHARGERUSB_FAULT (1 << 0)
121 /* CHARGERUSB_INT_MASK */
122 #define MASK_MCURRENT_TERM (1 << 3)
123 #define MASK_MCHARGERUSB_STAT (1 << 2)
124 #define MASK_MCHARGERUSB_THMREG (1 << 1)
125 #define MASK_MCHARGERUSB_FAULT (1 << 0)
127 /* CHARGERUSB_STATUS_INT1 */
128 #define CHARGERUSB_STATUS_INT1_TMREG (1 << 7)
129 #define CHARGERUSB_STATUS_INT1_NO_BAT (1 << 6)
130 #define CHARGERUSB_STATUS_INT1_BST_OCP (1 << 5)
131 #define CHARGERUSB_STATUS_INT1_TH_SHUTD (1 << 4)
132 #define CHARGERUSB_STATUS_INT1_BAT_OVP (1 << 3)
133 #define CHARGERUSB_STATUS_INT1_POOR_SRC (1 << 2)
134 #define CHARGERUSB_STATUS_INT1_SLP_MODE (1 << 1)
135 #define CHARGERUSB_STATUS_INT1_VBUS_OVP (1 << 0)
137 /* CHARGERUSB_STATUS_INT2 */
138 #define ICCLOOP (1 << 3)
139 #define CURRENT_TERM (1 << 2)
140 #define CHARGE_DONE (1 << 1)
141 #define ANTICOLLAPSE (1 << 0)
143 /* CHARGERUSB_CTRL1 */
144 #define SUSPEND_BOOT (1 << 7)
145 #define OPA_MODE (1 << 6)
146 #define HZ_MODE (1 << 5)
147 #define TERM (1 << 4)
149 /* CHARGERUSB_CTRL2 */
150 #define CHARGERUSB_CTRL2_VITERM_50 (0 << 5)
151 #define CHARGERUSB_CTRL2_VITERM_100 (1 << 5)
152 #define CHARGERUSB_CTRL2_VITERM_150 (2 << 5)
153 #define CHARGERUSB_CTRL2_VITERM_400 (7 << 5)
155 /* CHARGERUSB_CTRL3 */
156 #define VBUSCHRG_LDO_OVRD (1 << 7)
157 #define CHARGE_ONCE (1 << 6)
158 #define BST_HW_PR_DIS (1 << 5)
159 #define AUTOSUPPLY (1 << 3)
160 #define BUCK_HSILIM (1 << 0)
162 /* CHARGERUSB_VOREG */
163 #define CHARGERUSB_VOREG_3P52 0x01
164 #define CHARGERUSB_VOREG_4P0 0x19
165 #define CHARGERUSB_VOREG_4P2 0x23
166 #define CHARGERUSB_VOREG_4P76 0x3F
168 /* CHARGERUSB_VICHRG */
169 #define CHARGERUSB_VICHRG_300 0x0
170 #define CHARGERUSB_VICHRG_500 0x4
171 #define CHARGERUSB_VICHRG_1500 0xE
173 /* CHARGERUSB_CINLIMIT */
174 #define CHARGERUSB_CIN_LIMIT_100 0x1
175 #define CHARGERUSB_CIN_LIMIT_300 0x5
176 #define CHARGERUSB_CIN_LIMIT_500 0x9
177 #define CHARGERUSB_CIN_LIMIT_NONE 0xF
179 /* CHARGERUSB_CTRLLIMIT1 */
180 #define VOREGL_4P16 0x21
181 #define VOREGL_4P56 0x35
183 /* CHARGERUSB_CTRLLIMIT2 */
184 #define CHARGERUSB_CTRLLIMIT2_1500 0x0E
185 #define LOCK_LIMIT (1 << 4)
187 /* ANTICOLLAPSE_CTRL2 */
188 #define BUCK_VTH_SHIFT 5
191 #define CC_ACTIVE_MODE_SHIFT 6
192 #define CC_AUTOCLEAR (1 << 2)
193 #define CC_CAL_EN (1 << 1)
194 #define CC_PAUSE (1 << 0)
196 #define REG_TOGGLE1 0x90
197 #define FGDITHS (1 << 7)
198 #define FGDITHR (1 << 6)
202 /* TWL6030_GPADC_CTRL */
203 #define GPADC_CTRL_TEMP1_EN (1 << 0) /* input ch 1 */
204 #define GPADC_CTRL_TEMP2_EN (1 << 1) /* input ch 4 */
205 #define GPADC_CTRL_SCALER_EN (1 << 2) /* input ch 2 */
206 #define GPADC_CTRL_SCALER_DIV4 (1 << 3)
207 #define GPADC_CTRL_SCALER_EN_CH11 (1 << 4) /* input ch 11 */
208 #define GPADC_CTRL_TEMP1_EN_MONITOR (1 << 5)
209 #define GPADC_CTRL_TEMP2_EN_MONITOR (1 << 6)
210 #define GPADC_CTRL_ISOURCE_EN (1 << 7)
212 #define GPADC_ISOURCE_22uA 22
213 #define GPADC_ISOURCE_7uA 7
215 /* TWL6030/6032 BATTERY VOLTAGE GPADC CHANNELS */
217 #define TWL6030_GPADC_VBAT_CHNL 0x07
218 #define TWL6032_GPADC_VBAT_CHNL 0x12
220 /* TWL6030_GPADC_CTRL2 */
221 #define GPADC_CTRL2_CH18_SCALER_EN BIT(2)
223 #define ENABLE_ISOURCE 0x80
225 #define REG_MISC1 0xE4
226 #define VAC_MEAS 0x04
227 #define VBAT_MEAS 0x02
230 #define REG_USB_VBUS_CTRL_SET 0x04
231 #define VBUS_MEAS 0x01
232 #define REG_USB_ID_CTRL_SET 0x06
235 #define BBSPOR_CFG 0xE6
236 #define BB_CHG_EN (1 << 3)
238 #define STS_HW_CONDITIONS 0x21
239 #define STS_USB_ID (1 << 2) /* Level status of USB ID */
241 #define BATTERY_RESISTOR 10000
242 #define SIMULATOR_RESISTOR 5000
243 #define BATTERY_DETECT_THRESHOLD ((BATTERY_RESISTOR + SIMULATOR_RESISTOR) / 2) //battery voltage threshold divided by 22uA
244 #define CHARGING_CAPACITY_UPDATE_PERIOD (1000 * 60 * 1)
246 /* To get VBUS input limit from twl6030_usb */
247 #if CONFIG_TWL6030_USB
248 extern unsigned int twl6030_get_usb_max_power(struct otg_transceiver *x);
250 static inline unsigned int twl6030_get_usb_max_power(struct otg_transceiver *x)
256 /* Ptr to thermistor table */
257 static const unsigned int fuelgauge_rate[4] = {1, 4, 16, 64};
258 static struct wake_lock chrg_lock;
261 struct twl6030_bci_device_info {
288 u8 watchdog_duration;
289 u16 current_avg_interval;
290 u16 monitoring_interval;
291 unsigned int min_vbus;
293 struct twl4030_bci_platform_data *platform_data;
295 unsigned int charger_incurrentmA;
296 unsigned int charger_outcurrentmA;
297 unsigned long usb_max_power;
300 unsigned int capacity;
301 unsigned int capacity_debounce_count;
302 unsigned long ac_next_refresh;
303 unsigned int prev_capacity;
304 unsigned int wakelock_enabled;
306 struct power_supply bat;
307 struct power_supply usb;
308 struct power_supply ac;
309 struct power_supply bk_bat;
311 struct otg_transceiver *otg;
312 struct notifier_block nb;
313 struct work_struct usb_work;
315 struct workqueue_struct *freezable_work;
317 struct delayed_work twl6030_bci_monitor_work;
318 struct delayed_work twl6030_current_avg_work;
320 unsigned long features;
325 /* max scale current based on sense resitor */
326 int current_max_scale;
327 struct delayed_work work;
328 unsigned int interval;
331 static BLOCKING_NOTIFIER_HEAD(notifier_list);
332 extern u32 wakeup_timer_seconds;
334 static void twl6030_config_min_vbus_reg(struct twl6030_bci_device_info *di,
340 /* not required on TWL6032 */
341 if (di->features & TWL6032_SUBCLASS)
344 if (value > 4760 || value < 4200) {
345 dev_err(di->dev, "invalid min vbus\n");
349 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &rd_reg,
353 rd_reg = rd_reg & 0x1F;
354 rd_reg = rd_reg | (((value - 4200)/80) << BUCK_VTH_SHIFT);
355 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, rd_reg,
361 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
364 static void twl6030_config_iterm_reg(struct twl6030_bci_device_info *di,
365 unsigned int term_currentmA)
369 if ((term_currentmA > 400) || (term_currentmA < 50)) {
370 dev_err(di->dev, "invalid termination current\n");
374 term_currentmA = ((term_currentmA - 50)/50) << 5;
375 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, term_currentmA,
378 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
381 static unsigned int twl6030_get_iterm_reg(struct twl6030_bci_device_info *di)
384 unsigned int currentmA;
387 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &val, CHARGERUSB_CTRL2);
389 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
392 currentmA = 50 + (val >> 5) * 50;
397 static void twl6030_config_voreg_reg(struct twl6030_bci_device_info *di,
398 unsigned int voltagemV)
402 if ((voltagemV < 3500) || (voltagemV > 4760)) {
403 dev_err(di->dev, "invalid charger_voltagemV\n");
407 voltagemV = (voltagemV - 3500) / 20;
408 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, voltagemV,
411 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
414 static unsigned int twl6030_get_voreg_reg(struct twl6030_bci_device_info *di)
417 unsigned int voltagemV;
420 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &val, CHARGERUSB_VOREG);
422 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
425 voltagemV = 3500 + (val * 20);
430 static void twl6030_config_vichrg_reg(struct twl6030_bci_device_info *di,
431 unsigned int currentmA)
435 if ((currentmA >= 300) && (currentmA <= 450))
436 currentmA = (currentmA - 300) / 50;
437 else if ((currentmA >= 500) && (currentmA <= 1500))
438 currentmA = (currentmA - 500) / 100 + 4;
440 dev_err(di->dev, "invalid charger_currentmA\n");
444 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, currentmA,
447 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
450 static void twl6030_config_cinlimit_reg(struct twl6030_bci_device_info *di,
451 unsigned int currentmA)
455 if ((currentmA >= 50) && (currentmA <= 750))
456 currentmA = (currentmA - 50) / 50;
457 else if ((currentmA > 750) && (currentmA <= 1500) &&
458 (di->features & TWL6032_SUBCLASS)) {
459 currentmA = ((currentmA % 100) ? 0x30 : 0x20) +
460 ((currentmA - 100) / 100);
461 } else if (currentmA < 50) {
462 dev_err(di->dev, "invalid input current limit\n");
465 /* This is no current limit */
469 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, currentmA,
470 CHARGERUSB_CINLIMIT);
472 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
475 static void twl6030_config_limit1_reg(struct twl6030_bci_device_info *di,
476 unsigned int voltagemV)
480 if ((voltagemV < 3500) || (voltagemV > 4760)) {
481 dev_err(di->dev, "invalid max_charger_voltagemV\n");
485 voltagemV = (voltagemV - 3500) / 20;
486 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, voltagemV,
487 CHARGERUSB_CTRLLIMIT1);
489 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
492 static unsigned int twl6030_get_limit1_reg(struct twl6030_bci_device_info *di)
495 unsigned int voltagemV;
498 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &val,
499 CHARGERUSB_CTRLLIMIT1);
501 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
504 voltagemV = 3500 + (val * 20);
509 static void twl6030_config_limit2_reg(struct twl6030_bci_device_info *di,
510 unsigned int currentmA)
514 if ((currentmA >= 300) && (currentmA <= 450))
515 currentmA = (currentmA - 300) / 50;
516 else if ((currentmA >= 500) && (currentmA <= 1500))
517 currentmA = (currentmA - 500) / 100 + 4;
519 dev_err(di->dev, "invalid max_charger_currentmA\n");
523 currentmA |= LOCK_LIMIT;
524 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, currentmA,
525 CHARGERUSB_CTRLLIMIT2);
527 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
530 static const int vichrg[] = {
531 300, 350, 400, 450, 500, 600, 700, 800,
532 900, 1000, 1100, 1200, 1300, 1400, 1500, 300
535 static unsigned int twl6030_get_limit2_reg(struct twl6030_bci_device_info *di)
538 unsigned int currentmA;
541 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &val,
542 CHARGERUSB_CTRLLIMIT2);
544 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
547 currentmA = vichrg[val & 0xF];
553 * Return channel value
556 static int twl6030_get_gpadc_conversion(struct twl6030_bci_device_info *di,
559 struct twl6030_gpadc_request req;
563 req.channels = (1 << channel_no);
564 req.method = TWL6030_GPADC_SW2;
567 ret = twl6030_gpadc_conversion(&req);
571 if (req.rbuf[channel_no] > 0)
572 temp = req.rbuf[channel_no];
577 static int is_battery_present(struct twl6030_bci_device_info *di)
580 static unsigned int current_src_val;
583 * Prevent charging on batteries were id resistor is
586 val = twl6030_get_gpadc_conversion(di,di->gpadc_vbat_chnl);
589 * twl6030_get_gpadc_conversion for
590 * 6030 return resistance, for 6032 - voltage and
591 * it should be converted to resistance before
594 if (!current_src_val) {
597 if (twl_i2c_read_u8(TWL_MODULE_MADC, ®,
599 pr_err("%s: Error reading TWL6030_GPADC_CTRL\n",
602 current_src_val = (reg & GPADC_CTRL_ISOURCE_EN) ?
607 val = (val * 1000) / current_src_val;
609 if (val < BATTERY_DETECT_THRESHOLD)
615 static void twl6030_stop_usb_charger(struct twl6030_bci_device_info *di)
620 if (di->use_hw_charger) {
621 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, ®,
626 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, reg,
634 di->charger_source = 0;
635 di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
637 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, 0, CONTROLLER_CTRL1);
641 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
644 static void twl6030_start_usb_charger(struct twl6030_bci_device_info *di)
649 if (di->use_hw_charger) {
650 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, ®,
656 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, reg,
664 if (!is_battery_present(di)) {
665 dev_info(di->dev, "BATTERY NOT DETECTED!\n");
669 if (di->charger_source == POWER_SUPPLY_TYPE_MAINS)
672 dev_dbg(di->dev, "USB input current limit %dmA\n",
673 di->charger_incurrentmA);
674 if (di->charger_incurrentmA < 50) {
675 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER,
676 0, CONTROLLER_CTRL1);
683 twl6030_config_vichrg_reg(di, di->charger_outcurrentmA);
684 twl6030_config_cinlimit_reg(di, di->charger_incurrentmA);
685 twl6030_config_voreg_reg(di, di->platform_data->max_bat_voltagemV);
686 twl6030_config_iterm_reg(di, di->platform_data->termination_currentmA);
688 if (di->charger_incurrentmA >= 50) {
689 reg = CONTROLLER_CTRL1_EN_CHARGER;
691 if (di->use_power_path)
692 reg |= CONTROLLER_CTRL1_EN_LINCH;
694 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, reg,
699 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
703 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
706 static void twl6030_stop_ac_charger(struct twl6030_bci_device_info *di)
711 di->charger_source = 0;
712 di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
713 events = BQ2415x_STOP_CHARGING;
715 if (di->use_hw_charger)
718 blocking_notifier_call_chain(¬ifier_list, events, NULL);
720 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, 0, CONTROLLER_CTRL1);
722 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
724 if (di->wakelock_enabled)
725 wake_unlock(&chrg_lock);
728 static void twl6030_start_ac_charger(struct twl6030_bci_device_info *di)
733 if (!is_battery_present(di)) {
734 dev_info(di->dev, "BATTERY NOT DETECTED!\n");
737 dev_dbg(di->dev, "AC charger detected\n");
738 di->charger_source = POWER_SUPPLY_TYPE_MAINS;
739 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
740 events = BQ2415x_START_CHARGING;
742 if (di->use_hw_charger)
745 blocking_notifier_call_chain(¬ifier_list, events, NULL);
747 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER,
748 CONTROLLER_CTRL1_EN_CHARGER |
749 CONTROLLER_CTRL1_SEL_CHARGER,
752 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
754 if (di->wakelock_enabled)
755 wake_lock(&chrg_lock);
758 static void twl6030_stop_charger(struct twl6030_bci_device_info *di)
760 if (di->charger_source == POWER_SUPPLY_TYPE_MAINS)
761 twl6030_stop_ac_charger(di);
762 else if (di->charger_source == POWER_SUPPLY_TYPE_USB)
763 twl6030_stop_usb_charger(di);
766 static void twl6032_charger_ctrl_interrupt(struct twl6030_bci_device_info *di)
768 u8 stat_toggle, stat_reset, stat_set = 0;
769 u8 present_state = 0, linear_state;
770 u8 present_status = 0;
773 err = twl_i2c_read_u8(TWL6032_MODULE_CHARGER, &present_state,
776 dev_err(di->dev, "%s: Error access to TWL6030 (%d)\n",
781 err = twl_i2c_read_u8(TWL6032_MODULE_CHARGER, &present_status,
782 CHARGERUSB_INT_STATUS);
784 dev_err(di->dev, "%s: Error access to TWL6030 (%d)\n",
789 linear_state = di->linear_stat;
791 stat_toggle = linear_state ^ present_state;
792 stat_set = stat_toggle & present_state;
793 stat_reset = stat_toggle & linear_state;
794 di->linear_stat = present_state;
796 if (stat_set & LINEAR_CHRG_STS_CRYSTL_OSC_OK)
797 dev_dbg(di->dev, "Linear status: CRYSTAL OSC OK\n");
798 if (present_state & LINEAR_CHRG_STS_END_OF_CHARGE) {
799 dev_dbg(di->dev, "Linear status: END OF CHARGE\n");
800 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
802 if (present_status & EN_LINCH) {
803 dev_dbg(di->dev, "Linear status: START OF CHARGE\n");
804 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
807 if (stat_set & LINEAR_CHRG_STS_VBATOV) {
808 dev_dbg(di->dev, "Linear Status: VBATOV\n");
809 di->bat_health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
811 if (stat_reset & LINEAR_CHRG_STS_VBATOV) {
812 dev_dbg(di->dev, "Linear Status: VBATOV\n");
813 di->bat_health = POWER_SUPPLY_HEALTH_GOOD;
816 if (stat_set & LINEAR_CHRG_STS_VSYSOV)
817 dev_dbg(di->dev, "Linear Status: VSYSOV\n");
818 if (stat_set & LINEAR_CHRG_STS_DPPM_STS)
819 dev_dbg(di->dev, "Linear Status: DPPM STS\n");
820 if (stat_set & LINEAR_CHRG_STS_CV_STS)
821 dev_dbg(di->dev, "Linear Status: CV STS\n");
822 if (stat_set & LINEAR_CHRG_STS_CC_STS)
823 dev_dbg(di->dev, "Linear Status: CC STS\n");
827 * Interrupt service routine
829 * Attends to TWL 6030 power module interruptions events, specifically
830 * USB_PRES (USB charger presence) CHG_PRES (AC charger presence) events
833 static irqreturn_t twl6030charger_ctrl_interrupt(int irq, void *_di)
835 struct twl6030_bci_device_info *di = _di;
837 int charger_fault = 0;
839 u8 stat_toggle, stat_reset, stat_set = 0;
841 u8 present_charge_state = 0;
842 u8 ac_or_vbus, no_ac_and_vbus = 0;
843 u8 hw_state = 0, temp = 0;
845 /* read charger controller_stat1 */
846 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &present_charge_state,
850 * Since present state read failed, charger_state is no
851 * longer valid, reset to zero inorder to detect next events
857 ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &hw_state, STS_HW_CONDITIONS);
861 charge_state = di->stat1;
863 stat_toggle = charge_state ^ present_charge_state;
864 stat_set = stat_toggle & present_charge_state;
865 stat_reset = stat_toggle & charge_state;
867 no_ac_and_vbus = !((present_charge_state) & (VBUS_DET | VAC_DET));
868 ac_or_vbus = charge_state & (VBUS_DET | VAC_DET);
869 if (no_ac_and_vbus && ac_or_vbus) {
870 di->charger_source = 0;
871 dev_dbg(di->dev, "No Charging source\n");
872 /* disable charging when no source present */
875 charge_state = present_charge_state;
876 di->stat1 = present_charge_state;
877 if ((charge_state & VAC_DET) &&
878 (charge_state & CONTROLLER_STAT1_EXTCHRG_STATZ)) {
879 events = BQ2415x_CHARGER_FAULT;
880 blocking_notifier_call_chain(¬ifier_list, events, NULL);
883 if (stat_reset & VBUS_DET) {
884 /* On a USB detach, UNMASK VBUS OVP if masked*/
885 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &temp,
886 CHARGERUSB_INT_MASK);
890 if (temp & MASK_MCHARGERUSB_FAULT) {
891 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER,
892 (temp & ~MASK_MCHARGERUSB_FAULT),
893 CHARGERUSB_INT_MASK);
898 dev_info(di->dev, "usb removed\n");
899 twl6030_stop_usb_charger(di);
900 if (present_charge_state & VAC_DET)
901 twl6030_start_ac_charger(di);
905 if (stat_set & VBUS_DET) {
906 /* In HOST mode (ID GROUND) when a device is connected,
907 * Mask VBUS OVP interrupt and do no enable usb
910 if (hw_state & STS_USB_ID) {
911 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER,
913 CHARGERUSB_INT_MASK);
917 if (!(temp & MASK_MCHARGERUSB_FAULT)) {
918 ret = twl_i2c_write_u8(
919 TWL6030_MODULE_CHARGER,
920 (temp | MASK_MCHARGERUSB_FAULT),
921 CHARGERUSB_INT_MASK);
926 di->usb_online = POWER_SUPPLY_TYPE_USB;
927 if ((present_charge_state & VAC_DET) &&
928 (di->vac_priority == 2))
929 dev_info(di->dev, "USB charger detected"
930 ", continue with VAC\n");
933 POWER_SUPPLY_TYPE_USB;
935 POWER_SUPPLY_STATUS_CHARGING;
937 dev_info(di->dev, "vbus detect\n");
941 if (stat_reset & VAC_DET) {
943 dev_info(di->dev, "vac removed\n");
944 twl6030_stop_ac_charger(di);
945 if (present_charge_state & VBUS_DET) {
946 di->charger_source = POWER_SUPPLY_TYPE_USB;
948 POWER_SUPPLY_STATUS_CHARGING;
949 twl6030_start_usb_charger(di);
952 if (stat_set & VAC_DET) {
953 di->ac_online = POWER_SUPPLY_TYPE_MAINS;
954 if ((present_charge_state & VBUS_DET) &&
955 (di->vac_priority == 3))
957 "AC charger detected"
958 ", continue with VBUS\n");
960 twl6030_start_ac_charger(di);
963 if (stat_set & CONTROLLER_STAT1_FAULT_WDG) {
965 dev_info(di->dev, "Fault watchdog fired\n");
967 if (stat_reset & CONTROLLER_STAT1_FAULT_WDG)
968 dev_err(di->dev, "Fault watchdog recovered\n");
969 if (stat_set & CONTROLLER_STAT1_BAT_REMOVED)
970 dev_err(di->dev, "Battery removed\n");
971 if (stat_reset & CONTROLLER_STAT1_BAT_REMOVED)
972 dev_err(di->dev, "Battery inserted\n");
973 if (stat_set & CONTROLLER_STAT1_BAT_TEMP_OVRANGE) {
974 dev_err(di->dev, "Battery temperature overrange\n");
975 di->bat_health = POWER_SUPPLY_HEALTH_OVERHEAT;
977 if (stat_reset & CONTROLLER_STAT1_BAT_TEMP_OVRANGE) {
978 dev_err(di->dev, "Battery temperature within range\n");
979 di->bat_health = POWER_SUPPLY_HEALTH_GOOD;
981 if (di->features & TWL6032_SUBCLASS)
982 twl6032_charger_ctrl_interrupt(di);
985 twl6030_stop_usb_charger(di);
986 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
987 dev_err(di->dev, "Charger Fault stop charging\n");
990 if (di->capacity != -1)
991 power_supply_changed(&di->bat);
993 cancel_delayed_work(&di->twl6030_bci_monitor_work);
994 queue_delayed_work(di->freezable_work, &di->twl6030_bci_monitor_work, 0);
1000 static irqreturn_t twl6030charger_fault_interrupt(int irq, void *_di)
1002 struct twl6030_bci_device_info *di = _di;
1003 int charger_fault = 0;
1006 u8 usb_charge_sts = 0, usb_charge_sts1 = 0, usb_charge_sts2 = 0;
1008 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &usb_charge_sts,
1009 CHARGERUSB_INT_STATUS);
1013 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &usb_charge_sts1,
1014 CHARGERUSB_STATUS_INT1);
1018 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &usb_charge_sts2,
1019 CHARGERUSB_STATUS_INT2);
1023 di->status_int1 = usb_charge_sts1;
1024 di->status_int2 = usb_charge_sts2;
1025 if (usb_charge_sts & CURRENT_TERM_INT)
1026 dev_dbg(di->dev, "USB CURRENT_TERM_INT\n");
1027 if (usb_charge_sts & CHARGERUSB_THMREG)
1028 dev_dbg(di->dev, "USB CHARGERUSB_THMREG\n");
1029 if (usb_charge_sts & CHARGERUSB_FAULT)
1030 dev_dbg(di->dev, "USB CHARGERUSB_FAULT\n");
1032 if (usb_charge_sts1 & CHARGERUSB_STATUS_INT1_TMREG)
1033 dev_dbg(di->dev, "USB CHARGER Thermal regulation activated\n");
1034 if (usb_charge_sts1 & CHARGERUSB_STATUS_INT1_NO_BAT)
1035 dev_dbg(di->dev, "No Battery Present\n");
1036 if (usb_charge_sts1 & CHARGERUSB_STATUS_INT1_BST_OCP)
1037 dev_dbg(di->dev, "USB CHARGER Boost Over current protection\n");
1038 if (usb_charge_sts1 & CHARGERUSB_STATUS_INT1_TH_SHUTD) {
1040 dev_dbg(di->dev, "USB CHARGER Thermal Shutdown\n");
1042 if (usb_charge_sts1 & CHARGERUSB_STATUS_INT1_BAT_OVP)
1043 dev_dbg(di->dev, "USB CHARGER Bat Over Voltage Protection\n");
1044 if (usb_charge_sts1 & CHARGERUSB_STATUS_INT1_POOR_SRC)
1045 dev_dbg(di->dev, "USB CHARGER Poor input source\n");
1046 if (usb_charge_sts1 & CHARGERUSB_STATUS_INT1_SLP_MODE)
1047 dev_dbg(di->dev, "USB CHARGER Sleep mode\n");
1048 if (usb_charge_sts1 & CHARGERUSB_STATUS_INT1_VBUS_OVP)
1049 dev_dbg(di->dev, "USB CHARGER VBUS over voltage\n");
1051 if (usb_charge_sts2 & CHARGE_DONE) {
1052 di->charge_status = POWER_SUPPLY_STATUS_FULL;
1053 dev_dbg(di->dev, "USB charge done\n");
1055 if (usb_charge_sts2 & CURRENT_TERM)
1056 dev_dbg(di->dev, "USB CURRENT_TERM\n");
1057 if (usb_charge_sts2 & ICCLOOP)
1058 dev_dbg(di->dev, "USB ICCLOOP\n");
1059 if (usb_charge_sts2 & ANTICOLLAPSE)
1060 dev_dbg(di->dev, "USB ANTICOLLAPSE\n");
1062 if (charger_fault) {
1063 twl6030_stop_usb_charger(di);
1064 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1065 dev_err(di->dev, "Charger Fault stop charging\n");
1067 dev_info(di->dev, "Charger fault detected STS, INT1, INT2 %x %x %x\n",
1068 usb_charge_sts, usb_charge_sts1, usb_charge_sts2);
1070 power_supply_changed(&di->bat);
1076 * In HW charger mode on 6032 irq routines must only deal with updating
1077 * state of charger. The hardware deals with start/stop conditions
1080 static irqreturn_t twl6032charger_ctrl_interrupt_hw(int irq, void *_di)
1082 struct twl6030_bci_device_info *di = _di;
1084 int charger_stop = 0, end_of_charge = 0;
1087 /* read charger controller_stat1 */
1088 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &stat1,
1093 ret = twl_i2c_read_u8(TWL6032_MODULE_CHARGER, &linear,
1098 if (!(stat1 & (VBUS_DET | VAC_DET))) {
1100 di->ac_online = di->usb_online = 0;
1103 if (!(di->usb_online || di->ac_online)) {
1104 if (stat1 & VBUS_DET) {
1106 di->bat_health = POWER_SUPPLY_HEALTH_GOOD;
1107 } else if (stat1 & VAC_DET) {
1109 di->bat_health = POWER_SUPPLY_HEALTH_GOOD;
1113 if (stat1 & CONTROLLER_STAT1_FAULT_WDG) {
1115 di->bat_health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
1116 dev_err(di->dev, "Charger error : Fault watchdog\n");
1118 if (stat1 & CONTROLLER_STAT1_BAT_REMOVED) {
1120 di->bat_health = POWER_SUPPLY_HEALTH_DEAD;
1121 dev_info(di->dev, "Battery removed\n");
1123 if (stat1 & CONTROLLER_STAT1_BAT_TEMP_OVRANGE) {
1126 "Charger error : Battery temperature overrange\n");
1127 di->bat_health = POWER_SUPPLY_HEALTH_OVERHEAT;
1130 if ((stat1 & CONTROLLER_STAT1_LINCH_GATED) &&
1131 di->use_power_path) {
1135 if (linear & LINEAR_CHRG_STS_CRYSTL_OSC_OK) {
1136 di->bat_health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
1137 dev_err(di->dev, "Charger error: CRYSTAL OSC OK\n");
1140 if (linear & LINEAR_CHRG_STS_END_OF_CHARGE) {
1142 di->bat_health = POWER_SUPPLY_HEALTH_GOOD;
1143 dev_info(di->dev, "Charger: Full charge\n");
1146 if (linear & LINEAR_CHRG_STS_VBATOV) {
1147 di->bat_health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
1149 "Charger error : Linear Status: VBATOV\n");
1152 if (linear & LINEAR_CHRG_STS_VSYSOV) {
1153 di->bat_health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
1155 "Charger error : Linear Status: VSYSOV\n");
1160 if (!(stat1 & (VBUS_DET | VAC_DET))) {
1161 di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
1165 POWER_SUPPLY_STATUS_FULL;
1168 POWER_SUPPLY_STATUS_NOT_CHARGING;
1172 power_supply_changed(&di->bat);
1178 static irqreturn_t twl6032charger_fault_interrupt_hw(int irq, void *_di)
1180 struct twl6030_bci_device_info *di = _di;
1181 int charger_stop = 0, charger_start = 0;
1183 u8 sts, sts_int1, sts_int2, stat1;
1185 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &sts,
1186 CHARGERUSB_INT_STATUS);
1190 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &sts_int1,
1191 CHARGERUSB_STATUS_INT1);
1195 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &sts_int2,
1196 CHARGERUSB_STATUS_INT2);
1200 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &stat1,
1205 if (sts & EN_LINCH) {
1207 dev_dbg(di->dev, "Charger: EN_LINCH\n");
1211 if ((sts & CURRENT_TERM_INT) && !di->use_power_path) {
1212 dev_dbg(di->dev, "Charger: CURRENT_TERM_INT\n");
1214 if (sts_int2 & CURRENT_TERM) {
1216 dev_err(di->dev, "Charger error: CURRENT_TERM\n");
1220 if (sts & CHARGERUSB_STAT) {
1221 dev_dbg(di->dev, "Charger: CHARGEUSB_STAT\n");
1223 if (sts_int2 & ANTICOLLAPSE)
1224 dev_err(di->dev, "Charger error: ANTICOLLAPSE\n");
1227 if (sts & CHARGERUSB_THMREG) {
1228 dev_dbg(di->dev, "Charger: CHARGERUSB_THMREG\n");
1230 if (sts_int1 & CHARGERUSB_STATUS_INT1_TMREG)
1231 dev_err(di->dev, "Charger error: TMREG\n");
1234 if (sts & CHARGERUSB_FAULT) {
1235 dev_dbg(di->dev, "Charger: CHARGERUSB_FAULT\n");
1239 if (!di->use_power_path) {
1240 if (sts_int1 & CHARGERUSB_STATUS_INT1_NO_BAT) {
1241 di->bat_health = POWER_SUPPLY_HEALTH_DEAD;
1243 "Charger error : NO_BAT\n");
1245 if (sts_int1 & CHARGERUSB_STATUS_INT1_BAT_OVP) {
1247 POWER_SUPPLY_HEALTH_OVERVOLTAGE;
1248 dev_err(di->dev, "Charger error : BAT_OVP\n");
1252 if (sts_int1 & CHARGERUSB_STATUS_INT1_BST_OCP) {
1253 di->bat_health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
1254 printk(KERN_ERR "Charger error : BST_OCP\n");
1256 if (sts_int1 & CHARGERUSB_STATUS_INT1_TH_SHUTD) {
1257 di->bat_health = POWER_SUPPLY_HEALTH_OVERHEAT;
1258 printk(KERN_ERR "Charger error : TH_SHUTD\n");
1260 if (sts_int1 & CHARGERUSB_STATUS_INT1_POOR_SRC) {
1261 di->bat_health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
1262 printk(KERN_ERR "Charger error : POOR_SRC\n");
1264 if (sts_int1 & CHARGERUSB_STATUS_INT1_SLP_MODE)
1265 dev_err(di->dev, "Charger error: SLP_MODE\n");
1267 if (sts_int1 & CHARGERUSB_STATUS_INT1_VBUS_OVP) {
1268 di->bat_health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
1269 printk(KERN_ERR "Charger error : VBUS_OVP\n");
1274 if (!(stat1 & (VBUS_DET | VAC_DET)))
1275 di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
1277 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1281 if (charger_start) {
1282 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
1283 di->bat_health = POWER_SUPPLY_HEALTH_GOOD;
1286 power_supply_changed(&di->bat);
1291 static void twl6030battery_current(struct twl6030_bci_device_info *di)
1296 int current_now = 0;
1298 /* FG_REG_10, 11 is 14 bit signed instantaneous current sample value */
1299 ret = twl_i2c_read(TWL6030_MODULE_GASGAUGE, (u8 *)&read_value,
1302 dev_info(di->dev, "failed to read FG_REG_10: current_now\n");
1306 temp = ((s16)(read_value << 2) >> 2);
1307 current_now = temp - di->cc_offset;
1309 /* current drawn per sec */
1310 current_now = current_now * fuelgauge_rate[di->fuelgauge_mode];
1311 /* current in mAmperes */
1312 current_now = (current_now * di->current_max_scale) >> 13;
1313 /* current in uAmperes */
1314 current_now = current_now * 1000;
1315 di->current_uA = current_now;
1321 * Setup the twl6030 BCI module to enable backup
1324 static int twl6030backupbatt_setup(void)
1329 ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &rd_reg, BBSPOR_CFG);
1333 rd_reg |= BB_CHG_EN;
1334 ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, rd_reg, BBSPOR_CFG);
1340 * Setup the twl6030 BCI module to measure battery
1343 static int twl6030battery_temp_setup(bool enable)
1348 ret = twl_i2c_read_u8(TWL_MODULE_MADC, &rd_reg, TWL6030_GPADC_CTRL);
1353 rd_reg |= (GPADC_CTRL_TEMP1_EN | GPADC_CTRL_TEMP2_EN |
1354 GPADC_CTRL_TEMP1_EN_MONITOR |
1355 GPADC_CTRL_TEMP2_EN_MONITOR | GPADC_CTRL_SCALER_DIV4);
1357 rd_reg ^= (GPADC_CTRL_TEMP1_EN | GPADC_CTRL_TEMP2_EN |
1358 GPADC_CTRL_TEMP1_EN_MONITOR |
1359 GPADC_CTRL_TEMP2_EN_MONITOR | GPADC_CTRL_SCALER_DIV4);
1361 ret = twl_i2c_write_u8(TWL_MODULE_MADC, rd_reg, TWL6030_GPADC_CTRL);
1366 static int twl6030battery_voltage_setup(struct twl6030_bci_device_info *di)
1371 ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &rd_reg, REG_MISC1);
1375 rd_reg = rd_reg | VAC_MEAS | VBAT_MEAS | BB_MEAS;
1376 ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, rd_reg, REG_MISC1);
1380 ret = twl_i2c_read_u8(TWL_MODULE_USB, &rd_reg, REG_USB_VBUS_CTRL_SET);
1384 rd_reg = rd_reg | VBUS_MEAS;
1385 ret = twl_i2c_write_u8(TWL_MODULE_USB, rd_reg, REG_USB_VBUS_CTRL_SET);
1389 ret = twl_i2c_read_u8(TWL_MODULE_USB, &rd_reg, REG_USB_ID_CTRL_SET);
1393 rd_reg = rd_reg | ID_MEAS;
1394 ret = twl_i2c_write_u8(TWL_MODULE_USB, rd_reg, REG_USB_ID_CTRL_SET);
1398 if (di->features & TWL6032_SUBCLASS)
1399 ret = twl_i2c_write_u8(TWL_MODULE_MADC,
1400 GPADC_CTRL2_CH18_SCALER_EN,
1401 TWL6030_GPADC_CTRL2);
1406 static int twl6030battery_current_setup(bool enable)
1412 * Writing 0 to REG_TOGGLE1 has no effect, so
1413 * can directly set/reset FG.
1416 reg = FGDITHS | FGS;
1418 reg = FGDITHR | FGR;
1420 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, reg, REG_TOGGLE1);
1424 ret = twl_i2c_write_u8(TWL6030_MODULE_GASGAUGE, CC_CAL_EN, FG_REG_00);
1429 static enum power_supply_property twl6030_bci_battery_props[] = {
1430 POWER_SUPPLY_PROP_STATUS,
1431 POWER_SUPPLY_PROP_HEALTH,
1432 POWER_SUPPLY_PROP_ONLINE,
1433 POWER_SUPPLY_PROP_VOLTAGE_NOW,
1434 POWER_SUPPLY_PROP_CURRENT_NOW,
1435 POWER_SUPPLY_PROP_CURRENT_AVG,
1436 POWER_SUPPLY_PROP_CAPACITY,
1437 POWER_SUPPLY_PROP_TEMP,
1440 static enum power_supply_property twl6030_usb_props[] = {
1441 POWER_SUPPLY_PROP_ONLINE,
1442 POWER_SUPPLY_PROP_VOLTAGE_NOW,
1445 static enum power_supply_property twl6030_ac_props[] = {
1446 POWER_SUPPLY_PROP_ONLINE,
1447 POWER_SUPPLY_PROP_VOLTAGE_NOW,
1450 static enum power_supply_property twl6030_bk_bci_battery_props[] = {
1451 POWER_SUPPLY_PROP_VOLTAGE_NOW,
1454 static void twl6030_current_avg(struct work_struct *work)
1458 int current_avg_uA = 0;
1460 struct twl6030_bci_device_info *di = container_of(work,
1461 struct twl6030_bci_device_info,
1462 twl6030_current_avg_work.work);
1464 di->charge_n2 = di->charge_n1;
1465 di->timer_n2 = di->timer_n1;
1467 /* FG_REG_01, 02, 03 is 24 bit unsigned sample counter value */
1468 ret = twl_i2c_read(TWL6030_MODULE_GASGAUGE, (u8 *) &di->timer_n1,
1473 * FG_REG_04, 5, 6, 7 is 32 bit signed accumulator value
1474 * accumulates instantaneous current value
1476 ret = twl_i2c_read(TWL6030_MODULE_GASGAUGE, (u8 *) &di->charge_n1,
1480 /* FG_REG_08, 09 is 10 bit signed calibration offset value */
1481 ret = twl_i2c_read(TWL6030_MODULE_GASGAUGE, (u8 *) &cc_offset,
1485 cc_offset = ((s16)(cc_offset << 6) >> 6);
1486 di->cc_offset = cc_offset;
1488 samples = di->timer_n1 - di->timer_n2;
1489 /* check for timer overflow */
1490 if (di->timer_n1 < di->timer_n2)
1491 samples = samples + (1 << 24);
1493 /* offset is accumulative over number of samples */
1494 cc_offset = cc_offset * samples;
1496 current_avg_uA = ((di->charge_n1 - di->charge_n2 - cc_offset)
1497 * di->current_max_scale) /
1498 fuelgauge_rate[di->fuelgauge_mode];
1499 /* clock is a fixed 32Khz */
1500 current_avg_uA >>= 15;
1502 /* Correct for the fuelguage sampling rate */
1503 samples /= fuelgauge_rate[di->fuelgauge_mode] * 4;
1506 * Only update the current average if we have had a valid number
1507 * of samples in the accumulation.
1510 current_avg_uA = current_avg_uA / samples;
1511 di->current_avg_uA = current_avg_uA * 1000;
1514 queue_delayed_work(di->freezable_work, &di->twl6030_current_avg_work,
1515 msecs_to_jiffies(1000 * di->current_avg_interval));
1518 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
1521 static int capacity_changed(struct twl6030_bci_device_info *di)
1523 int curr_capacity = di->capacity;
1524 int charger_source = di->charger_source;
1525 int charging_disabled = 0;
1527 /* Because system load is always greater than
1528 * termination current, we will never get a CHARGE DONE
1529 * int from BQ. And charging will alwys be in progress.
1530 * We consider Vbat>3900 to be a full battery.
1531 * Since Voltage measured during charging is Voreg ~4.2v,
1532 * we dont update capacity if we are charging.
1535 /* if it has been more than 10 minutes since our last update
1536 * and we are charging we force a update.
1539 if (time_after(jiffies, di->ac_next_refresh)
1540 && (di->charger_source != POWER_SUPPLY_TYPE_BATTERY)) {
1542 charging_disabled = 1;
1543 di->ac_next_refresh = jiffies +
1544 msecs_to_jiffies(CHARGING_CAPACITY_UPDATE_PERIOD);
1547 /* We have to disable charging to read correct
1550 twl6030_stop_charger(di);
1551 /*voltage setteling time*/
1554 di->voltage_mV = twl6030_get_gpadc_conversion(di,
1555 di->gpadc_vbat_chnl);
1558 /* Setting the capacity level only makes sense when on
1559 * the battery is powering the board.
1561 // if (di->charge_status == POWER_SUPPLY_STATUS_DISCHARGING) {
1562 if (di->voltage_mV < 3500)
1564 else if (di->voltage_mV < 3600 && di->voltage_mV >= 3500)
1566 else if (di->voltage_mV < 3700 && di->voltage_mV >= 3600)
1568 else if (di->voltage_mV < 3800 && di->voltage_mV >= 3700)
1570 else if (di->voltage_mV < 3900 && di->voltage_mV >= 3800)
1572 else if (di->voltage_mV >= 3900)
1573 curr_capacity = 100;
1576 /* if we disabled charging to check capacity,
1577 * enable it again after we read the
1580 if (charging_disabled) {
1581 if (charger_source == POWER_SUPPLY_TYPE_MAINS)
1582 twl6030_start_ac_charger(di);
1583 else if (charger_source == POWER_SUPPLY_TYPE_USB)
1584 twl6030_start_usb_charger(di);
1587 /* if battery is not present we assume it is on battery simulator and
1588 * current capacity is set to 100%
1590 if (!is_battery_present(di))
1591 curr_capacity = 100;
1593 /* Debouncing of voltage change. */
1594 if (di->capacity == -1) {
1595 di->capacity = curr_capacity;
1596 di->capacity_debounce_count = 0;
1600 if (curr_capacity != di->prev_capacity) {
1601 di->prev_capacity = curr_capacity;
1602 di->capacity_debounce_count = 0;
1603 } else if (++di->capacity_debounce_count >= 4) {
1604 di->capacity = curr_capacity;
1605 di->capacity_debounce_count = 0;
1612 static int twl6030_set_watchdog(struct twl6030_bci_device_info *di, int val)
1614 di->watchdog_duration = val;
1616 dev_dbg(di->dev, "Watchdog reset %d", val);
1618 return twl_i2c_write_u8(TWL6030_MODULE_CHARGER, val, CONTROLLER_WDG);
1622 static void twl6030_bci_battery_work(struct work_struct *work)
1624 struct twl6030_bci_device_info *di = container_of(work,
1625 struct twl6030_bci_device_info, twl6030_bci_monitor_work.work);
1626 struct twl6030_gpadc_request req;
1631 /* Kick the charger watchdog */
1632 if (di->charge_status == POWER_SUPPLY_STATUS_CHARGING)
1633 twl6030_set_watchdog(di, di->watchdog_duration);
1635 req.method = TWL6030_GPADC_SW2;
1636 req.channels = (1 << 1) | (1 << di->gpadc_vbat_chnl) | (1 << 8);
1637 // req.channels = (1 << di->gpadc_vbat_chnl);
1640 ret = twl6030_gpadc_conversion(&req);
1642 queue_delayed_work(di->freezable_work, &di->twl6030_bci_monitor_work,
1643 msecs_to_jiffies(1000 * di->monitoring_interval));
1645 dev_info(di->dev, "gpadc conversion failed: %d\n", ret);
1649 if (req.rbuf[di->gpadc_vbat_chnl] > 0)
1650 di->voltage_mV = req.rbuf[di->gpadc_vbat_chnl];
1652 if (req.rbuf[8] > 0)
1653 di->bk_voltage_mV = req.rbuf[8];
1655 if (di->platform_data->battery_tmp_tbl == NULL)
1658 adc_code = req.rbuf[1];
1659 for (temp = 0; temp < di->platform_data->tblsize; temp++) {
1660 if (adc_code >= di->platform_data->
1661 battery_tmp_tbl[temp])
1665 /* first 2 values are for negative temperature */
1666 di->temp_C = (temp - 2); /* in degrees Celsius */
1668 if (capacity_changed(di))
1669 power_supply_changed(&di->bat);
1672 static void twl6030_current_mode_changed(struct twl6030_bci_device_info *di)
1676 /* FG_REG_01, 02, 03 is 24 bit unsigned sample counter value */
1677 ret = twl_i2c_read(TWL6030_MODULE_GASGAUGE, (u8 *) &di->timer_n1,
1682 * FG_REG_04, 5, 6, 7 is 32 bit signed accumulator value
1683 * accumulates instantaneous current value
1685 ret = twl_i2c_read(TWL6030_MODULE_GASGAUGE, (u8 *) &di->charge_n1,
1690 cancel_delayed_work(&di->twl6030_current_avg_work);
1691 queue_delayed_work(di->freezable_work, &di->twl6030_current_avg_work,
1692 msecs_to_jiffies(1000 * di->current_avg_interval));
1695 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
1698 static void twl6030_work_interval_changed(struct twl6030_bci_device_info *di)
1700 cancel_delayed_work(&di->twl6030_bci_monitor_work);
1701 queue_delayed_work(di->freezable_work, &di->twl6030_bci_monitor_work,
1702 msecs_to_jiffies(1000 * di->monitoring_interval));
1705 #define to_twl6030_bci_device_info(x) container_of((x), \
1706 struct twl6030_bci_device_info, bat);
1708 static void twl6030_bci_battery_external_power_changed(struct power_supply *psy)
1710 struct twl6030_bci_device_info *di = to_twl6030_bci_device_info(psy);
1712 cancel_delayed_work(&di->twl6030_bci_monitor_work);
1713 queue_delayed_work(di->freezable_work, &di->twl6030_bci_monitor_work, 0);
1716 #define to_twl6030_ac_device_info(x) container_of((x), \
1717 struct twl6030_bci_device_info, ac);
1719 static int twl6030_ac_get_property(struct power_supply *psy,
1720 enum power_supply_property psp,
1721 union power_supply_propval *val)
1723 struct twl6030_bci_device_info *di = to_twl6030_ac_device_info(psy);
1726 case POWER_SUPPLY_PROP_ONLINE:
1727 val->intval = di->ac_online;
1729 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
1730 val->intval = twl6030_get_gpadc_conversion(di, 9) * 1000;
1739 #define to_twl6030_usb_device_info(x) container_of((x), \
1740 struct twl6030_bci_device_info, usb);
1742 static int twl6030_usb_get_property(struct power_supply *psy,
1743 enum power_supply_property psp,
1744 union power_supply_propval *val)
1746 struct twl6030_bci_device_info *di = to_twl6030_usb_device_info(psy);
1749 case POWER_SUPPLY_PROP_ONLINE:
1750 val->intval = di->usb_online;
1752 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
1753 val->intval = twl6030_get_gpadc_conversion(di, 10) * 1000;
1762 #define to_twl6030_bk_bci_device_info(x) container_of((x), \
1763 struct twl6030_bci_device_info, bk_bat);
1765 static int twl6030_bk_bci_battery_get_property(struct power_supply *psy,
1766 enum power_supply_property psp,
1767 union power_supply_propval *val)
1769 struct twl6030_bci_device_info *di = to_twl6030_bk_bci_device_info(psy);
1772 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
1773 val->intval = di->bk_voltage_mV * 1000;
1782 static int twl6030_bci_battery_get_property(struct power_supply *psy,
1783 enum power_supply_property psp,
1784 union power_supply_propval *val)
1786 struct twl6030_bci_device_info *di;
1788 di = to_twl6030_bci_device_info(psy);
1791 case POWER_SUPPLY_PROP_STATUS:
1792 val->intval = di->charge_status;
1794 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
1795 di->voltage_mV = twl6030_get_gpadc_conversion(di,
1796 di->gpadc_vbat_chnl);
1797 val->intval = di->voltage_mV * 1000;
1799 case POWER_SUPPLY_PROP_CURRENT_NOW:
1800 twl6030battery_current(di);
1801 val->intval = di->current_uA;
1803 case POWER_SUPPLY_PROP_TEMP:
1804 val->intval = di->temp_C;
1806 case POWER_SUPPLY_PROP_ONLINE:
1807 val->intval = di->charger_source;
1809 case POWER_SUPPLY_PROP_CURRENT_AVG:
1810 val->intval = di->current_avg_uA;
1812 case POWER_SUPPLY_PROP_HEALTH:
1813 val->intval = di->bat_health;
1815 case POWER_SUPPLY_PROP_CAPACITY:
1816 val->intval = di->capacity;
1824 int twl6030_register_notifier(struct notifier_block *nb,
1825 unsigned int events)
1827 return blocking_notifier_chain_register(¬ifier_list, nb);
1829 EXPORT_SYMBOL_GPL(twl6030_register_notifier);
1831 int twl6030_unregister_notifier(struct notifier_block *nb,
1832 unsigned int events)
1834 return blocking_notifier_chain_unregister(¬ifier_list, nb);
1836 EXPORT_SYMBOL_GPL(twl6030_unregister_notifier);
1838 static void twl6030_usb_charger_work(struct work_struct *work)
1840 struct twl6030_bci_device_info *di =
1841 container_of(work, struct twl6030_bci_device_info, usb_work);
1843 switch (di->event) {
1844 case USB_EVENT_CHARGER:
1845 /* POWER_SUPPLY_TYPE_USB_DCP */
1846 di->usb_online = POWER_SUPPLY_TYPE_USB_DCP;
1847 di->charger_incurrentmA = 1800;
1849 case USB_EVENT_VBUS:
1850 switch (di->usb_online) {
1851 case POWER_SUPPLY_TYPE_USB_CDP:
1853 * Only 500mA here or high speed chirp
1854 * handshaking may break
1856 di->charger_incurrentmA = 500;
1857 case POWER_SUPPLY_TYPE_USB:
1861 case USB_EVENT_NONE:
1863 di->charger_incurrentmA = 0;
1865 case USB_EVENT_ENUMERATED:
1866 if (di->usb_online == POWER_SUPPLY_TYPE_USB_CDP)
1867 di->charger_incurrentmA = 560;
1869 di->charger_incurrentmA = di->usb_max_power;
1874 twl6030_start_usb_charger(di);
1875 power_supply_changed(&di->usb);
1878 static int twl6030_usb_notifier_call(struct notifier_block *nb,
1879 unsigned long event, void *data)
1881 struct twl6030_bci_device_info *di =
1882 container_of(nb, struct twl6030_bci_device_info, nb);
1886 case USB_EVENT_VBUS:
1887 di->usb_online = *((unsigned int *) data);
1889 case USB_EVENT_ENUMERATED:
1890 di->usb_max_power = *((unsigned int *) data);
1892 case USB_EVENT_CHARGER:
1893 case USB_EVENT_NONE:
1900 schedule_work(&di->usb_work);
1905 static ssize_t set_fg_mode(struct device *dev,
1906 struct device_attribute *attr, const char *buf, size_t count)
1911 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
1913 if ((strict_strtol(buf, 10, &val) < 0) || (val > 3))
1915 di->fuelgauge_mode = val;
1916 ret = twl_i2c_write_u8(TWL6030_MODULE_GASGAUGE, (val << 6) | CC_CAL_EN,
1920 twl6030_current_mode_changed(di);
1924 static ssize_t show_fg_mode(struct device *dev,
1925 struct device_attribute *attr, char *buf)
1928 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
1930 val = di->fuelgauge_mode;
1931 return sprintf(buf, "%d\n", val);
1934 static ssize_t set_charge_src(struct device *dev,
1935 struct device_attribute *attr, const char *buf, size_t count)
1939 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
1941 if ((strict_strtol(buf, 10, &val) < 0) || (val < 2) || (val > 3))
1943 di->vac_priority = val;
1947 static ssize_t show_charge_src(struct device *dev,
1948 struct device_attribute *attr, char *buf)
1951 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
1953 val = di->vac_priority;
1954 return sprintf(buf, "%d\n", val);
1957 static ssize_t show_vbus_voltage(struct device *dev,
1958 struct device_attribute *attr, char *buf)
1961 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
1963 val = twl6030_get_gpadc_conversion(di, 10);
1965 return sprintf(buf, "%d\n", val);
1968 static ssize_t show_id_level(struct device *dev, struct device_attribute *attr,
1972 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
1974 val = twl6030_get_gpadc_conversion(di, 14);
1976 return sprintf(buf, "%d\n", val);
1979 static ssize_t set_watchdog(struct device *dev,
1980 struct device_attribute *attr, const char *buf, size_t count)
1985 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
1987 if ((strict_strtol(buf, 10, &val) < 0) || (val < 1) || (val > 127))
1989 ret = twl6030_set_watchdog(di, val);
1996 static ssize_t show_watchdog(struct device *dev,
1997 struct device_attribute *attr, char *buf)
2000 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2002 val = di->watchdog_duration;
2003 return sprintf(buf, "%d\n", val);
2006 static ssize_t show_fg_counter(struct device *dev,
2007 struct device_attribute *attr, char *buf)
2012 ret = twl_i2c_read(TWL6030_MODULE_GASGAUGE, (u8 *) &fg_counter,
2016 return sprintf(buf, "%d\n", fg_counter);
2019 static ssize_t show_fg_accumulator(struct device *dev,
2020 struct device_attribute *attr, char *buf)
2025 ret = twl_i2c_read(TWL6030_MODULE_GASGAUGE, (u8 *) &fg_accum,
2030 return sprintf(buf, "%ld\n", fg_accum);
2033 static ssize_t show_fg_offset(struct device *dev,
2034 struct device_attribute *attr, char *buf)
2039 ret = twl_i2c_read(TWL6030_MODULE_GASGAUGE, (u8 *) &fg_offset,
2043 fg_offset = ((s16)(fg_offset << 6) >> 6);
2045 return sprintf(buf, "%d\n", fg_offset);
2048 static ssize_t set_fg_clear(struct device *dev, struct device_attribute *attr,
2049 const char *buf, size_t count)
2055 if ((strict_strtol(buf, 10, &val) < 0) || (val != 1))
2057 ret = twl_i2c_write_u8(TWL6030_MODULE_GASGAUGE, CC_AUTOCLEAR,
2065 static ssize_t set_fg_cal(struct device *dev, struct device_attribute *attr,
2066 const char *buf, size_t count)
2072 if ((strict_strtol(buf, 10, &val) < 0) || (val != 1))
2074 ret = twl_i2c_write_u8(TWL6030_MODULE_GASGAUGE, CC_CAL_EN, FG_REG_00);
2081 static ssize_t set_charging(struct device *dev, struct device_attribute *attr,
2082 const char *buf, size_t count)
2085 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2087 if (strncmp(buf, "startac", 7) == 0) {
2088 if (di->charger_source == POWER_SUPPLY_TYPE_USB)
2089 twl6030_stop_usb_charger(di);
2090 twl6030_start_ac_charger(di);
2091 } else if (strncmp(buf, "startusb", 8) == 0) {
2092 if (di->charger_source == POWER_SUPPLY_TYPE_MAINS)
2093 twl6030_stop_ac_charger(di);
2094 di->charger_source = POWER_SUPPLY_TYPE_USB;
2095 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
2096 twl6030_start_usb_charger(di);
2097 } else if (strncmp(buf, "stop" , 4) == 0)
2098 twl6030_stop_charger(di);
2105 static ssize_t set_regulation_voltage(struct device *dev,
2106 struct device_attribute *attr, const char *buf, size_t count)
2110 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2112 if ((strict_strtol(buf, 10, &val) < 0) || (val < 3500)
2113 || (val > di->platform_data->max_charger_voltagemV))
2115 di->platform_data->max_bat_voltagemV = val;
2116 twl6030_config_voreg_reg(di, val);
2121 static ssize_t show_regulation_voltage(struct device *dev,
2122 struct device_attribute *attr, char *buf)
2125 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2127 val = di->platform_data->max_bat_voltagemV;
2128 return sprintf(buf, "%u\n", val);
2131 static ssize_t set_termination_current(struct device *dev,
2132 struct device_attribute *attr, const char *buf, size_t count)
2136 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2138 if ((strict_strtol(buf, 10, &val) < 0) || (val < 50) || (val > 400))
2140 di->platform_data->termination_currentmA = val;
2141 twl6030_config_iterm_reg(di, val);
2146 static ssize_t show_termination_current(struct device *dev,
2147 struct device_attribute *attr, char *buf)
2150 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2152 val = di->platform_data->termination_currentmA;
2153 return sprintf(buf, "%u\n", val);
2156 static ssize_t set_cin_limit(struct device *dev,
2157 struct device_attribute *attr, const char *buf, size_t count)
2161 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2163 if ((strict_strtol(buf, 10, &val) < 0) || (val < 50) || (val > 1500))
2165 di->charger_incurrentmA = val;
2166 twl6030_config_cinlimit_reg(di, val);
2171 static ssize_t show_cin_limit(struct device *dev, struct device_attribute *attr,
2175 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2177 val = di->charger_incurrentmA;
2178 return sprintf(buf, "%u\n", val);
2181 static ssize_t set_charge_current(struct device *dev,
2182 struct device_attribute *attr, const char *buf, size_t count)
2186 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2188 if ((strict_strtol(buf, 10, &val) < 0) || (val < 300)
2189 || (val > di->platform_data->max_charger_currentmA))
2191 di->charger_outcurrentmA = val;
2192 twl6030_config_vichrg_reg(di, val);
2197 static ssize_t show_charge_current(struct device *dev,
2198 struct device_attribute *attr, char *buf)
2201 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2203 val = di->charger_outcurrentmA;
2204 return sprintf(buf, "%u\n", val);
2207 static ssize_t set_min_vbus(struct device *dev, struct device_attribute *attr,
2208 const char *buf, size_t count)
2212 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2214 if ((strict_strtol(buf, 10, &val) < 0) || (val < 4200) || (val > 4760))
2217 twl6030_config_min_vbus_reg(di, val);
2222 static ssize_t show_min_vbus(struct device *dev, struct device_attribute *attr,
2226 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2229 return sprintf(buf, "%u\n", val);
2232 static ssize_t set_current_avg_interval(struct device *dev,
2233 struct device_attribute *attr, const char *buf, size_t count)
2237 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2239 if ((strict_strtol(buf, 10, &val) < 0) || (val < 10) || (val > 3600))
2241 di->current_avg_interval = val;
2242 twl6030_current_mode_changed(di);
2247 static ssize_t show_current_avg_interval(struct device *dev,
2248 struct device_attribute *attr, char *buf)
2251 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2253 val = di->current_avg_interval;
2254 return sprintf(buf, "%u\n", val);
2257 static ssize_t set_wakelock_enable(struct device *dev,
2258 struct device_attribute *attr, const char *buf, size_t count)
2262 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2264 if ((strict_strtol(buf, 10, &val) < 0) || (val < 0) || (val > 1))
2267 if ((val) && (di->charger_source == POWER_SUPPLY_TYPE_MAINS))
2268 wake_lock(&chrg_lock);
2270 wake_unlock(&chrg_lock);
2272 di->wakelock_enabled = val;
2276 static ssize_t show_wakelock_enable(struct device *dev,
2277 struct device_attribute *attr, char *buf)
2280 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2282 val = di->wakelock_enabled;
2283 return sprintf(buf, "%u\n", val);
2286 static ssize_t set_monitoring_interval(struct device *dev,
2287 struct device_attribute *attr, const char *buf, size_t count)
2291 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2293 if ((strict_strtol(buf, 10, &val) < 0) || (val < 10) || (val > 3600))
2295 di->monitoring_interval = val;
2296 twl6030_work_interval_changed(di);
2301 static ssize_t show_monitoring_interval(struct device *dev,
2302 struct device_attribute *attr, char *buf)
2305 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2307 val = di->monitoring_interval;
2308 return sprintf(buf, "%u\n", val);
2311 static ssize_t show_bsi(struct device *dev,
2312 struct device_attribute *attr, char *buf)
2315 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2317 val = twl6030_get_gpadc_conversion(di, 0);
2318 return sprintf(buf, "%d\n", val);
2321 static ssize_t show_stat1(struct device *dev,
2322 struct device_attribute *attr, char *buf)
2325 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2328 return sprintf(buf, "%u\n", val);
2331 static ssize_t show_status_int1(struct device *dev,
2332 struct device_attribute *attr, char *buf)
2335 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2337 val = di->status_int1;
2338 return sprintf(buf, "%u\n", val);
2341 static ssize_t show_status_int2(struct device *dev,
2342 struct device_attribute *attr, char *buf)
2345 struct twl6030_bci_device_info *di = dev_get_drvdata(dev);
2347 val = di->status_int2;
2348 return sprintf(buf, "%u\n", val);
2351 static DEVICE_ATTR(fg_mode, S_IWUSR | S_IRUGO, show_fg_mode, set_fg_mode);
2352 static DEVICE_ATTR(charge_src, S_IWUSR | S_IRUGO, show_charge_src,
2354 static DEVICE_ATTR(vbus_voltage, S_IRUGO, show_vbus_voltage, NULL);
2355 static DEVICE_ATTR(id_level, S_IRUGO, show_id_level, NULL);
2356 static DEVICE_ATTR(watchdog, S_IWUSR | S_IRUGO, show_watchdog, set_watchdog);
2357 static DEVICE_ATTR(fg_counter, S_IRUGO, show_fg_counter, NULL);
2358 static DEVICE_ATTR(fg_accumulator, S_IRUGO, show_fg_accumulator, NULL);
2359 static DEVICE_ATTR(fg_offset, S_IRUGO, show_fg_offset, NULL);
2360 static DEVICE_ATTR(fg_clear, S_IWUSR, NULL, set_fg_clear);
2361 static DEVICE_ATTR(fg_cal, S_IWUSR, NULL, set_fg_cal);
2362 static DEVICE_ATTR(charging, S_IWUSR | S_IRUGO, NULL, set_charging);
2363 static DEVICE_ATTR(regulation_voltage, S_IWUSR | S_IRUGO,
2364 show_regulation_voltage, set_regulation_voltage);
2365 static DEVICE_ATTR(termination_current, S_IWUSR | S_IRUGO,
2366 show_termination_current, set_termination_current);
2367 static DEVICE_ATTR(cin_limit, S_IWUSR | S_IRUGO, show_cin_limit,
2369 static DEVICE_ATTR(charge_current, S_IWUSR | S_IRUGO, show_charge_current,
2370 set_charge_current);
2371 static DEVICE_ATTR(min_vbus, S_IWUSR | S_IRUGO, show_min_vbus, set_min_vbus);
2372 static DEVICE_ATTR(monitoring_interval, S_IWUSR | S_IRUGO,
2373 show_monitoring_interval, set_monitoring_interval);
2374 static DEVICE_ATTR(current_avg_interval, S_IWUSR | S_IRUGO,
2375 show_current_avg_interval, set_current_avg_interval);
2376 static DEVICE_ATTR(wakelock_enable, S_IWUSR | S_IRUGO,
2377 show_wakelock_enable, set_wakelock_enable);
2378 static DEVICE_ATTR(bsi, S_IRUGO, show_bsi, NULL);
2379 static DEVICE_ATTR(stat1, S_IRUGO, show_stat1, NULL);
2380 static DEVICE_ATTR(status_int1, S_IRUGO, show_status_int1, NULL);
2381 static DEVICE_ATTR(status_int2, S_IRUGO, show_status_int2, NULL);
2383 static struct attribute *twl6030_bci_attributes[] = {
2384 &dev_attr_fg_mode.attr,
2385 &dev_attr_charge_src.attr,
2386 &dev_attr_vbus_voltage.attr,
2387 &dev_attr_id_level.attr,
2388 &dev_attr_watchdog.attr,
2389 &dev_attr_fg_counter.attr,
2390 &dev_attr_fg_accumulator.attr,
2391 &dev_attr_fg_offset.attr,
2392 &dev_attr_fg_clear.attr,
2393 &dev_attr_fg_cal.attr,
2394 &dev_attr_charging.attr,
2395 &dev_attr_regulation_voltage.attr,
2396 &dev_attr_termination_current.attr,
2397 &dev_attr_cin_limit.attr,
2398 &dev_attr_charge_current.attr,
2399 &dev_attr_min_vbus.attr,
2400 &dev_attr_monitoring_interval.attr,
2401 &dev_attr_current_avg_interval.attr,
2403 &dev_attr_stat1.attr,
2404 &dev_attr_status_int1.attr,
2405 &dev_attr_status_int2.attr,
2406 &dev_attr_wakelock_enable.attr,
2410 static const struct attribute_group twl6030_bci_attr_group = {
2411 .attrs = twl6030_bci_attributes,
2414 static char *twl6030_bci_supplied_to[] = {
2418 extern int dwc_vbus_status(void);
2420 static void twl6030_battery_update_status(struct twl6030_bci_device_info *di)
2422 power_supply_changed(&di->bat);
2424 static void twl6030_battery_work(struct work_struct *work)
2426 struct twl6030_bci_device_info *di = container_of(work, struct twl6030_bci_device_info, work.work);
2427 twl6030_battery_update_status(di);
2428 //set charging current
2429 twl_i2c_write_u8(TWL6030_MODULE_CHARGER,0x00,CHARGERUSB_CTRL1);
2430 if(2 == dwc_vbus_status()){
2431 twl_i2c_write_u8(TWL6030_MODULE_CHARGER, 0x29,CHARGERUSB_CINLIMIT); //set vbus input current is 1A
2432 twl_i2c_write_u8(TWL6030_MODULE_CHARGER, 0x09,CHARGERUSB_VICHRG); //set mos output current is 1A
2434 else if(1 == dwc_vbus_status()){
2435 twl_i2c_write_u8(TWL6030_MODULE_CHARGER, 0x09,CHARGERUSB_CINLIMIT);//set vbus input current is 500ma
2436 twl_i2c_write_u8(TWL6030_MODULE_CHARGER, 0x04,CHARGERUSB_VICHRG); //set mos output current is 500ma
2439 /* reschedule for the next time */
2440 queue_delayed_work(di->freezable_work, &di->work, di->interval);
2443 static int __devinit twl6030_bci_battery_probe(struct platform_device *pdev)
2445 struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
2446 struct twl6030_bci_device_info *di;
2449 u8 controller_stat = 0;
2450 u8 chargerusb_ctrl1 = 0;
2453 printk("%s\n", __func__);
2455 dev_info(&pdev->dev, "platform_data not available\n");
2459 di = kzalloc(sizeof(*di), GFP_KERNEL);
2463 di->platform_data = kmemdup(pdata, sizeof(*pdata), GFP_KERNEL);
2464 if (!di->platform_data) {
2469 if (pdata->monitoring_interval == 0) {
2470 di->monitoring_interval = 10;
2471 di->current_avg_interval = 10;
2473 di->monitoring_interval = pdata->monitoring_interval;
2474 di->current_avg_interval = pdata->monitoring_interval;
2477 di->platform_data = pdata;
2478 di->features = pdata->features;
2479 di->dev = &pdev->dev;
2481 if (di->features & TWL6032_SUBCLASS) {
2482 ret = twl_i2c_read_u8(TWL_MODULE_RTC, ®, CHARGER_MODE_REG);
2484 goto temp_setup_fail;
2486 if (reg & CHARGER_MODE_POWERPATH) {
2487 dev_dbg(di->dev, "Charger: PowerPath\n");
2488 di->use_power_path = 1;
2490 dev_dbg(di->dev, "Charger: NON PowerPath\n");
2491 di->use_power_path = 0;
2494 if (reg & CHARGER_MODE_AUTOCHARGE) {
2495 dev_dbg(di->dev, "Charger: AutoCharge\n");
2496 di->use_hw_charger = 1;
2498 dev_dbg(di->dev, "Charger: NON AutoCharge\n");
2499 di->use_hw_charger = 0;
2502 di->use_power_path = 0;
2503 di->use_hw_charger = 0;
2506 if (di->use_hw_charger) {
2507 di->platform_data->max_charger_currentmA =
2508 twl6030_get_limit2_reg(di);
2509 di->platform_data->max_charger_voltagemV =
2510 twl6030_get_limit1_reg(di);
2511 di->platform_data->termination_currentmA =
2512 twl6030_get_iterm_reg(di);
2513 di->platform_data->max_bat_voltagemV =
2514 twl6030_get_voreg_reg(di);
2517 di->bat.name = "twl6030_battery";
2518 di->bat.supplied_to = twl6030_bci_supplied_to;
2519 di->bat.num_supplicants = ARRAY_SIZE(twl6030_bci_supplied_to);
2520 di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
2521 di->bat.properties = twl6030_bci_battery_props;
2522 di->bat.num_properties = ARRAY_SIZE(twl6030_bci_battery_props);
2523 di->bat.get_property = twl6030_bci_battery_get_property;
2524 di->bat.external_power_changed =
2525 twl6030_bci_battery_external_power_changed;
2526 di->bat_health = POWER_SUPPLY_HEALTH_GOOD;
2528 di->usb.name = "twl6030_usb";
2529 di->usb.type = POWER_SUPPLY_TYPE_USB;
2530 di->usb.properties = twl6030_usb_props;
2531 di->usb.num_properties = ARRAY_SIZE(twl6030_usb_props);
2532 di->usb.get_property = twl6030_usb_get_property;
2534 di->ac.name = "twl6030_ac";
2535 di->ac.type = POWER_SUPPLY_TYPE_MAINS;
2536 di->ac.properties = twl6030_ac_props;
2537 di->ac.num_properties = ARRAY_SIZE(twl6030_ac_props);
2538 di->ac.get_property = twl6030_ac_get_property;
2540 di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
2542 di->bk_bat.name = "twl6030_bk_battery";
2543 di->bk_bat.type = POWER_SUPPLY_TYPE_BATTERY;
2544 di->bk_bat.properties = twl6030_bk_bci_battery_props;
2545 di->bk_bat.num_properties = ARRAY_SIZE(twl6030_bk_bci_battery_props);
2546 di->bk_bat.get_property = twl6030_bk_bci_battery_get_property;
2548 di->vac_priority = 2;
2550 di->capacity_debounce_count = 0;
2551 di->ac_next_refresh = jiffies - 1;
2552 platform_set_drvdata(pdev, di);
2554 /* calculate current max scale from sense */
2555 if (pdata->sense_resistor_mohm) {
2556 di->current_max_scale = (62000) / pdata->sense_resistor_mohm;
2558 /* Set sensible defaults if platform data is missing */
2559 if (di->features & TWL6032_SUBCLASS)
2560 di->current_max_scale = 3100;
2562 di->current_max_scale = 6200;
2565 wake_lock_init(&chrg_lock, WAKE_LOCK_SUSPEND, "ac_chrg_wake_lock");
2566 /* settings for temperature sensing */
2567 ret = twl6030battery_temp_setup(true);
2569 goto temp_setup_fail;
2571 /* request charger fault interruption choosing between sw/hw mode */
2572 irq = platform_get_irq(pdev, 1);
2573 if (!di->use_hw_charger)
2574 ret = request_threaded_irq(irq, NULL,
2575 twl6030charger_fault_interrupt,
2576 0, "twl_bci_fault", di);
2578 ret = request_threaded_irq(irq, NULL,
2579 twl6032charger_fault_interrupt_hw,
2580 0, "twl_bci_fault", di);
2583 dev_info(&pdev->dev, "could not request irq %d, status %d\n",
2585 goto temp_setup_fail;
2588 /* request charger ctrl interruption choosing between sw/hw mode */
2589 irq = platform_get_irq(pdev, 0);
2590 if (!di->use_hw_charger)
2591 ret = request_threaded_irq(irq, NULL,
2592 twl6030charger_ctrl_interrupt,
2593 0, "twl_bci_ctrl", di);
2595 ret = request_threaded_irq(irq, NULL,
2596 twl6032charger_ctrl_interrupt_hw,
2597 0, "twl_bci_ctrl", di);
2600 dev_info(&pdev->dev, "could not request irq %d, status %d\n",
2605 ret = power_supply_register(&pdev->dev, &di->bat);
2607 dev_info(&pdev->dev, "failed to register main battery\n");
2611 ret = power_supply_register(&pdev->dev, &di->usb);
2613 dev_info(&pdev->dev, "failed to register usb power supply\n");
2617 ret = power_supply_register(&pdev->dev, &di->ac);
2619 dev_info(&pdev->dev, "failed to register ac power supply\n");
2623 ret = power_supply_register(&pdev->dev, &di->bk_bat);
2625 dev_info(&pdev->dev, "failed to register backup battery\n");
2626 goto bk_batt_failed;
2631 //di->freezable_work = create_freezable_workqueue("battery");
2632 di->freezable_work = system_freezable_wq;
2633 INIT_DELAYED_WORK(&di->twl6030_bci_monitor_work,
2634 twl6030_bci_battery_work);
2635 queue_delayed_work(di->freezable_work, &di->twl6030_bci_monitor_work, 0);
2637 INIT_DELAYED_WORK_DEFERRABLE(&di->twl6030_current_avg_work,
2638 twl6030_current_avg);
2639 queue_delayed_work(di->freezable_work, &di->twl6030_current_avg_work, 500);
2641 ret = twl6030battery_voltage_setup(di);
2643 dev_info(&pdev->dev, "voltage measurement setup failed\n");
2645 ret = twl6030battery_current_setup(true);
2647 dev_info(&pdev->dev, "current measurement setup failed\n");
2649 /* initialize for USB charging */
2650 if (!di->use_hw_charger) {
2651 twl6030_config_limit1_reg(di, pdata->max_charger_voltagemV);
2652 twl6030_config_limit2_reg(di,
2653 di->platform_data->max_charger_currentmA);
2655 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, MBAT_TEMP,
2656 CONTROLLER_INT_MASK);
2658 goto bk_batt_failed;
2660 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, MASK_MCHARGERUSB_THMREG,
2661 CHARGERUSB_INT_MASK);
2663 goto bk_batt_failed;
2665 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &controller_stat,
2668 goto bk_batt_failed;
2670 di->stat1 = controller_stat;
2671 di->charger_outcurrentmA = di->platform_data->max_charger_currentmA;
2673 twl6030_set_watchdog(di, 32);
2675 INIT_WORK(&di->usb_work, twl6030_usb_charger_work);
2676 di->nb.notifier_call = twl6030_usb_notifier_call;
2677 di->otg = otg_get_transceiver();
2679 ret = otg_register_notifier(di->otg, &di->nb);
2681 dev_err(&pdev->dev, "otg register notifier"
2682 " failed %d\n", ret);
2684 dev_err(&pdev->dev, "otg_get_transceiver failed %d\n", ret);
2686 if (di->features & TWL6032_SUBCLASS) {
2687 di->charger_incurrentmA = 100;
2688 di->gpadc_vbat_chnl = TWL6032_GPADC_VBAT_CHNL;
2690 di->charger_incurrentmA = twl6030_get_usb_max_power(di->otg);
2691 di->gpadc_vbat_chnl = TWL6030_GPADC_VBAT_CHNL;
2694 di->voltage_mV = twl6030_get_gpadc_conversion(di, di->gpadc_vbat_chnl);
2695 dev_info(&pdev->dev, "Battery Voltage at Bootup is %d mV\n",
2698 ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &hw_state, STS_HW_CONDITIONS);
2700 goto bk_batt_failed;
2701 if (!is_battery_present(di)) {
2702 if (!(hw_state & STS_USB_ID)) {
2703 dev_dbg(di->dev, "Put USB in HZ mode\n");
2704 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER,
2705 &chargerusb_ctrl1, CHARGERUSB_CTRL1);
2707 goto bk_batt_failed;
2709 chargerusb_ctrl1 |= HZ_MODE;
2710 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER,
2711 chargerusb_ctrl1, CHARGERUSB_CTRL1);
2713 goto bk_batt_failed;
2715 } else if (!di->use_hw_charger) {
2716 if (controller_stat & VAC_DET) {
2717 di->ac_online = POWER_SUPPLY_TYPE_MAINS;
2718 twl6030_start_ac_charger(di);
2719 } else if (controller_stat & VBUS_DET) {
2721 * In HOST mode (ID GROUND) with a device connected,
2722 * do no enable usb charging
2724 if (!(hw_state & STS_USB_ID)) {
2725 di->usb_online = POWER_SUPPLY_TYPE_USB;
2726 di->charger_source = POWER_SUPPLY_TYPE_USB;
2728 POWER_SUPPLY_STATUS_CHARGING;
2729 di->event = USB_EVENT_VBUS;
2730 schedule_work(&di->usb_work);
2734 int fault, charge_usb, charge_ac;
2736 twl_i2c_read_u8(TWL6032_MODULE_CHARGER, ®,
2737 CHARGERUSB_INT_STATUS);
2739 fault = !(di->stat1 & CONTROLLER_STAT1_LINCH_GATED) &&
2740 !(di->stat1 & CONTROLLER_STAT1_FAULT_WDG);
2741 charge_usb = (di->stat1 & VBUS_DET) &&
2742 !(reg & CHARGERUSB_FAULT);
2743 charge_ac = (di->stat1 & VAC_DET) &&
2744 !(di->stat1 & CONTROLLER_STAT1_EXTCHRG_STATZ);
2746 dev_dbg(di->dev, "boot charge state fault %d, usb %d, ac %d\n",
2747 fault, charge_usb, charge_ac);
2749 if (fault && (charge_usb || charge_ac))
2750 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
2752 if (di->stat1 & (VBUS_DET | VAC_DET))
2754 POWER_SUPPLY_STATUS_NOT_CHARGING;
2757 POWER_SUPPLY_STATUS_DISCHARGING;
2761 di->interval = msecs_to_jiffies(1 * 1000);
2762 INIT_DELAYED_WORK(&di->work, twl6030_battery_work);
2763 queue_delayed_work(di->freezable_work, &di->work, 1*HZ);
2765 ret = twl6030backupbatt_setup();
2767 dev_info(&pdev->dev, "Backup Bat charging setup failed\n");
2769 twl6030_interrupt_unmask(TWL6030_CHARGER_CTRL_INT_MASK,
2770 REG_INT_MSK_LINE_C);
2771 twl6030_interrupt_unmask(TWL6030_CHARGER_CTRL_INT_MASK,
2773 twl6030_interrupt_unmask(TWL6030_CHARGER_FAULT_INT_MASK,
2774 REG_INT_MSK_LINE_C);
2775 twl6030_interrupt_unmask(TWL6030_CHARGER_FAULT_INT_MASK,
2778 ret = sysfs_create_group(&pdev->dev.kobj, &twl6030_bci_attr_group);
2780 dev_info(&pdev->dev, "could not create sysfs files\n");
2785 cancel_delayed_work(&di->twl6030_bci_monitor_work);
2786 power_supply_unregister(&di->ac);
2788 power_supply_unregister(&di->usb);
2790 power_supply_unregister(&di->bat);
2794 irq = platform_get_irq(pdev, 1);
2797 wake_lock_destroy(&chrg_lock);
2798 platform_set_drvdata(pdev, NULL);
2804 static int __devexit twl6030_bci_battery_remove(struct platform_device *pdev)
2806 struct twl6030_bci_device_info *di = platform_get_drvdata(pdev);
2809 twl6030_interrupt_mask(TWL6030_CHARGER_CTRL_INT_MASK,
2810 REG_INT_MSK_LINE_C);
2811 twl6030_interrupt_mask(TWL6030_CHARGER_CTRL_INT_MASK,
2813 twl6030_interrupt_mask(TWL6030_CHARGER_FAULT_INT_MASK,
2814 REG_INT_MSK_LINE_C);
2815 twl6030_interrupt_mask(TWL6030_CHARGER_FAULT_INT_MASK,
2818 irq = platform_get_irq(pdev, 0);
2821 irq = platform_get_irq(pdev, 1);
2824 otg_unregister_notifier(di->otg, &di->nb);
2825 sysfs_remove_group(&pdev->dev.kobj, &twl6030_bci_attr_group);
2826 cancel_delayed_work(&di->twl6030_bci_monitor_work);
2827 cancel_delayed_work(&di->twl6030_current_avg_work);
2828 flush_scheduled_work();
2829 power_supply_unregister(&di->bat);
2830 power_supply_unregister(&di->usb);
2831 power_supply_unregister(&di->ac);
2832 power_supply_unregister(&di->bk_bat);
2833 wake_lock_destroy(&chrg_lock);
2834 platform_set_drvdata(pdev, NULL);
2835 kfree(di->platform_data);
2842 static int twl6030_bci_battery_suspend(struct device *dev)
2844 struct platform_device *pdev = to_platform_device(dev);
2845 struct twl6030_bci_device_info *di = platform_get_drvdata(pdev);
2850 /* mask to prevent wakeup due to 32s timeout from External charger */
2851 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &rd_reg,
2852 CONTROLLER_INT_MASK);
2856 rd_reg |= MVAC_FAULT;
2857 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, MBAT_TEMP,
2858 CONTROLLER_INT_MASK);
2862 //cancel_delayed_work(&di->work);
2863 //cancel_delayed_work(&di->twl6030_bci_monitor_work);
2864 //cancel_delayed_work(&di->twl6030_current_avg_work);
2866 /* We cannot tolarate a sleep longer than 30 seconds
2867 * while on ac charging we have to reset the BQ watchdog timer.
2869 // if ((di->charger_source == POWER_SUPPLY_TYPE_MAINS) &&
2870 // ((wakeup_timer_seconds > 25) || !wakeup_timer_seconds)) {
2871 // wakeup_timer_seconds = 25;
2874 /*reset the BQ watch dog*/
2875 events = BQ2415x_RESET_TIMER;
2876 blocking_notifier_call_chain(¬ifier_list, events, NULL);
2878 ret = twl6030battery_temp_setup(false);
2880 pr_err("%s: Temp measurement setup failed (%d)!\n",
2885 ret = twl6030battery_current_setup(false);
2887 pr_err("%s: Current measurement setup failed (%d)!\n",
2894 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
2898 static int twl6030_bci_battery_resume(struct device *dev)
2900 struct platform_device *pdev = to_platform_device(dev);
2901 struct twl6030_bci_device_info *di = platform_get_drvdata(pdev);
2906 ret = twl6030battery_temp_setup(true);
2908 pr_err("%s: Temp measurement setup failed (%d)!\n",
2913 ret = twl6030battery_current_setup(true);
2915 pr_err("%s: Current measurement setup failed (%d)!\n",
2920 ret = twl_i2c_read_u8(TWL6030_MODULE_CHARGER, &rd_reg, CONTROLLER_INT_MASK);
2924 rd_reg &= ~(0xFF & MVAC_FAULT);
2925 ret = twl_i2c_write_u8(TWL6030_MODULE_CHARGER, MBAT_TEMP,
2926 CONTROLLER_INT_MASK);
2930 //queue_delayed_work(di->freezable_work, &di->twl6030_bci_monitor_work, 0);
2931 //queue_delayed_work(di->freezable_work, &di->twl6030_current_avg_work, 50);
2932 //queue_delayed_work(di->freezable_work, &di->work, di->interval);
2934 events = BQ2415x_RESET_TIMER;
2935 blocking_notifier_call_chain(¬ifier_list, events, NULL);
2939 pr_err("%s: Error access to TWL6030 (%d)\n", __func__, ret);
2943 #define twl6030_bci_battery_suspend NULL
2944 #define twl6030_bci_battery_resume NULL
2945 #endif /* CONFIG_PM */
2947 static const struct dev_pm_ops pm_ops = {
2948 .suspend = twl6030_bci_battery_suspend,
2949 .resume = twl6030_bci_battery_resume,
2952 static struct platform_driver twl6030_bci_battery_driver = {
2953 .probe = twl6030_bci_battery_probe,
2954 .remove = __devexit_p(twl6030_bci_battery_remove),
2956 .name = "twl6030_bci",
2961 static int __init twl6030_battery_init(void)
2963 return platform_driver_register(&twl6030_bci_battery_driver);
2965 module_init(twl6030_battery_init);
2967 static void __exit twl6030_battery_exit(void)
2969 platform_driver_unregister(&twl6030_bci_battery_driver);
2971 module_exit(twl6030_battery_exit);
2973 MODULE_LICENSE("GPL");
2974 MODULE_ALIAS("platform:twl6030_bci");
2975 MODULE_AUTHOR("Texas Instruments Inc");