treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / sh / boards / mach-microdev / irq.c
blobdc27492c83d7657ae53d8fbf72d6759dcfa8fac2
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/sh/boards/superh/microdev/irq.c
5 * Copyright (C) 2003 Sean McGoogan (Sean.McGoogan@superh.com)
7 * SuperH SH4-202 MicroDev board support.
8 */
10 #include <linux/init.h>
11 #include <linux/irq.h>
12 #include <linux/interrupt.h>
13 #include <asm/io.h>
14 #include <mach/microdev.h>
16 #define NUM_EXTERNAL_IRQS 16 /* IRL0 .. IRL15 */
18 static const struct {
19 unsigned char fpgaIrq;
20 unsigned char mapped;
21 const char *name;
22 } fpgaIrqTable[NUM_EXTERNAL_IRQS] = {
23 { 0, 0, "unused" }, /* IRQ #0 IRL=15 0x200 */
24 { MICRODEV_FPGA_IRQ_KEYBOARD, 1, "keyboard" }, /* IRQ #1 IRL=14 0x220 */
25 { MICRODEV_FPGA_IRQ_SERIAL1, 1, "Serial #1"}, /* IRQ #2 IRL=13 0x240 */
26 { MICRODEV_FPGA_IRQ_ETHERNET, 1, "Ethernet" }, /* IRQ #3 IRL=12 0x260 */
27 { MICRODEV_FPGA_IRQ_SERIAL2, 0, "Serial #2"}, /* IRQ #4 IRL=11 0x280 */
28 { 0, 0, "unused" }, /* IRQ #5 IRL=10 0x2a0 */
29 { 0, 0, "unused" }, /* IRQ #6 IRL=9 0x2c0 */
30 { MICRODEV_FPGA_IRQ_USB_HC, 1, "USB" }, /* IRQ #7 IRL=8 0x2e0 */
31 { MICRODEV_IRQ_PCI_INTA, 1, "PCI INTA" }, /* IRQ #8 IRL=7 0x300 */
32 { MICRODEV_IRQ_PCI_INTB, 1, "PCI INTB" }, /* IRQ #9 IRL=6 0x320 */
33 { MICRODEV_IRQ_PCI_INTC, 1, "PCI INTC" }, /* IRQ #10 IRL=5 0x340 */
34 { MICRODEV_IRQ_PCI_INTD, 1, "PCI INTD" }, /* IRQ #11 IRL=4 0x360 */
35 { MICRODEV_FPGA_IRQ_MOUSE, 1, "mouse" }, /* IRQ #12 IRL=3 0x380 */
36 { MICRODEV_FPGA_IRQ_IDE2, 1, "IDE #2" }, /* IRQ #13 IRL=2 0x3a0 */
37 { MICRODEV_FPGA_IRQ_IDE1, 1, "IDE #1" }, /* IRQ #14 IRL=1 0x3c0 */
38 { 0, 0, "unused" }, /* IRQ #15 IRL=0 0x3e0 */
41 #if (MICRODEV_LINUX_IRQ_KEYBOARD != 1)
42 # error Inconsistancy in defining the IRQ# for Keyboard!
43 #endif
45 #if (MICRODEV_LINUX_IRQ_ETHERNET != 3)
46 # error Inconsistancy in defining the IRQ# for Ethernet!
47 #endif
49 #if (MICRODEV_LINUX_IRQ_USB_HC != 7)
50 # error Inconsistancy in defining the IRQ# for USB!
51 #endif
53 #if (MICRODEV_LINUX_IRQ_MOUSE != 12)
54 # error Inconsistancy in defining the IRQ# for PS/2 Mouse!
55 #endif
57 #if (MICRODEV_LINUX_IRQ_IDE2 != 13)
58 # error Inconsistancy in defining the IRQ# for secondary IDE!
59 #endif
61 #if (MICRODEV_LINUX_IRQ_IDE1 != 14)
62 # error Inconsistancy in defining the IRQ# for primary IDE!
63 #endif
65 static void disable_microdev_irq(struct irq_data *data)
67 unsigned int irq = data->irq;
68 unsigned int fpgaIrq;
70 if (irq >= NUM_EXTERNAL_IRQS)
71 return;
72 if (!fpgaIrqTable[irq].mapped)
73 return;
75 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
77 /* disable interrupts on the FPGA INTC register */
78 __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG);
81 static void enable_microdev_irq(struct irq_data *data)
83 unsigned int irq = data->irq;
84 unsigned long priorityReg, priorities, pri;
85 unsigned int fpgaIrq;
87 if (unlikely(irq >= NUM_EXTERNAL_IRQS))
88 return;
89 if (unlikely(!fpgaIrqTable[irq].mapped))
90 return;
92 pri = 15 - irq;
94 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
95 priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq);
97 /* set priority for the interrupt */
98 priorities = __raw_readl(priorityReg);
99 priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq);
100 priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri);
101 __raw_writel(priorities, priorityReg);
103 /* enable interrupts on the FPGA INTC register */
104 __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG);
107 static struct irq_chip microdev_irq_type = {
108 .name = "MicroDev-IRQ",
109 .irq_unmask = enable_microdev_irq,
110 .irq_mask = disable_microdev_irq,
113 /* This function sets the desired irq handler to be a MicroDev type */
114 static void __init make_microdev_irq(unsigned int irq)
116 disable_irq_nosync(irq);
117 irq_set_chip_and_handler(irq, &microdev_irq_type, handle_level_irq);
118 disable_microdev_irq(irq_get_irq_data(irq));
121 extern void __init init_microdev_irq(void)
123 int i;
125 /* disable interrupts on the FPGA INTC register */
126 __raw_writel(~0ul, MICRODEV_FPGA_INTDSB_REG);
128 for (i = 0; i < NUM_EXTERNAL_IRQS; i++)
129 make_microdev_irq(i);
132 extern void microdev_print_fpga_intc_status(void)
134 volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG;
135 volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG;
136 volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0);
137 volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8);
138 volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16);
139 volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24);
140 volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG;
141 volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG;
143 printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n");
144 printk("FPGA_INTENB = 0x%08x\n", *intenb);
145 printk("FPGA_INTDSB = 0x%08x\n", *intdsb);
146 printk("FPGA_INTSRC = 0x%08x\n", *intsrc);
147 printk("FPGA_INTREQ = 0x%08x\n", *intreq);
148 printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria);
149 printk("-------------------------------------------------------------------------------\n");