dm: mmc: Move non-CONFIG_BLK code into mmc_legacy.c

Rather than having #ifdef in mmc.c, move this code into the legacy file.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2016-06-12 23:30:17 -06:00
parent eede897e27
commit 5aed4cbba0
2 changed files with 91 additions and 95 deletions

View file

@ -585,29 +585,6 @@ int mmc_switch_part(struct mmc *mmc, unsigned int part_num)
return ret;
}
#ifndef CONFIG_BLK
static int mmc_select_hwpartp(struct blk_desc *desc, int hwpart)
{
struct mmc *mmc = find_mmc_device(desc->devnum);
int ret;
if (!mmc)
return -ENODEV;
if (mmc->block_dev.hwpart == hwpart)
return 0;
if (mmc->part_config == MMCPART_NOAVAILABLE)
return -EMEDIUMTYPE;
ret = mmc_switch_part(mmc, hwpart);
if (ret)
return ret;
return 0;
}
#endif
int mmc_hwpart_config(struct mmc *mmc,
const struct mmc_hwpart_conf *conf,
enum mmc_hwpart_conf_mode mode)
@ -1511,68 +1488,6 @@ static int mmc_send_if_cond(struct mmc *mmc)
return 0;
}
#ifndef CONFIG_BLK
struct mmc *mmc_create(const struct mmc_config *cfg, void *priv)
{
struct blk_desc *bdesc;
struct mmc *mmc;
/* quick validation */
if (cfg == NULL || cfg->ops == NULL || cfg->ops->send_cmd == NULL ||
cfg->f_min == 0 || cfg->f_max == 0 || cfg->b_max == 0)
return NULL;
mmc = calloc(1, sizeof(*mmc));
if (mmc == NULL)
return NULL;
mmc->cfg = cfg;
mmc->priv = priv;
/* the following chunk was mmc_register() */
/* Setup dsr related values */
mmc->dsr_imp = 0;
mmc->dsr = 0xffffffff;
/* Setup the universal parts of the block interface just once */
bdesc = mmc_get_blk_desc(mmc);
bdesc->if_type = IF_TYPE_MMC;
bdesc->removable = 1;
bdesc->devnum = mmc_get_next_devnum();
bdesc->block_read = mmc_bread;
bdesc->block_write = mmc_bwrite;
bdesc->block_erase = mmc_berase;
/* setup initial part type */
bdesc->part_type = mmc->cfg->part_type;
mmc_list_add(mmc);
return mmc;
}
void mmc_destroy(struct mmc *mmc)
{
/* only freeing memory for now */
free(mmc);
}
static int mmc_get_dev(int dev, struct blk_desc **descp)
{
struct mmc *mmc = find_mmc_device(dev);
int ret;
if (!mmc)
return -ENODEV;
ret = mmc_init(mmc);
if (ret)
return ret;
*descp = &mmc->block_dev;
return 0;
}
#endif
/* board-specific MMC power initializations. */
__weak void board_mmc_power_init(void)
{
@ -1894,13 +1809,3 @@ int mmc_set_rst_n_function(struct mmc *mmc, u8 enable)
enable);
}
#endif
#ifndef CONFIG_BLK
U_BOOT_LEGACY_BLK(mmc) = {
.if_typename = "mmc",
.if_type = IF_TYPE_MMC,
.max_devs = -1,
.get_dev = mmc_get_dev,
.select_hwpart = mmc_select_hwpartp,
};
#endif

View file

@ -6,7 +6,9 @@
*/
#include <common.h>
#include <malloc.h>
#include <mmc.h>
#include "mmc_private.h"
static struct list_head mmc_devices;
static int cur_dev_num = -1;
@ -106,3 +108,92 @@ void print_mmc_devices(char separator)
#else
void print_mmc_devices(char separator) { }
#endif
struct mmc *mmc_create(const struct mmc_config *cfg, void *priv)
{
struct blk_desc *bdesc;
struct mmc *mmc;
/* quick validation */
if (cfg == NULL || cfg->ops == NULL || cfg->ops->send_cmd == NULL ||
cfg->f_min == 0 || cfg->f_max == 0 || cfg->b_max == 0)
return NULL;
mmc = calloc(1, sizeof(*mmc));
if (mmc == NULL)
return NULL;
mmc->cfg = cfg;
mmc->priv = priv;
/* the following chunk was mmc_register() */
/* Setup dsr related values */
mmc->dsr_imp = 0;
mmc->dsr = 0xffffffff;
/* Setup the universal parts of the block interface just once */
bdesc = mmc_get_blk_desc(mmc);
bdesc->if_type = IF_TYPE_MMC;
bdesc->removable = 1;
bdesc->devnum = mmc_get_next_devnum();
bdesc->block_read = mmc_bread;
bdesc->block_write = mmc_bwrite;
bdesc->block_erase = mmc_berase;
/* setup initial part type */
bdesc->part_type = mmc->cfg->part_type;
mmc_list_add(mmc);
return mmc;
}
void mmc_destroy(struct mmc *mmc)
{
/* only freeing memory for now */
free(mmc);
}
static int mmc_select_hwpartp(struct blk_desc *desc, int hwpart)
{
struct mmc *mmc = find_mmc_device(desc->devnum);
int ret;
if (!mmc)
return -ENODEV;
if (mmc->block_dev.hwpart == hwpart)
return 0;
if (mmc->part_config == MMCPART_NOAVAILABLE)
return -EMEDIUMTYPE;
ret = mmc_switch_part(mmc, hwpart);
if (ret)
return ret;
return 0;
}
static int mmc_get_dev(int dev, struct blk_desc **descp)
{
struct mmc *mmc = find_mmc_device(dev);
int ret;
if (!mmc)
return -ENODEV;
ret = mmc_init(mmc);
if (ret)
return ret;
*descp = &mmc->block_dev;
return 0;
}
U_BOOT_LEGACY_BLK(mmc) = {
.if_typename = "mmc",
.if_type = IF_TYPE_MMC,
.max_devs = -1,
.get_dev = mmc_get_dev,
.select_hwpart = mmc_select_hwpartp,
};