xref: /linux/drivers/sh/pm_runtime.c (revision 3c90c55dcde745bed81f6447f24ba96bda43d984)
1750a7eeeSPaul Mundt /*
2d03299eeSPaul Mundt  * Runtime PM support code
3750a7eeeSPaul Mundt  *
4750a7eeeSPaul Mundt  *  Copyright (C) 2009-2010 Magnus Damm
5750a7eeeSPaul Mundt  *
6750a7eeeSPaul Mundt  * This file is subject to the terms and conditions of the GNU General Public
7750a7eeeSPaul Mundt  * License.  See the file "COPYING" in the main directory of this archive
8750a7eeeSPaul Mundt  * for more details.
9750a7eeeSPaul Mundt  */
10750a7eeeSPaul Mundt 
11750a7eeeSPaul Mundt #include <linux/init.h>
12750a7eeeSPaul Mundt #include <linux/kernel.h>
13750a7eeeSPaul Mundt #include <linux/io.h>
14750a7eeeSPaul Mundt #include <linux/pm_runtime.h>
15750a7eeeSPaul Mundt #include <linux/pm_domain.h>
16750a7eeeSPaul Mundt #include <linux/pm_clock.h>
17750a7eeeSPaul Mundt #include <linux/platform_device.h>
18750a7eeeSPaul Mundt #include <linux/clk.h>
19750a7eeeSPaul Mundt #include <linux/sh_clk.h>
20750a7eeeSPaul Mundt #include <linux/bitmap.h>
21750a7eeeSPaul Mundt #include <linux/slab.h>
22750a7eeeSPaul Mundt 
23750a7eeeSPaul Mundt #ifdef CONFIG_PM_RUNTIME
24750a7eeeSPaul Mundt 
25750a7eeeSPaul Mundt static int default_platform_runtime_idle(struct device *dev)
26750a7eeeSPaul Mundt {
27750a7eeeSPaul Mundt 	/* suspend synchronously to disable clocks immediately */
2845f0a85cSRafael J. Wysocki 	return 0;
29750a7eeeSPaul Mundt }
30750a7eeeSPaul Mundt 
31750a7eeeSPaul Mundt static struct dev_pm_domain default_pm_domain = {
32750a7eeeSPaul Mundt 	.ops = {
33750a7eeeSPaul Mundt 		.runtime_suspend = pm_clk_suspend,
34750a7eeeSPaul Mundt 		.runtime_resume = pm_clk_resume,
35750a7eeeSPaul Mundt 		.runtime_idle = default_platform_runtime_idle,
36750a7eeeSPaul Mundt 		USE_PLATFORM_PM_SLEEP_OPS
37750a7eeeSPaul Mundt 	},
38750a7eeeSPaul Mundt };
39750a7eeeSPaul Mundt 
40750a7eeeSPaul Mundt #define DEFAULT_PM_DOMAIN_PTR	(&default_pm_domain)
41750a7eeeSPaul Mundt 
42750a7eeeSPaul Mundt #else
43750a7eeeSPaul Mundt 
44750a7eeeSPaul Mundt #define DEFAULT_PM_DOMAIN_PTR	NULL
45750a7eeeSPaul Mundt 
46750a7eeeSPaul Mundt #endif /* CONFIG_PM_RUNTIME */
47750a7eeeSPaul Mundt 
48750a7eeeSPaul Mundt static struct pm_clk_notifier_block platform_bus_notifier = {
49750a7eeeSPaul Mundt 	.pm_domain = DEFAULT_PM_DOMAIN_PTR,
50750a7eeeSPaul Mundt 	.con_ids = { NULL, },
51750a7eeeSPaul Mundt };
52750a7eeeSPaul Mundt 
53*3c90c55dSGeert Uytterhoeven static bool default_pm_on;
54*3c90c55dSGeert Uytterhoeven 
55750a7eeeSPaul Mundt static int __init sh_pm_runtime_init(void)
56750a7eeeSPaul Mundt {
57*3c90c55dSGeert Uytterhoeven 	if (IS_ENABLED(CONFIG_ARCH_SHMOBILE_MULTI)) {
58*3c90c55dSGeert Uytterhoeven 		if (!of_machine_is_compatible("renesas,emev2") &&
59*3c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r7s72100") &&
60*3c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a73a4") &&
61*3c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7740") &&
62*3c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7778") &&
63*3c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7779") &&
64*3c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7790") &&
65*3c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7791") &&
66*3c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,sh7372") &&
67*3c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,sh73a0"))
68*3c90c55dSGeert Uytterhoeven 			return 0;
69*3c90c55dSGeert Uytterhoeven 	}
70*3c90c55dSGeert Uytterhoeven 
71*3c90c55dSGeert Uytterhoeven 	default_pm_on = true;
72750a7eeeSPaul Mundt 	pm_clk_add_notifier(&platform_bus_type, &platform_bus_notifier);
73750a7eeeSPaul Mundt 	return 0;
74750a7eeeSPaul Mundt }
75750a7eeeSPaul Mundt core_initcall(sh_pm_runtime_init);
76750a7eeeSPaul Mundt 
77750a7eeeSPaul Mundt static int __init sh_pm_runtime_late_init(void)
78750a7eeeSPaul Mundt {
79*3c90c55dSGeert Uytterhoeven 	if (default_pm_on)
80750a7eeeSPaul Mundt 		pm_genpd_poweroff_unused();
81750a7eeeSPaul Mundt 	return 0;
82750a7eeeSPaul Mundt }
83750a7eeeSPaul Mundt late_initcall(sh_pm_runtime_late_init);
84