dw_mmc-rockchip.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /*
  33. * cclkin: source clock of mmc controller
  34. * bus_hz: card interface clock generated by CLKGEN
  35. * bus_hz = cclkin / RK3288_CLKGEN_DIV
  36. * ios->clock = (div == 0) ? bus_hz : (bus_hz / (2 * div))
  37. *
  38. * Note: div can only be 0 or 1
  39. * if DDR50 8bit mode(only emmc work in 8bit mode),
  40. * div must be set 1
  41. */
  42. if (ios->bus_width == MMC_BUS_WIDTH_8 &&
  43. ios->timing == MMC_TIMING_MMC_DDR52)
  44. cclkin = 2 * ios->clock * RK3288_CLKGEN_DIV;
  45. else
  46. cclkin = ios->clock * RK3288_CLKGEN_DIV;
  47. ret = clk_set_rate(host->ciu_clk, cclkin);
  48. if (ret)
  49. dev_warn(host->dev, "failed to set rate %uHz\n", ios->clock);
  50. bus_hz = clk_get_rate(host->ciu_clk) / RK3288_CLKGEN_DIV;
  51. if (bus_hz != host->bus_hz) {
  52. host->bus_hz = bus_hz;
  53. /* force dw_mci_setup_bus() */
  54. host->current_speed = 0;
  55. }
  56. }
  57. static const struct dw_mci_drv_data rk2928_drv_data = {
  58. .prepare_command = dw_mci_rockchip_prepare_command,
  59. };
  60. static const struct dw_mci_drv_data rk3288_drv_data = {
  61. .prepare_command = dw_mci_rockchip_prepare_command,
  62. .set_ios = dw_mci_rk3288_set_ios,
  63. .setup_clock = dw_mci_rk3288_setup_clock,
  64. };
  65. static const struct of_device_id dw_mci_rockchip_match[] = {
  66. { .compatible = "rockchip,rk2928-dw-mshc",
  67. .data = &rk2928_drv_data },
  68. { .compatible = "rockchip,rk3288-dw-mshc",
  69. .data = &rk3288_drv_data },
  70. {},
  71. };
  72. MODULE_DEVICE_TABLE(of, dw_mci_rockchip_match);
  73. static int dw_mci_rockchip_probe(struct platform_device *pdev)
  74. {
  75. const struct dw_mci_drv_data *drv_data;
  76. const struct of_device_id *match;
  77. if (!pdev->dev.of_node)
  78. return -ENODEV;
  79. match = of_match_node(dw_mci_rockchip_match, pdev->dev.of_node);
  80. drv_data = match->data;
  81. return dw_mci_pltfm_register(pdev, drv_data);
  82. }
  83. #ifdef CONFIG_PM_SLEEP
  84. static int dw_mci_rockchip_suspend(struct device *dev)
  85. {
  86. struct dw_mci *host = dev_get_drvdata(dev);
  87. return dw_mci_suspend(host);
  88. }
  89. static int dw_mci_rockchip_resume(struct device *dev)
  90. {
  91. struct dw_mci *host = dev_get_drvdata(dev);
  92. return dw_mci_resume(host);
  93. }
  94. #endif /* CONFIG_PM_SLEEP */
  95. static SIMPLE_DEV_PM_OPS(dw_mci_rockchip_pmops,
  96. dw_mci_rockchip_suspend,
  97. dw_mci_rockchip_resume);
  98. static struct platform_driver dw_mci_rockchip_pltfm_driver = {
  99. .probe = dw_mci_rockchip_probe,
  100. .remove = __exit_p(dw_mci_pltfm_remove),
  101. .driver = {
  102. .name = "dwmmc_rockchip",
  103. .of_match_table = dw_mci_rockchip_match,
  104. .pm = &dw_mci_rockchip_pmops,
  105. },
  106. };
  107. module_platform_driver(dw_mci_rockchip_pltfm_driver);
  108. MODULE_AUTHOR("Addy Ke <addy.ke@rock-chips.com>");
  109. MODULE_DESCRIPTION("Rockchip Specific DW-MSHC Driver Extension");
  110. MODULE_ALIAS("platform:dwmmc-rockchip");
  111. MODULE_LICENSE("GPL v2");