[PATCH v3 2/2] mtd: spi-nor: Add support for flash reset

Sai Krishna Potthuri posted 2 patches 3 years, 7 months ago
[PATCH v3 2/2] mtd: spi-nor: Add support for flash reset
Posted by Sai Krishna Potthuri 3 years, 7 months ago
Add support for spi-nor flash reset via GPIO controller by reading the
reset-gpio property. If there is a valid GPIO specifier then reset will
be performed by asserting and deasserting the GPIO using gpiod APIs
otherwise it will not perform any operation.

Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
Reviewed-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/core.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index f2c64006f8d7..a78ab9bae2be 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2933,6 +2933,27 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
 	mtd->_put_device = spi_nor_put_device;
 }
 
+static int spi_nor_hw_reset(struct spi_nor *nor)
+{
+	struct gpio_desc *reset;
+
+	reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR_OR_NULL(reset))
+		return PTR_ERR_OR_ZERO(reset);
+
+	/*
+	 * Experimental delay values by looking at different flash device
+	 * vendors datasheets.
+	 */
+	usleep_range(1, 5);
+	gpiod_set_value_cansleep(reset, 1);
+	usleep_range(100, 150);
+	gpiod_set_value_cansleep(reset, 0);
+	usleep_range(1000, 1200);
+
+	return 0;
+}
+
 int spi_nor_scan(struct spi_nor *nor, const char *name,
 		 const struct spi_nor_hwcaps *hwcaps)
 {
@@ -2965,6 +2986,10 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	if (!nor->bouncebuf)
 		return -ENOMEM;
 
+	ret = spi_nor_hw_reset(nor);
+	if (ret)
+		return ret;
+
 	info = spi_nor_get_flash_info(nor, name);
 	if (IS_ERR(info))
 		return PTR_ERR(info);
-- 
2.17.1
Re: [PATCH v3 2/2] mtd: spi-nor: Add support for flash reset
Posted by Tudor.Ambarus@microchip.com 3 years, 6 months ago
On 9/8/22 09:44, Sai Krishna Potthuri wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Add support for spi-nor flash reset via GPIO controller by reading the
> reset-gpio property. If there is a valid GPIO specifier then reset will
> be performed by asserting and deasserting the GPIO using gpiod APIs
> otherwise it will not perform any operation.
> 
> Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
> Reviewed-by: Michael Walle <michael@walle.cc>
> ---
>  drivers/mtd/spi-nor/core.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index f2c64006f8d7..a78ab9bae2be 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2933,6 +2933,27 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
>         mtd->_put_device = spi_nor_put_device;
>  }
> 
> +static int spi_nor_hw_reset(struct spi_nor *nor)
> +{
> +       struct gpio_desc *reset;
> +
> +       reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW);
> +       if (IS_ERR_OR_NULL(reset))
> +               return PTR_ERR_OR_ZERO(reset);
> +
> +       /*
> +        * Experimental delay values by looking at different flash device
> +        * vendors datasheets.
> +        */
> +       usleep_range(1, 5);
> +       gpiod_set_value_cansleep(reset, 1);
> +       usleep_range(100, 150);
> +       gpiod_set_value_cansleep(reset, 0);
> +       usleep_range(1000, 1200);
> +
> +       return 0;
> +}
> +
>  int spi_nor_scan(struct spi_nor *nor, const char *name,
>                  const struct spi_nor_hwcaps *hwcaps)
>  {
> @@ -2965,6 +2986,10 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>         if (!nor->bouncebuf)
>                 return -ENOMEM;
> 
> +       ret = spi_nor_hw_reset(nor);

Should we condition the calling of this method by the absence of the "broken-flash-reset"
dt prop?

> +       if (ret)
> +               return ret;
> +
>         info = spi_nor_get_flash_info(nor, name);
>         if (IS_ERR(info))
>                 return PTR_ERR(info);
> --
> 2.17.1
> 


-- 
Cheers,
ta
RE: [PATCH v3 2/2] mtd: spi-nor: Add support for flash reset
Posted by Potthuri, Sai Krishna 3 years, 6 months ago
Hi Tudor Ambarus,

> -----Original Message-----
> From: Tudor.Ambarus@microchip.com <Tudor.Ambarus@microchip.com>
> Sent: Monday, October 3, 2022 3:13 PM
> To: Potthuri, Sai Krishna <sai.krishna.potthuri@amd.com>;
> pratyush@kernel.org; michael@walle.cc; miquel.raynal@bootlin.com;
> richard@nod.at; vigneshr@ti.com; robh+dt@kernel.org;
> krzysztof.kozlowski+dt@linaro.org
> Cc: devicetree@vger.kernel.org; linux-mtd@lists.infradead.org; linux-
> kernel@vger.kernel.org; saikrishna12468@gmail.com; git (AMD-Xilinx)
> <git@amd.com>
> Subject: Re: [PATCH v3 2/2] mtd: spi-nor: Add support for flash reset
> 
> On 9/8/22 09:44, Sai Krishna Potthuri wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know
> > the content is safe
> >
> > Add support for spi-nor flash reset via GPIO controller by reading the
> > reset-gpio property. If there is a valid GPIO specifier then reset
> > will be performed by asserting and deasserting the GPIO using gpiod
> > APIs otherwise it will not perform any operation.
> >
> > Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
> > Reviewed-by: Michael Walle <michael@walle.cc>
> > ---
> >  drivers/mtd/spi-nor/core.c | 25 +++++++++++++++++++++++++
> >  1 file changed, 25 insertions(+)
> >
> > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> > index f2c64006f8d7..a78ab9bae2be 100644
> > --- a/drivers/mtd/spi-nor/core.c
> > +++ b/drivers/mtd/spi-nor/core.c
> > @@ -2933,6 +2933,27 @@ static void spi_nor_set_mtd_info(struct spi_nor
> *nor)
> >         mtd->_put_device = spi_nor_put_device;  }
> >
> > +static int spi_nor_hw_reset(struct spi_nor *nor) {
> > +       struct gpio_desc *reset;
> > +
> > +       reset = devm_gpiod_get_optional(nor->dev, "reset",
> GPIOD_OUT_LOW);
> > +       if (IS_ERR_OR_NULL(reset))
> > +               return PTR_ERR_OR_ZERO(reset);
> > +
> > +       /*
> > +        * Experimental delay values by looking at different flash device
> > +        * vendors datasheets.
> > +        */
> > +       usleep_range(1, 5);
> > +       gpiod_set_value_cansleep(reset, 1);
> > +       usleep_range(100, 150);
> > +       gpiod_set_value_cansleep(reset, 0);
> > +       usleep_range(1000, 1200);
> > +
> > +       return 0;
> > +}
> > +
> >  int spi_nor_scan(struct spi_nor *nor, const char *name,
> >                  const struct spi_nor_hwcaps *hwcaps)  { @@ -2965,6
> > +2986,10 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
> >         if (!nor->bouncebuf)
> >                 return -ENOMEM;
> >
> > +       ret = spi_nor_hw_reset(nor);
> 
> Should we condition the calling of this method by the absence of the
> "broken-flash-reset"
> dt prop?
This is the suggestion from Michael on top of my initial series for which
i also agreed to have this call unconditionally. If device tree is having this
reset property then we can do the reset in any case.

Regards
Sai Krishna

Re: [PATCH v3 2/2] mtd: spi-nor: Add support for flash reset
Posted by Tudor.Ambarus@microchip.com 3 years, 6 months ago
On 10/3/22 13:06, Potthuri, Sai Krishna wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Hi Tudor Ambarus,
> 
>> -----Original Message-----
>> From: Tudor.Ambarus@microchip.com <Tudor.Ambarus@microchip.com>
>> Sent: Monday, October 3, 2022 3:13 PM
>> To: Potthuri, Sai Krishna <sai.krishna.potthuri@amd.com>;
>> pratyush@kernel.org; michael@walle.cc; miquel.raynal@bootlin.com;
>> richard@nod.at; vigneshr@ti.com; robh+dt@kernel.org;
>> krzysztof.kozlowski+dt@linaro.org
>> Cc: devicetree@vger.kernel.org; linux-mtd@lists.infradead.org; linux-
>> kernel@vger.kernel.org; saikrishna12468@gmail.com; git (AMD-Xilinx)
>> <git@amd.com>
>> Subject: Re: [PATCH v3 2/2] mtd: spi-nor: Add support for flash reset
>>
>> On 9/8/22 09:44, Sai Krishna Potthuri wrote:
>>> EXTERNAL EMAIL: Do not click links or open attachments unless you know
>>> the content is safe
>>>
>>> Add support for spi-nor flash reset via GPIO controller by reading the
>>> reset-gpio property. If there is a valid GPIO specifier then reset
>>> will be performed by asserting and deasserting the GPIO using gpiod
>>> APIs otherwise it will not perform any operation.
>>>
>>> Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
>>> Reviewed-by: Michael Walle <michael@walle.cc>
>>> ---
>>>  drivers/mtd/spi-nor/core.c | 25 +++++++++++++++++++++++++
>>>  1 file changed, 25 insertions(+)
>>>
>>> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
>>> index f2c64006f8d7..a78ab9bae2be 100644
>>> --- a/drivers/mtd/spi-nor/core.c
>>> +++ b/drivers/mtd/spi-nor/core.c
>>> @@ -2933,6 +2933,27 @@ static void spi_nor_set_mtd_info(struct spi_nor
>> *nor)
>>>         mtd->_put_device = spi_nor_put_device;  }
>>>
>>> +static int spi_nor_hw_reset(struct spi_nor *nor) {
>>> +       struct gpio_desc *reset;
>>> +
>>> +       reset = devm_gpiod_get_optional(nor->dev, "reset",
>> GPIOD_OUT_LOW);
>>> +       if (IS_ERR_OR_NULL(reset))
>>> +               return PTR_ERR_OR_ZERO(reset);
>>> +
>>> +       /*
>>> +        * Experimental delay values by looking at different flash device
>>> +        * vendors datasheets.
>>> +        */
>>> +       usleep_range(1, 5);
>>> +       gpiod_set_value_cansleep(reset, 1);
>>> +       usleep_range(100, 150);
>>> +       gpiod_set_value_cansleep(reset, 0);
>>> +       usleep_range(1000, 1200);
>>> +
>>> +       return 0;
>>> +}
>>> +
>>>  int spi_nor_scan(struct spi_nor *nor, const char *name,
>>>                  const struct spi_nor_hwcaps *hwcaps)  { @@ -2965,6
>>> +2986,10 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>>>         if (!nor->bouncebuf)
>>>                 return -ENOMEM;
>>>
>>> +       ret = spi_nor_hw_reset(nor);
>>
>> Should we condition the calling of this method by the absence of the
>> "broken-flash-reset"
>> dt prop?
> This is the suggestion from Michael on top of my initial series for which
> i also agreed to have this call unconditionally. If device tree is having this
> reset property then we can do the reset in any case.
> 

Okay.

-- 
Cheers,
ta