2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-10-01 15:34:41 +00:00
|
|
|
/*
|
|
|
|
* Marvell SD Host Controller Interface
|
|
|
|
*/
|
|
|
|
|
2011-06-28 21:50:07 +00:00
|
|
|
#include <common.h>
|
2019-04-11 02:56:58 +00:00
|
|
|
#include <dm.h>
|
2011-06-28 21:50:07 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <sdhci.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2015-10-01 15:34:41 +00:00
|
|
|
#include <linux/mbus.h>
|
|
|
|
|
2019-04-11 02:56:58 +00:00
|
|
|
#define MVSDH_NAME "mv_sdh"
|
|
|
|
|
2015-10-01 15:34:41 +00:00
|
|
|
#define SDHCI_WINDOW_CTRL(win) (0x4080 + ((win) << 4))
|
|
|
|
#define SDHCI_WINDOW_BASE(win) (0x4084 + ((win) << 4))
|
|
|
|
|
2023-02-10 12:23:52 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
struct mv_sdhci_plat {
|
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
|
|
|
};
|
|
|
|
|
2015-10-01 15:34:41 +00:00
|
|
|
static void sdhci_mvebu_mbus_config(void __iomem *base)
|
|
|
|
{
|
|
|
|
const struct mbus_dram_target_info *dram;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dram = mvebu_mbus_dram_info();
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
writel(0, base + SDHCI_WINDOW_CTRL(i));
|
|
|
|
writel(0, base + SDHCI_WINDOW_BASE(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dram->num_cs; i++) {
|
|
|
|
const struct mbus_dram_window *cs = dram->cs + i;
|
|
|
|
|
|
|
|
/* Write size, attributes and target id to control register */
|
|
|
|
writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
|
|
|
|
(dram->mbus_dram_target_id << 4) | 1,
|
|
|
|
base + SDHCI_WINDOW_CTRL(i));
|
|
|
|
|
|
|
|
/* Write base address to base register */
|
|
|
|
writel(cs->base, base + SDHCI_WINDOW_BASE(i));
|
|
|
|
}
|
|
|
|
}
|
2011-06-28 21:50:07 +00:00
|
|
|
|
2019-04-11 02:56:58 +00:00
|
|
|
static int mv_sdhci_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct mv_sdhci_plat *plat = dev_get_plat(dev);
|
2019-04-11 02:56:58 +00:00
|
|
|
struct sdhci_host *host = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
host->name = MVSDH_NAME;
|
2020-07-17 05:36:46 +00:00
|
|
|
host->ioaddr = dev_read_addr_ptr(dev);
|
2019-04-11 02:56:58 +00:00
|
|
|
host->quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD;
|
2019-07-22 15:55:35 +00:00
|
|
|
host->mmc = &plat->mmc;
|
|
|
|
host->mmc->dev = dev;
|
|
|
|
host->mmc->priv = host;
|
2019-04-11 02:56:58 +00:00
|
|
|
|
2021-02-02 06:43:04 +00:00
|
|
|
ret = mmc_of_parse(dev, &plat->cfg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-04-11 02:56:58 +00:00
|
|
|
ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2023-02-10 12:23:50 +00:00
|
|
|
/* Configure SDHCI MBUS mbus bridge windows */
|
|
|
|
sdhci_mvebu_mbus_config(host->ioaddr);
|
2019-04-11 02:56:58 +00:00
|
|
|
|
|
|
|
upriv->mmc = host->mmc;
|
|
|
|
|
|
|
|
return sdhci_probe(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mv_sdhci_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct mv_sdhci_plat *plat = dev_get_plat(dev);
|
2019-04-11 02:56:58 +00:00
|
|
|
|
|
|
|
return sdhci_bind(dev, &plat->mmc, &plat->cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id mv_sdhci_ids[] = {
|
|
|
|
{ .compatible = "marvell,armada-380-sdhci" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(mv_sdhci_drv) = {
|
|
|
|
.name = MVSDH_NAME,
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = mv_sdhci_ids,
|
|
|
|
.bind = mv_sdhci_bind,
|
|
|
|
.probe = mv_sdhci_probe,
|
|
|
|
.ops = &sdhci_ops,
|
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 mv_sdhci_plat),
|
2019-04-11 02:56:58 +00:00
|
|
|
};
|