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
6 Signed-off-by: John Crispin <blogic@openwrt.org>
8 arch/mips/ralink/cevt-rt3352.c | 85 ++++++++++++++++++++++++++--------------
9 1 file changed, 56 insertions(+), 29 deletions(-)
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)
17 sdev->freq_scale = status;
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"));
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);
28 +static inline unsigned int read_count(struct systick_device *sdev)
30 + return ioread32(sdev->membase + SYSTICK_COUNT);
33 +static inline unsigned int read_compare(struct systick_device *sdev)
35 + return ioread32(sdev->membase + SYSTICK_COMPARE);
38 +static inline void write_compare(struct systick_device *sdev, unsigned int val)
40 + iowrite32(val, sdev->membase + SYSTICK_COMPARE);
43 static int systick_next_event(unsigned long delta,
44 struct clock_event_device *evt)
46 struct systick_device *sdev;
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;
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)
65 static irqreturn_t systick_interrupt(int irq, void *dev_id)
67 - struct clock_event_device *dev = (struct clock_event_device *) dev_id;
69 + struct clock_event_device *cdev;
70 + struct systick_device *sdev;
72 + if (read_c0_cause() & STATUSF_IP7) {
73 + cdev = (struct clock_event_device *) dev_id;
74 + sdev = container_of(cdev, struct systick_device, dev);
76 - dev->event_handler(dev);
77 + /* Clear Count/Compare Interrupt */
78 + write_compare(sdev, read_compare(sdev));
79 + cdev->event_handler(cdev);
84 + return IRQ_RETVAL(ret);
87 static struct systick_device systick = {
90 - * cevt-r4k uses 300, make sure systick
91 - * gets used if available
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);
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);
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)
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},
118 static void __init ralink_systick_init(struct device_node *np)
120 const struct of_device_id *match;
123 systick.membase = of_iomap(np, 0);
124 if (!systick.membase)
127 match = of_match_node(systick_match, np);
130 systick_freq_scaling = match->data;
132 + * cevt-r4k uses 300, make sure systick
133 + * gets used if available
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);
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);
155 - clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
156 - SYSTICK_FREQ, 301, 16, clocksource_mmio_readl_up);
158 - clockevents_register_device(&systick.dev);
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);