Blame view
drivers/mmc/host/atmel-mci.c
56.3 KB
7d2be0749 atmel-mci: Driver... |
1 2 3 4 5 6 7 8 9 10 11 |
/* * Atmel MultiMedia Card Interface driver * * Copyright (C) 2004-2008 Atmel Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/blkdev.h> #include <linux/clk.h> |
deec9ae31 atmel-mci: debugf... |
12 |
#include <linux/debugfs.h> |
7d2be0749 atmel-mci: Driver... |
13 |
#include <linux/device.h> |
65e8b083f atmel-mci: Add ex... |
14 15 |
#include <linux/dmaengine.h> #include <linux/dma-mapping.h> |
fbfca4b87 avr32: clean up m... |
16 |
#include <linux/err.h> |
3c26e1703 avr32: some mmc/s... |
17 |
#include <linux/gpio.h> |
7d2be0749 atmel-mci: Driver... |
18 19 20 21 22 23 |
#include <linux/init.h> #include <linux/interrupt.h> #include <linux/ioport.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/scatterlist.h> |
deec9ae31 atmel-mci: debugf... |
24 |
#include <linux/seq_file.h> |
5a0e3ad6a include cleanup: ... |
25 |
#include <linux/slab.h> |
deec9ae31 atmel-mci: debugf... |
26 |
#include <linux/stat.h> |
7d2be0749 atmel-mci: Driver... |
27 28 |
#include <linux/mmc/host.h> |
2f1d79188 mmc: atmel-mci: f... |
29 |
#include <linux/mmc/sdio.h> |
2635d1ba7 atmel-mci: change... |
30 31 |
#include <mach/atmel-mci.h> |
c42aa775c atmel-mci: move a... |
32 |
#include <linux/atmel-mci.h> |
796211b79 mmc: atmel-mci: a... |
33 |
#include <linux/atmel_pdc.h> |
7d2be0749 atmel-mci: Driver... |
34 |
|
7d2be0749 atmel-mci: Driver... |
35 36 |
#include <asm/io.h> #include <asm/unaligned.h> |
04d699c36 atmel-mci: unifie... |
37 |
#include <mach/cpu.h> |
3663b736a avr32: Use <mach/... |
38 |
#include <mach/board.h> |
7d2be0749 atmel-mci: Driver... |
39 40 |
#include "atmel-mci-regs.h" |
2c96a293b mmc: atmel-mci: c... |
41 |
#define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | ATMCI_UNRE) |
65e8b083f atmel-mci: Add ex... |
42 |
#define ATMCI_DMA_THRESHOLD 16 |
7d2be0749 atmel-mci: Driver... |
43 44 45 |
enum { EVENT_CMD_COMPLETE = 0, |
7d2be0749 atmel-mci: Driver... |
46 |
EVENT_XFER_COMPLETE, |
c06ad2580 atmel-mci: Implem... |
47 48 49 50 51 |
EVENT_DATA_COMPLETE, EVENT_DATA_ERROR, }; enum atmel_mci_state { |
965ebf33e atmel-mci: suppor... |
52 53 |
STATE_IDLE = 0, STATE_SENDING_CMD, |
c06ad2580 atmel-mci: Implem... |
54 55 56 57 |
STATE_SENDING_DATA, STATE_DATA_BUSY, STATE_SENDING_STOP, STATE_DATA_ERROR, |
7d2be0749 atmel-mci: Driver... |
58 |
}; |
796211b79 mmc: atmel-mci: a... |
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
enum atmci_xfer_dir { XFER_RECEIVE = 0, XFER_TRANSMIT, }; enum atmci_pdc_buf { PDC_FIRST_BUF = 0, PDC_SECOND_BUF, }; struct atmel_mci_caps { bool has_dma; bool has_pdc; bool has_cfg_reg; bool has_cstor_reg; bool has_highspeed; bool has_rwproof; }; |
65e8b083f atmel-mci: Add ex... |
77 |
struct atmel_mci_dma { |
65e8b083f atmel-mci: Add ex... |
78 79 |
struct dma_chan *chan; struct dma_async_tx_descriptor *data_desc; |
65e8b083f atmel-mci: Add ex... |
80 |
}; |
965ebf33e atmel-mci: suppor... |
81 82 83 84 |
/** * struct atmel_mci - MMC controller state shared between all slots * @lock: Spinlock protecting the queue and associated data. * @regs: Pointer to MMIO registers. |
796211b79 mmc: atmel-mci: a... |
85 |
* @sg: Scatterlist entry currently being processed by PIO or PDC code. |
965ebf33e atmel-mci: suppor... |
86 87 88 89 90 91 92 |
* @pio_offset: Offset into the current scatterlist entry. * @cur_slot: The slot which is currently using the controller. * @mrq: The request currently being processed on @cur_slot, * or NULL if the controller is idle. * @cmd: The command currently being sent to the card, or NULL. * @data: The data currently being transferred, or NULL if no data * transfer is in progress. |
796211b79 mmc: atmel-mci: a... |
93 |
* @data_size: just data->blocks * data->blksz. |
65e8b083f atmel-mci: Add ex... |
94 95 |
* @dma: DMA client state. * @data_chan: DMA channel being used for the current data transfer. |
965ebf33e atmel-mci: suppor... |
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
* @cmd_status: Snapshot of SR taken upon completion of the current * command. Only valid when EVENT_CMD_COMPLETE is pending. * @data_status: Snapshot of SR taken upon completion of the current * data transfer. Only valid when EVENT_DATA_COMPLETE or * EVENT_DATA_ERROR is pending. * @stop_cmdr: Value to be loaded into CMDR when the stop command is * to be sent. * @tasklet: Tasklet running the request state machine. * @pending_events: Bitmask of events flagged by the interrupt handler * to be processed by the tasklet. * @completed_events: Bitmask of events which the state machine has * processed. * @state: Tasklet state. * @queue: List of slots waiting for access to the controller. * @need_clock_update: Update the clock rate before the next request. * @need_reset: Reset controller before next request. * @mode_reg: Value of the MR register. |
74791a2dc mmc: atmel-mci: n... |
113 |
* @cfg_reg: Value of the CFG register. |
965ebf33e atmel-mci: suppor... |
114 115 116 117 118 119 |
* @bus_hz: The rate of @mck in Hz. This forms the basis for MMC bus * rate and timeout calculations. * @mapbase: Physical address of the MMIO registers. * @mck: The peripheral bus clock hooked up to the MMC controller. * @pdev: Platform device associated with the MMC controller. * @slot: Slots sharing this MMC controller. |
796211b79 mmc: atmel-mci: a... |
120 121 122 123 124 125 126 |
* @caps: MCI capabilities depending on MCI version. * @prepare_data: function to setup MCI before data transfer which * depends on MCI capabilities. * @submit_data: function to start data transfer which depends on MCI * capabilities. * @stop_transfer: function to stop data transfer which depends on MCI * capabilities. |
965ebf33e atmel-mci: suppor... |
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
* * Locking * ======= * * @lock is a softirq-safe spinlock protecting @queue as well as * @cur_slot, @mrq and @state. These must always be updated * at the same time while holding @lock. * * @lock also protects mode_reg and need_clock_update since these are * used to synchronize mode register updates with the queue * processing. * * The @mrq field of struct atmel_mci_slot is also protected by @lock, * and must always be written at the same time as the slot is added to * @queue. * * @pending_events and @completed_events are accessed using atomic bit * operations, so they don't need any locking. * * None of the fields touched by the interrupt handler need any * locking. However, ordering is important: Before EVENT_DATA_ERROR or * EVENT_DATA_COMPLETE is set in @pending_events, all data-related * interrupts must be disabled and @data_status updated with a * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the |
25985edce Fix common misspe... |
151 |
* CMDRDY interrupt must be disabled and @cmd_status updated with a |
965ebf33e atmel-mci: suppor... |
152 153 154 155 |
* snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the * bytes_xfered field of @data must be written. This is ensured by * using barriers. */ |
7d2be0749 atmel-mci: Driver... |
156 |
struct atmel_mci { |
965ebf33e atmel-mci: suppor... |
157 |
spinlock_t lock; |
7d2be0749 atmel-mci: Driver... |
158 159 160 161 |
void __iomem *regs; struct scatterlist *sg; unsigned int pio_offset; |
965ebf33e atmel-mci: suppor... |
162 |
struct atmel_mci_slot *cur_slot; |
7d2be0749 atmel-mci: Driver... |
163 164 165 |
struct mmc_request *mrq; struct mmc_command *cmd; struct mmc_data *data; |
796211b79 mmc: atmel-mci: a... |
166 |
unsigned int data_size; |
7d2be0749 atmel-mci: Driver... |
167 |
|
65e8b083f atmel-mci: Add ex... |
168 169 |
struct atmel_mci_dma dma; struct dma_chan *data_chan; |
7d2be0749 atmel-mci: Driver... |
170 171 |
u32 cmd_status; u32 data_status; |
7d2be0749 atmel-mci: Driver... |
172 |
u32 stop_cmdr; |
7d2be0749 atmel-mci: Driver... |
173 174 175 |
struct tasklet_struct tasklet; unsigned long pending_events; unsigned long completed_events; |
c06ad2580 atmel-mci: Implem... |
176 |
enum atmel_mci_state state; |
965ebf33e atmel-mci: suppor... |
177 |
struct list_head queue; |
7d2be0749 atmel-mci: Driver... |
178 |
|
965ebf33e atmel-mci: suppor... |
179 180 181 |
bool need_clock_update; bool need_reset; u32 mode_reg; |
74791a2dc mmc: atmel-mci: n... |
182 |
u32 cfg_reg; |
7d2be0749 atmel-mci: Driver... |
183 184 185 186 |
unsigned long bus_hz; unsigned long mapbase; struct clk *mck; struct platform_device *pdev; |
965ebf33e atmel-mci: suppor... |
187 |
|
2c96a293b mmc: atmel-mci: c... |
188 |
struct atmel_mci_slot *slot[ATMCI_MAX_NR_SLOTS]; |
796211b79 mmc: atmel-mci: a... |
189 190 191 192 193 194 |
struct atmel_mci_caps caps; u32 (*prepare_data)(struct atmel_mci *host, struct mmc_data *data); void (*submit_data)(struct atmel_mci *host, struct mmc_data *data); void (*stop_transfer)(struct atmel_mci *host); |
965ebf33e atmel-mci: suppor... |
195 196 197 198 199 200 201 |
}; /** * struct atmel_mci_slot - MMC slot state * @mmc: The mmc_host representing this slot. * @host: The MMC controller this slot is using. * @sdc_reg: Value of SDCR to be written before using this slot. |
88ff82ed4 mmc: atmel-mci: A... |
202 |
* @sdio_irq: SDIO irq mask for this slot. |
965ebf33e atmel-mci: suppor... |
203 204 205 206 207 208 209 210 211 212 |
* @mrq: mmc_request currently being processed or waiting to be * processed, or NULL when the slot is idle. * @queue_node: List node for placing this node in the @queue list of * &struct atmel_mci. * @clock: Clock rate configured by set_ios(). Protected by host->lock. * @flags: Random state bits associated with the slot. * @detect_pin: GPIO pin used for card detection, or negative if not * available. * @wp_pin: GPIO pin used for card write protect sending, or negative * if not available. |
1c1452be2 atmel-mci: Add su... |
213 |
* @detect_is_active_high: The state of the detect pin when it is active. |
965ebf33e atmel-mci: suppor... |
214 215 216 217 218 219 220 |
* @detect_timer: Timer used for debouncing @detect_pin interrupts. */ struct atmel_mci_slot { struct mmc_host *mmc; struct atmel_mci *host; u32 sdc_reg; |
88ff82ed4 mmc: atmel-mci: A... |
221 |
u32 sdio_irq; |
965ebf33e atmel-mci: suppor... |
222 223 224 225 226 227 228 229 230 |
struct mmc_request *mrq; struct list_head queue_node; unsigned int clock; unsigned long flags; #define ATMCI_CARD_PRESENT 0 #define ATMCI_CARD_NEED_INIT 1 #define ATMCI_SHUTDOWN 2 |
5c2f2b9bd mmc: atmel-mci: a... |
231 |
#define ATMCI_SUSPENDED 3 |
965ebf33e atmel-mci: suppor... |
232 233 234 |
int detect_pin; int wp_pin; |
1c1452be2 atmel-mci: Add su... |
235 |
bool detect_is_active_high; |
965ebf33e atmel-mci: suppor... |
236 237 |
struct timer_list detect_timer; |
7d2be0749 atmel-mci: Driver... |
238 |
}; |
7d2be0749 atmel-mci: Driver... |
239 240 |
#define atmci_test_and_clear_pending(host, event) \ test_and_clear_bit(event, &host->pending_events) |
7d2be0749 atmel-mci: Driver... |
241 242 243 244 |
#define atmci_set_completed(host, event) \ set_bit(event, &host->completed_events) #define atmci_set_pending(host, event) \ set_bit(event, &host->pending_events) |
7d2be0749 atmel-mci: Driver... |
245 |
|
deec9ae31 atmel-mci: debugf... |
246 247 248 249 250 251 |
/* * The debugfs stuff below is mostly optimized away when * CONFIG_DEBUG_FS is not set. */ static int atmci_req_show(struct seq_file *s, void *v) { |
965ebf33e atmel-mci: suppor... |
252 253 |
struct atmel_mci_slot *slot = s->private; struct mmc_request *mrq; |
deec9ae31 atmel-mci: debugf... |
254 255 256 257 258 |
struct mmc_command *cmd; struct mmc_command *stop; struct mmc_data *data; /* Make sure we get a consistent snapshot */ |
965ebf33e atmel-mci: suppor... |
259 260 |
spin_lock_bh(&slot->host->lock); mrq = slot->mrq; |
deec9ae31 atmel-mci: debugf... |
261 262 263 264 265 266 267 268 269 270 271 272 |
if (mrq) { cmd = mrq->cmd; data = mrq->data; stop = mrq->stop; if (cmd) seq_printf(s, "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d ", cmd->opcode, cmd->arg, cmd->flags, cmd->resp[0], cmd->resp[1], cmd->resp[2], |
d586ebbb8 mmc: atmel-mci: f... |
273 |
cmd->resp[3], cmd->error); |
deec9ae31 atmel-mci: debugf... |
274 275 276 277 278 279 280 281 282 283 284 |
if (data) seq_printf(s, "DATA %u / %u * %u flg %x err %d ", data->bytes_xfered, data->blocks, data->blksz, data->flags, data->error); if (stop) seq_printf(s, "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d ", stop->opcode, stop->arg, stop->flags, stop->resp[0], stop->resp[1], stop->resp[2], |
d586ebbb8 mmc: atmel-mci: f... |
285 |
stop->resp[3], stop->error); |
deec9ae31 atmel-mci: debugf... |
286 |
} |
965ebf33e atmel-mci: suppor... |
287 |
spin_unlock_bh(&slot->host->lock); |
deec9ae31 atmel-mci: debugf... |
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
return 0; } static int atmci_req_open(struct inode *inode, struct file *file) { return single_open(file, atmci_req_show, inode->i_private); } static const struct file_operations atmci_req_fops = { .owner = THIS_MODULE, .open = atmci_req_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; static void atmci_show_status_reg(struct seq_file *s, const char *regname, u32 value) { static const char *sr_bit[] = { [0] = "CMDRDY", [1] = "RXRDY", [2] = "TXRDY", [3] = "BLKE", [4] = "DTIP", [5] = "NOTBUSY", |
04d699c36 atmel-mci: unifie... |
315 316 |
[6] = "ENDRX", [7] = "ENDTX", |
deec9ae31 atmel-mci: debugf... |
317 318 |
[8] = "SDIOIRQA", [9] = "SDIOIRQB", |
04d699c36 atmel-mci: unifie... |
319 320 321 |
[12] = "SDIOWAIT", [14] = "RXBUFF", [15] = "TXBUFE", |
deec9ae31 atmel-mci: debugf... |
322 323 324 325 326 327 328 |
[16] = "RINDE", [17] = "RDIRE", [18] = "RCRCE", [19] = "RENDE", [20] = "RTOE", [21] = "DCRCE", [22] = "DTOE", |
04d699c36 atmel-mci: unifie... |
329 330 331 332 333 |
[23] = "CSTOE", [24] = "BLKOVRE", [25] = "DMADONE", [26] = "FIFOEMPTY", [27] = "XFRDONE", |
deec9ae31 atmel-mci: debugf... |
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
[30] = "OVRE", [31] = "UNRE", }; unsigned int i; seq_printf(s, "%s:\t0x%08x", regname, value); for (i = 0; i < ARRAY_SIZE(sr_bit); i++) { if (value & (1 << i)) { if (sr_bit[i]) seq_printf(s, " %s", sr_bit[i]); else seq_puts(s, " UNKNOWN"); } } seq_putc(s, ' '); } static int atmci_regs_show(struct seq_file *s, void *v) { struct atmel_mci *host = s->private; u32 *buf; |
2c96a293b mmc: atmel-mci: c... |
356 |
buf = kmalloc(ATMCI_REGS_SIZE, GFP_KERNEL); |
deec9ae31 atmel-mci: debugf... |
357 358 |
if (!buf) return -ENOMEM; |
965ebf33e atmel-mci: suppor... |
359 360 361 362 363 364 |
/* * Grab a more or less consistent snapshot. Note that we're * not disabling interrupts, so IMR and SR may not be * consistent. */ spin_lock_bh(&host->lock); |
87e60f2b8 atmel-mci: debugf... |
365 |
clk_enable(host->mck); |
2c96a293b mmc: atmel-mci: c... |
366 |
memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE); |
87e60f2b8 atmel-mci: debugf... |
367 |
clk_disable(host->mck); |
965ebf33e atmel-mci: suppor... |
368 |
spin_unlock_bh(&host->lock); |
deec9ae31 atmel-mci: debugf... |
369 370 371 |
seq_printf(s, "MR:\t0x%08x%s%s CLKDIV=%u ", |
2c96a293b mmc: atmel-mci: c... |
372 373 374 375 376 377 378 379 380 381 |
buf[ATMCI_MR / 4], buf[ATMCI_MR / 4] & ATMCI_MR_RDPROOF ? " RDPROOF" : "", buf[ATMCI_MR / 4] & ATMCI_MR_WRPROOF ? " WRPROOF" : "", buf[ATMCI_MR / 4] & 0xff); seq_printf(s, "DTOR:\t0x%08x ", buf[ATMCI_DTOR / 4]); seq_printf(s, "SDCR:\t0x%08x ", buf[ATMCI_SDCR / 4]); seq_printf(s, "ARGR:\t0x%08x ", buf[ATMCI_ARGR / 4]); |
deec9ae31 atmel-mci: debugf... |
382 383 |
seq_printf(s, "BLKR:\t0x%08x BCNT=%u BLKLEN=%u ", |
2c96a293b mmc: atmel-mci: c... |
384 385 386 |
buf[ATMCI_BLKR / 4], buf[ATMCI_BLKR / 4] & 0xffff, (buf[ATMCI_BLKR / 4] >> 16) & 0xffff); |
796211b79 mmc: atmel-mci: a... |
387 |
if (host->caps.has_cstor_reg) |
2c96a293b mmc: atmel-mci: c... |
388 389 |
seq_printf(s, "CSTOR:\t0x%08x ", buf[ATMCI_CSTOR / 4]); |
deec9ae31 atmel-mci: debugf... |
390 391 |
/* Don't read RSPR and RDR; it will consume the data there */ |
2c96a293b mmc: atmel-mci: c... |
392 393 |
atmci_show_status_reg(s, "SR", buf[ATMCI_SR / 4]); atmci_show_status_reg(s, "IMR", buf[ATMCI_IMR / 4]); |
deec9ae31 atmel-mci: debugf... |
394 |
|
796211b79 mmc: atmel-mci: a... |
395 |
if (host->caps.has_dma) { |
74791a2dc mmc: atmel-mci: n... |
396 |
u32 val; |
2c96a293b mmc: atmel-mci: c... |
397 |
val = buf[ATMCI_DMA / 4]; |
74791a2dc mmc: atmel-mci: n... |
398 399 400 401 402 |
seq_printf(s, "DMA:\t0x%08x OFFSET=%u CHKSIZE=%u%s ", val, val & 3, ((val >> 4) & 3) ? 1 << (((val >> 4) & 3) + 1) : 1, |
2c96a293b mmc: atmel-mci: c... |
403 |
val & ATMCI_DMAEN ? " DMAEN" : ""); |
796211b79 mmc: atmel-mci: a... |
404 405 406 |
} if (host->caps.has_cfg_reg) { u32 val; |
74791a2dc mmc: atmel-mci: n... |
407 |
|
2c96a293b mmc: atmel-mci: c... |
408 |
val = buf[ATMCI_CFG / 4]; |
74791a2dc mmc: atmel-mci: n... |
409 410 411 |
seq_printf(s, "CFG:\t0x%08x%s%s%s%s ", val, |
2c96a293b mmc: atmel-mci: c... |
412 413 414 415 |
val & ATMCI_CFG_FIFOMODE_1DATA ? " FIFOMODE_ONE_DATA" : "", val & ATMCI_CFG_FERRCTRL_COR ? " FERRCTRL_CLEAR_ON_READ" : "", val & ATMCI_CFG_HSMODE ? " HSMODE" : "", val & ATMCI_CFG_LSYNC ? " LSYNC" : ""); |
74791a2dc mmc: atmel-mci: n... |
416 |
} |
b17339a12 atmel-mci: Fix me... |
417 |
kfree(buf); |
deec9ae31 atmel-mci: debugf... |
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
return 0; } static int atmci_regs_open(struct inode *inode, struct file *file) { return single_open(file, atmci_regs_show, inode->i_private); } static const struct file_operations atmci_regs_fops = { .owner = THIS_MODULE, .open = atmci_regs_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; |
965ebf33e atmel-mci: suppor... |
433 |
static void atmci_init_debugfs(struct atmel_mci_slot *slot) |
deec9ae31 atmel-mci: debugf... |
434 |
{ |
965ebf33e atmel-mci: suppor... |
435 436 437 438 |
struct mmc_host *mmc = slot->mmc; struct atmel_mci *host = slot->host; struct dentry *root; struct dentry *node; |
deec9ae31 atmel-mci: debugf... |
439 |
|
deec9ae31 atmel-mci: debugf... |
440 441 442 443 444 445 446 447 448 449 |
root = mmc->debugfs_root; if (!root) return; node = debugfs_create_file("regs", S_IRUSR, root, host, &atmci_regs_fops); if (IS_ERR(node)) return; if (!node) goto err; |
965ebf33e atmel-mci: suppor... |
450 |
node = debugfs_create_file("req", S_IRUSR, root, slot, &atmci_req_fops); |
deec9ae31 atmel-mci: debugf... |
451 452 |
if (!node) goto err; |
c06ad2580 atmel-mci: Implem... |
453 454 455 |
node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state); if (!node) goto err; |
deec9ae31 atmel-mci: debugf... |
456 457 458 459 460 461 462 463 464 465 466 467 468 |
node = debugfs_create_x32("pending_events", S_IRUSR, root, (u32 *)&host->pending_events); if (!node) goto err; node = debugfs_create_x32("completed_events", S_IRUSR, root, (u32 *)&host->completed_events); if (!node) goto err; return; err: |
965ebf33e atmel-mci: suppor... |
469 470 |
dev_err(&mmc->class_dev, "failed to initialize debugfs for slot "); |
deec9ae31 atmel-mci: debugf... |
471 |
} |
7d2be0749 atmel-mci: Driver... |
472 |
|
2c96a293b mmc: atmel-mci: c... |
473 |
static inline unsigned int atmci_ns_to_clocks(struct atmel_mci *host, |
7d2be0749 atmel-mci: Driver... |
474 475 476 477 478 479 |
unsigned int ns) { return (ns * (host->bus_hz / 1000000) + 999) / 1000; } static void atmci_set_timeout(struct atmel_mci *host, |
965ebf33e atmel-mci: suppor... |
480 |
struct atmel_mci_slot *slot, struct mmc_data *data) |
7d2be0749 atmel-mci: Driver... |
481 482 483 484 485 486 487 |
{ static unsigned dtomul_to_shift[] = { 0, 4, 7, 8, 10, 12, 16, 20 }; unsigned timeout; unsigned dtocyc; unsigned dtomul; |
2c96a293b mmc: atmel-mci: c... |
488 489 |
timeout = atmci_ns_to_clocks(host, data->timeout_ns) + data->timeout_clks; |
7d2be0749 atmel-mci: Driver... |
490 491 492 493 494 495 496 497 498 499 500 501 |
for (dtomul = 0; dtomul < 8; dtomul++) { unsigned shift = dtomul_to_shift[dtomul]; dtocyc = (timeout + (1 << shift) - 1) >> shift; if (dtocyc < 15) break; } if (dtomul >= 8) { dtomul = 7; dtocyc = 15; } |
965ebf33e atmel-mci: suppor... |
502 503 |
dev_vdbg(&slot->mmc->class_dev, "setting timeout to %u cycles ", |
7d2be0749 atmel-mci: Driver... |
504 |
dtocyc << dtomul_to_shift[dtomul]); |
03fc9a7f0 mmc: atmel-mci: c... |
505 |
atmci_writel(host, ATMCI_DTOR, (ATMCI_DTOMUL(dtomul) | ATMCI_DTOCYC(dtocyc))); |
7d2be0749 atmel-mci: Driver... |
506 507 508 509 510 511 512 513 514 515 516 517 |
} /* * Return mask with command flags to be enabled for this command. */ static u32 atmci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) { struct mmc_data *data; u32 cmdr; cmd->error = -EINPROGRESS; |
2c96a293b mmc: atmel-mci: c... |
518 |
cmdr = ATMCI_CMDR_CMDNB(cmd->opcode); |
7d2be0749 atmel-mci: Driver... |
519 520 521 |
if (cmd->flags & MMC_RSP_PRESENT) { if (cmd->flags & MMC_RSP_136) |
2c96a293b mmc: atmel-mci: c... |
522 |
cmdr |= ATMCI_CMDR_RSPTYP_136BIT; |
7d2be0749 atmel-mci: Driver... |
523 |
else |
2c96a293b mmc: atmel-mci: c... |
524 |
cmdr |= ATMCI_CMDR_RSPTYP_48BIT; |
7d2be0749 atmel-mci: Driver... |
525 526 527 528 529 530 531 |
} /* * This should really be MAXLAT_5 for CMD2 and ACMD41, but * it's too difficult to determine whether this is an ACMD or * not. Better make it 64. */ |
2c96a293b mmc: atmel-mci: c... |
532 |
cmdr |= ATMCI_CMDR_MAXLAT_64CYC; |
7d2be0749 atmel-mci: Driver... |
533 534 |
if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN) |
2c96a293b mmc: atmel-mci: c... |
535 |
cmdr |= ATMCI_CMDR_OPDCMD; |
7d2be0749 atmel-mci: Driver... |
536 537 538 |
data = cmd->data; if (data) { |
2c96a293b mmc: atmel-mci: c... |
539 |
cmdr |= ATMCI_CMDR_START_XFER; |
2f1d79188 mmc: atmel-mci: f... |
540 541 |
if (cmd->opcode == SD_IO_RW_EXTENDED) { |
2c96a293b mmc: atmel-mci: c... |
542 |
cmdr |= ATMCI_CMDR_SDIO_BLOCK; |
2f1d79188 mmc: atmel-mci: f... |
543 544 |
} else { if (data->flags & MMC_DATA_STREAM) |
2c96a293b mmc: atmel-mci: c... |
545 |
cmdr |= ATMCI_CMDR_STREAM; |
2f1d79188 mmc: atmel-mci: f... |
546 |
else if (data->blocks > 1) |
2c96a293b mmc: atmel-mci: c... |
547 |
cmdr |= ATMCI_CMDR_MULTI_BLOCK; |
2f1d79188 mmc: atmel-mci: f... |
548 |
else |
2c96a293b mmc: atmel-mci: c... |
549 |
cmdr |= ATMCI_CMDR_BLOCK; |
2f1d79188 mmc: atmel-mci: f... |
550 |
} |
7d2be0749 atmel-mci: Driver... |
551 552 |
if (data->flags & MMC_DATA_READ) |
2c96a293b mmc: atmel-mci: c... |
553 |
cmdr |= ATMCI_CMDR_TRDIR_READ; |
7d2be0749 atmel-mci: Driver... |
554 555 556 557 |
} return cmdr; } |
11d1488b0 mmc: atmel-mci: c... |
558 |
static void atmci_send_command(struct atmel_mci *host, |
965ebf33e atmel-mci: suppor... |
559 |
struct mmc_command *cmd, u32 cmd_flags) |
7d2be0749 atmel-mci: Driver... |
560 |
{ |
7d2be0749 atmel-mci: Driver... |
561 562 |
WARN_ON(host->cmd); host->cmd = cmd; |
965ebf33e atmel-mci: suppor... |
563 |
dev_vdbg(&host->pdev->dev, |
7d2be0749 atmel-mci: Driver... |
564 565 566 |
"start command: ARGR=0x%08x CMDR=0x%08x ", cmd->arg, cmd_flags); |
03fc9a7f0 mmc: atmel-mci: c... |
567 568 |
atmci_writel(host, ATMCI_ARGR, cmd->arg); atmci_writel(host, ATMCI_CMDR, cmd_flags); |
7d2be0749 atmel-mci: Driver... |
569 |
} |
2c96a293b mmc: atmel-mci: c... |
570 |
static void atmci_send_stop_cmd(struct atmel_mci *host, struct mmc_data *data) |
7d2be0749 atmel-mci: Driver... |
571 |
{ |
11d1488b0 mmc: atmel-mci: c... |
572 |
atmci_send_command(host, data->stop, host->stop_cmdr); |
03fc9a7f0 mmc: atmel-mci: c... |
573 |
atmci_writel(host, ATMCI_IER, ATMCI_CMDRDY); |
7d2be0749 atmel-mci: Driver... |
574 |
} |
796211b79 mmc: atmel-mci: a... |
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
/* * Configure given PDC buffer taking care of alignement issues. * Update host->data_size and host->sg. */ static void atmci_pdc_set_single_buf(struct atmel_mci *host, enum atmci_xfer_dir dir, enum atmci_pdc_buf buf_nb) { u32 pointer_reg, counter_reg; if (dir == XFER_RECEIVE) { pointer_reg = ATMEL_PDC_RPR; counter_reg = ATMEL_PDC_RCR; } else { pointer_reg = ATMEL_PDC_TPR; counter_reg = ATMEL_PDC_TCR; } if (buf_nb == PDC_SECOND_BUF) { |
1ebbe3d31 mmc: atmel-mci: u... |
593 594 |
pointer_reg += ATMEL_PDC_SCND_BUF_OFF; counter_reg += ATMEL_PDC_SCND_BUF_OFF; |
796211b79 mmc: atmel-mci: a... |
595 596 597 |
} atmci_writel(host, pointer_reg, sg_dma_address(host->sg)); |
341fa4c3a mmc: atmel-mci: c... |
598 |
if (host->data_size <= sg_dma_len(host->sg)) { |
796211b79 mmc: atmel-mci: a... |
599 600 601 602 603 604 605 606 607 608 609 |
if (host->data_size & 0x3) { /* If size is different from modulo 4, transfer bytes */ atmci_writel(host, counter_reg, host->data_size); atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCFBYTE); } else { /* Else transfer 32-bits words */ atmci_writel(host, counter_reg, host->data_size / 4); } host->data_size = 0; } else { /* We assume the size of a page is 32-bits aligned */ |
341fa4c3a mmc: atmel-mci: c... |
610 611 |
atmci_writel(host, counter_reg, sg_dma_len(host->sg) / 4); host->data_size -= sg_dma_len(host->sg); |
796211b79 mmc: atmel-mci: a... |
612 613 614 615 616 617 618 619 620 621 622 |
if (host->data_size) host->sg = sg_next(host->sg); } } /* * Configure PDC buffer according to the data size ie configuring one or two * buffers. Don't use this function if you want to configure only the second * buffer. In this case, use atmci_pdc_set_single_buf. */ static void atmci_pdc_set_both_buf(struct atmel_mci *host, int dir) |
65e8b083f atmel-mci: Add ex... |
623 |
{ |
796211b79 mmc: atmel-mci: a... |
624 625 626 627 628 629 630 631 632 633 634 |
atmci_pdc_set_single_buf(host, dir, PDC_FIRST_BUF); if (host->data_size) atmci_pdc_set_single_buf(host, dir, PDC_SECOND_BUF); } /* * Unmap sg lists, called when transfer is finished. */ static void atmci_pdc_cleanup(struct atmel_mci *host) { struct mmc_data *data = host->data; |
65e8b083f atmel-mci: Add ex... |
635 |
|
009a891b2 mmc: atmel-mci: p... |
636 |
if (data) |
796211b79 mmc: atmel-mci: a... |
637 638 639 640 |
dma_unmap_sg(&host->pdev->dev, data->sg, data->sg_len, ((data->flags & MMC_DATA_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE)); |
65e8b083f atmel-mci: Add ex... |
641 |
} |
796211b79 mmc: atmel-mci: a... |
642 643 644 645 646 647 |
/* * Disable PDC transfers. Update pending flags to EVENT_XFER_COMPLETE after * having received ATMCI_TXBUFE or ATMCI_RXBUFF interrupt. Enable ATMCI_NOTBUSY * interrupt needed for both transfer directions. */ static void atmci_pdc_complete(struct atmel_mci *host) |
65e8b083f atmel-mci: Add ex... |
648 |
{ |
796211b79 mmc: atmel-mci: a... |
649 650 |
atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS); atmci_pdc_cleanup(host); |
65e8b083f atmel-mci: Add ex... |
651 |
|
796211b79 mmc: atmel-mci: a... |
652 653 654 655 656 |
/* * If the card was removed, data will be NULL. No point trying * to send the stop command or waiting for NBUSY in this case. */ if (host->data) { |
65e8b083f atmel-mci: Add ex... |
657 |
atmci_set_pending(host, EVENT_XFER_COMPLETE); |
796211b79 mmc: atmel-mci: a... |
658 |
tasklet_schedule(&host->tasklet); |
03fc9a7f0 mmc: atmel-mci: c... |
659 |
atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); |
65e8b083f atmel-mci: Add ex... |
660 661 |
} } |
796211b79 mmc: atmel-mci: a... |
662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
static void atmci_dma_cleanup(struct atmel_mci *host) { struct mmc_data *data = host->data; if (data) dma_unmap_sg(host->dma.chan->device->dev, data->sg, data->sg_len, ((data->flags & MMC_DATA_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE)); } /* * This function is called by the DMA driver from tasklet context. */ |
65e8b083f atmel-mci: Add ex... |
676 677 678 679 680 681 682 |
static void atmci_dma_complete(void *arg) { struct atmel_mci *host = arg; struct mmc_data *data = host->data; dev_vdbg(&host->pdev->dev, "DMA complete "); |
796211b79 mmc: atmel-mci: a... |
683 |
if (host->caps.has_dma) |
74791a2dc mmc: atmel-mci: n... |
684 |
/* Disable DMA hardware handshaking on MCI */ |
03fc9a7f0 mmc: atmel-mci: c... |
685 |
atmci_writel(host, ATMCI_DMA, atmci_readl(host, ATMCI_DMA) & ~ATMCI_DMAEN); |
74791a2dc mmc: atmel-mci: n... |
686 |
|
65e8b083f atmel-mci: Add ex... |
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 |
atmci_dma_cleanup(host); /* * If the card was removed, data will be NULL. No point trying * to send the stop command or waiting for NBUSY in this case. */ if (data) { atmci_set_pending(host, EVENT_XFER_COMPLETE); tasklet_schedule(&host->tasklet); /* * Regardless of what the documentation says, we have * to wait for NOTBUSY even after block read * operations. * * When the DMA transfer is complete, the controller * may still be reading the CRC from the card, i.e. * the data transfer is still in progress and we * haven't seen all the potential error bits yet. * * The interrupt handler will schedule a different * tasklet to finish things up when the data transfer * is completely done. * * We may not complete the mmc request here anyway * because the mmc layer may call back and cause us to * violate the "don't submit new operations from the * completion callback" rule of the dma engine * framework. */ |
03fc9a7f0 mmc: atmel-mci: c... |
717 |
atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); |
65e8b083f atmel-mci: Add ex... |
718 719 |
} } |
796211b79 mmc: atmel-mci: a... |
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
/* * Returns a mask of interrupt flags to be enabled after the whole * request has been prepared. */ static u32 atmci_prepare_data(struct atmel_mci *host, struct mmc_data *data) { u32 iflags; data->error = -EINPROGRESS; host->sg = data->sg; host->data = data; host->data_chan = NULL; iflags = ATMCI_DATA_ERROR_FLAGS; /* * Errata: MMC data write operation with less than 12 * bytes is impossible. * * Errata: MCI Transmit Data Register (TDR) FIFO * corruption when length is not multiple of 4. */ if (data->blocks * data->blksz < 12 || (data->blocks * data->blksz) & 3) host->need_reset = true; host->pio_offset = 0; if (data->flags & MMC_DATA_READ) iflags |= ATMCI_RXRDY; else iflags |= ATMCI_TXRDY; return iflags; } /* * Set interrupt flags and set block length into the MCI mode register even * if this value is also accessible in the MCI block register. It seems to be * necessary before the High Speed MCI version. It also map sg and configure * PDC registers. */ static u32 atmci_prepare_data_pdc(struct atmel_mci *host, struct mmc_data *data) { u32 iflags, tmp; unsigned int sg_len; enum dma_data_direction dir; data->error = -EINPROGRESS; host->data = data; host->sg = data->sg; iflags = ATMCI_DATA_ERROR_FLAGS; /* Enable pdc mode */ atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCMODE); if (data->flags & MMC_DATA_READ) { dir = DMA_FROM_DEVICE; iflags |= ATMCI_ENDRX | ATMCI_RXBUFF; } else { dir = DMA_TO_DEVICE; iflags |= ATMCI_ENDTX | ATMCI_TXBUFE; } /* Set BLKLEN */ tmp = atmci_readl(host, ATMCI_MR); tmp &= 0x0000ffff; tmp |= ATMCI_BLKLEN(data->blksz); atmci_writel(host, ATMCI_MR, tmp); /* Configure PDC */ host->data_size = data->blocks * data->blksz; sg_len = dma_map_sg(&host->pdev->dev, data->sg, data->sg_len, dir); |
796211b79 mmc: atmel-mci: a... |
795 796 797 798 799 800 801 802 |
if (host->data_size) atmci_pdc_set_both_buf(host, ((dir == DMA_FROM_DEVICE) ? XFER_RECEIVE : XFER_TRANSMIT)); return iflags; } static u32 |
74791a2dc mmc: atmel-mci: n... |
803 |
atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data) |
65e8b083f atmel-mci: Add ex... |
804 805 806 807 808 809 |
{ struct dma_chan *chan; struct dma_async_tx_descriptor *desc; struct scatterlist *sg; unsigned int i; enum dma_data_direction direction; |
657a77fa7 dmaengine: Move a... |
810 |
unsigned int sglen; |
796211b79 mmc: atmel-mci: a... |
811 812 813 814 815 816 817 818 819 |
u32 iflags; data->error = -EINPROGRESS; WARN_ON(host->data); host->sg = NULL; host->data = data; iflags = ATMCI_DATA_ERROR_FLAGS; |
65e8b083f atmel-mci: Add ex... |
820 821 822 823 824 825 |
/* * We don't do DMA on "complex" transfers, i.e. with * non-word-aligned buffers or lengths. Also, we don't bother * with all the DMA setup overhead for short transfers. */ |
796211b79 mmc: atmel-mci: a... |
826 827 |
if (data->blocks * data->blksz < ATMCI_DMA_THRESHOLD) return atmci_prepare_data(host, data); |
65e8b083f atmel-mci: Add ex... |
828 |
if (data->blksz & 3) |
796211b79 mmc: atmel-mci: a... |
829 |
return atmci_prepare_data(host, data); |
65e8b083f atmel-mci: Add ex... |
830 831 832 |
for_each_sg(data->sg, sg, data->sg_len, i) { if (sg->offset & 3 || sg->length & 3) |
796211b79 mmc: atmel-mci: a... |
833 |
return atmci_prepare_data(host, data); |
65e8b083f atmel-mci: Add ex... |
834 835 836 837 |
} /* If we don't have a channel, we can't do DMA */ chan = host->dma.chan; |
6f49a57aa dmaengine: up-lev... |
838 |
if (chan) |
65e8b083f atmel-mci: Add ex... |
839 |
host->data_chan = chan; |
65e8b083f atmel-mci: Add ex... |
840 841 842 |
if (!chan) return -ENODEV; |
796211b79 mmc: atmel-mci: a... |
843 |
if (host->caps.has_dma) |
03fc9a7f0 mmc: atmel-mci: c... |
844 |
atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(3) | ATMCI_DMAEN); |
74791a2dc mmc: atmel-mci: n... |
845 |
|
65e8b083f atmel-mci: Add ex... |
846 847 848 849 |
if (data->flags & MMC_DATA_READ) direction = DMA_FROM_DEVICE; else direction = DMA_TO_DEVICE; |
266ac3f29 mmc: atmel-mci: m... |
850 |
sglen = dma_map_sg(chan->device->dev, data->sg, |
796211b79 mmc: atmel-mci: a... |
851 |
data->sg_len, direction); |
88ce4db31 mmc: atmel-mci: c... |
852 |
|
65e8b083f atmel-mci: Add ex... |
853 |
desc = chan->device->device_prep_slave_sg(chan, |
88ce4db31 mmc: atmel-mci: c... |
854 |
data->sg, sglen, direction, |
65e8b083f atmel-mci: Add ex... |
855 856 |
DMA_PREP_INTERRUPT | DMA_CTRL_ACK); if (!desc) |
657a77fa7 dmaengine: Move a... |
857 |
goto unmap_exit; |
65e8b083f atmel-mci: Add ex... |
858 859 860 861 |
host->dma.data_desc = desc; desc->callback = atmci_dma_complete; desc->callback_param = host; |
65e8b083f atmel-mci: Add ex... |
862 |
|
796211b79 mmc: atmel-mci: a... |
863 |
return iflags; |
657a77fa7 dmaengine: Move a... |
864 |
unmap_exit: |
88ce4db31 mmc: atmel-mci: c... |
865 |
dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, direction); |
657a77fa7 dmaengine: Move a... |
866 |
return -ENOMEM; |
65e8b083f atmel-mci: Add ex... |
867 |
} |
796211b79 mmc: atmel-mci: a... |
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 |
static void atmci_submit_data(struct atmel_mci *host, struct mmc_data *data) { return; } /* * Start PDC according to transfer direction. */ static void atmci_submit_data_pdc(struct atmel_mci *host, struct mmc_data *data) { if (data->flags & MMC_DATA_READ) atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN); else atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN); } static void atmci_submit_data_dma(struct atmel_mci *host, struct mmc_data *data) |
74791a2dc mmc: atmel-mci: n... |
888 889 890 891 892 |
{ struct dma_chan *chan = host->data_chan; struct dma_async_tx_descriptor *desc = host->dma.data_desc; if (chan) { |
5328906aa mmc: atmel-mci: u... |
893 894 |
dmaengine_submit(desc); dma_async_issue_pending(chan); |
74791a2dc mmc: atmel-mci: n... |
895 896 |
} } |
796211b79 mmc: atmel-mci: a... |
897 |
static void atmci_stop_transfer(struct atmel_mci *host) |
65e8b083f atmel-mci: Add ex... |
898 |
{ |
65e8b083f atmel-mci: Add ex... |
899 |
atmci_set_pending(host, EVENT_XFER_COMPLETE); |
03fc9a7f0 mmc: atmel-mci: c... |
900 |
atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); |
65e8b083f atmel-mci: Add ex... |
901 |
} |
7d2be0749 atmel-mci: Driver... |
902 |
/* |
796211b79 mmc: atmel-mci: a... |
903 |
* Stop data transfer because error(s) occured. |
7d2be0749 atmel-mci: Driver... |
904 |
*/ |
796211b79 mmc: atmel-mci: a... |
905 |
static void atmci_stop_transfer_pdc(struct atmel_mci *host) |
7d2be0749 atmel-mci: Driver... |
906 |
{ |
796211b79 mmc: atmel-mci: a... |
907 908 909 |
atmci_set_pending(host, EVENT_XFER_COMPLETE); atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); } |
965ebf33e atmel-mci: suppor... |
910 |
|
796211b79 mmc: atmel-mci: a... |
911 912 913 |
static void atmci_stop_transfer_dma(struct atmel_mci *host) { struct dma_chan *chan = host->data_chan; |
965ebf33e atmel-mci: suppor... |
914 |
|
796211b79 mmc: atmel-mci: a... |
915 916 917 918 919 920 921 |
if (chan) { dmaengine_terminate_all(chan); atmci_dma_cleanup(host); } else { /* Data transfer was stopped by the interrupt handler */ atmci_set_pending(host, EVENT_XFER_COMPLETE); atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); |
65e8b083f atmel-mci: Add ex... |
922 |
} |
7d2be0749 atmel-mci: Driver... |
923 |
} |
796211b79 mmc: atmel-mci: a... |
924 925 926 927 |
/* * Start a request: prepare data if needed, prepare the command and activate * interrupts. */ |
965ebf33e atmel-mci: suppor... |
928 929 |
static void atmci_start_request(struct atmel_mci *host, struct atmel_mci_slot *slot) |
7d2be0749 atmel-mci: Driver... |
930 |
{ |
965ebf33e atmel-mci: suppor... |
931 |
struct mmc_request *mrq; |
7d2be0749 atmel-mci: Driver... |
932 |
struct mmc_command *cmd; |
965ebf33e atmel-mci: suppor... |
933 |
struct mmc_data *data; |
7d2be0749 atmel-mci: Driver... |
934 |
u32 iflags; |
965ebf33e atmel-mci: suppor... |
935 |
u32 cmdflags; |
7d2be0749 atmel-mci: Driver... |
936 |
|
965ebf33e atmel-mci: suppor... |
937 938 |
mrq = slot->mrq; host->cur_slot = slot; |
7d2be0749 atmel-mci: Driver... |
939 |
host->mrq = mrq; |
965ebf33e atmel-mci: suppor... |
940 |
|
7d2be0749 atmel-mci: Driver... |
941 942 |
host->pending_events = 0; host->completed_events = 0; |
ca55f46e1 atmel-mci: Don't ... |
943 |
host->data_status = 0; |
7d2be0749 atmel-mci: Driver... |
944 |
|
965ebf33e atmel-mci: suppor... |
945 |
if (host->need_reset) { |
03fc9a7f0 mmc: atmel-mci: c... |
946 947 948 |
atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN); atmci_writel(host, ATMCI_MR, host->mode_reg); |
796211b79 mmc: atmel-mci: a... |
949 |
if (host->caps.has_cfg_reg) |
03fc9a7f0 mmc: atmel-mci: c... |
950 |
atmci_writel(host, ATMCI_CFG, host->cfg_reg); |
965ebf33e atmel-mci: suppor... |
951 952 |
host->need_reset = false; } |
03fc9a7f0 mmc: atmel-mci: c... |
953 |
atmci_writel(host, ATMCI_SDCR, slot->sdc_reg); |
965ebf33e atmel-mci: suppor... |
954 |
|
03fc9a7f0 mmc: atmel-mci: c... |
955 |
iflags = atmci_readl(host, ATMCI_IMR); |
2c96a293b mmc: atmel-mci: c... |
956 |
if (iflags & ~(ATMCI_SDIOIRQA | ATMCI_SDIOIRQB)) |
965ebf33e atmel-mci: suppor... |
957 958 959 960 961 962 |
dev_warn(&slot->mmc->class_dev, "WARNING: IMR=0x%08x ", iflags); if (unlikely(test_and_clear_bit(ATMCI_CARD_NEED_INIT, &slot->flags))) { /* Send init sequence (74 clock cycles) */ |
03fc9a7f0 mmc: atmel-mci: c... |
963 964 |
atmci_writel(host, ATMCI_CMDR, ATMCI_CMDR_SPCMD_INIT); while (!(atmci_readl(host, ATMCI_SR) & ATMCI_CMDRDY)) |
965ebf33e atmel-mci: suppor... |
965 966 |
cpu_relax(); } |
74791a2dc mmc: atmel-mci: n... |
967 |
iflags = 0; |
7d2be0749 atmel-mci: Driver... |
968 969 |
data = mrq->data; if (data) { |
965ebf33e atmel-mci: suppor... |
970 |
atmci_set_timeout(host, slot, data); |
a252e3e35 atmel-mci: Initia... |
971 972 |
/* Must set block count/size before sending command */ |
03fc9a7f0 mmc: atmel-mci: c... |
973 |
atmci_writel(host, ATMCI_BLKR, ATMCI_BCNT(data->blocks) |
2c96a293b mmc: atmel-mci: c... |
974 |
| ATMCI_BLKLEN(data->blksz)); |
965ebf33e atmel-mci: suppor... |
975 976 |
dev_vdbg(&slot->mmc->class_dev, "BLKR=0x%08x ", |
2c96a293b mmc: atmel-mci: c... |
977 |
ATMCI_BCNT(data->blocks) | ATMCI_BLKLEN(data->blksz)); |
74791a2dc mmc: atmel-mci: n... |
978 |
|
796211b79 mmc: atmel-mci: a... |
979 |
iflags |= host->prepare_data(host, data); |
7d2be0749 atmel-mci: Driver... |
980 |
} |
2c96a293b mmc: atmel-mci: c... |
981 |
iflags |= ATMCI_CMDRDY; |
7d2be0749 atmel-mci: Driver... |
982 |
cmd = mrq->cmd; |
965ebf33e atmel-mci: suppor... |
983 |
cmdflags = atmci_prepare_command(slot->mmc, cmd); |
11d1488b0 mmc: atmel-mci: c... |
984 |
atmci_send_command(host, cmd, cmdflags); |
7d2be0749 atmel-mci: Driver... |
985 986 |
if (data) |
796211b79 mmc: atmel-mci: a... |
987 |
host->submit_data(host, data); |
7d2be0749 atmel-mci: Driver... |
988 989 |
if (mrq->stop) { |
965ebf33e atmel-mci: suppor... |
990 |
host->stop_cmdr = atmci_prepare_command(slot->mmc, mrq->stop); |
2c96a293b mmc: atmel-mci: c... |
991 |
host->stop_cmdr |= ATMCI_CMDR_STOP_XFER; |
7d2be0749 atmel-mci: Driver... |
992 |
if (!(data->flags & MMC_DATA_WRITE)) |
2c96a293b mmc: atmel-mci: c... |
993 |
host->stop_cmdr |= ATMCI_CMDR_TRDIR_READ; |
7d2be0749 atmel-mci: Driver... |
994 |
if (data->flags & MMC_DATA_STREAM) |
2c96a293b mmc: atmel-mci: c... |
995 |
host->stop_cmdr |= ATMCI_CMDR_STREAM; |
7d2be0749 atmel-mci: Driver... |
996 |
else |
2c96a293b mmc: atmel-mci: c... |
997 |
host->stop_cmdr |= ATMCI_CMDR_MULTI_BLOCK; |
7d2be0749 atmel-mci: Driver... |
998 999 1000 1001 1002 1003 1004 1005 |
} /* * We could have enabled interrupts earlier, but I suspect * that would open up a nice can of interesting race * conditions (e.g. command and data complete, but stop not * prepared yet.) */ |
03fc9a7f0 mmc: atmel-mci: c... |
1006 |
atmci_writel(host, ATMCI_IER, iflags); |
965ebf33e atmel-mci: suppor... |
1007 |
} |
7d2be0749 atmel-mci: Driver... |
1008 |
|
965ebf33e atmel-mci: suppor... |
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
static void atmci_queue_request(struct atmel_mci *host, struct atmel_mci_slot *slot, struct mmc_request *mrq) { dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d ", host->state); spin_lock_bh(&host->lock); slot->mrq = mrq; if (host->state == STATE_IDLE) { host->state = STATE_SENDING_CMD; atmci_start_request(host, slot); } else { list_add_tail(&slot->queue_node, &host->queue); } spin_unlock_bh(&host->lock); } |
7d2be0749 atmel-mci: Driver... |
1026 |
|
965ebf33e atmel-mci: suppor... |
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 |
static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq) { struct atmel_mci_slot *slot = mmc_priv(mmc); struct atmel_mci *host = slot->host; struct mmc_data *data; WARN_ON(slot->mrq); /* * We may "know" the card is gone even though there's still an * electrical connection. If so, we really need to communicate * this to the MMC core since there won't be any more * interrupts as the card is completely removed. Otherwise, * the MMC core might believe the card is still there even * though the card was just removed very slowly. */ if (!test_bit(ATMCI_CARD_PRESENT, &slot->flags)) { mrq->cmd->error = -ENOMEDIUM; mmc_request_done(mmc, mrq); return; } /* We don't support multiple blocks of weird lengths. */ data = mrq->data; if (data && data->blocks > 1 && data->blksz & 3) { mrq->cmd->error = -EINVAL; mmc_request_done(mmc, mrq); } atmci_queue_request(host, slot, mrq); |
7d2be0749 atmel-mci: Driver... |
1057 1058 1059 1060 |
} static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) { |
965ebf33e atmel-mci: suppor... |
1061 1062 1063 |
struct atmel_mci_slot *slot = mmc_priv(mmc); struct atmel_mci *host = slot->host; unsigned int i; |
7d2be0749 atmel-mci: Driver... |
1064 |
|
2c96a293b mmc: atmel-mci: c... |
1065 |
slot->sdc_reg &= ~ATMCI_SDCBUS_MASK; |
945533b53 atmel-mci: Don't ... |
1066 1067 |
switch (ios->bus_width) { case MMC_BUS_WIDTH_1: |
2c96a293b mmc: atmel-mci: c... |
1068 |
slot->sdc_reg |= ATMCI_SDCBUS_1BIT; |
945533b53 atmel-mci: Don't ... |
1069 1070 |
break; case MMC_BUS_WIDTH_4: |
2c96a293b mmc: atmel-mci: c... |
1071 |
slot->sdc_reg |= ATMCI_SDCBUS_4BIT; |
945533b53 atmel-mci: Don't ... |
1072 1073 |
break; } |
7d2be0749 atmel-mci: Driver... |
1074 |
if (ios->clock) { |
965ebf33e atmel-mci: suppor... |
1075 |
unsigned int clock_min = ~0U; |
7d2be0749 atmel-mci: Driver... |
1076 |
u32 clkdiv; |
965ebf33e atmel-mci: suppor... |
1077 1078 |
spin_lock_bh(&host->lock); if (!host->mode_reg) { |
945533b53 atmel-mci: Don't ... |
1079 |
clk_enable(host->mck); |
03fc9a7f0 mmc: atmel-mci: c... |
1080 1081 |
atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN); |
796211b79 mmc: atmel-mci: a... |
1082 |
if (host->caps.has_cfg_reg) |
03fc9a7f0 mmc: atmel-mci: c... |
1083 |
atmci_writel(host, ATMCI_CFG, host->cfg_reg); |
965ebf33e atmel-mci: suppor... |
1084 |
} |
945533b53 atmel-mci: Don't ... |
1085 |
|
965ebf33e atmel-mci: suppor... |
1086 1087 1088 1089 1090 |
/* * Use mirror of ios->clock to prevent race with mmc * core ios update when finding the minimum. */ slot->clock = ios->clock; |
2c96a293b mmc: atmel-mci: c... |
1091 |
for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) { |
965ebf33e atmel-mci: suppor... |
1092 1093 1094 1095 1096 1097 1098 |
if (host->slot[i] && host->slot[i]->clock && host->slot[i]->clock < clock_min) clock_min = host->slot[i]->clock; } /* Calculate clock divider */ clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * clock_min) - 1; |
7d2be0749 atmel-mci: Driver... |
1099 1100 1101 1102 |
if (clkdiv > 255) { dev_warn(&mmc->class_dev, "clock %u too slow; using %lu ", |
965ebf33e atmel-mci: suppor... |
1103 |
clock_min, host->bus_hz / (2 * 256)); |
7d2be0749 atmel-mci: Driver... |
1104 1105 |
clkdiv = 255; } |
2c96a293b mmc: atmel-mci: c... |
1106 |
host->mode_reg = ATMCI_MR_CLKDIV(clkdiv); |
04d699c36 atmel-mci: unifie... |
1107 |
|
965ebf33e atmel-mci: suppor... |
1108 1109 1110 1111 1112 |
/* * WRPROOF and RDPROOF prevent overruns/underruns by * stopping the clock when the FIFO is full/empty. * This state is not expected to last for long. */ |
796211b79 mmc: atmel-mci: a... |
1113 |
if (host->caps.has_rwproof) |
2c96a293b mmc: atmel-mci: c... |
1114 |
host->mode_reg |= (ATMCI_MR_WRPROOF | ATMCI_MR_RDPROOF); |
7d2be0749 atmel-mci: Driver... |
1115 |
|
796211b79 mmc: atmel-mci: a... |
1116 |
if (host->caps.has_cfg_reg) { |
99ddffd8e mmc: atmel-mci: e... |
1117 1118 |
/* setup High Speed mode in relation with card capacity */ if (ios->timing == MMC_TIMING_SD_HS) |
2c96a293b mmc: atmel-mci: c... |
1119 |
host->cfg_reg |= ATMCI_CFG_HSMODE; |
99ddffd8e mmc: atmel-mci: e... |
1120 |
else |
2c96a293b mmc: atmel-mci: c... |
1121 |
host->cfg_reg &= ~ATMCI_CFG_HSMODE; |
99ddffd8e mmc: atmel-mci: e... |
1122 1123 1124 |
} if (list_empty(&host->queue)) { |
03fc9a7f0 mmc: atmel-mci: c... |
1125 |
atmci_writel(host, ATMCI_MR, host->mode_reg); |
796211b79 mmc: atmel-mci: a... |
1126 |
if (host->caps.has_cfg_reg) |
03fc9a7f0 mmc: atmel-mci: c... |
1127 |
atmci_writel(host, ATMCI_CFG, host->cfg_reg); |
99ddffd8e mmc: atmel-mci: e... |
1128 |
} else { |
965ebf33e atmel-mci: suppor... |
1129 |
host->need_clock_update = true; |
99ddffd8e mmc: atmel-mci: e... |
1130 |
} |
965ebf33e atmel-mci: suppor... |
1131 1132 |
spin_unlock_bh(&host->lock); |
945533b53 atmel-mci: Don't ... |
1133 |
} else { |
965ebf33e atmel-mci: suppor... |
1134 1135 1136 1137 |
bool any_slot_active = false; spin_lock_bh(&host->lock); slot->clock = 0; |
2c96a293b mmc: atmel-mci: c... |
1138 |
for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) { |
965ebf33e atmel-mci: suppor... |
1139 1140 1141 1142 |
if (host->slot[i] && host->slot[i]->clock) { any_slot_active = true; break; } |
945533b53 atmel-mci: Don't ... |
1143 |
} |
965ebf33e atmel-mci: suppor... |
1144 |
if (!any_slot_active) { |
03fc9a7f0 mmc: atmel-mci: c... |
1145 |
atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS); |
965ebf33e atmel-mci: suppor... |
1146 |
if (host->mode_reg) { |
03fc9a7f0 mmc: atmel-mci: c... |
1147 |
atmci_readl(host, ATMCI_MR); |
965ebf33e atmel-mci: suppor... |
1148 1149 1150 1151 1152 |
clk_disable(host->mck); } host->mode_reg = 0; } spin_unlock_bh(&host->lock); |
7d2be0749 atmel-mci: Driver... |
1153 1154 1155 |
} switch (ios->power_mode) { |
965ebf33e atmel-mci: suppor... |
1156 1157 1158 |
case MMC_POWER_UP: set_bit(ATMCI_CARD_NEED_INIT, &slot->flags); break; |
7d2be0749 atmel-mci: Driver... |
1159 1160 1161 1162 1163 |
default: /* * TODO: None of the currently available AVR32-based * boards allow MMC power to be turned off. Implement * power control when this can be tested properly. |
965ebf33e atmel-mci: suppor... |
1164 1165 1166 1167 1168 1169 1170 |
* * We also need to hook this into the clock management * somehow so that newly inserted cards aren't * subjected to a fast clock before we have a chance * to figure out what the maximum rate is. Currently, * there's no way to avoid this, and there never will * be for boards that don't support power control. |
7d2be0749 atmel-mci: Driver... |
1171 1172 1173 1174 1175 1176 1177 |
*/ break; } } static int atmci_get_ro(struct mmc_host *mmc) { |
965ebf33e atmel-mci: suppor... |
1178 1179 |
int read_only = -ENOSYS; struct atmel_mci_slot *slot = mmc_priv(mmc); |
7d2be0749 atmel-mci: Driver... |
1180 |
|
965ebf33e atmel-mci: suppor... |
1181 1182 |
if (gpio_is_valid(slot->wp_pin)) { read_only = gpio_get_value(slot->wp_pin); |
7d2be0749 atmel-mci: Driver... |
1183 1184 1185 |
dev_dbg(&mmc->class_dev, "card is %s ", read_only ? "read-only" : "read-write"); |
7d2be0749 atmel-mci: Driver... |
1186 1187 1188 1189 |
} return read_only; } |
965ebf33e atmel-mci: suppor... |
1190 1191 1192 1193 1194 1195 |
static int atmci_get_cd(struct mmc_host *mmc) { int present = -ENOSYS; struct atmel_mci_slot *slot = mmc_priv(mmc); if (gpio_is_valid(slot->detect_pin)) { |
1c1452be2 atmel-mci: Add su... |
1196 1197 |
present = !(gpio_get_value(slot->detect_pin) ^ slot->detect_is_active_high); |
965ebf33e atmel-mci: suppor... |
1198 1199 1200 1201 1202 1203 1204 |
dev_dbg(&mmc->class_dev, "card is %spresent ", present ? "" : "not "); } return present; } |
88ff82ed4 mmc: atmel-mci: A... |
1205 1206 1207 1208 1209 1210 |
static void atmci_enable_sdio_irq(struct mmc_host *mmc, int enable) { struct atmel_mci_slot *slot = mmc_priv(mmc); struct atmel_mci *host = slot->host; if (enable) |
03fc9a7f0 mmc: atmel-mci: c... |
1211 |
atmci_writel(host, ATMCI_IER, slot->sdio_irq); |
88ff82ed4 mmc: atmel-mci: A... |
1212 |
else |
03fc9a7f0 mmc: atmel-mci: c... |
1213 |
atmci_writel(host, ATMCI_IDR, slot->sdio_irq); |
88ff82ed4 mmc: atmel-mci: A... |
1214 |
} |
965ebf33e atmel-mci: suppor... |
1215 |
static const struct mmc_host_ops atmci_ops = { |
7d2be0749 atmel-mci: Driver... |
1216 1217 1218 |
.request = atmci_request, .set_ios = atmci_set_ios, .get_ro = atmci_get_ro, |
965ebf33e atmel-mci: suppor... |
1219 |
.get_cd = atmci_get_cd, |
88ff82ed4 mmc: atmel-mci: A... |
1220 |
.enable_sdio_irq = atmci_enable_sdio_irq, |
7d2be0749 atmel-mci: Driver... |
1221 |
}; |
965ebf33e atmel-mci: suppor... |
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 |
/* Called with host->lock held */ static void atmci_request_end(struct atmel_mci *host, struct mmc_request *mrq) __releases(&host->lock) __acquires(&host->lock) { struct atmel_mci_slot *slot = NULL; struct mmc_host *prev_mmc = host->cur_slot->mmc; WARN_ON(host->cmd || host->data); /* * Update the MMC clock rate if necessary. This may be * necessary if set_ios() is called when a different slot is |
25985edce Fix common misspe... |
1235 |
* busy transferring data. |
965ebf33e atmel-mci: suppor... |
1236 |
*/ |
99ddffd8e mmc: atmel-mci: e... |
1237 |
if (host->need_clock_update) { |
03fc9a7f0 mmc: atmel-mci: c... |
1238 |
atmci_writel(host, ATMCI_MR, host->mode_reg); |
796211b79 mmc: atmel-mci: a... |
1239 |
if (host->caps.has_cfg_reg) |
03fc9a7f0 mmc: atmel-mci: c... |
1240 |
atmci_writel(host, ATMCI_CFG, host->cfg_reg); |
99ddffd8e mmc: atmel-mci: e... |
1241 |
} |
965ebf33e atmel-mci: suppor... |
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 |
host->cur_slot->mrq = NULL; host->mrq = NULL; if (!list_empty(&host->queue)) { slot = list_entry(host->queue.next, struct atmel_mci_slot, queue_node); list_del(&slot->queue_node); dev_vdbg(&host->pdev->dev, "list not empty: %s is next ", mmc_hostname(slot->mmc)); host->state = STATE_SENDING_CMD; atmci_start_request(host, slot); } else { dev_vdbg(&host->pdev->dev, "list empty "); host->state = STATE_IDLE; } spin_unlock(&host->lock); mmc_request_done(prev_mmc, mrq); spin_lock(&host->lock); } |
7d2be0749 atmel-mci: Driver... |
1264 |
static void atmci_command_complete(struct atmel_mci *host, |
c06ad2580 atmel-mci: Implem... |
1265 |
struct mmc_command *cmd) |
7d2be0749 atmel-mci: Driver... |
1266 |
{ |
c06ad2580 atmel-mci: Implem... |
1267 |
u32 status = host->cmd_status; |
7d2be0749 atmel-mci: Driver... |
1268 |
/* Read the response from the card (up to 16 bytes) */ |
03fc9a7f0 mmc: atmel-mci: c... |
1269 1270 1271 1272 |
cmd->resp[0] = atmci_readl(host, ATMCI_RSPR); cmd->resp[1] = atmci_readl(host, ATMCI_RSPR); cmd->resp[2] = atmci_readl(host, ATMCI_RSPR); cmd->resp[3] = atmci_readl(host, ATMCI_RSPR); |
7d2be0749 atmel-mci: Driver... |
1273 |
|
2c96a293b mmc: atmel-mci: c... |
1274 |
if (status & ATMCI_RTOE) |
7d2be0749 atmel-mci: Driver... |
1275 |
cmd->error = -ETIMEDOUT; |
2c96a293b mmc: atmel-mci: c... |
1276 |
else if ((cmd->flags & MMC_RSP_CRC) && (status & ATMCI_RCRCE)) |
7d2be0749 atmel-mci: Driver... |
1277 |
cmd->error = -EILSEQ; |
2c96a293b mmc: atmel-mci: c... |
1278 |
else if (status & (ATMCI_RINDE | ATMCI_RDIRE | ATMCI_RENDE)) |
7d2be0749 atmel-mci: Driver... |
1279 1280 1281 1282 1283 |
cmd->error = -EIO; else cmd->error = 0; if (cmd->error) { |
965ebf33e atmel-mci: suppor... |
1284 |
dev_dbg(&host->pdev->dev, |
7d2be0749 atmel-mci: Driver... |
1285 1286 1287 1288 |
"command error: status=0x%08x ", status); if (cmd->data) { |
796211b79 mmc: atmel-mci: a... |
1289 |
host->stop_transfer(host); |
009a891b2 mmc: atmel-mci: p... |
1290 |
host->data = NULL; |
03fc9a7f0 mmc: atmel-mci: c... |
1291 |
atmci_writel(host, ATMCI_IDR, ATMCI_NOTBUSY |
2c96a293b mmc: atmel-mci: c... |
1292 |
| ATMCI_TXRDY | ATMCI_RXRDY |
7d2be0749 atmel-mci: Driver... |
1293 1294 1295 1296 1297 1298 1299 |
| ATMCI_DATA_ERROR_FLAGS); } } } static void atmci_detect_change(unsigned long data) { |
965ebf33e atmel-mci: suppor... |
1300 1301 1302 |
struct atmel_mci_slot *slot = (struct atmel_mci_slot *)data; bool present; bool present_old; |
7d2be0749 atmel-mci: Driver... |
1303 1304 |
/* |
965ebf33e atmel-mci: suppor... |
1305 1306 1307 1308 |
* atmci_cleanup_slot() sets the ATMCI_SHUTDOWN flag before * freeing the interrupt. We must not re-enable the interrupt * if it has been freed, and if we're shutting down, it * doesn't really matter whether the card is present or not. |
7d2be0749 atmel-mci: Driver... |
1309 1310 |
*/ smp_rmb(); |
965ebf33e atmel-mci: suppor... |
1311 |
if (test_bit(ATMCI_SHUTDOWN, &slot->flags)) |
7d2be0749 atmel-mci: Driver... |
1312 |
return; |
965ebf33e atmel-mci: suppor... |
1313 |
enable_irq(gpio_to_irq(slot->detect_pin)); |
1c1452be2 atmel-mci: Add su... |
1314 1315 |
present = !(gpio_get_value(slot->detect_pin) ^ slot->detect_is_active_high); |
965ebf33e atmel-mci: suppor... |
1316 |
present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags); |
7d2be0749 atmel-mci: Driver... |
1317 |
|
965ebf33e atmel-mci: suppor... |
1318 1319 1320 |
dev_vdbg(&slot->mmc->class_dev, "detect change: %d (was %d) ", present, present_old); |
7d2be0749 atmel-mci: Driver... |
1321 |
|
965ebf33e atmel-mci: suppor... |
1322 1323 1324 1325 1326 1327 |
if (present != present_old) { struct atmel_mci *host = slot->host; struct mmc_request *mrq; dev_dbg(&slot->mmc->class_dev, "card %s ", |
7d2be0749 atmel-mci: Driver... |
1328 |
present ? "inserted" : "removed"); |
7d2be0749 atmel-mci: Driver... |
1329 |
|
965ebf33e atmel-mci: suppor... |
1330 1331 1332 1333 1334 1335 |
spin_lock(&host->lock); if (!present) clear_bit(ATMCI_CARD_PRESENT, &slot->flags); else set_bit(ATMCI_CARD_PRESENT, &slot->flags); |
7d2be0749 atmel-mci: Driver... |
1336 1337 |
/* Clean up queue if present */ |
965ebf33e atmel-mci: suppor... |
1338 |
mrq = slot->mrq; |
7d2be0749 atmel-mci: Driver... |
1339 |
if (mrq) { |
965ebf33e atmel-mci: suppor... |
1340 1341 1342 1343 1344 |
if (mrq == host->mrq) { /* * Reset controller to terminate any ongoing * commands or data transfers. */ |
03fc9a7f0 mmc: atmel-mci: c... |
1345 1346 1347 |
atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN); atmci_writel(host, ATMCI_MR, host->mode_reg); |
796211b79 mmc: atmel-mci: a... |
1348 |
if (host->caps.has_cfg_reg) |
03fc9a7f0 mmc: atmel-mci: c... |
1349 |
atmci_writel(host, ATMCI_CFG, host->cfg_reg); |
965ebf33e atmel-mci: suppor... |
1350 1351 1352 1353 1354 1355 |
host->data = NULL; host->cmd = NULL; switch (host->state) { case STATE_IDLE: |
c06ad2580 atmel-mci: Implem... |
1356 |
break; |
965ebf33e atmel-mci: suppor... |
1357 1358 1359 1360 1361 1362 |
case STATE_SENDING_CMD: mrq->cmd->error = -ENOMEDIUM; if (!mrq->data) break; /* fall through */ case STATE_SENDING_DATA: |
c06ad2580 atmel-mci: Implem... |
1363 |
mrq->data->error = -ENOMEDIUM; |
796211b79 mmc: atmel-mci: a... |
1364 |
host->stop_transfer(host); |
c06ad2580 atmel-mci: Implem... |
1365 |
break; |
965ebf33e atmel-mci: suppor... |
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 |
case STATE_DATA_BUSY: case STATE_DATA_ERROR: if (mrq->data->error == -EINPROGRESS) mrq->data->error = -ENOMEDIUM; if (!mrq->stop) break; /* fall through */ case STATE_SENDING_STOP: mrq->stop->error = -ENOMEDIUM; break; } |
7d2be0749 atmel-mci: Driver... |
1377 |
|
965ebf33e atmel-mci: suppor... |
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 |
atmci_request_end(host, mrq); } else { list_del(&slot->queue_node); mrq->cmd->error = -ENOMEDIUM; if (mrq->data) mrq->data->error = -ENOMEDIUM; if (mrq->stop) mrq->stop->error = -ENOMEDIUM; spin_unlock(&host->lock); mmc_request_done(slot->mmc, mrq); spin_lock(&host->lock); } |
7d2be0749 atmel-mci: Driver... |
1391 |
} |
965ebf33e atmel-mci: suppor... |
1392 |
spin_unlock(&host->lock); |
7d2be0749 atmel-mci: Driver... |
1393 |
|
965ebf33e atmel-mci: suppor... |
1394 |
mmc_detect_change(slot->mmc, 0); |
7d2be0749 atmel-mci: Driver... |
1395 1396 1397 1398 1399 |
} } static void atmci_tasklet_func(unsigned long priv) { |
965ebf33e atmel-mci: suppor... |
1400 |
struct atmel_mci *host = (struct atmel_mci *)priv; |
7d2be0749 atmel-mci: Driver... |
1401 1402 |
struct mmc_request *mrq = host->mrq; struct mmc_data *data = host->data; |
c06ad2580 atmel-mci: Implem... |
1403 1404 1405 1406 |
struct mmc_command *cmd = host->cmd; enum atmel_mci_state state = host->state; enum atmel_mci_state prev_state; u32 status; |
965ebf33e atmel-mci: suppor... |
1407 |
spin_lock(&host->lock); |
c06ad2580 atmel-mci: Implem... |
1408 |
state = host->state; |
7d2be0749 atmel-mci: Driver... |
1409 |
|
965ebf33e atmel-mci: suppor... |
1410 |
dev_vdbg(&host->pdev->dev, |
c06ad2580 atmel-mci: Implem... |
1411 1412 1413 |
"tasklet: state %u pending/completed/mask %lx/%lx/%x ", state, host->pending_events, host->completed_events, |
03fc9a7f0 mmc: atmel-mci: c... |
1414 |
atmci_readl(host, ATMCI_IMR)); |
7d2be0749 atmel-mci: Driver... |
1415 |
|
c06ad2580 atmel-mci: Implem... |
1416 1417 |
do { prev_state = state; |
7d2be0749 atmel-mci: Driver... |
1418 |
|
c06ad2580 atmel-mci: Implem... |
1419 |
switch (state) { |
965ebf33e atmel-mci: suppor... |
1420 1421 |
case STATE_IDLE: break; |
c06ad2580 atmel-mci: Implem... |
1422 1423 1424 1425 |
case STATE_SENDING_CMD: if (!atmci_test_and_clear_pending(host, EVENT_CMD_COMPLETE)) break; |
7d2be0749 atmel-mci: Driver... |
1426 |
|
c06ad2580 atmel-mci: Implem... |
1427 1428 1429 1430 |
host->cmd = NULL; atmci_set_completed(host, EVENT_CMD_COMPLETE); atmci_command_complete(host, mrq->cmd); if (!mrq->data || cmd->error) { |
965ebf33e atmel-mci: suppor... |
1431 1432 |
atmci_request_end(host, host->mrq); goto unlock; |
c06ad2580 atmel-mci: Implem... |
1433 |
} |
7d2be0749 atmel-mci: Driver... |
1434 |
|
c06ad2580 atmel-mci: Implem... |
1435 1436 |
prev_state = state = STATE_SENDING_DATA; /* fall through */ |
7d2be0749 atmel-mci: Driver... |
1437 |
|
c06ad2580 atmel-mci: Implem... |
1438 1439 1440 |
case STATE_SENDING_DATA: if (atmci_test_and_clear_pending(host, EVENT_DATA_ERROR)) { |
796211b79 mmc: atmel-mci: a... |
1441 |
host->stop_transfer(host); |
c06ad2580 atmel-mci: Implem... |
1442 |
if (data->stop) |
2c96a293b mmc: atmel-mci: c... |
1443 |
atmci_send_stop_cmd(host, data); |
c06ad2580 atmel-mci: Implem... |
1444 1445 1446 |
state = STATE_DATA_ERROR; break; } |
7d2be0749 atmel-mci: Driver... |
1447 |
|
c06ad2580 atmel-mci: Implem... |
1448 1449 1450 |
if (!atmci_test_and_clear_pending(host, EVENT_XFER_COMPLETE)) break; |
7d2be0749 atmel-mci: Driver... |
1451 |
|
c06ad2580 atmel-mci: Implem... |
1452 1453 1454 |
atmci_set_completed(host, EVENT_XFER_COMPLETE); prev_state = state = STATE_DATA_BUSY; /* fall through */ |
7d2be0749 atmel-mci: Driver... |
1455 |
|
c06ad2580 atmel-mci: Implem... |
1456 1457 1458 1459 1460 1461 1462 1463 1464 |
case STATE_DATA_BUSY: if (!atmci_test_and_clear_pending(host, EVENT_DATA_COMPLETE)) break; host->data = NULL; atmci_set_completed(host, EVENT_DATA_COMPLETE); status = host->data_status; if (unlikely(status & ATMCI_DATA_ERROR_FLAGS)) { |
2c96a293b mmc: atmel-mci: c... |
1465 |
if (status & ATMCI_DTOE) { |
965ebf33e atmel-mci: suppor... |
1466 |
dev_dbg(&host->pdev->dev, |
c06ad2580 atmel-mci: Implem... |
1467 1468 1469 |
"data timeout error "); data->error = -ETIMEDOUT; |
2c96a293b mmc: atmel-mci: c... |
1470 |
} else if (status & ATMCI_DCRCE) { |
965ebf33e atmel-mci: suppor... |
1471 |
dev_dbg(&host->pdev->dev, |
c06ad2580 atmel-mci: Implem... |
1472 1473 1474 1475 |
"data CRC error "); data->error = -EILSEQ; } else { |
965ebf33e atmel-mci: suppor... |
1476 |
dev_dbg(&host->pdev->dev, |
c06ad2580 atmel-mci: Implem... |
1477 1478 1479 1480 1481 1482 1483 1484 |
"data FIFO error (status=%08x) ", status); data->error = -EIO; } } else { data->bytes_xfered = data->blocks * data->blksz; data->error = 0; |
03fc9a7f0 mmc: atmel-mci: c... |
1485 |
atmci_writel(host, ATMCI_IDR, ATMCI_DATA_ERROR_FLAGS); |
c06ad2580 atmel-mci: Implem... |
1486 1487 1488 |
} if (!data->stop) { |
965ebf33e atmel-mci: suppor... |
1489 1490 |
atmci_request_end(host, host->mrq); goto unlock; |
c06ad2580 atmel-mci: Implem... |
1491 |
} |
7d2be0749 atmel-mci: Driver... |
1492 |
|
c06ad2580 atmel-mci: Implem... |
1493 1494 |
prev_state = state = STATE_SENDING_STOP; if (!data->error) |
2c96a293b mmc: atmel-mci: c... |
1495 |
atmci_send_stop_cmd(host, data); |
c06ad2580 atmel-mci: Implem... |
1496 1497 1498 1499 1500 1501 1502 1503 1504 |
/* fall through */ case STATE_SENDING_STOP: if (!atmci_test_and_clear_pending(host, EVENT_CMD_COMPLETE)) break; host->cmd = NULL; atmci_command_complete(host, mrq->stop); |
965ebf33e atmel-mci: suppor... |
1505 1506 |
atmci_request_end(host, host->mrq); goto unlock; |
c06ad2580 atmel-mci: Implem... |
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 |
case STATE_DATA_ERROR: if (!atmci_test_and_clear_pending(host, EVENT_XFER_COMPLETE)) break; state = STATE_DATA_BUSY; break; } } while (state != prev_state); host->state = state; |
965ebf33e atmel-mci: suppor... |
1519 1520 1521 |
unlock: spin_unlock(&host->lock); |
7d2be0749 atmel-mci: Driver... |
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
} static void atmci_read_data_pio(struct atmel_mci *host) { struct scatterlist *sg = host->sg; void *buf = sg_virt(sg); unsigned int offset = host->pio_offset; struct mmc_data *data = host->data; u32 value; u32 status; unsigned int nbytes = 0; do { |
03fc9a7f0 mmc: atmel-mci: c... |
1535 |
value = atmci_readl(host, ATMCI_RDR); |
7d2be0749 atmel-mci: Driver... |
1536 1537 1538 1539 1540 1541 1542 |
if (likely(offset + 4 <= sg->length)) { put_unaligned(value, (u32 *)(buf + offset)); offset += 4; nbytes += 4; if (offset == sg->length) { |
5e7184ae0 atmel-mci: Add mi... |
1543 |
flush_dcache_page(sg_page(sg)); |
7d2be0749 atmel-mci: Driver... |
1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 |
host->sg = sg = sg_next(sg); if (!sg) goto done; offset = 0; buf = sg_virt(sg); } } else { unsigned int remaining = sg->length - offset; memcpy(buf + offset, &value, remaining); nbytes += remaining; flush_dcache_page(sg_page(sg)); host->sg = sg = sg_next(sg); if (!sg) goto done; offset = 4 - remaining; buf = sg_virt(sg); memcpy(buf, (u8 *)&value + remaining, offset); nbytes += offset; } |
03fc9a7f0 mmc: atmel-mci: c... |
1566 |
status = atmci_readl(host, ATMCI_SR); |
7d2be0749 atmel-mci: Driver... |
1567 |
if (status & ATMCI_DATA_ERROR_FLAGS) { |
03fc9a7f0 mmc: atmel-mci: c... |
1568 |
atmci_writel(host, ATMCI_IDR, (ATMCI_NOTBUSY | ATMCI_RXRDY |
7d2be0749 atmel-mci: Driver... |
1569 1570 |
| ATMCI_DATA_ERROR_FLAGS)); host->data_status = status; |
965ebf33e atmel-mci: suppor... |
1571 1572 |
data->bytes_xfered += nbytes; smp_wmb(); |
7d2be0749 atmel-mci: Driver... |
1573 1574 |
atmci_set_pending(host, EVENT_DATA_ERROR); tasklet_schedule(&host->tasklet); |
965ebf33e atmel-mci: suppor... |
1575 |
return; |
7d2be0749 atmel-mci: Driver... |
1576 |
} |
2c96a293b mmc: atmel-mci: c... |
1577 |
} while (status & ATMCI_RXRDY); |
7d2be0749 atmel-mci: Driver... |
1578 1579 1580 1581 1582 1583 1584 |
host->pio_offset = offset; data->bytes_xfered += nbytes; return; done: |
03fc9a7f0 mmc: atmel-mci: c... |
1585 1586 |
atmci_writel(host, ATMCI_IDR, ATMCI_RXRDY); atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); |
7d2be0749 atmel-mci: Driver... |
1587 |
data->bytes_xfered += nbytes; |
965ebf33e atmel-mci: suppor... |
1588 |
smp_wmb(); |
c06ad2580 atmel-mci: Implem... |
1589 |
atmci_set_pending(host, EVENT_XFER_COMPLETE); |
7d2be0749 atmel-mci: Driver... |
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 |
} static void atmci_write_data_pio(struct atmel_mci *host) { struct scatterlist *sg = host->sg; void *buf = sg_virt(sg); unsigned int offset = host->pio_offset; struct mmc_data *data = host->data; u32 value; u32 status; unsigned int nbytes = 0; do { if (likely(offset + 4 <= sg->length)) { value = get_unaligned((u32 *)(buf + offset)); |
03fc9a7f0 mmc: atmel-mci: c... |
1605 |
atmci_writel(host, ATMCI_TDR, value); |
7d2be0749 atmel-mci: Driver... |
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 |
offset += 4; nbytes += 4; if (offset == sg->length) { host->sg = sg = sg_next(sg); if (!sg) goto done; offset = 0; buf = sg_virt(sg); } } else { unsigned int remaining = sg->length - offset; value = 0; memcpy(&value, buf + offset, remaining); nbytes += remaining; host->sg = sg = sg_next(sg); if (!sg) { |
03fc9a7f0 mmc: atmel-mci: c... |
1626 |
atmci_writel(host, ATMCI_TDR, value); |
7d2be0749 atmel-mci: Driver... |
1627 1628 1629 1630 1631 1632 |
goto done; } offset = 4 - remaining; buf = sg_virt(sg); memcpy((u8 *)&value + remaining, buf, offset); |
03fc9a7f0 mmc: atmel-mci: c... |
1633 |
atmci_writel(host, ATMCI_TDR, value); |
7d2be0749 atmel-mci: Driver... |
1634 1635 |
nbytes += offset; } |
03fc9a7f0 mmc: atmel-mci: c... |
1636 |
status = atmci_readl(host, ATMCI_SR); |
7d2be0749 atmel-mci: Driver... |
1637 |
if (status & ATMCI_DATA_ERROR_FLAGS) { |
03fc9a7f0 mmc: atmel-mci: c... |
1638 |
atmci_writel(host, ATMCI_IDR, (ATMCI_NOTBUSY | ATMCI_TXRDY |
7d2be0749 atmel-mci: Driver... |
1639 1640 |
| ATMCI_DATA_ERROR_FLAGS)); host->data_status = status; |
965ebf33e atmel-mci: suppor... |
1641 1642 |
data->bytes_xfered += nbytes; smp_wmb(); |
7d2be0749 atmel-mci: Driver... |
1643 1644 |
atmci_set_pending(host, EVENT_DATA_ERROR); tasklet_schedule(&host->tasklet); |
965ebf33e atmel-mci: suppor... |
1645 |
return; |
7d2be0749 atmel-mci: Driver... |
1646 |
} |
2c96a293b mmc: atmel-mci: c... |
1647 |
} while (status & ATMCI_TXRDY); |
7d2be0749 atmel-mci: Driver... |
1648 1649 1650 1651 1652 1653 1654 |
host->pio_offset = offset; data->bytes_xfered += nbytes; return; done: |
03fc9a7f0 mmc: atmel-mci: c... |
1655 1656 |
atmci_writel(host, ATMCI_IDR, ATMCI_TXRDY); atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); |
7d2be0749 atmel-mci: Driver... |
1657 |
data->bytes_xfered += nbytes; |
965ebf33e atmel-mci: suppor... |
1658 |
smp_wmb(); |
c06ad2580 atmel-mci: Implem... |
1659 |
atmci_set_pending(host, EVENT_XFER_COMPLETE); |
7d2be0749 atmel-mci: Driver... |
1660 |
} |
965ebf33e atmel-mci: suppor... |
1661 |
static void atmci_cmd_interrupt(struct atmel_mci *host, u32 status) |
7d2be0749 atmel-mci: Driver... |
1662 |
{ |
03fc9a7f0 mmc: atmel-mci: c... |
1663 |
atmci_writel(host, ATMCI_IDR, ATMCI_CMDRDY); |
7d2be0749 atmel-mci: Driver... |
1664 |
|
c06ad2580 atmel-mci: Implem... |
1665 |
host->cmd_status = status; |
965ebf33e atmel-mci: suppor... |
1666 |
smp_wmb(); |
c06ad2580 atmel-mci: Implem... |
1667 |
atmci_set_pending(host, EVENT_CMD_COMPLETE); |
7d2be0749 atmel-mci: Driver... |
1668 1669 |
tasklet_schedule(&host->tasklet); } |
88ff82ed4 mmc: atmel-mci: A... |
1670 1671 1672 |
static void atmci_sdio_interrupt(struct atmel_mci *host, u32 status) { int i; |
2c96a293b mmc: atmel-mci: c... |
1673 |
for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) { |
88ff82ed4 mmc: atmel-mci: A... |
1674 1675 1676 1677 1678 1679 |
struct atmel_mci_slot *slot = host->slot[i]; if (slot && (status & slot->sdio_irq)) { mmc_signal_sdio_irq(slot->mmc); } } } |
7d2be0749 atmel-mci: Driver... |
1680 1681 |
static irqreturn_t atmci_interrupt(int irq, void *dev_id) { |
965ebf33e atmel-mci: suppor... |
1682 |
struct atmel_mci *host = dev_id; |
7d2be0749 atmel-mci: Driver... |
1683 1684 |
u32 status, mask, pending; unsigned int pass_count = 0; |
7d2be0749 atmel-mci: Driver... |
1685 |
do { |
03fc9a7f0 mmc: atmel-mci: c... |
1686 1687 |
status = atmci_readl(host, ATMCI_SR); mask = atmci_readl(host, ATMCI_IMR); |
7d2be0749 atmel-mci: Driver... |
1688 1689 1690 1691 1692 |
pending = status & mask; if (!pending) break; if (pending & ATMCI_DATA_ERROR_FLAGS) { |
03fc9a7f0 mmc: atmel-mci: c... |
1693 |
atmci_writel(host, ATMCI_IDR, ATMCI_DATA_ERROR_FLAGS |
2c96a293b mmc: atmel-mci: c... |
1694 |
| ATMCI_RXRDY | ATMCI_TXRDY); |
03fc9a7f0 mmc: atmel-mci: c... |
1695 |
pending &= atmci_readl(host, ATMCI_IMR); |
965ebf33e atmel-mci: suppor... |
1696 |
|
7d2be0749 atmel-mci: Driver... |
1697 |
host->data_status = status; |
965ebf33e atmel-mci: suppor... |
1698 |
smp_wmb(); |
7d2be0749 atmel-mci: Driver... |
1699 1700 1701 |
atmci_set_pending(host, EVENT_DATA_ERROR); tasklet_schedule(&host->tasklet); } |
796211b79 mmc: atmel-mci: a... |
1702 |
|
796211b79 mmc: atmel-mci: a... |
1703 1704 |
if (pending & ATMCI_TXBUFE) { atmci_writel(host, ATMCI_IDR, ATMCI_TXBUFE); |
7e8ba228d mmc: atmel-mci: f... |
1705 |
atmci_writel(host, ATMCI_IDR, ATMCI_ENDTX); |
796211b79 mmc: atmel-mci: a... |
1706 1707 1708 1709 1710 1711 1712 |
/* * We can receive this interruption before having configured * the second pdc buffer, so we need to reconfigure first and * second buffers again */ if (host->data_size) { atmci_pdc_set_both_buf(host, XFER_TRANSMIT); |
7e8ba228d mmc: atmel-mci: f... |
1713 |
atmci_writel(host, ATMCI_IER, ATMCI_ENDTX); |
796211b79 mmc: atmel-mci: a... |
1714 1715 1716 1717 |
atmci_writel(host, ATMCI_IER, ATMCI_TXBUFE); } else { atmci_pdc_complete(host); } |
7e8ba228d mmc: atmel-mci: f... |
1718 1719 |
} else if (pending & ATMCI_ENDTX) { atmci_writel(host, ATMCI_IDR, ATMCI_ENDTX); |
796211b79 mmc: atmel-mci: a... |
1720 1721 1722 |
if (host->data_size) { atmci_pdc_set_single_buf(host, |
7e8ba228d mmc: atmel-mci: f... |
1723 1724 |
XFER_TRANSMIT, PDC_SECOND_BUF); atmci_writel(host, ATMCI_IER, ATMCI_ENDTX); |
796211b79 mmc: atmel-mci: a... |
1725 1726 1727 1728 1729 |
} } if (pending & ATMCI_RXBUFF) { atmci_writel(host, ATMCI_IDR, ATMCI_RXBUFF); |
7e8ba228d mmc: atmel-mci: f... |
1730 |
atmci_writel(host, ATMCI_IDR, ATMCI_ENDRX); |
796211b79 mmc: atmel-mci: a... |
1731 1732 1733 1734 1735 1736 1737 |
/* * We can receive this interruption before having configured * the second pdc buffer, so we need to reconfigure first and * second buffers again */ if (host->data_size) { atmci_pdc_set_both_buf(host, XFER_RECEIVE); |
7e8ba228d mmc: atmel-mci: f... |
1738 |
atmci_writel(host, ATMCI_IER, ATMCI_ENDRX); |
796211b79 mmc: atmel-mci: a... |
1739 1740 1741 1742 |
atmci_writel(host, ATMCI_IER, ATMCI_RXBUFF); } else { atmci_pdc_complete(host); } |
7e8ba228d mmc: atmel-mci: f... |
1743 1744 1745 1746 1747 1748 1749 1750 |
} else if (pending & ATMCI_ENDRX) { atmci_writel(host, ATMCI_IDR, ATMCI_ENDRX); if (host->data_size) { atmci_pdc_set_single_buf(host, XFER_RECEIVE, PDC_SECOND_BUF); atmci_writel(host, ATMCI_IER, ATMCI_ENDRX); } |
796211b79 mmc: atmel-mci: a... |
1751 |
} |
7e8ba228d mmc: atmel-mci: f... |
1752 |
|
2c96a293b mmc: atmel-mci: c... |
1753 |
if (pending & ATMCI_NOTBUSY) { |
03fc9a7f0 mmc: atmel-mci: c... |
1754 |
atmci_writel(host, ATMCI_IDR, |
2c96a293b mmc: atmel-mci: c... |
1755 |
ATMCI_DATA_ERROR_FLAGS | ATMCI_NOTBUSY); |
ca55f46e1 atmel-mci: Don't ... |
1756 1757 |
if (!host->data_status) host->data_status = status; |
965ebf33e atmel-mci: suppor... |
1758 |
smp_wmb(); |
7d2be0749 atmel-mci: Driver... |
1759 1760 1761 |
atmci_set_pending(host, EVENT_DATA_COMPLETE); tasklet_schedule(&host->tasklet); } |
2c96a293b mmc: atmel-mci: c... |
1762 |
if (pending & ATMCI_RXRDY) |
7d2be0749 atmel-mci: Driver... |
1763 |
atmci_read_data_pio(host); |
2c96a293b mmc: atmel-mci: c... |
1764 |
if (pending & ATMCI_TXRDY) |
7d2be0749 atmel-mci: Driver... |
1765 |
atmci_write_data_pio(host); |
2c96a293b mmc: atmel-mci: c... |
1766 |
if (pending & ATMCI_CMDRDY) |
965ebf33e atmel-mci: suppor... |
1767 |
atmci_cmd_interrupt(host, status); |
88ff82ed4 mmc: atmel-mci: A... |
1768 |
|
2c96a293b mmc: atmel-mci: c... |
1769 |
if (pending & (ATMCI_SDIOIRQA | ATMCI_SDIOIRQB)) |
88ff82ed4 mmc: atmel-mci: A... |
1770 |
atmci_sdio_interrupt(host, status); |
7d2be0749 atmel-mci: Driver... |
1771 |
} while (pass_count++ < 5); |
7d2be0749 atmel-mci: Driver... |
1772 1773 1774 1775 1776 |
return pass_count ? IRQ_HANDLED : IRQ_NONE; } static irqreturn_t atmci_detect_interrupt(int irq, void *dev_id) { |
965ebf33e atmel-mci: suppor... |
1777 |
struct atmel_mci_slot *slot = dev_id; |
7d2be0749 atmel-mci: Driver... |
1778 1779 1780 1781 1782 1783 1784 |
/* * Disable interrupts until the pin has stabilized and check * the state then. Use mod_timer() since we may be in the * middle of the timer routine when this interrupt triggers. */ disable_irq_nosync(irq); |
965ebf33e atmel-mci: suppor... |
1785 |
mod_timer(&slot->detect_timer, jiffies + msecs_to_jiffies(20)); |
7d2be0749 atmel-mci: Driver... |
1786 1787 1788 |
return IRQ_HANDLED; } |
965ebf33e atmel-mci: suppor... |
1789 1790 |
static int __init atmci_init_slot(struct atmel_mci *host, struct mci_slot_pdata *slot_data, unsigned int id, |
88ff82ed4 mmc: atmel-mci: A... |
1791 |
u32 sdc_reg, u32 sdio_irq) |
965ebf33e atmel-mci: suppor... |
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 |
{ struct mmc_host *mmc; struct atmel_mci_slot *slot; mmc = mmc_alloc_host(sizeof(struct atmel_mci_slot), &host->pdev->dev); if (!mmc) return -ENOMEM; slot = mmc_priv(mmc); slot->mmc = mmc; slot->host = host; slot->detect_pin = slot_data->detect_pin; slot->wp_pin = slot_data->wp_pin; |
1c1452be2 atmel-mci: Add su... |
1805 |
slot->detect_is_active_high = slot_data->detect_is_active_high; |
965ebf33e atmel-mci: suppor... |
1806 |
slot->sdc_reg = sdc_reg; |
88ff82ed4 mmc: atmel-mci: A... |
1807 |
slot->sdio_irq = sdio_irq; |
965ebf33e atmel-mci: suppor... |
1808 1809 1810 1811 1812 |
mmc->ops = &atmci_ops; mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512); mmc->f_max = host->bus_hz / 2; mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
88ff82ed4 mmc: atmel-mci: A... |
1813 1814 |
if (sdio_irq) mmc->caps |= MMC_CAP_SDIO_IRQ; |
796211b79 mmc: atmel-mci: a... |
1815 |
if (host->caps.has_highspeed) |
99ddffd8e mmc: atmel-mci: e... |
1816 |
mmc->caps |= MMC_CAP_SD_HIGHSPEED; |
965ebf33e atmel-mci: suppor... |
1817 1818 |
if (slot_data->bus_width >= 4) mmc->caps |= MMC_CAP_4_BIT_DATA; |
a36274e01 mmc: Remove disti... |
1819 |
mmc->max_segs = 64; |
965ebf33e atmel-mci: suppor... |
1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 |
mmc->max_req_size = 32768 * 512; mmc->max_blk_size = 32768; mmc->max_blk_count = 512; /* Assume card is present initially */ set_bit(ATMCI_CARD_PRESENT, &slot->flags); if (gpio_is_valid(slot->detect_pin)) { if (gpio_request(slot->detect_pin, "mmc_detect")) { dev_dbg(&mmc->class_dev, "no detect pin available "); slot->detect_pin = -EBUSY; |
1c1452be2 atmel-mci: Add su... |
1831 1832 |
} else if (gpio_get_value(slot->detect_pin) ^ slot->detect_is_active_high) { |
965ebf33e atmel-mci: suppor... |
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 |
clear_bit(ATMCI_CARD_PRESENT, &slot->flags); } } if (!gpio_is_valid(slot->detect_pin)) mmc->caps |= MMC_CAP_NEEDS_POLL; if (gpio_is_valid(slot->wp_pin)) { if (gpio_request(slot->wp_pin, "mmc_wp")) { dev_dbg(&mmc->class_dev, "no WP pin available "); slot->wp_pin = -EBUSY; } } host->slot[id] = slot; mmc_add_host(mmc); if (gpio_is_valid(slot->detect_pin)) { int ret; setup_timer(&slot->detect_timer, atmci_detect_change, (unsigned long)slot); ret = request_irq(gpio_to_irq(slot->detect_pin), atmci_detect_interrupt, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, "mmc-detect", slot); if (ret) { dev_dbg(&mmc->class_dev, "could not request IRQ %d for detect pin ", gpio_to_irq(slot->detect_pin)); gpio_free(slot->detect_pin); slot->detect_pin = -EBUSY; } } atmci_init_debugfs(slot); return 0; } static void __exit atmci_cleanup_slot(struct atmel_mci_slot *slot, unsigned int id) { /* Debugfs stuff is cleaned up by mmc core */ set_bit(ATMCI_SHUTDOWN, &slot->flags); smp_wmb(); mmc_remove_host(slot->mmc); if (gpio_is_valid(slot->detect_pin)) { int pin = slot->detect_pin; free_irq(gpio_to_irq(pin), slot); del_timer_sync(&slot->detect_timer); gpio_free(pin); } if (gpio_is_valid(slot->wp_pin)) gpio_free(slot->wp_pin); slot->host->slot[id] = NULL; mmc_free_host(slot->mmc); } |
2c96a293b mmc: atmel-mci: c... |
1899 |
static bool atmci_filter(struct dma_chan *chan, void *slave) |
74465b4ff atmel-mci: conver... |
1900 |
{ |
2635d1ba7 atmel-mci: change... |
1901 |
struct mci_dma_data *sl = slave; |
74465b4ff atmel-mci: conver... |
1902 |
|
2635d1ba7 atmel-mci: change... |
1903 1904 |
if (sl && find_slave_dev(sl) == chan->device->dev) { chan->private = slave_data_ptr(sl); |
7dd602510 dmaengine: kill e... |
1905 |
return true; |
2635d1ba7 atmel-mci: change... |
1906 |
} else { |
7dd602510 dmaengine: kill e... |
1907 |
return false; |
2635d1ba7 atmel-mci: change... |
1908 |
} |
74465b4ff atmel-mci: conver... |
1909 |
} |
2635d1ba7 atmel-mci: change... |
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 |
static void atmci_configure_dma(struct atmel_mci *host) { struct mci_platform_data *pdata; if (host == NULL) return; pdata = host->pdev->dev.platform_data; if (pdata && find_slave_dev(pdata->dma_slave)) { dma_cap_mask_t mask; setup_dma_addr(pdata->dma_slave, |
2c96a293b mmc: atmel-mci: c... |
1924 1925 |
host->mapbase + ATMCI_TDR, host->mapbase + ATMCI_RDR); |
2635d1ba7 atmel-mci: change... |
1926 1927 1928 1929 1930 |
/* Try to grab a DMA channel */ dma_cap_zero(mask); dma_cap_set(DMA_SLAVE, mask); host->dma.chan = |
2c96a293b mmc: atmel-mci: c... |
1931 |
dma_request_channel(mask, atmci_filter, pdata->dma_slave); |
2635d1ba7 atmel-mci: change... |
1932 1933 1934 1935 |
} if (!host->dma.chan) dev_notice(&host->pdev->dev, "DMA not available, using PIO "); |
74791a2dc mmc: atmel-mci: n... |
1936 1937 1938 1939 1940 |
else dev_info(&host->pdev->dev, "Using %s for DMA transfers ", dma_chan_name(host->dma.chan)); |
2635d1ba7 atmel-mci: change... |
1941 |
} |
796211b79 mmc: atmel-mci: a... |
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 |
static inline unsigned int atmci_get_version(struct atmel_mci *host) { return atmci_readl(host, ATMCI_VERSION) & 0x00000fff; } /* * HSMCI (High Speed MCI) module is not fully compatible with MCI module. * HSMCI provides DMA support and a new config register but no more supports * PDC. */ static void __init atmci_get_cap(struct atmel_mci *host) { unsigned int version; version = atmci_get_version(host); dev_info(&host->pdev->dev, "version: 0x%x ", version); host->caps.has_dma = 0; host->caps.has_pdc = 0; host->caps.has_cfg_reg = 0; host->caps.has_cstor_reg = 0; host->caps.has_highspeed = 0; host->caps.has_rwproof = 0; /* keep only major version number */ switch (version & 0xf00) { case 0x100: case 0x200: host->caps.has_pdc = 1; host->caps.has_rwproof = 1; break; case 0x300: case 0x400: case 0x500: #ifdef CONFIG_AT_HDMAC host->caps.has_dma = 1; |
2635d1ba7 atmel-mci: change... |
1981 |
#else |
796211b79 mmc: atmel-mci: a... |
1982 1983 1984 1985 |
host->caps.has_dma = 0; dev_info(&host->pdev->dev, "has dma capability but dma engine is not selected, then use pio "); |
74465b4ff atmel-mci: conver... |
1986 |
#endif |
796211b79 mmc: atmel-mci: a... |
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 |
host->caps.has_cfg_reg = 1; host->caps.has_cstor_reg = 1; host->caps.has_highspeed = 1; host->caps.has_rwproof = 1; break; default: dev_warn(&host->pdev->dev, "Unmanaged mci version, set minimum capabilities "); break; } } |
74465b4ff atmel-mci: conver... |
1999 |
|
7d2be0749 atmel-mci: Driver... |
2000 2001 2002 |
static int __init atmci_probe(struct platform_device *pdev) { struct mci_platform_data *pdata; |
965ebf33e atmel-mci: suppor... |
2003 2004 2005 2006 2007 |
struct atmel_mci *host; struct resource *regs; unsigned int nr_slots; int irq; int ret; |
7d2be0749 atmel-mci: Driver... |
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 |
regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!regs) return -ENXIO; pdata = pdev->dev.platform_data; if (!pdata) return -ENXIO; irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; |
965ebf33e atmel-mci: suppor... |
2018 2019 |
host = kzalloc(sizeof(struct atmel_mci), GFP_KERNEL); if (!host) |
7d2be0749 atmel-mci: Driver... |
2020 |
return -ENOMEM; |
7d2be0749 atmel-mci: Driver... |
2021 |
host->pdev = pdev; |
965ebf33e atmel-mci: suppor... |
2022 2023 |
spin_lock_init(&host->lock); INIT_LIST_HEAD(&host->queue); |
7d2be0749 atmel-mci: Driver... |
2024 2025 2026 2027 2028 2029 2030 2031 |
host->mck = clk_get(&pdev->dev, "mci_clk"); if (IS_ERR(host->mck)) { ret = PTR_ERR(host->mck); goto err_clk_get; } ret = -ENOMEM; |
e8e3f6ca1 mmc: atmel-mci.c:... |
2032 |
host->regs = ioremap(regs->start, resource_size(regs)); |
7d2be0749 atmel-mci: Driver... |
2033 2034 2035 2036 |
if (!host->regs) goto err_ioremap; clk_enable(host->mck); |
03fc9a7f0 mmc: atmel-mci: c... |
2037 |
atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); |
7d2be0749 atmel-mci: Driver... |
2038 2039 2040 2041 |
host->bus_hz = clk_get_rate(host->mck); clk_disable(host->mck); host->mapbase = regs->start; |
965ebf33e atmel-mci: suppor... |
2042 |
tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)host); |
7d2be0749 atmel-mci: Driver... |
2043 |
|
89c8aa203 mmc: struct devic... |
2044 |
ret = request_irq(irq, atmci_interrupt, 0, dev_name(&pdev->dev), host); |
7d2be0749 atmel-mci: Driver... |
2045 2046 |
if (ret) goto err_request_irq; |
796211b79 mmc: atmel-mci: a... |
2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 |
/* Get MCI capabilities and set operations according to it */ atmci_get_cap(host); if (host->caps.has_dma) { dev_info(&pdev->dev, "using DMA "); host->prepare_data = &atmci_prepare_data_dma; host->submit_data = &atmci_submit_data_dma; host->stop_transfer = &atmci_stop_transfer_dma; } else if (host->caps.has_pdc) { dev_info(&pdev->dev, "using PDC "); host->prepare_data = &atmci_prepare_data_pdc; host->submit_data = &atmci_submit_data_pdc; host->stop_transfer = &atmci_stop_transfer_pdc; } else { dev_info(&pdev->dev, "no DMA, no PDC "); host->prepare_data = &atmci_prepare_data; host->submit_data = &atmci_submit_data; host->stop_transfer = &atmci_stop_transfer; } if (host->caps.has_dma) atmci_configure_dma(host); |
65e8b083f atmel-mci: Add ex... |
2071 |
|
7d2be0749 atmel-mci: Driver... |
2072 |
platform_set_drvdata(pdev, host); |
965ebf33e atmel-mci: suppor... |
2073 2074 2075 2076 2077 |
/* We need at least one slot to succeed */ nr_slots = 0; ret = -ENODEV; if (pdata->slot[0].bus_width) { ret = atmci_init_slot(host, &pdata->slot[0], |
2c96a293b mmc: atmel-mci: c... |
2078 |
0, ATMCI_SDCSEL_SLOT_A, ATMCI_SDIOIRQA); |
965ebf33e atmel-mci: suppor... |
2079 2080 2081 2082 2083 |
if (!ret) nr_slots++; } if (pdata->slot[1].bus_width) { ret = atmci_init_slot(host, &pdata->slot[1], |
2c96a293b mmc: atmel-mci: c... |
2084 |
1, ATMCI_SDCSEL_SLOT_B, ATMCI_SDIOIRQB); |
965ebf33e atmel-mci: suppor... |
2085 2086 |
if (!ret) nr_slots++; |
7d2be0749 atmel-mci: Driver... |
2087 |
} |
04d699c36 atmel-mci: unifie... |
2088 2089 2090 |
if (!nr_slots) { dev_err(&pdev->dev, "init failed: no slot defined "); |
965ebf33e atmel-mci: suppor... |
2091 |
goto err_init_slot; |
04d699c36 atmel-mci: unifie... |
2092 |
} |
7d2be0749 atmel-mci: Driver... |
2093 |
|
965ebf33e atmel-mci: suppor... |
2094 2095 2096 2097 |
dev_info(&pdev->dev, "Atmel MCI controller at 0x%08lx irq %d, %u slots ", host->mapbase, irq, nr_slots); |
deec9ae31 atmel-mci: debugf... |
2098 |
|
7d2be0749 atmel-mci: Driver... |
2099 |
return 0; |
965ebf33e atmel-mci: suppor... |
2100 |
err_init_slot: |
74465b4ff atmel-mci: conver... |
2101 2102 |
if (host->dma.chan) dma_release_channel(host->dma.chan); |
965ebf33e atmel-mci: suppor... |
2103 |
free_irq(irq, host); |
7d2be0749 atmel-mci: Driver... |
2104 2105 2106 2107 2108 |
err_request_irq: iounmap(host->regs); err_ioremap: clk_put(host->mck); err_clk_get: |
965ebf33e atmel-mci: suppor... |
2109 |
kfree(host); |
7d2be0749 atmel-mci: Driver... |
2110 2111 2112 2113 2114 |
return ret; } static int __exit atmci_remove(struct platform_device *pdev) { |
965ebf33e atmel-mci: suppor... |
2115 2116 |
struct atmel_mci *host = platform_get_drvdata(pdev); unsigned int i; |
7d2be0749 atmel-mci: Driver... |
2117 2118 |
platform_set_drvdata(pdev, NULL); |
2c96a293b mmc: atmel-mci: c... |
2119 |
for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) { |
965ebf33e atmel-mci: suppor... |
2120 2121 2122 |
if (host->slot[i]) atmci_cleanup_slot(host->slot[i], i); } |
7d2be0749 atmel-mci: Driver... |
2123 |
|
965ebf33e atmel-mci: suppor... |
2124 |
clk_enable(host->mck); |
03fc9a7f0 mmc: atmel-mci: c... |
2125 2126 2127 |
atmci_writel(host, ATMCI_IDR, ~0UL); atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS); atmci_readl(host, ATMCI_SR); |
965ebf33e atmel-mci: suppor... |
2128 |
clk_disable(host->mck); |
7d2be0749 atmel-mci: Driver... |
2129 |
|
65e8b083f atmel-mci: Add ex... |
2130 |
#ifdef CONFIG_MMC_ATMELMCI_DMA |
74465b4ff atmel-mci: conver... |
2131 2132 |
if (host->dma.chan) dma_release_channel(host->dma.chan); |
65e8b083f atmel-mci: Add ex... |
2133 |
#endif |
965ebf33e atmel-mci: suppor... |
2134 2135 |
free_irq(platform_get_irq(pdev, 0), host); iounmap(host->regs); |
7d2be0749 atmel-mci: Driver... |
2136 |
|
965ebf33e atmel-mci: suppor... |
2137 2138 |
clk_put(host->mck); kfree(host); |
7d2be0749 atmel-mci: Driver... |
2139 |
|
7d2be0749 atmel-mci: Driver... |
2140 2141 |
return 0; } |
5c2f2b9bd mmc: atmel-mci: a... |
2142 2143 2144 2145 2146 |
#ifdef CONFIG_PM static int atmci_suspend(struct device *dev) { struct atmel_mci *host = dev_get_drvdata(dev); int i; |
2c96a293b mmc: atmel-mci: c... |
2147 |
for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) { |
5c2f2b9bd mmc: atmel-mci: a... |
2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 |
struct atmel_mci_slot *slot = host->slot[i]; int ret; if (!slot) continue; ret = mmc_suspend_host(slot->mmc); if (ret < 0) { while (--i >= 0) { slot = host->slot[i]; if (slot && test_bit(ATMCI_SUSPENDED, &slot->flags)) { mmc_resume_host(host->slot[i]->mmc); clear_bit(ATMCI_SUSPENDED, &slot->flags); } } return ret; } else { set_bit(ATMCI_SUSPENDED, &slot->flags); } } return 0; } static int atmci_resume(struct device *dev) { struct atmel_mci *host = dev_get_drvdata(dev); int i; int ret = 0; |
2c96a293b mmc: atmel-mci: c... |
2177 |
for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) { |
5c2f2b9bd mmc: atmel-mci: a... |
2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 |
struct atmel_mci_slot *slot = host->slot[i]; int err; slot = host->slot[i]; if (!slot) continue; if (!test_bit(ATMCI_SUSPENDED, &slot->flags)) continue; err = mmc_resume_host(slot->mmc); if (err < 0) ret = err; else clear_bit(ATMCI_SUSPENDED, &slot->flags); } return ret; } static SIMPLE_DEV_PM_OPS(atmci_pm, atmci_suspend, atmci_resume); #define ATMCI_PM_OPS (&atmci_pm) #else #define ATMCI_PM_OPS NULL #endif |
7d2be0749 atmel-mci: Driver... |
2200 2201 2202 2203 |
static struct platform_driver atmci_driver = { .remove = __exit_p(atmci_remove), .driver = { .name = "atmel_mci", |
5c2f2b9bd mmc: atmel-mci: a... |
2204 |
.pm = ATMCI_PM_OPS, |
7d2be0749 atmel-mci: Driver... |
2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 |
}, }; static int __init atmci_init(void) { return platform_driver_probe(&atmci_driver, atmci_probe); } static void __exit atmci_exit(void) { platform_driver_unregister(&atmci_driver); } |
74465b4ff atmel-mci: conver... |
2217 |
late_initcall(atmci_init); /* try to load after dma driver when built-in */ |
7d2be0749 atmel-mci: Driver... |
2218 2219 2220 |
module_exit(atmci_exit); MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver"); |
e05503ef1 Haavard Skinnemoe... |
2221 |
MODULE_AUTHOR("Haavard Skinnemoen (Atmel)"); |
7d2be0749 atmel-mci: Driver... |
2222 |
MODULE_LICENSE("GPL v2"); |