sdhci-sirf.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * SDHCI support for SiRF primaII and marco SoCs
  3. *
  4. * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/device.h>
  10. #include <linux/mmc/host.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/of_gpio.h>
  14. #include <linux/mmc/slot-gpio.h>
  15. #include "sdhci-pltfm.h"
  16. struct sdhci_sirf_priv {
  17. struct clk *clk;
  18. int gpio_cd;
  19. };
  20. static unsigned int sdhci_sirf_get_max_clk(struct sdhci_host *host)
  21. {
  22. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  23. struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
  24. return clk_get_rate(priv->clk);
  25. }
  26. static struct sdhci_ops sdhci_sirf_ops = {
  27. .get_max_clock = sdhci_sirf_get_max_clk,
  28. };
  29. static struct sdhci_pltfm_data sdhci_sirf_pdata = {
  30. .ops = &sdhci_sirf_ops,
  31. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  32. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  33. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
  34. SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
  35. SDHCI_QUIRK_DELAY_AFTER_POWER,
  36. };
  37. static int sdhci_sirf_probe(struct platform_device *pdev)
  38. {
  39. struct sdhci_host *host;
  40. struct sdhci_pltfm_host *pltfm_host;
  41. struct sdhci_sirf_priv *priv;
  42. struct clk *clk;
  43. int gpio_cd;
  44. int ret;
  45. clk = devm_clk_get(&pdev->dev, NULL);
  46. if (IS_ERR(clk)) {
  47. dev_err(&pdev->dev, "unable to get clock");
  48. return PTR_ERR(clk);
  49. }
  50. if (pdev->dev.of_node)
  51. gpio_cd = of_get_named_gpio(pdev->dev.of_node, "cd-gpios", 0);
  52. else
  53. gpio_cd = -EINVAL;
  54. host = sdhci_pltfm_init(pdev, &sdhci_sirf_pdata, sizeof(struct sdhci_sirf_priv));
  55. if (IS_ERR(host))
  56. return PTR_ERR(host);
  57. pltfm_host = sdhci_priv(host);
  58. priv = sdhci_pltfm_priv(pltfm_host);
  59. priv->clk = clk;
  60. priv->gpio_cd = gpio_cd;
  61. sdhci_get_of_property(pdev);
  62. ret = clk_prepare_enable(priv->clk);
  63. if (ret)
  64. goto err_clk_prepare;
  65. ret = sdhci_add_host(host);
  66. if (ret)
  67. goto err_sdhci_add;
  68. /*
  69. * We must request the IRQ after sdhci_add_host(), as the tasklet only
  70. * gets setup in sdhci_add_host() and we oops.
  71. */
  72. if (gpio_is_valid(priv->gpio_cd)) {
  73. ret = mmc_gpio_request_cd(host->mmc, priv->gpio_cd, 0);
  74. if (ret) {
  75. dev_err(&pdev->dev, "card detect irq request failed: %d\n",
  76. ret);
  77. goto err_request_cd;
  78. }
  79. }
  80. return 0;
  81. err_request_cd:
  82. sdhci_remove_host(host, 0);
  83. err_sdhci_add:
  84. clk_disable_unprepare(priv->clk);
  85. err_clk_prepare:
  86. sdhci_pltfm_free(pdev);
  87. return ret;
  88. }
  89. static int sdhci_sirf_remove(struct platform_device *pdev)
  90. {
  91. struct sdhci_host *host = platform_get_drvdata(pdev);
  92. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  93. struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
  94. sdhci_pltfm_unregister(pdev);
  95. if (gpio_is_valid(priv->gpio_cd))
  96. mmc_gpio_free_cd(host->mmc);
  97. clk_disable_unprepare(priv->clk);
  98. return 0;
  99. }
  100. #ifdef CONFIG_PM_SLEEP
  101. static int sdhci_sirf_suspend(struct device *dev)
  102. {
  103. struct sdhci_host *host = dev_get_drvdata(dev);
  104. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  105. struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
  106. int ret;
  107. ret = sdhci_suspend_host(host);
  108. if (ret)
  109. return ret;
  110. clk_disable(priv->clk);
  111. return 0;
  112. }
  113. static int sdhci_sirf_resume(struct device *dev)
  114. {
  115. struct sdhci_host *host = dev_get_drvdata(dev);
  116. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  117. struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
  118. int ret;
  119. ret = clk_enable(priv->clk);
  120. if (ret) {
  121. dev_dbg(dev, "Resume: Error enabling clock\n");
  122. return ret;
  123. }
  124. return sdhci_resume_host(host);
  125. }
  126. static SIMPLE_DEV_PM_OPS(sdhci_sirf_pm_ops, sdhci_sirf_suspend, sdhci_sirf_resume);
  127. #endif
  128. static const struct of_device_id sdhci_sirf_of_match[] = {
  129. { .compatible = "sirf,prima2-sdhc" },
  130. { }
  131. };
  132. MODULE_DEVICE_TABLE(of, sdhci_sirf_of_match);
  133. static struct platform_driver sdhci_sirf_driver = {
  134. .driver = {
  135. .name = "sdhci-sirf",
  136. .owner = THIS_MODULE,
  137. .of_match_table = sdhci_sirf_of_match,
  138. #ifdef CONFIG_PM_SLEEP
  139. .pm = &sdhci_sirf_pm_ops,
  140. #endif
  141. },
  142. .probe = sdhci_sirf_probe,
  143. .remove = sdhci_sirf_remove,
  144. };
  145. module_platform_driver(sdhci_sirf_driver);
  146. MODULE_DESCRIPTION("SDHCI driver for SiRFprimaII/SiRFmarco");
  147. MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
  148. MODULE_LICENSE("GPL v2");