Skip to contentSkip to conversation

mach-ixp4xx: made gpio functions atomic

PATCH New Frans Meulenbroeks 2 participants 4 messages Oct 30, 2011 – Jan 3, 2012 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mach-ixp4xx: made gpio functions atomic

gpio_line_set and gpio_line config on ixp4xx were not atomic This patch fixes this by surrounding them with local_irq_save and local_irq_restore calls, similar to the way Lennert Buytenhek implemented this for iop. (see arch/arm/plat-iop/gpio.c)

---

Note: an alternative solution would be to use the set_bit and clear_bit atomic functions, but I felt it better to do things the same way as Lennert did. Also it could be that this is a few bytes smaller. Didn't check that.

arch/arm/mach-ixp4xx/include/mach/platform.h renamed from arch/arm/mach-ixp4xx/include/mach/platform.h.orig +10 -0
@@ -14,6 +14,8 @@
 #ifndef __ASSEMBLY__
 
 #include <asm/types.h>
+#include <asm/system.h>
+#include <linux/kernel.h>
 
 #ifndef	__ARMEB__
 #define	REG_OFFSET	0
@@ -150,10 +152,14 @@
 
 static inline void gpio_line_config(u8 line, u32 direction)
 {
+	unsigned long flags;
+
+	local_irq_save(flags);
 	if (direction == IXP4XX_GPIO_IN)
 		*IXP4XX_GPIO_GPOER |= (1 << line);
 	else
 		*IXP4XX_GPIO_GPOER &= ~(1 << line);
+	local_irq_restore(flags);
 }
 
 static inline void gpio_line_get(u8 line, int *value)
@@ -163,10 +169,14 @@
 
 static inline void gpio_line_set(u8 line, int value)
 {
+	unsigned long flags;
+
+	local_irq_save(flags);
 	if (value == IXP4XX_GPIO_HIGH)
 	    *IXP4XX_GPIO_GPOUTR |= (1 << line);
 	else if (value == IXP4XX_GPIO_LOW)
 	    *IXP4XX_GPIO_GPOUTR &= ~(1 << line);
+	local_irq_restore(flags);
 }
 
 #endif // __ASSEMBLY__
#1 lore raw

PATCH 1/1 mach-ixp4xx: made gpio functions atomic

Quoted 5 lines · Frans Meulenbroeks

gpio_line_set and gpio_line config on ixp4xx were not atomic This patch fixes this by surrounding them with local_irq_save and local_irq_restore calls, similar to the way Lennert Buytenhek implemented this for iop. (see arch/arm/plat-iop/gpio.c)

Quoted 7 lines

---

Note: an alternative solution would be to use the set_bit and clear_bit atomic functions, but I felt it better to do things the same way as Lennert did. Also it could be that this is a few bytes smaller. Didn't check that.

set_bit and clear_bit should not be used on IO memory - on ARMv6 and later these use the load exclusive/store exclusive operations which are only valid on 'normal memory' mappings and not 'device' mappings.

Plus of course, IO memory is supposed to be __iomem and accessed using the proper accessors, and using set_bit and clear_bit on such pointers will issue sparse warnings.

#3 lore raw

PATCH 1/1 mach-ixp4xx: made gpio functions atomic

In reply to a message not in the archive
Quoted 1 line · Frans Meulenbroeks

May I consider the patch accepted or is some rework needed?

Neither, I was just commenting on it. MAINTAINERS says:

ARM/INTEL IXP4XX ARM ARCHITECTURE

M:      Imre Kaloz <[email protected]>
M:      Krzysztof Halasa <[email protected]>
L:      linux-arm-kernel at lists.infradead.org (moderated for non-subscribers)
S:      Maintained
F:      arch/arm/mach-ixp4xx/

It would be a good idea to have acks from Imre and/or Krzysztof, even better if they can apply it themselves.

#5 lore raw

PATCH 1/1 mach-ixp4xx: made gpio functions atomic

In reply to a message not in the archive
Quoted 5 lines · Frans Meulenbroeks

Ping.

Didn't hear anything concerning this patch I submitted 2 months ago. Seems a very trivial patch to me. Would it be possible to apply this (or provide feedback why it is not ok).

This should really be using the gpiolib stuff rather than persisting with its own private gpio API invention (and fixing problems in it which gpiolib already solves.)

Any chance someone could look into doing that conversion?