da3ca270fa465902f7cdd15f23d4c62a775b55c5
[openwrt/openwrt.git] / target / linux / pistachio / patches-5.15 / 401-mtd-nor-support-mtd-name-from-device-tree.patch
1 From f32bc2aa01edcba2f2ed5db151cf183eac9ef919 Mon Sep 17 00:00:00 2001
2 From: Abhimanyu Vishwakarma <Abhimanyu.Vishwakarma@imgtec.com>
3 Date: Sat, 25 Feb 2017 16:42:50 +0000
4 Subject: mtd: nor: support mtd name from device tree
5
6 Signed-off-by: Abhimanyu Vishwakarma <Abhimanyu.Vishwakarma@imgtec.com>
7 ---
8 drivers/mtd/spi-nor/spi-nor.c | 8 +++++++-
9 1 file changed, 7 insertions(+), 1 deletion(-)
10
11 --- a/drivers/mtd/spi-nor/core.c
12 +++ b/drivers/mtd/spi-nor/core.c
13 @@ -3098,6 +3098,7 @@ int spi_nor_scan(struct spi_nor *nor, co
14 struct device *dev = nor->dev;
15 struct mtd_info *mtd = &nor->mtd;
16 struct device_node *np = spi_nor_get_flash_node(nor);
17 + const char __maybe_unused *of_mtd_name = NULL;
18 int ret;
19 int i;
20
21 @@ -3152,7 +3153,12 @@ int spi_nor_scan(struct spi_nor *nor, co
22 if (ret)
23 return ret;
24
25 - if (!mtd->name)
26 +#ifdef CONFIG_MTD_OF_PARTS
27 + of_property_read_string(np, "linux,mtd-name", &of_mtd_name);
28 +#endif
29 + if (of_mtd_name)
30 + mtd->name = of_mtd_name;
31 + else if (!mtd->name)
32 mtd->name = dev_name(dev);
33 mtd->priv = nor;
34 mtd->type = MTD_NORFLASH;
35 --- a/drivers/mtd/mtdcore.c
36 +++ b/drivers/mtd/mtdcore.c
37 @@ -847,6 +847,17 @@ out_error:
38 */
39 static void mtd_set_dev_defaults(struct mtd_info *mtd)
40 {
41 +#ifdef CONFIG_MTD_OF_PARTS
42 + const char __maybe_unused *of_mtd_name = NULL;
43 + struct device_node *np;
44 +
45 + np = mtd_get_of_node(mtd);
46 + if (np && !mtd->name) {
47 + of_property_read_string(np, "linux,mtd-name", &of_mtd_name);
48 + if (of_mtd_name)
49 + mtd->name = of_mtd_name;
50 + } else
51 +#endif
52 if (mtd->dev.parent) {
53 if (!mtd->owner && mtd->dev.parent->driver)
54 mtd->owner = mtd->dev.parent->driver->owner;