2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-08-30 22:55:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <clk.h>
|
|
|
|
#include <dm.h>
|
2016-07-04 17:58:27 +00:00
|
|
|
#include <dt-structs.h>
|
2015-08-30 22:55:37 +00:00
|
|
|
#include <dwmmc.h>
|
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2016-07-04 17:58:27 +00:00
|
|
|
#include <mapmem.h>
|
2016-01-22 02:43:34 +00:00
|
|
|
#include <pwrseq.h>
|
2015-08-30 22:55:37 +00:00
|
|
|
#include <syscon.h>
|
2016-01-22 02:43:34 +00:00
|
|
|
#include <asm/gpio.h>
|
2019-03-28 03:01:23 +00:00
|
|
|
#include <asm/arch-rockchip/clock.h>
|
|
|
|
#include <asm/arch-rockchip/periph.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2015-08-30 22:55:37 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
|
2016-05-14 20:03:08 +00:00
|
|
|
struct rockchip_mmc_plat {
|
2016-07-04 17:58:27 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
struct dtd_rockchip_rk3288_dw_mshc dtplat;
|
|
|
|
#endif
|
2016-05-14 20:03:08 +00:00
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
|
|
|
};
|
|
|
|
|
2015-08-30 22:55:37 +00:00
|
|
|
struct rockchip_dwmmc_priv {
|
2016-06-17 15:44:00 +00:00
|
|
|
struct clk clk;
|
2015-08-30 22:55:37 +00:00
|
|
|
struct dwmci_host host;
|
2016-07-04 17:58:26 +00:00
|
|
|
int fifo_depth;
|
|
|
|
bool fifo_mode;
|
|
|
|
u32 minmax[2];
|
2015-08-30 22:55:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static uint rockchip_dwmmc_get_mmc_clk(struct dwmci_host *host, uint freq)
|
|
|
|
{
|
|
|
|
struct udevice *dev = host->priv;
|
|
|
|
struct rockchip_dwmmc_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
ret = clk_set_rate(&priv->clk, freq);
|
2015-08-30 22:55:37 +00:00
|
|
|
if (ret < 0) {
|
2017-06-14 08:31:49 +00:00
|
|
|
debug("%s: err=%d\n", __func__, ret);
|
2015-08-30 22:55:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return freq;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int rockchip_dwmmc_of_to_plat(struct udevice *dev)
|
2015-08-30 22:55:37 +00:00
|
|
|
{
|
|
|
|
struct rockchip_dwmmc_priv *priv = dev_get_priv(dev);
|
|
|
|
struct dwmci_host *host = &priv->host;
|
|
|
|
|
2021-08-07 13:24:06 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(OF_REAL))
|
|
|
|
return 0;
|
|
|
|
|
2015-08-30 22:55:37 +00:00
|
|
|
host->name = dev->name;
|
2017-09-11 20:04:15 +00:00
|
|
|
host->ioaddr = dev_read_addr_ptr(dev);
|
2017-06-07 16:46:00 +00:00
|
|
|
host->buswidth = dev_read_u32_default(dev, "bus-width", 4);
|
2015-08-30 22:55:37 +00:00
|
|
|
host->get_mmc_clk = rockchip_dwmmc_get_mmc_clk;
|
|
|
|
host->priv = dev;
|
|
|
|
|
2015-11-18 01:37:25 +00:00
|
|
|
/* use non-removeable as sdcard and emmc as judgement */
|
2017-06-07 16:46:00 +00:00
|
|
|
if (dev_read_bool(dev, "non-removable"))
|
2016-01-08 06:06:49 +00:00
|
|
|
host->dev_index = 0;
|
|
|
|
else
|
2015-11-18 01:37:25 +00:00
|
|
|
host->dev_index = 1;
|
2015-08-30 22:55:37 +00:00
|
|
|
|
2017-06-07 16:46:00 +00:00
|
|
|
priv->fifo_depth = dev_read_u32_default(dev, "fifo-depth", 0);
|
|
|
|
|
2016-07-04 17:58:26 +00:00
|
|
|
if (priv->fifo_depth < 0)
|
|
|
|
return -EINVAL;
|
2017-06-07 16:46:00 +00:00
|
|
|
priv->fifo_mode = dev_read_bool(dev, "fifo-mode");
|
2017-04-25 07:52:07 +00:00
|
|
|
|
2019-11-19 11:04:01 +00:00
|
|
|
#ifdef CONFIG_SPL_BUILD
|
|
|
|
if (!priv->fifo_mode)
|
|
|
|
priv->fifo_mode = dev_read_bool(dev, "u-boot,spl-fifo-mode");
|
|
|
|
#endif
|
|
|
|
|
2017-04-25 07:52:07 +00:00
|
|
|
/*
|
|
|
|
* 'clock-freq-min-max' is deprecated
|
|
|
|
* (see https://github.com/torvalds/linux/commit/b023030f10573de738bbe8df63d43acab64c9f7b)
|
|
|
|
*/
|
2017-06-07 16:46:00 +00:00
|
|
|
if (dev_read_u32_array(dev, "clock-freq-min-max", priv->minmax, 2)) {
|
|
|
|
int val = dev_read_u32_default(dev, "max-frequency", -EINVAL);
|
2017-04-25 07:52:07 +00:00
|
|
|
|
|
|
|
if (val < 0)
|
|
|
|
return val;
|
|
|
|
|
|
|
|
priv->minmax[0] = 400000; /* 400 kHz */
|
|
|
|
priv->minmax[1] = val;
|
|
|
|
} else {
|
|
|
|
debug("%s: 'clock-freq-min-max' property was deprecated.\n",
|
|
|
|
__func__);
|
|
|
|
}
|
2021-08-07 13:24:06 +00:00
|
|
|
|
2015-08-30 22:55:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rockchip_dwmmc_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct rockchip_mmc_plat *plat = dev_get_plat(dev);
|
2015-08-30 22:55:37 +00:00
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
|
|
|
struct rockchip_dwmmc_priv *priv = dev_get_priv(dev);
|
|
|
|
struct dwmci_host *host = &priv->host;
|
|
|
|
int ret;
|
|
|
|
|
2016-07-04 17:58:27 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
struct dtd_rockchip_rk3288_dw_mshc *dtplat = &plat->dtplat;
|
|
|
|
|
|
|
|
host->name = dev->name;
|
|
|
|
host->ioaddr = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
|
|
|
|
host->buswidth = dtplat->bus_width;
|
|
|
|
host->get_mmc_clk = rockchip_dwmmc_get_mmc_clk;
|
|
|
|
host->priv = dev;
|
|
|
|
host->dev_index = 0;
|
|
|
|
priv->fifo_depth = dtplat->fifo_depth;
|
|
|
|
priv->fifo_mode = 0;
|
2017-06-14 08:31:46 +00:00
|
|
|
priv->minmax[0] = 400000; /* 400 kHz */
|
|
|
|
priv->minmax[1] = dtplat->max_frequency;
|
2016-07-04 17:58:27 +00:00
|
|
|
|
2021-08-07 13:24:09 +00:00
|
|
|
ret = clk_get_by_phandle(dev, dtplat->clocks, &priv->clk);
|
2016-07-04 17:58:27 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
#else
|
2017-06-14 08:31:49 +00:00
|
|
|
ret = clk_get_by_index(dev, 0, &priv->clk);
|
2016-01-22 02:43:38 +00:00
|
|
|
if (ret < 0)
|
2015-08-30 22:55:37 +00:00
|
|
|
return ret;
|
2016-07-04 17:58:27 +00:00
|
|
|
#endif
|
2015-11-17 06:20:24 +00:00
|
|
|
host->fifoth_val = MSIZE(0x2) |
|
2016-07-04 17:58:26 +00:00
|
|
|
RX_WMARK(priv->fifo_depth / 2 - 1) |
|
|
|
|
TX_WMARK(priv->fifo_depth / 2);
|
2015-11-17 06:20:24 +00:00
|
|
|
|
2016-07-04 17:58:26 +00:00
|
|
|
host->fifo_mode = priv->fifo_mode;
|
2015-11-17 06:20:24 +00:00
|
|
|
|
2021-02-16 01:16:54 +00:00
|
|
|
#ifdef CONFIG_MMC_PWRSEQ
|
2016-01-22 02:43:34 +00:00
|
|
|
/* Enable power if needed */
|
2021-02-16 01:16:54 +00:00
|
|
|
ret = mmc_pwrseq_get_power(dev, &plat->cfg);
|
2016-01-22 02:43:34 +00:00
|
|
|
if (!ret) {
|
2021-02-16 01:16:54 +00:00
|
|
|
ret = pwrseq_set_power(plat->cfg.pwr_dev, true);
|
2016-01-22 02:43:34 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
2016-09-23 10:13:16 +00:00
|
|
|
dwmci_setup_cfg(&plat->cfg, host, priv->minmax[1], priv->minmax[0]);
|
2016-05-14 20:03:08 +00:00
|
|
|
host->mmc = &plat->mmc;
|
|
|
|
host->mmc->priv = &priv->host;
|
2016-05-01 19:52:34 +00:00
|
|
|
host->mmc->dev = dev;
|
2015-08-30 22:55:37 +00:00
|
|
|
upriv->mmc = host->mmc;
|
|
|
|
|
2016-06-13 05:30:24 +00:00
|
|
|
return dwmci_probe(dev);
|
2015-08-30 22:55:37 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 20:03:08 +00:00
|
|
|
static int rockchip_dwmmc_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct rockchip_mmc_plat *plat = dev_get_plat(dev);
|
2016-05-14 20:03:08 +00:00
|
|
|
|
2016-09-06 13:17:32 +00:00
|
|
|
return dwmci_bind(dev, &plat->mmc, &plat->cfg);
|
2016-05-14 20:03:08 +00:00
|
|
|
}
|
|
|
|
|
2015-08-30 22:55:37 +00:00
|
|
|
static const struct udevice_id rockchip_dwmmc_ids[] = {
|
2018-09-21 08:59:46 +00:00
|
|
|
{ .compatible = "rockchip,rk2928-dw-mshc" },
|
2015-08-30 22:55:37 +00:00
|
|
|
{ .compatible = "rockchip,rk3288-dw-mshc" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:04 +00:00
|
|
|
U_BOOT_DRIVER(rockchip_rk3288_dw_mshc) = {
|
2016-07-04 17:58:27 +00:00
|
|
|
.name = "rockchip_rk3288_dw_mshc",
|
2015-08-30 22:55:37 +00:00
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = rockchip_dwmmc_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = rockchip_dwmmc_of_to_plat,
|
2016-06-13 05:30:24 +00:00
|
|
|
.ops = &dm_dwmci_ops,
|
2016-05-14 20:03:08 +00:00
|
|
|
.bind = rockchip_dwmmc_bind,
|
2015-08-30 22:55:37 +00:00
|
|
|
.probe = rockchip_dwmmc_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct rockchip_dwmmc_priv),
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct rockchip_mmc_plat),
|
2015-08-30 22:55:37 +00:00
|
|
|
};
|
2016-01-22 02:43:34 +00:00
|
|
|
|
2020-12-29 03:34:57 +00:00
|
|
|
DM_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc)
|
|
|
|
DM_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3368_dw_mshc)
|