blob: faa651602780b6570b1af0d079d08a9b409e651e [file] [log] [blame]
Kukjin Kim68ae8992012-04-15 21:40:33 -07001/*
Jongpill Lee0df04f82010-05-17 16:56:26 +09002 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
4 *
5 * S5P - IRQ EINT support
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#include <linux/kernel.h>
13#include <linux/interrupt.h>
14#include <linux/irq.h>
15#include <linux/io.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080016#include <linux/device.h>
Jongpill Lee0df04f82010-05-17 16:56:26 +090017#include <linux/gpio.h>
Rob Herring9e47b8b2013-01-07 09:45:59 -060018#include <linux/irqchip/arm-vic.h>
Jongpill Lee0df04f82010-05-17 16:56:26 +090019
20#include <plat/regs-irqtype.h>
21
22#include <mach/map.h>
23#include <plat/cpu.h>
24#include <plat/pm.h>
25
26#include <plat/gpio-cfg.h>
27#include <mach/regs-gpio.h>
28
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010029static inline void s5p_irq_eint_mask(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +090030{
31 u32 mask;
32
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010033 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
34 mask |= eint_irq_to_bit(data->irq);
35 __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +090036}
37
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010038static void s5p_irq_eint_unmask(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +090039{
40 u32 mask;
41
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010042 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
43 mask &= ~(eint_irq_to_bit(data->irq));
44 __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +090045}
46
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010047static inline void s5p_irq_eint_ack(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +090048{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010049 __raw_writel(eint_irq_to_bit(data->irq),
50 S5P_EINT_PEND(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +090051}
52
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010053static void s5p_irq_eint_maskack(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +090054{
55 /* compiler should in-line these */
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010056 s5p_irq_eint_mask(data);
57 s5p_irq_eint_ack(data);
Jongpill Lee0df04f82010-05-17 16:56:26 +090058}
59
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010060static int s5p_irq_eint_set_type(struct irq_data *data, unsigned int type)
Jongpill Lee0df04f82010-05-17 16:56:26 +090061{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010062 int offs = EINT_OFFSET(data->irq);
Jongpill Lee0df04f82010-05-17 16:56:26 +090063 int shift;
64 u32 ctrl, mask;
65 u32 newvalue = 0;
66
67 switch (type) {
68 case IRQ_TYPE_EDGE_RISING:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090069 newvalue = S5P_IRQ_TYPE_EDGE_RISING;
Jongpill Lee0df04f82010-05-17 16:56:26 +090070 break;
71
72 case IRQ_TYPE_EDGE_FALLING:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090073 newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
Jongpill Lee0df04f82010-05-17 16:56:26 +090074 break;
75
76 case IRQ_TYPE_EDGE_BOTH:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090077 newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
Jongpill Lee0df04f82010-05-17 16:56:26 +090078 break;
79
80 case IRQ_TYPE_LEVEL_LOW:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090081 newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
Jongpill Lee0df04f82010-05-17 16:56:26 +090082 break;
83
84 case IRQ_TYPE_LEVEL_HIGH:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090085 newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
Jongpill Lee0df04f82010-05-17 16:56:26 +090086 break;
87
88 default:
89 printk(KERN_ERR "No such irq type %d", type);
90 return -EINVAL;
91 }
92
93 shift = (offs & 0x7) * 4;
94 mask = 0x7 << shift;
95
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010096 ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +090097 ctrl &= ~mask;
98 ctrl |= newvalue << shift;
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010099 __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +0900100
101 if ((0 <= offs) && (offs < 8))
102 s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE);
103
104 else if ((8 <= offs) && (offs < 16))
105 s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE);
106
107 else if ((16 <= offs) && (offs < 24))
108 s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE);
109
110 else if ((24 <= offs) && (offs < 32))
111 s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE);
112
113 else
114 printk(KERN_ERR "No such irq number %d", offs);
115
116 return 0;
117}
118
119static struct irq_chip s5p_irq_eint = {
120 .name = "s5p-eint",
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100121 .irq_mask = s5p_irq_eint_mask,
122 .irq_unmask = s5p_irq_eint_unmask,
123 .irq_mask_ack = s5p_irq_eint_maskack,
124 .irq_ack = s5p_irq_eint_ack,
125 .irq_set_type = s5p_irq_eint_set_type,
Jongpill Lee0df04f82010-05-17 16:56:26 +0900126#ifdef CONFIG_PM
Mark Brownf5aeffb2010-12-02 14:35:38 +0900127 .irq_set_wake = s3c_irqext_wake,
Jongpill Lee0df04f82010-05-17 16:56:26 +0900128#endif
129};
130
131/* s5p_irq_demux_eint
132 *
133 * This function demuxes the IRQ from the group0 external interrupts,
134 * from EINTs 16 to 31. It is designed to be inlined into the specific
135 * handler s5p_irq_demux_eintX_Y.
136 *
137 * Each EINT pend/mask registers handle eight of them.
138 */
139static inline void s5p_irq_demux_eint(unsigned int start)
140{
Pannaga Bhushan5fae4052010-05-24 15:08:31 +0900141 u32 status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
Jongpill Lee0df04f82010-05-17 16:56:26 +0900142 u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
143 unsigned int irq;
144
Jongpill Lee0df04f82010-05-17 16:56:26 +0900145 status &= ~mask;
146 status &= 0xff;
147
148 while (status) {
Pannaga Bhushan5fae4052010-05-24 15:08:31 +0900149 irq = fls(status) - 1;
150 generic_handle_irq(irq + start);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900151 status &= ~(1 << irq);
152 }
153}
154
155static void s5p_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
156{
157 s5p_irq_demux_eint(IRQ_EINT(16));
158 s5p_irq_demux_eint(IRQ_EINT(24));
159}
160
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100161static inline void s5p_irq_vic_eint_mask(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900162{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100163 void __iomem *base = irq_data_get_irq_chip_data(data);
Pannaga Bhushan5fae4052010-05-24 15:08:31 +0900164
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100165 s5p_irq_eint_mask(data);
166 writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE_CLEAR);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900167}
168
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100169static void s5p_irq_vic_eint_unmask(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900170{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100171 void __iomem *base = irq_data_get_irq_chip_data(data);
Pannaga Bhushan5fae4052010-05-24 15:08:31 +0900172
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100173 s5p_irq_eint_unmask(data);
174 writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900175}
176
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100177static inline void s5p_irq_vic_eint_ack(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900178{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100179 __raw_writel(eint_irq_to_bit(data->irq),
180 S5P_EINT_PEND(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +0900181}
182
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100183static void s5p_irq_vic_eint_maskack(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900184{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100185 s5p_irq_vic_eint_mask(data);
186 s5p_irq_vic_eint_ack(data);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900187}
188
189static struct irq_chip s5p_irq_vic_eint = {
190 .name = "s5p_vic_eint",
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100191 .irq_mask = s5p_irq_vic_eint_mask,
192 .irq_unmask = s5p_irq_vic_eint_unmask,
193 .irq_mask_ack = s5p_irq_vic_eint_maskack,
194 .irq_ack = s5p_irq_vic_eint_ack,
195 .irq_set_type = s5p_irq_eint_set_type,
Jongpill Lee0df04f82010-05-17 16:56:26 +0900196#ifdef CONFIG_PM
Mark Brownf5aeffb2010-12-02 14:35:38 +0900197 .irq_set_wake = s3c_irqext_wake,
Jongpill Lee0df04f82010-05-17 16:56:26 +0900198#endif
199};
200
Kukjin Kim6d259a22012-01-21 12:00:13 +0900201static int __init s5p_init_irq_eint(void)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900202{
203 int irq;
204
205 for (irq = IRQ_EINT(0); irq <= IRQ_EINT(15); irq++)
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100206 irq_set_chip(irq, &s5p_irq_vic_eint);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900207
208 for (irq = IRQ_EINT(16); irq <= IRQ_EINT(31); irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100209 irq_set_chip_and_handler(irq, &s5p_irq_eint, handle_level_irq);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900210 set_irq_flags(irq, IRQF_VALID);
211 }
212
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100213 irq_set_chained_handler(IRQ_EINT16_31, s5p_irq_demux_eint16_31);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900214 return 0;
215}
216
217arch_initcall(s5p_init_irq_eint);