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