Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 1 | /* |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 2 | * (C) Copyright 2013 - 2015 Xilinx, Inc. |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 3 | * |
| 4 | * Xilinx Zynq SD Host Controller Interface |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 10 | #include <dm.h> |
Michal Simek | c57ba04 | 2014-02-24 11:16:31 +0100 | [diff] [blame] | 11 | #include <fdtdec.h> |
| 12 | #include <libfdt.h> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 13 | #include <malloc.h> |
| 14 | #include <sdhci.h> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 15 | |
Siva Durga Prasad Paladugu | f02a5e2 | 2016-01-05 12:21:04 +0530 | [diff] [blame] | 16 | #ifndef CONFIG_ZYNQ_SDHCI_MIN_FREQ |
| 17 | # define CONFIG_ZYNQ_SDHCI_MIN_FREQ 0 |
| 18 | #endif |
| 19 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 20 | struct arasan_sdhci_plat { |
| 21 | struct mmc_config cfg; |
| 22 | struct mmc mmc; |
| 23 | }; |
| 24 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 25 | static int arasan_sdhci_probe(struct udevice *dev) |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 26 | { |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 27 | struct arasan_sdhci_plat *plat = dev_get_platdata(dev); |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 28 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 29 | struct sdhci_host *host = dev_get_priv(dev); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 30 | int ret; |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 31 | |
Siva Durga Prasad Paladugu | 049e003 | 2014-07-08 15:31:04 +0530 | [diff] [blame] | 32 | host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | |
Siva Durga Prasad Paladugu | 0d6891b | 2014-01-22 09:17:09 +0100 | [diff] [blame] | 33 | SDHCI_QUIRK_BROKEN_R1B; |
Siva Durga Prasad Paladugu | a1619fe | 2016-01-12 15:12:16 +0530 | [diff] [blame] | 34 | |
| 35 | #ifdef CONFIG_ZYNQ_HISPD_BROKEN |
| 36 | host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT; |
| 37 | #endif |
| 38 | |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 39 | host->version = sdhci_readw(host, SDHCI_HOST_VERSION); |
| 40 | |
Jaehoon Chung | 8a5ffbb | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 41 | ret = sdhci_setup_cfg(&plat->cfg, host, CONFIG_ZYNQ_SDHCI_MAX_FREQ, |
| 42 | CONFIG_ZYNQ_SDHCI_MIN_FREQ); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 43 | host->mmc = &plat->mmc; |
| 44 | if (ret) |
| 45 | return ret; |
| 46 | host->mmc->priv = host; |
Simon Glass | 77ca42b | 2016-05-01 13:52:34 -0600 | [diff] [blame] | 47 | host->mmc->dev = dev; |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 48 | upriv->mmc = host->mmc; |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 49 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 50 | return sdhci_probe(dev); |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 51 | } |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 52 | |
| 53 | static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev) |
| 54 | { |
| 55 | struct sdhci_host *host = dev_get_priv(dev); |
| 56 | |
Masahiro Yamada | a440561 | 2016-04-22 20:59:31 +0900 | [diff] [blame] | 57 | host->name = dev->name; |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 58 | host->ioaddr = (void *)dev_get_addr(dev); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 63 | static int arasan_sdhci_bind(struct udevice *dev) |
| 64 | { |
| 65 | struct arasan_sdhci_plat *plat = dev_get_platdata(dev); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 66 | |
Masahiro Yamada | cdb67f3 | 2016-09-06 22:17:32 +0900 | [diff] [blame] | 67 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 68 | } |
| 69 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 70 | static const struct udevice_id arasan_sdhci_ids[] = { |
| 71 | { .compatible = "arasan,sdhci-8.9a" }, |
| 72 | { } |
| 73 | }; |
| 74 | |
| 75 | U_BOOT_DRIVER(arasan_sdhci_drv) = { |
| 76 | .name = "arasan_sdhci", |
| 77 | .id = UCLASS_MMC, |
| 78 | .of_match = arasan_sdhci_ids, |
| 79 | .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata, |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 80 | .ops = &sdhci_ops, |
| 81 | .bind = arasan_sdhci_bind, |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 82 | .probe = arasan_sdhci_probe, |
| 83 | .priv_auto_alloc_size = sizeof(struct sdhci_host), |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 84 | .platdata_auto_alloc_size = sizeof(struct arasan_sdhci_plat), |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 85 | }; |