sdhci-sirf.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. .set_clock = sdhci_set_clock,
  28. .get_max_clock = sdhci_sirf_get_max_clk,
  29. .set_bus_width = sdhci_set_bus_width,
  30. .reset = sdhci_reset,
  31. .set_uhs_signaling = sdhci_set_uhs_signaling,
  32. };
  33. static struct sdhci_pltfm_data sdhci_sirf_pdata = {
  34. .ops = &sdhci_sirf_ops,
  35. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  36. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  37. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
  38. SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
  39. SDHCI_QUIRK_DELAY_AFTER_POWER,
  40. };
  41. static int sdhci_sirf_probe(struct platform_device *pdev)
  42. {
  43. struct sdhci_host *host;
  44. struct sdhci_pltfm_host *pltfm_host;
  45. struct sdhci_sirf_priv *priv;
  46. struct clk *clk;
  47. int gpio_cd;
  48. int ret;
  49. clk = devm_clk_get(&pdev->dev, NULL);
  50. if (IS_ERR(clk)) {
  51. dev_err(&pdev->dev, "unable to get clock");
  52. return PTR_ERR(clk);
  53. }
  54. if (pdev->dev.of_node)
  55. gpio_cd = of_get_named_gpio(pdev->dev.of_node, "cd-gpios", 0);
  56. else
  57. gpio_cd = -EINVAL;
  58. host = sdhci_pltfm_init(pdev, &sdhci_sirf_pdata, sizeof(struct sdhci_sirf_priv));
  59. if (IS_ERR(host))
  60. return PTR_ERR(host);
  61. pltfm_host = sdhci_priv(host);
  62. priv = sdhci_pltfm_priv(pltfm_host);
  63. priv->clk = clk;
  64. priv->gpio_cd = gpio_cd;
  65. sdhci_get_of_property(pdev);
  66. ret = clk_prepare_enable(priv->clk);
  67. if (ret)
  68. goto err_clk_prepare;
  69. ret = sdhci_add_host(host);
  70. if (ret)
  71. goto err_sdhci_add;
  72. /*
  73. * We must request the IRQ after sdhci_add_host(), as the tasklet only
  74. * gets setup in sdhci_add_host() and we oops.
  75. */
  76. if (gpio_is_valid(priv->gpio_cd)) {
  77. ret = mmc_gpio_request_cd(host->mmc, priv->gpio_cd, 0);
  78. if (ret) {
  79. dev_err(&pdev->dev, "card detect irq request failed: %d\n",
  80. ret);
  81. goto err_request_cd;
  82. }
  83. }
  84. return 0;
  85. err_request_cd:
  86. sdhci_remove_host(host, 0);
  87. err_sdhci_add:
  88. clk_disable_unprepare(priv->clk);
  89. err_clk_prepare:
  90. sdhci_pltfm_free(pdev);
  91. return ret;
  92. }
  93. static int sdhci_sirf_remove(struct platform_device *pdev)
  94. {
  95. struct sdhci_host *host = platform_get_drvdata(pdev);
  96. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  97. struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
  98. sdhci_pltfm_unregister(pdev);
  99. if (gpio_is_valid(priv->gpio_cd))
  100. mmc_gpio_free_cd(host->mmc);
  101. clk_disable_unprepare(priv->clk);
  102. return 0;
  103. }
  104. #ifdef CONFIG_PM_SLEEP
  105. static int sdhci_sirf_suspend(struct device *dev)
  106. {
  107. struct sdhci_host *host = dev_get_drvdata(dev);
  108. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  109. struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
  110. int ret;
  111. ret = sdhci_suspend_host(host);
  112. if (ret)
  113. return ret;
  114. clk_disable(priv->clk);
  115. return 0;
  116. }
  117. static int sdhci_sirf_resume(struct device *dev)
  118. {
  119. struct sdhci_host *host = dev_get_drvdata(dev);
  120. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  121. struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host);
  122. int ret;
  123. ret = clk_enable(priv->clk);
  124. if (ret) {
  125. dev_dbg(dev, "Resume: Error enabling clock\n");
  126. return ret;
  127. }
  128. return sdhci_resume_host(host);
  129. }
  130. static SIMPLE_DEV_PM_OPS(sdhci_sirf_pm_ops, sdhci_sirf_suspend, sdhci_sirf_resume);
  131. #endif
  132. static const struct of_device_id sdhci_sirf_of_match[] = {
  133. { .compatible = "sirf,prima2-sdhc" },
  134. { }
  135. };
  136. MODULE_DEVICE_TABLE(of, sdhci_sirf_of_match);
  137. static struct platform_driver sdhci_sirf_driver = {
  138. .driver = {
  139. .name = "sdhci-sirf",
  140. .owner = THIS_MODULE,
  141. .of_match_table = sdhci_sirf_of_match,
  142. #ifdef CONFIG_PM_SLEEP
  143. .pm = &sdhci_sirf_pm_ops,
  144. #endif
  145. },
  146. .probe = sdhci_sirf_probe,
  147. .remove = sdhci_sirf_remove,
  148. };
  149. module_platform_driver(sdhci_sirf_driver);
  150. MODULE_DESCRIPTION("SDHCI driver for SiRFprimaII/SiRFmarco");
  151. MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
  152. MODULE_LICENSE("GPL v2");