diff options
Diffstat (limited to 'drivers/mmc')
-rw-r--r-- | drivers/mmc/hi6220_dw_mmc.c | 100 | ||||
-rw-r--r-- | drivers/mmc/mmc.c | 39 |
2 files changed, 102 insertions, 37 deletions
diff --git a/drivers/mmc/hi6220_dw_mmc.c b/drivers/mmc/hi6220_dw_mmc.c index ce395d5..cc58aff 100644 --- a/drivers/mmc/hi6220_dw_mmc.c +++ b/drivers/mmc/hi6220_dw_mmc.c @@ -5,51 +5,89 @@ */ #include <common.h> +#include <dm.h> #include <dwmmc.h> +#include <errno.h> +#include <fdtdec.h> #include <malloc.h> -#include <linux/errno.h> -#define DWMMC_MAX_CH_NUM 4 +DECLARE_GLOBAL_DATA_PTR; -#define DWMMC_MAX_FREQ 50000000 -#define DWMMC_MIN_FREQ 400000 +struct hi6220_dwmmc_plat { + struct mmc_config cfg; + struct mmc mmc; +}; -/* Source clock is configured to 100MHz by ATF bl1*/ -#define MMC0_DEFAULT_FREQ 100000000 +struct hi6220_dwmmc_priv_data { + struct dwmci_host host; +}; -static int hi6220_dwmci_core_init(struct dwmci_host *host, int index) +static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev) { - host->name = "Hisilicon DWMMC"; + struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev); + struct dwmci_host *host = &priv->host; - host->dev_index = index; + host->name = dev->name; + host->ioaddr = (void *)devfdt_get_addr(dev); + host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), + "bus-width", 4); + + /* use non-removable property for differentiating SD card and eMMC */ + if (dev_read_bool(dev, "non-removable")) + host->dev_index = 0; + else + host->dev_index = 1; + + host->priv = priv; - /* Add the mmc channel to be registered with mmc core */ - if (add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ)) { - printf("DWMMC%d registration failed\n", index); - return -1; - } return 0; } -/* - * This function adds the mmc channel to be registered with mmc core. - * index - mmc channel number. - * regbase - register base address of mmc channel specified in 'index'. - * bus_width - operating bus width of mmc channel specified in 'index'. - */ -int hi6220_dwmci_add_port(int index, u32 regbase, int bus_width) +static int hi6220_dwmmc_probe(struct udevice *dev) { - struct dwmci_host *host = NULL; + struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev); + struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); + struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev); + struct dwmci_host *host = &priv->host; - host = calloc(1, sizeof(struct dwmci_host)); - if (!host) { - pr_err("dwmci_host calloc failed!\n"); - return -ENOMEM; - } + /* Use default bus speed due to absence of clk driver */ + host->bus_hz = 50000000; - host->ioaddr = (void *)(ulong)regbase; - host->buswidth = bus_width; - host->bus_hz = MMC0_DEFAULT_FREQ; + dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000); + host->mmc = &plat->mmc; - return hi6220_dwmci_core_init(host, index); + host->mmc->priv = &priv->host; + upriv->mmc = host->mmc; + host->mmc->dev = dev; + + return dwmci_probe(dev); } + +static int hi6220_dwmmc_bind(struct udevice *dev) +{ + struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev); + int ret; + + ret = dwmci_bind(dev, &plat->mmc, &plat->cfg); + if (ret) + return ret; + + return 0; +} + +static const struct udevice_id hi6220_dwmmc_ids[] = { + { .compatible = "hisilicon,hi6220-dw-mshc" }, + { } +}; + +U_BOOT_DRIVER(hi6220_dwmmc_drv) = { + .name = "hi6220_dwmmc", + .id = UCLASS_MMC, + .of_match = hi6220_dwmmc_ids, + .ofdata_to_platdata = hi6220_dwmmc_ofdata_to_platdata, + .ops = &dm_dwmci_ops, + .bind = hi6220_dwmmc_bind, + .probe = hi6220_dwmmc_probe, + .priv_auto_alloc_size = sizeof(struct hi6220_dwmmc_priv_data), + .platdata_auto_alloc_size = sizeof(struct hi6220_dwmmc_plat), +}; diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index d858127..84d157f 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -754,7 +754,8 @@ int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value) } #if !CONFIG_IS_ENABLED(MMC_TINY) -static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode) +static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode, + bool hsdowngrade) { int err; int speed_bits; @@ -788,6 +789,20 @@ static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode) if (err) return err; +#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ + CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) + /* + * In case the eMMC is in HS200/HS400 mode and we are downgrading + * to HS mode, the card clock are still running much faster than + * the supported HS mode clock, so we can not reliably read out + * Extended CSD. Reconfigure the controller to run at HS mode. + */ + if (hsdowngrade) { + mmc_select_mode(mmc, MMC_HS); + mmc_set_clock(mmc, mmc_mode2freq(mmc, MMC_HS), false); + } +#endif + if ((mode == MMC_HS) || (mode == MMC_HS_52)) { /* Now check to see that it worked */ err = mmc_send_ext_csd(mmc, test_csd); @@ -1849,7 +1864,7 @@ static int mmc_select_hs400(struct mmc *mmc) int err; /* Set timing to HS200 for tuning */ - err = mmc_set_card_speed(mmc, MMC_HS_200); + err = mmc_set_card_speed(mmc, MMC_HS_200, false); if (err) return err; @@ -1865,7 +1880,7 @@ static int mmc_select_hs400(struct mmc *mmc) } /* Set back to HS */ - mmc_set_card_speed(mmc, MMC_HS); + mmc_set_card_speed(mmc, MMC_HS, false); mmc_set_clock(mmc, mmc_mode2freq(mmc, MMC_HS), false); err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, @@ -1873,7 +1888,7 @@ static int mmc_select_hs400(struct mmc *mmc) if (err) return err; - err = mmc_set_card_speed(mmc, MMC_HS_400); + err = mmc_set_card_speed(mmc, MMC_HS_400, false); if (err) return err; @@ -1920,7 +1935,19 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps) return -ENOTSUPP; } - mmc_set_clock(mmc, mmc->legacy_speed, MMC_CLK_ENABLE); +#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ + CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) + /* + * In case the eMMC is in HS200/HS400 mode, downgrade to HS mode + * before doing anything else, since a transition from either of + * the HS200/HS400 mode directly to legacy mode is not supported. + */ + if (mmc->selected_mode == MMC_HS_200 || + mmc->selected_mode == MMC_HS_400) + mmc_set_card_speed(mmc, MMC_HS, true); + else +#endif + mmc_set_clock(mmc, mmc->legacy_speed, MMC_CLK_ENABLE); for_each_mmc_mode_by_pref(card_caps, mwt) { for_each_supported_width(card_caps & mwt->widths, @@ -1952,7 +1979,7 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps) } } else { /* configure the bus speed (card) */ - err = mmc_set_card_speed(mmc, mwt->mode); + err = mmc_set_card_speed(mmc, mwt->mode, false); if (err) goto error; |