tegra-aconnect.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Tegra ACONNECT Bus Driver
  3. *
  4. * Copyright (C) 2016, NVIDIA CORPORATION. All rights reserved.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/module.h>
  12. #include <linux/of_platform.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/pm_runtime.h>
  15. struct tegra_aconnect {
  16. struct clk *ape_clk;
  17. struct clk *apb2ape_clk;
  18. };
  19. static int tegra_aconnect_probe(struct platform_device *pdev)
  20. {
  21. struct tegra_aconnect *aconnect;
  22. if (!pdev->dev.of_node)
  23. return -EINVAL;
  24. aconnect = devm_kzalloc(&pdev->dev, sizeof(struct tegra_aconnect),
  25. GFP_KERNEL);
  26. if (!aconnect)
  27. return -ENOMEM;
  28. aconnect->ape_clk = devm_clk_get(&pdev->dev, "ape");
  29. if (IS_ERR(aconnect->ape_clk)) {
  30. dev_err(&pdev->dev, "Can't retrieve ape clock\n");
  31. return PTR_ERR(aconnect->ape_clk);
  32. }
  33. aconnect->apb2ape_clk = devm_clk_get(&pdev->dev, "apb2ape");
  34. if (IS_ERR(aconnect->apb2ape_clk)) {
  35. dev_err(&pdev->dev, "Can't retrieve apb2ape clock\n");
  36. return PTR_ERR(aconnect->apb2ape_clk);
  37. }
  38. dev_set_drvdata(&pdev->dev, aconnect);
  39. pm_runtime_enable(&pdev->dev);
  40. of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
  41. dev_info(&pdev->dev, "Tegra ACONNECT bus registered\n");
  42. return 0;
  43. }
  44. static int tegra_aconnect_remove(struct platform_device *pdev)
  45. {
  46. pm_runtime_disable(&pdev->dev);
  47. return 0;
  48. }
  49. static int tegra_aconnect_runtime_resume(struct device *dev)
  50. {
  51. struct tegra_aconnect *aconnect = dev_get_drvdata(dev);
  52. int ret;
  53. ret = clk_prepare_enable(aconnect->ape_clk);
  54. if (ret) {
  55. dev_err(dev, "ape clk_enable failed: %d\n", ret);
  56. return ret;
  57. }
  58. ret = clk_prepare_enable(aconnect->apb2ape_clk);
  59. if (ret) {
  60. clk_disable_unprepare(aconnect->ape_clk);
  61. dev_err(dev, "apb2ape clk_enable failed: %d\n", ret);
  62. return ret;
  63. }
  64. return 0;
  65. }
  66. static int tegra_aconnect_runtime_suspend(struct device *dev)
  67. {
  68. struct tegra_aconnect *aconnect = dev_get_drvdata(dev);
  69. clk_disable_unprepare(aconnect->ape_clk);
  70. clk_disable_unprepare(aconnect->apb2ape_clk);
  71. return 0;
  72. }
  73. static const struct dev_pm_ops tegra_aconnect_pm_ops = {
  74. SET_RUNTIME_PM_OPS(tegra_aconnect_runtime_suspend,
  75. tegra_aconnect_runtime_resume, NULL)
  76. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
  77. pm_runtime_force_resume)
  78. };
  79. static const struct of_device_id tegra_aconnect_of_match[] = {
  80. { .compatible = "nvidia,tegra210-aconnect", },
  81. { }
  82. };
  83. MODULE_DEVICE_TABLE(of, tegra_aconnect_of_match);
  84. static struct platform_driver tegra_aconnect_driver = {
  85. .probe = tegra_aconnect_probe,
  86. .remove = tegra_aconnect_remove,
  87. .driver = {
  88. .name = "tegra-aconnect",
  89. .of_match_table = tegra_aconnect_of_match,
  90. .pm = &tegra_aconnect_pm_ops,
  91. },
  92. };
  93. module_platform_driver(tegra_aconnect_driver);
  94. MODULE_DESCRIPTION("NVIDIA Tegra ACONNECT Bus Driver");
  95. MODULE_AUTHOR("Jon Hunter <jonathanh@nvidia.com>");
  96. MODULE_LICENSE("GPL v2");