16 #include <linux/module.h>
21 #include <linux/slab.h>
24 #include <mach/hardware.h>
27 #define irq_to_gpio(irq) ((irq) - gpio_to_irq(0))
37 static unsigned char gpio_int_unmasked[3];
38 static unsigned char gpio_int_enabled[3];
39 static unsigned char gpio_int_type1[3];
40 static unsigned char gpio_int_type2[3];
41 static unsigned char gpio_int_debounce[3];
44 static const u8 int_type1_register_offset[3] = { 0x90, 0xac, 0x4c };
45 static const u8 int_type2_register_offset[3] = { 0x94, 0xb0, 0x50 };
46 static const u8 eoi_register_offset[3] = { 0x98, 0xb4, 0x54 };
47 static const u8 int_en_register_offset[3] = { 0x9c, 0xb8, 0x58 };
48 static const u8 int_debounce_register_offset[3] = { 0xa8, 0xc4, 0x64 };
50 static void ep93xx_gpio_update_int_params(
unsigned port)
62 __raw_writeb(gpio_int_unmasked[port] & gpio_int_enabled[port],
66 static void ep93xx_gpio_int_debounce(
unsigned int irq,
bool enable)
70 int port_mask = 1 << (line & 7);
73 gpio_int_debounce[
port] |= port_mask;
75 gpio_int_debounce[
port] &= ~port_mask;
81 static void ep93xx_gpio_ab_irq_handler(
unsigned int irq,
struct irq_desc *
desc)
87 for (i = 0; i < 8; i++) {
88 if (status & (1 << i)) {
95 for (i = 0; i < 8; i++) {
96 if (status & (1 << i)) {
103 static void ep93xx_gpio_f_irq_handler(
unsigned int irq,
struct irq_desc *desc)
110 int port_f_idx = ((irq + 1) & 7) ^ 4;
116 static void ep93xx_gpio_irq_ack(
struct irq_data *
d)
119 int port = line >> 3;
120 int port_mask = 1 << (line & 7);
123 gpio_int_type2[
port] ^= port_mask;
124 ep93xx_gpio_update_int_params(port);
130 static void ep93xx_gpio_irq_mask_ack(
struct irq_data *d)
133 int port = line >> 3;
134 int port_mask = 1 << (line & 7);
137 gpio_int_type2[port] ^= port_mask;
139 gpio_int_unmasked[
port] &= ~port_mask;
140 ep93xx_gpio_update_int_params(port);
145 static void ep93xx_gpio_irq_mask(
struct irq_data *d)
148 int port = line >> 3;
150 gpio_int_unmasked[
port] &= ~(1 << (line & 7));
151 ep93xx_gpio_update_int_params(port);
154 static void ep93xx_gpio_irq_unmask(
struct irq_data *d)
157 int port = line >> 3;
159 gpio_int_unmasked[
port] |= 1 << (line & 7);
160 ep93xx_gpio_update_int_params(port);
168 static int ep93xx_gpio_irq_type(
struct irq_data *d,
unsigned int type)
171 const int port = gpio >> 3;
172 const int port_mask = 1 << (gpio & 7);
179 gpio_int_type1[
port] |= port_mask;
180 gpio_int_type2[
port] |= port_mask;
184 gpio_int_type1[
port] |= port_mask;
185 gpio_int_type2[
port] &= ~port_mask;
189 gpio_int_type1[
port] &= ~port_mask;
190 gpio_int_type2[
port] |= port_mask;
194 gpio_int_type1[
port] &= ~port_mask;
195 gpio_int_type2[
port] &= ~port_mask;
199 gpio_int_type1[
port] |= port_mask;
202 gpio_int_type2[
port] &= ~port_mask;
204 gpio_int_type2[
port] |= port_mask;
211 __irq_set_handler_locked(d->
irq, handler);
213 gpio_int_enabled[
port] |= port_mask;
215 ep93xx_gpio_update_int_params(port);
220 static struct irq_chip ep93xx_gpio_irq_chip = {
222 .irq_ack = ep93xx_gpio_irq_ack,
223 .irq_mask_ack = ep93xx_gpio_irq_mask_ack,
224 .irq_mask = ep93xx_gpio_irq_mask,
225 .irq_unmask = ep93xx_gpio_irq_unmask,
226 .irq_set_type = ep93xx_gpio_irq_type,
229 static void ep93xx_gpio_init_irq(
void)
235 irq_set_chip_and_handler(gpio_irq, &ep93xx_gpio_irq_chip,
241 ep93xx_gpio_ab_irq_handler);
243 ep93xx_gpio_f_irq_handler);
245 ep93xx_gpio_f_irq_handler);
247 ep93xx_gpio_f_irq_handler);
249 ep93xx_gpio_f_irq_handler);
251 ep93xx_gpio_f_irq_handler);
253 ep93xx_gpio_f_irq_handler);
255 ep93xx_gpio_f_irq_handler);
257 ep93xx_gpio_f_irq_handler);
272 #define EP93XX_GPIO_BANK(_label, _data, _dir, _base, _debounce) \
278 .has_debounce = _debounce, \
292 static int ep93xx_gpio_set_debounce(
struct gpio_chip *
chip,
293 unsigned offset,
unsigned debounce)
295 int gpio = chip->base +
offset;
301 ep93xx_gpio_int_debounce(irq, debounce ?
true :
false);
311 static int ep93xx_gpio_to_irq(
struct gpio_chip *chip,
unsigned offset)
313 int gpio = chip->base +
offset;
333 bgc->
gc.base = bank->
base;
336 bgc->
gc.set_debounce = ep93xx_gpio_set_debounce;
337 bgc->
gc.to_irq = ep93xx_gpio_to_irq;
351 ep93xx_gpio = kzalloc(
sizeof(*ep93xx_gpio),
GFP_KERNEL);
373 for (i = 0; i <
ARRAY_SIZE(ep93xx_gpio_banks); i++) {
377 if (ep93xx_gpio_add_bank(bgc, &pdev->
dev, mmio, bank))
378 dev_warn(&pdev->
dev,
"Unable to add gpio bank %s\n",
382 ep93xx_gpio_init_irq();
390 dev_info(&pdev->
dev,
"%s failed with errno %d\n", __func__, ret);
396 .name =
"gpio-ep93xx",
399 .probe = ep93xx_gpio_probe,
402 static int __init ep93xx_gpio_init(
void)