power: supply: sc2731_charger: Add charger status detection
authorBaolin Wang <baolin.wang@linaro.org>
Mon, 12 Nov 2018 10:52:36 +0000 (18:52 +0800)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Wed, 5 Dec 2018 22:51:58 +0000 (23:51 +0100)
The USB charger status can be notified before the charger driver registers
the USB phy notifier, so we should check the charger status in probe() in
case we missed the USB charger notification.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/sc2731_charger.c

index 393ba9883c4abd2fb18e94465535a68b823d6ce0..a012d6c94bc31295b2c710f7cbccb9e4064ae5f1 100644 (file)
@@ -432,6 +432,24 @@ error:
        return ret;
 }
 
+static void sc2731_charger_detect_status(struct sc2731_charger_info *info)
+{
+       unsigned int min, max;
+
+       /*
+        * If the USB charger status has been USB_CHARGER_PRESENT before
+        * registering the notifier, we should start to charge with getting
+        * the charge current.
+        */
+       if (info->usb_phy->chg_state != USB_CHARGER_PRESENT)
+               return;
+
+       usb_phy_get_charger_current(info->usb_phy, &min, &max);
+       info->limit = min;
+
+       schedule_work(&info->work);
+}
+
 static int sc2731_charger_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
@@ -486,6 +504,8 @@ static int sc2731_charger_probe(struct platform_device *pdev)
                return ret;
        }
 
+       sc2731_charger_detect_status(info);
+
        return 0;
 }