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 | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame^] | 25 | static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev) |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 26 | { |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame^] | 27 | struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev); |
| 28 | struct dwmci_host *host = &priv->host; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 29 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame^] | 30 | host->name = dev->name; |
| 31 | host->ioaddr = (void *)devfdt_get_addr(dev); |
| 32 | host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
| 33 | "bus-width", 4); |
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 | /* use non-removable property for differentiating SD card and eMMC */ |
| 36 | if (dev_read_bool(dev, "non-removable")) |
| 37 | host->dev_index = 0; |
| 38 | else |
| 39 | host->dev_index = 1; |
| 40 | |
| 41 | host->priv = priv; |
| 42 | |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 43 | return 0; |
| 44 | } |
| 45 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame^] | 46 | static int hi6220_dwmmc_probe(struct udevice *dev) |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 47 | { |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame^] | 48 | struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev); |
| 49 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 50 | struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev); |
| 51 | struct dwmci_host *host = &priv->host; |
| 52 | |
| 53 | /* Use default bus speed due to absence of clk driver */ |
| 54 | host->bus_hz = 50000000; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 55 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame^] | 56 | dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000); |
| 57 | host->mmc = &plat->mmc; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 58 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame^] | 59 | host->mmc->priv = &priv->host; |
| 60 | upriv->mmc = host->mmc; |
| 61 | host->mmc->dev = dev; |
Peter Griffin | af0c1be | 2015-07-30 18:55:22 +0100 | [diff] [blame] | 62 | |
Manivannan Sadhasivam | 6ad4f8c | 2018-12-27 19:04:04 +0530 | [diff] [blame^] | 63 | return dwmci_probe(dev); |
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 | |
| 66 | static int hi6220_dwmmc_bind(struct udevice *dev) |
| 67 | { |
| 68 | struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev); |
| 69 | int ret; |
| 70 | |
| 71 | ret = dwmci_bind(dev, &plat->mmc, &plat->cfg); |
| 72 | if (ret) |
| 73 | return ret; |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static const struct udevice_id hi6220_dwmmc_ids[] = { |
| 79 | { .compatible = "hisilicon,hi6220-dw-mshc" }, |
| 80 | { } |
| 81 | }; |
| 82 | |
| 83 | U_BOOT_DRIVER(hi6220_dwmmc_drv) = { |
| 84 | .name = "hi6220_dwmmc", |
| 85 | .id = UCLASS_MMC, |
| 86 | .of_match = hi6220_dwmmc_ids, |
| 87 | .ofdata_to_platdata = hi6220_dwmmc_ofdata_to_platdata, |
| 88 | .ops = &dm_dwmci_ops, |
| 89 | .bind = hi6220_dwmmc_bind, |
| 90 | .probe = hi6220_dwmmc_probe, |
| 91 | .priv_auto_alloc_size = sizeof(struct hi6220_dwmmc_priv_data), |
| 92 | .platdata_auto_alloc_size = sizeof(struct hi6220_dwmmc_plat), |
| 93 | }; |