2 * Sonics Silicon Backplane
3 * ChipCommon serial flash interface
5 * Licensed under the GNU/GPL. See COPYING for details.
8 #include <linux/ssb/ssb.h>
10 #include "ssb_private.h"
12 static struct resource ssb_sflash_resource
= {
16 .flags
= IORESOURCE_MEM
| IORESOURCE_READONLY
,
19 struct platform_device ssb_sflash_dev
= {
21 .resource
= &ssb_sflash_resource
,
25 struct ssb_sflash_tbl_e
{
32 static const struct ssb_sflash_tbl_e ssb_sflash_st_tbl
[] = {
33 { "M25P20", 0x11, 0x10000, 4, },
34 { "M25P40", 0x12, 0x10000, 8, },
36 { "M25P16", 0x14, 0x10000, 32, },
37 { "M25P32", 0x15, 0x10000, 64, },
38 { "M25P64", 0x16, 0x10000, 128, },
39 { "M25FL128", 0x17, 0x10000, 256, },
43 static const struct ssb_sflash_tbl_e ssb_sflash_sst_tbl
[] = {
44 { "SST25WF512", 1, 0x1000, 16, },
45 { "SST25VF512", 0x48, 0x1000, 16, },
46 { "SST25WF010", 2, 0x1000, 32, },
47 { "SST25VF010", 0x49, 0x1000, 32, },
48 { "SST25WF020", 3, 0x1000, 64, },
49 { "SST25VF020", 0x43, 0x1000, 64, },
50 { "SST25WF040", 4, 0x1000, 128, },
51 { "SST25VF040", 0x44, 0x1000, 128, },
52 { "SST25VF040B", 0x8d, 0x1000, 128, },
53 { "SST25WF080", 5, 0x1000, 256, },
54 { "SST25VF080B", 0x8e, 0x1000, 256, },
55 { "SST25VF016", 0x41, 0x1000, 512, },
56 { "SST25VF032", 0x4a, 0x1000, 1024, },
57 { "SST25VF064", 0x4b, 0x1000, 2048, },
61 static const struct ssb_sflash_tbl_e ssb_sflash_at_tbl
[] = {
62 { "AT45DB011", 0xc, 256, 512, },
63 { "AT45DB021", 0x14, 256, 1024, },
64 { "AT45DB041", 0x1c, 256, 2048, },
65 { "AT45DB081", 0x24, 256, 4096, },
66 { "AT45DB161", 0x2c, 512, 4096, },
67 { "AT45DB321", 0x34, 512, 8192, },
68 { "AT45DB642", 0x3c, 1024, 8192, },
72 static void ssb_sflash_cmd(struct ssb_chipcommon
*cc
, u32 opcode
)
75 chipco_write32(cc
, SSB_CHIPCO_FLASHCTL
,
76 SSB_CHIPCO_FLASHCTL_START
| opcode
);
77 for (i
= 0; i
< 1000; i
++) {
78 if (!(chipco_read32(cc
, SSB_CHIPCO_FLASHCTL
) &
79 SSB_CHIPCO_FLASHCTL_BUSY
))
83 pr_err("SFLASH control command failed (timeout)!\n");
86 /* Initialize serial flash access */
87 int ssb_sflash_init(struct ssb_chipcommon
*cc
)
89 struct ssb_sflash
*sflash
= &cc
->dev
->bus
->mipscore
.sflash
;
90 const struct ssb_sflash_tbl_e
*e
;
93 switch (cc
->capabilities
& SSB_CHIPCO_CAP_FLASHT
) {
94 case SSB_CHIPCO_FLASHT_STSER
:
95 ssb_sflash_cmd(cc
, SSB_CHIPCO_FLASHCTL_ST_DP
);
97 chipco_write32(cc
, SSB_CHIPCO_FLASHADDR
, 0);
98 ssb_sflash_cmd(cc
, SSB_CHIPCO_FLASHCTL_ST_RES
);
99 id
= chipco_read32(cc
, SSB_CHIPCO_FLASHDATA
);
101 chipco_write32(cc
, SSB_CHIPCO_FLASHADDR
, 1);
102 ssb_sflash_cmd(cc
, SSB_CHIPCO_FLASHCTL_ST_RES
);
103 id2
= chipco_read32(cc
, SSB_CHIPCO_FLASHDATA
);
107 for (e
= ssb_sflash_sst_tbl
; e
->name
; e
++) {
115 for (e
= ssb_sflash_st_tbl
; e
->name
; e
++) {
122 pr_err("Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n",
128 case SSB_CHIPCO_FLASHT_ATSER
:
129 ssb_sflash_cmd(cc
, SSB_CHIPCO_FLASHCTL_AT_STATUS
);
130 id
= chipco_read32(cc
, SSB_CHIPCO_FLASHDATA
) & 0x3c;
132 for (e
= ssb_sflash_at_tbl
; e
->name
; e
++) {
137 pr_err("Unsupported Atmel serial flash (id: 0x%X)\n",
144 pr_err("Unsupported flash type\n");
148 sflash
->window
= SSB_FLASH2
;
149 sflash
->blocksize
= e
->blocksize
;
150 sflash
->numblocks
= e
->numblocks
;
151 sflash
->size
= sflash
->blocksize
* sflash
->numblocks
;
152 sflash
->present
= true;
154 pr_info("Found %s serial flash (size: %dKiB, blocksize: 0x%X, blocks: %d)\n",
155 e
->name
, sflash
->size
/ 1024, e
->blocksize
, e
->numblocks
);
157 /* Prepare platform device, but don't register it yet. It's too early,
158 * malloc (required by device_private_init) is not available yet. */
159 ssb_sflash_dev
.resource
[0].end
= ssb_sflash_dev
.resource
[0].start
+
161 ssb_sflash_dev
.dev
.platform_data
= sflash
;