Skip to contentSkip to conversation

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

PATCH In review Yauhen Kharuzhy 5 participants 9 messages Sep 16, 2019 – Sep 20, 2019 External connector subsystem (extcon)

lore
Share & tools
lore
#0 lore raw

Patch to prevent resetting USB connection if OTG device is connected during of driver initialization.

v2:
Change (id == INTEL_USB_ID_FLOAT) check to (id != INTEL_USB_ID_GND) as Hans de Goede advised.

#1 lore raw

PATCH v2 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..da1886a92f75 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_GND)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
 
 	/* Get initial state */
 	cht_wc_extcon_pwrsrc_event(ext);
Signature · 1 line
2.23.0.rc1
Reviewed-by on v2 1/1
#2 lore raw

Hi,

Quoted 10 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.

---

Patch looks good to me:

Regards,

Hans

Quoted 38 lines
  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..da1886a92f75 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_GND)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
 
  	/* Get initial state */
  	cht_wc_extcon_pwrsrc_event(ext);
#3 lore raw
In reply to Yauhen Kharuzhy
Quoted 8 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 static int cht_wc_extcon_probe(struct platform_device *pdev) · line 397

Quoted 7 lines
drivers/extcon/extcon-intel-cht-wc.c +7 -0
+	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);

We have second implementation of this. Would it make sense to split to some helper?

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

Quoted 3 lines
drivers/extcon/extcon-intel-cht-wc.c +3 -0
+	/* If no USB host or device connected, route D+ and D- to PMIC for
+	 * initial charger detection
+	 */

I'm not sure it's acceptable style of multi-line comment, but it's up to maintainer.

Quoted 8 lines
drivers/extcon/extcon-intel-cht-wc.c +2 -0
+	if (id != INTEL_USB_ID_GND)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
 
 	/* Get initial state */
 	cht_wc_extcon_pwrsrc_event(ext);
Signature · 1 line
2.23.0.rc1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 7 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.

Quoted 10 lines

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

Quoted 7 lines
drivers/extcon/extcon-intel-cht-wc.c +7 -0
+	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);

We have second implementation of this. Would it make sense to split to some helper?

Do you mean the combination of regmap_read(...CHT_WC_PWRSRC_STS, &pwrsrc_sts) with cht_wc_extcon_get_id()?

In the cht_wc_extcon_pwrsrc_event() function the pwrsrc_sts is checked for other bits also, so separation of PWRSRC_STS read and id calculation to one routine will cause non-clear function calls like as get_powersrc_and_check_id(..., &powersrc_sts, &id) which is not looks better than current code duplication. Or we need to spend some time for refactoring and testing of cht_wc_extcon_pwrsrc_event() code.

Quoted 7 lines

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

Quoted 4 lines
drivers/extcon/extcon-intel-cht-wc.c +3 -0
+	/* If no USB host or device connected, route D+ and D- to PMIC for
+	 * initial charger detection
+	 */

I'm not sure it's acceptable style of multi-line comment, but it's up to maintainer.

Argh, you are right, I fixed this in local copy but this is not significant typo.

Quoted 15 lines
Quoted 9 lines
drivers/extcon/extcon-intel-cht-wc.c +2 -0
+	if (id != INTEL_USB_ID_GND)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
 
 	/* Get initial state */
 	cht_wc_extcon_pwrsrc_event(ext);
Signature · 1 line
2.23.0.rc1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 1 line
Yauhen Kharuzhy
#5 lore raw
Quoted 19 lines · Yauhen Kharuzhy
Quoted 17 lines · Andy Shevchenko
Quoted 15 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 +7 -0
+   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);
Quoted 5 lines
Quoted 2 lines

We have second implementation of this. Would it make sense to split to some helper?

Do you mean the combination of regmap_read(...CHT_WC_PWRSRC_STS, &pwrsrc_sts) with cht_wc_extcon_get_id()?

Yes.

Quoted 5 lines

In the cht_wc_extcon_pwrsrc_event() function the pwrsrc_sts is checked for other bits also, so separation of PWRSRC_STS read and id calculation to one routine will cause non-clear function calls like as get_powersrc_and_check_id(..., &powersrc_sts, &id) which is not looks better than current code duplication.

I see. Thanks for answer.

Quoted 2 lines

Or we need to spend some time for
refactoring and testing of cht_wc_extcon_pwrsrc_event() code.

Perhaps, In any case I'm not objecting of the current approach.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#6 lore raw

Hi Andy,

Quoted 34 lines · Andy Shevchenko
Quoted 19 lines · Yauhen Kharuzhy
Quoted 17 lines · Andy Shevchenko
Quoted 15 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 +7 -0
+   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);
Quoted 5 lines
Quoted 2 lines

We have second implementation of this. Would it make sense to split to some helper?

Do you mean the combination of regmap_read(...CHT_WC_PWRSRC_STS, &pwrsrc_sts) with cht_wc_extcon_get_id()?

Yes.

Quoted 5 lines

In the cht_wc_extcon_pwrsrc_event() function the pwrsrc_sts is checked for other bits also, so separation of PWRSRC_STS read and id calculation to one routine will cause non-clear function calls like as get_powersrc_and_check_id(..., &powersrc_sts, &id) which is not looks better than current code duplication.

Quoted 7 lines

I see. Thanks for answer.

Quoted 2 lines

Or we need to spend some time for
refactoring and testing of cht_wc_extcon_pwrsrc_event() code.

Perhaps, In any case I'm not objecting of the current approach.

If you think it is OK, could you reply with your tag? and I'll fix the multi-line comment by myself.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
Reviewed-by on v2 1/1
#7 lore raw
In reply to Yauhen Kharuzhy
Quoted 9 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.

FWIW,

Quoted 42 lines
---
 drivers/extcon/extcon-intel-cht-wc.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +14 -3
index 9d32150e68db..da1886a92f75 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_GND)
+               cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
 
        /* Get initial state */
        cht_wc_extcon_pwrsrc_event(ext);
--

2.23.0.rc1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#8 lore raw
In reply to Yauhen Kharuzhy

Hi,

Quoted 38 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 +7 -2
index 9d32150e68db..da1886a92f75 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;
+	}
+

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

Quoted 10 lines
drivers/extcon/extcon-intel-cht-wc.c +7 -0
+	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_GND)
+		cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
 
 	/* Get initial state */
 	cht_wc_extcon_pwrsrc_event(ext);

I edit this patch as following by myself and then applied it.

drivers/extcon/extcon-intel-cht-wc.c +14 -2
index 9d32150e68db..771f6f4cf92e 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;
+       }
+
+       /*
+        * If no USB host or device connected, route D+ and D- to PMIC for
+        * initial charger detection
+        */
+       id = cht_wc_extcon_get_id(ext, pwrsrc_sts);
+       if (id != INTEL_USB_ID_GND)
+               cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC);
 
 
 
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics