sdhci-brcmstb.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. static const struct sdhci_ops sdhci_brcmstb_ops = {
  22. .set_clock = sdhci_set_clock,
  23. .set_bus_width = sdhci_set_bus_width,
  24. .reset = sdhci_reset,
  25. .set_uhs_signaling = sdhci_set_uhs_signaling,
  26. };
  27. static const struct sdhci_pltfm_data sdhci_brcmstb_pdata = {
  28. .ops = &sdhci_brcmstb_ops,
  29. };
  30. static int sdhci_brcmstb_probe(struct platform_device *pdev)
  31. {
  32. struct sdhci_host *host;
  33. struct sdhci_pltfm_host *pltfm_host;
  34. struct clk *clk;
  35. int res;
  36. clk = devm_clk_get(&pdev->dev, NULL);
  37. if (IS_ERR(clk)) {
  38. dev_err(&pdev->dev, "Clock not found in Device Tree\n");
  39. clk = NULL;
  40. }
  41. res = clk_prepare_enable(clk);
  42. if (res)
  43. return res;
  44. host = sdhci_pltfm_init(pdev, &sdhci_brcmstb_pdata, 0);
  45. if (IS_ERR(host)) {
  46. res = PTR_ERR(host);
  47. goto err_clk;
  48. }
  49. sdhci_get_of_property(pdev);
  50. res = mmc_of_parse(host->mmc);
  51. if (res)
  52. goto err;
  53. /*
  54. * Supply the existing CAPS, but clear the UHS modes. This
  55. * will allow these modes to be specified by device tree
  56. * properties through mmc_of_parse().
  57. */
  58. host->caps = sdhci_readl(host, SDHCI_CAPABILITIES);
  59. if (of_device_is_compatible(pdev->dev.of_node, "brcm,bcm7425-sdhci"))
  60. host->caps &= ~SDHCI_CAN_64BIT;
  61. host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
  62. host->caps1 &= ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 |
  63. SDHCI_SUPPORT_DDR50);
  64. host->quirks |= SDHCI_QUIRK_MISSING_CAPS |
  65. SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
  66. res = sdhci_add_host(host);
  67. if (res)
  68. goto err;
  69. pltfm_host = sdhci_priv(host);
  70. pltfm_host->clk = clk;
  71. return res;
  72. err:
  73. sdhci_pltfm_free(pdev);
  74. err_clk:
  75. clk_disable_unprepare(clk);
  76. return res;
  77. }
  78. static const struct of_device_id sdhci_brcm_of_match[] = {
  79. { .compatible = "brcm,bcm7425-sdhci" },
  80. { .compatible = "brcm,bcm7445-sdhci" },
  81. {},
  82. };
  83. MODULE_DEVICE_TABLE(of, sdhci_brcm_of_match);
  84. static struct platform_driver sdhci_brcmstb_driver = {
  85. .driver = {
  86. .name = "sdhci-brcmstb",
  87. .pm = &sdhci_pltfm_pmops,
  88. .of_match_table = of_match_ptr(sdhci_brcm_of_match),
  89. },
  90. .probe = sdhci_brcmstb_probe,
  91. .remove = sdhci_pltfm_unregister,
  92. };
  93. module_platform_driver(sdhci_brcmstb_driver);
  94. MODULE_DESCRIPTION("SDHCI driver for Broadcom BRCMSTB SoCs");
  95. MODULE_AUTHOR("Broadcom");
  96. MODULE_LICENSE("GPL v2");