aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/card/Kconfig12
-rw-r--r--drivers/mmc/card/Makefile1
-rw-r--r--drivers/mmc/card/block.c2
-rw-r--r--drivers/mmc/card/mmc_test.c892
-rw-r--r--drivers/mmc/host/Kconfig2
-rw-r--r--drivers/mmc/host/at91_mci.c5
-rw-r--r--drivers/mmc/host/omap.c12
-rw-r--r--drivers/mmc/host/pxamci.c13
-rw-r--r--drivers/mmc/host/sdhci.c34
-rw-r--r--drivers/mmc/host/wbsd.c21
10 files changed, 972 insertions, 22 deletions
diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
index aa8a4e461942..dd0f398ee2f5 100644
--- a/drivers/mmc/card/Kconfig
+++ b/drivers/mmc/card/Kconfig
@@ -39,3 +39,15 @@ config SDIO_UART
39 SDIO function driver for SDIO cards that implements the UART 39 SDIO function driver for SDIO cards that implements the UART
40 class, as well as the GPS class which appears like a UART. 40 class, as well as the GPS class which appears like a UART.
41 41
42config MMC_TEST
43 tristate "MMC host test driver"
44 default n
45 help
46 Development driver that performs a series of reads and writes
47 to a memory card in order to expose certain well known bugs
48 in host controllers. The tests are executed by writing to the
49 "test" file in sysfs under each card. Note that whatever is
50 on your card will be overwritten by these tests.
51
52 This driver is only of interest to those developing or
53 testing a host driver. Most people should say N here.
diff --git a/drivers/mmc/card/Makefile b/drivers/mmc/card/Makefile
index fc5a784cfa1a..0d407514f67d 100644
--- a/drivers/mmc/card/Makefile
+++ b/drivers/mmc/card/Makefile
@@ -8,6 +8,7 @@ endif
8 8
9obj-$(CONFIG_MMC_BLOCK) += mmc_block.o 9obj-$(CONFIG_MMC_BLOCK) += mmc_block.o
10mmc_block-objs := block.o queue.o 10mmc_block-objs := block.o queue.o
11obj-$(CONFIG_MMC_TEST) += mmc_test.o
11 12
12obj-$(CONFIG_SDIO_UART) += sdio_uart.o 13obj-$(CONFIG_SDIO_UART) += sdio_uart.o
13 14
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 91ded3e82401..f9ad960d7c1a 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -46,7 +46,7 @@
46#define MMC_SHIFT 3 46#define MMC_SHIFT 3
47#define MMC_NUM_MINORS (256 >> MMC_SHIFT) 47#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
48 48
49static unsigned long dev_use[MMC_NUM_MINORS/(8*sizeof(unsigned long))]; 49static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS);
50 50
51/* 51/*
52 * There is one mmc_blk_data per slot. 52 * There is one mmc_blk_data per slot.
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
new file mode 100644
index 000000000000..ffadee549a41
--- /dev/null
+++ b/drivers/mmc/card/mmc_test.c
@@ -0,0 +1,892 @@
1/*
2 * linux/drivers/mmc/card/mmc_test.c
3 *
4 * Copyright 2007 Pierre Ossman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 */
11
12#include <linux/mmc/core.h>
13#include <linux/mmc/card.h>
14#include <linux/mmc/host.h>
15#include <linux/mmc/mmc.h>
16
17#include <linux/scatterlist.h>
18
19#define RESULT_OK 0
20#define RESULT_FAIL 1
21#define RESULT_UNSUP_HOST 2
22#define RESULT_UNSUP_CARD 3
23
24#define BUFFER_SIZE (PAGE_SIZE * 4)
25
26struct mmc_test_card {
27 struct mmc_card *card;
28
29 u8 *buffer;
30};
31
32/*******************************************************************/
33/* Helper functions */
34/*******************************************************************/
35
36static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size)
37{
38 struct mmc_command cmd;
39 int ret;
40
41 cmd.opcode = MMC_SET_BLOCKLEN;
42 cmd.arg = size;
43 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
44 ret = mmc_wait_for_cmd(test->card->host, &cmd, 0);
45 if (ret)
46 return ret;
47
48 return 0;
49}
50
51static int __mmc_test_transfer(struct mmc_test_card *test, int write,
52 unsigned broken_xfer, u8 *buffer, unsigned addr,
53 unsigned blocks, unsigned blksz)
54{
55 int ret, busy;
56
57 struct mmc_request mrq;
58 struct mmc_command cmd;
59 struct mmc_command stop;
60 struct mmc_data data;
61
62 struct scatterlist sg;
63
64 memset(&mrq, 0, sizeof(struct mmc_request));
65
66 mrq.cmd = &cmd;
67 mrq.data = &data;
68
69 memset(&cmd, 0, sizeof(struct mmc_command));
70
71 if (broken_xfer) {
72 if (blocks > 1) {
73 cmd.opcode = write ?
74 MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
75 } else {
76 cmd.opcode = MMC_SEND_STATUS;
77 }
78 } else {
79 if (blocks > 1) {
80 cmd.opcode = write ?
81 MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK;
82 } else {
83 cmd.opcode = write ?
84 MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
85 }
86 }
87
88 if (broken_xfer && blocks == 1)
89 cmd.arg = test->card->rca << 16;
90 else
91 cmd.arg = addr;
92 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
93
94 memset(&stop, 0, sizeof(struct mmc_command));
95
96 if (!broken_xfer && (blocks > 1)) {
97 stop.opcode = MMC_STOP_TRANSMISSION;
98 stop.arg = 0;
99 stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
100
101 mrq.stop = &stop;
102 }
103
104 memset(&data, 0, sizeof(struct mmc_data));
105
106 data.blksz = blksz;
107 data.blocks = blocks;
108 data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
109 data.sg = &sg;
110 data.sg_len = 1;
111
112 sg_init_one(&sg, buffer, blocks * blksz);
113
114 mmc_set_data_timeout(&data, test->card);
115
116 mmc_wait_for_req(test->card->host, &mrq);
117
118 ret = 0;
119
120 if (broken_xfer) {
121 if (!ret && cmd.error)
122 ret = cmd.error;
123 if (!ret && data.error == 0)
124 ret = RESULT_FAIL;
125 if (!ret && data.error != -ETIMEDOUT)
126 ret = data.error;
127 if (!ret && stop.error)
128 ret = stop.error;
129 if (blocks > 1) {
130 if (!ret && data.bytes_xfered > blksz)
131 ret = RESULT_FAIL;
132 } else {
133 if (!ret && data.bytes_xfered > 0)
134 ret = RESULT_FAIL;
135 }
136 } else {
137 if (!ret && cmd.error)
138 ret = cmd.error;
139 if (!ret && data.error)
140 ret = data.error;
141 if (!ret && stop.error)
142 ret = stop.error;
143 if (!ret && data.bytes_xfered != blocks * blksz)
144 ret = RESULT_FAIL;
145 }
146
147 if (ret == -EINVAL)
148 ret = RESULT_UNSUP_HOST;
149
150 busy = 0;
151 do {
152 int ret2;
153
154 memset(&cmd, 0, sizeof(struct mmc_command));
155
156 cmd.opcode = MMC_SEND_STATUS;
157 cmd.arg = test->card->rca << 16;
158 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
159
160 ret2 = mmc_wait_for_cmd(test->card->host, &cmd, 0);
161 if (ret2)
162 break;
163
164 if (!busy && !(cmd.resp[0] & R1_READY_FOR_DATA)) {
165 busy = 1;
166 printk(KERN_INFO "%s: Warning: Host did not "
167 "wait for busy state to end.\n",
168 mmc_hostname(test->card->host));
169 }
170 } while (!(cmd.resp[0] & R1_READY_FOR_DATA));
171
172 return ret;
173}
174
175static int mmc_test_transfer(struct mmc_test_card *test, int write,
176 u8 *buffer, unsigned addr, unsigned blocks, unsigned blksz)
177{
178 return __mmc_test_transfer(test, write, 0, buffer,
179 addr, blocks, blksz);
180}
181
182static int mmc_test_prepare_verify(struct mmc_test_card *test, int write)
183{
184 int ret, i;
185
186 ret = mmc_test_set_blksize(test, 512);
187 if (ret)
188 return ret;
189
190 if (write)
191 memset(test->buffer, 0xDF, BUFFER_SIZE);
192 else {
193 for (i = 0;i < BUFFER_SIZE;i++)
194 test->buffer[i] = i;
195 }
196
197 for (i = 0;i < BUFFER_SIZE / 512;i++) {
198 ret = mmc_test_transfer(test, 1, test->buffer + i * 512,
199 i * 512, 1, 512);
200 if (ret)
201 return ret;
202 }
203
204 return 0;
205}
206
207static int mmc_test_prepare_verify_write(struct mmc_test_card *test)
208{
209 return mmc_test_prepare_verify(test, 1);
210}
211
212static int mmc_test_prepare_verify_read(struct mmc_test_card *test)
213{
214 return mmc_test_prepare_verify(test, 0);
215}
216
217static int mmc_test_verified_transfer(struct mmc_test_card *test, int write,
218 u8 *buffer, unsigned addr, unsigned blocks, unsigned blksz)
219{
220 int ret, i, sectors;
221
222 /*
223 * It is assumed that the above preparation has been done.
224 */
225
226 memset(test->buffer, 0, BUFFER_SIZE);
227
228 if (write) {
229 for (i = 0;i < blocks * blksz;i++)
230 buffer[i] = i;
231 }
232
233 ret = mmc_test_set_blksize(test, blksz);
234 if (ret)
235 return ret;
236
237 ret = mmc_test_transfer(test, write, buffer, addr, blocks, blksz);
238 if (ret)
239 return ret;
240
241 if (write) {
242 ret = mmc_test_set_blksize(test, 512);
243 if (ret)
244 return ret;
245
246 sectors = (blocks * blksz + 511) / 512;
247 if ((sectors * 512) == (blocks * blksz))
248 sectors++;
249
250 if ((sectors * 512) > BUFFER_SIZE)
251 return -EINVAL;
252
253 memset(test->buffer, 0, sectors * 512);
254
255 for (i = 0;i < sectors;i++) {
256 ret = mmc_test_transfer(test, 0,
257 test->buffer + i * 512,
258 addr + i * 512, 1, 512);
259 if (ret)
260 return ret;
261 }
262
263 for (i = 0;i < blocks * blksz;i++) {
264 if (test->buffer[i] != (u8)i)
265 return RESULT_FAIL;
266 }
267
268 for (;i < sectors * 512;i++) {
269 if (test->buffer[i] != 0xDF)
270 return RESULT_FAIL;
271 }
272 } else {
273 for (i = 0;i < blocks * blksz;i++) {
274 if (buffer[i] != (u8)i)
275 return RESULT_FAIL;
276 }
277 }
278
279 return 0;
280}
281
282static int mmc_test_cleanup_verify(struct mmc_test_card *test)
283{
284 int ret, i;
285
286 ret = mmc_test_set_blksize(test, 512);
287 if (ret)
288 return ret;
289
290 memset(test->buffer, 0, BUFFER_SIZE);
291
292 for (i = 0;i < BUFFER_SIZE / 512;i++) {
293 ret = mmc_test_transfer(test, 1, test->buffer + i * 512,
294 i * 512, 1, 512);
295 if (ret)
296 return ret;
297 }
298
299 return 0;
300}
301
302/*******************************************************************/
303/* Tests */
304/*******************************************************************/
305
306struct mmc_test_case {
307 const char *name;
308
309 int (*prepare)(struct mmc_test_card *);
310 int (*run)(struct mmc_test_card *);
311 int (*cleanup)(struct mmc_test_card *);
312};
313
314static int mmc_test_basic_write(struct mmc_test_card *test)
315{
316 int ret;
317
318 ret = mmc_test_set_blksize(test, 512);
319 if (ret)
320 return ret;
321
322 ret = mmc_test_transfer(test, 1, test->buffer, 0, 1, 512);
323 if (ret)
324 return ret;
325
326 return 0;
327}
328
329static int mmc_test_basic_read(struct mmc_test_card *test)
330{
331 int ret;
332
333 ret = mmc_test_set_blksize(test, 512);
334 if (ret)
335 return ret;
336
337 ret = mmc_test_transfer(test, 0, test->buffer, 0, 1, 512);
338 if (ret)
339 return ret;
340
341 return 0;
342}
343
344static int mmc_test_verify_write(struct mmc_test_card *test)
345{
346 int ret;
347
348 ret = mmc_test_verified_transfer(test, 1, test->buffer, 0, 1, 512);
349 if (ret)
350 return ret;
351
352 return 0;
353}
354
355static int mmc_test_verify_read(struct mmc_test_card *test)
356{
357 int ret;
358
359 ret = mmc_test_verified_transfer(test, 0, test->buffer, 0, 1, 512);
360 if (ret)
361 return ret;
362
363 return 0;
364}
365
366static int mmc_test_multi_write(struct mmc_test_card *test)
367{
368 int ret;
369 unsigned int size;
370
371 if (test->card->host->max_blk_count == 1)
372 return RESULT_UNSUP_HOST;
373
374 size = PAGE_SIZE * 2;
375 size = min(size, test->card->host->max_req_size);
376 size = min(size, test->card->host->max_seg_size);
377 size = min(size, test->card->host->max_blk_count * 512);
378
379 if (size < 1024)
380 return RESULT_UNSUP_HOST;
381
382 ret = mmc_test_verified_transfer(test, 1, test->buffer, 0,
383 size / 512, 512);
384 if (ret)
385 return ret;
386
387 return 0;
388}
389
390static int mmc_test_multi_read(struct mmc_test_card *test)
391{
392 int ret;
393 unsigned int size;
394
395 if (test->card->host->max_blk_count == 1)
396 return RESULT_UNSUP_HOST;
397
398 size = PAGE_SIZE * 2;
399 size = min(size, test->card->host->max_req_size);
400 size = min(size, test->card->host->max_seg_size);
401 size = min(size, test->card->host->max_blk_count * 512);
402
403 if (size < 1024)
404 return RESULT_UNSUP_HOST;
405
406 ret = mmc_test_verified_transfer(test, 0, test->buffer, 0,
407 size / 512, 512);
408 if (ret)
409 return ret;
410
411 return 0;
412}
413
414static int mmc_test_pow2_write(struct mmc_test_card *test)
415{
416 int ret, i;
417
418 if (!test->card->csd.write_partial)
419 return RESULT_UNSUP_CARD;
420
421 for (i = 1; i < 512;i <<= 1) {
422 ret = mmc_test_verified_transfer(test, 1,
423 test->buffer, 0, 1, i);
424 if (ret)
425 return ret;
426 }
427
428 return 0;
429}
430
431static int mmc_test_pow2_read(struct mmc_test_card *test)
432{
433 int ret, i;
434
435 if (!test->card->csd.read_partial)
436 return RESULT_UNSUP_CARD;
437
438 for (i = 1; i < 512;i <<= 1) {
439 ret = mmc_test_verified_transfer(test, 0,
440 test->buffer, 0, 1, i);
441 if (ret)
442 return ret;
443 }
444
445 return 0;
446}
447
448static int mmc_test_weird_write(struct mmc_test_card *test)
449{
450 int ret, i;
451
452 if (!test->card->csd.write_partial)
453 return RESULT_UNSUP_CARD;
454
455 for (i = 3; i < 512;i += 7) {
456 ret = mmc_test_verified_transfer(test, 1,
457 test->buffer, 0, 1, i);
458 if (ret)
459 return ret;
460 }
461
462 return 0;
463}
464
465static int mmc_test_weird_read(struct mmc_test_card *test)
466{
467 int ret, i;
468
469 if (!test->card->csd.read_partial)
470 return RESULT_UNSUP_CARD;
471
472 for (i = 3; i < 512;i += 7) {
473 ret = mmc_test_verified_transfer(test, 0,
474 test->buffer, 0, 1, i);
475 if (ret)
476 return ret;
477 }
478
479 return 0;
480}
481
482static int mmc_test_align_write(struct mmc_test_card *test)
483{
484 int ret, i;
485
486 for (i = 1;i < 4;i++) {
487 ret = mmc_test_verified_transfer(test, 1, test->buffer + i,
488 0, 1, 512);
489 if (ret)
490 return ret;
491 }
492
493 return 0;
494}
495
496static int mmc_test_align_read(struct mmc_test_card *test)
497{
498 int ret, i;
499
500 for (i = 1;i < 4;i++) {
501 ret = mmc_test_verified_transfer(test, 0, test->buffer + i,
502 0, 1, 512);
503 if (ret)
504 return ret;
505 }
506
507 return 0;
508}
509
510static int mmc_test_align_multi_write(struct mmc_test_card *test)
511{
512 int ret, i;
513 unsigned int size;
514
515 if (test->card->host->max_blk_count == 1)
516 return RESULT_UNSUP_HOST;
517
518 size = PAGE_SIZE * 2;
519 size = min(size, test->card->host->max_req_size);
520 size = min(size, test->card->host->max_seg_size);
521 size = min(size, test->card->host->max_blk_count * 512);
522
523 if (size < 1024)
524 return RESULT_UNSUP_HOST;
525
526 for (i = 1;i < 4;i++) {
527 ret = mmc_test_verified_transfer(test, 1, test->buffer + i,
528 0, size / 512, 512);
529 if (ret)
530 return ret;
531 }
532
533 return 0;
534}
535
536static int mmc_test_align_multi_read(struct mmc_test_card *test)
537{
538 int ret, i;
539 unsigned int size;
540
541 if (test->card->host->max_blk_count == 1)
542 return RESULT_UNSUP_HOST;
543
544 size = PAGE_SIZE * 2;
545 size = min(size, test->card->host->max_req_size);
546 size = min(size, test->card->host->max_seg_size);
547 size = min(size, test->card->host->max_blk_count * 512);
548
549 if (size < 1024)
550 return RESULT_UNSUP_HOST;
551
552 for (i = 1;i < 4;i++) {
553 ret = mmc_test_verified_transfer(test, 0, test->buffer + i,
554 0, size / 512, 512);
555 if (ret)
556 return ret;
557 }
558
559 return 0;
560}
561
562static int mmc_test_xfersize_write(struct mmc_test_card *test)
563{
564 int ret;
565
566 ret = mmc_test_set_blksize(test, 512);
567 if (ret)
568 return ret;
569
570 ret = __mmc_test_transfer(test, 1, 1, test->buffer, 0, 1, 512);
571 if (ret)
572 return ret;
573
574 return 0;
575}
576
577static int mmc_test_xfersize_read(struct mmc_test_card *test)
578{
579 int ret;
580
581 ret = mmc_test_set_blksize(test, 512);
582 if (ret)
583 return ret;
584
585 ret = __mmc_test_transfer(test, 0, 1, test->buffer, 0, 1, 512);
586 if (ret)
587 return ret;
588
589 return 0;
590}
591
592static int mmc_test_multi_xfersize_write(struct mmc_test_card *test)
593{
594 int ret;
595
596 if (test->card->host->max_blk_count == 1)
597 return RESULT_UNSUP_HOST;
598
599 ret = mmc_test_set_blksize(test, 512);
600 if (ret)
601 return ret;
602
603 ret = __mmc_test_transfer(test, 1, 1, test->buffer, 0, 2, 512);
604 if (ret)
605 return ret;
606
607 return 0;
608}
609
610static int mmc_test_multi_xfersize_read(struct mmc_test_card *test)
611{
612 int ret;
613
614 if (test->card->host->max_blk_count == 1)
615 return RESULT_UNSUP_HOST;
616
617 ret = mmc_test_set_blksize(test, 512);
618 if (ret)
619 return ret;
620
621 ret = __mmc_test_transfer(test, 0, 1, test->buffer, 0, 2, 512);
622 if (ret)
623 return ret;
624
625 return 0;
626}
627
628static const struct mmc_test_case mmc_test_cases[] = {
629 {
630 .name = "Basic write (no data verification)",
631 .run = mmc_test_basic_write,
632 },
633
634 {
635 .name = "Basic read (no data verification)",
636 .run = mmc_test_basic_read,
637 },
638
639 {
640 .name = "Basic write (with data verification)",
641 .prepare = mmc_test_prepare_verify_write,
642 .run = mmc_test_verify_write,
643 .cleanup = mmc_test_cleanup_verify,
644 },
645
646 {
647 .name = "Basic read (with data verification)",
648 .prepare = mmc_test_prepare_verify_read,
649 .run = mmc_test_verify_read,
650 .cleanup = mmc_test_cleanup_verify,
651 },
652
653 {
654 .name = "Multi-block write",
655 .prepare = mmc_test_prepare_verify_write,
656 .run = mmc_test_multi_write,
657 .cleanup = mmc_test_cleanup_verify,
658 },
659
660 {
661 .name = "Multi-block read",
662 .prepare = mmc_test_prepare_verify_read,
663 .run = mmc_test_multi_read,
664 .cleanup = mmc_test_cleanup_verify,
665 },
666
667 {
668 .name = "Power of two block writes",
669 .prepare = mmc_test_prepare_verify_write,
670 .run = mmc_test_pow2_write,
671 .cleanup = mmc_test_cleanup_verify,
672 },
673
674 {
675 .name = "Power of two block reads",
676 .prepare = mmc_test_prepare_verify_read,
677 .run = mmc_test_pow2_read,
678 .cleanup = mmc_test_cleanup_verify,
679 },
680
681 {
682 .name = "Weird sized block writes",
683 .prepare = mmc_test_prepare_verify_write,
684 .run = mmc_test_weird_write,
685 .cleanup = mmc_test_cleanup_verify,
686 },
687
688 {
689 .name = "Weird sized block reads",
690 .prepare = mmc_test_prepare_verify_read,
691 .run = mmc_test_weird_read,
692 .cleanup = mmc_test_cleanup_verify,
693 },
694
695 {
696 .name = "Badly aligned write",
697 .prepare = mmc_test_prepare_verify_write,
698 .run = mmc_test_align_write,
699 .cleanup = mmc_test_cleanup_verify,
700 },
701
702 {
703 .name = "Badly aligned read",
704 .prepare = mmc_test_prepare_verify_read,
705 .run = mmc_test_align_read,
706 .cleanup = mmc_test_cleanup_verify,
707 },
708
709 {
710 .name = "Badly aligned multi-block write",
711 .prepare = mmc_test_prepare_verify_write,
712 .run = mmc_test_align_multi_write,
713 .cleanup = mmc_test_cleanup_verify,
714 },
715
716 {
717 .name = "Badly aligned multi-block read",
718 .prepare = mmc_test_prepare_verify_read,
719 .run = mmc_test_align_multi_read,
720 .cleanup = mmc_test_cleanup_verify,
721 },
722
723 {
724 .name = "Correct xfer_size at write (start failure)",
725 .run = mmc_test_xfersize_write,
726 },
727
728 {
729 .name = "Correct xfer_size at read (start failure)",
730 .run = mmc_test_xfersize_read,
731 },
732
733 {
734 .name = "Correct xfer_size at write (midway failure)",
735 .run = mmc_test_multi_xfersize_write,
736 },
737
738 {
739 .name = "Correct xfer_size at read (midway failure)",
740 .run = mmc_test_multi_xfersize_read,
741 },
742};
743
744static struct mutex mmc_test_lock;
745
746static void mmc_test_run(struct mmc_test_card *test)
747{
748 int i, ret;
749
750 printk(KERN_INFO "%s: Starting tests of card %s...\n",
751 mmc_hostname(test->card->host), mmc_card_id(test->card));
752
753 mmc_claim_host(test->card->host);
754
755 for (i = 0;i < ARRAY_SIZE(mmc_test_cases);i++) {
756 printk(KERN_INFO "%s: Test case %d. %s...\n",
757 mmc_hostname(test->card->host), i + 1,
758 mmc_test_cases[i].name);
759
760 if (mmc_test_cases[i].prepare) {
761 ret = mmc_test_cases[i].prepare(test);
762 if (ret) {
763 printk(KERN_INFO "%s: Result: Prepare "
764 "stage failed! (%d)\n",
765 mmc_hostname(test->card->host),
766 ret);
767 continue;
768 }
769 }
770
771 ret = mmc_test_cases[i].run(test);
772 switch (ret) {
773 case RESULT_OK:
774 printk(KERN_INFO "%s: Result: OK\n",
775 mmc_hostname(test->card->host));
776 break;
777 case RESULT_FAIL:
778 printk(KERN_INFO "%s: Result: FAILED\n",
779 mmc_hostname(test->card->host));
780 break;
781 case RESULT_UNSUP_HOST:
782 printk(KERN_INFO "%s: Result: UNSUPPORTED "
783 "(by host)\n",
784 mmc_hostname(test->card->host));
785 break;
786 case RESULT_UNSUP_CARD:
787 printk(KERN_INFO "%s: Result: UNSUPPORTED "
788 "(by card)\n",
789 mmc_hostname(test->card->host));
790 break;
791 default:
792 printk(KERN_INFO "%s: Result: ERROR (%d)\n",
793 mmc_hostname(test->card->host), ret);
794 }
795
796 if (mmc_test_cases[i].cleanup) {
797 ret = mmc_test_cases[i].cleanup(test);
798 if (ret) {
799 printk(KERN_INFO "%s: Warning: Cleanup "
800 "stage failed! (%d)\n",
801 mmc_hostname(test->card->host),
802 ret);
803 }
804 }
805 }
806
807 mmc_release_host(test->card->host);
808
809 printk(KERN_INFO "%s: Tests completed.\n",
810 mmc_hostname(test->card->host));
811}
812
813static ssize_t mmc_test_show(struct device *dev,
814 struct device_attribute *attr, char *buf)
815{
816 mutex_lock(&mmc_test_lock);
817 mutex_unlock(&mmc_test_lock);
818
819 return 0;
820}
821
822static ssize_t mmc_test_store(struct device *dev,
823 struct device_attribute *attr, const char *buf, size_t count)
824{
825 struct mmc_card *card;
826 struct mmc_test_card *test;
827
828 card = container_of(dev, struct mmc_card, dev);
829
830 test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL);
831 if (!test)
832 return -ENOMEM;
833
834 test->card = card;
835
836 test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL);
837 if (test->buffer) {
838 mutex_lock(&mmc_test_lock);
839 mmc_test_run(test);
840 mutex_unlock(&mmc_test_lock);
841 }
842
843 kfree(test->buffer);
844 kfree(test);
845
846 return count;
847}
848
849static DEVICE_ATTR(test, S_IWUSR | S_IRUGO, mmc_test_show, mmc_test_store);
850
851static int mmc_test_probe(struct mmc_card *card)
852{
853 int ret;
854
855 mutex_init(&mmc_test_lock);
856
857 ret = device_create_file(&card->dev, &dev_attr_test);
858 if (ret)
859 return ret;
860
861 return 0;
862}
863
864static void mmc_test_remove(struct mmc_card *card)
865{
866 device_remove_file(&card->dev, &dev_attr_test);
867}
868
869static struct mmc_driver mmc_driver = {
870 .drv = {
871 .name = "mmc_test",
872 },
873 .probe = mmc_test_probe,
874 .remove = mmc_test_remove,
875};
876
877static int __init mmc_test_init(void)
878{
879 return mmc_register_driver(&mmc_driver);
880}
881
882static void __exit mmc_test_exit(void)
883{
884 mmc_unregister_driver(&mmc_driver);
885}
886
887module_init(mmc_test_init);
888module_exit(mmc_test_exit);
889
890MODULE_LICENSE("GPL");
891MODULE_DESCRIPTION("Multimedia Card (MMC) host test driver");
892MODULE_AUTHOR("Pierre Ossman");
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 3b3cd0e74715..dead61754ad7 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -119,7 +119,7 @@ config MMC_TIFM_SD
119 119
120config MMC_SPI 120config MMC_SPI
121 tristate "MMC/SD over SPI" 121 tristate "MMC/SD over SPI"
122 depends on MMC && SPI_MASTER && !HIGHMEM 122 depends on MMC && SPI_MASTER && !HIGHMEM && HAS_DMA
123 select CRC7 123 select CRC7
124 select CRC_ITU_T 124 select CRC_ITU_T
125 help 125 help
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
index a28fc2f68ce2..8979ad330a4d 100644
--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -663,9 +663,12 @@ static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
663 gpio_set_value(host->board->vcc_pin, 0); 663 gpio_set_value(host->board->vcc_pin, 0);
664 break; 664 break;
665 case MMC_POWER_UP: 665 case MMC_POWER_UP:
666 case MMC_POWER_ON:
667 gpio_set_value(host->board->vcc_pin, 1); 666 gpio_set_value(host->board->vcc_pin, 1);
668 break; 667 break;
668 case MMC_POWER_ON:
669 break;
670 default:
671 WARN_ON(1);
669 } 672 }
670 } 673 }
671} 674}
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 14759e9f42ad..549517c35675 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -1003,7 +1003,7 @@ static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data)
1003 1003
1004static int mmc_omap_get_dma_channel(struct mmc_omap_host *host, struct mmc_data *data) 1004static int mmc_omap_get_dma_channel(struct mmc_omap_host *host, struct mmc_data *data)
1005{ 1005{
1006 const char *dev_name; 1006 const char *dma_dev_name;
1007 int sync_dev, dma_ch, is_read, r; 1007 int sync_dev, dma_ch, is_read, r;
1008 1008
1009 is_read = !(data->flags & MMC_DATA_WRITE); 1009 is_read = !(data->flags & MMC_DATA_WRITE);
@@ -1018,21 +1018,21 @@ static int mmc_omap_get_dma_channel(struct mmc_omap_host *host, struct mmc_data
1018 if (is_read) { 1018 if (is_read) {
1019 if (host->id == 1) { 1019 if (host->id == 1) {
1020 sync_dev = OMAP_DMA_MMC_RX; 1020 sync_dev = OMAP_DMA_MMC_RX;
1021 dev_name = "MMC1 read"; 1021 dma_dev_name = "MMC1 read";
1022 } else { 1022 } else {
1023 sync_dev = OMAP_DMA_MMC2_RX; 1023 sync_dev = OMAP_DMA_MMC2_RX;
1024 dev_name = "MMC2 read"; 1024 dma_dev_name = "MMC2 read";
1025 } 1025 }
1026 } else { 1026 } else {
1027 if (host->id == 1) { 1027 if (host->id == 1) {
1028 sync_dev = OMAP_DMA_MMC_TX; 1028 sync_dev = OMAP_DMA_MMC_TX;
1029 dev_name = "MMC1 write"; 1029 dma_dev_name = "MMC1 write";
1030 } else { 1030 } else {
1031 sync_dev = OMAP_DMA_MMC2_TX; 1031 sync_dev = OMAP_DMA_MMC2_TX;
1032 dev_name = "MMC2 write"; 1032 dma_dev_name = "MMC2 write";
1033 } 1033 }
1034 } 1034 }
1035 r = omap_request_dma(sync_dev, dev_name, mmc_omap_dma_cb, 1035 r = omap_request_dma(sync_dev, dma_dev_name, mmc_omap_dma_cb,
1036 host, &dma_ch); 1036 host, &dma_ch);
1037 if (r != 0) { 1037 if (r != 0) {
1038 dev_dbg(mmc_dev(host->mmc), "omap_request_dma() failed with %d\n", r); 1038 dev_dbg(mmc_dev(host->mmc), "omap_request_dma() failed with %d\n", r);
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index 65210fca37ed..d89475d36988 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -114,6 +114,7 @@ static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
114 unsigned int nob = data->blocks; 114 unsigned int nob = data->blocks;
115 unsigned long long clks; 115 unsigned long long clks;
116 unsigned int timeout; 116 unsigned int timeout;
117 bool dalgn = 0;
117 u32 dcmd; 118 u32 dcmd;
118 int i; 119 int i;
119 120
@@ -152,6 +153,9 @@ static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
152 host->sg_cpu[i].dcmd = dcmd | length; 153 host->sg_cpu[i].dcmd = dcmd | length;
153 if (length & 31 && !(data->flags & MMC_DATA_READ)) 154 if (length & 31 && !(data->flags & MMC_DATA_READ))
154 host->sg_cpu[i].dcmd |= DCMD_ENDIRQEN; 155 host->sg_cpu[i].dcmd |= DCMD_ENDIRQEN;
156 /* Not aligned to 8-byte boundary? */
157 if (sg_dma_address(&data->sg[i]) & 0x7)
158 dalgn = 1;
155 if (data->flags & MMC_DATA_READ) { 159 if (data->flags & MMC_DATA_READ) {
156 host->sg_cpu[i].dsadr = host->res->start + MMC_RXFIFO; 160 host->sg_cpu[i].dsadr = host->res->start + MMC_RXFIFO;
157 host->sg_cpu[i].dtadr = sg_dma_address(&data->sg[i]); 161 host->sg_cpu[i].dtadr = sg_dma_address(&data->sg[i]);
@@ -165,6 +169,15 @@ static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
165 host->sg_cpu[host->dma_len - 1].ddadr = DDADR_STOP; 169 host->sg_cpu[host->dma_len - 1].ddadr = DDADR_STOP;
166 wmb(); 170 wmb();
167 171
172 /*
173 * The PXA27x DMA controller encounters overhead when working with
174 * unaligned (to 8-byte boundaries) data, so switch on byte alignment
175 * mode only if we have unaligned data.
176 */
177 if (dalgn)
178 DALGN |= (1 << host->dma);
179 else
180 DALGN &= (1 << host->dma);
168 DDADR(host->dma) = host->sg_dma; 181 DDADR(host->dma) = host->sg_dma;
169 DCSR(host->dma) = DCSR_RUN; 182 DCSR(host->dma) = DCSR_RUN;
170} 183}
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 07c2048b230b..b413aa6c246b 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -55,6 +55,10 @@ static unsigned int debug_quirks = 0;
55#define SDHCI_QUIRK_32BIT_DMA_SIZE (1<<7) 55#define SDHCI_QUIRK_32BIT_DMA_SIZE (1<<7)
56/* Controller needs to be reset after each request to stay stable */ 56/* Controller needs to be reset after each request to stay stable */
57#define SDHCI_QUIRK_RESET_AFTER_REQUEST (1<<8) 57#define SDHCI_QUIRK_RESET_AFTER_REQUEST (1<<8)
58/* Controller needs voltage and power writes to happen separately */
59#define SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER (1<<9)
60/* Controller has an off-by-one issue with timeout value */
61#define SDHCI_QUIRK_INCR_TIMEOUT_CONTROL (1<<10)
58 62
59static const struct pci_device_id pci_ids[] __devinitdata = { 63static const struct pci_device_id pci_ids[] __devinitdata = {
60 { 64 {
@@ -115,7 +119,8 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
115 .subvendor = PCI_ANY_ID, 119 .subvendor = PCI_ANY_ID,
116 .subdevice = PCI_ANY_ID, 120 .subdevice = PCI_ANY_ID,
117 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE | 121 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
118 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS, 122 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
123 SDHCI_QUIRK_BROKEN_DMA,
119 }, 124 },
120 125
121 { 126 {
@@ -124,7 +129,17 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
124 .subvendor = PCI_ANY_ID, 129 .subvendor = PCI_ANY_ID,
125 .subdevice = PCI_ANY_ID, 130 .subdevice = PCI_ANY_ID,
126 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE | 131 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
127 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS, 132 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
133 SDHCI_QUIRK_BROKEN_DMA,
134 },
135
136 {
137 .vendor = PCI_VENDOR_ID_MARVELL,
138 .device = PCI_DEVICE_ID_MARVELL_CAFE_SD,
139 .subvendor = PCI_ANY_ID,
140 .subdevice = PCI_ANY_ID,
141 .driver_data = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
142 SDHCI_QUIRK_INCR_TIMEOUT_CONTROL,
128 }, 143 },
129 144
130 { 145 {
@@ -469,6 +484,13 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
469 break; 484 break;
470 } 485 }
471 486
487 /*
488 * Compensate for an off-by-one error in the CaFe hardware; otherwise,
489 * a too-small count gives us interrupt timeouts.
490 */
491 if ((host->chip->quirks & SDHCI_QUIRK_INCR_TIMEOUT_CONTROL))
492 count++;
493
472 if (count >= 0xF) { 494 if (count >= 0xF) {
473 printk(KERN_WARNING "%s: Too large timeout requested!\n", 495 printk(KERN_WARNING "%s: Too large timeout requested!\n",
474 mmc_hostname(host->mmc)); 496 mmc_hostname(host->mmc));
@@ -774,6 +796,14 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
774 BUG(); 796 BUG();
775 } 797 }
776 798
799 /*
800 * At least the CaFe chip gets confused if we set the voltage
801 * and set turn on power at the same time, so set the voltage first.
802 */
803 if ((host->chip->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER))
804 writeb(pwr & ~SDHCI_POWER_ON,
805 host->ioaddr + SDHCI_POWER_CONTROL);
806
777 writeb(pwr, host->ioaddr + SDHCI_POWER_CONTROL); 807 writeb(pwr, host->ioaddr + SDHCI_POWER_CONTROL);
778 808
779out: 809out:
diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
index be624a049c67..c303e7f57ab4 100644
--- a/drivers/mmc/host/wbsd.c
+++ b/drivers/mmc/host/wbsd.c
@@ -1457,17 +1457,7 @@ static int __devinit wbsd_request_irq(struct wbsd_host *host, int irq)
1457 int ret; 1457 int ret;
1458 1458
1459 /* 1459 /*
1460 * Allocate interrupt. 1460 * Set up tasklets. Must be done before requesting interrupt.
1461 */
1462
1463 ret = request_irq(irq, wbsd_irq, IRQF_SHARED, DRIVER_NAME, host);
1464 if (ret)
1465 return ret;
1466
1467 host->irq = irq;
1468
1469 /*
1470 * Set up tasklets.
1471 */ 1461 */
1472 tasklet_init(&host->card_tasklet, wbsd_tasklet_card, 1462 tasklet_init(&host->card_tasklet, wbsd_tasklet_card,
1473 (unsigned long)host); 1463 (unsigned long)host);
@@ -1480,6 +1470,15 @@ static int __devinit wbsd_request_irq(struct wbsd_host *host, int irq)
1480 tasklet_init(&host->finish_tasklet, wbsd_tasklet_finish, 1470 tasklet_init(&host->finish_tasklet, wbsd_tasklet_finish,
1481 (unsigned long)host); 1471 (unsigned long)host);
1482 1472
1473 /*
1474 * Allocate interrupt.
1475 */
1476 ret = request_irq(irq, wbsd_irq, IRQF_SHARED, DRIVER_NAME, host);
1477 if (ret)
1478 return ret;
1479
1480 host->irq = irq;
1481
1483 return 0; 1482 return 0;
1484} 1483}
1485 1484