106-v5.18-mtd-rawnand-brcmnand-Allow-platform-data-instantation.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. From: Florian Fainelli <[email protected]>
  2. Subject: [PATCH v3 7/9] mtd: rawnand: brcmnand: Allow platform data instantation
  3. Date: Fri, 07 Jan 2022 10:46:12 -0800
  4. Content-Type: text/plain; charset="utf-8"
  5. Make use of the recently refactored code in brcmnand_init_cs() and
  6. derive the chip-select from the platform data that is supplied. Update
  7. the various code paths to avoid relying on possibly non-existent
  8. resources, too.
  9. Signed-off-by: Florian Fainelli <[email protected]>
  10. ---
  11. drivers/mtd/nand/raw/brcmnand/brcmnand.c | 45 ++++++++++++++++++------
  12. 1 file changed, 35 insertions(+), 10 deletions(-)
  13. --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
  14. +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
  15. @@ -9,6 +9,7 @@
  16. #include <linux/delay.h>
  17. #include <linux/device.h>
  18. #include <linux/platform_device.h>
  19. +#include <linux/platform_data/brcmnand.h>
  20. #include <linux/err.h>
  21. #include <linux/completion.h>
  22. #include <linux/interrupt.h>
  23. @@ -2811,7 +2812,8 @@ static const struct nand_controller_ops
  24. .attach_chip = brcmnand_attach_chip,
  25. };
  26. -static int brcmnand_init_cs(struct brcmnand_host *host)
  27. +static int brcmnand_init_cs(struct brcmnand_host *host,
  28. + const char * const *part_probe_types)
  29. {
  30. struct brcmnand_controller *ctrl = host->ctrl;
  31. struct device *dev = ctrl->dev;
  32. @@ -2864,7 +2866,7 @@ static int brcmnand_init_cs(struct brcmn
  33. if (ret)
  34. return ret;
  35. - ret = mtd_device_register(mtd, NULL, 0);
  36. + ret = mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
  37. if (ret)
  38. nand_cleanup(chip);
  39. @@ -3033,17 +3035,15 @@ static int brcmnand_edu_setup(struct pla
  40. int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
  41. {
  42. + struct brcmnand_platform_data *pd = dev_get_platdata(&pdev->dev);
  43. struct device *dev = &pdev->dev;
  44. struct device_node *dn = dev->of_node, *child;
  45. struct brcmnand_controller *ctrl;
  46. + struct brcmnand_host *host;
  47. struct resource *res;
  48. int ret;
  49. - /* We only support device-tree instantiation */
  50. - if (!dn)
  51. - return -ENODEV;
  52. -
  53. - if (!of_match_node(brcmnand_of_match, dn))
  54. + if (dn && !of_match_node(brcmnand_of_match, dn))
  55. return -ENODEV;
  56. ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
  57. @@ -3070,7 +3070,7 @@ int brcmnand_probe(struct platform_devic
  58. /* NAND register range */
  59. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  60. ctrl->nand_base = devm_ioremap_resource(dev, res);
  61. - if (IS_ERR(ctrl->nand_base))
  62. + if (IS_ERR(ctrl->nand_base) && !brcmnand_soc_has_ops(soc))
  63. return PTR_ERR(ctrl->nand_base);
  64. /* Enable clock before using NAND registers */
  65. @@ -3218,7 +3218,6 @@ int brcmnand_probe(struct platform_devic
  66. for_each_available_child_of_node(dn, child) {
  67. if (of_device_is_compatible(child, "brcm,nandcs")) {
  68. - struct brcmnand_host *host;
  69. host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
  70. if (!host) {
  71. @@ -3238,7 +3237,7 @@ int brcmnand_probe(struct platform_devic
  72. nand_set_flash_node(&host->chip, child);
  73. - ret = brcmnand_init_cs(host);
  74. + ret = brcmnand_init_cs(host, NULL);
  75. if (ret) {
  76. devm_kfree(dev, host);
  77. continue; /* Try all chip-selects */
  78. @@ -3248,6 +3247,32 @@ int brcmnand_probe(struct platform_devic
  79. }
  80. }
  81. + if (!list_empty(&ctrl->host_list))
  82. + return 0;
  83. +
  84. + if (!pd) {
  85. + ret = -ENODEV;
  86. + goto err;
  87. + }
  88. +
  89. + /* If we got there we must have been probing via platform data */
  90. + host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
  91. + if (!host) {
  92. + ret = -ENOMEM;
  93. + goto err;
  94. + }
  95. + host->pdev = pdev;
  96. + host->ctrl = ctrl;
  97. + host->cs = pd->chip_select;
  98. + host->chip.ecc.size = pd->ecc_stepsize;
  99. + host->chip.ecc.strength = pd->ecc_strength;
  100. +
  101. + ret = brcmnand_init_cs(host, pd->part_probe_types);
  102. + if (ret)
  103. + goto err;
  104. +
  105. + list_add_tail(&host->node, &ctrl->host_list);
  106. +
  107. /* No chip-selects could initialize properly */
  108. if (list_empty(&ctrl->host_list)) {
  109. ret = -ENODEV;