2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-11-02 02:57:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Atmel Corporation
|
|
|
|
* Wenyou.Yang <wenyou.yang@atmel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-08-10 02:51:05 +00:00
|
|
|
#include <clk.h>
|
|
|
|
#include <dm.h>
|
2015-11-02 02:57:09 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <sdhci.h>
|
|
|
|
#include <asm/arch/clk.h>
|
|
|
|
|
|
|
|
#define ATMEL_SDHC_MIN_FREQ 400000
|
2017-11-17 06:51:27 +00:00
|
|
|
#define ATMEL_SDHC_GCK_RATE 240000000
|
2015-11-02 02:57:09 +00:00
|
|
|
|
2016-08-10 02:51:05 +00:00
|
|
|
#ifndef CONFIG_DM_MMC
|
2015-11-02 02:57:09 +00:00
|
|
|
int atmel_sdhci_init(void *regbase, u32 id)
|
|
|
|
{
|
|
|
|
struct sdhci_host *host;
|
|
|
|
u32 max_clk, min_clk = ATMEL_SDHC_MIN_FREQ;
|
|
|
|
|
|
|
|
host = (struct sdhci_host *)calloc(1, sizeof(struct sdhci_host));
|
|
|
|
if (!host) {
|
|
|
|
printf("%s: sdhci_host calloc failed\n", __func__);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
host->name = "atmel_sdhci";
|
|
|
|
host->ioaddr = regbase;
|
2017-05-11 00:25:12 +00:00
|
|
|
host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD;
|
2015-11-02 02:57:09 +00:00
|
|
|
max_clk = at91_get_periph_generated_clk(id);
|
|
|
|
if (!max_clk) {
|
|
|
|
printf("%s: Failed to get the proper clock\n", __func__);
|
|
|
|
free(host);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2017-01-17 14:58:48 +00:00
|
|
|
host->max_clk = max_clk;
|
2015-11-02 02:57:09 +00:00
|
|
|
|
2017-01-17 14:58:48 +00:00
|
|
|
add_sdhci(host, 0, min_clk);
|
2015-11-02 02:57:09 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-08-10 02:51:05 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
struct atmel_sdhci_plat {
|
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int atmel_sdhci_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
|
|
|
struct atmel_sdhci_plat *plat = dev_get_platdata(dev);
|
|
|
|
struct sdhci_host *host = dev_get_priv(dev);
|
|
|
|
u32 max_clk;
|
|
|
|
struct clk clk;
|
|
|
|
int ret;
|
|
|
|
|
2016-09-27 03:00:34 +00:00
|
|
|
ret = clk_get_by_index(dev, 0, &clk);
|
2016-08-10 02:51:05 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = clk_enable(&clk);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
host->name = dev->name;
|
2017-05-17 23:18:05 +00:00
|
|
|
host->ioaddr = (void *)devfdt_get_addr(dev);
|
2016-08-10 02:51:05 +00:00
|
|
|
|
2017-05-11 00:25:12 +00:00
|
|
|
host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD;
|
2017-01-17 23:52:55 +00:00
|
|
|
host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
|
2016-08-10 02:51:05 +00:00
|
|
|
"bus-width", 4);
|
|
|
|
|
2016-09-27 03:00:34 +00:00
|
|
|
ret = clk_get_by_index(dev, 1, &clk);
|
2016-08-10 02:51:05 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-11-17 06:51:27 +00:00
|
|
|
ret = clk_set_rate(&clk, ATMEL_SDHC_GCK_RATE);
|
2016-08-10 02:51:05 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
max_clk = clk_get_rate(&clk);
|
|
|
|
if (!max_clk)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-01-17 14:58:48 +00:00
|
|
|
host->max_clk = max_clk;
|
2019-08-06 02:47:47 +00:00
|
|
|
host->mmc = &plat->mmc;
|
|
|
|
host->mmc->dev = dev;
|
2017-01-17 14:58:48 +00:00
|
|
|
|
|
|
|
ret = sdhci_setup_cfg(&plat->cfg, host, 0, ATMEL_SDHC_MIN_FREQ);
|
2016-08-10 02:51:05 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
host->mmc->priv = host;
|
|
|
|
upriv->mmc = host->mmc;
|
|
|
|
|
|
|
|
clk_free(&clk);
|
|
|
|
|
|
|
|
return sdhci_probe(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atmel_sdhci_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct atmel_sdhci_plat *plat = dev_get_platdata(dev);
|
|
|
|
|
2016-09-06 13:17:32 +00:00
|
|
|
return sdhci_bind(dev, &plat->mmc, &plat->cfg);
|
2016-08-10 02:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id atmel_sdhci_ids[] = {
|
|
|
|
{ .compatible = "atmel,sama5d2-sdhci" },
|
2019-09-27 13:08:36 +00:00
|
|
|
{ .compatible = "microchip,sam9x60-sdhci" },
|
2016-08-10 02:51:05 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(atmel_sdhci_drv) = {
|
|
|
|
.name = "atmel_sdhci",
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = atmel_sdhci_ids,
|
|
|
|
.ops = &sdhci_ops,
|
|
|
|
.bind = atmel_sdhci_bind,
|
|
|
|
.probe = atmel_sdhci_probe,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct sdhci_host),
|
|
|
|
.platdata_auto_alloc_size = sizeof(struct atmel_sdhci_plat),
|
|
|
|
};
|
|
|
|
#endif
|