blob: cc58aff38cc415db07f6330111a040251a8c5ebc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Griffinaf0c1be2015-07-30 18:55:22 +01002/*
3 * (C) Copyright 2015 Linaro
4 * peter.griffin <peter.griffin@linaro.org>
Peter Griffinaf0c1be2015-07-30 18:55:22 +01005 */
6
7#include <common.h>
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +05308#include <dm.h>
Peter Griffinaf0c1be2015-07-30 18:55:22 +01009#include <dwmmc.h>
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053010#include <errno.h>
11#include <fdtdec.h>
Peter Griffinaf0c1be2015-07-30 18:55:22 +010012#include <malloc.h>
Peter Griffinaf0c1be2015-07-30 18:55:22 +010013
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053014DECLARE_GLOBAL_DATA_PTR;
Peter Griffinaf0c1be2015-07-30 18:55:22 +010015
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053016struct hi6220_dwmmc_plat {
17 struct mmc_config cfg;
18 struct mmc mmc;
19};
Peter Griffinaf0c1be2015-07-30 18:55:22 +010020
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053021struct hi6220_dwmmc_priv_data {
22 struct dwmci_host host;
23};
Peter Griffinaf0c1be2015-07-30 18:55:22 +010024
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053025static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev)
Peter Griffinaf0c1be2015-07-30 18:55:22 +010026{
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053027 struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
28 struct dwmci_host *host = &priv->host;
Peter Griffinaf0c1be2015-07-30 18:55:22 +010029
Manivannan Sadhasivam6ad4f8c2018-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 Griffinaf0c1be2015-07-30 18:55:22 +010034
Manivannan Sadhasivam6ad4f8c2018-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 Griffinaf0c1be2015-07-30 18:55:22 +010043 return 0;
44}
45
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053046static int hi6220_dwmmc_probe(struct udevice *dev)
Peter Griffinaf0c1be2015-07-30 18:55:22 +010047{
Manivannan Sadhasivam6ad4f8c2018-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;
52
53 /* Use default bus speed due to absence of clk driver */
54 host->bus_hz = 50000000;
Peter Griffinaf0c1be2015-07-30 18:55:22 +010055
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053056 dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
57 host->mmc = &plat->mmc;
Peter Griffinaf0c1be2015-07-30 18:55:22 +010058
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053059 host->mmc->priv = &priv->host;
60 upriv->mmc = host->mmc;
61 host->mmc->dev = dev;
Peter Griffinaf0c1be2015-07-30 18:55:22 +010062
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053063 return dwmci_probe(dev);
Peter Griffinaf0c1be2015-07-30 18:55:22 +010064}
Manivannan Sadhasivam6ad4f8c2018-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" },
80 { }
81};
82
83U_BOOT_DRIVER(hi6220_dwmmc_drv) = {
84 .name = "hi6220_dwmmc",
85 .id = UCLASS_MMC,
86 .of_match = hi6220_dwmmc_ids,
87 .ofdata_to_platdata = hi6220_dwmmc_ofdata_to_platdata,
88 .ops = &dm_dwmci_ops,
89 .bind = hi6220_dwmmc_bind,
90 .probe = hi6220_dwmmc_probe,
91 .priv_auto_alloc_size = sizeof(struct hi6220_dwmmc_priv_data),
92 .platdata_auto_alloc_size = sizeof(struct hi6220_dwmmc_plat),
93};