15 #include <linux/kernel.h>
19 #include <mach/common.h>
30 #define gpio_reg_index(gpio) ((gpio) >> 5)
31 #define gpio_reg_bit(gpio) BIT((gpio) & 0x1f)
33 #define gpio_reg_rmw(reg, mask, val) \
34 __raw_writel((__raw_readl(reg) & ~(mask)) | (val), (reg))
36 #define gpio_reg_set_bit(reg, gpio) \
37 gpio_reg_rmw((reg) + gpio_reg_index(gpio), 0, gpio_reg_bit(gpio))
39 #define gpio_reg_clear_bit(reg, gpio) \
40 gpio_reg_rmw((reg) + gpio_reg_index(gpio), gpio_reg_bit(gpio), 0)
42 #define gpio_reg_get_bit(reg, gpio) \
43 (__raw_readl((reg) + gpio_reg_index(gpio)) & gpio_reg_bit(gpio))
45 #define chip2controller(chip) \
46 container_of(chip, struct davinci_gpio_controller, chip)
48 #define TNETV107X_GPIO_CTLRS DIV_ROUND_UP(TNETV107X_N_GPIO, 32)
52 static int tnetv107x_gpio_request(
struct gpio_chip *
chip,
unsigned offset)
63 spin_unlock_irqrestore(&ctlr->
lock, flags);
68 static void tnetv107x_gpio_free(
struct gpio_chip *
chip,
unsigned offset)
79 spin_unlock_irqrestore(&ctlr->
lock, flags);
82 static int tnetv107x_gpio_dir_in(
struct gpio_chip *
chip,
unsigned offset)
93 spin_unlock_irqrestore(&ctlr->
lock, flags);
98 static int tnetv107x_gpio_dir_out(
struct gpio_chip *
chip,
115 spin_unlock_irqrestore(&ctlr->
lock, flags);
120 static int tnetv107x_gpio_get(
struct gpio_chip *chip,
unsigned offset)
124 unsigned gpio = chip->base +
offset;
132 static void tnetv107x_gpio_set(
struct gpio_chip *chip,
133 unsigned offset,
int value)
137 unsigned gpio = chip->base +
offset;
147 spin_unlock_irqrestore(&ctlr->
lock, flags);
150 static int __init tnetv107x_gpio_setup(
void)
163 pr_err(
"GPIO setup: how many GPIOs?\n");
174 for (i = 0, base = 0; base < ngpio; i++, base += 32) {
177 ctlr->
chip.label =
"tnetv107x";
178 ctlr->
chip.can_sleep = 0;
179 ctlr->
chip.base = base;
180 ctlr->
chip.ngpio = ngpio - base;
181 if (ctlr->
chip.ngpio > 32)
182 ctlr->
chip.ngpio = 32;
184 ctlr->
chip.request = tnetv107x_gpio_request;
185 ctlr->
chip.free = tnetv107x_gpio_free;
186 ctlr->
chip.direction_input = tnetv107x_gpio_dir_in;
187 ctlr->
chip.get = tnetv107x_gpio_get;
188 ctlr->
chip.direction_output = tnetv107x_gpio_dir_out;
189 ctlr->
chip.set = tnetv107x_gpio_set;