1 From bd30f19a006fb52bac80c6463c49dd2f4159f4ac Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 28 Jul 2013 16:26:41 +0200
4 Subject: [PATCH 06/53] MIPS: ralink: add cpu frequency scaling
6 This feature will break udelay() and cause the delay loop to have longer delays
7 when the frequency is scaled causing a performance hit.
9 Signed-off-by: John Crispin <blogic@openwrt.org>
11 arch/mips/ralink/cevt-rt3352.c | 38 ++++++++++++++++++++++++++++++++++++++
12 1 file changed, 38 insertions(+)
14 --- a/arch/mips/ralink/cevt-rt3352.c
15 +++ b/arch/mips/ralink/cevt-rt3352.c
17 /* enable the counter */
18 #define CFG_CNT_EN 0x1
20 +/* mt7620 frequency scaling defines */
21 +#define CLK_LUT_CFG 0x40
22 +#define SLEEP_EN BIT(31)
24 struct systick_device {
25 void __iomem *membase;
26 struct clock_event_device dev;
27 @@ -36,9 +40,26 @@ struct systick_device {
31 +static void (*systick_freq_scaling)(struct systick_device *sdev, int status);
33 static int systick_set_oneshot(struct clock_event_device *evt);
34 static int systick_shutdown(struct clock_event_device *evt);
36 +static inline void mt7620_freq_scaling(struct systick_device *sdev, int status)
38 + if (sdev->freq_scale == status)
41 + sdev->freq_scale = status;
43 + pr_info("%s: %s autosleep mode\n", systick.dev.name,
44 + (status) ? ("enable") : ("disable"));
46 + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) | SLEEP_EN, CLK_LUT_CFG);
48 + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) & ~SLEEP_EN, CLK_LUT_CFG);
51 static int systick_next_event(unsigned long delta,
52 struct clock_event_device *evt)
54 @@ -99,6 +120,9 @@ static int systick_shutdown(struct clock
55 sdev->irq_requested = 0;
56 iowrite32(0, systick.membase + SYSTICK_CONFIG);
58 + if (systick_freq_scaling)
59 + systick_freq_scaling(sdev, 0);
64 @@ -114,15 +138,29 @@ static int systick_set_oneshot(struct cl
65 iowrite32(CFG_EXT_STK_EN | CFG_CNT_EN,
66 systick.membase + SYSTICK_CONFIG);
68 + if (systick_freq_scaling)
69 + systick_freq_scaling(sdev, 1);
74 +static const struct of_device_id systick_match[] = {
75 + { .compatible = "ralink,mt7620-systick", .data = mt7620_freq_scaling},
79 static void __init ralink_systick_init(struct device_node *np)
81 + const struct of_device_id *match;
83 systick.membase = of_iomap(np, 0);
87 + match = of_match_node(systick_match, np);
89 + systick_freq_scaling = match->data;
91 systick_irqaction.name = np->name;
92 systick.dev.name = np->name;
93 clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60);