pinctrl: imx8m: support i.MX8MP
[oweals/u-boot.git] / drivers / mmc / hi6220_dw_mmc.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2015 Linaro
4  * peter.griffin <peter.griffin@linaro.org>
5  */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <dwmmc.h>
10 #include <errno.h>
11 #include <fdtdec.h>
12 #include <malloc.h>
13
14 DECLARE_GLOBAL_DATA_PTR;
15
16 struct hi6220_dwmmc_plat {
17         struct mmc_config cfg;
18         struct mmc mmc;
19 };
20
21 struct hi6220_dwmmc_priv_data {
22         struct dwmci_host host;
23 };
24
25 struct hisi_mmc_data {
26         unsigned int clock;
27         bool use_fifo;
28 };
29
30 static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev)
31 {
32         struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
33         struct dwmci_host *host = &priv->host;
34
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),
38                                         "bus-width", 4);
39
40         /* use non-removable property for differentiating SD card and eMMC */
41         if (dev_read_bool(dev, "non-removable"))
42                 host->dev_index = 0;
43         else
44                 host->dev_index = 1;
45
46         host->priv = priv;
47
48         return 0;
49 }
50
51 static int hi6220_dwmmc_probe(struct udevice *dev)
52 {
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;
58
59         mmc_data = (struct hisi_mmc_data *)dev_get_driver_data(dev);
60
61         /* Use default bus speed due to absence of clk driver */
62         host->bus_hz = mmc_data->clock;
63
64         dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
65         host->mmc = &plat->mmc;
66
67         host->fifo_mode = mmc_data->use_fifo;
68         host->mmc->priv = &priv->host;
69         upriv->mmc = host->mmc;
70         host->mmc->dev = dev;
71
72         return dwmci_probe(dev);
73 }
74
75 static int hi6220_dwmmc_bind(struct udevice *dev)
76 {
77         struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev);
78         int ret;
79
80         ret = dwmci_bind(dev, &plat->mmc, &plat->cfg);
81         if (ret)
82                 return ret;
83
84         return 0;
85 }
86
87 static const struct hisi_mmc_data hi3660_mmc_data = {
88         .clock = 3200000,
89         .use_fifo = true,
90 };
91
92 static const struct hisi_mmc_data hi6220_mmc_data = {
93         .clock = 50000000,
94         .use_fifo = false,
95 };
96
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 },
104         { }
105 };
106
107 U_BOOT_DRIVER(hi6220_dwmmc_drv) = {
108         .name = "hi6220_dwmmc",
109         .id = UCLASS_MMC,
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),
117 };