twl4030_charger: reduce usb charge current further
[pandora-kernel.git] / drivers / power / twl4030_charger.c
index 643727f..d8467d2 100644 (file)
 #define IRQ_CHECK_PERIOD       (3 * HZ)
 #define IRQ_CHECK_THRESHOLD    4
 
+/* By default, 80mA */
+static unsigned end_of_charge_current = 80000;
+module_param(end_of_charge_current, uint, 0);
+MODULE_PARM_DESC(end_of_charge_current,
+       "Stop charging when the charger current goes below this threshold");
+
 static bool allow_usb = 1;
 module_param(allow_usb, bool, 0644);
 MODULE_PARM_DESC(allow_usb, "Allow USB charge drawing default current");
@@ -700,6 +706,19 @@ static ssize_t store_charge_current(struct device *dev,
        if (ret)
                return -EINVAL;
 
+       /*
+        * Previously, this sysfs parameter used a different raw-register
+        * format. All legal values in this format fall numerically into the
+        * range [0, 1023]. Since in the new format, these encode values so
+        * low as to be meaningless, reject them here so that anybody trying
+        * to use the old format will have at least a chance of figuring out
+        * why it isn't working any more. Note that in both formats, the value
+        * 0 has the same meaning, so it is allowed where values in the range
+        * [1, 1023] are not.
+        */
+       if (new_current < 1024 && new_current != 0)
+               return -EINVAL;
+
        ret = update_charge_parameters(bci, new_current, -1);
        if (ret)
                return ret;
@@ -919,12 +938,23 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
        bci->irq_chg = platform_get_irq(pdev, 0);
        bci->irq_bci = platform_get_irq(pdev, 1);
        bci->ac_current = 1200000; /* ~1.2A */
-       bci->usb_current = 560000; /* ~560mA */
+       bci->usb_current = 530000; /* ~530mA */
 
-       if ((ret = twl4030bci_get_charging_current(bci, &bci->charge_current)))
-               goto fail_read_charge_params;
-       if ((ret = twl4030bci_get_eoc_current(bci, &bci->eoc_current)))
-               goto fail_read_charge_params;
+       /*
+        * Make sure to set sane charging settings
+        *
+        * charge_current:
+        * ~500mA (doesn't really get used, overridden by ac_current or
+        * usb_current as soon as a charger is plugged in).
+        *
+        * end_of_charge_current:
+        * defaults to ~400mA (can be set with the eoc_current option)
+        * This is as high as it can be set in the TWL4030. Seems to be a
+        * fairly sane value. Certainly more sane then the default 80mA.
+        */
+       if ((ret = update_charge_parameters(bci,
+                       500000, end_of_charge_current)))
+               goto fail_set_charge_params;
 
        bci->irq_had_charger = -1;
        bci->irq_check_count_time = jiffies;
@@ -1056,7 +1086,7 @@ fail_register_ac:
        led_trigger_unregister_simple(bci->charging_any_trig);
        platform_set_drvdata(pdev, NULL);
 
-fail_read_charge_params:
+fail_set_charge_params:
        kfree(bci);
 
        return ret;