sdhci-brcmstb.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * sdhci-brcmstb.c Support for SDHCI on Broadcom BRCMSTB SoC's
  3. *
  4. * Copyright (C) 2015 Broadcom Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/io.h>
  17. #include <linux/mmc/host.h>
  18. #include <linux/module.h>
  19. #include <linux/of.h>
  20. #include "sdhci-pltfm.h"
  21. #ifdef CONFIG_PM_SLEEP
  22. static int sdhci_brcmstb_suspend(struct device *dev)
  23. {
  24. struct sdhci_host *host = dev_get_drvdata(dev);
  25. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  26. int res;
  27. if (host->tuning_mode != SDHCI_TUNING_MODE_3)
  28. mmc_retune_needed(host->mmc);
  29. res = sdhci_suspend_host(host);
  30. if (res)
  31. return res;
  32. clk_disable_unprepare(pltfm_host->clk);
  33. return res;
  34. }
  35. static int sdhci_brcmstb_resume(struct device *dev)
  36. {
  37. struct sdhci_host *host = dev_get_drvdata(dev);
  38. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  39. int err;
  40. err = clk_prepare_enable(pltfm_host->clk);
  41. if (err)
  42. return err;
  43. return sdhci_resume_host(host);
  44. }
  45. #endif /* CONFIG_PM_SLEEP */
  46. static SIMPLE_DEV_PM_OPS(sdhci_brcmstb_pmops, sdhci_brcmstb_suspend,
  47. sdhci_brcmstb_resume);
  48. static const struct sdhci_ops sdhci_brcmstb_ops = {
  49. .set_clock = sdhci_set_clock,
  50. .set_bus_width = sdhci_set_bus_width,
  51. .reset = sdhci_reset,
  52. .set_uhs_signaling = sdhci_set_uhs_signaling,
  53. };
  54. static struct sdhci_pltfm_data sdhci_brcmstb_pdata = {
  55. .ops = &sdhci_brcmstb_ops,
  56. };
  57. static int sdhci_brcmstb_probe(struct platform_device *pdev)
  58. {
  59. struct sdhci_host *host;
  60. struct sdhci_pltfm_host *pltfm_host;
  61. struct clk *clk;
  62. int res;
  63. clk = devm_clk_get(&pdev->dev, NULL);
  64. if (IS_ERR(clk)) {
  65. dev_err(&pdev->dev, "Clock not found in Device Tree\n");
  66. clk = NULL;
  67. }
  68. res = clk_prepare_enable(clk);
  69. if (res)
  70. return res;
  71. host = sdhci_pltfm_init(pdev, &sdhci_brcmstb_pdata, 0);
  72. if (IS_ERR(host)) {
  73. res = PTR_ERR(host);
  74. goto err_clk;
  75. }
  76. /* Enable MMC_CAP2_HC_ERASE_SZ for better max discard calculations */
  77. host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
  78. sdhci_get_of_property(pdev);
  79. mmc_of_parse(host->mmc);
  80. /*
  81. * Supply the existing CAPS, but clear the UHS modes. This
  82. * will allow these modes to be specified by device tree
  83. * properties through mmc_of_parse().
  84. */
  85. host->caps = sdhci_readl(host, SDHCI_CAPABILITIES);
  86. if (of_device_is_compatible(pdev->dev.of_node, "brcm,bcm7425-sdhci"))
  87. host->caps &= ~SDHCI_CAN_64BIT;
  88. host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
  89. host->caps1 &= ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 |
  90. SDHCI_SUPPORT_DDR50);
  91. host->quirks |= SDHCI_QUIRK_MISSING_CAPS |
  92. SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
  93. res = sdhci_add_host(host);
  94. if (res)
  95. goto err;
  96. pltfm_host = sdhci_priv(host);
  97. pltfm_host->clk = clk;
  98. return res;
  99. err:
  100. sdhci_pltfm_free(pdev);
  101. err_clk:
  102. clk_disable_unprepare(clk);
  103. return res;
  104. }
  105. static const struct of_device_id sdhci_brcm_of_match[] = {
  106. { .compatible = "brcm,bcm7425-sdhci" },
  107. { .compatible = "brcm,bcm7445-sdhci" },
  108. {},
  109. };
  110. MODULE_DEVICE_TABLE(of, sdhci_brcm_of_match);
  111. static struct platform_driver sdhci_brcmstb_driver = {
  112. .driver = {
  113. .name = "sdhci-brcmstb",
  114. .pm = &sdhci_brcmstb_pmops,
  115. .of_match_table = of_match_ptr(sdhci_brcm_of_match),
  116. },
  117. .probe = sdhci_brcmstb_probe,
  118. .remove = sdhci_pltfm_unregister,
  119. };
  120. module_platform_driver(sdhci_brcmstb_driver);
  121. MODULE_DESCRIPTION("SDHCI driver for Broadcom BRCMSTB SoCs");
  122. MODULE_AUTHOR("Broadcom");
  123. MODULE_LICENSE("GPL v2");