3 * Patrice Chotard <patrice.chotard@st.com>
5 * SPDX-License-Identifier: GPL-2.0
12 #include <asm/arch/sdhci.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 struct sti_sdhci_plat {
17 struct mmc_config cfg;
22 * used to get access to MMC1 reset,
23 * will be removed when STi reset driver will be available
25 #define STIH410_SYSCONF5_BASE 0x092b0000
28 * sti_mmc_core_config: configure the Arasan HC
29 * @regbase: base address
30 * @mmc_instance: mmc instance id
31 * Description: this function is to configure the Arasan MMC HC.
32 * This should be called when the system starts in case of, on the SoC,
33 * it is needed to configure the host controller.
34 * This happens on some SoCs, i.e. StiH410, where the MMC0 inside the flashSS
35 * needs to be configured as MMC 4.5 to have full capabilities.
36 * W/o these settings the SDHCI could configure and use the embedded controller
37 * with limited features.
39 static void sti_mmc_core_config(const u32 regbase, int mmc_instance)
41 unsigned long *sysconf;
43 /* only MMC1 has a reset line */
45 sysconf = (unsigned long *)(STIH410_SYSCONF5_BASE +
46 ST_MMC_CCONFIG_REG_5);
47 generic_set_bit(SYSCONF_MMC1_ENABLE_BIT, sysconf);
50 writel(STI_FLASHSS_MMC_CORE_CONFIG_1,
51 regbase + FLASHSS_MMC_CORE_CONFIG_1);
54 writel(STI_FLASHSS_MMC_CORE_CONFIG2,
55 regbase + FLASHSS_MMC_CORE_CONFIG_2);
56 writel(STI_FLASHSS_MMC_CORE_CONFIG3,
57 regbase + FLASHSS_MMC_CORE_CONFIG_3);
59 writel(STI_FLASHSS_SDCARD_CORE_CONFIG2,
60 regbase + FLASHSS_MMC_CORE_CONFIG_2);
61 writel(STI_FLASHSS_SDCARD_CORE_CONFIG3,
62 regbase + FLASHSS_MMC_CORE_CONFIG_3);
64 writel(STI_FLASHSS_MMC_CORE_CONFIG4,
65 regbase + FLASHSS_MMC_CORE_CONFIG_4);
68 static int sti_sdhci_probe(struct udevice *dev)
70 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
71 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
72 struct sdhci_host *host = dev_get_priv(dev);
73 int ret, mmc_instance;
76 * identify current mmc instance, mmc1 has a reset, not mmc0
77 * MMC0 is wired to the SD slot,
78 * MMC1 is wired on the high speed connector
81 if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "resets", NULL))
86 sti_mmc_core_config((const u32) host->ioaddr, mmc_instance);
88 host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
89 SDHCI_QUIRK_32BIT_DMA_ADDR |
90 SDHCI_QUIRK_NO_HISPD_BIT;
92 host->host_caps = MMC_MODE_DDR_52MHz;
94 ret = sdhci_setup_cfg(&plat->cfg, host, 50000000, 400000);
98 host->mmc = &plat->mmc;
99 host->mmc->priv = host;
100 host->mmc->dev = dev;
101 upriv->mmc = host->mmc;
103 return sdhci_probe(dev);
106 static int sti_sdhci_ofdata_to_platdata(struct udevice *dev)
108 struct sdhci_host *host = dev_get_priv(dev);
110 host->name = strdup(dev->name);
111 host->ioaddr = (void *)dev_get_addr(dev);
113 host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
119 static int sti_sdhci_bind(struct udevice *dev)
121 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
123 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
126 static const struct udevice_id sti_sdhci_ids[] = {
127 { .compatible = "st,sdhci" },
131 U_BOOT_DRIVER(sti_mmc) = {
134 .of_match = sti_sdhci_ids,
135 .bind = sti_sdhci_bind,
137 .ofdata_to_platdata = sti_sdhci_ofdata_to_platdata,
138 .probe = sti_sdhci_probe,
139 .priv_auto_alloc_size = sizeof(struct sdhci_host),
140 .platdata_auto_alloc_size = sizeof(struct sti_sdhci_plat),