hi6220_dw_mmc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2015 Linaro
  4. * peter.griffin <peter.griffin@linaro.org>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <dwmmc.h>
  9. #include <errno.h>
  10. #include <fdtdec.h>
  11. #include <malloc.h>
  12. #include <asm/global_data.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. struct hi6220_dwmmc_plat {
  15. struct mmc_config cfg;
  16. struct mmc mmc;
  17. };
  18. struct hi6220_dwmmc_priv_data {
  19. struct dwmci_host host;
  20. };
  21. struct hisi_mmc_data {
  22. unsigned int clock;
  23. bool use_fifo;
  24. };
  25. static int hi6220_dwmmc_of_to_plat(struct udevice *dev)
  26. {
  27. struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
  28. struct dwmci_host *host = &priv->host;
  29. host->name = dev->name;
  30. host->ioaddr = dev_read_addr_ptr(dev);
  31. host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
  32. "bus-width", 4);
  33. /* use non-removable property for differentiating SD card and eMMC */
  34. if (dev_read_bool(dev, "non-removable"))
  35. host->dev_index = 0;
  36. else
  37. host->dev_index = 1;
  38. host->priv = priv;
  39. return 0;
  40. }
  41. static int hi6220_dwmmc_probe(struct udevice *dev)
  42. {
  43. struct hi6220_dwmmc_plat *plat = dev_get_plat(dev);
  44. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  45. struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
  46. struct dwmci_host *host = &priv->host;
  47. struct hisi_mmc_data *mmc_data;
  48. mmc_data = (struct hisi_mmc_data *)dev_get_driver_data(dev);
  49. /* Use default bus speed due to absence of clk driver */
  50. host->bus_hz = mmc_data->clock;
  51. dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
  52. host->mmc = &plat->mmc;
  53. host->fifo_mode = mmc_data->use_fifo;
  54. host->mmc->priv = &priv->host;
  55. upriv->mmc = host->mmc;
  56. host->mmc->dev = dev;
  57. return dwmci_probe(dev);
  58. }
  59. static int hi6220_dwmmc_bind(struct udevice *dev)
  60. {
  61. struct hi6220_dwmmc_plat *plat = dev_get_plat(dev);
  62. int ret;
  63. ret = dwmci_bind(dev, &plat->mmc, &plat->cfg);
  64. if (ret)
  65. return ret;
  66. return 0;
  67. }
  68. static const struct hisi_mmc_data hi3660_mmc_data = {
  69. .clock = 3200000,
  70. .use_fifo = true,
  71. };
  72. static const struct hisi_mmc_data hi6220_mmc_data = {
  73. .clock = 50000000,
  74. .use_fifo = false,
  75. };
  76. static const struct udevice_id hi6220_dwmmc_ids[] = {
  77. { .compatible = "hisilicon,hi6220-dw-mshc",
  78. .data = (ulong)&hi6220_mmc_data },
  79. { .compatible = "hisilicon,hi3798cv200-dw-mshc",
  80. .data = (ulong)&hi6220_mmc_data },
  81. { .compatible = "hisilicon,hi3660-dw-mshc",
  82. .data = (ulong)&hi3660_mmc_data },
  83. { }
  84. };
  85. U_BOOT_DRIVER(hi6220_dwmmc_drv) = {
  86. .name = "hi6220_dwmmc",
  87. .id = UCLASS_MMC,
  88. .of_match = hi6220_dwmmc_ids,
  89. .of_to_plat = hi6220_dwmmc_of_to_plat,
  90. .ops = &dm_dwmci_ops,
  91. .bind = hi6220_dwmmc_bind,
  92. .probe = hi6220_dwmmc_probe,
  93. .priv_auto = sizeof(struct hi6220_dwmmc_priv_data),
  94. .plat_auto = sizeof(struct hi6220_dwmmc_plat),
  95. };