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 <linux/gpio.h>
21 #include <linux/irq.h>
23 #include <mach/hardware.h>
25 struct ep93xx_gpio_chip
{
26 struct gpio_chip chip
;
28 void __iomem
*data_reg
;
29 void __iomem
*data_dir_reg
;
32 #define to_ep93xx_gpio_chip(c) container_of(c, struct ep93xx_gpio_chip, chip)
35 extern void ep93xx_gpio_int_mask(unsigned line
);
36 extern void ep93xx_gpio_update_int_params(unsigned port
);
38 static int ep93xx_gpio_direction_input(struct gpio_chip
*chip
, unsigned offset
)
40 struct ep93xx_gpio_chip
*ep93xx_chip
= to_ep93xx_gpio_chip(chip
);
44 local_irq_save(flags
);
45 v
= __raw_readb(ep93xx_chip
->data_dir_reg
);
47 __raw_writeb(v
, ep93xx_chip
->data_dir_reg
);
48 local_irq_restore(flags
);
53 static int ep93xx_gpio_direction_output(struct gpio_chip
*chip
,
54 unsigned offset
, int val
)
56 struct ep93xx_gpio_chip
*ep93xx_chip
= to_ep93xx_gpio_chip(chip
);
61 local_irq_save(flags
);
64 v
= __raw_readb(ep93xx_chip
->data_reg
);
69 __raw_writeb(v
, ep93xx_chip
->data_reg
);
71 /* Drive as an output */
72 line
= chip
->base
+ offset
;
73 if (line
<= EP93XX_GPIO_LINE_MAX_IRQ
) {
75 ep93xx_gpio_int_mask(line
);
76 ep93xx_gpio_update_int_params(line
>> 3);
79 v
= __raw_readb(ep93xx_chip
->data_dir_reg
);
81 __raw_writeb(v
, ep93xx_chip
->data_dir_reg
);
83 local_irq_restore(flags
);
88 static int ep93xx_gpio_get(struct gpio_chip
*chip
, unsigned offset
)
90 struct ep93xx_gpio_chip
*ep93xx_chip
= to_ep93xx_gpio_chip(chip
);
92 return !!(__raw_readb(ep93xx_chip
->data_reg
) & (1 << offset
));
95 static void ep93xx_gpio_set(struct gpio_chip
*chip
, unsigned offset
, int val
)
97 struct ep93xx_gpio_chip
*ep93xx_chip
= to_ep93xx_gpio_chip(chip
);
101 local_irq_save(flags
);
102 v
= __raw_readb(ep93xx_chip
->data_reg
);
107 __raw_writeb(v
, ep93xx_chip
->data_reg
);
108 local_irq_restore(flags
);
111 static void ep93xx_gpio_dbg_show(struct seq_file
*s
, struct gpio_chip
*chip
)
113 struct ep93xx_gpio_chip
*ep93xx_chip
= to_ep93xx_gpio_chip(chip
);
114 u8 data_reg
, data_dir_reg
;
117 data_reg
= __raw_readb(ep93xx_chip
->data_reg
);
118 data_dir_reg
= __raw_readb(ep93xx_chip
->data_dir_reg
);
120 gpio
= ep93xx_chip
->chip
.base
;
121 for (i
= 0; i
< chip
->ngpio
; i
++, gpio
++) {
122 int is_out
= data_dir_reg
& (1 << i
);
124 seq_printf(s
, " %s%d gpio-%-3d (%-12s) %s %s",
125 chip
->label
, i
, gpio
,
126 gpiochip_is_requested(chip
, i
) ? : "",
127 is_out
? "out" : "in ",
128 (data_reg
& (1 << i
)) ? "hi" : "lo");
131 int irq
= gpio_to_irq(gpio
);
132 struct irq_desc
*desc
= irq_desc
+ irq
;
134 if (irq
>= 0 && desc
->action
) {
137 switch (desc
->status
& IRQ_TYPE_SENSE_MASK
) {
139 trigger
= "(default)";
141 case IRQ_TYPE_EDGE_FALLING
:
142 trigger
= "edge-falling";
144 case IRQ_TYPE_EDGE_RISING
:
145 trigger
= "edge-rising";
147 case IRQ_TYPE_EDGE_BOTH
:
148 trigger
= "edge-both";
150 case IRQ_TYPE_LEVEL_HIGH
:
151 trigger
= "level-high";
153 case IRQ_TYPE_LEVEL_LOW
:
154 trigger
= "level-low";
157 trigger
= "?trigger?";
161 seq_printf(s
, " irq-%d %s%s",
163 (desc
->status
& IRQ_WAKEUP
)
172 #define EP93XX_GPIO_BANK(name, dr, ddr, base_gpio) \
176 .direction_input = ep93xx_gpio_direction_input, \
177 .direction_output = ep93xx_gpio_direction_output, \
178 .get = ep93xx_gpio_get, \
179 .set = ep93xx_gpio_set, \
180 .dbg_show = ep93xx_gpio_dbg_show, \
184 .data_reg = EP93XX_GPIO_REG(dr), \
185 .data_dir_reg = EP93XX_GPIO_REG(ddr), \
188 static struct ep93xx_gpio_chip ep93xx_gpio_banks
[] = {
189 EP93XX_GPIO_BANK("A", 0x00, 0x10, 0),
190 EP93XX_GPIO_BANK("B", 0x04, 0x14, 8),
191 EP93XX_GPIO_BANK("C", 0x08, 0x18, 40),
192 EP93XX_GPIO_BANK("D", 0x0c, 0x1c, 24),
193 EP93XX_GPIO_BANK("E", 0x20, 0x24, 32),
194 EP93XX_GPIO_BANK("F", 0x30, 0x34, 16),
195 EP93XX_GPIO_BANK("G", 0x38, 0x3c, 48),
196 EP93XX_GPIO_BANK("H", 0x40, 0x44, 56),
199 void __init
ep93xx_gpio_init(void)
203 for (i
= 0; i
< ARRAY_SIZE(ep93xx_gpio_banks
); i
++)
204 gpiochip_add(&ep93xx_gpio_banks
[i
].chip
);