* [PATCH v6 0/2] Implement vbus support for HD3SS3220 port controller
@ 2025-11-02 16:48 Krishna Kurapati
2025-11-02 16:48 ` [PATCH v6 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state Krishna Kurapati
2025-11-02 16:48 ` [PATCH v6 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
0 siblings, 2 replies; 7+ messages in thread
From: Krishna Kurapati @ 2025-11-02 16:48 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 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 | 72 +++++++++++++++++++
2 files changed, 80 insertions(+)
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state
2025-11-02 16:48 [PATCH v6 0/2] Implement vbus support for HD3SS3220 port controller Krishna Kurapati
@ 2025-11-02 16:48 ` Krishna Kurapati
2025-11-02 16:48 ` [PATCH v6 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
1 sibling, 0 replies; 7+ messages in thread
From: Krishna Kurapati @ 2025-11-02 16:48 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] 7+ messages in thread
* [PATCH v6 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
2025-11-02 16:48 [PATCH v6 0/2] Implement vbus support for HD3SS3220 port controller Krishna Kurapati
2025-11-02 16:48 ` [PATCH v6 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state Krishna Kurapati
@ 2025-11-02 16:48 ` Krishna Kurapati
2025-11-06 10:05 ` Heikki Krogerus
1 sibling, 1 reply; 7+ messages in thread
From: Krishna Kurapati @ 2025-11-02 16:48 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 | 72 +++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
index 3ecc688dda82..75fbda42eaf4 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,44 @@ 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 (!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 fwnode_handle *connector)
+{
+ int ret = 0;
+
+ hd3ss3220->vbus = devm_of_regulator_get_optional(hd3ss3220->dev,
+ to_of_node(connector),
+ "vbus");
+ if (PTR_ERR(hd3ss3220->vbus) == -ENODEV)
+ hd3ss3220->vbus = NULL;
+ else if (IS_ERR(hd3ss3220->vbus))
+ ret = PTR_ERR(hd3ss3220->vbus);
+
+ return ret;
+}
+
static int hd3ss3220_probe(struct i2c_client *client)
{
struct typec_capability typec_cap = { };
@@ -354,11 +400,37 @@ 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)
+ return dev_err_probe(hd3ss3220->dev, hd3ss3220->id_irq,
+ "failed to get ID gpio\n");
+
+ 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)
+ return dev_err_probe(hd3ss3220->dev, ret, "failed to get ID irq\n");
+ }
+
if (IS_ERR(hd3ss3220->role_sw)) {
ret = PTR_ERR(hd3ss3220->role_sw);
goto err_put_fwnode;
}
+ ret = hd3ss3220_get_vbus_supply(hd3ss3220, connector);
+ if (ret) {
+ dev_err(hd3ss3220->dev, "failed to get vbus: %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] 7+ messages in thread
* Re: [PATCH v6 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
2025-11-02 16:48 ` [PATCH v6 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
@ 2025-11-06 10:05 ` Heikki Krogerus
2025-11-06 10:16 ` Heikki Krogerus
2025-11-06 15:31 ` Krishna Kurapati PSSNV
0 siblings, 2 replies; 7+ messages in thread
From: Heikki Krogerus @ 2025-11-06 10:05 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
Hi Krishna,
Sun, Nov 02, 2025 at 10:18:19PM +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>
> ---
> drivers/usb/typec/hd3ss3220.c | 72 +++++++++++++++++++++++++++++++++++
> 1 file changed, 72 insertions(+)
>
> diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
> index 3ecc688dda82..75fbda42eaf4 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,44 @@ 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 (!hd3ss3220->vbus)
> + return IRQ_HANDLED;
If you don't need this routine unless there is a vbus regulator, then
don't register it at all if there is no vbus regulator.
> + id = hd3ss3220->id_gpiod ? gpiod_get_value_cansleep(hd3ss3220->id_gpiod) : 1;
You still don't need to check for hd3ss3220->id_gpiod - this function
will not get called unless it's there.
if (gpiod_get_value_cansleep(hd3ss3220->id_gpiod))
ret = regulator_disable(hd3ss3220->vbus);
else
ret = regulator_enable(hd3ss3220->vbus);
Note:
If you are concerned that the reference to the id_gpiod may be
released before this routine is unregistered, then that condition will
not help. The hd3ss3220->id_gpiod member is _not_ NULL after the
reference is released.
If you need a specific order in which the references are released,
then you can't use the resource management (devm_*) to automate things
for you.
> + 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 fwnode_handle *connector)
> +{
> + int ret = 0;
> +
> + hd3ss3220->vbus = devm_of_regulator_get_optional(hd3ss3220->dev,
> + to_of_node(connector),
> + "vbus");
> + if (PTR_ERR(hd3ss3220->vbus) == -ENODEV)
> + hd3ss3220->vbus = NULL;
> + else if (IS_ERR(hd3ss3220->vbus))
> + ret = PTR_ERR(hd3ss3220->vbus);
So the regulator API's optional functions return -ENODEV instead of NULL :(
In any case, don't double assign the member. Use local variable.
struct regulator *vbus;
vbus = devm_of_regulator_get_optional(...
if (IS_ERR(vbus) && vbus != ERR_PTR(-ENODEV))
return PTR_ERR(vbus);
hd3ss3220->vbus = vbus;
return 0;
I don't think you need this function - just do that in the probe function.
> + return ret;
> +}
> +
> static int hd3ss3220_probe(struct i2c_client *client)
> {
> struct typec_capability typec_cap = { };
> @@ -354,11 +400,37 @@ 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)
> + return dev_err_probe(hd3ss3220->dev, hd3ss3220->id_irq,
> + "failed to get ID gpio\n");
> +
> + 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)
> + return dev_err_probe(hd3ss3220->dev, ret, "failed to get ID irq\n");
> + }
> +
> if (IS_ERR(hd3ss3220->role_sw)) {
> ret = PTR_ERR(hd3ss3220->role_sw);
> goto err_put_fwnode;
> }
>
> + ret = hd3ss3220_get_vbus_supply(hd3ss3220, connector);
> + if (ret) {
> + dev_err(hd3ss3220->dev, "failed to get vbus: %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
thanks,
--
heikki
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
2025-11-06 10:05 ` Heikki Krogerus
@ 2025-11-06 10:16 ` Heikki Krogerus
2025-11-06 15:23 ` Krishna Kurapati PSSNV
2025-11-06 15:31 ` Krishna Kurapati PSSNV
1 sibling, 1 reply; 7+ messages in thread
From: Heikki Krogerus @ 2025-11-06 10:16 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
> struct regulator *vbus;
>
> vbus = devm_of_regulator_get_optional(...
> if (IS_ERR(vbus) && vbus != ERR_PTR(-ENODEV))
> return PTR_ERR(vbus);
>
> hd3ss3220->vbus = vbus;
Sorry, that has to be:
hd3ss3220->vbus = vbus == ERR_PTR(-ENODEV) ? NULL : vbus;
--
heikki
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
2025-11-06 10:16 ` Heikki Krogerus
@ 2025-11-06 15:23 ` Krishna Kurapati PSSNV
0 siblings, 0 replies; 7+ messages in thread
From: Krishna Kurapati PSSNV @ 2025-11-06 15:23 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Biju Das, Dmitry Baryshkov, linux-usb, devicetree,
linux-kernel
On 11/6/2025 3:46 PM, Heikki Krogerus wrote:
>> struct regulator *vbus;
>>
>> vbus = devm_of_regulator_get_optional(...
>> if (IS_ERR(vbus) && vbus != ERR_PTR(-ENODEV))
>> return PTR_ERR(vbus);
>>
>> hd3ss3220->vbus = vbus;
>
> Sorry, that has to be:
>
> hd3ss3220->vbus = vbus == ERR_PTR(-ENODEV) ? NULL : vbus;
>
>
Thanks for the review Heikki.
Will update the suggestions in next revision.
Regards,
Krishna,
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state
2025-11-06 10:05 ` Heikki Krogerus
2025-11-06 10:16 ` Heikki Krogerus
@ 2025-11-06 15:31 ` Krishna Kurapati PSSNV
1 sibling, 0 replies; 7+ messages in thread
From: Krishna Kurapati PSSNV @ 2025-11-06 15:31 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Biju Das, Dmitry Baryshkov, linux-usb, devicetree,
linux-kernel
On 11/6/2025 3:35 PM, Heikki Krogerus wrote:
> Hi Krishna,
>
> Sun, Nov 02, 2025 at 10:18:19PM +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>
>> ---
>> drivers/usb/typec/hd3ss3220.c | 72 +++++++++++++++++++++++++++++++++++
>> 1 file changed, 72 insertions(+)
>>
>> diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
>> index 3ecc688dda82..75fbda42eaf4 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,44 @@ 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 (!hd3ss3220->vbus)
>> + return IRQ_HANDLED;
>
> If you don't need this routine unless there is a vbus regulator, then
> don't register it at all if there is no vbus regulator.
>
Will move vbus check before id retrieval in probe and ignore retrieval
of ID if vbus is absent.
>> + id = hd3ss3220->id_gpiod ? gpiod_get_value_cansleep(hd3ss3220->id_gpiod) : 1;
>
> You still don't need to check for hd3ss3220->id_gpiod - this function
> will not get called unless it's there.
>
> if (gpiod_get_value_cansleep(hd3ss3220->id_gpiod))
> ret = regulator_disable(hd3ss3220->vbus);
> else
> ret = regulator_enable(hd3ss3220->vbus);
>
ACK.
> Note:
>
> If you are concerned that the reference to the id_gpiod may be
> released before this routine is unregistered, then that condition will
> not help. The hd3ss3220->id_gpiod member is _not_ NULL after the
> reference is released.
>
> If you need a specific order in which the references are released,
> then you can't use the resource management (devm_*) to automate things
> for you.
There is no specific order. So the id part I can keep it intact except
for checking presence of ID pin in interrupt handler.
>
>> + 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 fwnode_handle *connector)
>> +{
>> + int ret = 0;
>> +
>> + hd3ss3220->vbus = devm_of_regulator_get_optional(hd3ss3220->dev,
>> + to_of_node(connector),
>> + "vbus");
>> + if (PTR_ERR(hd3ss3220->vbus) == -ENODEV)
>> + hd3ss3220->vbus = NULL;
>> + else if (IS_ERR(hd3ss3220->vbus))
>> + ret = PTR_ERR(hd3ss3220->vbus);
>
> So the regulator API's optional functions return -ENODEV instead of NULL :(
> In any case, don't double assign the member. Use local variable.
>
> struct regulator *vbus;
>
> vbus = devm_of_regulator_get_optional(...
> if (IS_ERR(vbus) && vbus != ERR_PTR(-ENODEV))
> return PTR_ERR(vbus);
>
> hd3ss3220->vbus = vbus;
> return 0;
>
> I don't think you need this function - just do that in the probe function.
>
ACK.
Regards,
Krishna,
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-11-06 15:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-02 16:48 [PATCH v6 0/2] Implement vbus support for HD3SS3220 port controller Krishna Kurapati
2025-11-02 16:48 ` [PATCH v6 1/2] dt-bindings: usb: ti,hd3ss3220: Add support for VBUS based on ID state Krishna Kurapati
2025-11-02 16:48 ` [PATCH v6 2/2] usb: typec: hd3ss3220: Enable VBUS based on ID pin state Krishna Kurapati
2025-11-06 10:05 ` Heikki Krogerus
2025-11-06 10:16 ` Heikki Krogerus
2025-11-06 15:23 ` Krishna Kurapati PSSNV
2025-11-06 15:31 ` 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;
as well as URLs for NNTP newsgroup(s).