16 #include <linux/kernel.h>
22 #include <mach/hardware.h>
23 #include <mach/irqs.h>
25 #define GPIO_BASE(x) IO_ADDRESS(GEMINI_GPIO_BASE(x))
28 #define GPIO_DATA_OUT 0x0
29 #define GPIO_DATA_IN 0x4
31 #define GPIO_DATA_SET 0x10
32 #define GPIO_DATA_CLR 0x14
33 #define GPIO_PULL_EN 0x18
34 #define GPIO_PULL_TYPE 0x1C
35 #define GPIO_INT_EN 0x20
36 #define GPIO_INT_STAT 0x24
37 #define GPIO_INT_MASK 0x2C
38 #define GPIO_INT_CLR 0x30
39 #define GPIO_INT_TYPE 0x34
40 #define GPIO_INT_BOTH_EDGE 0x38
41 #define GPIO_INT_LEVEL 0x3C
42 #define GPIO_DEBOUNCE_EN 0x40
43 #define GPIO_DEBOUNCE_PRESCALE 0x44
45 #define GPIO_PORT_NUM 3
47 static void _set_gpio_irqenable(
unsigned int base,
unsigned int index,
53 reg = (reg & (~(1 <<
index))) | (!!enable << index);
57 static void gpio_ack_irq(
struct irq_data *
d)
65 static void gpio_mask_irq(
struct irq_data *d)
70 _set_gpio_irqenable(base, gpio % 32, 0);
73 static void gpio_unmask_irq(
struct irq_data *d)
78 _set_gpio_irqenable(base, gpio % 32, 1);
81 static int gpio_set_irq_type(
struct irq_data *d,
unsigned int type)
84 unsigned int gpio_mask = 1 << (gpio % 32);
86 unsigned int reg_both, reg_level, reg_type;
94 reg_type &= ~gpio_mask;
95 reg_both |= gpio_mask;
98 reg_type &= ~gpio_mask;
99 reg_both &= ~gpio_mask;
100 reg_level &= ~gpio_mask;
103 reg_type &= ~gpio_mask;
104 reg_both &= ~gpio_mask;
105 reg_level |= gpio_mask;
108 reg_type |= gpio_mask;
109 reg_level &= ~gpio_mask;
112 reg_type |= gpio_mask;
113 reg_level |= gpio_mask;
123 gpio_ack_irq(d->
irq);
128 static void gpio_irq_handler(
unsigned int irq,
struct irq_desc *
desc)
130 unsigned int port = (
unsigned int)irq_desc_get_handler_data(desc);
136 for (; irq_stat != 0; irq_stat >>= 1, gpio_irq_no++) {
138 if ((irq_stat & 1) == 0)
145 static struct irq_chip gpio_irq_chip = {
147 .irq_ack = gpio_ack_irq,
148 .irq_mask = gpio_mask_irq,
149 .irq_unmask = gpio_unmask_irq,
150 .irq_set_type = gpio_set_irq_type,
153 static void _set_gpio_direction(
struct gpio_chip *
chip,
unsigned offset,
156 unsigned int base =
GPIO_BASE(offset / 32);
161 reg |= 1 << (offset % 32);
163 reg &= ~(1 << (offset % 32));
167 static void gemini_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int value)
169 unsigned int base =
GPIO_BASE(offset / 32);
177 static int gemini_gpio_get(
struct gpio_chip *chip,
unsigned offset)
179 unsigned int base =
GPIO_BASE(offset / 32);
184 static int gemini_gpio_direction_input(
struct gpio_chip *chip,
unsigned offset)
186 _set_gpio_direction(chip, offset, 0);
190 static int gemini_gpio_direction_output(
struct gpio_chip *chip,
unsigned offset,
193 _set_gpio_direction(chip, offset, 1);
194 gemini_gpio_set(chip, offset, value);
198 static struct gpio_chip gemini_gpio_chip = {
200 .direction_input = gemini_gpio_direction_input,
201 .get = gemini_gpio_get,
202 .direction_output = gemini_gpio_direction_output,
203 .set = gemini_gpio_set,
220 irq_set_chip_and_handler(j, &gpio_irq_chip,
225 irq_set_chained_handler(
IRQ_GPIO(i), gpio_irq_handler);