406-v6.2-0002-mtd-core-try-to-find-OF-node-for-every-MTD-partition.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From ddb8cefb7af288950447ca6eeeafb09977dab56f Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  3. Date: Tue, 4 Oct 2022 10:37:10 +0200
  4. Subject: [PATCH] mtd: core: try to find OF node for every MTD partition
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. So far this feature was limited to the top-level "nvmem-cells" node.
  9. There are multiple parsers creating partitions and subpartitions
  10. dynamically. Extend that code to handle them too.
  11. This allows finding partition-* node for every MTD (sub)partition.
  12. Random example:
  13. partitions {
  14. compatible = "brcm,bcm947xx-cfe-partitions";
  15. partition-firmware {
  16. compatible = "brcm,trx";
  17. partition-loader {
  18. };
  19. };
  20. };
  21. Cc: Christian Marangi <[email protected]>
  22. Signed-off-by: Rafał Miłecki <[email protected]>
  23. Signed-off-by: Miquel Raynal <[email protected]>
  24. Link: https://lore.kernel.org/linux-mtd/[email protected]
  25. ---
  26. drivers/mtd/mtdcore.c | 18 ++++++------------
  27. 1 file changed, 6 insertions(+), 12 deletions(-)
  28. --- a/drivers/mtd/mtdcore.c
  29. +++ b/drivers/mtd/mtdcore.c
  30. @@ -569,20 +569,22 @@ static void mtd_check_of_node(struct mtd
  31. struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
  32. const char *pname, *prefix = "partition-";
  33. int plen, mtd_name_len, offset, prefix_len;
  34. - bool found = false;
  35. /* Check if MTD already has a device node */
  36. if (mtd_get_of_node(mtd))
  37. return;
  38. - /* Check if a partitions node exist */
  39. if (!mtd_is_partition(mtd))
  40. return;
  41. +
  42. parent_dn = of_node_get(mtd_get_of_node(mtd->parent));
  43. if (!parent_dn)
  44. return;
  45. - partitions = of_get_child_by_name(parent_dn, "partitions");
  46. + if (mtd_is_partition(mtd->parent))
  47. + partitions = of_node_get(parent_dn);
  48. + else
  49. + partitions = of_get_child_by_name(parent_dn, "partitions");
  50. if (!partitions)
  51. goto exit_parent;
  52. @@ -606,19 +608,11 @@ static void mtd_check_of_node(struct mtd
  53. plen = strlen(pname) - offset;
  54. if (plen == mtd_name_len &&
  55. !strncmp(mtd->name, pname + offset, plen)) {
  56. - found = true;
  57. + mtd_set_of_node(mtd, mtd_dn);
  58. break;
  59. }
  60. }
  61. - if (!found)
  62. - goto exit_partitions;
  63. -
  64. - /* Set of_node only for nvmem */
  65. - if (of_device_is_compatible(mtd_dn, "nvmem-cells"))
  66. - mtd_set_of_node(mtd, mtd_dn);
  67. -
  68. -exit_partitions:
  69. of_node_put(partitions);
  70. exit_parent:
  71. of_node_put(parent_dn);