aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Green <andy@openmoko.com>2009-02-05 17:01:56 +0000
committerAndy Green <agreen@octopus.localdomain>2009-02-05 17:01:56 +0000
commit9029dff1f370018665a6e2999632a34fd0518f4d (patch)
treec22b98c93bdbcc3b1477318f3d70e8f7bbdf22d4
parent8886032fd8cc0120b0d95a57137cc9b884325b3c (diff)
fix-pcf50633-set-charging-limit-with-usb-limit.patch
Cedric noticed that when he turned his GTA02 OFF while hooked to a "dumb" USB charger that should only be asked for 100mA, suddenly much more current was demanded. When PMU enters PMU standmy when we go OFF, its USB current limit is reset to the variant default of 500mA. Since we previously had the charging current limit fixed at 1A, it meant we immediately charge at 500mA. This patch makes the charging limit follow the USB current limit, so that even when we go off, no more than the last authorized amount of current will be taken, even if the USB current limit is later broken by the variant default. Reported-by: Cedric Berger <cedric.berger74@gmail.com> Signed-off-by: Andy Green <andy@openmoko.com>
-rw-r--r--drivers/power/pcf50633-charger.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/drivers/power/pcf50633-charger.c b/drivers/power/pcf50633-charger.c
index 874caf6033f..d20a7178329 100644
--- a/drivers/power/pcf50633-charger.c
+++ b/drivers/power/pcf50633-charger.c
@@ -48,16 +48,21 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
u8 bits;
int charging_start = 1;
u8 mbcs2, chgmod;
+ u8 mbcc5;
- if (ma >= 1000)
+ if (ma >= 1000) {
bits = PCF50633_MBCC7_USB_1000mA;
- else if (ma >= 500)
+ ma = 1000;
+ } else if (ma >= 500) {
bits = PCF50633_MBCC7_USB_500mA;
- else if (ma >= 100)
+ ma = 500;
+ } else if (ma >= 100) {
bits = PCF50633_MBCC7_USB_100mA;
- else {
+ ma = 100;
+ } else {
bits = PCF50633_MBCC7_USB_SUSPEND;
charging_start = 0;
+ ma = 0;
}
ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_MBCC7,
@@ -67,6 +72,20 @@ int pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
else
dev_info(pcf->dev, "usb curlim to %d mA\n", ma);
+ /*
+ * We limit the charging current to be the USB current limit.
+ * The reason is that on pcf50633, when it enters PMU Standby mode,
+ * which it does when the device goes "off", the USB current limit
+ * reverts to the variant default. It at least one common case, that
+ * default is 500mA. By setting the charging current to be the same
+ * as the USB limit we set here before PMU standby, we enforce it only
+ * using the correct amount of current even when the USB current limit
+ * gets reset to the wrong thing
+ */
+
+ mbcc5 = (ma << 8) / mbc->pcf->pdata->chg_ref_current_ma;
+ pcf50633_reg_write(mbc->pcf, PCF50633_REG_MBCC5, mbcc5);
+
mbcs2 = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
chgmod = (mbcs2 & PCF50633_MBCS2_MBC_MASK);