Skip to contentSkip to conversation

extcon: intel-cht-wc: Disable external 5v boost converter on probe

PATCH In review Hans de Goede 2 participants 5 messages Apr 4, 2017 – Apr 5, 2017 External connector subsystem (extcon)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 extcon: intel-cht-wc: Disable external 5v boost converter on probe

Disable the 5v boost converter on probe in case it was left on by the BIOS, this fixes 2 problems:

1) This gets seen by the external battery charger as a valid Vbus supply and it then tries to feed Vsys from this creating a feedback loop which causes aprox. 300 mA extra battery drain (and unless we drive the external-charger-disable pin high it also tries to charge the battery causing even more feedback).
2) This gets seen by the pwrsrc block as a SDP USB Vbus supply

Since the external battery charger has its own 5v boost converter which does not have these issues, we simply turn the separate external 5v boost converter off and leave it off entirely.

---
Changes in v2:
-Use CHT_WC_VBUS_GPIO_CTLO and CHT_WC_VBUS_GPIO_CTLO_OUTPUT as name for
the register defines

---
 drivers/extcon/extcon-intel-cht-wc.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/extcon/extcon-intel-cht-wc.c +35 -0
index f1c43af..e22df5f 100644
@@ -64,6 +64,9 @@
 #define CHT_WC_PWRSRC_ID_GND		BIT(3)
 #define CHT_WC_PWRSRC_ID_FLOAT		BIT(4)
 
+#define CHT_WC_VBUS_GPIO_CTLO		0x6e2d
+#define CHT_WC_VBUS_GPIO_CTLO_OUTPUT	BIT(0)
+
 enum cht_wc_usb_id {
 	USB_ID_OTG,
 	USB_ID_GND,
@@ -170,6 +173,23 @@ static void cht_wc_extcon_set_phymux(struct cht_wc_extcon_data *ext, u8 state)
 		dev_err(ext->dev, "Error writing phyctrl: %d\n", ret);
 }
 
+static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext,
+				       bool enable)
+{
+	int ret, val;
+
+	val = enable ? CHT_WC_VBUS_GPIO_CTLO_OUTPUT : 0;
+
+	/*
+	 * The 5V boost converter is enabled through a gpio on the PMIC, since
+	 * there currently is no gpio driver we access the gpio reg directly.
+	 */
+	ret = regmap_update_bits(ext->regmap, CHT_WC_VBUS_GPIO_CTLO,
+				 CHT_WC_VBUS_GPIO_CTLO_OUTPUT, val);
+	if (ret)
+		dev_err(ext->dev, "Error writing Vbus GPIO CTLO: %d\n", ret);
+}
+
 /* Small helper to sync EXTCON_CHG_USB_SDP and EXTCON_USB state */
 static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext,
 				    unsigned int cable, bool state)
@@ -280,6 +300,21 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
 	if (IS_ERR(ext->edev))
 		return PTR_ERR(ext->edev);
 
+	/*
+	 * When a host-cable is detected the BIOS enables an external 5v boost
+	 * converter to power connected devices there are 2 problems with this:
+	 * 1) This gets seen by the external battery charger as a valid Vbus
+	 *    supply and it then tries to feed Vsys from this creating a
+	 *    feedback loop which causes aprox. 300 mA extra battery drain
+	 *    (and unless we drive the external-charger-disable pin high it
+	 *    also tries to charge the battery causing even more feedback).
+	 * 2) This gets seen by the pwrsrc block as a SDP USB Vbus supply
+	 * Since the external battery charger has its own 5v boost converter
+	 * which does not have these issues, we simply turn the separate
+	 * external 5v boost converter off and leave it off entirely.
+	 */
+	cht_wc_extcon_set_5v_boost(ext, false);
+
 	/* Enable sw control */
 	ret = cht_wc_extcon_sw_control(ext, true);
 	if (ret)
Signature · 1 line
2.9.3
#1 lore raw

PATCH v2 2/2 extcon: intel-cht-wc: Ignore failure to detect charger-type on host mode exit

When we leave host-mode because the id-pin is no longer connected to ground, the 5v boost converter is normally still on, so we will see Vbus, but it is not from a charger (normally) so the charger-type detection will fail.

This commit silences the cht_wc_extcon_get_charger() false-positive errors when we're leaving host mode.

---
 drivers/extcon/extcon-intel-cht-wc.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +11 -4
index e22df5f..5f37112 100644
@@ -96,6 +96,7 @@ struct cht_wc_extcon_data {
 	struct regmap *regmap;
 	struct extcon_dev *edev;
 	unsigned int previous_cable;
+	bool usb_host;
 };
 
 static int cht_wc_extcon_get_id(struct cht_wc_extcon_data *ext, int pwrsrc_sts)
@@ -112,7 +113,8 @@ static int cht_wc_extcon_get_id(struct cht_wc_extcon_data *ext, int pwrsrc_sts)
 	return USB_ID_FLOAT;
 }
 
-static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext)
+static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext,
+				     bool ignore_errors)
 {
 	int ret, usbsrc, status;
 	unsigned long timeout;
@@ -135,6 +137,9 @@ static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext)
 	} while (time_before(jiffies, timeout));
 
 	if (status != CHT_WC_USBSRC_STS_SUCCESS) {
+		if (ignore_errors)
+			return EXTCON_CHG_USB_SDP; /* Save fallback */
+
 		if (status == CHT_WC_USBSRC_STS_FAIL)
 			dev_warn(ext->dev, "Could not detect charger type\n");
 		else
@@ -203,6 +208,8 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
 {
 	int ret, pwrsrc_sts, id;
 	unsigned int cable = EXTCON_NONE;
+	/* Ignore errors in host mode, as the 5v boost converter is on then */
+	bool ignore_get_charger_errors = ext->usb_host;
 
 	ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts);
 	if (ret) {
@@ -223,7 +230,7 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
 		goto set_state;
 	}
 
-	ret = cht_wc_extcon_get_charger(ext);
+	ret = cht_wc_extcon_get_charger(ext, ignore_get_charger_errors);
 	if (ret >= 0)
 		cable = ret;
 
@@ -238,8 +245,8 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
 		ext->previous_cable = cable;
 	}
 
-	extcon_set_state_sync(ext->edev, EXTCON_USB_HOST,
-			      id == USB_ID_GND || id == USB_RID_A);
+	ext->usb_host = id == USB_ID_GND || id == USB_RID_A;
+	extcon_set_state_sync(ext->edev, EXTCON_USB_HOST, ext->usb_host);
 }
 
 static irqreturn_t cht_wc_extcon_isr(int irq, void *data)
Signature · 1 line
2.9.3
maintainer
#2 lore raw

Re: [PATCH v2 2/2] extcon: intel-cht-wc: Ignore failure to detect charger-type on host mode exit

Quoted 64 lines · Hans de Goede

When we leave host-mode because the id-pin is no longer connected to ground, the 5v boost converter is normally still on, so we will see Vbus, but it is not from a charger (normally) so the charger-type detection will fail.

This commit silences the cht_wc_extcon_get_charger() false-positive errors when we're leaving host mode.

---
 drivers/extcon/extcon-intel-cht-wc.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +9 -2
index e22df5f..5f37112 100644
@@ -96,6 +96,7 @@ struct cht_wc_extcon_data {
 	struct regmap *regmap;
 	struct extcon_dev *edev;
 	unsigned int previous_cable;
+	bool usb_host;
 };
 
 static int cht_wc_extcon_get_id(struct cht_wc_extcon_data *ext, int pwrsrc_sts)
@@ -112,7 +113,8 @@ static int cht_wc_extcon_get_id(struct cht_wc_extcon_data *ext, int pwrsrc_sts)
 	return USB_ID_FLOAT;
 }
 
-static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext)
+static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext,
+				     bool ignore_errors)
 {
 	int ret, usbsrc, status;
 	unsigned long timeout;
@@ -135,6 +137,9 @@ static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext)
 	} while (time_before(jiffies, timeout));
 
 	if (status != CHT_WC_USBSRC_STS_SUCCESS) {
+		if (ignore_errors)
+			return EXTCON_CHG_USB_SDP; /* Save fallback */
+
 		if (status == CHT_WC_USBSRC_STS_FAIL)
 			dev_warn(ext->dev, "Could not detect charger type\n");
 		else
@@ -203,6 +208,8 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
 {
 	int ret, pwrsrc_sts, id;
 	unsigned int cable = EXTCON_NONE;
+	/* Ignore errors in host mode, as the 5v boost converter is on then */
+	bool ignore_get_charger_errors = ext->usb_host;
 
 	ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts);
 	if (ret) {
@@ -223,7 +230,7 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
 		goto set_state;
 	}
 
-	ret = cht_wc_extcon_get_charger(ext);
+	ret = cht_wc_extcon_get_charger(ext, ignore_get_charger_errors);
 	if (ret >= 0)
 		cable = ret;
 

drivers/extcon/extcon-intel-cht-wc.c static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) · line 248

Quoted 6 lines
drivers/extcon/extcon-intel-cht-wc.c +1 -2
@@ -238,8 +245,8 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
 		ext->previous_cable = cable;
 	}
 
-	extcon_set_state_sync(ext->edev, EXTCON_USB_HOST,
-			      id == USB_ID_GND || id == USB_RID_A);
+	ext->usb_host = id == USB_ID_GND || id == USB_RID_A;

I'll modify it as following to improve the readability:

	ext->usb_host = ((id == USB_ID_GND) || (id == USB_RID_A));
Quoted 5 lines
drivers/extcon/extcon-intel-cht-wc.c +1 -0
+	extcon_set_state_sync(ext->edev, EXTCON_USB_HOST, ext->usb_host);
 }
 
 static irqreturn_t cht_wc_extcon_isr(int irq, void *data)
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
maintainer
#3 lore raw
In reply to Hans de Goede

Hi,

Applied the patch1/patch2.

Quoted 84 lines · Hans de Goede

Disable the 5v boost converter on probe in case it was left on by the BIOS, this fixes 2 problems:

1) This gets seen by the external battery charger as a valid Vbus supply and it then tries to feed Vsys from this creating a feedback loop which causes aprox. 300 mA extra battery drain (and unless we drive the external-charger-disable pin high it also tries to charge the battery causing even more feedback).
2) This gets seen by the pwrsrc block as a SDP USB Vbus supply

Since the external battery charger has its own 5v boost converter which does not have these issues, we simply turn the separate external 5v boost converter off and leave it off entirely.

---
Changes in v2:

(quoted diff) +0 -2
-Use CHT_WC_VBUS_GPIO_CTLO and CHT_WC_VBUS_GPIO_CTLO_OUTPUT as name for
 the register defines
---
 drivers/extcon/extcon-intel-cht-wc.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/extcon/extcon-intel-cht-wc.c +35 -0
index f1c43af..e22df5f 100644
@@ -64,6 +64,9 @@
 #define CHT_WC_PWRSRC_ID_GND		BIT(3)
 #define CHT_WC_PWRSRC_ID_FLOAT		BIT(4)
 
+#define CHT_WC_VBUS_GPIO_CTLO		0x6e2d
+#define CHT_WC_VBUS_GPIO_CTLO_OUTPUT	BIT(0)
+
 enum cht_wc_usb_id {
 	USB_ID_OTG,
 	USB_ID_GND,
@@ -170,6 +173,23 @@ static void cht_wc_extcon_set_phymux(struct cht_wc_extcon_data *ext, u8 state)
 		dev_err(ext->dev, "Error writing phyctrl: %d\n", ret);
 }
 
+static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext,
+				       bool enable)
+{
+	int ret, val;
+
+	val = enable ? CHT_WC_VBUS_GPIO_CTLO_OUTPUT : 0;
+
+	/*
+	 * The 5V boost converter is enabled through a gpio on the PMIC, since
+	 * there currently is no gpio driver we access the gpio reg directly.
+	 */
+	ret = regmap_update_bits(ext->regmap, CHT_WC_VBUS_GPIO_CTLO,
+				 CHT_WC_VBUS_GPIO_CTLO_OUTPUT, val);
+	if (ret)
+		dev_err(ext->dev, "Error writing Vbus GPIO CTLO: %d\n", ret);
+}
+
 /* Small helper to sync EXTCON_CHG_USB_SDP and EXTCON_USB state */
 static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext,
 				    unsigned int cable, bool state)
@@ -280,6 +300,21 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
 	if (IS_ERR(ext->edev))
 		return PTR_ERR(ext->edev);
 
+	/*
+	 * When a host-cable is detected the BIOS enables an external 5v boost
+	 * converter to power connected devices there are 2 problems with this:
+	 * 1) This gets seen by the external battery charger as a valid Vbus
+	 *    supply and it then tries to feed Vsys from this creating a
+	 *    feedback loop which causes aprox. 300 mA extra battery drain
+	 *    (and unless we drive the external-charger-disable pin high it
+	 *    also tries to charge the battery causing even more feedback).
+	 * 2) This gets seen by the pwrsrc block as a SDP USB Vbus supply
+	 * Since the external battery charger has its own 5v boost converter
+	 * which does not have these issues, we simply turn the separate
+	 * external 5v boost converter off and leave it off entirely.
+	 */
+	cht_wc_extcon_set_5v_boost(ext, false);
+
 	/* Enable sw control */
 	ret = cht_wc_extcon_sw_control(ext, true);
 	if (ret)
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#4 lore raw

Hi,

Quoted 3 lines · Chanwoo Choi

Hi,

Applied the patch1/patch2.

Great, thank you.

Regards,

Hans

Quoted 88 lines · Hans de Goede
Quoted 84 lines

Disable the 5v boost converter on probe in case it was left on by the BIOS, this fixes 2 problems:

1) This gets seen by the external battery charger as a valid Vbus supply and it then tries to feed Vsys from this creating a feedback loop which causes aprox. 300 mA extra battery drain (and unless we drive the external-charger-disable pin high it also tries to charge the battery causing even more feedback).
2) This gets seen by the pwrsrc block as a SDP USB Vbus supply

Since the external battery charger has its own 5v boost converter which does not have these issues, we simply turn the separate external 5v boost converter off and leave it off entirely.

---
Changes in v2:

(quoted diff) +0 -2
-Use CHT_WC_VBUS_GPIO_CTLO and CHT_WC_VBUS_GPIO_CTLO_OUTPUT as name for
 the register defines
---
 drivers/extcon/extcon-intel-cht-wc.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/extcon/extcon-intel-cht-wc.c +35 -0
index f1c43af..e22df5f 100644
@@ -64,6 +64,9 @@
 #define CHT_WC_PWRSRC_ID_GND		BIT(3)
 #define CHT_WC_PWRSRC_ID_FLOAT		BIT(4)
 
+#define CHT_WC_VBUS_GPIO_CTLO		0x6e2d
+#define CHT_WC_VBUS_GPIO_CTLO_OUTPUT	BIT(0)
+
 enum cht_wc_usb_id {
 	USB_ID_OTG,
 	USB_ID_GND,
@@ -170,6 +173,23 @@ static void cht_wc_extcon_set_phymux(struct cht_wc_extcon_data *ext, u8 state)
 		dev_err(ext->dev, "Error writing phyctrl: %d\n", ret);
 }
 
+static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext,
+				       bool enable)
+{
+	int ret, val;
+
+	val = enable ? CHT_WC_VBUS_GPIO_CTLO_OUTPUT : 0;
+
+	/*
+	 * The 5V boost converter is enabled through a gpio on the PMIC, since
+	 * there currently is no gpio driver we access the gpio reg directly.
+	 */
+	ret = regmap_update_bits(ext->regmap, CHT_WC_VBUS_GPIO_CTLO,
+				 CHT_WC_VBUS_GPIO_CTLO_OUTPUT, val);
+	if (ret)
+		dev_err(ext->dev, "Error writing Vbus GPIO CTLO: %d\n", ret);
+}
+
 /* Small helper to sync EXTCON_CHG_USB_SDP and EXTCON_USB state */
 static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext,
 				    unsigned int cable, bool state)
@@ -280,6 +300,21 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
 	if (IS_ERR(ext->edev))
 		return PTR_ERR(ext->edev);
 
+	/*
+	 * When a host-cable is detected the BIOS enables an external 5v boost
+	 * converter to power connected devices there are 2 problems with this:
+	 * 1) This gets seen by the external battery charger as a valid Vbus
+	 *    supply and it then tries to feed Vsys from this creating a
+	 *    feedback loop which causes aprox. 300 mA extra battery drain
+	 *    (and unless we drive the external-charger-disable pin high it
+	 *    also tries to charge the battery causing even more feedback).
+	 * 2) This gets seen by the pwrsrc block as a SDP USB Vbus supply
+	 * Since the external battery charger has its own 5v boost converter
+	 * which does not have these issues, we simply turn the separate
+	 * external 5v boost converter off and leave it off entirely.
+	 */
+	cht_wc_extcon_set_5v_boost(ext, false);
+
 	/* Enable sw control */
 	ret = cht_wc_extcon_sw_control(ext, true);
 	if (ret)