mbox series

[0/3] spi-nor: add optional vcc-supply and enable it for i.MX93

Message ID 20240920-spi-v1-0-97f220c2e10c@nxp.com
Headers show
Series spi-nor: add optional vcc-supply and enable it for i.MX93 | expand

Message

Peng Fan Sept. 20, 2024, 8:54 a.m. UTC
spi-nor flash needs power supply to work properly, the power supply
could be software controlled. So need enable the power before using the
flash.

Patch 1,2 is to add vcc-supply for spi-nor
Patch 3 is to add overlays for i.MX93-11x11-EVK

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
Peng Fan (3):
      dt-bindings: mtd: jedec,spi-nor: add optional vcc-supply
      mtd: spi-nor: support vcc-supply regulator
      arm64: dts: imx93-11x11-evk: add overlays for flexspi flash

 .../devicetree/bindings/mtd/jedec,spi-nor.yaml     |  4 ++
 arch/arm64/boot/dts/freescale/Makefile             |  3 ++
 .../dts/freescale/imx93-11x11-evk-flexspi-m2.dtso  | 59 ++++++++++++++++++++++
 arch/arm64/boot/dts/freescale/imx93-11x11-evk.dts  | 10 ++++
 drivers/mtd/spi-nor/core.c                         |  5 ++
 5 files changed, 81 insertions(+)
---
base-commit: 3621a2c9142bd490af0666c0c02d52d60ce0d2a5
change-id: 20240920-spi-34231ea74761

Best regards,

Comments

Marco Felsch Sept. 20, 2024, 9:09 a.m. UTC | #1
On 24-09-20, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> spi nor flash needs power supply to work properly. The power supply
> maybe software controllable per board design. So add the support
> for an optional vcc-supply regulator.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/mtd/spi-nor/core.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 9d6e85bf227b..0449afe6bb20 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -17,6 +17,7 @@
>  #include <linux/mtd/spi-nor.h>
>  #include <linux/mutex.h>
>  #include <linux/of_platform.h>
> +#include <linux/regulator/consumer.h>
>  #include <linux/sched/task_stack.h>
>  #include <linux/sizes.h>
>  #include <linux/slab.h>
> @@ -3462,6 +3463,10 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>  	if (!nor->bouncebuf)
>  		return -ENOMEM;
>  
> +	ret = devm_regulator_get_enable_optional(dev, "vcc");
> +	if (ret)

This returns -ENODEV if no regulator was specified. In general all
SPI-NOR devices need a VCC supply, so don't use the regulator optional
API here, please check the regulator API doc.

In contrast to that the dt-bindings should have the vcc-supply as
optional to not cause a regression for exisiting systems.

Regards,
  Marco

> +		return ret;
> +
>  	ret = spi_nor_hw_reset(nor);
>  	if (ret)
>  		return ret;
> 
> -- 
> 2.37.1
> 
> 
>
Frank Li Sept. 20, 2024, 9:40 p.m. UTC | #2
On Fri, Sep 20, 2024 at 04:54:07PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> spi nor flash needs power supply to work properly. The power supply
> maybe software controllable per board design. So add the support
> for an optional vcc-supply regulator.
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/mtd/spi-nor/core.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 9d6e85bf227b..0449afe6bb20 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -17,6 +17,7 @@
>  #include <linux/mtd/spi-nor.h>
>  #include <linux/mutex.h>
>  #include <linux/of_platform.h>
> +#include <linux/regulator/consumer.h>
>  #include <linux/sched/task_stack.h>
>  #include <linux/sizes.h>
>  #include <linux/slab.h>
> @@ -3462,6 +3463,10 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>  	if (!nor->bouncebuf)
>  		return -ENOMEM;
>
> +	ret = devm_regulator_get_enable_optional(dev, "vcc");
> +	if (ret)
> +		return ret;
> +

I think devm_regulator_get_enable_optional() should be called in
spi_nor_probe(). spi_nor_scan() is public API, which may call many time.
That will cause regulartor reference counter wrong.

Frank

>  	ret = spi_nor_hw_reset(nor);
>  	if (ret)
>  		return ret;
>
> --
> 2.37.1
>