-From b5be6e3037650ff5615cb869f1972dea5a49bcb6 Mon Sep 17 00:00:00 2001
+From a62940e988526c881966a8c72cc28c95fca89f3c Mon Sep 17 00:00:00 2001
From: Hauke Mehrtens <hauke@hauke-m.de>
Date: Sun, 17 Jul 2011 14:53:07 +0200
-Subject: [PATCH 13/22] bcma: add serial flash support to bcma
+Subject: [PATCH 13/26] bcma: add serial flash support to bcma
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
drivers/bcma/Kconfig | 5 +
drivers/bcma/Makefile | 1 +
drivers/bcma/bcma_private.h | 5 +
- drivers/bcma/driver_chipcommon_sflash.c | 554 +++++++++++++++++++++++++++
+ drivers/bcma/driver_chipcommon_sflash.c | 555 +++++++++++++++++++++++++++
drivers/bcma/driver_mips.c | 8 +-
include/linux/bcma/bcma_driver_chipcommon.h | 24 ++
- 6 files changed, 596 insertions(+), 1 deletions(-)
+ 6 files changed, 597 insertions(+), 1 deletions(-)
create mode 100644 drivers/bcma/driver_chipcommon_sflash.c
--- a/drivers/bcma/Kconfig
bcma-$(CONFIG_BCMA_DRIVER_MIPS) += driver_mips.o
--- a/drivers/bcma/bcma_private.h
+++ b/drivers/bcma/bcma_private.h
-@@ -38,6 +38,11 @@ void bcma_chipco_serial_init(struct bcma
+@@ -41,6 +41,11 @@ void bcma_chipco_serial_init(struct bcma
u32 bcma_pmu_alp_clock(struct bcma_drv_cc *cc);
u32 bcma_pmu_get_clockcpu(struct bcma_drv_cc *cc);
extern int __init bcma_host_pci_init(void);
--- /dev/null
+++ b/drivers/bcma/driver_chipcommon_sflash.c
-@@ -0,0 +1,554 @@
+@@ -0,0 +1,555 @@
+/*
+ * Broadcom SiliconBackplane chipcommon serial flash interface
+ *
+{
+ bcma_cc_write32(cc, BCMA_CC_FLASHCTL,
+ BCMA_CC_FLASHCTL_START | opcode);
-+ while (bcma_cc_read32(cc, BCMA_CC_FLASHCTL)
-+ & BCMA_CC_FLASHCTL_BUSY);
++ while (bcma_cc_read32(cc, BCMA_CC_FLASHCTL) & BCMA_CC_FLASHCTL_BUSY)
++ ;
+}
+
+
+{
+ u32 id, id2;
+
-+ memset(&cc->flash.sflash, 0, sizeof(struct bcma_sflash));
++ memset(&cc->sflash, 0, sizeof(struct bcma_sflash));
+
+ switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
+ case BCMA_CC_FLASHT_STSER:
+ bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 0);
+ bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
+ id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
-+ cc->flash.sflash.blocksize = 64 * 1024;
++ cc->sflash.blocksize = 64 * 1024;
+ switch (id) {
+ case 0x11:
+ /* ST M25P20 2 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 4;
++ cc->sflash.numblocks = 4;
+ break;
+ case 0x12:
+ /* ST M25P40 4 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 8;
++ cc->sflash.numblocks = 8;
+ break;
+ case 0x13:
+ /* ST M25P80 8 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 16;
++ cc->sflash.numblocks = 16;
+ break;
+ case 0x14:
+ /* ST M25P16 16 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 32;
++ cc->sflash.numblocks = 32;
+ break;
+ case 0x15:
+ /* ST M25P32 32 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 64;
++ cc->sflash.numblocks = 64;
+ break;
+ case 0x16:
+ /* ST M25P64 64 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 128;
++ cc->sflash.numblocks = 128;
+ break;
+ case 0x17:
+ /* ST M25FL128 128 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 256;
++ cc->sflash.numblocks = 256;
+ break;
+ case 0xbf:
+ /* All of the following flashes are SST with
+ * We'll have to revamp the way we identify them
+ * since RES is not eough to disambiguate them.
+ */
-+ cc->flash.sflash.blocksize = 4 * 1024;
++ cc->sflash.blocksize = 4 * 1024;
+ bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 1);
+ bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
+ id2 = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
+ /* SST25WF512 512 Kbit Serial Flash */
+ case 0x48:
+ /* SST25VF512 512 Kbit Serial Flash */
-+ cc->flash.sflash.numblocks = 16;
++ cc->sflash.numblocks = 16;
+ break;
+ case 2:
+ /* SST25WF010 1 Mbit Serial Flash */
+ case 0x49:
+ /* SST25VF010 1 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 32;
++ cc->sflash.numblocks = 32;
+ break;
+ case 3:
+ /* SST25WF020 2 Mbit Serial Flash */
+ case 0x43:
+ /* SST25VF020 2 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 64;
++ cc->sflash.numblocks = 64;
+ break;
+ case 4:
+ /* SST25WF040 4 Mbit Serial Flash */
+ /* SST25VF040 4 Mbit Serial Flash */
+ case 0x8d:
+ /* SST25VF040B 4 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 128;
++ cc->sflash.numblocks = 128;
+ break;
+ case 5:
+ /* SST25WF080 8 Mbit Serial Flash */
+ case 0x8e:
+ /* SST25VF080B 8 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 256;
++ cc->sflash.numblocks = 256;
+ break;
+ case 0x41:
+ /* SST25VF016 16 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 512;
++ cc->sflash.numblocks = 512;
+ break;
+ case 0x4a:
+ /* SST25VF032 32 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 1024;
++ cc->sflash.numblocks = 1024;
+ break;
+ case 0x4b:
+ /* SST25VF064 64 Mbit Serial Flash */
-+ cc->flash.sflash.numblocks = 2048;
++ cc->sflash.numblocks = 2048;
+ break;
+ }
+ break;
+ switch (id) {
+ case 0xc:
+ /* Atmel AT45DB011 1Mbit Serial Flash */
-+ cc->flash.sflash.blocksize = 256;
-+ cc->flash.sflash.numblocks = 512;
++ cc->sflash.blocksize = 256;
++ cc->sflash.numblocks = 512;
+ break;
+ case 0x14:
+ /* Atmel AT45DB021 2Mbit Serial Flash */
-+ cc->flash.sflash.blocksize = 256;
-+ cc->flash.sflash.numblocks = 1024;
++ cc->sflash.blocksize = 256;
++ cc->sflash.numblocks = 1024;
+ break;
+ case 0x1c:
+ /* Atmel AT45DB041 4Mbit Serial Flash */
-+ cc->flash.sflash.blocksize = 256;
-+ cc->flash.sflash.numblocks = 2048;
++ cc->sflash.blocksize = 256;
++ cc->sflash.numblocks = 2048;
+ break;
+ case 0x24:
+ /* Atmel AT45DB081 8Mbit Serial Flash */
-+ cc->flash.sflash.blocksize = 256;
-+ cc->flash.sflash.numblocks = 4096;
++ cc->sflash.blocksize = 256;
++ cc->sflash.numblocks = 4096;
+ break;
+ case 0x2c:
+ /* Atmel AT45DB161 16Mbit Serial Flash */
-+ cc->flash.sflash.blocksize = 512;
-+ cc->flash.sflash.numblocks = 4096;
++ cc->sflash.blocksize = 512;
++ cc->sflash.numblocks = 4096;
+ break;
+ case 0x34:
+ /* Atmel AT45DB321 32Mbit Serial Flash */
-+ cc->flash.sflash.blocksize = 512;
-+ cc->flash.sflash.numblocks = 8192;
++ cc->sflash.blocksize = 512;
++ cc->sflash.numblocks = 8192;
+ break;
+ case 0x3c:
+ /* Atmel AT45DB642 64Mbit Serial Flash */
-+ cc->flash.sflash.blocksize = 1024;
-+ cc->flash.sflash.numblocks = 8192;
++ cc->sflash.blocksize = 1024;
++ cc->sflash.numblocks = 8192;
+ break;
+ }
+ break;
+ }
+
-+ cc->flash.sflash.size = cc->flash.sflash.blocksize * cc->flash.sflash.numblocks;
++ cc->sflash.size = cc->sflash.blocksize * cc->sflash.numblocks;
+
-+ return cc->flash.sflash.size ? 0 : -ENODEV;
++ return cc->sflash.size ? 0 : -ENODEV;
+}
+
+/* Read len bytes starting at offset into buf. Returns number of bytes read. */
+ if (!len)
+ return 0;
+
-+ if ((offset + len) > cc->flash.sflash.size)
++ if ((offset + len) > cc->sflash.size)
+ return -EINVAL;
+
+ if ((len >= 4) && (offset & 3))
+/* Poll for command completion. Returns zero when complete. */
+int bcma_sflash_poll(struct bcma_drv_cc *cc, u32 offset)
+{
-+ if (offset >= cc->flash.sflash.size)
++ if (offset >= cc->sflash.size)
+ return -22;
+
+ switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
+static int sflash_at_write(struct bcma_drv_cc *cc, u32 offset, u32 len,
+ const u8 *buf)
+{
-+ struct bcma_sflash *sfl = &cc->flash.sflash;
++ struct bcma_sflash *sfl = &cc->sflash;
+ u32 page, byte, mask;
+ int ret = 0;
+ mask = sfl->blocksize - 1;
+ if (!len)
+ return 0;
+
-+ if ((offset + len) > cc->flash.sflash.size)
++ if ((offset + len) > cc->sflash.size)
+ return -EINVAL;
+
-+ sfl = &cc->flash.sflash;
++ sfl = &cc->sflash;
+ switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
+ case BCMA_CC_FLASHT_STSER:
+ do {
+{
+ struct bcma_sflash *sfl;
+
-+ if (offset >= cc->flash.sflash.size)
++ if (offset >= cc->sflash.size)
+ return -EINVAL;
+
-+ sfl = &cc->flash.sflash;
++ sfl = &cc->sflash;
+ switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
+ case BCMA_CC_FLASHT_STSER:
+ bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_WREN);
+ if (len <= 0)
+ return 0;
+
-+ sfl = &cc->flash.sflash;
++ sfl = &cc->sflash;
+ if ((offset + len) > sfl->size)
+ return -EINVAL;
+
+ goto done;
+ }
+
-+ while (bcma_sflash_poll(cc, cur_offset));
++ while (bcma_sflash_poll(cc, cur_offset))
++ ;
+
+ cur_offset += bytes;
+ cur_length -= bytes;
pr_info("found parallel flash.\n");
--- a/include/linux/bcma/bcma_driver_chipcommon.h
+++ b/include/linux/bcma/bcma_driver_chipcommon.h
-@@ -358,6 +358,7 @@ struct bcma_chipcommon_pmu {
+@@ -375,6 +375,7 @@ struct bcma_chipcommon_pmu {
#ifdef CONFIG_BCMA_DRIVER_MIPS
enum bcma_flash_type {
BCMA_PFLASH,
};
struct bcma_pflash {
-@@ -366,8 +367,19 @@ struct bcma_pflash {
+@@ -383,6 +384,14 @@ struct bcma_pflash {
u32 window_size;
};
+};
+#endif /* CONFIG_BCMA_SFLASH */
+
- union bcma_flash {
- struct bcma_pflash pflash;
+ struct bcma_serial_port {
+ void *regs;
+ unsigned long clockspeed;
+@@ -405,6 +414,9 @@ struct bcma_drv_cc {
+ enum bcma_flash_type flash_type;
+ union {
+ struct bcma_pflash pflash;
+#ifdef CONFIG_BCMA_SFLASH
-+ struct bcma_sflash sflash;
++ struct bcma_sflash sflash;
+#endif /* CONFIG_BCMA_SFLASH */
- };
+ };
- struct bcma_serial_port {
-@@ -433,4 +445,16 @@ u32 bcma_chipco_gpio_polarity(struct bcm
- /* PMU support */
- extern void bcma_pmu_init(struct bcma_drv_cc *cc);
+ int nr_serial_ports;
+@@ -459,4 +471,16 @@ extern void bcma_chipco_chipctl_maskset(
+ extern void bcma_chipco_regctl_maskset(struct bcma_drv_cc *cc,
+ u32 offset, u32 mask, u32 set);
+#ifdef CONFIG_BCMA_SFLASH
+/* Chipcommon sflash support. */