Linux 3.11-rc3
[cris-mirror.git] / drivers / mtd / nand / bcm47xxnflash / main.c
blob7bae569fdc79880e5025a5db3e93dd34da274598
1 /*
2 * BCM47XX NAND flash driver
4 * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include "bcm47xxnflash.h"
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/platform_device.h>
18 #include <linux/bcma/bcma.h>
20 MODULE_DESCRIPTION("NAND flash driver for BCMA bus");
21 MODULE_LICENSE("GPL");
22 MODULE_AUTHOR("Rafał Miłecki");
24 static const char *probes[] = { "bcm47xxpart", NULL };
26 static int bcm47xxnflash_probe(struct platform_device *pdev)
28 struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
29 struct bcm47xxnflash *b47n;
30 int err = 0;
32 b47n = kzalloc(sizeof(*b47n), GFP_KERNEL);
33 if (!b47n) {
34 err = -ENOMEM;
35 goto out;
38 b47n->nand_chip.priv = b47n;
39 b47n->mtd.owner = THIS_MODULE;
40 b47n->mtd.priv = &b47n->nand_chip; /* Required */
41 b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
43 if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
44 err = bcm47xxnflash_ops_bcm4706_init(b47n);
45 } else {
46 pr_err("Device not supported\n");
47 err = -ENOTSUPP;
49 if (err) {
50 pr_err("Initialization failed: %d\n", err);
51 goto err_init;
54 err = mtd_device_parse_register(&b47n->mtd, probes, NULL, NULL, 0);
55 if (err) {
56 pr_err("Failed to register MTD device: %d\n", err);
57 goto err_dev_reg;
60 return 0;
62 err_dev_reg:
63 err_init:
64 kfree(b47n);
65 out:
66 return err;
69 static int bcm47xxnflash_remove(struct platform_device *pdev)
71 struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
73 if (nflash->mtd)
74 mtd_device_unregister(nflash->mtd);
76 return 0;
79 static struct platform_driver bcm47xxnflash_driver = {
80 .probe = bcm47xxnflash_probe,
81 .remove = bcm47xxnflash_remove,
82 .driver = {
83 .name = "bcma_nflash",
84 .owner = THIS_MODULE,
88 static int __init bcm47xxnflash_init(void)
90 int err;
92 err = platform_driver_register(&bcm47xxnflash_driver);
93 if (err)
94 pr_err("Failed to register bcm47xx nand flash driver: %d\n",
95 err);
97 return err;
100 static void __exit bcm47xxnflash_exit(void)
102 platform_driver_unregister(&bcm47xxnflash_driver);
105 module_init(bcm47xxnflash_init);
106 module_exit(bcm47xxnflash_exit);