dw_mmc-rockchip.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/clk.h>
  12. #include <linux/mmc/host.h>
  13. #include <linux/mmc/dw_mmc.h>
  14. #include <linux/of_address.h>
  15. #include "dw_mmc.h"
  16. #include "dw_mmc-pltfm.h"
  17. #define RK3288_CLKGEN_DIV 2
  18. static void dw_mci_rockchip_prepare_command(struct dw_mci *host, u32 *cmdr)
  19. {
  20. *cmdr |= SDMMC_CMD_USE_HOLD_REG;
  21. }
  22. static int dw_mci_rk3288_setup_clock(struct dw_mci *host)
  23. {
  24. host->bus_hz /= RK3288_CLKGEN_DIV;
  25. return 0;
  26. }
  27. static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios)
  28. {
  29. int ret;
  30. unsigned int cclkin;
  31. u32 bus_hz;
  32. if (ios->clock == 0)
  33. return;
  34. /*
  35. * cclkin: source clock of mmc controller
  36. * bus_hz: card interface clock generated by CLKGEN
  37. * bus_hz = cclkin / RK3288_CLKGEN_DIV
  38. * ios->clock = (div == 0) ? bus_hz : (bus_hz / (2 * div))
  39. *
  40. * Note: div can only be 0 or 1
  41. * if DDR50 8bit mode(only emmc work in 8bit mode),
  42. * div must be set 1
  43. */
  44. if (ios->bus_width == MMC_BUS_WIDTH_8 &&
  45. ios->timing == MMC_TIMING_MMC_DDR52)
  46. cclkin = 2 * ios->clock * RK3288_CLKGEN_DIV;
  47. else
  48. cclkin = ios->clock * RK3288_CLKGEN_DIV;
  49. ret = clk_set_rate(host->ciu_clk, cclkin);
  50. if (ret)
  51. dev_warn(host->dev, "failed to set rate %uHz\n", ios->clock);
  52. bus_hz = clk_get_rate(host->ciu_clk) / RK3288_CLKGEN_DIV;
  53. if (bus_hz != host->bus_hz) {
  54. host->bus_hz = bus_hz;
  55. /* force dw_mci_setup_bus() */
  56. host->current_speed = 0;
  57. }
  58. }
  59. static int dw_mci_rockchip_init(struct dw_mci *host)
  60. {
  61. /* It is slot 8 on Rockchip SoCs */
  62. host->sdio_id0 = 8;
  63. /* It needs this quirk on all Rockchip SoCs */
  64. host->pdata->quirks |= DW_MCI_QUIRK_BROKEN_DTO;
  65. return 0;
  66. }
  67. /* Common capabilities of RK3288 SoC */
  68. static unsigned long dw_mci_rk3288_dwmmc_caps[4] = {
  69. MMC_CAP_RUNTIME_RESUME, /* emmc */
  70. MMC_CAP_RUNTIME_RESUME, /* sdmmc */
  71. MMC_CAP_RUNTIME_RESUME, /* sdio0 */
  72. MMC_CAP_RUNTIME_RESUME, /* sdio1 */
  73. };
  74. static const struct dw_mci_drv_data rk2928_drv_data = {
  75. .prepare_command = dw_mci_rockchip_prepare_command,
  76. .init = dw_mci_rockchip_init,
  77. };
  78. static const struct dw_mci_drv_data rk3288_drv_data = {
  79. .caps = dw_mci_rk3288_dwmmc_caps,
  80. .prepare_command = dw_mci_rockchip_prepare_command,
  81. .set_ios = dw_mci_rk3288_set_ios,
  82. .setup_clock = dw_mci_rk3288_setup_clock,
  83. .init = dw_mci_rockchip_init,
  84. };
  85. static const struct of_device_id dw_mci_rockchip_match[] = {
  86. { .compatible = "rockchip,rk2928-dw-mshc",
  87. .data = &rk2928_drv_data },
  88. { .compatible = "rockchip,rk3288-dw-mshc",
  89. .data = &rk3288_drv_data },
  90. {},
  91. };
  92. MODULE_DEVICE_TABLE(of, dw_mci_rockchip_match);
  93. static int dw_mci_rockchip_probe(struct platform_device *pdev)
  94. {
  95. const struct dw_mci_drv_data *drv_data;
  96. const struct of_device_id *match;
  97. if (!pdev->dev.of_node)
  98. return -ENODEV;
  99. match = of_match_node(dw_mci_rockchip_match, pdev->dev.of_node);
  100. drv_data = match->data;
  101. return dw_mci_pltfm_register(pdev, drv_data);
  102. }
  103. #ifdef CONFIG_PM_SLEEP
  104. static int dw_mci_rockchip_suspend(struct device *dev)
  105. {
  106. struct dw_mci *host = dev_get_drvdata(dev);
  107. return dw_mci_suspend(host);
  108. }
  109. static int dw_mci_rockchip_resume(struct device *dev)
  110. {
  111. struct dw_mci *host = dev_get_drvdata(dev);
  112. return dw_mci_resume(host);
  113. }
  114. #endif /* CONFIG_PM_SLEEP */
  115. static SIMPLE_DEV_PM_OPS(dw_mci_rockchip_pmops,
  116. dw_mci_rockchip_suspend,
  117. dw_mci_rockchip_resume);
  118. static struct platform_driver dw_mci_rockchip_pltfm_driver = {
  119. .probe = dw_mci_rockchip_probe,
  120. .remove = dw_mci_pltfm_remove,
  121. .driver = {
  122. .name = "dwmmc_rockchip",
  123. .of_match_table = dw_mci_rockchip_match,
  124. .pm = &dw_mci_rockchip_pmops,
  125. },
  126. };
  127. module_platform_driver(dw_mci_rockchip_pltfm_driver);
  128. MODULE_AUTHOR("Addy Ke <addy.ke@rock-chips.com>");
  129. MODULE_DESCRIPTION("Rockchip Specific DW-MSHC Driver Extension");
  130. MODULE_ALIAS("platform:dwmmc_rockchip");
  131. MODULE_LICENSE("GPL v2");