blob: 44a74c4c5a01d0d4cedc1359cfe14143a9860037 [file] [log] [blame]
Magnus Damma662c082012-01-10 15:50:01 +09001/*
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 Damm585c09d2014-06-17 16:47:53 +090016#include <linux/pm_domain.h>
Magnus Damma662c082012-01-10 15:50:01 +090017#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 Uytterhoeven1b553532014-06-20 18:53:05 +020022
Magnus Damma662c082012-01-10 15:50:01 +090023#include <asm/io.h>
Geert Uytterhoeven1b553532014-06-20 18:53:05 +020024
Magnus Dammfd44aa52014-06-17 16:47:37 +090025#include "common.h"
Magnus Damm585c09d2014-06-17 16:47:53 +090026#include "pm-rcar.h"
Geert Uytterhoeven1b553532014-06-20 18:53:05 +020027#include "r8a7779.h"
Magnus Damma662c082012-01-10 15:50:01 +090028
Magnus Damma662c082012-01-10 15:50:01 +090029/* SYSC */
Magnus Damma662c082012-01-10 15:50:01 +090030#define SYSCIER 0x0c
31#define SYSCIMR 0x10
Magnus Damma662c082012-01-10 15:50:01 +090032
Magnus Damm585c09d2014-06-17 16:47:53 +090033struct r8a7779_pm_domain {
34 struct generic_pm_domain genpd;
35 struct rcar_sysc_ch ch;
36};
37
38static 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 Dammf40aaf62012-01-10 17:44:39 +090043#if defined(CONFIG_PM) || defined(CONFIG_SMP)
44
Magnus Damma662c082012-01-10 15:50:01 +090045static void __init r8a7779_sysc_init(void)
46{
Magnus Damma6557eb2014-01-15 16:43:08 +090047 void __iomem *base = rcar_sysc_init(0xffd85000);
Magnus Damma662c082012-01-10 15:50:01 +090048
49 /* enable all interrupt sources, but do not use interrupt handler */
Magnus Damma6557eb2014-01-15 16:43:08 +090050 iowrite32(0x0131000e, base + SYSCIER);
51 iowrite32(0, base + SYSCIMR);
Magnus Damma662c082012-01-10 15:50:01 +090052}
53
Magnus Dammf40aaf62012-01-10 17:44:39 +090054#else /* CONFIG_PM || CONFIG_SMP */
55
56static inline void r8a7779_sysc_init(void) {}
57
58#endif /* CONFIG_PM || CONFIG_SMP */
59
60#ifdef CONFIG_PM
61
Magnus Damma662c082012-01-10 15:50:01 +090062static int pd_power_down(struct generic_pm_domain *genpd)
63{
Magnus Damma6557eb2014-01-15 16:43:08 +090064 return rcar_sysc_power_down(to_r8a7779_ch(genpd));
Magnus Damma662c082012-01-10 15:50:01 +090065}
66
67static int pd_power_up(struct generic_pm_domain *genpd)
68{
Magnus Damma6557eb2014-01-15 16:43:08 +090069 return rcar_sysc_power_up(to_r8a7779_ch(genpd));
Magnus Damma662c082012-01-10 15:50:01 +090070}
71
72static bool pd_is_off(struct generic_pm_domain *genpd)
73{
Magnus Damma6557eb2014-01-15 16:43:08 +090074 return rcar_sysc_power_is_off(to_r8a7779_ch(genpd));
Magnus Damma662c082012-01-10 15:50:01 +090075}
76
77static bool pd_active_wakeup(struct device *dev)
78{
79 return true;
80}
81
Rafael J. Wysocki45e5ca52012-08-07 01:14:14 +020082static void r8a7779_init_pm_domain(struct r8a7779_pm_domain *r8a7779_pd)
Magnus Damma662c082012-01-10 15:50:01 +090083{
84 struct generic_pm_domain *genpd = &r8a7779_pd->genpd;
85
Ulf Hansson9c6a9732014-12-01 12:50:22 +010086 genpd->flags = GENPD_FLAG_PM_CLK;
Magnus Damma662c082012-01-10 15:50:01 +090087 pm_genpd_init(genpd, NULL, false);
Magnus Damma662c082012-01-10 15:50:01 +090088 genpd->dev_ops.active_wakeup = pd_active_wakeup;
Magnus Damma662c082012-01-10 15:50:01 +090089 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
Rafael J. Wysocki45e5ca52012-08-07 01:14:14 +020096static 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 },
Magnus Damma662c082012-01-10 15:50:01 +0900125};
126
Rafael J. Wysocki45e5ca52012-08-07 01:14:14 +0200127void __init r8a7779_init_pm_domains(void)
128{
129 int j;
Magnus Damma662c082012-01-10 15:50:01 +0900130
Rafael J. Wysocki45e5ca52012-08-07 01:14:14 +0200131 for (j = 0; j < ARRAY_SIZE(r8a7779_pm_domains); j++)
132 r8a7779_init_pm_domain(&r8a7779_pm_domains[j]);
133}
Magnus Damma662c082012-01-10 15:50:01 +0900134
Magnus Damma662c082012-01-10 15:50:01 +0900135#endif /* CONFIG_PM */
136
137void __init r8a7779_pm_init(void)
138{
Magnus Dammf40aaf62012-01-10 17:44:39 +0900139 static int once;
140
141 if (!once++)
142 r8a7779_sysc_init();
Magnus Damma662c082012-01-10 15:50:01 +0900143}