22 #include <linux/errno.h>
29 #include <linux/kernel.h>
30 #include <linux/module.h>
33 #include <linux/types.h>
43 #define GIUIOSELL 0x00
44 #define GIUIOSELH 0x02
47 #define GIUINTSTATL 0x08
48 #define GIUINTSTATH 0x0a
49 #define GIUINTENL 0x0c
50 #define GIUINTENH 0x0e
51 #define GIUINTTYPL 0x10
52 #define GIUINTTYPH 0x12
53 #define GIUINTALSELL 0x14
54 #define GIUINTALSELH 0x16
55 #define GIUINTHTSELL 0x18
56 #define GIUINTHTSELH 0x1a
57 #define GIUPODATL 0x1c
58 #define GIUPODATEN 0x1c
59 #define GIUPODATH 0x1e
63 #define GIUFEDGEINHL 0x20
64 #define GIUFEDGEINHH 0x22
65 #define GIUREDGEINHL 0x24
66 #define GIUREDGEINHH 0x26
68 #define GIUUSEUPDN 0x1e0
69 #define GIUTERMUPDN 0x1e2
71 #define GPIO_HAS_PULLUPDOWN_IO 0x0001
72 #define GPIO_HAS_OUTPUT_ENABLE 0x0002
73 #define GPIO_HAS_INTERRUPT_EDGE_SELECT 0x0100
81 static unsigned long giu_flags;
85 #define giu_read(offset) readw(giu_base + (offset))
86 #define giu_write(offset, value) writew((value), giu_base + (offset))
88 #define GPIO_PIN_OF_IRQ(irq) ((irq) - GIU_IRQ_BASE)
89 #define GIUINT_HIGH_OFFSET 16
90 #define GIUINT_HIGH_MAX 32
114 static void ack_giuint_low(
struct irq_data *
d)
119 static void mask_giuint_low(
struct irq_data *d)
124 static void mask_ack_giuint_low(
struct irq_data *d)
133 static void unmask_giuint_low(
struct irq_data *d)
138 static struct irq_chip giuint_low_irq_chip = {
140 .irq_ack = ack_giuint_low,
141 .irq_mask = mask_giuint_low,
142 .irq_mask_ack = mask_ack_giuint_low,
143 .irq_unmask = unmask_giuint_low,
146 static void ack_giuint_high(
struct irq_data *d)
152 static void mask_giuint_high(
struct irq_data *d)
157 static void mask_ack_giuint_high(
struct irq_data *d)
166 static void unmask_giuint_high(
struct irq_data *d)
171 static struct irq_chip giuint_high_irq_chip = {
173 .irq_ack = ack_giuint_high,
174 .irq_mask = mask_giuint_high,
175 .irq_mask_ack = mask_ack_giuint_high,
176 .irq_unmask = unmask_giuint_high,
179 static int giu_get_irq(
unsigned int irq)
181 u16 pendl, pendh, maskl, maskh;
193 for (i = 0; i < 16; i++) {
194 if (maskl & (1 << i))
198 for (i = 0; i < 16; i++) {
199 if (maskh & (1 << i))
204 printk(
KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
205 maskl, pendl, maskh, pendh);
241 irq_set_chip_and_handler(
GIU_IRQ(pin),
242 &giuint_low_irq_chip,
247 irq_set_chip_and_handler(
GIU_IRQ(pin),
248 &giuint_low_irq_chip,
276 irq_set_chip_and_handler(
GIU_IRQ(pin),
277 &giuint_high_irq_chip,
282 irq_set_chip_and_handler(
GIU_IRQ(pin),
283 &giuint_high_irq_chip,
313 static int giu_set_direction(
struct gpio_chip *
chip,
unsigned pin,
int dir)
318 if (pin >= chip->ngpio)
324 }
else if (pin < 32) {
326 mask = 1 << (pin - 16);
330 mask = 1 << (pin - 32);
356 spin_unlock_irqrestore(&giu_lock, flags);
393 spin_unlock_irqrestore(&giu_lock, flags);
399 static int vr41xx_gpio_get(
struct gpio_chip *chip,
unsigned pin)
403 if (pin >= chip->ngpio)
409 }
else if (pin < 32) {
411 mask = 1 << (pin - 16);
412 }
else if (pin < 48) {
414 mask = 1 << (pin - 32);
417 mask = 1 << (pin - 48);
426 static void vr41xx_gpio_set(
struct gpio_chip *chip,
unsigned pin,
432 if (pin >= chip->ngpio)
438 }
else if (pin < 32) {
440 mask = 1 << (pin - 16);
441 }
else if (pin < 48) {
443 mask = 1 << (pin - 32);
446 mask = 1 << (pin - 48);
458 spin_unlock_irqrestore(&giu_lock, flags);
462 static int vr41xx_gpio_direction_input(
struct gpio_chip *chip,
unsigned offset)
464 return giu_set_direction(chip, offset,
GPIO_INPUT);
467 static int vr41xx_gpio_direction_output(
struct gpio_chip *chip,
unsigned offset,
470 vr41xx_gpio_set(chip, offset, value);
472 return giu_set_direction(chip, offset,
GPIO_OUTPUT);
475 static int vr41xx_gpio_to_irq(
struct gpio_chip *chip,
unsigned offset)
477 if (offset >= chip->ngpio)
483 static struct gpio_chip vr41xx_gpio_chip = {
486 .direction_input = vr41xx_gpio_direction_input,
487 .get = vr41xx_gpio_get,
488 .direction_output = vr41xx_gpio_direction_output,
489 .set = vr41xx_gpio_set,
490 .to_irq = vr41xx_gpio_to_irq,
503 vr41xx_gpio_chip.ngpio = 50;
506 vr41xx_gpio_chip.ngpio = 36;
510 vr41xx_gpio_chip.ngpio = 48;
525 vr41xx_gpio_chip.dev = &pdev->
dev;
537 chip = &giuint_low_irq_chip;
539 chip = &giuint_high_irq_chip;
541 if (trigger & (1 << pin))