Re: [patch 2.6.20-rc1 5/6] SA1100 GPIO wrappers

From: pHilipp Zabel
Date: Sat Dec 30 2006 - 09:00:38 EST


On 12/30/06, David Brownell <david-b@xxxxxxxxxxx> wrote:
On Friday 29 December 2006 7:15 pm, Nicolas Pitre wrote:
> On Fri, 29 Dec 2006, David Brownell wrote:
>
> > Here's a version that compiles ...
>
> This patch is completely broken.

It's just what Philipp sent, with the "won't compile" bugs fixed.
Oh, and some #include tweaks. Philipp?

Corrected version attached. I also removed the out of line versions of
gpio_set/get_value.

> and you most probably need to protect the implied read-modify-write
> cycle with a spinlock unless the generic gpio API expects this
> protection is the responsibility of the caller.

No such lock is known to the caller. Some of those calls will need
to move to a C file somewhere.

Moved into generic.c

regards
Philipp

----------------------

Signed-off-by: Philipp Zabel <philipp.zabel@xxxxxxxxx>

Index: linux-2.6/include/asm-arm/arch-sa1100/gpio.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/include/asm-arm/arch-sa1100/gpio.h 2006-12-30
14:43:49.000000000 +0100
@@ -0,0 +1,72 @@
+/*
+ * linux/include/asm-arm/arch-sa1100/gpio.h
+ *
+ * SA1100 GPIO wrappers for arch-neutral GPIO calls
+ *
+ * Written by Philipp Zabel <philipp.zabel@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef __ASM_ARCH_SA1100_GPIO_H
+#define __ASM_ARCH_SA1100_GPIO_H
+
+#include <asm/hardware.h>
+#include <asm/irq.h>
+
+static inline int gpio_request(unsigned gpio, const char *label)
+{
+ return 0;
+}
+
+static inline void gpio_free(unsigned gpio)
+{
+ return;
+}
+
+#define gpio_direction_input sa1100_gpio_direction_output
+#define gpio_direction_output sa1100_gpio_direction_output
+
+static inline int gpio_get_value(unsigned gpio)
+{
+ return GPLR & GPIO_GPIO(gpio);
+}
+
+static inline void gpio_set_value(unsigned gpio, int value)
+{
+ if (value)
+ GPSR = GPIO_GPIO(gpio);
+ else
+ GPCR = GPIO_GPIO(gpio);
+}
+
+static inline unsigned gpio_to_irq(unsigned gpio)
+{
+ if (gpio < 11)
+ return IRQ_GPIO0 + gpio;
+ else
+ return IRQ_GPIO11 - 11 + gpio;
+}
+
+static inline unsigned irq_to_gpio(unsigned irq)
+{
+ if (irq < IRQ_GPIO11_27)
+ return irq - IRQ_GPIO0;
+ else
+ return irq - IRQ_GPIO11 + 11;
+}
+
+#endif /* __ASM_ARCH_SA1100_GPIO_H */
Index: linux-2.6/arch/arm/mach-sa1100/generic.c
===================================================================
--- linux-2.6.orig/arch/arm/mach-sa1100/generic.c 2006-12-27
21:50:03.000000000 +0100
+++ linux-2.6/arch/arm/mach-sa1100/generic.c 2006-12-30 14:50:42.000000000 +0100
@@ -138,6 +138,36 @@
return v;
}

+int sa1100_gpio_direction_input(unsigned gpio)
+{
+ unsigned long flags;
+
+ if (gpio > GPIO_MAX)
+ return -EINVAL;
+
+ local_irq_save(flags);
+ GPDR &= ~GPIO_GPIO(gpio);
+ local_irq_restore(flags);
+ return 0;
+}
+
+EXPORT_SYMBOL(sa1100_gpio_direction_input);
+
+int sa1100_gpio_direction_output(unsigned gpio)
+{
+ unsigned long flags;
+
+ if (gpio > GPIO_MAX)
+ return -EINVAL;
+
+ local_irq_save(flags);
+ GPDR |= GPIO_GPIO(gpio);
+ local_irq_restore(flags);
+ return 0;
+}
+
+EXPORT_SYMBOL(sa1100_gpio_direction_output);
+
/*
* Default power-off for SA1100
*/
Index: linux-2.6/include/asm-arm/arch-sa1100/hardware.h
===================================================================
--- linux-2.6.orig/include/asm-arm/arch-sa1100/hardware.h 2006-12-27
21:50:05.000000000 +0100
+++ linux-2.6/include/asm-arm/arch-sa1100/hardware.h 2006-12-30
14:43:30.000000000 +0100
@@ -48,6 +48,9 @@

#endif

+extern int sa1100_gpio_direction_input(unsigned gpio);
+extern int sa1100_gpio_direction_output(unsigned gpio);
+
#include "SA-1100.h"

#ifdef CONFIG_SA1101 Index: linux-2.6/include/asm-arm/arch-sa1100/gpio.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/include/asm-arm/arch-sa1100/gpio.h 2006-12-30 14:43:49.000000000 +0100
@@ -0,0 +1,72 @@
+/*
+ * linux/include/asm-arm/arch-sa1100/gpio.h
+ *
+ * SA1100 GPIO wrappers for arch-neutral GPIO calls
+ *
+ * Written by Philipp Zabel <philipp.zabel@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef __ASM_ARCH_SA1100_GPIO_H
+#define __ASM_ARCH_SA1100_GPIO_H
+
+#include <asm/hardware.h>
+#include <asm/irq.h>
+
+static inline int gpio_request(unsigned gpio, const char *label)
+{
+ return 0;
+}
+
+static inline void gpio_free(unsigned gpio)
+{
+ return;
+}
+
+#define gpio_direction_input sa1100_gpio_direction_output
+#define gpio_direction_output sa1100_gpio_direction_output
+
+static inline int gpio_get_value(unsigned gpio)
+{
+ return GPLR & GPIO_GPIO(gpio);
+}
+
+static inline void gpio_set_value(unsigned gpio, int value)
+{
+ if (value)
+ GPSR = GPIO_GPIO(gpio);
+ else
+ GPCR = GPIO_GPIO(gpio);
+}
+
+static inline unsigned gpio_to_irq(unsigned gpio)
+{
+ if (gpio < 11)
+ return IRQ_GPIO0 + gpio;
+ else
+ return IRQ_GPIO11 - 11 + gpio;
+}
+
+static inline unsigned irq_to_gpio(unsigned irq)
+{
+ if (irq < IRQ_GPIO11_27)
+ return irq - IRQ_GPIO0;
+ else
+ return irq - IRQ_GPIO11 + 11;
+}
+
+#endif /* __ASM_ARCH_SA1100_GPIO_H */
Index: linux-2.6/arch/arm/mach-sa1100/generic.c
===================================================================
--- linux-2.6.orig/arch/arm/mach-sa1100/generic.c 2006-12-27 21:50:03.000000000 +0100
+++ linux-2.6/arch/arm/mach-sa1100/generic.c 2006-12-30 14:50:42.000000000 +0100
@@ -138,6 +138,36 @@
return v;
}

+int sa1100_gpio_direction_input(unsigned gpio)
+{
+ unsigned long flags;
+
+ if (gpio > GPIO_MAX)
+ return -EINVAL;
+
+ local_irq_save(flags);
+ GPDR &= ~GPIO_GPIO(gpio);
+ local_irq_restore(flags);
+ return 0;
+}
+
+EXPORT_SYMBOL(sa1100_gpio_direction_input);
+
+int sa1100_gpio_direction_output(unsigned gpio)
+{
+ unsigned long flags;
+
+ if (gpio > GPIO_MAX)
+ return -EINVAL;
+
+ local_irq_save(flags);
+ GPDR |= GPIO_GPIO(gpio);
+ local_irq_restore(flags);
+ return 0;
+}
+
+EXPORT_SYMBOL(sa1100_gpio_direction_output);
+
/*
* Default power-off for SA1100
*/
Index: linux-2.6/include/asm-arm/arch-sa1100/hardware.h
===================================================================
--- linux-2.6.orig/include/asm-arm/arch-sa1100/hardware.h 2006-12-27 21:50:05.000000000 +0100
+++ linux-2.6/include/asm-arm/arch-sa1100/hardware.h 2006-12-30 14:43:30.000000000 +0100
@@ -48,6 +48,9 @@

#endif

+extern int sa1100_gpio_direction_input(unsigned gpio);
+extern int sa1100_gpio_direction_output(unsigned gpio);
+
#include "SA-1100.h"

#ifdef CONFIG_SA1101