ralink: bump to the target to v4.3
[openwrt/openwrt.git] / target / linux / ramips / patches-4.3 / 0006-MIPS-ralink-add-cpu-frequency-scaling.patch
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
5
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.
8
9 Signed-off-by: John Crispin <blogic@openwrt.org>
10 ---
11 arch/mips/ralink/cevt-rt3352.c | 38 ++++++++++++++++++++++++++++++++++++++
12 1 file changed, 38 insertions(+)
13
14 diff --git a/arch/mips/ralink/cevt-rt3352.c b/arch/mips/ralink/cevt-rt3352.c
15 index a8e70a9..b36888c 100644
16 --- a/arch/mips/ralink/cevt-rt3352.c
17 +++ b/arch/mips/ralink/cevt-rt3352.c
18 @@ -29,6 +29,10 @@
19 /* enable the counter */
20 #define CFG_CNT_EN 0x1
21
22 +/* mt7620 frequency scaling defines */
23 +#define CLK_LUT_CFG 0x40
24 +#define SLEEP_EN BIT(31)
25 +
26 struct systick_device {
27 void __iomem *membase;
28 struct clock_event_device dev;
29 @@ -36,9 +40,26 @@ struct systick_device {
30 int freq_scale;
31 };
32
33 +static void (*systick_freq_scaling)(struct systick_device *sdev, int status);
34 +
35 static int systick_set_oneshot(struct clock_event_device *evt);
36 static int systick_shutdown(struct clock_event_device *evt);
37
38 +static inline void mt7620_freq_scaling(struct systick_device *sdev, int status)
39 +{
40 + if (sdev->freq_scale == status)
41 + return;
42 +
43 + sdev->freq_scale = status;
44 +
45 + pr_info("%s: %s autosleep mode\n", systick.dev.name,
46 + (status) ? ("enable") : ("disable"));
47 + if (status)
48 + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) | SLEEP_EN, CLK_LUT_CFG);
49 + else
50 + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) & ~SLEEP_EN, CLK_LUT_CFG);
51 +}
52 +
53 static int systick_next_event(unsigned long delta,
54 struct clock_event_device *evt)
55 {
56 @@ -99,6 +120,9 @@ static int systick_shutdown(struct clock_event_device *evt)
57 sdev->irq_requested = 0;
58 iowrite32(0, systick.membase + SYSTICK_CONFIG);
59
60 + if (systick_freq_scaling)
61 + systick_freq_scaling(sdev, 0);
62 +
63 return 0;
64 }
65
66 @@ -114,15 +138,29 @@ static int systick_set_oneshot(struct clock_event_device *evt)
67 iowrite32(CFG_EXT_STK_EN | CFG_CNT_EN,
68 systick.membase + SYSTICK_CONFIG);
69
70 + if (systick_freq_scaling)
71 + systick_freq_scaling(sdev, 1);
72 +
73 return 0;
74 }
75
76 +static const struct of_device_id systick_match[] = {
77 + { .compatible = "ralink,mt7620-systick", .data = mt7620_freq_scaling},
78 + {},
79 +};
80 +
81 static void __init ralink_systick_init(struct device_node *np)
82 {
83 + const struct of_device_id *match;
84 +
85 systick.membase = of_iomap(np, 0);
86 if (!systick.membase)
87 return;
88
89 + match = of_match_node(systick_match, np);
90 + if (match)
91 + systick_freq_scaling = match->data;
92 +
93 systick_irqaction.name = np->name;
94 systick.dev.name = np->name;
95 clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60);
96 --
97 1.7.10.4
98