]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/mmc/sti_sdhci.c
SPDX: Convert all of our single license tags to Linux Kernel style
[thirdparty/u-boot.git] / drivers / mmc / sti_sdhci.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
eee20f81 2/*
fb48bc44
PC
3 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
eee20f81
PC
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <mmc.h>
dca3166f 10#include <reset-uclass.h>
eee20f81
PC
11#include <sdhci.h>
12#include <asm/arch/sdhci.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16struct sti_sdhci_plat {
17 struct mmc_config cfg;
18 struct mmc mmc;
dca3166f 19 struct reset_ctl reset;
819c626b 20 int instance;
eee20f81
PC
21};
22
eee20f81
PC
23/**
24 * sti_mmc_core_config: configure the Arasan HC
819c626b
PC
25 * @dev : udevice
26 *
eee20f81
PC
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.
34 */
dca3166f 35static int sti_mmc_core_config(struct udevice *dev)
eee20f81 36{
819c626b
PC
37 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
38 struct sdhci_host *host = dev_get_priv(dev);
dca3166f 39 int ret;
eee20f81
PC
40
41 /* only MMC1 has a reset line */
819c626b 42 if (plat->instance) {
dca3166f
PC
43 ret = reset_deassert(&plat->reset);
44 if (ret < 0) {
9b643e31 45 pr_err("MMC1 deassert failed: %d", ret);
dca3166f
PC
46 return ret;
47 }
eee20f81
PC
48 }
49
50 writel(STI_FLASHSS_MMC_CORE_CONFIG_1,
819c626b 51 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_1);
eee20f81 52
819c626b 53 if (plat->instance) {
eee20f81 54 writel(STI_FLASHSS_MMC_CORE_CONFIG2,
819c626b 55 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
eee20f81 56 writel(STI_FLASHSS_MMC_CORE_CONFIG3,
819c626b 57 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
eee20f81
PC
58 } else {
59 writel(STI_FLASHSS_SDCARD_CORE_CONFIG2,
819c626b 60 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
eee20f81 61 writel(STI_FLASHSS_SDCARD_CORE_CONFIG3,
819c626b 62 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
eee20f81
PC
63 }
64 writel(STI_FLASHSS_MMC_CORE_CONFIG4,
819c626b 65 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_4);
dca3166f
PC
66
67 return 0;
eee20f81
PC
68}
69
70static int sti_sdhci_probe(struct udevice *dev)
71{
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);
819c626b 75 int ret;
eee20f81
PC
76
77 /*
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
81 */
dca3166f
PC
82 ret = reset_get_by_index(dev, 0, &plat->reset);
83 if (!ret)
819c626b 84 plat->instance = 1;
eee20f81 85 else
dca3166f
PC
86 if (ret == -ENOENT)
87 plat->instance = 0;
88 else
89 return ret;
eee20f81 90
dca3166f
PC
91 ret = sti_mmc_core_config(dev);
92 if (ret)
93 return ret;
eee20f81
PC
94
95 host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
96 SDHCI_QUIRK_32BIT_DMA_ADDR |
97 SDHCI_QUIRK_NO_HISPD_BIT;
98
99 host->host_caps = MMC_MODE_DDR_52MHz;
100
101 ret = sdhci_setup_cfg(&plat->cfg, host, 50000000, 400000);
102 if (ret)
103 return ret;
104
105 host->mmc = &plat->mmc;
106 host->mmc->priv = host;
107 host->mmc->dev = dev;
108 upriv->mmc = host->mmc;
109
110 return sdhci_probe(dev);
111}
112
113static int sti_sdhci_ofdata_to_platdata(struct udevice *dev)
114{
115 struct sdhci_host *host = dev_get_priv(dev);
116
117 host->name = strdup(dev->name);
a821c4af 118 host->ioaddr = (void *)devfdt_get_addr(dev);
eee20f81
PC
119
120 host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
121 "bus-width", 4);
122
123 return 0;
124}
125
126static int sti_sdhci_bind(struct udevice *dev)
127{
128 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
129
130 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
131}
132
133static const struct udevice_id sti_sdhci_ids[] = {
134 { .compatible = "st,sdhci" },
135 { }
136};
137
138U_BOOT_DRIVER(sti_mmc) = {
139 .name = "sti_sdhci",
140 .id = UCLASS_MMC,
141 .of_match = sti_sdhci_ids,
142 .bind = sti_sdhci_bind,
143 .ops = &sdhci_ops,
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),
148};