sdhci-of-esdhc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. return ret;
  38. }
  39. static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
  40. {
  41. if (reg == SDHCI_BLOCK_SIZE) {
  42. /*
  43. * Two last DMA bits are reserved, and first one is used for
  44. * non-standard blksz of 4096 bytes that we don't support
  45. * yet. So clear the DMA boundary bits.
  46. */
  47. val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
  48. }
  49. sdhci_be32bs_writew(host, val, reg);
  50. }
  51. static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
  52. {
  53. /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
  54. if (reg == SDHCI_HOST_CONTROL)
  55. val &= ~ESDHC_HOST_CONTROL_RES;
  56. sdhci_be32bs_writeb(host, val, reg);
  57. }
  58. static int esdhc_of_enable_dma(struct sdhci_host *host)
  59. {
  60. setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
  61. return 0;
  62. }
  63. static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
  64. {
  65. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  66. return pltfm_host->clock;
  67. }
  68. static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
  69. {
  70. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  71. return pltfm_host->clock / 256 / 16;
  72. }
  73. static struct sdhci_ops sdhci_esdhc_ops = {
  74. .read_l = sdhci_be32bs_readl,
  75. .read_w = esdhc_readw,
  76. .read_b = esdhc_readb,
  77. .write_l = sdhci_be32bs_writel,
  78. .write_w = esdhc_writew,
  79. .write_b = esdhc_writeb,
  80. .set_clock = esdhc_set_clock,
  81. .enable_dma = esdhc_of_enable_dma,
  82. .get_max_clock = esdhc_of_get_max_clock,
  83. .get_min_clock = esdhc_of_get_min_clock,
  84. };
  85. static struct sdhci_pltfm_data sdhci_esdhc_pdata = {
  86. /* card detection could be handled via GPIO */
  87. .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
  88. | SDHCI_QUIRK_NO_CARD_NO_RESET,
  89. .ops = &sdhci_esdhc_ops,
  90. };
  91. static int __devinit sdhci_esdhc_probe(struct platform_device *pdev)
  92. {
  93. return sdhci_pltfm_register(pdev, &sdhci_esdhc_pdata);
  94. }
  95. static int __devexit sdhci_esdhc_remove(struct platform_device *pdev)
  96. {
  97. return sdhci_pltfm_unregister(pdev);
  98. }
  99. static const struct of_device_id sdhci_esdhc_of_match[] = {
  100. { .compatible = "fsl,mpc8379-esdhc" },
  101. { .compatible = "fsl,mpc8536-esdhc" },
  102. { .compatible = "fsl,esdhc" },
  103. { }
  104. };
  105. MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
  106. static struct platform_driver sdhci_esdhc_driver = {
  107. .driver = {
  108. .name = "sdhci-esdhc",
  109. .owner = THIS_MODULE,
  110. .of_match_table = sdhci_esdhc_of_match,
  111. },
  112. .probe = sdhci_esdhc_probe,
  113. .remove = __devexit_p(sdhci_esdhc_remove),
  114. #ifdef CONFIG_PM
  115. .suspend = sdhci_pltfm_suspend,
  116. .resume = sdhci_pltfm_resume,
  117. #endif
  118. };
  119. static int __init sdhci_esdhc_init(void)
  120. {
  121. return platform_driver_register(&sdhci_esdhc_driver);
  122. }
  123. module_init(sdhci_esdhc_init);
  124. static void __exit sdhci_esdhc_exit(void)
  125. {
  126. platform_driver_unregister(&sdhci_esdhc_driver);
  127. }
  128. module_exit(sdhci_esdhc_exit);
  129. MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
  130. MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
  131. "Anton Vorontsov <avorontsov@ru.mvista.com>");
  132. MODULE_LICENSE("GPL v2");