Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Linaro |
| 4 | * peter.griffin <peter.griffin@linaro.org> |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 8 | #include <dm.h> |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 9 | #include <dwmmc.h> |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 10 | #include <errno.h> |
| 11 | #include <fdtdec.h> |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 12 | #include <malloc.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 14 | |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 16 | |
Manivannan Sadhasivam | 6240e64 | 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 | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 21 | |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 22 | struct hi6220_dwmmc_priv_data { |
| 23 | struct dwmci_host host; |
| 24 | }; |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 25 | |
Manivannan Sadhasivam | 122537e | 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 | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 31 | static int hi6220_dwmmc_of_to_plat(struct udevice *dev) |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 32 | { |
Manivannan Sadhasivam | 6240e64 | 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 | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 35 | |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 36 | host->name = dev->name; |
Masahiro Yamada | 8613c8d | 2020-07-17 14:36:46 +0900 | [diff] [blame] | 37 | host->ioaddr = dev_read_addr_ptr(dev); |
Manivannan Sadhasivam | 6240e64 | 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 | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 40 | |
Manivannan Sadhasivam | 6240e64 | 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 | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 49 | return 0; |
| 50 | } |
| 51 | |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 52 | static int hi6220_dwmmc_probe(struct udevice *dev) |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 53 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 54 | struct hi6220_dwmmc_plat *plat = dev_get_plat(dev); |
Manivannan Sadhasivam | 6240e64 | 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 | 122537e | 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); |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 61 | |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 62 | /* Use default bus speed due to absence of clk driver */ |
Manivannan Sadhasivam | 122537e | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 63 | host->bus_hz = mmc_data->clock; |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 64 | |
Manivannan Sadhasivam | 6240e64 | 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 | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 67 | |
Manivannan Sadhasivam | 122537e | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 68 | host->fifo_mode = mmc_data->use_fifo; |
Manivannan Sadhasivam | 6240e64 | 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; |
| 72 | |
| 73 | return dwmci_probe(dev); |
Peter Griffin | 447da58 | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 74 | } |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 75 | |
| 76 | static int hi6220_dwmmc_bind(struct udevice *dev) |
| 77 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 78 | struct hi6220_dwmmc_plat *plat = dev_get_plat(dev); |
Manivannan Sadhasivam | 6240e64 | 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 | 122537e | 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 | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 98 | static const struct udevice_id hi6220_dwmmc_ids[] = { |
Manivannan Sadhasivam | 122537e | 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 }, |
Yang Xiwen | 8a5dc81 | 2023-04-01 19:17:34 +0800 | [diff] [blame] | 103 | { .compatible = "hisilicon,hi3798mv200-dw-mshc", |
| 104 | .data = (ulong)&hi6220_mmc_data }, |
Manivannan Sadhasivam | 122537e | 2019-08-02 20:40:10 +0530 | [diff] [blame] | 105 | { .compatible = "hisilicon,hi3660-dw-mshc", |
| 106 | .data = (ulong)&hi3660_mmc_data }, |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 107 | { } |
| 108 | }; |
| 109 | |
| 110 | U_BOOT_DRIVER(hi6220_dwmmc_drv) = { |
| 111 | .name = "hi6220_dwmmc", |
| 112 | .id = UCLASS_MMC, |
| 113 | .of_match = hi6220_dwmmc_ids, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 114 | .of_to_plat = hi6220_dwmmc_of_to_plat, |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 115 | .ops = &dm_dwmci_ops, |
| 116 | .bind = hi6220_dwmmc_bind, |
| 117 | .probe = hi6220_dwmmc_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 118 | .priv_auto = sizeof(struct hi6220_dwmmc_priv_data), |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 119 | .plat_auto = sizeof(struct hi6220_dwmmc_plat), |
Manivannan Sadhasivam | 6240e64 | 2018-12-27 19:04:04 +0530 | [diff] [blame] | 120 | }; |