ci_hdrc_tegra.c 3.5 KB

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