rockchip_dw_mmc.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2013 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <clk.h>
  8. #include <dm.h>
  9. #include <dwmmc.h>
  10. #include <errno.h>
  11. #include <syscon.h>
  12. #include <asm/arch/clock.h>
  13. #include <asm/arch/periph.h>
  14. #include <linux/err.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. struct rockchip_dwmmc_priv {
  17. struct udevice *clk;
  18. struct rk3288_grf *grf;
  19. struct dwmci_host host;
  20. };
  21. static uint rockchip_dwmmc_get_mmc_clk(struct dwmci_host *host, uint freq)
  22. {
  23. struct udevice *dev = host->priv;
  24. struct rockchip_dwmmc_priv *priv = dev_get_priv(dev);
  25. int ret;
  26. ret = clk_set_periph_rate(priv->clk, PERIPH_ID_SDMMC0 + host->dev_index,
  27. freq);
  28. if (ret < 0) {
  29. debug("%s: err=%d\n", __func__, ret);
  30. return ret;
  31. }
  32. return freq;
  33. }
  34. static int rockchip_dwmmc_ofdata_to_platdata(struct udevice *dev)
  35. {
  36. struct rockchip_dwmmc_priv *priv = dev_get_priv(dev);
  37. struct dwmci_host *host = &priv->host;
  38. host->name = dev->name;
  39. host->ioaddr = (void *)dev_get_addr(dev);
  40. host->buswidth = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
  41. "bus-width", 4);
  42. host->get_mmc_clk = rockchip_dwmmc_get_mmc_clk;
  43. host->priv = dev;
  44. /* TODO(sjg@chromium.org): Remove the need for this hack */
  45. host->dev_index = (ulong)host->ioaddr == 0xff0f0000 ? 0 : 1;
  46. return 0;
  47. }
  48. static int rockchip_dwmmc_probe(struct udevice *dev)
  49. {
  50. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  51. struct rockchip_dwmmc_priv *priv = dev_get_priv(dev);
  52. struct dwmci_host *host = &priv->host;
  53. u32 minmax[2];
  54. int ret;
  55. priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
  56. if (IS_ERR(priv->grf))
  57. return PTR_ERR(priv->grf);
  58. ret = uclass_get_device(UCLASS_CLK, CLK_GENERAL, &priv->clk);
  59. if (ret)
  60. return ret;
  61. ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset,
  62. "clock-freq-min-max", minmax, 2);
  63. if (!ret)
  64. ret = add_dwmci(host, minmax[1], minmax[0]);
  65. if (ret)
  66. return ret;
  67. upriv->mmc = host->mmc;
  68. return 0;
  69. }
  70. static const struct udevice_id rockchip_dwmmc_ids[] = {
  71. { .compatible = "rockchip,rk3288-dw-mshc" },
  72. { }
  73. };
  74. U_BOOT_DRIVER(rockchip_dwmmc_drv) = {
  75. .name = "rockchip_dwmmc",
  76. .id = UCLASS_MMC,
  77. .of_match = rockchip_dwmmc_ids,
  78. .ofdata_to_platdata = rockchip_dwmmc_ofdata_to_platdata,
  79. .probe = rockchip_dwmmc_probe,
  80. .priv_auto_alloc_size = sizeof(struct rockchip_dwmmc_priv),
  81. };