sdhci-pxav3.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (C) 2010 Marvell International Ltd.
  3. * Zhangfei Gao <zhangfei.gao@marvell.com>
  4. * Kevin Wang <dwang4@marvell.com>
  5. * Mingwei Wang <mwwang@marvell.com>
  6. * Philip Rakity <prakity@marvell.com>
  7. * Mark Brown <markb@marvell.com>
  8. *
  9. * This software is licensed under the terms of the GNU General Public
  10. * License version 2, as published by the Free Software Foundation, and
  11. * may be copied, distributed, and modified under those terms.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #include <linux/err.h>
  20. #include <linux/init.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/clk.h>
  23. #include <linux/io.h>
  24. #include <linux/gpio.h>
  25. #include <linux/mmc/card.h>
  26. #include <linux/mmc/host.h>
  27. #include <linux/platform_data/pxa_sdhci.h>
  28. #include <linux/slab.h>
  29. #include <linux/delay.h>
  30. #include "sdhci.h"
  31. #include "sdhci-pltfm.h"
  32. #define SD_CLOCK_BURST_SIZE_SETUP 0x10A
  33. #define SDCLK_SEL 0x100
  34. #define SDCLK_DELAY_SHIFT 9
  35. #define SDCLK_DELAY_MASK 0x1f
  36. #define SD_CFG_FIFO_PARAM 0x100
  37. #define SDCFG_GEN_PAD_CLK_ON (1<<6)
  38. #define SDCFG_GEN_PAD_CLK_CNT_MASK 0xFF
  39. #define SDCFG_GEN_PAD_CLK_CNT_SHIFT 24
  40. #define SD_SPI_MODE 0x108
  41. #define SD_CE_ATA_1 0x10C
  42. #define SD_CE_ATA_2 0x10E
  43. #define SDCE_MISC_INT (1<<2)
  44. #define SDCE_MISC_INT_EN (1<<1)
  45. static void pxav3_set_private_registers(struct sdhci_host *host, u8 mask)
  46. {
  47. struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc));
  48. struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data;
  49. if (mask == SDHCI_RESET_ALL) {
  50. /*
  51. * tune timing of read data/command when crc error happen
  52. * no performance impact
  53. */
  54. if (pdata && 0 != pdata->clk_delay_cycles) {
  55. u16 tmp;
  56. tmp = readw(host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP);
  57. tmp |= (pdata->clk_delay_cycles & SDCLK_DELAY_MASK)
  58. << SDCLK_DELAY_SHIFT;
  59. tmp |= SDCLK_SEL;
  60. writew(tmp, host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP);
  61. }
  62. }
  63. }
  64. #define MAX_WAIT_COUNT 5
  65. static void pxav3_gen_init_74_clocks(struct sdhci_host *host, u8 power_mode)
  66. {
  67. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  68. struct sdhci_pxa *pxa = pltfm_host->priv;
  69. u16 tmp;
  70. int count;
  71. if (pxa->power_mode == MMC_POWER_UP
  72. && power_mode == MMC_POWER_ON) {
  73. dev_dbg(mmc_dev(host->mmc),
  74. "%s: slot->power_mode = %d,"
  75. "ios->power_mode = %d\n",
  76. __func__,
  77. pxa->power_mode,
  78. power_mode);
  79. /* set we want notice of when 74 clocks are sent */
  80. tmp = readw(host->ioaddr + SD_CE_ATA_2);
  81. tmp |= SDCE_MISC_INT_EN;
  82. writew(tmp, host->ioaddr + SD_CE_ATA_2);
  83. /* start sending the 74 clocks */
  84. tmp = readw(host->ioaddr + SD_CFG_FIFO_PARAM);
  85. tmp |= SDCFG_GEN_PAD_CLK_ON;
  86. writew(tmp, host->ioaddr + SD_CFG_FIFO_PARAM);
  87. /* slowest speed is about 100KHz or 10usec per clock */
  88. udelay(740);
  89. count = 0;
  90. while (count++ < MAX_WAIT_COUNT) {
  91. if ((readw(host->ioaddr + SD_CE_ATA_2)
  92. & SDCE_MISC_INT) == 0)
  93. break;
  94. udelay(10);
  95. }
  96. if (count == MAX_WAIT_COUNT)
  97. dev_warn(mmc_dev(host->mmc), "74 clock interrupt not cleared\n");
  98. /* clear the interrupt bit if posted */
  99. tmp = readw(host->ioaddr + SD_CE_ATA_2);
  100. tmp |= SDCE_MISC_INT;
  101. writew(tmp, host->ioaddr + SD_CE_ATA_2);
  102. }
  103. pxa->power_mode = power_mode;
  104. }
  105. static int pxav3_set_uhs_signaling(struct sdhci_host *host, unsigned int uhs)
  106. {
  107. u16 ctrl_2;
  108. /*
  109. * Set V18_EN -- UHS modes do not work without this.
  110. * does not change signaling voltage
  111. */
  112. ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2);
  113. /* Select Bus Speed Mode for host */
  114. ctrl_2 &= ~SDHCI_CTRL_UHS_MASK;
  115. switch (uhs) {
  116. case MMC_TIMING_UHS_SDR12:
  117. ctrl_2 |= SDHCI_CTRL_UHS_SDR12;
  118. break;
  119. case MMC_TIMING_UHS_SDR25:
  120. ctrl_2 |= SDHCI_CTRL_UHS_SDR25;
  121. break;
  122. case MMC_TIMING_UHS_SDR50:
  123. ctrl_2 |= SDHCI_CTRL_UHS_SDR50 | SDHCI_CTRL_VDD_180;
  124. break;
  125. case MMC_TIMING_UHS_SDR104:
  126. ctrl_2 |= SDHCI_CTRL_UHS_SDR104 | SDHCI_CTRL_VDD_180;
  127. break;
  128. case MMC_TIMING_UHS_DDR50:
  129. ctrl_2 |= SDHCI_CTRL_UHS_DDR50 | SDHCI_CTRL_VDD_180;
  130. break;
  131. }
  132. sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
  133. dev_dbg(mmc_dev(host->mmc),
  134. "%s uhs = %d, ctrl_2 = %04X\n",
  135. __func__, uhs, ctrl_2);
  136. return 0;
  137. }
  138. static struct sdhci_ops pxav3_sdhci_ops = {
  139. .platform_reset_exit = pxav3_set_private_registers,
  140. .set_uhs_signaling = pxav3_set_uhs_signaling,
  141. .platform_send_init_74_clocks = pxav3_gen_init_74_clocks,
  142. };
  143. static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
  144. {
  145. struct sdhci_pltfm_host *pltfm_host;
  146. struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data;
  147. struct device *dev = &pdev->dev;
  148. struct sdhci_host *host = NULL;
  149. struct sdhci_pxa *pxa = NULL;
  150. int ret;
  151. struct clk *clk;
  152. pxa = kzalloc(sizeof(struct sdhci_pxa), GFP_KERNEL);
  153. if (!pxa)
  154. return -ENOMEM;
  155. host = sdhci_pltfm_init(pdev, NULL);
  156. if (IS_ERR(host)) {
  157. kfree(pxa);
  158. return PTR_ERR(host);
  159. }
  160. pltfm_host = sdhci_priv(host);
  161. pltfm_host->priv = pxa;
  162. clk = clk_get(dev, "PXA-SDHCLK");
  163. if (IS_ERR(clk)) {
  164. dev_err(dev, "failed to get io clock\n");
  165. ret = PTR_ERR(clk);
  166. goto err_clk_get;
  167. }
  168. pltfm_host->clk = clk;
  169. clk_enable(clk);
  170. host->quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL
  171. | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC;
  172. /* enable 1/8V DDR capable */
  173. host->mmc->caps |= MMC_CAP_1_8V_DDR;
  174. if (pdata) {
  175. if (pdata->flags & PXA_FLAG_CARD_PERMANENT) {
  176. /* on-chip device */
  177. host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
  178. host->mmc->caps |= MMC_CAP_NONREMOVABLE;
  179. }
  180. /* If slot design supports 8 bit data, indicate this to MMC. */
  181. if (pdata->flags & PXA_FLAG_SD_8_BIT_CAPABLE_SLOT)
  182. host->mmc->caps |= MMC_CAP_8_BIT_DATA;
  183. if (pdata->quirks)
  184. host->quirks |= pdata->quirks;
  185. if (pdata->host_caps)
  186. host->mmc->caps |= pdata->host_caps;
  187. if (pdata->pm_caps)
  188. host->mmc->pm_caps |= pdata->pm_caps;
  189. }
  190. host->ops = &pxav3_sdhci_ops;
  191. ret = sdhci_add_host(host);
  192. if (ret) {
  193. dev_err(&pdev->dev, "failed to add host\n");
  194. goto err_add_host;
  195. }
  196. platform_set_drvdata(pdev, host);
  197. return 0;
  198. err_add_host:
  199. clk_disable(clk);
  200. clk_put(clk);
  201. err_clk_get:
  202. sdhci_pltfm_free(pdev);
  203. kfree(pxa);
  204. return ret;
  205. }
  206. static int __devexit sdhci_pxav3_remove(struct platform_device *pdev)
  207. {
  208. struct sdhci_host *host = platform_get_drvdata(pdev);
  209. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  210. struct sdhci_pxa *pxa = pltfm_host->priv;
  211. sdhci_remove_host(host, 1);
  212. clk_disable(pltfm_host->clk);
  213. clk_put(pltfm_host->clk);
  214. sdhci_pltfm_free(pdev);
  215. kfree(pxa);
  216. platform_set_drvdata(pdev, NULL);
  217. return 0;
  218. }
  219. static struct platform_driver sdhci_pxav3_driver = {
  220. .driver = {
  221. .name = "sdhci-pxav3",
  222. .owner = THIS_MODULE,
  223. },
  224. .probe = sdhci_pxav3_probe,
  225. .remove = __devexit_p(sdhci_pxav3_remove),
  226. #ifdef CONFIG_PM
  227. .suspend = sdhci_pltfm_suspend,
  228. .resume = sdhci_pltfm_resume,
  229. #endif
  230. };
  231. static int __init sdhci_pxav3_init(void)
  232. {
  233. return platform_driver_register(&sdhci_pxav3_driver);
  234. }
  235. static void __exit sdhci_pxav3_exit(void)
  236. {
  237. platform_driver_unregister(&sdhci_pxav3_driver);
  238. }
  239. module_init(sdhci_pxav3_init);
  240. module_exit(sdhci_pxav3_exit);
  241. MODULE_DESCRIPTION("SDHCI driver for pxav3");
  242. MODULE_AUTHOR("Marvell International Ltd.");
  243. MODULE_LICENSE("GPL v2");