Skip to content

Commit 8e59130

Browse files
ffainellimiquelraynal
authored andcommitted
mtd: rawnand: brcmnand: Allow platform data instantation
Make use of the recently refactored code in brcmnand_init_cs() and derive the chip-select from the platform data that is supplied. Update the various code paths to avoid relying on possibly non-existent resources, too. Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 02d1d0e commit 8e59130

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

drivers/mtd/nand/raw/brcmnand/brcmnand.c

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/delay.h>
1010
#include <linux/device.h>
1111
#include <linux/platform_device.h>
12+
#include <linux/platform_data/brcmnand.h>
1213
#include <linux/err.h>
1314
#include <linux/completion.h>
1415
#include <linux/interrupt.h>
@@ -2768,7 +2769,8 @@ static const struct nand_controller_ops brcmnand_controller_ops = {
27682769
.attach_chip = brcmnand_attach_chip,
27692770
};
27702771

2771-
static int brcmnand_init_cs(struct brcmnand_host *host)
2772+
static int brcmnand_init_cs(struct brcmnand_host *host,
2773+
const char * const *part_probe_types)
27722774
{
27732775
struct brcmnand_controller *ctrl = host->ctrl;
27742776
struct device *dev = ctrl->dev;
@@ -2821,7 +2823,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host)
28212823
if (ret)
28222824
return ret;
28232825

2824-
ret = mtd_device_register(mtd, NULL, 0);
2826+
ret = mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
28252827
if (ret)
28262828
nand_cleanup(chip);
28272829

@@ -2990,17 +2992,15 @@ static int brcmnand_edu_setup(struct platform_device *pdev)
29902992

29912993
int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
29922994
{
2995+
struct brcmnand_platform_data *pd = dev_get_platdata(&pdev->dev);
29932996
struct device *dev = &pdev->dev;
29942997
struct device_node *dn = dev->of_node, *child;
29952998
struct brcmnand_controller *ctrl;
2999+
struct brcmnand_host *host;
29963000
struct resource *res;
29973001
int ret;
29983002

2999-
/* We only support device-tree instantiation */
3000-
if (!dn)
3001-
return -ENODEV;
3002-
3003-
if (!of_match_node(brcmnand_of_match, dn))
3003+
if (dn && !of_match_node(brcmnand_of_match, dn))
30043004
return -ENODEV;
30053005

30063006
ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
@@ -3027,7 +3027,7 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
30273027
/* NAND register range */
30283028
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
30293029
ctrl->nand_base = devm_ioremap_resource(dev, res);
3030-
if (IS_ERR(ctrl->nand_base))
3030+
if (IS_ERR(ctrl->nand_base) && !brcmnand_soc_has_ops(soc))
30313031
return PTR_ERR(ctrl->nand_base);
30323032

30333033
/* Enable clock before using NAND registers */
@@ -3171,7 +3171,6 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
31713171

31723172
for_each_available_child_of_node(dn, child) {
31733173
if (of_device_is_compatible(child, "brcm,nandcs")) {
3174-
struct brcmnand_host *host;
31753174

31763175
host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
31773176
if (!host) {
@@ -3191,7 +3190,7 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
31913190

31923191
nand_set_flash_node(&host->chip, child);
31933192

3194-
ret = brcmnand_init_cs(host);
3193+
ret = brcmnand_init_cs(host, NULL);
31953194
if (ret) {
31963195
devm_kfree(dev, host);
31973196
continue; /* Try all chip-selects */
@@ -3201,6 +3200,32 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
32013200
}
32023201
}
32033202

3203+
if (!list_empty(&ctrl->host_list))
3204+
return 0;
3205+
3206+
if (!pd) {
3207+
ret = -ENODEV;
3208+
goto err;
3209+
}
3210+
3211+
/* If we got there we must have been probing via platform data */
3212+
host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
3213+
if (!host) {
3214+
ret = -ENOMEM;
3215+
goto err;
3216+
}
3217+
host->pdev = pdev;
3218+
host->ctrl = ctrl;
3219+
host->cs = pd->chip_select;
3220+
host->chip.ecc.size = pd->ecc_stepsize;
3221+
host->chip.ecc.strength = pd->ecc_strength;
3222+
3223+
ret = brcmnand_init_cs(host, pd->part_probe_types);
3224+
if (ret)
3225+
goto err;
3226+
3227+
list_add_tail(&host->node, &ctrl->host_list);
3228+
32043229
/* No chip-selects could initialize properly */
32053230
if (list_empty(&ctrl->host_list)) {
32063231
ret = -ENODEV;

0 commit comments

Comments
 (0)