xref: /openbmc/linux/arch/sh/boards/mach-r2d/irq.c (revision f7018c21)
1 /*
2  * linux/arch/sh/boards/renesas/rts7751r2d/irq.c
3  *
4  * Copyright (C) 2007  Magnus Damm
5  * Copyright (C) 2000  Kazumoto Kojima
6  *
7  * Renesas Technology Sales RTS7751R2D Support, R2D-PLUS and R2D-1.
8  *
9  * Modified for RTS7751R2D by
10  * Atom Create Engineering Co., Ltd. 2002.
11  */
12 #include <linux/init.h>
13 #include <linux/irq.h>
14 #include <linux/interrupt.h>
15 #include <linux/io.h>
16 #include <mach/r2d.h>
17 
18 #define R2D_NR_IRL 13
19 
20 enum {
21 	UNUSED = 0,
22 
23 	/* board specific interrupt sources (R2D-1 and R2D-PLUS) */
24 	EXT,              /* EXT_INT0-3 */
25 	RTC_T, RTC_A,     /* Real Time Clock */
26 	AX88796,          /* Ethernet controller (R2D-1 board) */
27 	KEY,              /* Key input (R2D-PLUS board) */
28 	SDCARD,           /* SD Card */
29 	CF_CD, CF_IDE,    /* CF Card Detect + CF IDE */
30 	SM501,            /* SM501 aka Voyager */
31 	PCI_INTD_RTL8139, /* Ethernet controller */
32 	PCI_INTC_PCI1520, /* Cardbus/PCMCIA bridge */
33 	PCI_INTB_RTL8139, /* Ethernet controller with HUB (R2D-PLUS board) */
34 	PCI_INTB_SLOT,    /* PCI Slot 3.3v (R2D-1 board) */
35 	PCI_INTA_SLOT,    /* PCI Slot 3.3v */
36 	TP,               /* Touch Panel */
37 };
38 
39 #ifdef CONFIG_RTS7751R2D_1
40 
41 /* Vectors for R2D-1 */
42 static struct intc_vect vectors_r2d_1[] __initdata = {
43 	INTC_IRQ(EXT, IRQ_EXT),
44 	INTC_IRQ(RTC_T, IRQ_RTC_T), INTC_IRQ(RTC_A, IRQ_RTC_A),
45 	INTC_IRQ(AX88796, IRQ_AX88796), INTC_IRQ(SDCARD, IRQ_SDCARD),
46 	INTC_IRQ(CF_CD, IRQ_CF_CD), INTC_IRQ(CF_IDE, IRQ_CF_IDE), /* ng */
47 	INTC_IRQ(SM501, IRQ_VOYAGER),
48 	INTC_IRQ(PCI_INTD_RTL8139, IRQ_PCI_INTD),
49 	INTC_IRQ(PCI_INTC_PCI1520, IRQ_PCI_INTC),
50 	INTC_IRQ(PCI_INTB_SLOT, IRQ_PCI_INTB),
51 	INTC_IRQ(PCI_INTA_SLOT, IRQ_PCI_INTA),
52 	INTC_IRQ(TP, IRQ_TP),
53 };
54 
55 /* IRLMSK mask register layout for R2D-1 */
56 static struct intc_mask_reg mask_registers_r2d_1[] __initdata = {
57 	{ 0xa4000000, 0, 16, /* IRLMSK */
58 	  { TP, PCI_INTA_SLOT, PCI_INTB_SLOT,
59 	    PCI_INTC_PCI1520, PCI_INTD_RTL8139,
60 	    SM501, CF_IDE, CF_CD, SDCARD, AX88796,
61 	    RTC_A, RTC_T, 0, 0, 0, EXT } },
62 };
63 
64 /* IRLn to IRQ table for R2D-1 */
65 static unsigned char irl2irq_r2d_1[R2D_NR_IRL] __initdata = {
66 	IRQ_PCI_INTD, IRQ_CF_IDE, IRQ_CF_CD, IRQ_PCI_INTC,
67 	IRQ_VOYAGER, IRQ_AX88796, IRQ_RTC_A, IRQ_RTC_T,
68 	IRQ_SDCARD, IRQ_PCI_INTA, IRQ_PCI_INTB, IRQ_EXT,
69 	IRQ_TP,
70 };
71 
72 static DECLARE_INTC_DESC(intc_desc_r2d_1, "r2d-1", vectors_r2d_1,
73 			 NULL, mask_registers_r2d_1, NULL, NULL);
74 
75 #endif /* CONFIG_RTS7751R2D_1 */
76 
77 #ifdef CONFIG_RTS7751R2D_PLUS
78 
79 /* Vectors for R2D-PLUS */
80 static struct intc_vect vectors_r2d_plus[] __initdata = {
81 	INTC_IRQ(EXT, IRQ_EXT),
82 	INTC_IRQ(RTC_T, IRQ_RTC_T), INTC_IRQ(RTC_A, IRQ_RTC_A),
83 	INTC_IRQ(KEY, IRQ_KEY), INTC_IRQ(SDCARD, IRQ_SDCARD),
84 	INTC_IRQ(CF_CD, IRQ_CF_CD), INTC_IRQ(CF_IDE, IRQ_CF_IDE),
85 	INTC_IRQ(SM501, IRQ_VOYAGER),
86 	INTC_IRQ(PCI_INTD_RTL8139, IRQ_PCI_INTD),
87 	INTC_IRQ(PCI_INTC_PCI1520, IRQ_PCI_INTC),
88 	INTC_IRQ(PCI_INTB_RTL8139, IRQ_PCI_INTB),
89 	INTC_IRQ(PCI_INTA_SLOT, IRQ_PCI_INTA),
90 	INTC_IRQ(TP, IRQ_TP),
91 };
92 
93 /* IRLMSK mask register layout for R2D-PLUS */
94 static struct intc_mask_reg mask_registers_r2d_plus[] __initdata = {
95 	{ 0xa4000000, 0, 16, /* IRLMSK */
96 	  { TP, PCI_INTA_SLOT, PCI_INTB_RTL8139,
97 	    PCI_INTC_PCI1520, PCI_INTD_RTL8139,
98 	    SM501, CF_IDE, CF_CD, SDCARD, KEY,
99 	    RTC_A, RTC_T, 0, 0, 0, EXT } },
100 };
101 
102 /* IRLn to IRQ table for R2D-PLUS */
103 static unsigned char irl2irq_r2d_plus[R2D_NR_IRL] __initdata = {
104 	IRQ_PCI_INTD, IRQ_CF_IDE, IRQ_CF_CD, IRQ_PCI_INTC,
105 	IRQ_VOYAGER, IRQ_KEY, IRQ_RTC_A, IRQ_RTC_T,
106 	IRQ_SDCARD, IRQ_PCI_INTA, IRQ_PCI_INTB, IRQ_EXT,
107 	IRQ_TP,
108 };
109 
110 static DECLARE_INTC_DESC(intc_desc_r2d_plus, "r2d-plus", vectors_r2d_plus,
111 			 NULL, mask_registers_r2d_plus, NULL, NULL);
112 
113 #endif /* CONFIG_RTS7751R2D_PLUS */
114 
115 static unsigned char irl2irq[R2D_NR_IRL];
116 
117 int rts7751r2d_irq_demux(int irq)
118 {
119 	if (irq >= R2D_NR_IRL || irq < 0 || !irl2irq[irq])
120 		return irq;
121 
122 	return irl2irq[irq];
123 }
124 
125 /*
126  * Initialize IRQ setting
127  */
128 void __init init_rts7751r2d_IRQ(void)
129 {
130 	struct intc_desc *d;
131 
132 	switch (__raw_readw(PA_VERREG) & 0xf0) {
133 #ifdef CONFIG_RTS7751R2D_PLUS
134 	case 0x10:
135 		printk(KERN_INFO "Using R2D-PLUS interrupt controller.\n");
136 		d = &intc_desc_r2d_plus;
137 		memcpy(irl2irq, irl2irq_r2d_plus, R2D_NR_IRL);
138 		break;
139 #endif
140 #ifdef CONFIG_RTS7751R2D_1
141 	case 0x00: /* according to manual */
142 	case 0x30: /* in reality */
143 		printk(KERN_INFO "Using R2D-1 interrupt controller.\n");
144 		d = &intc_desc_r2d_1;
145 		memcpy(irl2irq, irl2irq_r2d_1, R2D_NR_IRL);
146 		break;
147 #endif
148 	default:
149 		printk(KERN_INFO "Unknown R2D interrupt controller 0x%04x\n",
150 		       __raw_readw(PA_VERREG));
151 		return;
152 	}
153 
154 	register_intc_controller(d);
155 }
156