Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * BCM47XX NAND flash driver
0004  *
0005  * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com>
0006  */
0007 
0008 #include "bcm47xxnflash.h"
0009 
0010 #include <linux/module.h>
0011 #include <linux/kernel.h>
0012 #include <linux/slab.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/bcma/bcma.h>
0015 
0016 MODULE_DESCRIPTION("NAND flash driver for BCMA bus");
0017 MODULE_LICENSE("GPL");
0018 MODULE_AUTHOR("Rafał Miłecki");
0019 
0020 static const char *probes[] = { "bcm47xxpart", NULL };
0021 
0022 static int bcm47xxnflash_probe(struct platform_device *pdev)
0023 {
0024     struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
0025     struct bcm47xxnflash *b47n;
0026     struct mtd_info *mtd;
0027     int err = 0;
0028 
0029     b47n = devm_kzalloc(&pdev->dev, sizeof(*b47n), GFP_KERNEL);
0030     if (!b47n)
0031         return -ENOMEM;
0032 
0033     nand_set_controller_data(&b47n->nand_chip, b47n);
0034     mtd = nand_to_mtd(&b47n->nand_chip);
0035     mtd->dev.parent = &pdev->dev;
0036     b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
0037 
0038     if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
0039         err = bcm47xxnflash_ops_bcm4706_init(b47n);
0040     } else {
0041         pr_err("Device not supported\n");
0042         err = -ENOTSUPP;
0043     }
0044     if (err) {
0045         pr_err("Initialization failed: %d\n", err);
0046         return err;
0047     }
0048 
0049     platform_set_drvdata(pdev, b47n);
0050 
0051     err = mtd_device_parse_register(mtd, probes, NULL, NULL, 0);
0052     if (err) {
0053         pr_err("Failed to register MTD device: %d\n", err);
0054         return err;
0055     }
0056 
0057     return 0;
0058 }
0059 
0060 static int bcm47xxnflash_remove(struct platform_device *pdev)
0061 {
0062     struct bcm47xxnflash *nflash = platform_get_drvdata(pdev);
0063     struct nand_chip *chip = &nflash->nand_chip;
0064     int ret;
0065 
0066     ret = mtd_device_unregister(nand_to_mtd(chip));
0067     WARN_ON(ret);
0068     nand_cleanup(chip);
0069 
0070     return 0;
0071 }
0072 
0073 static struct platform_driver bcm47xxnflash_driver = {
0074     .probe  = bcm47xxnflash_probe,
0075     .remove = bcm47xxnflash_remove,
0076     .driver = {
0077         .name = "bcma_nflash",
0078     },
0079 };
0080 
0081 module_platform_driver(bcm47xxnflash_driver);