dw_mmc-exynos.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. };
  37. /* Exynos implementation specific driver private data */
  38. struct dw_mci_exynos_priv_data {
  39. enum dw_mci_exynos_type ctrl_type;
  40. u8 ciu_div;
  41. u32 sdr_timing;
  42. u32 ddr_timing;
  43. };
  44. static struct dw_mci_exynos_compatible {
  45. char *compatible;
  46. enum dw_mci_exynos_type ctrl_type;
  47. } exynos_compat[] = {
  48. {
  49. .compatible = "samsung,exynos4210-dw-mshc",
  50. .ctrl_type = DW_MCI_TYPE_EXYNOS4210,
  51. }, {
  52. .compatible = "samsung,exynos4412-dw-mshc",
  53. .ctrl_type = DW_MCI_TYPE_EXYNOS4412,
  54. }, {
  55. .compatible = "samsung,exynos5250-dw-mshc",
  56. .ctrl_type = DW_MCI_TYPE_EXYNOS5250,
  57. },
  58. };
  59. static int dw_mci_exynos_priv_init(struct dw_mci *host)
  60. {
  61. struct dw_mci_exynos_priv_data *priv;
  62. int idx;
  63. priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
  64. if (!priv) {
  65. dev_err(host->dev, "mem alloc failed for private data\n");
  66. return -ENOMEM;
  67. }
  68. for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) {
  69. if (of_device_is_compatible(host->dev->of_node,
  70. exynos_compat[idx].compatible))
  71. priv->ctrl_type = exynos_compat[idx].ctrl_type;
  72. }
  73. host->priv = priv;
  74. return 0;
  75. }
  76. static int dw_mci_exynos_setup_clock(struct dw_mci *host)
  77. {
  78. struct dw_mci_exynos_priv_data *priv = host->priv;
  79. if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5250)
  80. host->bus_hz /= (priv->ciu_div + 1);
  81. else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412)
  82. host->bus_hz /= EXYNOS4412_FIXED_CIU_CLK_DIV;
  83. else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210)
  84. host->bus_hz /= EXYNOS4210_FIXED_CIU_CLK_DIV;
  85. return 0;
  86. }
  87. static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
  88. {
  89. /*
  90. * Exynos4412 and Exynos5250 extends the use of CMD register with the
  91. * use of bit 29 (which is reserved on standard MSHC controllers) for
  92. * optionally bypassing the HOLD register for command and data. The
  93. * HOLD register should be bypassed in case there is no phase shift
  94. * applied on CMD/DATA that is sent to the card.
  95. */
  96. if (SDMMC_CLKSEL_GET_DRV_WD3(mci_readl(host, CLKSEL)))
  97. *cmdr |= SDMMC_CMD_USE_HOLD_REG;
  98. }
  99. static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
  100. {
  101. struct dw_mci_exynos_priv_data *priv = host->priv;
  102. if (ios->timing == MMC_TIMING_UHS_DDR50)
  103. mci_writel(host, CLKSEL, priv->ddr_timing);
  104. else
  105. mci_writel(host, CLKSEL, priv->sdr_timing);
  106. }
  107. static int dw_mci_exynos_parse_dt(struct dw_mci *host)
  108. {
  109. struct dw_mci_exynos_priv_data *priv = host->priv;
  110. struct device_node *np = host->dev->of_node;
  111. u32 timing[2];
  112. u32 div = 0;
  113. int ret;
  114. of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div);
  115. priv->ciu_div = div;
  116. ret = of_property_read_u32_array(np,
  117. "samsung,dw-mshc-sdr-timing", timing, 2);
  118. if (ret)
  119. return ret;
  120. priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
  121. ret = of_property_read_u32_array(np,
  122. "samsung,dw-mshc-ddr-timing", timing, 2);
  123. if (ret)
  124. return ret;
  125. priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
  126. return 0;
  127. }
  128. /* Common capabilities of Exynos4/Exynos5 SoC */
  129. static unsigned long exynos_dwmmc_caps[4] = {
  130. MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR |
  131. MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23,
  132. MMC_CAP_CMD23,
  133. MMC_CAP_CMD23,
  134. MMC_CAP_CMD23,
  135. };
  136. static const struct dw_mci_drv_data exynos_drv_data = {
  137. .caps = exynos_dwmmc_caps,
  138. .init = dw_mci_exynos_priv_init,
  139. .setup_clock = dw_mci_exynos_setup_clock,
  140. .prepare_command = dw_mci_exynos_prepare_command,
  141. .set_ios = dw_mci_exynos_set_ios,
  142. .parse_dt = dw_mci_exynos_parse_dt,
  143. };
  144. static const struct of_device_id dw_mci_exynos_match[] = {
  145. { .compatible = "samsung,exynos4412-dw-mshc",
  146. .data = &exynos_drv_data, },
  147. { .compatible = "samsung,exynos5250-dw-mshc",
  148. .data = &exynos_drv_data, },
  149. {},
  150. };
  151. MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);
  152. static int dw_mci_exynos_probe(struct platform_device *pdev)
  153. {
  154. const struct dw_mci_drv_data *drv_data;
  155. const struct of_device_id *match;
  156. match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node);
  157. drv_data = match->data;
  158. return dw_mci_pltfm_register(pdev, drv_data);
  159. }
  160. static struct platform_driver dw_mci_exynos_pltfm_driver = {
  161. .probe = dw_mci_exynos_probe,
  162. .remove = __exit_p(dw_mci_pltfm_remove),
  163. .driver = {
  164. .name = "dwmmc_exynos",
  165. .of_match_table = dw_mci_exynos_match,
  166. .pm = &dw_mci_pltfm_pmops,
  167. },
  168. };
  169. module_platform_driver(dw_mci_exynos_pltfm_driver);
  170. MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension");
  171. MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com");
  172. MODULE_LICENSE("GPL v2");
  173. MODULE_ALIAS("platform:dwmmc-exynos");