1 Index: linux-2.6.21.7/drivers/mmc/at91_mci.c
2 ===================================================================
3 --- linux-2.6.21.7.orig/drivers/mmc/at91_mci.c
4 +++ linux-2.6.21.7/drivers/mmc/at91_mci.c
7 #define DRIVER_NAME "at91_mci"
10 +//#undef SUPPORT_4WIRE
11 +#define SUPPORT_4WIRE
13 #define FL_SENT_COMMAND (1 << 0)
14 #define FL_SENT_STOP (1 << 1)
15 @@ -132,7 +133,7 @@ struct at91mci_host
17 * Copy from sg to a dma block - used for transfers
19 -static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data)
20 +static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data)
22 unsigned int len, i, size;
23 unsigned *dmabuf = host->buffer;
24 @@ -181,7 +182,7 @@ static inline void at91mci_sg_to_dma(str
28 -static void at91mci_pre_dma_read(struct at91mci_host *host)
29 +static void at91_mci_pre_dma_read(struct at91mci_host *host)
32 struct scatterlist *sg;
33 @@ -249,23 +250,24 @@ static void at91mci_pre_dma_read(struct
35 * Handle after a dma read
37 -static void at91mci_post_dma_read(struct at91mci_host *host)
38 +static int at91_mci_post_dma_read(struct at91mci_host *host)
40 struct mmc_command *cmd;
41 struct mmc_data *data;
44 pr_debug("post dma read\n");
48 pr_debug("no command\n");
55 pr_debug("no data\n");
60 while (host->in_use_index < host->transfer_index) {
61 @@ -300,39 +302,14 @@ static void at91mci_post_dma_read(struct
63 /* Is there another transfer to trigger? */
64 if (host->transfer_index < data->sg_len)
65 - at91mci_pre_dma_read(host);
66 + at91_mci_pre_dma_read(host);
68 + at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_ENDRX);
69 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF);
70 - at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
73 pr_debug("post dma read done\n");
77 - * Handle transmitted data
79 -static void at91_mci_handle_transmitted(struct at91mci_host *host)
81 - struct mmc_command *cmd;
82 - struct mmc_data *data;
84 - pr_debug("Handling the transmit\n");
86 - /* Disable the transfer */
87 - at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
89 - /* Now wait for cmd ready */
90 - at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE);
91 - at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
99 - data->bytes_xfered = host->total_length;
104 @@ -340,10 +317,17 @@ static void at91_mci_handle_transmitted(
106 static void at91_mci_enable(struct at91mci_host *host)
110 at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
111 at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
112 at91_mci_write(host, AT91_MCI_DTOR, AT91_MCI_DTOMUL_1M | AT91_MCI_DTOCYC);
113 - at91_mci_write(host, AT91_MCI_MR, AT91_MCI_PDCMODE | 0x34a);
114 + mr = AT91_MCI_PDCMODE | 0x34a;
116 + if (cpu_is_at91sam9260() || cpu_is_at91sam9263())
117 + mr |= AT91_MCI_RDPROOF | AT91_MCI_WRPROOF;
119 + at91_mci_write(host, AT91_MCI_MR, mr);
121 /* use Slot A or B (only one at same time) */
122 at91_mci_write(host, AT91_MCI_SDCR, host->board->slot_b);
123 @@ -359,9 +343,8 @@ static void at91_mci_disable(struct at91
127 - * return the interrupts to enable
129 -static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_command *cmd)
130 +static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command *cmd)
132 unsigned int cmdr, mr;
133 unsigned int block_length;
134 @@ -372,8 +355,7 @@ static unsigned int at91_mci_send_comman
138 - /* Not sure if this is needed */
140 + /* Needed for leaving busy state before CMD1 */
141 if ((at91_mci_read(host, AT91_MCI_SR) & AT91_MCI_RTOE) && (cmd->opcode == 1)) {
142 pr_debug("Clearing timeout\n");
143 at91_mci_write(host, AT91_MCI_ARGR, 0);
144 @@ -383,7 +365,7 @@ static unsigned int at91_mci_send_comman
145 pr_debug("Clearing: SR = %08X\n", at91_mci_read(host, AT91_MCI_SR));
152 if (mmc_resp_type(cmd) == MMC_RSP_NONE)
153 @@ -440,50 +422,48 @@ static unsigned int at91_mci_send_comman
154 at91_mci_write(host, ATMEL_PDC_TCR, 0);
155 at91_mci_write(host, ATMEL_PDC_TNPR, 0);
156 at91_mci_write(host, ATMEL_PDC_TNCR, 0);
157 + ier = AT91_MCI_CMDRDY;
159 + /* zero block length in PDC mode */
160 + mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff;
161 + at91_mci_write(host, AT91_MCI_MR, mr | (block_length << 16) | AT91_MCI_PDCMODE);
164 + * Disable the PDC controller
166 + at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
168 - at91_mci_write(host, AT91_MCI_ARGR, cmd->arg);
169 - at91_mci_write(host, AT91_MCI_CMDR, cmdr);
170 - return AT91_MCI_CMDRDY;
173 - mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff; /* zero block length and PDC mode */
174 - at91_mci_write(host, AT91_MCI_MR, mr | (block_length << 16) | AT91_MCI_PDCMODE);
177 - * Disable the PDC controller
179 - at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
181 - if (cmdr & AT91_MCI_TRCMD_START) {
182 - data->bytes_xfered = 0;
183 - host->transfer_index = 0;
184 - host->in_use_index = 0;
185 - if (cmdr & AT91_MCI_TRDIR) {
189 - host->buffer = NULL;
190 - host->total_length = 0;
191 + if (cmdr & AT91_MCI_TRCMD_START) {
192 + data->bytes_xfered = 0;
193 + host->transfer_index = 0;
194 + host->in_use_index = 0;
195 + if (cmdr & AT91_MCI_TRDIR) {
199 + host->buffer = NULL;
200 + host->total_length = 0;
202 - at91mci_pre_dma_read(host);
203 - ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
209 - host->total_length = block_length * blocks;
210 - host->buffer = dma_alloc_coherent(NULL,
211 - host->total_length,
212 - &host->physical_address, GFP_KERNEL);
214 - at91mci_sg_to_dma(host, data);
216 - pr_debug("Transmitting %d bytes\n", host->total_length);
218 - at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
219 - at91_mci_write(host, ATMEL_PDC_TCR, host->total_length / 4);
220 - ier = AT91_MCI_TXBUFE;
221 + at91_mci_pre_dma_read(host);
222 + ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
228 + host->total_length = block_length * blocks;
229 + host->buffer = dma_alloc_coherent(NULL,
230 + host->total_length,
231 + &host->physical_address, GFP_KERNEL);
233 + at91_mci_sg_to_dma(host, data);
235 + pr_debug("Transmitting %d bytes\n", host->total_length);
237 + at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
238 + at91_mci_write(host, ATMEL_PDC_TCR, host->total_length / 4);
239 + ier = AT91_MCI_CMDRDY;
244 @@ -498,39 +478,24 @@ static unsigned int at91_mci_send_comman
245 if (cmdr & AT91_MCI_TRCMD_START) {
246 if (cmdr & AT91_MCI_TRDIR)
247 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN);
249 - at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
255 - * Wait for a command to complete
257 -static void at91mci_process_command(struct at91mci_host *host, struct mmc_command *cmd)
261 - ier = at91_mci_send_command(host, cmd);
263 - pr_debug("setting ier to %08X\n", ier);
265 - /* Stop on errors or the required value */
266 + /* Enable selected interrupts */
267 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_ERRORS | ier);
271 * Process the next step in the request
273 -static void at91mci_process_next(struct at91mci_host *host)
274 +static void at91_mci_process_next(struct at91mci_host *host)
276 if (!(host->flags & FL_SENT_COMMAND)) {
277 host->flags |= FL_SENT_COMMAND;
278 - at91mci_process_command(host, host->request->cmd);
279 + at91_mci_send_command(host, host->request->cmd);
281 else if ((!(host->flags & FL_SENT_STOP)) && host->request->stop) {
282 host->flags |= FL_SENT_STOP;
283 - at91mci_process_command(host, host->request->stop);
284 + at91_mci_send_command(host, host->request->stop);
287 mmc_request_done(host->mmc, host->request);
288 @@ -539,7 +504,7 @@ static void at91mci_process_next(struct
290 * Handle a command that has been completed
292 -static void at91mci_completed_command(struct at91mci_host *host)
293 +static void at91_mci_completed_command(struct at91mci_host *host)
295 struct mmc_command *cmd = host->cmd;
297 @@ -583,7 +548,7 @@ static void at91mci_completed_command(st
299 cmd->error = MMC_ERR_NONE;
301 - at91mci_process_next(host);
302 + at91_mci_process_next(host);
306 @@ -595,7 +560,60 @@ static void at91_mci_request(struct mmc_
310 - at91mci_process_next(host);
311 + at91_mci_process_next(host);
315 + * Handle transmitted data
317 +static void at91_mci_handle_transmitted(struct at91mci_host *host)
319 + struct mmc_command *cmd;
320 + struct mmc_data *data;
322 + pr_debug("Handling the transmit\n");
324 + /* Disable the transfer */
325 + at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
327 + /* Now wait for cmd ready */
328 + at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE);
336 + if (cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK) {
337 + pr_debug("multiple write : wait for BLKE...\n");
338 + at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE);
340 + at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
342 + data->bytes_xfered = host->total_length;
346 +/*Handle after command sent ready*/
347 +static int at91_mci_handle_cmdrdy(struct at91mci_host *host)
351 + else if (!host->cmd->data) {
352 + if (host->flags & FL_SENT_STOP) {
353 + /*After multi block write, we mus wait for NOTBUSY*/
354 + at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
356 + } else if (host->cmd->data->flags & MMC_DATA_WRITE) {
357 + /*After sending multi-block-write command, start DMA transfer*/
358 + at91_mci_write(host, AT91_MCI_IER, AT91_MCI_TXBUFE);
359 + at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE);
360 + at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
363 + /* command not completed, have to wait */
368 @@ -698,29 +716,33 @@ static irqreturn_t at91_mci_irq(int irq,
369 at91_mci_handle_transmitted(host);
372 + if (int_status & AT91_MCI_ENDRX) {
373 + pr_debug("ENDRX\n");
374 + at91_mci_post_dma_read(host);
377 if (int_status & AT91_MCI_RXBUFF) {
378 pr_debug("RX buffer full\n");
379 - at91_mci_write(host, AT91_MCI_IER, AT91_MCI_CMDRDY);
380 + at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
381 + at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_RXBUFF | AT91_MCI_ENDRX);
385 if (int_status & AT91_MCI_ENDTX)
386 pr_debug("Transmit has ended\n");
388 - if (int_status & AT91_MCI_ENDRX) {
389 - pr_debug("Receive has ended\n");
390 - at91mci_post_dma_read(host);
393 if (int_status & AT91_MCI_NOTBUSY) {
394 pr_debug("Card is ready\n");
395 - at91_mci_write(host, AT91_MCI_IER, AT91_MCI_CMDRDY);
399 if (int_status & AT91_MCI_DTIP)
400 pr_debug("Data transfer in progress\n");
402 - if (int_status & AT91_MCI_BLKE)
403 + if (int_status & AT91_MCI_BLKE) {
404 pr_debug("Block transfer has ended\n");
408 if (int_status & AT91_MCI_TXRDY)
409 pr_debug("Ready to transmit\n");
410 @@ -730,14 +752,14 @@ static irqreturn_t at91_mci_irq(int irq,
412 if (int_status & AT91_MCI_CMDRDY) {
413 pr_debug("Command ready\n");
415 + completed = at91_mci_handle_cmdrdy(host);
420 pr_debug("Completed command\n");
421 at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
422 - at91mci_completed_command(host);
423 + at91_mci_completed_command(host);
425 at91_mci_write(host, AT91_MCI_IDR, int_status);