1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2022 Nuvoton Technology Corp.
9 #include <power/regulator.h>
11 #define NPCM_SDHC_MIN_FREQ 400000
13 struct npcm_sdhci_plat {
14 struct mmc_config cfg;
18 static int npcm_sdhci_probe(struct udevice *dev)
20 struct npcm_sdhci_plat *plat = dev_get_plat(dev);
21 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
22 struct sdhci_host *host = dev_get_priv(dev);
23 struct udevice *vqmmc_supply;
27 host->name = dev->name;
28 host->ioaddr = dev_read_addr_ptr(dev);
29 host->max_clk = dev_read_u32_default(dev, "clock-frequency", 0);
31 ret = clk_get_by_index(dev, 0, &clk);
32 if (!ret && host->max_clk) {
33 ret = clk_set_rate(&clk, host->max_clk);
38 if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
39 device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_supply);
40 vqmmc_uv = dev_read_u32_default(dev, "vqmmc-microvolt", 0);
42 if (vqmmc_supply && vqmmc_uv)
43 regulator_set_value(vqmmc_supply, vqmmc_uv);
46 host->index = dev_read_u32_default(dev, "index", 0);
47 ret = mmc_of_parse(dev, &plat->cfg);
51 host->mmc = &plat->mmc;
52 host->mmc->priv = host;
54 upriv->mmc = host->mmc;
56 ret = sdhci_setup_cfg(&plat->cfg, host, 0, NPCM_SDHC_MIN_FREQ);
60 return sdhci_probe(dev);
63 static int npcm_sdhci_bind(struct udevice *dev)
65 struct npcm_sdhci_plat *plat = dev_get_plat(dev);
67 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
70 static const struct udevice_id npcm_mmc_ids[] = {
71 { .compatible = "nuvoton,npcm750-sdhci" },
72 { .compatible = "nuvoton,npcm845-sdhci" },
76 U_BOOT_DRIVER(npcm_sdhci_drv) = {
79 .of_match = npcm_mmc_ids,
81 .bind = npcm_sdhci_bind,
82 .probe = npcm_sdhci_probe,
83 .priv_auto = sizeof(struct sdhci_host),
84 .plat_auto = sizeof(struct npcm_sdhci_plat),