sdhci-dove.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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/clk.h>
  22. #include <linux/err.h>
  23. #include <linux/io.h>
  24. #include <linux/mmc/host.h>
  25. #include <linux/module.h>
  26. #include <linux/of.h>
  27. #include "sdhci-pltfm.h"
  28. struct sdhci_dove_priv {
  29. struct clk *clk;
  30. };
  31. static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)
  32. {
  33. u16 ret;
  34. switch (reg) {
  35. case SDHCI_HOST_VERSION:
  36. case SDHCI_SLOT_INT_STATUS:
  37. /* those registers don't exist */
  38. return 0;
  39. default:
  40. ret = readw(host->ioaddr + reg);
  41. }
  42. return ret;
  43. }
  44. static u32 sdhci_dove_readl(struct sdhci_host *host, int reg)
  45. {
  46. u32 ret;
  47. ret = readl(host->ioaddr + reg);
  48. switch (reg) {
  49. case SDHCI_CAPABILITIES:
  50. /* Mask the support for 3.0V */
  51. ret &= ~SDHCI_CAN_VDD_300;
  52. break;
  53. }
  54. return ret;
  55. }
  56. static const struct sdhci_ops sdhci_dove_ops = {
  57. .read_w = sdhci_dove_readw,
  58. .read_l = sdhci_dove_readl,
  59. .set_clock = sdhci_set_clock,
  60. .set_bus_width = sdhci_set_bus_width,
  61. .reset = sdhci_reset,
  62. .set_uhs_signaling = sdhci_set_uhs_signaling,
  63. };
  64. static const struct sdhci_pltfm_data sdhci_dove_pdata = {
  65. .ops = &sdhci_dove_ops,
  66. .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
  67. SDHCI_QUIRK_NO_BUSY_IRQ |
  68. SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  69. SDHCI_QUIRK_FORCE_DMA |
  70. SDHCI_QUIRK_NO_HISPD_BIT,
  71. };
  72. static int sdhci_dove_probe(struct platform_device *pdev)
  73. {
  74. struct sdhci_host *host;
  75. struct sdhci_pltfm_host *pltfm_host;
  76. struct sdhci_dove_priv *priv;
  77. int ret;
  78. priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv),
  79. GFP_KERNEL);
  80. if (!priv) {
  81. dev_err(&pdev->dev, "unable to allocate private data");
  82. return -ENOMEM;
  83. }
  84. priv->clk = devm_clk_get(&pdev->dev, NULL);
  85. host = sdhci_pltfm_init(pdev, &sdhci_dove_pdata, 0);
  86. if (IS_ERR(host))
  87. return PTR_ERR(host);
  88. pltfm_host = sdhci_priv(host);
  89. pltfm_host->priv = priv;
  90. if (!IS_ERR(priv->clk))
  91. clk_prepare_enable(priv->clk);
  92. ret = mmc_of_parse(host->mmc);
  93. if (ret)
  94. goto err_sdhci_add;
  95. ret = sdhci_add_host(host);
  96. if (ret)
  97. goto err_sdhci_add;
  98. return 0;
  99. err_sdhci_add:
  100. if (!IS_ERR(priv->clk))
  101. clk_disable_unprepare(priv->clk);
  102. sdhci_pltfm_free(pdev);
  103. return ret;
  104. }
  105. static int sdhci_dove_remove(struct platform_device *pdev)
  106. {
  107. struct sdhci_host *host = platform_get_drvdata(pdev);
  108. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  109. struct sdhci_dove_priv *priv = pltfm_host->priv;
  110. sdhci_pltfm_unregister(pdev);
  111. if (!IS_ERR(priv->clk))
  112. clk_disable_unprepare(priv->clk);
  113. return 0;
  114. }
  115. static const struct of_device_id sdhci_dove_of_match_table[] = {
  116. { .compatible = "marvell,dove-sdhci", },
  117. {}
  118. };
  119. MODULE_DEVICE_TABLE(of, sdhci_dove_of_match_table);
  120. static struct platform_driver sdhci_dove_driver = {
  121. .driver = {
  122. .name = "sdhci-dove",
  123. .owner = THIS_MODULE,
  124. .pm = SDHCI_PLTFM_PMOPS,
  125. .of_match_table = sdhci_dove_of_match_table,
  126. },
  127. .probe = sdhci_dove_probe,
  128. .remove = sdhci_dove_remove,
  129. };
  130. module_platform_driver(sdhci_dove_driver);
  131. MODULE_DESCRIPTION("SDHCI driver for Dove");
  132. MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>, "
  133. "Mike Rapoport <mike@compulab.co.il>");
  134. MODULE_LICENSE("GPL v2");