mtd: spi-nor: allow NULL as chip name and try to auto detect it

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Dec 15 19:59:10 PST 2014


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=58c81957b7d284c57a9fc1b815c77155ef744ea5
Commit:     58c81957b7d284c57a9fc1b815c77155ef744ea5
Parent:     7ca94e07fe8ccbaca9ecb59f388ab8dd93c73e88
Author:     Rafał Miłecki <zajec5 at gmail.com>
AuthorDate: Mon Dec 1 09:42:16 2014 +0100
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Mon Dec 1 10:21:42 2014 -0800

    mtd: spi-nor: allow NULL as chip name and try to auto detect it
    
    This will allow spi-nor users to plainly use JEDEC to detect flash chip.
    
    Signed-off-by: Rafał Miłecki <zajec5 at gmail.com>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/spi-nor/spi-nor.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 0f4f2ba..0f8ec3c 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -938,13 +938,21 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
 	if (ret)
 		return ret;
 
-	id = spi_nor_match_id(name);
-	if (!id)
+	/* Try to auto-detect if chip name wasn't specified */
+	if (!name)
+		id = spi_nor_read_id(nor);
+	else
+		id = spi_nor_match_id(name);
+	if (IS_ERR_OR_NULL(id))
 		return -ENOENT;
 
 	info = (void *)id->driver_data;
 
-	if (info->id_len) {
+	/*
+	 * If caller has specified name of flash model that can normally be
+	 * detected using JEDEC, let's verify it.
+	 */
+	if (name && info->id_len) {
 		const struct spi_device_id *jid;
 
 		jid = spi_nor_read_id(nor);



More information about the linux-mtd-cvs mailing list