]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
dm: mmc: Add support for driver-model block devices
authorSimon Glass <sjg@chromium.org>
Sun, 1 May 2016 19:52:41 +0000 (13:52 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 17 May 2016 15:54:43 +0000 (09:54 -0600)
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>
drivers/mmc/mmc.c
drivers/mmc/mmc_private.h
drivers/mmc/mmc_write.c
include/mmc.h
include/part.h

index 7183afcff2af52eafcd6b3f9d9c2b4d9c03509f9..74b3d68f871ccfc24c33e2fded971e5bba5c4739 100644 (file)
@@ -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
index 6ec52fda055a4d1434c95dc9d867a283de2fc66c..27b9e5f56f8c284d489e817d9a7e33fc5dc3f8b2 100644 (file)
@@ -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 */
 
index bd07b20f5fa5acef6fe332f8266cbb9fc70c9099..0f8b5c79d7c6073d47964e25140b1991b119cbc4 100644 (file)
@@ -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;
index fb8d9b2f55d7c77385556b6c34cbe49104625359..a5c6573ddd6efcf7fbd76903089b5c06e278cefd 100644 (file)
@@ -344,7 +344,9 @@ struct mmc_config {
 
 /* TODO struct mmc should be in mmc_private but it's hard to fix right now */
 struct mmc {
+#ifndef CONFIG_BLK
        struct list_head link;
+#endif
        const struct mmc_config *cfg;   /* provided configuration */
        uint version;
        void *priv;
@@ -376,7 +378,9 @@ struct mmc {
        u64 capacity_gp[4];
        u64 enh_user_start;
        u64 enh_user_size;
+#ifndef CONFIG_BLK
        struct blk_desc block_dev;
+#endif
        char op_cond_pending;   /* 1 if we are waiting on an op_cond command */
        char init_in_progress;  /* 1 if we have done mmc_start_init() */
        char preinit;           /* start init as early as possible */
index bc9dc64912b8b798ab084499c369d5e55c9f0cbc..226b5be9df26384818e0299fde0d5f0e9d782646 100644 (file)
@@ -73,23 +73,6 @@ typedef struct disk_partition {
  */
 struct blk_desc *blk_get_dev(const char *ifname, int dev);
 
-/**
- * mmc_select_hwpart() - Select the MMC hardware partiion on an MMC device
- *
- * MMC devices can support partitioning at the hardware level. This is quite
- * separate from the normal idea of software-based partitions. MMC hardware
- * partitions must be explicitly selected. Once selected only the region of
- * the device covered by that partition is accessible.
- *
- * The MMC standard provides for two boot partitions (numbered 1 and 2),
- * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
- *
- * @dev_num:   Block device number (struct blk_desc->dev value)
- * @hwpart:    Hardware partition number to select. 0 means the raw device,
- *             1 is the first partition, 2 is the second, etc.
- * @return 0 if OK, other value for an error
- */
-int mmc_select_hwpart(int dev_num, int hwpart);
 struct blk_desc *mg_disk_get_dev(int dev);
 int host_get_dev_err(int dev, struct blk_desc **blk_devp);
 
@@ -167,7 +150,6 @@ extern const struct block_drvr block_drvr[];
 #else
 static inline struct blk_desc *blk_get_dev(const char *ifname, int dev)
 { return NULL; }
-static inline int mmc_select_hwpart(int dev_num, int hwpart) { return -1; }
 static inline struct blk_desc *mg_disk_get_dev(int dev) { return NULL; }
 
 static inline int part_get_info(struct blk_desc *dev_desc, int part,