summaryrefslogtreecommitdiffstats
path: root/common/spl/spl_mmc.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-12-02 10:59:13 -0700
committerTom Rini <trini@konsulko.com>2015-12-05 18:22:34 -0500
commitb4857aa90105ea85bf029f8eb99e72fbadc0e2d0 (patch)
tree1e288524936ab3740e167d25be58cfe311416d03 /common/spl/spl_mmc.c
parent99c7a51a249292ba98889b253659b27ed089bd7e (diff)
downloadu-boot-b4857aa90105ea85bf029f8eb99e72fbadc0e2d0.tar.gz
u-boot-b4857aa90105ea85bf029f8eb99e72fbadc0e2d0.tar.xz
u-boot-b4857aa90105ea85bf029f8eb99e72fbadc0e2d0.zip
spl: mmc: Unify non/driver model spl_mmc_find_device()
It is risky to have two different functions with much the same code. Future authors may update one but not the other. It is hard to see which parts are the same and which are different. Unify the functions and drop the differences that are not really needed. Note that one puts() becomes printf() as Tom mentioned that this does not affect image size: https://patchwork.ozlabs.org/patch/537276/ Note: It would be better to have an empty printf() and avoid the #ifdef for CONFIG_SPL_LIBCOMMON_SUPPORT. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Michal Simek <michal.simek@xilinx.com>
Diffstat (limited to 'common/spl/spl_mmc.c')
-rw-r--r--common/spl/spl_mmc.c41
1 files changed, 9 insertions, 32 deletions
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index d8b514eac7..f2c1af5d35 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -78,10 +78,11 @@ int spl_mmc_get_device_index(u32 boot_device)
return -ENODEV;
}
-#ifdef CONFIG_DM_MMC
static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
{
+#ifdef CONFIG_DM_MMC
struct udevice *dev;
+#endif
int err, mmc_dev;
mmc_dev = spl_mmc_get_device_index(boot_device);
@@ -96,47 +97,23 @@ static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
return err;
}
+#ifdef CONFIG_DM_MMC
err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev);
- if (err) {
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
- printf("spl: could not find mmc device. error: %d\n", err);
-#endif
- return err;
- }
-
- *mmcp = NULL;
- *mmcp = mmc_get_mmc_dev(dev);
- return *mmcp != NULL ? 0 : -ENODEV;
-}
+ if (!err)
+ *mmcp = mmc_get_mmc_dev(dev);
#else
-static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
-{
- 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);
+ *mmcp = find_mmc_device(mmc_dev);
+ err = *mmcp ? 0 : -ENODEV;
+#endif
if (err) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
- printf("spl: could not initialize mmc. error: %d\n", err);
+ printf("spl: could not find mmc device. error: %d\n", err);
#endif
return err;
}
- /* We register only one device. So, the dev id is always 0 */
- *mmcp = find_mmc_device(mmc_dev);
- if (!*mmcp) {
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
- puts("spl: mmc device not found\n");
-#endif
- return -ENODEV;
- }
-
return 0;
}
-#endif
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
static int mmc_load_image_raw_partition(struct mmc *mmc, int partition)