[MMC] Fix SD timeout calculation
[pandora-kernel.git] / drivers / mmc / mmc.c
index da6ddd9..c0c7ef2 100644 (file)
@@ -9,7 +9,6 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
@@ -59,21 +58,23 @@ static const unsigned int tacc_mant[] = {
 
 
 /**
- *     mmc_request_done - finish processing an MMC command
- *     @host: MMC host which completed command
- *     @mrq: MMC request which completed
+ *     mmc_request_done - finish processing an MMC request
+ *     @host: MMC host which completed request
+ *     @mrq: MMC request which request
  *
  *     MMC drivers should call this function when they have completed
- *     their processing of a command.  This should be called before the
- *     data part of the command has completed.
+ *     their processing of a request.
  */
 void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
 {
        struct mmc_command *cmd = mrq->cmd;
-       int err = mrq->cmd->error;
-       pr_debug("MMC: req done (%02x): %d: %08x %08x %08x %08x\n",
-                cmd->opcode, err, cmd->resp[0], cmd->resp[1],
-                cmd->resp[2], cmd->resp[3]);
+       int err = cmd->error;
+
+       pr_debug("%s: req done (CMD%u): %d/%d/%d: %08x %08x %08x %08x\n",
+                mmc_hostname(host), cmd->opcode, err,
+                mrq->data ? mrq->data->error : 0,
+                mrq->stop ? mrq->stop->error : 0,
+                cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
 
        if (err && cmd->retries) {
                cmd->retries--;
@@ -97,8 +98,9 @@ EXPORT_SYMBOL(mmc_request_done);
 void
 mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 {
-       pr_debug("MMC: starting cmd %02x arg %08x flags %08x\n",
-                mrq->cmd->opcode, mrq->cmd->arg, mrq->cmd->flags);
+       pr_debug("%s: starting CMD%u arg %08x flags %08x\n",
+                mmc_hostname(host), mrq->cmd->opcode,
+                mrq->cmd->arg, mrq->cmd->flags);
 
        WARN_ON(host->card_busy == NULL);
 
@@ -126,7 +128,7 @@ static void mmc_wait_done(struct mmc_request *mrq)
 
 int mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
 {
-       DECLARE_COMPLETION(complete);
+       DECLARE_COMPLETION_ONSTACK(complete);
 
        mrq->done_data = &complete;
        mrq->done = mmc_wait_done;
@@ -312,6 +314,18 @@ void mmc_release_host(struct mmc_host *host)
 
 EXPORT_SYMBOL(mmc_release_host);
 
+static inline void mmc_set_ios(struct mmc_host *host)
+{
+       struct mmc_ios *ios = &host->ios;
+
+       pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u width %u\n",
+                mmc_hostname(host), ios->clock, ios->bus_mode,
+                ios->power_mode, ios->chip_select, ios->vdd,
+                ios->bus_width);
+       
+       host->ops->set_ios(host, ios);
+}
+
 static int mmc_select_card(struct mmc_host *host, struct mmc_card *card)
 {
        int err;
@@ -364,7 +378,7 @@ static int mmc_select_card(struct mmc_host *host, struct mmc_card *card)
                }
        }
 
-       host->ops->set_ios(host, &host->ios);
+       mmc_set_ios(host);
 
        return MMC_ERR_NONE;
 }
@@ -415,7 +429,7 @@ static u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
                ocr = 3 << bit;
 
                host->ios.vdd = bit;
-               host->ops->set_ios(host, &host->ios);
+               mmc_set_ios(host);
        } else {
                ocr = 0;
        }
@@ -549,6 +563,7 @@ static void mmc_decode_csd(struct mmc_card *card)
                csd->read_partial = UNSTUFF_BITS(resp, 79, 1);
                csd->write_misalign = UNSTUFF_BITS(resp, 78, 1);
                csd->read_misalign = UNSTUFF_BITS(resp, 77, 1);
+               csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3);
                csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4);
                csd->write_partial = UNSTUFF_BITS(resp, 21, 1);
        } else {
@@ -583,6 +598,7 @@ static void mmc_decode_csd(struct mmc_card *card)
                csd->read_partial = UNSTUFF_BITS(resp, 79, 1);
                csd->write_misalign = UNSTUFF_BITS(resp, 78, 1);
                csd->read_misalign = UNSTUFF_BITS(resp, 77, 1);
+               csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3);
                csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4);
                csd->write_partial = UNSTUFF_BITS(resp, 21, 1);
        }
@@ -666,7 +682,7 @@ static void mmc_idle_cards(struct mmc_host *host)
        struct mmc_command cmd;
 
        host->ios.chip_select = MMC_CS_HIGH;
-       host->ops->set_ios(host, &host->ios);
+       mmc_set_ios(host);
 
        mmc_delay(1);
 
@@ -679,7 +695,7 @@ static void mmc_idle_cards(struct mmc_host *host)
        mmc_delay(1);
 
        host->ios.chip_select = MMC_CS_DONTCARE;
-       host->ops->set_ios(host, &host->ios);
+       mmc_set_ios(host);
 
        mmc_delay(1);
 }
@@ -704,13 +720,13 @@ static void mmc_power_up(struct mmc_host *host)
        host->ios.chip_select = MMC_CS_DONTCARE;
        host->ios.power_mode = MMC_POWER_UP;
        host->ios.bus_width = MMC_BUS_WIDTH_1;
-       host->ops->set_ios(host, &host->ios);
+       mmc_set_ios(host);
 
        mmc_delay(1);
 
        host->ios.clock = host->f_min;
        host->ios.power_mode = MMC_POWER_ON;
-       host->ops->set_ios(host, &host->ios);
+       mmc_set_ios(host);
 
        mmc_delay(2);
 }
@@ -723,7 +739,7 @@ static void mmc_power_off(struct mmc_host *host)
        host->ios.chip_select = MMC_CS_DONTCARE;
        host->ios.power_mode = MMC_POWER_OFF;
        host->ios.bus_width = MMC_BUS_WIDTH_1;
-       host->ops->set_ios(host, &host->ios);
+       mmc_set_ios(host);
 }
 
 static int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
@@ -896,6 +912,7 @@ static void mmc_read_scrs(struct mmc_host *host)
        struct mmc_request mrq;
        struct mmc_command cmd;
        struct mmc_data data;
+       unsigned int timeout_us;
 
        struct scatterlist sg;
 
@@ -931,9 +948,20 @@ static void mmc_read_scrs(struct mmc_host *host)
 
                memset(&data, 0, sizeof(struct mmc_data));
 
-               data.timeout_ns = card->csd.tacc_ns * 10;
-               data.timeout_clks = card->csd.tacc_clks * 10;
+               data.timeout_ns = card->csd.tacc_ns * 100;
+               data.timeout_clks = card->csd.tacc_clks * 100;
+
+               timeout_us = data.timeout_ns / 1000;
+               timeout_us += data.timeout_clks * 1000 /
+                       (host->ios.clock / 1000);
+
+               if (timeout_us > 100000) {
+                       data.timeout_ns = 100000000;
+                       data.timeout_clks = 0;
+               }
+
                data.blksz_bits = 3;
+               data.blksz = 1 << 3;
                data.blocks = 1;
                data.flags = MMC_DATA_READ;
                data.sg = &sg;
@@ -971,7 +999,8 @@ static unsigned int mmc_calculate_clock(struct mmc_host *host)
                if (!mmc_card_dead(card) && max_dtr > card->csd.max_dtr)
                        max_dtr = card->csd.max_dtr;
 
-       pr_debug("MMC: selected %d.%03dMHz transfer rate\n",
+       pr_debug("%s: selected %d.%03dMHz transfer rate\n",
+                mmc_hostname(host),
                 max_dtr / 1000000, (max_dtr / 1000) % 1000);
 
        return max_dtr;
@@ -1046,7 +1075,7 @@ static void mmc_setup(struct mmc_host *host)
        } else {
                host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
                host->ios.clock = host->f_min;
-               host->ops->set_ios(host, &host->ios);
+               mmc_set_ios(host);
 
                /*
                 * We should remember the OCR mask from the existing
@@ -1082,7 +1111,7 @@ static void mmc_setup(struct mmc_host *host)
         * Ok, now switch to push-pull mode.
         */
        host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
-       host->ops->set_ios(host, &host->ios);
+       mmc_set_ios(host);
 
        mmc_read_csds(host);
 
@@ -1128,7 +1157,7 @@ static void mmc_rescan(void *data)
                 * attached cards and the host support.
                 */
                host->ios.clock = mmc_calculate_clock(host);
-               host->ops->set_ios(host, &host->ios);
+               mmc_set_ios(host);
        }
 
        mmc_release_host(host);