diff mbox series

[U-Boot,v3,18/25] tpm: add the possibility to reset the chip with a gpio

Message ID 20180502085934.29292-19-miquel.raynal@bootlin.com
State Superseded
Delegated to: Tom Rini
Headers show
Series Introduce TPMv2.0 support | expand

Commit Message

Miquel Raynal May 2, 2018, 8:59 a.m. UTC
On some designs, the reset line could not be connected to the SoC reset
line, in this case, request the GPIO and ensure the chip gets reset.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/tpm/tpm2_tis_spi.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Simon Glass May 3, 2018, 2:32 a.m. UTC | #1
Hi Miquel,

On 2 May 2018 at 02:59, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> On some designs, the reset line could not be connected to the SoC reset
> line, in this case, request the GPIO and ensure the chip gets reset.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/tpm/tpm2_tis_spi.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/drivers/tpm/tpm2_tis_spi.c b/drivers/tpm/tpm2_tis_spi.c
> index cfef5b8c24..824ab70bae 100644
> --- a/drivers/tpm/tpm2_tis_spi.c
> +++ b/drivers/tpm/tpm2_tis_spi.c
> @@ -24,6 +24,9 @@
>  #include <linux/compiler.h>
>  #include <linux/types.h>
>  #include <linux/unaligned/be_byteshift.h>
> +#ifdef CONFIG_DM_GPIO
> +#include <asm-generic/gpio.h>
> +#endif
>
>  #include "tpm_tis.h"
>  #include "tpm_internal.h"
> @@ -598,6 +601,21 @@ static int tpm_tis_spi_probe(struct udevice *dev)
>  {
>         struct tpm_chip *chip = dev_get_priv(dev);
>         int ret;
> +#ifdef CONFIG_DM_GPIO
> +       struct gpio_desc reset_gpio;
> +
> +       ret = gpio_request_by_name(dev, "gpio-reset", 0,
> +                                  &reset_gpio, GPIOD_IS_OUT);
> +       if (ret)
> +               log(LOGC_NONE, LOGL_NOTICE, "%s: missing reset GPIO\n",
> +                   __func__);
> +
> +       if (dm_gpio_is_valid(&reset_gpio)) {

If ret is 0 you know the GPIO is valid, so just check ret.

> +               dm_gpio_set_value(&reset_gpio, 0);
> +               mdelay(1);
> +               dm_gpio_set_value(&reset_gpio, 1);
> +       }
> +#endif
>
>         /* Ensure a minimum amount of time elapsed since reset */
>         mdelay(30);
> --
> 2.14.1
>

Regards,
Simon
diff mbox series

Patch

diff --git a/drivers/tpm/tpm2_tis_spi.c b/drivers/tpm/tpm2_tis_spi.c
index cfef5b8c24..824ab70bae 100644
--- a/drivers/tpm/tpm2_tis_spi.c
+++ b/drivers/tpm/tpm2_tis_spi.c
@@ -24,6 +24,9 @@ 
 #include <linux/compiler.h>
 #include <linux/types.h>
 #include <linux/unaligned/be_byteshift.h>
+#ifdef CONFIG_DM_GPIO
+#include <asm-generic/gpio.h>
+#endif
 
 #include "tpm_tis.h"
 #include "tpm_internal.h"
@@ -598,6 +601,21 @@  static int tpm_tis_spi_probe(struct udevice *dev)
 {
 	struct tpm_chip *chip = dev_get_priv(dev);
 	int ret;
+#ifdef CONFIG_DM_GPIO
+	struct gpio_desc reset_gpio;
+
+	ret = gpio_request_by_name(dev, "gpio-reset", 0,
+				   &reset_gpio, GPIOD_IS_OUT);
+	if (ret)
+		log(LOGC_NONE, LOGL_NOTICE, "%s: missing reset GPIO\n",
+		    __func__);
+
+	if (dm_gpio_is_valid(&reset_gpio)) {
+		dm_gpio_set_value(&reset_gpio, 0);
+		mdelay(1);
+		dm_gpio_set_value(&reset_gpio, 1);
+	}
+#endif
 
 	/* Ensure a minimum amount of time elapsed since reset */
 	mdelay(30);