xref: /linux/drivers/sh/pm_runtime.c (revision 3f17ea6dea8ba5668873afa54628a91aaa3fb1c0)
1 /*
2  * Runtime PM support code
3  *
4  *  Copyright (C) 2009-2010 Magnus Damm
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/init.h>
12 #include <linux/kernel.h>
13 #include <linux/io.h>
14 #include <linux/pm_runtime.h>
15 #include <linux/pm_domain.h>
16 #include <linux/pm_clock.h>
17 #include <linux/platform_device.h>
18 #include <linux/clk.h>
19 #include <linux/sh_clk.h>
20 #include <linux/bitmap.h>
21 #include <linux/slab.h>
22 
23 #ifdef CONFIG_PM_RUNTIME
24 static int sh_pm_runtime_suspend(struct device *dev)
25 {
26 	int ret;
27 
28 	ret = pm_generic_runtime_suspend(dev);
29 	if (ret) {
30 		dev_err(dev, "failed to suspend device\n");
31 		return ret;
32 	}
33 
34 	ret = pm_clk_suspend(dev);
35 	if (ret) {
36 		dev_err(dev, "failed to suspend clock\n");
37 		pm_generic_runtime_resume(dev);
38 		return ret;
39 	}
40 
41 	return 0;
42 }
43 
44 static int sh_pm_runtime_resume(struct device *dev)
45 {
46 	int ret;
47 
48 	ret = pm_clk_resume(dev);
49 	if (ret) {
50 		dev_err(dev, "failed to resume clock\n");
51 		return ret;
52 	}
53 
54 	return pm_generic_runtime_resume(dev);
55 }
56 
57 static struct dev_pm_domain default_pm_domain = {
58 	.ops = {
59 		.runtime_suspend = sh_pm_runtime_suspend,
60 		.runtime_resume = sh_pm_runtime_resume,
61 		USE_PLATFORM_PM_SLEEP_OPS
62 	},
63 };
64 
65 #define DEFAULT_PM_DOMAIN_PTR	(&default_pm_domain)
66 
67 #else
68 
69 #define DEFAULT_PM_DOMAIN_PTR	NULL
70 
71 #endif /* CONFIG_PM_RUNTIME */
72 
73 static struct pm_clk_notifier_block platform_bus_notifier = {
74 	.pm_domain = DEFAULT_PM_DOMAIN_PTR,
75 	.con_ids = { NULL, },
76 };
77 
78 static bool default_pm_on;
79 
80 static int __init sh_pm_runtime_init(void)
81 {
82 	if (IS_ENABLED(CONFIG_ARCH_SHMOBILE_MULTI)) {
83 		if (!of_machine_is_compatible("renesas,emev2") &&
84 		    !of_machine_is_compatible("renesas,r7s72100") &&
85 		    !of_machine_is_compatible("renesas,r8a73a4") &&
86 		    !of_machine_is_compatible("renesas,r8a7740") &&
87 		    !of_machine_is_compatible("renesas,r8a7778") &&
88 		    !of_machine_is_compatible("renesas,r8a7779") &&
89 		    !of_machine_is_compatible("renesas,r8a7790") &&
90 		    !of_machine_is_compatible("renesas,r8a7791") &&
91 		    !of_machine_is_compatible("renesas,r8a7792") &&
92 		    !of_machine_is_compatible("renesas,r8a7793") &&
93 		    !of_machine_is_compatible("renesas,r8a7794") &&
94 		    !of_machine_is_compatible("renesas,sh7372") &&
95 		    !of_machine_is_compatible("renesas,sh73a0"))
96 			return 0;
97 	}
98 
99 	default_pm_on = true;
100 	pm_clk_add_notifier(&platform_bus_type, &platform_bus_notifier);
101 	return 0;
102 }
103 core_initcall(sh_pm_runtime_init);
104 
105 static int __init sh_pm_runtime_late_init(void)
106 {
107 	if (default_pm_on)
108 		pm_genpd_poweroff_unused();
109 	return 0;
110 }
111 late_initcall(sh_pm_runtime_late_init);
112