X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=drivers%2Fmmc%2Fhi6220_dw_mmc.c;h=bb5d0922bebe1920a7bddc92e8f65bd57639f87c;hb=d1998a9fde0a917d6496299f6a97b6bccfdc6724;hp=731458c18c5630a382e533ae38f169ea713c5211;hpb=fcd78fa604d994477fd209b9faab4a974b103250;p=platform%2Fkernel%2Fu-boot.git diff --git a/drivers/mmc/hi6220_dw_mmc.c b/drivers/mmc/hi6220_dw_mmc.c index 731458c..bb5d092 100644 --- a/drivers/mmc/hi6220_dw_mmc.c +++ b/drivers/mmc/hi6220_dw_mmc.c @@ -1,56 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2015 Linaro * peter.griffin - * - * SPDX-License-Identifier: GPL-2.0+ */ #include +#include #include +#include +#include #include -#include -#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) +struct hisi_mmc_data { + unsigned int clock; + bool use_fifo; +}; + +static int hi6220_dwmmc_of_to_plat(struct udevice *dev) { - host->name = "HiKey DWMMC"; + struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev); + struct dwmci_host *host = &priv->host; + + host->name = dev->name; + host->ioaddr = dev_read_addr_ptr(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->dev_index = index; + 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_plat(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; + struct hisi_mmc_data *mmc_data; - host = calloc(1, sizeof(struct dwmci_host)); - if (!host) { - error("dwmci_host calloc failed!\n"); - return -ENOMEM; - } + mmc_data = (struct hisi_mmc_data *)dev_get_driver_data(dev); - host->ioaddr = (void *)regbase; - host->buswidth = bus_width; - host->bus_hz = MMC0_DEFAULT_FREQ; + /* Use default bus speed due to absence of clk driver */ + host->bus_hz = mmc_data->clock; - return hi6220_dwmci_core_init(host, index); + dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000); + host->mmc = &plat->mmc; + + host->fifo_mode = mmc_data->use_fifo; + 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_plat(dev); + int ret; + + ret = dwmci_bind(dev, &plat->mmc, &plat->cfg); + if (ret) + return ret; + + return 0; +} + +static const struct hisi_mmc_data hi3660_mmc_data = { + .clock = 3200000, + .use_fifo = true, +}; + +static const struct hisi_mmc_data hi6220_mmc_data = { + .clock = 50000000, + .use_fifo = false, +}; + +static const struct udevice_id hi6220_dwmmc_ids[] = { + { .compatible = "hisilicon,hi6220-dw-mshc", + .data = (ulong)&hi6220_mmc_data }, + { .compatible = "hisilicon,hi3798cv200-dw-mshc", + .data = (ulong)&hi6220_mmc_data }, + { .compatible = "hisilicon,hi3660-dw-mshc", + .data = (ulong)&hi3660_mmc_data }, + { } +}; + +U_BOOT_DRIVER(hi6220_dwmmc_drv) = { + .name = "hi6220_dwmmc", + .id = UCLASS_MMC, + .of_match = hi6220_dwmmc_ids, + .of_to_plat = hi6220_dwmmc_of_to_plat, + .ops = &dm_dwmci_ops, + .bind = hi6220_dwmmc_bind, + .probe = hi6220_dwmmc_probe, + .priv_auto = sizeof(struct hi6220_dwmmc_priv_data), + .plat_auto = sizeof(struct hi6220_dwmmc_plat), +};