[PATCH v2] arm/imx/gpio: add spinlock protection

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Thu Jul 29 02:42:41 EDT 2010


Hey Sascha,

On Tue, Jul 06, 2010 at 02:03:22PM +0300, Baruch Siach wrote:
> The GPIO registers need protection from concurrent access for operations that
> are not atomic.
> 
> Cc: stable at kernel.org
> Cc: Juergen Beisert <j.beisert at pengutronix.de>
> Cc: Daniel Mack <daniel at caiaq.de>
> Reported-by: rpkamiak at rockwellcollins.com
> Signed-off-by: Baruch Siach <baruch at tkos.co.il>
> ---
> Changes v1 -> v2
> 
>     Remove redundant protection of GPIO/IRQ registers

> 
>  arch/arm/plat-mxc/gpio.c              |    8 ++++++++
>  arch/arm/plat-mxc/include/mach/gpio.h |    1 +
>  2 files changed, 9 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/plat-mxc/gpio.c b/arch/arm/plat-mxc/gpio.c
> index 71437c6..9ebbd31 100644
> --- a/arch/arm/plat-mxc/gpio.c
> +++ b/arch/arm/plat-mxc/gpio.c
> @@ -214,13 +214,16 @@ static void _set_gpio_direction(struct gpio_chip *chip, unsigned offset,
>  	struct mxc_gpio_port *port =
>  		container_of(chip, struct mxc_gpio_port, chip);
>  	u32 l;
> +	unsigned long flags;
>  
> +	spin_lock_irqsave(&port->lock, flags);
>  	l = __raw_readl(port->base + GPIO_GDIR);
>  	if (dir)
>  		l |= 1 << offset;
>  	else
>  		l &= ~(1 << offset);
>  	__raw_writel(l, port->base + GPIO_GDIR);
> +	spin_unlock_irqrestore(&port->lock, flags);
>  }
>  
>  static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
> @@ -229,9 +232,12 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
>  		container_of(chip, struct mxc_gpio_port, chip);
>  	void __iomem *reg = port->base + GPIO_DR;
>  	u32 l;
> +	unsigned long flags;
>  
> +	spin_lock_irqsave(&port->lock, flags);
>  	l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
>  	__raw_writel(l, reg);
> +	spin_unlock_irqrestore(&port->lock, flags);
>  }
>  
>  static int mxc_gpio_get(struct gpio_chip *chip, unsigned offset)
> @@ -285,6 +291,8 @@ int __init mxc_gpio_init(struct mxc_gpio_port *port, int cnt)
>  		port[i].chip.base = i * 32;
>  		port[i].chip.ngpio = 32;
>  
> +		spin_lock_init(&port[i].lock);
> +
>  		/* its a serious configuration bug when it fails */
>  		BUG_ON( gpiochip_add(&port[i].chip) < 0 );
>  
> diff --git a/arch/arm/plat-mxc/include/mach/gpio.h b/arch/arm/plat-mxc/include/mach/gpio.h
> index 894d2f8..6bd932c 100644
> --- a/arch/arm/plat-mxc/include/mach/gpio.h
> +++ b/arch/arm/plat-mxc/include/mach/gpio.h
> @@ -36,6 +36,7 @@ struct mxc_gpio_port {
>  	int virtual_irq_start;
>  	struct gpio_chip chip;
>  	u32 both_edges;
> +	spinlock_t lock;
>  };
>  
>  int mxc_gpio_init(struct mxc_gpio_port*, int);

can you please fold this into Baruch's patch:

diff --git a/arch/arm/plat-mxc/include/mach/gpio.h b/arch/arm/plat-mxc/include/mach/gpio.h
index 661fbc6..af33b74 100644
--- a/arch/arm/plat-mxc/include/mach/gpio.h
+++ b/arch/arm/plat-mxc/include/mach/gpio.h
@@ -19,6 +19,7 @@
 #ifndef __ASM_ARCH_MXC_GPIO_H__
 #define __ASM_ARCH_MXC_GPIO_H__
 
+#include <linux/spinlock.h>
 #include <mach/hardware.h>
 #include <asm-generic/gpio.h>
 
This fixes a build failure with mx27_defconfig.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |



More information about the linux-arm-kernel mailing list