ci_hdrc_tegra.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2016, NVIDIA Corporation
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/module.h>
  7. #include <linux/of_device.h>
  8. #include <linux/reset.h>
  9. #include <linux/usb/chipidea.h>
  10. #include "ci.h"
  11. struct tegra_udc {
  12. struct ci_hdrc_platform_data data;
  13. struct platform_device *dev;
  14. struct usb_phy *phy;
  15. struct clk *clk;
  16. };
  17. struct tegra_udc_soc_info {
  18. unsigned long flags;
  19. };
  20. static const struct tegra_udc_soc_info tegra20_udc_soc_info = {
  21. .flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
  22. };
  23. static const struct tegra_udc_soc_info tegra30_udc_soc_info = {
  24. .flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
  25. };
  26. static const struct tegra_udc_soc_info tegra114_udc_soc_info = {
  27. .flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
  28. };
  29. static const struct tegra_udc_soc_info tegra124_udc_soc_info = {
  30. .flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
  31. };
  32. static const struct of_device_id tegra_udc_of_match[] = {
  33. {
  34. .compatible = "nvidia,tegra20-udc",
  35. .data = &tegra20_udc_soc_info,
  36. }, {
  37. .compatible = "nvidia,tegra30-udc",
  38. .data = &tegra30_udc_soc_info,
  39. }, {
  40. .compatible = "nvidia,tegra114-udc",
  41. .data = &tegra114_udc_soc_info,
  42. }, {
  43. .compatible = "nvidia,tegra124-udc",
  44. .data = &tegra124_udc_soc_info,
  45. }, {
  46. /* sentinel */
  47. }
  48. };
  49. MODULE_DEVICE_TABLE(of, tegra_udc_of_match);
  50. static int tegra_udc_probe(struct platform_device *pdev)
  51. {
  52. const struct tegra_udc_soc_info *soc;
  53. struct tegra_udc *udc;
  54. int err;
  55. udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL);
  56. if (!udc)
  57. return -ENOMEM;
  58. soc = of_device_get_match_data(&pdev->dev);
  59. if (!soc) {
  60. dev_err(&pdev->dev, "failed to match OF data\n");
  61. return -EINVAL;
  62. }
  63. udc->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
  64. if (IS_ERR(udc->phy)) {
  65. err = PTR_ERR(udc->phy);
  66. dev_err(&pdev->dev, "failed to get PHY: %d\n", err);
  67. return err;
  68. }
  69. udc->clk = devm_clk_get(&pdev->dev, NULL);
  70. if (IS_ERR(udc->clk)) {
  71. err = PTR_ERR(udc->clk);
  72. dev_err(&pdev->dev, "failed to get clock: %d\n", err);
  73. return err;
  74. }
  75. err = clk_prepare_enable(udc->clk);
  76. if (err < 0) {
  77. dev_err(&pdev->dev, "failed to enable clock: %d\n", err);
  78. return err;
  79. }
  80. /*
  81. * Tegra's USB PHY driver doesn't implement optional phy_init()
  82. * hook, so we have to power on UDC controller before ChipIdea
  83. * driver initialization kicks in.
  84. */
  85. usb_phy_set_suspend(udc->phy, 0);
  86. /* setup and register ChipIdea HDRC device */
  87. udc->data.name = "tegra-udc";
  88. udc->data.flags = soc->flags;
  89. udc->data.usb_phy = udc->phy;
  90. udc->data.capoffset = DEF_CAPOFFSET;
  91. udc->dev = ci_hdrc_add_device(&pdev->dev, pdev->resource,
  92. pdev->num_resources, &udc->data);
  93. if (IS_ERR(udc->dev)) {
  94. err = PTR_ERR(udc->dev);
  95. dev_err(&pdev->dev, "failed to add HDRC device: %d\n", err);
  96. goto fail_power_off;
  97. }
  98. platform_set_drvdata(pdev, udc);
  99. return 0;
  100. fail_power_off:
  101. usb_phy_set_suspend(udc->phy, 1);
  102. clk_disable_unprepare(udc->clk);
  103. return err;
  104. }
  105. static int tegra_udc_remove(struct platform_device *pdev)
  106. {
  107. struct tegra_udc *udc = platform_get_drvdata(pdev);
  108. ci_hdrc_remove_device(udc->dev);
  109. usb_phy_set_suspend(udc->phy, 1);
  110. clk_disable_unprepare(udc->clk);
  111. return 0;
  112. }
  113. static struct platform_driver tegra_udc_driver = {
  114. .driver = {
  115. .name = "tegra-udc",
  116. .of_match_table = tegra_udc_of_match,
  117. },
  118. .probe = tegra_udc_probe,
  119. .remove = tegra_udc_remove,
  120. };
  121. module_platform_driver(tegra_udc_driver);
  122. MODULE_DESCRIPTION("NVIDIA Tegra USB device mode driver");
  123. MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
  124. MODULE_ALIAS("platform:tegra-udc");
  125. MODULE_LICENSE("GPL v2");