1/*
2 * r8a7740 power management support
3 *
4 * Copyright (C) 2012  Renesas Solutions Corp.
5 * Copyright (C) 2012  Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License.  See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11#include <linux/console.h>
12#include <linux/io.h>
13#include <linux/suspend.h>
14
15#include "common.h"
16#include "pm-rmobile.h"
17
18#define SYSC_BASE	IOMEM(0xe6180000)
19
20#if defined(CONFIG_PM) && !defined(CONFIG_ARCH_MULTIPLATFORM)
21static int r8a7740_pd_a3sm_suspend(void)
22{
23	/*
24	 * The A3SM domain contains the CPU core and therefore it should
25	 * only be turned off if the CPU is not in use.
26	 */
27	return -EBUSY;
28}
29
30static int r8a7740_pd_a3sp_suspend(void)
31{
32	/*
33	 * Serial consoles make use of SCIF hardware located in A3SP,
34	 * keep such power domain on if "no_console_suspend" is set.
35	 */
36	return console_suspend_enabled ? 0 : -EBUSY;
37}
38
39static int r8a7740_pd_d4_suspend(void)
40{
41	/*
42	 * The D4 domain contains the Coresight-ETM hardware block and
43	 * therefore it should only be turned off if the debug module is
44	 * not in use.
45	 */
46	return -EBUSY;
47}
48
49static struct rmobile_pm_domain r8a7740_pm_domains[] = {
50	{
51		.genpd.name	= "A4LC",
52		.base		= SYSC_BASE,
53		.bit_shift	= 1,
54	}, {
55		.genpd.name	= "A4MP",
56		.base		= SYSC_BASE,
57		.bit_shift	= 2,
58	}, {
59		.genpd.name	= "D4",
60		.base		= SYSC_BASE,
61		.bit_shift	= 3,
62		.gov		= &pm_domain_always_on_gov,
63		.suspend	= r8a7740_pd_d4_suspend,
64	}, {
65		.genpd.name	= "A4R",
66		.base		= SYSC_BASE,
67		.bit_shift	= 5,
68	}, {
69		.genpd.name	= "A3RV",
70		.base		= SYSC_BASE,
71		.bit_shift	= 6,
72	}, {
73		.genpd.name	= "A4S",
74		.base		= SYSC_BASE,
75		.bit_shift	= 10,
76		.no_debug	= true,
77	}, {
78		.genpd.name	= "A3SP",
79		.base		= SYSC_BASE,
80		.bit_shift	= 11,
81		.gov		= &pm_domain_always_on_gov,
82		.no_debug	= true,
83		.suspend	= r8a7740_pd_a3sp_suspend,
84	}, {
85		.genpd.name	= "A3SM",
86		.base		= SYSC_BASE,
87		.bit_shift	= 12,
88		.gov		= &pm_domain_always_on_gov,
89		.suspend	= r8a7740_pd_a3sm_suspend,
90	}, {
91		.genpd.name	= "A3SG",
92		.base		= SYSC_BASE,
93		.bit_shift	= 13,
94	}, {
95		.genpd.name	= "A4SU",
96		.base		= SYSC_BASE,
97		.bit_shift	= 20,
98	},
99};
100
101void __init r8a7740_init_pm_domains(void)
102{
103	rmobile_init_domains(r8a7740_pm_domains, ARRAY_SIZE(r8a7740_pm_domains));
104	pm_genpd_add_subdomain_names("A4R", "A3RV");
105	pm_genpd_add_subdomain_names("A4S", "A3SP");
106	pm_genpd_add_subdomain_names("A4S", "A3SM");
107	pm_genpd_add_subdomain_names("A4S", "A3SG");
108}
109#endif /* CONFIG_PM && !CONFIG_ARCH_MULTIPLATFORM */
110
111#ifdef CONFIG_SUSPEND
112static int r8a7740_enter_suspend(suspend_state_t suspend_state)
113{
114	cpu_do_idle();
115	return 0;
116}
117
118static void r8a7740_suspend_init(void)
119{
120	shmobile_suspend_ops.enter = r8a7740_enter_suspend;
121}
122#else
123static void r8a7740_suspend_init(void) {}
124#endif
125
126void __init r8a7740_pm_init(void)
127{
128	r8a7740_suspend_init();
129}
130