From: Sven Eckelmann Date: Thu, 31 Dec 2020 00:25:10 +0100 Subject: ath79: Allow to set spi-nor mtd name via devicetree On ar71xx, it was possible to overwrite the name of the spi-nor mtd device identifier using the flash_platform_data which each mach-*.c could adjust for its devices. A similar feature was introduced for mtd-physmap in devicetree's. The property linux,mtd-name can be used to set the name and provide a stable identifier for mtdpart from the bootloader. But this feature is not yet available upstream for spi-nor devices which also might receive their partition layout from the bootloader. But the OpenWrt pistachio support for this property can simply be imported into ath79 to gain this support. Signed-off-by: Sven Eckelmann (cherry picked from commit 7f074fe1a79f27d30560c35778d963bc520e9a3e) diff --git a/target/linux/ath79/patches-5.10/401-mtd-nor-support-mtd-name-from-device-tree.patch b/target/linux/ath79/patches-5.10/401-mtd-nor-support-mtd-name-from-device-tree.patch new file mode 100644 index 0000000000000000000000000000000000000000..af032df51e6dbc3824a45a8efaa1ce8db2261b2a --- /dev/null +++ b/target/linux/ath79/patches-5.10/401-mtd-nor-support-mtd-name-from-device-tree.patch @@ -0,0 +1,51 @@ +From f32bc2aa01edcba2f2ed5db151cf183eac9ef919 Mon Sep 17 00:00:00 2001 +From: Abhimanyu Vishwakarma +Date: Sat, 25 Feb 2017 16:42:50 +0000 +Subject: mtd: nor: support mtd name from device tree + +Signed-off-by: Abhimanyu Vishwakarma + +--- a/drivers/mtd/spi-nor/core.c ++++ b/drivers/mtd/spi-nor/core.c +@@ -3088,6 +3088,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, + struct device *dev = nor->dev; + struct mtd_info *mtd = &nor->mtd; + struct device_node *np = spi_nor_get_flash_node(nor); ++ const char __maybe_unused *of_mtd_name = NULL; + int ret; + int i; + +@@ -3142,7 +3143,12 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, + if (ret) + return ret; + +- if (!mtd->name) ++#ifdef CONFIG_MTD_OF_PARTS ++ of_property_read_string(np, "linux,mtd-name", &of_mtd_name); ++#endif ++ if (of_mtd_name) ++ mtd->name = of_mtd_name; ++ else if (!mtd->name) + mtd->name = dev_name(dev); + mtd->priv = nor; + mtd->type = MTD_NORFLASH; +--- a/drivers/mtd/mtdcore.c ++++ b/drivers/mtd/mtdcore.c +@@ -762,6 +762,17 @@ int del_mtd_device(struct mtd_info *mtd) + */ + static void mtd_set_dev_defaults(struct mtd_info *mtd) + { ++#ifdef CONFIG_MTD_OF_PARTS ++ const char __maybe_unused *of_mtd_name = NULL; ++ struct device_node *np; ++ ++ np = mtd_get_of_node(mtd); ++ if (np && !mtd->name) { ++ of_property_read_string(np, "linux,mtd-name", &of_mtd_name); ++ if (of_mtd_name) ++ mtd->name = of_mtd_name; ++ } else ++#endif + if (mtd->dev.parent) { + if (!mtd->owner && mtd->dev.parent->driver) + mtd->owner = mtd->dev.parent->driver->owner; diff --git a/target/linux/ath79/patches-5.4/401-mtd-nor-support-mtd-name-from-device-tree.patch b/target/linux/ath79/patches-5.4/401-mtd-nor-support-mtd-name-from-device-tree.patch new file mode 100644 index 0000000000000000000000000000000000000000..a02b632e8c48f4a2df7d66b732aa60dd6788b6b1 --- /dev/null +++ b/target/linux/ath79/patches-5.4/401-mtd-nor-support-mtd-name-from-device-tree.patch @@ -0,0 +1,54 @@ +From f32bc2aa01edcba2f2ed5db151cf183eac9ef919 Mon Sep 17 00:00:00 2001 +From: Abhimanyu Vishwakarma +Date: Sat, 25 Feb 2017 16:42:50 +0000 +Subject: mtd: nor: support mtd name from device tree + +Signed-off-by: Abhimanyu Vishwakarma +--- + drivers/mtd/spi-nor/spi-nor.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +--- a/drivers/mtd/spi-nor/spi-nor.c ++++ b/drivers/mtd/spi-nor/spi-nor.c +@@ -4937,6 +4937,7 @@ int spi_nor_scan(struct spi_nor *nor, co + struct mtd_info *mtd = &nor->mtd; + struct device_node *np = spi_nor_get_flash_node(nor); + struct spi_nor_flash_parameter *params = &nor->params; ++ const char __maybe_unused *of_mtd_name = NULL; + int ret; + int i; + +@@ -4999,7 +5000,12 @@ int spi_nor_scan(struct spi_nor *nor, co + /* Init flash parameters based on flash_info struct and SFDP */ + spi_nor_init_params(nor); + +- if (!mtd->name) ++#ifdef CONFIG_MTD_OF_PARTS ++ of_property_read_string(np, "linux,mtd-name", &of_mtd_name); ++#endif ++ if (of_mtd_name) ++ mtd->name = of_mtd_name; ++ else if (!mtd->name) + mtd->name = dev_name(dev); + mtd->priv = nor; + mtd->type = MTD_NORFLASH; +--- a/drivers/mtd/mtdcore.c ++++ b/drivers/mtd/mtdcore.c +@@ -778,6 +778,17 @@ out_error: + */ + static void mtd_set_dev_defaults(struct mtd_info *mtd) + { ++#ifdef CONFIG_MTD_OF_PARTS ++ const char __maybe_unused *of_mtd_name = NULL; ++ struct device_node *np; ++ ++ np = mtd_get_of_node(mtd); ++ if (np && !mtd->name) { ++ of_property_read_string(np, "linux,mtd-name", &of_mtd_name); ++ if (of_mtd_name) ++ mtd->name = of_mtd_name; ++ } else ++#endif + if (mtd->dev.parent) { + if (!mtd->owner && mtd->dev.parent->driver) + mtd->owner = mtd->dev.parent->driver->owner;