dw_mmc-exynos.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Exynos Specific Extensions for Synopsys DW Multimedia Card Interface driver
  3. *
  4. * Copyright (C) 2012, Samsung Electronics Co., Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/clk.h>
  14. #include <linux/mmc/host.h>
  15. #include <linux/mmc/dw_mmc.h>
  16. #include <linux/of.h>
  17. #include <linux/of_gpio.h>
  18. #include "dw_mmc.h"
  19. #include "dw_mmc-pltfm.h"
  20. #define NUM_PINS(x) (x + 2)
  21. #define SDMMC_CLKSEL 0x09C
  22. #define SDMMC_CLKSEL_CCLK_SAMPLE(x) (((x) & 7) << 0)
  23. #define SDMMC_CLKSEL_CCLK_DRIVE(x) (((x) & 7) << 16)
  24. #define SDMMC_CLKSEL_CCLK_DIVIDER(x) (((x) & 7) << 24)
  25. #define SDMMC_CLKSEL_GET_DRV_WD3(x) (((x) >> 16) & 0x7)
  26. #define SDMMC_CLKSEL_TIMING(x, y, z) (SDMMC_CLKSEL_CCLK_SAMPLE(x) | \
  27. SDMMC_CLKSEL_CCLK_DRIVE(y) | \
  28. SDMMC_CLKSEL_CCLK_DIVIDER(z))
  29. #define EXYNOS4210_FIXED_CIU_CLK_DIV 2
  30. #define EXYNOS4412_FIXED_CIU_CLK_DIV 4
  31. /* Variations in Exynos specific dw-mshc controller */
  32. enum dw_mci_exynos_type {
  33. DW_MCI_TYPE_EXYNOS4210,
  34. DW_MCI_TYPE_EXYNOS4412,
  35. DW_MCI_TYPE_EXYNOS5250,
  36. DW_MCI_TYPE_EXYNOS5420,
  37. };
  38. /* Exynos implementation specific driver private data */
  39. struct dw_mci_exynos_priv_data {
  40. enum dw_mci_exynos_type ctrl_type;
  41. u8 ciu_div;
  42. u32 sdr_timing;
  43. u32 ddr_timing;
  44. };
  45. static struct dw_mci_exynos_compatible {
  46. char *compatible;
  47. enum dw_mci_exynos_type ctrl_type;
  48. } exynos_compat[] = {
  49. {
  50. .compatible = "samsung,exynos4210-dw-mshc",
  51. .ctrl_type = DW_MCI_TYPE_EXYNOS4210,
  52. }, {
  53. .compatible = "samsung,exynos4412-dw-mshc",
  54. .ctrl_type = DW_MCI_TYPE_EXYNOS4412,
  55. }, {
  56. .compatible = "samsung,exynos5250-dw-mshc",
  57. .ctrl_type = DW_MCI_TYPE_EXYNOS5250,
  58. }, {
  59. .compatible = "samsung,exynos5420-dw-mshc",
  60. .ctrl_type = DW_MCI_TYPE_EXYNOS5420,
  61. },
  62. };
  63. static int dw_mci_exynos_priv_init(struct dw_mci *host)
  64. {
  65. struct dw_mci_exynos_priv_data *priv;
  66. int idx;
  67. priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
  68. if (!priv) {
  69. dev_err(host->dev, "mem alloc failed for private data\n");
  70. return -ENOMEM;
  71. }
  72. for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) {
  73. if (of_device_is_compatible(host->dev->of_node,
  74. exynos_compat[idx].compatible))
  75. priv->ctrl_type = exynos_compat[idx].ctrl_type;
  76. }
  77. host->priv = priv;
  78. return 0;
  79. }
  80. static int dw_mci_exynos_setup_clock(struct dw_mci *host)
  81. {
  82. struct dw_mci_exynos_priv_data *priv = host->priv;
  83. if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5250 ||
  84. priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420)
  85. host->bus_hz /= (priv->ciu_div + 1);
  86. else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412)
  87. host->bus_hz /= EXYNOS4412_FIXED_CIU_CLK_DIV;
  88. else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210)
  89. host->bus_hz /= EXYNOS4210_FIXED_CIU_CLK_DIV;
  90. return 0;
  91. }
  92. static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
  93. {
  94. /*
  95. * Exynos4412 and Exynos5250 extends the use of CMD register with the
  96. * use of bit 29 (which is reserved on standard MSHC controllers) for
  97. * optionally bypassing the HOLD register for command and data. The
  98. * HOLD register should be bypassed in case there is no phase shift
  99. * applied on CMD/DATA that is sent to the card.
  100. */
  101. if (SDMMC_CLKSEL_GET_DRV_WD3(mci_readl(host, CLKSEL)))
  102. *cmdr |= SDMMC_CMD_USE_HOLD_REG;
  103. }
  104. static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
  105. {
  106. struct dw_mci_exynos_priv_data *priv = host->priv;
  107. if (ios->timing == MMC_TIMING_UHS_DDR50)
  108. mci_writel(host, CLKSEL, priv->ddr_timing);
  109. else
  110. mci_writel(host, CLKSEL, priv->sdr_timing);
  111. }
  112. static int dw_mci_exynos_parse_dt(struct dw_mci *host)
  113. {
  114. struct dw_mci_exynos_priv_data *priv = host->priv;
  115. struct device_node *np = host->dev->of_node;
  116. u32 timing[2];
  117. u32 div = 0;
  118. int ret;
  119. of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div);
  120. priv->ciu_div = div;
  121. ret = of_property_read_u32_array(np,
  122. "samsung,dw-mshc-sdr-timing", timing, 2);
  123. if (ret)
  124. return ret;
  125. priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
  126. ret = of_property_read_u32_array(np,
  127. "samsung,dw-mshc-ddr-timing", timing, 2);
  128. if (ret)
  129. return ret;
  130. priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
  131. return 0;
  132. }
  133. /* Common capabilities of Exynos4/Exynos5 SoC */
  134. static unsigned long exynos_dwmmc_caps[4] = {
  135. MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR |
  136. MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23,
  137. MMC_CAP_CMD23,
  138. MMC_CAP_CMD23,
  139. MMC_CAP_CMD23,
  140. };
  141. static const struct dw_mci_drv_data exynos_drv_data = {
  142. .caps = exynos_dwmmc_caps,
  143. .init = dw_mci_exynos_priv_init,
  144. .setup_clock = dw_mci_exynos_setup_clock,
  145. .prepare_command = dw_mci_exynos_prepare_command,
  146. .set_ios = dw_mci_exynos_set_ios,
  147. .parse_dt = dw_mci_exynos_parse_dt,
  148. };
  149. static const struct of_device_id dw_mci_exynos_match[] = {
  150. { .compatible = "samsung,exynos4412-dw-mshc",
  151. .data = &exynos_drv_data, },
  152. { .compatible = "samsung,exynos5250-dw-mshc",
  153. .data = &exynos_drv_data, },
  154. { .compatible = "samsung,exynos5420-dw-mshc",
  155. .data = &exynos_drv_data, },
  156. {},
  157. };
  158. MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);
  159. static int dw_mci_exynos_probe(struct platform_device *pdev)
  160. {
  161. const struct dw_mci_drv_data *drv_data;
  162. const struct of_device_id *match;
  163. match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node);
  164. drv_data = match->data;
  165. return dw_mci_pltfm_register(pdev, drv_data);
  166. }
  167. static struct platform_driver dw_mci_exynos_pltfm_driver = {
  168. .probe = dw_mci_exynos_probe,
  169. .remove = __exit_p(dw_mci_pltfm_remove),
  170. .driver = {
  171. .name = "dwmmc_exynos",
  172. .of_match_table = dw_mci_exynos_match,
  173. .pm = &dw_mci_pltfm_pmops,
  174. },
  175. };
  176. module_platform_driver(dw_mci_exynos_pltfm_driver);
  177. MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension");
  178. MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com");
  179. MODULE_LICENSE("GPL v2");
  180. MODULE_ALIAS("platform:dwmmc-exynos");