Loading...
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
11#include <linux/clk.h>
12#include <linux/module.h>
13#include <linux/of_platform.h>
14#include <linux/platform_device.h>
15#include <linux/pm_runtime.h>
16
17struct tegra_aconnect {
18 struct clk *ape_clk;
19 struct clk *apb2ape_clk;
20};
21
22static int tegra_aconnect_probe(struct platform_device *pdev)
23{
24 struct tegra_aconnect *aconnect;
25
26 if (!pdev->dev.of_node)
27 return -EINVAL;
28
29 aconnect = devm_kzalloc(&pdev->dev, sizeof(struct tegra_aconnect),
30 GFP_KERNEL);
31 if (!aconnect)
32 return -ENOMEM;
33
34 aconnect->ape_clk = devm_clk_get(&pdev->dev, "ape");
35 if (IS_ERR(aconnect->ape_clk)) {
36 dev_err(&pdev->dev, "Can't retrieve ape clock\n");
37 return PTR_ERR(aconnect->ape_clk);
38 }
39
40 aconnect->apb2ape_clk = devm_clk_get(&pdev->dev, "apb2ape");
41 if (IS_ERR(aconnect->apb2ape_clk)) {
42 dev_err(&pdev->dev, "Can't retrieve apb2ape clock\n");
43 return PTR_ERR(aconnect->apb2ape_clk);
44 }
45
46 dev_set_drvdata(&pdev->dev, aconnect);
47 pm_runtime_enable(&pdev->dev);
48
49 of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
50
51 dev_info(&pdev->dev, "Tegra ACONNECT bus registered\n");
52
53 return 0;
54}
55
56static void tegra_aconnect_remove(struct platform_device *pdev)
57{
58 pm_runtime_disable(&pdev->dev);
59}
60
61static int tegra_aconnect_runtime_resume(struct device *dev)
62{
63 struct tegra_aconnect *aconnect = dev_get_drvdata(dev);
64 int ret;
65
66 ret = clk_prepare_enable(aconnect->ape_clk);
67 if (ret) {
68 dev_err(dev, "ape clk_enable failed: %d\n", ret);
69 return ret;
70 }
71
72 ret = clk_prepare_enable(aconnect->apb2ape_clk);
73 if (ret) {
74 clk_disable_unprepare(aconnect->ape_clk);
75 dev_err(dev, "apb2ape clk_enable failed: %d\n", ret);
76 return ret;
77 }
78
79 return 0;
80}
81
82static int tegra_aconnect_runtime_suspend(struct device *dev)
83{
84 struct tegra_aconnect *aconnect = dev_get_drvdata(dev);
85
86 clk_disable_unprepare(aconnect->ape_clk);
87 clk_disable_unprepare(aconnect->apb2ape_clk);
88
89 return 0;
90}
91
92static const struct dev_pm_ops tegra_aconnect_pm_ops = {
93 SET_RUNTIME_PM_OPS(tegra_aconnect_runtime_suspend,
94 tegra_aconnect_runtime_resume, NULL)
95 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
96 pm_runtime_force_resume)
97};
98
99static const struct of_device_id tegra_aconnect_of_match[] = {
100 { .compatible = "nvidia,tegra210-aconnect", },
101 { }
102};
103MODULE_DEVICE_TABLE(of, tegra_aconnect_of_match);
104
105static struct platform_driver tegra_aconnect_driver = {
106 .probe = tegra_aconnect_probe,
107 .remove = tegra_aconnect_remove,
108 .driver = {
109 .name = "tegra-aconnect",
110 .of_match_table = tegra_aconnect_of_match,
111 .pm = &tegra_aconnect_pm_ops,
112 },
113};
114module_platform_driver(tegra_aconnect_driver);
115
116MODULE_DESCRIPTION("NVIDIA Tegra ACONNECT Bus Driver");
117MODULE_AUTHOR("Jon Hunter <jonathanh@nvidia.com>");
118MODULE_LICENSE("GPL v2");
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
11#include <linux/clk.h>
12#include <linux/module.h>
13#include <linux/of_platform.h>
14#include <linux/platform_device.h>
15#include <linux/pm_runtime.h>
16
17struct tegra_aconnect {
18 struct clk *ape_clk;
19 struct clk *apb2ape_clk;
20};
21
22static int tegra_aconnect_probe(struct platform_device *pdev)
23{
24 struct tegra_aconnect *aconnect;
25
26 if (!pdev->dev.of_node)
27 return -EINVAL;
28
29 aconnect = devm_kzalloc(&pdev->dev, sizeof(struct tegra_aconnect),
30 GFP_KERNEL);
31 if (!aconnect)
32 return -ENOMEM;
33
34 aconnect->ape_clk = devm_clk_get(&pdev->dev, "ape");
35 if (IS_ERR(aconnect->ape_clk)) {
36 dev_err(&pdev->dev, "Can't retrieve ape clock\n");
37 return PTR_ERR(aconnect->ape_clk);
38 }
39
40 aconnect->apb2ape_clk = devm_clk_get(&pdev->dev, "apb2ape");
41 if (IS_ERR(aconnect->apb2ape_clk)) {
42 dev_err(&pdev->dev, "Can't retrieve apb2ape clock\n");
43 return PTR_ERR(aconnect->apb2ape_clk);
44 }
45
46 dev_set_drvdata(&pdev->dev, aconnect);
47 pm_runtime_enable(&pdev->dev);
48
49 of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
50
51 dev_info(&pdev->dev, "Tegra ACONNECT bus registered\n");
52
53 return 0;
54}
55
56static int tegra_aconnect_remove(struct platform_device *pdev)
57{
58 pm_runtime_disable(&pdev->dev);
59
60 return 0;
61}
62
63static int tegra_aconnect_runtime_resume(struct device *dev)
64{
65 struct tegra_aconnect *aconnect = dev_get_drvdata(dev);
66 int ret;
67
68 ret = clk_prepare_enable(aconnect->ape_clk);
69 if (ret) {
70 dev_err(dev, "ape clk_enable failed: %d\n", ret);
71 return ret;
72 }
73
74 ret = clk_prepare_enable(aconnect->apb2ape_clk);
75 if (ret) {
76 clk_disable_unprepare(aconnect->ape_clk);
77 dev_err(dev, "apb2ape clk_enable failed: %d\n", ret);
78 return ret;
79 }
80
81 return 0;
82}
83
84static int tegra_aconnect_runtime_suspend(struct device *dev)
85{
86 struct tegra_aconnect *aconnect = dev_get_drvdata(dev);
87
88 clk_disable_unprepare(aconnect->ape_clk);
89 clk_disable_unprepare(aconnect->apb2ape_clk);
90
91 return 0;
92}
93
94static const struct dev_pm_ops tegra_aconnect_pm_ops = {
95 SET_RUNTIME_PM_OPS(tegra_aconnect_runtime_suspend,
96 tegra_aconnect_runtime_resume, NULL)
97 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
98 pm_runtime_force_resume)
99};
100
101static const struct of_device_id tegra_aconnect_of_match[] = {
102 { .compatible = "nvidia,tegra210-aconnect", },
103 { }
104};
105MODULE_DEVICE_TABLE(of, tegra_aconnect_of_match);
106
107static struct platform_driver tegra_aconnect_driver = {
108 .probe = tegra_aconnect_probe,
109 .remove = tegra_aconnect_remove,
110 .driver = {
111 .name = "tegra-aconnect",
112 .of_match_table = tegra_aconnect_of_match,
113 .pm = &tegra_aconnect_pm_ops,
114 },
115};
116module_platform_driver(tegra_aconnect_driver);
117
118MODULE_DESCRIPTION("NVIDIA Tegra ACONNECT Bus Driver");
119MODULE_AUTHOR("Jon Hunter <jonathanh@nvidia.com>");
120MODULE_LICENSE("GPL v2");