tegra-aconnect.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_clock.h>
  15. #include <linux/pm_runtime.h>
  16. static int tegra_aconnect_add_clock(struct device *dev, char *name)
  17. {
  18. struct clk *clk;
  19. int ret;
  20. clk = clk_get(dev, name);
  21. if (IS_ERR(clk)) {
  22. dev_err(dev, "%s clock not found\n", name);
  23. return PTR_ERR(clk);
  24. }
  25. ret = pm_clk_add_clk(dev, clk);
  26. if (ret)
  27. clk_put(clk);
  28. return ret;
  29. }
  30. static int tegra_aconnect_probe(struct platform_device *pdev)
  31. {
  32. int ret;
  33. if (!pdev->dev.of_node)
  34. return -EINVAL;
  35. ret = pm_clk_create(&pdev->dev);
  36. if (ret)
  37. return ret;
  38. ret = tegra_aconnect_add_clock(&pdev->dev, "ape");
  39. if (ret)
  40. goto clk_destroy;
  41. ret = tegra_aconnect_add_clock(&pdev->dev, "apb2ape");
  42. if (ret)
  43. goto clk_destroy;
  44. pm_runtime_enable(&pdev->dev);
  45. of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
  46. dev_info(&pdev->dev, "Tegra ACONNECT bus registered\n");
  47. return 0;
  48. clk_destroy:
  49. pm_clk_destroy(&pdev->dev);
  50. return ret;
  51. }
  52. static int tegra_aconnect_remove(struct platform_device *pdev)
  53. {
  54. pm_runtime_disable(&pdev->dev);
  55. pm_clk_destroy(&pdev->dev);
  56. return 0;
  57. }
  58. static int tegra_aconnect_runtime_resume(struct device *dev)
  59. {
  60. return pm_clk_resume(dev);
  61. }
  62. static int tegra_aconnect_runtime_suspend(struct device *dev)
  63. {
  64. return pm_clk_suspend(dev);
  65. }
  66. static const struct dev_pm_ops tegra_aconnect_pm_ops = {
  67. SET_RUNTIME_PM_OPS(tegra_aconnect_runtime_suspend,
  68. tegra_aconnect_runtime_resume, NULL)
  69. };
  70. static const struct of_device_id tegra_aconnect_of_match[] = {
  71. { .compatible = "nvidia,tegra210-aconnect", },
  72. { }
  73. };
  74. MODULE_DEVICE_TABLE(of, tegra_aconnect_of_match);
  75. static struct platform_driver tegra_aconnect_driver = {
  76. .probe = tegra_aconnect_probe,
  77. .remove = tegra_aconnect_remove,
  78. .driver = {
  79. .name = "tegra-aconnect",
  80. .of_match_table = tegra_aconnect_of_match,
  81. .pm = &tegra_aconnect_pm_ops,
  82. },
  83. };
  84. module_platform_driver(tegra_aconnect_driver);
  85. MODULE_DESCRIPTION("NVIDIA Tegra ACONNECT Bus Driver");
  86. MODULE_AUTHOR("Jon Hunter <jonathanh@nvidia.com>");
  87. MODULE_LICENSE("GPL v2");