blob: 71962cd47e03d4cc9e9670e4424af31008c741b7 [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>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Peter Griffin447da582015-07-30 18:55:22 +010014
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053015DECLARE_GLOBAL_DATA_PTR;
Peter Griffin447da582015-07-30 18:55:22 +010016
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053017struct hi6220_dwmmc_plat {
18 struct mmc_config cfg;
19 struct mmc mmc;
20};
Peter Griffin447da582015-07-30 18:55:22 +010021
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053022struct hi6220_dwmmc_priv_data {
23 struct dwmci_host host;
24};
Peter Griffin447da582015-07-30 18:55:22 +010025
Manivannan Sadhasivam122537e2019-08-02 20:40:10 +053026struct hisi_mmc_data {
27 unsigned int clock;
28 bool use_fifo;
29};
30
Simon Glassd1998a92020-12-03 16:55:21 -070031static int hi6220_dwmmc_of_to_plat(struct udevice *dev)
Peter Griffin447da582015-07-30 18:55:22 +010032{
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053033 struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
34 struct dwmci_host *host = &priv->host;
Peter Griffin447da582015-07-30 18:55:22 +010035
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053036 host->name = dev->name;
Masahiro Yamada8613c8d2020-07-17 14:36:46 +090037 host->ioaddr = dev_read_addr_ptr(dev);
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053038 host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
39 "bus-width", 4);
Peter Griffin447da582015-07-30 18:55:22 +010040
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053041 /* use non-removable property for differentiating SD card and eMMC */
42 if (dev_read_bool(dev, "non-removable"))
43 host->dev_index = 0;
44 else
45 host->dev_index = 1;
46
47 host->priv = priv;
48
Peter Griffin447da582015-07-30 18:55:22 +010049 return 0;
50}
51
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053052static int hi6220_dwmmc_probe(struct udevice *dev)
Peter Griffin447da582015-07-30 18:55:22 +010053{
Simon Glassc69cda22020-12-03 16:55:20 -070054 struct hi6220_dwmmc_plat *plat = dev_get_plat(dev);
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053055 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
56 struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
57 struct dwmci_host *host = &priv->host;
Manivannan Sadhasivam122537e2019-08-02 20:40:10 +053058 struct hisi_mmc_data *mmc_data;
59
60 mmc_data = (struct hisi_mmc_data *)dev_get_driver_data(dev);
Peter Griffin447da582015-07-30 18:55:22 +010061
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053062 /* Use default bus speed due to absence of clk driver */
Manivannan Sadhasivam122537e2019-08-02 20:40:10 +053063 host->bus_hz = mmc_data->clock;
Peter Griffin447da582015-07-30 18:55:22 +010064
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053065 dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
66 host->mmc = &plat->mmc;
Peter Griffin447da582015-07-30 18:55:22 +010067
Manivannan Sadhasivam122537e2019-08-02 20:40:10 +053068 host->fifo_mode = mmc_data->use_fifo;
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053069 host->mmc->priv = &priv->host;
70 upriv->mmc = host->mmc;
71 host->mmc->dev = dev;
72
73 return dwmci_probe(dev);
Peter Griffin447da582015-07-30 18:55:22 +010074}
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053075
76static int hi6220_dwmmc_bind(struct udevice *dev)
77{
Simon Glassc69cda22020-12-03 16:55:20 -070078 struct hi6220_dwmmc_plat *plat = dev_get_plat(dev);
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053079 int ret;
80
81 ret = dwmci_bind(dev, &plat->mmc, &plat->cfg);
82 if (ret)
83 return ret;
84
85 return 0;
86}
87
Manivannan Sadhasivam122537e2019-08-02 20:40:10 +053088static const struct hisi_mmc_data hi3660_mmc_data = {
89 .clock = 3200000,
90 .use_fifo = true,
91};
92
93static const struct hisi_mmc_data hi6220_mmc_data = {
94 .clock = 50000000,
95 .use_fifo = false,
96};
97
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +053098static const struct udevice_id hi6220_dwmmc_ids[] = {
Manivannan Sadhasivam122537e2019-08-02 20:40:10 +053099 { .compatible = "hisilicon,hi6220-dw-mshc",
100 .data = (ulong)&hi6220_mmc_data },
101 { .compatible = "hisilicon,hi3798cv200-dw-mshc",
102 .data = (ulong)&hi6220_mmc_data },
Yang Xiwen8a5dc812023-04-01 19:17:34 +0800103 { .compatible = "hisilicon,hi3798mv200-dw-mshc",
104 .data = (ulong)&hi6220_mmc_data },
Manivannan Sadhasivam122537e2019-08-02 20:40:10 +0530105 { .compatible = "hisilicon,hi3660-dw-mshc",
106 .data = (ulong)&hi3660_mmc_data },
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +0530107 { }
108};
109
110U_BOOT_DRIVER(hi6220_dwmmc_drv) = {
111 .name = "hi6220_dwmmc",
112 .id = UCLASS_MMC,
113 .of_match = hi6220_dwmmc_ids,
Simon Glassd1998a92020-12-03 16:55:21 -0700114 .of_to_plat = hi6220_dwmmc_of_to_plat,
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +0530115 .ops = &dm_dwmci_ops,
116 .bind = hi6220_dwmmc_bind,
117 .probe = hi6220_dwmmc_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700118 .priv_auto = sizeof(struct hi6220_dwmmc_priv_data),
Simon Glasscaa4daa2020-12-03 16:55:18 -0700119 .plat_auto = sizeof(struct hi6220_dwmmc_plat),
Manivannan Sadhasivam6240e642018-12-27 19:04:04 +0530120};