Skip to content

Commit 210d4bc

Browse files
neilbrownenomsg
authored andcommitted
twl4030_charger: Add backup-battery charging
This allows a voltage and current (bb_uvolts and bb_uamps) to be specified in the platform_data, and charging of the backup battery will be enabled with those specification. As it is not possible to monitor the backup battery at all there is no new device created to represent it. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
1 parent 9c645d2 commit 210d4bc

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎drivers/power/twl4030_charger.c‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define TWL4030_BCIVBUS 0x0c
2929
#define TWL4030_BCIMFSTS4 0x10
3030
#define TWL4030_BCICTL1 0x23
31+
#define TWL4030_BB_CFG 0x12
3132

3233
#define TWL4030_BCIAUTOWEN BIT(5)
3334
#define TWL4030_CONFIG_DONE BIT(4)
@@ -37,6 +38,17 @@
3738
#define TWL4030_USBFASTMCHG BIT(2)
3839
#define TWL4030_STS_VBUS BIT(7)
3940
#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
4052

4153
/* BCI interrupts */
4254
#define TWL4030_WOVF BIT(0) /* Watchdog overflow */
@@ -201,6 +213,49 @@ static int twl4030_charger_enable_ac(bool enable)
201213
return ret;
202214
}
203215

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+
204259
/*
205260
* TWL4030 CHG_PRES (AC charger presence) events
206261
*/
@@ -424,6 +479,7 @@ static enum power_supply_property twl4030_charger_props[] = {
424479
static int __init twl4030_bci_probe(struct platform_device *pdev)
425480
{
426481
struct twl4030_bci *bci;
482+
struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
427483
int ret;
428484
u32 reg;
429485

@@ -503,6 +559,8 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
503559

504560
twl4030_charger_enable_ac(true);
505561
twl4030_charger_enable_usb(bci, true);
562+
twl4030_charger_enable_backup(pdata->bb_uvolt,
563+
pdata->bb_uamp);
506564

507565
return 0;
508566

@@ -531,6 +589,7 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
531589

532590
twl4030_charger_enable_ac(false);
533591
twl4030_charger_enable_usb(bci, false);
592+
twl4030_charger_enable_backup(0, 0);
534593

535594
/* mask interrupts */
536595
twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff,

‎include/linux/i2c/twl.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ struct twl4030_clock_init_data {
555555
struct twl4030_bci_platform_data {
556556
int *battery_tmp_tbl;
557557
unsigned int tblsize;
558+
int bb_uvolt; /* voltage to charge backup battery */
559+
int bb_uamp; /* current for backup battery charging */
558560
};
559561

560562
/* TWL4030_GPIO_MAX (18) GPIOs, with interrupts */

0 commit comments

Comments
 (0)