^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Broadcom specific AMBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ChipCommon serial flash interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Licensed under the GNU/GPL. See COPYING for details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "bcma_private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/bcma/bcma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static struct resource bcma_sflash_resource = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) .name = "bcma_sflash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) .start = BCMA_SOC_FLASH2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) .end = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .flags = IORESOURCE_MEM | IORESOURCE_READONLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct platform_device bcma_sflash_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) .name = "bcma_sflash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .resource = &bcma_sflash_resource,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) .num_resources = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct bcma_sflash_tbl_e {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) u32 blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u16 numblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static const struct bcma_sflash_tbl_e bcma_sflash_st_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) { "M25P20", 0x11, 0x10000, 4, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) { "M25P40", 0x12, 0x10000, 8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) { "M25P16", 0x14, 0x10000, 32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) { "M25P32", 0x15, 0x10000, 64, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) { "M25P64", 0x16, 0x10000, 128, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) { "M25FL128", 0x17, 0x10000, 256, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) { "MX25L25635F", 0x18, 0x10000, 512, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) { NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const struct bcma_sflash_tbl_e bcma_sflash_sst_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) { "SST25WF512", 1, 0x1000, 16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) { "SST25VF512", 0x48, 0x1000, 16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) { "SST25WF010", 2, 0x1000, 32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) { "SST25VF010", 0x49, 0x1000, 32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) { "SST25WF020", 3, 0x1000, 64, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) { "SST25VF020", 0x43, 0x1000, 64, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) { "SST25WF040", 4, 0x1000, 128, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) { "SST25VF040", 0x44, 0x1000, 128, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) { "SST25VF040B", 0x8d, 0x1000, 128, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) { "SST25WF080", 5, 0x1000, 256, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) { "SST25VF080B", 0x8e, 0x1000, 256, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) { "SST25VF016", 0x41, 0x1000, 512, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) { "SST25VF032", 0x4a, 0x1000, 1024, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) { "SST25VF064", 0x4b, 0x1000, 2048, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) { NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static const struct bcma_sflash_tbl_e bcma_sflash_at_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) { "AT45DB011", 0xc, 256, 512, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) { "AT45DB021", 0x14, 256, 1024, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) { "AT45DB041", 0x1c, 256, 2048, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) { "AT45DB081", 0x24, 256, 4096, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) { "AT45DB161", 0x2c, 512, 4096, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) { "AT45DB321", 0x34, 512, 8192, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) { "AT45DB642", 0x3c, 1024, 8192, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) { NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static void bcma_sflash_cmd(struct bcma_drv_cc *cc, u32 opcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) bcma_cc_write32(cc, BCMA_CC_FLASHCTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) BCMA_CC_FLASHCTL_START | opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) for (i = 0; i < 1000; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (!(bcma_cc_read32(cc, BCMA_CC_FLASHCTL) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) BCMA_CC_FLASHCTL_BUSY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) bcma_err(cc->core->bus, "SFLASH control command failed (timeout)!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* Initialize serial flash access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int bcma_sflash_init(struct bcma_drv_cc *cc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct bcma_bus *bus = cc->core->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct bcma_sflash *sflash = &cc->sflash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) const struct bcma_sflash_tbl_e *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u32 id, id2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) case BCMA_CC_FLASHT_STSER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_DP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) id2 = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) switch (id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) case 0xbf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) for (e = bcma_sflash_sst_tbl; e->name; e++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (e->id == id2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case 0x13:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) for (e = bcma_sflash_st_tbl; e->name; e++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (e->id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!e->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) bcma_err(bus, "Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n", id, id2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) case BCMA_CC_FLASHT_ATSER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_AT_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA) & 0x3c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) for (e = bcma_sflash_at_tbl; e->name; e++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (e->id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!e->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) bcma_err(bus, "Unsupported Atmel serial flash (id: 0x%X)\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) bcma_err(bus, "Unsupported flash type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) sflash->blocksize = e->blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) sflash->numblocks = e->numblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) sflash->size = sflash->blocksize * sflash->numblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) sflash->present = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) bcma_info(bus, "Found %s serial flash (size: %dKiB, blocksize: 0x%X, blocks: %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) e->name, sflash->size / 1024, sflash->blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) sflash->numblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* Prepare platform device, but don't register it yet. It's too early,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * malloc (required by device_private_init) is not available yet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) bcma_sflash_dev.resource[0].end = bcma_sflash_dev.resource[0].start +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) sflash->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) bcma_sflash_dev.dev.platform_data = sflash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }