devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7 0/2] Implement vbus support for HD3SS3220 port controller
@ 2025-11-11  7:20 Krishna Kurapati
  2025-11-11  7:20 ` [PATCH v7 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state Krishna Kurapati
  2025-11-11  7:20 ` [PATCH v7 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
  0 siblings, 2 replies; 5+ messages in thread
From: Krishna Kurapati @ 2025-11-11  7:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Heikki Krogerus, Biju Das, Dmitry Baryshkov
  Cc: linux-usb, devicetree, linux-kernel, Krishna Kurapati

As per the data sheet of HD3SS3220:

"Upon detecting a UFP device, HD3SS3220 will keep ID pin high if VBUS is
not at VSafe0V. Once VBUS is at VSafe0V, the HD3SS3220 will assert ID pin
low. This is done to enforce Type-C requirement that VBUS must be at
VSafe0V before re-enabling VBUS"

This series implements support to read ID pin state and accordingly enable
VBUS.

---
Changes in v7:
- Removed check for id pin validity in ID isr routine.
- Made changes to request ID Pin only if vbus is present.
- Checking for return value of regulator disable as well.
- Reordered variables in beginning of probe to be in reverse xmas order

Link to v6:
https://lore.kernel.org/all/20251102164819.2798754-1-krishna.kurapati@oss.qualcomm.com/

Changes in v6:
- Modified logic to get vbus from connector as per comments received on v5.

Link to v5:
https://lore.kernel.org/all/20251027072741.1050177-1-krishna.kurapati@oss.qualcomm.com/

Changes in v5:
- Modified error handling in driver as per comments received on v4.

Link to v4:
https://lore.kernel.org/all/20251025122854.1163275-1-krishna.kurapati@oss.qualcomm.com/

Changes in v4:
- Modified logic to check for vbus supply. Directly checking first remote
  endpoint.
- Used of_regulator_get_optional instead of of_regulator_get

Link to v3:
https://lore.kernel.org/all/20251024181832.2744502-1-krishna.kurapati@oss.qualcomm.com/

Changes in v3:
- Removed vbus supply from hd3ss3220 bindings.
- Implemented getting vbus from connector node.

Link to v2:
https://lore.kernel.org/all/20251008175750.1770454-1-krishna.kurapati@oss.qualcomm.com/

Changes in v2:
- Fixed inclusion of header files appropriately.
- Modified commit text for driver patch.

Link to v1:
https://lore.kernel.org/all/20251002172539.586538-1-krishna.kurapati@oss.qualcomm.com/

Krishna Kurapati (2):
  dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state
  usb: typec: hd3ss3220: Enable VBUS based on ID pin state

 .../devicetree/bindings/usb/ti,hd3ss3220.yaml |  8 ++
 drivers/usb/typec/hd3ss3220.c                 | 75 ++++++++++++++++++-
 2 files changed, 81 insertions(+), 2 deletions(-)

-- 
2.34.1


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

* [PATCH v7 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state
  2025-11-11  7:20 [PATCH v7 0/2] Implement vbus support for HD3SS3220 port controller Krishna Kurapati
@ 2025-11-11  7:20 ` Krishna Kurapati
  2025-11-11  7:20 ` [PATCH v7 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
  1 sibling, 0 replies; 5+ messages in thread
From: Krishna Kurapati @ 2025-11-11  7:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Heikki Krogerus, Biju Das, Dmitry Baryshkov
  Cc: linux-usb, devicetree, linux-kernel, Krishna Kurapati

Update the bindings to support reading ID state and VBUS, as per the
HD3SS3220 data sheet. The ID pin is kept high if VBUS is not at VSafe0V and
asserted low once VBUS is at VSafe0V, enforcing the Type-C requirement that
VBUS must be at VSafe0V before re-enabling VBUS.

Add id-gpios property to describe the input gpio for USB ID pin.

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
---
 Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml b/Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml
index bec1c8047bc0..06099e93c6c3 100644
--- a/Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml
+++ b/Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml
@@ -25,6 +25,14 @@ properties:
   interrupts:
     maxItems: 1
 
+  id-gpios:
+    description:
+      An input gpio for USB ID pin. Upon detecting a UFP device, HD3SS3220
+      will keep ID pin high if VBUS is not at VSafe0V. Once VBUS is at VSafe0V,
+      the HD3SS3220 will assert ID pin low. This is done to enforce Type-C
+      requirement that VBUS must be at VSafe0V before re-enabling VBUS.
+    maxItems: 1
+
   ports:
     $ref: /schemas/graph.yaml#/properties/ports
     description: OF graph bindings (specified in bindings/graph.txt) that model
-- 
2.34.1


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

* [PATCH v7 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
  2025-11-11  7:20 [PATCH v7 0/2] Implement vbus support for HD3SS3220 port controller Krishna Kurapati
  2025-11-11  7:20 ` [PATCH v7 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state Krishna Kurapati
@ 2025-11-11  7:20 ` Krishna Kurapati
  2025-11-17  8:42   ` Heikki Krogerus
  2025-11-26 12:27   ` Andy Shevchenko
  1 sibling, 2 replies; 5+ messages in thread
From: Krishna Kurapati @ 2025-11-11  7:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Heikki Krogerus, Biju Das, Dmitry Baryshkov
  Cc: linux-usb, devicetree, linux-kernel, Krishna Kurapati

There is a ID pin present on HD3SS3220 controller that can be routed
to SoC. As per the datasheet:

"Upon detecting a UFP device, HD3SS3220 will keep ID pin high if VBUS is
not at VSafe0V. Once VBUS is at VSafe0V, the HD3SS3220 will assert ID pin
low. This is done to enforce Type-C requirement that VBUS must be at
VSafe0V before re-enabling VBUS"

Add support to read the ID pin state and enable VBUS accordingly.

Signed-off-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
---
 drivers/usb/typec/hd3ss3220.c | 75 ++++++++++++++++++++++++++++++++++-
 1 file changed, 73 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
index 3ecc688dda82..3876f4faead6 100644
--- a/drivers/usb/typec/hd3ss3220.c
+++ b/drivers/usb/typec/hd3ss3220.c
@@ -15,6 +15,9 @@
 #include <linux/usb/typec.h>
 #include <linux/delay.h>
 #include <linux/workqueue.h>
+#include <linux/gpio/consumer.h>
+#include <linux/regulator/consumer.h>
+#include <linux/of_graph.h>
 
 #define HD3SS3220_REG_CN_STAT		0x08
 #define HD3SS3220_REG_CN_STAT_CTRL	0x09
@@ -54,6 +57,11 @@ struct hd3ss3220 {
 	struct delayed_work output_poll_work;
 	enum usb_role role_state;
 	bool poll;
+
+	struct gpio_desc *id_gpiod;
+	int id_irq;
+
+	struct regulator *vbus;
 };
 
 static int hd3ss3220_set_power_opmode(struct hd3ss3220 *hd3ss3220, int power_opmode)
@@ -319,13 +327,33 @@ static const struct regmap_config config = {
 	.max_register = 0x0A,
 };
 
+static irqreturn_t hd3ss3220_id_isr(int irq, void *dev_id)
+{
+	struct hd3ss3220 *hd3ss3220 = dev_id;
+	int ret;
+	int id;
+
+	id = gpiod_get_value_cansleep(hd3ss3220->id_gpiod);
+	if (!id)
+		ret = regulator_enable(hd3ss3220->vbus);
+	else
+		ret = regulator_disable(hd3ss3220->vbus);
+
+	if (ret)
+		dev_err(hd3ss3220->dev,
+			"vbus regulator %s failed: %d\n", id ? "disable" : "enable", ret);
+
+	return IRQ_HANDLED;
+}
+
 static int hd3ss3220_probe(struct i2c_client *client)
 {
 	struct typec_capability typec_cap = { };
-	struct hd3ss3220 *hd3ss3220;
 	struct fwnode_handle *connector, *ep;
-	int ret;
+	struct hd3ss3220 *hd3ss3220;
+	struct regulator *vbus;
 	unsigned int data;
+	int ret;
 
 	hd3ss3220 = devm_kzalloc(&client->dev, sizeof(struct hd3ss3220),
 				 GFP_KERNEL);
@@ -359,6 +387,49 @@ static int hd3ss3220_probe(struct i2c_client *client)
 		goto err_put_fwnode;
 	}
 
+	vbus = devm_of_regulator_get_optional(hd3ss3220->dev,
+					      to_of_node(connector),
+					      "vbus");
+	if (IS_ERR(vbus) && vbus != ERR_PTR(-ENODEV)) {
+		ret = PTR_ERR(vbus);
+		dev_err(hd3ss3220->dev, "failed to get vbus: %d", ret);
+		goto err_put_fwnode;
+	}
+
+	hd3ss3220->vbus = (vbus == ERR_PTR(-ENODEV) ? NULL : vbus);
+
+	if (hd3ss3220->vbus) {
+		hd3ss3220->id_gpiod = devm_gpiod_get_optional(hd3ss3220->dev,
+							      "id",
+							      GPIOD_IN);
+		if (IS_ERR(hd3ss3220->id_gpiod)) {
+			ret = PTR_ERR(hd3ss3220->id_gpiod);
+			goto err_put_fwnode;
+		}
+	}
+
+	if (hd3ss3220->id_gpiod) {
+		hd3ss3220->id_irq = gpiod_to_irq(hd3ss3220->id_gpiod);
+		if (hd3ss3220->id_irq < 0) {
+			ret = hd3ss3220->id_irq;
+			dev_err(hd3ss3220->dev,
+				"failed to get ID gpio: %d\n",
+				hd3ss3220->id_irq);
+			goto err_put_fwnode;
+		}
+
+		ret = devm_request_threaded_irq(hd3ss3220->dev,
+						hd3ss3220->id_irq, NULL,
+						hd3ss3220_id_isr,
+						IRQF_TRIGGER_RISING |
+						IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+						dev_name(hd3ss3220->dev), hd3ss3220);
+		if (ret < 0) {
+			dev_err(hd3ss3220->dev, "failed to get ID irq: %d\n", ret);
+			goto err_put_fwnode;
+		}
+	}
+
 	typec_cap.prefer_role = TYPEC_NO_PREFERRED_ROLE;
 	typec_cap.driver_data = hd3ss3220;
 	typec_cap.type = TYPEC_PORT_DRP;
-- 
2.34.1


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

* Re: [PATCH v7 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
  2025-11-11  7:20 ` [PATCH v7 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
@ 2025-11-17  8:42   ` Heikki Krogerus
  2025-11-26 12:27   ` Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Heikki Krogerus @ 2025-11-17  8:42 UTC (permalink / raw)
  To: Krishna Kurapati
  Cc: Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Biju Das, Dmitry Baryshkov, linux-usb, devicetree,
	linux-kernel

Tue, Nov 11, 2025 at 12:50:25PM +0530, Krishna Kurapati kirjoitti:
> There is a ID pin present on HD3SS3220 controller that can be routed
> to SoC. As per the datasheet:
> 
> "Upon detecting a UFP device, HD3SS3220 will keep ID pin high if VBUS is
> not at VSafe0V. Once VBUS is at VSafe0V, the HD3SS3220 will assert ID pin
> low. This is done to enforce Type-C requirement that VBUS must be at
> VSafe0V before re-enabling VBUS"
> 
> Add support to read the ID pin state and enable VBUS accordingly.
> 
> Signed-off-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>

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

> ---
>  drivers/usb/typec/hd3ss3220.c | 75 ++++++++++++++++++++++++++++++++++-
>  1 file changed, 73 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
> index 3ecc688dda82..3876f4faead6 100644
> --- a/drivers/usb/typec/hd3ss3220.c
> +++ b/drivers/usb/typec/hd3ss3220.c
> @@ -15,6 +15,9 @@
>  #include <linux/usb/typec.h>
>  #include <linux/delay.h>
>  #include <linux/workqueue.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/of_graph.h>
>  
>  #define HD3SS3220_REG_CN_STAT		0x08
>  #define HD3SS3220_REG_CN_STAT_CTRL	0x09
> @@ -54,6 +57,11 @@ struct hd3ss3220 {
>  	struct delayed_work output_poll_work;
>  	enum usb_role role_state;
>  	bool poll;
> +
> +	struct gpio_desc *id_gpiod;
> +	int id_irq;
> +
> +	struct regulator *vbus;
>  };
>  
>  static int hd3ss3220_set_power_opmode(struct hd3ss3220 *hd3ss3220, int power_opmode)
> @@ -319,13 +327,33 @@ static const struct regmap_config config = {
>  	.max_register = 0x0A,
>  };
>  
> +static irqreturn_t hd3ss3220_id_isr(int irq, void *dev_id)
> +{
> +	struct hd3ss3220 *hd3ss3220 = dev_id;
> +	int ret;
> +	int id;
> +
> +	id = gpiod_get_value_cansleep(hd3ss3220->id_gpiod);
> +	if (!id)
> +		ret = regulator_enable(hd3ss3220->vbus);
> +	else
> +		ret = regulator_disable(hd3ss3220->vbus);
> +
> +	if (ret)
> +		dev_err(hd3ss3220->dev,
> +			"vbus regulator %s failed: %d\n", id ? "disable" : "enable", ret);
> +
> +	return IRQ_HANDLED;
> +}
> +
>  static int hd3ss3220_probe(struct i2c_client *client)
>  {
>  	struct typec_capability typec_cap = { };
> -	struct hd3ss3220 *hd3ss3220;
>  	struct fwnode_handle *connector, *ep;
> -	int ret;
> +	struct hd3ss3220 *hd3ss3220;
> +	struct regulator *vbus;
>  	unsigned int data;
> +	int ret;
>  
>  	hd3ss3220 = devm_kzalloc(&client->dev, sizeof(struct hd3ss3220),
>  				 GFP_KERNEL);
> @@ -359,6 +387,49 @@ static int hd3ss3220_probe(struct i2c_client *client)
>  		goto err_put_fwnode;
>  	}
>  
> +	vbus = devm_of_regulator_get_optional(hd3ss3220->dev,
> +					      to_of_node(connector),
> +					      "vbus");
> +	if (IS_ERR(vbus) && vbus != ERR_PTR(-ENODEV)) {
> +		ret = PTR_ERR(vbus);
> +		dev_err(hd3ss3220->dev, "failed to get vbus: %d", ret);
> +		goto err_put_fwnode;
> +	}
> +
> +	hd3ss3220->vbus = (vbus == ERR_PTR(-ENODEV) ? NULL : vbus);
> +
> +	if (hd3ss3220->vbus) {
> +		hd3ss3220->id_gpiod = devm_gpiod_get_optional(hd3ss3220->dev,
> +							      "id",
> +							      GPIOD_IN);
> +		if (IS_ERR(hd3ss3220->id_gpiod)) {
> +			ret = PTR_ERR(hd3ss3220->id_gpiod);
> +			goto err_put_fwnode;
> +		}
> +	}
> +
> +	if (hd3ss3220->id_gpiod) {
> +		hd3ss3220->id_irq = gpiod_to_irq(hd3ss3220->id_gpiod);
> +		if (hd3ss3220->id_irq < 0) {
> +			ret = hd3ss3220->id_irq;
> +			dev_err(hd3ss3220->dev,
> +				"failed to get ID gpio: %d\n",
> +				hd3ss3220->id_irq);
> +			goto err_put_fwnode;
> +		}
> +
> +		ret = devm_request_threaded_irq(hd3ss3220->dev,
> +						hd3ss3220->id_irq, NULL,
> +						hd3ss3220_id_isr,
> +						IRQF_TRIGGER_RISING |
> +						IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> +						dev_name(hd3ss3220->dev), hd3ss3220);
> +		if (ret < 0) {
> +			dev_err(hd3ss3220->dev, "failed to get ID irq: %d\n", ret);
> +			goto err_put_fwnode;
> +		}
> +	}
> +
>  	typec_cap.prefer_role = TYPEC_NO_PREFERRED_ROLE;
>  	typec_cap.driver_data = hd3ss3220;
>  	typec_cap.type = TYPEC_PORT_DRP;
> -- 
> 2.34.1

-- 
heikki

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

* Re: [PATCH v7 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
  2025-11-11  7:20 ` [PATCH v7 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
  2025-11-17  8:42   ` Heikki Krogerus
@ 2025-11-26 12:27   ` Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2025-11-26 12:27 UTC (permalink / raw)
  To: Krishna Kurapati
  Cc: Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Heikki Krogerus, Biju Das, Dmitry Baryshkov,
	linux-usb, devicetree, linux-kernel

On Tue, Nov 11, 2025 at 12:50:25PM +0530, Krishna Kurapati wrote:
> There is a ID pin present on HD3SS3220 controller that can be routed
> to SoC. As per the datasheet:
> 
> "Upon detecting a UFP device, HD3SS3220 will keep ID pin high if VBUS is
> not at VSafe0V. Once VBUS is at VSafe0V, the HD3SS3220 will assert ID pin
> low. This is done to enforce Type-C requirement that VBUS must be at
> VSafe0V before re-enabling VBUS"
> 
> Add support to read the ID pin state and enable VBUS accordingly.

...

> +	if (hd3ss3220->vbus) {
> +		hd3ss3220->id_gpiod = devm_gpiod_get_optional(hd3ss3220->dev,
> +							      "id",
> +							      GPIOD_IN);

Can be also

		ret = PTR_ERR_OR_ZERO(hd3ss3220->id_gpiod);
		if (IS_ERR(hd3ss3220->id_gpiod))
			goto err_put_fwnode;

> +		if (IS_ERR(hd3ss3220->id_gpiod)) {

> +		if (IS_ERR(hd3ss3220->id_gpiod)) {
> +			ret = PTR_ERR(hd3ss3220->id_gpiod);
> +			goto err_put_fwnode;
> +		}
> +	}

...

> +		ret = devm_request_threaded_irq(hd3ss3220->dev,
> +						hd3ss3220->id_irq, NULL,
> +						hd3ss3220_id_isr,
> +						IRQF_TRIGGER_RISING |
> +						IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> +						dev_name(hd3ss3220->dev), hd3ss3220);
> +		if (ret < 0) {
> +			dev_err(hd3ss3220->dev, "failed to get ID irq: %d\n", ret);

The above call already prints an error message, no need to repeat it here.

> +			goto err_put_fwnode;
> +		}

Since the patch is already applied, please send a followup for the second one
(the first one is up to you, just a hint for the future code contributions).

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2025-11-26 12:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-11  7:20 [PATCH v7 0/2] Implement vbus support for HD3SS3220 port controller Krishna Kurapati
2025-11-11  7:20 ` [PATCH v7 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state Krishna Kurapati
2025-11-11  7:20 ` [PATCH v7 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
2025-11-17  8:42   ` Heikki Krogerus
2025-11-26 12:27   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).