400-v5.19-mtd-call-of_platform_populate-for-MTD-partitions.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From bcdf0315a61a29eb753a607d3a85a4032de72d94 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  3. Date: Tue, 10 May 2022 15:12:59 +0200
  4. Subject: [PATCH] mtd: call of_platform_populate() for MTD partitions
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Until this change MTD subsystem supported handling partitions only with
  9. MTD partitions parsers. That's a specific / limited API designed around
  10. partitions.
  11. Some MTD partitions may however require different handling. They may
  12. contain specific data that needs to be parsed and somehow extracted. For
  13. that purpose MTD subsystem should allow binding of standard platform
  14. drivers.
  15. An example can be U-Boot (sub)partition with environment variables.
  16. There exist a "u-boot,env" DT binding for MTD (sub)partition that
  17. requires an NVMEM driver.
  18. Ref: 5db1c2dbc04c ("dt-bindings: nvmem: add U-Boot environment variables binding")
  19. Signed-off-by: Rafał Miłecki <[email protected]>
  20. Signed-off-by: Miquel Raynal <[email protected]>
  21. Link: https://lore.kernel.org/linux-mtd/[email protected]
  22. ---
  23. drivers/mtd/mtdpart.c | 9 +++++++++
  24. 1 file changed, 9 insertions(+)
  25. --- a/drivers/mtd/mtdpart.c
  26. +++ b/drivers/mtd/mtdpart.c
  27. @@ -17,6 +17,7 @@
  28. #include <linux/mtd/partitions.h>
  29. #include <linux/err.h>
  30. #include <linux/of.h>
  31. +#include <linux/of_platform.h>
  32. #include "mtdcore.h"
  33. @@ -577,10 +578,16 @@ static int mtd_part_of_parse(struct mtd_
  34. struct mtd_part_parser *parser;
  35. struct device_node *np;
  36. struct property *prop;
  37. + struct device *dev;
  38. const char *compat;
  39. const char *fixed = "fixed-partitions";
  40. int ret, err = 0;
  41. + dev = &master->dev;
  42. + /* Use parent device (controller) if the top level MTD is not registered */
  43. + if (!IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) && !mtd_is_partition(master))
  44. + dev = master->dev.parent;
  45. +
  46. np = mtd_get_of_node(master);
  47. if (mtd_is_partition(master))
  48. of_node_get(np);
  49. @@ -593,6 +600,7 @@ static int mtd_part_of_parse(struct mtd_
  50. continue;
  51. ret = mtd_part_do_parse(parser, master, pparts, NULL);
  52. if (ret > 0) {
  53. + of_platform_populate(np, NULL, NULL, dev);
  54. of_node_put(np);
  55. return ret;
  56. }
  57. @@ -600,6 +608,7 @@ static int mtd_part_of_parse(struct mtd_
  58. if (ret < 0 && !err)
  59. err = ret;
  60. }
  61. + of_platform_populate(np, NULL, NULL, dev);
  62. of_node_put(np);
  63. /*