linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash
@ 2017-12-05  5:33 Zhiqiang Hou
  2017-12-05  5:33 ` [PATCHv2 1/2] mtd: spi-nor: add an API to restore the status of SPI flash chip Zhiqiang Hou
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Zhiqiang Hou @ 2017-12-05  5:33 UTC (permalink / raw)
  To: linux-mtd, linux-kernel, computersforpeace, dwmw2,
	boris.brezillon, marek.vasut, richard, cyrille.pitchen
  Cc: Hou Zhiqiang

From: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>

To be compatible with legacy device, reset the addressing mode
to the default mode. Such as Freescale eSPI boot, it copies the
images from SPI flash without firing a reset signal previously,
so the reboot command will fail without reseting the addressing
mode of SPI flash.

Hou Zhiqiang (2):
  mtd: spi-nor: add an API to restore the status of SPI flash chip
  mtd: m25p80: restore the status of SPI flash when stop using it

 Documentation/mtd/spi-nor.txt |  3 +++
 drivers/mtd/devices/m25p80.c  |  9 +++++++++
 drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++++
 include/linux/mtd/spi-nor.h   |  6 ++++++
 4 files changed, 28 insertions(+)

-- 
2.14.1

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

* [PATCHv2 1/2] mtd: spi-nor: add an API to restore the status of SPI flash chip
  2017-12-05  5:33 [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash Zhiqiang Hou
@ 2017-12-05  5:33 ` Zhiqiang Hou
  2017-12-05  5:33 ` [PATCHv2 2/2] mtd: m25p80: restore the status of SPI flash when stop using it Zhiqiang Hou
  2017-12-05 20:40 ` [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash Cyrille Pitchen
  2 siblings, 0 replies; 5+ messages in thread
From: Zhiqiang Hou @ 2017-12-05  5:33 UTC (permalink / raw)
  To: linux-mtd, linux-kernel, computersforpeace, dwmw2,
	boris.brezillon, marek.vasut, richard, cyrille.pitchen
  Cc: Hou Zhiqiang

From: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>

Add this API to restore the status of SPI flash chip to the default
such as addressing mode, whenever detach the driver from device or
reboot the system.

Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
---
V2:
 - Changed the API name and added the comments and kernel document for it.
 - Export this symbol for modules.

 Documentation/mtd/spi-nor.txt |  3 +++
 drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++++
 include/linux/mtd/spi-nor.h   |  6 ++++++
 3 files changed, 19 insertions(+)

diff --git a/Documentation/mtd/spi-nor.txt b/Documentation/mtd/spi-nor.txt
index 548d6306ebca..da1fbff5a24c 100644
--- a/Documentation/mtd/spi-nor.txt
+++ b/Documentation/mtd/spi-nor.txt
@@ -60,3 +60,6 @@ The main API is spi_nor_scan(). Before you call the hook, a driver should
 initialize the necessary fields for spi_nor{}. Please see
 drivers/mtd/spi-nor/spi-nor.c for detail. Please also refer to fsl-quadspi.c
 when you want to write a new driver for a SPI NOR controller.
+Another API is spi_nor_restore(), this is used to restore the status of SPI
+flash chip such as addressing mode. Call it whenever detach the driver from
+device or reboot the system.
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index bc266f70a15b..4a925378d434 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2713,6 +2713,16 @@ static void spi_nor_resume(struct mtd_info *mtd)
 		dev_err(dev, "resume() failed\n");
 }
 
+void spi_nor_restore(struct spi_nor *nor)
+{
+	/* restore the addressing mode */
+	if ((nor->addr_width == 4) &&
+	    (JEDEC_MFR(nor->info) != SNOR_MFR_SPANSION) &&
+	    !(nor->info->flags & SPI_NOR_4B_OPCODES))
+		set_4byte(nor, nor->info, 0);
+}
+EXPORT_SYMBOL_GPL(spi_nor_restore);
+
 int spi_nor_scan(struct spi_nor *nor, const char *name,
 		 const struct spi_nor_hwcaps *hwcaps)
 {
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index d0c66a0975cf..0a182c3d0884 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -399,4 +399,10 @@ struct spi_nor_hwcaps {
 int spi_nor_scan(struct spi_nor *nor, const char *name,
 		 const struct spi_nor_hwcaps *hwcaps);
 
+/*
+ * spi_nor_restore_addr_mode() - restore the status of SPI NOR
+ * @nor:	the spi_nor structure
+ */
+void spi_nor_restore(struct spi_nor *nor);
+
 #endif
-- 
2.14.1

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

* [PATCHv2 2/2] mtd: m25p80: restore the status of SPI flash when stop using it
  2017-12-05  5:33 [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash Zhiqiang Hou
  2017-12-05  5:33 ` [PATCHv2 1/2] mtd: spi-nor: add an API to restore the status of SPI flash chip Zhiqiang Hou
@ 2017-12-05  5:33 ` Zhiqiang Hou
  2017-12-05 20:40 ` [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash Cyrille Pitchen
  2 siblings, 0 replies; 5+ messages in thread
From: Zhiqiang Hou @ 2017-12-05  5:33 UTC (permalink / raw)
  To: linux-mtd, linux-kernel, computersforpeace, dwmw2,
	boris.brezillon, marek.vasut, richard, cyrille.pitchen
  Cc: Hou Zhiqiang

From: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>

Implement .shutdown function to restore the status in reboot
process, and add the same operation to the .remove function.

Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
---
V2:
 - Changed code format slightly.

 drivers/mtd/devices/m25p80.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index dbe6a1de2bb8..a4e18f6aaa33 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -307,10 +307,18 @@ static int m25p_remove(struct spi_device *spi)
 {
 	struct m25p	*flash = spi_get_drvdata(spi);
 
+	spi_nor_restore(&flash->spi_nor);
+
 	/* Clean up MTD stuff. */
 	return mtd_device_unregister(&flash->spi_nor.mtd);
 }
 
+static void m25p_shutdown(struct spi_device *spi)
+{
+	struct m25p *flash = spi_get_drvdata(spi);
+
+	spi_nor_restore(&flash->spi_nor);
+}
 /*
  * Do NOT add to this array without reading the following:
  *
@@ -386,6 +394,7 @@ static struct spi_driver m25p80_driver = {
 	.id_table	= m25p_ids,
 	.probe	= m25p_probe,
 	.remove	= m25p_remove,
+	.shutdown	= m25p_shutdown,
 
 	/* REVISIT: many of these chips have deep power-down modes, which
 	 * should clearly be entered on suspend() to minimize power use.
-- 
2.14.1

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

* Re: [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash
  2017-12-05  5:33 [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash Zhiqiang Hou
  2017-12-05  5:33 ` [PATCHv2 1/2] mtd: spi-nor: add an API to restore the status of SPI flash chip Zhiqiang Hou
  2017-12-05  5:33 ` [PATCHv2 2/2] mtd: m25p80: restore the status of SPI flash when stop using it Zhiqiang Hou
@ 2017-12-05 20:40 ` Cyrille Pitchen
  2017-12-06  2:17   ` Z.q. Hou
  2 siblings, 1 reply; 5+ messages in thread
From: Cyrille Pitchen @ 2017-12-05 20:40 UTC (permalink / raw)
  To: Zhiqiang Hou, linux-mtd, linux-kernel, computersforpeace, dwmw2,
	boris.brezillon, marek.vasut, richard

Hi Hou,

Le 05/12/2017 à 06:33, Zhiqiang Hou a écrit :
> From: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> 
> To be compatible with legacy device, reset the addressing mode
> to the default mode. Such as Freescale eSPI boot, it copies the
> images from SPI flash without firing a reset signal previously,
> so the reboot command will fail without reseting the addressing
> mode of SPI flash.
>

You should put this in one of the commit messages so it explains which
issue is fixed by your patches.

Otherwise, your series looks good to me :)

Best regards,

Cyrille

> Hou Zhiqiang (2):
>   mtd: spi-nor: add an API to restore the status of SPI flash chip
>   mtd: m25p80: restore the status of SPI flash when stop using it
> 
>  Documentation/mtd/spi-nor.txt |  3 +++
>  drivers/mtd/devices/m25p80.c  |  9 +++++++++
>  drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++++
>  include/linux/mtd/spi-nor.h   |  6 ++++++
>  4 files changed, 28 insertions(+)
> 

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

* RE: [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash
  2017-12-05 20:40 ` [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash Cyrille Pitchen
@ 2017-12-06  2:17   ` Z.q. Hou
  0 siblings, 0 replies; 5+ messages in thread
From: Z.q. Hou @ 2017-12-06  2:17 UTC (permalink / raw)
  To: Cyrille Pitchen, linux-mtd, linux-kernel, computersforpeace,
	dwmw2, boris.brezillon, marek.vasut, richard

Hi Cyrille,

Thanks a lot for your comments!

> -----Original Message-----
> From: Cyrille Pitchen [mailto:cyrille.pitchen@wedev4u.fr]
> Sent: 2017年12月6日 4:41
> To: Z.q. Hou <zhiqiang.hou@nxp.com>; linux-mtd@lists.infradead.org;
> linux-kernel@vger.kernel.org; computersforpeace@gmail.com;
> dwmw2@infradead.org; boris.brezillon@free-electrons.com;
> marek.vasut@gmail.com; richard@nod.at
> Subject: Re: [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when
> stop using the flash
> 
> Hi Hou,
> 
> Le 05/12/2017 à 06:33, Zhiqiang Hou a écrit :
> > From: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> >
> > To be compatible with legacy device, reset the addressing mode to the
> > default mode. Such as Freescale eSPI boot, it copies the images from
> > SPI flash without firing a reset signal previously, so the reboot
> > command will fail without reseting the addressing mode of SPI flash.
> >
> 
> You should put this in one of the commit messages so it explains which issue is
> fixed by your patches.

Agree with you, and will do it in next version.

> 
> Otherwise, your series looks good to me :)
> 
> Best regards,
> 
> Cyrille
> 
> > Hou Zhiqiang (2):
> >   mtd: spi-nor: add an API to restore the status of SPI flash chip
> >   mtd: m25p80: restore the status of SPI flash when stop using it
> >
> >  Documentation/mtd/spi-nor.txt |  3 +++  drivers/mtd/devices/m25p80.c
> > |  9 +++++++++  drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++++
> >  include/linux/mtd/spi-nor.h   |  6 ++++++
> >  4 files changed, 28 insertions(+)
> >

Thanks,
Zhiqiang

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

end of thread, other threads:[~2017-12-06  2:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-05  5:33 [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash Zhiqiang Hou
2017-12-05  5:33 ` [PATCHv2 1/2] mtd: spi-nor: add an API to restore the status of SPI flash chip Zhiqiang Hou
2017-12-05  5:33 ` [PATCHv2 2/2] mtd: m25p80: restore the status of SPI flash when stop using it Zhiqiang Hou
2017-12-05 20:40 ` [PATCHv2 0/2] mtd: m25p80: restore the addressing mode when stop using the flash Cyrille Pitchen
2017-12-06  2:17   ` Z.q. Hou

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