blob: 23a1dd43c9b277df31d777b21f8302445cd036ae [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>
Simon Glass1e94b462023-09-14 18:21:46 -060015#include <linux/printk.h>
Patrice Chotardeee20f82017-02-21 13:37:09 +010016
17DECLARE_GLOBAL_DATA_PTR;
18
19struct sti_sdhci_plat {
20 struct mmc_config cfg;
21 struct mmc mmc;
Patrice Chotarddca31662017-09-05 11:04:20 +020022 struct reset_ctl reset;
Patrice Chotard819c6262017-09-05 11:04:18 +020023 int instance;
Patrice Chotardeee20f82017-02-21 13:37:09 +010024};
25
Patrice Chotardeee20f82017-02-21 13:37:09 +010026/**
27 * sti_mmc_core_config: configure the Arasan HC
Patrice Chotard819c6262017-09-05 11:04:18 +020028 * @dev : udevice
29 *
Patrice Chotardeee20f82017-02-21 13:37:09 +010030 * 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 Chotarddca31662017-09-05 11:04:20 +020038static int sti_mmc_core_config(struct udevice *dev)
Patrice Chotardeee20f82017-02-21 13:37:09 +010039{
Simon Glassc69cda22020-12-03 16:55:20 -070040 struct sti_sdhci_plat *plat = dev_get_plat(dev);
Patrice Chotard819c6262017-09-05 11:04:18 +020041 struct sdhci_host *host = dev_get_priv(dev);
Patrice Chotarddca31662017-09-05 11:04:20 +020042 int ret;
Patrice Chotardeee20f82017-02-21 13:37:09 +010043
44 /* only MMC1 has a reset line */
Patrice Chotard819c6262017-09-05 11:04:18 +020045 if (plat->instance) {
Patrice Chotarddca31662017-09-05 11:04:20 +020046 ret = reset_deassert(&plat->reset);
47 if (ret < 0) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090048 pr_err("MMC1 deassert failed: %d", ret);
Patrice Chotarddca31662017-09-05 11:04:20 +020049 return ret;
50 }
Patrice Chotardeee20f82017-02-21 13:37:09 +010051 }
52
53 writel(STI_FLASHSS_MMC_CORE_CONFIG_1,
Patrice Chotard819c6262017-09-05 11:04:18 +020054 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_1);
Patrice Chotardeee20f82017-02-21 13:37:09 +010055
Patrice Chotard819c6262017-09-05 11:04:18 +020056 if (plat->instance) {
Patrice Chotardeee20f82017-02-21 13:37:09 +010057 writel(STI_FLASHSS_MMC_CORE_CONFIG2,
Patrice Chotard819c6262017-09-05 11:04:18 +020058 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
Patrice Chotardeee20f82017-02-21 13:37:09 +010059 writel(STI_FLASHSS_MMC_CORE_CONFIG3,
Patrice Chotard819c6262017-09-05 11:04:18 +020060 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
Patrice Chotardeee20f82017-02-21 13:37:09 +010061 } else {
62 writel(STI_FLASHSS_SDCARD_CORE_CONFIG2,
Patrice Chotard819c6262017-09-05 11:04:18 +020063 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
Patrice Chotardeee20f82017-02-21 13:37:09 +010064 writel(STI_FLASHSS_SDCARD_CORE_CONFIG3,
Patrice Chotard819c6262017-09-05 11:04:18 +020065 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
Patrice Chotardeee20f82017-02-21 13:37:09 +010066 }
67 writel(STI_FLASHSS_MMC_CORE_CONFIG4,
Patrice Chotard819c6262017-09-05 11:04:18 +020068 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_4);
Patrice Chotarddca31662017-09-05 11:04:20 +020069
70 return 0;
Patrice Chotardeee20f82017-02-21 13:37:09 +010071}
72
73static int sti_sdhci_probe(struct udevice *dev)
74{
75 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
Simon Glassc69cda22020-12-03 16:55:20 -070076 struct sti_sdhci_plat *plat = dev_get_plat(dev);
Patrice Chotardeee20f82017-02-21 13:37:09 +010077 struct sdhci_host *host = dev_get_priv(dev);
Patrice Chotard819c6262017-09-05 11:04:18 +020078 int ret;
Patrice Chotardeee20f82017-02-21 13:37:09 +010079
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 Chotarddca31662017-09-05 11:04:20 +020085 ret = reset_get_by_index(dev, 0, &plat->reset);
86 if (!ret)
Patrice Chotard819c6262017-09-05 11:04:18 +020087 plat->instance = 1;
Patrice Chotardeee20f82017-02-21 13:37:09 +010088 else
Patrice Chotarddca31662017-09-05 11:04:20 +020089 if (ret == -ENOENT)
90 plat->instance = 0;
91 else
92 return ret;
Patrice Chotardeee20f82017-02-21 13:37:09 +010093
Patrice Chotarddca31662017-09-05 11:04:20 +020094 ret = sti_mmc_core_config(dev);
95 if (ret)
96 return ret;
Patrice Chotardeee20f82017-02-21 13:37:09 +010097
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 Chotard2e01fcf2019-07-24 09:51:02 +0200103 host->mmc = &plat->mmc;
104 host->mmc->dev = dev;
105 host->mmc->priv = host;
Patrice Chotardeee20f82017-02-21 13:37:09 +0100106
107 ret = sdhci_setup_cfg(&plat->cfg, host, 50000000, 400000);
108 if (ret)
109 return ret;
110
Patrice Chotardeee20f82017-02-21 13:37:09 +0100111 upriv->mmc = host->mmc;
112
113 return sdhci_probe(dev);
114}
115
Simon Glassd1998a92020-12-03 16:55:21 -0700116static int sti_sdhci_of_to_plat(struct udevice *dev)
Patrice Chotardeee20f82017-02-21 13:37:09 +0100117{
118 struct sdhci_host *host = dev_get_priv(dev);
119
120 host->name = strdup(dev->name);
Masahiro Yamada8613c8d2020-07-17 14:36:46 +0900121 host->ioaddr = dev_read_addr_ptr(dev);
Patrice Chotardeee20f82017-02-21 13:37:09 +0100122
123 host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
124 "bus-width", 4);
125
126 return 0;
127}
128
129static int sti_sdhci_bind(struct udevice *dev)
130{
Simon Glassc69cda22020-12-03 16:55:20 -0700131 struct sti_sdhci_plat *plat = dev_get_plat(dev);
Patrice Chotardeee20f82017-02-21 13:37:09 +0100132
133 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
134}
135
136static const struct udevice_id sti_sdhci_ids[] = {
137 { .compatible = "st,sdhci" },
138 { }
139};
140
141U_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 Glassd1998a92020-12-03 16:55:21 -0700147 .of_to_plat = sti_sdhci_of_to_plat,
Patrice Chotardeee20f82017-02-21 13:37:09 +0100148 .probe = sti_sdhci_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700149 .priv_auto = sizeof(struct sdhci_host),
Simon Glasscaa4daa2020-12-03 16:55:18 -0700150 .plat_auto = sizeof(struct sti_sdhci_plat),
Patrice Chotardeee20f82017-02-21 13:37:09 +0100151};