Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1544241

[PATCH 11/14] power: supply: axp288_charger: Get and process initial hardware-state

From Hans de Goede <hdegoede@redhat.com>
Newsgroups linux.kernel
Subject [PATCH 11/14] power: supply: axp288_charger: Get and process initial hardware-state
Date 2016-12-19 01:10 +0100
Message-ID <sPTGG-pT-41@gated-at.bofh.it> (permalink)
References <sPTGF-pT-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Do not wait for an extcon notification before processing the cable
states, instead queue the otg / cable work on probe to make sure we
immediately process the initial hardware state.

Note this also requiree moving the getting of the USB_HOST cable state
from the extcon notifier to the workqueue function.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/power/supply/axp288_charger.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/power/supply/axp288_charger.c b/drivers/power/supply/axp288_charger.c
index f033a5e..b489289 100644
--- a/drivers/power/supply/axp288_charger.c
+++ b/drivers/power/supply/axp288_charger.c
@@ -171,7 +171,7 @@ struct axp288_chrg_info {
 	int cv;
 	int max_cc;
 	int max_cv;
-	bool is_charger_enabled;
+	int is_charger_enabled;
 };
 
 static inline int axp288_charger_set_cc(struct axp288_chrg_info *info, int cc)
@@ -300,7 +300,7 @@ static int axp288_charger_enable_charger(struct axp288_chrg_info *info,
 {
 	int ret;
 
-	if (enable == info->is_charger_enabled)
+	if ((int)enable == info->is_charger_enabled)
 		return 0;
 
 	if (enable)
@@ -653,7 +653,17 @@ static void axp288_charger_otg_evt_worker(struct work_struct *work)
 {
 	struct axp288_chrg_info *info =
 	    container_of(work, struct axp288_chrg_info, otg.work);
-	int ret;
+	struct extcon_dev *edev = info->otg.cable;
+	int ret, usb_host = extcon_get_cable_state_(edev, EXTCON_USB_HOST);
+
+	dev_dbg(&info->pdev->dev, "external connector USB-Host is %s\n",
+				usb_host ? "attached" : "detached");
+
+	/*
+	 * Set usb_id_short flag to avoid running charger detection logic
+	 * in case usb host.
+	 */
+	info->otg.id_short = usb_host;
 
 	/* Disable VBUS path before enabling the 5V boost */
 	ret = axp288_charger_vbus_path_select(info, !info->otg.id_short);
@@ -666,17 +676,7 @@ static int axp288_charger_handle_otg_evt(struct notifier_block *nb,
 {
 	struct axp288_chrg_info *info =
 	    container_of(nb, struct axp288_chrg_info, otg.id_nb);
-	struct extcon_dev *edev = info->otg.cable;
-	int usb_host = extcon_get_cable_state_(edev, EXTCON_USB_HOST);
-
-	dev_dbg(&info->pdev->dev, "external connector USB-Host is %s\n",
-				usb_host ? "attached" : "detached");
 
-	/*
-	 * Set usb_id_short flag to avoid running charger detection logic
-	 * in case usb host.
-	 */
-	info->otg.id_short = usb_host;
 	schedule_work(&info->otg.work);
 
 	return NOTIFY_OK;
@@ -807,6 +807,8 @@ static int axp288_charger_probe(struct platform_device *pdev)
 	info->pdev = pdev;
 	info->regmap = axp20x->regmap;
 	info->regmap_irqc = axp20x->regmap_irqc;
+	info->cable.chg_type = -1;
+	info->is_charger_enabled = -1;
 
 	info->cable.edev = extcon_get_extcon_dev(AXP288_EXTCON_DEV_NAME);
 	if (info->cable.edev == NULL) {
@@ -849,6 +851,7 @@ static int axp288_charger_probe(struct platform_device *pdev)
 			return ret;
 		}
 	}
+	schedule_work(&info->cable.work);
 
 	/* Register for OTG notification */
 	INIT_WORK(&info->otg.work, axp288_charger_otg_evt_worker);
@@ -859,8 +862,7 @@ static int axp288_charger_probe(struct platform_device *pdev)
 		dev_err(dev, "failed to register EXTCON_USB_HOST notifier\n");
 		return ret;
 	}
-	info->otg.id_short = extcon_get_cable_state_(info->otg.cable,
-						     EXTCON_USB_HOST);
+	schedule_work(&info->otg.work);
 
 	/* Register charger interrupts */
 	for (i = 0; i < CHRG_INTR_END; i++) {
-- 
2.9.3

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/14] extcon api extension + axp288_charger fixes Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
  [PATCH 12/14] power: supply: axp288_charger: Fix wrong regmap_update_bits Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
  [PATCH 13/14] power: supply: axp288_charger: Remove unnecessary irq?_en register writes Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
  [PATCH 08/14] power: supply: axp288_charger: Actually get and use the USB_HOST extcon device Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
    Re: [PATCH 08/14] power: supply: axp288_charger: Actually get and use  the USB_HOST extcon device Chanwoo Choi <cw00.choi@samsung.com> - 2016-12-19 11:20 +0100
  [PATCH 14/14] power: supply: axp288_charger: Fix the module not auto-loading Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
  [PATCH 09/14] power: supply: axp288_charger: Handle charger type changing without disconnect Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
  [PATCH 11/14] power: supply: axp288_charger: Get and process initial hardware-state Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
  [PATCH 01/14] extcon: Add extcon_get_extcon_dev_by_cable_id function Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
    Re: [PATCH 01/14] extcon: Add extcon_get_extcon_dev_by_cable_id  function Chanwoo Choi <cw00.choi@samsung.com> - 2016-12-19 11:20 +0100
      Re: [PATCH 01/14] extcon: Add extcon_get_extcon_dev_by_cable_id  function Hans de Goede <hdegoede@redhat.com> - 2016-12-19 12:50 +0100
        Re: [PATCH 01/14] extcon: Add extcon_get_extcon_dev_by_cable_id  function Chanwoo Choi <cw00.choi@samsung.com> - 2016-12-19 13:00 +0100
  [PATCH 07/14] power: supply: axp288_charger: Move init_hw_regs call before supply registration Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
  [PATCH 03/14] power: supply: axp288_charger: Make charger_init_hw_regs propagate i2c errors Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
  [PATCH 05/14] power: supply: axp288_charger: use devm extcon / supply register Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:10 +0100
    Re: [PATCH 05/14] power: supply: axp288_charger: use devm extcon /  supply register Chanwoo Choi <cw00.choi@samsung.com> - 2016-12-19 09:10 +0100
      Re: [PATCH 05/14] power: supply: axp288_charger: use devm extcon /  supply register Hans de Goede <hdegoede@redhat.com> - 2016-12-19 09:50 +0100
  [PATCH 04/14] power: supply: axp288_charger: Drop platform_data dependency Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:20 +0100
  [PATCH 06/14] power: supply: axp288_charger: Register extcon notifers after power_supply Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:20 +0100
  [PATCH 02/14] extcon: Make extcon_register_notifier use extcon_get_extcon_dev_by_cable_id Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:20 +0100

csiph-web