diff options
-rw-r--r-- | arch/sh/include/asm/suspend.h | 9 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/shmobile/Makefile | 1 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/shmobile/cpuidle.c | 102 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/shmobile/pm.c | 26 |
4 files changed, 125 insertions, 13 deletions
diff --git a/arch/sh/include/asm/suspend.h b/arch/sh/include/asm/suspend.h index b1b995370e7..5c8ea28ff7a 100644 --- a/arch/sh/include/asm/suspend.h +++ b/arch/sh/include/asm/suspend.h | |||
@@ -10,6 +10,15 @@ struct swsusp_arch_regs { | |||
10 | struct pt_regs user_regs; | 10 | struct pt_regs user_regs; |
11 | unsigned long bank1_regs[8]; | 11 | unsigned long bank1_regs[8]; |
12 | }; | 12 | }; |
13 | |||
14 | void sh_mobile_call_standby(unsigned long mode); | ||
15 | |||
16 | #ifdef CONFIG_CPU_IDLE | ||
17 | void sh_mobile_setup_cpuidle(void); | ||
18 | #else | ||
19 | static inline void sh_mobile_setup_cpuidle(void) {} | ||
20 | #endif | ||
21 | |||
13 | #endif | 22 | #endif |
14 | 23 | ||
15 | /* flags passed to assembly suspend code */ | 24 | /* flags passed to assembly suspend code */ |
diff --git a/arch/sh/kernel/cpu/shmobile/Makefile b/arch/sh/kernel/cpu/shmobile/Makefile index 08bfa7c7db2..e8a5111e848 100644 --- a/arch/sh/kernel/cpu/shmobile/Makefile +++ b/arch/sh/kernel/cpu/shmobile/Makefile | |||
@@ -4,3 +4,4 @@ | |||
4 | 4 | ||
5 | # Power Management & Sleep mode | 5 | # Power Management & Sleep mode |
6 | obj-$(CONFIG_PM) += pm.o sleep.o | 6 | obj-$(CONFIG_PM) += pm.o sleep.o |
7 | obj-$(CONFIG_CPU_IDLE) += cpuidle.o | ||
diff --git a/arch/sh/kernel/cpu/shmobile/cpuidle.c b/arch/sh/kernel/cpu/shmobile/cpuidle.c new file mode 100644 index 00000000000..4afdd975cc6 --- /dev/null +++ b/arch/sh/kernel/cpu/shmobile/cpuidle.c | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | * arch/sh/kernel/cpu/shmobile/cpuidle.c | ||
3 | * | ||
4 | * Cpuidle support code for SuperH Mobile | ||
5 | * | ||
6 | * Copyright (C) 2009 Magnus Damm | ||
7 | * | ||
8 | * This file is subject to the terms and conditions of the GNU General Public | ||
9 | * License. See the file "COPYING" in the main directory of this archive | ||
10 | * for more details. | ||
11 | */ | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/suspend.h> | ||
16 | #include <linux/cpuidle.h> | ||
17 | #include <asm/suspend.h> | ||
18 | #include <asm/uaccess.h> | ||
19 | #include <asm/hwblk.h> | ||
20 | |||
21 | static unsigned long cpuidle_mode[] = { | ||
22 | SUSP_SH_SLEEP, /* regular sleep mode */ | ||
23 | SUSP_SH_SLEEP | SUSP_SH_SF, /* sleep mode + self refresh */ | ||
24 | }; | ||
25 | |||
26 | static int cpuidle_sleep_enter(struct cpuidle_device *dev, | ||
27 | struct cpuidle_state *state) | ||
28 | { | ||
29 | unsigned long allowed_mode = arch_hwblk_sleep_mode(); | ||
30 | ktime_t before, after; | ||
31 | int requested_state = state - &dev->states[0]; | ||
32 | int allowed_state; | ||
33 | int k; | ||
34 | |||
35 | /* convert allowed mode to allowed state */ | ||
36 | for (k = ARRAY_SIZE(cpuidle_mode) - 1; k > 0; k--) | ||
37 | if (cpuidle_mode[k] == allowed_mode) | ||
38 | break; | ||
39 | |||
40 | allowed_state = k; | ||
41 | |||
42 | /* take the following into account for sleep mode selection: | ||
43 | * - allowed_state: best mode allowed by hardware (clock deps) | ||
44 | * - requested_state: best mode allowed by software (latencies) | ||
45 | */ | ||
46 | k = min_t(int, allowed_state, requested_state); | ||
47 | |||
48 | dev->last_state = &dev->states[k]; | ||
49 | before = ktime_get(); | ||
50 | sh_mobile_call_standby(cpuidle_mode[k]); | ||
51 | after = ktime_get(); | ||
52 | return ktime_to_ns(ktime_sub(after, before)) >> 10; | ||
53 | } | ||
54 | |||
55 | static struct cpuidle_device cpuidle_dev; | ||
56 | static struct cpuidle_driver cpuidle_driver = { | ||
57 | .name = "sh_idle", | ||
58 | .owner = THIS_MODULE, | ||
59 | }; | ||
60 | |||
61 | void sh_mobile_setup_cpuidle(void) | ||
62 | { | ||
63 | struct cpuidle_device *dev = &cpuidle_dev; | ||
64 | struct cpuidle_state *state; | ||
65 | int i; | ||
66 | |||
67 | cpuidle_register_driver(&cpuidle_driver); | ||
68 | |||
69 | for (i = 0; i < CPUIDLE_STATE_MAX; i++) { | ||
70 | dev->states[i].name[0] = '\0'; | ||
71 | dev->states[i].desc[0] = '\0'; | ||
72 | } | ||
73 | |||
74 | i = CPUIDLE_DRIVER_STATE_START; | ||
75 | |||
76 | state = &dev->states[i++]; | ||
77 | snprintf(state->name, CPUIDLE_NAME_LEN, "C0"); | ||
78 | strncpy(state->desc, "SuperH Sleep Mode", CPUIDLE_DESC_LEN); | ||
79 | state->exit_latency = 1; | ||
80 | state->target_residency = 1 * 2; | ||
81 | state->power_usage = 3; | ||
82 | state->flags = 0; | ||
83 | state->flags |= CPUIDLE_FLAG_SHALLOW; | ||
84 | state->flags |= CPUIDLE_FLAG_TIME_VALID; | ||
85 | state->enter = cpuidle_sleep_enter; | ||
86 | |||
87 | dev->safe_state = state; | ||
88 | |||
89 | state = &dev->states[i++]; | ||
90 | snprintf(state->name, CPUIDLE_NAME_LEN, "C1"); | ||
91 | strncpy(state->desc, "SuperH Sleep Mode [SF]", CPUIDLE_DESC_LEN); | ||
92 | state->exit_latency = 100; | ||
93 | state->target_residency = 1 * 2; | ||
94 | state->power_usage = 1; | ||
95 | state->flags = 0; | ||
96 | state->flags |= CPUIDLE_FLAG_TIME_VALID; | ||
97 | state->enter = cpuidle_sleep_enter; | ||
98 | |||
99 | dev->state_count = i; | ||
100 | |||
101 | cpuidle_register_device(dev); | ||
102 | } | ||
diff --git a/arch/sh/kernel/cpu/shmobile/pm.c b/arch/sh/kernel/cpu/shmobile/pm.c index 8c067adf683..de078d24ce5 100644 --- a/arch/sh/kernel/cpu/shmobile/pm.c +++ b/arch/sh/kernel/cpu/shmobile/pm.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * arch/sh/kernel/cpu/sh4a/pm-sh_mobile.c | 2 | * arch/sh/kernel/cpu/shmobile/pm.c |
3 | * | 3 | * |
4 | * Power management support code for SuperH Mobile | 4 | * Power management support code for SuperH Mobile |
5 | * | 5 | * |
@@ -32,20 +32,17 @@ | |||
32 | * | 32 | * |
33 | * R-standby mode is unsupported, but will be added in the future | 33 | * R-standby mode is unsupported, but will be added in the future |
34 | * U-standby mode is low priority since it needs bootloader hacks | 34 | * U-standby mode is low priority since it needs bootloader hacks |
35 | * | ||
36 | * All modes should be tied in with cpuidle. But before that can | ||
37 | * happen we need to keep track of enabled hardware blocks so we | ||
38 | * can avoid entering sleep modes that stop clocks to hardware | ||
39 | * blocks that are in use even though the cpu core is idle. | ||
40 | */ | 35 | */ |
41 | 36 | ||
37 | #define ILRAM_BASE 0xe5200000 | ||
38 | |||
42 | extern const unsigned char sh_mobile_standby[]; | 39 | extern const unsigned char sh_mobile_standby[]; |
43 | extern const unsigned int sh_mobile_standby_size; | 40 | extern const unsigned int sh_mobile_standby_size; |
44 | 41 | ||
45 | static void sh_mobile_call_standby(unsigned long mode) | 42 | void sh_mobile_call_standby(unsigned long mode) |
46 | { | 43 | { |
47 | extern void *vbr_base; | 44 | extern void *vbr_base; |
48 | void *onchip_mem = (void *)0xe5200000; /* ILRAM */ | 45 | void *onchip_mem = (void *)ILRAM_BASE; |
49 | void (*standby_onchip_mem)(unsigned long) = onchip_mem; | 46 | void (*standby_onchip_mem)(unsigned long) = onchip_mem; |
50 | 47 | ||
51 | /* Note: Wake up from sleep may generate exceptions! | 48 | /* Note: Wake up from sleep may generate exceptions! |
@@ -55,11 +52,6 @@ static void sh_mobile_call_standby(unsigned long mode) | |||
55 | if (mode & SUSP_SH_SF) | 52 | if (mode & SUSP_SH_SF) |
56 | asm volatile("ldc %0, vbr" : : "r" (onchip_mem) : "memory"); | 53 | asm volatile("ldc %0, vbr" : : "r" (onchip_mem) : "memory"); |
57 | 54 | ||
58 | /* Copy the assembly snippet to the otherwise ununsed ILRAM */ | ||
59 | memcpy(onchip_mem, sh_mobile_standby, sh_mobile_standby_size); | ||
60 | wmb(); | ||
61 | ctrl_barrier(); | ||
62 | |||
63 | /* Let assembly snippet in on-chip memory handle the rest */ | 55 | /* Let assembly snippet in on-chip memory handle the rest */ |
64 | standby_onchip_mem(mode); | 56 | standby_onchip_mem(mode); |
65 | 57 | ||
@@ -85,7 +77,15 @@ static struct platform_suspend_ops sh_pm_ops = { | |||
85 | 77 | ||
86 | static int __init sh_pm_init(void) | 78 | static int __init sh_pm_init(void) |
87 | { | 79 | { |
80 | void *onchip_mem = (void *)ILRAM_BASE; | ||
81 | |||
82 | /* Copy the assembly snippet to the otherwise ununsed ILRAM */ | ||
83 | memcpy(onchip_mem, sh_mobile_standby, sh_mobile_standby_size); | ||
84 | wmb(); | ||
85 | ctrl_barrier(); | ||
86 | |||
88 | suspend_set_ops(&sh_pm_ops); | 87 | suspend_set_ops(&sh_pm_ops); |
88 | sh_mobile_setup_cpuidle(); | ||
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |
91 | 91 | ||