pandora: add leds_pwm platform data
[pandora-kernel.git] / drivers / mmc / core / sdio.c
index 06b6408..b9dee28 100644 (file)
@@ -187,6 +187,40 @@ static int sdio_disable_cd(struct mmc_card *card)
        return mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
 }
 
+/*
+ * Devices that remain active during a system suspend are
+ * put back into 1-bit mode.
+ */
+static int sdio_disable_wide(struct mmc_card *card)
+{
+       int ret;
+       u8 ctrl;
+
+       if (!(card->host->caps & MMC_CAP_4_BIT_DATA))
+               return 0;
+
+       if (card->cccr.low_speed && !card->cccr.wide_bus)
+               return 0;
+
+       ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl);
+       if (ret)
+               return ret;
+
+       if (!(ctrl & SDIO_BUS_WIDTH_4BIT))
+               return 0;
+
+       ctrl &= ~SDIO_BUS_WIDTH_4BIT;
+       ctrl |= SDIO_BUS_ASYNC_INT;
+
+       ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
+       if (ret)
+               return ret;
+
+       mmc_set_bus_width(card->host, MMC_BUS_WIDTH_1);
+
+       return 0;
+}
+
 /*
  * Test if the card supports high-speed mode and, if so, switch to it.
  */
@@ -224,7 +258,7 @@ static int sdio_enable_hs(struct mmc_card *card)
  * we're trying to reinitialise.
  */
 static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
-                             struct mmc_card *oldcard)
+                             struct mmc_card *oldcard, int powered_resume)
 {
        struct mmc_card *card;
        int err;
@@ -235,9 +269,11 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
        /*
         * Inform the card of the voltage
         */
-       err = mmc_send_io_op_cond(host, host->ocr, &ocr);
-       if (err)
-               goto err;
+       if (!powered_resume) {
+               err = mmc_send_io_op_cond(host, host->ocr, &ocr);
+               if (err)
+                       goto err;
+       }
 
        /*
         * For SPI, enable CRC as appropriate.
@@ -259,10 +295,16 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
 
        card->type = MMC_TYPE_SDIO;
 
+       /*
+        * Call the optional HC's init_card function to handle quirks.
+        */
+       if (host->ops->init_card)
+               host->ops->init_card(host, card);
+
        /*
         * For native busses:  set card RCA and quit open drain mode.
         */
-       if (!mmc_host_is_spi(host)) {
+       if (!powered_resume && !mmc_host_is_spi(host)) {
                err = mmc_send_relative_addr(host, &card->rca);
                if (err)
                        goto remove;
@@ -273,7 +315,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
        /*
         * Select card, as all following commands rely on that.
         */
-       if (!mmc_host_is_spi(host)) {
+       if (!powered_resume && !mmc_host_is_spi(host)) {
                err = mmc_select_card(card);
                if (err)
                        goto remove;
@@ -425,6 +467,12 @@ static int mmc_sdio_suspend(struct mmc_host *host)
                }
        }
 
+       if (!err && host->pm_flags & MMC_PM_KEEP_POWER) {
+               mmc_claim_host(host);
+               sdio_disable_wide(host->card);
+               mmc_release_host(host);
+       }
+
        return err;
 }
 
@@ -437,7 +485,13 @@ static int mmc_sdio_resume(struct mmc_host *host)
 
        /* Basic card reinitialization. */
        mmc_claim_host(host);
-       err = mmc_sdio_init_card(host, host->ocr, host->card);
+       err = mmc_sdio_init_card(host, host->ocr, host->card,
+                                (host->pm_flags & MMC_PM_KEEP_POWER));
+       if (!err)
+               /* We may have switched to 1-bit mode during suspend. */
+               err = sdio_enable_wide(host->card);
+       if (!err && host->sdio_irqs)
+               mmc_signal_sdio_irq(host);
        mmc_release_host(host);
 
        /*
@@ -507,7 +561,7 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
        /*
         * Detect and init the card.
         */
-       err = mmc_sdio_init_card(host, host->ocr, NULL);
+       err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
        if (err)
                goto err;
        card = host->card;