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