From 1bce5f39c2ce0c79f0769f2e69d5e9caed28dfc2 Mon Sep 17 00:00:00 2001 From: White Ding Date: Wed, 14 Nov 2018 12:04:27 +0100 Subject: mtd: nand: fix nand_lock/unlock() function Do nand reset before write protect check. If we want to check the WP# low or high through STATUS READ and check bit 7, we must reset the device, other operation (eg.erase/program a locked block) can also clear the bit 7 of status register. As we know the status register can be refreshed, if we do some operation to trigger it, for example if we do erase/program operation to one block that is locked, then READ STATUS, the bit 7 of READ STATUS will be 0 indicate the device in write protect, then if we do erase/program operation to another block that is unlocked, the bit 7 of READ STATUS will be 1 indicate the device is not write protect. Suppose we checked the bit 7 of READ STATUS is 0 then judge the WP# is low (write protect), but in this case the WP# maybe high if we do erase/program operation to a locked block, so we must reset the device if we want to check the WP# low or high through STATUS READ and check bit 7. Signed-off-by: White Ding Signed-off-by: Brian Norris [Cherry-picked from linux: 57d3a9a89a06 mtd: nand: fix nand_lock/unlock() function] Signed-off-by: Marc Kleine-Budde Signed-off-by: Sascha Hauer --- drivers/mtd/nand/nand_base.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index ccf9615042..128802fa5c 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -852,6 +852,15 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) chip->select_chip(mtd, chipnr); + /* + * Reset the chip. + * If we want to check the WP through READ STATUS and check the bit 7 + * we must reset the chip + * some operation can also clear the bit 7 of status register + * eg. erase/program a locked block + */ + chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); + /* Check, if it is write protected */ if (nand_check_wp(mtd)) { pr_debug("%s: device is write protected!\n", @@ -902,6 +911,15 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) chip->select_chip(mtd, chipnr); + /* + * Reset the chip. + * If we want to check the WP through READ STATUS and check the bit 7 + * we must reset the chip + * some operation can also clear the bit 7 of status register + * eg. erase/program a locked block + */ + chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); + /* Check, if it is write protected */ if (nand_check_wp(mtd)) { pr_debug("%s: device is write protected!\n", -- cgit v1.2.3 From b5ef34499a3064680918d91ecdea74ddcf98716e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 23 Nov 2018 15:50:15 +0100 Subject: mtd: return EOPNOTSUPP when attempting to erase an MTD_NO_ERASE device At least some MTD_NO_ERASE devices like MRAM do not specify a sensible erase block size; instead, erasesize is equal to the whole flash size. This leads to an EINVAL return from mtd_erase_align() whenever a partial erase is attempted. At least on the MRAM I tested, a full flash erase did not return an error, but it did not have any effect on the flash either. As erase seems to be entirely unsupported on this class of devices, and it is not necessary anyways, it's better to return early with EOPNOTSUPP. This fixes envfs_save() on a partitioned MRAM. Signed-off-by: Matthias Schiffer Signed-off-by: Sascha Hauer --- drivers/mtd/core.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index 56e85b3d8f..d3cbe502fa 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -178,6 +178,9 @@ static int mtd_op_erase(struct cdev *cdev, loff_t count, loff_t offset) loff_t addr; int ret; + if (mtd->flags & MTD_NO_ERASE) + return -EOPNOTSUPP; + ret = mtd_erase_align(mtd, &count, &offset); if (ret) return ret; -- cgit v1.2.3 From fd0ffdccbf53185baa632f982221b013b1ed85d3 Mon Sep 17 00:00:00 2001 From: Steffen Trumtrar Date: Tue, 27 Nov 2018 08:13:00 +0100 Subject: mtd: nand: denali: quiet down driver Instead of always printing the timing registers, make it a debug information only. Signed-off-by: Steffen Trumtrar Signed-off-by: Sascha Hauer --- drivers/mtd/nand/nand_denali.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/nand_denali.c b/drivers/mtd/nand/nand_denali.c index 8b09b3722f..c530a80bde 100644 --- a/drivers/mtd/nand/nand_denali.c +++ b/drivers/mtd/nand/nand_denali.c @@ -511,7 +511,7 @@ static uint16_t denali_nand_timing_set(struct denali_nand_info *denali) get_hynix_nand_para(denali, device_id); } - dev_info(denali->dev, + dev_dbg(denali->dev, "Dump timing register values:\n" "acc_clks: %d, re_2_we: %d, re_2_re: %d\n" "we_2_re: %d, addr_2_data: %d, rdwr_en_lo_cnt: %d\n" -- cgit v1.2.3 From 37e01d3a7a236f069bbd7efa5c1501e7b4ff7206 Mon Sep 17 00:00:00 2001 From: Alexis Ballier Date: Tue, 4 Dec 2018 10:11:34 +0100 Subject: mtd: spi-nor: Add support for sst25wf020a It is a 256KiB flash with 4 KiB erase sectors and 64KiB overlay blocks. This is the one available on Hardkernel's Odroid U3 shield. Signed-off-by: Alexis Ballier [Brian: seems like this does NOT require the usual SST_WRITE hacks] Signed-off-by: Brian Norris [Linux upstream commit: a1d97ef96e38] Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- drivers/mtd/spi-nor/spi-nor.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index d15a795413..48d5742d5b 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -594,6 +594,7 @@ static const struct spi_device_id spi_nor_ids[] = { { "sst25wf512", INFO(0xbf2501, 0, 64 * 1024, 1, SECT_4K | SST_WRITE) }, { "sst25wf010", INFO(0xbf2502, 0, 64 * 1024, 2, SECT_4K | SST_WRITE) }, { "sst25wf020", INFO(0xbf2503, 0, 64 * 1024, 4, SECT_4K | SST_WRITE) }, + { "sst25wf020a", INFO(0x621612, 0, 64 * 1024, 4, SECT_4K) }, { "sst25wf040", INFO(0xbf2504, 0, 64 * 1024, 8, SECT_4K | SST_WRITE) }, { "sst25wf080", INFO(0xbf2505, 0, 64 * 1024, 16, SECT_4K | SST_WRITE) }, -- cgit v1.2.3 From 1d3735498ace79322db05cf36c5ab595dd0c8112 Mon Sep 17 00:00:00 2001 From: Yao Yuan Date: Tue, 4 Dec 2018 10:11:35 +0100 Subject: mtd: spi-nor: Add support for sst25wf040b Signed-off-by: Yuan Yao Signed-off-by: Brian Norris [Linux upstream commit: c887be71cc39] Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- drivers/mtd/spi-nor/spi-nor.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 48d5742d5b..85b55c6982 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -595,6 +595,7 @@ static const struct spi_device_id spi_nor_ids[] = { { "sst25wf010", INFO(0xbf2502, 0, 64 * 1024, 2, SECT_4K | SST_WRITE) }, { "sst25wf020", INFO(0xbf2503, 0, 64 * 1024, 4, SECT_4K | SST_WRITE) }, { "sst25wf020a", INFO(0x621612, 0, 64 * 1024, 4, SECT_4K) }, + { "sst25wf040b", INFO(0x621613, 0, 64 * 1024, 8, SECT_4K) }, { "sst25wf040", INFO(0xbf2504, 0, 64 * 1024, 8, SECT_4K | SST_WRITE) }, { "sst25wf080", INFO(0xbf2505, 0, 64 * 1024, 16, SECT_4K | SST_WRITE) }, -- cgit v1.2.3