]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
mmc: Fixes for Dual Data Rate (DDR) support
authorAdrian Hunter <adrian.hunter@nokia.com>
Tue, 24 Aug 2010 10:20:26 +0000 (13:20 +0300)
committerChris Ball <cjb@laptop.org>
Sat, 23 Oct 2010 13:11:16 +0000 (21:11 +0800)
The DDR support patch needs the following fixes:

- The block driver does not need to know about DDR, any more
  than it needs to know about bus width.
- Not only the card must be switched to DDR mode.  The host
  controller must also be configured, which is done through
  the 'set_ios()' function.
- Do not set the DDR mode state until after the switch command
  is successful.
- Setting block length is not supported in DDR mode.  Make that
  a core function and change the other place it is used (mmc_test)
  also.

Signed-off-by: Adrian Hunter <adrian.hunter@nokia.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
drivers/mmc/card/block.c
drivers/mmc/card/mmc_test.c
drivers/mmc/core/bus.c
drivers/mmc/core/core.c
drivers/mmc/core/core.h
drivers/mmc/core/mmc.c
include/linux/mmc/core.h
include/linux/mmc/host.h

index aab593480975dea1f0f31143d4179fd6e3b7178b..a9970504cabbad33f7830bfeebcf1120bb2138a1 100644 (file)
@@ -373,8 +373,6 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
                        readcmd = MMC_READ_SINGLE_BLOCK;
                        writecmd = MMC_WRITE_BLOCK;
                }
-               if (mmc_card_ddr_mode(card))
-                       brq.data.flags |= MMC_DDR_MODE;
                if (rq_data_dir(req) == READ) {
                        brq.cmd.opcode = readcmd;
                        brq.data.flags |= MMC_DATA_READ;
@@ -653,26 +651,15 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
 static int
 mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
 {
-       struct mmc_command cmd;
        int err;
 
-       /*
-        * Block-addressed and ddr mode supported cards
-        * ignore MMC_SET_BLOCKLEN.
-        */
-       if (mmc_card_blockaddr(card) || mmc_card_ddr_mode(card))
-               return 0;
-
        mmc_claim_host(card->host);
-       cmd.opcode = MMC_SET_BLOCKLEN;
-       cmd.arg = 512;
-       cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
-       err = mmc_wait_for_cmd(card->host, &cmd, 5);
+       err = mmc_set_blocklen(card, 512);
        mmc_release_host(card->host);
 
        if (err) {
-               printk(KERN_ERR "%s: unable to set block size to %d: %d\n",
-                       md->disk->disk_name, cmd.arg, err);
+               printk(KERN_ERR "%s: unable to set block size to 512: %d\n",
+                       md->disk->disk_name, err);
                return -EINVAL;
        }
 
index c38a3a84a455b0afba20f824bf8cd24d31137921..21adc27f413281ec5e6d6f0e699a1a12f3b4ce9f 100644 (file)
@@ -155,17 +155,7 @@ struct mmc_test_card {
  */
 static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size)
 {
-       struct mmc_command cmd;
-       int ret;
-
-       cmd.opcode = MMC_SET_BLOCKLEN;
-       cmd.arg = size;
-       cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
-       ret = mmc_wait_for_cmd(test->card->host, &cmd, 0);
-       if (ret)
-               return ret;
-
-       return 0;
+       return mmc_set_blocklen(test->card, size);
 }
 
 /*
index e70bd6641ceead22cccf094e4344f5ef45415be6..da3c01b214ec0d5025038806fd290d350adb2f3d 100644 (file)
@@ -253,14 +253,16 @@ int mmc_add_card(struct mmc_card *card)
        }
 
        if (mmc_host_is_spi(card->host)) {
-               printk(KERN_INFO "%s: new %s%s card on SPI\n",
+               printk(KERN_INFO "%s: new %s%s%s card on SPI\n",
                        mmc_hostname(card->host),
                        mmc_card_highspeed(card) ? "high speed " : "",
+                       mmc_card_ddr_mode(card) ? "DDR " : "",
                        type);
        } else {
-               printk(KERN_INFO "%s: new %s%s card at address %04x\n",
+               printk(KERN_INFO "%s: new %s%s%s card at address %04x\n",
                        mmc_hostname(card->host),
                        mmc_card_highspeed(card) ? "high speed " : "",
+                       mmc_card_ddr_mode(card) ? "DDR " : "",
                        type, card->rca);
        }
 
index 46029d5c03641da8fac04410c24d0e45150eae68..7cb352b3b247ec5cae434a202cd9f41662755e36 100644 (file)
@@ -651,14 +651,23 @@ void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode)
 }
 
 /*
- * Change data bus width of a host.
+ * Change data bus width and DDR mode of a host.
  */
-void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
+void mmc_set_bus_width_ddr(struct mmc_host *host, unsigned int width, int ddr)
 {
        host->ios.bus_width = width;
+       host->ios.ddr = ddr ? MMC_DDR_MODE : MMC_SDR_MODE;
        mmc_set_ios(host);
 }
 
+/*
+ * Change data bus width of a host.
+ */
+void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
+{
+       mmc_set_bus_width_ddr(host, width, 0);
+}
+
 /**
  * mmc_vdd_to_ocrbitnum - Convert a voltage to the OCR bit number
  * @vdd:       voltage (mV)
@@ -1399,6 +1408,21 @@ int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
 }
 EXPORT_SYMBOL(mmc_erase_group_aligned);
 
+int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen)
+{
+       struct mmc_command cmd;
+
+       if (mmc_card_blockaddr(card) || mmc_card_ddr_mode(card))
+               return 0;
+
+       memset(&cmd, 0, sizeof(struct mmc_command));
+       cmd.opcode = MMC_SET_BLOCKLEN;
+       cmd.arg = blocklen;
+       cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
+       return mmc_wait_for_cmd(card->host, &cmd, 5);
+}
+EXPORT_SYMBOL(mmc_set_blocklen);
+
 void mmc_rescan(struct work_struct *work)
 {
        struct mmc_host *host =
index a2ca770ca89bd6fa0148f585cc074f7f569599fe..13240d128a6928c2c3259dca4d14e7d0d47d3568 100644 (file)
@@ -35,6 +35,7 @@ void mmc_set_chip_select(struct mmc_host *host, int mode);
 void mmc_set_clock(struct mmc_host *host, unsigned int hz);
 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
 void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
+void mmc_set_bus_width_ddr(struct mmc_host *host, unsigned int width, int ddr);
 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
 void mmc_set_timing(struct mmc_host *host, unsigned int timing);
 
index 66c4a59fee5fc6182bd5b260cf133af2a5f463d4..3ea58ce773ffaa957ce41b28d9ef54148bef066b 100644 (file)
@@ -375,7 +375,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
        struct mmc_card *oldcard)
 {
        struct mmc_card *card;
-       int err;
+       int err, ddr = 0;
        u32 cid[4];
        unsigned int max_dtr;
 
@@ -518,32 +518,32 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
        mmc_set_clock(host, max_dtr);
 
        /*
-        * Activate DDR50 mode (if supported).
+        * Indicate DDR mode (if supported).
         */
        if (mmc_card_highspeed(card)) {
                if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_8V)
                        && (host->caps & (MMC_CAP_1_8V_DDR)))
-                               mmc_card_set_ddr_mode(card);
+                               ddr = 1;
                else if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_2V)
                        && (host->caps & (MMC_CAP_1_2V_DDR)))
-                               mmc_card_set_ddr_mode(card);
+                               ddr = 1;
        }
 
        /*
-        * Activate wide bus (if supported).
+        * Activate wide bus and DDR (if supported).
         */
        if ((card->csd.mmca_vsn >= CSD_SPEC_VER_4) &&
            (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) {
                unsigned ext_csd_bit, bus_width;
 
                if (host->caps & MMC_CAP_8_BIT_DATA) {
-                       if (mmc_card_ddr_mode(card))
+                       if (ddr)
                                ext_csd_bit = EXT_CSD_DDR_BUS_WIDTH_8;
                        else
                                ext_csd_bit = EXT_CSD_BUS_WIDTH_8;
                        bus_width = MMC_BUS_WIDTH_8;
                } else {
-                       if (mmc_card_ddr_mode(card))
+                       if (ddr)
                                ext_csd_bit = EXT_CSD_DDR_BUS_WIDTH_4;
                        else
                                ext_csd_bit = EXT_CSD_BUS_WIDTH_4;
@@ -557,12 +557,13 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
                        goto free_card;
 
                if (err) {
-                       printk(KERN_WARNING "%s: switch to bus width %d "
+                       printk(KERN_WARNING "%s: switch to bus width %d ddr %d "
                               "failed\n", mmc_hostname(card->host),
-                              1 << bus_width);
+                              1 << bus_width, ddr);
                        err = 0;
                } else {
-                       mmc_set_bus_width(card->host, bus_width);
+                       mmc_card_set_ddr_mode(card);
+                       mmc_set_bus_width_ddr(card->host, bus_width, ddr);
                }
        }
 
index d0fbcacab52c139d16cc15cafdeecbfbf1400660..64e013f1cfb82a883a93982ec2cea3b42a0729fb 100644 (file)
@@ -109,7 +109,6 @@ struct mmc_data {
 #define MMC_DATA_WRITE (1 << 8)
 #define MMC_DATA_READ  (1 << 9)
 #define MMC_DATA_STREAM        (1 << 10)
-#define MMC_DDR_MODE   (1 << 11)
 
        unsigned int            bytes_xfered;
 
@@ -154,6 +153,8 @@ extern int mmc_can_secure_erase_trim(struct mmc_card *card);
 extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
                                   unsigned int nr);
 
+extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);
+
 extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
 extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
 
index 6711eb8715ba6d5a7550bea3560a5570c9902414..c4fb1c5efc447b472309c659380145ca01fc09a7 100644 (file)
@@ -50,6 +50,11 @@ struct mmc_ios {
 #define MMC_TIMING_LEGACY      0
 #define MMC_TIMING_MMC_HS      1
 #define MMC_TIMING_SD_HS       2
+
+       unsigned char   ddr;                    /* dual data rate used */
+
+#define MMC_SDR_MODE           0
+#define MMC_DDR_MODE           1
 };
 
 struct mmc_host_ops {