diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2014-09-29 05:47:54 -0400 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2014-10-17 12:29:21 -0400 |
commit | 70f3ce0510afdad7cbaf27ab7ab961377205c782 (patch) | |
tree | 29df1a4e2259f90e0d2a1d35a7c8484688dc6253 | |
parent | 90e55b3812a1245bb674afcc4410ddba7db402f6 (diff) |
mtd: spi-nor: make spi_nor_scan() take a chip type name, not spi_device_id
Drivers currently call spi_nor_match_id() and then spi_nor_scan().
This adds a dependency on struct spi_device_id which we want to
avoid. Make spi_nor_scan() do it for them.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
-rw-r--r-- | drivers/mtd/devices/m25p80.c | 4 | ||||
-rw-r--r-- | drivers/mtd/spi-nor/fsl-quadspi.c | 7 | ||||
-rw-r--r-- | drivers/mtd/spi-nor/spi-nor.c | 13 | ||||
-rw-r--r-- | include/linux/mtd/spi-nor.h | 20 |
4 files changed, 14 insertions, 30 deletions
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 822209d10689..bd5e4c6edfd4 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c | |||
@@ -193,7 +193,6 @@ static int m25p_probe(struct spi_device *spi) | |||
193 | { | 193 | { |
194 | struct mtd_part_parser_data ppdata; | 194 | struct mtd_part_parser_data ppdata; |
195 | struct flash_platform_data *data; | 195 | struct flash_platform_data *data; |
196 | const struct spi_device_id *id = NULL; | ||
197 | struct m25p *flash; | 196 | struct m25p *flash; |
198 | struct spi_nor *nor; | 197 | struct spi_nor *nor; |
199 | enum read_mode mode = SPI_NOR_NORMAL; | 198 | enum read_mode mode = SPI_NOR_NORMAL; |
@@ -241,8 +240,7 @@ static int m25p_probe(struct spi_device *spi) | |||
241 | else | 240 | else |
242 | flash_name = spi->modalias; | 241 | flash_name = spi->modalias; |
243 | 242 | ||
244 | id = spi_nor_match_id(flash_name); | 243 | ret = spi_nor_scan(nor, flash_name, mode); |
245 | ret = spi_nor_scan(nor, id, mode); | ||
246 | if (ret) | 244 | if (ret) |
247 | return ret; | 245 | return ret; |
248 | 246 | ||
diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c index 8d659a2888d5..d5269a26c839 100644 --- a/drivers/mtd/spi-nor/fsl-quadspi.c +++ b/drivers/mtd/spi-nor/fsl-quadspi.c | |||
@@ -881,7 +881,6 @@ static int fsl_qspi_probe(struct platform_device *pdev) | |||
881 | 881 | ||
882 | /* iterate the subnodes. */ | 882 | /* iterate the subnodes. */ |
883 | for_each_available_child_of_node(dev->of_node, np) { | 883 | for_each_available_child_of_node(dev->of_node, np) { |
884 | const struct spi_device_id *id; | ||
885 | char modalias[40]; | 884 | char modalias[40]; |
886 | 885 | ||
887 | /* skip the holes */ | 886 | /* skip the holes */ |
@@ -909,10 +908,6 @@ static int fsl_qspi_probe(struct platform_device *pdev) | |||
909 | if (of_modalias_node(np, modalias, sizeof(modalias)) < 0) | 908 | if (of_modalias_node(np, modalias, sizeof(modalias)) < 0) |
910 | goto map_failed; | 909 | goto map_failed; |
911 | 910 | ||
912 | id = spi_nor_match_id(modalias); | ||
913 | if (!id) | ||
914 | goto map_failed; | ||
915 | |||
916 | ret = of_property_read_u32(np, "spi-max-frequency", | 911 | ret = of_property_read_u32(np, "spi-max-frequency", |
917 | &q->clk_rate); | 912 | &q->clk_rate); |
918 | if (ret < 0) | 913 | if (ret < 0) |
@@ -921,7 +916,7 @@ static int fsl_qspi_probe(struct platform_device *pdev) | |||
921 | /* set the chip address for READID */ | 916 | /* set the chip address for READID */ |
922 | fsl_qspi_set_base_addr(q, nor); | 917 | fsl_qspi_set_base_addr(q, nor); |
923 | 918 | ||
924 | ret = spi_nor_scan(nor, id, SPI_NOR_QUAD); | 919 | ret = spi_nor_scan(nor, modalias, SPI_NOR_QUAD); |
925 | if (ret) | 920 | if (ret) |
926 | goto map_failed; | 921 | goto map_failed; |
927 | 922 | ||
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index ae16aa2f6885..5c8e39977bc5 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c | |||
@@ -28,6 +28,8 @@ | |||
28 | 28 | ||
29 | #define JEDEC_MFR(_jedec_id) ((_jedec_id) >> 16) | 29 | #define JEDEC_MFR(_jedec_id) ((_jedec_id) >> 16) |
30 | 30 | ||
31 | static const struct spi_device_id *spi_nor_match_id(const char *name); | ||
32 | |||
31 | /* | 33 | /* |
32 | * Read the status register, returning its value in the location | 34 | * Read the status register, returning its value in the location |
33 | * Return the status register value. | 35 | * Return the status register value. |
@@ -911,9 +913,9 @@ static int spi_nor_check(struct spi_nor *nor) | |||
911 | return 0; | 913 | return 0; |
912 | } | 914 | } |
913 | 915 | ||
914 | int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, | 916 | int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) |
915 | enum read_mode mode) | ||
916 | { | 917 | { |
918 | const struct spi_device_id *id = NULL; | ||
917 | struct flash_info *info; | 919 | struct flash_info *info; |
918 | struct device *dev = nor->dev; | 920 | struct device *dev = nor->dev; |
919 | struct mtd_info *mtd = nor->mtd; | 921 | struct mtd_info *mtd = nor->mtd; |
@@ -925,6 +927,10 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, | |||
925 | if (ret) | 927 | if (ret) |
926 | return ret; | 928 | return ret; |
927 | 929 | ||
930 | id = spi_nor_match_id(name); | ||
931 | if (!id) | ||
932 | return -ENOENT; | ||
933 | |||
928 | info = (void *)id->driver_data; | 934 | info = (void *)id->driver_data; |
929 | 935 | ||
930 | if (info->jedec_id) { | 936 | if (info->jedec_id) { |
@@ -1113,7 +1119,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, | |||
1113 | } | 1119 | } |
1114 | EXPORT_SYMBOL_GPL(spi_nor_scan); | 1120 | EXPORT_SYMBOL_GPL(spi_nor_scan); |
1115 | 1121 | ||
1116 | const struct spi_device_id *spi_nor_match_id(char *name) | 1122 | static const struct spi_device_id *spi_nor_match_id(const char *name) |
1117 | { | 1123 | { |
1118 | const struct spi_device_id *id = spi_nor_ids; | 1124 | const struct spi_device_id *id = spi_nor_ids; |
1119 | 1125 | ||
@@ -1124,7 +1130,6 @@ const struct spi_device_id *spi_nor_match_id(char *name) | |||
1124 | } | 1130 | } |
1125 | return NULL; | 1131 | return NULL; |
1126 | } | 1132 | } |
1127 | EXPORT_SYMBOL_GPL(spi_nor_match_id); | ||
1128 | 1133 | ||
1129 | MODULE_LICENSE("GPL"); | 1134 | MODULE_LICENSE("GPL"); |
1130 | MODULE_AUTHOR("Huang Shijie <shijie8@gmail.com>"); | 1135 | MODULE_AUTHOR("Huang Shijie <shijie8@gmail.com>"); |
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 9e6294f32ba8..a5a7a086748d 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h | |||
@@ -187,32 +187,18 @@ struct spi_nor { | |||
187 | /** | 187 | /** |
188 | * spi_nor_scan() - scan the SPI NOR | 188 | * spi_nor_scan() - scan the SPI NOR |
189 | * @nor: the spi_nor structure | 189 | * @nor: the spi_nor structure |
190 | * @id: the spi_device_id provided by the driver | 190 | * @name: the chip type name |
191 | * @mode: the read mode supported by the driver | 191 | * @mode: the read mode supported by the driver |
192 | * | 192 | * |
193 | * The drivers can use this fuction to scan the SPI NOR. | 193 | * The drivers can use this fuction to scan the SPI NOR. |
194 | * In the scanning, it will try to get all the necessary information to | 194 | * In the scanning, it will try to get all the necessary information to |
195 | * fill the mtd_info{} and the spi_nor{}. | 195 | * fill the mtd_info{} and the spi_nor{}. |
196 | * | 196 | * |
197 | * The board may assigns a spi_device_id with @id which be used to compared with | 197 | * The chip type name can be provided through the @name parameter. |
198 | * the spi_device_id detected by the scanning. | ||
199 | * | 198 | * |
200 | * Return: 0 for success, others for failure. | 199 | * Return: 0 for success, others for failure. |
201 | */ | 200 | */ |
202 | int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, | 201 | int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode); |
203 | enum read_mode mode); | ||
204 | extern const struct spi_device_id spi_nor_ids[]; | 202 | extern const struct spi_device_id spi_nor_ids[]; |
205 | 203 | ||
206 | /** | ||
207 | * spi_nor_match_id() - find the spi_device_id by the name | ||
208 | * @name: the name of the spi_device_id | ||
209 | * | ||
210 | * The drivers use this function to find the spi_device_id | ||
211 | * specified by the @name. | ||
212 | * | ||
213 | * Return: returns the right spi_device_id pointer on success, | ||
214 | * and returns NULL on failure. | ||
215 | */ | ||
216 | const struct spi_device_id *spi_nor_match_id(char *name); | ||
217 | |||
218 | #endif | 204 | #endif |