public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection
@ 2026-03-12  6:16 Alexander Koskovich
  2026-03-12 10:04 ` Bryan O'Donoghue
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alexander Koskovich @ 2026-03-12  6:16 UTC (permalink / raw)
  To: Bryan O'Donoghue, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Heikki Krogerus
  Cc: linux-arm-msm, linux-usb, devicetree, linux-kernel,
	Alexander Koskovich

This is required for devices (e.g. ASUS ROG Phone 3) where more than
one USB port can act as a sink and both share a single USBIN input on
the PMIC.

Because the PM8150B uses USBIN to determine VBUS presence, a charger
connected to one port causes the PMIC to falsely detect VBUS on the
other port, preventing it from entering source mode.

For example, plugging a charger into one port prevents using the other
port for a flash drive.

Fix this by adding support for the vbus-gpios connector binding so the
driver can use an external GPIO for per-port VBUS presence detection
instead of the shared USBIN register.

Signed-off-by: Alexander Koskovich <akoskovich@pm.me>
---
Changes in v2:
- Dropped RFC prefix
- Remove redundant vbus-detect-gpios, instead use existing vbus-gpios from usb-connector (Dmitry)
- Updated cover to better describe scenario where this change is relevant
- Update comment for EN_TRY_SRC to make more sense
- Skip vSafe5V poll too not just vSafe0V
- return gpiod_get_value_cansleep (Konrad)
- regmap_update_bits -> regmap_set_bits (Konrad)
- Get vbus-gpios per connector (Konrad)
- Add bracket to if (IS_ERR(pmic_typec_port->vbus_detect_gpio)) (Bryan)
- Link to v1: https://lore.kernel.org/r/20260308-qcom-typec-shared-vbus-v1-0-7d574b91052a@pm.me
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 53 +++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
index 8051eaa46991..a8f6687a3522 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
@@ -5,6 +5,7 @@
 
 #include <linux/delay.h>
 #include <linux/err.h>
+#include <linux/gpio/consumer.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/mod_devicetable.h>
@@ -176,6 +177,8 @@ struct pmic_typec_port {
 	bool				vbus_enabled;
 	struct mutex			vbus_lock;		/* VBUS state serialization */
 
+	struct gpio_desc		*vbus_detect_gpio;
+
 	int				cc;
 	bool				debouncing_cc;
 	struct delayed_work		cc_debounce_dwork;
@@ -279,6 +282,9 @@ static int qcom_pmic_typec_port_vbus_detect(struct pmic_typec_port *pmic_typec_p
 	unsigned int misc;
 	int ret;
 
+	if (pmic_typec_port->vbus_detect_gpio)
+		return gpiod_get_value_cansleep(pmic_typec_port->vbus_detect_gpio);
+
 	ret = regmap_read(pmic_typec_port->regmap,
 			  pmic_typec_port->base + TYPEC_MISC_STATUS_REG,
 			  &misc);
@@ -310,6 +316,13 @@ static int qcom_pmic_typec_port_vbus_toggle(struct pmic_typec_port *pmic_typec_p
 		val = TYPEC_SM_VBUS_VSAFE0V;
 	}
 
+	/*
+	 * On devices with multiple ports sharing USBIN, VBUS from another
+	 * port makes the USBIN-based vsafe polls unreliable.
+	 */
+	if (pmic_typec_port->vbus_detect_gpio)
+		return 0;
+
 	/* Poll waiting for transition to required vSafe5V or vSafe0V */
 	ret = regmap_read_poll_timeout(pmic_typec_port->regmap,
 				       pmic_typec_port->base + TYPEC_SM_STATUS_REG,
@@ -589,7 +602,15 @@ static int qcom_pmic_typec_port_start_toggling(struct tcpc_dev *tcpc,
 		mode = EN_SNK_ONLY;
 		break;
 	case TYPEC_PORT_DRP:
-		mode = EN_TRY_SNK;
+		/*
+		 * With VBUS present on USBIN from another port, EN_TRY_SNK
+		 * keeps the port in sink mode. Use EN_TRY_SRC so the port
+		 * tries to source first.
+		 */
+		if (pmic_typec_port->vbus_detect_gpio)
+			mode = EN_TRY_SRC;
+		else
+			mode = EN_TRY_SNK;
 		break;
 	}
 
@@ -677,6 +698,19 @@ static int qcom_pmic_typec_port_start(struct pmic_typec *tcpm,
 	if (ret)
 		goto done;
 
+	/*
+	 * On devices with multiple USB-C ports sharing USBIN, bypass
+	 * VSAFE0V so SRC attachment can complete despite VBUS being
+	 * present on USBIN from another port.
+	 */
+	if (pmic_typec_port->vbus_detect_gpio) {
+		ret = regmap_set_bits(pmic_typec_port->regmap,
+				     pmic_typec_port->base + TYPEC_EXIT_STATE_CFG_REG,
+				     BYPASS_VSAFE0V_DURING_ROLE_SWAP);
+		if (ret)
+			goto done;
+	}
+
 	pmic_typec_port->tcpm_port = tcpm_port;
 
 	for (i = 0; i < pmic_typec_port->nr_irqs; i++)
@@ -704,6 +738,7 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev,
 	struct device *dev = &pdev->dev;
 	struct pmic_typec_port_irq_data *irq_data;
 	struct pmic_typec_port *pmic_typec_port;
+	struct fwnode_handle *connector;
 	int i, ret, irq;
 
 	pmic_typec_port = devm_kzalloc(dev, sizeof(*pmic_typec_port), GFP_KERNEL);
@@ -724,6 +759,22 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev,
 	if (IS_ERR(pmic_typec_port->vdd_vbus))
 		return PTR_ERR(pmic_typec_port->vdd_vbus);
 
+	connector = device_get_named_child_node(dev, "connector");
+	if (connector) {
+		pmic_typec_port->vbus_detect_gpio =
+			devm_fwnode_gpiod_get(dev, connector, "vbus",
+					      GPIOD_IN, NULL);
+		fwnode_handle_put(connector);
+
+		if (IS_ERR(pmic_typec_port->vbus_detect_gpio)) {
+			ret = PTR_ERR(pmic_typec_port->vbus_detect_gpio);
+			pmic_typec_port->vbus_detect_gpio = NULL;
+			if (ret != -ENOENT)
+				return dev_err_probe(dev, ret,
+						     "failed to get vbus GPIO\n");
+		}
+	}
+
 	pmic_typec_port->dev = dev;
 	pmic_typec_port->base = base;
 	pmic_typec_port->regmap = regmap;

---
base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
change-id: 20260308-qcom-typec-shared-vbus-7d37c6b2d155

Best regards,
-- 
Alexander Koskovich <akoskovich@pm.me>



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection
  2026-03-12  6:16 [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection Alexander Koskovich
@ 2026-03-12 10:04 ` Bryan O'Donoghue
  2026-03-13  8:46 ` Heikki Krogerus
  2026-03-19 13:26 ` Konrad Dybcio
  2 siblings, 0 replies; 7+ messages in thread
From: Bryan O'Donoghue @ 2026-03-12 10:04 UTC (permalink / raw)
  To: Alexander Koskovich, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Heikki Krogerus
  Cc: linux-arm-msm, linux-usb, devicetree, linux-kernel

On 12/03/2026 06:16, Alexander Koskovich wrote:
> This is required for devices (e.g. ASUS ROG Phone 3) where more than
> one USB port can act as a sink and both share a single USBIN input on
> the PMIC.
> 
> Because the PM8150B uses USBIN to determine VBUS presence, a charger
> connected to one port causes the PMIC to falsely detect VBUS on the
> other port, preventing it from entering source mode.
> 
> For example, plugging a charger into one port prevents using the other
> port for a flash drive.
> 
> Fix this by adding support for the vbus-gpios connector binding so the
> driver can use an external GPIO for per-port VBUS presence detection
> instead of the shared USBIN register.
> 
> Signed-off-by: Alexander Koskovich <akoskovich@pm.me>
> ---
> Changes in v2:
> - Dropped RFC prefix
> - Remove redundant vbus-detect-gpios, instead use existing vbus-gpios from usb-connector (Dmitry)
> - Updated cover to better describe scenario where this change is relevant
> - Update comment for EN_TRY_SRC to make more sense
> - Skip vSafe5V poll too not just vSafe0V
> - return gpiod_get_value_cansleep (Konrad)
> - regmap_update_bits -> regmap_set_bits (Konrad)
> - Get vbus-gpios per connector (Konrad)
> - Add bracket to if (IS_ERR(pmic_typec_port->vbus_detect_gpio)) (Bryan)
> - Link to v1: https://lore.kernel.org/r/20260308-qcom-typec-shared-vbus-v1-0-7d574b91052a@pm.me
> ---
>   drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 53 +++++++++++++++++++++-
>   1 file changed, 52 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> index 8051eaa46991..a8f6687a3522 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> @@ -5,6 +5,7 @@
>   
>   #include <linux/delay.h>
>   #include <linux/err.h>
> +#include <linux/gpio/consumer.h>
>   #include <linux/interrupt.h>
>   #include <linux/kernel.h>
>   #include <linux/mod_devicetable.h>
> @@ -176,6 +177,8 @@ struct pmic_typec_port {
>   	bool				vbus_enabled;
>   	struct mutex			vbus_lock;		/* VBUS state serialization */
>   
> +	struct gpio_desc		*vbus_detect_gpio;
> +
>   	int				cc;
>   	bool				debouncing_cc;
>   	struct delayed_work		cc_debounce_dwork;
> @@ -279,6 +282,9 @@ static int qcom_pmic_typec_port_vbus_detect(struct pmic_typec_port *pmic_typec_p
>   	unsigned int misc;
>   	int ret;
>   
> +	if (pmic_typec_port->vbus_detect_gpio)
> +		return gpiod_get_value_cansleep(pmic_typec_port->vbus_detect_gpio);
> +
>   	ret = regmap_read(pmic_typec_port->regmap,
>   			  pmic_typec_port->base + TYPEC_MISC_STATUS_REG,
>   			  &misc);
> @@ -310,6 +316,13 @@ static int qcom_pmic_typec_port_vbus_toggle(struct pmic_typec_port *pmic_typec_p
>   		val = TYPEC_SM_VBUS_VSAFE0V;
>   	}
>   
> +	/*
> +	 * On devices with multiple ports sharing USBIN, VBUS from another
> +	 * port makes the USBIN-based vsafe polls unreliable.
> +	 */
> +	if (pmic_typec_port->vbus_detect_gpio)
> +		return 0;
> +
>   	/* Poll waiting for transition to required vSafe5V or vSafe0V */
>   	ret = regmap_read_poll_timeout(pmic_typec_port->regmap,
>   				       pmic_typec_port->base + TYPEC_SM_STATUS_REG,
> @@ -589,7 +602,15 @@ static int qcom_pmic_typec_port_start_toggling(struct tcpc_dev *tcpc,
>   		mode = EN_SNK_ONLY;
>   		break;
>   	case TYPEC_PORT_DRP:
> -		mode = EN_TRY_SNK;
> +		/*
> +		 * With VBUS present on USBIN from another port, EN_TRY_SNK
> +		 * keeps the port in sink mode. Use EN_TRY_SRC so the port
> +		 * tries to source first.
> +		 */
> +		if (pmic_typec_port->vbus_detect_gpio)
> +			mode = EN_TRY_SRC;
> +		else
> +			mode = EN_TRY_SNK;
>   		break;
>   	}
>   
> @@ -677,6 +698,19 @@ static int qcom_pmic_typec_port_start(struct pmic_typec *tcpm,
>   	if (ret)
>   		goto done;
>   
> +	/*
> +	 * On devices with multiple USB-C ports sharing USBIN, bypass
> +	 * VSAFE0V so SRC attachment can complete despite VBUS being
> +	 * present on USBIN from another port.
> +	 */
> +	if (pmic_typec_port->vbus_detect_gpio) {
> +		ret = regmap_set_bits(pmic_typec_port->regmap,
> +				     pmic_typec_port->base + TYPEC_EXIT_STATE_CFG_REG,
> +				     BYPASS_VSAFE0V_DURING_ROLE_SWAP);

off-by-one

once fixed:
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection
  2026-03-12  6:16 [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection Alexander Koskovich
  2026-03-12 10:04 ` Bryan O'Donoghue
@ 2026-03-13  8:46 ` Heikki Krogerus
  2026-03-19 13:26 ` Konrad Dybcio
  2 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2026-03-13  8:46 UTC (permalink / raw)
  To: Alexander Koskovich
  Cc: Bryan O'Donoghue, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-arm-msm, linux-usb,
	devicetree, linux-kernel

Thu, Mar 12, 2026 at 06:16:58AM +0000, Alexander Koskovich kirjoitti:
> This is required for devices (e.g. ASUS ROG Phone 3) where more than
> one USB port can act as a sink and both share a single USBIN input on
> the PMIC.
> 
> Because the PM8150B uses USBIN to determine VBUS presence, a charger
> connected to one port causes the PMIC to falsely detect VBUS on the
> other port, preventing it from entering source mode.
> 
> For example, plugging a charger into one port prevents using the other
> port for a flash drive.
> 
> Fix this by adding support for the vbus-gpios connector binding so the
> driver can use an external GPIO for per-port VBUS presence detection
> instead of the shared USBIN register.
> 
> Signed-off-by: Alexander Koskovich <akoskovich@pm.me>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> Changes in v2:
> - Dropped RFC prefix
> - Remove redundant vbus-detect-gpios, instead use existing vbus-gpios from usb-connector (Dmitry)
> - Updated cover to better describe scenario where this change is relevant
> - Update comment for EN_TRY_SRC to make more sense
> - Skip vSafe5V poll too not just vSafe0V
> - return gpiod_get_value_cansleep (Konrad)
> - regmap_update_bits -> regmap_set_bits (Konrad)
> - Get vbus-gpios per connector (Konrad)
> - Add bracket to if (IS_ERR(pmic_typec_port->vbus_detect_gpio)) (Bryan)
> - Link to v1: https://lore.kernel.org/r/20260308-qcom-typec-shared-vbus-v1-0-7d574b91052a@pm.me
> ---
>  drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 53 +++++++++++++++++++++-
>  1 file changed, 52 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> index 8051eaa46991..a8f6687a3522 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> @@ -5,6 +5,7 @@
>  
>  #include <linux/delay.h>
>  #include <linux/err.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/interrupt.h>
>  #include <linux/kernel.h>
>  #include <linux/mod_devicetable.h>
> @@ -176,6 +177,8 @@ struct pmic_typec_port {
>  	bool				vbus_enabled;
>  	struct mutex			vbus_lock;		/* VBUS state serialization */
>  
> +	struct gpio_desc		*vbus_detect_gpio;
> +
>  	int				cc;
>  	bool				debouncing_cc;
>  	struct delayed_work		cc_debounce_dwork;
> @@ -279,6 +282,9 @@ static int qcom_pmic_typec_port_vbus_detect(struct pmic_typec_port *pmic_typec_p
>  	unsigned int misc;
>  	int ret;
>  
> +	if (pmic_typec_port->vbus_detect_gpio)
> +		return gpiod_get_value_cansleep(pmic_typec_port->vbus_detect_gpio);
> +
>  	ret = regmap_read(pmic_typec_port->regmap,
>  			  pmic_typec_port->base + TYPEC_MISC_STATUS_REG,
>  			  &misc);
> @@ -310,6 +316,13 @@ static int qcom_pmic_typec_port_vbus_toggle(struct pmic_typec_port *pmic_typec_p
>  		val = TYPEC_SM_VBUS_VSAFE0V;
>  	}
>  
> +	/*
> +	 * On devices with multiple ports sharing USBIN, VBUS from another
> +	 * port makes the USBIN-based vsafe polls unreliable.
> +	 */
> +	if (pmic_typec_port->vbus_detect_gpio)
> +		return 0;
> +
>  	/* Poll waiting for transition to required vSafe5V or vSafe0V */
>  	ret = regmap_read_poll_timeout(pmic_typec_port->regmap,
>  				       pmic_typec_port->base + TYPEC_SM_STATUS_REG,
> @@ -589,7 +602,15 @@ static int qcom_pmic_typec_port_start_toggling(struct tcpc_dev *tcpc,
>  		mode = EN_SNK_ONLY;
>  		break;
>  	case TYPEC_PORT_DRP:
> -		mode = EN_TRY_SNK;
> +		/*
> +		 * With VBUS present on USBIN from another port, EN_TRY_SNK
> +		 * keeps the port in sink mode. Use EN_TRY_SRC so the port
> +		 * tries to source first.
> +		 */
> +		if (pmic_typec_port->vbus_detect_gpio)
> +			mode = EN_TRY_SRC;
> +		else
> +			mode = EN_TRY_SNK;
>  		break;
>  	}
>  
> @@ -677,6 +698,19 @@ static int qcom_pmic_typec_port_start(struct pmic_typec *tcpm,
>  	if (ret)
>  		goto done;
>  
> +	/*
> +	 * On devices with multiple USB-C ports sharing USBIN, bypass
> +	 * VSAFE0V so SRC attachment can complete despite VBUS being
> +	 * present on USBIN from another port.
> +	 */
> +	if (pmic_typec_port->vbus_detect_gpio) {
> +		ret = regmap_set_bits(pmic_typec_port->regmap,
> +				     pmic_typec_port->base + TYPEC_EXIT_STATE_CFG_REG,
> +				     BYPASS_VSAFE0V_DURING_ROLE_SWAP);
> +		if (ret)
> +			goto done;
> +	}
> +
>  	pmic_typec_port->tcpm_port = tcpm_port;
>  
>  	for (i = 0; i < pmic_typec_port->nr_irqs; i++)
> @@ -704,6 +738,7 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev,
>  	struct device *dev = &pdev->dev;
>  	struct pmic_typec_port_irq_data *irq_data;
>  	struct pmic_typec_port *pmic_typec_port;
> +	struct fwnode_handle *connector;
>  	int i, ret, irq;
>  
>  	pmic_typec_port = devm_kzalloc(dev, sizeof(*pmic_typec_port), GFP_KERNEL);
> @@ -724,6 +759,22 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev,
>  	if (IS_ERR(pmic_typec_port->vdd_vbus))
>  		return PTR_ERR(pmic_typec_port->vdd_vbus);
>  
> +	connector = device_get_named_child_node(dev, "connector");
> +	if (connector) {
> +		pmic_typec_port->vbus_detect_gpio =
> +			devm_fwnode_gpiod_get(dev, connector, "vbus",
> +					      GPIOD_IN, NULL);
> +		fwnode_handle_put(connector);
> +
> +		if (IS_ERR(pmic_typec_port->vbus_detect_gpio)) {
> +			ret = PTR_ERR(pmic_typec_port->vbus_detect_gpio);
> +			pmic_typec_port->vbus_detect_gpio = NULL;
> +			if (ret != -ENOENT)
> +				return dev_err_probe(dev, ret,
> +						     "failed to get vbus GPIO\n");
> +		}
> +	}
> +
>  	pmic_typec_port->dev = dev;
>  	pmic_typec_port->base = base;
>  	pmic_typec_port->regmap = regmap;
> 
> ---
> base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
> change-id: 20260308-qcom-typec-shared-vbus-7d37c6b2d155
> 
> Best regards,
> -- 
> Alexander Koskovich <akoskovich@pm.me>
> 

-- 
heikki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection
  2026-03-12  6:16 [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection Alexander Koskovich
  2026-03-12 10:04 ` Bryan O'Donoghue
  2026-03-13  8:46 ` Heikki Krogerus
@ 2026-03-19 13:26 ` Konrad Dybcio
  2026-03-19 19:57   ` Dmitry Baryshkov
  2 siblings, 1 reply; 7+ messages in thread
From: Konrad Dybcio @ 2026-03-19 13:26 UTC (permalink / raw)
  To: Alexander Koskovich, Bryan O'Donoghue, Greg Kroah-Hartman,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heikki Krogerus
  Cc: linux-arm-msm, linux-usb, devicetree, linux-kernel

On 3/12/26 7:16 AM, Alexander Koskovich wrote:
> This is required for devices (e.g. ASUS ROG Phone 3) where more than
> one USB port can act as a sink and both share a single USBIN input on
> the PMIC.
> 
> Because the PM8150B uses USBIN to determine VBUS presence, a charger
> connected to one port causes the PMIC to falsely detect VBUS on the
> other port, preventing it from entering source mode.
> 
> For example, plugging a charger into one port prevents using the other
> port for a flash drive.
> 
> Fix this by adding support for the vbus-gpios connector binding so the
> driver can use an external GPIO for per-port VBUS presence detection
> instead of the shared USBIN register.
> 
> Signed-off-by: Alexander Koskovich <akoskovich@pm.me>
> ---
> Changes in v2:
> - Dropped RFC prefix
> - Remove redundant vbus-detect-gpios, instead use existing vbus-gpios from usb-connector (Dmitry)
> - Updated cover to better describe scenario where this change is relevant
> - Update comment for EN_TRY_SRC to make more sense
> - Skip vSafe5V poll too not just vSafe0V
> - return gpiod_get_value_cansleep (Konrad)
> - regmap_update_bits -> regmap_set_bits (Konrad)
> - Get vbus-gpios per connector (Konrad)
> - Add bracket to if (IS_ERR(pmic_typec_port->vbus_detect_gpio)) (Bryan)
> - Link to v1: https://lore.kernel.org/r/20260308-qcom-typec-shared-vbus-v1-0-7d574b91052a@pm.me
> ---
>  drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 53 +++++++++++++++++++++-
>  1 file changed, 52 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> index 8051eaa46991..a8f6687a3522 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> @@ -5,6 +5,7 @@
>  
>  #include <linux/delay.h>
>  #include <linux/err.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/interrupt.h>
>  #include <linux/kernel.h>
>  #include <linux/mod_devicetable.h>
> @@ -176,6 +177,8 @@ struct pmic_typec_port {
>  	bool				vbus_enabled;
>  	struct mutex			vbus_lock;		/* VBUS state serialization */
>  
> +	struct gpio_desc		*vbus_detect_gpio;

I'd like for this to include the word 'secondary', since it's not obvious
that if an external GPIO is at play, we have two ports connected in this
uhh non-standard fashion

perhaps just secondary_vbus_detect_gpio

Konrad

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection
  2026-03-19 13:26 ` Konrad Dybcio
@ 2026-03-19 19:57   ` Dmitry Baryshkov
  2026-03-20 10:03     ` Bryan O'Donoghue
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Baryshkov @ 2026-03-19 19:57 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Alexander Koskovich, Bryan O'Donoghue, Greg Kroah-Hartman,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heikki Krogerus,
	linux-arm-msm, linux-usb, devicetree, linux-kernel

On Thu, Mar 19, 2026 at 02:26:00PM +0100, Konrad Dybcio wrote:
> On 3/12/26 7:16 AM, Alexander Koskovich wrote:
> > This is required for devices (e.g. ASUS ROG Phone 3) where more than
> > one USB port can act as a sink and both share a single USBIN input on
> > the PMIC.
> > 
> > Because the PM8150B uses USBIN to determine VBUS presence, a charger
> > connected to one port causes the PMIC to falsely detect VBUS on the
> > other port, preventing it from entering source mode.
> > 
> > For example, plugging a charger into one port prevents using the other
> > port for a flash drive.
> > 
> > Fix this by adding support for the vbus-gpios connector binding so the
> > driver can use an external GPIO for per-port VBUS presence detection
> > instead of the shared USBIN register.
> > 
> > Signed-off-by: Alexander Koskovich <akoskovich@pm.me>
> > ---
> > Changes in v2:
> > - Dropped RFC prefix
> > - Remove redundant vbus-detect-gpios, instead use existing vbus-gpios from usb-connector (Dmitry)
> > - Updated cover to better describe scenario where this change is relevant
> > - Update comment for EN_TRY_SRC to make more sense
> > - Skip vSafe5V poll too not just vSafe0V
> > - return gpiod_get_value_cansleep (Konrad)
> > - regmap_update_bits -> regmap_set_bits (Konrad)
> > - Get vbus-gpios per connector (Konrad)
> > - Add bracket to if (IS_ERR(pmic_typec_port->vbus_detect_gpio)) (Bryan)
> > - Link to v1: https://lore.kernel.org/r/20260308-qcom-typec-shared-vbus-v1-0-7d574b91052a@pm.me
> > ---
> >  drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 53 +++++++++++++++++++++-
> >  1 file changed, 52 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> > index 8051eaa46991..a8f6687a3522 100644
> > --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> > +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
> > @@ -5,6 +5,7 @@
> >  
> >  #include <linux/delay.h>
> >  #include <linux/err.h>
> > +#include <linux/gpio/consumer.h>
> >  #include <linux/interrupt.h>
> >  #include <linux/kernel.h>
> >  #include <linux/mod_devicetable.h>
> > @@ -176,6 +177,8 @@ struct pmic_typec_port {
> >  	bool				vbus_enabled;
> >  	struct mutex			vbus_lock;		/* VBUS state serialization */
> >  
> > +	struct gpio_desc		*vbus_detect_gpio;
> 
> I'd like for this to include the word 'secondary', since it's not obvious
> that if an external GPIO is at play, we have two ports connected in this
> uhh non-standard fashion
> 
> perhaps just secondary_vbus_detect_gpio

In theory it can be used even if we have one port.

-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection
  2026-03-19 19:57   ` Dmitry Baryshkov
@ 2026-03-20 10:03     ` Bryan O'Donoghue
  2026-03-23  9:36       ` Konrad Dybcio
  0 siblings, 1 reply; 7+ messages in thread
From: Bryan O'Donoghue @ 2026-03-20 10:03 UTC (permalink / raw)
  To: Dmitry Baryshkov, Konrad Dybcio
  Cc: Alexander Koskovich, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Heikki Krogerus, linux-arm-msm,
	linux-usb, devicetree, linux-kernel

On 19/03/2026 19:57, Dmitry Baryshkov wrote:
> On Thu, Mar 19, 2026 at 02:26:00PM +0100, Konrad Dybcio wrote:
>> On 3/12/26 7:16 AM, Alexander Koskovich wrote:
>>> This is required for devices (e.g. ASUS ROG Phone 3) where more than
>>> one USB port can act as a sink and both share a single USBIN input on
>>> the PMIC.
>>>
>>> Because the PM8150B uses USBIN to determine VBUS presence, a charger
>>> connected to one port causes the PMIC to falsely detect VBUS on the
>>> other port, preventing it from entering source mode.
>>>
>>> For example, plugging a charger into one port prevents using the other
>>> port for a flash drive.
>>>
>>> Fix this by adding support for the vbus-gpios connector binding so the
>>> driver can use an external GPIO for per-port VBUS presence detection
>>> instead of the shared USBIN register.
>>>
>>> Signed-off-by: Alexander Koskovich <akoskovich@pm.me>
>>> ---
>>> Changes in v2:
>>> - Dropped RFC prefix
>>> - Remove redundant vbus-detect-gpios, instead use existing vbus-gpios from usb-connector (Dmitry)
>>> - Updated cover to better describe scenario where this change is relevant
>>> - Update comment for EN_TRY_SRC to make more sense
>>> - Skip vSafe5V poll too not just vSafe0V
>>> - return gpiod_get_value_cansleep (Konrad)
>>> - regmap_update_bits -> regmap_set_bits (Konrad)
>>> - Get vbus-gpios per connector (Konrad)
>>> - Add bracket to if (IS_ERR(pmic_typec_port->vbus_detect_gpio)) (Bryan)
>>> - Link to v1: https://lore.kernel.org/r/20260308-qcom-typec-shared-vbus-v1-0-7d574b91052a@pm.me
>>> ---
>>>   drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 53 +++++++++++++++++++++-
>>>   1 file changed, 52 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
>>> index 8051eaa46991..a8f6687a3522 100644
>>> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
>>> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
>>> @@ -5,6 +5,7 @@
>>>   
>>>   #include <linux/delay.h>
>>>   #include <linux/err.h>
>>> +#include <linux/gpio/consumer.h>
>>>   #include <linux/interrupt.h>
>>>   #include <linux/kernel.h>
>>>   #include <linux/mod_devicetable.h>
>>> @@ -176,6 +177,8 @@ struct pmic_typec_port {
>>>   	bool				vbus_enabled;
>>>   	struct mutex			vbus_lock;		/* VBUS state serialization */
>>>   
>>> +	struct gpio_desc		*vbus_detect_gpio;
>>
>> I'd like for this to include the word 'secondary', since it's not obvious
>> that if an external GPIO is at play, we have two ports connected in this
>> uhh non-standard fashion
>>
>> perhaps just secondary_vbus_detect_gpio
> 
> In theory it can be used even if we have one port.
> 

That's true.

Its quite common in OTG devices to have VBUS detect GPIOs.

---
bod

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection
  2026-03-20 10:03     ` Bryan O'Donoghue
@ 2026-03-23  9:36       ` Konrad Dybcio
  0 siblings, 0 replies; 7+ messages in thread
From: Konrad Dybcio @ 2026-03-23  9:36 UTC (permalink / raw)
  To: Bryan O'Donoghue, Dmitry Baryshkov
  Cc: Alexander Koskovich, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Heikki Krogerus, linux-arm-msm,
	linux-usb, devicetree, linux-kernel

On 3/20/26 11:03 AM, Bryan O'Donoghue wrote:
> On 19/03/2026 19:57, Dmitry Baryshkov wrote:
>> On Thu, Mar 19, 2026 at 02:26:00PM +0100, Konrad Dybcio wrote:
>>> On 3/12/26 7:16 AM, Alexander Koskovich wrote:
>>>> This is required for devices (e.g. ASUS ROG Phone 3) where more than
>>>> one USB port can act as a sink and both share a single USBIN input on
>>>> the PMIC.
>>>>
>>>> Because the PM8150B uses USBIN to determine VBUS presence, a charger
>>>> connected to one port causes the PMIC to falsely detect VBUS on the
>>>> other port, preventing it from entering source mode.
>>>>
>>>> For example, plugging a charger into one port prevents using the other
>>>> port for a flash drive.
>>>>
>>>> Fix this by adding support for the vbus-gpios connector binding so the
>>>> driver can use an external GPIO for per-port VBUS presence detection
>>>> instead of the shared USBIN register.
>>>>
>>>> Signed-off-by: Alexander Koskovich <akoskovich@pm.me>
>>>> ---
>>>> Changes in v2:
>>>> - Dropped RFC prefix
>>>> - Remove redundant vbus-detect-gpios, instead use existing vbus-gpios from usb-connector (Dmitry)
>>>> - Updated cover to better describe scenario where this change is relevant
>>>> - Update comment for EN_TRY_SRC to make more sense
>>>> - Skip vSafe5V poll too not just vSafe0V
>>>> - return gpiod_get_value_cansleep (Konrad)
>>>> - regmap_update_bits -> regmap_set_bits (Konrad)
>>>> - Get vbus-gpios per connector (Konrad)
>>>> - Add bracket to if (IS_ERR(pmic_typec_port->vbus_detect_gpio)) (Bryan)
>>>> - Link to v1: https://lore.kernel.org/r/20260308-qcom-typec-shared-vbus-v1-0-7d574b91052a@pm.me
>>>> ---
>>>>   drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 53 +++++++++++++++++++++-
>>>>   1 file changed, 52 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
>>>> index 8051eaa46991..a8f6687a3522 100644
>>>> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
>>>> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
>>>> @@ -5,6 +5,7 @@
>>>>     #include <linux/delay.h>
>>>>   #include <linux/err.h>
>>>> +#include <linux/gpio/consumer.h>
>>>>   #include <linux/interrupt.h>
>>>>   #include <linux/kernel.h>
>>>>   #include <linux/mod_devicetable.h>
>>>> @@ -176,6 +177,8 @@ struct pmic_typec_port {
>>>>       bool                vbus_enabled;
>>>>       struct mutex            vbus_lock;        /* VBUS state serialization */
>>>>   +    struct gpio_desc        *vbus_detect_gpio;
>>>
>>> I'd like for this to include the word 'secondary', since it's not obvious
>>> that if an external GPIO is at play, we have two ports connected in this
>>> uhh non-standard fashion
>>>
>>> perhaps just secondary_vbus_detect_gpio
>>
>> In theory it can be used even if we have one port.
>>
> 
> That's true.
> 
> Its quite common in OTG devices to have VBUS detect GPIOs.

Sure, that's true for the qcom_pmic_typec_port_vbus_detect() part, but
this also triggers the 'TRY_SRC/TRY_SNK' and 'bypass VSAFE0V' workarounds
which I would assume would not necessary in that case

Konrad

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-23  9:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12  6:16 [PATCH v2] usb: typec: qcom: Add support for per port VBUS detection Alexander Koskovich
2026-03-12 10:04 ` Bryan O'Donoghue
2026-03-13  8:46 ` Heikki Krogerus
2026-03-19 13:26 ` Konrad Dybcio
2026-03-19 19:57   ` Dmitry Baryshkov
2026-03-20 10:03     ` Bryan O'Donoghue
2026-03-23  9:36       ` Konrad Dybcio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox