f_sdh30.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Socionext F_SDH30 eMMC driver
  4. * Copyright 2021 Linaro Ltd.
  5. * Copyright 2021 Socionext, Inc.
  6. */
  7. #include <common.h>
  8. #include <clk.h>
  9. #include <dm.h>
  10. #include <malloc.h>
  11. #include <sdhci.h>
  12. struct f_sdh30_plat {
  13. struct mmc_config cfg;
  14. struct mmc mmc;
  15. };
  16. DECLARE_GLOBAL_DATA_PTR;
  17. static int f_sdh30_sdhci_probe(struct udevice *dev)
  18. {
  19. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  20. struct f_sdh30_plat *plat = dev_get_plat(dev);
  21. struct sdhci_host *host = dev_get_priv(dev);
  22. int ret;
  23. ret = mmc_of_parse(dev, &plat->cfg);
  24. if (ret)
  25. return ret;
  26. host->mmc = &plat->mmc;
  27. host->mmc->dev = dev;
  28. host->mmc->priv = host;
  29. ret = sdhci_setup_cfg(&plat->cfg, host, 200000000, 400000);
  30. if (ret)
  31. return ret;
  32. upriv->mmc = host->mmc;
  33. mmc_set_clock(host->mmc, host->mmc->cfg->f_min, MMC_CLK_ENABLE);
  34. return sdhci_probe(dev);
  35. }
  36. static int f_sdh30_of_to_plat(struct udevice *dev)
  37. {
  38. struct sdhci_host *host = dev_get_priv(dev);
  39. host->name = strdup(dev->name);
  40. host->ioaddr = dev_read_addr_ptr(dev);
  41. host->bus_width = dev_read_u32_default(dev, "bus-width", 4);
  42. host->index = dev_read_u32_default(dev, "index", 0);
  43. return 0;
  44. }
  45. static int f_sdh30_bind(struct udevice *dev)
  46. {
  47. struct f_sdh30_plat *plat = dev_get_plat(dev);
  48. return sdhci_bind(dev, &plat->mmc, &plat->cfg);
  49. }
  50. static const struct udevice_id f_sdh30_mmc_ids[] = {
  51. { .compatible = "fujitsu,mb86s70-sdhci-3.0" },
  52. { }
  53. };
  54. U_BOOT_DRIVER(f_sdh30_drv) = {
  55. .name = "f_sdh30_sdhci",
  56. .id = UCLASS_MMC,
  57. .of_match = f_sdh30_mmc_ids,
  58. .of_to_plat = f_sdh30_of_to_plat,
  59. .ops = &sdhci_ops,
  60. .bind = f_sdh30_bind,
  61. .probe = f_sdh30_sdhci_probe,
  62. .priv_auto = sizeof(struct sdhci_host),
  63. .plat_auto = sizeof(struct f_sdh30_plat),
  64. };