rpcd: iwinfo plugin fixes
[openwrt.git] / target / linux / ramips / patches-4.4 / 0014-arch-mips-cleanup-cevt-rt3352.patch
1 From e6ed424c36458aff8738fb1fbb0141196678058a Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 7 Dec 2015 17:17:23 +0100
4 Subject: [PATCH 14/53] arch: mips: cleanup cevt-rt3352
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
8  arch/mips/ralink/cevt-rt3352.c |   85 ++++++++++++++++++++++++++--------------
9  1 file changed, 56 insertions(+), 29 deletions(-)
10
11 --- a/arch/mips/ralink/cevt-rt3352.c
12 +++ b/arch/mips/ralink/cevt-rt3352.c
13 @@ -52,7 +52,7 @@ static inline void mt7620_freq_scaling(s
14  
15         sdev->freq_scale = status;
16  
17 -       pr_info("%s: %s autosleep mode\n", systick.dev.name,
18 +       pr_info("%s: %s autosleep mode\n", sdev->dev.name,
19                         (status) ? ("enable") : ("disable"));
20         if (status)
21                 rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) | SLEEP_EN, CLK_LUT_CFG);
22 @@ -60,18 +60,33 @@ static inline void mt7620_freq_scaling(s
23                 rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) & ~SLEEP_EN, CLK_LUT_CFG);
24  }
25  
26 +static inline unsigned int read_count(struct systick_device *sdev)
27 +{
28 +       return ioread32(sdev->membase + SYSTICK_COUNT);
29 +}
30 +
31 +static inline unsigned int read_compare(struct systick_device *sdev)
32 +{
33 +       return ioread32(sdev->membase + SYSTICK_COMPARE);
34 +}
35 +
36 +static inline void write_compare(struct systick_device *sdev, unsigned int val)
37 +{
38 +       iowrite32(val, sdev->membase + SYSTICK_COMPARE);
39 +}
40 +
41  static int systick_next_event(unsigned long delta,
42                                 struct clock_event_device *evt)
43  {
44         struct systick_device *sdev;
45 -       u32 count;
46 +       int res;
47  
48         sdev = container_of(evt, struct systick_device, dev);
49 -       count = ioread32(sdev->membase + SYSTICK_COUNT);
50 -       count = (count + delta) % SYSTICK_FREQ;
51 -       iowrite32(count, sdev->membase + SYSTICK_COMPARE);
52 +       delta += read_count(sdev);
53 +       write_compare(sdev, delta);
54 +       res = ((int)(read_count(sdev) - delta) >= 0) ? -ETIME : 0;
55  
56 -       return 0;
57 +       return res;
58  }
59  
60  static void systick_event_handler(struct clock_event_device *dev)
61 @@ -81,20 +96,25 @@ static void systick_event_handler(struct
62  
63  static irqreturn_t systick_interrupt(int irq, void *dev_id)
64  {
65 -       struct clock_event_device *dev = (struct clock_event_device *) dev_id;
66 +       int ret = 0;
67 +       struct clock_event_device *cdev;
68 +       struct systick_device *sdev;
69  
70 -       dev->event_handler(dev);
71 +       if (read_c0_cause() & STATUSF_IP7) {
72 +               cdev = (struct clock_event_device *) dev_id;
73 +               sdev = container_of(cdev, struct systick_device, dev);
74 +
75 +               /* Clear Count/Compare Interrupt */
76 +               write_compare(sdev, read_compare(sdev));
77 +               cdev->event_handler(cdev);
78 +               ret = 1;
79 +       }
80  
81 -       return IRQ_HANDLED;
82 +       return IRQ_RETVAL(ret);
83  }
84  
85  static struct systick_device systick = {
86         .dev = {
87 -               /*
88 -                * cevt-r4k uses 300, make sure systick
89 -                * gets used if available
90 -                */
91 -               .rating                 = 310,
92                 .features               = CLOCK_EVT_FEAT_ONESHOT,
93                 .set_next_event         = systick_next_event,
94                 .set_state_shutdown     = systick_shutdown,
95 @@ -116,9 +136,9 @@ static int systick_shutdown(struct clock
96         sdev = container_of(evt, struct systick_device, dev);
97  
98         if (sdev->irq_requested)
99 -               free_irq(systick.dev.irq, &systick_irqaction);
100 +               remove_irq(systick.dev.irq, &systick_irqaction);
101         sdev->irq_requested = 0;
102 -       iowrite32(0, systick.membase + SYSTICK_CONFIG);
103 +       iowrite32(CFG_CNT_EN, systick.membase + SYSTICK_CONFIG);
104  
105         if (systick_freq_scaling)
106                 systick_freq_scaling(sdev, 0);
107 @@ -145,38 +165,45 @@ static int systick_set_oneshot(struct cl
108  }
109  
110  static const struct of_device_id systick_match[] = {
111 -       { .compatible = "ralink,mt7620-systick", .data = mt7620_freq_scaling},
112 +       { .compatible = "ralink,mt7620a-systick", .data = mt7620_freq_scaling},
113         {},
114  };
115  
116  static void __init ralink_systick_init(struct device_node *np)
117  {
118         const struct of_device_id *match;
119 +       int rating = 200;
120  
121         systick.membase = of_iomap(np, 0);
122         if (!systick.membase)
123                 return;
124  
125         match = of_match_node(systick_match, np);
126 -       if (match)
127 +       if (match) {
128                 systick_freq_scaling = match->data;
129 +               /*
130 +                * cevt-r4k uses 300, make sure systick
131 +                * gets used if available
132 +                */
133 +               rating = 310;
134 +       }
135  
136 -       systick_irqaction.name = np->name;
137 -       systick.dev.name = np->name;
138 -       clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60);
139 -       systick.dev.max_delta_ns = clockevent_delta2ns(0x7fff, &systick.dev);
140 -       systick.dev.min_delta_ns = clockevent_delta2ns(0x3, &systick.dev);
141 +       /* enable counter than register clock source */
142 +       iowrite32(CFG_CNT_EN, systick.membase + SYSTICK_CONFIG);
143 +       clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
144 +                       SYSTICK_FREQ, rating, 16, clocksource_mmio_readl_up);
145 +
146 +       /* register clock event */
147         systick.dev.irq = irq_of_parse_and_map(np, 0);
148         if (!systick.dev.irq) {
149                 pr_err("%s: request_irq failed", np->name);
150                 return;
151         }
152 -
153 -       clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
154 -                       SYSTICK_FREQ, 301, 16, clocksource_mmio_readl_up);
155 -
156 -       clockevents_register_device(&systick.dev);
157 -
158 +       systick_irqaction.name = np->name;
159 +       systick.dev.name = np->name;
160 +       systick.dev.rating = rating;
161 +       systick.dev.cpumask = cpumask_of(0);
162 +       clockevents_config_and_register(&systick.dev, SYSTICK_FREQ, 0x3, 0x7fff);
163         pr_info("%s: running - mult: %d, shift: %d\n",
164                         np->name, systick.dev.mult, systick.dev.shift);
165  }