Skip to contentSkip to conversation

extcon-intel-cht-wc: Don't reset USB data connection at probe

PATCH Superseded Yauhen Kharuzhy 2 participants 5 messages Aug 8, 2019 – Sep 16, 2019 External connector subsystem (extcon)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 extcon-intel-cht-wc: Don't reset USB data connection at probe

Intel Cherry Trail Whiskey Cove extcon driver connect USB data lines to PMIC at driver probing for further charger detection. This causes reset of USB data sessions and removing all devices from bus. If system was booted from Live CD or USB dongle, this makes system unusable.

Check if USB ID pin is floating and re-route data lines in this case only, don't touch otherwise.

---
 drivers/extcon/extcon-intel-cht-wc.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +14 -2
index 9d32150e68db..3ae573e93e6e 100644
@@ -338,6 +338,7 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
 	struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
 	struct cht_wc_extcon_data *ext;
 	unsigned long mask = ~(CHT_WC_PWRSRC_VBUS | CHT_WC_PWRSRC_USBID_MASK);
+	int pwrsrc_sts, id;
 	int irq, ret;
 
 	irq = platform_get_irq(pdev, 0);
@@ -387,8 +388,19 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
 		goto disable_sw_control;
 	}
 
-	/* Route D+ and D- to PMIC for initial charger detection */
-	cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
+	ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts);
+	if (ret) {
+		dev_err(ext->dev, "Error reading pwrsrc status: %d\n", ret);
+		goto disable_sw_control;
+	}
+
+	id = cht_wc_extcon_get_id(ext, pwrsrc_sts);
+
+	/* If no USB host or device connected, route D+ and D- to PMIC for
+	 * initial charger detection
+	 */
+	if (id == INTEL_USB_ID_FLOAT)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
 
 	/* Get initial state */
 	cht_wc_extcon_pwrsrc_event(ext);
Signature · 1 line
2.23.0.rc0
#1 lore raw

Hi,

Quoted 34 lines · Yauhen Kharuzhy

Intel Cherry Trail Whiskey Cove extcon driver connect USB data lines to PMIC at driver probing for further charger detection. This causes reset of USB data sessions and removing all devices from bus. If system was booted from Live CD or USB dongle, this makes system unusable.

Check if USB ID pin is floating and re-route data lines in this case only, don't touch otherwise.

---
  drivers/extcon/extcon-intel-cht-wc.c | 16 ++++++++++++++--
  1 file changed, 14 insertions(+), 2 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +4 -2
index 9d32150e68db..3ae573e93e6e 100644
@@ -338,6 +338,7 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
  	struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
  	struct cht_wc_extcon_data *ext;
  	unsigned long mask = ~(CHT_WC_PWRSRC_VBUS | CHT_WC_PWRSRC_USBID_MASK);
+	int pwrsrc_sts, id;
  	int irq, ret;
 
  	irq = platform_get_irq(pdev, 0);
@@ -387,8 +388,19 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
  		goto disable_sw_control;
  	}
 
-	/* Route D+ and D- to PMIC for initial charger detection */
-	cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
+	ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts);
+	if (ret) {
+		dev_err(ext->dev, "Error reading pwrsrc status: %d\n", ret);

drivers/extcon/extcon-intel-cht-wc.c static int cht_wc_extcon_probe(struct platform_device *pdev) · line 403

Quoted 10 lines
drivers/extcon/extcon-intel-cht-wc.c +10 -0
+		goto disable_sw_control;
+	}
+
+	id = cht_wc_extcon_get_id(ext, pwrsrc_sts);
+
+	/* If no USB host or device connected, route D+ and D- to PMIC for
+	 * initial charger detection
+	 */
+	if (id == INTEL_USB_ID_FLOAT)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);

The check here should be != INTEL_USB_ID_GND, when we are connected as device we are charging from the host we are connected to and the port we are connected to may be a CDP (charging downstream port) instead of a SDP (standard downstream port) allowing us to charge at 1.5A instead of 0.5A, also != INTEL_USB_ID_GND matches the condition used in cht_wc_extcon_pwrsrc_event to determine if we should continue with charger detection there.

Like your other patch I will try to give this one a test-run tomorrow.

Regards,

Hans

Quoted 4 lines
drivers/extcon/extcon-intel-cht-wc.c +0 -0
  	/* Get initial state */
  	cht_wc_extcon_pwrsrc_event(ext);
 
#2 lore raw
Quoted 46 lines · Hans de Goede

Hi,

Quoted 32 lines · Yauhen Kharuzhy

Intel Cherry Trail Whiskey Cove extcon driver connect USB data lines to PMIC at driver probing for further charger detection. This causes reset of USB data sessions and removing all devices from bus. If system was booted from Live CD or USB dongle, this makes system unusable.

Check if USB ID pin is floating and re-route data lines in this case only, don't touch otherwise.

---
  drivers/extcon/extcon-intel-cht-wc.c | 16 ++++++++++++++--
  1 file changed, 14 insertions(+), 2 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +4 -2
index 9d32150e68db..3ae573e93e6e 100644
@@ -338,6 +338,7 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
  	struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
  	struct cht_wc_extcon_data *ext;
  	unsigned long mask = ~(CHT_WC_PWRSRC_VBUS | CHT_WC_PWRSRC_USBID_MASK);
+	int pwrsrc_sts, id;
  	int irq, ret;
  	irq = platform_get_irq(pdev, 0);
@@ -387,8 +388,19 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
  		goto disable_sw_control;
  	}
-	/* Route D+ and D- to PMIC for initial charger detection */
-	cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
+	ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts);
+	if (ret) {
+		dev_err(ext->dev, "Error reading pwrsrc status: %d\n", ret);

drivers/extcon/extcon-intel-cht-wc.c static int cht_wc_extcon_probe(struct platform_device *pdev) · line 402

Quoted 10 lines
drivers/extcon/extcon-intel-cht-wc.c +10 -0
+		goto disable_sw_control;
+	}
+
+	id = cht_wc_extcon_get_id(ext, pwrsrc_sts);
+
+	/* If no USB host or device connected, route D+ and D- to PMIC for
+	 * initial charger detection
+	 */
+	if (id == INTEL_USB_ID_FLOAT)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
Quoted 7 lines

The check here should be != INTEL_USB_ID_GND, when we are connected as device we are charging from the host we are connected to and the port we are connected to may be a CDP (charging downstream port) instead of a SDP (standard downstream port) allowing us to charge at 1.5A instead of 0.5A, also != INTEL_USB_ID_GND matches the condition used in cht_wc_extcon_pwrsrc_event to determine if we should continue with charger detection there.

Actually it should be checked as ((id != INTEL_USB_ID_GND) && (id != INTEL_USB_RID_A)), to not interrupt connection if ACA used and our host is OTG A device (for example, if LiveCD boots from USB flash inserted into an ACA USB hub).

Quoted 11 lines

Like your other patch I will try to give this one a test-run tomorrow.

Regards,

Hans

Quoted 3 lines
drivers/extcon/extcon-intel-cht-wc.c +0 -0
  	/* Get initial state */
  	cht_wc_extcon_pwrsrc_event(ext);
 
Signature · 1 line
Yauhen Kharuzhy
#3 lore raw

Hi,

Quoted 55 lines · Yauhen Kharuzhy
Quoted 46 lines · Hans de Goede

Hi,

Quoted 32 lines · Yauhen Kharuzhy

Intel Cherry Trail Whiskey Cove extcon driver connect USB data lines to PMIC at driver probing for further charger detection. This causes reset of USB data sessions and removing all devices from bus. If system was booted from Live CD or USB dongle, this makes system unusable.

Check if USB ID pin is floating and re-route data lines in this case only, don't touch otherwise.

---
   drivers/extcon/extcon-intel-cht-wc.c | 16 ++++++++++++++--
   1 file changed, 14 insertions(+), 2 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +4 -2
index 9d32150e68db..3ae573e93e6e 100644
@@ -338,6 +338,7 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
   	struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
   	struct cht_wc_extcon_data *ext;
   	unsigned long mask = ~(CHT_WC_PWRSRC_VBUS | CHT_WC_PWRSRC_USBID_MASK);
+	int pwrsrc_sts, id;
   	int irq, ret;
   	irq = platform_get_irq(pdev, 0);
@@ -387,8 +388,19 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
   		goto disable_sw_control;
   	}
-	/* Route D+ and D- to PMIC for initial charger detection */
-	cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
+	ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts);
+	if (ret) {
+		dev_err(ext->dev, "Error reading pwrsrc status: %d\n", ret);

drivers/extcon/extcon-intel-cht-wc.c static int cht_wc_extcon_probe(struct platform_device *pdev) · line 402

Quoted 10 lines
drivers/extcon/extcon-intel-cht-wc.c +10 -0
+		goto disable_sw_control;
+	}
+
+	id = cht_wc_extcon_get_id(ext, pwrsrc_sts);
+
+	/* If no USB host or device connected, route D+ and D- to PMIC for
+	 * initial charger detection
+	 */
+	if (id == INTEL_USB_ID_FLOAT)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
Quoted 7 lines

The check here should be != INTEL_USB_ID_GND, when we are connected as device we are charging from the host we are connected to and the port we are connected to may be a CDP (charging downstream port) instead of a SDP (standard downstream port) allowing us to charge at 1.5A instead of 0.5A, also != INTEL_USB_ID_GND matches the condition used in cht_wc_extcon_pwrsrc_event to determine if we should continue with charger detection there.

Quoted 4 lines

Actually it should be checked as ((id != INTEL_USB_ID_GND) && (id != INTEL_USB_RID_A)), to not interrupt connection if ACA used and our host is OTG A device (for example, if LiveCD boots from USB flash inserted into an ACA USB hub).

Right, except that cht_wc_extcon_get_id never returns INTEL_USB_RID_A, so checking for that would be superfluous and also would be inconsistent with what cht_wc_extcon_pwrsrc_event is doing, so for now please just test for != INTEL_USB_ID_GND, if cht_wc_extcon_get_id ever starts supporting RID_A then we should fix both cht_wc_extcon_pwrsrc_event and you new check at that time.

Hmm, I now see that cht_wc_extcon_get_id currently only reports one of:
INTEL_USB_ID_GND or INTEL_USB_ID_FLOAT so == INTEL_USB_ID_FLOAT is equivalent to != INTEL_USB_ID_GND still please check for 1= INTEL_USB_ID_GND as that is what cht_wc_extcon_pwrsrc_event is doing.

Quoted 1 line
Quoted 1 line

Like your other patch I will try to give this one a test-run tomorrow.

I've given this patch a test-run today and I can confirm that BC1.2 charger detection still works fine on my device using this driver.

Regards,

Hans

#4 lore raw
Quoted 75 lines · Hans de Goede

Hi,

Quoted 55 lines · Yauhen Kharuzhy
Quoted 46 lines · Hans de Goede

Hi,

Quoted 32 lines · Yauhen Kharuzhy

Intel Cherry Trail Whiskey Cove extcon driver connect USB data lines to PMIC at driver probing for further charger detection. This causes reset of USB data sessions and removing all devices from bus. If system was booted from Live CD or USB dongle, this makes system unusable.

Check if USB ID pin is floating and re-route data lines in this case only, don't touch otherwise.

---
   drivers/extcon/extcon-intel-cht-wc.c | 16 ++++++++++++++--
   1 file changed, 14 insertions(+), 2 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +4 -2
index 9d32150e68db..3ae573e93e6e 100644
@@ -338,6 +338,7 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
   	struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
   	struct cht_wc_extcon_data *ext;
   	unsigned long mask = ~(CHT_WC_PWRSRC_VBUS | CHT_WC_PWRSRC_USBID_MASK);
+	int pwrsrc_sts, id;
   	int irq, ret;
   	irq = platform_get_irq(pdev, 0);
@@ -387,8 +388,19 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
   		goto disable_sw_control;
   	}
-	/* Route D+ and D- to PMIC for initial charger detection */
-	cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
+	ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts);
+	if (ret) {
+		dev_err(ext->dev, "Error reading pwrsrc status: %d\n", ret);

drivers/extcon/extcon-intel-cht-wc.c static int cht_wc_extcon_probe(struct platform_device *pdev) · line 402

Quoted 10 lines
drivers/extcon/extcon-intel-cht-wc.c +10 -0
+		goto disable_sw_control;
+	}
+
+	id = cht_wc_extcon_get_id(ext, pwrsrc_sts);
+
+	/* If no USB host or device connected, route D+ and D- to PMIC for
+	 * initial charger detection
+	 */
+	if (id == INTEL_USB_ID_FLOAT)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
Quoted 7 lines

The check here should be != INTEL_USB_ID_GND, when we are connected as device we are charging from the host we are connected to and the port we are connected to may be a CDP (charging downstream port) instead of a SDP (standard downstream port) allowing us to charge at 1.5A instead of 0.5A, also != INTEL_USB_ID_GND matches the condition used in cht_wc_extcon_pwrsrc_event to determine if we should continue with charger detection there.

Quoted 4 lines

Actually it should be checked as ((id != INTEL_USB_ID_GND) && (id != INTEL_USB_RID_A)), to not interrupt connection if ACA used and our host is OTG A device (for example, if LiveCD boots from USB flash inserted into an ACA USB hub).

Right, except that cht_wc_extcon_get_id never returns INTEL_USB_RID_A, so checking for that would be superfluous and also would be inconsistent with what cht_wc_extcon_pwrsrc_event is doing, so for now please just test for != INTEL_USB_ID_GND, if cht_wc_extcon_get_id ever starts supporting RID_A then we should fix both cht_wc_extcon_pwrsrc_event and you new check at that time.

Hmm, I now see that cht_wc_extcon_get_id currently only reports one of:
INTEL_USB_ID_GND or INTEL_USB_ID_FLOAT so == INTEL_USB_ID_FLOAT is equivalent to != INTEL_USB_ID_GND still please check for 1= INTEL_USB_ID_GND as that is what cht_wc_extcon_pwrsrc_event is doing.

Quoted 4 lines
Quoted 1 line
Quoted 1 line

Like your other patch I will try to give this one a test-run tomorrow.

I've given this patch a test-run today and I can confirm that BC1.2 charger detection still works fine on my device using this driver.

OK.

Signature · 1 line
Yauhen Kharuzhy