Skip to content

Commit a331ce6

Browse files
abresticralfbaechle
authored andcommitted
clocksource: mips-gic: Combine with GIC clockevent driver
Combine the GIC clocksource driver with the GIC clockevent driver from arch/mips/kernel/cevt-gic.c and remove the clockevent driver's separate Kconfig symbol. Signed-off-by: Andrew Bresticker <abrestic@chromium.org> Cc: Daniel Lezcano <daniel.lezcano@linaro.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Jason Cooper <jason@lakedaemon.net> Cc: Andrew Bresticker <abrestic@chromium.org> Cc: Paul Burton <paul.burton@imgtec.com> Cc: Qais Yousef <qais.yousef@imgtec.com> Cc: John Crispin <blogic@openwrt.org> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/8132/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent fa5635a commit a331ce6

6 files changed

Lines changed: 92 additions & 119 deletions

File tree

‎arch/mips/Kconfig‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,6 @@ config CEVT_GT641XX
935935
config CEVT_R4K
936936
bool
937937

938-
config CEVT_GIC
939-
select MIPS_CM
940-
bool
941-
942938
config CEVT_SB1250
943939
bool
944940

@@ -1911,15 +1907,6 @@ config FORCE_MAX_ZONEORDER
19111907
The page size is not necessarily 4KB. Keep this in mind
19121908
when choosing a value for this option.
19131909

1914-
config CEVT_GIC
1915-
bool "Use GIC global counter for clock events"
1916-
depends on MIPS_GIC && !MIPS_SEAD3
1917-
help
1918-
Use the GIC global counter for the clock events. The R4K clock
1919-
event driver is always present, so if the platform ends up not
1920-
detecting a GIC, it will fall back to the R4K timer for the
1921-
generation of clock events.
1922-
19231910
config BOARD_SCACHE
19241911
bool
19251912

‎arch/mips/include/asm/time.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extern int gic_clockevent_init(void);
5757

5858
static inline int mips_clockevent_init(void)
5959
{
60-
#if defined(CONFIG_CEVT_GIC)
60+
#if defined(CONFIG_CLKSRC_MIPS_GIC)
6161
return (gic_clockevent_init() | r4k_clockevent_init());
6262
#elif defined(CONFIG_CEVT_R4K)
6363
return r4k_clockevent_init();

‎arch/mips/kernel/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ endif
1919
obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o
2020
obj-$(CONFIG_CEVT_R4K) += cevt-r4k.o
2121
obj-$(CONFIG_CEVT_DS1287) += cevt-ds1287.o
22-
obj-$(CONFIG_CEVT_GIC) += cevt-gic.o
2322
obj-$(CONFIG_CEVT_GT641XX) += cevt-gt641xx.o
2423
obj-$(CONFIG_CEVT_SB1250) += cevt-sb1250.o
2524
obj-$(CONFIG_CEVT_TXX9) += cevt-txx9.o

‎arch/mips/kernel/cevt-gic.c‎

Lines changed: 0 additions & 103 deletions
This file was deleted.

‎drivers/clocksource/mips-gic-timer.c‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,100 @@
55
*
66
* Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
77
*/
8+
#include <linux/clockchips.h>
89
#include <linux/init.h>
10+
#include <linux/interrupt.h>
911
#include <linux/irqchip/mips-gic.h>
12+
#include <linux/percpu.h>
13+
#include <linux/smp.h>
1014
#include <linux/time.h>
1115

16+
#include <asm/time.h>
17+
18+
DEFINE_PER_CPU(struct clock_event_device, gic_clockevent_device);
19+
int gic_timer_irq_installed;
20+
21+
static int gic_next_event(unsigned long delta, struct clock_event_device *evt)
22+
{
23+
u64 cnt;
24+
int res;
25+
26+
cnt = gic_read_count();
27+
cnt += (u64)delta;
28+
gic_write_cpu_compare(cnt, cpumask_first(evt->cpumask));
29+
res = ((int)(gic_read_count() - cnt) >= 0) ? -ETIME : 0;
30+
return res;
31+
}
32+
33+
void gic_set_clock_mode(enum clock_event_mode mode,
34+
struct clock_event_device *evt)
35+
{
36+
/* Nothing to do ... */
37+
}
38+
39+
irqreturn_t gic_compare_interrupt(int irq, void *dev_id)
40+
{
41+
struct clock_event_device *cd;
42+
int cpu = smp_processor_id();
43+
44+
gic_write_compare(gic_read_compare());
45+
cd = &per_cpu(gic_clockevent_device, cpu);
46+
cd->event_handler(cd);
47+
return IRQ_HANDLED;
48+
}
49+
50+
struct irqaction gic_compare_irqaction = {
51+
.handler = gic_compare_interrupt,
52+
.flags = IRQF_PERCPU | IRQF_TIMER,
53+
.name = "timer",
54+
};
55+
56+
void gic_event_handler(struct clock_event_device *dev)
57+
{
58+
}
59+
60+
int gic_clockevent_init(void)
61+
{
62+
unsigned int cpu = smp_processor_id();
63+
struct clock_event_device *cd;
64+
unsigned int irq;
65+
66+
if (!cpu_has_counter || !gic_frequency)
67+
return -ENXIO;
68+
69+
irq = MIPS_GIC_IRQ_BASE + GIC_LOCAL_TO_HWIRQ(GIC_LOCAL_INT_COMPARE);
70+
71+
cd = &per_cpu(gic_clockevent_device, cpu);
72+
73+
cd->name = "MIPS GIC";
74+
cd->features = CLOCK_EVT_FEAT_ONESHOT |
75+
CLOCK_EVT_FEAT_C3STOP;
76+
77+
clockevent_set_clock(cd, gic_frequency);
78+
79+
/* Calculate the min / max delta */
80+
cd->max_delta_ns = clockevent_delta2ns(0x7fffffff, cd);
81+
cd->min_delta_ns = clockevent_delta2ns(0x300, cd);
82+
83+
cd->rating = 300;
84+
cd->irq = irq;
85+
cd->cpumask = cpumask_of(cpu);
86+
cd->set_next_event = gic_next_event;
87+
cd->set_mode = gic_set_clock_mode;
88+
cd->event_handler = gic_event_handler;
89+
90+
clockevents_register_device(cd);
91+
92+
if (!gic_timer_irq_installed) {
93+
setup_percpu_irq(irq, &gic_compare_irqaction);
94+
gic_timer_irq_installed = 1;
95+
}
96+
97+
enable_percpu_irq(irq, IRQ_TYPE_NONE);
98+
99+
return 0;
100+
}
101+
12102
static cycle_t gic_hpt_read(struct clocksource *cs)
13103
{
14104
return gic_read_count();

‎drivers/irqchip/irq-mips-gic.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static inline void gic_map_to_vpe(unsigned int intr, unsigned int vpe)
103103
GIC_SH_MAP_TO_VPE_REG_BIT(vpe));
104104
}
105105

106-
#if defined(CONFIG_CLKSRC_MIPS_GIC) || defined(CONFIG_CEVT_GIC)
106+
#ifdef CONFIG_CLKSRC_MIPS_GIC
107107
cycle_t gic_read_count(void)
108108
{
109109
unsigned int hi, hi2, lo;

0 commit comments

Comments
 (0)