blob: 67d6a05b3b5b2ad9c31b2c8c29aac24d8c9f227d [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 Sadhasivam122537e2019-08-02 20:40:10 +053025struct hisi_mmc_data {
26 unsigned int clock;
27 bool use_fifo;
28};
29
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053030static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev)
Peter Griffin447da582015-07-30 18:55:22 +010031{
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053032 struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
33 struct dwmci_host *host = &priv->host;
Peter Griffin447da582015-07-30 18:55:22 +010034
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053035 host->name = dev->name;
Masahiro Yamada8613c8d2020-07-17 14:36:46 +090036 host->ioaddr = dev_read_addr_ptr(dev);
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053037 host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
38 "bus-width", 4);
Peter Griffin447da582015-07-30 18:55:22 +010039
Manivannan Sadhasivam6240e642018-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 Griffin447da582015-07-30 18:55:22 +010048 return 0;
49}
50
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053051static int hi6220_dwmmc_probe(struct udevice *dev)
Peter Griffin447da582015-07-30 18:55:22 +010052{
Manivannan Sadhasivam6240e642018-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 Sadhasivam122537e2019-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);
Peter Griffin447da582015-07-30 18:55:22 +010060
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053061 /* Use default bus speed due to absence of clk driver */
Manivannan Sadhasivam122537e2019-08-02 20:40:10 +053062 host->bus_hz = mmc_data->clock;
Peter Griffin447da582015-07-30 18:55:22 +010063
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053064 dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
65 host->mmc = &plat->mmc;
Peter Griffin447da582015-07-30 18:55:22 +010066
Manivannan Sadhasivam122537e2019-08-02 20:40:10 +053067 host->fifo_mode = mmc_data->use_fifo;
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053068 host->mmc->priv = &priv->host;
69 upriv->mmc = host->mmc;
70 host->mmc->dev = dev;
71
72 return dwmci_probe(dev);
Peter Griffin447da582015-07-30 18:55:22 +010073}
Manivannan Sadhasivam6240e642018-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 Sadhasivam122537e2019-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 Sadhasivam6240e642018-12-27 19:04:04 +053097static const struct udevice_id hi6220_dwmmc_ids[] = {
Manivannan Sadhasivam122537e2019-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 Sadhasivam6240e642018-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};