blob: effd1e4c7c849fa43095ebeb47c7ab0d305696b1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Griffin447da582015-07-30 18:55:22 +01002/*
3 * (C) Copyright 2015 Linaro
4 * peter.griffin <peter.griffin@linaro.org>
Peter Griffin447da582015-07-30 18:55:22 +01005 */
6
7#include <common.h>
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +05308#include <dm.h>
Peter Griffin447da582015-07-30 18:55:22 +01009#include <dwmmc.h>
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053010#include <errno.h>
11#include <fdtdec.h>
Peter Griffin447da582015-07-30 18:55:22 +010012#include <malloc.h>
Peter Griffin447da582015-07-30 18:55:22 +010013
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053014DECLARE_GLOBAL_DATA_PTR;
Peter Griffin447da582015-07-30 18:55:22 +010015
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053016struct hi6220_dwmmc_plat {
17 struct mmc_config cfg;
18 struct mmc mmc;
19};
Peter Griffin447da582015-07-30 18:55:22 +010020
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053021struct hi6220_dwmmc_priv_data {
22 struct dwmci_host host;
23};
Peter Griffin447da582015-07-30 18:55:22 +010024
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053025static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev)
Peter Griffin447da582015-07-30 18:55:22 +010026{
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053027 struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
28 struct dwmci_host *host = &priv->host;
Peter Griffin447da582015-07-30 18:55:22 +010029
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053030 host->name = dev->name;
31 host->ioaddr = (void *)devfdt_get_addr(dev);
32 host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
33 "bus-width", 4);
Peter Griffin447da582015-07-30 18:55:22 +010034
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053035 /* use non-removable property for differentiating SD card and eMMC */
36 if (dev_read_bool(dev, "non-removable"))
37 host->dev_index = 0;
38 else
39 host->dev_index = 1;
40
41 host->priv = priv;
42
Peter Griffin447da582015-07-30 18:55:22 +010043 return 0;
44}
45
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053046static int hi6220_dwmmc_probe(struct udevice *dev)
Peter Griffin447da582015-07-30 18:55:22 +010047{
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053048 struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev);
49 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
50 struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
51 struct dwmci_host *host = &priv->host;
Peter Griffin447da582015-07-30 18:55:22 +010052
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053053 /* Use default bus speed due to absence of clk driver */
54 host->bus_hz = 50000000;
Peter Griffin447da582015-07-30 18:55:22 +010055
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053056 dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
57 host->mmc = &plat->mmc;
Peter Griffin447da582015-07-30 18:55:22 +010058
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053059 host->mmc->priv = &priv->host;
60 upriv->mmc = host->mmc;
61 host->mmc->dev = dev;
62
63 return dwmci_probe(dev);
Peter Griffin447da582015-07-30 18:55:22 +010064}
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053065
66static int hi6220_dwmmc_bind(struct udevice *dev)
67{
68 struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev);
69 int ret;
70
71 ret = dwmci_bind(dev, &plat->mmc, &plat->cfg);
72 if (ret)
73 return ret;
74
75 return 0;
76}
77
78static const struct udevice_id hi6220_dwmmc_ids[] = {
79 { .compatible = "hisilicon,hi6220-dw-mshc" },
Shawn Guo94f139a2019-01-17 12:09:51 +080080 { .compatible = "hisilicon,hi3798cv200-dw-mshc" },
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053081 { }
82};
83
84U_BOOT_DRIVER(hi6220_dwmmc_drv) = {
85 .name = "hi6220_dwmmc",
86 .id = UCLASS_MMC,
87 .of_match = hi6220_dwmmc_ids,
88 .ofdata_to_platdata = hi6220_dwmmc_ofdata_to_platdata,
89 .ops = &dm_dwmci_ops,
90 .bind = hi6220_dwmmc_bind,
91 .probe = hi6220_dwmmc_probe,
92 .priv_auto_alloc_size = sizeof(struct hi6220_dwmmc_priv_data),
93 .platdata_auto_alloc_size = sizeof(struct hi6220_dwmmc_plat),
94};