Commit | Line | Data |
---|---|---|
a662c082 MD |
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/platform_device.h> | |
17 | #include <linux/delay.h> | |
18 | #include <linux/irq.h> | |
19 | #include <linux/interrupt.h> | |
20 | #include <linux/console.h> | |
a662c082 | 21 | #include <asm/io.h> |
a6557eb7 | 22 | #include <mach/pm-rcar.h> |
a662c082 | 23 | #include <mach/r8a7779.h> |
fd44aa5e | 24 | #include "common.h" |
a662c082 | 25 | |
a662c082 | 26 | /* SYSC */ |
a662c082 MD |
27 | #define SYSCIER 0x0c |
28 | #define SYSCIMR 0x10 | |
a662c082 | 29 | |
f40aaf6d MD |
30 | #if defined(CONFIG_PM) || defined(CONFIG_SMP) |
31 | ||
a662c082 MD |
32 | static void __init r8a7779_sysc_init(void) |
33 | { | |
a6557eb7 | 34 | void __iomem *base = rcar_sysc_init(0xffd85000); |
a662c082 MD |
35 | |
36 | /* enable all interrupt sources, but do not use interrupt handler */ | |
a6557eb7 MD |
37 | iowrite32(0x0131000e, base + SYSCIER); |
38 | iowrite32(0, base + SYSCIMR); | |
a662c082 MD |
39 | } |
40 | ||
f40aaf6d MD |
41 | #else /* CONFIG_PM || CONFIG_SMP */ |
42 | ||
43 | static inline void r8a7779_sysc_init(void) {} | |
44 | ||
45 | #endif /* CONFIG_PM || CONFIG_SMP */ | |
46 | ||
47 | #ifdef CONFIG_PM | |
48 | ||
a662c082 MD |
49 | static int pd_power_down(struct generic_pm_domain *genpd) |
50 | { | |
a6557eb7 | 51 | return rcar_sysc_power_down(to_r8a7779_ch(genpd)); |
a662c082 MD |
52 | } |
53 | ||
54 | static int pd_power_up(struct generic_pm_domain *genpd) | |
55 | { | |
a6557eb7 | 56 | return rcar_sysc_power_up(to_r8a7779_ch(genpd)); |
a662c082 MD |
57 | } |
58 | ||
59 | static bool pd_is_off(struct generic_pm_domain *genpd) | |
60 | { | |
a6557eb7 | 61 | return rcar_sysc_power_is_off(to_r8a7779_ch(genpd)); |
a662c082 MD |
62 | } |
63 | ||
64 | static bool pd_active_wakeup(struct device *dev) | |
65 | { | |
66 | return true; | |
67 | } | |
68 | ||
45e5ca57 | 69 | static void r8a7779_init_pm_domain(struct r8a7779_pm_domain *r8a7779_pd) |
a662c082 MD |
70 | { |
71 | struct generic_pm_domain *genpd = &r8a7779_pd->genpd; | |
72 | ||
73 | pm_genpd_init(genpd, NULL, false); | |
74 | genpd->dev_ops.stop = pm_clk_suspend; | |
75 | genpd->dev_ops.start = pm_clk_resume; | |
76 | genpd->dev_ops.active_wakeup = pd_active_wakeup; | |
77 | genpd->dev_irq_safe = true; | |
78 | genpd->power_off = pd_power_down; | |
79 | genpd->power_on = pd_power_up; | |
80 | ||
81 | if (pd_is_off(&r8a7779_pd->genpd)) | |
82 | pd_power_up(&r8a7779_pd->genpd); | |
83 | } | |
84 | ||
45e5ca57 RW |
85 | static struct r8a7779_pm_domain r8a7779_pm_domains[] = { |
86 | { | |
87 | .genpd.name = "SH4A", | |
88 | .ch = { | |
89 | .chan_offs = 0x80, /* PWRSR1 .. PWRER1 */ | |
90 | .isr_bit = 16, /* SH4A */ | |
91 | }, | |
92 | }, | |
93 | { | |
94 | .genpd.name = "SGX", | |
95 | .ch = { | |
96 | .chan_offs = 0xc0, /* PWRSR2 .. PWRER2 */ | |
97 | .isr_bit = 20, /* SGX */ | |
98 | }, | |
99 | }, | |
100 | { | |
101 | .genpd.name = "VDP1", | |
102 | .ch = { | |
103 | .chan_offs = 0x100, /* PWRSR3 .. PWRER3 */ | |
104 | .isr_bit = 21, /* VDP */ | |
105 | }, | |
106 | }, | |
107 | { | |
108 | .genpd.name = "IMPX3", | |
109 | .ch = { | |
110 | .chan_offs = 0x140, /* PWRSR4 .. PWRER4 */ | |
111 | .isr_bit = 24, /* IMP */ | |
112 | }, | |
113 | }, | |
a662c082 MD |
114 | }; |
115 | ||
45e5ca57 RW |
116 | void __init r8a7779_init_pm_domains(void) |
117 | { | |
118 | int j; | |
a662c082 | 119 | |
45e5ca57 RW |
120 | for (j = 0; j < ARRAY_SIZE(r8a7779_pm_domains); j++) |
121 | r8a7779_init_pm_domain(&r8a7779_pm_domains[j]); | |
122 | } | |
a662c082 | 123 | |
a662c082 MD |
124 | #endif /* CONFIG_PM */ |
125 | ||
126 | void __init r8a7779_pm_init(void) | |
127 | { | |
f40aaf6d MD |
128 | static int once; |
129 | ||
130 | if (!once++) | |
131 | r8a7779_sysc_init(); | |
a662c082 | 132 | } |