aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/card
diff options
context:
space:
mode:
authorRussell King <rmk@dyn-67.arm.linux.org.uk>2008-10-15 18:16:07 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2008-10-15 18:16:07 -0400
commit2502991560dc8244dbe10e48473d85722c1e2ec1 (patch)
tree63b1f3be2ed56ff06f1e8db709e4ce85d69c3add /drivers/mmc/card
parent7e69a8c4d06b7ecb874f571e82b715a9f79bc3c4 (diff)
parenta9ff8f6462635c8d9f8d64b7b10ddcea8404d77b (diff)
Merge branch 'fixes' into for-linus
Conflicts: arch/arm/mach-versatile/core.c
Diffstat (limited to 'drivers/mmc/card')
-rw-r--r--drivers/mmc/card/Kconfig3
-rw-r--r--drivers/mmc/card/block.c58
-rw-r--r--drivers/mmc/card/queue.c23
3 files changed, 31 insertions, 53 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 ebc8b9d77613..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);
@@ -215,8 +215,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
215 struct mmc_blk_data *md = mq->data; 215 struct mmc_blk_data *md = mq->data;
216 struct mmc_card *card = md->queue.card; 216 struct mmc_card *card = md->queue.card;
217 struct mmc_blk_request brq; 217 struct mmc_blk_request brq;
218 int ret = 1, data_size, i; 218 int ret = 1;
219 struct scatterlist *sg;
220 219
221 mmc_claim_host(card->host); 220 mmc_claim_host(card->host);
222 221
@@ -232,13 +231,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
232 if (!mmc_card_blockaddr(card)) 231 if (!mmc_card_blockaddr(card))
233 brq.cmd.arg <<= 9; 232 brq.cmd.arg <<= 9;
234 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;
235 brq.data.blksz = 1 << md->block_bits; 234 brq.data.blksz = 512;
236 brq.stop.opcode = MMC_STOP_TRANSMISSION; 235 brq.stop.opcode = MMC_STOP_TRANSMISSION;
237 brq.stop.arg = 0; 236 brq.stop.arg = 0;
238 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;
239 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); 238 brq.data.blocks = req->nr_sectors;
240 if (brq.data.blocks > card->host->max_blk_count)
241 brq.data.blocks = card->host->max_blk_count;
242 239
243 if (brq.data.blocks > 1) { 240 if (brq.data.blocks > 1) {
244 /* SPI multiblock writes terminate using a special 241 /* SPI multiblock writes terminate using a special
@@ -270,24 +267,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
270 267
271 mmc_queue_bounce_pre(mq); 268 mmc_queue_bounce_pre(mq);
272 269
273 /*
274 * Adjust the sg list so it is the same size as the
275 * request.
276 */
277 if (brq.data.blocks !=
278 (req->nr_sectors >> (md->block_bits - 9))) {
279 data_size = brq.data.blocks * brq.data.blksz;
280 for_each_sg(brq.data.sg, sg, brq.data.sg_len, i) {
281 data_size -= sg->length;
282 if (data_size <= 0) {
283 sg->length += data_size;
284 i++;
285 break;
286 }
287 }
288 brq.data.sg_len = i;
289 }
290
291 mmc_wait_for_req(card->host, &brq.mrq); 270 mmc_wait_for_req(card->host, &brq.mrq);
292 271
293 mmc_queue_bounce_post(mq); 272 mmc_queue_bounce_post(mq);
@@ -372,16 +351,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
372 if (rq_data_dir(req) != READ) { 351 if (rq_data_dir(req) != READ) {
373 if (mmc_card_sd(card)) { 352 if (mmc_card_sd(card)) {
374 u32 blocks; 353 u32 blocks;
375 unsigned int bytes;
376 354
377 blocks = mmc_sd_num_wr_blocks(card); 355 blocks = mmc_sd_num_wr_blocks(card);
378 if (blocks != (u32)-1) { 356 if (blocks != (u32)-1) {
379 if (card->csd.write_partial)
380 bytes = blocks << md->block_bits;
381 else
382 bytes = blocks << 9;
383 spin_lock_irq(&md->lock); 357 spin_lock_irq(&md->lock);
384 ret = __blk_end_request(req, 0, bytes); 358 ret = __blk_end_request(req, 0, blocks << 9);
385 spin_unlock_irq(&md->lock); 359 spin_unlock_irq(&md->lock);
386 } 360 }
387 } else { 361 } else {
@@ -431,13 +405,6 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
431 */ 405 */
432 md->read_only = mmc_blk_readonly(card); 406 md->read_only = mmc_blk_readonly(card);
433 407
434 /*
435 * Both SD and MMC specifications state (although a bit
436 * unclearly in the MMC case) that a block size of 512
437 * bytes must always be supported by the card.
438 */
439 md->block_bits = 9;
440
441 md->disk = alloc_disk(1 << MMC_SHIFT); 408 md->disk = alloc_disk(1 << MMC_SHIFT);
442 if (md->disk == NULL) { 409 if (md->disk == NULL) {
443 ret = -ENOMEM; 410 ret = -ENOMEM;
@@ -475,7 +442,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
475 442
476 sprintf(md->disk->disk_name, "mmcblk%d", devidx); 443 sprintf(md->disk->disk_name, "mmcblk%d", devidx);
477 444
478 blk_queue_hardsect_size(md->queue.queue, 1 << md->block_bits); 445 blk_queue_hardsect_size(md->queue.queue, 512);
479 446
480 if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) { 447 if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
481 /* 448 /*
@@ -513,7 +480,7 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
513 480
514 mmc_claim_host(card->host); 481 mmc_claim_host(card->host);
515 cmd.opcode = MMC_SET_BLOCKLEN; 482 cmd.opcode = MMC_SET_BLOCKLEN;
516 cmd.arg = 1 << md->block_bits; 483 cmd.arg = 512;
517 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;
518 err = mmc_wait_for_cmd(card->host, &cmd, 5); 485 err = mmc_wait_for_cmd(card->host, &cmd, 5);
519 mmc_release_host(card->host); 486 mmc_release_host(card->host);
@@ -532,6 +499,8 @@ static int mmc_blk_probe(struct mmc_card *card)
532 struct mmc_blk_data *md; 499 struct mmc_blk_data *md;
533 int err; 500 int err;
534 501
502 char cap_str[10];
503
535 /* 504 /*
536 * Check that the card supports the command class(es) we need. 505 * Check that the card supports the command class(es) we need.
537 */ 506 */
@@ -546,10 +515,11 @@ static int mmc_blk_probe(struct mmc_card *card)
546 if (err) 515 if (err)
547 goto out; 516 goto out;
548 517
549 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",
550 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),
551 (unsigned long long)(get_capacity(md->disk) >> 1), 522 cap_str, md->read_only ? "(ro)" : "");
552 md->read_only ? "(ro)" : "");
553 523
554 mmc_set_drvdata(card, md); 524 mmc_set_drvdata(card, md);
555 add_disk(md->disk); 525 add_disk(md->disk);
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);