npcm_sdhci.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2022 Nuvoton Technology Corp.
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <sdhci.h>
  8. #include <clk.h>
  9. #include <power/regulator.h>
  10. #define NPCM_SDHC_MIN_FREQ 400000
  11. struct npcm_sdhci_plat {
  12. struct mmc_config cfg;
  13. struct mmc mmc;
  14. };
  15. static int npcm_sdhci_probe(struct udevice *dev)
  16. {
  17. struct npcm_sdhci_plat *plat = dev_get_plat(dev);
  18. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  19. struct sdhci_host *host = dev_get_priv(dev);
  20. struct udevice *vqmmc_supply;
  21. int vqmmc_uv, ret;
  22. struct clk clk;
  23. host->name = dev->name;
  24. host->ioaddr = dev_read_addr_ptr(dev);
  25. host->max_clk = dev_read_u32_default(dev, "clock-frequency", 0);
  26. ret = clk_get_by_index(dev, 0, &clk);
  27. if (!ret && host->max_clk) {
  28. ret = clk_set_rate(&clk, host->max_clk);
  29. if (ret < 0)
  30. return ret;
  31. }
  32. if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
  33. device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_supply);
  34. vqmmc_uv = dev_read_u32_default(dev, "vqmmc-microvolt", 0);
  35. /* Set IO voltage */
  36. if (vqmmc_supply && vqmmc_uv)
  37. regulator_set_value(vqmmc_supply, vqmmc_uv);
  38. }
  39. host->index = dev_read_u32_default(dev, "index", 0);
  40. ret = mmc_of_parse(dev, &plat->cfg);
  41. if (ret)
  42. return ret;
  43. host->mmc = &plat->mmc;
  44. host->mmc->priv = host;
  45. host->mmc->dev = dev;
  46. upriv->mmc = host->mmc;
  47. ret = sdhci_setup_cfg(&plat->cfg, host, 0, NPCM_SDHC_MIN_FREQ);
  48. if (ret)
  49. return ret;
  50. return sdhci_probe(dev);
  51. }
  52. static int npcm_sdhci_bind(struct udevice *dev)
  53. {
  54. struct npcm_sdhci_plat *plat = dev_get_plat(dev);
  55. return sdhci_bind(dev, &plat->mmc, &plat->cfg);
  56. }
  57. static const struct udevice_id npcm_mmc_ids[] = {
  58. { .compatible = "nuvoton,npcm750-sdhci" },
  59. { .compatible = "nuvoton,npcm845-sdhci" },
  60. { }
  61. };
  62. U_BOOT_DRIVER(npcm_sdhci_drv) = {
  63. .name = "npcm_sdhci",
  64. .id = UCLASS_MMC,
  65. .of_match = npcm_mmc_ids,
  66. .ops = &sdhci_ops,
  67. .bind = npcm_sdhci_bind,
  68. .probe = npcm_sdhci_probe,
  69. .priv_auto = sizeof(struct sdhci_host),
  70. .plat_auto = sizeof(struct npcm_sdhci_plat),
  71. };