sdhci-of-esdhc.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Freescale eSDHC controller driver.
  3. *
  4. * Copyright (c) 2007, 2010, 2012 Freescale Semiconductor, Inc.
  5. * Copyright (c) 2009 MontaVista Software, Inc.
  6. *
  7. * Authors: Xiaobo Xie <X.Xie@freescale.com>
  8. * Anton Vorontsov <avorontsov@ru.mvista.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. */
  15. #include <linux/io.h>
  16. #include <linux/of.h>
  17. #include <linux/delay.h>
  18. #include <linux/module.h>
  19. #include <linux/mmc/host.h>
  20. #include "sdhci-pltfm.h"
  21. #include "sdhci-esdhc.h"
  22. static u16 esdhc_readw(struct sdhci_host *host, int reg)
  23. {
  24. u16 ret;
  25. int base = reg & ~0x3;
  26. int shift = (reg & 0x2) * 8;
  27. if (unlikely(reg == SDHCI_HOST_VERSION))
  28. ret = in_be32(host->ioaddr + base) & 0xffff;
  29. else
  30. ret = (in_be32(host->ioaddr + base) >> shift) & 0xffff;
  31. return ret;
  32. }
  33. static u8 esdhc_readb(struct sdhci_host *host, int reg)
  34. {
  35. int base = reg & ~0x3;
  36. int shift = (reg & 0x3) * 8;
  37. u8 ret = (in_be32(host->ioaddr + base) >> shift) & 0xff;
  38. /*
  39. * "DMA select" locates at offset 0x28 in SD specification, but on
  40. * P5020 or P3041, it locates at 0x29.
  41. */
  42. if (reg == SDHCI_HOST_CONTROL) {
  43. u32 dma_bits;
  44. dma_bits = in_be32(host->ioaddr + reg);
  45. /* DMA select is 22,23 bits in Protocol Control Register */
  46. dma_bits = (dma_bits >> 5) & SDHCI_CTRL_DMA_MASK;
  47. /* fixup the result */
  48. ret &= ~SDHCI_CTRL_DMA_MASK;
  49. ret |= dma_bits;
  50. }
  51. return ret;
  52. }
  53. static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
  54. {
  55. if (reg == SDHCI_BLOCK_SIZE) {
  56. /*
  57. * Two last DMA bits are reserved, and first one is used for
  58. * non-standard blksz of 4096 bytes that we don't support
  59. * yet. So clear the DMA boundary bits.
  60. */
  61. val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
  62. }
  63. sdhci_be32bs_writew(host, val, reg);
  64. }
  65. static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
  66. {
  67. /*
  68. * "DMA select" location is offset 0x28 in SD specification, but on
  69. * P5020 or P3041, it's located at 0x29.
  70. */
  71. if (reg == SDHCI_HOST_CONTROL) {
  72. u32 dma_bits;
  73. /* DMA select is 22,23 bits in Protocol Control Register */
  74. dma_bits = (val & SDHCI_CTRL_DMA_MASK) << 5;
  75. clrsetbits_be32(host->ioaddr + reg , SDHCI_CTRL_DMA_MASK << 5,
  76. dma_bits);
  77. val &= ~SDHCI_CTRL_DMA_MASK;
  78. val |= in_be32(host->ioaddr + reg) & SDHCI_CTRL_DMA_MASK;
  79. }
  80. /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
  81. if (reg == SDHCI_HOST_CONTROL)
  82. val &= ~ESDHC_HOST_CONTROL_RES;
  83. sdhci_be32bs_writeb(host, val, reg);
  84. }
  85. static int esdhc_of_enable_dma(struct sdhci_host *host)
  86. {
  87. setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
  88. return 0;
  89. }
  90. static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
  91. {
  92. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  93. return pltfm_host->clock;
  94. }
  95. static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
  96. {
  97. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  98. return pltfm_host->clock / 256 / 16;
  99. }
  100. static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
  101. {
  102. /* Workaround to reduce the clock frequency for p1010 esdhc */
  103. if (of_find_compatible_node(NULL, NULL, "fsl,p1010-esdhc")) {
  104. if (clock > 20000000)
  105. clock -= 5000000;
  106. if (clock > 40000000)
  107. clock -= 5000000;
  108. }
  109. /* Set the clock */
  110. esdhc_set_clock(host, clock);
  111. }
  112. #ifdef CONFIG_PM
  113. static u32 esdhc_proctl;
  114. static void esdhc_of_suspend(struct sdhci_host *host)
  115. {
  116. esdhc_proctl = sdhci_be32bs_readl(host, SDHCI_HOST_CONTROL);
  117. }
  118. static void esdhc_of_resume(struct sdhci_host *host)
  119. {
  120. esdhc_of_enable_dma(host);
  121. sdhci_be32bs_writel(host, esdhc_proctl, SDHCI_HOST_CONTROL);
  122. }
  123. #endif
  124. static struct sdhci_ops sdhci_esdhc_ops = {
  125. .read_l = sdhci_be32bs_readl,
  126. .read_w = esdhc_readw,
  127. .read_b = esdhc_readb,
  128. .write_l = sdhci_be32bs_writel,
  129. .write_w = esdhc_writew,
  130. .write_b = esdhc_writeb,
  131. .set_clock = esdhc_of_set_clock,
  132. .enable_dma = esdhc_of_enable_dma,
  133. .get_max_clock = esdhc_of_get_max_clock,
  134. .get_min_clock = esdhc_of_get_min_clock,
  135. #ifdef CONFIG_PM
  136. .platform_suspend = esdhc_of_suspend,
  137. .platform_resume = esdhc_of_resume,
  138. #endif
  139. };
  140. static struct sdhci_pltfm_data sdhci_esdhc_pdata = {
  141. /* card detection could be handled via GPIO */
  142. .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
  143. | SDHCI_QUIRK_NO_CARD_NO_RESET,
  144. .ops = &sdhci_esdhc_ops,
  145. };
  146. static int __devinit sdhci_esdhc_probe(struct platform_device *pdev)
  147. {
  148. return sdhci_pltfm_register(pdev, &sdhci_esdhc_pdata);
  149. }
  150. static int __devexit sdhci_esdhc_remove(struct platform_device *pdev)
  151. {
  152. return sdhci_pltfm_unregister(pdev);
  153. }
  154. static const struct of_device_id sdhci_esdhc_of_match[] = {
  155. { .compatible = "fsl,mpc8379-esdhc" },
  156. { .compatible = "fsl,mpc8536-esdhc" },
  157. { .compatible = "fsl,esdhc" },
  158. { }
  159. };
  160. MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
  161. static struct platform_driver sdhci_esdhc_driver = {
  162. .driver = {
  163. .name = "sdhci-esdhc",
  164. .owner = THIS_MODULE,
  165. .of_match_table = sdhci_esdhc_of_match,
  166. .pm = SDHCI_PLTFM_PMOPS,
  167. },
  168. .probe = sdhci_esdhc_probe,
  169. .remove = __devexit_p(sdhci_esdhc_remove),
  170. };
  171. module_platform_driver(sdhci_esdhc_driver);
  172. MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
  173. MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
  174. "Anton Vorontsov <avorontsov@ru.mvista.com>");
  175. MODULE_LICENSE("GPL v2");