1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/slab.h>
4 #include <linux/mtd/mtd.h>
5 #include <linux/platform_device.h>
6 #include <linux/bcma/bcma.h>
9 MODULE_DESCRIPTION("Serial flash driver for BCMA bus");
11 static const char *probes[] = { "bcm47xxpart", NULL };
13 static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
14 size_t *retlen, u_char *buf)
16 struct bcma_sflash *sflash = mtd->priv;
18 /* Check address range */
19 if ((from + len) > mtd->size)
22 memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(sflash->window + from),
28 static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash,
32 mtd->name = "bcm47xxsflash";
33 mtd->owner = THIS_MODULE;
35 mtd->size = sflash->size;
36 mtd->_read = bcm47xxsflash_read;
38 /* TODO: implement writing support and verify/change following code */
39 mtd->flags = MTD_CAP_ROM;
40 mtd->writebufsize = mtd->writesize = 1;
43 static int bcm47xxsflash_probe(struct platform_device *pdev)
45 struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
48 sflash->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
53 bcm47xxsflash_fill_mtd(sflash, sflash->mtd);
55 err = mtd_device_parse_register(sflash->mtd, probes, NULL, NULL, 0);
57 pr_err("Failed to register MTD device: %d\n", err);
69 static int bcm47xxsflash_remove(struct platform_device *pdev)
71 struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
73 mtd_device_unregister(sflash->mtd);
79 static struct platform_driver bcma_sflash_driver = {
80 .remove = bcm47xxsflash_remove,
82 .name = "bcma_sflash",
87 static int __init bcm47xxsflash_init(void)
91 err = platform_driver_probe(&bcma_sflash_driver, bcm47xxsflash_probe);
93 pr_err("Failed to register BCMA serial flash driver: %d\n",
99 static void __exit bcm47xxsflash_exit(void)
101 platform_driver_unregister(&bcma_sflash_driver);
104 module_init(bcm47xxsflash_init);
105 module_exit(bcm47xxsflash_exit);