devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] usb: typec: tps6598x: add reset gpio support
@ 2023-09-15  6:50 Javier Carrasco
  2023-09-15  6:50 ` [PATCH 1/2] " Javier Carrasco
  2023-09-15  6:50 ` [PATCH 2/2] dt-bindings: usb: tps6598x: add reset-gpios property Javier Carrasco
  0 siblings, 2 replies; 10+ messages in thread
From: Javier Carrasco @ 2023-09-15  6:50 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Bryan O'Donoghue
  Cc: linux-usb, linux-kernel, devicetree, Javier Carrasco

The TPS6598x PD controller provides an active-high hardware reset input
that reinitializes all device settings. If it is not grounded by
design, the driver must be able to de-assert it in order to initialize
the device.

This series adds and documents the reset signal management. It also
includes the basic reset management for initialization and
suspend/resume control.

Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
---
Javier Carrasco (2):
      usb: typec: tps6598x: add reset gpio support
      dt-bindings: usb: tps6598x: add reset-gpios property

 .../devicetree/bindings/usb/ti,tps6598x.yaml        |  6 ++++++
 drivers/usb/typec/tipd/core.c                       | 21 ++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
---
base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
change-id: 20230912-topic-tps6598x_reset-55e9494e8649

Best regards,
-- 
Javier Carrasco <javier.carrasco@wolfvision.net>


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

* [PATCH 1/2] usb: typec: tps6598x: add reset gpio support
  2023-09-15  6:50 [PATCH 0/2] usb: typec: tps6598x: add reset gpio support Javier Carrasco
@ 2023-09-15  6:50 ` Javier Carrasco
  2023-09-15  6:57   ` Krzysztof Kozlowski
                     ` (2 more replies)
  2023-09-15  6:50 ` [PATCH 2/2] dt-bindings: usb: tps6598x: add reset-gpios property Javier Carrasco
  1 sibling, 3 replies; 10+ messages in thread
From: Javier Carrasco @ 2023-09-15  6:50 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Bryan O'Donoghue
  Cc: linux-usb, linux-kernel, devicetree, Javier Carrasco

The TPS6598x PD controller provides an active-high hardware reset input
that reinitializes all device settings. If it is not grounded by
design, the driver must be able to de-assert it in order to initialize
the device.

The PD controller is not ready for registration right after the reset
de-assertion and a delay must be introduced in that case. According to
TI, the delay can reach up to 1000 ms [1], which is in line with the
experimental results obtained with a TPS65987D.

Add a GPIO descriptor for the reset signal and basic reset management
for initialization and suspend/resume.

[1] https://e2e.ti.com/support/power-management-group/power-management/
f/power-management-forum/1269856/tps65987d-tps65987d-reset-de-assert-
to-normal-operation/4809389#4809389

Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
---
 drivers/usb/typec/tipd/core.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index 37b56ce75f39..550f5913e985 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -8,6 +8,7 @@
 
 #include <linux/i2c.h>
 #include <linux/acpi.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/power_supply.h>
@@ -43,6 +44,9 @@
 /* TPS_REG_SYSTEM_CONF bits */
 #define TPS_SYSCONF_PORTINFO(c)		((c) & 7)
 
+/* reset de-assertion to ready for operation */
+#define SETUP_MS			1000
+
 enum {
 	TPS_PORTINFO_SINK,
 	TPS_PORTINFO_SINK_ACCESSORY,
@@ -86,6 +90,7 @@ struct tps6598x {
 	struct mutex lock; /* device lock */
 	u8 i2c_protocol:1;
 
+	struct gpio_desc *reset;
 	struct typec_port *port;
 	struct typec_partner *partner;
 	struct usb_pd_identity partner_identity;
@@ -717,6 +722,13 @@ static int tps6598x_probe(struct i2c_client *client)
 	mutex_init(&tps->lock);
 	tps->dev = &client->dev;
 
+	tps->reset = devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(tps->reset))
+		return dev_err_probe(tps->dev, PTR_ERR(tps->reset),
+				     "failed to get reset GPIO\n");
+	if (tps->reset)
+		msleep(SETUP_MS);
+
 	tps->regmap = devm_regmap_init_i2c(client, &tps6598x_regmap_config);
 	if (IS_ERR(tps->regmap))
 		return PTR_ERR(tps->regmap);
@@ -892,6 +904,9 @@ static void tps6598x_remove(struct i2c_client *client)
 	tps6598x_disconnect(tps, 0);
 	typec_unregister_port(tps->port);
 	usb_role_switch_put(tps->role_sw);
+
+	if (tps->reset)
+		gpiod_set_value_cansleep(tps->reset, 1);
 }
 
 static int __maybe_unused tps6598x_suspend(struct device *dev)
@@ -902,7 +917,8 @@ static int __maybe_unused tps6598x_suspend(struct device *dev)
 	if (tps->wakeup) {
 		disable_irq(client->irq);
 		enable_irq_wake(client->irq);
-	}
+	} else if (tps->reset)
+		gpiod_set_value_cansleep(tps->reset, 1);
 
 	if (!client->irq)
 		cancel_delayed_work_sync(&tps->wq_poll);
@@ -918,6 +934,9 @@ static int __maybe_unused tps6598x_resume(struct device *dev)
 	if (tps->wakeup) {
 		disable_irq_wake(client->irq);
 		enable_irq(client->irq);
+	} else if (tps->reset) {
+		gpiod_set_value_cansleep(tps->reset, 0);
+		msleep(SETUP_MS);
 	}
 
 	if (!client->irq)

-- 
2.39.2


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

* [PATCH 2/2] dt-bindings: usb: tps6598x: add reset-gpios property
  2023-09-15  6:50 [PATCH 0/2] usb: typec: tps6598x: add reset gpio support Javier Carrasco
  2023-09-15  6:50 ` [PATCH 1/2] " Javier Carrasco
@ 2023-09-15  6:50 ` Javier Carrasco
  2023-09-15  6:56   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 10+ messages in thread
From: Javier Carrasco @ 2023-09-15  6:50 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Bryan O'Donoghue
  Cc: linux-usb, linux-kernel, devicetree, Javier Carrasco

The TPS6598x driver supports an optional high-level reset GPIO.
Document the new property and add it to the example.

Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
---
 Documentation/devicetree/bindings/usb/ti,tps6598x.yaml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml b/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml
index 5497a60cddbc..b1a621e06127 100644
--- a/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml
+++ b/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml
@@ -23,6 +23,10 @@ properties:
   reg:
     maxItems: 1
 
+  reset-gpios:
+    description: GPIO used for the HRESET pin.
+    maxItems: 1
+
   wakeup-source: true
 
   interrupts:
@@ -40,6 +44,7 @@ additionalProperties: true
 
 examples:
   - |
+    #include <dt-bindings/gpio/gpio.h>
     #include <dt-bindings/interrupt-controller/irq.h>
     i2c {
         #address-cells = <1>;
@@ -56,6 +61,7 @@ examples:
 
             pinctrl-names = "default";
             pinctrl-0 = <&typec_pins>;
+            reset-gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>;
 
             typec_con: connector {
                 compatible = "usb-c-connector";

-- 
2.39.2


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

* Re: [PATCH 2/2] dt-bindings: usb: tps6598x: add reset-gpios property
  2023-09-15  6:50 ` [PATCH 2/2] dt-bindings: usb: tps6598x: add reset-gpios property Javier Carrasco
@ 2023-09-15  6:56   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2023-09-15  6:56 UTC (permalink / raw)
  To: Javier Carrasco, Heikki Krogerus, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Bryan O'Donoghue
  Cc: linux-usb, linux-kernel, devicetree

On 15/09/2023 08:50, Javier Carrasco wrote:
> The TPS6598x driver supports an optional high-level reset GPIO.

What driver supports or not, it does not matter. The question is (and
commit msg should say) whether hardware has such reset pin or not.

> Document the new property and add it to the example.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
> ---
>  Documentation/devicetree/bindings/usb/ti,tps6598x.yaml | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml b/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml
> index 5497a60cddbc..b1a621e06127 100644
> --- a/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml
> +++ b/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml
> @@ -23,6 +23,10 @@ properties:
>    reg:
>      maxItems: 1
>  
> +  reset-gpios:
> +    description: GPIO used for the HRESET pin.

This probably answers that yes - it is a pin in hardware...

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof


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

* Re: [PATCH 1/2] usb: typec: tps6598x: add reset gpio support
  2023-09-15  6:50 ` [PATCH 1/2] " Javier Carrasco
@ 2023-09-15  6:57   ` Krzysztof Kozlowski
  2023-09-15  7:09     ` Javier Carrasco
  2023-09-15  9:52   ` Bryan O'Donoghue
  2023-09-15 10:23   ` Bryan O'Donoghue
  2 siblings, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2023-09-15  6:57 UTC (permalink / raw)
  To: Javier Carrasco, Heikki Krogerus, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Bryan O'Donoghue
  Cc: linux-usb, linux-kernel, devicetree

On 15/09/2023 08:50, Javier Carrasco wrote:
> The TPS6598x PD controller provides an active-high hardware reset input
> that reinitializes all device settings. If it is not grounded by
> design, the driver must be able to de-assert it in order to initialize
> the device.
> 
> The PD controller is not ready for registration right after the reset
> de-assertion and a delay must be introduced in that case. According to
> TI, the delay can reach up to 1000 ms [1], which is in line with the
> experimental results obtained with a TPS65987D.
> 
> Add a GPIO descriptor for the reset signal and basic reset management
> for initialization and suspend/resume.
> 
> [1] https://e2e.ti.com/support/power-management-group/power-management/
> f/power-management-forum/1269856/tps65987d-tps65987d-reset-de-assert-
> to-normal-operation/4809389#4809389
> 
> Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
> ---
>  drivers/usb/typec/tipd/core.c | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 37b56ce75f39..550f5913e985 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -8,6 +8,7 @@
>  
>  #include <linux/i2c.h>
>  #include <linux/acpi.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/power_supply.h>
> @@ -43,6 +44,9 @@
>  /* TPS_REG_SYSTEM_CONF bits */
>  #define TPS_SYSCONF_PORTINFO(c)		((c) & 7)
>  
> +/* reset de-assertion to ready for operation */
> +#define SETUP_MS			1000

1 second? That's a bit a lot. Does it come from datasheet?

> +
>  enum {
>  	TPS_PORTINFO_SINK,
>  	TPS_PORTINFO_SINK_ACCESSORY,
> @@ -86,6 +90,7 @@ struct tps6598x {
>  	struct mutex lock; /* device lock */
>  	u8 i2c_protocol:1;
>  
> +	struct gpio_desc *reset;
>  	struct typec_port *port;
>  	struct typec_partner *partner;
>  	struct usb_pd_identity partner_identity;
> @@ -717,6 +722,13 @@ static int tps6598x_probe(struct i2c_client *client)
>  	mutex_init(&tps->lock);
>  	tps->dev = &client->dev;
>  
> +	tps->reset = devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW);
> +	if (IS_ERR(tps->reset))
> +		return dev_err_probe(tps->dev, PTR_ERR(tps->reset),
> +				     "failed to get reset GPIO\n");
> +	if (tps->reset)
> +		msleep(SETUP_MS);
> +
>  	tps->regmap = devm_regmap_init_i2c(client, &tps6598x_regmap_config);
>  	if (IS_ERR(tps->regmap))
>  		return PTR_ERR(tps->regmap);
> @@ -892,6 +904,9 @@ static void tps6598x_remove(struct i2c_client *client)
>  	tps6598x_disconnect(tps, 0);
>  	typec_unregister_port(tps->port);
>  	usb_role_switch_put(tps->role_sw);
> +
> +	if (tps->reset)
> +		gpiod_set_value_cansleep(tps->reset, 1);
>  }
>  
>  static int __maybe_unused tps6598x_suspend(struct device *dev)
> @@ -902,7 +917,8 @@ static int __maybe_unused tps6598x_suspend(struct device *dev)
>  	if (tps->wakeup) {
>  		disable_irq(client->irq);
>  		enable_irq_wake(client->irq);
> -	}
> +	} else if (tps->reset)
> +		gpiod_set_value_cansleep(tps->reset, 1);

Missing {} (see Linux coding style).

>  
>  	if (!client->irq)
>  		cancel_delayed_work_sync(&tps->wq_poll);
> @@ -918,6 +934,9 @@ static int __maybe_unused tps6598x_resume(struct device *dev)
>  	if (tps->wakeup) {
>  		disable_irq_wake(client->irq);
>  		enable_irq(client->irq);
> +	} else if (tps->reset) {
> +		gpiod_set_value_cansleep(tps->reset, 0);
> +		msleep(SETUP_MS);
>  	}
>  
>  	if (!client->irq)
> 

Best regards,
Krzysztof


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

* Re: [PATCH 1/2] usb: typec: tps6598x: add reset gpio support
  2023-09-15  6:57   ` Krzysztof Kozlowski
@ 2023-09-15  7:09     ` Javier Carrasco
  0 siblings, 0 replies; 10+ messages in thread
From: Javier Carrasco @ 2023-09-15  7:09 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Heikki Krogerus, Greg Kroah-Hartman,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bryan O'Donoghue
  Cc: linux-usb, linux-kernel, devicetree

Hello Krzysztof,

On 15.09.23 08:57, Krzysztof Kozlowski wrote:
> On 15/09/2023 08:50, Javier Carrasco wrote:
>> The TPS6598x PD controller provides an active-high hardware reset input
>> that reinitializes all device settings. If it is not grounded by
>> design, the driver must be able to de-assert it in order to initialize
>> the device.
>>
>> The PD controller is not ready for registration right after the reset
>> de-assertion and a delay must be introduced in that case. According to
>> TI, the delay can reach up to 1000 ms [1], which is in line with the
>> experimental results obtained with a TPS65987D.
>>
>> Add a GPIO descriptor for the reset signal and basic reset management
>> for initialization and suspend/resume.
>>
>> [1] https://e2e.ti.com/support/power-management-group/power-management/
>> f/power-management-forum/1269856/tps65987d-tps65987d-reset-de-assert-
>> to-normal-operation/4809389#4809389
>>
>> Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
>> ---
>>  drivers/usb/typec/tipd/core.c | 21 ++++++++++++++++++++-
>>  1 file changed, 20 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
>> index 37b56ce75f39..550f5913e985 100644
>> --- a/drivers/usb/typec/tipd/core.c
>> +++ b/drivers/usb/typec/tipd/core.c
>> @@ -8,6 +8,7 @@
>>  
>>  #include <linux/i2c.h>
>>  #include <linux/acpi.h>
>> +#include <linux/gpio/consumer.h>
>>  #include <linux/module.h>
>>  #include <linux/of.h>
>>  #include <linux/power_supply.h>
>> @@ -43,6 +44,9 @@
>>  /* TPS_REG_SYSTEM_CONF bits */
>>  #define TPS_SYSCONF_PORTINFO(c)		((c) & 7)
>>  
>> +/* reset de-assertion to ready for operation */
>> +#define SETUP_MS			1000
> 
> 1 second? That's a bit a lot. Does it come from datasheet?
> 
I also thought it is a long delay, but when I tested it myself with real
hardware I got values of hundreds of milliseconds until the
regmap_init_i2c was able to reach the device. I also noticed that there
is already a timeout of 1s in the tps_6598x_exec_cmd function, which
made me suspect that the timing might be a factor to consider.

The datasheet does not provide any timing for the reset, so I asked the
manufacturer (TI).
The reply form the TI technical staff was that depending on the
configuration it might take from 800 to 1000 ms. I added a link to that
answer in the commit message.

>> +
>>  enum {
>>  	TPS_PORTINFO_SINK,
>>  	TPS_PORTINFO_SINK_ACCESSORY,
>> @@ -86,6 +90,7 @@ struct tps6598x {
>>  	struct mutex lock; /* device lock */
>>  	u8 i2c_protocol:1;
>>  
>> +	struct gpio_desc *reset;
>>  	struct typec_port *port;
>>  	struct typec_partner *partner;
>>  	struct usb_pd_identity partner_identity;
>> @@ -717,6 +722,13 @@ static int tps6598x_probe(struct i2c_client *client)
>>  	mutex_init(&tps->lock);
>>  	tps->dev = &client->dev;
>>  
>> +	tps->reset = devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW);
>> +	if (IS_ERR(tps->reset))
>> +		return dev_err_probe(tps->dev, PTR_ERR(tps->reset),
>> +				     "failed to get reset GPIO\n");
>> +	if (tps->reset)
>> +		msleep(SETUP_MS);
>> +
>>  	tps->regmap = devm_regmap_init_i2c(client, &tps6598x_regmap_config);
>>  	if (IS_ERR(tps->regmap))
>>  		return PTR_ERR(tps->regmap);
>> @@ -892,6 +904,9 @@ static void tps6598x_remove(struct i2c_client *client)
>>  	tps6598x_disconnect(tps, 0);
>>  	typec_unregister_port(tps->port);
>>  	usb_role_switch_put(tps->role_sw);
>> +
>> +	if (tps->reset)
>> +		gpiod_set_value_cansleep(tps->reset, 1);
>>  }
>>  
>>  static int __maybe_unused tps6598x_suspend(struct device *dev)
>> @@ -902,7 +917,8 @@ static int __maybe_unused tps6598x_suspend(struct device *dev)
>>  	if (tps->wakeup) {
>>  		disable_irq(client->irq);
>>  		enable_irq_wake(client->irq);
>> -	}
>> +	} else if (tps->reset)
>> +		gpiod_set_value_cansleep(tps->reset, 1);
> 
> Missing {} (see Linux coding style).
> 
Thanks, I will correct this for v2.
>>  
>>  	if (!client->irq)
>>  		cancel_delayed_work_sync(&tps->wq_poll);
>> @@ -918,6 +934,9 @@ static int __maybe_unused tps6598x_resume(struct device *dev)
>>  	if (tps->wakeup) {
>>  		disable_irq_wake(client->irq);
>>  		enable_irq(client->irq);
>> +	} else if (tps->reset) {
>> +		gpiod_set_value_cansleep(tps->reset, 0);
>> +		msleep(SETUP_MS);
>>  	}
>>  
>>  	if (!client->irq)
>>
> 
> Best regards,
> Krzysztof
> 
Best regards,
Javier Carrasco

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

* Re: [PATCH 1/2] usb: typec: tps6598x: add reset gpio support
  2023-09-15  6:50 ` [PATCH 1/2] " Javier Carrasco
  2023-09-15  6:57   ` Krzysztof Kozlowski
@ 2023-09-15  9:52   ` Bryan O'Donoghue
  2023-09-15 10:03     ` Krzysztof Kozlowski
  2023-09-15 10:07     ` Javier Carrasco
  2023-09-15 10:23   ` Bryan O'Donoghue
  2 siblings, 2 replies; 10+ messages in thread
From: Bryan O'Donoghue @ 2023-09-15  9:52 UTC (permalink / raw)
  To: Javier Carrasco, Heikki Krogerus, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-usb, linux-kernel, devicetree

On 15/09/2023 07:50, Javier Carrasco wrote:
> The TPS6598x PD controller provides an active-high hardware reset input
> that reinitializes all device settings. If it is not grounded by
> design, the driver must be able to de-assert it in order to initialize
> the device.
> 
> The PD controller is not ready for registration right after the reset
> de-assertion and a delay must be introduced in that case. According to
> TI, the delay can reach up to 1000 ms [1], which is in line with the
> experimental results obtained with a TPS65987D.
> 
> Add a GPIO descriptor for the reset signal and basic reset management
> for initialization and suspend/resume.
> 
> [1] https://e2e.ti.com/support/power-management-group/power-management/
> f/power-management-forum/1269856/tps65987d-tps65987d-reset-de-assert-
> to-normal-operation/4809389#4809389
> 
> Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
> ---
>   drivers/usb/typec/tipd/core.c | 21 ++++++++++++++++++++-
>   1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 37b56ce75f39..550f5913e985 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -8,6 +8,7 @@
>   
>   #include <linux/i2c.h>
>   #include <linux/acpi.h>
> +#include <linux/gpio/consumer.h>
>   #include <linux/module.h>
>   #include <linux/of.h>
>   #include <linux/power_supply.h>
> @@ -43,6 +44,9 @@
>   /* TPS_REG_SYSTEM_CONF bits */
>   #define TPS_SYSCONF_PORTINFO(c)		((c) & 7)
>   
> +/* reset de-assertion to ready for operation */
> +#define SETUP_MS			1000
> +
>   enum {
>   	TPS_PORTINFO_SINK,
>   	TPS_PORTINFO_SINK_ACCESSORY,
> @@ -86,6 +90,7 @@ struct tps6598x {
>   	struct mutex lock; /* device lock */
>   	u8 i2c_protocol:1;
>   
> +	struct gpio_desc *reset;
>   	struct typec_port *port;
>   	struct typec_partner *partner;
>   	struct usb_pd_identity partner_identity;
> @@ -717,6 +722,13 @@ static int tps6598x_probe(struct i2c_client *client)
>   	mutex_init(&tps->lock);
>   	tps->dev = &client->dev;
>   
> +	tps->reset = devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW);
> +	if (IS_ERR(tps->reset))
> +		return dev_err_probe(tps->dev, PTR_ERR(tps->reset),
> +				     "failed to get reset GPIO\n");
> +	if (tps->reset)
> +		msleep(SETUP_MS);
> +

This looks a bit odd to me, shouldn't you drive reset to zero ?

if (tps->reset) {
     gpiod_set_value_cansleep(tps->reset, 0);
     msleep(SETUP_MS);
}

also wouldn't it make sense to functionally decompose that and reuse in 
probe() and tps6598x_resume() ?

tps6598x_reset() {
     if (tps->reset) {
         gpiod_set_value_cansleep(tps->reset, 0);
         msleep(SETUP_MS);
     }
}

---
bod

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

* Re: [PATCH 1/2] usb: typec: tps6598x: add reset gpio support
  2023-09-15  9:52   ` Bryan O'Donoghue
@ 2023-09-15 10:03     ` Krzysztof Kozlowski
  2023-09-15 10:07     ` Javier Carrasco
  1 sibling, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2023-09-15 10:03 UTC (permalink / raw)
  To: Bryan O'Donoghue, Javier Carrasco, Heikki Krogerus,
	Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-usb, linux-kernel, devicetree

On 15/09/2023 11:52, Bryan O'Donoghue wrote:
>> +	struct gpio_desc *reset;
>>   	struct typec_port *port;
>>   	struct typec_partner *partner;
>>   	struct usb_pd_identity partner_identity;
>> @@ -717,6 +722,13 @@ static int tps6598x_probe(struct i2c_client *client)
>>   	mutex_init(&tps->lock);
>>   	tps->dev = &client->dev;
>>   
>> +	tps->reset = devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW);
>> +	if (IS_ERR(tps->reset))
>> +		return dev_err_probe(tps->dev, PTR_ERR(tps->reset),
>> +				     "failed to get reset GPIO\n");
>> +	if (tps->reset)
>> +		msleep(SETUP_MS);
>> +
> 
> This looks a bit odd to me, shouldn't you drive reset to zero ?
> 
> if (tps->reset) {
>      gpiod_set_value_cansleep(tps->reset, 0);

It is driven by GPIOD_OUT_LOW.

>      msleep(SETUP_MS);
> }
> 
> also wouldn't it make sense to functionally decompose that and reuse in 
> probe() and tps6598x_resume() ?
> 
> tps6598x_reset() {
>      if (tps->reset) {
>          gpiod_set_value_cansleep(tps->reset, 0);
>          msleep(SETUP_MS);
>      }
> }


Best regards,
Krzysztof


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

* Re: [PATCH 1/2] usb: typec: tps6598x: add reset gpio support
  2023-09-15  9:52   ` Bryan O'Donoghue
  2023-09-15 10:03     ` Krzysztof Kozlowski
@ 2023-09-15 10:07     ` Javier Carrasco
  1 sibling, 0 replies; 10+ messages in thread
From: Javier Carrasco @ 2023-09-15 10:07 UTC (permalink / raw)
  To: Bryan O'Donoghue, Heikki Krogerus, Greg Kroah-Hartman,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-usb, linux-kernel, devicetree

Hello Bryan,

On 15.09.23 11:52, Bryan O'Donoghue wrote:
> On 15/09/2023 07:50, Javier Carrasco wrote:
>> The TPS6598x PD controller provides an active-high hardware reset input
>> that reinitializes all device settings. If it is not grounded by
>> design, the driver must be able to de-assert it in order to initialize
>> the device.
>>
>> The PD controller is not ready for registration right after the reset
>> de-assertion and a delay must be introduced in that case. According to
>> TI, the delay can reach up to 1000 ms [1], which is in line with the
>> experimental results obtained with a TPS65987D.
>>
>> Add a GPIO descriptor for the reset signal and basic reset management
>> for initialization and suspend/resume.
>>
>> [1]
>> https://e2e.ti.com/support/power-management-group/power-management/
>> f/power-management-forum/1269856/tps65987d-tps65987d-reset-de-assert-
>> to-normal-operation/4809389#4809389
>>
>> Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
>> ---
>>   drivers/usb/typec/tipd/core.c | 21 ++++++++++++++++++++-
>>   1 file changed, 20 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/typec/tipd/core.c
>> b/drivers/usb/typec/tipd/core.c
>> index 37b56ce75f39..550f5913e985 100644
>> --- a/drivers/usb/typec/tipd/core.c
>> +++ b/drivers/usb/typec/tipd/core.c
>> @@ -8,6 +8,7 @@
>>     #include <linux/i2c.h>
>>   #include <linux/acpi.h>
>> +#include <linux/gpio/consumer.h>
>>   #include <linux/module.h>
>>   #include <linux/of.h>
>>   #include <linux/power_supply.h>
>> @@ -43,6 +44,9 @@
>>   /* TPS_REG_SYSTEM_CONF bits */
>>   #define TPS_SYSCONF_PORTINFO(c)        ((c) & 7)
>>   +/* reset de-assertion to ready for operation */
>> +#define SETUP_MS            1000
>> +
>>   enum {
>>       TPS_PORTINFO_SINK,
>>       TPS_PORTINFO_SINK_ACCESSORY,
>> @@ -86,6 +90,7 @@ struct tps6598x {
>>       struct mutex lock; /* device lock */
>>       u8 i2c_protocol:1;
>>   +    struct gpio_desc *reset;
>>       struct typec_port *port;
>>       struct typec_partner *partner;
>>       struct usb_pd_identity partner_identity;
>> @@ -717,6 +722,13 @@ static int tps6598x_probe(struct i2c_client *client)
>>       mutex_init(&tps->lock);
>>       tps->dev = &client->dev;
>>   +    tps->reset = devm_gpiod_get_optional(tps->dev, "reset",
>> GPIOD_OUT_LOW);
>> +    if (IS_ERR(tps->reset))
>> +        return dev_err_probe(tps->dev, PTR_ERR(tps->reset),
>> +                     "failed to get reset GPIO\n");
>> +    if (tps->reset)
>> +        msleep(SETUP_MS);
>> +
> 
> This looks a bit odd to me, shouldn't you drive reset to zero ?
> 
> if (tps->reset) {
>     gpiod_set_value_cansleep(tps->reset, 0);
>     msleep(SETUP_MS);
> }
> 
The reset line is driven to zero by means fo the GPIOD_OUT_LOW flag, so
there is no need to set it explicitly again.

> also wouldn't it make sense to functionally decompose that and reuse in
> probe() and tps6598x_resume() ?
> 
> tps6598x_reset() {
>     if (tps->reset) {
>         gpiod_set_value_cansleep(tps->reset, 0);
>         msleep(SETUP_MS);
>     }
> }
> 
I can move the reset action to a separate function as you proposed, but
then I suppose it would make sense to use the same function for both
reset levels. Maybe something like:

tps6598x_reset(bool level) {
    if (tps->reset) {
        gpiod_set_value_cansleep(tps->reset, level);
	if (!level)
            msleep(SETUP_MS);
    }
}

> ---
> bod
Thanks for your feedback.

Best regards,
Javier Carrasco

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

* Re: [PATCH 1/2] usb: typec: tps6598x: add reset gpio support
  2023-09-15  6:50 ` [PATCH 1/2] " Javier Carrasco
  2023-09-15  6:57   ` Krzysztof Kozlowski
  2023-09-15  9:52   ` Bryan O'Donoghue
@ 2023-09-15 10:23   ` Bryan O'Donoghue
  2 siblings, 0 replies; 10+ messages in thread
From: Bryan O'Donoghue @ 2023-09-15 10:23 UTC (permalink / raw)
  To: Javier Carrasco, Heikki Krogerus, Greg Kroah-Hartman, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-usb, linux-kernel, devicetree

On 15/09/2023 07:50, Javier Carrasco wrote:
> The TPS6598x PD controller provides an active-high hardware reset input
> that reinitializes all device settings. If it is not grounded by
> design, the driver must be able to de-assert it in order to initialize
> the device.
> 
> The PD controller is not ready for registration right after the reset
> de-assertion and a delay must be introduced in that case. According to
> TI, the delay can reach up to 1000 ms [1], which is in line with the
> experimental results obtained with a TPS65987D.
> 
> Add a GPIO descriptor for the reset signal and basic reset management
> for initialization and suspend/resume.
> 
> [1] https://e2e.ti.com/support/power-management-group/power-management/
> f/power-management-forum/1269856/tps65987d-tps65987d-reset-de-assert-
> to-normal-operation/4809389#4809389
> 
> Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>

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


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

end of thread, other threads:[~2023-09-15 10:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-15  6:50 [PATCH 0/2] usb: typec: tps6598x: add reset gpio support Javier Carrasco
2023-09-15  6:50 ` [PATCH 1/2] " Javier Carrasco
2023-09-15  6:57   ` Krzysztof Kozlowski
2023-09-15  7:09     ` Javier Carrasco
2023-09-15  9:52   ` Bryan O'Donoghue
2023-09-15 10:03     ` Krzysztof Kozlowski
2023-09-15 10:07     ` Javier Carrasco
2023-09-15 10:23   ` Bryan O'Donoghue
2023-09-15  6:50 ` [PATCH 2/2] dt-bindings: usb: tps6598x: add reset-gpios property Javier Carrasco
2023-09-15  6:56   ` Krzysztof Kozlowski

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).