2 * (C) Copyright 2016 Fuzhou Rockchip Electronics Co., Ltd
4 * Rockchip SD Host Controller Interface
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <dt-structs.h>
12 #include <linux/libfdt.h>
18 DECLARE_GLOBAL_DATA_PTR;
19 /* 400KHz is max freq for card ID etc. Use that as min */
20 #define EMMC_MIN_FREQ 400000
22 struct rockchip_sdhc_plat {
23 #if CONFIG_IS_ENABLED(OF_PLATDATA)
24 struct dtd_rockchip_rk3399_sdhci_5_1 dtplat;
26 struct mmc_config cfg;
30 struct rockchip_sdhc {
31 struct sdhci_host host;
35 static int arasan_sdhci_probe(struct udevice *dev)
37 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
38 struct rockchip_sdhc_plat *plat = dev_get_platdata(dev);
39 struct rockchip_sdhc *prv = dev_get_priv(dev);
40 struct sdhci_host *host = &prv->host;
41 int max_frequency, ret;
44 #if CONFIG_IS_ENABLED(OF_PLATDATA)
45 struct dtd_rockchip_rk3399_sdhci_5_1 *dtplat = &plat->dtplat;
47 host->name = dev->name;
48 host->ioaddr = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
49 max_frequency = dtplat->max_frequency;
50 ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &clk);
52 max_frequency = dev_read_u32_default(dev, "max-frequency", 0);
53 ret = clk_get_by_index(dev, 0, &clk);
56 ret = clk_set_rate(&clk, max_frequency);
57 if (IS_ERR_VALUE(ret))
58 printf("%s clk set rate fail!\n", __func__);
60 printf("%s fail to get clk\n", __func__);
63 host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD;
64 host->max_clk = max_frequency;
66 * The sdhci-driver only supports 4bit and 8bit, as sdhci_setup_cfg
67 * doesn't allow us to clear MMC_MODE_4BIT. Consequently, we don't
68 * check for other bus-width values.
70 if (host->bus_width == 8)
71 host->host_caps |= MMC_MODE_8BIT;
73 ret = sdhci_setup_cfg(&plat->cfg, host, 0, EMMC_MIN_FREQ);
75 host->mmc = &plat->mmc;
78 host->mmc->priv = &prv->host;
80 upriv->mmc = host->mmc;
82 return sdhci_probe(dev);
85 static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
87 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
88 struct sdhci_host *host = dev_get_priv(dev);
90 host->name = dev->name;
91 host->ioaddr = dev_read_addr_ptr(dev);
92 host->bus_width = dev_read_u32_default(dev, "bus-width", 4);
98 static int rockchip_sdhci_bind(struct udevice *dev)
100 struct rockchip_sdhc_plat *plat = dev_get_platdata(dev);
102 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
105 static const struct udevice_id arasan_sdhci_ids[] = {
106 { .compatible = "arasan,sdhci-5.1" },
110 U_BOOT_DRIVER(arasan_sdhci_drv) = {
111 .name = "rockchip_rk3399_sdhci_5_1",
113 .of_match = arasan_sdhci_ids,
114 .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata,
116 .bind = rockchip_sdhci_bind,
117 .probe = arasan_sdhci_probe,
118 .priv_auto_alloc_size = sizeof(struct rockchip_sdhc),
119 .platdata_auto_alloc_size = sizeof(struct rockchip_sdhc_plat),