2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-04-23 02:36:28 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2012 SAMSUNG Electronics
|
|
|
|
* Jaehoon Chung <jh80.chung@samsung.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-09-09 09:23:23 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2012-04-23 02:36:28 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <sdhci.h>
|
2014-03-07 13:59:41 +00:00
|
|
|
#include <fdtdec.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2014-03-07 13:59:41 +00:00
|
|
|
#include <asm/gpio.h>
|
2012-04-23 02:36:28 +00:00
|
|
|
#include <asm/arch/mmc.h>
|
2012-08-30 16:24:11 +00:00
|
|
|
#include <asm/arch/clk.h>
|
2014-03-07 13:59:41 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <asm/arch/pinmux.h>
|
2012-04-23 02:36:28 +00:00
|
|
|
|
2016-09-09 09:23:23 +00:00
|
|
|
#ifdef CONFIG_DM_MMC
|
|
|
|
struct s5p_sdhci_plat {
|
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
#endif
|
|
|
|
|
2012-04-23 02:36:28 +00:00
|
|
|
static char *S5P_NAME = "SAMSUNG SDHCI";
|
|
|
|
static void s5p_sdhci_set_control_reg(struct sdhci_host *host)
|
|
|
|
{
|
|
|
|
unsigned long val, ctrl;
|
|
|
|
/*
|
|
|
|
* SELCLKPADDS[17:16]
|
|
|
|
* 00 = 2mA
|
|
|
|
* 01 = 4mA
|
|
|
|
* 10 = 7mA
|
|
|
|
* 11 = 9mA
|
|
|
|
*/
|
|
|
|
sdhci_writel(host, SDHCI_CTRL4_DRIVE_MASK(0x3), SDHCI_CONTROL4);
|
|
|
|
|
|
|
|
val = sdhci_readl(host, SDHCI_CONTROL2);
|
2015-02-23 21:52:22 +00:00
|
|
|
val &= SDHCI_CTRL2_SELBASECLK_MASK(3);
|
2012-04-23 02:36:28 +00:00
|
|
|
|
|
|
|
val |= SDHCI_CTRL2_ENSTAASYNCCLR |
|
|
|
|
SDHCI_CTRL2_ENCMDCNFMSK |
|
|
|
|
SDHCI_CTRL2_ENFBCLKRX |
|
|
|
|
SDHCI_CTRL2_ENCLKOUTHOLD;
|
|
|
|
|
|
|
|
sdhci_writel(host, val, SDHCI_CONTROL2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FCSEL3[31] FCSEL2[23] FCSEL1[15] FCSEL0[7]
|
|
|
|
* FCSel[1:0] : Rx Feedback Clock Delay Control
|
|
|
|
* Inverter delay means10ns delay if SDCLK 50MHz setting
|
|
|
|
* 01 = Delay1 (basic delay)
|
|
|
|
* 11 = Delay2 (basic delay + 2ns)
|
|
|
|
* 00 = Delay3 (inverter delay)
|
|
|
|
* 10 = Delay4 (inverter delay + 2ns)
|
|
|
|
*/
|
2012-08-30 16:24:08 +00:00
|
|
|
val = SDHCI_CTRL3_FCSEL0 | SDHCI_CTRL3_FCSEL1;
|
2012-04-23 02:36:28 +00:00
|
|
|
sdhci_writel(host, val, SDHCI_CONTROL3);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SELBASECLK[5:4]
|
|
|
|
* 00/01 = HCLK
|
|
|
|
* 10 = EPLL
|
|
|
|
* 11 = XTI or XEXTCLK
|
|
|
|
*/
|
|
|
|
ctrl = sdhci_readl(host, SDHCI_CONTROL2);
|
|
|
|
ctrl &= ~SDHCI_CTRL2_SELBASECLK_MASK(0x3);
|
|
|
|
ctrl |= SDHCI_CTRL2_SELBASECLK_MASK(0x2);
|
|
|
|
sdhci_writel(host, ctrl, SDHCI_CONTROL2);
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:30:17 +00:00
|
|
|
static void s5p_set_clock(struct sdhci_host *host, u32 div)
|
|
|
|
{
|
|
|
|
/* ToDo : Use the Clock Framework */
|
|
|
|
set_mmc_clk(host->index, div);
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:30:18 +00:00
|
|
|
static const struct sdhci_ops s5p_sdhci_ops = {
|
|
|
|
.set_clock = &s5p_set_clock,
|
|
|
|
.set_control_reg = &s5p_sdhci_set_control_reg,
|
|
|
|
};
|
|
|
|
|
2014-05-16 04:59:59 +00:00
|
|
|
static int s5p_sdhci_core_init(struct sdhci_host *host)
|
2012-04-23 02:36:28 +00:00
|
|
|
{
|
|
|
|
host->name = S5P_NAME;
|
|
|
|
|
2012-08-30 16:24:08 +00:00
|
|
|
host->quirks = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_BROKEN_VOLTAGE |
|
2016-07-12 12:18:47 +00:00
|
|
|
SDHCI_QUIRK_32BIT_DMA_ADDR |
|
2013-07-19 08:44:49 +00:00
|
|
|
SDHCI_QUIRK_WAIT_SEND_CMD | SDHCI_QUIRK_USE_WIDE8;
|
2017-01-17 14:58:48 +00:00
|
|
|
host->max_clk = 52000000;
|
2012-04-23 02:36:28 +00:00
|
|
|
host->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
|
2016-12-30 06:30:18 +00:00
|
|
|
host->ops = &s5p_sdhci_ops;
|
2012-04-23 02:36:28 +00:00
|
|
|
|
2014-05-16 04:59:59 +00:00
|
|
|
if (host->bus_width == 8)
|
2013-07-19 08:44:49 +00:00
|
|
|
host->host_caps |= MMC_MODE_8BIT;
|
2012-04-23 02:36:28 +00:00
|
|
|
|
2016-09-09 09:23:23 +00:00
|
|
|
#ifndef CONFIG_BLK
|
2017-01-17 14:58:48 +00:00
|
|
|
return add_sdhci(host, 0, 400000);
|
2016-09-09 09:23:23 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2012-04-23 02:36:28 +00:00
|
|
|
}
|
2014-03-07 13:59:41 +00:00
|
|
|
|
2014-05-16 04:59:59 +00:00
|
|
|
int s5p_sdhci_init(u32 regbase, int index, int bus_width)
|
|
|
|
{
|
2015-10-05 11:47:50 +00:00
|
|
|
struct sdhci_host *host = calloc(1, sizeof(struct sdhci_host));
|
2014-05-16 04:59:59 +00:00
|
|
|
if (!host) {
|
2015-10-05 11:47:50 +00:00
|
|
|
printf("sdhci__host allocation fail!\n");
|
2016-09-25 23:10:02 +00:00
|
|
|
return -ENOMEM;
|
2014-05-16 04:59:59 +00:00
|
|
|
}
|
|
|
|
host->ioaddr = (void *)regbase;
|
|
|
|
host->index = index;
|
|
|
|
host->bus_width = bus_width;
|
|
|
|
|
|
|
|
return s5p_sdhci_core_init(host);
|
|
|
|
}
|
|
|
|
|
2014-03-07 13:59:41 +00:00
|
|
|
static int do_sdhci_init(struct sdhci_host *host)
|
|
|
|
{
|
2015-10-05 11:47:53 +00:00
|
|
|
int dev_id, flag, ret;
|
2014-03-07 13:59:41 +00:00
|
|
|
|
|
|
|
flag = host->bus_width == 8 ? PINMUX_FLAG_8BIT_MODE : PINMUX_FLAG_NONE;
|
|
|
|
dev_id = host->index + PERIPH_ID_SDMMC0;
|
|
|
|
|
2015-10-28 14:41:50 +00:00
|
|
|
ret = exynos_pinmux_config(dev_id, flag);
|
|
|
|
if (ret) {
|
|
|
|
printf("external SD not configured\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-06 03:05:38 +00:00
|
|
|
if (dm_gpio_is_valid(&host->pwr_gpio)) {
|
|
|
|
dm_gpio_set_value(&host->pwr_gpio, 1);
|
2015-10-05 11:47:53 +00:00
|
|
|
ret = exynos_pinmux_config(dev_id, flag);
|
|
|
|
if (ret) {
|
2014-03-07 13:59:41 +00:00
|
|
|
debug("MMC not configured\n");
|
2015-10-05 11:47:53 +00:00
|
|
|
return ret;
|
2014-03-07 13:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-06 03:05:38 +00:00
|
|
|
if (dm_gpio_is_valid(&host->cd_gpio)) {
|
2015-10-05 11:47:53 +00:00
|
|
|
ret = dm_gpio_get_value(&host->cd_gpio);
|
|
|
|
if (ret) {
|
|
|
|
debug("no SD card detected (%d)\n", ret);
|
2014-03-07 13:59:41 +00:00
|
|
|
return -ENODEV;
|
2015-10-05 11:47:53 +00:00
|
|
|
}
|
2014-03-07 13:59:41 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 04:59:59 +00:00
|
|
|
return s5p_sdhci_core_init(host);
|
2014-03-07 13:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sdhci_get_config(const void *blob, int node, struct sdhci_host *host)
|
|
|
|
{
|
|
|
|
int bus_width, dev_id;
|
|
|
|
unsigned int base;
|
|
|
|
|
|
|
|
/* Get device id */
|
|
|
|
dev_id = pinmux_decode_periph_id(blob, node);
|
2016-11-24 06:05:51 +00:00
|
|
|
if (dev_id < PERIPH_ID_SDMMC0 || dev_id > PERIPH_ID_SDMMC3) {
|
2014-03-07 13:59:41 +00:00
|
|
|
debug("MMC: Can't get device id\n");
|
2016-09-25 23:10:02 +00:00
|
|
|
return -EINVAL;
|
2014-03-07 13:59:41 +00:00
|
|
|
}
|
|
|
|
host->index = dev_id - PERIPH_ID_SDMMC0;
|
|
|
|
|
|
|
|
/* Get bus width */
|
|
|
|
bus_width = fdtdec_get_int(blob, node, "samsung,bus-width", 0);
|
|
|
|
if (bus_width <= 0) {
|
|
|
|
debug("MMC: Can't get bus-width\n");
|
2016-09-25 23:10:02 +00:00
|
|
|
return -EINVAL;
|
2014-03-07 13:59:41 +00:00
|
|
|
}
|
|
|
|
host->bus_width = bus_width;
|
|
|
|
|
|
|
|
/* Get the base address from the device node */
|
|
|
|
base = fdtdec_get_addr(blob, node, "reg");
|
|
|
|
if (!base) {
|
|
|
|
debug("MMC: Can't get base address\n");
|
2016-09-25 23:10:02 +00:00
|
|
|
return -EINVAL;
|
2014-03-07 13:59:41 +00:00
|
|
|
}
|
|
|
|
host->ioaddr = (void *)base;
|
|
|
|
|
2017-05-31 03:47:09 +00:00
|
|
|
gpio_request_by_name_nodev(offset_to_ofnode(node), "pwr-gpios", 0,
|
|
|
|
&host->pwr_gpio, GPIOD_IS_OUT);
|
|
|
|
gpio_request_by_name_nodev(offset_to_ofnode(node), "cd-gpios", 0,
|
|
|
|
&host->cd_gpio, GPIOD_IS_IN);
|
2014-03-07 13:59:41 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-09 09:23:23 +00:00
|
|
|
#ifdef CONFIG_DM_MMC
|
|
|
|
static int s5p_sdhci_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct s5p_sdhci_plat *plat = dev_get_plat(dev);
|
2016-09-09 09:23:23 +00:00
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
|
|
|
struct sdhci_host *host = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
2017-01-17 23:52:55 +00:00
|
|
|
ret = sdhci_get_config(gd->fdt_blob, dev_of_offset(dev), host);
|
2016-09-09 09:23:23 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = do_sdhci_init(host);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-01-16 15:25:33 +00:00
|
|
|
ret = mmc_of_parse(dev, &plat->cfg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-08-06 02:47:59 +00:00
|
|
|
host->mmc = &plat->mmc;
|
|
|
|
host->mmc->dev = dev;
|
2020-01-16 15:25:33 +00:00
|
|
|
|
2017-01-17 14:58:48 +00:00
|
|
|
ret = sdhci_setup_cfg(&plat->cfg, host, 0, 400000);
|
2016-09-09 09:23:23 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
host->mmc->priv = host;
|
|
|
|
upriv->mmc = host->mmc;
|
|
|
|
|
|
|
|
return sdhci_probe(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s5p_sdhci_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct s5p_sdhci_plat *plat = dev_get_plat(dev);
|
2016-09-09 09:23:23 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = sdhci_bind(dev, &plat->mmc, &plat->cfg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id s5p_sdhci_ids[] = {
|
|
|
|
{ .compatible = "samsung,exynos4412-sdhci"},
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(s5p_sdhci_drv) = {
|
|
|
|
.name = "s5p_sdhci",
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = s5p_sdhci_ids,
|
|
|
|
.bind = s5p_sdhci_bind,
|
|
|
|
.ops = &sdhci_ops,
|
|
|
|
.probe = s5p_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 s5p_sdhci_plat),
|
2016-09-09 09:23:23 +00:00
|
|
|
};
|
|
|
|
#endif /* CONFIG_DM_MMC */
|