0e567cb2f01fc7f4a08b076d005e017e8d8d35fd
[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 --- a/arch/mips/ralink/cevt-rt3352.c
15 +++ b/arch/mips/ralink/cevt-rt3352.c
16 @@ -29,6 +29,10 @@
17  /* enable the counter */
18  #define CFG_CNT_EN             0x1
19  
20 +/* mt7620 frequency scaling defines */
21 +#define CLK_LUT_CFG    0x40
22 +#define SLEEP_EN       BIT(31)
23 +
24  struct systick_device {
25         void __iomem *membase;
26         struct clock_event_device dev;
27 @@ -36,6 +40,8 @@ struct systick_device {
28         int freq_scale;
29  };
30  
31 +static void (*systick_freq_scaling)(struct systick_device *sdev, int status);
32 +
33  static void systick_set_clock_mode(enum clock_event_mode mode,
34                                 struct clock_event_device *evt);
35  
36 @@ -87,6 +93,21 @@ static struct irqaction systick_irqactio
37         .dev_id = &systick.dev,
38  };
39  
40 +static inline void mt7620_freq_scaling(struct systick_device *sdev, int status)
41 +{
42 +       if (sdev->freq_scale == status)
43 +               return;
44 +
45 +       sdev->freq_scale = status;
46 +
47 +       pr_info("%s: %s autosleep mode\n", systick.dev.name,
48 +                       (status) ? ("enable") : ("disable"));
49 +       if (status)
50 +               rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) | SLEEP_EN, CLK_LUT_CFG);
51 +       else
52 +               rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) & ~SLEEP_EN, CLK_LUT_CFG);
53 +}
54 +
55  static void systick_set_clock_mode(enum clock_event_mode mode,
56                                 struct clock_event_device *evt)
57  {
58 @@ -101,9 +122,13 @@ static void systick_set_clock_mode(enum
59                 sdev->irq_requested = 1;
60                 iowrite32(CFG_EXT_STK_EN | CFG_CNT_EN,
61                                 systick.membase + SYSTICK_CONFIG);
62 +               if (systick_freq_scaling)
63 +                       systick_freq_scaling(sdev, 1);
64                 break;
65  
66         case CLOCK_EVT_MODE_SHUTDOWN:
67 +               if (systick_freq_scaling)
68 +                       systick_freq_scaling(sdev, 0);
69                 if (sdev->irq_requested)
70                         free_irq(systick.dev.irq, &systick_irqaction);
71                 sdev->irq_requested = 0;
72 @@ -116,12 +141,23 @@ static void systick_set_clock_mode(enum
73         }
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);