1 From e76ecd496c9b074ab21b17f12494d823a407e89a 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 21/57] 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 | 36 ++++++++++++++++++++++++++++++++++++
12 1 file changed, 36 insertions(+)
14 diff --git a/arch/mips/ralink/cevt-rt3352.c b/arch/mips/ralink/cevt-rt3352.c
15 index 24bf057..4174b40 100644
16 --- a/arch/mips/ralink/cevt-rt3352.c
17 +++ b/arch/mips/ralink/cevt-rt3352.c
19 /* enable the counter */
20 #define CFG_CNT_EN 0x1
22 +/* mt7620 frequency scaling defines */
23 +#define CLK_LUT_CFG 0x40
24 +#define SLEEP_EN BIT(31)
26 struct systick_device {
27 void __iomem *membase;
28 struct clock_event_device dev;
29 @@ -36,6 +40,8 @@ struct systick_device {
33 +static void (*systick_freq_scaling)(struct systick_device *sdev, int status);
35 static void systick_set_clock_mode(enum clock_event_mode mode,
36 struct clock_event_device *evt);
38 @@ -87,6 +93,21 @@ static struct irqaction systick_irqaction = {
39 .dev_id = &systick.dev,
42 +static inline void mt7620_freq_scaling(struct systick_device *sdev, int status)
44 + if (sdev->freq_scale == status)
47 + sdev->freq_scale = status;
49 + pr_info("%s: %s autosleep mode\n", systick.dev.name,
50 + (status) ? ("enable") : ("disable"));
52 + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) | SLEEP_EN, CLK_LUT_CFG);
54 + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) & ~SLEEP_EN, CLK_LUT_CFG);
57 static void systick_set_clock_mode(enum clock_event_mode mode,
58 struct clock_event_device *evt)
60 @@ -101,9 +122,13 @@ static void systick_set_clock_mode(enum clock_event_mode mode,
61 sdev->irq_requested = 1;
62 iowrite32(CFG_EXT_STK_EN | CFG_CNT_EN,
63 systick.membase + SYSTICK_CONFIG);
64 + if (systick_freq_scaling)
65 + systick_freq_scaling(sdev, 1);
68 case CLOCK_EVT_MODE_SHUTDOWN:
69 + if (systick_freq_scaling)
70 + systick_freq_scaling(sdev, 0);
71 if (sdev->irq_requested)
72 free_irq(systick.dev.irq, &systick_irqaction);
73 sdev->irq_requested = 0;
74 @@ -116,12 +141,23 @@ static void systick_set_clock_mode(enum clock_event_mode mode,
78 +static const struct of_device_id systick_match[] = {
79 + { .compatible = "ralink,mt7620-systick", .data = mt7620_freq_scaling},
83 static void __init ralink_systick_init(struct device_node *np)
85 + const struct of_device_id *match;
87 systick.membase = of_iomap(np, 0);
91 + match = of_match_node(systick_match, np);
93 + systick_freq_scaling = match->data;
95 systick_irqaction.name = np->name;
96 systick.dev.name = np->name;
97 clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60);