Skip to content

Commit 95150ae

Browse files
abresticralfbaechle
authored andcommitted
irqchip: mips-gic: Implement irq_set_type callback
Implement an irq_set_type callback for the GIC which is used to set the polarity and trigger type of GIC interrupts. Signed-off-by: Andrew Bresticker <abrestic@chromium.org> Acked-by: Jason Cooper <jason@lakedaemon.net> Reviewed-by: Qais Yousef <qais.yousef@imgtec.com> Tested-by: Qais Yousef <qais.yousef@imgtec.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Jeffrey Deans <jeffrey.deans@imgtec.com> Cc: Markos Chandras <markos.chandras@imgtec.com> Cc: Paul Burton <paul.burton@imgtec.com> Cc: Jonas Gorski <jogo@openwrt.org> Cc: John Crispin <blogic@openwrt.org> Cc: David Daney <ddaney.cavm@gmail.com> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/7810/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 5561c9e commit 95150ae

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

arch/mips/include/asm/gic.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define GIC_POL_NEG 0
2424
#define GIC_TRIG_EDGE 1
2525
#define GIC_TRIG_LEVEL 0
26+
#define GIC_TRIG_DUAL_ENABLE 1
27+
#define GIC_TRIG_DUAL_DISABLE 0
2628

2729
#define MSK(n) ((1 << (n)) - 1)
2830
#define REG32(addr) (*(volatile unsigned int *) (addr))
@@ -179,6 +181,13 @@
179181
GIC_INTR_OFS(intr)), (1 << GIC_INTR_BIT(intr)), \
180182
(trig) << GIC_INTR_BIT(intr))
181183

184+
/* Dual edge triggering : Reset Value is always 0 */
185+
#define GIC_SH_SET_DUAL_OFS 0x0200
186+
#define GIC_SET_DUAL(intr, dual) \
187+
GICBIS(GIC_REG_ADDR(SHARED, GIC_SH_SET_DUAL_OFS + \
188+
GIC_INTR_OFS(intr)), (1 << GIC_INTR_BIT(intr)), \
189+
(dual) << GIC_INTR_BIT(intr))
190+
182191
/* Mask manipulation */
183192
#define GIC_SH_SMASK_OFS 0x0380
184193
#define GIC_SET_INTR_MASK(intr) \

drivers/irqchip/irq-mips-gic.c

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct gic_intrmask_regs {
4343
static struct gic_pcpu_mask pcpu_masks[NR_CPUS];
4444
static struct gic_pending_regs pending_regs[NR_CPUS];
4545
static struct gic_intrmask_regs intrmask_regs[NR_CPUS];
46+
static DEFINE_SPINLOCK(gic_lock);
4647

4748
#if defined(CONFIG_CSRC_GIC) || defined(CONFIG_CEVT_GIC)
4849
cycle_t gic_read_count(void)
@@ -244,9 +245,60 @@ static void gic_ack_irq(struct irq_data *d)
244245
GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), d->irq - gic_irq_base);
245246
}
246247

247-
#ifdef CONFIG_SMP
248-
static DEFINE_SPINLOCK(gic_lock);
248+
static int gic_set_type(struct irq_data *d, unsigned int type)
249+
{
250+
unsigned int irq = d->irq - gic_irq_base;
251+
unsigned long flags;
252+
bool is_edge;
253+
254+
spin_lock_irqsave(&gic_lock, flags);
255+
switch (type & IRQ_TYPE_SENSE_MASK) {
256+
case IRQ_TYPE_EDGE_FALLING:
257+
GIC_SET_POLARITY(irq, GIC_POL_NEG);
258+
GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE);
259+
GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
260+
is_edge = true;
261+
break;
262+
case IRQ_TYPE_EDGE_RISING:
263+
GIC_SET_POLARITY(irq, GIC_POL_POS);
264+
GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE);
265+
GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
266+
is_edge = true;
267+
break;
268+
case IRQ_TYPE_EDGE_BOTH:
269+
/* polarity is irrelevant in this case */
270+
GIC_SET_TRIGGER(irq, GIC_TRIG_EDGE);
271+
GIC_SET_DUAL(irq, GIC_TRIG_DUAL_ENABLE);
272+
is_edge = true;
273+
break;
274+
case IRQ_TYPE_LEVEL_LOW:
275+
GIC_SET_POLARITY(irq, GIC_POL_NEG);
276+
GIC_SET_TRIGGER(irq, GIC_TRIG_LEVEL);
277+
GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
278+
is_edge = false;
279+
break;
280+
case IRQ_TYPE_LEVEL_HIGH:
281+
default:
282+
GIC_SET_POLARITY(irq, GIC_POL_POS);
283+
GIC_SET_TRIGGER(irq, GIC_TRIG_LEVEL);
284+
GIC_SET_DUAL(irq, GIC_TRIG_DUAL_DISABLE);
285+
is_edge = false;
286+
break;
287+
}
249288

289+
if (is_edge) {
290+
gic_irq_flags[irq] |= GIC_TRIG_EDGE;
291+
__irq_set_handler_locked(d->irq, handle_edge_irq);
292+
} else {
293+
gic_irq_flags[irq] &= ~GIC_TRIG_EDGE;
294+
__irq_set_handler_locked(d->irq, handle_level_irq);
295+
}
296+
spin_unlock_irqrestore(&gic_lock, flags);
297+
298+
return 0;
299+
}
300+
301+
#ifdef CONFIG_SMP
250302
static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
251303
bool force)
252304
{
@@ -282,6 +334,7 @@ static struct irq_chip gic_irq_controller = {
282334
.irq_ack = gic_ack_irq,
283335
.irq_mask = gic_mask_irq,
284336
.irq_unmask = gic_unmask_irq,
337+
.irq_set_type = gic_set_type,
285338
#ifdef CONFIG_SMP
286339
.irq_set_affinity = gic_set_affinity,
287340
#endif

0 commit comments

Comments
 (0)