1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * GT641xx IRQ routines.
5 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
7 #include <linux/hardirq.h>
8 #include <linux/init.h>
10 #include <linux/spinlock.h>
11 #include <linux/types.h>
13 #include <asm/gt64120.h>
15 #define GT641XX_IRQ_TO_BIT(irq) (1U << (irq - GT641XX_IRQ_BASE))
17 static DEFINE_RAW_SPINLOCK(gt641xx_irq_lock);
19 static void ack_gt641xx_irq(struct irq_data *d)
24 raw_spin_lock_irqsave(>641xx_irq_lock, flags);
25 cause = GT_READ(GT_INTRCAUSE_OFS);
26 cause &= ~GT641XX_IRQ_TO_BIT(d->irq);
27 GT_WRITE(GT_INTRCAUSE_OFS, cause);
28 raw_spin_unlock_irqrestore(>641xx_irq_lock, flags);
31 static void mask_gt641xx_irq(struct irq_data *d)
36 raw_spin_lock_irqsave(>641xx_irq_lock, flags);
37 mask = GT_READ(GT_INTRMASK_OFS);
38 mask &= ~GT641XX_IRQ_TO_BIT(d->irq);
39 GT_WRITE(GT_INTRMASK_OFS, mask);
40 raw_spin_unlock_irqrestore(>641xx_irq_lock, flags);
43 static void mask_ack_gt641xx_irq(struct irq_data *d)
48 raw_spin_lock_irqsave(>641xx_irq_lock, flags);
49 mask = GT_READ(GT_INTRMASK_OFS);
50 mask &= ~GT641XX_IRQ_TO_BIT(d->irq);
51 GT_WRITE(GT_INTRMASK_OFS, mask);
53 cause = GT_READ(GT_INTRCAUSE_OFS);
54 cause &= ~GT641XX_IRQ_TO_BIT(d->irq);
55 GT_WRITE(GT_INTRCAUSE_OFS, cause);
56 raw_spin_unlock_irqrestore(>641xx_irq_lock, flags);
59 static void unmask_gt641xx_irq(struct irq_data *d)
64 raw_spin_lock_irqsave(>641xx_irq_lock, flags);
65 mask = GT_READ(GT_INTRMASK_OFS);
66 mask |= GT641XX_IRQ_TO_BIT(d->irq);
67 GT_WRITE(GT_INTRMASK_OFS, mask);
68 raw_spin_unlock_irqrestore(>641xx_irq_lock, flags);
71 static struct irq_chip gt641xx_irq_chip = {
73 .irq_ack = ack_gt641xx_irq,
74 .irq_mask = mask_gt641xx_irq,
75 .irq_mask_ack = mask_ack_gt641xx_irq,
76 .irq_unmask = unmask_gt641xx_irq,
79 void gt641xx_irq_dispatch(void)
84 cause = GT_READ(GT_INTRCAUSE_OFS);
85 mask = GT_READ(GT_INTRMASK_OFS);
89 * bit0 : logical or of all the interrupt bits.
90 * bit30: logical or of bits[29:26,20:1].
91 * bit31: logical or of bits[25:1].
93 for (i = 1; i < 30; i++) {
94 if (cause & (1U << i)) {
95 do_IRQ(GT641XX_IRQ_BASE + i);
100 atomic_inc(&irq_err_count);
103 void __init gt641xx_irq_init(void)
107 GT_WRITE(GT_INTRMASK_OFS, 0);
108 GT_WRITE(GT_INTRCAUSE_OFS, 0);
111 * bit0 : logical or of all the interrupt bits.
112 * bit30: logical or of bits[29:26,20:1].
113 * bit31: logical or of bits[25:1].
115 for (i = 1; i < 30; i++)
116 irq_set_chip_and_handler(GT641XX_IRQ_BASE + i,
117 >641xx_irq_chip, handle_level_irq);