blob: 205f1c499c463840b7feac961128bd72e2582aae [file] [log] [blame]
Rafał Miłecki72a525c2013-01-06 21:48:50 +01001/*
2 * Sonics Silicon Backplane
3 * ChipCommon serial flash interface
4 *
5 * Licensed under the GNU/GPL. See COPYING for details.
6 */
7
8#include <linux/ssb/ssb.h>
9
10#include "ssb_private.h"
11
Rafał Miłecki59015272013-01-10 10:11:37 +010012struct ssb_sflash_tbl_e {
13 char *name;
14 u32 id;
15 u32 blocksize;
16 u16 numblocks;
17};
18
Rafał Miłecki39cd2062013-06-17 19:19:19 +020019static const struct ssb_sflash_tbl_e ssb_sflash_st_tbl[] = {
Rafał Miłecki59015272013-01-10 10:11:37 +010020 { "M25P20", 0x11, 0x10000, 4, },
21 { "M25P40", 0x12, 0x10000, 8, },
22
23 { "M25P16", 0x14, 0x10000, 32, },
24 { "M25P32", 0x15, 0x10000, 64, },
25 { "M25P64", 0x16, 0x10000, 128, },
26 { "M25FL128", 0x17, 0x10000, 256, },
27 { 0 },
28};
29
Rafał Miłecki39cd2062013-06-17 19:19:19 +020030static const struct ssb_sflash_tbl_e ssb_sflash_sst_tbl[] = {
Rafał Miłecki59015272013-01-10 10:11:37 +010031 { "SST25WF512", 1, 0x1000, 16, },
32 { "SST25VF512", 0x48, 0x1000, 16, },
33 { "SST25WF010", 2, 0x1000, 32, },
34 { "SST25VF010", 0x49, 0x1000, 32, },
35 { "SST25WF020", 3, 0x1000, 64, },
36 { "SST25VF020", 0x43, 0x1000, 64, },
37 { "SST25WF040", 4, 0x1000, 128, },
38 { "SST25VF040", 0x44, 0x1000, 128, },
39 { "SST25VF040B", 0x8d, 0x1000, 128, },
40 { "SST25WF080", 5, 0x1000, 256, },
41 { "SST25VF080B", 0x8e, 0x1000, 256, },
42 { "SST25VF016", 0x41, 0x1000, 512, },
43 { "SST25VF032", 0x4a, 0x1000, 1024, },
44 { "SST25VF064", 0x4b, 0x1000, 2048, },
45 { 0 },
46};
47
Rafał Miłecki39cd2062013-06-17 19:19:19 +020048static const struct ssb_sflash_tbl_e ssb_sflash_at_tbl[] = {
Rafał Miłecki59015272013-01-10 10:11:37 +010049 { "AT45DB011", 0xc, 256, 512, },
50 { "AT45DB021", 0x14, 256, 1024, },
51 { "AT45DB041", 0x1c, 256, 2048, },
52 { "AT45DB081", 0x24, 256, 4096, },
53 { "AT45DB161", 0x2c, 512, 4096, },
54 { "AT45DB321", 0x34, 512, 8192, },
55 { "AT45DB642", 0x3c, 1024, 8192, },
56 { 0 },
57};
58
59static void ssb_sflash_cmd(struct ssb_chipcommon *cc, u32 opcode)
60{
61 int i;
62 chipco_write32(cc, SSB_CHIPCO_FLASHCTL,
63 SSB_CHIPCO_FLASHCTL_START | opcode);
64 for (i = 0; i < 1000; i++) {
65 if (!(chipco_read32(cc, SSB_CHIPCO_FLASHCTL) &
66 SSB_CHIPCO_FLASHCTL_BUSY))
67 return;
68 cpu_relax();
69 }
70 pr_err("SFLASH control command failed (timeout)!\n");
71}
72
Rafał Miłecki72a525c2013-01-06 21:48:50 +010073/* Initialize serial flash access */
74int ssb_sflash_init(struct ssb_chipcommon *cc)
75{
Rafał Miłeckie570bd02013-06-17 19:56:20 +020076 struct ssb_sflash *sflash = &cc->dev->bus->mipscore.sflash;
Rafał Miłecki39cd2062013-06-17 19:19:19 +020077 const struct ssb_sflash_tbl_e *e;
Rafał Miłecki59015272013-01-10 10:11:37 +010078 u32 id, id2;
79
80 switch (cc->capabilities & SSB_CHIPCO_CAP_FLASHT) {
81 case SSB_CHIPCO_FLASHT_STSER:
82 ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_ST_DP);
83
84 chipco_write32(cc, SSB_CHIPCO_FLASHADDR, 0);
85 ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_ST_RES);
86 id = chipco_read32(cc, SSB_CHIPCO_FLASHDATA);
87
88 chipco_write32(cc, SSB_CHIPCO_FLASHADDR, 1);
89 ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_ST_RES);
90 id2 = chipco_read32(cc, SSB_CHIPCO_FLASHDATA);
91
92 switch (id) {
93 case 0xbf:
94 for (e = ssb_sflash_sst_tbl; e->name; e++) {
95 if (e->id == id2)
96 break;
97 }
98 break;
99 case 0x13:
100 return -ENOTSUPP;
101 default:
102 for (e = ssb_sflash_st_tbl; e->name; e++) {
103 if (e->id == id)
104 break;
105 }
106 break;
107 }
108 if (!e->name) {
109 pr_err("Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n",
110 id, id2);
111 return -ENOTSUPP;
112 }
113
114 break;
115 case SSB_CHIPCO_FLASHT_ATSER:
116 ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_AT_STATUS);
117 id = chipco_read32(cc, SSB_CHIPCO_FLASHDATA) & 0x3c;
118
119 for (e = ssb_sflash_at_tbl; e->name; e++) {
120 if (e->id == id)
121 break;
122 }
123 if (!e->name) {
124 pr_err("Unsupported Atmel serial flash (id: 0x%X)\n",
125 id);
126 return -ENOTSUPP;
127 }
128
129 break;
130 default:
131 pr_err("Unsupported flash type\n");
132 return -ENOTSUPP;
133 }
134
Rafał Miłeckie570bd02013-06-17 19:56:20 +0200135 sflash->window = SSB_FLASH2;
136 sflash->blocksize = e->blocksize;
137 sflash->numblocks = e->numblocks;
138 sflash->size = sflash->blocksize * sflash->numblocks;
139 sflash->present = true;
140
Rafał Miłecki59015272013-01-10 10:11:37 +0100141 pr_info("Found %s serial flash (blocksize: 0x%X, blocks: %d)\n",
142 e->name, e->blocksize, e->numblocks);
143
Rafał Miłecki72a525c2013-01-06 21:48:50 +0100144 pr_err("Serial flash support is not implemented yet!\n");
145
146 return -ENOTSUPP;
147}