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> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 14 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 16 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 17 | struct hi6220_dwmmc_plat { |
| 18 | struct mmc_config cfg; |
| 19 | struct mmc mmc; |
| 20 | }; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 21 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 22 | struct hi6220_dwmmc_priv_data { |
| 23 | struct dwmci_host host; |
| 24 | }; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 25 | |
Manivannan Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 26 | struct hisi_mmc_data { |
| 27 | unsigned int clock; |
| 28 | bool use_fifo; |
| 29 | }; |
| 30 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 31 | static int hi6220_dwmmc_of_to_plat(struct udevice *dev) |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 32 | { |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 33 | struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev); |
| 34 | struct dwmci_host *host = &priv->host; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 35 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 36 | host->name = dev->name; |
Masahiro Yamada | 1096ae1 | 2020-07-17 14:36:46 +0900 | [diff] [blame] | 37 | host->ioaddr = dev_read_addr_ptr(dev); |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 38 | host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
| 39 | "bus-width", 4); |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 40 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 41 | /* 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 Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 49 | return 0; |
| 50 | } |
| 51 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 52 | static int hi6220_dwmmc_probe(struct udevice *dev) |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 53 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 54 | struct hi6220_dwmmc_plat *plat = dev_get_plat(dev); |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 55 | 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 Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 58 | struct hisi_mmc_data *mmc_data; |
| 59 | |
| 60 | mmc_data = (struct hisi_mmc_data *)dev_get_driver_data(dev); |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 61 | |
| 62 | /* Use default bus speed due to absence of clk driver */ |
Manivannan Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 63 | host->bus_hz = mmc_data->clock; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 64 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 65 | dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000); |
| 66 | host->mmc = &plat->mmc; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 67 | |
Manivannan Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 68 | host->fifo_mode = mmc_data->use_fifo; |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 69 | host->mmc->priv = &priv->host; |
| 70 | upriv->mmc = host->mmc; |
| 71 | host->mmc->dev = dev; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 72 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 73 | return dwmci_probe(dev); |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 74 | } |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 75 | |
| 76 | static int hi6220_dwmmc_bind(struct udevice *dev) |
| 77 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 78 | struct hi6220_dwmmc_plat *plat = dev_get_plat(dev); |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 79 | 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 Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 88 | static const struct hisi_mmc_data hi3660_mmc_data = { |
| 89 | .clock = 3200000, |
| 90 | .use_fifo = true, |
| 91 | }; |
| 92 | |
| 93 | static const struct hisi_mmc_data hi6220_mmc_data = { |
| 94 | .clock = 50000000, |
| 95 | .use_fifo = false, |
| 96 | }; |
| 97 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 98 | static const struct udevice_id hi6220_dwmmc_ids[] = { |
Manivannan Sadhasivam | 759c45a | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 99 | { .compatible = "hisilicon,hi6220-dw-mshc", |
| 100 | .data = (ulong)&hi6220_mmc_data }, |
| 101 | { .compatible = "hisilicon,hi3798cv200-dw-mshc", |
| 102 | .data = (ulong)&hi6220_mmc_data }, |
| 103 | { .compatible = "hisilicon,hi3660-dw-mshc", |
| 104 | .data = (ulong)&hi3660_mmc_data }, |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 105 | { } |
| 106 | }; |
| 107 | |
| 108 | U_BOOT_DRIVER(hi6220_dwmmc_drv) = { |
| 109 | .name = "hi6220_dwmmc", |
| 110 | .id = UCLASS_MMC, |
| 111 | .of_match = hi6220_dwmmc_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 112 | .of_to_plat = hi6220_dwmmc_of_to_plat, |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 113 | .ops = &dm_dwmci_ops, |
| 114 | .bind = hi6220_dwmmc_bind, |
| 115 | .probe = hi6220_dwmmc_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 116 | .priv_auto = sizeof(struct hi6220_dwmmc_priv_data), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 117 | .plat_auto = sizeof(struct hi6220_dwmmc_plat), |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 118 | }; |