36 #include <linux/module.h>
39 #include <linux/slab.h>
50 #define GPIO_OUT_OFF 0x0000
51 #define GPIO_IO_CONF_OFF 0x0004
52 #define GPIO_BLINK_EN_OFF 0x0008
53 #define GPIO_IN_POL_OFF 0x000c
54 #define GPIO_DATA_IN_OFF 0x0010
55 #define GPIO_EDGE_CAUSE_OFF 0x0014
56 #define GPIO_EDGE_MASK_OFF 0x0018
57 #define GPIO_LEVEL_MASK_OFF 0x001c
60 #define GPIO_EDGE_MASK_MV78200_OFF(cpu) ((cpu) ? 0x30 : 0x18)
61 #define GPIO_LEVEL_MASK_MV78200_OFF(cpu) ((cpu) ? 0x34 : 0x1C)
66 #define GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu) ((cpu) * 0x4)
67 #define GPIO_EDGE_MASK_ARMADAXP_OFF(cpu) (0x10 + (cpu) * 0x4)
68 #define GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu) (0x20 + (cpu) * 0x4)
70 #define MVEBU_GPIO_SOC_VARIANT_ORION 0x1
71 #define MVEBU_GPIO_SOC_VARIANT_MV78200 0x2
72 #define MVEBU_GPIO_SOC_VARIANT_ARMADAXP 0x3
74 #define MVEBU_MAX_GPIO_PER_BANK 32
181 static void mvebu_gpio_set(
struct gpio_chip *
chip,
unsigned pin,
int value)
194 writel_relaxed(u, mvebu_gpioreg_out(mvchip));
195 spin_unlock_irqrestore(&mvchip->
lock, flags);
198 static int mvebu_gpio_get(
struct gpio_chip *chip,
unsigned pin)
204 if (
readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin)) {
211 return (u >> pin) & 1;
214 static void mvebu_gpio_blink(
struct gpio_chip *chip,
unsigned pin,
int value)
227 writel_relaxed(u, mvebu_gpioreg_blink(mvchip));
228 spin_unlock_irqrestore(&mvchip->
lock, flags);
231 static int mvebu_gpio_direction_input(
struct gpio_chip *chip,
unsigned pin)
248 writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip));
249 spin_unlock_irqrestore(&mvchip->
lock, flags);
254 static int mvebu_gpio_direction_output(
struct gpio_chip *chip,
unsigned pin,
269 mvebu_gpio_blink(chip, pin, 0);
270 mvebu_gpio_set(chip, pin, value);
275 writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip));
276 spin_unlock_irqrestore(&mvchip->
lock, flags);
281 static int mvebu_gpio_to_irq(
struct gpio_chip *chip,
unsigned pin)
291 static void mvebu_gpio_irq_ack(
struct irq_data *
d)
293 struct irq_chip_generic *
gc = irq_data_get_irq_chip_data(d);
298 writel_relaxed(mask, mvebu_gpioreg_edge_cause(mvchip));
302 static void mvebu_gpio_edge_irq_mask(
struct irq_data *d)
304 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
306 u32 mask = 1 << (d->
irq - gc->irq_base);
309 gc->mask_cache &= ~mask;
310 writel_relaxed(gc->mask_cache, mvebu_gpioreg_edge_mask(mvchip));
314 static void mvebu_gpio_edge_irq_unmask(
struct irq_data *d)
316 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
318 u32 mask = 1 << (d->
irq - gc->irq_base);
321 gc->mask_cache |=
mask;
322 writel_relaxed(gc->mask_cache, mvebu_gpioreg_edge_mask(mvchip));
326 static void mvebu_gpio_level_irq_mask(
struct irq_data *d)
328 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
330 u32 mask = 1 << (d->
irq - gc->irq_base);
333 gc->mask_cache &= ~mask;
334 writel_relaxed(gc->mask_cache, mvebu_gpioreg_level_mask(mvchip));
338 static void mvebu_gpio_level_irq_unmask(
struct irq_data *d)
340 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
342 u32 mask = 1 << (d->
irq - gc->irq_base);
345 gc->mask_cache |=
mask;
346 writel_relaxed(gc->mask_cache, mvebu_gpioreg_level_mask(mvchip));
376 static int mvebu_gpio_irq_set_type(
struct irq_data *d,
unsigned int type)
378 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
379 struct irq_chip_type *
ct = irq_data_get_chip_type(d);
396 if (!(ct->type & type))
408 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip));
414 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip));
430 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip));
437 static void mvebu_gpio_irq_handler(
unsigned int irq,
struct irq_desc *
desc)
451 for (i = 0; i < mvchip->
chip.ngpio; i++) {
456 if (!(cause & (1 << i)))
466 writel_relaxed(polarity, mvebu_gpioreg_in_pol(mvchip));
474 .name =
"orion-gpio",
476 .name =
"mv78200-gpio",
478 .name =
"armadaxp-gpio",
487 .compatible =
"marvell,orion-gpio",
491 .compatible =
"marvell,mv78200-gpio",
495 .compatible =
"marvell,armadaxp-gpio",
510 struct irq_chip_generic *gc;
511 struct irq_chip_type *
ct;
518 soc_variant = (
int) match->
data;
524 dev_err(&pdev->
dev,
"Cannot get memory resource\n");
530 dev_err(&pdev->
dev,
"Cannot allocate memory\n");
534 if (of_property_read_u32(pdev->
dev.of_node,
"ngpios", &ngpios)) {
535 dev_err(&pdev->
dev,
"Missing ngpios OF property\n");
546 mvchip->
chip.label = dev_name(&pdev->
dev);
549 mvchip->
chip.direction_input = mvebu_gpio_direction_input;
550 mvchip->
chip.get = mvebu_gpio_get;
551 mvchip->
chip.direction_output = mvebu_gpio_direction_output;
552 mvchip->
chip.set = mvebu_gpio_set;
553 mvchip->
chip.to_irq = mvebu_gpio_to_irq;
555 mvchip->
chip.ngpio = ngpios;
556 mvchip->
chip.can_sleep = 0;
558 mvchip->
chip.of_node = np;
574 dev_err(&pdev->
dev,
"Cannot get memory resource\n");
590 switch(soc_variant) {
598 for (cpu = 0; cpu < 2; cpu++) {
599 writel_relaxed(0, mvchip->
membase +
601 writel_relaxed(0, mvchip->
membase +
609 for (cpu = 0; cpu < 4; cpu++) {
631 for (i = 0; i < 4; i++) {
637 irq_set_chained_handler(irq, mvebu_gpio_irq_handler);
640 mvchip->
irqbase = irq_alloc_descs(-1, 0, ngpios, -1);
650 dev_err(&pdev->
dev,
"Cannot allocate generic irq_chip\n");
655 gc->private = mvchip;
656 ct = &gc->chip_types[0];
658 ct->chip.irq_mask = mvebu_gpio_level_irq_mask;
659 ct->chip.irq_unmask = mvebu_gpio_level_irq_unmask;
660 ct->chip.irq_set_type = mvebu_gpio_irq_set_type;
661 ct->chip.name = mvchip->
chip.label;
663 ct = &gc->chip_types[1];
665 ct->chip.irq_ack = mvebu_gpio_irq_ack;
666 ct->chip.irq_mask = mvebu_gpio_edge_irq_mask;
667 ct->chip.irq_unmask = mvebu_gpio_edge_irq_unmask;
668 ct->chip.irq_set_type = mvebu_gpio_irq_set_type;
670 ct->chip.name = mvchip->
chip.label;
681 dev_err(&pdev->
dev,
"couldn't allocate irq domain %s (DT).\n",
695 .name =
"mvebu-gpio",
697 .of_match_table = mvebu_gpio_of_match,
699 .probe = mvebu_gpio_probe,
700 .id_table = mvebu_gpio_ids,
703 static int __init mvebu_gpio_init(
void)