blob: a52acdccd0c4a83ced68f678c06c67ebf4b3b3c0 [file] [log] [blame]
Rafał Miłeckia54013702012-11-12 13:03:21 +01001/*
2 * BCM47XX NAND flash driver
3 *
4 * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com>
5 *
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.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/platform_device.h>
16#include <linux/bcma/bcma.h>
17
18#include "bcm47xxnflash.h"
19
20MODULE_DESCRIPTION("NAND flash driver for BCMA bus");
21MODULE_LICENSE("GPL");
22MODULE_AUTHOR("Rafał Miłecki");
23
24static const char *probes[] = { "bcm47xxpart", NULL };
25
26static int bcm47xxnflash_probe(struct platform_device *pdev)
27{
28 struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
29 struct bcm47xxnflash *b47n;
30 int err = 0;
31
32 b47n = kzalloc(sizeof(*b47n), GFP_KERNEL);
33 if (!b47n) {
34 err = -ENOMEM;
35 goto out;
36 }
37
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);
42
Rafał Miłecki00940a22012-11-12 13:03:25 +010043 if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
44 err = bcm47xxnflash_ops_bcm4706_init(b47n);
Rafał Miłeckia54013702012-11-12 13:03:21 +010045 } else {
46 pr_err("Device not supported\n");
47 err = -ENOTSUPP;
48 }
49 if (err) {
50 pr_err("Initialization failed: %d\n", err);
51 goto err_init;
52 }
53
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;
58 }
59
60 return 0;
61
62err_dev_reg:
63err_init:
64 kfree(b47n);
65out:
66 return err;
67}
68
Greg Kroah-Hartmand8929942012-12-21 13:19:05 -080069static int bcm47xxnflash_remove(struct platform_device *pdev)
Rafał Miłeckia54013702012-11-12 13:03:21 +010070{
71 struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
72
73 if (nflash->mtd)
74 mtd_device_unregister(nflash->mtd);
75
76 return 0;
77}
78
79static struct platform_driver bcm47xxnflash_driver = {
Hauke Mehrtensa7bf6542013-01-28 11:25:48 +010080 .probe = bcm47xxnflash_probe,
Greg Kroah-Hartmand8929942012-12-21 13:19:05 -080081 .remove = bcm47xxnflash_remove,
Rafał Miłeckia54013702012-11-12 13:03:21 +010082 .driver = {
83 .name = "bcma_nflash",
84 .owner = THIS_MODULE,
85 },
86};
87
88static int __init bcm47xxnflash_init(void)
89{
90 int err;
91
Hauke Mehrtensa7bf6542013-01-28 11:25:48 +010092 err = platform_driver_register(&bcm47xxnflash_driver);
Rafał Miłeckia54013702012-11-12 13:03:21 +010093 if (err)
Hauke Mehrtens0fca6ab2013-01-28 11:25:47 +010094 pr_err("Failed to register bcm47xx nand flash driver: %d\n",
95 err);
Rafał Miłeckia54013702012-11-12 13:03:21 +010096
97 return err;
98}
99
100static void __exit bcm47xxnflash_exit(void)
101{
102 platform_driver_unregister(&bcm47xxnflash_driver);
103}
104
105module_init(bcm47xxnflash_init);
106module_exit(bcm47xxnflash_exit);