xref: /openbmc/u-boot/drivers/mmc/mmc-uclass.c (revision f99c2efe)
1e7ecf7cbSSimon Glass /*
2e7ecf7cbSSimon Glass  * Copyright (C) 2015 Google, Inc
3e7ecf7cbSSimon Glass  * Written by Simon Glass <sjg@chromium.org>
4e7ecf7cbSSimon Glass  *
5e7ecf7cbSSimon Glass  * SPDX-License-Identifier:	GPL-2.0+
6e7ecf7cbSSimon Glass  */
7e7ecf7cbSSimon Glass 
8e7ecf7cbSSimon Glass #include <common.h>
9e7ecf7cbSSimon Glass #include <mmc.h>
10e7ecf7cbSSimon Glass #include <dm.h>
11eede897eSSimon Glass #include <dm/device-internal.h>
12e7ecf7cbSSimon Glass #include <dm/lists.h>
13eede897eSSimon Glass #include "mmc_private.h"
14e7ecf7cbSSimon Glass 
1502ad33aaSJaehoon Chung DECLARE_GLOBAL_DATA_PTR;
1602ad33aaSJaehoon Chung 
178ca51e51SSimon Glass int dm_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
188ca51e51SSimon Glass 		    struct mmc_data *data)
198ca51e51SSimon Glass {
208ca51e51SSimon Glass 	struct mmc *mmc = mmc_get_mmc_dev(dev);
218ca51e51SSimon Glass 	struct dm_mmc_ops *ops = mmc_get_ops(dev);
228ca51e51SSimon Glass 	int ret;
238ca51e51SSimon Glass 
248ca51e51SSimon Glass 	mmmc_trace_before_send(mmc, cmd);
258ca51e51SSimon Glass 	if (ops->send_cmd)
268ca51e51SSimon Glass 		ret = ops->send_cmd(dev, cmd, data);
278ca51e51SSimon Glass 	else
288ca51e51SSimon Glass 		ret = -ENOSYS;
298ca51e51SSimon Glass 	mmmc_trace_after_send(mmc, cmd, ret);
308ca51e51SSimon Glass 
318ca51e51SSimon Glass 	return ret;
328ca51e51SSimon Glass }
338ca51e51SSimon Glass 
348ca51e51SSimon Glass int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
358ca51e51SSimon Glass {
368ca51e51SSimon Glass 	return dm_mmc_send_cmd(mmc->dev, cmd, data);
378ca51e51SSimon Glass }
388ca51e51SSimon Glass 
398ca51e51SSimon Glass int dm_mmc_set_ios(struct udevice *dev)
408ca51e51SSimon Glass {
418ca51e51SSimon Glass 	struct dm_mmc_ops *ops = mmc_get_ops(dev);
428ca51e51SSimon Glass 
438ca51e51SSimon Glass 	if (!ops->set_ios)
448ca51e51SSimon Glass 		return -ENOSYS;
458ca51e51SSimon Glass 	return ops->set_ios(dev);
468ca51e51SSimon Glass }
478ca51e51SSimon Glass 
488ca51e51SSimon Glass int mmc_set_ios(struct mmc *mmc)
498ca51e51SSimon Glass {
508ca51e51SSimon Glass 	return dm_mmc_set_ios(mmc->dev);
518ca51e51SSimon Glass }
528ca51e51SSimon Glass 
53318a7a57SJean-Jacques Hiblot void dm_mmc_send_init_stream(struct udevice *dev)
54318a7a57SJean-Jacques Hiblot {
55318a7a57SJean-Jacques Hiblot 	struct dm_mmc_ops *ops = mmc_get_ops(dev);
56318a7a57SJean-Jacques Hiblot 
57318a7a57SJean-Jacques Hiblot 	if (ops->send_init_stream)
58318a7a57SJean-Jacques Hiblot 		ops->send_init_stream(dev);
59318a7a57SJean-Jacques Hiblot }
60318a7a57SJean-Jacques Hiblot 
61318a7a57SJean-Jacques Hiblot void mmc_send_init_stream(struct mmc *mmc)
62318a7a57SJean-Jacques Hiblot {
63318a7a57SJean-Jacques Hiblot 	dm_mmc_send_init_stream(mmc->dev);
64318a7a57SJean-Jacques Hiblot }
65318a7a57SJean-Jacques Hiblot 
66*f99c2efeSJean-Jacques Hiblot #if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
67c10b85d6SJean-Jacques Hiblot int dm_mmc_wait_dat0(struct udevice *dev, int state, int timeout)
68c10b85d6SJean-Jacques Hiblot {
69c10b85d6SJean-Jacques Hiblot 	struct dm_mmc_ops *ops = mmc_get_ops(dev);
70c10b85d6SJean-Jacques Hiblot 
71c10b85d6SJean-Jacques Hiblot 	if (!ops->wait_dat0)
72c10b85d6SJean-Jacques Hiblot 		return -ENOSYS;
73c10b85d6SJean-Jacques Hiblot 	return ops->wait_dat0(dev, state, timeout);
74c10b85d6SJean-Jacques Hiblot }
75c10b85d6SJean-Jacques Hiblot 
76c10b85d6SJean-Jacques Hiblot int mmc_wait_dat0(struct mmc *mmc, int state, int timeout)
77c10b85d6SJean-Jacques Hiblot {
78c10b85d6SJean-Jacques Hiblot 	return dm_mmc_wait_dat0(mmc->dev, state, timeout);
79c10b85d6SJean-Jacques Hiblot }
80*f99c2efeSJean-Jacques Hiblot #endif
81c10b85d6SJean-Jacques Hiblot 
828ca51e51SSimon Glass int dm_mmc_get_wp(struct udevice *dev)
838ca51e51SSimon Glass {
848ca51e51SSimon Glass 	struct dm_mmc_ops *ops = mmc_get_ops(dev);
858ca51e51SSimon Glass 
868ca51e51SSimon Glass 	if (!ops->get_wp)
878ca51e51SSimon Glass 		return -ENOSYS;
888ca51e51SSimon Glass 	return ops->get_wp(dev);
898ca51e51SSimon Glass }
908ca51e51SSimon Glass 
918ca51e51SSimon Glass int mmc_getwp(struct mmc *mmc)
928ca51e51SSimon Glass {
938ca51e51SSimon Glass 	return dm_mmc_get_wp(mmc->dev);
948ca51e51SSimon Glass }
958ca51e51SSimon Glass 
968ca51e51SSimon Glass int dm_mmc_get_cd(struct udevice *dev)
978ca51e51SSimon Glass {
988ca51e51SSimon Glass 	struct dm_mmc_ops *ops = mmc_get_ops(dev);
998ca51e51SSimon Glass 
1008ca51e51SSimon Glass 	if (!ops->get_cd)
1018ca51e51SSimon Glass 		return -ENOSYS;
1028ca51e51SSimon Glass 	return ops->get_cd(dev);
1038ca51e51SSimon Glass }
1048ca51e51SSimon Glass 
1058ca51e51SSimon Glass int mmc_getcd(struct mmc *mmc)
1068ca51e51SSimon Glass {
1078ca51e51SSimon Glass 	return dm_mmc_get_cd(mmc->dev);
1088ca51e51SSimon Glass }
1098ca51e51SSimon Glass 
110*f99c2efeSJean-Jacques Hiblot #ifdef MMC_SUPPORTS_TUNING
111ec841209SKishon Vijay Abraham I int dm_mmc_execute_tuning(struct udevice *dev, uint opcode)
112ec841209SKishon Vijay Abraham I {
113ec841209SKishon Vijay Abraham I 	struct dm_mmc_ops *ops = mmc_get_ops(dev);
114ec841209SKishon Vijay Abraham I 
115ec841209SKishon Vijay Abraham I 	if (!ops->execute_tuning)
116ec841209SKishon Vijay Abraham I 		return -ENOSYS;
117ec841209SKishon Vijay Abraham I 	return ops->execute_tuning(dev, opcode);
118ec841209SKishon Vijay Abraham I }
119ec841209SKishon Vijay Abraham I 
120ec841209SKishon Vijay Abraham I int mmc_execute_tuning(struct mmc *mmc, uint opcode)
121ec841209SKishon Vijay Abraham I {
122ec841209SKishon Vijay Abraham I 	return dm_mmc_execute_tuning(mmc->dev, opcode);
123ec841209SKishon Vijay Abraham I }
124*f99c2efeSJean-Jacques Hiblot #endif
125ec841209SKishon Vijay Abraham I 
1267abff2c3SJean-Jacques Hiblot int mmc_of_parse(struct udevice *dev, struct mmc_config *cfg)
1279215ef5eSKishon Vijay Abraham I {
1289215ef5eSKishon Vijay Abraham I 	int val;
1299215ef5eSKishon Vijay Abraham I 
1307abff2c3SJean-Jacques Hiblot 	val = dev_read_u32_default(dev, "bus-width", 1);
1319215ef5eSKishon Vijay Abraham I 
1329215ef5eSKishon Vijay Abraham I 	switch (val) {
1339215ef5eSKishon Vijay Abraham I 	case 0x8:
1349215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_MODE_8BIT;
1359215ef5eSKishon Vijay Abraham I 		/* fall through */
1369215ef5eSKishon Vijay Abraham I 	case 0x4:
1379215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_MODE_4BIT;
1389215ef5eSKishon Vijay Abraham I 		/* fall through */
1399215ef5eSKishon Vijay Abraham I 	case 0x1:
1409215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_MODE_1BIT;
1419215ef5eSKishon Vijay Abraham I 		break;
1429215ef5eSKishon Vijay Abraham I 	default:
1437abff2c3SJean-Jacques Hiblot 		debug("warning: %s invalid bus-width property. using 1-bit\n",
1447abff2c3SJean-Jacques Hiblot 		      dev_read_name(dev));
1457abff2c3SJean-Jacques Hiblot 		cfg->host_caps |= MMC_MODE_1BIT;
1467abff2c3SJean-Jacques Hiblot 		break;
1479215ef5eSKishon Vijay Abraham I 	}
1489215ef5eSKishon Vijay Abraham I 
1497abff2c3SJean-Jacques Hiblot 	cfg->f_max = dev_read_u32_default(dev, "max-frequency", 52000000);
1509215ef5eSKishon Vijay Abraham I 
1517abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "cap-sd-highspeed"))
1529215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_CAP(SD_HS);
1537abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "cap-mmc-highspeed"))
1549215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_CAP(MMC_HS);
1557abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "sd-uhs-sdr12"))
1569215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_CAP(UHS_SDR12);
1577abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "sd-uhs-sdr25"))
1589215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_CAP(UHS_SDR25);
1597abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "sd-uhs-sdr50"))
1609215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_CAP(UHS_SDR50);
1617abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "sd-uhs-sdr104"))
1629215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_CAP(UHS_SDR104);
1637abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "sd-uhs-ddr50"))
1649215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_CAP(UHS_DDR50);
1657abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "mmc-ddr-1_8v"))
1669215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_CAP(MMC_DDR_52);
1677abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "mmc-ddr-1_2v"))
1687abff2c3SJean-Jacques Hiblot 		cfg->host_caps |= MMC_CAP(MMC_DDR_52);
1697abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "mmc-hs200-1_8v"))
1707abff2c3SJean-Jacques Hiblot 		cfg->host_caps |= MMC_CAP(MMC_HS_200);
1717abff2c3SJean-Jacques Hiblot 	if (dev_read_bool(dev, "mmc-hs200-1_2v"))
1729215ef5eSKishon Vijay Abraham I 		cfg->host_caps |= MMC_CAP(MMC_HS_200);
1739215ef5eSKishon Vijay Abraham I 
1749215ef5eSKishon Vijay Abraham I 	return 0;
1759215ef5eSKishon Vijay Abraham I }
1769215ef5eSKishon Vijay Abraham I 
177e7ecf7cbSSimon Glass struct mmc *mmc_get_mmc_dev(struct udevice *dev)
178e7ecf7cbSSimon Glass {
179e7ecf7cbSSimon Glass 	struct mmc_uclass_priv *upriv;
180e7ecf7cbSSimon Glass 
181e7ecf7cbSSimon Glass 	if (!device_active(dev))
182e7ecf7cbSSimon Glass 		return NULL;
183e7ecf7cbSSimon Glass 	upriv = dev_get_uclass_priv(dev);
184e7ecf7cbSSimon Glass 	return upriv->mmc;
185e7ecf7cbSSimon Glass }
186e7ecf7cbSSimon Glass 
187c4d660d4SSimon Glass #if CONFIG_IS_ENABLED(BLK)
1888ef761edSSimon Glass struct mmc *find_mmc_device(int dev_num)
1898ef761edSSimon Glass {
1908ef761edSSimon Glass 	struct udevice *dev, *mmc_dev;
1918ef761edSSimon Glass 	int ret;
1928ef761edSSimon Glass 
19397525647SSimon Glass 	ret = blk_find_device(IF_TYPE_MMC, dev_num, &dev);
1948ef761edSSimon Glass 
1958ef761edSSimon Glass 	if (ret) {
1968ef761edSSimon Glass #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
1978ef761edSSimon Glass 		printf("MMC Device %d not found\n", dev_num);
1988ef761edSSimon Glass #endif
1998ef761edSSimon Glass 		return NULL;
2008ef761edSSimon Glass 	}
2018ef761edSSimon Glass 
2028ef761edSSimon Glass 	mmc_dev = dev_get_parent(dev);
2038ef761edSSimon Glass 
20497525647SSimon Glass 	struct mmc *mmc = mmc_get_mmc_dev(mmc_dev);
20597525647SSimon Glass 
20697525647SSimon Glass 	return mmc;
2078ef761edSSimon Glass }
2088ef761edSSimon Glass 
2098ef761edSSimon Glass int get_mmc_num(void)
2108ef761edSSimon Glass {
21146683f3dSKever Yang 	return max((blk_find_max_devnum(IF_TYPE_MMC) + 1), 0);
2128ef761edSSimon Glass }
2138ef761edSSimon Glass 
2148ef761edSSimon Glass int mmc_get_next_devnum(void)
2158ef761edSSimon Glass {
216dd399cb7SMasahiro Yamada 	return blk_find_max_devnum(IF_TYPE_MMC);
2178ef761edSSimon Glass }
2188ef761edSSimon Glass 
2198ef761edSSimon Glass struct blk_desc *mmc_get_blk_desc(struct mmc *mmc)
2208ef761edSSimon Glass {
2218ef761edSSimon Glass 	struct blk_desc *desc;
2228ef761edSSimon Glass 	struct udevice *dev;
2238ef761edSSimon Glass 
2248ef761edSSimon Glass 	device_find_first_child(mmc->dev, &dev);
2258ef761edSSimon Glass 	if (!dev)
2268ef761edSSimon Glass 		return NULL;
2278ef761edSSimon Glass 	desc = dev_get_uclass_platdata(dev);
2288ef761edSSimon Glass 
2298ef761edSSimon Glass 	return desc;
2308ef761edSSimon Glass }
2318ef761edSSimon Glass 
2328ef761edSSimon Glass void mmc_do_preinit(void)
2338ef761edSSimon Glass {
2348ef761edSSimon Glass 	struct udevice *dev;
2358ef761edSSimon Glass 	struct uclass *uc;
2368ef761edSSimon Glass 	int ret;
2378ef761edSSimon Glass 
2388ef761edSSimon Glass 	ret = uclass_get(UCLASS_MMC, &uc);
2398ef761edSSimon Glass 	if (ret)
2408ef761edSSimon Glass 		return;
2418ef761edSSimon Glass 	uclass_foreach_dev(dev, uc) {
2428ef761edSSimon Glass 		struct mmc *m = mmc_get_mmc_dev(dev);
2438ef761edSSimon Glass 
2448ef761edSSimon Glass 		if (!m)
2458ef761edSSimon Glass 			continue;
2468ef761edSSimon Glass #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
2478ef761edSSimon Glass 		mmc_set_preinit(m, 1);
2488ef761edSSimon Glass #endif
2498ef761edSSimon Glass 		if (m->preinit)
2508ef761edSSimon Glass 			mmc_start_init(m);
2518ef761edSSimon Glass 	}
2528ef761edSSimon Glass }
2538ef761edSSimon Glass 
2548ef761edSSimon Glass #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
2558ef761edSSimon Glass void print_mmc_devices(char separator)
2568ef761edSSimon Glass {
2578ef761edSSimon Glass 	struct udevice *dev;
2588ef761edSSimon Glass 	char *mmc_type;
2598ef761edSSimon Glass 	bool first = true;
2608ef761edSSimon Glass 
2618ef761edSSimon Glass 	for (uclass_first_device(UCLASS_MMC, &dev);
2628ef761edSSimon Glass 	     dev;
2631bd4f92cSXu Ziyuan 	     uclass_next_device(&dev), first = false) {
2648ef761edSSimon Glass 		struct mmc *m = mmc_get_mmc_dev(dev);
2658ef761edSSimon Glass 
2668ef761edSSimon Glass 		if (!first) {
2678ef761edSSimon Glass 			printf("%c", separator);
2688ef761edSSimon Glass 			if (separator != '\n')
2698ef761edSSimon Glass 				puts(" ");
2708ef761edSSimon Glass 		}
2718ef761edSSimon Glass 		if (m->has_init)
2728ef761edSSimon Glass 			mmc_type = IS_SD(m) ? "SD" : "eMMC";
2738ef761edSSimon Glass 		else
2748ef761edSSimon Glass 			mmc_type = NULL;
2758ef761edSSimon Glass 
2768ef761edSSimon Glass 		printf("%s: %d", m->cfg->name, mmc_get_blk_desc(m)->devnum);
2778ef761edSSimon Glass 		if (mmc_type)
2788ef761edSSimon Glass 			printf(" (%s)", mmc_type);
2798ef761edSSimon Glass 	}
2808ef761edSSimon Glass 
2818ef761edSSimon Glass 	printf("\n");
2828ef761edSSimon Glass }
2838ef761edSSimon Glass 
2848ef761edSSimon Glass #else
2858ef761edSSimon Glass void print_mmc_devices(char separator) { }
2868ef761edSSimon Glass #endif
287eede897eSSimon Glass 
288eede897eSSimon Glass int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
289eede897eSSimon Glass {
290eede897eSSimon Glass 	struct blk_desc *bdesc;
291eede897eSSimon Glass 	struct udevice *bdev;
29202ad33aaSJaehoon Chung 	int ret, devnum = -1;
293eede897eSSimon Glass 
29466656020SSimon Glass 	if (!mmc_get_ops(dev))
29566656020SSimon Glass 		return -ENOSYS;
29602ad33aaSJaehoon Chung #ifndef CONFIG_SPL_BUILD
29702ad33aaSJaehoon Chung 	/* Use the fixed index with aliase node's index */
29866e0ed5cSSimon Glass 	ret = dev_read_alias_seq(dev, &devnum);
29966e0ed5cSSimon Glass 	debug("%s: alias ret=%d, devnum=%d\n", __func__, ret, devnum);
30002ad33aaSJaehoon Chung #endif
30102ad33aaSJaehoon Chung 
30202ad33aaSJaehoon Chung 	ret = blk_create_devicef(dev, "mmc_blk", "blk", IF_TYPE_MMC,
30302ad33aaSJaehoon Chung 			devnum, 512, 0, &bdev);
304eede897eSSimon Glass 	if (ret) {
305eede897eSSimon Glass 		debug("Cannot create block device\n");
306eede897eSSimon Glass 		return ret;
307eede897eSSimon Glass 	}
308eede897eSSimon Glass 	bdesc = dev_get_uclass_platdata(bdev);
309eede897eSSimon Glass 	mmc->cfg = cfg;
310eede897eSSimon Glass 	mmc->priv = dev;
311eede897eSSimon Glass 
312eede897eSSimon Glass 	/* the following chunk was from mmc_register() */
313eede897eSSimon Glass 
314eede897eSSimon Glass 	/* Setup dsr related values */
315eede897eSSimon Glass 	mmc->dsr_imp = 0;
316eede897eSSimon Glass 	mmc->dsr = 0xffffffff;
317eede897eSSimon Glass 	/* Setup the universal parts of the block interface just once */
318eede897eSSimon Glass 	bdesc->removable = 1;
319eede897eSSimon Glass 
320eede897eSSimon Glass 	/* setup initial part type */
321eede897eSSimon Glass 	bdesc->part_type = cfg->part_type;
322eede897eSSimon Glass 	mmc->dev = dev;
323eede897eSSimon Glass 
324eede897eSSimon Glass 	return 0;
325eede897eSSimon Glass }
326eede897eSSimon Glass 
327eede897eSSimon Glass int mmc_unbind(struct udevice *dev)
328eede897eSSimon Glass {
329eede897eSSimon Glass 	struct udevice *bdev;
330eede897eSSimon Glass 
331eede897eSSimon Glass 	device_find_first_child(dev, &bdev);
332eede897eSSimon Glass 	if (bdev) {
333706865afSStefan Roese 		device_remove(bdev, DM_REMOVE_NORMAL);
334eede897eSSimon Glass 		device_unbind(bdev);
335eede897eSSimon Glass 	}
336eede897eSSimon Glass 
337eede897eSSimon Glass 	return 0;
338eede897eSSimon Glass }
339eede897eSSimon Glass 
340eede897eSSimon Glass static int mmc_select_hwpart(struct udevice *bdev, int hwpart)
341eede897eSSimon Glass {
342eede897eSSimon Glass 	struct udevice *mmc_dev = dev_get_parent(bdev);
343eede897eSSimon Glass 	struct mmc *mmc = mmc_get_mmc_dev(mmc_dev);
344eede897eSSimon Glass 	struct blk_desc *desc = dev_get_uclass_platdata(bdev);
345eede897eSSimon Glass 
346eede897eSSimon Glass 	if (desc->hwpart == hwpart)
347eede897eSSimon Glass 		return 0;
348eede897eSSimon Glass 
349eede897eSSimon Glass 	if (mmc->part_config == MMCPART_NOAVAILABLE)
350eede897eSSimon Glass 		return -EMEDIUMTYPE;
351eede897eSSimon Glass 
352dd399cb7SMasahiro Yamada 	return mmc_switch_part(mmc, hwpart);
353eede897eSSimon Glass }
354eede897eSSimon Glass 
355a0269bb6SFiach Antaw static int mmc_blk_probe(struct udevice *dev)
356a0269bb6SFiach Antaw {
357854f9a71SSimon Glass 	struct udevice *mmc_dev = dev_get_parent(dev);
358854f9a71SSimon Glass 	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc_dev);
359854f9a71SSimon Glass 	struct mmc *mmc = upriv->mmc;
360854f9a71SSimon Glass 	int ret;
361a0269bb6SFiach Antaw 
362854f9a71SSimon Glass 	ret = mmc_init(mmc);
363854f9a71SSimon Glass 	if (ret) {
364854f9a71SSimon Glass 		debug("%s: mmc_init() failed (err=%d)\n", __func__, ret);
365854f9a71SSimon Glass 		return ret;
366854f9a71SSimon Glass 	}
367854f9a71SSimon Glass 
368854f9a71SSimon Glass 	return 0;
369a0269bb6SFiach Antaw }
370a0269bb6SFiach Antaw 
371eede897eSSimon Glass static const struct blk_ops mmc_blk_ops = {
372eede897eSSimon Glass 	.read	= mmc_bread,
373eede897eSSimon Glass #ifndef CONFIG_SPL_BUILD
374eede897eSSimon Glass 	.write	= mmc_bwrite,
375561e624cSSimon Glass 	.erase	= mmc_berase,
376eede897eSSimon Glass #endif
377eede897eSSimon Glass 	.select_hwpart	= mmc_select_hwpart,
378eede897eSSimon Glass };
379eede897eSSimon Glass 
380eede897eSSimon Glass U_BOOT_DRIVER(mmc_blk) = {
381eede897eSSimon Glass 	.name		= "mmc_blk",
382eede897eSSimon Glass 	.id		= UCLASS_BLK,
383eede897eSSimon Glass 	.ops		= &mmc_blk_ops,
384a0269bb6SFiach Antaw 	.probe		= mmc_blk_probe,
385eede897eSSimon Glass };
3868ef761edSSimon Glass #endif /* CONFIG_BLK */
3878ef761edSSimon Glass 
388e7ecf7cbSSimon Glass U_BOOT_DRIVER(mmc) = {
389e7ecf7cbSSimon Glass 	.name	= "mmc",
390e7ecf7cbSSimon Glass 	.id	= UCLASS_MMC,
391e7ecf7cbSSimon Glass };
392e7ecf7cbSSimon Glass 
393e7ecf7cbSSimon Glass UCLASS_DRIVER(mmc) = {
394e7ecf7cbSSimon Glass 	.id		= UCLASS_MMC,
395e7ecf7cbSSimon Glass 	.name		= "mmc",
396e7ecf7cbSSimon Glass 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
397e7ecf7cbSSimon Glass 	.per_device_auto_alloc_size = sizeof(struct mmc_uclass_priv),
398e7ecf7cbSSimon Glass };
399