tangier_sdhci.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2017 Intel Corporation
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <dm/device.h>
  8. #include <linux/io.h>
  9. #include <linux/sizes.h>
  10. #include <malloc.h>
  11. #include <mmc.h>
  12. #include <sdhci.h>
  13. #define SDHCI_TANGIER_FMAX 200000000
  14. #define SDHCI_TANGIER_FMIN 400000
  15. struct sdhci_tangier_plat {
  16. struct mmc_config cfg;
  17. struct mmc mmc;
  18. void __iomem *ioaddr;
  19. };
  20. static int sdhci_tangier_bind(struct udevice *dev)
  21. {
  22. struct sdhci_tangier_plat *plat = dev_get_platdata(dev);
  23. return sdhci_bind(dev, &plat->mmc, &plat->cfg);
  24. }
  25. static int sdhci_tangier_probe(struct udevice *dev)
  26. {
  27. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  28. struct sdhci_tangier_plat *plat = dev_get_platdata(dev);
  29. struct sdhci_host *host = dev_get_priv(dev);
  30. fdt_addr_t base;
  31. int ret;
  32. base = dev_read_addr(dev);
  33. if (base == FDT_ADDR_T_NONE)
  34. return -EINVAL;
  35. plat->ioaddr = devm_ioremap(dev, base, SZ_1K);
  36. if (!plat->ioaddr)
  37. return -ENOMEM;
  38. host->name = dev->name;
  39. host->ioaddr = plat->ioaddr;
  40. host->quirks = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_BROKEN_VOLTAGE |
  41. SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD;
  42. /* MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195 */
  43. host->voltages = MMC_VDD_165_195;
  44. host->mmc = &plat->mmc;
  45. host->mmc->dev = dev;
  46. ret = sdhci_setup_cfg(&plat->cfg, host, SDHCI_TANGIER_FMAX,
  47. SDHCI_TANGIER_FMIN);
  48. if (ret)
  49. return ret;
  50. upriv->mmc = &plat->mmc;
  51. host->mmc->priv = host;
  52. return sdhci_probe(dev);
  53. }
  54. static const struct udevice_id sdhci_tangier_match[] = {
  55. { .compatible = "intel,sdhci-tangier" },
  56. { /* sentinel */ }
  57. };
  58. U_BOOT_DRIVER(sdhci_tangier) = {
  59. .name = "sdhci-tangier",
  60. .id = UCLASS_MMC,
  61. .of_match = sdhci_tangier_match,
  62. .bind = sdhci_tangier_bind,
  63. .probe = sdhci_tangier_probe,
  64. .ops = &sdhci_ops,
  65. .priv_auto_alloc_size = sizeof(struct sdhci_host),
  66. .platdata_auto_alloc_size = sizeof(struct sdhci_tangier_plat),
  67. };