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