]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/mmc/core/sdio.c
sdio: enable wide bus mode
[linux-2.6-omap-h63xx.git] / drivers / mmc / core / sdio.c
index 7ce3e3104d2193f6c5413408979b9346e35d0b8f..48c465a8e34e83d744d4d86d512ad808adb35081 100644 (file)
 #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)
+{
+       int ret;
+       unsigned char data;
+
+       ret = mmc_io_rw_direct(func->card, 0, 0,
+               func->num * 0x100 + SDIO_FBR_STD_IF, 0, &data);
+       if (ret)
+               goto out;
+
+       data &= 0x0f;
+
+       if (data == 0x0f) {
+               ret = mmc_io_rw_direct(func->card, 0, 0,
+                       func->num * 0x100 + SDIO_FBR_STD_IF_EXT, 0, &data);
+               if (ret)
+                       goto out;
+       }
+
+       func->class = data;
+
+out:
+       return ret;
+}
 
 static int sdio_init_func(struct mmc_card *card, unsigned int fn)
 {
+       int ret;
        struct sdio_func *func;
 
        BUG_ON(fn > SDIO_MAX_FUNCS);
@@ -35,9 +62,25 @@ static int sdio_init_func(struct mmc_card *card, unsigned int fn)
 
        func->num = fn;
 
+       ret = sdio_read_fbr(func);
+       if (ret)
+               goto fail;
+
+       ret = sdio_read_func_cis(func);
+       if (ret)
+               goto fail;
+
        card->sdio_func[fn - 1] = func;
 
        return 0;
+
+fail:
+       /*
+        * It is okay to remove the function here even though we hold
+        * the host lock as we haven't registered the device yet.
+        */
+       sdio_remove_func(func);
+       return ret;
 }
 
 static int sdio_read_cccr(struct mmc_card *card)
@@ -95,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.
  */
@@ -243,6 +312,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.
         */