401-mtd-nor-support-mtd-name-from-device-tree.patch 1.6 KB

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