linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin
@ 2023-07-14  8:19 Naresh Solanki
  2023-07-14  8:19 ` [PATCH v3 2/2] pinctrl: cy8c95x0: Add reset support Naresh Solanki
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Naresh Solanki @ 2023-07-14  8:19 UTC (permalink / raw)
  To: Linus Walleij, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Patrick Rudolph
  Cc: Naresh Solanki, linux-gpio, devicetree, linux-kernel

From: Patrick Rudolph <patrick.rudolph@9elements.com>

This patch adds support for an optional reset pin.

The reset pin is used to bring the chip into a known state and has an
internal pull-down, allowing it to be left floating if not needed.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
---
Changes in V3:
- Update reset-gpios description.
Changes in V2:
- Update subject
- Update reset-gpios description.
---
 .../devicetree/bindings/pinctrl/cypress,cy8c95x0.yaml         | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/pinctrl/cypress,cy8c95x0.yaml b/Documentation/devicetree/bindings/pinctrl/cypress,cy8c95x0.yaml
index 222d57541b65..7f30ec2f1e54 100644
--- a/Documentation/devicetree/bindings/pinctrl/cypress,cy8c95x0.yaml
+++ b/Documentation/devicetree/bindings/pinctrl/cypress,cy8c95x0.yaml
@@ -51,6 +51,10 @@ properties:
     description:
       Optional power supply.
 
+  reset-gpios:
+    description: GPIO connected to the XRES pin
+    maxItems: 1
+
 patternProperties:
   '-pins$':
     type: object

base-commit: 3bc551a3007a751a53bfba5b37fa16157f4fb861
-- 
2.41.0


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

* [PATCH v3 2/2] pinctrl: cy8c95x0: Add reset support
  2023-07-14  8:19 [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin Naresh Solanki
@ 2023-07-14  8:19 ` Naresh Solanki
  2023-07-20 20:10   ` andy.shevchenko
  2023-07-14  8:51 ` [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin Krzysztof Kozlowski
  2023-07-20 19:19 ` Linus Walleij
  2 siblings, 1 reply; 5+ messages in thread
From: Naresh Solanki @ 2023-07-14  8:19 UTC (permalink / raw)
  To: Patrick Rudolph, Linus Walleij; +Cc: Naresh Solanki, linux-gpio, linux-kernel

From: Patrick Rudolph <patrick.rudolph@9elements.com>

This patch adds support for an optional "reset" GPIO pin in the cy8c95x0
pinctrl driver. On probe, the reset pin is pulled low to bring chip out
of reset. The reset pin has an internal pull-down and can be left
floating if not required.

The datasheet doesn't mention any timing related to the reset pin.

Based on empirical tests, it was found that the chip requires a
delay of 250 milliseconds before accepting I2C transfers after driving
the reset pin low. Therefore, a delay of 250ms is added before
proceeding with I2C transfers.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
---
Changes in V2:
- None
---
 drivers/pinctrl/pinctrl-cy8c95x0.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c
index 2ecc96691c55..58ca6fac7849 100644
--- a/drivers/pinctrl/pinctrl-cy8c95x0.c
+++ b/drivers/pinctrl/pinctrl-cy8c95x0.c
@@ -164,6 +164,7 @@ struct cy8c95x0_pinctrl {
 	struct pinctrl_desc pinctrl_desc;
 	char name[32];
 	unsigned int tpin;
+	struct gpio_desc *gpio_reset;
 };
 
 static const struct pinctrl_pin_desc cy8c9560_pins[] = {
@@ -1383,6 +1384,20 @@ static int cy8c95x0_probe(struct i2c_client *client)
 		chip->regulator = reg;
 	}
 
+	/* bring the chip out of reset if reset pin is provided */
+	chip->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(chip->gpio_reset)) {
+		ret = dev_err_probe(chip->dev, PTR_ERR(chip->gpio_reset),
+				    "Failed to get GPIO 'reset'\n");
+		goto err_exit;
+	} else if (chip->gpio_reset) {
+		usleep_range(1000, 2000);
+		gpiod_set_value_cansleep(chip->gpio_reset, 0);
+		usleep_range(250000, 300000);
+
+		gpiod_set_consumer_name(chip->gpio_reset, "CY8C95X0 RESET");
+	}
+
 	chip->regmap = devm_regmap_init_i2c(client, &cy8c95x0_i2c_regmap);
 	if (IS_ERR(chip->regmap)) {
 		ret = PTR_ERR(chip->regmap);
-- 
2.41.0


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

* Re: [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin
  2023-07-14  8:19 [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin Naresh Solanki
  2023-07-14  8:19 ` [PATCH v3 2/2] pinctrl: cy8c95x0: Add reset support Naresh Solanki
@ 2023-07-14  8:51 ` Krzysztof Kozlowski
  2023-07-20 19:19 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-14  8:51 UTC (permalink / raw)
  To: Naresh Solanki, Linus Walleij, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Patrick Rudolph
  Cc: linux-gpio, devicetree, linux-kernel

On 14/07/2023 10:19, Naresh Solanki wrote:
> From: Patrick Rudolph <patrick.rudolph@9elements.com>
> 
> This patch adds support for an optional reset pin.
> 
> The reset pin is used to bring the chip into a known state and has an
> internal pull-down, allowing it to be left floating if not needed.
> 
> Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
> Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
> ---

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

Best regards,
Krzysztof


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

* Re: [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin
  2023-07-14  8:19 [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin Naresh Solanki
  2023-07-14  8:19 ` [PATCH v3 2/2] pinctrl: cy8c95x0: Add reset support Naresh Solanki
  2023-07-14  8:51 ` [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin Krzysztof Kozlowski
@ 2023-07-20 19:19 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2023-07-20 19:19 UTC (permalink / raw)
  To: Naresh Solanki
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Patrick Rudolph,
	linux-gpio, devicetree, linux-kernel

Hi Naresh!

On Fri, Jul 14, 2023 at 10:19 AM Naresh Solanki
<naresh.solanki@9elements.com> wrote:

> From: Patrick Rudolph <patrick.rudolph@9elements.com>
>
> This patch adds support for an optional reset pin.
>
> The reset pin is used to bring the chip into a known state and has an
> internal pull-down, allowing it to be left floating if not needed.
>
> Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
> Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>

Both patches applied!

Yours,
Linus Walleij

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

* Re: [PATCH v3 2/2] pinctrl: cy8c95x0: Add reset support
  2023-07-14  8:19 ` [PATCH v3 2/2] pinctrl: cy8c95x0: Add reset support Naresh Solanki
@ 2023-07-20 20:10   ` andy.shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: andy.shevchenko @ 2023-07-20 20:10 UTC (permalink / raw)
  To: Naresh Solanki; +Cc: Patrick Rudolph, Linus Walleij, linux-gpio, linux-kernel

Fri, Jul 14, 2023 at 10:19:01AM +0200, Naresh Solanki kirjoitti:
> From: Patrick Rudolph <patrick.rudolph@9elements.com>
> 
> This patch adds support for an optional "reset" GPIO pin in the cy8c95x0

Find "This patch" in the Submitting Patches documentation and modify this
accordingly.

> pinctrl driver. On probe, the reset pin is pulled low to bring chip out
> of reset. The reset pin has an internal pull-down and can be left
> floating if not required.
> 
> The datasheet doesn't mention any timing related to the reset pin.
> 
> Based on empirical tests, it was found that the chip requires a
> delay of 250 milliseconds before accepting I2C transfers after driving
> the reset pin low. Therefore, a delay of 250ms is added before
> proceeding with I2C transfers.

...

> +	/* bring the chip out of reset if reset pin is provided */
> +	chip->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);

&client->dev

> +	if (IS_ERR(chip->gpio_reset)) {
> +		ret = dev_err_probe(chip->dev, PTR_ERR(chip->gpio_reset),

chip->dev

Why inconsistent?

> +				    "Failed to get GPIO 'reset'\n");
> +		goto err_exit;

I haven't looked at the context, but this seems like a smoke, we usually don't
have such in devm-enabled drivers.

> +	} else if (chip->gpio_reset) {
> +		usleep_range(1000, 2000);
> +		gpiod_set_value_cansleep(chip->gpio_reset, 0);

> +		usleep_range(250000, 300000);

This is incorrect use of usleep_range(). Please, read documentation
Documentation/timers/timers-howto.rst on the topic. The fix can be switching to
fsleep() in both branches.


> +		gpiod_set_consumer_name(chip->gpio_reset, "CY8C95X0 RESET");

This can be done uncoditionally before toggling the reset.

> +	}

...

This change wasn't Cc'ed to me, however I was contributing a lot into this driver.
I would recommend to use my "smart" script [1] to send patches. It has some
heuristics which works well in 98% of the cases for me.

[1]: https://github.com/andy-shev/home-bin-tools/blob/master/ge2maintainer.sh


-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2023-07-20 20:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-14  8:19 [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin Naresh Solanki
2023-07-14  8:19 ` [PATCH v3 2/2] pinctrl: cy8c95x0: Add reset support Naresh Solanki
2023-07-20 20:10   ` andy.shevchenko
2023-07-14  8:51 ` [PATCH v3 1/2] dt-bindings: pinctrl: cypress,cy8c95x0: Add reset pin Krzysztof Kozlowski
2023-07-20 19:19 ` Linus Walleij

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