Ben Dooks | d9b79fb | 2008-10-21 14:06:51 +0100 | [diff] [blame] | 1 | /* 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 Dooks | 966bcc1 | 2008-12-12 00:24:32 +0000 | [diff] [blame] | 17 | #include <linux/serial_core.h> |
Ben Dooks | f982dc5 | 2008-10-21 14:06:57 +0100 | [diff] [blame] | 18 | #include <linux/irq.h> |
Ben Dooks | d9b79fb | 2008-10-21 14:06:51 +0100 | [diff] [blame] | 19 | #include <linux/io.h> |
| 20 | |
| 21 | #include <asm/hardware/vic.h> |
Ben Dooks | d9b79fb | 2008-10-21 14:06:51 +0100 | [diff] [blame] | 22 | |
| 23 | #include <mach/map.h> |
Ben Dooks | 7162ba0 | 2010-01-06 10:14:51 +0900 | [diff] [blame^] | 24 | #include <plat/irq-vic-timer.h> |
Ben Dooks | 966bcc1 | 2008-12-12 00:24:32 +0000 | [diff] [blame] | 25 | #include <plat/regs-serial.h> |
Ben Dooks | d9b79fb | 2008-10-21 14:06:51 +0100 | [diff] [blame] | 26 | #include <plat/cpu.h> |
| 27 | |
Ben Dooks | 3e694d4 | 2008-10-21 14:07:05 +0100 | [diff] [blame] | 28 | struct 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 | */ |
| 37 | static 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 | |
| 60 | static 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 | |
| 66 | static 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 Dooks | 3e694d4 | 2008-10-21 14:07:05 +0100 | [diff] [blame] | 72 | |
| 73 | static 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 | |
| 84 | static 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 | |
| 96 | static 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 | |
| 107 | static 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 | |
| 115 | static 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 | |
| 131 | static 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 | |
| 139 | static void __init s3c64xx_uart_irq(struct uart_irq *uirq) |
| 140 | { |
Ben Dooks | fdca9bf | 2009-02-27 11:29:23 +0000 | [diff] [blame] | 141 | void __iomem *reg_base = uirq->regs; |
Ben Dooks | 3e694d4 | 2008-10-21 14:07:05 +0100 | [diff] [blame] | 142 | 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 Dooks | d9b79fb | 2008-10-21 14:06:51 +0100 | [diff] [blame] | 160 | void __init s3c64xx_init_irq(u32 vic0_valid, u32 vic1_valid) |
| 161 | { |
Ben Dooks | 7162ba0 | 2010-01-06 10:14:51 +0900 | [diff] [blame^] | 162 | int uart; |
Ben Dooks | f982dc5 | 2008-10-21 14:06:57 +0100 | [diff] [blame] | 163 | |
Ben Dooks | 39669f5 | 2008-10-21 14:07:12 +0100 | [diff] [blame] | 164 | printk(KERN_DEBUG "%s: initialising interrupts\n", __func__); |
Ben Dooks | d9b79fb | 2008-10-21 14:06:51 +0100 | [diff] [blame] | 165 | |
| 166 | /* initialise the pair of VICs */ |
Ben Dooks | c07f87f | 2009-03-24 15:30:07 +0000 | [diff] [blame] | 167 | vic_init(S3C_VA_VIC0, S3C_VIC0_BASE, vic0_valid, 0); |
| 168 | vic_init(S3C_VA_VIC1, S3C_VIC1_BASE, vic1_valid, 0); |
Ben Dooks | f982dc5 | 2008-10-21 14:06:57 +0100 | [diff] [blame] | 169 | |
| 170 | /* add the timer sub-irqs */ |
| 171 | |
Ben Dooks | 7162ba0 | 2010-01-06 10:14:51 +0900 | [diff] [blame^] | 172 | 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 Dooks | 3e694d4 | 2008-10-21 14:07:05 +0100 | [diff] [blame] | 177 | |
| 178 | for (uart = 0; uart < ARRAY_SIZE(uart_irqs); uart++) |
| 179 | s3c64xx_uart_irq(&uart_irqs[uart]); |
Ben Dooks | d9b79fb | 2008-10-21 14:06:51 +0100 | [diff] [blame] | 180 | } |