]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/mmc/card/block.c
Merge branch 'v28-range-hrtimers-for-linus-v2' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-omap-h63xx.git] / drivers / mmc / card / block.c
index ebc8b9d77613132f290b7372196ab50bfe416144..3d067c35185db9704157d8bc4bddbecc20bf22c7 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/blkdev.h>
 #include <linux/mutex.h>
 #include <linux/scatterlist.h>
+#include <linux/string_helpers.h>
 
 #include <linux/mmc/card.h>
 #include <linux/mmc/host.h>
@@ -57,7 +58,6 @@ struct mmc_blk_data {
        struct mmc_queue queue;
 
        unsigned int    usage;
-       unsigned int    block_bits;
        unsigned int    read_only;
 };
 
@@ -83,7 +83,7 @@ static void mmc_blk_put(struct mmc_blk_data *md)
        mutex_lock(&open_lock);
        md->usage--;
        if (md->usage == 0) {
-               int devidx = md->disk->first_minor >> MMC_SHIFT;
+               int devidx = MINOR(disk_devt(md->disk)) >> MMC_SHIFT;
                __clear_bit(devidx, dev_use);
 
                put_disk(md->disk);
@@ -92,18 +92,17 @@ static void mmc_blk_put(struct mmc_blk_data *md)
        mutex_unlock(&open_lock);
 }
 
-static int mmc_blk_open(struct inode *inode, struct file *filp)
+static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
 {
-       struct mmc_blk_data *md;
+       struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
        int ret = -ENXIO;
 
-       md = mmc_blk_get(inode->i_bdev->bd_disk);
        if (md) {
                if (md->usage == 2)
-                       check_disk_change(inode->i_bdev);
+                       check_disk_change(bdev);
                ret = 0;
 
-               if ((filp->f_mode & FMODE_WRITE) && md->read_only) {
+               if ((mode & FMODE_WRITE) && md->read_only) {
                        mmc_blk_put(md);
                        ret = -EROFS;
                }
@@ -112,9 +111,9 @@ static int mmc_blk_open(struct inode *inode, struct file *filp)
        return ret;
 }
 
-static int mmc_blk_release(struct inode *inode, struct file *filp)
+static int mmc_blk_release(struct gendisk *disk, fmode_t mode)
 {
-       struct mmc_blk_data *md = inode->i_bdev->bd_disk->private_data;
+       struct mmc_blk_data *md = disk->private_data;
 
        mmc_blk_put(md);
        return 0;
@@ -215,8 +214,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
        struct mmc_blk_data *md = mq->data;
        struct mmc_card *card = md->queue.card;
        struct mmc_blk_request brq;
-       int ret = 1, data_size, i;
-       struct scatterlist *sg;
+       int ret = 1;
 
        mmc_claim_host(card->host);
 
@@ -232,13 +230,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
                if (!mmc_card_blockaddr(card))
                        brq.cmd.arg <<= 9;
                brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
-               brq.data.blksz = 1 << md->block_bits;
+               brq.data.blksz = 512;
                brq.stop.opcode = MMC_STOP_TRANSMISSION;
                brq.stop.arg = 0;
                brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
-               brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
-               if (brq.data.blocks > card->host->max_blk_count)
-                       brq.data.blocks = card->host->max_blk_count;
+               brq.data.blocks = req->nr_sectors;
 
                if (brq.data.blocks > 1) {
                        /* SPI multiblock writes terminate using a special
@@ -270,24 +266,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
 
                mmc_queue_bounce_pre(mq);
 
-               /*
-                * Adjust the sg list so it is the same size as the
-                * request.
-                */
-               if (brq.data.blocks !=
-                   (req->nr_sectors >> (md->block_bits - 9))) {
-                       data_size = brq.data.blocks * brq.data.blksz;
-                       for_each_sg(brq.data.sg, sg, brq.data.sg_len, i) {
-                               data_size -= sg->length;
-                               if (data_size <= 0) {
-                                       sg->length += data_size;
-                                       i++;
-                                       break;
-                               }
-                       }
-                       brq.data.sg_len = i;
-               }
-
                mmc_wait_for_req(card->host, &brq.mrq);
 
                mmc_queue_bounce_post(mq);
@@ -372,16 +350,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
        if (rq_data_dir(req) != READ) {
                if (mmc_card_sd(card)) {
                        u32 blocks;
-                       unsigned int bytes;
 
                        blocks = mmc_sd_num_wr_blocks(card);
                        if (blocks != (u32)-1) {
-                               if (card->csd.write_partial)
-                                       bytes = blocks << md->block_bits;
-                               else
-                                       bytes = blocks << 9;
                                spin_lock_irq(&md->lock);
-                               ret = __blk_end_request(req, 0, bytes);
+                               ret = __blk_end_request(req, 0, blocks << 9);
                                spin_unlock_irq(&md->lock);
                        }
                } else {
@@ -431,13 +404,6 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
         */
        md->read_only = mmc_blk_readonly(card);
 
-       /*
-        * Both SD and MMC specifications state (although a bit
-        * unclearly in the MMC case) that a block size of 512
-        * bytes must always be supported by the card.
-        */
-       md->block_bits = 9;
-
        md->disk = alloc_disk(1 << MMC_SHIFT);
        if (md->disk == NULL) {
                ret = -ENOMEM;
@@ -475,7 +441,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
 
        sprintf(md->disk->disk_name, "mmcblk%d", devidx);
 
-       blk_queue_hardsect_size(md->queue.queue, 1 << md->block_bits);
+       blk_queue_hardsect_size(md->queue.queue, 512);
 
        if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
                /*
@@ -513,7 +479,7 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
 
        mmc_claim_host(card->host);
        cmd.opcode = MMC_SET_BLOCKLEN;
-       cmd.arg = 1 << md->block_bits;
+       cmd.arg = 512;
        cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
        err = mmc_wait_for_cmd(card->host, &cmd, 5);
        mmc_release_host(card->host);
@@ -532,6 +498,8 @@ static int mmc_blk_probe(struct mmc_card *card)
        struct mmc_blk_data *md;
        int err;
 
+       char cap_str[10];
+
        /*
         * Check that the card supports the command class(es) we need.
         */
@@ -546,10 +514,11 @@ static int mmc_blk_probe(struct mmc_card *card)
        if (err)
                goto out;
 
-       printk(KERN_INFO "%s: %s %s %lluKiB %s\n",
+       string_get_size(get_capacity(md->disk) << 9, STRING_UNITS_2,
+                       cap_str, sizeof(cap_str));
+       printk(KERN_INFO "%s: %s %s %s %s\n",
                md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
-               (unsigned long long)(get_capacity(md->disk) >> 1),
-               md->read_only ? "(ro)" : "");
+               cap_str, md->read_only ? "(ro)" : "");
 
        mmc_set_drvdata(card, md);
        add_disk(md->disk);