2 * Copyright (C) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
14 struct mmc *mmc_get_mmc_dev(struct udevice *dev)
16 struct mmc_uclass_priv *upriv;
18 if (!device_active(dev))
20 upriv = dev_get_uclass_priv(dev);
25 struct mmc *find_mmc_device(int dev_num)
27 struct udevice *dev, *mmc_dev;
30 ret = blk_get_device(IF_TYPE_MMC, dev_num, &dev);
33 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
34 printf("MMC Device %d not found\n", dev_num);
39 mmc_dev = dev_get_parent(dev);
41 return mmc_get_mmc_dev(mmc_dev);
46 return max(blk_find_max_devnum(IF_TYPE_MMC), 0);
49 int mmc_get_next_devnum(void)
60 struct blk_desc *mmc_get_blk_desc(struct mmc *mmc)
62 struct blk_desc *desc;
65 device_find_first_child(mmc->dev, &dev);
68 desc = dev_get_uclass_platdata(dev);
73 void mmc_do_preinit(void)
79 ret = uclass_get(UCLASS_MMC, &uc);
82 uclass_foreach_dev(dev, uc) {
83 struct mmc *m = mmc_get_mmc_dev(dev);
87 #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
88 mmc_set_preinit(m, 1);
95 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
96 void print_mmc_devices(char separator)
102 for (uclass_first_device(UCLASS_MMC, &dev);
104 uclass_next_device(&dev)) {
105 struct mmc *m = mmc_get_mmc_dev(dev);
108 printf("%c", separator);
109 if (separator != '\n')
113 mmc_type = IS_SD(m) ? "SD" : "eMMC";
117 printf("%s: %d", m->cfg->name, mmc_get_blk_desc(m)->devnum);
119 printf(" (%s)", mmc_type);
126 void print_mmc_devices(char separator) { }
128 #endif /* CONFIG_BLK */
130 U_BOOT_DRIVER(mmc) = {
135 UCLASS_DRIVER(mmc) = {
138 .flags = DM_UC_FLAG_SEQ_ALIAS,
139 .per_device_auto_alloc_size = sizeof(struct mmc_uclass_priv),