sdhci-of-esdhc.c 3.7 KB

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