blob: 9a8aff3396197ca097d0a3d34c61c71da31401b4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/boards/superh/microdev/irq.c
3 *
4 * Copyright (C) 2003 Sean McGoogan (Sean.McGoogan@superh.com)
5 *
6 * SuperH SH4-202 MicroDev board support.
7 *
8 * May be copied or modified under the terms of the GNU General Public
9 * License. See linux/COPYING for more information.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13#include <linux/irq.h>
Paul Mundt8b19a7c2007-06-04 10:50:42 +090014#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/io.h>
Paul Mundt7639a452008-10-20 13:02:48 +090016#include <mach/microdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#define NUM_EXTERNAL_IRQS 16 /* IRL0 .. IRL15 */
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020static const struct {
21 unsigned char fpgaIrq;
22 unsigned char mapped;
23 const char *name;
24} fpgaIrqTable[NUM_EXTERNAL_IRQS] = {
25 { 0, 0, "unused" }, /* IRQ #0 IRL=15 0x200 */
26 { MICRODEV_FPGA_IRQ_KEYBOARD, 1, "keyboard" }, /* IRQ #1 IRL=14 0x220 */
27 { MICRODEV_FPGA_IRQ_SERIAL1, 1, "Serial #1"}, /* IRQ #2 IRL=13 0x240 */
28 { MICRODEV_FPGA_IRQ_ETHERNET, 1, "Ethernet" }, /* IRQ #3 IRL=12 0x260 */
29 { MICRODEV_FPGA_IRQ_SERIAL2, 0, "Serial #2"}, /* IRQ #4 IRL=11 0x280 */
30 { 0, 0, "unused" }, /* IRQ #5 IRL=10 0x2a0 */
31 { 0, 0, "unused" }, /* IRQ #6 IRL=9 0x2c0 */
32 { MICRODEV_FPGA_IRQ_USB_HC, 1, "USB" }, /* IRQ #7 IRL=8 0x2e0 */
33 { MICRODEV_IRQ_PCI_INTA, 1, "PCI INTA" }, /* IRQ #8 IRL=7 0x300 */
34 { MICRODEV_IRQ_PCI_INTB, 1, "PCI INTB" }, /* IRQ #9 IRL=6 0x320 */
35 { MICRODEV_IRQ_PCI_INTC, 1, "PCI INTC" }, /* IRQ #10 IRL=5 0x340 */
36 { MICRODEV_IRQ_PCI_INTD, 1, "PCI INTD" }, /* IRQ #11 IRL=4 0x360 */
37 { MICRODEV_FPGA_IRQ_MOUSE, 1, "mouse" }, /* IRQ #12 IRL=3 0x380 */
38 { MICRODEV_FPGA_IRQ_IDE2, 1, "IDE #2" }, /* IRQ #13 IRL=2 0x3a0 */
39 { MICRODEV_FPGA_IRQ_IDE1, 1, "IDE #1" }, /* IRQ #14 IRL=1 0x3c0 */
40 { 0, 0, "unused" }, /* IRQ #15 IRL=0 0x3e0 */
41};
42
43#if (MICRODEV_LINUX_IRQ_KEYBOARD != 1)
44# error Inconsistancy in defining the IRQ# for Keyboard!
45#endif
46
47#if (MICRODEV_LINUX_IRQ_ETHERNET != 3)
48# error Inconsistancy in defining the IRQ# for Ethernet!
49#endif
50
51#if (MICRODEV_LINUX_IRQ_USB_HC != 7)
52# error Inconsistancy in defining the IRQ# for USB!
53#endif
54
55#if (MICRODEV_LINUX_IRQ_MOUSE != 12)
56# error Inconsistancy in defining the IRQ# for PS/2 Mouse!
57#endif
58
59#if (MICRODEV_LINUX_IRQ_IDE2 != 13)
60# error Inconsistancy in defining the IRQ# for secondary IDE!
61#endif
62
63#if (MICRODEV_LINUX_IRQ_IDE1 != 14)
64# error Inconsistancy in defining the IRQ# for primary IDE!
65#endif
66
Paul Mundtd6138832010-10-27 14:54:10 +090067static void disable_microdev_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Paul Mundtd6138832010-10-27 14:54:10 +090069 unsigned int irq = data->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 unsigned int fpgaIrq;
71
Paul Mundt8599cf02006-09-27 18:03:34 +090072 if (irq >= NUM_EXTERNAL_IRQS)
73 return;
74 if (!fpgaIrqTable[irq].mapped)
75 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
78
Simon Arlotte868d612007-05-14 08:15:10 +090079 /* disable interrupts on the FPGA INTC register */
Paul Mundt9d56dd32010-01-26 12:58:40 +090080 __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Paul Mundtd6138832010-10-27 14:54:10 +090083static void enable_microdev_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Paul Mundtd6138832010-10-27 14:54:10 +090085 unsigned int irq = data->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned long priorityReg, priorities, pri;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 unsigned int fpgaIrq;
88
Paul Mundt8599cf02006-09-27 18:03:34 +090089 if (unlikely(irq >= NUM_EXTERNAL_IRQS))
90 return;
91 if (unlikely(!fpgaIrqTable[irq].mapped))
92 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 pri = 15 - irq;
95
96 fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
97 priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq);
98
Paul Mundt8599cf02006-09-27 18:03:34 +090099 /* set priority for the interrupt */
Paul Mundt9d56dd32010-01-26 12:58:40 +0900100 priorities = __raw_readl(priorityReg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq);
102 priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri);
Paul Mundt9d56dd32010-01-26 12:58:40 +0900103 __raw_writel(priorities, priorityReg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Simon Arlotte868d612007-05-14 08:15:10 +0900105 /* enable interrupts on the FPGA INTC register */
Paul Mundt9d56dd32010-01-26 12:58:40 +0900106 __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
Paul Mundtd6138832010-10-27 14:54:10 +0900109static struct irq_chip microdev_irq_type = {
110 .name = "MicroDev-IRQ",
111 .irq_unmask = enable_microdev_irq,
112 .irq_mask = disable_microdev_irq,
113};
114
Matt Flemingbe729fd2008-12-14 12:02:24 +0000115/* This function sets the desired irq handler to be a MicroDev type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static void __init make_microdev_irq(unsigned int irq)
117{
118 disable_irq_nosync(irq);
Thomas Gleixnerfcb89182011-03-24 16:31:17 +0100119 irq_set_chip_and_handler(irq, &microdev_irq_type, handle_level_irq);
Paul Mundtd6138832010-10-27 14:54:10 +0900120 disable_microdev_irq(irq_get_irq_data(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123extern void __init init_microdev_irq(void)
124{
125 int i;
126
Matt Flemingbe729fd2008-12-14 12:02:24 +0000127 /* disable interrupts on the FPGA INTC register */
Paul Mundt9d56dd32010-01-26 12:58:40 +0900128 __raw_writel(~0ul, MICRODEV_FPGA_INTDSB_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 for (i = 0; i < NUM_EXTERNAL_IRQS; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 make_microdev_irq(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134extern void microdev_print_fpga_intc_status(void)
135{
136 volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG;
137 volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG;
138 volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0);
139 volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8);
140 volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16);
141 volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24);
142 volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG;
143 volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG;
144
145 printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n");
146 printk("FPGA_INTENB = 0x%08x\n", *intenb);
147 printk("FPGA_INTDSB = 0x%08x\n", *intdsb);
148 printk("FPGA_INTSRC = 0x%08x\n", *intsrc);
149 printk("FPGA_INTREQ = 0x%08x\n", *intreq);
150 printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria);
151 printk("-------------------------------------------------------------------------------\n");
152}