1239-mtd-extend-physmap_of-to-let-the-device-tree-specify.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. From 6b54054c4053215fe4add195c67daca9a466ba92 Mon Sep 17 00:00:00 2001
  2. From: "ying.zhang" <ying.zhang22455@nxp.com>
  3. Date: Fri, 23 Dec 2016 22:21:22 +0800
  4. Subject: [PATCH] mtd: extend physmap_of to let the device tree specify the
  5. parition probe
  6. This is to support custom partitioning schemes for embedded PPC. To use
  7. define your own mtd_part_parser and then add something like:
  8. linux,part-probe = "my_probe", "cmdlinepart";
  9. To the board's dts file.
  10. If linux,part-probe is not specified then this behaves the same as before.
  11. Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
  12. Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  13. ---
  14. drivers/mtd/maps/physmap_of.c | 46 ++++++++++++++++++++++++++++++++++++++++-
  15. 1 file changed, 45 insertions(+), 1 deletion(-)
  16. --- a/drivers/mtd/maps/physmap_of.c
  17. +++ b/drivers/mtd/maps/physmap_of.c
  18. @@ -112,9 +112,47 @@ static struct mtd_info *obsolete_probe(s
  19. static const char * const part_probe_types_def[] = {
  20. "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
  21. +static const char * const *of_get_probes(struct device_node *dp)
  22. +{
  23. + const char *cp;
  24. + int cplen;
  25. + unsigned int l;
  26. + unsigned int count;
  27. + const char **res;
  28. +
  29. + cp = of_get_property(dp, "linux,part-probe", &cplen);
  30. + if (cp == NULL)
  31. + return part_probe_types_def;
  32. +
  33. + count = 0;
  34. + for (l = 0; l != cplen; l++)
  35. + if (cp[l] == 0)
  36. + count++;
  37. +
  38. + res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
  39. + if (!res)
  40. + return NULL;
  41. + count = 0;
  42. + while (cplen > 0) {
  43. + res[count] = cp;
  44. + l = strlen(cp) + 1;
  45. + cp += l;
  46. + cplen -= l;
  47. + count++;
  48. + }
  49. + return res;
  50. +}
  51. +
  52. +static void of_free_probes(const char * const *probes)
  53. +{
  54. + if (probes != part_probe_types_def)
  55. + kfree(probes);
  56. +}
  57. +
  58. static const struct of_device_id of_flash_match[];
  59. static int of_flash_probe(struct platform_device *dev)
  60. {
  61. + const char * const *part_probe_types;
  62. const struct of_device_id *match;
  63. struct device_node *dp = dev->dev.of_node;
  64. struct resource res;
  65. @@ -273,8 +311,14 @@ static int of_flash_probe(struct platfor
  66. goto err_out;
  67. ppdata.of_node = dp;
  68. - mtd_device_parse_register(info->cmtd, part_probe_types_def, &ppdata,
  69. + part_probe_types = of_get_probes(dp);
  70. + if (!part_probe_types) {
  71. + err = -ENOMEM;
  72. + goto err_out;
  73. + }
  74. + mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
  75. NULL, 0);
  76. + of_free_probes(part_probe_types);
  77. kfree(mtd_list);