Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Linaro |
| 4 | * peter.griffin <peter.griffin@linaro.org> |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 8 | #include <dm.h> |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 9 | #include <dwmmc.h> |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 10 | #include <errno.h> |
| 11 | #include <fdtdec.h> |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 12 | #include <malloc.h> |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 13 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 15 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 16 | struct hi6220_dwmmc_plat { |
| 17 | struct mmc_config cfg; |
| 18 | struct mmc mmc; |
| 19 | }; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 20 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 21 | struct hi6220_dwmmc_priv_data { |
| 22 | struct dwmci_host host; |
| 23 | }; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 24 | |
Manivannan Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 25 | struct hisi_mmc_data { |
| 26 | unsigned int clock; |
| 27 | bool use_fifo; |
| 28 | }; |
| 29 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 30 | static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev) |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 31 | { |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 32 | struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev); |
| 33 | struct dwmci_host *host = &priv->host; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 34 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 35 | host->name = dev->name; |
Masahiro Yamada | 1096ae1 | 2020-07-17 14:36:46 +0900 | [diff] [blame] | 36 | host->ioaddr = dev_read_addr_ptr(dev); |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 37 | host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
| 38 | "bus-width", 4); |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 39 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 40 | /* 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 Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 51 | static int hi6220_dwmmc_probe(struct udevice *dev) |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 52 | { |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 53 | 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 Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 57 | struct hisi_mmc_data *mmc_data; |
| 58 | |
| 59 | mmc_data = (struct hisi_mmc_data *)dev_get_driver_data(dev); |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 60 | |
| 61 | /* Use default bus speed due to absence of clk driver */ |
Manivannan Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 62 | host->bus_hz = mmc_data->clock; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 63 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 64 | dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000); |
| 65 | host->mmc = &plat->mmc; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 66 | |
Manivannan Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 67 | host->fifo_mode = mmc_data->use_fifo; |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 68 | host->mmc->priv = &priv->host; |
| 69 | upriv->mmc = host->mmc; |
| 70 | host->mmc->dev = dev; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 71 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 72 | return dwmci_probe(dev); |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 73 | } |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 74 | |
| 75 | static 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 Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 87 | static const struct hisi_mmc_data hi3660_mmc_data = { |
| 88 | .clock = 3200000, |
| 89 | .use_fifo = true, |
| 90 | }; |
| 91 | |
| 92 | static const struct hisi_mmc_data hi6220_mmc_data = { |
| 93 | .clock = 50000000, |
| 94 | .use_fifo = false, |
| 95 | }; |
| 96 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 97 | static const struct udevice_id hi6220_dwmmc_ids[] = { |
Manivannan Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 98 | { .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 Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 104 | { } |
| 105 | }; |
| 106 | |
| 107 | U_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 | }; |