1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * BCM47XX NAND flash driver
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com>
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include "bcm47xxnflash.h"
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #include <linux/module.h>
11*4882a593Smuzhiyun #include <linux/kernel.h>
12*4882a593Smuzhiyun #include <linux/slab.h>
13*4882a593Smuzhiyun #include <linux/platform_device.h>
14*4882a593Smuzhiyun #include <linux/bcma/bcma.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun MODULE_DESCRIPTION("NAND flash driver for BCMA bus");
17*4882a593Smuzhiyun MODULE_LICENSE("GPL");
18*4882a593Smuzhiyun MODULE_AUTHOR("Rafał Miłecki");
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun static const char *probes[] = { "bcm47xxpart", NULL };
21*4882a593Smuzhiyun
bcm47xxnflash_probe(struct platform_device * pdev)22*4882a593Smuzhiyun static int bcm47xxnflash_probe(struct platform_device *pdev)
23*4882a593Smuzhiyun {
24*4882a593Smuzhiyun struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
25*4882a593Smuzhiyun struct bcm47xxnflash *b47n;
26*4882a593Smuzhiyun struct mtd_info *mtd;
27*4882a593Smuzhiyun int err = 0;
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun b47n = devm_kzalloc(&pdev->dev, sizeof(*b47n), GFP_KERNEL);
30*4882a593Smuzhiyun if (!b47n)
31*4882a593Smuzhiyun return -ENOMEM;
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun nand_set_controller_data(&b47n->nand_chip, b47n);
34*4882a593Smuzhiyun mtd = nand_to_mtd(&b47n->nand_chip);
35*4882a593Smuzhiyun mtd->dev.parent = &pdev->dev;
36*4882a593Smuzhiyun b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
39*4882a593Smuzhiyun err = bcm47xxnflash_ops_bcm4706_init(b47n);
40*4882a593Smuzhiyun } else {
41*4882a593Smuzhiyun pr_err("Device not supported\n");
42*4882a593Smuzhiyun err = -ENOTSUPP;
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun if (err) {
45*4882a593Smuzhiyun pr_err("Initialization failed: %d\n", err);
46*4882a593Smuzhiyun return err;
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun platform_set_drvdata(pdev, b47n);
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun err = mtd_device_parse_register(mtd, probes, NULL, NULL, 0);
52*4882a593Smuzhiyun if (err) {
53*4882a593Smuzhiyun pr_err("Failed to register MTD device: %d\n", err);
54*4882a593Smuzhiyun return err;
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun return 0;
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun
bcm47xxnflash_remove(struct platform_device * pdev)60*4882a593Smuzhiyun static int bcm47xxnflash_remove(struct platform_device *pdev)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun struct bcm47xxnflash *nflash = platform_get_drvdata(pdev);
63*4882a593Smuzhiyun struct nand_chip *chip = &nflash->nand_chip;
64*4882a593Smuzhiyun int ret;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun ret = mtd_device_unregister(nand_to_mtd(chip));
67*4882a593Smuzhiyun WARN_ON(ret);
68*4882a593Smuzhiyun nand_cleanup(chip);
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun return 0;
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun static struct platform_driver bcm47xxnflash_driver = {
74*4882a593Smuzhiyun .probe = bcm47xxnflash_probe,
75*4882a593Smuzhiyun .remove = bcm47xxnflash_remove,
76*4882a593Smuzhiyun .driver = {
77*4882a593Smuzhiyun .name = "bcma_nflash",
78*4882a593Smuzhiyun },
79*4882a593Smuzhiyun };
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun module_platform_driver(bcm47xxnflash_driver);
82