aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/power/pcf50633-charger.c88
-rw-r--r--drivers/power/pda_power.c89
2 files changed, 148 insertions, 29 deletions
diff --git a/drivers/power/pcf50633-charger.c b/drivers/power/pcf50633-charger.c
index 41aec2acbb91..e8b278f71781 100644
--- a/drivers/power/pcf50633-charger.c
+++ b/drivers/power/pcf50633-charger.c
@@ -36,6 +36,8 @@ struct pcf50633_mbc {
36 36
37 struct power_supply usb; 37 struct power_supply usb;
38 struct power_supply adapter; 38 struct power_supply adapter;
39
40 struct delayed_work charging_restart_work;
39}; 41};
40 42
41int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma) 43int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
@@ -43,6 +45,8 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
43 struct pcf50633_mbc *mbc = platform_get_drvdata(pcf->mbc_pdev); 45 struct pcf50633_mbc *mbc = platform_get_drvdata(pcf->mbc_pdev);
44 int ret = 0; 46 int ret = 0;
45 u8 bits; 47 u8 bits;
48 int charging_start = 1;
49 u8 mbcs2, chgmod;
46 50
47 if (ma >= 1000) 51 if (ma >= 1000)
48 bits = PCF50633_MBCC7_USB_1000mA; 52 bits = PCF50633_MBCC7_USB_1000mA;
@@ -50,8 +54,10 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
50 bits = PCF50633_MBCC7_USB_500mA; 54 bits = PCF50633_MBCC7_USB_500mA;
51 else if (ma >= 100) 55 else if (ma >= 100)
52 bits = PCF50633_MBCC7_USB_100mA; 56 bits = PCF50633_MBCC7_USB_100mA;
53 else 57 else {
54 bits = PCF50633_MBCC7_USB_SUSPEND; 58 bits = PCF50633_MBCC7_USB_SUSPEND;
59 charging_start = 0;
60 }
55 61
56 ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_MBCC7, 62 ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_MBCC7,
57 PCF50633_MBCC7_USB_MASK, bits); 63 PCF50633_MBCC7_USB_MASK, bits);
@@ -60,6 +66,22 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
60 else 66 else
61 dev_info(pcf->dev, "usb curlim to %d mA\n", ma); 67 dev_info(pcf->dev, "usb curlim to %d mA\n", ma);
62 68
69 /* Manual charging start */
70 mbcs2 = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
71 chgmod = (mbcs2 & PCF50633_MBCS2_MBC_MASK);
72
73 /* If chgmod == BATFULL, setting chgena has no effect.
74 * We need to set resume instead.
75 */
76 if (chgmod != PCF50633_MBCS2_MBC_BAT_FULL)
77 pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_MBCC1,
78 PCF50633_MBCC1_CHGENA, PCF50633_MBCC1_CHGENA);
79 else
80 pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_MBCC1,
81 PCF50633_MBCC1_RESUME, PCF50633_MBCC1_RESUME);
82
83 mbc->usb_active = charging_start;
84
63 power_supply_changed(&mbc->usb); 85 power_supply_changed(&mbc->usb);
64 86
65 return ret; 87 return ret;
@@ -84,21 +106,6 @@ int pcf50633_mbc_get_status(struct pcf50633 *pcf)
84} 106}
85EXPORT_SYMBOL_GPL(pcf50633_mbc_get_status); 107EXPORT_SYMBOL_GPL(pcf50633_mbc_get_status);
86 108
87void pcf50633_mbc_set_status(struct pcf50633 *pcf, int what, int status)
88{
89 struct pcf50633_mbc *mbc = platform_get_drvdata(pcf->mbc_pdev);
90
91 if (what & PCF50633_MBC_USB_ONLINE)
92 mbc->usb_online = !!status;
93 if (what & PCF50633_MBC_USB_ACTIVE)
94 mbc->usb_active = !!status;
95 if (what & PCF50633_MBC_ADAPTER_ONLINE)
96 mbc->adapter_online = !!status;
97 if (what & PCF50633_MBC_ADAPTER_ACTIVE)
98 mbc->adapter_active = !!status;
99}
100EXPORT_SYMBOL_GPL(pcf50633_mbc_set_status);
101
102static ssize_t 109static ssize_t
103show_chgmode(struct device *dev, struct device_attribute *attr, char *buf) 110show_chgmode(struct device *dev, struct device_attribute *attr, char *buf)
104{ 111{
@@ -160,10 +167,44 @@ static struct attribute_group mbc_attr_group = {
160 .attrs = pcf50633_mbc_sysfs_entries, 167 .attrs = pcf50633_mbc_sysfs_entries,
161}; 168};
162 169
170/* MBC state machine switches into charging mode when the battery voltage
171 * falls below 96% of a battery float voltage. But the voltage drop in Li-ion
172 * batteries is marginal(1~2 %) till about 80% of its capacity - which means,
173 * after a BATFULL, charging won't be restarted until 80%.
174 *
175 * This work_struct function restarts charging at regular intervals to make
176 * sure we don't discharge too much
177 */
178
179static void pcf50633_mbc_charging_restart(struct work_struct *work)
180{
181 struct pcf50633_mbc *mbc;
182 u8 mbcs2, chgmod;
183
184 mbc = container_of(work, struct pcf50633_mbc,
185 charging_restart_work.work);
186
187 mbcs2 = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCS2);
188 chgmod = (mbcs2 & PCF50633_MBCS2_MBC_MASK);
189
190 if (chgmod != PCF50633_MBCS2_MBC_BAT_FULL)
191 return;
192
193 /* Restart charging */
194 pcf50633_reg_set_bit_mask(mbc->pcf, PCF50633_REG_MBCC1,
195 PCF50633_MBCC1_RESUME, PCF50633_MBCC1_RESUME);
196 mbc->usb_active = 1;
197 power_supply_changed(&mbc->usb);
198
199 dev_info(mbc->pcf->dev, "Charging restarted\n");
200}
201
163static void 202static void
164pcf50633_mbc_irq_handler(int irq, void *data) 203pcf50633_mbc_irq_handler(int irq, void *data)
165{ 204{
166 struct pcf50633_mbc *mbc = data; 205 struct pcf50633_mbc *mbc = data;
206 int chg_restart_interval =
207 mbc->pcf->pdata->charging_restart_interval;
167 208
168 /* USB */ 209 /* USB */
169 if (irq == PCF50633_IRQ_USBINS) { 210 if (irq == PCF50633_IRQ_USBINS) {
@@ -172,6 +213,7 @@ pcf50633_mbc_irq_handler(int irq, void *data)
172 mbc->usb_online = 0; 213 mbc->usb_online = 0;
173 mbc->usb_active = 0; 214 mbc->usb_active = 0;
174 pcf50633_mbc_usb_curlim_set(mbc->pcf, 0); 215 pcf50633_mbc_usb_curlim_set(mbc->pcf, 0);
216 cancel_delayed_work_sync(&mbc->charging_restart_work);
175 } 217 }
176 218
177 /* Adapter */ 219 /* Adapter */
@@ -186,7 +228,14 @@ pcf50633_mbc_irq_handler(int irq, void *data)
186 if (irq == PCF50633_IRQ_BATFULL) { 228 if (irq == PCF50633_IRQ_BATFULL) {
187 mbc->usb_active = 0; 229 mbc->usb_active = 0;
188 mbc->adapter_active = 0; 230 mbc->adapter_active = 0;
189 } 231
232 if (chg_restart_interval > 0)
233 schedule_delayed_work(&mbc->charging_restart_work,
234 chg_restart_interval);
235 } else if (irq == PCF50633_IRQ_USBLIMON)
236 mbc->usb_active = 0;
237 else if (irq == PCF50633_IRQ_USBLIMOFF)
238 mbc->usb_active = 1;
190 239
191 power_supply_changed(&mbc->usb); 240 power_supply_changed(&mbc->usb);
192 power_supply_changed(&mbc->adapter); 241 power_supply_changed(&mbc->adapter);
@@ -303,6 +352,9 @@ static int __devinit pcf50633_mbc_probe(struct platform_device *pdev)
303 return ret; 352 return ret;
304 } 353 }
305 354
355 INIT_DELAYED_WORK(&mbc->charging_restart_work,
356 pcf50633_mbc_charging_restart);
357
306 ret = sysfs_create_group(&pdev->dev.kobj, &mbc_attr_group); 358 ret = sysfs_create_group(&pdev->dev.kobj, &mbc_attr_group);
307 if (ret) 359 if (ret)
308 dev_err(mbc->pcf->dev, "failed to create sysfs entries\n"); 360 dev_err(mbc->pcf->dev, "failed to create sysfs entries\n");
@@ -328,6 +380,8 @@ static int __devexit pcf50633_mbc_remove(struct platform_device *pdev)
328 power_supply_unregister(&mbc->usb); 380 power_supply_unregister(&mbc->usb);
329 power_supply_unregister(&mbc->adapter); 381 power_supply_unregister(&mbc->adapter);
330 382
383 cancel_delayed_work_sync(&mbc->charging_restart_work);
384
331 kfree(mbc); 385 kfree(mbc);
332 386
333 return 0; 387 return 0;
diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index b56a704409d2..a232de6a5703 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -12,11 +12,14 @@
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/err.h>
15#include <linux/interrupt.h> 16#include <linux/interrupt.h>
16#include <linux/power_supply.h> 17#include <linux/power_supply.h>
17#include <linux/pda_power.h> 18#include <linux/pda_power.h>
19#include <linux/regulator/consumer.h>
18#include <linux/timer.h> 20#include <linux/timer.h>
19#include <linux/jiffies.h> 21#include <linux/jiffies.h>
22#include <linux/usb/otg.h>
20 23
21static inline unsigned int get_irq_flags(struct resource *res) 24static inline unsigned int get_irq_flags(struct resource *res)
22{ 25{
@@ -35,6 +38,11 @@ static struct timer_list supply_timer;
35static struct timer_list polling_timer; 38static struct timer_list polling_timer;
36static int polling; 39static int polling;
37 40
41#ifdef CONFIG_USB_OTG_UTILS
42static struct otg_transceiver *transceiver;
43#endif
44static struct regulator *ac_draw;
45
38enum { 46enum {
39 PDA_PSY_OFFLINE = 0, 47 PDA_PSY_OFFLINE = 0,
40 PDA_PSY_ONLINE = 1, 48 PDA_PSY_ONLINE = 1,
@@ -104,18 +112,35 @@ static void update_status(void)
104 112
105static void update_charger(void) 113static void update_charger(void)
106{ 114{
107 if (!pdata->set_charge) 115 static int regulator_enabled;
108 return; 116 int max_uA = pdata->ac_max_uA;
109 117
110 if (new_ac_status > 0) { 118 if (pdata->set_charge) {
111 dev_dbg(dev, "charger on (AC)\n"); 119 if (new_ac_status > 0) {
112 pdata->set_charge(PDA_POWER_CHARGE_AC); 120 dev_dbg(dev, "charger on (AC)\n");
113 } else if (new_usb_status > 0) { 121 pdata->set_charge(PDA_POWER_CHARGE_AC);
114 dev_dbg(dev, "charger on (USB)\n"); 122 } else if (new_usb_status > 0) {
115 pdata->set_charge(PDA_POWER_CHARGE_USB); 123 dev_dbg(dev, "charger on (USB)\n");
116 } else { 124 pdata->set_charge(PDA_POWER_CHARGE_USB);
117 dev_dbg(dev, "charger off\n"); 125 } else {
118 pdata->set_charge(0); 126 dev_dbg(dev, "charger off\n");
127 pdata->set_charge(0);
128 }
129 } else if (ac_draw) {
130 if (new_ac_status > 0) {
131 regulator_set_current_limit(ac_draw, max_uA, max_uA);
132 if (!regulator_enabled) {
133 dev_dbg(dev, "charger on (AC)\n");
134 regulator_enable(ac_draw);
135 regulator_enabled = 1;
136 }
137 } else {
138 if (regulator_enabled) {
139 dev_dbg(dev, "charger off\n");
140 regulator_disable(ac_draw);
141 regulator_enabled = 0;
142 }
143 }
119 } 144 }
120} 145}
121 146
@@ -194,6 +219,13 @@ static void polling_timer_func(unsigned long unused)
194 jiffies + msecs_to_jiffies(pdata->polling_interval)); 219 jiffies + msecs_to_jiffies(pdata->polling_interval));
195} 220}
196 221
222#ifdef CONFIG_USB_OTG_UTILS
223static int otg_is_usb_online(void)
224{
225 return (transceiver->state == OTG_STATE_B_PERIPHERAL);
226}
227#endif
228
197static int pda_power_probe(struct platform_device *pdev) 229static int pda_power_probe(struct platform_device *pdev)
198{ 230{
199 int ret = 0; 231 int ret = 0;
@@ -227,6 +259,9 @@ static int pda_power_probe(struct platform_device *pdev)
227 if (!pdata->polling_interval) 259 if (!pdata->polling_interval)
228 pdata->polling_interval = 2000; 260 pdata->polling_interval = 2000;
229 261
262 if (!pdata->ac_max_uA)
263 pdata->ac_max_uA = 500000;
264
230 setup_timer(&charger_timer, charger_timer_func, 0); 265 setup_timer(&charger_timer, charger_timer_func, 0);
231 setup_timer(&supply_timer, supply_timer_func, 0); 266 setup_timer(&supply_timer, supply_timer_func, 0);
232 267
@@ -240,6 +275,13 @@ static int pda_power_probe(struct platform_device *pdev)
240 pda_psy_usb.num_supplicants = pdata->num_supplicants; 275 pda_psy_usb.num_supplicants = pdata->num_supplicants;
241 } 276 }
242 277
278 ac_draw = regulator_get(dev, "ac_draw");
279 if (IS_ERR(ac_draw)) {
280 dev_dbg(dev, "couldn't get ac_draw regulator\n");
281 ac_draw = NULL;
282 ret = PTR_ERR(ac_draw);
283 }
284
243 if (pdata->is_ac_online) { 285 if (pdata->is_ac_online) {
244 ret = power_supply_register(&pdev->dev, &pda_psy_ac); 286 ret = power_supply_register(&pdev->dev, &pda_psy_ac);
245 if (ret) { 287 if (ret) {
@@ -261,6 +303,13 @@ static int pda_power_probe(struct platform_device *pdev)
261 } 303 }
262 } 304 }
263 305
306#ifdef CONFIG_USB_OTG_UTILS
307 transceiver = otg_get_transceiver();
308 if (transceiver && !pdata->is_usb_online) {
309 pdata->is_usb_online = otg_is_usb_online;
310 }
311#endif
312
264 if (pdata->is_usb_online) { 313 if (pdata->is_usb_online) {
265 ret = power_supply_register(&pdev->dev, &pda_psy_usb); 314 ret = power_supply_register(&pdev->dev, &pda_psy_usb);
266 if (ret) { 315 if (ret) {
@@ -300,10 +349,18 @@ usb_irq_failed:
300usb_supply_failed: 349usb_supply_failed:
301 if (pdata->is_ac_online && ac_irq) 350 if (pdata->is_ac_online && ac_irq)
302 free_irq(ac_irq->start, &pda_psy_ac); 351 free_irq(ac_irq->start, &pda_psy_ac);
352#ifdef CONFIG_USB_OTG_UTILS
353 if (transceiver)
354 otg_put_transceiver(transceiver);
355#endif
303ac_irq_failed: 356ac_irq_failed:
304 if (pdata->is_ac_online) 357 if (pdata->is_ac_online)
305 power_supply_unregister(&pda_psy_ac); 358 power_supply_unregister(&pda_psy_ac);
306ac_supply_failed: 359ac_supply_failed:
360 if (ac_draw) {
361 regulator_put(ac_draw);
362 ac_draw = NULL;
363 }
307 if (pdata->exit) 364 if (pdata->exit)
308 pdata->exit(dev); 365 pdata->exit(dev);
309init_failed: 366init_failed:
@@ -327,6 +384,14 @@ static int pda_power_remove(struct platform_device *pdev)
327 power_supply_unregister(&pda_psy_usb); 384 power_supply_unregister(&pda_psy_usb);
328 if (pdata->is_ac_online) 385 if (pdata->is_ac_online)
329 power_supply_unregister(&pda_psy_ac); 386 power_supply_unregister(&pda_psy_ac);
387#ifdef CONFIG_USB_OTG_UTILS
388 if (transceiver)
389 otg_put_transceiver(transceiver);
390#endif
391 if (ac_draw) {
392 regulator_put(ac_draw);
393 ac_draw = NULL;
394 }
330 if (pdata->exit) 395 if (pdata->exit)
331 pdata->exit(dev); 396 pdata->exit(dev);
332 397