Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 2 | /* |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 3 | * (C) Copyright 2013 - 2015 Xilinx, Inc. |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 4 | * |
| 5 | * Xilinx Zynq SD Host Controller Interface |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Stefan Herbrechtsmeier | e0f4de1 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 8 | #include <clk.h> |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 9 | #include <common.h> |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 10 | #include <dm.h> |
Michal Simek | 345d3c0 | 2014-02-24 11:16:31 +0100 | [diff] [blame] | 11 | #include <fdtdec.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 13 | #include <malloc.h> |
| 14 | #include <sdhci.h> |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 15 | |
Stefan Herbrechtsmeier | 61e745d | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 18 | struct arasan_sdhci_plat { |
| 19 | struct mmc_config cfg; |
| 20 | struct mmc mmc; |
Stefan Herbrechtsmeier | 61e745d | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 21 | unsigned int f_max; |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 22 | }; |
| 23 | |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 24 | static int arasan_sdhci_probe(struct udevice *dev) |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 25 | { |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 26 | struct arasan_sdhci_plat *plat = dev_get_platdata(dev); |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 27 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 28 | struct sdhci_host *host = dev_get_priv(dev); |
Stefan Herbrechtsmeier | e0f4de1 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 29 | struct clk clk; |
| 30 | unsigned long clock; |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 31 | int ret; |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 32 | |
Stefan Herbrechtsmeier | e0f4de1 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 33 | ret = clk_get_by_index(dev, 0, &clk); |
| 34 | if (ret < 0) { |
| 35 | dev_err(dev, "failed to get clock\n"); |
| 36 | return ret; |
| 37 | } |
| 38 | |
| 39 | clock = clk_get_rate(&clk); |
| 40 | if (IS_ERR_VALUE(clock)) { |
| 41 | dev_err(dev, "failed to get rate\n"); |
| 42 | return clock; |
| 43 | } |
| 44 | debug("%s: CLK %ld\n", __func__, clock); |
| 45 | |
| 46 | ret = clk_enable(&clk); |
| 47 | if (ret && ret != -ENOSYS) { |
| 48 | dev_err(dev, "failed to enable clock\n"); |
| 49 | return ret; |
| 50 | } |
| 51 | |
Siva Durga Prasad Paladugu | eddabd1 | 2014-07-08 15:31:04 +0530 | [diff] [blame] | 52 | host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | |
Siva Durga Prasad Paladugu | f9ec45d | 2014-01-22 09:17:09 +0100 | [diff] [blame] | 53 | SDHCI_QUIRK_BROKEN_R1B; |
Siva Durga Prasad Paladugu | b215614 | 2016-01-12 15:12:16 +0530 | [diff] [blame] | 54 | |
| 55 | #ifdef CONFIG_ZYNQ_HISPD_BROKEN |
Hannes Schmelzer | 4781921 | 2018-03-07 08:00:57 +0100 | [diff] [blame] | 56 | host->quirks |= SDHCI_QUIRK_BROKEN_HISPD_MODE; |
Siva Durga Prasad Paladugu | b215614 | 2016-01-12 15:12:16 +0530 | [diff] [blame] | 57 | #endif |
| 58 | |
Stefan Herbrechtsmeier | e0f4de1 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 59 | host->max_clk = clock; |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 60 | |
Stefan Herbrechtsmeier | 61e745d | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 61 | ret = sdhci_setup_cfg(&plat->cfg, host, plat->f_max, |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 62 | CONFIG_ZYNQ_SDHCI_MIN_FREQ); |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 63 | host->mmc = &plat->mmc; |
| 64 | if (ret) |
| 65 | return ret; |
| 66 | host->mmc->priv = host; |
Simon Glass | cffe5d8 | 2016-05-01 13:52:34 -0600 | [diff] [blame] | 67 | host->mmc->dev = dev; |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 68 | upriv->mmc = host->mmc; |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 69 | |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 70 | return sdhci_probe(dev); |
Michal Simek | 293eb33 | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 71 | } |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 72 | |
| 73 | static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev) |
| 74 | { |
Stefan Herbrechtsmeier | 61e745d | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 75 | struct arasan_sdhci_plat *plat = dev_get_platdata(dev); |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 76 | struct sdhci_host *host = dev_get_priv(dev); |
| 77 | |
Masahiro Yamada | cacd1d2 | 2016-04-22 20:59:31 +0900 | [diff] [blame] | 78 | host->name = dev->name; |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 79 | host->ioaddr = (void *)devfdt_get_addr(dev); |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 80 | |
Simon Glass | da409cc | 2017-05-17 17:18:09 -0600 | [diff] [blame] | 81 | plat->f_max = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
Stefan Herbrechtsmeier | 61e745d | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 82 | "max-frequency", CONFIG_ZYNQ_SDHCI_MAX_FREQ); |
| 83 | |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 87 | static int arasan_sdhci_bind(struct udevice *dev) |
| 88 | { |
| 89 | struct arasan_sdhci_plat *plat = dev_get_platdata(dev); |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 90 | |
Masahiro Yamada | 24f5aec | 2016-09-06 22:17:32 +0900 | [diff] [blame] | 91 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 92 | } |
| 93 | |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 94 | static const struct udevice_id arasan_sdhci_ids[] = { |
| 95 | { .compatible = "arasan,sdhci-8.9a" }, |
| 96 | { } |
| 97 | }; |
| 98 | |
| 99 | U_BOOT_DRIVER(arasan_sdhci_drv) = { |
| 100 | .name = "arasan_sdhci", |
| 101 | .id = UCLASS_MMC, |
| 102 | .of_match = arasan_sdhci_ids, |
| 103 | .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata, |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 104 | .ops = &sdhci_ops, |
| 105 | .bind = arasan_sdhci_bind, |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 106 | .probe = arasan_sdhci_probe, |
| 107 | .priv_auto_alloc_size = sizeof(struct sdhci_host), |
Simon Glass | 329a449 | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 108 | .platdata_auto_alloc_size = sizeof(struct arasan_sdhci_plat), |
Michal Simek | d9ae52c | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 109 | }; |