aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/power/twl4030_charger.c59
-rw-r--r--include/linux/i2c/twl.h2
2 files changed, 61 insertions, 0 deletions
diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index 3e6e99101106..0511610b235f 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -28,6 +28,7 @@
28#define TWL4030_BCIVBUS 0x0c 28#define TWL4030_BCIVBUS 0x0c
29#define TWL4030_BCIMFSTS4 0x10 29#define TWL4030_BCIMFSTS4 0x10
30#define TWL4030_BCICTL1 0x23 30#define TWL4030_BCICTL1 0x23
31#define TWL4030_BB_CFG 0x12
31 32
32#define TWL4030_BCIAUTOWEN BIT(5) 33#define TWL4030_BCIAUTOWEN BIT(5)
33#define TWL4030_CONFIG_DONE BIT(4) 34#define TWL4030_CONFIG_DONE BIT(4)
@@ -37,6 +38,17 @@
37#define TWL4030_USBFASTMCHG BIT(2) 38#define TWL4030_USBFASTMCHG BIT(2)
38#define TWL4030_STS_VBUS BIT(7) 39#define TWL4030_STS_VBUS BIT(7)
39#define TWL4030_STS_USB_ID BIT(2) 40#define TWL4030_STS_USB_ID BIT(2)
41#define TWL4030_BBCHEN BIT(4)
42#define TWL4030_BBSEL_MASK 0b1100
43#define TWL4030_BBSEL_2V5 0b0000
44#define TWL4030_BBSEL_3V0 0b0100
45#define TWL4030_BBSEL_3V1 0b1000
46#define TWL4030_BBSEL_3V2 0b1100
47#define TWL4030_BBISEL_MASK 0b11
48#define TWL4030_BBISEL_25uA 0b00
49#define TWL4030_BBISEL_150uA 0b01
50#define TWL4030_BBISEL_500uA 0b10
51#define TWL4030_BBISEL_1000uA 0b11
40 52
41/* BCI interrupts */ 53/* BCI interrupts */
42#define TWL4030_WOVF BIT(0) /* Watchdog overflow */ 54#define TWL4030_WOVF BIT(0) /* Watchdog overflow */
@@ -202,6 +214,49 @@ static int twl4030_charger_enable_ac(bool enable)
202} 214}
203 215
204/* 216/*
217 * Enable/Disable charging of Backup Battery.
218 */
219static int twl4030_charger_enable_backup(int uvolt, int uamp)
220{
221 int ret;
222 u8 flags;
223
224 if (uvolt < 2500000 ||
225 uamp < 25) {
226 /* disable charging of backup battery */
227 ret = twl4030_clear_set(TWL4030_MODULE_PM_RECEIVER,
228 TWL4030_BBCHEN, 0, TWL4030_BB_CFG);
229 return ret;
230 }
231
232 flags = TWL4030_BBCHEN;
233 if (uvolt >= 3200000)
234 flags |= TWL4030_BBSEL_3V2;
235 else if (uvolt >= 3100000)
236 flags |= TWL4030_BBSEL_3V1;
237 else if (uvolt >= 3000000)
238 flags |= TWL4030_BBSEL_3V0;
239 else
240 flags |= TWL4030_BBSEL_2V5;
241
242 if (uamp >= 1000)
243 flags |= TWL4030_BBISEL_1000uA;
244 else if (uamp >= 500)
245 flags |= TWL4030_BBISEL_500uA;
246 else if (uamp >= 150)
247 flags |= TWL4030_BBISEL_150uA;
248 else
249 flags |= TWL4030_BBISEL_25uA;
250
251 ret = twl4030_clear_set(TWL4030_MODULE_PM_RECEIVER,
252 TWL4030_BBSEL_MASK | TWL4030_BBISEL_MASK,
253 flags,
254 TWL4030_BB_CFG);
255
256 return ret;
257}
258
259/*
205 * TWL4030 CHG_PRES (AC charger presence) events 260 * TWL4030 CHG_PRES (AC charger presence) events
206 */ 261 */
207static irqreturn_t twl4030_charger_interrupt(int irq, void *arg) 262static irqreturn_t twl4030_charger_interrupt(int irq, void *arg)
@@ -424,6 +479,7 @@ static enum power_supply_property twl4030_charger_props[] = {
424static int __init twl4030_bci_probe(struct platform_device *pdev) 479static int __init twl4030_bci_probe(struct platform_device *pdev)
425{ 480{
426 struct twl4030_bci *bci; 481 struct twl4030_bci *bci;
482 struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
427 int ret; 483 int ret;
428 u32 reg; 484 u32 reg;
429 485
@@ -503,6 +559,8 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
503 559
504 twl4030_charger_enable_ac(true); 560 twl4030_charger_enable_ac(true);
505 twl4030_charger_enable_usb(bci, true); 561 twl4030_charger_enable_usb(bci, true);
562 twl4030_charger_enable_backup(pdata->bb_uvolt,
563 pdata->bb_uamp);
506 564
507 return 0; 565 return 0;
508 566
@@ -531,6 +589,7 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
531 589
532 twl4030_charger_enable_ac(false); 590 twl4030_charger_enable_ac(false);
533 twl4030_charger_enable_usb(bci, false); 591 twl4030_charger_enable_usb(bci, false);
592 twl4030_charger_enable_backup(0, 0);
534 593
535 /* mask interrupts */ 594 /* mask interrupts */
536 twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff, 595 twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff,
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index 3993477103a5..8eec4403b170 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -555,6 +555,8 @@ struct twl4030_clock_init_data {
555struct twl4030_bci_platform_data { 555struct twl4030_bci_platform_data {
556 int *battery_tmp_tbl; 556 int *battery_tmp_tbl;
557 unsigned int tblsize; 557 unsigned int tblsize;
558 int bb_uvolt; /* voltage to charge backup battery */
559 int bb_uamp; /* current for backup battery charging */
558}; 560};
559 561
560/* TWL4030_GPIO_MAX (18) GPIOs, with interrupts */ 562/* TWL4030_GPIO_MAX (18) GPIOs, with interrupts */