]> git.sur5r.net Git - u-boot/blobdiff - drivers/mmc/mmc.c
pci: Set PCI_COMMAND_IO bit for VGA device
[u-boot] / drivers / mmc / mmc.c
index 31f8647d8615987e94bb4d1de86203c660749bae..2a58702848b7f977bd3d10b12bd9138287fc1df5 100644 (file)
 #include <config.h>
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <dm/device-internal.h>
 #include <errno.h>
 #include <mmc.h>
 #include <part.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <linux/list.h>
 #include <div64.h>
 #include "mmc_private.h"
@@ -250,14 +253,18 @@ static ulong mmc_bread(int dev_num, lbaint_t start, lbaint_t blkcnt, void *dst)
                return 0;
        }
 
-       if (mmc_set_blocklen(mmc, mmc->read_bl_len))
+       if (mmc_set_blocklen(mmc, mmc->read_bl_len)) {
+               debug("%s: Failed to set blocklen\n", __func__);
                return 0;
+       }
 
        do {
                cur = (blocks_todo > mmc->cfg->b_max) ?
                        mmc->cfg->b_max : blocks_todo;
-               if(mmc_read_blocks(mmc, dst, start, cur) != cur)
+               if (mmc_read_blocks(mmc, dst, start, cur) != cur) {
+                       debug("%s: Failed to read blocks\n", __func__);
                        return 0;
+               }
                blocks_todo -= cur;
                start += cur;
                dst += cur * mmc->read_bl_len;
@@ -363,15 +370,12 @@ static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)
        cmd.cmdidx = MMC_CMD_SEND_OP_COND;
        cmd.resp_type = MMC_RSP_R3;
        cmd.cmdarg = 0;
-       if (use_arg && !mmc_host_is_spi(mmc)) {
-               cmd.cmdarg =
+       if (use_arg && !mmc_host_is_spi(mmc))
+               cmd.cmdarg = OCR_HCS |
                        (mmc->cfg->voltages &
                        (mmc->ocr & OCR_VOLTAGE_MASK)) |
                        (mmc->ocr & OCR_ACCESS_MODE);
 
-               if (mmc->cfg->host_caps & MMC_MODE_HC)
-                       cmd.cmdarg |= OCR_HCS;
-       }
        err = mmc_send_cmd(mmc, &cmd, NULL);
        if (err)
                return err;
@@ -1596,6 +1600,9 @@ int mmc_start_init(struct mmc *mmc)
        if (mmc->has_init)
                return 0;
 
+#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
+       mmc_adapter_card_type_ident();
+#endif
        board_mmc_power_init();
 
        /* made sure it's not NULL earlier */
@@ -1747,19 +1754,62 @@ static void do_preinit(void)
        list_for_each(entry, &mmc_devices) {
                m = list_entry(entry, struct mmc, link);
 
+#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
+               mmc_set_preinit(m, 1);
+#endif
                if (m->preinit)
                        mmc_start_init(m);
        }
 }
 
+#if defined(CONFIG_DM_MMC) && defined(CONFIG_SPL_BUILD)
+static int mmc_probe(bd_t *bis)
+{
+       return 0;
+}
+#elif defined(CONFIG_DM_MMC)
+static int mmc_probe(bd_t *bis)
+{
+       int ret;
+       struct uclass *uc;
+       struct udevice *m;
+
+       ret = uclass_get(UCLASS_MMC, &uc);
+       if (ret)
+               return ret;
+
+       uclass_foreach_dev(m, uc) {
+               ret = device_probe(m);
+               if (ret)
+                       printf("%s - probe failed: %d\n", m->name, ret);
+       }
+
+       return 0;
+}
+#else
+static int mmc_probe(bd_t *bis)
+{
+       if (board_mmc_init(bis) < 0)
+               cpu_mmc_init(bis);
+
+       return 0;
+}
+#endif
 
 int mmc_initialize(bd_t *bis)
 {
+       static int initialized = 0;
+       int ret;
+       if (initialized)        /* Avoid initializing mmc multiple times */
+               return 0;
+       initialized = 1;
+
        INIT_LIST_HEAD (&mmc_devices);
        cur_dev_num = 0;
 
-       if (board_mmc_init(bis) < 0)
-               cpu_mmc_init(bis);
+       ret = mmc_probe(bis);
+       if (ret)
+               return ret;
 
 #ifndef CONFIG_SPL_BUILD
        print_mmc_devices(',');