2019-08-27 14:48:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright 2019 IBM Corp.
|
|
|
|
* Eddie James <eajames@linux.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <clk.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <sdhci.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2022-06-23 09:05:34 +00:00
|
|
|
#include <dm/lists.h>
|
2019-08-27 14:48:03 +00:00
|
|
|
|
|
|
|
struct aspeed_sdhci_plat {
|
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int aspeed_sdhci_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct aspeed_sdhci_plat *plat = dev_get_plat(dev);
|
2019-08-27 14:48:03 +00:00
|
|
|
struct sdhci_host *host = dev_get_priv(dev);
|
|
|
|
u32 max_clk;
|
|
|
|
struct clk clk;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clk_get_by_index(dev, 0, &clk);
|
2022-06-23 09:05:33 +00:00
|
|
|
if (ret) {
|
|
|
|
debug("%s: clock get failed %d\n", __func__, ret);
|
2019-08-27 14:48:03 +00:00
|
|
|
return ret;
|
2022-06-23 09:05:33 +00:00
|
|
|
}
|
2019-08-27 14:48:03 +00:00
|
|
|
|
|
|
|
ret = clk_enable(&clk);
|
2022-06-23 09:05:33 +00:00
|
|
|
if (ret) {
|
|
|
|
debug("%s: clock enable failed %d\n", __func__, ret);
|
2019-08-27 14:48:03 +00:00
|
|
|
goto free;
|
2022-06-23 09:05:33 +00:00
|
|
|
}
|
2019-08-27 14:48:03 +00:00
|
|
|
|
|
|
|
host->name = dev->name;
|
2020-07-17 05:36:46 +00:00
|
|
|
host->ioaddr = dev_read_addr_ptr(dev);
|
2019-08-27 14:48:03 +00:00
|
|
|
|
|
|
|
max_clk = clk_get_rate(&clk);
|
|
|
|
if (IS_ERR_VALUE(max_clk)) {
|
|
|
|
ret = max_clk;
|
2022-06-23 09:05:33 +00:00
|
|
|
debug("%s: clock rate get failed %d\n", __func__, ret);
|
2019-08-27 14:48:03 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
host->max_clk = max_clk;
|
|
|
|
host->mmc = &plat->mmc;
|
|
|
|
host->mmc->dev = dev;
|
|
|
|
host->mmc->priv = host;
|
|
|
|
upriv->mmc = host->mmc;
|
|
|
|
|
|
|
|
ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = sdhci_probe(dev);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
clk_disable(&clk);
|
|
|
|
free:
|
|
|
|
clk_free(&clk);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aspeed_sdhci_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct aspeed_sdhci_plat *plat = dev_get_plat(dev);
|
2019-08-27 14:48:03 +00:00
|
|
|
|
|
|
|
return sdhci_bind(dev, &plat->mmc, &plat->cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id aspeed_sdhci_ids[] = {
|
|
|
|
{ .compatible = "aspeed,ast2400-sdhci" },
|
|
|
|
{ .compatible = "aspeed,ast2500-sdhci" },
|
|
|
|
{ .compatible = "aspeed,ast2600-sdhci" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(aspeed_sdhci_drv) = {
|
|
|
|
.name = "aspeed_sdhci",
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = aspeed_sdhci_ids,
|
|
|
|
.ops = &sdhci_ops,
|
|
|
|
.bind = aspeed_sdhci_bind,
|
|
|
|
.probe = aspeed_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 aspeed_sdhci_plat),
|
2019-08-27 14:48:03 +00:00
|
|
|
};
|
2022-06-23 09:05:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int aspeed_sdc_probe(struct udevice *parent)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id aspeed_sdc_ids[] = {
|
|
|
|
{ .compatible = "aspeed,ast2400-sd-controller" },
|
|
|
|
{ .compatible = "aspeed,ast2500-sd-controller" },
|
|
|
|
{ .compatible = "aspeed,ast2600-sd-controller" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(aspeed_sdc_drv) = {
|
|
|
|
.name = "aspeed_sdc",
|
|
|
|
.id = UCLASS_MISC,
|
|
|
|
.of_match = aspeed_sdc_ids,
|
|
|
|
.probe = aspeed_sdc_probe,
|
|
|
|
};
|