+// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2012 SAMSUNG Electronics
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <dwmmc.h>
#include <fdtdec.h>
-#include <libfdt.h>
+#include <asm/global_data.h>
+#include <linux/libfdt.h>
#include <malloc.h>
#include <errno.h>
#include <asm/arch/dwmmc.h>
#include <asm/arch/pinmux.h>
#include <asm/arch/power.h>
#include <asm/gpio.h>
+#include <linux/printk.h>
#define DWMMC_MAX_CH_NUM 4
#define DWMMC_MAX_FREQ 52000000
* Function used as callback function to initialise the
* CLKSEL register for every mmc channel.
*/
-static void exynos_dwmci_clksel(struct dwmci_host *host)
+static int exynos_dwmci_clksel(struct dwmci_host *host)
{
+#ifdef CONFIG_DM_MMC
+ struct dwmci_exynos_priv_data *priv =
+ container_of(host, struct dwmci_exynos_priv_data, host);
+#else
struct dwmci_exynos_priv_data *priv = host->priv;
-
+#endif
dwmci_writel(host, DWMCI_CLKSEL, priv->sdr_timing);
+
+ return 0;
}
unsigned int exynos_dwmci_get_clk(struct dwmci_host *host, uint freq)
return 0;
}
-static struct dwmci_host dwmci_host[DWMMC_MAX_CH_NUM];
-
static int do_dwmci_init(struct dwmci_host *host)
{
int flag, err;
}
static int exynos_dwmci_get_config(const void *blob, int node,
- struct dwmci_host *host)
+ struct dwmci_host *host,
+ struct dwmci_exynos_priv_data *priv)
{
int err = 0;
u32 base, timing[3];
- struct dwmci_exynos_priv_data *priv;
-
- priv = malloc(sizeof(struct dwmci_exynos_priv_data));
- if (!priv) {
- error("dwmci_exynos_priv_data malloc fail!\n");
- return -ENOMEM;
- }
/* Extract device id for each mmc channel */
host->dev_id = pinmux_decode_periph_id(blob, node);
host->bus_hz = fdtdec_get_int(blob, node, "bus_hz", 0);
host->div = fdtdec_get_int(blob, node, "div", 0);
- host->priv = priv;
-
- return 0;
-}
-
-static int exynos_dwmci_process_node(const void *blob,
- int node_list[], int count)
-{
- struct dwmci_host *host;
- int i, node, err;
-
- for (i = 0; i < count; i++) {
- node = node_list[i];
- if (node <= 0)
- continue;
- host = &dwmci_host[i];
- err = exynos_dwmci_get_config(blob, node, host);
- if (err) {
- printf("%s: failed to decode dev %d\n", __func__, i);
- return err;
- }
-
- do_dwmci_init(host);
- }
return 0;
}
-int exynos_dwmmc_init(const void *blob)
-{
- int node_list[DWMMC_MAX_CH_NUM];
- int boot_dev_node;
- int err = 0, count;
-
- count = fdtdec_find_aliases_for_id(blob, "mmc",
- COMPAT_SAMSUNG_EXYNOS_DWMMC, node_list,
- DWMMC_MAX_CH_NUM);
-
- /* For DWMMC always set boot device as mmc 0 */
- if (count >= 3 && get_boot_mode() == BOOT_MODE_SD) {
- boot_dev_node = node_list[2];
- node_list[2] = node_list[0];
- node_list[0] = boot_dev_node;
- }
-
- err = exynos_dwmci_process_node(blob, node_list, count);
-
- return err;
-}
-
#ifdef CONFIG_DM_MMC
static int exynos_dwmmc_probe(struct udevice *dev)
{
- struct exynos_mmc_plat *plat = dev_get_platdata(dev);
+ struct exynos_mmc_plat *plat = dev_get_plat(dev);
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
struct dwmci_exynos_priv_data *priv = dev_get_priv(dev);
struct dwmci_host *host = &priv->host;
int err;
- err = exynos_dwmci_get_config(gd->fdt_blob, dev->of_offset, host);
+ err = exynos_dwmci_get_config(gd->fdt_blob, dev_of_offset(dev), host,
+ priv);
if (err)
return err;
err = do_dwmci_init(host);
if (err)
return err;
- dwmci_setup_cfg(&plat->cfg, host->name, host->buswidth, host->caps,
- DWMMC_MAX_FREQ, DWMMC_MIN_FREQ);
+ dwmci_setup_cfg(&plat->cfg, host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ);
host->mmc = &plat->mmc;
host->mmc->priv = &priv->host;
host->priv = dev;
static int exynos_dwmmc_bind(struct udevice *dev)
{
- struct exynos_mmc_plat *plat = dev_get_platdata(dev);
- int ret;
+ struct exynos_mmc_plat *plat = dev_get_plat(dev);
- ret = dwmci_bind(dev, &plat->mmc, &plat->cfg);
- if (ret)
- return ret;
-
- return 0;
+ return dwmci_bind(dev, &plat->mmc, &plat->cfg);
}
static const struct udevice_id exynos_dwmmc_ids[] = {
{ .compatible = "samsung,exynos4412-dw-mshc" },
+ { .compatible = "samsung,exynos-dwmmc" },
{ }
};
.bind = exynos_dwmmc_bind,
.ops = &dm_dwmci_ops,
.probe = exynos_dwmmc_probe,
- .priv_auto_alloc_size = sizeof(struct dwmci_exynos_priv_data),
- .platdata_auto_alloc_size = sizeof(struct exynos_mmc_plat),
+ .priv_auto = sizeof(struct dwmci_exynos_priv_data),
+ .plat_auto = sizeof(struct exynos_mmc_plat),
};
#endif