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