]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/mmc/core/sdio.c
Merge branch 'zero-len' of git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik...
[linux-2.6-omap-h63xx.git] / drivers / mmc / core / sdio.c
index be623856f288cbb92e6cad85441639afc7ef4f8d..4eab79e09cccacbab8b7ecf7d2ae780f9e5b9e05 100644 (file)
@@ -22,6 +22,7 @@
 #include "mmc_ops.h"
 #include "sd_ops.h"
 #include "sdio_ops.h"
+#include "sdio_cis.h"
 
 static int sdio_read_fbr(struct sdio_func *func)
 {
@@ -29,7 +30,7 @@ static int sdio_read_fbr(struct sdio_func *func)
        unsigned char data;
 
        ret = mmc_io_rw_direct(func->card, 0, 0,
-               func->num * 0x100 + SDIO_FBR_STD_IF, 0, &data);
+               SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF, 0, &data);
        if (ret)
                goto out;
 
@@ -37,7 +38,7 @@ static int sdio_read_fbr(struct sdio_func *func)
 
        if (data == 0x0f) {
                ret = mmc_io_rw_direct(func->card, 0, 0,
-                       func->num * 0x100 + SDIO_FBR_STD_IF_EXT, 0, &data);
+                       SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF_EXT, 0, &data);
                if (ret)
                        goto out;
        }
@@ -65,6 +66,10 @@ static int sdio_init_func(struct mmc_card *card, unsigned int fn)
        if (ret)
                goto fail;
 
+       ret = sdio_read_func_cis(func);
+       if (ret)
+               goto fail;
+
        card->sdio_func[fn - 1] = func;
 
        return 0;
@@ -133,6 +138,32 @@ out:
        return ret;
 }
 
+static int sdio_enable_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;
+
+       ctrl |= SDIO_BUS_WIDTH_4BIT;
+
+       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_4);
+
+       return 0;
+}
+
 /*
  * Host is being removed. Free up the current card.
  */
@@ -199,7 +230,7 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
        struct mmc_card *card;
 
        BUG_ON(!host);
-       BUG_ON(!host->claimed);
+       WARN_ON(!host->claimed);
 
        mmc_attach_bus(host, &mmc_sdio_ops);
 
@@ -238,6 +269,15 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
        if (err)
                goto err;
 
+       /*
+        * For SPI, enable CRC as appropriate.
+        */
+       if (mmc_host_is_spi(host)) {
+               err = mmc_spi_set_crc(host, use_spi_crc);
+               if (err)
+                       goto err;
+       }
+
        /*
         * The number of functions on the card is encoded inside
         * the ocr.
@@ -247,7 +287,7 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
        /*
         * Allocate card structure.
         */
-       card = mmc_alloc_card(host);
+       card = mmc_alloc_card(host, NULL);
        if (IS_ERR(card)) {
                err = PTR_ERR(card);
                goto err;
@@ -259,20 +299,24 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
        host->card = card;
 
        /*
-        * Set card RCA.
+        * For native busses:  set card RCA and quit open drain mode.
         */
-       err = mmc_send_relative_addr(host, &card->rca);
-       if (err)
-               goto remove;
+       if (!mmc_host_is_spi(host)) {
+               err = mmc_send_relative_addr(host, &card->rca);
+               if (err)
+                       goto remove;
 
-       mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
+               mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
+       }
 
        /*
         * Select card, as all following commands rely on that.
         */
-       err = mmc_select_card(card);
-       if (err)
-               goto remove;
+       if (!mmc_host_is_spi(host)) {
+               err = mmc_select_card(card);
+               if (err)
+                       goto remove;
+       }
 
        /*
         * Read the common registers.
@@ -281,6 +325,26 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
        if (err)
                goto remove;
 
+       /*
+        * Read the common CIS tuples.
+        */
+       err = sdio_read_common_cis(card);
+       if (err)
+               goto remove;
+
+       /*
+        * No support for high-speed yet, so just set
+        * the card's maximum speed.
+        */
+       mmc_set_clock(host, card->cis.max_dtr);
+
+       /*
+        * Switch to wider bus (if supported).
+        */
+       err = sdio_enable_wide(card);
+       if (err)
+               goto remove;
+
        /*
         * Initialize (but don't add) all present functions.
         */