* [PATCH v4 0/2] Implement vbus support for HD3SS3220 port controller
@ 2025-10-25 12:28 Krishna Kurapati
2025-10-25 12:28 ` [PATCH v4 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state Krishna Kurapati
2025-10-25 12:28 ` [PATCH v4 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-10-25 12:28 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 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 | 9 +++
drivers/usb/typec/hd3ss3220.c | 79 +++++++++++++++++++
2 files changed, 88 insertions(+)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state
2025-10-25 12:28 [PATCH v4 0/2] Implement vbus support for HD3SS3220 port controller Krishna Kurapati
@ 2025-10-25 12:28 ` Krishna Kurapati
2025-10-25 12:28 ` [PATCH v4 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-10-25 12:28 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.
Signed-off-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
---
Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml b/Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml
index bec1c8047bc0..7ad79aa61efe 100644
--- a/Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml
+++ b/Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml
@@ -25,6 +25,15 @@ 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 [flat|nested] 5+ messages in thread
* [PATCH v4 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
2025-10-25 12:28 [PATCH v4 0/2] Implement vbus support for HD3SS3220 port controller Krishna Kurapati
2025-10-25 12:28 ` [PATCH v4 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state Krishna Kurapati
@ 2025-10-25 12:28 ` Krishna Kurapati
2025-10-25 14:14 ` Christophe JAILLET
1 sibling, 1 reply; 5+ messages in thread
From: Krishna Kurapati @ 2025-10-25 12:28 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 | 79 +++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
index 3ecc688dda82..970c0ca8f8d4 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,6 +327,49 @@ 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;
+
+ if (IS_ERR_OR_NULL(hd3ss3220->vbus))
+ return IRQ_HANDLED;
+
+ id = hd3ss3220->id_gpiod ? gpiod_get_value_cansleep(hd3ss3220->id_gpiod) : 1;
+
+ if (!id) {
+ ret = regulator_enable(hd3ss3220->vbus);
+ if (ret)
+ dev_err(hd3ss3220->dev, "enable vbus regulator failed\n");
+ } else {
+ regulator_disable(hd3ss3220->vbus);
+ }
+
+ return IRQ_HANDLED;
+}
+
+static int hd3ss3220_get_vbus_supply(struct hd3ss3220 *hd3ss3220)
+{
+ struct device_node *hd3ss3220_node = hd3ss3220->dev->of_node;
+ struct device_node *np;
+ int ret = 0;
+
+ np = of_graph_get_remote_node(hd3ss3220_node, 0, 0);
+ if (!np) {
+ dev_err(hd3ss3220->dev, "failed to get device node");
+ return -ENODEV;
+ }
+
+ hd3ss3220->vbus = of_regulator_get_optional(hd3ss3220->dev, np, "vbus");
+ if (IS_ERR(hd3ss3220->vbus))
+ hd3ss3220->vbus = NULL;
+
+ of_node_put(np);
+
+ return ret;
+}
+
static int hd3ss3220_probe(struct i2c_client *client)
{
struct typec_capability typec_cap = { };
@@ -354,6 +405,34 @@ static int hd3ss3220_probe(struct i2c_client *client)
hd3ss3220->role_sw = usb_role_switch_get(hd3ss3220->dev);
}
+ hd3ss3220->id_gpiod = devm_gpiod_get_optional(hd3ss3220->dev, "id", GPIOD_IN);
+ if (IS_ERR(hd3ss3220->id_gpiod))
+ return PTR_ERR(hd3ss3220->id_gpiod);
+
+ if (hd3ss3220->id_gpiod) {
+ hd3ss3220->id_irq = gpiod_to_irq(hd3ss3220->id_gpiod);
+ if (hd3ss3220->id_irq < 0) {
+ dev_err(hd3ss3220->dev, "failed to get ID IRQ\n");
+ return hd3ss3220->id_irq;
+ }
+
+ 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\n");
+ return ret;
+ }
+ }
+
+ ret = hd3ss3220_get_vbus_supply(hd3ss3220);
+ if (ret)
+ return dev_err_probe(hd3ss3220->dev,
+ PTR_ERR(hd3ss3220->vbus), "failed to get vbus\n");
+
if (IS_ERR(hd3ss3220->role_sw)) {
ret = PTR_ERR(hd3ss3220->role_sw);
goto err_put_fwnode;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
2025-10-25 12:28 ` [PATCH v4 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
@ 2025-10-25 14:14 ` Christophe JAILLET
2025-10-26 18:03 ` Krishna Kurapati PSSNV
0 siblings, 1 reply; 5+ messages in thread
From: Christophe JAILLET @ 2025-10-25 14:14 UTC (permalink / raw)
To: krishna.kurapati
Cc: biju.das.jz, conor+dt, devicetree, dmitry.baryshkov, gregkh,
heikki.krogerus, krzk+dt, linux-kernel, linux-usb, robh
Le 25/10/2025 à 14:28, Krishna Kurapati a écrit :
> 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-5oFBVzJwu8Ry9aJCnZT0Uw@public.gmane.org>
> ---
> drivers/usb/typec/hd3ss3220.c | 79 +++++++++++++++++++++++++++++++++++
> 1 file changed, 79 insertions(+)
>
> diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
> index 3ecc688dda82..970c0ca8f8d4 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,6 +327,49 @@ 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;
> +
> + if (IS_ERR_OR_NULL(hd3ss3220->vbus))
I don't think it can be ERR. hd3ss3220_get_vbus_supply() forces it to
NULL in such a case.
> + return IRQ_HANDLED;
> +
> + id = hd3ss3220->id_gpiod ? gpiod_get_value_cansleep(hd3ss3220->id_gpiod) : 1;
> +
> + if (!id) {
> + ret = regulator_enable(hd3ss3220->vbus);
> + if (ret)
> + dev_err(hd3ss3220->dev, "enable vbus regulator failed\n");
> + } else {
> + regulator_disable(hd3ss3220->vbus);
> + }
> +
> + return IRQ_HANDLED;
> +}
> +
> +static int hd3ss3220_get_vbus_supply(struct hd3ss3220 *hd3ss3220)
> +{
> + struct device_node *hd3ss3220_node = hd3ss3220->dev->of_node;
> + struct device_node *np;
> + int ret = 0;
> +
> + np = of_graph_get_remote_node(hd3ss3220_node, 0, 0);
> + if (!np) {
> + dev_err(hd3ss3220->dev, "failed to get device node");
> + return -ENODEV;
> + }
> +
> + hd3ss3220->vbus = of_regulator_get_optional(hd3ss3220->dev, np, "vbus");
> + if (IS_ERR(hd3ss3220->vbus))
> + hd3ss3220->vbus = NULL;
> +
> + of_node_put(np);
> +
> + return ret;
return 0 and avoid 'ret'?
> +}
> +
> static int hd3ss3220_probe(struct i2c_client *client)
> {
> struct typec_capability typec_cap = { };
> @@ -354,6 +405,34 @@ static int hd3ss3220_probe(struct i2c_client *client)
> hd3ss3220->role_sw = usb_role_switch_get(hd3ss3220->dev);
> }
>
> + hd3ss3220->id_gpiod = devm_gpiod_get_optional(hd3ss3220->dev, "id", GPIOD_IN);
> + if (IS_ERR(hd3ss3220->id_gpiod))
> + return PTR_ERR(hd3ss3220->id_gpiod);
> +
> + if (hd3ss3220->id_gpiod) {
> + hd3ss3220->id_irq = gpiod_to_irq(hd3ss3220->id_gpiod);
> + if (hd3ss3220->id_irq < 0) {
> + dev_err(hd3ss3220->dev, "failed to get ID IRQ\n");
Maybe return dev_err_probe() to log the error and simplify code?
> + return hd3ss3220->id_irq;
> + }
> +
> + 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\n");
Maybe return dev_err_probe() to log the error and simplify code?
Above, you use "ID IRQ" and here "id irq". Maybe keep the case case? Or
change the 2nd message that looks a copy'n'paste error to me.
> + return ret;
> + }
> + }
> +
> + ret = hd3ss3220_get_vbus_supply(hd3ss3220);
> + if (ret)
> + return dev_err_probe(hd3ss3220->dev,
> + PTR_ERR(hd3ss3220->vbus), "failed to get vbus\n");
Why PTR_ERR(hd3ss3220->vbus)? Should this be 'ret'?
If hd3ss3220_get_vbus_supply() fails, vbus will be NULL in all cases.
In hd3ss3220_get_vbus_supply(), if -ENODEV is returned, it is not
initialized yet, and if of_regulator_get_optional() fails, it is set to
NULL.
> +
> if (IS_ERR(hd3ss3220->role_sw)) {
> ret = PTR_ERR(hd3ss3220->role_sw);
> goto err_put_fwnode;
CJ
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
2025-10-25 14:14 ` Christophe JAILLET
@ 2025-10-26 18:03 ` Krishna Kurapati PSSNV
0 siblings, 0 replies; 5+ messages in thread
From: Krishna Kurapati PSSNV @ 2025-10-26 18:03 UTC (permalink / raw)
To: Christophe JAILLET
Cc: biju.das.jz, conor+dt, devicetree, dmitry.baryshkov, gregkh,
heikki.krogerus, krzk+dt, linux-kernel, linux-usb, robh
On 10/25/2025 7:44 PM, Christophe JAILLET wrote:
> Le 25/10/2025 à 14:28, Krishna Kurapati a écrit :
>> 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.
>>
[...]
>> +static irqreturn_t hd3ss3220_id_isr(int irq, void *dev_id)
>> +{
>> + struct hd3ss3220 *hd3ss3220 = dev_id;
>> + int ret;
>> + int id;
>> +
>> + if (IS_ERR_OR_NULL(hd3ss3220->vbus))
>
> I don't think it can be ERR. hd3ss3220_get_vbus_supply() forces it to
> NULL in such a case.
>
ACK. Will make it (!hd3ss3220->vbus).
>> + return IRQ_HANDLED;
>> +
>> + id = hd3ss3220->id_gpiod ? gpiod_get_value_cansleep(hd3ss3220-
>> >id_gpiod) : 1;
>> +
>> + if (!id) {
>> + ret = regulator_enable(hd3ss3220->vbus);
>> + if (ret)
>> + dev_err(hd3ss3220->dev, "enable vbus regulator failed\n");
>> + } else {
>> + regulator_disable(hd3ss3220->vbus);
>> + }
>> +
>> + return IRQ_HANDLED;
>> +}
>> +
>> +static int hd3ss3220_get_vbus_supply(struct hd3ss3220 *hd3ss3220)
>> +{
>> + struct device_node *hd3ss3220_node = hd3ss3220->dev->of_node;
>> + struct device_node *np;
>> + int ret = 0;
>> +
>> + np = of_graph_get_remote_node(hd3ss3220_node, 0, 0);
>> + if (!np) {
>> + dev_err(hd3ss3220->dev, "failed to get device node");
>> + return -ENODEV;
>> + }
>> +
>> + hd3ss3220->vbus = of_regulator_get_optional(hd3ss3220->dev, np,
>> "vbus");
>> + if (IS_ERR(hd3ss3220->vbus))
>> + hd3ss3220->vbus = NULL;
>> +
>> + of_node_put(np);
>> +
>> + return ret;
>
> return 0 and avoid 'ret'?
ACK.
>
>> +}
>> +
>> static int hd3ss3220_probe(struct i2c_client *client)
>> {
>> struct typec_capability typec_cap = { };
>> @@ -354,6 +405,34 @@ static int hd3ss3220_probe(struct i2c_client
>> *client)
>> hd3ss3220->role_sw = usb_role_switch_get(hd3ss3220->dev);
>> }
>> + hd3ss3220->id_gpiod = devm_gpiod_get_optional(hd3ss3220->dev,
>> "id", GPIOD_IN);
>> + if (IS_ERR(hd3ss3220->id_gpiod))
>> + return PTR_ERR(hd3ss3220->id_gpiod);
>> +
>> + if (hd3ss3220->id_gpiod) {
>> + hd3ss3220->id_irq = gpiod_to_irq(hd3ss3220->id_gpiod);
>> + if (hd3ss3220->id_irq < 0) {
>> + dev_err(hd3ss3220->dev, "failed to get ID IRQ\n");
>
> Maybe return dev_err_probe() to log the error and simplify code?
>
ACK.
>> + return hd3
ss3220->id_irq;
>> + }
>> +
>> + 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\n");
>
> Maybe return dev_err_probe() to log the error and simplify code?
>
> Above, you use "ID IRQ" and here "id irq". Maybe keep the case case? Or
> change the 2nd message that looks a copy'n'paste error to me.
>
ACK. Will correct it.
>> + return ret;
>> + }
>> + }
>> +
>> + ret = hd3ss3220_get_vbus_supply(hd3ss3220);
>> + if (ret)
>> + return dev_err_probe(hd3ss3220->dev,
>> + PTR_ERR(hd3ss3220->vbus), "failed to get vbus\n");
>
> Why PTR_ERR(hd3ss3220->vbus)? Should this be 'ret'?
>
> If hd3ss3220_get_vbus_supply() fails, vbus will be NULL in all cases.
>
> In hd3ss3220_get_vbus_supply(), if -ENODEV is returned, it is not
> initialized yet, and if of_regulator_get_optional() fails, it is set to
> NULL.
>
Yes, ret is better. Will change it accordingly.
Regards,
Krishna,
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-10-26 18:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-25 12:28 [PATCH v4 0/2] Implement vbus support for HD3SS3220 port controller Krishna Kurapati
2025-10-25 12:28 ` [PATCH v4 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state Krishna Kurapati
2025-10-25 12:28 ` [PATCH v4 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
2025-10-25 14:14 ` Christophe JAILLET
2025-10-26 18:03 ` Krishna Kurapati PSSNV
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®