blob: ae233bdeb7e24bc0a759f493543b3bf07a727808 [file] [log] [blame]
Byungho Minc9b870e2009-06-23 21:40:03 +09001/* arch/arm/plat-s5pc1xx/irq.c
2 *
3 * Copyright 2009 Samsung Electronics Co.
4 * Byungho Min <bhmin@samsung.com>
5 *
6 * S5PC1XX - Interrupt handling
7 *
8 * Based on plat-s3c64xx/irq.c
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/kernel.h>
16#include <linux/interrupt.h>
17#include <linux/irq.h>
18#include <linux/io.h>
19
20#include <asm/hardware/vic.h>
21
22#include <mach/map.h>
Ben Dooks47101ec2010-01-07 14:41:38 +090023#include <plat/irq-vic-timer.h>
Byungho Minc9b870e2009-06-23 21:40:03 +090024#include <plat/cpu.h>
25
Byungho Minc9b870e2009-06-23 21:40:03 +090026struct uart_irq {
27 void __iomem *regs;
28 unsigned int base_irq;
29 unsigned int parent_irq;
30};
31
32/* Note, we make use of the fact that the parent IRQs, IRQ_UART[0..3]
33 * are consecutive when looking up the interrupt in the demux routines.
34 */
35static struct uart_irq uart_irqs[] = {
36 [0] = {
37 .regs = (void *)S3C_VA_UART0,
38 .base_irq = IRQ_S3CUART_BASE0,
39 .parent_irq = IRQ_UART0,
40 },
41 [1] = {
42 .regs = (void *)S3C_VA_UART1,
43 .base_irq = IRQ_S3CUART_BASE1,
44 .parent_irq = IRQ_UART1,
45 },
46 [2] = {
47 .regs = (void *)S3C_VA_UART2,
48 .base_irq = IRQ_S3CUART_BASE2,
49 .parent_irq = IRQ_UART2,
50 },
51 [3] = {
52 .regs = (void *)S3C_VA_UART3,
53 .base_irq = IRQ_S3CUART_BASE3,
54 .parent_irq = IRQ_UART3,
55 },
56};
57
58static inline void __iomem *s3c_irq_uart_base(unsigned int irq)
59{
60 struct uart_irq *uirq = get_irq_chip_data(irq);
61 return uirq->regs;
62}
63
64static inline unsigned int s3c_irq_uart_bit(unsigned int irq)
65{
66 return irq & 3;
67}
68
69/* UART interrupt registers, not worth adding to seperate include header */
70#define S3C64XX_UINTP 0x30
71#define S3C64XX_UINTSP 0x34
72#define S3C64XX_UINTM 0x38
73
74static void s3c_irq_uart_mask(unsigned int irq)
75{
76 void __iomem *regs = s3c_irq_uart_base(irq);
77 unsigned int bit = s3c_irq_uart_bit(irq);
78 u32 reg;
79
80 reg = __raw_readl(regs + S3C64XX_UINTM);
81 reg |= (1 << bit);
82 __raw_writel(reg, regs + S3C64XX_UINTM);
83}
84
85static void s3c_irq_uart_maskack(unsigned int irq)
86{
87 void __iomem *regs = s3c_irq_uart_base(irq);
88 unsigned int bit = s3c_irq_uart_bit(irq);
89 u32 reg;
90
91 reg = __raw_readl(regs + S3C64XX_UINTM);
92 reg |= (1 << bit);
93 __raw_writel(reg, regs + S3C64XX_UINTM);
94 __raw_writel(1 << bit, regs + S3C64XX_UINTP);
95}
96
97static void s3c_irq_uart_unmask(unsigned int irq)
98{
99 void __iomem *regs = s3c_irq_uart_base(irq);
100 unsigned int bit = s3c_irq_uart_bit(irq);
101 u32 reg;
102
103 reg = __raw_readl(regs + S3C64XX_UINTM);
104 reg &= ~(1 << bit);
105 __raw_writel(reg, regs + S3C64XX_UINTM);
106}
107
108static void s3c_irq_uart_ack(unsigned int irq)
109{
110 void __iomem *regs = s3c_irq_uart_base(irq);
111 unsigned int bit = s3c_irq_uart_bit(irq);
112
113 __raw_writel(1 << bit, regs + S3C64XX_UINTP);
114}
115
116static void s3c_irq_demux_uart(unsigned int irq, struct irq_desc *desc)
117{
118 struct uart_irq *uirq = &uart_irqs[irq - IRQ_UART0];
119 u32 pend = __raw_readl(uirq->regs + S3C64XX_UINTP);
120 int base = uirq->base_irq;
121
122 if (pend & (1 << 0))
123 generic_handle_irq(base);
124 if (pend & (1 << 1))
125 generic_handle_irq(base + 1);
126 if (pend & (1 << 2))
127 generic_handle_irq(base + 2);
128 if (pend & (1 << 3))
129 generic_handle_irq(base + 3);
130}
131
132static struct irq_chip s3c_irq_uart = {
133 .name = "s3c-uart",
134 .mask = s3c_irq_uart_mask,
135 .unmask = s3c_irq_uart_unmask,
136 .mask_ack = s3c_irq_uart_maskack,
137 .ack = s3c_irq_uart_ack,
138};
139
140static void __init s5pc1xx_uart_irq(struct uart_irq *uirq)
141{
142 void __iomem *reg_base = uirq->regs;
143 unsigned int irq;
144 int offs;
145
146 /* mask all interrupts at the start. */
147 __raw_writel(0xf, reg_base + S3C64XX_UINTM);
148
149 for (offs = 0; offs < 3; offs++) {
150 irq = uirq->base_irq + offs;
151
152 set_irq_chip(irq, &s3c_irq_uart);
153 set_irq_chip_data(irq, uirq);
154 set_irq_handler(irq, handle_level_irq);
155 set_irq_flags(irq, IRQF_VALID);
156 }
157
158 set_irq_chained_handler(uirq->parent_irq, s3c_irq_demux_uart);
159}
160
161void __init s5pc1xx_init_irq(u32 *vic_valid, int num)
162{
163 int i;
Ben Dooks47101ec2010-01-07 14:41:38 +0900164 int uart;
Byungho Minc9b870e2009-06-23 21:40:03 +0900165
166 printk(KERN_DEBUG "%s: initialising interrupts\n", __func__);
167
168 /* initialise the pair of VICs */
169 for (i = 0; i < num; i++)
170 vic_init((void *)S5PC1XX_VA_VIC(i), S3C_IRQ(i * S3C_IRQ_OFFSET),
171 vic_valid[i], 0);
172
173 /* add the timer sub-irqs */
174
Ben Dooks47101ec2010-01-07 14:41:38 +0900175 s3c_init_vic_timer_irq(IRQ_TIMER0_VIC, IRQ_TIMER0);
176 s3c_init_vic_timer_irq(IRQ_TIMER1_VIC, IRQ_TIMER1);
177 s3c_init_vic_timer_irq(IRQ_TIMER2_VIC, IRQ_TIMER2);
178 s3c_init_vic_timer_irq(IRQ_TIMER3_VIC, IRQ_TIMER3);
179 s3c_init_vic_timer_irq(IRQ_TIMER4_VIC, IRQ_TIMER4);
Byungho Minc9b870e2009-06-23 21:40:03 +0900180
181 for (uart = 0; uart < ARRAY_SIZE(uart_irqs); uart++)
182 s5pc1xx_uart_irq(&uart_irqs[uart]);
183}
184
185