Blame view

drivers/bcma/driver_chipcommon_sflash.c 4.19 KB
23cb3b212   Rafał Miłecki   bcma: add place f...
1
2
3
4
5
6
  /*
   * Broadcom specific AMBA
   * ChipCommon serial flash interface
   *
   * Licensed under the GNU/GPL. See COPYING for details.
   */
58b27101e   Rafał Miłecki   bcma: Xflash: reo...
7
  #include "bcma_private.h"
d57ef3a6a   Rafał Miłecki   bcma: detect and ...
8
  #include <linux/platform_device.h>
23cb3b212   Rafał Miłecki   bcma: add place f...
9
  #include <linux/bcma/bcma.h>
23cb3b212   Rafał Miłecki   bcma: add place f...
10

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