sg3-utils: add newer buildable version
[openembedded.git] / recipes / linux / linux-kirkwood / 0001--ARM-Kirkwood-CPU-idle-driver.patch
1 From 286f96f0b2e1ee5a124effba59a01f8d4bf69ddf Mon Sep 17 00:00:00 2001
2 From: Rabeeh Khoury <rabeeh@marvell.com>
3 Date: Tue, 24 Mar 2009 16:10:15 +0200
4 Subject: [PATCH] [ARM] Kirkwood: CPU idle driver
5
6 The patch adds support for Kirkwood cpu idle.
7 Two idle states are defined:
8 1. Wait-for-interrupt (replacing default kirkwood wfi)
9 2. Wait-for-interrupt and DDR self refresh
10
11 Signed-off-by: Rabeeh Khoury <rabeeh@marvell.com>
12 Signed-off-by: Nicolas Pitre <nico@marvell.com>
13 ---
14  arch/arm/configs/kirkwood_defconfig            |    4 +-
15  arch/arm/mach-kirkwood/Makefile                |    2 +
16  arch/arm/mach-kirkwood/cpuidle.c               |   96 ++++++++++++++++++++++++
17  arch/arm/mach-kirkwood/include/mach/kirkwood.h |    1 +
18  4 files changed, 102 insertions(+), 1 deletions(-)
19  create mode 100644 arch/arm/mach-kirkwood/cpuidle.c
20
21 diff --git a/arch/arm/configs/kirkwood_defconfig b/arch/arm/configs/kirkwood_defconfig
22 index c367ae4..a99b3eb 100644
23 --- a/arch/arm/configs/kirkwood_defconfig
24 +++ b/arch/arm/configs/kirkwood_defconfig
25 @@ -263,7 +263,9 @@ CONFIG_CMDLINE=""
26  #
27  # CPU Power Management
28  #
29 -# CONFIG_CPU_IDLE is not set
30 +CONFIG_CPU_IDLE=y
31 +CONFIG_CPU_IDLE_GOV_LADDER=y
32 +CONFIG_CPU_IDLE_GOV_MENU=y
33  
34  #
35  # Floating point emulation
36 diff --git a/arch/arm/mach-kirkwood/Makefile b/arch/arm/mach-kirkwood/Makefile
37 index 8f03c9b..f21f35d 100644
38 --- a/arch/arm/mach-kirkwood/Makefile
39 +++ b/arch/arm/mach-kirkwood/Makefile
40 @@ -5,3 +5,5 @@ obj-$(CONFIG_MACH_RD88F6192_NAS)        += rd88f6192-nas-setup.o
41  obj-$(CONFIG_MACH_RD88F6281)           += rd88f6281-setup.o
42  obj-$(CONFIG_MACH_SHEEVAPLUG)          += sheevaplug-setup.o
43  obj-$(CONFIG_MACH_TS219)               += ts219-setup.o
44 +
45 +obj-$(CONFIG_CPU_IDLE)                 += cpuidle.o
46 diff --git a/arch/arm/mach-kirkwood/cpuidle.c b/arch/arm/mach-kirkwood/cpuidle.c
47 new file mode 100644
48 index 0000000..43052c7
49 --- /dev/null
50 +++ b/arch/arm/mach-kirkwood/cpuidle.c
51 @@ -0,0 +1,96 @@
52 +/*
53 + * arch/arm/mach-kirkwood/cpuidle.c
54 + *
55 + * CPU idle Marvell Kirkwood SoCs
56 + *
57 + * This file is licensed under the terms of the GNU General Public
58 + * License version 2.  This program is licensed "as is" without any
59 + * warranty of any kind, whether express or implied.
60 + *
61 + * The cpu idle uses wait-for-interrupt and DDR self refresh in order
62 + * to implement two idle states -
63 + * #1 wait-for-interrupt
64 + * #2 wait-for-interrupt and DDR self refresh
65 + */
66 +
67 +#include <linux/kernel.h>
68 +#include <linux/init.h>
69 +#include <linux/platform_device.h>
70 +#include <linux/cpuidle.h>
71 +#include <asm/io.h>
72 +#include <asm/proc-fns.h>
73 +#include <mach/kirkwood.h>
74 +
75 +#define KIRKWOOD_MAX_STATES    2
76 +
77 +static struct cpuidle_driver kirkwood_idle_driver = {
78 +       .name =         "kirkwood_idle",
79 +       .owner =        THIS_MODULE,
80 +};
81 +
82 +static DEFINE_PER_CPU(struct cpuidle_device, kirkwood_cpuidle_device);
83 +
84 +/* Actual code that puts the SoC in different idle states */
85 +static int kirkwood_enter_idle(struct cpuidle_device *dev,
86 +                              struct cpuidle_state *state)
87 +{
88 +       struct timeval before, after;
89 +       int idle_time;
90 +
91 +       local_irq_disable();
92 +       do_gettimeofday(&before);
93 +       if (state == &dev->states[0])
94 +               /* Wait for interrupt state */
95 +               cpu_do_idle();
96 +       else if (state == &dev->states[1]) {
97 +               /*
98 +                * Following write will put DDR in self refresh.
99 +                * Note that we have 256 cycles before DDR puts it
100 +                * self in self-refresh, so the wait-for-interrupt
101 +                * call afterwards won't get the DDR from self refresh
102 +                * mode.
103 +                */
104 +               writel(0x7, DDR_OPERATION_BASE);
105 +               cpu_do_idle();
106 +       }
107 +       do_gettimeofday(&after);
108 +       local_irq_enable();
109 +       idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
110 +                       (after.tv_usec - before.tv_usec);
111 +       return idle_time;
112 +}
113 +
114 +/* Initialize CPU idle by registering the idle states */
115 +static int kirkwood_init_cpuidle(void)
116 +{
117 +       struct cpuidle_device *device;
118 +
119 +       cpuidle_register_driver(&kirkwood_idle_driver);
120 +
121 +       device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id());
122 +       device->state_count = KIRKWOOD_MAX_STATES;
123 +
124 +       /* Wait for interrupt state */
125 +       device->states[0].enter = kirkwood_enter_idle;
126 +       device->states[0].exit_latency = 1;
127 +       device->states[0].target_residency = 10000;
128 +       device->states[0].flags = CPUIDLE_FLAG_TIME_VALID;
129 +       strcpy(device->states[0].name, "WFI");
130 +       strcpy(device->states[0].desc, "Wait for interrupt");
131 +
132 +       /* Wait for interrupt and DDR self refresh state */
133 +       device->states[1].enter = kirkwood_enter_idle;
134 +       device->states[1].exit_latency = 10;
135 +       device->states[1].target_residency = 10000;
136 +       device->states[1].flags = CPUIDLE_FLAG_TIME_VALID;
137 +       strcpy(device->states[1].name, "DDR SR");
138 +       strcpy(device->states[1].desc, "WFI and DDR Self Refresh");
139 +
140 +       if (cpuidle_register_device(device)) {
141 +               printk(KERN_ERR "kirkwood_init_cpuidle: Failed registering\n");
142 +               return -EIO;
143 +       }
144 +       return 0;
145 +}
146 +
147 +device_initcall(kirkwood_init_cpuidle);
148 diff --git a/arch/arm/mach-kirkwood/include/mach/kirkwood.h b/arch/arm/mach-kirkwood/include/mach/kirkwood.h
149 index 38c9868..e9ae73d 100644
150 --- a/arch/arm/mach-kirkwood/include/mach/kirkwood.h
151 +++ b/arch/arm/mach-kirkwood/include/mach/kirkwood.h
152 @@ -86,6 +86,7 @@
153   */
154  #define DDR_VIRT_BASE          (KIRKWOOD_REGS_VIRT_BASE | 0x00000)
155  #define  DDR_WINDOW_CPU_BASE   (DDR_VIRT_BASE | 0x1500)
156 +#define DDR_OPERATION_BASE     (DDR_VIRT_BASE | 0x1418)
157  
158  #define DEV_BUS_PHYS_BASE      (KIRKWOOD_REGS_PHYS_BASE | 0x10000)
159  #define DEV_BUS_VIRT_BASE      (KIRKWOOD_REGS_VIRT_BASE | 0x10000)
160 -- 
161 1.6.0.4
162