Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 320490
b: refs/heads/master
c: 210d4bc
h: refs/heads/master
v: v3
  • Loading branch information
NeilBrown authored and Anton Vorontsov committed Jun 20, 2012
1 parent 1c0dccf commit 82c1b31
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9c645d2f887bd92df487b2c5dcd44d5fc0e7c761
refs/heads/master: 210d4bc8a3128e3e61ac3bf4657114f8e6450e2a
59 changes: 59 additions & 0 deletions trunk/drivers/power/twl4030_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define TWL4030_BCIVBUS 0x0c
#define TWL4030_BCIMFSTS4 0x10
#define TWL4030_BCICTL1 0x23
#define TWL4030_BB_CFG 0x12

#define TWL4030_BCIAUTOWEN BIT(5)
#define TWL4030_CONFIG_DONE BIT(4)
Expand All @@ -37,6 +38,17 @@
#define TWL4030_USBFASTMCHG BIT(2)
#define TWL4030_STS_VBUS BIT(7)
#define TWL4030_STS_USB_ID BIT(2)
#define TWL4030_BBCHEN BIT(4)
#define TWL4030_BBSEL_MASK 0b1100
#define TWL4030_BBSEL_2V5 0b0000
#define TWL4030_BBSEL_3V0 0b0100
#define TWL4030_BBSEL_3V1 0b1000
#define TWL4030_BBSEL_3V2 0b1100
#define TWL4030_BBISEL_MASK 0b11
#define TWL4030_BBISEL_25uA 0b00
#define TWL4030_BBISEL_150uA 0b01
#define TWL4030_BBISEL_500uA 0b10
#define TWL4030_BBISEL_1000uA 0b11

/* BCI interrupts */
#define TWL4030_WOVF BIT(0) /* Watchdog overflow */
Expand Down Expand Up @@ -201,6 +213,49 @@ static int twl4030_charger_enable_ac(bool enable)
return ret;
}

/*
* Enable/Disable charging of Backup Battery.
*/
static int twl4030_charger_enable_backup(int uvolt, int uamp)
{
int ret;
u8 flags;

if (uvolt < 2500000 ||
uamp < 25) {
/* disable charging of backup battery */
ret = twl4030_clear_set(TWL4030_MODULE_PM_RECEIVER,
TWL4030_BBCHEN, 0, TWL4030_BB_CFG);
return ret;
}

flags = TWL4030_BBCHEN;
if (uvolt >= 3200000)
flags |= TWL4030_BBSEL_3V2;
else if (uvolt >= 3100000)
flags |= TWL4030_BBSEL_3V1;
else if (uvolt >= 3000000)
flags |= TWL4030_BBSEL_3V0;
else
flags |= TWL4030_BBSEL_2V5;

if (uamp >= 1000)
flags |= TWL4030_BBISEL_1000uA;
else if (uamp >= 500)
flags |= TWL4030_BBISEL_500uA;
else if (uamp >= 150)
flags |= TWL4030_BBISEL_150uA;
else
flags |= TWL4030_BBISEL_25uA;

ret = twl4030_clear_set(TWL4030_MODULE_PM_RECEIVER,
TWL4030_BBSEL_MASK | TWL4030_BBISEL_MASK,
flags,
TWL4030_BB_CFG);

return ret;
}

/*
* TWL4030 CHG_PRES (AC charger presence) events
*/
Expand Down Expand Up @@ -424,6 +479,7 @@ static enum power_supply_property twl4030_charger_props[] = {
static int __init twl4030_bci_probe(struct platform_device *pdev)
{
struct twl4030_bci *bci;
struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
int ret;
u32 reg;

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

twl4030_charger_enable_ac(true);
twl4030_charger_enable_usb(bci, true);
twl4030_charger_enable_backup(pdata->bb_uvolt,
pdata->bb_uamp);

return 0;

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

twl4030_charger_enable_ac(false);
twl4030_charger_enable_usb(bci, false);
twl4030_charger_enable_backup(0, 0);

/* mask interrupts */
twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff,
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/linux/i2c/twl.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ struct twl4030_clock_init_data {
struct twl4030_bci_platform_data {
int *battery_tmp_tbl;
unsigned int tblsize;
int bb_uvolt; /* voltage to charge backup battery */
int bb_uamp; /* current for backup battery charging */
};

/* TWL4030_GPIO_MAX (18) GPIOs, with interrupts */
Expand Down

0 comments on commit 82c1b31

Please sign in to comment.