2 * linux/arch/arm/mach-ep93xx/gpio.c
4 * Generic EP93xx GPIO handling
6 * Copyright (c) 2008 Ryan Mallon <ryan@bluewatersys.com>
8 * Based on code originally from:
9 * linux/arch/arm/mach-ep93xx/core.c
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/init.h>
17 #include <linux/module.h>
18 #include <linux/seq_file.h>
20 #include <asm/arch/ep93xx-regs.h>
24 struct ep93xx_gpio_chip {
25 struct gpio_chip chip;
27 unsigned int data_reg;
28 unsigned int data_dir_reg;
31 #define to_ep93xx_gpio_chip(c) container_of(c, struct ep93xx_gpio_chip, chip)
34 extern void ep93xx_gpio_int_mask(unsigned line);
35 extern void ep93xx_gpio_update_int_params(unsigned port);
37 static int ep93xx_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
39 struct ep93xx_gpio_chip *ep93xx_chip = to_ep93xx_gpio_chip(chip);
43 local_irq_save(flags);
44 v = __raw_readb(ep93xx_chip->data_dir_reg);
46 __raw_writeb(v, ep93xx_chip->data_dir_reg);
47 local_irq_restore(flags);
52 static int ep93xx_gpio_direction_output(struct gpio_chip *chip,
53 unsigned offset, int val)
55 struct ep93xx_gpio_chip *ep93xx_chip = to_ep93xx_gpio_chip(chip);
60 local_irq_save(flags);
63 v = __raw_readb(ep93xx_chip->data_reg);
68 __raw_writeb(v, ep93xx_chip->data_reg);
70 /* Drive as an output */
71 line = chip->base + offset;
72 if (line <= EP93XX_GPIO_LINE_MAX_IRQ) {
74 ep93xx_gpio_int_mask(line);
75 ep93xx_gpio_update_int_params(line >> 3);
78 v = __raw_readb(ep93xx_chip->data_dir_reg);
80 __raw_writeb(v, ep93xx_chip->data_dir_reg);
82 local_irq_restore(flags);
87 static int ep93xx_gpio_get(struct gpio_chip *chip, unsigned offset)
89 struct ep93xx_gpio_chip *ep93xx_chip = to_ep93xx_gpio_chip(chip);
91 return !!(__raw_readb(ep93xx_chip->data_reg) & (1 << offset));
94 static void ep93xx_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
96 struct ep93xx_gpio_chip *ep93xx_chip = to_ep93xx_gpio_chip(chip);
100 local_irq_save(flags);
101 v = __raw_readb(ep93xx_chip->data_reg);
106 __raw_writeb(v, ep93xx_chip->data_reg);
107 local_irq_restore(flags);
110 static void ep93xx_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
112 struct ep93xx_gpio_chip *ep93xx_chip = to_ep93xx_gpio_chip(chip);
113 u8 data_reg, data_dir_reg;
116 data_reg = __raw_readb(ep93xx_chip->data_reg);
117 data_dir_reg = __raw_readb(ep93xx_chip->data_dir_reg);
119 for (i = 0; i < chip->ngpio; i++)
120 seq_printf(s, "GPIO %s%d: %s %s\n", chip->label, i,
121 (data_reg & (1 << i)) ? "set" : "clear",
122 (data_dir_reg & (1 << i)) ? "out" : "in");
125 #define EP93XX_GPIO_BANK(name, dr, ddr, base_gpio) \
129 .direction_input = ep93xx_gpio_direction_input, \
130 .direction_output = ep93xx_gpio_direction_output, \
131 .get = ep93xx_gpio_get, \
132 .set = ep93xx_gpio_set, \
133 .dbg_show = ep93xx_gpio_dbg_show, \
137 .data_reg = EP93XX_GPIO_REG(dr), \
138 .data_dir_reg = EP93XX_GPIO_REG(ddr), \
141 static struct ep93xx_gpio_chip ep93xx_gpio_banks[] = {
142 EP93XX_GPIO_BANK("A", 0x00, 0x10, 0),
143 EP93XX_GPIO_BANK("B", 0x04, 0x14, 8),
144 EP93XX_GPIO_BANK("C", 0x30, 0x34, 40),
145 EP93XX_GPIO_BANK("D", 0x0c, 0x1c, 24),
146 EP93XX_GPIO_BANK("E", 0x20, 0x24, 32),
147 EP93XX_GPIO_BANK("F", 0x08, 0x18, 16),
148 EP93XX_GPIO_BANK("G", 0x38, 0x3c, 48),
149 EP93XX_GPIO_BANK("H", 0x40, 0x44, 56),
152 void __init ep93xx_gpio_init(void)
156 for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++)
157 gpiochip_add(&ep93xx_gpio_banks[i].chip);