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