sdhci-of-esdhc.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Freescale eSDHC controller driver.
  3. *
  4. * Copyright (c) 2007, 2010 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/delay.h>
  17. #include <linux/module.h>
  18. #include <linux/mmc/host.h>
  19. #include "sdhci-pltfm.h"
  20. #include "sdhci-esdhc.h"
  21. static u16 esdhc_readw(struct sdhci_host *host, int reg)
  22. {
  23. u16 ret;
  24. int base = reg & ~0x3;
  25. int shift = (reg & 0x2) * 8;
  26. if (unlikely(reg == SDHCI_HOST_VERSION))
  27. ret = in_be32(host->ioaddr + base) & 0xffff;
  28. else
  29. ret = (in_be32(host->ioaddr + base) >> shift) & 0xffff;
  30. return ret;
  31. }
  32. static u8 esdhc_readb(struct sdhci_host *host, int reg)
  33. {
  34. int base = reg & ~0x3;
  35. int shift = (reg & 0x3) * 8;
  36. u8 ret = (in_be32(host->ioaddr + base) >> shift) & 0xff;
  37. /*
  38. * "DMA select" locates at offset 0x28 in SD specification, but on
  39. * P5020 or P3041, it locates at 0x29.
  40. */
  41. if (reg == SDHCI_HOST_CONTROL) {
  42. u32 dma_bits;
  43. dma_bits = in_be32(host->ioaddr + reg);
  44. /* DMA select is 22,23 bits in Protocol Control Register */
  45. dma_bits = (dma_bits >> 5) & SDHCI_CTRL_DMA_MASK;
  46. /* fixup the result */
  47. ret &= ~SDHCI_CTRL_DMA_MASK;
  48. ret |= dma_bits;
  49. }
  50. return ret;
  51. }
  52. static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
  53. {
  54. if (reg == SDHCI_BLOCK_SIZE) {
  55. /*
  56. * Two last DMA bits are reserved, and first one is used for
  57. * non-standard blksz of 4096 bytes that we don't support
  58. * yet. So clear the DMA boundary bits.
  59. */
  60. val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
  61. }
  62. sdhci_be32bs_writew(host, val, reg);
  63. }
  64. static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
  65. {
  66. /*
  67. * "DMA select" location is offset 0x28 in SD specification, but on
  68. * P5020 or P3041, it's located at 0x29.
  69. */
  70. if (reg == SDHCI_HOST_CONTROL) {
  71. u32 dma_bits;
  72. /* DMA select is 22,23 bits in Protocol Control Register */
  73. dma_bits = (val & SDHCI_CTRL_DMA_MASK) << 5;
  74. clrsetbits_be32(host->ioaddr + reg , SDHCI_CTRL_DMA_MASK << 5,
  75. dma_bits);
  76. val &= ~SDHCI_CTRL_DMA_MASK;
  77. val |= in_be32(host->ioaddr + reg) & SDHCI_CTRL_DMA_MASK;
  78. }
  79. /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
  80. if (reg == SDHCI_HOST_CONTROL)
  81. val &= ~ESDHC_HOST_CONTROL_RES;
  82. sdhci_be32bs_writeb(host, val, reg);
  83. }
  84. static int esdhc_of_enable_dma(struct sdhci_host *host)
  85. {
  86. setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
  87. return 0;
  88. }
  89. static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
  90. {
  91. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  92. return pltfm_host->clock;
  93. }
  94. static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
  95. {
  96. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  97. return pltfm_host->clock / 256 / 16;
  98. }
  99. static struct sdhci_ops sdhci_esdhc_ops = {
  100. .read_l = sdhci_be32bs_readl,
  101. .read_w = esdhc_readw,
  102. .read_b = esdhc_readb,
  103. .write_l = sdhci_be32bs_writel,
  104. .write_w = esdhc_writew,
  105. .write_b = esdhc_writeb,
  106. .set_clock = esdhc_set_clock,
  107. .enable_dma = esdhc_of_enable_dma,
  108. .get_max_clock = esdhc_of_get_max_clock,
  109. .get_min_clock = esdhc_of_get_min_clock,
  110. };
  111. static struct sdhci_pltfm_data sdhci_esdhc_pdata = {
  112. /* card detection could be handled via GPIO */
  113. .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
  114. | SDHCI_QUIRK_NO_CARD_NO_RESET,
  115. .ops = &sdhci_esdhc_ops,
  116. };
  117. static int __devinit sdhci_esdhc_probe(struct platform_device *pdev)
  118. {
  119. return sdhci_pltfm_register(pdev, &sdhci_esdhc_pdata);
  120. }
  121. static int __devexit sdhci_esdhc_remove(struct platform_device *pdev)
  122. {
  123. return sdhci_pltfm_unregister(pdev);
  124. }
  125. static const struct of_device_id sdhci_esdhc_of_match[] = {
  126. { .compatible = "fsl,mpc8379-esdhc" },
  127. { .compatible = "fsl,mpc8536-esdhc" },
  128. { .compatible = "fsl,esdhc" },
  129. { }
  130. };
  131. MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
  132. static struct platform_driver sdhci_esdhc_driver = {
  133. .driver = {
  134. .name = "sdhci-esdhc",
  135. .owner = THIS_MODULE,
  136. .of_match_table = sdhci_esdhc_of_match,
  137. .pm = SDHCI_PLTFM_PMOPS,
  138. },
  139. .probe = sdhci_esdhc_probe,
  140. .remove = __devexit_p(sdhci_esdhc_remove),
  141. };
  142. module_platform_driver(sdhci_esdhc_driver);
  143. MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
  144. MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
  145. "Anton Vorontsov <avorontsov@ru.mvista.com>");
  146. MODULE_LICENSE("GPL v2");