0001
0002
0003
0004
0005
0006
0007
0008 #include "bcma_private.h"
0009
0010 #include <linux/platform_device.h>
0011 #include <linux/bcma/bcma.h>
0012
0013 static struct resource bcma_sflash_resource = {
0014 .name = "bcma_sflash",
0015 .start = BCMA_SOC_FLASH2,
0016 .end = 0,
0017 .flags = IORESOURCE_MEM | IORESOURCE_READONLY,
0018 };
0019
0020 struct platform_device bcma_sflash_dev = {
0021 .name = "bcma_sflash",
0022 .resource = &bcma_sflash_resource,
0023 .num_resources = 1,
0024 };
0025
0026 struct bcma_sflash_tbl_e {
0027 char *name;
0028 u32 id;
0029 u32 blocksize;
0030 u16 numblocks;
0031 };
0032
0033 static const struct bcma_sflash_tbl_e bcma_sflash_st_tbl[] = {
0034 { "M25P20", 0x11, 0x10000, 4, },
0035 { "M25P40", 0x12, 0x10000, 8, },
0036
0037 { "M25P16", 0x14, 0x10000, 32, },
0038 { "M25P32", 0x15, 0x10000, 64, },
0039 { "M25P64", 0x16, 0x10000, 128, },
0040 { "M25FL128", 0x17, 0x10000, 256, },
0041 { "MX25L25635F", 0x18, 0x10000, 512, },
0042 { NULL },
0043 };
0044
0045 static const struct bcma_sflash_tbl_e bcma_sflash_sst_tbl[] = {
0046 { "SST25WF512", 1, 0x1000, 16, },
0047 { "SST25VF512", 0x48, 0x1000, 16, },
0048 { "SST25WF010", 2, 0x1000, 32, },
0049 { "SST25VF010", 0x49, 0x1000, 32, },
0050 { "SST25WF020", 3, 0x1000, 64, },
0051 { "SST25VF020", 0x43, 0x1000, 64, },
0052 { "SST25WF040", 4, 0x1000, 128, },
0053 { "SST25VF040", 0x44, 0x1000, 128, },
0054 { "SST25VF040B", 0x8d, 0x1000, 128, },
0055 { "SST25WF080", 5, 0x1000, 256, },
0056 { "SST25VF080B", 0x8e, 0x1000, 256, },
0057 { "SST25VF016", 0x41, 0x1000, 512, },
0058 { "SST25VF032", 0x4a, 0x1000, 1024, },
0059 { "SST25VF064", 0x4b, 0x1000, 2048, },
0060 { NULL },
0061 };
0062
0063 static const struct bcma_sflash_tbl_e bcma_sflash_at_tbl[] = {
0064 { "AT45DB011", 0xc, 256, 512, },
0065 { "AT45DB021", 0x14, 256, 1024, },
0066 { "AT45DB041", 0x1c, 256, 2048, },
0067 { "AT45DB081", 0x24, 256, 4096, },
0068 { "AT45DB161", 0x2c, 512, 4096, },
0069 { "AT45DB321", 0x34, 512, 8192, },
0070 { "AT45DB642", 0x3c, 1024, 8192, },
0071 { NULL },
0072 };
0073
0074 static void bcma_sflash_cmd(struct bcma_drv_cc *cc, u32 opcode)
0075 {
0076 int i;
0077 bcma_cc_write32(cc, BCMA_CC_FLASHCTL,
0078 BCMA_CC_FLASHCTL_START | opcode);
0079 for (i = 0; i < 1000; i++) {
0080 if (!(bcma_cc_read32(cc, BCMA_CC_FLASHCTL) &
0081 BCMA_CC_FLASHCTL_BUSY))
0082 return;
0083 cpu_relax();
0084 }
0085 bcma_err(cc->core->bus, "SFLASH control command failed (timeout)!\n");
0086 }
0087
0088
0089 int bcma_sflash_init(struct bcma_drv_cc *cc)
0090 {
0091 struct bcma_bus *bus = cc->core->bus;
0092 struct bcma_sflash *sflash = &cc->sflash;
0093 const struct bcma_sflash_tbl_e *e;
0094 u32 id, id2;
0095
0096 switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
0097 case BCMA_CC_FLASHT_STSER:
0098 bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_DP);
0099
0100 bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 0);
0101 bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
0102 id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
0103
0104 bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 1);
0105 bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
0106 id2 = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
0107
0108 switch (id) {
0109 case 0xbf:
0110 for (e = bcma_sflash_sst_tbl; e->name; e++) {
0111 if (e->id == id2)
0112 break;
0113 }
0114 break;
0115 case 0x13:
0116 return -ENOTSUPP;
0117 default:
0118 for (e = bcma_sflash_st_tbl; e->name; e++) {
0119 if (e->id == id)
0120 break;
0121 }
0122 break;
0123 }
0124 if (!e->name) {
0125 bcma_err(bus, "Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n", id, id2);
0126 return -ENOTSUPP;
0127 }
0128
0129 break;
0130 case BCMA_CC_FLASHT_ATSER:
0131 bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_AT_STATUS);
0132 id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA) & 0x3c;
0133
0134 for (e = bcma_sflash_at_tbl; e->name; e++) {
0135 if (e->id == id)
0136 break;
0137 }
0138 if (!e->name) {
0139 bcma_err(bus, "Unsupported Atmel serial flash (id: 0x%X)\n", id);
0140 return -ENOTSUPP;
0141 }
0142
0143 break;
0144 default:
0145 bcma_err(bus, "Unsupported flash type\n");
0146 return -ENOTSUPP;
0147 }
0148
0149 sflash->blocksize = e->blocksize;
0150 sflash->numblocks = e->numblocks;
0151 sflash->size = sflash->blocksize * sflash->numblocks;
0152 sflash->present = true;
0153
0154 bcma_info(bus, "Found %s serial flash (size: %dKiB, blocksize: 0x%X, blocks: %d)\n",
0155 e->name, sflash->size / 1024, sflash->blocksize,
0156 sflash->numblocks);
0157
0158
0159
0160 bcma_sflash_dev.resource[0].end = bcma_sflash_dev.resource[0].start +
0161 sflash->size;
0162 bcma_sflash_dev.dev.platform_data = sflash;
0163
0164 return 0;
0165 }