ARM: zynq: Do not select options if SPL is not enabled
[oweals/u-boot.git] / common / spl / spl_mmc.c
index b68190a265bc1956902508efe18f7b934531a335..c3931c6c4d7761c598d45312e2b5ffc01a676231 100644 (file)
@@ -28,7 +28,7 @@ static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
                                         sizeof(struct image_header));
 
        /* read image header to find the image size & load address */
-       count = mmc->block_dev.block_read(0, sector, 1, header);
+       count = mmc->block_dev.block_read(&mmc->block_dev, sector, 1, header);
        debug("read sector %lx, count=%lu\n", sector, count);
        if (count == 0)
                goto end;
@@ -45,7 +45,8 @@ static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
                             mmc->read_bl_len;
 
        /* Read the header too to avoid extra memcpy */
-       count = mmc->block_dev.block_read(0, sector, image_size_sectors,
+       count = mmc->block_dev.block_read(&mmc->block_dev, sector,
+                                         image_size_sectors,
                                          (void *)(ulong)spl_image.load_addr);
        debug("read %x sectors to %x\n", image_size_sectors,
              spl_image.load_addr);
@@ -61,38 +62,35 @@ end:
        return 0;
 }
 
-#ifdef CONFIG_DM_MMC
-static int spl_mmc_find_device(struct mmc **mmc)
+int spl_mmc_get_device_index(u32 boot_device)
 {
-       struct udevice *dev;
-       int err;
-
-       err = mmc_initialize(NULL);
-       if (err) {
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-               printf("spl: could not initialize mmc. error: %d\n", err);
-#endif
-               return err;
+       switch (boot_device) {
+       case BOOT_DEVICE_MMC1:
+               return 0;
+       case BOOT_DEVICE_MMC2:
+       case BOOT_DEVICE_MMC2_2:
+               return 1;
        }
 
-       err = uclass_get_device(UCLASS_MMC, 0, &dev);
-       if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-               printf("spl: could not find mmc device. error: %d\n", err);
+       printf("spl: unsupported mmc boot device.\n");
 #endif
-               return err;
-       }
 
-       *mmc = NULL;
-       *mmc = mmc_get_mmc_dev(dev);
-       return *mmc != NULL ? 0 : -ENODEV;
+       return -ENODEV;
 }
-#else
-static int spl_mmc_find_device(struct mmc **mmc)
+
+static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
 {
-       int err;
+#ifdef CONFIG_DM_MMC
+       struct udevice *dev;
+#endif
+       int err, mmc_dev;
+
+       mmc_dev = spl_mmc_get_device_index(boot_device);
+       if (mmc_dev < 0)
+               return mmc_dev;
 
-       err = mmc_initialize(gd->bd);
+       err = mmc_initialize(NULL);
        if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
                printf("spl: could not initialize mmc. error: %d\n", err);
@@ -100,18 +98,23 @@ static int spl_mmc_find_device(struct mmc **mmc)
                return err;
        }
 
-       /* We register only one device. So, the dev id is always 0 */
-       *mmc = find_mmc_device(0);
-       if (!*mmc) {
+#ifdef CONFIG_DM_MMC
+       err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev);
+       if (!err)
+               *mmcp = mmc_get_mmc_dev(dev);
+#else
+       *mmcp = find_mmc_device(mmc_dev);
+       err = *mmcp ? 0 : -ENODEV;
+#endif
+       if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-               puts("spl: mmc device not found\n");
+               printf("spl: could not find mmc device. error: %d\n", err);
 #endif
-               return -ENODEV;
+               return err;
        }
 
        return 0;
 }
-#endif
 
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
 static int mmc_load_image_raw_partition(struct mmc *mmc, int partition)
@@ -147,7 +150,7 @@ static int mmc_load_image_raw_os(struct mmc *mmc)
 {
        unsigned long count;
 
-       count = mmc->block_dev.block_read(0,
+       count = mmc->block_dev.block_read(&mmc->block_dev,
                CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR,
                CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS,
                (void *) CONFIG_SYS_SPL_ARGS_ADDR);
@@ -221,14 +224,14 @@ int spl_mmc_do_fs_boot(struct mmc *mmc)
 }
 #endif
 
-int spl_mmc_load_image(void)
+int spl_mmc_load_image(u32 boot_device)
 {
-       struct mmc *mmc;
+       struct mmc *mmc = NULL;
        u32 boot_mode;
        int err = 0;
        __maybe_unused int part;
 
-       err = spl_mmc_find_device(&mmc);
+       err = spl_mmc_find_device(&mmc, boot_device);
        if (err)
                return err;