kernel: add pending mtd patches adding NVMEM support
[openwrt/openwrt.git] / target / linux / pistachio / patches-5.4 / 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/spi-nor.c
12 +++ b/drivers/mtd/spi-nor/spi-nor.c
13 @@ -4938,6 +4938,7 @@ int spi_nor_scan(struct spi_nor *nor, co
14 struct mtd_info *mtd = &nor->mtd;
15 struct device_node *np = spi_nor_get_flash_node(nor);
16 struct spi_nor_flash_parameter *params = &nor->params;
17 + const char __maybe_unused *of_mtd_name = NULL;
18 int ret;
19 int i;
20
21 @@ -5000,7 +5001,12 @@ int spi_nor_scan(struct spi_nor *nor, co
22 /* Init flash parameters based on flash_info struct and SFDP */
23 spi_nor_init_params(nor);
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 @@ -779,6 +779,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;