|
28 | 28 | #define TWL4030_BCIVBUS 0x0c |
29 | 29 | #define TWL4030_BCIMFSTS4 0x10 |
30 | 30 | #define TWL4030_BCICTL1 0x23 |
| 31 | +#define TWL4030_BB_CFG 0x12 |
31 | 32 |
|
32 | 33 | #define TWL4030_BCIAUTOWEN BIT(5) |
33 | 34 | #define TWL4030_CONFIG_DONE BIT(4) |
|
37 | 38 | #define TWL4030_USBFASTMCHG BIT(2) |
38 | 39 | #define TWL4030_STS_VBUS BIT(7) |
39 | 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 | 53 | /* BCI interrupts */ |
42 | 54 | #define TWL4030_WOVF BIT(0) /* Watchdog overflow */ |
@@ -201,6 +213,49 @@ static int twl4030_charger_enable_ac(bool enable) |
201 | 213 | return ret; |
202 | 214 | } |
203 | 215 |
|
| 216 | +/* |
| 217 | + * Enable/Disable charging of Backup Battery. |
| 218 | + */ |
| 219 | +static 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 | + |
204 | 259 | /* |
205 | 260 | * TWL4030 CHG_PRES (AC charger presence) events |
206 | 261 | */ |
@@ -424,6 +479,7 @@ static enum power_supply_property twl4030_charger_props[] = { |
424 | 479 | static int __init twl4030_bci_probe(struct platform_device *pdev) |
425 | 480 | { |
426 | 481 | struct twl4030_bci *bci; |
| 482 | + struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data; |
427 | 483 | int ret; |
428 | 484 | u32 reg; |
429 | 485 |
|
@@ -503,6 +559,8 @@ static int __init twl4030_bci_probe(struct platform_device *pdev) |
503 | 559 |
|
504 | 560 | twl4030_charger_enable_ac(true); |
505 | 561 | twl4030_charger_enable_usb(bci, true); |
| 562 | + twl4030_charger_enable_backup(pdata->bb_uvolt, |
| 563 | + pdata->bb_uamp); |
506 | 564 |
|
507 | 565 | return 0; |
508 | 566 |
|
@@ -531,6 +589,7 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev) |
531 | 589 |
|
532 | 590 | twl4030_charger_enable_ac(false); |
533 | 591 | twl4030_charger_enable_usb(bci, false); |
| 592 | + twl4030_charger_enable_backup(0, 0); |
534 | 593 |
|
535 | 594 | /* mask interrupts */ |
536 | 595 | twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff, |
|
0 commit comments