pm_runtime.c 2.1 KB
Newer Older
M
Magnus Damm 已提交
1
/*
2
 * Runtime PM support code
M
Magnus Damm 已提交
3 4 5 6 7 8 9 10 11 12 13 14
 *
 *  Copyright (C) 2009-2010 Magnus Damm
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/io.h>
#include <linux/pm_runtime.h>
15
#include <linux/pm_domain.h>
16
#include <linux/pm_clock.h>
M
Magnus Damm 已提交
17 18 19 20
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/sh_clk.h>
#include <linux/bitmap.h>
21
#include <linux/slab.h>
M
Magnus Damm 已提交
22 23 24

#ifdef CONFIG_PM_RUNTIME

25
static int default_platform_runtime_idle(struct device *dev)
M
Magnus Damm 已提交
26 27
{
	/* suspend synchronously to disable clocks immediately */
28
	return 0;
M
Magnus Damm 已提交
29 30
}

31
static struct dev_pm_domain default_pm_domain = {
32
	.ops = {
33 34
		.runtime_suspend = pm_clk_suspend,
		.runtime_resume = pm_clk_resume,
35 36 37 38 39
		.runtime_idle = default_platform_runtime_idle,
		USE_PLATFORM_PM_SLEEP_OPS
	},
};

40
#define DEFAULT_PM_DOMAIN_PTR	(&default_pm_domain)
41

42
#else
M
Magnus Damm 已提交
43

44
#define DEFAULT_PM_DOMAIN_PTR	NULL
M
Magnus Damm 已提交
45 46 47

#endif /* CONFIG_PM_RUNTIME */

48
static struct pm_clk_notifier_block platform_bus_notifier = {
49
	.pm_domain = DEFAULT_PM_DOMAIN_PTR,
50
	.con_ids = { NULL, },
M
Magnus Damm 已提交
51 52
};

53 54
static bool default_pm_on;

M
Magnus Damm 已提交
55 56
static int __init sh_pm_runtime_init(void)
{
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
	if (IS_ENABLED(CONFIG_ARCH_SHMOBILE_MULTI)) {
		if (!of_machine_is_compatible("renesas,emev2") &&
		    !of_machine_is_compatible("renesas,r7s72100") &&
		    !of_machine_is_compatible("renesas,r8a73a4") &&
		    !of_machine_is_compatible("renesas,r8a7740") &&
		    !of_machine_is_compatible("renesas,r8a7778") &&
		    !of_machine_is_compatible("renesas,r8a7779") &&
		    !of_machine_is_compatible("renesas,r8a7790") &&
		    !of_machine_is_compatible("renesas,r8a7791") &&
		    !of_machine_is_compatible("renesas,sh7372") &&
		    !of_machine_is_compatible("renesas,sh73a0"))
			return 0;
	}

	default_pm_on = true;
72
	pm_clk_add_notifier(&platform_bus_type, &platform_bus_notifier);
M
Magnus Damm 已提交
73 74 75
	return 0;
}
core_initcall(sh_pm_runtime_init);
76 77 78

static int __init sh_pm_runtime_late_init(void)
{
79 80
	if (default_pm_on)
		pm_genpd_poweroff_unused();
81 82 83
	return 0;
}
late_initcall(sh_pm_runtime_late_init);