diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2010-06-19 00:08:11 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2010-08-05 08:26:14 -0400 |
commit | c863a2368ced0e6df07121d13933ee0f5a5ee681 (patch) | |
tree | 1f246916a7f940aa1ac50b5a88a2729e81cdfc3a /arch/mips | |
parent | b200eff6d16cf53dfaf14eb6f1934890d2db2237 (diff) |
MIPS: JZ4740: Add power-management and system reset support
Add support for suspend/resume and poweroff/reboot on a JZ4740 SoC.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/1398/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/jz4740/pm.c | 56 | ||||
-rw-r--r-- | arch/mips/jz4740/reset.c | 79 | ||||
-rw-r--r-- | arch/mips/jz4740/reset.h | 6 |
3 files changed, 141 insertions, 0 deletions
diff --git a/arch/mips/jz4740/pm.c b/arch/mips/jz4740/pm.c new file mode 100644 index 000000000000..a9994585424d --- /dev/null +++ b/arch/mips/jz4740/pm.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de> | ||
3 | * JZ4740 SoC power management support | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License as published by the | ||
7 | * Free Software Foundation; either version 2 of the License, or (at your | ||
8 | * option) any later version. | ||
9 | * | ||
10 | * You should have received a copy of the GNU General Public License along | ||
11 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
12 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/init.h> | ||
17 | #include <linux/pm.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <linux/suspend.h> | ||
20 | |||
21 | #include <asm/mach-jz4740/clock.h> | ||
22 | |||
23 | #include "clock.h" | ||
24 | #include "irq.h" | ||
25 | |||
26 | static int jz4740_pm_enter(suspend_state_t state) | ||
27 | { | ||
28 | jz4740_intc_suspend(); | ||
29 | jz4740_clock_suspend(); | ||
30 | |||
31 | jz4740_clock_set_wait_mode(JZ4740_WAIT_MODE_SLEEP); | ||
32 | |||
33 | __asm__(".set\tmips3\n\t" | ||
34 | "wait\n\t" | ||
35 | ".set\tmips0"); | ||
36 | |||
37 | jz4740_clock_set_wait_mode(JZ4740_WAIT_MODE_IDLE); | ||
38 | |||
39 | jz4740_clock_resume(); | ||
40 | jz4740_intc_resume(); | ||
41 | |||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static struct platform_suspend_ops jz4740_pm_ops = { | ||
46 | .valid = suspend_valid_only_mem, | ||
47 | .enter = jz4740_pm_enter, | ||
48 | }; | ||
49 | |||
50 | static int __init jz4740_pm_init(void) | ||
51 | { | ||
52 | suspend_set_ops(&jz4740_pm_ops); | ||
53 | return 0; | ||
54 | |||
55 | } | ||
56 | late_initcall(jz4740_pm_init); | ||
diff --git a/arch/mips/jz4740/reset.c b/arch/mips/jz4740/reset.c new file mode 100644 index 000000000000..5f1fb95c0d0d --- /dev/null +++ b/arch/mips/jz4740/reset.c | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of the GNU General Public License as published by the | ||
6 | * Free Software Foundation; either version 2 of the License, or (at your | ||
7 | * option) any later version. | ||
8 | * | ||
9 | * You should have received a copy of the GNU General Public License along | ||
10 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
11 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/io.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/pm.h> | ||
18 | |||
19 | #include <asm/reboot.h> | ||
20 | |||
21 | #include <asm/mach-jz4740/base.h> | ||
22 | #include <asm/mach-jz4740/timer.h> | ||
23 | |||
24 | static void jz4740_halt(void) | ||
25 | { | ||
26 | while (1) { | ||
27 | __asm__(".set push;\n" | ||
28 | ".set mips3;\n" | ||
29 | "wait;\n" | ||
30 | ".set pop;\n" | ||
31 | ); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | #define JZ_REG_WDT_DATA 0x00 | ||
36 | #define JZ_REG_WDT_COUNTER_ENABLE 0x04 | ||
37 | #define JZ_REG_WDT_COUNTER 0x08 | ||
38 | #define JZ_REG_WDT_CTRL 0x0c | ||
39 | |||
40 | static void jz4740_restart(char *command) | ||
41 | { | ||
42 | void __iomem *wdt_base = ioremap(JZ4740_WDT_BASE_ADDR, 0x0f); | ||
43 | |||
44 | jz4740_timer_enable_watchdog(); | ||
45 | |||
46 | writeb(0, wdt_base + JZ_REG_WDT_COUNTER_ENABLE); | ||
47 | |||
48 | writew(0, wdt_base + JZ_REG_WDT_COUNTER); | ||
49 | writew(0, wdt_base + JZ_REG_WDT_DATA); | ||
50 | writew(BIT(2), wdt_base + JZ_REG_WDT_CTRL); | ||
51 | |||
52 | writeb(1, wdt_base + JZ_REG_WDT_COUNTER_ENABLE); | ||
53 | jz4740_halt(); | ||
54 | } | ||
55 | |||
56 | #define JZ_REG_RTC_CTRL 0x00 | ||
57 | #define JZ_REG_RTC_HIBERNATE 0x20 | ||
58 | |||
59 | #define JZ_RTC_CTRL_WRDY BIT(7) | ||
60 | |||
61 | static void jz4740_power_off(void) | ||
62 | { | ||
63 | void __iomem *rtc_base = ioremap(JZ4740_RTC_BASE_ADDR, 0x24); | ||
64 | uint32_t ctrl; | ||
65 | |||
66 | do { | ||
67 | ctrl = readl(rtc_base + JZ_REG_RTC_CTRL); | ||
68 | } while (!(ctrl & JZ_RTC_CTRL_WRDY)); | ||
69 | |||
70 | writel(1, rtc_base + JZ_REG_RTC_HIBERNATE); | ||
71 | jz4740_halt(); | ||
72 | } | ||
73 | |||
74 | void jz4740_reset_init(void) | ||
75 | { | ||
76 | _machine_restart = jz4740_restart; | ||
77 | _machine_halt = jz4740_halt; | ||
78 | pm_power_off = jz4740_power_off; | ||
79 | } | ||
diff --git a/arch/mips/jz4740/reset.h b/arch/mips/jz4740/reset.h new file mode 100644 index 000000000000..5202ab4ad9db --- /dev/null +++ b/arch/mips/jz4740/reset.h | |||
@@ -0,0 +1,6 @@ | |||
1 | #ifndef __MIPS_JZ4740_RESET_H__ | ||
2 | #define __MIPS_JZ4740_RESET_H__ | ||
3 | |||
4 | extern void jz4740_reset_init(void); | ||
5 | |||
6 | #endif | ||