Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 1 | /* |
| 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łecki | be0638d | 2013-02-07 11:56:04 +0100 | [diff] [blame] | 12 | #include "bcm47xxnflash.h" |
| 13 | |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 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> |
| 19 | |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 20 | MODULE_DESCRIPTION("NAND flash driver for BCMA bus"); |
| 21 | MODULE_LICENSE("GPL"); |
| 22 | MODULE_AUTHOR("Rafał Miłecki"); |
| 23 | |
| 24 | static const char *probes[] = { "bcm47xxpart", NULL }; |
| 25 | |
| 26 | static int bcm47xxnflash_probe(struct platform_device *pdev) |
| 27 | { |
| 28 | struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev); |
| 29 | struct bcm47xxnflash *b47n; |
Boris BREZILLON | 17dd20b | 2015-12-10 08:59:52 +0100 | [diff] [blame^] | 30 | struct mtd_info *mtd; |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 31 | int err = 0; |
| 32 | |
Sachin Kamat | 7e3019e | 2013-10-11 10:11:25 +0530 | [diff] [blame] | 33 | b47n = devm_kzalloc(&pdev->dev, sizeof(*b47n), GFP_KERNEL); |
| 34 | if (!b47n) |
| 35 | return -ENOMEM; |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 36 | |
| 37 | b47n->nand_chip.priv = b47n; |
Boris BREZILLON | 17dd20b | 2015-12-10 08:59:52 +0100 | [diff] [blame^] | 38 | mtd = nand_to_mtd(&b47n->nand_chip); |
| 39 | mtd->dev.parent = &pdev->dev; |
| 40 | mtd->priv = &b47n->nand_chip; /* Required */ |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 41 | b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash); |
| 42 | |
Rafał Miłecki | 00940a2 | 2012-11-12 13:03:25 +0100 | [diff] [blame] | 43 | if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) { |
| 44 | err = bcm47xxnflash_ops_bcm4706_init(b47n); |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 45 | } else { |
| 46 | pr_err("Device not supported\n"); |
| 47 | err = -ENOTSUPP; |
| 48 | } |
| 49 | if (err) { |
| 50 | pr_err("Initialization failed: %d\n", err); |
Sachin Kamat | 7e3019e | 2013-10-11 10:11:25 +0530 | [diff] [blame] | 51 | return err; |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Brian Norris | 665d2c2 | 2015-12-08 17:04:59 -0800 | [diff] [blame] | 54 | platform_set_drvdata(pdev, b47n); |
| 55 | |
Boris BREZILLON | 17dd20b | 2015-12-10 08:59:52 +0100 | [diff] [blame^] | 56 | err = mtd_device_parse_register(mtd, probes, NULL, NULL, 0); |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 57 | if (err) { |
| 58 | pr_err("Failed to register MTD device: %d\n", err); |
Sachin Kamat | 7e3019e | 2013-10-11 10:11:25 +0530 | [diff] [blame] | 59 | return err; |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | return 0; |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Greg Kroah-Hartman | d892994 | 2012-12-21 13:19:05 -0800 | [diff] [blame] | 65 | static int bcm47xxnflash_remove(struct platform_device *pdev) |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 66 | { |
Brian Norris | 665d2c2 | 2015-12-08 17:04:59 -0800 | [diff] [blame] | 67 | struct bcm47xxnflash *nflash = platform_get_drvdata(pdev); |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 68 | |
Boris BREZILLON | 17dd20b | 2015-12-10 08:59:52 +0100 | [diff] [blame^] | 69 | nand_release(nand_to_mtd(&nflash->nand_chip)); |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static struct platform_driver bcm47xxnflash_driver = { |
Hauke Mehrtens | a7bf654 | 2013-01-28 11:25:48 +0100 | [diff] [blame] | 75 | .probe = bcm47xxnflash_probe, |
Greg Kroah-Hartman | d892994 | 2012-12-21 13:19:05 -0800 | [diff] [blame] | 76 | .remove = bcm47xxnflash_remove, |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 77 | .driver = { |
| 78 | .name = "bcma_nflash", |
Rafał Miłecki | a5401370 | 2012-11-12 13:03:21 +0100 | [diff] [blame] | 79 | }, |
| 80 | }; |
| 81 | |
Sachin Kamat | 994bbd0 | 2013-10-11 10:11:24 +0530 | [diff] [blame] | 82 | module_platform_driver(bcm47xxnflash_driver); |