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 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 9 | #include <clk.h> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 10 | #include <common.h> |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 11 | #include <dm.h> |
Michal Simek | c57ba04 | 2014-02-24 11:16:31 +0100 | [diff] [blame] | 12 | #include <fdtdec.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 13 | #include <linux/libfdt.h> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 14 | #include <malloc.h> |
| 15 | #include <sdhci.h> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 16 | |
Stefan Herbrechtsmeier | 5567b42 | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 19 | struct arasan_sdhci_plat { |
| 20 | struct mmc_config cfg; |
| 21 | struct mmc mmc; |
Stefan Herbrechtsmeier | 5567b42 | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 22 | unsigned int f_max; |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 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); |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 30 | struct clk clk; |
| 31 | unsigned long clock; |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 32 | int ret; |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 33 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 34 | ret = clk_get_by_index(dev, 0, &clk); |
| 35 | if (ret < 0) { |
| 36 | dev_err(dev, "failed to get clock\n"); |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | clock = clk_get_rate(&clk); |
| 41 | if (IS_ERR_VALUE(clock)) { |
| 42 | dev_err(dev, "failed to get rate\n"); |
| 43 | return clock; |
| 44 | } |
| 45 | debug("%s: CLK %ld\n", __func__, clock); |
| 46 | |
| 47 | ret = clk_enable(&clk); |
| 48 | if (ret && ret != -ENOSYS) { |
| 49 | dev_err(dev, "failed to enable clock\n"); |
| 50 | return ret; |
| 51 | } |
| 52 | |
Siva Durga Prasad Paladugu | 049e003 | 2014-07-08 15:31:04 +0530 | [diff] [blame] | 53 | host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | |
Siva Durga Prasad Paladugu | 0d6891b | 2014-01-22 09:17:09 +0100 | [diff] [blame] | 54 | SDHCI_QUIRK_BROKEN_R1B; |
Siva Durga Prasad Paladugu | a1619fe | 2016-01-12 15:12:16 +0530 | [diff] [blame] | 55 | |
| 56 | #ifdef CONFIG_ZYNQ_HISPD_BROKEN |
| 57 | host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT; |
| 58 | #endif |
| 59 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 60 | host->max_clk = clock; |
Stefan Herbrechtsmeier | bc47e0e | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 61 | |
Stefan Herbrechtsmeier | 5567b42 | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 62 | ret = sdhci_setup_cfg(&plat->cfg, host, plat->f_max, |
Jaehoon Chung | 8a5ffbb | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 63 | CONFIG_ZYNQ_SDHCI_MIN_FREQ); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 64 | host->mmc = &plat->mmc; |
| 65 | if (ret) |
| 66 | return ret; |
| 67 | host->mmc->priv = host; |
Simon Glass | 77ca42b | 2016-05-01 13:52:34 -0600 | [diff] [blame] | 68 | host->mmc->dev = dev; |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 69 | upriv->mmc = host->mmc; |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 70 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 71 | return sdhci_probe(dev); |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 72 | } |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 73 | |
| 74 | static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev) |
| 75 | { |
Stefan Herbrechtsmeier | 5567b42 | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 76 | struct arasan_sdhci_plat *plat = dev_get_platdata(dev); |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 77 | struct sdhci_host *host = dev_get_priv(dev); |
| 78 | |
Masahiro Yamada | a440561 | 2016-04-22 20:59:31 +0900 | [diff] [blame] | 79 | host->name = dev->name; |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 80 | host->ioaddr = (void *)devfdt_get_addr(dev); |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 81 | |
Simon Glass | 7a49443 | 2017-05-17 17:18:09 -0600 | [diff] [blame] | 82 | plat->f_max = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
Stefan Herbrechtsmeier | 5567b42 | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 83 | "max-frequency", CONFIG_ZYNQ_SDHCI_MAX_FREQ); |
| 84 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 88 | static int arasan_sdhci_bind(struct udevice *dev) |
| 89 | { |
| 90 | struct arasan_sdhci_plat *plat = dev_get_platdata(dev); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 91 | |
Masahiro Yamada | cdb67f3 | 2016-09-06 22:17:32 +0900 | [diff] [blame] | 92 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 93 | } |
| 94 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 95 | static const struct udevice_id arasan_sdhci_ids[] = { |
| 96 | { .compatible = "arasan,sdhci-8.9a" }, |
| 97 | { } |
| 98 | }; |
| 99 | |
| 100 | U_BOOT_DRIVER(arasan_sdhci_drv) = { |
| 101 | .name = "arasan_sdhci", |
| 102 | .id = UCLASS_MMC, |
| 103 | .of_match = arasan_sdhci_ids, |
| 104 | .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata, |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 105 | .ops = &sdhci_ops, |
| 106 | .bind = arasan_sdhci_bind, |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 107 | .probe = arasan_sdhci_probe, |
| 108 | .priv_auto_alloc_size = sizeof(struct sdhci_host), |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 109 | .platdata_auto_alloc_size = sizeof(struct arasan_sdhci_plat), |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 110 | }; |