1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
10 #include <reset-uclass.h>
12 #include <asm/arch/sdhci.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 struct sti_sdhci_plat {
17 struct mmc_config cfg;
19 struct reset_ctl reset;
24 * sti_mmc_core_config: configure the Arasan HC
27 * Description: this function is to configure the Arasan MMC HC.
28 * This should be called when the system starts in case of, on the SoC,
29 * it is needed to configure the host controller.
30 * This happens on some SoCs, i.e. StiH410, where the MMC0 inside the flashSS
31 * needs to be configured as MMC 4.5 to have full capabilities.
32 * W/o these settings the SDHCI could configure and use the embedded controller
33 * with limited features.
35 static int sti_mmc_core_config(struct udevice *dev)
37 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
38 struct sdhci_host *host = dev_get_priv(dev);
41 /* only MMC1 has a reset line */
43 ret = reset_deassert(&plat->reset);
45 pr_err("MMC1 deassert failed: %d", ret);
50 writel(STI_FLASHSS_MMC_CORE_CONFIG_1,
51 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_1);
54 writel(STI_FLASHSS_MMC_CORE_CONFIG2,
55 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
56 writel(STI_FLASHSS_MMC_CORE_CONFIG3,
57 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
59 writel(STI_FLASHSS_SDCARD_CORE_CONFIG2,
60 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
61 writel(STI_FLASHSS_SDCARD_CORE_CONFIG3,
62 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
64 writel(STI_FLASHSS_MMC_CORE_CONFIG4,
65 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_4);
70 static int sti_sdhci_probe(struct udevice *dev)
72 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
73 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
74 struct sdhci_host *host = dev_get_priv(dev);
78 * identify current mmc instance, mmc1 has a reset, not mmc0
79 * MMC0 is wired to the SD slot,
80 * MMC1 is wired on the high speed connector
82 ret = reset_get_by_index(dev, 0, &plat->reset);
91 ret = sti_mmc_core_config(dev);
95 host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
96 SDHCI_QUIRK_32BIT_DMA_ADDR |
97 SDHCI_QUIRK_NO_HISPD_BIT;
99 host->host_caps = MMC_MODE_DDR_52MHz;
100 host->mmc = &plat->mmc;
101 host->mmc->dev = dev;
102 host->mmc->priv = host;
104 ret = sdhci_setup_cfg(&plat->cfg, host, 50000000, 400000);
108 upriv->mmc = host->mmc;
110 return sdhci_probe(dev);
113 static int sti_sdhci_ofdata_to_platdata(struct udevice *dev)
115 struct sdhci_host *host = dev_get_priv(dev);
117 host->name = strdup(dev->name);
118 host->ioaddr = (void *)devfdt_get_addr(dev);
120 host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
126 static int sti_sdhci_bind(struct udevice *dev)
128 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
130 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
133 static const struct udevice_id sti_sdhci_ids[] = {
134 { .compatible = "st,sdhci" },
138 U_BOOT_DRIVER(sti_mmc) = {
141 .of_match = sti_sdhci_ids,
142 .bind = sti_sdhci_bind,
144 .ofdata_to_platdata = sti_sdhci_ofdata_to_platdata,
145 .probe = sti_sdhci_probe,
146 .priv_auto_alloc_size = sizeof(struct sdhci_host),
147 .platdata_auto_alloc_size = sizeof(struct sti_sdhci_plat),