13 #include <linux/errno.h>
14 #include <linux/module.h>
18 #include <linux/bitops.h>
21 #include <linux/device.h>
24 #include <linux/slab.h>
37 #define PL061_GPIO_NR 8
40 struct pl061_context_save_regs {
64 struct pl061_context_save_regs csave_regs;
68 static int pl061_direction_input(
struct gpio_chip *
gc,
unsigned offset)
72 unsigned char gpiodir;
74 if (offset >= gc->ngpio)
81 spin_unlock_irqrestore(&chip->
lock, flags);
86 static int pl061_direction_output(
struct gpio_chip *gc,
unsigned offset,
91 unsigned char gpiodir;
93 if (offset >= gc->ngpio)
97 writeb(!!value << offset, chip->
base + (1 << (offset + 2)));
106 writeb(!!value << offset, chip->
base + (1 << (offset + 2)));
107 spin_unlock_irqrestore(&chip->
lock, flags);
112 static int pl061_get_value(
struct gpio_chip *gc,
unsigned offset)
116 return !!
readb(chip->
base + (1 << (offset + 2)));
119 static void pl061_set_value(
struct gpio_chip *gc,
unsigned offset,
int value)
123 writeb(!!value << offset, chip->
base + (1 << (offset + 2)));
126 static int pl061_to_irq(
struct gpio_chip *gc,
unsigned offset)
138 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
142 u8 gpiois, gpioibe, gpioiev;
157 gpioiev &= ~(1 <<
offset);
166 gpioibe &= ~(1 <<
offset);
170 gpioiev &= ~(1 <<
offset);
181 static void pl061_irq_handler(
unsigned irq,
struct irq_desc *
desc)
183 unsigned long pending;
185 struct pl061_gpio *chip = irq_desc_get_handler_data(desc);
186 struct irq_chip *irqchip = irq_desc_get_chip(desc);
188 chained_irq_enter(irqchip, desc);
197 chained_irq_exit(irqchip, desc);
202 struct irq_chip_type *
ct;
206 chip->irq_gc->private =
chip;
208 ct = chip->irq_gc->chip_types;
211 ct->chip.irq_set_type = pl061_irq_type;
229 pdata = dev->
dev.platform_data;
233 }
else if (dev->
dev.of_node) {
242 resource_size(&dev->
res),
"pl061")) {
255 chip->
gc.direction_input = pl061_direction_input;
256 chip->
gc.direction_output = pl061_direction_output;
257 chip->
gc.get = pl061_get_value;
258 chip->
gc.set = pl061_set_value;
259 chip->
gc.to_irq = pl061_to_irq;
261 chip->
gc.label = dev_name(&dev->
dev);
262 chip->
gc.dev = &dev->
dev;
276 pl061_init_gc(chip, chip->
irq_base);
284 irq_set_chained_handler(irq, pl061_irq_handler);
290 pl061_direction_output(&chip->
gc, i,
291 pdata->
values & (1 << i));
293 pl061_direction_input(&chip->
gc, i);
312 static int pl061_suspend(
struct device *dev)
317 chip->csave_regs.gpio_data = 0;
325 if (chip->csave_regs.gpio_dir & (1 << offset))
326 chip->csave_regs.gpio_data |=
327 pl061_get_value(&chip->
gc, offset) <<
offset;
333 static int pl061_resume(
struct device *dev)
339 if (chip->csave_regs.gpio_dir & (1 << offset))
340 pl061_direction_output(&chip->
gc, offset,
341 chip->csave_regs.gpio_data &
344 pl061_direction_input(&chip->
gc, offset);
355 static const struct dev_pm_ops pl061_dev_pm_ops = {
357 .resume = pl061_resume,
358 .freeze = pl061_suspend,
359 .restore = pl061_resume,
363 static struct amba_id pl061_ids[] = {
375 .name =
"pl061_gpio",
377 .pm = &pl061_dev_pm_ops,
380 .id_table = pl061_ids,
381 .probe = pl061_probe,
384 static int __init pl061_gpio_init(
void)