ralink: add 3.14 support
[openwrt.git] / target / linux / ramips / patches-3.14 / 0021-MIPS-ralink-add-cpu-frequency-scaling.patch
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
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 |   36 ++++++++++++++++++++++++++++++++++++
12  1 file changed, 36 insertions(+)
13
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
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,6 +40,8 @@ struct systick_device {
30         int freq_scale;
31  };
32  
33 +static void (*systick_freq_scaling)(struct systick_device *sdev, int status);
34 +
35  static void systick_set_clock_mode(enum clock_event_mode mode,
36                                 struct clock_event_device *evt);
37  
38 @@ -87,6 +93,21 @@ static struct irqaction systick_irqaction = {
39         .dev_id = &systick.dev,
40  };
41  
42 +static inline void mt7620_freq_scaling(struct systick_device *sdev, int status)
43 +{
44 +       if (sdev->freq_scale == status)
45 +               return;
46 +
47 +       sdev->freq_scale = status;
48 +
49 +       pr_info("%s: %s autosleep mode\n", systick.dev.name,
50 +                       (status) ? ("enable") : ("disable"));
51 +       if (status)
52 +               rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) | SLEEP_EN, CLK_LUT_CFG);
53 +       else
54 +               rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) & ~SLEEP_EN, CLK_LUT_CFG);
55 +}
56 +
57  static void systick_set_clock_mode(enum clock_event_mode mode,
58                                 struct clock_event_device *evt)
59  {
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);
66                 break;
67  
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,
75         }
76  }
77  
78 +static const struct of_device_id systick_match[] = {
79 +       { .compatible = "ralink,mt7620-systick", .data = mt7620_freq_scaling},
80 +       {},
81 +};
82 +
83  static void __init ralink_systick_init(struct device_node *np)
84  {
85 +       const struct of_device_id *match;
86 +
87         systick.membase = of_iomap(np, 0);
88         if (!systick.membase)
89                 return;
90  
91 +       match = of_match_node(systick_match, np);
92 +       if (match)
93 +               systick_freq_scaling = match->data;
94 +
95         systick_irqaction.name = np->name;
96         systick.dev.name = np->name;
97         clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60);
98 -- 
99 1.7.10.4
100