2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-02-21 12:37:09 +00:00
|
|
|
/*
|
2017-10-23 07:53:57 +00:00
|
|
|
* Copyright (C) 2017, STMicroelectronics - All Rights Reserved
|
2020-12-02 17:47:30 +00:00
|
|
|
* Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
|
2017-02-21 12:37:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-02-21 12:37:09 +00:00
|
|
|
#include <mmc.h>
|
2017-09-05 09:04:20 +00:00
|
|
|
#include <reset-uclass.h>
|
2017-02-21 12:37:09 +00:00
|
|
|
#include <sdhci.h>
|
|
|
|
#include <asm/arch/sdhci.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2023-09-15 00:21:46 +00:00
|
|
|
#include <linux/printk.h>
|
2017-02-21 12:37:09 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
struct sti_sdhci_plat {
|
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
2017-09-05 09:04:20 +00:00
|
|
|
struct reset_ctl reset;
|
2017-09-05 09:04:18 +00:00
|
|
|
int instance;
|
2017-02-21 12:37:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sti_mmc_core_config: configure the Arasan HC
|
2017-09-05 09:04:18 +00:00
|
|
|
* @dev : udevice
|
|
|
|
*
|
2017-02-21 12:37:09 +00:00
|
|
|
* Description: this function is to configure the Arasan MMC HC.
|
|
|
|
* This should be called when the system starts in case of, on the SoC,
|
|
|
|
* it is needed to configure the host controller.
|
|
|
|
* This happens on some SoCs, i.e. StiH410, where the MMC0 inside the flashSS
|
|
|
|
* needs to be configured as MMC 4.5 to have full capabilities.
|
|
|
|
* W/o these settings the SDHCI could configure and use the embedded controller
|
|
|
|
* with limited features.
|
|
|
|
*/
|
2017-09-05 09:04:20 +00:00
|
|
|
static int sti_mmc_core_config(struct udevice *dev)
|
2017-02-21 12:37:09 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct sti_sdhci_plat *plat = dev_get_plat(dev);
|
2017-09-05 09:04:18 +00:00
|
|
|
struct sdhci_host *host = dev_get_priv(dev);
|
2017-09-05 09:04:20 +00:00
|
|
|
int ret;
|
2017-02-21 12:37:09 +00:00
|
|
|
|
|
|
|
/* only MMC1 has a reset line */
|
2017-09-05 09:04:18 +00:00
|
|
|
if (plat->instance) {
|
2017-09-05 09:04:20 +00:00
|
|
|
ret = reset_deassert(&plat->reset);
|
|
|
|
if (ret < 0) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("MMC1 deassert failed: %d", ret);
|
2017-09-05 09:04:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2017-02-21 12:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
writel(STI_FLASHSS_MMC_CORE_CONFIG_1,
|
2017-09-05 09:04:18 +00:00
|
|
|
host->ioaddr + FLASHSS_MMC_CORE_CONFIG_1);
|
2017-02-21 12:37:09 +00:00
|
|
|
|
2017-09-05 09:04:18 +00:00
|
|
|
if (plat->instance) {
|
2017-02-21 12:37:09 +00:00
|
|
|
writel(STI_FLASHSS_MMC_CORE_CONFIG2,
|
2017-09-05 09:04:18 +00:00
|
|
|
host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
|
2017-02-21 12:37:09 +00:00
|
|
|
writel(STI_FLASHSS_MMC_CORE_CONFIG3,
|
2017-09-05 09:04:18 +00:00
|
|
|
host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
|
2017-02-21 12:37:09 +00:00
|
|
|
} else {
|
|
|
|
writel(STI_FLASHSS_SDCARD_CORE_CONFIG2,
|
2017-09-05 09:04:18 +00:00
|
|
|
host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
|
2017-02-21 12:37:09 +00:00
|
|
|
writel(STI_FLASHSS_SDCARD_CORE_CONFIG3,
|
2017-09-05 09:04:18 +00:00
|
|
|
host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
|
2017-02-21 12:37:09 +00:00
|
|
|
}
|
|
|
|
writel(STI_FLASHSS_MMC_CORE_CONFIG4,
|
2017-09-05 09:04:18 +00:00
|
|
|
host->ioaddr + FLASHSS_MMC_CORE_CONFIG_4);
|
2017-09-05 09:04:20 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-02-21 12:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sti_sdhci_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct sti_sdhci_plat *plat = dev_get_plat(dev);
|
2017-02-21 12:37:09 +00:00
|
|
|
struct sdhci_host *host = dev_get_priv(dev);
|
2017-09-05 09:04:18 +00:00
|
|
|
int ret;
|
2017-02-21 12:37:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* identify current mmc instance, mmc1 has a reset, not mmc0
|
|
|
|
* MMC0 is wired to the SD slot,
|
|
|
|
* MMC1 is wired on the high speed connector
|
|
|
|
*/
|
2017-09-05 09:04:20 +00:00
|
|
|
ret = reset_get_by_index(dev, 0, &plat->reset);
|
|
|
|
if (!ret)
|
2017-09-05 09:04:18 +00:00
|
|
|
plat->instance = 1;
|
2017-02-21 12:37:09 +00:00
|
|
|
else
|
2017-09-05 09:04:20 +00:00
|
|
|
if (ret == -ENOENT)
|
|
|
|
plat->instance = 0;
|
|
|
|
else
|
|
|
|
return ret;
|
2017-02-21 12:37:09 +00:00
|
|
|
|
2017-09-05 09:04:20 +00:00
|
|
|
ret = sti_mmc_core_config(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-02-21 12:37:09 +00:00
|
|
|
|
|
|
|
host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
|
|
|
|
SDHCI_QUIRK_32BIT_DMA_ADDR |
|
|
|
|
SDHCI_QUIRK_NO_HISPD_BIT;
|
|
|
|
|
|
|
|
host->host_caps = MMC_MODE_DDR_52MHz;
|
2019-07-24 07:51:02 +00:00
|
|
|
host->mmc = &plat->mmc;
|
|
|
|
host->mmc->dev = dev;
|
|
|
|
host->mmc->priv = host;
|
2017-02-21 12:37:09 +00:00
|
|
|
|
|
|
|
ret = sdhci_setup_cfg(&plat->cfg, host, 50000000, 400000);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
upriv->mmc = host->mmc;
|
|
|
|
|
|
|
|
return sdhci_probe(dev);
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int sti_sdhci_of_to_plat(struct udevice *dev)
|
2017-02-21 12:37:09 +00:00
|
|
|
{
|
|
|
|
struct sdhci_host *host = dev_get_priv(dev);
|
|
|
|
|
|
|
|
host->name = strdup(dev->name);
|
2020-07-17 05:36:46 +00:00
|
|
|
host->ioaddr = dev_read_addr_ptr(dev);
|
2017-02-21 12:37:09 +00:00
|
|
|
|
|
|
|
host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
|
|
|
|
"bus-width", 4);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sti_sdhci_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct sti_sdhci_plat *plat = dev_get_plat(dev);
|
2017-02-21 12:37:09 +00:00
|
|
|
|
|
|
|
return sdhci_bind(dev, &plat->mmc, &plat->cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id sti_sdhci_ids[] = {
|
|
|
|
{ .compatible = "st,sdhci" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sti_mmc) = {
|
|
|
|
.name = "sti_sdhci",
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = sti_sdhci_ids,
|
|
|
|
.bind = sti_sdhci_bind,
|
|
|
|
.ops = &sdhci_ops,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = sti_sdhci_of_to_plat,
|
2017-02-21 12:37:09 +00:00
|
|
|
.probe = sti_sdhci_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct sdhci_host),
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct sti_sdhci_plat),
|
2017-02-21 12:37:09 +00:00
|
|
|
};
|