arm: Move the set_handle_irq and handle_arch_irq declarations to asm/irq.h
[deliverable/linux.git] / arch / arm / plat-samsung / s5p-irq-gpioint.c
CommitLineData
68ae8998 1/*
170a4617
MS
2 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
3 * Author: Kyungmin Park <kyungmin.park@samsung.com>
4 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
5 * Author: Marek Szyprowski <m.szyprowski@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/interrupt.h>
16#include <linux/irq.h>
17#include <linux/io.h>
18#include <linux/gpio.h>
a43efddc 19#include <linux/slab.h>
170a4617
MS
20
21#include <mach/map.h>
22#include <plat/gpio-core.h>
23#include <plat/gpio-cfg.h>
24
3f6065dd
MS
25#include <asm/mach/irq.h>
26
5fa1a2e1 27#define GPIO_BASE(chip) ((void __iomem *)((unsigned long)((chip)->base) & 0xFFFFF000u))
170a4617 28
2de09262
MS
29#define CON_OFFSET 0x700
30#define MASK_OFFSET 0x900
31#define PEND_OFFSET 0xA00
32#define REG_OFFSET(x) ((x) << 2)
170a4617 33
a43efddc
MS
34struct s5p_gpioint_bank {
35 struct list_head list;
36 int start;
37 int nr_groups;
38 int irq;
782d8a3c 39 struct samsung_gpio_chip **chips;
a43efddc
MS
40 void (*handler)(unsigned int, struct irq_desc *);
41};
42
6d259a25 43static LIST_HEAD(banks);
170a4617 44
ad739dcf 45static int s5p_gpioint_set_type(struct irq_data *d, unsigned int type)
170a4617 46{
ad739dcf
TG
47 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
48 struct irq_chip_type *ct = gc->chip_types;
49 unsigned int shift = (d->irq - gc->irq_base) << 2;
170a4617
MS
50
51 switch (type) {
52 case IRQ_TYPE_EDGE_RISING:
9adf5d22 53 type = S5P_IRQ_TYPE_EDGE_RISING;
170a4617
MS
54 break;
55 case IRQ_TYPE_EDGE_FALLING:
9adf5d22 56 type = S5P_IRQ_TYPE_EDGE_FALLING;
170a4617
MS
57 break;
58 case IRQ_TYPE_EDGE_BOTH:
9adf5d22 59 type = S5P_IRQ_TYPE_EDGE_BOTH;
170a4617
MS
60 break;
61 case IRQ_TYPE_LEVEL_HIGH:
9adf5d22 62 type = S5P_IRQ_TYPE_LEVEL_HIGH;
170a4617
MS
63 break;
64 case IRQ_TYPE_LEVEL_LOW:
9adf5d22 65 type = S5P_IRQ_TYPE_LEVEL_LOW;
170a4617
MS
66 break;
67 case IRQ_TYPE_NONE:
68 default:
69 printk(KERN_WARNING "No irq type\n");
70 return -EINVAL;
71 }
72
ad739dcf
TG
73 gc->type_cache &= ~(0x7 << shift);
74 gc->type_cache |= type << shift;
75 writel(gc->type_cache, gc->reg_base + ct->regs.type);
170a4617
MS
76 return 0;
77}
78
170a4617
MS
79static void s5p_gpioint_handler(unsigned int irq, struct irq_desc *desc)
80{
6845664a 81 struct s5p_gpioint_bank *bank = irq_get_handler_data(irq);
2de09262 82 int group, pend_offset, mask_offset;
170a4617
MS
83 unsigned int pend, mask;
84
3f6065dd
MS
85 struct irq_chip *chip = irq_get_chip(irq);
86 chained_irq_enter(chip, desc);
87
a43efddc 88 for (group = 0; group < bank->nr_groups; group++) {
782d8a3c 89 struct samsung_gpio_chip *chip = bank->chips[group];
2de09262
MS
90 if (!chip)
91 continue;
92
93 pend_offset = REG_OFFSET(group);
94 pend = __raw_readl(GPIO_BASE(chip) + PEND_OFFSET + pend_offset);
170a4617
MS
95 if (!pend)
96 continue;
97
2de09262
MS
98 mask_offset = REG_OFFSET(group);
99 mask = __raw_readl(GPIO_BASE(chip) + MASK_OFFSET + mask_offset);
170a4617
MS
100 pend &= ~mask;
101
2de09262
MS
102 while (pend) {
103 int offset = fls(pend) - 1;
104 int real_irq = chip->irq_base + offset;
105 generic_handle_irq(real_irq);
106 pend &= ~BIT(offset);
170a4617
MS
107 }
108 }
3f6065dd 109 chained_irq_exit(chip, desc);
170a4617
MS
110}
111
782d8a3c 112static __init int s5p_gpioint_add(struct samsung_gpio_chip *chip)
170a4617
MS
113{
114 static int used_gpioint_groups = 0;
ad739dcf 115 int group = chip->group;
b76f7cdc 116 struct s5p_gpioint_bank *b, *bank = NULL;
ad739dcf
TG
117 struct irq_chip_generic *gc;
118 struct irq_chip_type *ct;
170a4617
MS
119
120 if (used_gpioint_groups >= S5P_GPIOINT_GROUP_COUNT)
121 return -ENOMEM;
122
b76f7cdc
MS
123 list_for_each_entry(b, &banks, list) {
124 if (group >= b->start && group < b->start + b->nr_groups) {
125 bank = b;
a43efddc 126 break;
b76f7cdc 127 }
a43efddc
MS
128 }
129 if (!bank)
130 return -EINVAL;
131
132 if (!bank->handler) {
782d8a3c 133 bank->chips = kzalloc(sizeof(struct samsung_gpio_chip *) *
a43efddc
MS
134 bank->nr_groups, GFP_KERNEL);
135 if (!bank->chips)
136 return -ENOMEM;
137
6845664a
TG
138 irq_set_chained_handler(bank->irq, s5p_gpioint_handler);
139 irq_set_handler_data(bank->irq, bank);
a43efddc
MS
140 bank->handler = s5p_gpioint_handler;
141 printk(KERN_INFO "Registered chained gpio int handler for interrupt %d.\n",
142 bank->irq);
143 }
144
145 /*
25985edc 146 * chained GPIO irq has been successfully registered, allocate new gpio
a43efddc
MS
147 * int group and assign irq nubmers
148 */
170a4617
MS
149 chip->irq_base = S5P_GPIOINT_BASE +
150 used_gpioint_groups * S5P_GPIOINT_GROUP_SIZE;
151 used_gpioint_groups++;
152
a43efddc 153 bank->chips[group - bank->start] = chip;
ad739dcf
TG
154
155 gc = irq_alloc_generic_chip("s5p_gpioint", 1, chip->irq_base,
5fa1a2e1 156 GPIO_BASE(chip),
ad739dcf
TG
157 handle_level_irq);
158 if (!gc)
159 return -ENOMEM;
160 ct = gc->chip_types;
659fb32d 161 ct->chip.irq_ack = irq_gc_ack_set_bit;
ad739dcf
TG
162 ct->chip.irq_mask = irq_gc_mask_set_bit;
163 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
164 ct->chip.irq_set_type = s5p_gpioint_set_type,
1052cff3
MS
165 ct->regs.ack = PEND_OFFSET + REG_OFFSET(group - bank->start);
166 ct->regs.mask = MASK_OFFSET + REG_OFFSET(group - bank->start);
167 ct->regs.type = CON_OFFSET + REG_OFFSET(group - bank->start);
ad739dcf
TG
168 irq_setup_generic_chip(gc, IRQ_MSK(chip->chip.ngpio),
169 IRQ_GC_INIT_MASK_CACHE,
170 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
170a4617
MS
171 return 0;
172}
173
174int __init s5p_register_gpio_interrupt(int pin)
175{
782d8a3c 176 struct samsung_gpio_chip *my_chip = samsung_gpiolib_getchip(pin);
170a4617
MS
177 int offset, group;
178 int ret;
179
180 if (!my_chip)
181 return -EINVAL;
182
183 offset = pin - my_chip->chip.base;
184 group = my_chip->group;
185
186 /* check if the group has been already registered */
187 if (my_chip->irq_base)
453e2dd7 188 goto success;
170a4617
MS
189
190 /* register gpio group */
191 ret = s5p_gpioint_add(my_chip);
192 if (ret == 0) {
8ce14a22 193 my_chip->chip.to_irq = samsung_gpiolib_to_irq;
170a4617
MS
194 printk(KERN_INFO "Registered interrupt support for gpio group %d.\n",
195 group);
453e2dd7 196 goto success;
170a4617
MS
197 }
198 return ret;
453e2dd7
EK
199success:
200 my_chip->bitmap_gpio_int |= BIT(offset);
201
202 return my_chip->irq_base + offset;
170a4617 203}
a43efddc
MS
204
205int __init s5p_register_gpioint_bank(int chain_irq, int start, int nr_groups)
206{
207 struct s5p_gpioint_bank *bank;
208
209 bank = kzalloc(sizeof(*bank), GFP_KERNEL);
210 if (!bank)
211 return -ENOMEM;
212
213 bank->start = start;
214 bank->nr_groups = nr_groups;
215 bank->irq = chain_irq;
216
217 list_add_tail(&bank->list, &banks);
218 return 0;
219}
This page took 0.263782 seconds and 5 git commands to generate.