1 From 2c5a3db21926e9ebfd7a32e3c36a3256ed84903c Mon Sep 17 00:00:00 2001
2 From: Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
3 Date: Thu, 19 Nov 2015 20:25:24 +0800
4 Subject: [PATCH 090/113] mtd: spi-nor: Add SPI NOR layer PM support
8 Add the Power Management API in SPI NOR framework.
9 The Power Management system will turn off power supply to SPI flash
10 when system suspending, and then the SPI flash will be in the reset
11 state after system resuming. As a result, the status&configurations
12 of SPI flash driver will mismatch with its current hardware state.
13 So reinitialize SPI flash to make sure it is resumed to the correct
15 And the SPI NOR layer just do common configuration depending on the
16 records in structure spi_nor.
18 Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
19 Integrated-by: Jiang Yutang <yutang.jiang@nxp.com>
21 drivers/mtd/spi-nor/spi-nor.c | 74 ++++++++++++++++++++++++++++++++++-------
22 include/linux/mtd/spi-nor.h | 9 +++++
23 2 files changed, 71 insertions(+), 12 deletions(-)
25 --- a/drivers/mtd/spi-nor/spi-nor.c
26 +++ b/drivers/mtd/spi-nor/spi-nor.c
27 @@ -1139,6 +1139,26 @@ static int spi_nor_check(struct spi_nor
32 + * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up
33 + * with the software protection bits set
35 +static int spi_nor_unprotect_on_powerup(struct spi_nor *nor)
37 + const struct flash_info *info = NULL;
40 + info = spi_nor_read_id(nor);
41 + if (JEDEC_MFR(info) == SNOR_MFR_ATMEL ||
42 + JEDEC_MFR(info) == SNOR_MFR_INTEL ||
43 + JEDEC_MFR(info) == SNOR_MFR_SST) {
45 + ret = write_sr(nor, 0);
51 int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
53 const struct flash_info *info = NULL;
54 @@ -1186,18 +1206,9 @@ int spi_nor_scan(struct spi_nor *nor, co
56 mutex_init(&nor->lock);
59 - * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up
60 - * with the software protection bits set
63 - if (JEDEC_MFR(info) == SNOR_MFR_ATMEL ||
64 - JEDEC_MFR(info) == SNOR_MFR_INTEL ||
65 - JEDEC_MFR(info) == SNOR_MFR_MACRONIX ||
66 - JEDEC_MFR(info) == SNOR_MFR_SST) {
70 + ret = spi_nor_unprotect_on_powerup(nor);
75 mtd->name = dev_name(dev);
76 @@ -1363,6 +1374,45 @@ int spi_nor_scan(struct spi_nor *nor, co
78 EXPORT_SYMBOL_GPL(spi_nor_scan);
80 +static int spi_nor_hw_reinit(struct spi_nor *nor)
82 + const struct flash_info *info = NULL;
83 + struct device *dev = nor->dev;
86 + info = spi_nor_read_id(nor);
88 + ret = spi_nor_unprotect_on_powerup(nor);
92 + if (nor->flash_read == SPI_NOR_QUAD) {
93 + ret = set_quad_mode(nor, info);
95 + dev_err(dev, "quad mode not supported\n");
100 + if (nor->addr_width == 4 &&
101 + JEDEC_MFR(info) != SNOR_MFR_SPANSION)
102 + set_4byte(nor, info, 1);
107 +int spi_nor_suspend(struct spi_nor *nor)
111 +EXPORT_SYMBOL_GPL(spi_nor_suspend);
113 +int spi_nor_resume(struct spi_nor *nor)
115 + return spi_nor_hw_reinit(nor);
117 +EXPORT_SYMBOL_GPL(spi_nor_resume);
119 static const struct flash_info *spi_nor_match_id(const char *name)
121 const struct flash_info *id = spi_nor_ids;
122 --- a/include/linux/mtd/spi-nor.h
123 +++ b/include/linux/mtd/spi-nor.h
124 @@ -210,4 +210,13 @@ static inline struct device_node *spi_no
126 int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode);
129 + * spi_nor_suspend/resume() - the SPI NOR layer PM API
130 + * @nor: the spi_nor structure
132 + * Return: 0 for success, others for failure.
134 +int spi_nor_suspend(struct spi_nor *nor);
135 +int spi_nor_resume(struct spi_nor *nor);