twl4030_charger: Add option to set end-of-charge current
authorGrond <grond66@riseup.net>
Tue, 20 Dec 2016 18:59:59 +0000 (10:59 -0800)
committerGrazvydas Ignotas <notasas@gmail.com>
Wed, 21 Dec 2016 23:40:55 +0000 (01:40 +0200)
Previously, this was fetched from hardware at modprobe time.
However, this requires userspace to set it every time the module is
loaded. This commit hardcodes the default of 80mA, but allows the
user to change it, if so desired.

drivers/power/twl4030_charger.c

index 643727f..4cd0fcd 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");
@@ -921,10 +927,21 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
        bci->ac_current = 1200000; /* ~1.2A */
        bci->usb_current = 560000; /* ~560mA */
 
-       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 +1073,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;