sdhci-dove.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * sdhci-dove.c Support for SDHCI on Marvell's Dove SoC
  3. *
  4. * Author: Saeed Bishara <saeed@marvell.com>
  5. * Mike Rapoport <mike@compulab.co.il>
  6. * Based on sdhci-cns3xxx.c
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/err.h>
  22. #include <linux/io.h>
  23. #include <linux/clk.h>
  24. #include <linux/err.h>
  25. #include <linux/module.h>
  26. #include <linux/mmc/host.h>
  27. #include <linux/of.h>
  28. #include "sdhci-pltfm.h"
  29. struct sdhci_dove_priv {
  30. struct clk *clk;
  31. };
  32. static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)
  33. {
  34. u16 ret;
  35. switch (reg) {
  36. case SDHCI_HOST_VERSION:
  37. case SDHCI_SLOT_INT_STATUS:
  38. /* those registers don't exist */
  39. return 0;
  40. default:
  41. ret = readw(host->ioaddr + reg);
  42. }
  43. return ret;
  44. }
  45. static u32 sdhci_dove_readl(struct sdhci_host *host, int reg)
  46. {
  47. u32 ret;
  48. switch (reg) {
  49. case SDHCI_CAPABILITIES:
  50. ret = readl(host->ioaddr + reg);
  51. /* Mask the support for 3.0V */
  52. ret &= ~SDHCI_CAN_VDD_300;
  53. break;
  54. default:
  55. ret = readl(host->ioaddr + reg);
  56. }
  57. return ret;
  58. }
  59. static struct sdhci_ops sdhci_dove_ops = {
  60. .read_w = sdhci_dove_readw,
  61. .read_l = sdhci_dove_readl,
  62. };
  63. static struct sdhci_pltfm_data sdhci_dove_pdata = {
  64. .ops = &sdhci_dove_ops,
  65. .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
  66. SDHCI_QUIRK_NO_BUSY_IRQ |
  67. SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  68. SDHCI_QUIRK_FORCE_DMA |
  69. SDHCI_QUIRK_NO_HISPD_BIT,
  70. };
  71. static int __devinit sdhci_dove_probe(struct platform_device *pdev)
  72. {
  73. struct sdhci_host *host;
  74. struct sdhci_pltfm_host *pltfm_host;
  75. struct sdhci_dove_priv *priv;
  76. int ret;
  77. priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv),
  78. GFP_KERNEL);
  79. if (!priv) {
  80. dev_err(&pdev->dev, "unable to allocate private data");
  81. return -ENOMEM;
  82. }
  83. priv->clk = clk_get(&pdev->dev, NULL);
  84. if (!IS_ERR(priv->clk))
  85. clk_prepare_enable(priv->clk);
  86. ret = sdhci_pltfm_register(pdev, &sdhci_dove_pdata);
  87. if (ret)
  88. goto sdhci_dove_register_fail;
  89. host = platform_get_drvdata(pdev);
  90. pltfm_host = sdhci_priv(host);
  91. pltfm_host->priv = priv;
  92. return 0;
  93. sdhci_dove_register_fail:
  94. if (!IS_ERR(priv->clk)) {
  95. clk_disable_unprepare(priv->clk);
  96. clk_put(priv->clk);
  97. }
  98. return ret;
  99. }
  100. static int __devexit sdhci_dove_remove(struct platform_device *pdev)
  101. {
  102. struct sdhci_host *host = platform_get_drvdata(pdev);
  103. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  104. struct sdhci_dove_priv *priv = pltfm_host->priv;
  105. sdhci_pltfm_unregister(pdev);
  106. if (!IS_ERR(priv->clk)) {
  107. clk_disable_unprepare(priv->clk);
  108. clk_put(priv->clk);
  109. }
  110. return 0;
  111. }
  112. static const struct of_device_id sdhci_dove_of_match_table[] __devinitdata = {
  113. { .compatible = "marvell,dove-sdhci", },
  114. {}
  115. };
  116. MODULE_DEVICE_TABLE(of, sdhci_dove_of_match_table);
  117. static struct platform_driver sdhci_dove_driver = {
  118. .driver = {
  119. .name = "sdhci-dove",
  120. .owner = THIS_MODULE,
  121. .pm = SDHCI_PLTFM_PMOPS,
  122. .of_match_table = of_match_ptr(sdhci_dove_of_match_table),
  123. },
  124. .probe = sdhci_dove_probe,
  125. .remove = __devexit_p(sdhci_dove_remove),
  126. };
  127. module_platform_driver(sdhci_dove_driver);
  128. MODULE_DESCRIPTION("SDHCI driver for Dove");
  129. MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>, "
  130. "Mike Rapoport <mike@compulab.co.il>");
  131. MODULE_LICENSE("GPL v2");