]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mtd: basic (read only) driver for BCMA serial flash
authorRafał Miłecki <zajec5@gmail.com>
Mon, 17 Sep 2012 09:50:49 +0000 (11:50 +0200)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Tue, 18 Sep 2012 11:00:10 +0000 (14:00 +0300)
This registers MTD driver for serial flash platform device. Right now it
supports reading only, writing still has to be implemented.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
drivers/mtd/devices/Kconfig
drivers/mtd/devices/Makefile
drivers/mtd/devices/bcm47xxsflash.c [new file with mode: 0644]
include/linux/bcma/bcma_driver_chipcommon.h

index 6cc5a1ac380218809155eed6ff1ce2f3c861e68a..ce6e3d4029d0c90650f83be2b9ebd16a98dd328d 100644 (file)
@@ -120,6 +120,14 @@ config MTD_SST25L
          Set up your spi devices with the right board-specific platform data,
          if you want to specify device partitioning.
 
+config MTD_BCM47XXSFLASH
+       tristate "Support for serial flash on BCMA bus"
+       depends on BCMA_SFLASH
+       help
+         BCMA bus can have various flash memories attached, they are
+         registered by bcma as platform devices. This enables driver for
+         serial flash memories.
+
 config MTD_SLRAM
        tristate "Uncached system RAM"
        help
index a4dd1d822b6c0db81a2bafd7c9ed6b790ca4ac2e..395733a30ef44e7c483e79768db3c7b5e46e68ba 100644 (file)
@@ -19,5 +19,6 @@ obj-$(CONFIG_MTD_DATAFLASH)   += mtd_dataflash.o
 obj-$(CONFIG_MTD_M25P80)       += m25p80.o
 obj-$(CONFIG_MTD_SPEAR_SMI)    += spear_smi.o
 obj-$(CONFIG_MTD_SST25L)       += sst25l.o
+obj-$(CONFIG_MTD_BCM47XXSFLASH)        += bcm47xxsflash.o
 
 CFLAGS_docg3.o                 += -I$(src)
\ No newline at end of file
diff --git a/drivers/mtd/devices/bcm47xxsflash.c b/drivers/mtd/devices/bcm47xxsflash.c
new file mode 100644 (file)
index 0000000..a328872
--- /dev/null
@@ -0,0 +1,131 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/mtd/mtd.h>
+#include <linux/platform_device.h>
+#include <linux/bcma/bcma.h>
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Serial flash driver for BCMA bus");
+
+static const char *probes[] = { "bcm47xxpart", NULL };
+
+static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
+                             size_t *retlen, u_char *buf)
+{
+       struct bcma_sflash *sflash = mtd->priv;
+       size_t bytes_read = 0;
+       __iomem u8 *src = (__iomem u8 *)KSEG0ADDR(sflash->window + from);
+       int i;
+       size_t unaligned_before, unaligned_after;
+
+       /* Check address range */
+       if ((from + len) > mtd->size)
+               return -EINVAL;
+
+       unaligned_before = from & 0x3;
+       unaligned_after = (from + len) & 0x3;
+
+       for (i = 0; i < unaligned_before; i++) {
+               *buf = readb(src);
+               buf++;
+               src++;
+               bytes_read++;
+       }
+       for (i = from - unaligned_before; i < from + len - unaligned_after;
+            i += 4) {
+               *(u32 *)buf = readl(src);
+               buf += 4;
+               src += 4;
+               bytes_read += 4;
+       }
+       for (i = 0; i < unaligned_after; i++) {
+               *buf = readb(src);
+               buf++;
+               src++;
+               bytes_read++;
+       }
+
+       *retlen = bytes_read;
+
+       return 0;
+}
+
+static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash,
+                                  struct mtd_info *mtd)
+{
+       mtd->priv = sflash;
+       mtd->name = "bcm47xxsflash";
+       mtd->owner = THIS_MODULE;
+       mtd->type = MTD_ROM;
+       mtd->size = sflash->size;
+       mtd->_read = bcm47xxsflash_read;
+
+       /* TODO: implement writing support and verify/change following code */
+       mtd->flags = MTD_CAP_ROM;
+       mtd->writebufsize = mtd->writesize = 1;
+}
+
+static int bcm47xxsflash_probe(struct platform_device *pdev)
+{
+       struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
+       int err;
+
+       sflash->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
+       if (!sflash->mtd) {
+               err = -ENOMEM;
+               goto out;
+       }
+       bcm47xxsflash_fill_mtd(sflash, sflash->mtd);
+
+       err = mtd_device_parse_register(sflash->mtd, probes, NULL, NULL, 0);
+       if (err) {
+               pr_err("Failed to register MTD device: %d\n", err);
+               goto err_dev_reg;
+       }
+
+       return 0;
+
+err_dev_reg:
+       kfree(sflash->mtd);
+out:
+       return err;
+}
+
+static int __devexit bcm47xxsflash_remove(struct platform_device *pdev)
+{
+       struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
+
+       mtd_device_unregister(sflash->mtd);
+       kfree(sflash->mtd);
+
+       return 0;
+}
+
+static struct platform_driver bcma_sflash_driver = {
+       .remove = __devexit_p(bcm47xxsflash_remove),
+       .driver = {
+               .name = "bcma_sflash",
+               .owner = THIS_MODULE,
+       },
+};
+
+static int __init bcm47xxsflash_init(void)
+{
+       int err;
+
+       err = platform_driver_probe(&bcma_sflash_driver, bcm47xxsflash_probe);
+       if (err)
+               pr_err("Failed to register BCMA serial flash driver: %d\n",
+                      err);
+
+       return err;
+}
+
+static void __exit bcm47xxsflash_exit(void)
+{
+       platform_driver_unregister(&bcma_sflash_driver);
+}
+
+module_init(bcm47xxsflash_init);
+module_exit(bcm47xxsflash_exit);
index 6ba45d2b99db2e153be43225addaabdb39060072..1cf1749440ac66dabd8b0f797e80690bbde9961d 100644 (file)
@@ -522,6 +522,8 @@ struct bcma_sflash {
        u32 blocksize;
        u16 numblocks;
        u32 size;
+
+       struct mtd_info *mtd;
 };
 #endif