13 #include <linux/errno.h>
14 #include <linux/kernel.h>
34 #define chip2controller(chip) \
35 container_of(chip, struct davinci_gpio_controller, chip)
46 else if (gpio < 32 * 2)
48 else if (gpio < 32 * 3)
50 else if (gpio < 32 * 4)
52 else if (gpio < 32 * 5)
68 static int __init davinci_gpio_irq_setup(
void);
73 static inline int __davinci_direction(
struct gpio_chip *
chip,
91 spin_unlock_irqrestore(&d->
lock, flags);
96 static int davinci_direction_in(
struct gpio_chip *chip,
unsigned offset)
98 return __davinci_direction(chip, offset,
false, 0);
102 davinci_direction_out(
struct gpio_chip *chip,
unsigned offset,
int value)
104 return __davinci_direction(chip, offset,
true, value);
114 static int davinci_gpio_get(
struct gpio_chip *chip,
unsigned offset)
126 davinci_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int value)
134 static int __init davinci_gpio_setup(
void)
151 pr_err(
"GPIO setup: how many GPIOs?\n");
162 for (i = 0, base = 0; base < ngpio; i++, base += 32) {
163 chips[
i].chip.label =
"DaVinci";
165 chips[
i].chip.direction_input = davinci_direction_in;
166 chips[
i].chip.get = davinci_gpio_get;
167 chips[
i].chip.direction_output = davinci_direction_out;
168 chips[
i].chip.set = davinci_gpio_set;
170 chips[
i].chip.base = base;
171 chips[
i].chip.ngpio = ngpio - base;
172 if (
chips[i].chip.ngpio > 32)
177 regs = gpio2regs(base);
189 davinci_gpio_irq_setup();
206 static void gpio_irq_disable(
struct irq_data *d)
209 u32 mask = (
u32) irq_data_get_irq_handler_data(d);
215 static void gpio_irq_enable(
struct irq_data *d)
218 u32 mask = (
u32) irq_data_get_irq_handler_data(d);
219 unsigned status = irqd_get_trigger_type(d);
239 static struct irq_chip gpio_irqchip = {
241 .irq_enable = gpio_irq_enable,
242 .irq_disable = gpio_irq_disable,
243 .irq_set_type = gpio_irq_type,
293 static int gpio_to_irq_banked(
struct gpio_chip *chip,
unsigned offset)
303 static int gpio_to_irq_unbanked(
struct gpio_chip *chip,
unsigned offset)
316 static int gpio_irq_type_unbanked(
struct irq_data *
data,
unsigned trigger)
325 mask = __gpio_mask(data->
irq - soc_info->
gpio_irq);
346 static int __init davinci_gpio_irq_setup(
void)
348 unsigned gpio, irq, bank;
351 unsigned ngpio, bank_irq;
369 clk_prepare_enable(clk);
376 for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 32) {
377 chips[bank].chip.to_irq = gpio_to_irq_banked;
389 static struct irq_chip_type gpio_unbanked;
392 chips[0].chip.to_irq = gpio_to_irq_unbanked;
398 struct irq_chip_type, chip);
399 gpio_unbanked.chip.name =
"GPIO-AINTC";
400 gpio_unbanked.chip.irq_set_type = gpio_irq_type_unbanked;
408 for (gpio = 0; gpio < soc_info->
gpio_unbanked; gpio++, irq++) {
423 bank++, bank_irq++) {
432 irq_set_chained_handler(bank_irq, gpio_irq_handler);
441 for (i = 0; i < 16 && gpio < ngpio; i++, irq++, gpio++) {