blob: 8b69bca05876f25e2af6c4225cf9334dfc7f41af [file] [log] [blame]
Ben Dooksd9b79fb2008-10-21 14:06:51 +01001/* arch/arm/plat-s3c64xx/irq.c
2 *
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
7 *
8 * S3C64XX - Interrupt handling
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>
Ben Dooks966bcc12008-12-12 00:24:32 +000017#include <linux/serial_core.h>
Ben Dooksf982dc52008-10-21 14:06:57 +010018#include <linux/irq.h>
Ben Dooksd9b79fb2008-10-21 14:06:51 +010019#include <linux/io.h>
20
21#include <asm/hardware/vic.h>
Ben Dooksd9b79fb2008-10-21 14:06:51 +010022
23#include <mach/map.h>
Ben Dooks7162ba02010-01-06 10:14:51 +090024#include <plat/irq-vic-timer.h>
Ben Dooks966bcc12008-12-12 00:24:32 +000025#include <plat/regs-serial.h>
Ben Dooksd9b79fb2008-10-21 14:06:51 +010026#include <plat/cpu.h>
27
Ben Dooks3e694d42008-10-21 14:07:05 +010028struct uart_irq {
29 void __iomem *regs;
30 unsigned int base_irq;
31 unsigned int parent_irq;
32};
33
34/* Note, we make use of the fact that the parent IRQs, IRQ_UART[0..3]
35 * are consecutive when looking up the interrupt in the demux routines.
36 */
37static struct uart_irq uart_irqs[] = {
38 [0] = {
39 .regs = S3C_VA_UART0,
40 .base_irq = IRQ_S3CUART_BASE0,
41 .parent_irq = IRQ_UART0,
42 },
43 [1] = {
44 .regs = S3C_VA_UART1,
45 .base_irq = IRQ_S3CUART_BASE1,
46 .parent_irq = IRQ_UART1,
47 },
48 [2] = {
49 .regs = S3C_VA_UART2,
50 .base_irq = IRQ_S3CUART_BASE2,
51 .parent_irq = IRQ_UART2,
52 },
53 [3] = {
54 .regs = S3C_VA_UART3,
55 .base_irq = IRQ_S3CUART_BASE3,
56 .parent_irq = IRQ_UART3,
57 },
58};
59
60static inline void __iomem *s3c_irq_uart_base(unsigned int irq)
61{
62 struct uart_irq *uirq = get_irq_chip_data(irq);
63 return uirq->regs;
64}
65
66static inline unsigned int s3c_irq_uart_bit(unsigned int irq)
67{
68 return irq & 3;
69}
70
71/* UART interrupt registers, not worth adding to seperate include header */
Ben Dooks3e694d42008-10-21 14:07:05 +010072
73static void s3c_irq_uart_mask(unsigned int irq)
74{
75 void __iomem *regs = s3c_irq_uart_base(irq);
76 unsigned int bit = s3c_irq_uart_bit(irq);
77 u32 reg;
78
79 reg = __raw_readl(regs + S3C64XX_UINTM);
80 reg |= (1 << bit);
81 __raw_writel(reg, regs + S3C64XX_UINTM);
82}
83
84static void s3c_irq_uart_maskack(unsigned int irq)
85{
86 void __iomem *regs = s3c_irq_uart_base(irq);
87 unsigned int bit = s3c_irq_uart_bit(irq);
88 u32 reg;
89
90 reg = __raw_readl(regs + S3C64XX_UINTM);
91 reg |= (1 << bit);
92 __raw_writel(reg, regs + S3C64XX_UINTM);
93 __raw_writel(1 << bit, regs + S3C64XX_UINTP);
94}
95
96static void s3c_irq_uart_unmask(unsigned int irq)
97{
98 void __iomem *regs = s3c_irq_uart_base(irq);
99 unsigned int bit = s3c_irq_uart_bit(irq);
100 u32 reg;
101
102 reg = __raw_readl(regs + S3C64XX_UINTM);
103 reg &= ~(1 << bit);
104 __raw_writel(reg, regs + S3C64XX_UINTM);
105}
106
107static void s3c_irq_uart_ack(unsigned int irq)
108{
109 void __iomem *regs = s3c_irq_uart_base(irq);
110 unsigned int bit = s3c_irq_uart_bit(irq);
111
112 __raw_writel(1 << bit, regs + S3C64XX_UINTP);
113}
114
115static void s3c_irq_demux_uart(unsigned int irq, struct irq_desc *desc)
116{
117 struct uart_irq *uirq = &uart_irqs[irq - IRQ_UART0];
118 u32 pend = __raw_readl(uirq->regs + S3C64XX_UINTP);
119 int base = uirq->base_irq;
120
121 if (pend & (1 << 0))
122 generic_handle_irq(base);
123 if (pend & (1 << 1))
124 generic_handle_irq(base + 1);
125 if (pend & (1 << 2))
126 generic_handle_irq(base + 2);
127 if (pend & (1 << 3))
128 generic_handle_irq(base + 3);
129}
130
131static struct irq_chip s3c_irq_uart = {
132 .name = "s3c-uart",
133 .mask = s3c_irq_uart_mask,
134 .unmask = s3c_irq_uart_unmask,
135 .mask_ack = s3c_irq_uart_maskack,
136 .ack = s3c_irq_uart_ack,
137};
138
139static void __init s3c64xx_uart_irq(struct uart_irq *uirq)
140{
Ben Dooksfdca9bf2009-02-27 11:29:23 +0000141 void __iomem *reg_base = uirq->regs;
Ben Dooks3e694d42008-10-21 14:07:05 +0100142 unsigned int irq;
143 int offs;
144
145 /* mask all interrupts at the start. */
146 __raw_writel(0xf, reg_base + S3C64XX_UINTM);
147
148 for (offs = 0; offs < 3; offs++) {
149 irq = uirq->base_irq + offs;
150
151 set_irq_chip(irq, &s3c_irq_uart);
152 set_irq_chip_data(irq, uirq);
153 set_irq_handler(irq, handle_level_irq);
154 set_irq_flags(irq, IRQF_VALID);
155 }
156
157 set_irq_chained_handler(uirq->parent_irq, s3c_irq_demux_uart);
158}
159
Ben Dooksd9b79fb2008-10-21 14:06:51 +0100160void __init s3c64xx_init_irq(u32 vic0_valid, u32 vic1_valid)
161{
Ben Dooks7162ba02010-01-06 10:14:51 +0900162 int uart;
Ben Dooksf982dc52008-10-21 14:06:57 +0100163
Ben Dooks39669f52008-10-21 14:07:12 +0100164 printk(KERN_DEBUG "%s: initialising interrupts\n", __func__);
Ben Dooksd9b79fb2008-10-21 14:06:51 +0100165
166 /* initialise the pair of VICs */
Ben Dooksc07f87f2009-03-24 15:30:07 +0000167 vic_init(S3C_VA_VIC0, S3C_VIC0_BASE, vic0_valid, 0);
168 vic_init(S3C_VA_VIC1, S3C_VIC1_BASE, vic1_valid, 0);
Ben Dooksf982dc52008-10-21 14:06:57 +0100169
170 /* add the timer sub-irqs */
171
Ben Dooks7162ba02010-01-06 10:14:51 +0900172 s3c_init_vic_timer_irq(IRQ_TIMER0_VIC, IRQ_TIMER0);
173 s3c_init_vic_timer_irq(IRQ_TIMER1_VIC, IRQ_TIMER1);
174 s3c_init_vic_timer_irq(IRQ_TIMER2_VIC, IRQ_TIMER2);
175 s3c_init_vic_timer_irq(IRQ_TIMER3_VIC, IRQ_TIMER3);
176 s3c_init_vic_timer_irq(IRQ_TIMER4_VIC, IRQ_TIMER4);
Ben Dooks3e694d42008-10-21 14:07:05 +0100177
178 for (uart = 0; uart < ARRAY_SIZE(uart_irqs); uart++)
179 s3c64xx_uart_irq(&uart_irqs[uart]);
Ben Dooksd9b79fb2008-10-21 14:06:51 +0100180}