23 #include <linux/module.h>
30 #include <linux/slab.h>
32 #define DRIVER_NAME "timb-gpio"
36 #define TGPIO_IER 0x08
37 #define TGPIO_ISR 0x0c
38 #define TGPIO_IPR 0x10
39 #define TGPIO_ICR 0x14
40 #define TGPIO_FLR 0x18
41 #define TGPIO_LVR 0x1c
42 #define TGPIO_VER 0x20
43 #define TGPIO_BFLR 0x24
53 static int timbgpio_update_bit(
struct gpio_chip *
gpio,
unsigned index,
59 spin_lock(&tgpio->
lock);
68 spin_unlock(&tgpio->
lock);
73 static int timbgpio_gpio_direction_input(
struct gpio_chip *
gpio,
unsigned nr)
75 return timbgpio_update_bit(gpio, nr,
TGPIODIR,
true);
78 static int timbgpio_gpio_get(
struct gpio_chip *
gpio,
unsigned nr)
84 return (value & (1 << nr)) ? 1 : 0;
87 static int timbgpio_gpio_direction_output(
struct gpio_chip *gpio,
90 return timbgpio_update_bit(gpio, nr,
TGPIODIR,
false);
93 static void timbgpio_gpio_set(
struct gpio_chip *gpio,
96 timbgpio_update_bit(gpio, nr,
TGPIOVAL, val != 0);
99 static int timbgpio_to_irq(
struct gpio_chip *gpio,
unsigned offset)
112 static void timbgpio_irq_disable(
struct irq_data *
d)
114 struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
121 spin_unlock_irqrestore(&tgpio->
lock, flags);
124 static void timbgpio_irq_enable(
struct irq_data *
d)
126 struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
133 spin_unlock_irqrestore(&tgpio->
lock, flags);
138 struct timbgpio *tgpio = irq_data_get_irq_chip_data(d);
141 u32 lvr, flr, bflr = 0;
192 spin_unlock_irqrestore(&tgpio->
lock, flags);
196 static void timbgpio_irq(
unsigned int irq,
struct irq_desc *
desc)
198 struct timbgpio *tgpio = irq_get_handler_data(irq);
220 .irq_enable = timbgpio_irq_enable,
221 .irq_disable = timbgpio_irq_disable,
222 .irq_set_type = timbgpio_irq_type,
228 struct gpio_chip *
gc;
234 if (!pdata || pdata->
nr_pins > 32) {
268 gc->label = dev_name(&pdev->
dev);
270 gc->dev = &pdev->
dev;
271 gc->direction_input = timbgpio_gpio_direction_input;
272 gc->get = timbgpio_gpio_get;
273 gc->direction_output = timbgpio_gpio_direction_output;
274 gc->set = timbgpio_gpio_set;
275 gc->to_irq = (irq >= 0 && tgpio->
irq_base > 0) ? timbgpio_to_irq :
NULL;
285 platform_set_drvdata(pdev, tgpio);
290 if (irq < 0 || tgpio->
irq_base <= 0)
293 for (i = 0; i < pdata->
nr_pins; i++) {
303 irq_set_chained_handler(irq, timbgpio_irq);
323 struct timbgpio *tgpio = platform_get_drvdata(pdev);
327 if (irq >= 0 && tgpio->
irq_base > 0) {
329 for (i = 0; i < pdata->
nr_pins; i++) {
334 irq_set_handler(irq,
NULL);
346 platform_set_drvdata(pdev,
NULL);
356 .probe = timbgpio_probe,
357 .remove = timbgpio_remove,