2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-07-18 09:00:58 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2016 Fuzhou Rockchip Electronics Co., Ltd
|
|
|
|
*
|
|
|
|
* Rockchip SD Host Controller Interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2017-02-13 09:38:57 +00:00
|
|
|
#include <dt-structs.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2016-07-18 09:00:58 +00:00
|
|
|
#include <malloc.h>
|
2017-02-13 09:38:57 +00:00
|
|
|
#include <mapmem.h>
|
2016-07-18 09:00:58 +00:00
|
|
|
#include <sdhci.h>
|
2016-12-28 03:32:35 +00:00
|
|
|
#include <clk.h>
|
2016-07-18 09:00:58 +00:00
|
|
|
|
|
|
|
/* 400KHz is max freq for card ID etc. Use that as min */
|
|
|
|
#define EMMC_MIN_FREQ 400000
|
|
|
|
|
|
|
|
struct rockchip_sdhc_plat {
|
2017-02-13 09:38:57 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
struct dtd_rockchip_rk3399_sdhci_5_1 dtplat;
|
|
|
|
#endif
|
2016-07-18 09:00:58 +00:00
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rockchip_sdhc {
|
|
|
|
struct sdhci_host host;
|
|
|
|
void *base;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int arasan_sdhci_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct rockchip_sdhc_plat *plat = dev_get_plat(dev);
|
2016-07-18 09:00:58 +00:00
|
|
|
struct rockchip_sdhc *prv = dev_get_priv(dev);
|
|
|
|
struct sdhci_host *host = &prv->host;
|
2016-12-28 03:32:35 +00:00
|
|
|
int max_frequency, ret;
|
|
|
|
struct clk clk;
|
|
|
|
|
2017-02-13 09:38:57 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
struct dtd_rockchip_rk3399_sdhci_5_1 *dtplat = &plat->dtplat;
|
2016-12-28 03:32:35 +00:00
|
|
|
|
2017-02-13 09:38:57 +00:00
|
|
|
host->name = dev->name;
|
2017-09-07 03:20:50 +00:00
|
|
|
host->ioaddr = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
|
2017-02-13 09:38:57 +00:00
|
|
|
max_frequency = dtplat->max_frequency;
|
2020-06-25 04:10:13 +00:00
|
|
|
ret = clk_get_by_driver_info(dev, dtplat->clocks, &clk);
|
2017-02-13 09:38:57 +00:00
|
|
|
#else
|
2017-06-07 16:46:00 +00:00
|
|
|
max_frequency = dev_read_u32_default(dev, "max-frequency", 0);
|
2016-12-28 03:32:35 +00:00
|
|
|
ret = clk_get_by_index(dev, 0, &clk);
|
2017-02-13 09:38:57 +00:00
|
|
|
#endif
|
2016-12-28 03:32:35 +00:00
|
|
|
if (!ret) {
|
|
|
|
ret = clk_set_rate(&clk, max_frequency);
|
|
|
|
if (IS_ERR_VALUE(ret))
|
|
|
|
printf("%s clk set rate fail!\n", __func__);
|
|
|
|
} else {
|
|
|
|
printf("%s fail to get clk\n", __func__);
|
|
|
|
}
|
2016-07-18 09:00:58 +00:00
|
|
|
|
|
|
|
host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD;
|
2017-01-17 14:58:48 +00:00
|
|
|
host->max_clk = max_frequency;
|
2018-03-26 17:59:10 +00:00
|
|
|
/*
|
|
|
|
* The sdhci-driver only supports 4bit and 8bit, as sdhci_setup_cfg
|
|
|
|
* doesn't allow us to clear MMC_MODE_4BIT. Consequently, we don't
|
|
|
|
* check for other bus-width values.
|
|
|
|
*/
|
|
|
|
if (host->bus_width == 8)
|
|
|
|
host->host_caps |= MMC_MODE_8BIT;
|
2016-07-18 09:00:58 +00:00
|
|
|
|
|
|
|
host->mmc = &plat->mmc;
|
|
|
|
host->mmc->priv = &prv->host;
|
|
|
|
host->mmc->dev = dev;
|
|
|
|
upriv->mmc = host->mmc;
|
|
|
|
|
2019-07-19 10:01:11 +00:00
|
|
|
ret = sdhci_setup_cfg(&plat->cfg, host, 0, EMMC_MIN_FREQ);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-07-18 09:00:58 +00:00
|
|
|
return sdhci_probe(dev);
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int arasan_sdhci_of_to_plat(struct udevice *dev)
|
2016-07-18 09:00:58 +00:00
|
|
|
{
|
2017-02-13 09:38:57 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
|
2016-07-18 09:00:58 +00:00
|
|
|
struct sdhci_host *host = dev_get_priv(dev);
|
|
|
|
|
|
|
|
host->name = dev->name;
|
2017-09-11 20:04:21 +00:00
|
|
|
host->ioaddr = dev_read_addr_ptr(dev);
|
2018-03-26 17:59:10 +00:00
|
|
|
host->bus_width = dev_read_u32_default(dev, "bus-width", 4);
|
2017-02-13 09:38:57 +00:00
|
|
|
#endif
|
2016-07-18 09:00:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rockchip_sdhci_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct rockchip_sdhc_plat *plat = dev_get_plat(dev);
|
2016-07-18 09:00:58 +00:00
|
|
|
|
2016-09-06 13:17:32 +00:00
|
|
|
return sdhci_bind(dev, &plat->mmc, &plat->cfg);
|
2016-07-18 09:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id arasan_sdhci_ids[] = {
|
|
|
|
{ .compatible = "arasan,sdhci-5.1" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(arasan_sdhci_drv) = {
|
2017-02-13 09:38:57 +00:00
|
|
|
.name = "rockchip_rk3399_sdhci_5_1",
|
2016-07-18 09:00:58 +00:00
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = arasan_sdhci_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = arasan_sdhci_of_to_plat,
|
2016-07-18 09:00:58 +00:00
|
|
|
.ops = &sdhci_ops,
|
|
|
|
.bind = rockchip_sdhci_bind,
|
|
|
|
.probe = arasan_sdhci_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct rockchip_sdhc),
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct rockchip_sdhc_plat),
|
2016-07-18 09:00:58 +00:00
|
|
|
};
|