mtd: spi-nor: add a helper to find the spi_device_id
authorHuang Shijie <b32955@freescale.com>
Mon, 24 Feb 2014 10:37:40 +0000 (18:37 +0800)
committerBrian Norris <computersforpeace@gmail.com>
Mon, 14 Apr 2014 18:22:58 +0000 (11:22 -0700)
Add the spi_nor_match_id() to find the proper spi_device_id with the
NOR flash's name in the spi_nor_ids table.

Signed-off-by: Huang Shijie <b32955@freescale.com>
Acked-by: Marek Vasut <marex@denx.de>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
drivers/mtd/spi-nor/spi-nor.c
include/linux/mtd/spi-nor.h

index 50b929095bdb8ea3aa685ffc14b47a99687b525e..f7c9e638623bfaa5f851881526713eef7a2f6006 100644 (file)
@@ -1082,6 +1082,18 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
        return 0;
 }
 
+const struct spi_device_id *spi_nor_match_id(char *name)
+{
+       const struct spi_device_id *id = spi_nor_ids;
+
+       while (id->name[0]) {
+               if (!strcmp(name, id->name))
+                       return id;
+               id++;
+       }
+       return NULL;
+}
+
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Huang Shijie <shijie8@gmail.com>");
 MODULE_AUTHOR("Mike Lavender");
index 16d8409abcdc00d5ba35932f88555e43c5a5dbce..41dae78fbd1d49f42ae7a03bb242042a38529d79 100644 (file)
@@ -182,4 +182,16 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
                        enum read_mode mode);
 extern const struct spi_device_id spi_nor_ids[];
 
+/**
+ * spi_nor_match_id() - find the spi_device_id by the name
+ * @name:      the name of the spi_device_id
+ *
+ * The drivers use this function to find the spi_device_id
+ * specified by the @name.
+ *
+ * Return: returns the right spi_device_id pointer on success,
+ *         and returns NULL on failure.
+ */
+const struct spi_device_id *spi_nor_match_id(char *name);
+
 #endif