blob: 6194768fd72767e4756852b02d74a81ec6c5146f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Patrice Chotardeee20f82017-02-21 13:37:09 +01002/*
Patrice Chotardfb48bc42017-10-23 09:53:57 +02003 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
Patrice Chotard0f8106f2020-12-02 18:47:30 +01004 * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
Patrice Chotardeee20f82017-02-21 13:37:09 +01005 */
6
7#include <common.h>
8#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Patrice Chotardeee20f82017-02-21 13:37:09 +010010#include <mmc.h>
Patrice Chotarddca31662017-09-05 11:04:20 +020011#include <reset-uclass.h>
Patrice Chotardeee20f82017-02-21 13:37:09 +010012#include <sdhci.h>
13#include <asm/arch/sdhci.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Patrice Chotardeee20f82017-02-21 13:37:09 +010015
16DECLARE_GLOBAL_DATA_PTR;
17
18struct sti_sdhci_plat {
19 struct mmc_config cfg;
20 struct mmc mmc;
Patrice Chotarddca31662017-09-05 11:04:20 +020021 struct reset_ctl reset;
Patrice Chotard819c6262017-09-05 11:04:18 +020022 int instance;
Patrice Chotardeee20f82017-02-21 13:37:09 +010023};
24
Patrice Chotardeee20f82017-02-21 13:37:09 +010025/**
26 * sti_mmc_core_config: configure the Arasan HC
Patrice Chotard819c6262017-09-05 11:04:18 +020027 * @dev : udevice
28 *
Patrice Chotardeee20f82017-02-21 13:37:09 +010029 * 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 Chotarddca31662017-09-05 11:04:20 +020037static int sti_mmc_core_config(struct udevice *dev)
Patrice Chotardeee20f82017-02-21 13:37:09 +010038{
Simon Glassc69cda22020-12-03 16:55:20 -070039 struct sti_sdhci_plat *plat = dev_get_plat(dev);
Patrice Chotard819c6262017-09-05 11:04:18 +020040 struct sdhci_host *host = dev_get_priv(dev);
Patrice Chotarddca31662017-09-05 11:04:20 +020041 int ret;
Patrice Chotardeee20f82017-02-21 13:37:09 +010042
43 /* only MMC1 has a reset line */
Patrice Chotard819c6262017-09-05 11:04:18 +020044 if (plat->instance) {
Patrice Chotarddca31662017-09-05 11:04:20 +020045 ret = reset_deassert(&plat->reset);
46 if (ret < 0) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090047 pr_err("MMC1 deassert failed: %d", ret);
Patrice Chotarddca31662017-09-05 11:04:20 +020048 return ret;
49 }
Patrice Chotardeee20f82017-02-21 13:37:09 +010050 }
51
52 writel(STI_FLASHSS_MMC_CORE_CONFIG_1,
Patrice Chotard819c6262017-09-05 11:04:18 +020053 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_1);
Patrice Chotardeee20f82017-02-21 13:37:09 +010054
Patrice Chotard819c6262017-09-05 11:04:18 +020055 if (plat->instance) {
Patrice Chotardeee20f82017-02-21 13:37:09 +010056 writel(STI_FLASHSS_MMC_CORE_CONFIG2,
Patrice Chotard819c6262017-09-05 11:04:18 +020057 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
Patrice Chotardeee20f82017-02-21 13:37:09 +010058 writel(STI_FLASHSS_MMC_CORE_CONFIG3,
Patrice Chotard819c6262017-09-05 11:04:18 +020059 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
Patrice Chotardeee20f82017-02-21 13:37:09 +010060 } else {
61 writel(STI_FLASHSS_SDCARD_CORE_CONFIG2,
Patrice Chotard819c6262017-09-05 11:04:18 +020062 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
Patrice Chotardeee20f82017-02-21 13:37:09 +010063 writel(STI_FLASHSS_SDCARD_CORE_CONFIG3,
Patrice Chotard819c6262017-09-05 11:04:18 +020064 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
Patrice Chotardeee20f82017-02-21 13:37:09 +010065 }
66 writel(STI_FLASHSS_MMC_CORE_CONFIG4,
Patrice Chotard819c6262017-09-05 11:04:18 +020067 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_4);
Patrice Chotarddca31662017-09-05 11:04:20 +020068
69 return 0;
Patrice Chotardeee20f82017-02-21 13:37:09 +010070}
71
72static int sti_sdhci_probe(struct udevice *dev)
73{
74 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
Simon Glassc69cda22020-12-03 16:55:20 -070075 struct sti_sdhci_plat *plat = dev_get_plat(dev);
Patrice Chotardeee20f82017-02-21 13:37:09 +010076 struct sdhci_host *host = dev_get_priv(dev);
Patrice Chotard819c6262017-09-05 11:04:18 +020077 int ret;
Patrice Chotardeee20f82017-02-21 13:37:09 +010078
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 Chotarddca31662017-09-05 11:04:20 +020084 ret = reset_get_by_index(dev, 0, &plat->reset);
85 if (!ret)
Patrice Chotard819c6262017-09-05 11:04:18 +020086 plat->instance = 1;
Patrice Chotardeee20f82017-02-21 13:37:09 +010087 else
Patrice Chotarddca31662017-09-05 11:04:20 +020088 if (ret == -ENOENT)
89 plat->instance = 0;
90 else
91 return ret;
Patrice Chotardeee20f82017-02-21 13:37:09 +010092
Patrice Chotarddca31662017-09-05 11:04:20 +020093 ret = sti_mmc_core_config(dev);
94 if (ret)
95 return ret;
Patrice Chotardeee20f82017-02-21 13:37:09 +010096
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 Chotard2e01fcf2019-07-24 09:51:02 +0200102 host->mmc = &plat->mmc;
103 host->mmc->dev = dev;
104 host->mmc->priv = host;
Patrice Chotardeee20f82017-02-21 13:37:09 +0100105
106 ret = sdhci_setup_cfg(&plat->cfg, host, 50000000, 400000);
107 if (ret)
108 return ret;
109
Patrice Chotardeee20f82017-02-21 13:37:09 +0100110 upriv->mmc = host->mmc;
111
112 return sdhci_probe(dev);
113}
114
Simon Glassd1998a92020-12-03 16:55:21 -0700115static int sti_sdhci_of_to_plat(struct udevice *dev)
Patrice Chotardeee20f82017-02-21 13:37:09 +0100116{
117 struct sdhci_host *host = dev_get_priv(dev);
118
119 host->name = strdup(dev->name);
Masahiro Yamada8613c8d2020-07-17 14:36:46 +0900120 host->ioaddr = dev_read_addr_ptr(dev);
Patrice Chotardeee20f82017-02-21 13:37:09 +0100121
122 host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
123 "bus-width", 4);
124
125 return 0;
126}
127
128static int sti_sdhci_bind(struct udevice *dev)
129{
Simon Glassc69cda22020-12-03 16:55:20 -0700130 struct sti_sdhci_plat *plat = dev_get_plat(dev);
Patrice Chotardeee20f82017-02-21 13:37:09 +0100131
132 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
133}
134
135static const struct udevice_id sti_sdhci_ids[] = {
136 { .compatible = "st,sdhci" },
137 { }
138};
139
140U_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 Glassd1998a92020-12-03 16:55:21 -0700146 .of_to_plat = sti_sdhci_of_to_plat,
Patrice Chotardeee20f82017-02-21 13:37:09 +0100147 .probe = sti_sdhci_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700148 .priv_auto = sizeof(struct sdhci_host),
Simon Glasscaa4daa2020-12-03 16:55:18 -0700149 .plat_auto = sizeof(struct sti_sdhci_plat),
Patrice Chotardeee20f82017-02-21 13:37:09 +0100150};