aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/card
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc/card')
-rw-r--r--drivers/mmc/card/Kconfig3
-rw-r--r--drivers/mmc/card/block.c71
-rw-r--r--drivers/mmc/card/mmc_test.c4
-rw-r--r--drivers/mmc/card/queue.c23
4 files changed, 42 insertions, 59 deletions
diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
index dd0f398ee2f5..3f2a912659af 100644
--- a/drivers/mmc/card/Kconfig
+++ b/drivers/mmc/card/Kconfig
@@ -2,7 +2,7 @@
2# MMC/SD card drivers 2# MMC/SD card drivers
3# 3#
4 4
5comment "MMC/SD Card Drivers" 5comment "MMC/SD/SDIO Card Drivers"
6 6
7config MMC_BLOCK 7config MMC_BLOCK
8 tristate "MMC block device driver" 8 tristate "MMC block device driver"
@@ -34,7 +34,6 @@ config MMC_BLOCK_BOUNCE
34 34
35config SDIO_UART 35config SDIO_UART
36 tristate "SDIO UART/GPS class support" 36 tristate "SDIO UART/GPS class support"
37 depends on MMC
38 help 37 help
39 SDIO function driver for SDIO cards that implements the UART 38 SDIO function driver for SDIO cards that implements the UART
40 class, as well as the GPS class which appears like a UART. 39 class, as well as the GPS class which appears like a UART.
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 86dbb366415a..24c97d3d16bb 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -29,6 +29,7 @@
29#include <linux/blkdev.h> 29#include <linux/blkdev.h>
30#include <linux/mutex.h> 30#include <linux/mutex.h>
31#include <linux/scatterlist.h> 31#include <linux/scatterlist.h>
32#include <linux/string_helpers.h>
32 33
33#include <linux/mmc/card.h> 34#include <linux/mmc/card.h>
34#include <linux/mmc/host.h> 35#include <linux/mmc/host.h>
@@ -57,7 +58,6 @@ struct mmc_blk_data {
57 struct mmc_queue queue; 58 struct mmc_queue queue;
58 59
59 unsigned int usage; 60 unsigned int usage;
60 unsigned int block_bits;
61 unsigned int read_only; 61 unsigned int read_only;
62}; 62};
63 63
@@ -83,7 +83,7 @@ static void mmc_blk_put(struct mmc_blk_data *md)
83 mutex_lock(&open_lock); 83 mutex_lock(&open_lock);
84 md->usage--; 84 md->usage--;
85 if (md->usage == 0) { 85 if (md->usage == 0) {
86 int devidx = md->disk->first_minor >> MMC_SHIFT; 86 int devidx = MINOR(disk_devt(md->disk)) >> MMC_SHIFT;
87 __clear_bit(devidx, dev_use); 87 __clear_bit(devidx, dev_use);
88 88
89 put_disk(md->disk); 89 put_disk(md->disk);
@@ -103,8 +103,10 @@ static int mmc_blk_open(struct inode *inode, struct file *filp)
103 check_disk_change(inode->i_bdev); 103 check_disk_change(inode->i_bdev);
104 ret = 0; 104 ret = 0;
105 105
106 if ((filp->f_mode & FMODE_WRITE) && md->read_only) 106 if ((filp->f_mode & FMODE_WRITE) && md->read_only) {
107 mmc_blk_put(md);
107 ret = -EROFS; 108 ret = -EROFS;
109 }
108 } 110 }
109 111
110 return ret; 112 return ret;
@@ -213,8 +215,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
213 struct mmc_blk_data *md = mq->data; 215 struct mmc_blk_data *md = mq->data;
214 struct mmc_card *card = md->queue.card; 216 struct mmc_card *card = md->queue.card;
215 struct mmc_blk_request brq; 217 struct mmc_blk_request brq;
216 int ret = 1, data_size, i; 218 int ret = 1;
217 struct scatterlist *sg;
218 219
219 mmc_claim_host(card->host); 220 mmc_claim_host(card->host);
220 221
@@ -230,13 +231,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
230 if (!mmc_card_blockaddr(card)) 231 if (!mmc_card_blockaddr(card))
231 brq.cmd.arg <<= 9; 232 brq.cmd.arg <<= 9;
232 brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; 233 brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
233 brq.data.blksz = 1 << md->block_bits; 234 brq.data.blksz = 512;
234 brq.stop.opcode = MMC_STOP_TRANSMISSION; 235 brq.stop.opcode = MMC_STOP_TRANSMISSION;
235 brq.stop.arg = 0; 236 brq.stop.arg = 0;
236 brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; 237 brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
237 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); 238 brq.data.blocks = req->nr_sectors;
238 if (brq.data.blocks > card->host->max_blk_count)
239 brq.data.blocks = card->host->max_blk_count;
240 239
241 if (brq.data.blocks > 1) { 240 if (brq.data.blocks > 1) {
242 /* SPI multiblock writes terminate using a special 241 /* SPI multiblock writes terminate using a special
@@ -268,24 +267,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
268 267
269 mmc_queue_bounce_pre(mq); 268 mmc_queue_bounce_pre(mq);
270 269
271 /*
272 * Adjust the sg list so it is the same size as the
273 * request.
274 */
275 if (brq.data.blocks !=
276 (req->nr_sectors >> (md->block_bits - 9))) {
277 data_size = brq.data.blocks * brq.data.blksz;
278 for_each_sg(brq.data.sg, sg, brq.data.sg_len, i) {
279 data_size -= sg->length;
280 if (data_size <= 0) {
281 sg->length += data_size;
282 i++;
283 break;
284 }
285 }
286 brq.data.sg_len = i;
287 }
288
289 mmc_wait_for_req(card->host, &brq.mrq); 270 mmc_wait_for_req(card->host, &brq.mrq);
290 271
291 mmc_queue_bounce_post(mq); 272 mmc_queue_bounce_post(mq);
@@ -370,16 +351,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
370 if (rq_data_dir(req) != READ) { 351 if (rq_data_dir(req) != READ) {
371 if (mmc_card_sd(card)) { 352 if (mmc_card_sd(card)) {
372 u32 blocks; 353 u32 blocks;
373 unsigned int bytes;
374 354
375 blocks = mmc_sd_num_wr_blocks(card); 355 blocks = mmc_sd_num_wr_blocks(card);
376 if (blocks != (u32)-1) { 356 if (blocks != (u32)-1) {
377 if (card->csd.write_partial)
378 bytes = blocks << md->block_bits;
379 else
380 bytes = blocks << 9;
381 spin_lock_irq(&md->lock); 357 spin_lock_irq(&md->lock);
382 ret = __blk_end_request(req, 0, bytes); 358 ret = __blk_end_request(req, 0, blocks << 9);
383 spin_unlock_irq(&md->lock); 359 spin_unlock_irq(&md->lock);
384 } 360 }
385 } else { 361 } else {
@@ -429,13 +405,6 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
429 */ 405 */
430 md->read_only = mmc_blk_readonly(card); 406 md->read_only = mmc_blk_readonly(card);
431 407
432 /*
433 * Both SD and MMC specifications state (although a bit
434 * unclearly in the MMC case) that a block size of 512
435 * bytes must always be supported by the card.
436 */
437 md->block_bits = 9;
438
439 md->disk = alloc_disk(1 << MMC_SHIFT); 408 md->disk = alloc_disk(1 << MMC_SHIFT);
440 if (md->disk == NULL) { 409 if (md->disk == NULL) {
441 ret = -ENOMEM; 410 ret = -ENOMEM;
@@ -473,7 +442,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
473 442
474 sprintf(md->disk->disk_name, "mmcblk%d", devidx); 443 sprintf(md->disk->disk_name, "mmcblk%d", devidx);
475 444
476 blk_queue_hardsect_size(md->queue.queue, 1 << md->block_bits); 445 blk_queue_hardsect_size(md->queue.queue, 512);
477 446
478 if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) { 447 if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
479 /* 448 /*
@@ -511,7 +480,7 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
511 480
512 mmc_claim_host(card->host); 481 mmc_claim_host(card->host);
513 cmd.opcode = MMC_SET_BLOCKLEN; 482 cmd.opcode = MMC_SET_BLOCKLEN;
514 cmd.arg = 1 << md->block_bits; 483 cmd.arg = 512;
515 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; 484 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
516 err = mmc_wait_for_cmd(card->host, &cmd, 5); 485 err = mmc_wait_for_cmd(card->host, &cmd, 5);
517 mmc_release_host(card->host); 486 mmc_release_host(card->host);
@@ -530,6 +499,8 @@ static int mmc_blk_probe(struct mmc_card *card)
530 struct mmc_blk_data *md; 499 struct mmc_blk_data *md;
531 int err; 500 int err;
532 501
502 char cap_str[10];
503
533 /* 504 /*
534 * Check that the card supports the command class(es) we need. 505 * Check that the card supports the command class(es) we need.
535 */ 506 */
@@ -544,10 +515,11 @@ static int mmc_blk_probe(struct mmc_card *card)
544 if (err) 515 if (err)
545 goto out; 516 goto out;
546 517
547 printk(KERN_INFO "%s: %s %s %lluKiB %s\n", 518 string_get_size(get_capacity(md->disk) << 9, STRING_UNITS_2,
519 cap_str, sizeof(cap_str));
520 printk(KERN_INFO "%s: %s %s %s %s\n",
548 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card), 521 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
549 (unsigned long long)(get_capacity(md->disk) >> 1), 522 cap_str, md->read_only ? "(ro)" : "");
550 md->read_only ? "(ro)" : "");
551 523
552 mmc_set_drvdata(card, md); 524 mmc_set_drvdata(card, md);
553 add_disk(md->disk); 525 add_disk(md->disk);
@@ -613,14 +585,19 @@ static struct mmc_driver mmc_driver = {
613 585
614static int __init mmc_blk_init(void) 586static int __init mmc_blk_init(void)
615{ 587{
616 int res = -ENOMEM; 588 int res;
617 589
618 res = register_blkdev(MMC_BLOCK_MAJOR, "mmc"); 590 res = register_blkdev(MMC_BLOCK_MAJOR, "mmc");
619 if (res) 591 if (res)
620 goto out; 592 goto out;
621 593
622 return mmc_register_driver(&mmc_driver); 594 res = mmc_register_driver(&mmc_driver);
595 if (res)
596 goto out2;
623 597
598 return 0;
599 out2:
600 unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
624 out: 601 out:
625 return res; 602 return res;
626} 603}
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index f26b01d811ae..b92b172074ee 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -1040,7 +1040,7 @@ static const struct mmc_test_case mmc_test_cases[] = {
1040 1040
1041}; 1041};
1042 1042
1043static struct mutex mmc_test_lock; 1043static DEFINE_MUTEX(mmc_test_lock);
1044 1044
1045static void mmc_test_run(struct mmc_test_card *test, int testcase) 1045static void mmc_test_run(struct mmc_test_card *test, int testcase)
1046{ 1046{
@@ -1171,8 +1171,6 @@ static int mmc_test_probe(struct mmc_card *card)
1171 if ((card->type != MMC_TYPE_MMC) && (card->type != MMC_TYPE_SD)) 1171 if ((card->type != MMC_TYPE_MMC) && (card->type != MMC_TYPE_SD))
1172 return -ENODEV; 1172 return -ENODEV;
1173 1173
1174 mutex_init(&mmc_test_lock);
1175
1176 ret = device_create_file(&card->dev, &dev_attr_test); 1174 ret = device_create_file(&card->dev, &dev_attr_test);
1177 if (ret) 1175 if (ret)
1178 return ret; 1176 return ret;
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 3dee97e7d165..406989e992ba 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -31,7 +31,7 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
31 /* 31 /*
32 * We only like normal block requests. 32 * We only like normal block requests.
33 */ 33 */
34 if (!blk_fs_request(req) && !blk_pc_request(req)) { 34 if (!blk_fs_request(req)) {
35 blk_dump_rq_flags(req, "MMC bad request"); 35 blk_dump_rq_flags(req, "MMC bad request");
36 return BLKPREP_KILL; 36 return BLKPREP_KILL;
37 } 37 }
@@ -131,6 +131,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
131 mq->req = NULL; 131 mq->req = NULL;
132 132
133 blk_queue_prep_rq(mq->queue, mmc_prep_request); 133 blk_queue_prep_rq(mq->queue, mmc_prep_request);
134 blk_queue_ordered(mq->queue, QUEUE_ORDERED_DRAIN, NULL);
134 135
135#ifdef CONFIG_MMC_BLOCK_BOUNCE 136#ifdef CONFIG_MMC_BLOCK_BOUNCE
136 if (host->max_hw_segs == 1) { 137 if (host->max_hw_segs == 1) {
@@ -142,12 +143,19 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
142 bouncesz = host->max_req_size; 143 bouncesz = host->max_req_size;
143 if (bouncesz > host->max_seg_size) 144 if (bouncesz > host->max_seg_size)
144 bouncesz = host->max_seg_size; 145 bouncesz = host->max_seg_size;
146 if (bouncesz > (host->max_blk_count * 512))
147 bouncesz = host->max_blk_count * 512;
148
149 if (bouncesz > 512) {
150 mq->bounce_buf = kmalloc(bouncesz, GFP_KERNEL);
151 if (!mq->bounce_buf) {
152 printk(KERN_WARNING "%s: unable to "
153 "allocate bounce buffer\n",
154 mmc_card_name(card));
155 }
156 }
145 157
146 mq->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); 158 if (mq->bounce_buf) {
147 if (!mq->bounce_buf) {
148 printk(KERN_WARNING "%s: unable to allocate "
149 "bounce buffer\n", mmc_card_name(card));
150 } else {
151 blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_ANY); 159 blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_ANY);
152 blk_queue_max_sectors(mq->queue, bouncesz / 512); 160 blk_queue_max_sectors(mq->queue, bouncesz / 512);
153 blk_queue_max_phys_segments(mq->queue, bouncesz / 512); 161 blk_queue_max_phys_segments(mq->queue, bouncesz / 512);
@@ -175,7 +183,8 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
175 183
176 if (!mq->bounce_buf) { 184 if (!mq->bounce_buf) {
177 blk_queue_bounce_limit(mq->queue, limit); 185 blk_queue_bounce_limit(mq->queue, limit);
178 blk_queue_max_sectors(mq->queue, host->max_req_size / 512); 186 blk_queue_max_sectors(mq->queue,
187 min(host->max_blk_count, host->max_req_size / 512));
179 blk_queue_max_phys_segments(mq->queue, host->max_phys_segs); 188 blk_queue_max_phys_segments(mq->queue, host->max_phys_segs);
180 blk_queue_max_hw_segments(mq->queue, host->max_hw_segs); 189 blk_queue_max_hw_segments(mq->queue, host->max_hw_segs);
181 blk_queue_max_segment_size(mq->queue, host->max_seg_size); 190 blk_queue_max_segment_size(mq->queue, host->max_seg_size);