Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 2 | /* |
Patrice Chotard | 9e21624 | 2017-10-23 09:53:57 +0200 | [diff] [blame] | 3 | * Copyright (C) 2017, STMicroelectronics - All Rights Reserved |
| 4 | * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics. |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <mmc.h> |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 10 | #include <reset-uclass.h> |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 11 | #include <sdhci.h> |
| 12 | #include <asm/arch/sdhci.h> |
| 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | struct sti_sdhci_plat { |
| 17 | struct mmc_config cfg; |
| 18 | struct mmc mmc; |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 19 | struct reset_ctl reset; |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 20 | int instance; |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 21 | }; |
| 22 | |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 23 | /** |
| 24 | * sti_mmc_core_config: configure the Arasan HC |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 25 | * @dev : udevice |
| 26 | * |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 27 | * Description: this function is to configure the Arasan MMC HC. |
| 28 | * This should be called when the system starts in case of, on the SoC, |
| 29 | * it is needed to configure the host controller. |
| 30 | * This happens on some SoCs, i.e. StiH410, where the MMC0 inside the flashSS |
| 31 | * needs to be configured as MMC 4.5 to have full capabilities. |
| 32 | * W/o these settings the SDHCI could configure and use the embedded controller |
| 33 | * with limited features. |
| 34 | */ |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 35 | static int sti_mmc_core_config(struct udevice *dev) |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 36 | { |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 37 | struct sti_sdhci_plat *plat = dev_get_platdata(dev); |
| 38 | struct sdhci_host *host = dev_get_priv(dev); |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 39 | int ret; |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 40 | |
| 41 | /* only MMC1 has a reset line */ |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 42 | if (plat->instance) { |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 43 | ret = reset_deassert(&plat->reset); |
| 44 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 45 | pr_err("MMC1 deassert failed: %d", ret); |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 46 | return ret; |
| 47 | } |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | writel(STI_FLASHSS_MMC_CORE_CONFIG_1, |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 51 | host->ioaddr + FLASHSS_MMC_CORE_CONFIG_1); |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 52 | |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 53 | if (plat->instance) { |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 54 | writel(STI_FLASHSS_MMC_CORE_CONFIG2, |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 55 | host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2); |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 56 | writel(STI_FLASHSS_MMC_CORE_CONFIG3, |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 57 | host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3); |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 58 | } else { |
| 59 | writel(STI_FLASHSS_SDCARD_CORE_CONFIG2, |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 60 | host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2); |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 61 | writel(STI_FLASHSS_SDCARD_CORE_CONFIG3, |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 62 | host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3); |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 63 | } |
| 64 | writel(STI_FLASHSS_MMC_CORE_CONFIG4, |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 65 | host->ioaddr + FLASHSS_MMC_CORE_CONFIG_4); |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 66 | |
| 67 | return 0; |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static int sti_sdhci_probe(struct udevice *dev) |
| 71 | { |
| 72 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 73 | struct sti_sdhci_plat *plat = dev_get_platdata(dev); |
| 74 | struct sdhci_host *host = dev_get_priv(dev); |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 75 | int ret; |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * identify current mmc instance, mmc1 has a reset, not mmc0 |
| 79 | * MMC0 is wired to the SD slot, |
| 80 | * MMC1 is wired on the high speed connector |
| 81 | */ |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 82 | ret = reset_get_by_index(dev, 0, &plat->reset); |
| 83 | if (!ret) |
Patrice Chotard | 1b888b8 | 2017-09-05 11:04:18 +0200 | [diff] [blame] | 84 | plat->instance = 1; |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 85 | else |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 86 | if (ret == -ENOENT) |
| 87 | plat->instance = 0; |
| 88 | else |
| 89 | return ret; |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 90 | |
Patrice Chotard | 36904ad | 2017-09-05 11:04:20 +0200 | [diff] [blame] | 91 | ret = sti_mmc_core_config(dev); |
| 92 | if (ret) |
| 93 | return ret; |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 94 | |
| 95 | host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | |
| 96 | SDHCI_QUIRK_32BIT_DMA_ADDR | |
| 97 | SDHCI_QUIRK_NO_HISPD_BIT; |
| 98 | |
| 99 | host->host_caps = MMC_MODE_DDR_52MHz; |
| 100 | |
| 101 | ret = sdhci_setup_cfg(&plat->cfg, host, 50000000, 400000); |
| 102 | if (ret) |
| 103 | return ret; |
| 104 | |
| 105 | host->mmc = &plat->mmc; |
| 106 | host->mmc->priv = host; |
| 107 | host->mmc->dev = dev; |
| 108 | upriv->mmc = host->mmc; |
| 109 | |
| 110 | return sdhci_probe(dev); |
| 111 | } |
| 112 | |
| 113 | static int sti_sdhci_ofdata_to_platdata(struct udevice *dev) |
| 114 | { |
| 115 | struct sdhci_host *host = dev_get_priv(dev); |
| 116 | |
| 117 | host->name = strdup(dev->name); |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 118 | host->ioaddr = (void *)devfdt_get_addr(dev); |
Patrice Chotard | 2eea7d8 | 2017-02-21 13:37:09 +0100 | [diff] [blame] | 119 | |
| 120 | host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
| 121 | "bus-width", 4); |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static int sti_sdhci_bind(struct udevice *dev) |
| 127 | { |
| 128 | struct sti_sdhci_plat *plat = dev_get_platdata(dev); |
| 129 | |
| 130 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
| 131 | } |
| 132 | |
| 133 | static const struct udevice_id sti_sdhci_ids[] = { |
| 134 | { .compatible = "st,sdhci" }, |
| 135 | { } |
| 136 | }; |
| 137 | |
| 138 | U_BOOT_DRIVER(sti_mmc) = { |
| 139 | .name = "sti_sdhci", |
| 140 | .id = UCLASS_MMC, |
| 141 | .of_match = sti_sdhci_ids, |
| 142 | .bind = sti_sdhci_bind, |
| 143 | .ops = &sdhci_ops, |
| 144 | .ofdata_to_platdata = sti_sdhci_ofdata_to_platdata, |
| 145 | .probe = sti_sdhci_probe, |
| 146 | .priv_auto_alloc_size = sizeof(struct sdhci_host), |
| 147 | .platdata_auto_alloc_size = sizeof(struct sti_sdhci_plat), |
| 148 | }; |