diff options
Diffstat (limited to 'drivers/mmc')
27 files changed, 2278 insertions, 241 deletions
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index cb9fbc83b090..d545f79f6000 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/kdev_t.h> | 29 | #include <linux/kdev_t.h> |
30 | #include <linux/blkdev.h> | 30 | #include <linux/blkdev.h> |
31 | #include <linux/mutex.h> | 31 | #include <linux/mutex.h> |
32 | #include <linux/smp_lock.h> | ||
32 | #include <linux/scatterlist.h> | 33 | #include <linux/scatterlist.h> |
33 | #include <linux/string_helpers.h> | 34 | #include <linux/string_helpers.h> |
34 | 35 | ||
@@ -107,6 +108,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode) | |||
107 | struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk); | 108 | struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk); |
108 | int ret = -ENXIO; | 109 | int ret = -ENXIO; |
109 | 110 | ||
111 | lock_kernel(); | ||
110 | if (md) { | 112 | if (md) { |
111 | if (md->usage == 2) | 113 | if (md->usage == 2) |
112 | check_disk_change(bdev); | 114 | check_disk_change(bdev); |
@@ -117,6 +119,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode) | |||
117 | ret = -EROFS; | 119 | ret = -EROFS; |
118 | } | 120 | } |
119 | } | 121 | } |
122 | unlock_kernel(); | ||
120 | 123 | ||
121 | return ret; | 124 | return ret; |
122 | } | 125 | } |
@@ -125,7 +128,9 @@ static int mmc_blk_release(struct gendisk *disk, fmode_t mode) | |||
125 | { | 128 | { |
126 | struct mmc_blk_data *md = disk->private_data; | 129 | struct mmc_blk_data *md = disk->private_data; |
127 | 130 | ||
131 | lock_kernel(); | ||
128 | mmc_blk_put(md); | 132 | mmc_blk_put(md); |
133 | unlock_kernel(); | ||
129 | return 0; | 134 | return 0; |
130 | } | 135 | } |
131 | 136 | ||
@@ -242,7 +247,76 @@ static u32 get_card_status(struct mmc_card *card, struct request *req) | |||
242 | return cmd.resp[0]; | 247 | return cmd.resp[0]; |
243 | } | 248 | } |
244 | 249 | ||
245 | static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | 250 | static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) |
251 | { | ||
252 | struct mmc_blk_data *md = mq->data; | ||
253 | struct mmc_card *card = md->queue.card; | ||
254 | unsigned int from, nr, arg; | ||
255 | int err = 0; | ||
256 | |||
257 | mmc_claim_host(card->host); | ||
258 | |||
259 | if (!mmc_can_erase(card)) { | ||
260 | err = -EOPNOTSUPP; | ||
261 | goto out; | ||
262 | } | ||
263 | |||
264 | from = blk_rq_pos(req); | ||
265 | nr = blk_rq_sectors(req); | ||
266 | |||
267 | if (mmc_can_trim(card)) | ||
268 | arg = MMC_TRIM_ARG; | ||
269 | else | ||
270 | arg = MMC_ERASE_ARG; | ||
271 | |||
272 | err = mmc_erase(card, from, nr, arg); | ||
273 | out: | ||
274 | spin_lock_irq(&md->lock); | ||
275 | __blk_end_request(req, err, blk_rq_bytes(req)); | ||
276 | spin_unlock_irq(&md->lock); | ||
277 | |||
278 | mmc_release_host(card->host); | ||
279 | |||
280 | return err ? 0 : 1; | ||
281 | } | ||
282 | |||
283 | static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq, | ||
284 | struct request *req) | ||
285 | { | ||
286 | struct mmc_blk_data *md = mq->data; | ||
287 | struct mmc_card *card = md->queue.card; | ||
288 | unsigned int from, nr, arg; | ||
289 | int err = 0; | ||
290 | |||
291 | mmc_claim_host(card->host); | ||
292 | |||
293 | if (!mmc_can_secure_erase_trim(card)) { | ||
294 | err = -EOPNOTSUPP; | ||
295 | goto out; | ||
296 | } | ||
297 | |||
298 | from = blk_rq_pos(req); | ||
299 | nr = blk_rq_sectors(req); | ||
300 | |||
301 | if (mmc_can_trim(card) && !mmc_erase_group_aligned(card, from, nr)) | ||
302 | arg = MMC_SECURE_TRIM1_ARG; | ||
303 | else | ||
304 | arg = MMC_SECURE_ERASE_ARG; | ||
305 | |||
306 | err = mmc_erase(card, from, nr, arg); | ||
307 | if (!err && arg == MMC_SECURE_TRIM1_ARG) | ||
308 | err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG); | ||
309 | out: | ||
310 | spin_lock_irq(&md->lock); | ||
311 | __blk_end_request(req, err, blk_rq_bytes(req)); | ||
312 | spin_unlock_irq(&md->lock); | ||
313 | |||
314 | mmc_release_host(card->host); | ||
315 | |||
316 | return err ? 0 : 1; | ||
317 | } | ||
318 | |||
319 | static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req) | ||
246 | { | 320 | { |
247 | struct mmc_blk_data *md = mq->data; | 321 | struct mmc_blk_data *md = mq->data; |
248 | struct mmc_card *card = md->queue.card; | 322 | struct mmc_card *card = md->queue.card; |
@@ -470,6 +544,17 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
470 | return 0; | 544 | return 0; |
471 | } | 545 | } |
472 | 546 | ||
547 | static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | ||
548 | { | ||
549 | if (req->cmd_flags & REQ_DISCARD) { | ||
550 | if (req->cmd_flags & REQ_SECURE) | ||
551 | return mmc_blk_issue_secdiscard_rq(mq, req); | ||
552 | else | ||
553 | return mmc_blk_issue_discard_rq(mq, req); | ||
554 | } else { | ||
555 | return mmc_blk_issue_rw_rq(mq, req); | ||
556 | } | ||
557 | } | ||
473 | 558 | ||
474 | static inline int mmc_blk_readonly(struct mmc_card *card) | 559 | static inline int mmc_blk_readonly(struct mmc_card *card) |
475 | { | 560 | { |
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c index 445d7db2277e..5dd8576b5c18 100644 --- a/drivers/mmc/card/mmc_test.c +++ b/drivers/mmc/card/mmc_test.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | 17 | ||
18 | #include <linux/scatterlist.h> | 18 | #include <linux/scatterlist.h> |
19 | #include <linux/swap.h> /* For nr_free_buffer_pages() */ | ||
19 | 20 | ||
20 | #define RESULT_OK 0 | 21 | #define RESULT_OK 0 |
21 | #define RESULT_FAIL 1 | 22 | #define RESULT_FAIL 1 |
@@ -25,6 +26,60 @@ | |||
25 | #define BUFFER_ORDER 2 | 26 | #define BUFFER_ORDER 2 |
26 | #define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER) | 27 | #define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER) |
27 | 28 | ||
29 | /* | ||
30 | * Limit the test area size to the maximum MMC HC erase group size. Note that | ||
31 | * the maximum SD allocation unit size is just 4MiB. | ||
32 | */ | ||
33 | #define TEST_AREA_MAX_SIZE (128 * 1024 * 1024) | ||
34 | |||
35 | /** | ||
36 | * struct mmc_test_pages - pages allocated by 'alloc_pages()'. | ||
37 | * @page: first page in the allocation | ||
38 | * @order: order of the number of pages allocated | ||
39 | */ | ||
40 | struct mmc_test_pages { | ||
41 | struct page *page; | ||
42 | unsigned int order; | ||
43 | }; | ||
44 | |||
45 | /** | ||
46 | * struct mmc_test_mem - allocated memory. | ||
47 | * @arr: array of allocations | ||
48 | * @cnt: number of allocations | ||
49 | */ | ||
50 | struct mmc_test_mem { | ||
51 | struct mmc_test_pages *arr; | ||
52 | unsigned int cnt; | ||
53 | }; | ||
54 | |||
55 | /** | ||
56 | * struct mmc_test_area - information for performance tests. | ||
57 | * @max_sz: test area size (in bytes) | ||
58 | * @dev_addr: address on card at which to do performance tests | ||
59 | * @max_segs: maximum segments in scatterlist @sg | ||
60 | * @blocks: number of (512 byte) blocks currently mapped by @sg | ||
61 | * @sg_len: length of currently mapped scatterlist @sg | ||
62 | * @mem: allocated memory | ||
63 | * @sg: scatterlist | ||
64 | */ | ||
65 | struct mmc_test_area { | ||
66 | unsigned long max_sz; | ||
67 | unsigned int dev_addr; | ||
68 | unsigned int max_segs; | ||
69 | unsigned int blocks; | ||
70 | unsigned int sg_len; | ||
71 | struct mmc_test_mem *mem; | ||
72 | struct scatterlist *sg; | ||
73 | }; | ||
74 | |||
75 | /** | ||
76 | * struct mmc_test_card - test information. | ||
77 | * @card: card under test | ||
78 | * @scratch: transfer buffer | ||
79 | * @buffer: transfer buffer | ||
80 | * @highmem: buffer for highmem tests | ||
81 | * @area: information for performance tests | ||
82 | */ | ||
28 | struct mmc_test_card { | 83 | struct mmc_test_card { |
29 | struct mmc_card *card; | 84 | struct mmc_card *card; |
30 | 85 | ||
@@ -33,6 +88,7 @@ struct mmc_test_card { | |||
33 | #ifdef CONFIG_HIGHMEM | 88 | #ifdef CONFIG_HIGHMEM |
34 | struct page *highmem; | 89 | struct page *highmem; |
35 | #endif | 90 | #endif |
91 | struct mmc_test_area area; | ||
36 | }; | 92 | }; |
37 | 93 | ||
38 | /*******************************************************************/ | 94 | /*******************************************************************/ |
@@ -97,6 +153,12 @@ static void mmc_test_prepare_mrq(struct mmc_test_card *test, | |||
97 | mmc_set_data_timeout(mrq->data, test->card); | 153 | mmc_set_data_timeout(mrq->data, test->card); |
98 | } | 154 | } |
99 | 155 | ||
156 | static int mmc_test_busy(struct mmc_command *cmd) | ||
157 | { | ||
158 | return !(cmd->resp[0] & R1_READY_FOR_DATA) || | ||
159 | (R1_CURRENT_STATE(cmd->resp[0]) == 7); | ||
160 | } | ||
161 | |||
100 | /* | 162 | /* |
101 | * Wait for the card to finish the busy state | 163 | * Wait for the card to finish the busy state |
102 | */ | 164 | */ |
@@ -117,13 +179,13 @@ static int mmc_test_wait_busy(struct mmc_test_card *test) | |||
117 | if (ret) | 179 | if (ret) |
118 | break; | 180 | break; |
119 | 181 | ||
120 | if (!busy && !(cmd.resp[0] & R1_READY_FOR_DATA)) { | 182 | if (!busy && mmc_test_busy(&cmd)) { |
121 | busy = 1; | 183 | busy = 1; |
122 | printk(KERN_INFO "%s: Warning: Host did not " | 184 | printk(KERN_INFO "%s: Warning: Host did not " |
123 | "wait for busy state to end.\n", | 185 | "wait for busy state to end.\n", |
124 | mmc_hostname(test->card->host)); | 186 | mmc_hostname(test->card->host)); |
125 | } | 187 | } |
126 | } while (!(cmd.resp[0] & R1_READY_FOR_DATA)); | 188 | } while (mmc_test_busy(&cmd)); |
127 | 189 | ||
128 | return ret; | 190 | return ret; |
129 | } | 191 | } |
@@ -170,6 +232,248 @@ static int mmc_test_buffer_transfer(struct mmc_test_card *test, | |||
170 | return 0; | 232 | return 0; |
171 | } | 233 | } |
172 | 234 | ||
235 | static void mmc_test_free_mem(struct mmc_test_mem *mem) | ||
236 | { | ||
237 | if (!mem) | ||
238 | return; | ||
239 | while (mem->cnt--) | ||
240 | __free_pages(mem->arr[mem->cnt].page, | ||
241 | mem->arr[mem->cnt].order); | ||
242 | kfree(mem->arr); | ||
243 | kfree(mem); | ||
244 | } | ||
245 | |||
246 | /* | ||
247 | * Allocate a lot of memory, preferrably max_sz but at least min_sz. In case | ||
248 | * there isn't much memory do not exceed 1/16th total lowmem pages. | ||
249 | */ | ||
250 | static struct mmc_test_mem *mmc_test_alloc_mem(unsigned long min_sz, | ||
251 | unsigned long max_sz) | ||
252 | { | ||
253 | unsigned long max_page_cnt = DIV_ROUND_UP(max_sz, PAGE_SIZE); | ||
254 | unsigned long min_page_cnt = DIV_ROUND_UP(min_sz, PAGE_SIZE); | ||
255 | unsigned long page_cnt = 0; | ||
256 | unsigned long limit = nr_free_buffer_pages() >> 4; | ||
257 | struct mmc_test_mem *mem; | ||
258 | |||
259 | if (max_page_cnt > limit) | ||
260 | max_page_cnt = limit; | ||
261 | if (max_page_cnt < min_page_cnt) | ||
262 | max_page_cnt = min_page_cnt; | ||
263 | |||
264 | mem = kzalloc(sizeof(struct mmc_test_mem), GFP_KERNEL); | ||
265 | if (!mem) | ||
266 | return NULL; | ||
267 | |||
268 | mem->arr = kzalloc(sizeof(struct mmc_test_pages) * max_page_cnt, | ||
269 | GFP_KERNEL); | ||
270 | if (!mem->arr) | ||
271 | goto out_free; | ||
272 | |||
273 | while (max_page_cnt) { | ||
274 | struct page *page; | ||
275 | unsigned int order; | ||
276 | gfp_t flags = GFP_KERNEL | GFP_DMA | __GFP_NOWARN | | ||
277 | __GFP_NORETRY; | ||
278 | |||
279 | order = get_order(max_page_cnt << PAGE_SHIFT); | ||
280 | while (1) { | ||
281 | page = alloc_pages(flags, order); | ||
282 | if (page || !order) | ||
283 | break; | ||
284 | order -= 1; | ||
285 | } | ||
286 | if (!page) { | ||
287 | if (page_cnt < min_page_cnt) | ||
288 | goto out_free; | ||
289 | break; | ||
290 | } | ||
291 | mem->arr[mem->cnt].page = page; | ||
292 | mem->arr[mem->cnt].order = order; | ||
293 | mem->cnt += 1; | ||
294 | if (max_page_cnt <= (1UL << order)) | ||
295 | break; | ||
296 | max_page_cnt -= 1UL << order; | ||
297 | page_cnt += 1UL << order; | ||
298 | } | ||
299 | |||
300 | return mem; | ||
301 | |||
302 | out_free: | ||
303 | mmc_test_free_mem(mem); | ||
304 | return NULL; | ||
305 | } | ||
306 | |||
307 | /* | ||
308 | * Map memory into a scatterlist. Optionally allow the same memory to be | ||
309 | * mapped more than once. | ||
310 | */ | ||
311 | static int mmc_test_map_sg(struct mmc_test_mem *mem, unsigned long sz, | ||
312 | struct scatterlist *sglist, int repeat, | ||
313 | unsigned int max_segs, unsigned int *sg_len) | ||
314 | { | ||
315 | struct scatterlist *sg = NULL; | ||
316 | unsigned int i; | ||
317 | |||
318 | sg_init_table(sglist, max_segs); | ||
319 | |||
320 | *sg_len = 0; | ||
321 | do { | ||
322 | for (i = 0; i < mem->cnt; i++) { | ||
323 | unsigned long len = PAGE_SIZE << mem->arr[i].order; | ||
324 | |||
325 | if (sz < len) | ||
326 | len = sz; | ||
327 | if (sg) | ||
328 | sg = sg_next(sg); | ||
329 | else | ||
330 | sg = sglist; | ||
331 | if (!sg) | ||
332 | return -EINVAL; | ||
333 | sg_set_page(sg, mem->arr[i].page, len, 0); | ||
334 | sz -= len; | ||
335 | *sg_len += 1; | ||
336 | if (!sz) | ||
337 | break; | ||
338 | } | ||
339 | } while (sz && repeat); | ||
340 | |||
341 | if (sz) | ||
342 | return -EINVAL; | ||
343 | |||
344 | if (sg) | ||
345 | sg_mark_end(sg); | ||
346 | |||
347 | return 0; | ||
348 | } | ||
349 | |||
350 | /* | ||
351 | * Map memory into a scatterlist so that no pages are contiguous. Allow the | ||
352 | * same memory to be mapped more than once. | ||
353 | */ | ||
354 | static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem, | ||
355 | unsigned long sz, | ||
356 | struct scatterlist *sglist, | ||
357 | unsigned int max_segs, | ||
358 | unsigned int *sg_len) | ||
359 | { | ||
360 | struct scatterlist *sg = NULL; | ||
361 | unsigned int i = mem->cnt, cnt; | ||
362 | unsigned long len; | ||
363 | void *base, *addr, *last_addr = NULL; | ||
364 | |||
365 | sg_init_table(sglist, max_segs); | ||
366 | |||
367 | *sg_len = 0; | ||
368 | while (sz && i) { | ||
369 | base = page_address(mem->arr[--i].page); | ||
370 | cnt = 1 << mem->arr[i].order; | ||
371 | while (sz && cnt) { | ||
372 | addr = base + PAGE_SIZE * --cnt; | ||
373 | if (last_addr && last_addr + PAGE_SIZE == addr) | ||
374 | continue; | ||
375 | last_addr = addr; | ||
376 | len = PAGE_SIZE; | ||
377 | if (sz < len) | ||
378 | len = sz; | ||
379 | if (sg) | ||
380 | sg = sg_next(sg); | ||
381 | else | ||
382 | sg = sglist; | ||
383 | if (!sg) | ||
384 | return -EINVAL; | ||
385 | sg_set_page(sg, virt_to_page(addr), len, 0); | ||
386 | sz -= len; | ||
387 | *sg_len += 1; | ||
388 | } | ||
389 | } | ||
390 | |||
391 | if (sg) | ||
392 | sg_mark_end(sg); | ||
393 | |||
394 | return 0; | ||
395 | } | ||
396 | |||
397 | /* | ||
398 | * Calculate transfer rate in bytes per second. | ||
399 | */ | ||
400 | static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts) | ||
401 | { | ||
402 | uint64_t ns; | ||
403 | |||
404 | ns = ts->tv_sec; | ||
405 | ns *= 1000000000; | ||
406 | ns += ts->tv_nsec; | ||
407 | |||
408 | bytes *= 1000000000; | ||
409 | |||
410 | while (ns > UINT_MAX) { | ||
411 | bytes >>= 1; | ||
412 | ns >>= 1; | ||
413 | } | ||
414 | |||
415 | if (!ns) | ||
416 | return 0; | ||
417 | |||
418 | do_div(bytes, (uint32_t)ns); | ||
419 | |||
420 | return bytes; | ||
421 | } | ||
422 | |||
423 | /* | ||
424 | * Print the transfer rate. | ||
425 | */ | ||
426 | static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes, | ||
427 | struct timespec *ts1, struct timespec *ts2) | ||
428 | { | ||
429 | unsigned int rate, sectors = bytes >> 9; | ||
430 | struct timespec ts; | ||
431 | |||
432 | ts = timespec_sub(*ts2, *ts1); | ||
433 | |||
434 | rate = mmc_test_rate(bytes, &ts); | ||
435 | |||
436 | printk(KERN_INFO "%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu " | ||
437 | "seconds (%u kB/s, %u KiB/s)\n", | ||
438 | mmc_hostname(test->card->host), sectors, sectors >> 1, | ||
439 | (sectors == 1 ? ".5" : ""), (unsigned long)ts.tv_sec, | ||
440 | (unsigned long)ts.tv_nsec, rate / 1000, rate / 1024); | ||
441 | } | ||
442 | |||
443 | /* | ||
444 | * Print the average transfer rate. | ||
445 | */ | ||
446 | static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes, | ||
447 | unsigned int count, struct timespec *ts1, | ||
448 | struct timespec *ts2) | ||
449 | { | ||
450 | unsigned int rate, sectors = bytes >> 9; | ||
451 | uint64_t tot = bytes * count; | ||
452 | struct timespec ts; | ||
453 | |||
454 | ts = timespec_sub(*ts2, *ts1); | ||
455 | |||
456 | rate = mmc_test_rate(tot, &ts); | ||
457 | |||
458 | printk(KERN_INFO "%s: Transfer of %u x %u sectors (%u x %u%s KiB) took " | ||
459 | "%lu.%09lu seconds (%u kB/s, %u KiB/s)\n", | ||
460 | mmc_hostname(test->card->host), count, sectors, count, | ||
461 | sectors >> 1, (sectors == 1 ? ".5" : ""), | ||
462 | (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec, | ||
463 | rate / 1000, rate / 1024); | ||
464 | } | ||
465 | |||
466 | /* | ||
467 | * Return the card size in sectors. | ||
468 | */ | ||
469 | static unsigned int mmc_test_capacity(struct mmc_card *card) | ||
470 | { | ||
471 | if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) | ||
472 | return card->ext_csd.sectors; | ||
473 | else | ||
474 | return card->csd.capacity << (card->csd.read_blkbits - 9); | ||
475 | } | ||
476 | |||
173 | /*******************************************************************/ | 477 | /*******************************************************************/ |
174 | /* Test preparation and cleanup */ | 478 | /* Test preparation and cleanup */ |
175 | /*******************************************************************/ | 479 | /*******************************************************************/ |
@@ -893,8 +1197,419 @@ static int mmc_test_multi_read_high(struct mmc_test_card *test) | |||
893 | return 0; | 1197 | return 0; |
894 | } | 1198 | } |
895 | 1199 | ||
1200 | #else | ||
1201 | |||
1202 | static int mmc_test_no_highmem(struct mmc_test_card *test) | ||
1203 | { | ||
1204 | printk(KERN_INFO "%s: Highmem not configured - test skipped\n", | ||
1205 | mmc_hostname(test->card->host)); | ||
1206 | return 0; | ||
1207 | } | ||
1208 | |||
896 | #endif /* CONFIG_HIGHMEM */ | 1209 | #endif /* CONFIG_HIGHMEM */ |
897 | 1210 | ||
1211 | /* | ||
1212 | * Map sz bytes so that it can be transferred. | ||
1213 | */ | ||
1214 | static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz, | ||
1215 | int max_scatter) | ||
1216 | { | ||
1217 | struct mmc_test_area *t = &test->area; | ||
1218 | |||
1219 | t->blocks = sz >> 9; | ||
1220 | |||
1221 | if (max_scatter) { | ||
1222 | return mmc_test_map_sg_max_scatter(t->mem, sz, t->sg, | ||
1223 | t->max_segs, &t->sg_len); | ||
1224 | } else { | ||
1225 | return mmc_test_map_sg(t->mem, sz, t->sg, 1, t->max_segs, | ||
1226 | &t->sg_len); | ||
1227 | } | ||
1228 | } | ||
1229 | |||
1230 | /* | ||
1231 | * Transfer bytes mapped by mmc_test_area_map(). | ||
1232 | */ | ||
1233 | static int mmc_test_area_transfer(struct mmc_test_card *test, | ||
1234 | unsigned int dev_addr, int write) | ||
1235 | { | ||
1236 | struct mmc_test_area *t = &test->area; | ||
1237 | |||
1238 | return mmc_test_simple_transfer(test, t->sg, t->sg_len, dev_addr, | ||
1239 | t->blocks, 512, write); | ||
1240 | } | ||
1241 | |||
1242 | /* | ||
1243 | * Map and transfer bytes. | ||
1244 | */ | ||
1245 | static int mmc_test_area_io(struct mmc_test_card *test, unsigned long sz, | ||
1246 | unsigned int dev_addr, int write, int max_scatter, | ||
1247 | int timed) | ||
1248 | { | ||
1249 | struct timespec ts1, ts2; | ||
1250 | int ret; | ||
1251 | |||
1252 | ret = mmc_test_area_map(test, sz, max_scatter); | ||
1253 | if (ret) | ||
1254 | return ret; | ||
1255 | |||
1256 | if (timed) | ||
1257 | getnstimeofday(&ts1); | ||
1258 | |||
1259 | ret = mmc_test_area_transfer(test, dev_addr, write); | ||
1260 | if (ret) | ||
1261 | return ret; | ||
1262 | |||
1263 | if (timed) | ||
1264 | getnstimeofday(&ts2); | ||
1265 | |||
1266 | if (timed) | ||
1267 | mmc_test_print_rate(test, sz, &ts1, &ts2); | ||
1268 | |||
1269 | return 0; | ||
1270 | } | ||
1271 | |||
1272 | /* | ||
1273 | * Write the test area entirely. | ||
1274 | */ | ||
1275 | static int mmc_test_area_fill(struct mmc_test_card *test) | ||
1276 | { | ||
1277 | return mmc_test_area_io(test, test->area.max_sz, test->area.dev_addr, | ||
1278 | 1, 0, 0); | ||
1279 | } | ||
1280 | |||
1281 | /* | ||
1282 | * Erase the test area entirely. | ||
1283 | */ | ||
1284 | static int mmc_test_area_erase(struct mmc_test_card *test) | ||
1285 | { | ||
1286 | struct mmc_test_area *t = &test->area; | ||
1287 | |||
1288 | if (!mmc_can_erase(test->card)) | ||
1289 | return 0; | ||
1290 | |||
1291 | return mmc_erase(test->card, t->dev_addr, test->area.max_sz >> 9, | ||
1292 | MMC_ERASE_ARG); | ||
1293 | } | ||
1294 | |||
1295 | /* | ||
1296 | * Cleanup struct mmc_test_area. | ||
1297 | */ | ||
1298 | static int mmc_test_area_cleanup(struct mmc_test_card *test) | ||
1299 | { | ||
1300 | struct mmc_test_area *t = &test->area; | ||
1301 | |||
1302 | kfree(t->sg); | ||
1303 | mmc_test_free_mem(t->mem); | ||
1304 | |||
1305 | return 0; | ||
1306 | } | ||
1307 | |||
1308 | /* | ||
1309 | * Initialize an area for testing large transfers. The size of the area is the | ||
1310 | * preferred erase size which is a good size for optimal transfer speed. Note | ||
1311 | * that is typically 4MiB for modern cards. The test area is set to the middle | ||
1312 | * of the card because cards may have different charateristics at the front | ||
1313 | * (for FAT file system optimization). Optionally, the area is erased (if the | ||
1314 | * card supports it) which may improve write performance. Optionally, the area | ||
1315 | * is filled with data for subsequent read tests. | ||
1316 | */ | ||
1317 | static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill) | ||
1318 | { | ||
1319 | struct mmc_test_area *t = &test->area; | ||
1320 | unsigned long min_sz = 64 * 1024; | ||
1321 | int ret; | ||
1322 | |||
1323 | ret = mmc_test_set_blksize(test, 512); | ||
1324 | if (ret) | ||
1325 | return ret; | ||
1326 | |||
1327 | if (test->card->pref_erase > TEST_AREA_MAX_SIZE >> 9) | ||
1328 | t->max_sz = TEST_AREA_MAX_SIZE; | ||
1329 | else | ||
1330 | t->max_sz = (unsigned long)test->card->pref_erase << 9; | ||
1331 | /* | ||
1332 | * Try to allocate enough memory for the whole area. Less is OK | ||
1333 | * because the same memory can be mapped into the scatterlist more than | ||
1334 | * once. | ||
1335 | */ | ||
1336 | t->mem = mmc_test_alloc_mem(min_sz, t->max_sz); | ||
1337 | if (!t->mem) | ||
1338 | return -ENOMEM; | ||
1339 | |||
1340 | t->max_segs = DIV_ROUND_UP(t->max_sz, PAGE_SIZE); | ||
1341 | t->sg = kmalloc(sizeof(struct scatterlist) * t->max_segs, GFP_KERNEL); | ||
1342 | if (!t->sg) { | ||
1343 | ret = -ENOMEM; | ||
1344 | goto out_free; | ||
1345 | } | ||
1346 | |||
1347 | t->dev_addr = mmc_test_capacity(test->card) / 2; | ||
1348 | t->dev_addr -= t->dev_addr % (t->max_sz >> 9); | ||
1349 | |||
1350 | if (erase) { | ||
1351 | ret = mmc_test_area_erase(test); | ||
1352 | if (ret) | ||
1353 | goto out_free; | ||
1354 | } | ||
1355 | |||
1356 | if (fill) { | ||
1357 | ret = mmc_test_area_fill(test); | ||
1358 | if (ret) | ||
1359 | goto out_free; | ||
1360 | } | ||
1361 | |||
1362 | return 0; | ||
1363 | |||
1364 | out_free: | ||
1365 | mmc_test_area_cleanup(test); | ||
1366 | return ret; | ||
1367 | } | ||
1368 | |||
1369 | /* | ||
1370 | * Prepare for large transfers. Do not erase the test area. | ||
1371 | */ | ||
1372 | static int mmc_test_area_prepare(struct mmc_test_card *test) | ||
1373 | { | ||
1374 | return mmc_test_area_init(test, 0, 0); | ||
1375 | } | ||
1376 | |||
1377 | /* | ||
1378 | * Prepare for large transfers. Do erase the test area. | ||
1379 | */ | ||
1380 | static int mmc_test_area_prepare_erase(struct mmc_test_card *test) | ||
1381 | { | ||
1382 | return mmc_test_area_init(test, 1, 0); | ||
1383 | } | ||
1384 | |||
1385 | /* | ||
1386 | * Prepare for large transfers. Erase and fill the test area. | ||
1387 | */ | ||
1388 | static int mmc_test_area_prepare_fill(struct mmc_test_card *test) | ||
1389 | { | ||
1390 | return mmc_test_area_init(test, 1, 1); | ||
1391 | } | ||
1392 | |||
1393 | /* | ||
1394 | * Test best-case performance. Best-case performance is expected from | ||
1395 | * a single large transfer. | ||
1396 | * | ||
1397 | * An additional option (max_scatter) allows the measurement of the same | ||
1398 | * transfer but with no contiguous pages in the scatter list. This tests | ||
1399 | * the efficiency of DMA to handle scattered pages. | ||
1400 | */ | ||
1401 | static int mmc_test_best_performance(struct mmc_test_card *test, int write, | ||
1402 | int max_scatter) | ||
1403 | { | ||
1404 | return mmc_test_area_io(test, test->area.max_sz, test->area.dev_addr, | ||
1405 | write, max_scatter, 1); | ||
1406 | } | ||
1407 | |||
1408 | /* | ||
1409 | * Best-case read performance. | ||
1410 | */ | ||
1411 | static int mmc_test_best_read_performance(struct mmc_test_card *test) | ||
1412 | { | ||
1413 | return mmc_test_best_performance(test, 0, 0); | ||
1414 | } | ||
1415 | |||
1416 | /* | ||
1417 | * Best-case write performance. | ||
1418 | */ | ||
1419 | static int mmc_test_best_write_performance(struct mmc_test_card *test) | ||
1420 | { | ||
1421 | return mmc_test_best_performance(test, 1, 0); | ||
1422 | } | ||
1423 | |||
1424 | /* | ||
1425 | * Best-case read performance into scattered pages. | ||
1426 | */ | ||
1427 | static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card *test) | ||
1428 | { | ||
1429 | return mmc_test_best_performance(test, 0, 1); | ||
1430 | } | ||
1431 | |||
1432 | /* | ||
1433 | * Best-case write performance from scattered pages. | ||
1434 | */ | ||
1435 | static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card *test) | ||
1436 | { | ||
1437 | return mmc_test_best_performance(test, 1, 1); | ||
1438 | } | ||
1439 | |||
1440 | /* | ||
1441 | * Single read performance by transfer size. | ||
1442 | */ | ||
1443 | static int mmc_test_profile_read_perf(struct mmc_test_card *test) | ||
1444 | { | ||
1445 | unsigned long sz; | ||
1446 | unsigned int dev_addr; | ||
1447 | int ret; | ||
1448 | |||
1449 | for (sz = 512; sz < test->area.max_sz; sz <<= 1) { | ||
1450 | dev_addr = test->area.dev_addr + (sz >> 9); | ||
1451 | ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 1); | ||
1452 | if (ret) | ||
1453 | return ret; | ||
1454 | } | ||
1455 | dev_addr = test->area.dev_addr; | ||
1456 | return mmc_test_area_io(test, sz, dev_addr, 0, 0, 1); | ||
1457 | } | ||
1458 | |||
1459 | /* | ||
1460 | * Single write performance by transfer size. | ||
1461 | */ | ||
1462 | static int mmc_test_profile_write_perf(struct mmc_test_card *test) | ||
1463 | { | ||
1464 | unsigned long sz; | ||
1465 | unsigned int dev_addr; | ||
1466 | int ret; | ||
1467 | |||
1468 | ret = mmc_test_area_erase(test); | ||
1469 | if (ret) | ||
1470 | return ret; | ||
1471 | for (sz = 512; sz < test->area.max_sz; sz <<= 1) { | ||
1472 | dev_addr = test->area.dev_addr + (sz >> 9); | ||
1473 | ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 1); | ||
1474 | if (ret) | ||
1475 | return ret; | ||
1476 | } | ||
1477 | ret = mmc_test_area_erase(test); | ||
1478 | if (ret) | ||
1479 | return ret; | ||
1480 | dev_addr = test->area.dev_addr; | ||
1481 | return mmc_test_area_io(test, sz, dev_addr, 1, 0, 1); | ||
1482 | } | ||
1483 | |||
1484 | /* | ||
1485 | * Single trim performance by transfer size. | ||
1486 | */ | ||
1487 | static int mmc_test_profile_trim_perf(struct mmc_test_card *test) | ||
1488 | { | ||
1489 | unsigned long sz; | ||
1490 | unsigned int dev_addr; | ||
1491 | struct timespec ts1, ts2; | ||
1492 | int ret; | ||
1493 | |||
1494 | if (!mmc_can_trim(test->card)) | ||
1495 | return RESULT_UNSUP_CARD; | ||
1496 | |||
1497 | if (!mmc_can_erase(test->card)) | ||
1498 | return RESULT_UNSUP_HOST; | ||
1499 | |||
1500 | for (sz = 512; sz < test->area.max_sz; sz <<= 1) { | ||
1501 | dev_addr = test->area.dev_addr + (sz >> 9); | ||
1502 | getnstimeofday(&ts1); | ||
1503 | ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG); | ||
1504 | if (ret) | ||
1505 | return ret; | ||
1506 | getnstimeofday(&ts2); | ||
1507 | mmc_test_print_rate(test, sz, &ts1, &ts2); | ||
1508 | } | ||
1509 | dev_addr = test->area.dev_addr; | ||
1510 | getnstimeofday(&ts1); | ||
1511 | ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG); | ||
1512 | if (ret) | ||
1513 | return ret; | ||
1514 | getnstimeofday(&ts2); | ||
1515 | mmc_test_print_rate(test, sz, &ts1, &ts2); | ||
1516 | return 0; | ||
1517 | } | ||
1518 | |||
1519 | /* | ||
1520 | * Consecutive read performance by transfer size. | ||
1521 | */ | ||
1522 | static int mmc_test_profile_seq_read_perf(struct mmc_test_card *test) | ||
1523 | { | ||
1524 | unsigned long sz; | ||
1525 | unsigned int dev_addr, i, cnt; | ||
1526 | struct timespec ts1, ts2; | ||
1527 | int ret; | ||
1528 | |||
1529 | for (sz = 512; sz <= test->area.max_sz; sz <<= 1) { | ||
1530 | cnt = test->area.max_sz / sz; | ||
1531 | dev_addr = test->area.dev_addr; | ||
1532 | getnstimeofday(&ts1); | ||
1533 | for (i = 0; i < cnt; i++) { | ||
1534 | ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0); | ||
1535 | if (ret) | ||
1536 | return ret; | ||
1537 | dev_addr += (sz >> 9); | ||
1538 | } | ||
1539 | getnstimeofday(&ts2); | ||
1540 | mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); | ||
1541 | } | ||
1542 | return 0; | ||
1543 | } | ||
1544 | |||
1545 | /* | ||
1546 | * Consecutive write performance by transfer size. | ||
1547 | */ | ||
1548 | static int mmc_test_profile_seq_write_perf(struct mmc_test_card *test) | ||
1549 | { | ||
1550 | unsigned long sz; | ||
1551 | unsigned int dev_addr, i, cnt; | ||
1552 | struct timespec ts1, ts2; | ||
1553 | int ret; | ||
1554 | |||
1555 | for (sz = 512; sz <= test->area.max_sz; sz <<= 1) { | ||
1556 | ret = mmc_test_area_erase(test); | ||
1557 | if (ret) | ||
1558 | return ret; | ||
1559 | cnt = test->area.max_sz / sz; | ||
1560 | dev_addr = test->area.dev_addr; | ||
1561 | getnstimeofday(&ts1); | ||
1562 | for (i = 0; i < cnt; i++) { | ||
1563 | ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0); | ||
1564 | if (ret) | ||
1565 | return ret; | ||
1566 | dev_addr += (sz >> 9); | ||
1567 | } | ||
1568 | getnstimeofday(&ts2); | ||
1569 | mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); | ||
1570 | } | ||
1571 | return 0; | ||
1572 | } | ||
1573 | |||
1574 | /* | ||
1575 | * Consecutive trim performance by transfer size. | ||
1576 | */ | ||
1577 | static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test) | ||
1578 | { | ||
1579 | unsigned long sz; | ||
1580 | unsigned int dev_addr, i, cnt; | ||
1581 | struct timespec ts1, ts2; | ||
1582 | int ret; | ||
1583 | |||
1584 | if (!mmc_can_trim(test->card)) | ||
1585 | return RESULT_UNSUP_CARD; | ||
1586 | |||
1587 | if (!mmc_can_erase(test->card)) | ||
1588 | return RESULT_UNSUP_HOST; | ||
1589 | |||
1590 | for (sz = 512; sz <= test->area.max_sz; sz <<= 1) { | ||
1591 | ret = mmc_test_area_erase(test); | ||
1592 | if (ret) | ||
1593 | return ret; | ||
1594 | ret = mmc_test_area_fill(test); | ||
1595 | if (ret) | ||
1596 | return ret; | ||
1597 | cnt = test->area.max_sz / sz; | ||
1598 | dev_addr = test->area.dev_addr; | ||
1599 | getnstimeofday(&ts1); | ||
1600 | for (i = 0; i < cnt; i++) { | ||
1601 | ret = mmc_erase(test->card, dev_addr, sz >> 9, | ||
1602 | MMC_TRIM_ARG); | ||
1603 | if (ret) | ||
1604 | return ret; | ||
1605 | dev_addr += (sz >> 9); | ||
1606 | } | ||
1607 | getnstimeofday(&ts2); | ||
1608 | mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2); | ||
1609 | } | ||
1610 | return 0; | ||
1611 | } | ||
1612 | |||
898 | static const struct mmc_test_case mmc_test_cases[] = { | 1613 | static const struct mmc_test_case mmc_test_cases[] = { |
899 | { | 1614 | { |
900 | .name = "Basic write (no data verification)", | 1615 | .name = "Basic write (no data verification)", |
@@ -1040,8 +1755,100 @@ static const struct mmc_test_case mmc_test_cases[] = { | |||
1040 | .cleanup = mmc_test_cleanup, | 1755 | .cleanup = mmc_test_cleanup, |
1041 | }, | 1756 | }, |
1042 | 1757 | ||
1758 | #else | ||
1759 | |||
1760 | { | ||
1761 | .name = "Highmem write", | ||
1762 | .run = mmc_test_no_highmem, | ||
1763 | }, | ||
1764 | |||
1765 | { | ||
1766 | .name = "Highmem read", | ||
1767 | .run = mmc_test_no_highmem, | ||
1768 | }, | ||
1769 | |||
1770 | { | ||
1771 | .name = "Multi-block highmem write", | ||
1772 | .run = mmc_test_no_highmem, | ||
1773 | }, | ||
1774 | |||
1775 | { | ||
1776 | .name = "Multi-block highmem read", | ||
1777 | .run = mmc_test_no_highmem, | ||
1778 | }, | ||
1779 | |||
1043 | #endif /* CONFIG_HIGHMEM */ | 1780 | #endif /* CONFIG_HIGHMEM */ |
1044 | 1781 | ||
1782 | { | ||
1783 | .name = "Best-case read performance", | ||
1784 | .prepare = mmc_test_area_prepare_fill, | ||
1785 | .run = mmc_test_best_read_performance, | ||
1786 | .cleanup = mmc_test_area_cleanup, | ||
1787 | }, | ||
1788 | |||
1789 | { | ||
1790 | .name = "Best-case write performance", | ||
1791 | .prepare = mmc_test_area_prepare_erase, | ||
1792 | .run = mmc_test_best_write_performance, | ||
1793 | .cleanup = mmc_test_area_cleanup, | ||
1794 | }, | ||
1795 | |||
1796 | { | ||
1797 | .name = "Best-case read performance into scattered pages", | ||
1798 | .prepare = mmc_test_area_prepare_fill, | ||
1799 | .run = mmc_test_best_read_perf_max_scatter, | ||
1800 | .cleanup = mmc_test_area_cleanup, | ||
1801 | }, | ||
1802 | |||
1803 | { | ||
1804 | .name = "Best-case write performance from scattered pages", | ||
1805 | .prepare = mmc_test_area_prepare_erase, | ||
1806 | .run = mmc_test_best_write_perf_max_scatter, | ||
1807 | .cleanup = mmc_test_area_cleanup, | ||
1808 | }, | ||
1809 | |||
1810 | { | ||
1811 | .name = "Single read performance by transfer size", | ||
1812 | .prepare = mmc_test_area_prepare_fill, | ||
1813 | .run = mmc_test_profile_read_perf, | ||
1814 | .cleanup = mmc_test_area_cleanup, | ||
1815 | }, | ||
1816 | |||
1817 | { | ||
1818 | .name = "Single write performance by transfer size", | ||
1819 | .prepare = mmc_test_area_prepare, | ||
1820 | .run = mmc_test_profile_write_perf, | ||
1821 | .cleanup = mmc_test_area_cleanup, | ||
1822 | }, | ||
1823 | |||
1824 | { | ||
1825 | .name = "Single trim performance by transfer size", | ||
1826 | .prepare = mmc_test_area_prepare_fill, | ||
1827 | .run = mmc_test_profile_trim_perf, | ||
1828 | .cleanup = mmc_test_area_cleanup, | ||
1829 | }, | ||
1830 | |||
1831 | { | ||
1832 | .name = "Consecutive read performance by transfer size", | ||
1833 | .prepare = mmc_test_area_prepare_fill, | ||
1834 | .run = mmc_test_profile_seq_read_perf, | ||
1835 | .cleanup = mmc_test_area_cleanup, | ||
1836 | }, | ||
1837 | |||
1838 | { | ||
1839 | .name = "Consecutive write performance by transfer size", | ||
1840 | .prepare = mmc_test_area_prepare, | ||
1841 | .run = mmc_test_profile_seq_write_perf, | ||
1842 | .cleanup = mmc_test_area_cleanup, | ||
1843 | }, | ||
1844 | |||
1845 | { | ||
1846 | .name = "Consecutive trim performance by transfer size", | ||
1847 | .prepare = mmc_test_area_prepare, | ||
1848 | .run = mmc_test_profile_seq_trim_perf, | ||
1849 | .cleanup = mmc_test_area_cleanup, | ||
1850 | }, | ||
1851 | |||
1045 | }; | 1852 | }; |
1046 | 1853 | ||
1047 | static DEFINE_MUTEX(mmc_test_lock); | 1854 | static DEFINE_MUTEX(mmc_test_lock); |
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c index d6ded247d941..e876678176be 100644 --- a/drivers/mmc/card/queue.c +++ b/drivers/mmc/card/queue.c | |||
@@ -30,9 +30,9 @@ | |||
30 | static int mmc_prep_request(struct request_queue *q, struct request *req) | 30 | static int mmc_prep_request(struct request_queue *q, struct request *req) |
31 | { | 31 | { |
32 | /* | 32 | /* |
33 | * We only like normal block requests. | 33 | * We only like normal block requests and discards. |
34 | */ | 34 | */ |
35 | if (!blk_fs_request(req)) { | 35 | if (req->cmd_type != REQ_TYPE_FS && !(req->cmd_flags & REQ_DISCARD)) { |
36 | blk_dump_rq_flags(req, "MMC bad request"); | 36 | blk_dump_rq_flags(req, "MMC bad request"); |
37 | return BLKPREP_KILL; | 37 | return BLKPREP_KILL; |
38 | } | 38 | } |
@@ -128,8 +128,23 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock | |||
128 | mq->req = NULL; | 128 | mq->req = NULL; |
129 | 129 | ||
130 | blk_queue_prep_rq(mq->queue, mmc_prep_request); | 130 | blk_queue_prep_rq(mq->queue, mmc_prep_request); |
131 | blk_queue_ordered(mq->queue, QUEUE_ORDERED_DRAIN, NULL); | 131 | blk_queue_ordered(mq->queue, QUEUE_ORDERED_DRAIN); |
132 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue); | 132 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue); |
133 | if (mmc_can_erase(card)) { | ||
134 | queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mq->queue); | ||
135 | mq->queue->limits.max_discard_sectors = UINT_MAX; | ||
136 | if (card->erased_byte == 0) | ||
137 | mq->queue->limits.discard_zeroes_data = 1; | ||
138 | if (!mmc_can_trim(card) && is_power_of_2(card->erase_size)) { | ||
139 | mq->queue->limits.discard_granularity = | ||
140 | card->erase_size << 9; | ||
141 | mq->queue->limits.discard_alignment = | ||
142 | card->erase_size << 9; | ||
143 | } | ||
144 | if (mmc_can_secure_erase_trim(card)) | ||
145 | queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, | ||
146 | mq->queue); | ||
147 | } | ||
133 | 148 | ||
134 | #ifdef CONFIG_MMC_BLOCK_BOUNCE | 149 | #ifdef CONFIG_MMC_BLOCK_BOUNCE |
135 | if (host->max_hw_segs == 1) { | 150 | if (host->max_hw_segs == 1) { |
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index 49d9dcaeca49..7cd9749dc21d 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c | |||
@@ -37,6 +37,8 @@ static ssize_t mmc_type_show(struct device *dev, | |||
37 | return sprintf(buf, "SD\n"); | 37 | return sprintf(buf, "SD\n"); |
38 | case MMC_TYPE_SDIO: | 38 | case MMC_TYPE_SDIO: |
39 | return sprintf(buf, "SDIO\n"); | 39 | return sprintf(buf, "SDIO\n"); |
40 | case MMC_TYPE_SD_COMBO: | ||
41 | return sprintf(buf, "SDcombo\n"); | ||
40 | default: | 42 | default: |
41 | return -EFAULT; | 43 | return -EFAULT; |
42 | } | 44 | } |
@@ -74,6 +76,9 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
74 | case MMC_TYPE_SDIO: | 76 | case MMC_TYPE_SDIO: |
75 | type = "SDIO"; | 77 | type = "SDIO"; |
76 | break; | 78 | break; |
79 | case MMC_TYPE_SD_COMBO: | ||
80 | type = "SDcombo"; | ||
81 | break; | ||
77 | default: | 82 | default: |
78 | type = NULL; | 83 | type = NULL; |
79 | } | 84 | } |
@@ -239,6 +244,10 @@ int mmc_add_card(struct mmc_card *card) | |||
239 | case MMC_TYPE_SDIO: | 244 | case MMC_TYPE_SDIO: |
240 | type = "SDIO"; | 245 | type = "SDIO"; |
241 | break; | 246 | break; |
247 | case MMC_TYPE_SD_COMBO: | ||
248 | type = "SD-combo"; | ||
249 | if (mmc_card_blockaddr(card)) | ||
250 | type = "SDHC-combo"; | ||
242 | default: | 251 | default: |
243 | type = "?"; | 252 | type = "?"; |
244 | break; | 253 | break; |
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 569e94da844c..5db49b124ffa 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c | |||
@@ -1050,6 +1050,352 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay) | |||
1050 | 1050 | ||
1051 | EXPORT_SYMBOL(mmc_detect_change); | 1051 | EXPORT_SYMBOL(mmc_detect_change); |
1052 | 1052 | ||
1053 | void mmc_init_erase(struct mmc_card *card) | ||
1054 | { | ||
1055 | unsigned int sz; | ||
1056 | |||
1057 | if (is_power_of_2(card->erase_size)) | ||
1058 | card->erase_shift = ffs(card->erase_size) - 1; | ||
1059 | else | ||
1060 | card->erase_shift = 0; | ||
1061 | |||
1062 | /* | ||
1063 | * It is possible to erase an arbitrarily large area of an SD or MMC | ||
1064 | * card. That is not desirable because it can take a long time | ||
1065 | * (minutes) potentially delaying more important I/O, and also the | ||
1066 | * timeout calculations become increasingly hugely over-estimated. | ||
1067 | * Consequently, 'pref_erase' is defined as a guide to limit erases | ||
1068 | * to that size and alignment. | ||
1069 | * | ||
1070 | * For SD cards that define Allocation Unit size, limit erases to one | ||
1071 | * Allocation Unit at a time. For MMC cards that define High Capacity | ||
1072 | * Erase Size, whether it is switched on or not, limit to that size. | ||
1073 | * Otherwise just have a stab at a good value. For modern cards it | ||
1074 | * will end up being 4MiB. Note that if the value is too small, it | ||
1075 | * can end up taking longer to erase. | ||
1076 | */ | ||
1077 | if (mmc_card_sd(card) && card->ssr.au) { | ||
1078 | card->pref_erase = card->ssr.au; | ||
1079 | card->erase_shift = ffs(card->ssr.au) - 1; | ||
1080 | } else if (card->ext_csd.hc_erase_size) { | ||
1081 | card->pref_erase = card->ext_csd.hc_erase_size; | ||
1082 | } else { | ||
1083 | sz = (card->csd.capacity << (card->csd.read_blkbits - 9)) >> 11; | ||
1084 | if (sz < 128) | ||
1085 | card->pref_erase = 512 * 1024 / 512; | ||
1086 | else if (sz < 512) | ||
1087 | card->pref_erase = 1024 * 1024 / 512; | ||
1088 | else if (sz < 1024) | ||
1089 | card->pref_erase = 2 * 1024 * 1024 / 512; | ||
1090 | else | ||
1091 | card->pref_erase = 4 * 1024 * 1024 / 512; | ||
1092 | if (card->pref_erase < card->erase_size) | ||
1093 | card->pref_erase = card->erase_size; | ||
1094 | else { | ||
1095 | sz = card->pref_erase % card->erase_size; | ||
1096 | if (sz) | ||
1097 | card->pref_erase += card->erase_size - sz; | ||
1098 | } | ||
1099 | } | ||
1100 | } | ||
1101 | |||
1102 | static void mmc_set_mmc_erase_timeout(struct mmc_card *card, | ||
1103 | struct mmc_command *cmd, | ||
1104 | unsigned int arg, unsigned int qty) | ||
1105 | { | ||
1106 | unsigned int erase_timeout; | ||
1107 | |||
1108 | if (card->ext_csd.erase_group_def & 1) { | ||
1109 | /* High Capacity Erase Group Size uses HC timeouts */ | ||
1110 | if (arg == MMC_TRIM_ARG) | ||
1111 | erase_timeout = card->ext_csd.trim_timeout; | ||
1112 | else | ||
1113 | erase_timeout = card->ext_csd.hc_erase_timeout; | ||
1114 | } else { | ||
1115 | /* CSD Erase Group Size uses write timeout */ | ||
1116 | unsigned int mult = (10 << card->csd.r2w_factor); | ||
1117 | unsigned int timeout_clks = card->csd.tacc_clks * mult; | ||
1118 | unsigned int timeout_us; | ||
1119 | |||
1120 | /* Avoid overflow: e.g. tacc_ns=80000000 mult=1280 */ | ||
1121 | if (card->csd.tacc_ns < 1000000) | ||
1122 | timeout_us = (card->csd.tacc_ns * mult) / 1000; | ||
1123 | else | ||
1124 | timeout_us = (card->csd.tacc_ns / 1000) * mult; | ||
1125 | |||
1126 | /* | ||
1127 | * ios.clock is only a target. The real clock rate might be | ||
1128 | * less but not that much less, so fudge it by multiplying by 2. | ||
1129 | */ | ||
1130 | timeout_clks <<= 1; | ||
1131 | timeout_us += (timeout_clks * 1000) / | ||
1132 | (card->host->ios.clock / 1000); | ||
1133 | |||
1134 | erase_timeout = timeout_us / 1000; | ||
1135 | |||
1136 | /* | ||
1137 | * Theoretically, the calculation could underflow so round up | ||
1138 | * to 1ms in that case. | ||
1139 | */ | ||
1140 | if (!erase_timeout) | ||
1141 | erase_timeout = 1; | ||
1142 | } | ||
1143 | |||
1144 | /* Multiplier for secure operations */ | ||
1145 | if (arg & MMC_SECURE_ARGS) { | ||
1146 | if (arg == MMC_SECURE_ERASE_ARG) | ||
1147 | erase_timeout *= card->ext_csd.sec_erase_mult; | ||
1148 | else | ||
1149 | erase_timeout *= card->ext_csd.sec_trim_mult; | ||
1150 | } | ||
1151 | |||
1152 | erase_timeout *= qty; | ||
1153 | |||
1154 | /* | ||
1155 | * Ensure at least a 1 second timeout for SPI as per | ||
1156 | * 'mmc_set_data_timeout()' | ||
1157 | */ | ||
1158 | if (mmc_host_is_spi(card->host) && erase_timeout < 1000) | ||
1159 | erase_timeout = 1000; | ||
1160 | |||
1161 | cmd->erase_timeout = erase_timeout; | ||
1162 | } | ||
1163 | |||
1164 | static void mmc_set_sd_erase_timeout(struct mmc_card *card, | ||
1165 | struct mmc_command *cmd, unsigned int arg, | ||
1166 | unsigned int qty) | ||
1167 | { | ||
1168 | if (card->ssr.erase_timeout) { | ||
1169 | /* Erase timeout specified in SD Status Register (SSR) */ | ||
1170 | cmd->erase_timeout = card->ssr.erase_timeout * qty + | ||
1171 | card->ssr.erase_offset; | ||
1172 | } else { | ||
1173 | /* | ||
1174 | * Erase timeout not specified in SD Status Register (SSR) so | ||
1175 | * use 250ms per write block. | ||
1176 | */ | ||
1177 | cmd->erase_timeout = 250 * qty; | ||
1178 | } | ||
1179 | |||
1180 | /* Must not be less than 1 second */ | ||
1181 | if (cmd->erase_timeout < 1000) | ||
1182 | cmd->erase_timeout = 1000; | ||
1183 | } | ||
1184 | |||
1185 | static void mmc_set_erase_timeout(struct mmc_card *card, | ||
1186 | struct mmc_command *cmd, unsigned int arg, | ||
1187 | unsigned int qty) | ||
1188 | { | ||
1189 | if (mmc_card_sd(card)) | ||
1190 | mmc_set_sd_erase_timeout(card, cmd, arg, qty); | ||
1191 | else | ||
1192 | mmc_set_mmc_erase_timeout(card, cmd, arg, qty); | ||
1193 | } | ||
1194 | |||
1195 | static int mmc_do_erase(struct mmc_card *card, unsigned int from, | ||
1196 | unsigned int to, unsigned int arg) | ||
1197 | { | ||
1198 | struct mmc_command cmd; | ||
1199 | unsigned int qty = 0; | ||
1200 | int err; | ||
1201 | |||
1202 | /* | ||
1203 | * qty is used to calculate the erase timeout which depends on how many | ||
1204 | * erase groups (or allocation units in SD terminology) are affected. | ||
1205 | * We count erasing part of an erase group as one erase group. | ||
1206 | * For SD, the allocation units are always a power of 2. For MMC, the | ||
1207 | * erase group size is almost certainly also power of 2, but it does not | ||
1208 | * seem to insist on that in the JEDEC standard, so we fall back to | ||
1209 | * division in that case. SD may not specify an allocation unit size, | ||
1210 | * in which case the timeout is based on the number of write blocks. | ||
1211 | * | ||
1212 | * Note that the timeout for secure trim 2 will only be correct if the | ||
1213 | * number of erase groups specified is the same as the total of all | ||
1214 | * preceding secure trim 1 commands. Since the power may have been | ||
1215 | * lost since the secure trim 1 commands occurred, it is generally | ||
1216 | * impossible to calculate the secure trim 2 timeout correctly. | ||
1217 | */ | ||
1218 | if (card->erase_shift) | ||
1219 | qty += ((to >> card->erase_shift) - | ||
1220 | (from >> card->erase_shift)) + 1; | ||
1221 | else if (mmc_card_sd(card)) | ||
1222 | qty += to - from + 1; | ||
1223 | else | ||
1224 | qty += ((to / card->erase_size) - | ||
1225 | (from / card->erase_size)) + 1; | ||
1226 | |||
1227 | if (!mmc_card_blockaddr(card)) { | ||
1228 | from <<= 9; | ||
1229 | to <<= 9; | ||
1230 | } | ||
1231 | |||
1232 | memset(&cmd, 0, sizeof(struct mmc_command)); | ||
1233 | if (mmc_card_sd(card)) | ||
1234 | cmd.opcode = SD_ERASE_WR_BLK_START; | ||
1235 | else | ||
1236 | cmd.opcode = MMC_ERASE_GROUP_START; | ||
1237 | cmd.arg = from; | ||
1238 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; | ||
1239 | err = mmc_wait_for_cmd(card->host, &cmd, 0); | ||
1240 | if (err) { | ||
1241 | printk(KERN_ERR "mmc_erase: group start error %d, " | ||
1242 | "status %#x\n", err, cmd.resp[0]); | ||
1243 | err = -EINVAL; | ||
1244 | goto out; | ||
1245 | } | ||
1246 | |||
1247 | memset(&cmd, 0, sizeof(struct mmc_command)); | ||
1248 | if (mmc_card_sd(card)) | ||
1249 | cmd.opcode = SD_ERASE_WR_BLK_END; | ||
1250 | else | ||
1251 | cmd.opcode = MMC_ERASE_GROUP_END; | ||
1252 | cmd.arg = to; | ||
1253 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; | ||
1254 | err = mmc_wait_for_cmd(card->host, &cmd, 0); | ||
1255 | if (err) { | ||
1256 | printk(KERN_ERR "mmc_erase: group end error %d, status %#x\n", | ||
1257 | err, cmd.resp[0]); | ||
1258 | err = -EINVAL; | ||
1259 | goto out; | ||
1260 | } | ||
1261 | |||
1262 | memset(&cmd, 0, sizeof(struct mmc_command)); | ||
1263 | cmd.opcode = MMC_ERASE; | ||
1264 | cmd.arg = arg; | ||
1265 | cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; | ||
1266 | mmc_set_erase_timeout(card, &cmd, arg, qty); | ||
1267 | err = mmc_wait_for_cmd(card->host, &cmd, 0); | ||
1268 | if (err) { | ||
1269 | printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n", | ||
1270 | err, cmd.resp[0]); | ||
1271 | err = -EIO; | ||
1272 | goto out; | ||
1273 | } | ||
1274 | |||
1275 | if (mmc_host_is_spi(card->host)) | ||
1276 | goto out; | ||
1277 | |||
1278 | do { | ||
1279 | memset(&cmd, 0, sizeof(struct mmc_command)); | ||
1280 | cmd.opcode = MMC_SEND_STATUS; | ||
1281 | cmd.arg = card->rca << 16; | ||
1282 | cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; | ||
1283 | /* Do not retry else we can't see errors */ | ||
1284 | err = mmc_wait_for_cmd(card->host, &cmd, 0); | ||
1285 | if (err || (cmd.resp[0] & 0xFDF92000)) { | ||
1286 | printk(KERN_ERR "error %d requesting status %#x\n", | ||
1287 | err, cmd.resp[0]); | ||
1288 | err = -EIO; | ||
1289 | goto out; | ||
1290 | } | ||
1291 | } while (!(cmd.resp[0] & R1_READY_FOR_DATA) || | ||
1292 | R1_CURRENT_STATE(cmd.resp[0]) == 7); | ||
1293 | out: | ||
1294 | return err; | ||
1295 | } | ||
1296 | |||
1297 | /** | ||
1298 | * mmc_erase - erase sectors. | ||
1299 | * @card: card to erase | ||
1300 | * @from: first sector to erase | ||
1301 | * @nr: number of sectors to erase | ||
1302 | * @arg: erase command argument (SD supports only %MMC_ERASE_ARG) | ||
1303 | * | ||
1304 | * Caller must claim host before calling this function. | ||
1305 | */ | ||
1306 | int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, | ||
1307 | unsigned int arg) | ||
1308 | { | ||
1309 | unsigned int rem, to = from + nr; | ||
1310 | |||
1311 | if (!(card->host->caps & MMC_CAP_ERASE) || | ||
1312 | !(card->csd.cmdclass & CCC_ERASE)) | ||
1313 | return -EOPNOTSUPP; | ||
1314 | |||
1315 | if (!card->erase_size) | ||
1316 | return -EOPNOTSUPP; | ||
1317 | |||
1318 | if (mmc_card_sd(card) && arg != MMC_ERASE_ARG) | ||
1319 | return -EOPNOTSUPP; | ||
1320 | |||
1321 | if ((arg & MMC_SECURE_ARGS) && | ||
1322 | !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)) | ||
1323 | return -EOPNOTSUPP; | ||
1324 | |||
1325 | if ((arg & MMC_TRIM_ARGS) && | ||
1326 | !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)) | ||
1327 | return -EOPNOTSUPP; | ||
1328 | |||
1329 | if (arg == MMC_SECURE_ERASE_ARG) { | ||
1330 | if (from % card->erase_size || nr % card->erase_size) | ||
1331 | return -EINVAL; | ||
1332 | } | ||
1333 | |||
1334 | if (arg == MMC_ERASE_ARG) { | ||
1335 | rem = from % card->erase_size; | ||
1336 | if (rem) { | ||
1337 | rem = card->erase_size - rem; | ||
1338 | from += rem; | ||
1339 | if (nr > rem) | ||
1340 | nr -= rem; | ||
1341 | else | ||
1342 | return 0; | ||
1343 | } | ||
1344 | rem = nr % card->erase_size; | ||
1345 | if (rem) | ||
1346 | nr -= rem; | ||
1347 | } | ||
1348 | |||
1349 | if (nr == 0) | ||
1350 | return 0; | ||
1351 | |||
1352 | to = from + nr; | ||
1353 | |||
1354 | if (to <= from) | ||
1355 | return -EINVAL; | ||
1356 | |||
1357 | /* 'from' and 'to' are inclusive */ | ||
1358 | to -= 1; | ||
1359 | |||
1360 | return mmc_do_erase(card, from, to, arg); | ||
1361 | } | ||
1362 | EXPORT_SYMBOL(mmc_erase); | ||
1363 | |||
1364 | int mmc_can_erase(struct mmc_card *card) | ||
1365 | { | ||
1366 | if ((card->host->caps & MMC_CAP_ERASE) && | ||
1367 | (card->csd.cmdclass & CCC_ERASE) && card->erase_size) | ||
1368 | return 1; | ||
1369 | return 0; | ||
1370 | } | ||
1371 | EXPORT_SYMBOL(mmc_can_erase); | ||
1372 | |||
1373 | int mmc_can_trim(struct mmc_card *card) | ||
1374 | { | ||
1375 | if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN) | ||
1376 | return 1; | ||
1377 | return 0; | ||
1378 | } | ||
1379 | EXPORT_SYMBOL(mmc_can_trim); | ||
1380 | |||
1381 | int mmc_can_secure_erase_trim(struct mmc_card *card) | ||
1382 | { | ||
1383 | if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN) | ||
1384 | return 1; | ||
1385 | return 0; | ||
1386 | } | ||
1387 | EXPORT_SYMBOL(mmc_can_secure_erase_trim); | ||
1388 | |||
1389 | int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from, | ||
1390 | unsigned int nr) | ||
1391 | { | ||
1392 | if (!card->erase_size) | ||
1393 | return 0; | ||
1394 | if (from % card->erase_size || nr % card->erase_size) | ||
1395 | return 0; | ||
1396 | return 1; | ||
1397 | } | ||
1398 | EXPORT_SYMBOL(mmc_erase_group_aligned); | ||
1053 | 1399 | ||
1054 | void mmc_rescan(struct work_struct *work) | 1400 | void mmc_rescan(struct work_struct *work) |
1055 | { | 1401 | { |
@@ -1057,6 +1403,17 @@ void mmc_rescan(struct work_struct *work) | |||
1057 | container_of(work, struct mmc_host, detect.work); | 1403 | container_of(work, struct mmc_host, detect.work); |
1058 | u32 ocr; | 1404 | u32 ocr; |
1059 | int err; | 1405 | int err; |
1406 | unsigned long flags; | ||
1407 | |||
1408 | spin_lock_irqsave(&host->lock, flags); | ||
1409 | |||
1410 | if (host->rescan_disable) { | ||
1411 | spin_unlock_irqrestore(&host->lock, flags); | ||
1412 | return; | ||
1413 | } | ||
1414 | |||
1415 | spin_unlock_irqrestore(&host->lock, flags); | ||
1416 | |||
1060 | 1417 | ||
1061 | mmc_bus_get(host); | 1418 | mmc_bus_get(host); |
1062 | 1419 | ||
@@ -1099,8 +1456,15 @@ void mmc_rescan(struct work_struct *work) | |||
1099 | */ | 1456 | */ |
1100 | err = mmc_send_io_op_cond(host, 0, &ocr); | 1457 | err = mmc_send_io_op_cond(host, 0, &ocr); |
1101 | if (!err) { | 1458 | if (!err) { |
1102 | if (mmc_attach_sdio(host, ocr)) | 1459 | if (mmc_attach_sdio(host, ocr)) { |
1103 | mmc_power_off(host); | 1460 | mmc_claim_host(host); |
1461 | /* try SDMEM (but not MMC) even if SDIO is broken */ | ||
1462 | if (mmc_send_app_op_cond(host, 0, &ocr)) | ||
1463 | goto out_fail; | ||
1464 | |||
1465 | if (mmc_attach_sd(host, ocr)) | ||
1466 | mmc_power_off(host); | ||
1467 | } | ||
1104 | goto out; | 1468 | goto out; |
1105 | } | 1469 | } |
1106 | 1470 | ||
@@ -1124,6 +1488,7 @@ void mmc_rescan(struct work_struct *work) | |||
1124 | goto out; | 1488 | goto out; |
1125 | } | 1489 | } |
1126 | 1490 | ||
1491 | out_fail: | ||
1127 | mmc_release_host(host); | 1492 | mmc_release_host(host); |
1128 | mmc_power_off(host); | 1493 | mmc_power_off(host); |
1129 | 1494 | ||
@@ -1266,19 +1631,6 @@ int mmc_suspend_host(struct mmc_host *host) | |||
1266 | if (host->bus_ops && !host->bus_dead) { | 1631 | if (host->bus_ops && !host->bus_dead) { |
1267 | if (host->bus_ops->suspend) | 1632 | if (host->bus_ops->suspend) |
1268 | err = host->bus_ops->suspend(host); | 1633 | err = host->bus_ops->suspend(host); |
1269 | if (err == -ENOSYS || !host->bus_ops->resume) { | ||
1270 | /* | ||
1271 | * We simply "remove" the card in this case. | ||
1272 | * It will be redetected on resume. | ||
1273 | */ | ||
1274 | if (host->bus_ops->remove) | ||
1275 | host->bus_ops->remove(host); | ||
1276 | mmc_claim_host(host); | ||
1277 | mmc_detach_bus(host); | ||
1278 | mmc_release_host(host); | ||
1279 | host->pm_flags = 0; | ||
1280 | err = 0; | ||
1281 | } | ||
1282 | } | 1634 | } |
1283 | mmc_bus_put(host); | 1635 | mmc_bus_put(host); |
1284 | 1636 | ||
@@ -1310,28 +1662,61 @@ int mmc_resume_host(struct mmc_host *host) | |||
1310 | printk(KERN_WARNING "%s: error %d during resume " | 1662 | printk(KERN_WARNING "%s: error %d during resume " |
1311 | "(card was removed?)\n", | 1663 | "(card was removed?)\n", |
1312 | mmc_hostname(host), err); | 1664 | mmc_hostname(host), err); |
1313 | if (host->bus_ops->remove) | ||
1314 | host->bus_ops->remove(host); | ||
1315 | mmc_claim_host(host); | ||
1316 | mmc_detach_bus(host); | ||
1317 | mmc_release_host(host); | ||
1318 | /* no need to bother upper layers */ | ||
1319 | err = 0; | 1665 | err = 0; |
1320 | } | 1666 | } |
1321 | } | 1667 | } |
1322 | mmc_bus_put(host); | 1668 | mmc_bus_put(host); |
1323 | 1669 | ||
1324 | /* | ||
1325 | * We add a slight delay here so that resume can progress | ||
1326 | * in parallel. | ||
1327 | */ | ||
1328 | mmc_detect_change(host, 1); | ||
1329 | |||
1330 | return err; | 1670 | return err; |
1331 | } | 1671 | } |
1332 | |||
1333 | EXPORT_SYMBOL(mmc_resume_host); | 1672 | EXPORT_SYMBOL(mmc_resume_host); |
1334 | 1673 | ||
1674 | /* Do the card removal on suspend if card is assumed removeable | ||
1675 | * Do that in pm notifier while userspace isn't yet frozen, so we will be able | ||
1676 | to sync the card. | ||
1677 | */ | ||
1678 | int mmc_pm_notify(struct notifier_block *notify_block, | ||
1679 | unsigned long mode, void *unused) | ||
1680 | { | ||
1681 | struct mmc_host *host = container_of( | ||
1682 | notify_block, struct mmc_host, pm_notify); | ||
1683 | unsigned long flags; | ||
1684 | |||
1685 | |||
1686 | switch (mode) { | ||
1687 | case PM_HIBERNATION_PREPARE: | ||
1688 | case PM_SUSPEND_PREPARE: | ||
1689 | |||
1690 | spin_lock_irqsave(&host->lock, flags); | ||
1691 | host->rescan_disable = 1; | ||
1692 | spin_unlock_irqrestore(&host->lock, flags); | ||
1693 | cancel_delayed_work_sync(&host->detect); | ||
1694 | |||
1695 | if (!host->bus_ops || host->bus_ops->suspend) | ||
1696 | break; | ||
1697 | |||
1698 | mmc_claim_host(host); | ||
1699 | |||
1700 | if (host->bus_ops->remove) | ||
1701 | host->bus_ops->remove(host); | ||
1702 | |||
1703 | mmc_detach_bus(host); | ||
1704 | mmc_release_host(host); | ||
1705 | host->pm_flags = 0; | ||
1706 | break; | ||
1707 | |||
1708 | case PM_POST_SUSPEND: | ||
1709 | case PM_POST_HIBERNATION: | ||
1710 | |||
1711 | spin_lock_irqsave(&host->lock, flags); | ||
1712 | host->rescan_disable = 0; | ||
1713 | spin_unlock_irqrestore(&host->lock, flags); | ||
1714 | mmc_detect_change(host, 0); | ||
1715 | |||
1716 | } | ||
1717 | |||
1718 | return 0; | ||
1719 | } | ||
1335 | #endif | 1720 | #endif |
1336 | 1721 | ||
1337 | static int __init mmc_init(void) | 1722 | static int __init mmc_init(void) |
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index a811c52a1659..9d9eef50e5d1 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h | |||
@@ -29,6 +29,8 @@ struct mmc_bus_ops { | |||
29 | void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); | 29 | void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); |
30 | void mmc_detach_bus(struct mmc_host *host); | 30 | void mmc_detach_bus(struct mmc_host *host); |
31 | 31 | ||
32 | void mmc_init_erase(struct mmc_card *card); | ||
33 | |||
32 | void mmc_set_chip_select(struct mmc_host *host, int mode); | 34 | void mmc_set_chip_select(struct mmc_host *host, int mode); |
33 | void mmc_set_clock(struct mmc_host *host, unsigned int hz); | 35 | void mmc_set_clock(struct mmc_host *host, unsigned int hz); |
34 | void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode); | 36 | void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode); |
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 47353909e345..0efe631e50ca 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/pagemap.h> | 17 | #include <linux/pagemap.h> |
18 | #include <linux/leds.h> | 18 | #include <linux/leds.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include <linux/suspend.h> | ||
20 | 21 | ||
21 | #include <linux/mmc/host.h> | 22 | #include <linux/mmc/host.h> |
22 | 23 | ||
@@ -85,6 +86,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) | |||
85 | init_waitqueue_head(&host->wq); | 86 | init_waitqueue_head(&host->wq); |
86 | INIT_DELAYED_WORK(&host->detect, mmc_rescan); | 87 | INIT_DELAYED_WORK(&host->detect, mmc_rescan); |
87 | INIT_DELAYED_WORK_DEFERRABLE(&host->disable, mmc_host_deeper_disable); | 88 | INIT_DELAYED_WORK_DEFERRABLE(&host->disable, mmc_host_deeper_disable); |
89 | host->pm_notify.notifier_call = mmc_pm_notify; | ||
88 | 90 | ||
89 | /* | 91 | /* |
90 | * By default, hosts do not support SGIO or large requests. | 92 | * By default, hosts do not support SGIO or large requests. |
@@ -133,6 +135,7 @@ int mmc_add_host(struct mmc_host *host) | |||
133 | #endif | 135 | #endif |
134 | 136 | ||
135 | mmc_start_host(host); | 137 | mmc_start_host(host); |
138 | register_pm_notifier(&host->pm_notify); | ||
136 | 139 | ||
137 | return 0; | 140 | return 0; |
138 | } | 141 | } |
@@ -149,6 +152,7 @@ EXPORT_SYMBOL(mmc_add_host); | |||
149 | */ | 152 | */ |
150 | void mmc_remove_host(struct mmc_host *host) | 153 | void mmc_remove_host(struct mmc_host *host) |
151 | { | 154 | { |
155 | unregister_pm_notifier(&host->pm_notify); | ||
152 | mmc_stop_host(host); | 156 | mmc_stop_host(host); |
153 | 157 | ||
154 | #ifdef CONFIG_DEBUG_FS | 158 | #ifdef CONFIG_DEBUG_FS |
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 89f7a25b7ac1..6909a54c39be 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c | |||
@@ -108,23 +108,34 @@ static int mmc_decode_cid(struct mmc_card *card) | |||
108 | return 0; | 108 | return 0; |
109 | } | 109 | } |
110 | 110 | ||
111 | static void mmc_set_erase_size(struct mmc_card *card) | ||
112 | { | ||
113 | if (card->ext_csd.erase_group_def & 1) | ||
114 | card->erase_size = card->ext_csd.hc_erase_size; | ||
115 | else | ||
116 | card->erase_size = card->csd.erase_size; | ||
117 | |||
118 | mmc_init_erase(card); | ||
119 | } | ||
120 | |||
111 | /* | 121 | /* |
112 | * Given a 128-bit response, decode to our card CSD structure. | 122 | * Given a 128-bit response, decode to our card CSD structure. |
113 | */ | 123 | */ |
114 | static int mmc_decode_csd(struct mmc_card *card) | 124 | static int mmc_decode_csd(struct mmc_card *card) |
115 | { | 125 | { |
116 | struct mmc_csd *csd = &card->csd; | 126 | struct mmc_csd *csd = &card->csd; |
117 | unsigned int e, m, csd_struct; | 127 | unsigned int e, m, a, b; |
118 | u32 *resp = card->raw_csd; | 128 | u32 *resp = card->raw_csd; |
119 | 129 | ||
120 | /* | 130 | /* |
121 | * We only understand CSD structure v1.1 and v1.2. | 131 | * We only understand CSD structure v1.1 and v1.2. |
122 | * v1.2 has extra information in bits 15, 11 and 10. | 132 | * v1.2 has extra information in bits 15, 11 and 10. |
133 | * We also support eMMC v4.4 & v4.41. | ||
123 | */ | 134 | */ |
124 | csd_struct = UNSTUFF_BITS(resp, 126, 2); | 135 | csd->structure = UNSTUFF_BITS(resp, 126, 2); |
125 | if (csd_struct != 1 && csd_struct != 2) { | 136 | if (csd->structure == 0) { |
126 | printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", | 137 | printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", |
127 | mmc_hostname(card->host), csd_struct); | 138 | mmc_hostname(card->host), csd->structure); |
128 | return -EINVAL; | 139 | return -EINVAL; |
129 | } | 140 | } |
130 | 141 | ||
@@ -151,6 +162,13 @@ static int mmc_decode_csd(struct mmc_card *card) | |||
151 | csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); | 162 | csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); |
152 | csd->write_partial = UNSTUFF_BITS(resp, 21, 1); | 163 | csd->write_partial = UNSTUFF_BITS(resp, 21, 1); |
153 | 164 | ||
165 | if (csd->write_blkbits >= 9) { | ||
166 | a = UNSTUFF_BITS(resp, 42, 5); | ||
167 | b = UNSTUFF_BITS(resp, 37, 5); | ||
168 | csd->erase_size = (a + 1) * (b + 1); | ||
169 | csd->erase_size <<= csd->write_blkbits - 9; | ||
170 | } | ||
171 | |||
154 | return 0; | 172 | return 0; |
155 | } | 173 | } |
156 | 174 | ||
@@ -207,11 +225,22 @@ static int mmc_read_ext_csd(struct mmc_card *card) | |||
207 | goto out; | 225 | goto out; |
208 | } | 226 | } |
209 | 227 | ||
228 | /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */ | ||
229 | if (card->csd.structure == 3) { | ||
230 | int ext_csd_struct = ext_csd[EXT_CSD_STRUCTURE]; | ||
231 | if (ext_csd_struct > 2) { | ||
232 | printk(KERN_ERR "%s: unrecognised EXT_CSD structure " | ||
233 | "version %d\n", mmc_hostname(card->host), | ||
234 | ext_csd_struct); | ||
235 | err = -EINVAL; | ||
236 | goto out; | ||
237 | } | ||
238 | } | ||
239 | |||
210 | card->ext_csd.rev = ext_csd[EXT_CSD_REV]; | 240 | card->ext_csd.rev = ext_csd[EXT_CSD_REV]; |
211 | if (card->ext_csd.rev > 5) { | 241 | if (card->ext_csd.rev > 5) { |
212 | printk(KERN_ERR "%s: unrecognised EXT_CSD structure " | 242 | printk(KERN_ERR "%s: unrecognised EXT_CSD revision %d\n", |
213 | "version %d\n", mmc_hostname(card->host), | 243 | mmc_hostname(card->host), card->ext_csd.rev); |
214 | card->ext_csd.rev); | ||
215 | err = -EINVAL; | 244 | err = -EINVAL; |
216 | goto out; | 245 | goto out; |
217 | } | 246 | } |
@@ -222,7 +251,9 @@ static int mmc_read_ext_csd(struct mmc_card *card) | |||
222 | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | | 251 | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | |
223 | ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | | 252 | ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | |
224 | ext_csd[EXT_CSD_SEC_CNT + 3] << 24; | 253 | ext_csd[EXT_CSD_SEC_CNT + 3] << 24; |
225 | if (card->ext_csd.sectors) | 254 | |
255 | /* Cards with density > 2GiB are sector addressed */ | ||
256 | if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) | ||
226 | mmc_card_set_blockaddr(card); | 257 | mmc_card_set_blockaddr(card); |
227 | } | 258 | } |
228 | 259 | ||
@@ -247,8 +278,30 @@ static int mmc_read_ext_csd(struct mmc_card *card) | |||
247 | if (sa_shift > 0 && sa_shift <= 0x17) | 278 | if (sa_shift > 0 && sa_shift <= 0x17) |
248 | card->ext_csd.sa_timeout = | 279 | card->ext_csd.sa_timeout = |
249 | 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; | 280 | 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; |
281 | card->ext_csd.erase_group_def = | ||
282 | ext_csd[EXT_CSD_ERASE_GROUP_DEF]; | ||
283 | card->ext_csd.hc_erase_timeout = 300 * | ||
284 | ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; | ||
285 | card->ext_csd.hc_erase_size = | ||
286 | ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10; | ||
250 | } | 287 | } |
251 | 288 | ||
289 | if (card->ext_csd.rev >= 4) { | ||
290 | card->ext_csd.sec_trim_mult = | ||
291 | ext_csd[EXT_CSD_SEC_TRIM_MULT]; | ||
292 | card->ext_csd.sec_erase_mult = | ||
293 | ext_csd[EXT_CSD_SEC_ERASE_MULT]; | ||
294 | card->ext_csd.sec_feature_support = | ||
295 | ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; | ||
296 | card->ext_csd.trim_timeout = 300 * | ||
297 | ext_csd[EXT_CSD_TRIM_MULT]; | ||
298 | } | ||
299 | |||
300 | if (ext_csd[EXT_CSD_ERASED_MEM_CONT]) | ||
301 | card->erased_byte = 0xFF; | ||
302 | else | ||
303 | card->erased_byte = 0x0; | ||
304 | |||
252 | out: | 305 | out: |
253 | kfree(ext_csd); | 306 | kfree(ext_csd); |
254 | 307 | ||
@@ -260,6 +313,8 @@ MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], | |||
260 | MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], | 313 | MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], |
261 | card->raw_csd[2], card->raw_csd[3]); | 314 | card->raw_csd[2], card->raw_csd[3]); |
262 | MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); | 315 | MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); |
316 | MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); | ||
317 | MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); | ||
263 | MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); | 318 | MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); |
264 | MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); | 319 | MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); |
265 | MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); | 320 | MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); |
@@ -271,6 +326,8 @@ static struct attribute *mmc_std_attrs[] = { | |||
271 | &dev_attr_cid.attr, | 326 | &dev_attr_cid.attr, |
272 | &dev_attr_csd.attr, | 327 | &dev_attr_csd.attr, |
273 | &dev_attr_date.attr, | 328 | &dev_attr_date.attr, |
329 | &dev_attr_erase_size.attr, | ||
330 | &dev_attr_preferred_erase_size.attr, | ||
274 | &dev_attr_fwrev.attr, | 331 | &dev_attr_fwrev.attr, |
275 | &dev_attr_hwrev.attr, | 332 | &dev_attr_hwrev.attr, |
276 | &dev_attr_manfid.attr, | 333 | &dev_attr_manfid.attr, |
@@ -407,6 +464,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
407 | err = mmc_read_ext_csd(card); | 464 | err = mmc_read_ext_csd(card); |
408 | if (err) | 465 | if (err) |
409 | goto free_card; | 466 | goto free_card; |
467 | /* Erase size depends on CSD and Extended CSD */ | ||
468 | mmc_set_erase_size(card); | ||
410 | } | 469 | } |
411 | 470 | ||
412 | /* | 471 | /* |
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 5eac21df4809..0f5241085557 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c | |||
@@ -59,7 +59,7 @@ static const unsigned int tacc_mant[] = { | |||
59 | /* | 59 | /* |
60 | * Given the decoded CSD structure, decode the raw CID to our CID structure. | 60 | * Given the decoded CSD structure, decode the raw CID to our CID structure. |
61 | */ | 61 | */ |
62 | static void mmc_decode_cid(struct mmc_card *card) | 62 | void mmc_decode_cid(struct mmc_card *card) |
63 | { | 63 | { |
64 | u32 *resp = card->raw_cid; | 64 | u32 *resp = card->raw_cid; |
65 | 65 | ||
@@ -119,6 +119,13 @@ static int mmc_decode_csd(struct mmc_card *card) | |||
119 | csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); | 119 | csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); |
120 | csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); | 120 | csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); |
121 | csd->write_partial = UNSTUFF_BITS(resp, 21, 1); | 121 | csd->write_partial = UNSTUFF_BITS(resp, 21, 1); |
122 | |||
123 | if (UNSTUFF_BITS(resp, 46, 1)) { | ||
124 | csd->erase_size = 1; | ||
125 | } else if (csd->write_blkbits >= 9) { | ||
126 | csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1; | ||
127 | csd->erase_size <<= csd->write_blkbits - 9; | ||
128 | } | ||
122 | break; | 129 | break; |
123 | case 1: | 130 | case 1: |
124 | /* | 131 | /* |
@@ -147,6 +154,7 @@ static int mmc_decode_csd(struct mmc_card *card) | |||
147 | csd->r2w_factor = 4; /* Unused */ | 154 | csd->r2w_factor = 4; /* Unused */ |
148 | csd->write_blkbits = 9; | 155 | csd->write_blkbits = 9; |
149 | csd->write_partial = 0; | 156 | csd->write_partial = 0; |
157 | csd->erase_size = 1; | ||
150 | break; | 158 | break; |
151 | default: | 159 | default: |
152 | printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", | 160 | printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", |
@@ -154,6 +162,8 @@ static int mmc_decode_csd(struct mmc_card *card) | |||
154 | return -EINVAL; | 162 | return -EINVAL; |
155 | } | 163 | } |
156 | 164 | ||
165 | card->erase_size = csd->erase_size; | ||
166 | |||
157 | return 0; | 167 | return 0; |
158 | } | 168 | } |
159 | 169 | ||
@@ -179,10 +189,68 @@ static int mmc_decode_scr(struct mmc_card *card) | |||
179 | scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); | 189 | scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); |
180 | scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); | 190 | scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); |
181 | 191 | ||
192 | if (UNSTUFF_BITS(resp, 55, 1)) | ||
193 | card->erased_byte = 0xFF; | ||
194 | else | ||
195 | card->erased_byte = 0x0; | ||
196 | |||
182 | return 0; | 197 | return 0; |
183 | } | 198 | } |
184 | 199 | ||
185 | /* | 200 | /* |
201 | * Fetch and process SD Status register. | ||
202 | */ | ||
203 | static int mmc_read_ssr(struct mmc_card *card) | ||
204 | { | ||
205 | unsigned int au, es, et, eo; | ||
206 | int err, i; | ||
207 | u32 *ssr; | ||
208 | |||
209 | if (!(card->csd.cmdclass & CCC_APP_SPEC)) { | ||
210 | printk(KERN_WARNING "%s: card lacks mandatory SD Status " | ||
211 | "function.\n", mmc_hostname(card->host)); | ||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | ssr = kmalloc(64, GFP_KERNEL); | ||
216 | if (!ssr) | ||
217 | return -ENOMEM; | ||
218 | |||
219 | err = mmc_app_sd_status(card, ssr); | ||
220 | if (err) { | ||
221 | printk(KERN_WARNING "%s: problem reading SD Status " | ||
222 | "register.\n", mmc_hostname(card->host)); | ||
223 | err = 0; | ||
224 | goto out; | ||
225 | } | ||
226 | |||
227 | for (i = 0; i < 16; i++) | ||
228 | ssr[i] = be32_to_cpu(ssr[i]); | ||
229 | |||
230 | /* | ||
231 | * UNSTUFF_BITS only works with four u32s so we have to offset the | ||
232 | * bitfield positions accordingly. | ||
233 | */ | ||
234 | au = UNSTUFF_BITS(ssr, 428 - 384, 4); | ||
235 | if (au > 0 || au <= 9) { | ||
236 | card->ssr.au = 1 << (au + 4); | ||
237 | es = UNSTUFF_BITS(ssr, 408 - 384, 16); | ||
238 | et = UNSTUFF_BITS(ssr, 402 - 384, 6); | ||
239 | eo = UNSTUFF_BITS(ssr, 400 - 384, 2); | ||
240 | if (es && et) { | ||
241 | card->ssr.erase_timeout = (et * 1000) / es; | ||
242 | card->ssr.erase_offset = eo * 1000; | ||
243 | } | ||
244 | } else { | ||
245 | printk(KERN_WARNING "%s: SD Status: Invalid Allocation Unit " | ||
246 | "size.\n", mmc_hostname(card->host)); | ||
247 | } | ||
248 | out: | ||
249 | kfree(ssr); | ||
250 | return err; | ||
251 | } | ||
252 | |||
253 | /* | ||
186 | * Fetches and decodes switch information | 254 | * Fetches and decodes switch information |
187 | */ | 255 | */ |
188 | static int mmc_read_switch(struct mmc_card *card) | 256 | static int mmc_read_switch(struct mmc_card *card) |
@@ -238,7 +306,7 @@ out: | |||
238 | /* | 306 | /* |
239 | * Test if the card supports high-speed mode and, if so, switch to it. | 307 | * Test if the card supports high-speed mode and, if so, switch to it. |
240 | */ | 308 | */ |
241 | static int mmc_switch_hs(struct mmc_card *card) | 309 | int mmc_sd_switch_hs(struct mmc_card *card) |
242 | { | 310 | { |
243 | int err; | 311 | int err; |
244 | u8 *status; | 312 | u8 *status; |
@@ -272,9 +340,9 @@ static int mmc_switch_hs(struct mmc_card *card) | |||
272 | printk(KERN_WARNING "%s: Problem switching card " | 340 | printk(KERN_WARNING "%s: Problem switching card " |
273 | "into high-speed mode!\n", | 341 | "into high-speed mode!\n", |
274 | mmc_hostname(card->host)); | 342 | mmc_hostname(card->host)); |
343 | err = 0; | ||
275 | } else { | 344 | } else { |
276 | mmc_card_set_highspeed(card); | 345 | err = 1; |
277 | mmc_set_timing(card->host, MMC_TIMING_SD_HS); | ||
278 | } | 346 | } |
279 | 347 | ||
280 | out: | 348 | out: |
@@ -289,6 +357,8 @@ MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], | |||
289 | card->raw_csd[2], card->raw_csd[3]); | 357 | card->raw_csd[2], card->raw_csd[3]); |
290 | MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]); | 358 | MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]); |
291 | MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); | 359 | MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); |
360 | MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); | ||
361 | MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); | ||
292 | MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); | 362 | MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); |
293 | MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); | 363 | MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); |
294 | MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); | 364 | MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); |
@@ -302,6 +372,8 @@ static struct attribute *sd_std_attrs[] = { | |||
302 | &dev_attr_csd.attr, | 372 | &dev_attr_csd.attr, |
303 | &dev_attr_scr.attr, | 373 | &dev_attr_scr.attr, |
304 | &dev_attr_date.attr, | 374 | &dev_attr_date.attr, |
375 | &dev_attr_erase_size.attr, | ||
376 | &dev_attr_preferred_erase_size.attr, | ||
305 | &dev_attr_fwrev.attr, | 377 | &dev_attr_fwrev.attr, |
306 | &dev_attr_hwrev.attr, | 378 | &dev_attr_hwrev.attr, |
307 | &dev_attr_manfid.attr, | 379 | &dev_attr_manfid.attr, |
@@ -320,26 +392,16 @@ static const struct attribute_group *sd_attr_groups[] = { | |||
320 | NULL, | 392 | NULL, |
321 | }; | 393 | }; |
322 | 394 | ||
323 | static struct device_type sd_type = { | 395 | struct device_type sd_type = { |
324 | .groups = sd_attr_groups, | 396 | .groups = sd_attr_groups, |
325 | }; | 397 | }; |
326 | 398 | ||
327 | /* | 399 | /* |
328 | * Handle the detection and initialisation of a card. | 400 | * Fetch CID from card. |
329 | * | ||
330 | * In the case of a resume, "oldcard" will contain the card | ||
331 | * we're trying to reinitialise. | ||
332 | */ | 401 | */ |
333 | static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, | 402 | int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid) |
334 | struct mmc_card *oldcard) | ||
335 | { | 403 | { |
336 | struct mmc_card *card; | ||
337 | int err; | 404 | int err; |
338 | u32 cid[4]; | ||
339 | unsigned int max_dtr; | ||
340 | |||
341 | BUG_ON(!host); | ||
342 | WARN_ON(!host->claimed); | ||
343 | 405 | ||
344 | /* | 406 | /* |
345 | * Since we're changing the OCR value, we seem to | 407 | * Since we're changing the OCR value, we seem to |
@@ -361,92 +423,67 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, | |||
361 | 423 | ||
362 | err = mmc_send_app_op_cond(host, ocr, NULL); | 424 | err = mmc_send_app_op_cond(host, ocr, NULL); |
363 | if (err) | 425 | if (err) |
364 | goto err; | 426 | return err; |
365 | 427 | ||
366 | /* | ||
367 | * Fetch CID from card. | ||
368 | */ | ||
369 | if (mmc_host_is_spi(host)) | 428 | if (mmc_host_is_spi(host)) |
370 | err = mmc_send_cid(host, cid); | 429 | err = mmc_send_cid(host, cid); |
371 | else | 430 | else |
372 | err = mmc_all_send_cid(host, cid); | 431 | err = mmc_all_send_cid(host, cid); |
373 | if (err) | ||
374 | goto err; | ||
375 | 432 | ||
376 | if (oldcard) { | 433 | return err; |
377 | if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { | 434 | } |
378 | err = -ENOENT; | ||
379 | goto err; | ||
380 | } | ||
381 | |||
382 | card = oldcard; | ||
383 | } else { | ||
384 | /* | ||
385 | * Allocate card structure. | ||
386 | */ | ||
387 | card = mmc_alloc_card(host, &sd_type); | ||
388 | if (IS_ERR(card)) { | ||
389 | err = PTR_ERR(card); | ||
390 | goto err; | ||
391 | } | ||
392 | 435 | ||
393 | card->type = MMC_TYPE_SD; | 436 | int mmc_sd_get_csd(struct mmc_host *host, struct mmc_card *card) |
394 | memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); | 437 | { |
395 | } | 438 | int err; |
396 | 439 | ||
397 | /* | 440 | /* |
398 | * For native busses: get card RCA and quit open drain mode. | 441 | * Fetch CSD from card. |
399 | */ | 442 | */ |
400 | if (!mmc_host_is_spi(host)) { | 443 | err = mmc_send_csd(card, card->raw_csd); |
401 | err = mmc_send_relative_addr(host, &card->rca); | 444 | if (err) |
402 | if (err) | 445 | return err; |
403 | goto free_card; | ||
404 | 446 | ||
405 | mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); | 447 | err = mmc_decode_csd(card); |
406 | } | 448 | if (err) |
449 | return err; | ||
407 | 450 | ||
408 | if (!oldcard) { | 451 | return 0; |
452 | } | ||
453 | |||
454 | int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, | ||
455 | bool reinit) | ||
456 | { | ||
457 | int err; | ||
458 | |||
459 | if (!reinit) { | ||
409 | /* | 460 | /* |
410 | * Fetch CSD from card. | 461 | * Fetch SCR from card. |
411 | */ | 462 | */ |
412 | err = mmc_send_csd(card, card->raw_csd); | 463 | err = mmc_app_send_scr(card, card->raw_scr); |
413 | if (err) | ||
414 | goto free_card; | ||
415 | |||
416 | err = mmc_decode_csd(card); | ||
417 | if (err) | 464 | if (err) |
418 | goto free_card; | 465 | return err; |
419 | |||
420 | mmc_decode_cid(card); | ||
421 | } | ||
422 | 466 | ||
423 | /* | 467 | err = mmc_decode_scr(card); |
424 | * Select card, as all following commands rely on that. | ||
425 | */ | ||
426 | if (!mmc_host_is_spi(host)) { | ||
427 | err = mmc_select_card(card); | ||
428 | if (err) | 468 | if (err) |
429 | goto free_card; | 469 | return err; |
430 | } | ||
431 | 470 | ||
432 | if (!oldcard) { | ||
433 | /* | 471 | /* |
434 | * Fetch SCR from card. | 472 | * Fetch and process SD Status register. |
435 | */ | 473 | */ |
436 | err = mmc_app_send_scr(card, card->raw_scr); | 474 | err = mmc_read_ssr(card); |
437 | if (err) | 475 | if (err) |
438 | goto free_card; | 476 | return err; |
439 | 477 | ||
440 | err = mmc_decode_scr(card); | 478 | /* Erase init depends on CSD and SSR */ |
441 | if (err < 0) | 479 | mmc_init_erase(card); |
442 | goto free_card; | ||
443 | 480 | ||
444 | /* | 481 | /* |
445 | * Fetch switch information from card. | 482 | * Fetch switch information from card. |
446 | */ | 483 | */ |
447 | err = mmc_read_switch(card); | 484 | err = mmc_read_switch(card); |
448 | if (err) | 485 | if (err) |
449 | goto free_card; | 486 | return err; |
450 | } | 487 | } |
451 | 488 | ||
452 | /* | 489 | /* |
@@ -458,20 +495,34 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, | |||
458 | if (mmc_host_is_spi(host)) { | 495 | if (mmc_host_is_spi(host)) { |
459 | err = mmc_spi_set_crc(host, use_spi_crc); | 496 | err = mmc_spi_set_crc(host, use_spi_crc); |
460 | if (err) | 497 | if (err) |
461 | goto free_card; | 498 | return err; |
462 | } | 499 | } |
463 | 500 | ||
464 | /* | 501 | /* |
465 | * Attempt to change to high-speed (if supported) | 502 | * Check if read-only switch is active. |
466 | */ | 503 | */ |
467 | err = mmc_switch_hs(card); | 504 | if (!reinit) { |
468 | if (err) | 505 | int ro = -1; |
469 | goto free_card; | ||
470 | 506 | ||
471 | /* | 507 | if (host->ops->get_ro) |
472 | * Compute bus speed. | 508 | ro = host->ops->get_ro(host); |
473 | */ | 509 | |
474 | max_dtr = (unsigned int)-1; | 510 | if (ro < 0) { |
511 | printk(KERN_WARNING "%s: host does not " | ||
512 | "support reading read-only " | ||
513 | "switch. assuming write-enable.\n", | ||
514 | mmc_hostname(host)); | ||
515 | } else if (ro > 0) { | ||
516 | mmc_card_set_readonly(card); | ||
517 | } | ||
518 | } | ||
519 | |||
520 | return 0; | ||
521 | } | ||
522 | |||
523 | unsigned mmc_sd_get_max_clock(struct mmc_card *card) | ||
524 | { | ||
525 | unsigned max_dtr = (unsigned int)-1; | ||
475 | 526 | ||
476 | if (mmc_card_highspeed(card)) { | 527 | if (mmc_card_highspeed(card)) { |
477 | if (max_dtr > card->sw_caps.hs_max_dtr) | 528 | if (max_dtr > card->sw_caps.hs_max_dtr) |
@@ -480,7 +531,97 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, | |||
480 | max_dtr = card->csd.max_dtr; | 531 | max_dtr = card->csd.max_dtr; |
481 | } | 532 | } |
482 | 533 | ||
483 | mmc_set_clock(host, max_dtr); | 534 | return max_dtr; |
535 | } | ||
536 | |||
537 | void mmc_sd_go_highspeed(struct mmc_card *card) | ||
538 | { | ||
539 | mmc_card_set_highspeed(card); | ||
540 | mmc_set_timing(card->host, MMC_TIMING_SD_HS); | ||
541 | } | ||
542 | |||
543 | /* | ||
544 | * Handle the detection and initialisation of a card. | ||
545 | * | ||
546 | * In the case of a resume, "oldcard" will contain the card | ||
547 | * we're trying to reinitialise. | ||
548 | */ | ||
549 | static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, | ||
550 | struct mmc_card *oldcard) | ||
551 | { | ||
552 | struct mmc_card *card; | ||
553 | int err; | ||
554 | u32 cid[4]; | ||
555 | |||
556 | BUG_ON(!host); | ||
557 | WARN_ON(!host->claimed); | ||
558 | |||
559 | err = mmc_sd_get_cid(host, ocr, cid); | ||
560 | if (err) | ||
561 | return err; | ||
562 | |||
563 | if (oldcard) { | ||
564 | if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) | ||
565 | return -ENOENT; | ||
566 | |||
567 | card = oldcard; | ||
568 | } else { | ||
569 | /* | ||
570 | * Allocate card structure. | ||
571 | */ | ||
572 | card = mmc_alloc_card(host, &sd_type); | ||
573 | if (IS_ERR(card)) | ||
574 | return PTR_ERR(card); | ||
575 | |||
576 | card->type = MMC_TYPE_SD; | ||
577 | memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); | ||
578 | } | ||
579 | |||
580 | /* | ||
581 | * For native busses: get card RCA and quit open drain mode. | ||
582 | */ | ||
583 | if (!mmc_host_is_spi(host)) { | ||
584 | err = mmc_send_relative_addr(host, &card->rca); | ||
585 | if (err) | ||
586 | return err; | ||
587 | |||
588 | mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); | ||
589 | } | ||
590 | |||
591 | if (!oldcard) { | ||
592 | err = mmc_sd_get_csd(host, card); | ||
593 | if (err) | ||
594 | return err; | ||
595 | |||
596 | mmc_decode_cid(card); | ||
597 | } | ||
598 | |||
599 | /* | ||
600 | * Select card, as all following commands rely on that. | ||
601 | */ | ||
602 | if (!mmc_host_is_spi(host)) { | ||
603 | err = mmc_select_card(card); | ||
604 | if (err) | ||
605 | return err; | ||
606 | } | ||
607 | |||
608 | err = mmc_sd_setup_card(host, card, oldcard != NULL); | ||
609 | if (err) | ||
610 | goto free_card; | ||
611 | |||
612 | /* | ||
613 | * Attempt to change to high-speed (if supported) | ||
614 | */ | ||
615 | err = mmc_sd_switch_hs(card); | ||
616 | if (err > 0) | ||
617 | mmc_sd_go_highspeed(card); | ||
618 | else if (err) | ||
619 | goto free_card; | ||
620 | |||
621 | /* | ||
622 | * Set bus speed. | ||
623 | */ | ||
624 | mmc_set_clock(host, mmc_sd_get_max_clock(card)); | ||
484 | 625 | ||
485 | /* | 626 | /* |
486 | * Switch to wider bus (if supported). | 627 | * Switch to wider bus (if supported). |
@@ -494,30 +635,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, | |||
494 | mmc_set_bus_width(host, MMC_BUS_WIDTH_4); | 635 | mmc_set_bus_width(host, MMC_BUS_WIDTH_4); |
495 | } | 636 | } |
496 | 637 | ||
497 | /* | 638 | host->card = card; |
498 | * Check if read-only switch is active. | ||
499 | */ | ||
500 | if (!oldcard) { | ||
501 | if (!host->ops->get_ro || host->ops->get_ro(host) < 0) { | ||
502 | printk(KERN_WARNING "%s: host does not " | ||
503 | "support reading read-only " | ||
504 | "switch. assuming write-enable.\n", | ||
505 | mmc_hostname(host)); | ||
506 | } else { | ||
507 | if (host->ops->get_ro(host) > 0) | ||
508 | mmc_card_set_readonly(card); | ||
509 | } | ||
510 | } | ||
511 | |||
512 | if (!oldcard) | ||
513 | host->card = card; | ||
514 | |||
515 | return 0; | 639 | return 0; |
516 | 640 | ||
517 | free_card: | 641 | free_card: |
518 | if (!oldcard) | 642 | if (!oldcard) |
519 | mmc_remove_card(card); | 643 | mmc_remove_card(card); |
520 | err: | ||
521 | 644 | ||
522 | return err; | 645 | return err; |
523 | } | 646 | } |
diff --git a/drivers/mmc/core/sd.h b/drivers/mmc/core/sd.h new file mode 100644 index 000000000000..3d8800fa7600 --- /dev/null +++ b/drivers/mmc/core/sd.h | |||
@@ -0,0 +1,17 @@ | |||
1 | #ifndef _MMC_CORE_SD_H | ||
2 | #define _MMC_CORE_SD_H | ||
3 | |||
4 | #include <linux/mmc/card.h> | ||
5 | |||
6 | extern struct device_type sd_type; | ||
7 | |||
8 | int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid); | ||
9 | int mmc_sd_get_csd(struct mmc_host *host, struct mmc_card *card); | ||
10 | void mmc_decode_cid(struct mmc_card *card); | ||
11 | int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, | ||
12 | bool reinit); | ||
13 | unsigned mmc_sd_get_max_clock(struct mmc_card *card); | ||
14 | int mmc_sd_switch_hs(struct mmc_card *card); | ||
15 | void mmc_sd_go_highspeed(struct mmc_card *card); | ||
16 | |||
17 | #endif | ||
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c index 63772e7e7608..797cdb5887fd 100644 --- a/drivers/mmc/core/sd_ops.c +++ b/drivers/mmc/core/sd_ops.c | |||
@@ -346,3 +346,51 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group, | |||
346 | return 0; | 346 | return 0; |
347 | } | 347 | } |
348 | 348 | ||
349 | int mmc_app_sd_status(struct mmc_card *card, void *ssr) | ||
350 | { | ||
351 | int err; | ||
352 | struct mmc_request mrq; | ||
353 | struct mmc_command cmd; | ||
354 | struct mmc_data data; | ||
355 | struct scatterlist sg; | ||
356 | |||
357 | BUG_ON(!card); | ||
358 | BUG_ON(!card->host); | ||
359 | BUG_ON(!ssr); | ||
360 | |||
361 | /* NOTE: caller guarantees ssr is heap-allocated */ | ||
362 | |||
363 | err = mmc_app_cmd(card->host, card); | ||
364 | if (err) | ||
365 | return err; | ||
366 | |||
367 | memset(&mrq, 0, sizeof(struct mmc_request)); | ||
368 | memset(&cmd, 0, sizeof(struct mmc_command)); | ||
369 | memset(&data, 0, sizeof(struct mmc_data)); | ||
370 | |||
371 | mrq.cmd = &cmd; | ||
372 | mrq.data = &data; | ||
373 | |||
374 | cmd.opcode = SD_APP_SD_STATUS; | ||
375 | cmd.arg = 0; | ||
376 | cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_ADTC; | ||
377 | |||
378 | data.blksz = 64; | ||
379 | data.blocks = 1; | ||
380 | data.flags = MMC_DATA_READ; | ||
381 | data.sg = &sg; | ||
382 | data.sg_len = 1; | ||
383 | |||
384 | sg_init_one(&sg, ssr, 64); | ||
385 | |||
386 | mmc_set_data_timeout(&data, card); | ||
387 | |||
388 | mmc_wait_for_req(card->host, &mrq); | ||
389 | |||
390 | if (cmd.error) | ||
391 | return cmd.error; | ||
392 | if (data.error) | ||
393 | return data.error; | ||
394 | |||
395 | return 0; | ||
396 | } | ||
diff --git a/drivers/mmc/core/sd_ops.h b/drivers/mmc/core/sd_ops.h index 9742d8a30664..ffc2305d905f 100644 --- a/drivers/mmc/core/sd_ops.h +++ b/drivers/mmc/core/sd_ops.h | |||
@@ -19,6 +19,7 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca); | |||
19 | int mmc_app_send_scr(struct mmc_card *card, u32 *scr); | 19 | int mmc_app_send_scr(struct mmc_card *card, u32 *scr); |
20 | int mmc_sd_switch(struct mmc_card *card, int mode, int group, | 20 | int mmc_sd_switch(struct mmc_card *card, int mode, int group, |
21 | u8 value, u8 *resp); | 21 | u8 value, u8 *resp); |
22 | int mmc_app_sd_status(struct mmc_card *card, void *ssr); | ||
22 | 23 | ||
23 | #endif | 24 | #endif |
24 | 25 | ||
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index b9dee28ee7d0..bd2755e8d9a3 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c | |||
@@ -18,6 +18,7 @@ | |||
18 | 18 | ||
19 | #include "core.h" | 19 | #include "core.h" |
20 | #include "bus.h" | 20 | #include "bus.h" |
21 | #include "sd.h" | ||
21 | #include "sdio_bus.h" | 22 | #include "sdio_bus.h" |
22 | #include "mmc_ops.h" | 23 | #include "mmc_ops.h" |
23 | #include "sd_ops.h" | 24 | #include "sd_ops.h" |
@@ -62,13 +63,19 @@ static int sdio_init_func(struct mmc_card *card, unsigned int fn) | |||
62 | 63 | ||
63 | func->num = fn; | 64 | func->num = fn; |
64 | 65 | ||
65 | ret = sdio_read_fbr(func); | 66 | if (!(card->quirks & MMC_QUIRK_NONSTD_SDIO)) { |
66 | if (ret) | 67 | ret = sdio_read_fbr(func); |
67 | goto fail; | 68 | if (ret) |
69 | goto fail; | ||
68 | 70 | ||
69 | ret = sdio_read_func_cis(func); | 71 | ret = sdio_read_func_cis(func); |
70 | if (ret) | 72 | if (ret) |
71 | goto fail; | 73 | goto fail; |
74 | } else { | ||
75 | func->vendor = func->card->cis.vendor; | ||
76 | func->device = func->card->cis.device; | ||
77 | func->max_blksize = func->card->cis.blksize; | ||
78 | } | ||
72 | 79 | ||
73 | card->sdio_func[fn - 1] = func; | 80 | card->sdio_func[fn - 1] = func; |
74 | 81 | ||
@@ -159,9 +166,7 @@ static int sdio_enable_wide(struct mmc_card *card) | |||
159 | if (ret) | 166 | if (ret) |
160 | return ret; | 167 | return ret; |
161 | 168 | ||
162 | mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); | 169 | return 1; |
163 | |||
164 | return 0; | ||
165 | } | 170 | } |
166 | 171 | ||
167 | /* | 172 | /* |
@@ -221,10 +226,34 @@ static int sdio_disable_wide(struct mmc_card *card) | |||
221 | return 0; | 226 | return 0; |
222 | } | 227 | } |
223 | 228 | ||
229 | |||
230 | static int sdio_enable_4bit_bus(struct mmc_card *card) | ||
231 | { | ||
232 | int err; | ||
233 | |||
234 | if (card->type == MMC_TYPE_SDIO) | ||
235 | return sdio_enable_wide(card); | ||
236 | |||
237 | if ((card->host->caps & MMC_CAP_4_BIT_DATA) && | ||
238 | (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) { | ||
239 | err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); | ||
240 | if (err) | ||
241 | return err; | ||
242 | } else | ||
243 | return 0; | ||
244 | |||
245 | err = sdio_enable_wide(card); | ||
246 | if (err <= 0) | ||
247 | mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1); | ||
248 | |||
249 | return err; | ||
250 | } | ||
251 | |||
252 | |||
224 | /* | 253 | /* |
225 | * Test if the card supports high-speed mode and, if so, switch to it. | 254 | * Test if the card supports high-speed mode and, if so, switch to it. |
226 | */ | 255 | */ |
227 | static int sdio_enable_hs(struct mmc_card *card) | 256 | static int mmc_sdio_switch_hs(struct mmc_card *card, int enable) |
228 | { | 257 | { |
229 | int ret; | 258 | int ret; |
230 | u8 speed; | 259 | u8 speed; |
@@ -239,16 +268,56 @@ static int sdio_enable_hs(struct mmc_card *card) | |||
239 | if (ret) | 268 | if (ret) |
240 | return ret; | 269 | return ret; |
241 | 270 | ||
242 | speed |= SDIO_SPEED_EHS; | 271 | if (enable) |
272 | speed |= SDIO_SPEED_EHS; | ||
273 | else | ||
274 | speed &= ~SDIO_SPEED_EHS; | ||
243 | 275 | ||
244 | ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL); | 276 | ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL); |
245 | if (ret) | 277 | if (ret) |
246 | return ret; | 278 | return ret; |
247 | 279 | ||
248 | mmc_card_set_highspeed(card); | 280 | return 1; |
249 | mmc_set_timing(card->host, MMC_TIMING_SD_HS); | 281 | } |
250 | 282 | ||
251 | return 0; | 283 | /* |
284 | * Enable SDIO/combo card's high-speed mode. Return 0/1 if [not]supported. | ||
285 | */ | ||
286 | static int sdio_enable_hs(struct mmc_card *card) | ||
287 | { | ||
288 | int ret; | ||
289 | |||
290 | ret = mmc_sdio_switch_hs(card, true); | ||
291 | if (ret <= 0 || card->type == MMC_TYPE_SDIO) | ||
292 | return ret; | ||
293 | |||
294 | ret = mmc_sd_switch_hs(card); | ||
295 | if (ret <= 0) | ||
296 | mmc_sdio_switch_hs(card, false); | ||
297 | |||
298 | return ret; | ||
299 | } | ||
300 | |||
301 | static unsigned mmc_sdio_get_max_clock(struct mmc_card *card) | ||
302 | { | ||
303 | unsigned max_dtr; | ||
304 | |||
305 | if (mmc_card_highspeed(card)) { | ||
306 | /* | ||
307 | * The SDIO specification doesn't mention how | ||
308 | * the CIS transfer speed register relates to | ||
309 | * high-speed, but it seems that 50 MHz is | ||
310 | * mandatory. | ||
311 | */ | ||
312 | max_dtr = 50000000; | ||
313 | } else { | ||
314 | max_dtr = card->cis.max_dtr; | ||
315 | } | ||
316 | |||
317 | if (card->type == MMC_TYPE_SD_COMBO) | ||
318 | max_dtr = min(max_dtr, mmc_sd_get_max_clock(card)); | ||
319 | |||
320 | return max_dtr; | ||
252 | } | 321 | } |
253 | 322 | ||
254 | /* | 323 | /* |
@@ -293,7 +362,24 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
293 | goto err; | 362 | goto err; |
294 | } | 363 | } |
295 | 364 | ||
296 | card->type = MMC_TYPE_SDIO; | 365 | err = mmc_sd_get_cid(host, host->ocr & ocr, card->raw_cid); |
366 | |||
367 | if (!err) { | ||
368 | card->type = MMC_TYPE_SD_COMBO; | ||
369 | |||
370 | if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO || | ||
371 | memcmp(card->raw_cid, oldcard->raw_cid, sizeof(card->raw_cid)) != 0)) { | ||
372 | mmc_remove_card(card); | ||
373 | return -ENOENT; | ||
374 | } | ||
375 | } else { | ||
376 | card->type = MMC_TYPE_SDIO; | ||
377 | |||
378 | if (oldcard && oldcard->type != MMC_TYPE_SDIO) { | ||
379 | mmc_remove_card(card); | ||
380 | return -ENOENT; | ||
381 | } | ||
382 | } | ||
297 | 383 | ||
298 | /* | 384 | /* |
299 | * Call the optional HC's init_card function to handle quirks. | 385 | * Call the optional HC's init_card function to handle quirks. |
@@ -313,6 +399,17 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
313 | } | 399 | } |
314 | 400 | ||
315 | /* | 401 | /* |
402 | * Read CSD, before selecting the card | ||
403 | */ | ||
404 | if (!oldcard && card->type == MMC_TYPE_SD_COMBO) { | ||
405 | err = mmc_sd_get_csd(host, card); | ||
406 | if (err) | ||
407 | return err; | ||
408 | |||
409 | mmc_decode_cid(card); | ||
410 | } | ||
411 | |||
412 | /* | ||
316 | * Select card, as all following commands rely on that. | 413 | * Select card, as all following commands rely on that. |
317 | */ | 414 | */ |
318 | if (!powered_resume && !mmc_host_is_spi(host)) { | 415 | if (!powered_resume && !mmc_host_is_spi(host)) { |
@@ -321,6 +418,23 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
321 | goto remove; | 418 | goto remove; |
322 | } | 419 | } |
323 | 420 | ||
421 | if (card->quirks & MMC_QUIRK_NONSTD_SDIO) { | ||
422 | /* | ||
423 | * This is non-standard SDIO device, meaning it doesn't | ||
424 | * have any CIA (Common I/O area) registers present. | ||
425 | * It's host's responsibility to fill cccr and cis | ||
426 | * structures in init_card(). | ||
427 | */ | ||
428 | mmc_set_clock(host, card->cis.max_dtr); | ||
429 | |||
430 | if (card->cccr.high_speed) { | ||
431 | mmc_card_set_highspeed(card); | ||
432 | mmc_set_timing(card->host, MMC_TIMING_SD_HS); | ||
433 | } | ||
434 | |||
435 | goto finish; | ||
436 | } | ||
437 | |||
324 | /* | 438 | /* |
325 | * Read the common registers. | 439 | * Read the common registers. |
326 | */ | 440 | */ |
@@ -339,43 +453,57 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
339 | int same = (card->cis.vendor == oldcard->cis.vendor && | 453 | int same = (card->cis.vendor == oldcard->cis.vendor && |
340 | card->cis.device == oldcard->cis.device); | 454 | card->cis.device == oldcard->cis.device); |
341 | mmc_remove_card(card); | 455 | mmc_remove_card(card); |
342 | if (!same) { | 456 | if (!same) |
343 | err = -ENOENT; | 457 | return -ENOENT; |
344 | goto err; | 458 | |
345 | } | ||
346 | card = oldcard; | 459 | card = oldcard; |
347 | return 0; | 460 | return 0; |
348 | } | 461 | } |
349 | 462 | ||
463 | if (card->type == MMC_TYPE_SD_COMBO) { | ||
464 | err = mmc_sd_setup_card(host, card, oldcard != NULL); | ||
465 | /* handle as SDIO-only card if memory init failed */ | ||
466 | if (err) { | ||
467 | mmc_go_idle(host); | ||
468 | if (mmc_host_is_spi(host)) | ||
469 | /* should not fail, as it worked previously */ | ||
470 | mmc_spi_set_crc(host, use_spi_crc); | ||
471 | card->type = MMC_TYPE_SDIO; | ||
472 | } else | ||
473 | card->dev.type = &sd_type; | ||
474 | } | ||
475 | |||
476 | /* | ||
477 | * If needed, disconnect card detection pull-up resistor. | ||
478 | */ | ||
479 | err = sdio_disable_cd(card); | ||
480 | if (err) | ||
481 | goto remove; | ||
482 | |||
350 | /* | 483 | /* |
351 | * Switch to high-speed (if supported). | 484 | * Switch to high-speed (if supported). |
352 | */ | 485 | */ |
353 | err = sdio_enable_hs(card); | 486 | err = sdio_enable_hs(card); |
354 | if (err) | 487 | if (err > 0) |
488 | mmc_sd_go_highspeed(card); | ||
489 | else if (err) | ||
355 | goto remove; | 490 | goto remove; |
356 | 491 | ||
357 | /* | 492 | /* |
358 | * Change to the card's maximum speed. | 493 | * Change to the card's maximum speed. |
359 | */ | 494 | */ |
360 | if (mmc_card_highspeed(card)) { | 495 | mmc_set_clock(host, mmc_sdio_get_max_clock(card)); |
361 | /* | ||
362 | * The SDIO specification doesn't mention how | ||
363 | * the CIS transfer speed register relates to | ||
364 | * high-speed, but it seems that 50 MHz is | ||
365 | * mandatory. | ||
366 | */ | ||
367 | mmc_set_clock(host, 50000000); | ||
368 | } else { | ||
369 | mmc_set_clock(host, card->cis.max_dtr); | ||
370 | } | ||
371 | 496 | ||
372 | /* | 497 | /* |
373 | * Switch to wider bus (if supported). | 498 | * Switch to wider bus (if supported). |
374 | */ | 499 | */ |
375 | err = sdio_enable_wide(card); | 500 | err = sdio_enable_4bit_bus(card); |
376 | if (err) | 501 | if (err > 0) |
502 | mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); | ||
503 | else if (err) | ||
377 | goto remove; | 504 | goto remove; |
378 | 505 | ||
506 | finish: | ||
379 | if (!oldcard) | 507 | if (!oldcard) |
380 | host->card = card; | 508 | host->card = card; |
381 | return 0; | 509 | return 0; |
@@ -487,9 +615,14 @@ static int mmc_sdio_resume(struct mmc_host *host) | |||
487 | mmc_claim_host(host); | 615 | mmc_claim_host(host); |
488 | err = mmc_sdio_init_card(host, host->ocr, host->card, | 616 | err = mmc_sdio_init_card(host, host->ocr, host->card, |
489 | (host->pm_flags & MMC_PM_KEEP_POWER)); | 617 | (host->pm_flags & MMC_PM_KEEP_POWER)); |
490 | if (!err) | 618 | if (!err) { |
491 | /* We may have switched to 1-bit mode during suspend. */ | 619 | /* We may have switched to 1-bit mode during suspend. */ |
492 | err = sdio_enable_wide(host->card); | 620 | err = sdio_enable_4bit_bus(host->card); |
621 | if (err > 0) { | ||
622 | mmc_set_bus_width(host, MMC_BUS_WIDTH_4); | ||
623 | err = 0; | ||
624 | } | ||
625 | } | ||
493 | if (!err && host->sdio_irqs) | 626 | if (!err && host->sdio_irqs) |
494 | mmc_signal_sdio_irq(host); | 627 | mmc_signal_sdio_irq(host); |
495 | mmc_release_host(host); | 628 | mmc_release_host(host); |
@@ -574,13 +707,6 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr) | |||
574 | card->sdio_funcs = 0; | 707 | card->sdio_funcs = 0; |
575 | 708 | ||
576 | /* | 709 | /* |
577 | * If needed, disconnect card detection pull-up resistor. | ||
578 | */ | ||
579 | err = sdio_disable_cd(card); | ||
580 | if (err) | ||
581 | goto remove; | ||
582 | |||
583 | /* | ||
584 | * Initialize (but don't add) all present functions. | 710 | * Initialize (but don't add) all present functions. |
585 | */ | 711 | */ |
586 | for (i = 0; i < funcs; i++, card->sdio_funcs++) { | 712 | for (i = 0; i < funcs; i++, card->sdio_funcs++) { |
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index d25e22cee4c4..c997474c649f 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig | |||
@@ -121,6 +121,15 @@ config MMC_SDHCI_PLTFM | |||
121 | 121 | ||
122 | If unsure, say N. | 122 | If unsure, say N. |
123 | 123 | ||
124 | config MMC_SDHCI_CNS3XXX | ||
125 | bool "SDHCI support on the Cavium Networks CNS3xxx SoC" | ||
126 | depends on ARCH_CNS3XXX | ||
127 | depends on MMC_SDHCI_PLTFM | ||
128 | help | ||
129 | This selects the SDHCI support for CNS3xxx System-on-Chip devices. | ||
130 | |||
131 | If unsure, say N. | ||
132 | |||
124 | config MMC_SDHCI_S3C | 133 | config MMC_SDHCI_S3C |
125 | tristate "SDHCI support on Samsung S3C SoC" | 134 | tristate "SDHCI support on Samsung S3C SoC" |
126 | depends on MMC_SDHCI && (PLAT_S3C24XX || PLAT_S3C64XX) | 135 | depends on MMC_SDHCI && (PLAT_S3C24XX || PLAT_S3C64XX) |
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile index f4e53c98d944..fe0ba4e2b8b0 100644 --- a/drivers/mmc/host/Makefile +++ b/drivers/mmc/host/Makefile | |||
@@ -12,7 +12,6 @@ obj-$(CONFIG_MMC_IMX) += imxmmc.o | |||
12 | obj-$(CONFIG_MMC_MXC) += mxcmmc.o | 12 | obj-$(CONFIG_MMC_MXC) += mxcmmc.o |
13 | obj-$(CONFIG_MMC_SDHCI) += sdhci.o | 13 | obj-$(CONFIG_MMC_SDHCI) += sdhci.o |
14 | obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o | 14 | obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o |
15 | obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-pltfm.o | ||
16 | obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o | 15 | obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o |
17 | obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o | 16 | obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o |
18 | obj-$(CONFIG_MMC_WBSD) += wbsd.o | 17 | obj-$(CONFIG_MMC_WBSD) += wbsd.o |
@@ -38,6 +37,10 @@ obj-$(CONFIG_SDH_BFIN) += bfin_sdh.o | |||
38 | obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o | 37 | obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o |
39 | obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o | 38 | obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o |
40 | 39 | ||
40 | obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-platform.o | ||
41 | sdhci-platform-y := sdhci-pltfm.o | ||
42 | sdhci-platform-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o | ||
43 | |||
41 | obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o | 44 | obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o |
42 | sdhci-of-y := sdhci-of-core.o | 45 | sdhci-of-y := sdhci-of-core.o |
43 | sdhci-of-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o | 46 | sdhci-of-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o |
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c index 24e09454e522..3bd8ff71ec22 100644 --- a/drivers/mmc/host/msm_sdcc.c +++ b/drivers/mmc/host/msm_sdcc.c | |||
@@ -1057,22 +1057,6 @@ msmsdcc_init_dma(struct msmsdcc_host *host) | |||
1057 | return 0; | 1057 | return 0; |
1058 | } | 1058 | } |
1059 | 1059 | ||
1060 | #ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ | ||
1061 | static void | ||
1062 | do_resume_work(struct work_struct *work) | ||
1063 | { | ||
1064 | struct msmsdcc_host *host = | ||
1065 | container_of(work, struct msmsdcc_host, resume_task); | ||
1066 | struct mmc_host *mmc = host->mmc; | ||
1067 | |||
1068 | if (mmc) { | ||
1069 | mmc_resume_host(mmc); | ||
1070 | if (host->stat_irq) | ||
1071 | enable_irq(host->stat_irq); | ||
1072 | } | ||
1073 | } | ||
1074 | #endif | ||
1075 | |||
1076 | static int | 1060 | static int |
1077 | msmsdcc_probe(struct platform_device *pdev) | 1061 | msmsdcc_probe(struct platform_device *pdev) |
1078 | { | 1062 | { |
@@ -1145,15 +1129,6 @@ msmsdcc_probe(struct platform_device *pdev) | |||
1145 | host->dmares = dmares; | 1129 | host->dmares = dmares; |
1146 | spin_lock_init(&host->lock); | 1130 | spin_lock_init(&host->lock); |
1147 | 1131 | ||
1148 | #ifdef CONFIG_MMC_EMBEDDED_SDIO | ||
1149 | if (plat->embedded_sdio) | ||
1150 | mmc_set_embedded_sdio_data(mmc, | ||
1151 | &plat->embedded_sdio->cis, | ||
1152 | &plat->embedded_sdio->cccr, | ||
1153 | plat->embedded_sdio->funcs, | ||
1154 | plat->embedded_sdio->num_funcs); | ||
1155 | #endif | ||
1156 | |||
1157 | /* | 1132 | /* |
1158 | * Setup DMA | 1133 | * Setup DMA |
1159 | */ | 1134 | */ |
diff --git a/drivers/mmc/host/msm_sdcc.h b/drivers/mmc/host/msm_sdcc.h index da0039c9285e..d7dedcf33b5b 100644 --- a/drivers/mmc/host/msm_sdcc.h +++ b/drivers/mmc/host/msm_sdcc.h | |||
@@ -235,10 +235,6 @@ struct msmsdcc_host { | |||
235 | int cmdpoll; | 235 | int cmdpoll; |
236 | struct msmsdcc_stats stats; | 236 | struct msmsdcc_stats stats; |
237 | 237 | ||
238 | #ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ | ||
239 | struct work_struct resume_task; | ||
240 | #endif | ||
241 | |||
242 | /* Command parameters */ | 238 | /* Command parameters */ |
243 | unsigned int cmd_timeout; | 239 | unsigned int cmd_timeout; |
244 | unsigned int cmd_pio_irqmask; | 240 | unsigned int cmd_pio_irqmask; |
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index b032828c6126..4a8776f8afdd 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/clk.h> | 28 | #include <linux/clk.h> |
29 | #include <linux/mmc/host.h> | 29 | #include <linux/mmc/host.h> |
30 | #include <linux/mmc/core.h> | 30 | #include <linux/mmc/core.h> |
31 | #include <linux/mmc/mmc.h> | ||
31 | #include <linux/io.h> | 32 | #include <linux/io.h> |
32 | #include <linux/semaphore.h> | 33 | #include <linux/semaphore.h> |
33 | #include <linux/gpio.h> | 34 | #include <linux/gpio.h> |
@@ -78,6 +79,7 @@ | |||
78 | #define INT_EN_MASK 0x307F0033 | 79 | #define INT_EN_MASK 0x307F0033 |
79 | #define BWR_ENABLE (1 << 4) | 80 | #define BWR_ENABLE (1 << 4) |
80 | #define BRR_ENABLE (1 << 5) | 81 | #define BRR_ENABLE (1 << 5) |
82 | #define DTO_ENABLE (1 << 20) | ||
81 | #define INIT_STREAM (1 << 1) | 83 | #define INIT_STREAM (1 << 1) |
82 | #define DP_SELECT (1 << 21) | 84 | #define DP_SELECT (1 << 21) |
83 | #define DDIR (1 << 4) | 85 | #define DDIR (1 << 4) |
@@ -523,7 +525,8 @@ static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host) | |||
523 | dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n"); | 525 | dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n"); |
524 | } | 526 | } |
525 | 527 | ||
526 | static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host) | 528 | static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host, |
529 | struct mmc_command *cmd) | ||
527 | { | 530 | { |
528 | unsigned int irq_mask; | 531 | unsigned int irq_mask; |
529 | 532 | ||
@@ -532,6 +535,10 @@ static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host) | |||
532 | else | 535 | else |
533 | irq_mask = INT_EN_MASK; | 536 | irq_mask = INT_EN_MASK; |
534 | 537 | ||
538 | /* Disable timeout for erases */ | ||
539 | if (cmd->opcode == MMC_ERASE) | ||
540 | irq_mask &= ~DTO_ENABLE; | ||
541 | |||
535 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); | 542 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
536 | OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); | 543 | OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); |
537 | OMAP_HSMMC_WRITE(host->base, IE, irq_mask); | 544 | OMAP_HSMMC_WRITE(host->base, IE, irq_mask); |
@@ -782,7 +789,7 @@ omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd, | |||
782 | mmc_hostname(host->mmc), cmd->opcode, cmd->arg); | 789 | mmc_hostname(host->mmc), cmd->opcode, cmd->arg); |
783 | host->cmd = cmd; | 790 | host->cmd = cmd; |
784 | 791 | ||
785 | omap_hsmmc_enable_irq(host); | 792 | omap_hsmmc_enable_irq(host, cmd); |
786 | 793 | ||
787 | host->response_busy = 0; | 794 | host->response_busy = 0; |
788 | if (cmd->flags & MMC_RSP_PRESENT) { | 795 | if (cmd->flags & MMC_RSP_PRESENT) { |
@@ -1273,8 +1280,11 @@ static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *cb_data) | |||
1273 | struct mmc_data *data = host->mrq->data; | 1280 | struct mmc_data *data = host->mrq->data; |
1274 | int dma_ch, req_in_progress; | 1281 | int dma_ch, req_in_progress; |
1275 | 1282 | ||
1276 | if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ) | 1283 | if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) { |
1277 | dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n"); | 1284 | dev_warn(mmc_dev(host->mmc), "unexpected dma status %x\n", |
1285 | ch_status); | ||
1286 | return; | ||
1287 | } | ||
1278 | 1288 | ||
1279 | spin_lock(&host->irq_lock); | 1289 | spin_lock(&host->irq_lock); |
1280 | if (host->dma_ch < 0) { | 1290 | if (host->dma_ch < 0) { |
@@ -1598,6 +1608,14 @@ static int omap_hsmmc_get_ro(struct mmc_host *mmc) | |||
1598 | return mmc_slot(host).get_ro(host->dev, 0); | 1608 | return mmc_slot(host).get_ro(host->dev, 0); |
1599 | } | 1609 | } |
1600 | 1610 | ||
1611 | static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card) | ||
1612 | { | ||
1613 | struct omap_hsmmc_host *host = mmc_priv(mmc); | ||
1614 | |||
1615 | if (mmc_slot(host).init_card) | ||
1616 | mmc_slot(host).init_card(card); | ||
1617 | } | ||
1618 | |||
1601 | static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host) | 1619 | static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host) |
1602 | { | 1620 | { |
1603 | u32 hctl, capa, value; | 1621 | u32 hctl, capa, value; |
@@ -1869,6 +1887,7 @@ static const struct mmc_host_ops omap_hsmmc_ops = { | |||
1869 | .set_ios = omap_hsmmc_set_ios, | 1887 | .set_ios = omap_hsmmc_set_ios, |
1870 | .get_cd = omap_hsmmc_get_cd, | 1888 | .get_cd = omap_hsmmc_get_cd, |
1871 | .get_ro = omap_hsmmc_get_ro, | 1889 | .get_ro = omap_hsmmc_get_ro, |
1890 | .init_card = omap_hsmmc_init_card, | ||
1872 | /* NYET -- enable_sdio_irq */ | 1891 | /* NYET -- enable_sdio_irq */ |
1873 | }; | 1892 | }; |
1874 | 1893 | ||
@@ -1879,6 +1898,7 @@ static const struct mmc_host_ops omap_hsmmc_ps_ops = { | |||
1879 | .set_ios = omap_hsmmc_set_ios, | 1898 | .set_ios = omap_hsmmc_set_ios, |
1880 | .get_cd = omap_hsmmc_get_cd, | 1899 | .get_cd = omap_hsmmc_get_cd, |
1881 | .get_ro = omap_hsmmc_get_ro, | 1900 | .get_ro = omap_hsmmc_get_ro, |
1901 | .init_card = omap_hsmmc_init_card, | ||
1882 | /* NYET -- enable_sdio_irq */ | 1902 | /* NYET -- enable_sdio_irq */ |
1883 | }; | 1903 | }; |
1884 | 1904 | ||
@@ -2094,12 +2114,25 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev) | |||
2094 | mmc->max_seg_size = mmc->max_req_size; | 2114 | mmc->max_seg_size = mmc->max_req_size; |
2095 | 2115 | ||
2096 | mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | | 2116 | mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | |
2097 | MMC_CAP_WAIT_WHILE_BUSY; | 2117 | MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE; |
2098 | 2118 | ||
2099 | if (mmc_slot(host).wires >= 8) | 2119 | switch (mmc_slot(host).wires) { |
2120 | case 8: | ||
2100 | mmc->caps |= MMC_CAP_8_BIT_DATA; | 2121 | mmc->caps |= MMC_CAP_8_BIT_DATA; |
2101 | else if (mmc_slot(host).wires >= 4) | 2122 | /* Fall through */ |
2123 | case 4: | ||
2102 | mmc->caps |= MMC_CAP_4_BIT_DATA; | 2124 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
2125 | break; | ||
2126 | case 1: | ||
2127 | /* Nothing to crib here */ | ||
2128 | case 0: | ||
2129 | /* Assuming nothing was given by board, Core use's 1-Bit */ | ||
2130 | break; | ||
2131 | default: | ||
2132 | /* Completely unexpected.. Core goes with 1-Bit Width */ | ||
2133 | dev_crit(mmc_dev(host->mmc), "Invalid width %d\n used!" | ||
2134 | "using 1 instead\n", mmc_slot(host).wires); | ||
2135 | } | ||
2103 | 2136 | ||
2104 | if (mmc_slot(host).nonremovable) | 2137 | if (mmc_slot(host).nonremovable) |
2105 | mmc->caps |= MMC_CAP_NONREMOVABLE; | 2138 | mmc->caps |= MMC_CAP_NONREMOVABLE; |
diff --git a/drivers/mmc/host/sdhci-cns3xxx.c b/drivers/mmc/host/sdhci-cns3xxx.c new file mode 100644 index 000000000000..b7050b380d5f --- /dev/null +++ b/drivers/mmc/host/sdhci-cns3xxx.c | |||
@@ -0,0 +1,97 @@ | |||
1 | /* | ||
2 | * SDHCI support for CNS3xxx SoC | ||
3 | * | ||
4 | * Copyright 2008 Cavium Networks | ||
5 | * Copyright 2010 MontaVista Software, LLC. | ||
6 | * | ||
7 | * Authors: Scott Shu | ||
8 | * Anton Vorontsov <avorontsov@mvista.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | */ | ||
14 | |||
15 | #include <linux/delay.h> | ||
16 | #include <linux/device.h> | ||
17 | #include <linux/mmc/host.h> | ||
18 | #include <linux/sdhci-pltfm.h> | ||
19 | #include <mach/cns3xxx.h> | ||
20 | #include "sdhci.h" | ||
21 | #include "sdhci-pltfm.h" | ||
22 | |||
23 | static unsigned int sdhci_cns3xxx_get_max_clk(struct sdhci_host *host) | ||
24 | { | ||
25 | return 150000000; | ||
26 | } | ||
27 | |||
28 | static void sdhci_cns3xxx_set_clock(struct sdhci_host *host, unsigned int clock) | ||
29 | { | ||
30 | struct device *dev = mmc_dev(host->mmc); | ||
31 | int div = 1; | ||
32 | u16 clk; | ||
33 | unsigned long timeout; | ||
34 | |||
35 | if (clock == host->clock) | ||
36 | return; | ||
37 | |||
38 | sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); | ||
39 | |||
40 | if (clock == 0) | ||
41 | goto out; | ||
42 | |||
43 | while (host->max_clk / div > clock) { | ||
44 | /* | ||
45 | * On CNS3xxx divider grows linearly up to 4, and then | ||
46 | * exponentially up to 256. | ||
47 | */ | ||
48 | if (div < 4) | ||
49 | div += 1; | ||
50 | else if (div < 256) | ||
51 | div *= 2; | ||
52 | else | ||
53 | break; | ||
54 | } | ||
55 | |||
56 | dev_dbg(dev, "desired SD clock: %d, actual: %d\n", | ||
57 | clock, host->max_clk / div); | ||
58 | |||
59 | /* Divide by 3 is special. */ | ||
60 | if (div != 3) | ||
61 | div >>= 1; | ||
62 | |||
63 | clk = div << SDHCI_DIVIDER_SHIFT; | ||
64 | clk |= SDHCI_CLOCK_INT_EN; | ||
65 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); | ||
66 | |||
67 | timeout = 20; | ||
68 | while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) | ||
69 | & SDHCI_CLOCK_INT_STABLE)) { | ||
70 | if (timeout == 0) { | ||
71 | dev_warn(dev, "clock is unstable"); | ||
72 | break; | ||
73 | } | ||
74 | timeout--; | ||
75 | mdelay(1); | ||
76 | } | ||
77 | |||
78 | clk |= SDHCI_CLOCK_CARD_EN; | ||
79 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); | ||
80 | out: | ||
81 | host->clock = clock; | ||
82 | } | ||
83 | |||
84 | static struct sdhci_ops sdhci_cns3xxx_ops = { | ||
85 | .get_max_clock = sdhci_cns3xxx_get_max_clk, | ||
86 | .set_clock = sdhci_cns3xxx_set_clock, | ||
87 | }; | ||
88 | |||
89 | struct sdhci_pltfm_data sdhci_cns3xxx_pdata = { | ||
90 | .ops = &sdhci_cns3xxx_ops, | ||
91 | .quirks = SDHCI_QUIRK_BROKEN_DMA | | ||
92 | SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK | | ||
93 | SDHCI_QUIRK_INVERTED_WRITE_PROTECT | | ||
94 | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN | | ||
95 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | | ||
96 | SDHCI_QUIRK_NONSTANDARD_CLOCK, | ||
97 | }; | ||
diff --git a/drivers/mmc/host/sdhci-of-core.c b/drivers/mmc/host/sdhci-of-core.c index a6bd448a3b46..c51b71174c1d 100644 --- a/drivers/mmc/host/sdhci-of-core.c +++ b/drivers/mmc/host/sdhci-of-core.c | |||
@@ -154,6 +154,10 @@ static int __devinit sdhci_of_probe(struct platform_device *ofdev, | |||
154 | host->ops = &sdhci_of_data->ops; | 154 | host->ops = &sdhci_of_data->ops; |
155 | } | 155 | } |
156 | 156 | ||
157 | if (of_get_property(np, "sdhci,auto-cmd12", NULL)) | ||
158 | host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12; | ||
159 | |||
160 | |||
157 | if (of_get_property(np, "sdhci,1-bit-only", NULL)) | 161 | if (of_get_property(np, "sdhci,1-bit-only", NULL)) |
158 | host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; | 162 | host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; |
159 | 163 | ||
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c index 65483fdea45b..e8aa99deae9a 100644 --- a/drivers/mmc/host/sdhci-pci.c +++ b/drivers/mmc/host/sdhci-pci.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/pci.h> | 17 | #include <linux/pci.h> |
18 | #include <linux/dma-mapping.h> | 18 | #include <linux/dma-mapping.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include <linux/device.h> | ||
20 | 21 | ||
21 | #include <linux/mmc/host.h> | 22 | #include <linux/mmc/host.h> |
22 | 23 | ||
@@ -84,7 +85,30 @@ static int ricoh_probe(struct sdhci_pci_chip *chip) | |||
84 | if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG || | 85 | if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG || |
85 | chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY) | 86 | chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY) |
86 | chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET; | 87 | chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET; |
88 | return 0; | ||
89 | } | ||
90 | |||
91 | static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot) | ||
92 | { | ||
93 | slot->host->caps = | ||
94 | ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT) | ||
95 | & SDHCI_TIMEOUT_CLK_MASK) | | ||
96 | |||
97 | ((0x21 << SDHCI_CLOCK_BASE_SHIFT) | ||
98 | & SDHCI_CLOCK_BASE_MASK) | | ||
87 | 99 | ||
100 | SDHCI_TIMEOUT_CLK_UNIT | | ||
101 | SDHCI_CAN_VDD_330 | | ||
102 | SDHCI_CAN_DO_SDMA; | ||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | static int ricoh_mmc_resume(struct sdhci_pci_chip *chip) | ||
107 | { | ||
108 | /* Apply a delay to allow controller to settle */ | ||
109 | /* Otherwise it becomes confused if card state changed | ||
110 | during suspend */ | ||
111 | msleep(500); | ||
88 | return 0; | 112 | return 0; |
89 | } | 113 | } |
90 | 114 | ||
@@ -95,6 +119,15 @@ static const struct sdhci_pci_fixes sdhci_ricoh = { | |||
95 | SDHCI_QUIRK_CLOCK_BEFORE_RESET, | 119 | SDHCI_QUIRK_CLOCK_BEFORE_RESET, |
96 | }; | 120 | }; |
97 | 121 | ||
122 | static const struct sdhci_pci_fixes sdhci_ricoh_mmc = { | ||
123 | .probe_slot = ricoh_mmc_probe_slot, | ||
124 | .resume = ricoh_mmc_resume, | ||
125 | .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | | ||
126 | SDHCI_QUIRK_CLOCK_BEFORE_RESET | | ||
127 | SDHCI_QUIRK_NO_CARD_NO_RESET | | ||
128 | SDHCI_QUIRK_MISSING_CAPS | ||
129 | }; | ||
130 | |||
98 | static const struct sdhci_pci_fixes sdhci_ene_712 = { | 131 | static const struct sdhci_pci_fixes sdhci_ene_712 = { |
99 | .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | | 132 | .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | |
100 | SDHCI_QUIRK_BROKEN_DMA, | 133 | SDHCI_QUIRK_BROKEN_DMA, |
@@ -374,6 +407,22 @@ static const struct pci_device_id pci_ids[] __devinitdata = { | |||
374 | }, | 407 | }, |
375 | 408 | ||
376 | { | 409 | { |
410 | .vendor = PCI_VENDOR_ID_RICOH, | ||
411 | .device = 0x843, | ||
412 | .subvendor = PCI_ANY_ID, | ||
413 | .subdevice = PCI_ANY_ID, | ||
414 | .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, | ||
415 | }, | ||
416 | |||
417 | { | ||
418 | .vendor = PCI_VENDOR_ID_RICOH, | ||
419 | .device = 0xe822, | ||
420 | .subvendor = PCI_ANY_ID, | ||
421 | .subdevice = PCI_ANY_ID, | ||
422 | .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, | ||
423 | }, | ||
424 | |||
425 | { | ||
377 | .vendor = PCI_VENDOR_ID_ENE, | 426 | .vendor = PCI_VENDOR_ID_ENE, |
378 | .device = PCI_DEVICE_ID_ENE_CB712_SD, | 427 | .device = PCI_DEVICE_ID_ENE_CB712_SD, |
379 | .subvendor = PCI_ANY_ID, | 428 | .subvendor = PCI_ANY_ID, |
diff --git a/drivers/mmc/host/sdhci-pltfm.c b/drivers/mmc/host/sdhci-pltfm.c index b6ee0d719698..e045e3c61dde 100644 --- a/drivers/mmc/host/sdhci-pltfm.c +++ b/drivers/mmc/host/sdhci-pltfm.c | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/highmem.h> | 26 | #include <linux/highmem.h> |
27 | #include <linux/mod_devicetable.h> | ||
27 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
28 | 29 | ||
29 | #include <linux/mmc/host.h> | 30 | #include <linux/mmc/host.h> |
@@ -32,6 +33,7 @@ | |||
32 | #include <linux/sdhci-pltfm.h> | 33 | #include <linux/sdhci-pltfm.h> |
33 | 34 | ||
34 | #include "sdhci.h" | 35 | #include "sdhci.h" |
36 | #include "sdhci-pltfm.h" | ||
35 | 37 | ||
36 | /*****************************************************************************\ | 38 | /*****************************************************************************\ |
37 | * * | 39 | * * |
@@ -51,10 +53,14 @@ static struct sdhci_ops sdhci_pltfm_ops = { | |||
51 | static int __devinit sdhci_pltfm_probe(struct platform_device *pdev) | 53 | static int __devinit sdhci_pltfm_probe(struct platform_device *pdev) |
52 | { | 54 | { |
53 | struct sdhci_pltfm_data *pdata = pdev->dev.platform_data; | 55 | struct sdhci_pltfm_data *pdata = pdev->dev.platform_data; |
56 | const struct platform_device_id *platid = platform_get_device_id(pdev); | ||
54 | struct sdhci_host *host; | 57 | struct sdhci_host *host; |
55 | struct resource *iomem; | 58 | struct resource *iomem; |
56 | int ret; | 59 | int ret; |
57 | 60 | ||
61 | if (!pdata && platid && platid->driver_data) | ||
62 | pdata = (void *)platid->driver_data; | ||
63 | |||
58 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 64 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
59 | if (!iomem) { | 65 | if (!iomem) { |
60 | ret = -ENOMEM; | 66 | ret = -ENOMEM; |
@@ -150,6 +156,15 @@ static int __devexit sdhci_pltfm_remove(struct platform_device *pdev) | |||
150 | return 0; | 156 | return 0; |
151 | } | 157 | } |
152 | 158 | ||
159 | static const struct platform_device_id sdhci_pltfm_ids[] = { | ||
160 | { "sdhci", }, | ||
161 | #ifdef CONFIG_MMC_SDHCI_CNS3XXX | ||
162 | { "sdhci-cns3xxx", (kernel_ulong_t)&sdhci_cns3xxx_pdata }, | ||
163 | #endif | ||
164 | { }, | ||
165 | }; | ||
166 | MODULE_DEVICE_TABLE(platform, sdhci_pltfm_ids); | ||
167 | |||
153 | static struct platform_driver sdhci_pltfm_driver = { | 168 | static struct platform_driver sdhci_pltfm_driver = { |
154 | .driver = { | 169 | .driver = { |
155 | .name = "sdhci", | 170 | .name = "sdhci", |
@@ -157,6 +172,7 @@ static struct platform_driver sdhci_pltfm_driver = { | |||
157 | }, | 172 | }, |
158 | .probe = sdhci_pltfm_probe, | 173 | .probe = sdhci_pltfm_probe, |
159 | .remove = __devexit_p(sdhci_pltfm_remove), | 174 | .remove = __devexit_p(sdhci_pltfm_remove), |
175 | .id_table = sdhci_pltfm_ids, | ||
160 | }; | 176 | }; |
161 | 177 | ||
162 | /*****************************************************************************\ | 178 | /*****************************************************************************\ |
@@ -181,4 +197,3 @@ module_exit(sdhci_drv_exit); | |||
181 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver"); | 197 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver"); |
182 | MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>"); | 198 | MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>"); |
183 | MODULE_LICENSE("GPL v2"); | 199 | MODULE_LICENSE("GPL v2"); |
184 | MODULE_ALIAS("platform:sdhci"); | ||
diff --git a/drivers/mmc/host/sdhci-pltfm.h b/drivers/mmc/host/sdhci-pltfm.h new file mode 100644 index 000000000000..900f32902f73 --- /dev/null +++ b/drivers/mmc/host/sdhci-pltfm.h | |||
@@ -0,0 +1,18 @@ | |||
1 | /* | ||
2 | * Copyright 2010 MontaVista Software, LLC. | ||
3 | * | ||
4 | * Author: Anton Vorontsov <avorontsov@ru.mvista.com> | ||
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 version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #ifndef _DRIVERS_MMC_SDHCI_PLTFM_H | ||
12 | #define _DRIVERS_MMC_SDHCI_PLTFM_H | ||
13 | |||
14 | #include <linux/sdhci-pltfm.h> | ||
15 | |||
16 | extern struct sdhci_pltfm_data sdhci_cns3xxx_pdata; | ||
17 | |||
18 | #endif /* _DRIVERS_MMC_SDHCI_PLTFM_H */ | ||
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c index ad30f074ee15..0a7f2614c6f0 100644 --- a/drivers/mmc/host/sdhci-s3c.c +++ b/drivers/mmc/host/sdhci-s3c.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/clk.h> | 19 | #include <linux/clk.h> |
20 | #include <linux/io.h> | 20 | #include <linux/io.h> |
21 | #include <linux/gpio.h> | ||
21 | 22 | ||
22 | #include <linux/mmc/host.h> | 23 | #include <linux/mmc/host.h> |
23 | 24 | ||
@@ -44,6 +45,8 @@ struct sdhci_s3c { | |||
44 | struct resource *ioarea; | 45 | struct resource *ioarea; |
45 | struct s3c_sdhci_platdata *pdata; | 46 | struct s3c_sdhci_platdata *pdata; |
46 | unsigned int cur_clk; | 47 | unsigned int cur_clk; |
48 | int ext_cd_irq; | ||
49 | int ext_cd_gpio; | ||
47 | 50 | ||
48 | struct clk *clk_io; | 51 | struct clk *clk_io; |
49 | struct clk *clk_bus[MAX_BUS_CLK]; | 52 | struct clk *clk_bus[MAX_BUS_CLK]; |
@@ -110,11 +113,6 @@ static unsigned int sdhci_s3c_get_max_clk(struct sdhci_host *host) | |||
110 | return max; | 113 | return max; |
111 | } | 114 | } |
112 | 115 | ||
113 | static unsigned int sdhci_s3c_get_timeout_clk(struct sdhci_host *host) | ||
114 | { | ||
115 | return sdhci_s3c_get_max_clk(host) / 1000000; | ||
116 | } | ||
117 | |||
118 | /** | 116 | /** |
119 | * sdhci_s3c_consider_clock - consider one the bus clocks for current setting | 117 | * sdhci_s3c_consider_clock - consider one the bus clocks for current setting |
120 | * @ourhost: Our SDHCI instance. | 118 | * @ourhost: Our SDHCI instance. |
@@ -188,7 +186,6 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock) | |||
188 | 186 | ||
189 | ourhost->cur_clk = best_src; | 187 | ourhost->cur_clk = best_src; |
190 | host->max_clk = clk_get_rate(clk); | 188 | host->max_clk = clk_get_rate(clk); |
191 | host->timeout_clk = sdhci_s3c_get_timeout_clk(host); | ||
192 | 189 | ||
193 | ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2); | 190 | ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2); |
194 | ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK; | 191 | ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK; |
@@ -209,12 +206,93 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock) | |||
209 | } | 206 | } |
210 | } | 207 | } |
211 | 208 | ||
209 | /** | ||
210 | * sdhci_s3c_get_min_clock - callback to get minimal supported clock value | ||
211 | * @host: The SDHCI host being queried | ||
212 | * | ||
213 | * To init mmc host properly a minimal clock value is needed. For high system | ||
214 | * bus clock's values the standard formula gives values out of allowed range. | ||
215 | * The clock still can be set to lower values, if clock source other then | ||
216 | * system bus is selected. | ||
217 | */ | ||
218 | static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host) | ||
219 | { | ||
220 | struct sdhci_s3c *ourhost = to_s3c(host); | ||
221 | unsigned int delta, min = UINT_MAX; | ||
222 | int src; | ||
223 | |||
224 | for (src = 0; src < MAX_BUS_CLK; src++) { | ||
225 | delta = sdhci_s3c_consider_clock(ourhost, src, 0); | ||
226 | if (delta == UINT_MAX) | ||
227 | continue; | ||
228 | /* delta is a negative value in this case */ | ||
229 | if (-delta < min) | ||
230 | min = -delta; | ||
231 | } | ||
232 | return min; | ||
233 | } | ||
234 | |||
212 | static struct sdhci_ops sdhci_s3c_ops = { | 235 | static struct sdhci_ops sdhci_s3c_ops = { |
213 | .get_max_clock = sdhci_s3c_get_max_clk, | 236 | .get_max_clock = sdhci_s3c_get_max_clk, |
214 | .get_timeout_clock = sdhci_s3c_get_timeout_clk, | ||
215 | .set_clock = sdhci_s3c_set_clock, | 237 | .set_clock = sdhci_s3c_set_clock, |
238 | .get_min_clock = sdhci_s3c_get_min_clock, | ||
216 | }; | 239 | }; |
217 | 240 | ||
241 | static void sdhci_s3c_notify_change(struct platform_device *dev, int state) | ||
242 | { | ||
243 | struct sdhci_host *host = platform_get_drvdata(dev); | ||
244 | if (host) { | ||
245 | mutex_lock(&host->lock); | ||
246 | if (state) { | ||
247 | dev_dbg(&dev->dev, "card inserted.\n"); | ||
248 | host->flags &= ~SDHCI_DEVICE_DEAD; | ||
249 | host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; | ||
250 | } else { | ||
251 | dev_dbg(&dev->dev, "card removed.\n"); | ||
252 | host->flags |= SDHCI_DEVICE_DEAD; | ||
253 | host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; | ||
254 | } | ||
255 | sdhci_card_detect(host); | ||
256 | mutex_unlock(&host->lock); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id) | ||
261 | { | ||
262 | struct sdhci_s3c *sc = dev_id; | ||
263 | int status = gpio_get_value(sc->ext_cd_gpio); | ||
264 | if (sc->pdata->ext_cd_gpio_invert) | ||
265 | status = !status; | ||
266 | sdhci_s3c_notify_change(sc->pdev, status); | ||
267 | return IRQ_HANDLED; | ||
268 | } | ||
269 | |||
270 | static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc) | ||
271 | { | ||
272 | struct s3c_sdhci_platdata *pdata = sc->pdata; | ||
273 | struct device *dev = &sc->pdev->dev; | ||
274 | |||
275 | if (gpio_request(pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) { | ||
276 | sc->ext_cd_gpio = pdata->ext_cd_gpio; | ||
277 | sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio); | ||
278 | if (sc->ext_cd_irq && | ||
279 | request_threaded_irq(sc->ext_cd_irq, NULL, | ||
280 | sdhci_s3c_gpio_card_detect_thread, | ||
281 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | ||
282 | dev_name(dev), sc) == 0) { | ||
283 | int status = gpio_get_value(sc->ext_cd_gpio); | ||
284 | if (pdata->ext_cd_gpio_invert) | ||
285 | status = !status; | ||
286 | sdhci_s3c_notify_change(sc->pdev, status); | ||
287 | } else { | ||
288 | dev_warn(dev, "cannot request irq for card detect\n"); | ||
289 | sc->ext_cd_irq = 0; | ||
290 | } | ||
291 | } else { | ||
292 | dev_err(dev, "cannot request gpio for card detect\n"); | ||
293 | } | ||
294 | } | ||
295 | |||
218 | static int __devinit sdhci_s3c_probe(struct platform_device *pdev) | 296 | static int __devinit sdhci_s3c_probe(struct platform_device *pdev) |
219 | { | 297 | { |
220 | struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data; | 298 | struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data; |
@@ -252,6 +330,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) | |||
252 | sc->host = host; | 330 | sc->host = host; |
253 | sc->pdev = pdev; | 331 | sc->pdev = pdev; |
254 | sc->pdata = pdata; | 332 | sc->pdata = pdata; |
333 | sc->ext_cd_gpio = -1; /* invalid gpio number */ | ||
255 | 334 | ||
256 | platform_set_drvdata(pdev, host); | 335 | platform_set_drvdata(pdev, host); |
257 | 336 | ||
@@ -318,6 +397,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) | |||
318 | 397 | ||
319 | /* Setup quirks for the controller */ | 398 | /* Setup quirks for the controller */ |
320 | host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC; | 399 | host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC; |
400 | host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT; | ||
321 | 401 | ||
322 | #ifndef CONFIG_MMC_SDHCI_S3C_DMA | 402 | #ifndef CONFIG_MMC_SDHCI_S3C_DMA |
323 | 403 | ||
@@ -332,15 +412,34 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) | |||
332 | * SDHCI block, or a missing configuration that needs to be set. */ | 412 | * SDHCI block, or a missing configuration that needs to be set. */ |
333 | host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ; | 413 | host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ; |
334 | 414 | ||
415 | if (pdata->cd_type == S3C_SDHCI_CD_NONE || | ||
416 | pdata->cd_type == S3C_SDHCI_CD_PERMANENT) | ||
417 | host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; | ||
418 | |||
419 | if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT) | ||
420 | host->mmc->caps = MMC_CAP_NONREMOVABLE; | ||
421 | |||
335 | host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR | | 422 | host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR | |
336 | SDHCI_QUIRK_32BIT_DMA_SIZE); | 423 | SDHCI_QUIRK_32BIT_DMA_SIZE); |
337 | 424 | ||
425 | /* HSMMC on Samsung SoCs uses SDCLK as timeout clock */ | ||
426 | host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK; | ||
427 | |||
338 | ret = sdhci_add_host(host); | 428 | ret = sdhci_add_host(host); |
339 | if (ret) { | 429 | if (ret) { |
340 | dev_err(dev, "sdhci_add_host() failed\n"); | 430 | dev_err(dev, "sdhci_add_host() failed\n"); |
341 | goto err_add_host; | 431 | goto err_add_host; |
342 | } | 432 | } |
343 | 433 | ||
434 | /* The following two methods of card detection might call | ||
435 | sdhci_s3c_notify_change() immediately, so they can be called | ||
436 | only after sdhci_add_host(). Setup errors are ignored. */ | ||
437 | if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_init) | ||
438 | pdata->ext_cd_init(&sdhci_s3c_notify_change); | ||
439 | if (pdata->cd_type == S3C_SDHCI_CD_GPIO && | ||
440 | gpio_is_valid(pdata->ext_cd_gpio)) | ||
441 | sdhci_s3c_setup_card_detect_gpio(sc); | ||
442 | |||
344 | return 0; | 443 | return 0; |
345 | 444 | ||
346 | err_add_host: | 445 | err_add_host: |
@@ -365,10 +464,20 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) | |||
365 | 464 | ||
366 | static int __devexit sdhci_s3c_remove(struct platform_device *pdev) | 465 | static int __devexit sdhci_s3c_remove(struct platform_device *pdev) |
367 | { | 466 | { |
467 | struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data; | ||
368 | struct sdhci_host *host = platform_get_drvdata(pdev); | 468 | struct sdhci_host *host = platform_get_drvdata(pdev); |
369 | struct sdhci_s3c *sc = sdhci_priv(host); | 469 | struct sdhci_s3c *sc = sdhci_priv(host); |
370 | int ptr; | 470 | int ptr; |
371 | 471 | ||
472 | if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup) | ||
473 | pdata->ext_cd_cleanup(&sdhci_s3c_notify_change); | ||
474 | |||
475 | if (sc->ext_cd_irq) | ||
476 | free_irq(sc->ext_cd_irq, sc); | ||
477 | |||
478 | if (gpio_is_valid(sc->ext_cd_gpio)) | ||
479 | gpio_free(sc->ext_cd_gpio); | ||
480 | |||
372 | sdhci_remove_host(host, 1); | 481 | sdhci_remove_host(host, 1); |
373 | 482 | ||
374 | for (ptr = 0; ptr < 3; ptr++) { | 483 | for (ptr = 0; ptr < 3; ptr++) { |
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index c6d1bd8d4ac4..785512133b50 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/dma-mapping.h> | 19 | #include <linux/dma-mapping.h> |
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/scatterlist.h> | 21 | #include <linux/scatterlist.h> |
22 | #include <linux/regulator/consumer.h> | ||
22 | 23 | ||
23 | #include <linux/leds.h> | 24 | #include <linux/leds.h> |
24 | 25 | ||
@@ -817,8 +818,12 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host, | |||
817 | WARN_ON(!host->data); | 818 | WARN_ON(!host->data); |
818 | 819 | ||
819 | mode = SDHCI_TRNS_BLK_CNT_EN; | 820 | mode = SDHCI_TRNS_BLK_CNT_EN; |
820 | if (data->blocks > 1) | 821 | if (data->blocks > 1) { |
821 | mode |= SDHCI_TRNS_MULTI; | 822 | if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) |
823 | mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12; | ||
824 | else | ||
825 | mode |= SDHCI_TRNS_MULTI; | ||
826 | } | ||
822 | if (data->flags & MMC_DATA_READ) | 827 | if (data->flags & MMC_DATA_READ) |
823 | mode |= SDHCI_TRNS_READ; | 828 | mode |= SDHCI_TRNS_READ; |
824 | if (host->flags & SDHCI_REQ_USE_DMA) | 829 | if (host->flags & SDHCI_REQ_USE_DMA) |
@@ -1108,6 +1113,12 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
1108 | #ifndef SDHCI_USE_LEDS_CLASS | 1113 | #ifndef SDHCI_USE_LEDS_CLASS |
1109 | sdhci_activate_led(host); | 1114 | sdhci_activate_led(host); |
1110 | #endif | 1115 | #endif |
1116 | if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) { | ||
1117 | if (mrq->stop) { | ||
1118 | mrq->data->stop = NULL; | ||
1119 | mrq->stop = NULL; | ||
1120 | } | ||
1121 | } | ||
1111 | 1122 | ||
1112 | host->mrq = mrq; | 1123 | host->mrq = mrq; |
1113 | 1124 | ||
@@ -1159,6 +1170,11 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
1159 | 1170 | ||
1160 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); | 1171 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
1161 | 1172 | ||
1173 | if (ios->bus_width == MMC_BUS_WIDTH_8) | ||
1174 | ctrl |= SDHCI_CTRL_8BITBUS; | ||
1175 | else | ||
1176 | ctrl &= ~SDHCI_CTRL_8BITBUS; | ||
1177 | |||
1162 | if (ios->bus_width == MMC_BUS_WIDTH_4) | 1178 | if (ios->bus_width == MMC_BUS_WIDTH_4) |
1163 | ctrl |= SDHCI_CTRL_4BITBUS; | 1179 | ctrl |= SDHCI_CTRL_4BITBUS; |
1164 | else | 1180 | else |
@@ -1603,7 +1619,10 @@ int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state) | |||
1603 | 1619 | ||
1604 | free_irq(host->irq, host); | 1620 | free_irq(host->irq, host); |
1605 | 1621 | ||
1606 | return 0; | 1622 | if (host->vmmc) |
1623 | ret = regulator_disable(host->vmmc); | ||
1624 | |||
1625 | return ret; | ||
1607 | } | 1626 | } |
1608 | 1627 | ||
1609 | EXPORT_SYMBOL_GPL(sdhci_suspend_host); | 1628 | EXPORT_SYMBOL_GPL(sdhci_suspend_host); |
@@ -1612,6 +1631,13 @@ int sdhci_resume_host(struct sdhci_host *host) | |||
1612 | { | 1631 | { |
1613 | int ret; | 1632 | int ret; |
1614 | 1633 | ||
1634 | if (host->vmmc) { | ||
1635 | int ret = regulator_enable(host->vmmc); | ||
1636 | if (ret) | ||
1637 | return ret; | ||
1638 | } | ||
1639 | |||
1640 | |||
1615 | if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { | 1641 | if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { |
1616 | if (host->ops->enable_dma) | 1642 | if (host->ops->enable_dma) |
1617 | host->ops->enable_dma(host); | 1643 | host->ops->enable_dma(host); |
@@ -1687,7 +1713,8 @@ int sdhci_add_host(struct sdhci_host *host) | |||
1687 | host->version); | 1713 | host->version); |
1688 | } | 1714 | } |
1689 | 1715 | ||
1690 | caps = sdhci_readl(host, SDHCI_CAPABILITIES); | 1716 | caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps : |
1717 | sdhci_readl(host, SDHCI_CAPABILITIES); | ||
1691 | 1718 | ||
1692 | if (host->quirks & SDHCI_QUIRK_FORCE_DMA) | 1719 | if (host->quirks & SDHCI_QUIRK_FORCE_DMA) |
1693 | host->flags |= SDHCI_USE_SDMA; | 1720 | host->flags |= SDHCI_USE_SDMA; |
@@ -1785,13 +1812,12 @@ int sdhci_add_host(struct sdhci_host *host) | |||
1785 | * Set host parameters. | 1812 | * Set host parameters. |
1786 | */ | 1813 | */ |
1787 | mmc->ops = &sdhci_ops; | 1814 | mmc->ops = &sdhci_ops; |
1788 | if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK && | 1815 | if (host->ops->get_min_clock) |
1789 | host->ops->set_clock && host->ops->get_min_clock) | ||
1790 | mmc->f_min = host->ops->get_min_clock(host); | 1816 | mmc->f_min = host->ops->get_min_clock(host); |
1791 | else | 1817 | else |
1792 | mmc->f_min = host->max_clk / 256; | 1818 | mmc->f_min = host->max_clk / 256; |
1793 | mmc->f_max = host->max_clk; | 1819 | mmc->f_max = host->max_clk; |
1794 | mmc->caps = MMC_CAP_SDIO_IRQ; | 1820 | mmc->caps |= MMC_CAP_SDIO_IRQ; |
1795 | 1821 | ||
1796 | if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) | 1822 | if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) |
1797 | mmc->caps |= MMC_CAP_4_BIT_DATA; | 1823 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
@@ -1884,6 +1910,14 @@ int sdhci_add_host(struct sdhci_host *host) | |||
1884 | if (ret) | 1910 | if (ret) |
1885 | goto untasklet; | 1911 | goto untasklet; |
1886 | 1912 | ||
1913 | host->vmmc = regulator_get(mmc_dev(mmc), "vmmc"); | ||
1914 | if (IS_ERR(host->vmmc)) { | ||
1915 | printk(KERN_INFO "%s: no vmmc regulator found\n", mmc_hostname(mmc)); | ||
1916 | host->vmmc = NULL; | ||
1917 | } else { | ||
1918 | regulator_enable(host->vmmc); | ||
1919 | } | ||
1920 | |||
1887 | sdhci_init(host, 0); | 1921 | sdhci_init(host, 0); |
1888 | 1922 | ||
1889 | #ifdef CONFIG_MMC_DEBUG | 1923 | #ifdef CONFIG_MMC_DEBUG |
@@ -1968,6 +2002,11 @@ void sdhci_remove_host(struct sdhci_host *host, int dead) | |||
1968 | tasklet_kill(&host->card_tasklet); | 2002 | tasklet_kill(&host->card_tasklet); |
1969 | tasklet_kill(&host->finish_tasklet); | 2003 | tasklet_kill(&host->finish_tasklet); |
1970 | 2004 | ||
2005 | if (host->vmmc) { | ||
2006 | regulator_disable(host->vmmc); | ||
2007 | regulator_put(host->vmmc); | ||
2008 | } | ||
2009 | |||
1971 | kfree(host->adma_desc); | 2010 | kfree(host->adma_desc); |
1972 | kfree(host->align_buffer); | 2011 | kfree(host->align_buffer); |
1973 | 2012 | ||
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index c8468134adc9..036cfae76368 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h | |||
@@ -72,6 +72,7 @@ | |||
72 | #define SDHCI_CTRL_ADMA1 0x08 | 72 | #define SDHCI_CTRL_ADMA1 0x08 |
73 | #define SDHCI_CTRL_ADMA32 0x10 | 73 | #define SDHCI_CTRL_ADMA32 0x10 |
74 | #define SDHCI_CTRL_ADMA64 0x18 | 74 | #define SDHCI_CTRL_ADMA64 0x18 |
75 | #define SDHCI_CTRL_8BITBUS 0x20 | ||
75 | 76 | ||
76 | #define SDHCI_POWER_CONTROL 0x29 | 77 | #define SDHCI_POWER_CONTROL 0x29 |
77 | #define SDHCI_POWER_ON 0x01 | 78 | #define SDHCI_POWER_ON 0x01 |
@@ -240,12 +241,18 @@ struct sdhci_host { | |||
240 | #define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25) | 241 | #define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25) |
241 | /* Controller cannot support End Attribute in NOP ADMA descriptor */ | 242 | /* Controller cannot support End Attribute in NOP ADMA descriptor */ |
242 | #define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26) | 243 | #define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26) |
244 | /* Controller is missing device caps. Use caps provided by host */ | ||
245 | #define SDHCI_QUIRK_MISSING_CAPS (1<<27) | ||
246 | /* Controller uses Auto CMD12 command to stop the transfer */ | ||
247 | #define SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 (1<<28) | ||
243 | 248 | ||
244 | int irq; /* Device IRQ */ | 249 | int irq; /* Device IRQ */ |
245 | void __iomem * ioaddr; /* Mapped address */ | 250 | void __iomem * ioaddr; /* Mapped address */ |
246 | 251 | ||
247 | const struct sdhci_ops *ops; /* Low level hw interface */ | 252 | const struct sdhci_ops *ops; /* Low level hw interface */ |
248 | 253 | ||
254 | struct regulator *vmmc; /* Power regulator */ | ||
255 | |||
249 | /* Internal data */ | 256 | /* Internal data */ |
250 | struct mmc_host *mmc; /* MMC structure */ | 257 | struct mmc_host *mmc; /* MMC structure */ |
251 | u64 dma_mask; /* custom DMA mask */ | 258 | u64 dma_mask; /* custom DMA mask */ |
@@ -292,6 +299,8 @@ struct sdhci_host { | |||
292 | 299 | ||
293 | struct timer_list timer; /* Timer for timeouts */ | 300 | struct timer_list timer; /* Timer for timeouts */ |
294 | 301 | ||
302 | unsigned int caps; /* Alternative capabilities */ | ||
303 | |||
295 | unsigned long private[0] ____cacheline_aligned; | 304 | unsigned long private[0] ____cacheline_aligned; |
296 | }; | 305 | }; |
297 | 306 | ||
@@ -407,6 +416,7 @@ static inline void *sdhci_priv(struct sdhci_host *host) | |||
407 | return (void *)host->private; | 416 | return (void *)host->private; |
408 | } | 417 | } |
409 | 418 | ||
419 | extern void sdhci_card_detect(struct sdhci_host *host); | ||
410 | extern int sdhci_add_host(struct sdhci_host *host); | 420 | extern int sdhci_add_host(struct sdhci_host *host); |
411 | extern void sdhci_remove_host(struct sdhci_host *host, int dead); | 421 | extern void sdhci_remove_host(struct sdhci_host *host, int dead); |
412 | 422 | ||
diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c index e7507af3856e..7aa65bb2af4a 100644 --- a/drivers/mmc/host/sdricoh_cs.c +++ b/drivers/mmc/host/sdricoh_cs.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/ioport.h> | 30 | #include <linux/ioport.h> |
31 | #include <linux/scatterlist.h> | 31 | #include <linux/scatterlist.h> |
32 | 32 | ||
33 | #include <pcmcia/cs_types.h> | ||
34 | #include <pcmcia/cs.h> | 33 | #include <pcmcia/cs.h> |
35 | #include <pcmcia/cistpl.h> | 34 | #include <pcmcia/cistpl.h> |
36 | #include <pcmcia/ds.h> | 35 | #include <pcmcia/ds.h> |