Kever Yang | 79c8306 | 2016-07-18 17:00:58 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2016 Fuzhou Rockchip Electronics Co., Ltd |
| 3 | * |
| 4 | * Rockchip SD Host Controller Interface |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
| 11 | #include <fdtdec.h> |
| 12 | #include <libfdt.h> |
| 13 | #include <malloc.h> |
| 14 | #include <sdhci.h> |
| 15 | |
| 16 | /* 400KHz is max freq for card ID etc. Use that as min */ |
| 17 | #define EMMC_MIN_FREQ 400000 |
| 18 | |
| 19 | struct rockchip_sdhc_plat { |
| 20 | struct mmc_config cfg; |
| 21 | struct mmc mmc; |
| 22 | }; |
| 23 | |
| 24 | struct rockchip_sdhc { |
| 25 | struct sdhci_host host; |
| 26 | void *base; |
| 27 | }; |
| 28 | |
| 29 | static int arasan_sdhci_probe(struct udevice *dev) |
| 30 | { |
| 31 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 32 | struct rockchip_sdhc_plat *plat = dev_get_platdata(dev); |
| 33 | struct rockchip_sdhc *prv = dev_get_priv(dev); |
| 34 | struct sdhci_host *host = &prv->host; |
| 35 | int ret; |
Kever Yang | 79c8306 | 2016-07-18 17:00:58 +0800 | [diff] [blame] | 36 | |
Kever Yang | 79c8306 | 2016-07-18 17:00:58 +0800 | [diff] [blame] | 37 | host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD; |
| 38 | |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 39 | ret = sdhci_setup_cfg(&plat->cfg, host, CONFIG_ROCKCHIP_SDHCI_MAX_FREQ, |
| 40 | EMMC_MIN_FREQ); |
Kever Yang | 79c8306 | 2016-07-18 17:00:58 +0800 | [diff] [blame] | 41 | |
| 42 | host->mmc = &plat->mmc; |
| 43 | if (ret) |
| 44 | return ret; |
| 45 | host->mmc->priv = &prv->host; |
| 46 | host->mmc->dev = dev; |
| 47 | upriv->mmc = host->mmc; |
| 48 | |
| 49 | return sdhci_probe(dev); |
| 50 | } |
| 51 | |
| 52 | static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev) |
| 53 | { |
| 54 | struct sdhci_host *host = dev_get_priv(dev); |
| 55 | |
| 56 | host->name = dev->name; |
| 57 | host->ioaddr = dev_get_addr_ptr(dev); |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static int rockchip_sdhci_bind(struct udevice *dev) |
| 63 | { |
| 64 | struct rockchip_sdhc_plat *plat = dev_get_platdata(dev); |
Kever Yang | 79c8306 | 2016-07-18 17:00:58 +0800 | [diff] [blame] | 65 | |
Masahiro Yamada | 24f5aec | 2016-09-06 22:17:32 +0900 | [diff] [blame] | 66 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
Kever Yang | 79c8306 | 2016-07-18 17:00:58 +0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static const struct udevice_id arasan_sdhci_ids[] = { |
| 70 | { .compatible = "arasan,sdhci-5.1" }, |
| 71 | { } |
| 72 | }; |
| 73 | |
| 74 | U_BOOT_DRIVER(arasan_sdhci_drv) = { |
| 75 | .name = "arasan_sdhci", |
| 76 | .id = UCLASS_MMC, |
| 77 | .of_match = arasan_sdhci_ids, |
| 78 | .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata, |
| 79 | .ops = &sdhci_ops, |
| 80 | .bind = rockchip_sdhci_bind, |
| 81 | .probe = arasan_sdhci_probe, |
| 82 | .priv_auto_alloc_size = sizeof(struct rockchip_sdhc), |
| 83 | .platdata_auto_alloc_size = sizeof(struct rockchip_sdhc_plat), |
| 84 | }; |