blob: 6de7924383594f72679c9b16c85eaf78c88e21b7 [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 Sadhasivam759c45a2019-08-02 20:40:10 +053025struct hisi_mmc_data {
26 unsigned int clock;
27 bool use_fifo;
28};
29
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053030static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev)
Peter Griffinaf0c1be2015-07-30 18:55:22 +010031{
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053032 struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
33 struct dwmci_host *host = &priv->host;
Peter Griffinaf0c1be2015-07-30 18:55:22 +010034
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053035 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);
Peter Griffinaf0c1be2015-07-30 18:55:22 +010039
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053040 /* 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
Peter Griffinaf0c1be2015-07-30 18:55:22 +010048 return 0;
49}
50
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053051static int hi6220_dwmmc_probe(struct udevice *dev)
Peter Griffinaf0c1be2015-07-30 18:55:22 +010052{
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053053 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;
Manivannan Sadhasivam759c45a2019-08-02 20:40:10 +053057 struct hisi_mmc_data *mmc_data;
58
59 mmc_data = (struct hisi_mmc_data *)dev_get_driver_data(dev);
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053060
61 /* Use default bus speed due to absence of clk driver */
Manivannan Sadhasivam759c45a2019-08-02 20:40:10 +053062 host->bus_hz = mmc_data->clock;
Peter Griffinaf0c1be2015-07-30 18:55:22 +010063
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053064 dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
65 host->mmc = &plat->mmc;
Peter Griffinaf0c1be2015-07-30 18:55:22 +010066
Manivannan Sadhasivam759c45a2019-08-02 20:40:10 +053067 host->fifo_mode = mmc_data->use_fifo;
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053068 host->mmc->priv = &priv->host;
69 upriv->mmc = host->mmc;
70 host->mmc->dev = dev;
Peter Griffinaf0c1be2015-07-30 18:55:22 +010071
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053072 return dwmci_probe(dev);
Peter Griffinaf0c1be2015-07-30 18:55:22 +010073}
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053074
75static 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
Manivannan Sadhasivam759c45a2019-08-02 20:40:10 +053087static const struct hisi_mmc_data hi3660_mmc_data = {
88 .clock = 3200000,
89 .use_fifo = true,
90};
91
92static const struct hisi_mmc_data hi6220_mmc_data = {
93 .clock = 50000000,
94 .use_fifo = false,
95};
96
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +053097static const struct udevice_id hi6220_dwmmc_ids[] = {
Manivannan Sadhasivam759c45a2019-08-02 20:40:10 +053098 { .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 },
Manivannan Sadhasivam6ad4f8c2018-12-27 19:04:04 +0530104 { }
105};
106
107U_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};