Merge tag 'mvebu-soc-3.17' of git://git.infradead.org/linux-mvebu into next/soc
[cascardo/linux.git] / arch / arm / mach-shmobile / pm-r8a7779.c
1 /*
2  * r8a7779 Power management support
3  *
4  * Copyright (C) 2011  Renesas Solutions Corp.
5  * Copyright (C) 2011  Magnus Damm
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
12 #include <linux/pm.h>
13 #include <linux/suspend.h>
14 #include <linux/err.h>
15 #include <linux/pm_clock.h>
16 #include <linux/pm_domain.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/irq.h>
20 #include <linux/interrupt.h>
21 #include <linux/console.h>
22 #include <asm/io.h>
23 #include <mach/r8a7779.h>
24 #include "common.h"
25 #include "pm-rcar.h"
26
27 /* SYSC */
28 #define SYSCIER 0x0c
29 #define SYSCIMR 0x10
30
31 struct r8a7779_pm_domain {
32         struct generic_pm_domain genpd;
33         struct rcar_sysc_ch ch;
34 };
35
36 static inline struct rcar_sysc_ch *to_r8a7779_ch(struct generic_pm_domain *d)
37 {
38         return &container_of(d, struct r8a7779_pm_domain, genpd)->ch;
39 }
40
41 #if defined(CONFIG_PM) || defined(CONFIG_SMP)
42
43 static void __init r8a7779_sysc_init(void)
44 {
45         void __iomem *base = rcar_sysc_init(0xffd85000);
46
47         /* enable all interrupt sources, but do not use interrupt handler */
48         iowrite32(0x0131000e, base + SYSCIER);
49         iowrite32(0, base + SYSCIMR);
50 }
51
52 #else /* CONFIG_PM || CONFIG_SMP */
53
54 static inline void r8a7779_sysc_init(void) {}
55
56 #endif /* CONFIG_PM || CONFIG_SMP */
57
58 #ifdef CONFIG_PM
59
60 static int pd_power_down(struct generic_pm_domain *genpd)
61 {
62         return rcar_sysc_power_down(to_r8a7779_ch(genpd));
63 }
64
65 static int pd_power_up(struct generic_pm_domain *genpd)
66 {
67         return rcar_sysc_power_up(to_r8a7779_ch(genpd));
68 }
69
70 static bool pd_is_off(struct generic_pm_domain *genpd)
71 {
72         return rcar_sysc_power_is_off(to_r8a7779_ch(genpd));
73 }
74
75 static bool pd_active_wakeup(struct device *dev)
76 {
77         return true;
78 }
79
80 static void r8a7779_init_pm_domain(struct r8a7779_pm_domain *r8a7779_pd)
81 {
82         struct generic_pm_domain *genpd = &r8a7779_pd->genpd;
83
84         pm_genpd_init(genpd, NULL, false);
85         genpd->dev_ops.stop = pm_clk_suspend;
86         genpd->dev_ops.start = pm_clk_resume;
87         genpd->dev_ops.active_wakeup = pd_active_wakeup;
88         genpd->dev_irq_safe = true;
89         genpd->power_off = pd_power_down;
90         genpd->power_on = pd_power_up;
91
92         if (pd_is_off(&r8a7779_pd->genpd))
93                 pd_power_up(&r8a7779_pd->genpd);
94 }
95
96 static struct r8a7779_pm_domain r8a7779_pm_domains[] = {
97         {
98                 .genpd.name = "SH4A",
99                 .ch = {
100                         .chan_offs = 0x80, /* PWRSR1 .. PWRER1 */
101                         .isr_bit = 16, /* SH4A */
102                 },
103         },
104         {
105                 .genpd.name = "SGX",
106                 .ch = {
107                         .chan_offs = 0xc0, /* PWRSR2 .. PWRER2 */
108                         .isr_bit = 20, /* SGX */
109                 },
110         },
111         {
112                 .genpd.name = "VDP1",
113                 .ch = {
114                         .chan_offs = 0x100, /* PWRSR3 .. PWRER3 */
115                         .isr_bit = 21, /* VDP */
116                 },
117         },
118         {
119                 .genpd.name = "IMPX3",
120                 .ch = {
121                         .chan_offs = 0x140, /* PWRSR4 .. PWRER4 */
122                         .isr_bit = 24, /* IMP */
123                 },
124         },
125 };
126
127 void __init r8a7779_init_pm_domains(void)
128 {
129         int j;
130
131         for (j = 0; j < ARRAY_SIZE(r8a7779_pm_domains); j++)
132                 r8a7779_init_pm_domain(&r8a7779_pm_domains[j]);
133 }
134
135 #endif /* CONFIG_PM */
136
137 void __init r8a7779_pm_init(void)
138 {
139         static int once;
140
141         if (!once++)
142                 r8a7779_sysc_init();
143 }