Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 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> |
Magnus Damm | 585c09d | 2014-06-17 16:47:53 +0900 | [diff] [blame] | 16 | #include <linux/pm_domain.h> |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 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> |
Geert Uytterhoeven | 1b55353 | 2014-06-20 18:53:05 +0200 | [diff] [blame] | 22 | |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 23 | #include <asm/io.h> |
Geert Uytterhoeven | 1b55353 | 2014-06-20 18:53:05 +0200 | [diff] [blame] | 24 | |
Magnus Damm | fd44aa5 | 2014-06-17 16:47:37 +0900 | [diff] [blame] | 25 | #include "common.h" |
Magnus Damm | 585c09d | 2014-06-17 16:47:53 +0900 | [diff] [blame] | 26 | #include "pm-rcar.h" |
Geert Uytterhoeven | 1b55353 | 2014-06-20 18:53:05 +0200 | [diff] [blame] | 27 | #include "r8a7779.h" |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 28 | |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 29 | /* SYSC */ |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 30 | #define SYSCIER 0x0c |
| 31 | #define SYSCIMR 0x10 |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 32 | |
Magnus Damm | 585c09d | 2014-06-17 16:47:53 +0900 | [diff] [blame] | 33 | struct r8a7779_pm_domain { |
| 34 | struct generic_pm_domain genpd; |
| 35 | struct rcar_sysc_ch ch; |
| 36 | }; |
| 37 | |
| 38 | static inline struct rcar_sysc_ch *to_r8a7779_ch(struct generic_pm_domain *d) |
| 39 | { |
| 40 | return &container_of(d, struct r8a7779_pm_domain, genpd)->ch; |
| 41 | } |
| 42 | |
Magnus Damm | f40aaf6 | 2012-01-10 17:44:39 +0900 | [diff] [blame] | 43 | #if defined(CONFIG_PM) || defined(CONFIG_SMP) |
| 44 | |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 45 | static void __init r8a7779_sysc_init(void) |
| 46 | { |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 47 | void __iomem *base = rcar_sysc_init(0xffd85000); |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 48 | |
| 49 | /* enable all interrupt sources, but do not use interrupt handler */ |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 50 | iowrite32(0x0131000e, base + SYSCIER); |
| 51 | iowrite32(0, base + SYSCIMR); |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 52 | } |
| 53 | |
Magnus Damm | f40aaf6 | 2012-01-10 17:44:39 +0900 | [diff] [blame] | 54 | #else /* CONFIG_PM || CONFIG_SMP */ |
| 55 | |
| 56 | static inline void r8a7779_sysc_init(void) {} |
| 57 | |
| 58 | #endif /* CONFIG_PM || CONFIG_SMP */ |
| 59 | |
| 60 | #ifdef CONFIG_PM |
| 61 | |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 62 | static int pd_power_down(struct generic_pm_domain *genpd) |
| 63 | { |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 64 | return rcar_sysc_power_down(to_r8a7779_ch(genpd)); |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static int pd_power_up(struct generic_pm_domain *genpd) |
| 68 | { |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 69 | return rcar_sysc_power_up(to_r8a7779_ch(genpd)); |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static bool pd_is_off(struct generic_pm_domain *genpd) |
| 73 | { |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 74 | return rcar_sysc_power_is_off(to_r8a7779_ch(genpd)); |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static bool pd_active_wakeup(struct device *dev) |
| 78 | { |
| 79 | return true; |
| 80 | } |
| 81 | |
Rafael J. Wysocki | 45e5ca5 | 2012-08-07 01:14:14 +0200 | [diff] [blame] | 82 | static void r8a7779_init_pm_domain(struct r8a7779_pm_domain *r8a7779_pd) |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 83 | { |
| 84 | struct generic_pm_domain *genpd = &r8a7779_pd->genpd; |
| 85 | |
| 86 | pm_genpd_init(genpd, NULL, false); |
| 87 | genpd->dev_ops.stop = pm_clk_suspend; |
| 88 | genpd->dev_ops.start = pm_clk_resume; |
| 89 | genpd->dev_ops.active_wakeup = pd_active_wakeup; |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 90 | genpd->power_off = pd_power_down; |
| 91 | genpd->power_on = pd_power_up; |
| 92 | |
| 93 | if (pd_is_off(&r8a7779_pd->genpd)) |
| 94 | pd_power_up(&r8a7779_pd->genpd); |
| 95 | } |
| 96 | |
Rafael J. Wysocki | 45e5ca5 | 2012-08-07 01:14:14 +0200 | [diff] [blame] | 97 | static struct r8a7779_pm_domain r8a7779_pm_domains[] = { |
| 98 | { |
| 99 | .genpd.name = "SH4A", |
| 100 | .ch = { |
| 101 | .chan_offs = 0x80, /* PWRSR1 .. PWRER1 */ |
| 102 | .isr_bit = 16, /* SH4A */ |
| 103 | }, |
| 104 | }, |
| 105 | { |
| 106 | .genpd.name = "SGX", |
| 107 | .ch = { |
| 108 | .chan_offs = 0xc0, /* PWRSR2 .. PWRER2 */ |
| 109 | .isr_bit = 20, /* SGX */ |
| 110 | }, |
| 111 | }, |
| 112 | { |
| 113 | .genpd.name = "VDP1", |
| 114 | .ch = { |
| 115 | .chan_offs = 0x100, /* PWRSR3 .. PWRER3 */ |
| 116 | .isr_bit = 21, /* VDP */ |
| 117 | }, |
| 118 | }, |
| 119 | { |
| 120 | .genpd.name = "IMPX3", |
| 121 | .ch = { |
| 122 | .chan_offs = 0x140, /* PWRSR4 .. PWRER4 */ |
| 123 | .isr_bit = 24, /* IMP */ |
| 124 | }, |
| 125 | }, |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 126 | }; |
| 127 | |
Rafael J. Wysocki | 45e5ca5 | 2012-08-07 01:14:14 +0200 | [diff] [blame] | 128 | void __init r8a7779_init_pm_domains(void) |
| 129 | { |
| 130 | int j; |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 131 | |
Rafael J. Wysocki | 45e5ca5 | 2012-08-07 01:14:14 +0200 | [diff] [blame] | 132 | for (j = 0; j < ARRAY_SIZE(r8a7779_pm_domains); j++) |
| 133 | r8a7779_init_pm_domain(&r8a7779_pm_domains[j]); |
| 134 | } |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 135 | |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 136 | #endif /* CONFIG_PM */ |
| 137 | |
| 138 | void __init r8a7779_pm_init(void) |
| 139 | { |
Magnus Damm | f40aaf6 | 2012-01-10 17:44:39 +0900 | [diff] [blame] | 140 | static int once; |
| 141 | |
| 142 | if (!once++) |
| 143 | r8a7779_sysc_init(); |
Magnus Damm | a662c08 | 2012-01-10 15:50:01 +0900 | [diff] [blame] | 144 | } |