2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-12-31 00:26:14 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2013 Altera Corporation <www.altera.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2013-12-31 00:26:14 +00:00
|
|
|
#include <asm/arch/clock_manager.h>
|
|
|
|
#include <asm/arch/system_manager.h>
|
2018-08-01 16:28:35 +00:00
|
|
|
#include <clk.h>
|
2015-11-30 19:41:04 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <dwmmc.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fdtdec.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2015-11-30 19:41:04 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <malloc.h>
|
2018-06-14 10:45:21 +00:00
|
|
|
#include <reset.h>
|
2015-11-30 19:41:04 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2013-12-31 00:26:14 +00:00
|
|
|
|
2016-07-05 23:10:16 +00:00
|
|
|
struct socfpga_dwmci_plat {
|
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
|
|
|
};
|
|
|
|
|
2015-11-30 19:41:04 +00:00
|
|
|
/* socfpga implmentation specific driver private data */
|
2015-11-26 01:43:43 +00:00
|
|
|
struct dwmci_socfpga_priv_data {
|
2015-11-30 19:41:04 +00:00
|
|
|
struct dwmci_host host;
|
|
|
|
unsigned int drvsel;
|
|
|
|
unsigned int smplsel;
|
2015-11-26 01:43:43 +00:00
|
|
|
};
|
|
|
|
|
2018-06-14 10:45:21 +00:00
|
|
|
static void socfpga_dwmci_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct reset_ctl_bulk reset_bulk;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = reset_get_bulk(dev, &reset_bulk);
|
|
|
|
if (ret) {
|
|
|
|
dev_warn(dev, "Can't get reset: %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
reset_deassert_bulk(&reset_bulk);
|
|
|
|
}
|
|
|
|
|
2015-11-26 01:43:43 +00:00
|
|
|
static void socfpga_dwmci_clksel(struct dwmci_host *host)
|
|
|
|
{
|
|
|
|
struct dwmci_socfpga_priv_data *priv = host->priv;
|
2015-12-02 19:31:33 +00:00
|
|
|
u32 sdmmc_mask = ((priv->smplsel & 0x7) << SYSMGR_SDMMC_SMPLSEL_SHIFT) |
|
|
|
|
((priv->drvsel & 0x7) << SYSMGR_SDMMC_DRVSEL_SHIFT);
|
2013-12-31 00:26:14 +00:00
|
|
|
|
|
|
|
/* Disable SDMMC clock. */
|
2019-11-08 02:38:21 +00:00
|
|
|
clrbits_le32(socfpga_get_clkmgr_addr() + CLKMGR_PERPLL_EN,
|
|
|
|
CLKMGR_PERPLLGRP_EN_SDMMCCLK_MASK);
|
2013-12-31 00:26:14 +00:00
|
|
|
|
2015-11-26 01:43:43 +00:00
|
|
|
debug("%s: drvsel %d smplsel %d\n", __func__,
|
|
|
|
priv->drvsel, priv->smplsel);
|
2019-11-08 02:38:20 +00:00
|
|
|
writel(sdmmc_mask, socfpga_get_sysmgr_addr() + SYSMGR_SDMMC);
|
2013-12-31 00:26:14 +00:00
|
|
|
|
|
|
|
debug("%s: SYSMGR_SDMMCGRP_CTRL_REG = 0x%x\n", __func__,
|
2019-11-08 02:38:20 +00:00
|
|
|
readl(socfpga_get_sysmgr_addr() + SYSMGR_SDMMC));
|
2013-12-31 00:26:14 +00:00
|
|
|
|
|
|
|
/* Enable SDMMC clock */
|
2019-11-08 02:38:21 +00:00
|
|
|
setbits_le32(socfpga_get_clkmgr_addr() + CLKMGR_PERPLL_EN,
|
|
|
|
CLKMGR_PERPLLGRP_EN_SDMMCCLK_MASK);
|
2013-12-31 00:26:14 +00:00
|
|
|
}
|
|
|
|
|
2018-08-01 16:28:35 +00:00
|
|
|
static int socfpga_dwmmc_get_clk_rate(struct udevice *dev)
|
2013-12-31 00:26:14 +00:00
|
|
|
{
|
2015-11-30 19:41:04 +00:00
|
|
|
struct dwmci_socfpga_priv_data *priv = dev_get_priv(dev);
|
|
|
|
struct dwmci_host *host = &priv->host;
|
2018-08-01 16:28:35 +00:00
|
|
|
#if CONFIG_IS_ENABLED(CLK)
|
|
|
|
struct clk clk;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clk_get_by_index(dev, 1, &clk);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-09-08 12:08:45 +00:00
|
|
|
|
2018-08-01 16:28:35 +00:00
|
|
|
host->bus_hz = clk_get_rate(&clk);
|
|
|
|
|
|
|
|
clk_free(&clk);
|
|
|
|
#else
|
|
|
|
/* Fixed clock divide by 4 which due to the SDMMC wrapper */
|
|
|
|
host->bus_hz = cm_get_mmc_controller_clk_hz();
|
|
|
|
#endif
|
|
|
|
if (host->bus_hz == 0) {
|
2015-11-30 19:41:04 +00:00
|
|
|
printf("DWMMC: MMC clock is zero!");
|
2015-07-25 08:48:14 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-08-01 16:28:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int socfpga_dwmmc_ofdata_to_platdata(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dwmci_socfpga_priv_data *priv = dev_get_priv(dev);
|
|
|
|
struct dwmci_host *host = &priv->host;
|
|
|
|
int fifo_depth;
|
|
|
|
|
2017-01-17 23:52:55 +00:00
|
|
|
fifo_depth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
|
2015-11-30 19:41:04 +00:00
|
|
|
"fifo-depth", 0);
|
2015-07-25 08:48:14 +00:00
|
|
|
if (fifo_depth < 0) {
|
2015-11-30 19:41:04 +00:00
|
|
|
printf("DWMMC: Can't get FIFO depth\n");
|
2015-07-25 08:48:14 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-11-30 19:41:04 +00:00
|
|
|
host->name = dev->name;
|
2020-07-24 12:42:06 +00:00
|
|
|
host->ioaddr = (void *)devfdt_get_addr(dev);
|
2017-01-17 23:52:55 +00:00
|
|
|
host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
|
2015-11-30 19:41:04 +00:00
|
|
|
"bus-width", 4);
|
2013-12-31 00:26:14 +00:00
|
|
|
host->clksel = socfpga_dwmci_clksel;
|
2015-11-30 19:41:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO(sjg@chromium.org): Remove the need for this hack.
|
|
|
|
* We only have one dwmmc block on gen5 SoCFPGA.
|
|
|
|
*/
|
|
|
|
host->dev_index = 0;
|
2013-12-31 00:26:14 +00:00
|
|
|
host->fifoth_val = MSIZE(0x2) |
|
2015-07-25 08:48:14 +00:00
|
|
|
RX_WMARK(fifo_depth / 2 - 1) | TX_WMARK(fifo_depth / 2);
|
2017-01-17 23:52:55 +00:00
|
|
|
priv->drvsel = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
|
2015-11-30 19:41:04 +00:00
|
|
|
"drvsel", 3);
|
2017-01-17 23:52:55 +00:00
|
|
|
priv->smplsel = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
|
2015-11-30 19:41:04 +00:00
|
|
|
"smplsel", 0);
|
2015-11-26 01:43:43 +00:00
|
|
|
host->priv = priv;
|
2013-12-31 00:26:14 +00:00
|
|
|
|
2015-07-25 08:48:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-30 19:41:04 +00:00
|
|
|
static int socfpga_dwmmc_probe(struct udevice *dev)
|
2015-07-25 08:48:14 +00:00
|
|
|
{
|
2016-07-05 23:10:16 +00:00
|
|
|
#ifdef CONFIG_BLK
|
|
|
|
struct socfpga_dwmci_plat *plat = dev_get_platdata(dev);
|
|
|
|
#endif
|
2015-11-30 19:41:04 +00:00
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
|
|
|
struct dwmci_socfpga_priv_data *priv = dev_get_priv(dev);
|
|
|
|
struct dwmci_host *host = &priv->host;
|
2018-08-01 16:28:35 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = socfpga_dwmmc_get_clk_rate(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-07-05 23:10:16 +00:00
|
|
|
|
2018-06-14 10:45:21 +00:00
|
|
|
socfpga_dwmci_reset(dev);
|
|
|
|
|
2016-07-05 23:10:16 +00:00
|
|
|
#ifdef CONFIG_BLK
|
2016-09-23 10:13:16 +00:00
|
|
|
dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
|
2016-07-05 23:10:16 +00:00
|
|
|
host->mmc = &plat->mmc;
|
|
|
|
#else
|
2015-07-25 08:48:14 +00:00
|
|
|
|
2015-11-30 19:41:04 +00:00
|
|
|
ret = add_dwmci(host, host->bus_hz, 400000);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-07-05 23:10:16 +00:00
|
|
|
#endif
|
|
|
|
host->mmc->priv = &priv->host;
|
2015-11-30 19:41:04 +00:00
|
|
|
upriv->mmc = host->mmc;
|
2016-05-01 19:52:34 +00:00
|
|
|
host->mmc->dev = dev;
|
2015-07-25 08:48:14 +00:00
|
|
|
|
2018-03-06 08:07:23 +00:00
|
|
|
return dwmci_probe(dev);
|
2015-07-25 08:48:14 +00:00
|
|
|
}
|
2015-11-30 19:41:04 +00:00
|
|
|
|
2016-07-05 23:10:16 +00:00
|
|
|
static int socfpga_dwmmc_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BLK
|
|
|
|
struct socfpga_dwmci_plat *plat = dev_get_platdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = dwmci_bind(dev, &plat->mmc, &plat->cfg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-30 19:41:04 +00:00
|
|
|
static const struct udevice_id socfpga_dwmmc_ids[] = {
|
|
|
|
{ .compatible = "altr,socfpga-dw-mshc" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(socfpga_dwmmc_drv) = {
|
|
|
|
.name = "socfpga_dwmmc",
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = socfpga_dwmmc_ids,
|
|
|
|
.ofdata_to_platdata = socfpga_dwmmc_ofdata_to_platdata,
|
2016-10-24 16:24:37 +00:00
|
|
|
.ops = &dm_dwmci_ops,
|
2016-07-05 23:10:16 +00:00
|
|
|
.bind = socfpga_dwmmc_bind,
|
2015-11-30 19:41:04 +00:00
|
|
|
.probe = socfpga_dwmmc_probe,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct dwmci_socfpga_priv_data),
|
2016-10-24 16:24:37 +00:00
|
|
|
.platdata_auto_alloc_size = sizeof(struct socfpga_dwmci_plat),
|
2015-11-30 19:41:04 +00:00
|
|
|
};
|