sdhci-brcmstb.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. res = sdhci_suspend_host(host);
  28. if (res)
  29. return res;
  30. clk_disable_unprepare(pltfm_host->clk);
  31. return res;
  32. }
  33. static int sdhci_brcmstb_resume(struct device *dev)
  34. {
  35. struct sdhci_host *host = dev_get_drvdata(dev);
  36. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  37. int err;
  38. err = clk_prepare_enable(pltfm_host->clk);
  39. if (err)
  40. return err;
  41. return sdhci_resume_host(host);
  42. }
  43. #endif /* CONFIG_PM_SLEEP */
  44. static SIMPLE_DEV_PM_OPS(sdhci_brcmstb_pmops, sdhci_brcmstb_suspend,
  45. sdhci_brcmstb_resume);
  46. static const struct sdhci_ops sdhci_brcmstb_ops = {
  47. .set_clock = sdhci_set_clock,
  48. .set_bus_width = sdhci_set_bus_width,
  49. .reset = sdhci_reset,
  50. .set_uhs_signaling = sdhci_set_uhs_signaling,
  51. };
  52. static struct sdhci_pltfm_data sdhci_brcmstb_pdata = {
  53. .ops = &sdhci_brcmstb_ops,
  54. };
  55. static int sdhci_brcmstb_probe(struct platform_device *pdev)
  56. {
  57. struct sdhci_host *host;
  58. struct sdhci_pltfm_host *pltfm_host;
  59. struct clk *clk;
  60. int res;
  61. clk = devm_clk_get(&pdev->dev, NULL);
  62. if (IS_ERR(clk)) {
  63. dev_err(&pdev->dev, "Clock not found in Device Tree\n");
  64. clk = NULL;
  65. }
  66. res = clk_prepare_enable(clk);
  67. if (res)
  68. return res;
  69. host = sdhci_pltfm_init(pdev, &sdhci_brcmstb_pdata, 0);
  70. if (IS_ERR(host)) {
  71. res = PTR_ERR(host);
  72. goto err_clk;
  73. }
  74. /* Enable MMC_CAP2_HC_ERASE_SZ for better max discard calculations */
  75. host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
  76. sdhci_get_of_property(pdev);
  77. mmc_of_parse(host->mmc);
  78. /*
  79. * Supply the existing CAPS, but clear the UHS modes. This
  80. * will allow these modes to be specified by device tree
  81. * properties through mmc_of_parse().
  82. */
  83. host->caps = sdhci_readl(host, SDHCI_CAPABILITIES);
  84. host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
  85. host->caps1 &= ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 |
  86. SDHCI_SUPPORT_DDR50);
  87. host->quirks |= SDHCI_QUIRK_MISSING_CAPS |
  88. SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
  89. res = sdhci_add_host(host);
  90. if (res)
  91. goto err;
  92. pltfm_host = sdhci_priv(host);
  93. pltfm_host->clk = clk;
  94. return res;
  95. err:
  96. sdhci_pltfm_free(pdev);
  97. err_clk:
  98. clk_disable_unprepare(clk);
  99. return res;
  100. }
  101. static const struct of_device_id sdhci_brcm_of_match[] = {
  102. { .compatible = "brcm,bcm7425-sdhci" },
  103. {},
  104. };
  105. MODULE_DEVICE_TABLE(of, sdhci_brcm_of_match);
  106. static struct platform_driver sdhci_brcmstb_driver = {
  107. .driver = {
  108. .name = "sdhci-brcmstb",
  109. .owner = THIS_MODULE,
  110. .pm = &sdhci_brcmstb_pmops,
  111. .of_match_table = of_match_ptr(sdhci_brcm_of_match),
  112. },
  113. .probe = sdhci_brcmstb_probe,
  114. .remove = sdhci_pltfm_unregister,
  115. };
  116. module_platform_driver(sdhci_brcmstb_driver);
  117. MODULE_DESCRIPTION("SDHCI driver for Broadcom BRCMSTB SoCs");
  118. MODULE_AUTHOR("Broadcom");
  119. MODULE_LICENSE("GPL v2");