1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Linaro
4 * peter.griffin <peter.griffin@linaro.org>
14 DECLARE_GLOBAL_DATA_PTR;
16 struct hi6220_dwmmc_plat {
17 struct mmc_config cfg;
21 struct hi6220_dwmmc_priv_data {
22 struct dwmci_host host;
25 struct hisi_mmc_data {
30 static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev)
32 struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
33 struct dwmci_host *host = &priv->host;
35 host->name = dev->name;
36 host->ioaddr = (void *)devfdt_get_addr(dev);
37 host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
40 /* use non-removable property for differentiating SD card and eMMC */
41 if (dev_read_bool(dev, "non-removable"))
51 static int hi6220_dwmmc_probe(struct udevice *dev)
53 struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev);
54 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
55 struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
56 struct dwmci_host *host = &priv->host;
57 struct hisi_mmc_data *mmc_data;
59 mmc_data = (struct hisi_mmc_data *)dev_get_driver_data(dev);
61 /* Use default bus speed due to absence of clk driver */
62 host->bus_hz = mmc_data->clock;
64 dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
65 host->mmc = &plat->mmc;
67 host->fifo_mode = mmc_data->use_fifo;
68 host->mmc->priv = &priv->host;
69 upriv->mmc = host->mmc;
72 return dwmci_probe(dev);
75 static int hi6220_dwmmc_bind(struct udevice *dev)
77 struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev);
80 ret = dwmci_bind(dev, &plat->mmc, &plat->cfg);
87 static const struct hisi_mmc_data hi3660_mmc_data = {
92 static const struct hisi_mmc_data hi6220_mmc_data = {
97 static const struct udevice_id hi6220_dwmmc_ids[] = {
98 { .compatible = "hisilicon,hi6220-dw-mshc",
99 .data = (ulong)&hi6220_mmc_data },
100 { .compatible = "hisilicon,hi3798cv200-dw-mshc",
101 .data = (ulong)&hi6220_mmc_data },
102 { .compatible = "hisilicon,hi3660-dw-mshc",
103 .data = (ulong)&hi3660_mmc_data },
107 U_BOOT_DRIVER(hi6220_dwmmc_drv) = {
108 .name = "hi6220_dwmmc",
110 .of_match = hi6220_dwmmc_ids,
111 .ofdata_to_platdata = hi6220_dwmmc_ofdata_to_platdata,
112 .ops = &dm_dwmci_ops,
113 .bind = hi6220_dwmmc_bind,
114 .probe = hi6220_dwmmc_probe,
115 .priv_auto_alloc_size = sizeof(struct hi6220_dwmmc_priv_data),
116 .platdata_auto_alloc_size = sizeof(struct hi6220_dwmmc_plat),