blob: 33bd3f3d20f5b9b00b95cc17777309fd4aa585e1 [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>
18
19#include <asm/hardware/vic.h>
20
21#include <plat/regs-irqtype.h>
22
23#include <mach/map.h>
24#include <plat/cpu.h>
25#include <plat/pm.h>
26
27#include <plat/gpio-cfg.h>
28#include <mach/regs-gpio.h>
29
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010030static inline void s5p_irq_eint_mask(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +090031{
32 u32 mask;
33
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010034 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
35 mask |= eint_irq_to_bit(data->irq);
36 __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +090037}
38
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010039static void s5p_irq_eint_unmask(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +090040{
41 u32 mask;
42
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010043 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
44 mask &= ~(eint_irq_to_bit(data->irq));
45 __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +090046}
47
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010048static inline void s5p_irq_eint_ack(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +090049{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010050 __raw_writel(eint_irq_to_bit(data->irq),
51 S5P_EINT_PEND(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +090052}
53
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010054static void s5p_irq_eint_maskack(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +090055{
56 /* compiler should in-line these */
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010057 s5p_irq_eint_mask(data);
58 s5p_irq_eint_ack(data);
Jongpill Lee0df04f82010-05-17 16:56:26 +090059}
60
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010061static int s5p_irq_eint_set_type(struct irq_data *data, unsigned int type)
Jongpill Lee0df04f82010-05-17 16:56:26 +090062{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010063 int offs = EINT_OFFSET(data->irq);
Jongpill Lee0df04f82010-05-17 16:56:26 +090064 int shift;
65 u32 ctrl, mask;
66 u32 newvalue = 0;
67
68 switch (type) {
69 case IRQ_TYPE_EDGE_RISING:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090070 newvalue = S5P_IRQ_TYPE_EDGE_RISING;
Jongpill Lee0df04f82010-05-17 16:56:26 +090071 break;
72
73 case IRQ_TYPE_EDGE_FALLING:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090074 newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
Jongpill Lee0df04f82010-05-17 16:56:26 +090075 break;
76
77 case IRQ_TYPE_EDGE_BOTH:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090078 newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
Jongpill Lee0df04f82010-05-17 16:56:26 +090079 break;
80
81 case IRQ_TYPE_LEVEL_LOW:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090082 newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
Jongpill Lee0df04f82010-05-17 16:56:26 +090083 break;
84
85 case IRQ_TYPE_LEVEL_HIGH:
Marek Szyprowski9adf5d22010-10-02 11:48:09 +090086 newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
Jongpill Lee0df04f82010-05-17 16:56:26 +090087 break;
88
89 default:
90 printk(KERN_ERR "No such irq type %d", type);
91 return -EINVAL;
92 }
93
94 shift = (offs & 0x7) * 4;
95 mask = 0x7 << shift;
96
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +010097 ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +090098 ctrl &= ~mask;
99 ctrl |= newvalue << shift;
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100100 __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +0900101
102 if ((0 <= offs) && (offs < 8))
103 s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE);
104
105 else if ((8 <= offs) && (offs < 16))
106 s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE);
107
108 else if ((16 <= offs) && (offs < 24))
109 s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE);
110
111 else if ((24 <= offs) && (offs < 32))
112 s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE);
113
114 else
115 printk(KERN_ERR "No such irq number %d", offs);
116
117 return 0;
118}
119
120static struct irq_chip s5p_irq_eint = {
121 .name = "s5p-eint",
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100122 .irq_mask = s5p_irq_eint_mask,
123 .irq_unmask = s5p_irq_eint_unmask,
124 .irq_mask_ack = s5p_irq_eint_maskack,
125 .irq_ack = s5p_irq_eint_ack,
126 .irq_set_type = s5p_irq_eint_set_type,
Jongpill Lee0df04f82010-05-17 16:56:26 +0900127#ifdef CONFIG_PM
Mark Brownf5aeffb2010-12-02 14:35:38 +0900128 .irq_set_wake = s3c_irqext_wake,
Jongpill Lee0df04f82010-05-17 16:56:26 +0900129#endif
130};
131
132/* s5p_irq_demux_eint
133 *
134 * This function demuxes the IRQ from the group0 external interrupts,
135 * from EINTs 16 to 31. It is designed to be inlined into the specific
136 * handler s5p_irq_demux_eintX_Y.
137 *
138 * Each EINT pend/mask registers handle eight of them.
139 */
140static inline void s5p_irq_demux_eint(unsigned int start)
141{
Pannaga Bhushan5fae4052010-05-24 15:08:31 +0900142 u32 status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
Jongpill Lee0df04f82010-05-17 16:56:26 +0900143 u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
144 unsigned int irq;
145
Jongpill Lee0df04f82010-05-17 16:56:26 +0900146 status &= ~mask;
147 status &= 0xff;
148
149 while (status) {
Pannaga Bhushan5fae4052010-05-24 15:08:31 +0900150 irq = fls(status) - 1;
151 generic_handle_irq(irq + start);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900152 status &= ~(1 << irq);
153 }
154}
155
156static void s5p_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
157{
158 s5p_irq_demux_eint(IRQ_EINT(16));
159 s5p_irq_demux_eint(IRQ_EINT(24));
160}
161
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100162static inline void s5p_irq_vic_eint_mask(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900163{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100164 void __iomem *base = irq_data_get_irq_chip_data(data);
Pannaga Bhushan5fae4052010-05-24 15:08:31 +0900165
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100166 s5p_irq_eint_mask(data);
167 writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE_CLEAR);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900168}
169
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100170static void s5p_irq_vic_eint_unmask(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900171{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100172 void __iomem *base = irq_data_get_irq_chip_data(data);
Pannaga Bhushan5fae4052010-05-24 15:08:31 +0900173
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100174 s5p_irq_eint_unmask(data);
175 writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900176}
177
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100178static inline void s5p_irq_vic_eint_ack(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900179{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100180 __raw_writel(eint_irq_to_bit(data->irq),
181 S5P_EINT_PEND(EINT_REG_NR(data->irq)));
Jongpill Lee0df04f82010-05-17 16:56:26 +0900182}
183
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100184static void s5p_irq_vic_eint_maskack(struct irq_data *data)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900185{
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100186 s5p_irq_vic_eint_mask(data);
187 s5p_irq_vic_eint_ack(data);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900188}
189
190static struct irq_chip s5p_irq_vic_eint = {
191 .name = "s5p_vic_eint",
Lennert Buytenhekbb0b2372010-12-14 22:55:26 +0100192 .irq_mask = s5p_irq_vic_eint_mask,
193 .irq_unmask = s5p_irq_vic_eint_unmask,
194 .irq_mask_ack = s5p_irq_vic_eint_maskack,
195 .irq_ack = s5p_irq_vic_eint_ack,
196 .irq_set_type = s5p_irq_eint_set_type,
Jongpill Lee0df04f82010-05-17 16:56:26 +0900197#ifdef CONFIG_PM
Mark Brownf5aeffb2010-12-02 14:35:38 +0900198 .irq_set_wake = s3c_irqext_wake,
Jongpill Lee0df04f82010-05-17 16:56:26 +0900199#endif
200};
201
Kukjin Kim6d259a22012-01-21 12:00:13 +0900202static int __init s5p_init_irq_eint(void)
Jongpill Lee0df04f82010-05-17 16:56:26 +0900203{
204 int irq;
205
206 for (irq = IRQ_EINT(0); irq <= IRQ_EINT(15); irq++)
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100207 irq_set_chip(irq, &s5p_irq_vic_eint);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900208
209 for (irq = IRQ_EINT(16); irq <= IRQ_EINT(31); irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100210 irq_set_chip_and_handler(irq, &s5p_irq_eint, handle_level_irq);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900211 set_irq_flags(irq, IRQF_VALID);
212 }
213
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100214 irq_set_chained_handler(IRQ_EINT16_31, s5p_irq_demux_eint16_31);
Jongpill Lee0df04f82010-05-17 16:56:26 +0900215 return 0;
216}
217
218arch_initcall(s5p_init_irq_eint);