cregit-Linux how code gets into the kernel

Release 4.11 drivers/gpio/gpio-mvebu.c

Directory: drivers/gpio
/*
 * GPIO driver for Marvell SoCs
 *
 * Copyright (C) 2012 Marvell
 *
 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
 * Andrew Lunn <andrew@lunn.ch>
 * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 *
 * This driver is a fairly straightforward GPIO driver for the
 * complete family of Marvell EBU SoC platforms (Orion, Dove,
 * Kirkwood, Discovery, Armada 370/XP). The only complexity of this
 * driver is the different register layout that exists between the
 * non-SMP platforms (Orion, Dove, Kirkwood, Armada 370) and the SMP
 * platforms (MV78200 from the Discovery family and the Armada
 * XP). Therefore, this driver handles three variants of the GPIO
 * block:
 * - the basic variant, called "orion-gpio", with the simplest
 *   register set. Used on Orion, Dove, Kirkwoord, Armada 370 and
 *   non-SMP Discovery systems
 * - the mv78200 variant for MV78200 Discovery systems. This variant
 *   turns the edge mask and level mask registers into CPU0 edge
 *   mask/level mask registers, and adds CPU1 edge mask/level mask
 *   registers.
 * - the armadaxp variant for Armada XP systems. This variant keeps
 *   the normal cause/edge mask/level mask registers when the global
 *   interrupts are used, but adds per-CPU cause/edge mask/level mask
 *   registers n a separate memory area for the per-CPU GPIO
 *   interrupts.
 */

#include <linux/err.h>
#include <linux/init.h>
#include <linux/gpio.h>
#include <linux/irq.h>
#include <linux/slab.h>
#include <linux/irqdomain.h>
#include <linux/io.h>
#include <linux/of_irq.h>
#include <linux/of_device.h>
#include <linux/clk.h>
#include <linux/pinctrl/consumer.h>
#include <linux/irqchip/chained_irq.h>

/*
 * GPIO unit register offsets.
 */

#define GPIO_OUT_OFF		0x0000

#define GPIO_IO_CONF_OFF	0x0004

#define GPIO_BLINK_EN_OFF	0x0008

#define GPIO_IN_POL_OFF		0x000c

#define GPIO_DATA_IN_OFF	0x0010

#define GPIO_EDGE_CAUSE_OFF	0x0014

#define GPIO_EDGE_MASK_OFF	0x0018

#define GPIO_LEVEL_MASK_OFF	0x001c

/* The MV78200 has per-CPU registers for edge mask and level mask */

#define GPIO_EDGE_MASK_MV78200_OFF(cpu)	  ((cpu) ? 0x30 : 0x18)

#define GPIO_LEVEL_MASK_MV78200_OFF(cpu)  ((cpu) ? 0x34 : 0x1C)

/* The Armada XP has per-CPU registers for interrupt cause, interrupt
 * mask and interrupt level mask. Those are relative to the
 * percpu_membase. */

#define GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu) ((cpu) * 0x4)

#define GPIO_EDGE_MASK_ARMADAXP_OFF(cpu)  (0x10 + (cpu) * 0x4)

#define GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu) (0x20 + (cpu) * 0x4)


#define MVEBU_GPIO_SOC_VARIANT_ORION	0x1

#define MVEBU_GPIO_SOC_VARIANT_MV78200	0x2

#define MVEBU_GPIO_SOC_VARIANT_ARMADAXP 0x3


#define MVEBU_MAX_GPIO_PER_BANK		32


struct mvebu_gpio_chip {
	
struct gpio_chip   chip;
	
spinlock_t	   lock;
	
void __iomem	  *membase;
	
void __iomem	  *percpu_membase;
	
int		   irqbase;
	
struct irq_domain *domain;
	
int		   soc_variant;

	/* Used to preserve GPIO registers across suspend/resume */
	
u32                out_reg;
	
u32                io_conf_reg;
	
u32                blink_en_reg;
	
u32                in_pol_reg;
	
u32                edge_mask_regs[4];
	
u32                level_mask_regs[4];
};

/*
 * Functions returning addresses of individual registers for a given
 * GPIO controller.
 */

static inline void __iomem *mvebu_gpioreg_out(struct mvebu_gpio_chip *mvchip) { return mvchip->membase + GPIO_OUT_OFF; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni21100.00%1100.00%
Total21100.00%1100.00%


static inline void __iomem *mvebu_gpioreg_blink(struct mvebu_gpio_chip *mvchip) { return mvchip->membase + GPIO_BLINK_EN_OFF; }

Contributors

PersonTokensPropCommitsCommitProp
Jamie Lentin21100.00%1100.00%
Total21100.00%1100.00%


static inline void __iomem * mvebu_gpioreg_io_conf(struct mvebu_gpio_chip *mvchip) { return mvchip->membase + GPIO_IO_CONF_OFF; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni21100.00%1100.00%
Total21100.00%1100.00%


static inline void __iomem *mvebu_gpioreg_in_pol(struct mvebu_gpio_chip *mvchip) { return mvchip->membase + GPIO_IN_POL_OFF; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni21100.00%1100.00%
Total21100.00%1100.00%


static inline void __iomem * mvebu_gpioreg_data_in(struct mvebu_gpio_chip *mvchip) { return mvchip->membase + GPIO_DATA_IN_OFF; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni21100.00%1100.00%
Total21100.00%1100.00%


static inline void __iomem * mvebu_gpioreg_edge_cause(struct mvebu_gpio_chip *mvchip) { int cpu; switch (mvchip->soc_variant) { case MVEBU_GPIO_SOC_VARIANT_ORION: case MVEBU_GPIO_SOC_VARIANT_MV78200: return mvchip->membase + GPIO_EDGE_CAUSE_OFF; case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: cpu = smp_processor_id(); return mvchip->percpu_membase + GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu); default: BUG(); } }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni60100.00%1100.00%
Total60100.00%1100.00%


static inline void __iomem * mvebu_gpioreg_edge_mask(struct mvebu_gpio_chip *mvchip) { int cpu; switch (mvchip->soc_variant) { case MVEBU_GPIO_SOC_VARIANT_ORION: return mvchip->membase + GPIO_EDGE_MASK_OFF; case MVEBU_GPIO_SOC_VARIANT_MV78200: cpu = smp_processor_id(); return mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(cpu); case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: cpu = smp_processor_id(); return mvchip->percpu_membase + GPIO_EDGE_MASK_ARMADAXP_OFF(cpu); default: BUG(); } }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni75100.00%1100.00%
Total75100.00%1100.00%


static void __iomem *mvebu_gpioreg_level_mask(struct mvebu_gpio_chip *mvchip) { int cpu; switch (mvchip->soc_variant) { case MVEBU_GPIO_SOC_VARIANT_ORION: return mvchip->membase + GPIO_LEVEL_MASK_OFF; case MVEBU_GPIO_SOC_VARIANT_MV78200: cpu = smp_processor_id(); return mvchip->membase + GPIO_LEVEL_MASK_MV78200_OFF(cpu); case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: cpu = smp_processor_id(); return mvchip->percpu_membase + GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu); default: BUG(); } }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni74100.00%1100.00%
Total74100.00%1100.00%

/* * Functions implementing the gpio_chip methods */
static void mvebu_gpio_set(struct gpio_chip *chip, unsigned pin, int value) { struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); unsigned long flags; u32 u; spin_lock_irqsave(&mvchip->lock, flags); u = readl_relaxed(mvebu_gpioreg_out(mvchip)); if (value) u |= 1 << pin; else u &= ~(1 << pin); writel_relaxed(u, mvebu_gpioreg_out(mvchip)); spin_unlock_irqrestore(&mvchip->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni9398.94%150.00%
Linus Walleij11.06%150.00%
Total94100.00%2100.00%


static int mvebu_gpio_get(struct gpio_chip *chip, unsigned pin) { struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); u32 u; if (readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin)) { u = readl_relaxed(mvebu_gpioreg_data_in(mvchip)) ^ readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); } else { u = readl_relaxed(mvebu_gpioreg_out(mvchip)); } return (u >> pin) & 1; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni8498.82%150.00%
Linus Walleij11.18%150.00%
Total85100.00%2100.00%


static void mvebu_gpio_blink(struct gpio_chip *chip, unsigned pin, int value) { struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); unsigned long flags; u32 u; spin_lock_irqsave(&mvchip->lock, flags); u = readl_relaxed(mvebu_gpioreg_blink(mvchip)); if (value) u |= 1 << pin; else u &= ~(1 << pin); writel_relaxed(u, mvebu_gpioreg_blink(mvchip)); spin_unlock_irqrestore(&mvchip->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Jamie Lentin9398.94%150.00%
Linus Walleij11.06%150.00%
Total94100.00%2100.00%


static int mvebu_gpio_direction_input(struct gpio_chip *chip, unsigned pin) { struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); unsigned long flags; int ret; u32 u; /* Check with the pinctrl driver whether this pin is usable as * an input GPIO */ ret = pinctrl_gpio_direction_input(chip->base + pin); if (ret) return ret; spin_lock_irqsave(&mvchip->lock, flags); u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)); u |= 1 << pin; writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip)); spin_unlock_irqrestore(&mvchip->lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni10199.02%150.00%
Linus Walleij10.98%150.00%
Total102100.00%2100.00%


static int mvebu_gpio_direction_output(struct gpio_chip *chip, unsigned pin, int value) { struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); unsigned long flags; int ret; u32 u; /* Check with the pinctrl driver whether this pin is usable as * an output GPIO */ ret = pinctrl_gpio_direction_output(chip->base + pin); if (ret) return ret; mvebu_gpio_blink(chip, pin, 0); mvebu_gpio_set(chip, pin, value); spin_lock_irqsave(&mvchip->lock, flags); u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)); u &= ~(1 << pin); writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip)); spin_unlock_irqrestore(&mvchip->lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni11692.06%250.00%
Jamie Lentin97.14%125.00%
Linus Walleij10.79%125.00%
Total126100.00%4100.00%


static int mvebu_gpio_to_irq(struct gpio_chip *chip, unsigned pin) { struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); return irq_create_mapping(mvchip->domain, pin); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni3397.06%150.00%
Linus Walleij12.94%150.00%
Total34100.00%2100.00%

/* * Functions implementing the irq_chip methods */
static void mvebu_gpio_irq_ack(struct irq_data *d) { struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); struct mvebu_gpio_chip *mvchip = gc->private; u32 mask = d->mask; irq_gc_lock(gc); writel_relaxed(~mask, mvebu_gpioreg_edge_cause(mvchip)); irq_gc_unlock(gc); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni5696.55%150.00%
Jason Gunthorpe23.45%150.00%
Total58100.00%2100.00%


static void mvebu_gpio_edge_irq_mask(struct irq_data *d) { struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); struct mvebu_gpio_chip *mvchip = gc->private; struct irq_chip_type *ct = irq_data_get_chip_type(d); u32 mask = d->mask; irq_gc_lock(gc); ct->mask_cache_priv &= ~mask; writel_relaxed(ct->mask_cache_priv, mvebu_gpioreg_edge_mask(mvchip)); irq_gc_unlock(gc); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni6180.26%133.33%
Gregory CLEMENT1418.42%133.33%
Jason Gunthorpe11.32%133.33%
Total76100.00%3100.00%


static void mvebu_gpio_edge_irq_unmask(struct irq_data *d) { struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); struct mvebu_gpio_chip *mvchip = gc->private; struct irq_chip_type *ct = irq_data_get_chip_type(d); u32 mask = d->mask; irq_gc_lock(gc); ct->mask_cache_priv |= mask; writel_relaxed(ct->mask_cache_priv, mvebu_gpioreg_edge_mask(mvchip)); irq_gc_unlock(gc); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni6080.00%133.33%
Gregory CLEMENT1418.67%133.33%
Jason Gunthorpe11.33%133.33%
Total75100.00%3100.00%


static void mvebu_gpio_level_irq_mask(struct irq_data *d) { struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); struct mvebu_gpio_chip *mvchip = gc->private; struct irq_chip_type *ct = irq_data_get_chip_type(d); u32 mask = d->mask; irq_gc_lock(gc); ct->mask_cache_priv &= ~mask; writel_relaxed(ct->mask_cache_priv, mvebu_gpioreg_level_mask(mvchip)); irq_gc_unlock(gc); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni6180.26%133.33%
Gregory CLEMENT1418.42%133.33%
Jason Gunthorpe11.32%133.33%
Total76100.00%3100.00%


static void mvebu_gpio_level_irq_unmask(struct irq_data *d) { struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); struct mvebu_gpio_chip *mvchip = gc->private; struct irq_chip_type *ct = irq_data_get_chip_type(d); u32 mask = d->mask; irq_gc_lock(gc); ct->mask_cache_priv |= mask; writel_relaxed(ct->mask_cache_priv, mvebu_gpioreg_level_mask(mvchip)); irq_gc_unlock(gc); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni6080.00%133.33%
Gregory CLEMENT1418.67%133.33%
Jason Gunthorpe11.33%133.33%
Total75100.00%3100.00%

/***************************************************************************** * MVEBU GPIO IRQ * * GPIO_IN_POL register controls whether GPIO_DATA_IN will hold the same * value of the line or the opposite value. * * Level IRQ handlers: DATA_IN is used directly as cause register. * Interrupt are masked by LEVEL_MASK registers. * Edge IRQ handlers: Change in DATA_IN are latched in EDGE_CAUSE. * Interrupt are masked by EDGE_MASK registers. * Both-edge handlers: Similar to regular Edge handlers, but also swaps * the polarity to catch the next line transaction. * This is a race condition that might not perfectly * work on some use cases. * * Every eight GPIO lines are grouped (OR'ed) before going up to main * cause register. * * EDGE cause mask * data-in /--------| |-----| |----\ * -----| |----- ---- to main cause reg * X \----------------| |----/ * polarity LEVEL mask * ****************************************************************************/
static int mvebu_gpio_irq_set_type(struct irq_data *d, unsigned int type) { struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); struct irq_chip_type *ct = irq_data_get_chip_type(d); struct mvebu_gpio_chip *mvchip = gc->private; int pin; u32 u; pin = d->hwirq; u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin); if (!u) return -EINVAL; type &= IRQ_TYPE_SENSE_MASK; if (type == IRQ_TYPE_NONE) return -EINVAL; /* Check if we need to change chip and handler */ if (!(ct->type & type)) if (irq_setup_alt_chip(d, type)) return -EINVAL; /* * Configure interrupt polarity. */ switch (type) { case IRQ_TYPE_EDGE_RISING: case IRQ_TYPE_LEVEL_HIGH: u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); u &= ~(1 << pin); writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); break; case IRQ_TYPE_EDGE_FALLING: case IRQ_TYPE_LEVEL_LOW: u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); u |= 1 << pin; writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); break; case IRQ_TYPE_EDGE_BOTH: { u32 v; v = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)) ^ readl_relaxed(mvebu_gpioreg_data_in(mvchip)); /* * set initial polarity based on current input level */ u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); if (v & (1 << pin)) u |= 1 << pin; /* falling */ else u &= ~(1 << pin); /* rising */ writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); break; } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni27298.91%150.00%
Axel Lin31.09%150.00%
Total275100.00%2100.00%


static void mvebu_gpio_irq_handler(struct irq_desc *desc) { struct mvebu_gpio_chip *mvchip = irq_desc_get_handler_data(desc); struct irq_chip *chip = irq_desc_get_chip(desc); u32 cause, type; int i; if (mvchip == NULL) return; chained_irq_enter(chip, desc); cause = readl_relaxed(mvebu_gpioreg_data_in(mvchip)) & readl_relaxed(mvebu_gpioreg_level_mask(mvchip)); cause |= readl_relaxed(mvebu_gpioreg_edge_cause(mvchip)) & readl_relaxed(mvebu_gpioreg_edge_mask(mvchip)); for (i = 0; i < mvchip->chip.ngpio; i++) { int irq; irq = irq_find_mapping(mvchip->domain, i); if (!(cause & (1 << i))) continue; type = irq_get_trigger_type(irq); if ((type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) { /* Swap polarity (race with GPIO line) */ u32 polarity; polarity = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); polarity ^= 1 << i; writel_relaxed(polarity, mvebu_gpioreg_in_pol(mvchip)); } generic_handle_irq(irq); } chained_irq_exit(chip, desc); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni18995.94%240.00%
Jason Gunthorpe52.54%120.00%
Jiang Liu21.02%120.00%
Javier Martinez Canillas10.51%120.00%
Total197100.00%5100.00%

#ifdef CONFIG_DEBUG_FS #include <linux/seq_file.h>
static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) { struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk; int i; out = readl_relaxed(mvebu_gpioreg_out(mvchip)); io_conf = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)); blink = readl_relaxed(mvebu_gpioreg_blink(mvchip)); in_pol = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); data_in = readl_relaxed(mvebu_gpioreg_data_in(mvchip)); cause = readl_relaxed(mvebu_gpioreg_edge_cause(mvchip)); edg_msk = readl_relaxed(mvebu_gpioreg_edge_mask(mvchip)); lvl_msk = readl_relaxed(mvebu_gpioreg_level_mask(mvchip)); for (i = 0; i < chip->ngpio; i++) { const char *label; u32 msk; bool is_out; label = gpiochip_is_requested(chip, i); if (!label) continue; msk = 1 << i; is_out = !(io_conf & msk); seq_printf(s, " gpio-%-3d (%-20.20s)", chip->base + i, label); if (is_out) { seq_printf(s, " out %s %s\n", out & msk ? "hi" : "lo", blink & msk ? "(blink )" : ""); continue; } seq_printf(s, " in %s (act %s) - IRQ", (data_in ^ in_pol) & msk ? "hi" : "lo", in_pol & msk ? "lo" : "hi"); if (!((edg_msk | lvl_msk) & msk)) { seq_puts(s, " disabled\n"); continue; } if (edg_msk & msk) seq_puts(s, " edge "); if (lvl_msk & msk) seq_puts(s, " level"); seq_printf(s, " (%s)\n", cause & msk ? "pending" : "clear "); } }

Contributors

PersonTokensPropCommitsCommitProp
Simon Guinot31698.75%133.33%
Andrew Lunn30.94%133.33%
Linus Walleij10.31%133.33%
Total320100.00%3100.00%

#else #define mvebu_gpio_dbg_show NULL #endif static const struct of_device_id mvebu_gpio_of_match[] = { { .compatible = "marvell,orion-gpio", .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION, }, { .compatible = "marvell,mv78200-gpio", .data = (void *) MVEBU_GPIO_SOC_VARIANT_MV78200, }, { .compatible = "marvell,armadaxp-gpio", .data = (void *) MVEBU_GPIO_SOC_VARIANT_ARMADAXP, }, { /* sentinel */ }, };
static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state) { struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev); int i; mvchip->out_reg = readl(mvebu_gpioreg_out(mvchip)); mvchip->io_conf_reg = readl(mvebu_gpioreg_io_conf(mvchip)); mvchip->blink_en_reg = readl(mvebu_gpioreg_blink(mvchip)); mvchip->in_pol_reg = readl(mvebu_gpioreg_in_pol(mvchip)); switch (mvchip->soc_variant) { case MVEBU_GPIO_SOC_VARIANT_ORION: mvchip->edge_mask_regs[0] = readl(mvchip->membase + GPIO_EDGE_MASK_OFF); mvchip->level_mask_regs[0] = readl(mvchip->membase + GPIO_LEVEL_MASK_OFF); break; case MVEBU_GPIO_SOC_VARIANT_MV78200: for (i = 0; i < 2; i++) { mvchip->edge_mask_regs[i] = readl(mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(i)); mvchip->level_mask_regs[i] = readl(mvchip->membase + GPIO_LEVEL_MASK_MV78200_OFF(i)); } break; case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: for (i = 0; i < 4; i++) { mvchip->edge_mask_regs[i] = readl(mvchip->membase + GPIO_EDGE_MASK_ARMADAXP_OFF(i)); mvchip->level_mask_regs[i] = readl(mvchip->membase + GPIO_LEVEL_MASK_ARMADAXP_OFF(i)); } break; default: BUG(); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni240100.00%1100.00%
Total240100.00%1100.00%


static int mvebu_gpio_resume(struct platform_device *pdev) { struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev); int i; writel(mvchip->out_reg, mvebu_gpioreg_out(mvchip)); writel(mvchip->io_conf_reg, mvebu_gpioreg_io_conf(mvchip)); writel(mvchip->blink_en_reg, mvebu_gpioreg_blink(mvchip)); writel(mvchip->in_pol_reg, mvebu_gpioreg_in_pol(mvchip)); switch (mvchip->soc_variant) { case MVEBU_GPIO_SOC_VARIANT_ORION: writel(mvchip->edge_mask_regs[0], mvchip->membase + GPIO_EDGE_MASK_OFF); writel(mvchip->level_mask_regs[0], mvchip->membase + GPIO_LEVEL_MASK_OFF); break; case MVEBU_GPIO_SOC_VARIANT_MV78200: for (i = 0; i < 2; i++) { writel(mvchip->edge_mask_regs[i], mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(i)); writel(mvchip->level_mask_regs[i], mvchip->membase + GPIO_LEVEL_MASK_MV78200_OFF(i)); } break; case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: for (i = 0; i < 4; i++) { writel(mvchip->edge_mask_regs[i], mvchip->membase + GPIO_EDGE_MASK_ARMADAXP_OFF(i)); writel(mvchip->level_mask_regs[i], mvchip->membase + GPIO_LEVEL_MASK_ARMADAXP_OFF(i)); } break; default: BUG(); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni237100.00%1100.00%
Total237100.00%1100.00%


static int mvebu_gpio_probe(struct platform_device *pdev) { struct mvebu_gpio_chip *mvchip; const struct of_device_id *match; struct device_node *np = pdev->dev.of_node; struct resource *res; struct irq_chip_generic *gc; struct irq_chip_type *ct; struct clk *clk; unsigned int ngpios; bool have_irqs; int soc_variant; int i, cpu, id; int err; match = of_match_device(mvebu_gpio_of_match, &pdev->dev); if (match) soc_variant = (unsigned long) match->data; else soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; /* Some gpio controllers do not provide irq support */ have_irqs = of_irq_count(np) != 0; mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), GFP_KERNEL); if (!mvchip) return -ENOMEM; platform_set_drvdata(pdev, mvchip); if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) { dev_err(&pdev->dev, "Missing ngpios OF property\n"); return -ENODEV; } id = of_alias_get_id(pdev->dev.of_node, "gpio"); if (id < 0) { dev_err(&pdev->dev, "Couldn't get OF id\n"); return id; } clk = devm_clk_get(&pdev->dev, NULL); /* Not all SoCs require a clock.*/ if (!IS_ERR(clk)) clk_prepare_enable(clk); mvchip->soc_variant = soc_variant; mvchip->chip.label = dev_name(&pdev->dev); mvchip->chip.parent = &pdev->dev; mvchip->chip.request = gpiochip_generic_request; mvchip->chip.free = gpiochip_generic_free; mvchip->chip.direction_input = mvebu_gpio_direction_input; mvchip->chip.get = mvebu_gpio_get; mvchip->chip.direction_output = mvebu_gpio_direction_output; mvchip->chip.set = mvebu_gpio_set; if (have_irqs) mvchip->chip.to_irq = mvebu_gpio_to_irq; mvchip->chip.base = id * MVEBU_MAX_GPIO_PER_BANK; mvchip->chip.ngpio = ngpios; mvchip->chip.can_sleep = false; mvchip->chip.of_node = np; mvchip->chip.dbg_show = mvebu_gpio_dbg_show; spin_lock_init(&mvchip->lock); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); mvchip->membase = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(mvchip->membase)) return PTR_ERR(mvchip->membase); /* The Armada XP has a second range of registers for the * per-CPU registers */ if (soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) { res = platform_get_resource(pdev, IORESOURCE_MEM, 1); mvchip->percpu_membase = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(mvchip->percpu_membase)) return PTR_ERR(mvchip->percpu_membase); } /* * Mask and clear GPIO interrupts. */ switch (soc_variant) { case MVEBU_GPIO_SOC_VARIANT_ORION: writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF); writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF); writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_OFF); break; case MVEBU_GPIO_SOC_VARIANT_MV78200: writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF); for (cpu = 0; cpu < 2; cpu++) { writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(cpu)); writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_MV78200_OFF(cpu)); } break; case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF); writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF); writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_OFF); for (cpu = 0; cpu < 4; cpu++) { writel_relaxed(0, mvchip->percpu_membase + GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu)); writel_relaxed(0, mvchip->percpu_membase + GPIO_EDGE_MASK_ARMADAXP_OFF(cpu)); writel_relaxed(0, mvchip->percpu_membase + GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu)); } break; default: BUG(); } devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip); /* Some gpio controllers do not provide irq support */ if (!have_irqs) return 0; mvchip->domain = irq_domain_add_linear(np, ngpios, &irq_generic_chip_ops, NULL); if (!mvchip->domain) { dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n", mvchip->chip.label); return -ENODEV; } err = irq_alloc_domain_generic_chips( mvchip->domain, ngpios, 2, np->name, handle_level_irq, IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_LEVEL, 0, 0); if (err) { dev_err(&pdev->dev, "couldn't allocate irq chips %s (DT).\n", mvchip->chip.label); goto err_domain; } /* NOTE: The common accessors cannot be used because of the percpu * access to the mask registers */ gc = irq_get_domain_generic_chip(mvchip->domain, 0); gc->private = mvchip; ct = &gc->chip_types[0]; ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW; ct->chip.irq_mask = mvebu_gpio_level_irq_mask; ct->chip.irq_unmask = mvebu_gpio_level_irq_unmask; ct->chip.irq_set_type = mvebu_gpio_irq_set_type; ct->chip.name = mvchip->chip.label; ct = &gc->chip_types[1]; ct->type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; ct->chip.irq_ack = mvebu_gpio_irq_ack; ct->chip.irq_mask = mvebu_gpio_edge_irq_mask; ct->chip.irq_unmask = mvebu_gpio_edge_irq_unmask; ct->chip.irq_set_type = mvebu_gpio_irq_set_type; ct->handler = handle_edge_irq; ct->chip.name = mvchip->chip.label; /* Setup the interrupt handlers. Each chip can have up to 4 * interrupt handlers, with each handler dealing with 8 GPIO * pins. */ for (i = 0; i < 4; i++) { int irq = platform_get_irq(pdev, i); if (irq < 0) continue; irq_set_chained_handler_and_data(irq, mvebu_gpio_irq_handler, mvchip); } return 0; err_domain: irq_domain_remove(mvchip->domain); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni78178.57%213.33%
Jason Gunthorpe11111.17%16.67%
Andrew Lunn404.02%213.33%
Thierry Reding202.01%16.67%
Julia Lawall111.11%16.67%
Simon Guinot80.80%16.67%
Laxman Dewangan80.80%16.67%
Axel Lin70.70%16.67%
Linus Walleij40.40%320.00%
Jonas Gorski20.20%16.67%
Russell King20.20%16.67%
Total994100.00%15100.00%

static struct platform_driver mvebu_gpio_driver = { .driver = { .name = "mvebu-gpio", .of_match_table = mvebu_gpio_of_match, }, .probe = mvebu_gpio_probe, .suspend = mvebu_gpio_suspend, .resume = mvebu_gpio_resume, }; builtin_platform_driver(mvebu_gpio_driver);

Overall Contributors

PersonTokensPropCommitsCommitProp
Thomas Petazzoni301379.84%415.38%
Simon Guinot3388.96%13.85%
Jamie Lentin1233.26%13.85%
Jason Gunthorpe1223.23%13.85%
Gregory CLEMENT561.48%13.85%
Andrew Lunn481.27%311.54%
Thierry Reding230.61%13.85%
Julia Lawall110.29%13.85%
Linus Walleij110.29%311.54%
Axel Lin100.26%27.69%
Laxman Dewangan80.21%13.85%
Jonas Gorski20.05%13.85%
Paul Gortmaker20.05%13.85%
Russell King20.05%13.85%
Jiang Liu20.05%13.85%
Ezequiel García10.03%13.85%
Jingoo Han10.03%13.85%
Javier Martinez Canillas10.03%13.85%
Bill Pemberton0.00%00.00%
Total3774100.00%26100.00%
Directory: drivers/gpio
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.