23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
29 #include <linux/pci.h>
66 static inline u32 __bit(
int nr)
75 static void gsta_gpio_set(
struct gpio_chip *
gpio,
unsigned nr,
int val)
87 static int gsta_gpio_get(
struct gpio_chip *gpio,
unsigned nr)
96 static int gsta_gpio_direction_output(
struct gpio_chip *gpio,
unsigned nr,
112 static int gsta_gpio_direction_input(
struct gpio_chip *gpio,
unsigned nr)
122 static int gsta_gpio_to_irq(
struct gpio_chip *gpio,
unsigned offset)
128 static void gsta_gpio_setup(
struct gsta_gpio *chip)
130 struct gpio_chip *gpio = &chip->
gpio;
140 gpio->label = dev_name(chip->
dev);
142 gpio->direction_input = gsta_gpio_direction_input;
143 gpio->get = gsta_gpio_get;
144 gpio->direction_output = gsta_gpio_direction_output;
145 gpio->set = gsta_gpio_set;
146 gpio->dbg_show =
NULL;
150 gpio->to_irq = gsta_gpio_to_irq;
166 static void gsta_set_config(
struct gsta_gpio *chip,
int nr,
unsigned cfg)
174 pr_info(
"%s: %p %i %i\n", __func__, chip, nr, cfg);
188 spin_unlock_irqrestore(&chip->
lock, flags);
222 spin_unlock_irqrestore(&chip->
lock, flags);
224 pr_err(
"%s: chip %p, pin %i, cfg %i is invalid\n",
225 __func__, chip, nr, cfg);
234 struct irq_chip_generic *
gc = irq_data_get_irq_chip_data(data);
251 spin_unlock_irqrestore(&chip->
lock, flags);
255 static void gsta_irq_enable(
struct irq_data *data)
257 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
270 if (type & IRQ_TYPE_EDGE_RISING)
279 spin_unlock_irqrestore(&chip->
lock, flags);
283 static int gsta_irq_type(
struct irq_data *
d,
unsigned int type)
285 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
291 pr_debug(
"%s: unsupported type 0x%x\n", __func__, type);
310 regs = chip->
regs[
i];
312 while ((is =
readl(®s->
is))) {
325 struct irq_chip_generic *gc;
326 struct irq_chip_type *
ct;
333 ct->chip.irq_set_type = gsta_irq_type;
334 ct->chip.irq_disable = gsta_irq_disable;
335 ct->chip.irq_enable = gsta_irq_enable;
343 struct irq_chip_type *ct = gc->chip_types;
347 irq_set_chip_and_handler(i, &ct->chip, ct->handler);
351 gc->irq_cnt = i - gc->irq_base;
364 pdev = *(
struct pci_dev **)(dev->
dev.platform_data);
365 gpio_pdata = dev_get_platdata(&pdev->
dev);
367 if (gpio_pdata ==
NULL)
369 pr_debug(
"gpio config: %p\n", gpio_pdata);
385 gsta_gpio_setup(chip);
388 gsta_set_config(chip, i, gpio_pdata->
pinconfig[i]);
391 err = irq_alloc_descs(-1, 384, GSTA_NR_GPIO,
NUMA_NO_NODE);
393 dev_warn(&dev->
dev,
"sta2x11 gpio: Can't get irq base (%i)\n",
398 gsta_alloc_irq_chip(chip);
403 dev_err(&dev->
dev,
"sta2x11 gpio: Can't request irq (%i)\n",
410 dev_err(&dev->
dev,
"sta2x11 gpio: Can't register (%i)\n",
415 platform_set_drvdata(dev, chip);
427 .name =
"sta2x11-gpio",