diff options
author | Simon Glass <sjg@chromium.org> | 2016-05-01 13:52:41 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2016-05-17 09:54:43 -0600 |
commit | 33fb211dd2706e666db4008801dc0d5903fd82f6 (patch) | |
tree | 5d29a3fea60d78047d2afa7b884c667ac84c35ad /drivers | |
parent | ad27dd5e13436b554f0f3cb9cd3e79634494072d (diff) | |
download | u-boot-33fb211dd2706e666db4008801dc0d5903fd82f6.tar.gz u-boot-33fb211dd2706e666db4008801dc0d5903fd82f6.tar.xz u-boot-33fb211dd2706e666db4008801dc0d5903fd82f6.zip |
dm: mmc: Add support for driver-model block devices
Add support for enabling CONFIG_BLK with MMC. This involves changing a
few functions to use struct udevice and adding a MMC block device driver.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mmc/mmc.c | 48 | ||||
-rw-r--r-- | drivers/mmc/mmc_private.h | 9 | ||||
-rw-r--r-- | drivers/mmc/mmc_write.c | 9 |
3 files changed, 54 insertions, 12 deletions
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 7183afcff2..74b3d68f87 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -216,9 +216,17 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start, return blkcnt; } +#ifdef CONFIG_BLK +static ulong mmc_bread(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, + void *dst) +#else static ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, void *dst) +#endif { +#ifdef CONFIG_BLK + struct blk_desc *block_dev = dev_get_uclass_platdata(dev); +#endif int dev_num = block_dev->devnum; int err; lbaint_t cur, blocks_todo = blkcnt; @@ -580,15 +588,15 @@ static int mmc_switch_part(struct mmc *mmc, unsigned int part_num) return ret; } -static int mmc_select_hwpartp(struct blk_desc *desc, int hwpart) +#ifdef CONFIG_BLK +static int mmc_select_hwpart(struct udevice *bdev, int hwpart) { - struct mmc *mmc = find_mmc_device(desc->devnum); + struct udevice *mmc_dev = dev_get_parent(bdev); + struct mmc *mmc = mmc_get_mmc_dev(mmc_dev); + struct blk_desc *desc = dev_get_uclass_platdata(bdev); int ret; - if (!mmc) - return -ENODEV; - - if (mmc->block_dev.hwpart == hwpart) + if (desc->hwpart == hwpart) return 0; if (mmc->part_config == MMCPART_NOAVAILABLE) @@ -600,10 +608,10 @@ static int mmc_select_hwpartp(struct blk_desc *desc, int hwpart) return 0; } - -int mmc_select_hwpart(int dev_num, int hwpart) +#else +static int mmc_select_hwpartp(struct blk_desc *desc, int hwpart) { - struct mmc *mmc = find_mmc_device(dev_num); + struct mmc *mmc = find_mmc_device(desc->devnum); int ret; if (!mmc) @@ -621,6 +629,7 @@ int mmc_select_hwpart(int dev_num, int hwpart) return 0; } +#endif int mmc_hwpart_config(struct mmc *mmc, const struct mmc_hwpart_conf *conf, @@ -1554,7 +1563,6 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg) mmc->dsr_imp = 0; mmc->dsr = 0xffffffff; /* Setup the universal parts of the block interface just once */ - bdesc->if_type = IF_TYPE_MMC; bdesc->removable = 1; /* setup initial part type */ @@ -1623,6 +1631,7 @@ void mmc_destroy(struct mmc *mmc) } #endif +#ifndef CONFIG_BLK static int mmc_get_dev(int dev, struct blk_desc **descp) { struct mmc *mmc = find_mmc_device(dev); @@ -1638,6 +1647,7 @@ static int mmc_get_dev(int dev, struct blk_desc **descp) return 0; } +#endif /* board-specific MMC power initializations. */ __weak void board_mmc_power_init(void) @@ -1729,7 +1739,11 @@ int mmc_init(struct mmc *mmc) { int err = 0; unsigned start; +#ifdef CONFIG_DM_MMC + struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc->dev); + upriv->mmc = mmc; +#endif if (mmc->has_init) return 0; @@ -1957,6 +1971,19 @@ int mmc_set_rst_n_function(struct mmc *mmc, u8 enable) } #endif +#ifdef CONFIG_BLK +static const struct blk_ops mmc_blk_ops = { + .read = mmc_bread, + .write = mmc_bwrite, + .select_hwpart = mmc_select_hwpart, +}; + +U_BOOT_DRIVER(mmc_blk) = { + .name = "mmc_blk", + .id = UCLASS_BLK, + .ops = &mmc_blk_ops, +}; +#else U_BOOT_LEGACY_BLK(mmc) = { .if_typename = "mmc", .if_type = IF_TYPE_MMC, @@ -1964,3 +1991,4 @@ U_BOOT_LEGACY_BLK(mmc) = { .get_dev = mmc_get_dev, .select_hwpart = mmc_select_hwpartp, }; +#endif diff --git a/drivers/mmc/mmc_private.h b/drivers/mmc/mmc_private.h index 6ec52fda05..27b9e5f56f 100644 --- a/drivers/mmc/mmc_private.h +++ b/drivers/mmc/mmc_private.h @@ -25,8 +25,13 @@ void mmc_adapter_card_type_ident(void); unsigned long mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt); -unsigned long mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, - lbaint_t blkcnt, const void *src); +#ifdef CONFIG_BLK +ulong mmc_bwrite(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, + const void *src); +#else +ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, + const void *src); +#endif #else /* CONFIG_SPL_BUILD */ diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c index bd07b20f5f..0f8b5c79d7 100644 --- a/drivers/mmc/mmc_write.c +++ b/drivers/mmc/mmc_write.c @@ -9,6 +9,7 @@ #include <config.h> #include <common.h> +#include <dm.h> #include <part.h> #include <div64.h> #include <linux/math64.h> @@ -172,9 +173,17 @@ static ulong mmc_write_blocks(struct mmc *mmc, lbaint_t start, return blkcnt; } +#ifdef CONFIG_BLK +ulong mmc_bwrite(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, + const void *src) +#else ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, const void *src) +#endif { +#ifdef CONFIG_BLK + struct blk_desc *block_dev = dev_get_uclass_platdata(dev); +#endif int dev_num = block_dev->devnum; lbaint_t cur, blocks_todo = blkcnt; int err; |