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