2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-01-28 10:00:18 +00:00
|
|
|
/*
|
|
|
|
* Support of SDHCI for Microchip PIC32 SoC.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Microchip Technology Inc.
|
|
|
|
* Andrei Pistirica <andrei.pistirica@microchip.com>
|
|
|
|
*/
|
|
|
|
|
2017-05-17 23:18:07 +00:00
|
|
|
#include <dm.h>
|
2016-01-28 10:00:18 +00:00
|
|
|
#include <sdhci.h>
|
2020-09-01 02:55:14 +00:00
|
|
|
#include <clk.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <mach/pic32.h>
|
2016-01-28 10:00:18 +00:00
|
|
|
|
2020-09-01 02:55:14 +00:00
|
|
|
struct pic32_sdhci_plat {
|
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
2016-12-30 06:30:14 +00:00
|
|
|
};
|
|
|
|
|
2016-01-28 10:00:18 +00:00
|
|
|
static int pic32_sdhci_probe(struct udevice *dev)
|
|
|
|
{
|
2020-09-01 02:55:14 +00:00
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct pic32_sdhci_plat *plat = dev_get_plat(dev);
|
2016-01-28 10:00:18 +00:00
|
|
|
struct sdhci_host *host = dev_get_priv(dev);
|
2020-09-01 02:55:14 +00:00
|
|
|
|
|
|
|
struct clk clk;
|
|
|
|
ulong clk_rate;
|
2016-01-28 10:00:18 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-09-01 02:55:14 +00:00
|
|
|
ret = clk_get_by_name(dev, "base_clk", &clk);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
clk_rate = clk_get_rate(&clk);
|
|
|
|
clk_free(&clk);
|
|
|
|
|
|
|
|
if (IS_ERR_VALUE(clk_rate))
|
|
|
|
return clk_rate;
|
|
|
|
|
|
|
|
host->ioaddr = dev_remap_addr(dev);
|
|
|
|
|
|
|
|
if (!host->ioaddr)
|
2016-01-28 10:00:18 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-04-22 11:59:31 +00:00
|
|
|
host->name = dev->name;
|
2016-12-30 06:30:15 +00:00
|
|
|
host->quirks = SDHCI_QUIRK_NO_HISPD_BIT;
|
2020-09-01 02:55:14 +00:00
|
|
|
host->bus_width = dev_read_u32_default(dev, "bus-width", 4);
|
|
|
|
host->max_clk = clk_rate;
|
|
|
|
|
|
|
|
host->mmc = &plat->mmc;
|
|
|
|
host->mmc->dev = dev;
|
|
|
|
|
|
|
|
ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
|
|
|
|
if (ret)
|
2016-01-28 10:00:18 +00:00
|
|
|
return ret;
|
|
|
|
|
2020-09-01 02:55:14 +00:00
|
|
|
host->mmc->priv = host;
|
|
|
|
upriv->mmc = host->mmc;
|
2017-01-17 14:58:48 +00:00
|
|
|
|
2020-09-01 02:55:14 +00:00
|
|
|
ret = sdhci_probe(dev);
|
2016-05-01 19:52:34 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-09-01 02:55:14 +00:00
|
|
|
|
|
|
|
if (!dev_read_bool(dev, "microchip,use-sdcd")) {
|
|
|
|
// Use workaround 1 for erratum #15 by default
|
|
|
|
u8 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
|
|
|
|
ctrl = (ctrl & ~SDHCI_CTRL_CD_TEST_INS) | SDHCI_CTRL_CD_TEST;
|
|
|
|
sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
|
|
|
|
}
|
2016-05-01 19:52:34 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-01-28 10:00:18 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 02:55:14 +00:00
|
|
|
static int pic32_sdhci_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct pic32_sdhci_plat *plat = dev_get_plat(dev);
|
2020-09-01 02:55:14 +00:00
|
|
|
|
|
|
|
return sdhci_bind(dev, &plat->mmc, &plat->cfg);
|
|
|
|
}
|
|
|
|
|
2016-01-28 10:00:18 +00:00
|
|
|
static const struct udevice_id pic32_sdhci_ids[] = {
|
|
|
|
{ .compatible = "microchip,pic32mzda-sdhci" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(pic32_sdhci_drv) = {
|
|
|
|
.name = "pic32_sdhci",
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = pic32_sdhci_ids,
|
2020-09-01 02:55:14 +00:00
|
|
|
.ops = &sdhci_ops,
|
|
|
|
.bind = pic32_sdhci_bind,
|
2016-01-28 10:00:18 +00:00
|
|
|
.probe = pic32_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 pic32_sdhci_plat)
|
2016-01-28 10:00:18 +00:00
|
|
|
};
|