31d686b9557b41c7dab5bd18c52bb19eb79d432f
[openwrt/staging/rmilecki.git] /
1 From: Florian Fainelli <f.fainelli@gmail.com>
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
6 Make use of the recently refactored code in brcmnand_init_cs() and
7 derive the chip-select from the platform data that is supplied. Update
8 the various code paths to avoid relying on possibly non-existent
9 resources, too.
10
11 Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
12 ---
13 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 45 ++++++++++++++++++------
14 1 file changed, 35 insertions(+), 10 deletions(-)
15
16 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
17 +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
18 @@ -9,6 +9,7 @@
19 #include <linux/delay.h>
20 #include <linux/device.h>
21 #include <linux/platform_device.h>
22 +#include <linux/platform_data/brcmnand.h>
23 #include <linux/err.h>
24 #include <linux/completion.h>
25 #include <linux/interrupt.h>
26 @@ -2768,7 +2769,8 @@ static const struct nand_controller_ops
27 .attach_chip = brcmnand_attach_chip,
28 };
29
30 -static int brcmnand_init_cs(struct brcmnand_host *host)
31 +static int brcmnand_init_cs(struct brcmnand_host *host,
32 + const char * const *part_probe_types)
33 {
34 struct brcmnand_controller *ctrl = host->ctrl;
35 struct device *dev = ctrl->dev;
36 @@ -2821,7 +2823,7 @@ static int brcmnand_init_cs(struct brcmn
37 if (ret)
38 return ret;
39
40 - ret = mtd_device_register(mtd, NULL, 0);
41 + ret = mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
42 if (ret)
43 nand_cleanup(chip);
44
45 @@ -2990,17 +2992,15 @@ static int brcmnand_edu_setup(struct pla
46
47 int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
48 {
49 + struct brcmnand_platform_data *pd = dev_get_platdata(&pdev->dev);
50 struct device *dev = &pdev->dev;
51 struct device_node *dn = dev->of_node, *child;
52 struct brcmnand_controller *ctrl;
53 + struct brcmnand_host *host;
54 struct resource *res;
55 int ret;
56
57 - /* We only support device-tree instantiation */
58 - if (!dn)
59 - return -ENODEV;
60 -
61 - if (!of_match_node(brcmnand_of_match, dn))
62 + if (dn && !of_match_node(brcmnand_of_match, dn))
63 return -ENODEV;
64
65 ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
66 @@ -3027,7 +3027,7 @@ int brcmnand_probe(struct platform_devic
67 /* NAND register range */
68 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
69 ctrl->nand_base = devm_ioremap_resource(dev, res);
70 - if (IS_ERR(ctrl->nand_base))
71 + if (IS_ERR(ctrl->nand_base) && !brcmnand_soc_has_ops(soc))
72 return PTR_ERR(ctrl->nand_base);
73
74 /* Enable clock before using NAND registers */
75 @@ -3171,7 +3171,6 @@ int brcmnand_probe(struct platform_devic
76
77 for_each_available_child_of_node(dn, child) {
78 if (of_device_is_compatible(child, "brcm,nandcs")) {
79 - struct brcmnand_host *host;
80
81 host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
82 if (!host) {
83 @@ -3191,7 +3190,7 @@ int brcmnand_probe(struct platform_devic
84
85 nand_set_flash_node(&host->chip, child);
86
87 - ret = brcmnand_init_cs(host);
88 + ret = brcmnand_init_cs(host, NULL);
89 if (ret) {
90 devm_kfree(dev, host);
91 continue; /* Try all chip-selects */
92 @@ -3201,6 +3200,32 @@ int brcmnand_probe(struct platform_devic
93 }
94 }
95
96 + if (!list_empty(&ctrl->host_list))
97 + return 0;
98 +
99 + if (!pd) {
100 + ret = -ENODEV;
101 + goto err;
102 + }
103 +
104 + /* If we got there we must have been probing via platform data */
105 + host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
106 + if (!host) {
107 + ret = -ENOMEM;
108 + goto err;
109 + }
110 + host->pdev = pdev;
111 + host->ctrl = ctrl;
112 + host->cs = pd->chip_select;
113 + host->chip.ecc.size = pd->ecc_stepsize;
114 + host->chip.ecc.strength = pd->ecc_strength;
115 +
116 + ret = brcmnand_init_cs(host, pd->part_probe_types);
117 + if (ret)
118 + goto err;
119 +
120 + list_add_tail(&host->node, &ctrl->host_list);
121 +
122 /* No chip-selects could initialize properly */
123 if (list_empty(&ctrl->host_list)) {
124 ret = -ENODEV;