2 * Broadcom specific AMBA
3 * ChipCommon serial flash interface
5 * Licensed under the GNU/GPL. See COPYING for details.
8 #include "bcma_private.h"
10 #include <linux/platform_device.h>
11 #include <linux/bcma/bcma.h>
13 static struct resource bcma_sflash_resource
= {
14 .name
= "bcma_sflash",
15 .start
= BCMA_SOC_FLASH2
,
17 .flags
= IORESOURCE_MEM
| IORESOURCE_READONLY
,
20 struct platform_device bcma_sflash_dev
= {
21 .name
= "bcma_sflash",
22 .resource
= &bcma_sflash_resource
,
26 struct bcma_sflash_tbl_e
{
33 static const struct bcma_sflash_tbl_e bcma_sflash_st_tbl
[] = {
34 { "M25P20", 0x11, 0x10000, 4, },
35 { "M25P40", 0x12, 0x10000, 8, },
37 { "M25P16", 0x14, 0x10000, 32, },
38 { "M25P32", 0x15, 0x10000, 64, },
39 { "M25P64", 0x16, 0x10000, 128, },
40 { "M25FL128", 0x17, 0x10000, 256, },
44 static const struct bcma_sflash_tbl_e bcma_sflash_sst_tbl
[] = {
45 { "SST25WF512", 1, 0x1000, 16, },
46 { "SST25VF512", 0x48, 0x1000, 16, },
47 { "SST25WF010", 2, 0x1000, 32, },
48 { "SST25VF010", 0x49, 0x1000, 32, },
49 { "SST25WF020", 3, 0x1000, 64, },
50 { "SST25VF020", 0x43, 0x1000, 64, },
51 { "SST25WF040", 4, 0x1000, 128, },
52 { "SST25VF040", 0x44, 0x1000, 128, },
53 { "SST25VF040B", 0x8d, 0x1000, 128, },
54 { "SST25WF080", 5, 0x1000, 256, },
55 { "SST25VF080B", 0x8e, 0x1000, 256, },
56 { "SST25VF016", 0x41, 0x1000, 512, },
57 { "SST25VF032", 0x4a, 0x1000, 1024, },
58 { "SST25VF064", 0x4b, 0x1000, 2048, },
62 static const struct bcma_sflash_tbl_e bcma_sflash_at_tbl
[] = {
63 { "AT45DB011", 0xc, 256, 512, },
64 { "AT45DB021", 0x14, 256, 1024, },
65 { "AT45DB041", 0x1c, 256, 2048, },
66 { "AT45DB081", 0x24, 256, 4096, },
67 { "AT45DB161", 0x2c, 512, 4096, },
68 { "AT45DB321", 0x34, 512, 8192, },
69 { "AT45DB642", 0x3c, 1024, 8192, },
73 static void bcma_sflash_cmd(struct bcma_drv_cc
*cc
, u32 opcode
)
76 bcma_cc_write32(cc
, BCMA_CC_FLASHCTL
,
77 BCMA_CC_FLASHCTL_START
| opcode
);
78 for (i
= 0; i
< 1000; i
++) {
79 if (!(bcma_cc_read32(cc
, BCMA_CC_FLASHCTL
) &
80 BCMA_CC_FLASHCTL_BUSY
))
84 bcma_err(cc
->core
->bus
, "SFLASH control command failed (timeout)!\n");
87 /* Initialize serial flash access */
88 int bcma_sflash_init(struct bcma_drv_cc
*cc
)
90 struct bcma_bus
*bus
= cc
->core
->bus
;
91 struct bcma_sflash
*sflash
= &cc
->sflash
;
92 const struct bcma_sflash_tbl_e
*e
;
95 switch (cc
->capabilities
& BCMA_CC_CAP_FLASHT
) {
96 case BCMA_CC_FLASHT_STSER
:
97 bcma_sflash_cmd(cc
, BCMA_CC_FLASHCTL_ST_DP
);
99 bcma_cc_write32(cc
, BCMA_CC_FLASHADDR
, 0);
100 bcma_sflash_cmd(cc
, BCMA_CC_FLASHCTL_ST_RES
);
101 id
= bcma_cc_read32(cc
, BCMA_CC_FLASHDATA
);
103 bcma_cc_write32(cc
, BCMA_CC_FLASHADDR
, 1);
104 bcma_sflash_cmd(cc
, BCMA_CC_FLASHCTL_ST_RES
);
105 id2
= bcma_cc_read32(cc
, BCMA_CC_FLASHDATA
);
109 for (e
= bcma_sflash_sst_tbl
; e
->name
; e
++) {
117 for (e
= bcma_sflash_st_tbl
; e
->name
; e
++) {
124 bcma_err(bus
, "Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n", id
, id2
);
129 case BCMA_CC_FLASHT_ATSER
:
130 bcma_sflash_cmd(cc
, BCMA_CC_FLASHCTL_AT_STATUS
);
131 id
= bcma_cc_read32(cc
, BCMA_CC_FLASHDATA
) & 0x3c;
133 for (e
= bcma_sflash_at_tbl
; e
->name
; e
++) {
138 bcma_err(bus
, "Unsupported Atmel serial flash (id: 0x%X)\n", id
);
144 bcma_err(bus
, "Unsupported flash type\n");
148 sflash
->window
= BCMA_SOC_FLASH2
;
149 sflash
->blocksize
= e
->blocksize
;
150 sflash
->numblocks
= e
->numblocks
;
151 sflash
->size
= sflash
->blocksize
* sflash
->numblocks
;
152 sflash
->present
= true;
154 bcma_info(bus
, "Found %s serial flash (size: %dKiB, blocksize: 0x%X, blocks: %d)\n",
155 e
->name
, sflash
->size
/ 1024, sflash
->blocksize
,
158 /* Prepare platform device, but don't register it yet. It's too early,
159 * malloc (required by device_private_init) is not available yet. */
160 bcma_sflash_dev
.resource
[0].end
= bcma_sflash_dev
.resource
[0].start
+
162 bcma_sflash_dev
.dev
.platform_data
= sflash
;