aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pcmcia/at91_cf.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pcmcia/at91_cf.c')
-rw-r--r--drivers/pcmcia/at91_cf.c69
1 files changed, 23 insertions, 46 deletions
diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c
index 3bcb7dc32995..b6746301d9a9 100644
--- a/drivers/pcmcia/at91_cf.c
+++ b/drivers/pcmcia/at91_cf.c
@@ -32,10 +32,11 @@
32 * A0..A10 work in each range; A23 indicates I/O space; A25 is CFRNW; 32 * A0..A10 work in each range; A23 indicates I/O space; A25 is CFRNW;
33 * some other bit in {A24,A22..A11} is nREG to flag memory access 33 * some other bit in {A24,A22..A11} is nREG to flag memory access
34 * (vs attributes). So more than 2KB/region would just be waste. 34 * (vs attributes). So more than 2KB/region would just be waste.
35 * Note: These are offsets from the physical base address.
35 */ 36 */
36#define CF_ATTR_PHYS (AT91_CF_BASE) 37#define CF_ATTR_PHYS (0)
37#define CF_IO_PHYS (AT91_CF_BASE + (1 << 23)) 38#define CF_IO_PHYS (1 << 23)
38#define CF_MEM_PHYS (AT91_CF_BASE + 0x017ff800) 39#define CF_MEM_PHYS (0x017ff800)
39 40
40/*--------------------------------------------------------------------------*/ 41/*--------------------------------------------------------------------------*/
41 42
@@ -48,6 +49,8 @@ struct at91_cf_socket {
48 49
49 struct platform_device *pdev; 50 struct platform_device *pdev;
50 struct at91_cf_data *board; 51 struct at91_cf_data *board;
52
53 unsigned long phys_baseaddr;
51}; 54};
52 55
53#define SZ_2K (2 * SZ_1K) 56#define SZ_2K (2 * SZ_1K)
@@ -154,9 +157,8 @@ static int at91_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
154 157
155 /* 158 /*
156 * Use 16 bit accesses unless/until we need 8-bit i/o space. 159 * Use 16 bit accesses unless/until we need 8-bit i/o space.
157 * Always set CSR4 ... PCMCIA won't always unmap things.
158 */ 160 */
159 csr = at91_sys_read(AT91_SMC_CSR(4)) & ~AT91_SMC_DBW; 161 csr = at91_sys_read(AT91_SMC_CSR(cf->board->chipselect)) & ~AT91_SMC_DBW;
160 162
161 /* 163 /*
162 * NOTE: this CF controller ignores IOIS16, so we can't really do 164 * NOTE: this CF controller ignores IOIS16, so we can't really do
@@ -168,14 +170,14 @@ static int at91_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
168 * some cards only like that way to get at the odd byte, despite 170 * some cards only like that way to get at the odd byte, despite
169 * CF 3.0 spec table 35 also giving the D8-D15 option. 171 * CF 3.0 spec table 35 also giving the D8-D15 option.
170 */ 172 */
171 if (!(io->flags & (MAP_16BIT|MAP_AUTOSZ))) { 173 if (!(io->flags & (MAP_16BIT | MAP_AUTOSZ))) {
172 csr |= AT91_SMC_DBW_8; 174 csr |= AT91_SMC_DBW_8;
173 pr_debug("%s: 8bit i/o bus\n", driver_name); 175 pr_debug("%s: 8bit i/o bus\n", driver_name);
174 } else { 176 } else {
175 csr |= AT91_SMC_DBW_16; 177 csr |= AT91_SMC_DBW_16;
176 pr_debug("%s: 16bit i/o bus\n", driver_name); 178 pr_debug("%s: 16bit i/o bus\n", driver_name);
177 } 179 }
178 at91_sys_write(AT91_SMC_CSR(4), csr); 180 at91_sys_write(AT91_SMC_CSR(cf->board->chipselect), csr);
179 181
180 io->start = cf->socket.io_offset; 182 io->start = cf->socket.io_offset;
181 io->stop = io->start + SZ_2K - 1; 183 io->stop = io->start + SZ_2K - 1;
@@ -194,11 +196,11 @@ at91_cf_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *map)
194 196
195 cf = container_of(s, struct at91_cf_socket, socket); 197 cf = container_of(s, struct at91_cf_socket, socket);
196 198
197 map->flags &= MAP_ACTIVE|MAP_ATTRIB|MAP_16BIT; 199 map->flags &= (MAP_ACTIVE | MAP_ATTRIB | MAP_16BIT);
198 if (map->flags & MAP_ATTRIB) 200 if (map->flags & MAP_ATTRIB)
199 map->static_start = CF_ATTR_PHYS; 201 map->static_start = cf->phys_baseaddr + CF_ATTR_PHYS;
200 else 202 else
201 map->static_start = CF_MEM_PHYS; 203 map->static_start = cf->phys_baseaddr + CF_MEM_PHYS;
202 204
203 return 0; 205 return 0;
204} 206}
@@ -219,7 +221,6 @@ static int __init at91_cf_probe(struct platform_device *pdev)
219 struct at91_cf_socket *cf; 221 struct at91_cf_socket *cf;
220 struct at91_cf_data *board = pdev->dev.platform_data; 222 struct at91_cf_data *board = pdev->dev.platform_data;
221 struct resource *io; 223 struct resource *io;
222 unsigned int csa;
223 int status; 224 int status;
224 225
225 if (!board || !board->det_pin || !board->rst_pin) 226 if (!board || !board->det_pin || !board->rst_pin)
@@ -235,33 +236,11 @@ static int __init at91_cf_probe(struct platform_device *pdev)
235 236
236 cf->board = board; 237 cf->board = board;
237 cf->pdev = pdev; 238 cf->pdev = pdev;
239 cf->phys_baseaddr = io->start;
238 platform_set_drvdata(pdev, cf); 240 platform_set_drvdata(pdev, cf);
239 241
240 /* CF takes over CS4, CS5, CS6 */
241 csa = at91_sys_read(AT91_EBI_CSA);
242 at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
243
244 /* nWAIT is _not_ a default setting */
245 (void) at91_set_A_periph(AT91_PIN_PC6, 1); /* nWAIT */
246
247 /*
248 * Static memory controller timing adjustments.
249 * REVISIT: these timings are in terms of MCK cycles, so
250 * when MCK changes (cpufreq etc) so must these values...
251 */
252 at91_sys_write(AT91_SMC_CSR(4),
253 AT91_SMC_ACSS_STD
254 | AT91_SMC_DBW_16
255 | AT91_SMC_BAT
256 | AT91_SMC_WSEN
257 | AT91_SMC_NWS_(32) /* wait states */
258 | AT91_SMC_RWSETUP_(6) /* setup time */
259 | AT91_SMC_RWHOLD_(4) /* hold time */
260 );
261
262 /* must be a GPIO; ergo must trigger on both edges */ 242 /* must be a GPIO; ergo must trigger on both edges */
263 status = request_irq(board->det_pin, at91_cf_irq, 243 status = request_irq(board->det_pin, at91_cf_irq, 0, driver_name, cf);
264 IRQF_SAMPLE_RANDOM, driver_name, cf);
265 if (status < 0) 244 if (status < 0)
266 goto fail0; 245 goto fail0;
267 device_init_wakeup(&pdev->dev, 1); 246 device_init_wakeup(&pdev->dev, 1);
@@ -282,14 +261,18 @@ static int __init at91_cf_probe(struct platform_device *pdev)
282 cf->socket.pci_irq = NR_IRQS + 1; 261 cf->socket.pci_irq = NR_IRQS + 1;
283 262
284 /* pcmcia layer only remaps "real" memory not iospace */ 263 /* pcmcia layer only remaps "real" memory not iospace */
285 cf->socket.io_offset = (unsigned long) ioremap(CF_IO_PHYS, SZ_2K); 264 cf->socket.io_offset = (unsigned long) ioremap(cf->phys_baseaddr + CF_IO_PHYS, SZ_2K);
286 if (!cf->socket.io_offset) 265 if (!cf->socket.io_offset) {
266 status = -ENXIO;
287 goto fail1; 267 goto fail1;
268 }
288 269
289 /* reserve CS4, CS5, and CS6 regions; but use just CS4 */ 270 /* reserve chip-select regions */
290 if (!request_mem_region(io->start, io->end + 1 - io->start, 271 if (!request_mem_region(io->start, io->end + 1 - io->start,
291 driver_name)) 272 driver_name)) {
273 status = -ENXIO;
292 goto fail1; 274 goto fail1;
275 }
293 276
294 pr_info("%s: irqs det #%d, io #%d\n", driver_name, 277 pr_info("%s: irqs det #%d, io #%d\n", driver_name,
295 board->det_pin, board->irq_pin); 278 board->det_pin, board->irq_pin);
@@ -319,9 +302,7 @@ fail1:
319fail0a: 302fail0a:
320 device_init_wakeup(&pdev->dev, 0); 303 device_init_wakeup(&pdev->dev, 0);
321 free_irq(board->det_pin, cf); 304 free_irq(board->det_pin, cf);
322 device_init_wakeup(&pdev->dev, 0);
323fail0: 305fail0:
324 at91_sys_write(AT91_EBI_CSA, csa);
325 kfree(cf); 306 kfree(cf);
326 return status; 307 return status;
327} 308}
@@ -331,19 +312,15 @@ static int __exit at91_cf_remove(struct platform_device *pdev)
331 struct at91_cf_socket *cf = platform_get_drvdata(pdev); 312 struct at91_cf_socket *cf = platform_get_drvdata(pdev);
332 struct at91_cf_data *board = cf->board; 313 struct at91_cf_data *board = cf->board;
333 struct resource *io = cf->socket.io[0].res; 314 struct resource *io = cf->socket.io[0].res;
334 unsigned int csa;
335 315
336 pcmcia_unregister_socket(&cf->socket); 316 pcmcia_unregister_socket(&cf->socket);
337 if (board->irq_pin) 317 if (board->irq_pin)
338 free_irq(board->irq_pin, cf); 318 free_irq(board->irq_pin, cf);
339 free_irq(board->det_pin, cf);
340 device_init_wakeup(&pdev->dev, 0); 319 device_init_wakeup(&pdev->dev, 0);
320 free_irq(board->det_pin, cf);
341 iounmap((void __iomem *) cf->socket.io_offset); 321 iounmap((void __iomem *) cf->socket.io_offset);
342 release_mem_region(io->start, io->end + 1 - io->start); 322 release_mem_region(io->start, io->end + 1 - io->start);
343 323
344 csa = at91_sys_read(AT91_EBI_CSA);
345 at91_sys_write(AT91_EBI_CSA, csa & ~AT91_EBI_CS4A);
346
347 kfree(cf); 324 kfree(cf);
348 return 0; 325 return 0;
349} 326}