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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rockchip_dwmmc_ofdata_to_platdata(struct udevice *dev)
|
|
|
|
{
|
2016-07-04 17:58:27 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
|
2015-08-30 22:55:37 +00:00
|
|
|
struct rockchip_dwmmc_priv *priv = dev_get_priv(dev);
|
|
|
|
struct dwmci_host *host = &priv->host;
|
|
|
|
|
|
|
|
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__);
|
|
|
|
}
|
2016-07-04 17:58:27 +00:00
|
|
|
#endif
|
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;
|
2016-01-22 02:43:34 +00:00
|
|
|
struct udevice *pwr_dev __maybe_unused;
|
2015-08-30 22:55:37 +00:00
|
|
|
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
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
ret = clk_get_by_driver_info(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
|
|
|
|
2016-01-22 02:43:34 +00:00
|
|
|
#ifdef CONFIG_PWRSEQ
|
|
|
|
/* Enable power if needed */
|
|
|
|
ret = uclass_get_device_by_phandle(UCLASS_PWRSEQ, dev, "mmc-pwrseq",
|
|
|
|
&pwr_dev);
|
|
|
|
if (!ret) {
|
|
|
|
ret = pwrseq_set_power(pwr_dev, true);
|
|
|
|
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,
|
|
|
|
.ofdata_to_platdata = rockchip_dwmmc_ofdata_to_platdata,
|
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-06-25 04:10:06 +00:00
|
|
|
U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc)
|
|
|
|
U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3368_dw_mshc)
|
|
|
|
|
2016-01-22 02:43:34 +00:00
|
|
|
#ifdef CONFIG_PWRSEQ
|
|
|
|
static int rockchip_dwmmc_pwrseq_set_power(struct udevice *dev, bool enable)
|
|
|
|
{
|
|
|
|
struct gpio_desc reset;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = gpio_request_by_name(dev, "reset-gpios", 0, &reset, GPIOD_IS_OUT);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
dm_gpio_set_value(&reset, 1);
|
|
|
|
udelay(1);
|
|
|
|
dm_gpio_set_value(&reset, 0);
|
|
|
|
udelay(200);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct pwrseq_ops rockchip_dwmmc_pwrseq_ops = {
|
|
|
|
.set_power = rockchip_dwmmc_pwrseq_set_power,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id rockchip_dwmmc_pwrseq_ids[] = {
|
|
|
|
{ .compatible = "mmc-pwrseq-emmc" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(rockchip_dwmmc_pwrseq_drv) = {
|
|
|
|
.name = "mmc_pwrseq_emmc",
|
|
|
|
.id = UCLASS_PWRSEQ,
|
|
|
|
.of_match = rockchip_dwmmc_pwrseq_ids,
|
|
|
|
.ops = &rockchip_dwmmc_pwrseq_ops,
|
|
|
|
};
|
|
|
|
#endif
|