xref: /linux/drivers/sh/pm_runtime.c (revision 230f259ffe4ad6d334bb100ce1c0c6a73ff18989)
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 
23300be5b9SRafael J. Wysocki #ifdef CONFIG_PM
248255fe16SBen Dooks static int sh_pm_runtime_suspend(struct device *dev)
258255fe16SBen Dooks {
268255fe16SBen Dooks 	int ret;
278255fe16SBen Dooks 
288255fe16SBen Dooks 	ret = pm_generic_runtime_suspend(dev);
298255fe16SBen Dooks 	if (ret) {
308255fe16SBen Dooks 		dev_err(dev, "failed to suspend device\n");
318255fe16SBen Dooks 		return ret;
328255fe16SBen Dooks 	}
338255fe16SBen Dooks 
348255fe16SBen Dooks 	ret = pm_clk_suspend(dev);
358255fe16SBen Dooks 	if (ret) {
368255fe16SBen Dooks 		dev_err(dev, "failed to suspend clock\n");
378255fe16SBen Dooks 		pm_generic_runtime_resume(dev);
388255fe16SBen Dooks 		return ret;
398255fe16SBen Dooks 	}
408255fe16SBen Dooks 
418255fe16SBen Dooks 	return 0;
428255fe16SBen Dooks }
438255fe16SBen Dooks 
448255fe16SBen Dooks static int sh_pm_runtime_resume(struct device *dev)
458255fe16SBen Dooks {
468255fe16SBen Dooks 	int ret;
478255fe16SBen Dooks 
488255fe16SBen Dooks 	ret = pm_clk_resume(dev);
498255fe16SBen Dooks 	if (ret) {
508255fe16SBen Dooks 		dev_err(dev, "failed to resume clock\n");
518255fe16SBen Dooks 		return ret;
528255fe16SBen Dooks 	}
538255fe16SBen Dooks 
548255fe16SBen Dooks 	return pm_generic_runtime_resume(dev);
558255fe16SBen Dooks }
568255fe16SBen Dooks 
57750a7eeeSPaul Mundt static struct dev_pm_domain default_pm_domain = {
58750a7eeeSPaul Mundt 	.ops = {
598255fe16SBen Dooks 		.runtime_suspend = sh_pm_runtime_suspend,
608255fe16SBen Dooks 		.runtime_resume = sh_pm_runtime_resume,
61750a7eeeSPaul Mundt 		USE_PLATFORM_PM_SLEEP_OPS
62750a7eeeSPaul Mundt 	},
63750a7eeeSPaul Mundt };
64750a7eeeSPaul Mundt 
65750a7eeeSPaul Mundt #define DEFAULT_PM_DOMAIN_PTR	(&default_pm_domain)
66750a7eeeSPaul Mundt 
67750a7eeeSPaul Mundt #else
68750a7eeeSPaul Mundt 
69750a7eeeSPaul Mundt #define DEFAULT_PM_DOMAIN_PTR	NULL
70750a7eeeSPaul Mundt 
71300be5b9SRafael J. Wysocki #endif /* CONFIG_PM */
72750a7eeeSPaul Mundt 
73750a7eeeSPaul Mundt static struct pm_clk_notifier_block platform_bus_notifier = {
74750a7eeeSPaul Mundt 	.pm_domain = DEFAULT_PM_DOMAIN_PTR,
75750a7eeeSPaul Mundt 	.con_ids = { NULL, },
76750a7eeeSPaul Mundt };
77750a7eeeSPaul Mundt 
78750a7eeeSPaul Mundt static int __init sh_pm_runtime_init(void)
79750a7eeeSPaul Mundt {
803c90c55dSGeert Uytterhoeven 	if (IS_ENABLED(CONFIG_ARCH_SHMOBILE_MULTI)) {
813c90c55dSGeert Uytterhoeven 		if (!of_machine_is_compatible("renesas,emev2") &&
823c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r7s72100") &&
83a5cb514fSGeert Uytterhoeven #ifndef CONFIG_PM_GENERIC_DOMAINS_OF
84*230f259fSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a73a4") &&
853c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7740") &&
8641b4b3bcSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,sh73a0") &&
87a5cb514fSGeert Uytterhoeven #endif
883c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7778") &&
893c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7779") &&
903c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7790") &&
913c90c55dSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7791") &&
922f35fb3cSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7792") &&
932f35fb3cSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7793") &&
942f35fb3cSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,r8a7794") &&
9541b4b3bcSGeert Uytterhoeven 		    !of_machine_is_compatible("renesas,sh7372"))
963c90c55dSGeert Uytterhoeven 			return 0;
973c90c55dSGeert Uytterhoeven 	}
983c90c55dSGeert Uytterhoeven 
99750a7eeeSPaul Mundt 	pm_clk_add_notifier(&platform_bus_type, &platform_bus_notifier);
100750a7eeeSPaul Mundt 	return 0;
101750a7eeeSPaul Mundt }
102750a7eeeSPaul Mundt core_initcall(sh_pm_runtime_init);
103