tegra-aconnect.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 void tegra_aconnect_remove(struct platform_device *pdev)
  45. {
  46. pm_runtime_disable(&pdev->dev);
  47. }
  48. static int tegra_aconnect_runtime_resume(struct device *dev)
  49. {
  50. struct tegra_aconnect *aconnect = dev_get_drvdata(dev);
  51. int ret;
  52. ret = clk_prepare_enable(aconnect->ape_clk);
  53. if (ret) {
  54. dev_err(dev, "ape clk_enable failed: %d\n", ret);
  55. return ret;
  56. }
  57. ret = clk_prepare_enable(aconnect->apb2ape_clk);
  58. if (ret) {
  59. clk_disable_unprepare(aconnect->ape_clk);
  60. dev_err(dev, "apb2ape clk_enable failed: %d\n", ret);
  61. return ret;
  62. }
  63. return 0;
  64. }
  65. static int tegra_aconnect_runtime_suspend(struct device *dev)
  66. {
  67. struct tegra_aconnect *aconnect = dev_get_drvdata(dev);
  68. clk_disable_unprepare(aconnect->ape_clk);
  69. clk_disable_unprepare(aconnect->apb2ape_clk);
  70. return 0;
  71. }
  72. static const struct dev_pm_ops tegra_aconnect_pm_ops = {
  73. SET_RUNTIME_PM_OPS(tegra_aconnect_runtime_suspend,
  74. tegra_aconnect_runtime_resume, NULL)
  75. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
  76. pm_runtime_force_resume)
  77. };
  78. static const struct of_device_id tegra_aconnect_of_match[] = {
  79. { .compatible = "nvidia,tegra210-aconnect", },
  80. { }
  81. };
  82. MODULE_DEVICE_TABLE(of, tegra_aconnect_of_match);
  83. static struct platform_driver tegra_aconnect_driver = {
  84. .probe = tegra_aconnect_probe,
  85. .remove_new = tegra_aconnect_remove,
  86. .driver = {
  87. .name = "tegra-aconnect",
  88. .of_match_table = tegra_aconnect_of_match,
  89. .pm = &tegra_aconnect_pm_ops,
  90. },
  91. };
  92. module_platform_driver(tegra_aconnect_driver);
  93. MODULE_DESCRIPTION("NVIDIA Tegra ACONNECT Bus Driver");
  94. MODULE_AUTHOR("Jon Hunter <jonathanh@nvidia.com>");
  95. MODULE_LICENSE("GPL v2");