blob: 461577cfb5bc64d2d6ccebeea6d79cc3fff11b34 [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
Rafał Miłeckibe0638d2013-02-07 11:56:04 +010012#include "bcm47xxnflash.h"
13
Rafał Miłeckia54013702012-11-12 13:03:21 +010014#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>
19
Rafał Miłeckia54013702012-11-12 13:03:21 +010020MODULE_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
Sachin Kamat7e3019e2013-10-11 10:11:25 +053032 b47n = devm_kzalloc(&pdev->dev, sizeof(*b47n), GFP_KERNEL);
33 if (!b47n)
34 return -ENOMEM;
Rafał Miłeckia54013702012-11-12 13:03:21 +010035
36 b47n->nand_chip.priv = b47n;
37 b47n->mtd.owner = THIS_MODULE;
38 b47n->mtd.priv = &b47n->nand_chip; /* Required */
39 b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
40
Rafał Miłecki00940a22012-11-12 13:03:25 +010041 if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
42 err = bcm47xxnflash_ops_bcm4706_init(b47n);
Rafał Miłeckia54013702012-11-12 13:03:21 +010043 } else {
44 pr_err("Device not supported\n");
45 err = -ENOTSUPP;
46 }
47 if (err) {
48 pr_err("Initialization failed: %d\n", err);
Sachin Kamat7e3019e2013-10-11 10:11:25 +053049 return err;
Rafał Miłeckia54013702012-11-12 13:03:21 +010050 }
51
52 err = mtd_device_parse_register(&b47n->mtd, probes, NULL, NULL, 0);
53 if (err) {
54 pr_err("Failed to register MTD device: %d\n", err);
Sachin Kamat7e3019e2013-10-11 10:11:25 +053055 return err;
Rafał Miłeckia54013702012-11-12 13:03:21 +010056 }
57
58 return 0;
Rafał Miłeckia54013702012-11-12 13:03:21 +010059}
60
Greg Kroah-Hartmand8929942012-12-21 13:19:05 -080061static int bcm47xxnflash_remove(struct platform_device *pdev)
Rafał Miłeckia54013702012-11-12 13:03:21 +010062{
63 struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
64
65 if (nflash->mtd)
66 mtd_device_unregister(nflash->mtd);
67
68 return 0;
69}
70
71static struct platform_driver bcm47xxnflash_driver = {
Hauke Mehrtensa7bf6542013-01-28 11:25:48 +010072 .probe = bcm47xxnflash_probe,
Greg Kroah-Hartmand8929942012-12-21 13:19:05 -080073 .remove = bcm47xxnflash_remove,
Rafał Miłeckia54013702012-11-12 13:03:21 +010074 .driver = {
75 .name = "bcma_nflash",
Rafał Miłeckia54013702012-11-12 13:03:21 +010076 },
77};
78
Sachin Kamat994bbd02013-10-11 10:11:24 +053079module_platform_driver(bcm47xxnflash_driver);