X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=drivers%2Fmmc%2Fs5p_sdhci.c;h=9dd0b865eb867643fe0630bbe4363f1705679d10;hb=7997599e2df64c8fb450bc03f2d618adbde05f6e;hp=3bace21a046b4564bff4c4c39373e538fb15d48f;hpb=2863a9bfc29092be37f8beee230883367b057065;p=oweals%2Fu-boot.git diff --git a/drivers/mmc/s5p_sdhci.c b/drivers/mmc/s5p_sdhci.c index 3bace21a04..9dd0b865eb 100644 --- a/drivers/mmc/s5p_sdhci.c +++ b/drivers/mmc/s5p_sdhci.c @@ -1,21 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2012 SAMSUNG Electronics * Jaehoon Chung - * - * SPDX-License-Identifier: GPL-2.0+ */ #include +#include #include #include #include -#include +#include #include #include #include #include #include +#ifdef CONFIG_DM_MMC +struct s5p_sdhci_plat { + struct mmc_config cfg; + struct mmc mmc; +}; + +DECLARE_GLOBAL_DATA_PTR; +#endif + static char *S5P_NAME = "SAMSUNG SDHCI"; static void s5p_sdhci_set_control_reg(struct sdhci_host *host) { @@ -63,6 +72,17 @@ static void s5p_sdhci_set_control_reg(struct sdhci_host *host) sdhci_writel(host, ctrl, SDHCI_CONTROL2); } +static void s5p_set_clock(struct sdhci_host *host, u32 div) +{ + /* ToDo : Use the Clock Framework */ + set_mmc_clk(host->index, div); +} + +static const struct sdhci_ops s5p_sdhci_ops = { + .set_clock = &s5p_set_clock, + .set_control_reg = &s5p_sdhci_set_control_reg, +}; + static int s5p_sdhci_core_init(struct sdhci_host *host) { host->name = S5P_NAME; @@ -70,16 +90,18 @@ static int s5p_sdhci_core_init(struct sdhci_host *host) host->quirks = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_BROKEN_VOLTAGE | SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD | SDHCI_QUIRK_USE_WIDE8; + host->max_clk = 52000000; host->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; - host->version = sdhci_readw(host, SDHCI_HOST_VERSION); - - host->set_control_reg = &s5p_sdhci_set_control_reg; - host->set_clock = set_mmc_clk; + host->ops = &s5p_sdhci_ops; if (host->bus_width == 8) host->host_caps |= MMC_MODE_8BIT; - return add_sdhci(host, 52000000, 400000); +#ifndef CONFIG_BLK + return add_sdhci(host, 0, 400000); +#else + return 0; +#endif } int s5p_sdhci_init(u32 regbase, int index, int bus_width) @@ -87,7 +109,7 @@ int s5p_sdhci_init(u32 regbase, int index, int bus_width) struct sdhci_host *host = calloc(1, sizeof(struct sdhci_host)); if (!host) { printf("sdhci__host allocation fail!\n"); - return 1; + return -ENOMEM; } host->ioaddr = (void *)regbase; host->index = index; @@ -96,9 +118,6 @@ int s5p_sdhci_init(u32 regbase, int index, int bus_width) return s5p_sdhci_core_init(host); } -#if CONFIG_IS_ENABLED(OF_CONTROL) -struct sdhci_host sdhci_host[SDHCI_MAX_HOSTS]; - static int do_sdhci_init(struct sdhci_host *host) { int dev_id, flag, ret; @@ -139,9 +158,9 @@ static int sdhci_get_config(const void *blob, int node, struct sdhci_host *host) /* Get device id */ dev_id = pinmux_decode_periph_id(blob, node); - if (dev_id < PERIPH_ID_SDMMC0 && dev_id > PERIPH_ID_SDMMC3) { + if (dev_id < PERIPH_ID_SDMMC0 || dev_id > PERIPH_ID_SDMMC3) { debug("MMC: Can't get device id\n"); - return -1; + return -EINVAL; } host->index = dev_id - PERIPH_ID_SDMMC0; @@ -149,7 +168,7 @@ static int sdhci_get_config(const void *blob, int node, struct sdhci_host *host) bus_width = fdtdec_get_int(blob, node, "samsung,bus-width", 0); if (bus_width <= 0) { debug("MMC: Can't get bus-width\n"); - return -1; + return -EINVAL; } host->bus_width = bus_width; @@ -157,61 +176,71 @@ static int sdhci_get_config(const void *blob, int node, struct sdhci_host *host) base = fdtdec_get_addr(blob, node, "reg"); if (!base) { debug("MMC: Can't get base address\n"); - return -1; + return -EINVAL; } host->ioaddr = (void *)base; - gpio_request_by_name_nodev(blob, node, "pwr-gpios", 0, &host->pwr_gpio, - GPIOD_IS_OUT); - gpio_request_by_name_nodev(blob, node, "cd-gpios", 0, &host->cd_gpio, - GPIOD_IS_IN); + gpio_request_by_name_nodev(offset_to_ofnode(node), "pwr-gpios", 0, + &host->pwr_gpio, GPIOD_IS_OUT); + gpio_request_by_name_nodev(offset_to_ofnode(node), "cd-gpios", 0, + &host->cd_gpio, GPIOD_IS_IN); return 0; } -static int process_nodes(const void *blob, int node_list[], int count) +#ifdef CONFIG_DM_MMC +static int s5p_sdhci_probe(struct udevice *dev) { - struct sdhci_host *host; - int i, node, ret; - int failed = 0; - - debug("%s: count = %d\n", __func__, count); + struct s5p_sdhci_plat *plat = dev_get_platdata(dev); + struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); + struct sdhci_host *host = dev_get_priv(dev); + int ret; - /* build sdhci_host[] for each controller */ - for (i = 0; i < count; i++) { - node = node_list[i]; - if (node <= 0) - continue; + ret = sdhci_get_config(gd->fdt_blob, dev_of_offset(dev), host); + if (ret) + return ret; - host = &sdhci_host[i]; + ret = do_sdhci_init(host); + if (ret) + return ret; - ret = sdhci_get_config(blob, node, host); - if (ret) { - printf("%s: failed to decode dev %d (%d)\n", __func__, i, ret); - failed++; - continue; - } + ret = sdhci_setup_cfg(&plat->cfg, host, 0, 400000); + if (ret) + return ret; - ret = do_sdhci_init(host); - if (ret && ret != -ENODEV) { - printf("%s: failed to initialize dev %d (%d)\n", __func__, i, ret); - failed++; - } - } + host->mmc = &plat->mmc; + host->mmc->priv = host; + host->mmc->dev = dev; + upriv->mmc = host->mmc; - /* we only consider it an error when all nodes fail */ - return (failed == count ? -1 : 0); + return sdhci_probe(dev); } -int exynos_mmc_init(const void *blob) +static int s5p_sdhci_bind(struct udevice *dev) { - int count; - int node_list[SDHCI_MAX_HOSTS]; + struct s5p_sdhci_plat *plat = dev_get_platdata(dev); + int ret; - count = fdtdec_find_aliases_for_id(blob, "mmc", - COMPAT_SAMSUNG_EXYNOS_MMC, node_list, - SDHCI_MAX_HOSTS); + ret = sdhci_bind(dev, &plat->mmc, &plat->cfg); + if (ret) + return ret; - return process_nodes(blob, node_list, count); + return 0; } -#endif + +static const struct udevice_id s5p_sdhci_ids[] = { + { .compatible = "samsung,exynos4412-sdhci"}, + { } +}; + +U_BOOT_DRIVER(s5p_sdhci_drv) = { + .name = "s5p_sdhci", + .id = UCLASS_MMC, + .of_match = s5p_sdhci_ids, + .bind = s5p_sdhci_bind, + .ops = &sdhci_ops, + .probe = s5p_sdhci_probe, + .priv_auto_alloc_size = sizeof(struct sdhci_host), + .platdata_auto_alloc_size = sizeof(struct s5p_sdhci_plat), +}; +#endif /* CONFIG_DM_MMC */