aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/twl4030_charger.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-07-31 21:08:25 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-31 21:08:25 -0400
commit4b24ff71108164e047cf2c95990b77651163e315 (patch)
tree4b478906379adf22ff259fc1f2cce0da796df415 /drivers/power/twl4030_charger.c
parentbca1a5c0eabe0f17081760c61e8d08e73dd6b6a6 (diff)
parent4b1bf5871f7d59de6484cc887e205d6d2f1e6fbd (diff)
Merge tag 'for-v3.6' of git://git.infradead.org/battery-2.6
Pull battery updates from Anton Vorontsov: "The tag contains just a few battery-related changes for v3.6. It's is all pretty straightforward, except one thing. One of our patches added thermal support for power supply class, but thermal/ subsystem changed under our feet. We (well, Stephen, that is) caught the issue and it was decided[1] that I'd just delay the battery pull request, and then will fix it up by merging upstream back into battery tree at the specific commit. That's not all though: another[2] small fixup for thermal subsystem was needed to get rid of a warning in power supply subsystem (the warning was not drivers/power's "fault", the thermal registration function just needed a proper const annotation, which is also done by a small commit on top of the merge. So, to sum this up: - The 'master' branch of the battery tree was in the -next tree for weeks, was never rebased, altered etc. It should be all OK; - Although, for-v3.6 tag contains the 'master' branch + merge + the warning fix. [1] http://lkml.org/lkml/2012/6/19/23 [2] http://lkml.org/lkml/2012/6/18/28" * tag 'for-v3.6' of git://git.infradead.org/battery-2.6: (23 commits) thermal: Constify 'type' argument for the registration routine olpc-battery: update CHARGE_FULL_DESIGN property for BYD LiFe batteries olpc-battery: Add VOLTAGE_MAX_DESIGN property charger-manager: Fix build break related to EXTCON lp8727_charger: Move header file into platform_data directory power_supply: Add min/max alert properties for CAPACITY, TEMP, TEMP_AMBIENT bq27x00_battery: Add support for BQ27425 chip charger-manager: Set current limit of regulator for over current protection charger-manager: Use EXTCON Subsystem to detect charger cables for charging test_power: Add VOLTAGE_NOW and BATTERY_TEMP properties test_power: Add support for USB AC source gpio-charger: Use cansleep version of gpio_set_value bq27x00_battery: Add support for power average and health properties sbs-battery: Don't trigger false supply_changed event twl4030_charger: Allow charger to control the regulator that feeds it twl4030_charger: Add backup-battery charging twl4030_charger: Fix some typos max17042_battery: Support CHARGE_COUNTER power supply attribute smb347-charger: Add constant charge and current properties power_supply: Add constant charge_current and charge_voltage properties ...
Diffstat (limited to 'drivers/power/twl4030_charger.c')
-rw-r--r--drivers/power/twl4030_charger.c80
1 files changed, 77 insertions, 3 deletions
diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index 7cacbaa68efe..15f4d5d8611b 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -22,6 +22,7 @@
22#include <linux/power_supply.h> 22#include <linux/power_supply.h>
23#include <linux/notifier.h> 23#include <linux/notifier.h>
24#include <linux/usb/otg.h> 24#include <linux/usb/otg.h>
25#include <linux/regulator/machine.h>
25 26
26#define TWL4030_BCIMSTATEC 0x02 27#define TWL4030_BCIMSTATEC 0x02
27#define TWL4030_BCIICHG 0x08 28#define TWL4030_BCIICHG 0x08
@@ -29,6 +30,7 @@
29#define TWL4030_BCIVBUS 0x0c 30#define TWL4030_BCIVBUS 0x0c
30#define TWL4030_BCIMFSTS4 0x10 31#define TWL4030_BCIMFSTS4 0x10
31#define TWL4030_BCICTL1 0x23 32#define TWL4030_BCICTL1 0x23
33#define TWL4030_BB_CFG 0x12
32 34
33#define TWL4030_BCIAUTOWEN BIT(5) 35#define TWL4030_BCIAUTOWEN BIT(5)
34#define TWL4030_CONFIG_DONE BIT(4) 36#define TWL4030_CONFIG_DONE BIT(4)
@@ -38,6 +40,17 @@
38#define TWL4030_USBFASTMCHG BIT(2) 40#define TWL4030_USBFASTMCHG BIT(2)
39#define TWL4030_STS_VBUS BIT(7) 41#define TWL4030_STS_VBUS BIT(7)
40#define TWL4030_STS_USB_ID BIT(2) 42#define TWL4030_STS_USB_ID BIT(2)
43#define TWL4030_BBCHEN BIT(4)
44#define TWL4030_BBSEL_MASK 0b1100
45#define TWL4030_BBSEL_2V5 0b0000
46#define TWL4030_BBSEL_3V0 0b0100
47#define TWL4030_BBSEL_3V1 0b1000
48#define TWL4030_BBSEL_3V2 0b1100
49#define TWL4030_BBISEL_MASK 0b11
50#define TWL4030_BBISEL_25uA 0b00
51#define TWL4030_BBISEL_150uA 0b01
52#define TWL4030_BBISEL_500uA 0b10
53#define TWL4030_BBISEL_1000uA 0b11
41 54
42/* BCI interrupts */ 55/* BCI interrupts */
43#define TWL4030_WOVF BIT(0) /* Watchdog overflow */ 56#define TWL4030_WOVF BIT(0) /* Watchdog overflow */
@@ -75,6 +88,8 @@ struct twl4030_bci {
75 struct work_struct work; 88 struct work_struct work;
76 int irq_chg; 89 int irq_chg;
77 int irq_bci; 90 int irq_bci;
91 struct regulator *usb_reg;
92 int usb_enabled;
78 93
79 unsigned long event; 94 unsigned long event;
80}; 95};
@@ -104,7 +119,7 @@ static int twl4030_bci_read(u8 reg, u8 *val)
104 119
105static int twl4030_clear_set_boot_bci(u8 clear, u8 set) 120static int twl4030_clear_set_boot_bci(u8 clear, u8 set)
106{ 121{
107 return twl4030_clear_set(TWL4030_MODULE_PM_MASTER, 0, 122 return twl4030_clear_set(TWL4030_MODULE_PM_MASTER, clear,
108 TWL4030_CONFIG_DONE | TWL4030_BCIAUTOWEN | set, 123 TWL4030_CONFIG_DONE | TWL4030_BCIAUTOWEN | set,
109 TWL4030_PM_MASTER_BOOT_BCI); 124 TWL4030_PM_MASTER_BOOT_BCI);
110} 125}
@@ -152,14 +167,14 @@ static int twl4030_bci_have_vbus(struct twl4030_bci *bci)
152} 167}
153 168
154/* 169/*
155 * Enable/Disable USB Charge funtionality. 170 * Enable/Disable USB Charge functionality.
156 */ 171 */
157static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable) 172static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
158{ 173{
159 int ret; 174 int ret;
160 175
161 if (enable) { 176 if (enable) {
162 /* Check for USB charger conneted */ 177 /* Check for USB charger connected */
163 if (!twl4030_bci_have_vbus(bci)) 178 if (!twl4030_bci_have_vbus(bci))
164 return -ENODEV; 179 return -ENODEV;
165 180
@@ -172,6 +187,12 @@ static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
172 return -EACCES; 187 return -EACCES;
173 } 188 }
174 189
190 /* Need to keep regulator on */
191 if (!bci->usb_enabled) {
192 regulator_enable(bci->usb_reg);
193 bci->usb_enabled = 1;
194 }
195
175 /* forcing the field BCIAUTOUSB (BOOT_BCI[1]) to 1 */ 196 /* forcing the field BCIAUTOUSB (BOOT_BCI[1]) to 1 */
176 ret = twl4030_clear_set_boot_bci(0, TWL4030_BCIAUTOUSB); 197 ret = twl4030_clear_set_boot_bci(0, TWL4030_BCIAUTOUSB);
177 if (ret < 0) 198 if (ret < 0)
@@ -182,6 +203,10 @@ static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
182 TWL4030_USBFASTMCHG, TWL4030_BCIMFSTS4); 203 TWL4030_USBFASTMCHG, TWL4030_BCIMFSTS4);
183 } else { 204 } else {
184 ret = twl4030_clear_set_boot_bci(TWL4030_BCIAUTOUSB, 0); 205 ret = twl4030_clear_set_boot_bci(TWL4030_BCIAUTOUSB, 0);
206 if (bci->usb_enabled) {
207 regulator_disable(bci->usb_reg);
208 bci->usb_enabled = 0;
209 }
185 } 210 }
186 211
187 return ret; 212 return ret;
@@ -203,6 +228,49 @@ static int twl4030_charger_enable_ac(bool enable)
203} 228}
204 229
205/* 230/*
231 * Enable/Disable charging of Backup Battery.
232 */
233static int twl4030_charger_enable_backup(int uvolt, int uamp)
234{
235 int ret;
236 u8 flags;
237
238 if (uvolt < 2500000 ||
239 uamp < 25) {
240 /* disable charging of backup battery */
241 ret = twl4030_clear_set(TWL4030_MODULE_PM_RECEIVER,
242 TWL4030_BBCHEN, 0, TWL4030_BB_CFG);
243 return ret;
244 }
245
246 flags = TWL4030_BBCHEN;
247 if (uvolt >= 3200000)
248 flags |= TWL4030_BBSEL_3V2;
249 else if (uvolt >= 3100000)
250 flags |= TWL4030_BBSEL_3V1;
251 else if (uvolt >= 3000000)
252 flags |= TWL4030_BBSEL_3V0;
253 else
254 flags |= TWL4030_BBSEL_2V5;
255
256 if (uamp >= 1000)
257 flags |= TWL4030_BBISEL_1000uA;
258 else if (uamp >= 500)
259 flags |= TWL4030_BBISEL_500uA;
260 else if (uamp >= 150)
261 flags |= TWL4030_BBISEL_150uA;
262 else
263 flags |= TWL4030_BBISEL_25uA;
264
265 ret = twl4030_clear_set(TWL4030_MODULE_PM_RECEIVER,
266 TWL4030_BBSEL_MASK | TWL4030_BBISEL_MASK,
267 flags,
268 TWL4030_BB_CFG);
269
270 return ret;
271}
272
273/*
206 * TWL4030 CHG_PRES (AC charger presence) events 274 * TWL4030 CHG_PRES (AC charger presence) events
207 */ 275 */
208static irqreturn_t twl4030_charger_interrupt(int irq, void *arg) 276static irqreturn_t twl4030_charger_interrupt(int irq, void *arg)
@@ -425,6 +493,7 @@ static enum power_supply_property twl4030_charger_props[] = {
425static int __init twl4030_bci_probe(struct platform_device *pdev) 493static int __init twl4030_bci_probe(struct platform_device *pdev)
426{ 494{
427 struct twl4030_bci *bci; 495 struct twl4030_bci *bci;
496 struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
428 int ret; 497 int ret;
429 u32 reg; 498 u32 reg;
430 499
@@ -456,6 +525,8 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
456 bci->usb.num_properties = ARRAY_SIZE(twl4030_charger_props); 525 bci->usb.num_properties = ARRAY_SIZE(twl4030_charger_props);
457 bci->usb.get_property = twl4030_bci_get_property; 526 bci->usb.get_property = twl4030_bci_get_property;
458 527
528 bci->usb_reg = regulator_get(bci->dev, "bci3v1");
529
459 ret = power_supply_register(&pdev->dev, &bci->usb); 530 ret = power_supply_register(&pdev->dev, &bci->usb);
460 if (ret) { 531 if (ret) {
461 dev_err(&pdev->dev, "failed to register usb: %d\n", ret); 532 dev_err(&pdev->dev, "failed to register usb: %d\n", ret);
@@ -504,6 +575,8 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
504 575
505 twl4030_charger_enable_ac(true); 576 twl4030_charger_enable_ac(true);
506 twl4030_charger_enable_usb(bci, true); 577 twl4030_charger_enable_usb(bci, true);
578 twl4030_charger_enable_backup(pdata->bb_uvolt,
579 pdata->bb_uamp);
507 580
508 return 0; 581 return 0;
509 582
@@ -532,6 +605,7 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
532 605
533 twl4030_charger_enable_ac(false); 606 twl4030_charger_enable_ac(false);
534 twl4030_charger_enable_usb(bci, false); 607 twl4030_charger_enable_usb(bci, false);
608 twl4030_charger_enable_backup(0, 0);
535 609
536 /* mask interrupts */ 610 /* mask interrupts */
537 twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff, 611 twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff,