Skip to contentSkip to conversation

sh: Add GPIO and pinmux base code

PATCH In review Magnus Damm 2 participants 3 messages Sep 27, 2008 – Sep 29, 2008 SuperH

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 sh: Add GPIO and pinmux base code

From: Magnus Damm <[email protected]>

This patch adds the pinmux table parser and gpiolib glue. The old SH3 header code is removed.

---

Requires the request/free gpiolib patch by David Brownell.

 arch/sh/Kconfig            |    3 
 arch/sh/include/asm/gpio.h |  118 +++++++++++
 arch/sh/kernel/Makefile_32 |    1 
 arch/sh/kernel/Makefile_64 |    1 
 arch/sh/kernel/gpio.c      |  436 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 550 insertions(+), 9 deletions(-)
arch/sh/Kconfig +3 -0
@@ -60,6 +60,9 @@ config GENERIC_HARDIRQS_NO__DO_IRQ
 config GENERIC_IRQ_PROBE
 	def_bool y
 
+config GENERIC_GPIO
+	def_bool n
+
 config GENERIC_CALIBRATE_DELAY
 	bool
 
arch/sh/include/asm/gpio.h +109 -9

128 lines not on this page · raw message

arch/sh/kernel/Makefile_32 +1 -0
@@ -23,5 +23,6 @@ obj-$(CONFIG_PM)		+= pm.o
 obj-$(CONFIG_STACKTRACE)	+= stacktrace.o
 obj-$(CONFIG_IO_TRAPPED)	+= io_trapped.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
+obj-$(CONFIG_GPIOLIB)		+= gpio.o
 
 EXTRA_CFLAGS += -Werror
arch/sh/kernel/Makefile_64 +1 -0
@@ -18,5 +18,6 @@ obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
 obj-$(CONFIG_PM)		+= pm.o
 obj-$(CONFIG_STACKTRACE)	+= stacktrace.o
 obj-$(CONFIG_IO_TRAPPED)	+= io_trapped.o
+obj-$(CONFIG_GPIOLIB)		+= gpio.o
 
 EXTRA_CFLAGS += -Werror
arch/sh/kernel/gpio.c new file +436 -0

436 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This patch adds the pinmux table parser and gpiolib glue. The old SH3 header code is removed.

For starters, I don't know why you decided to kill off the SH-3 gpio header. It's still in active use by the magicpanelr2 board. Once 7720 and mpr2 are converted over, then we can kill off the header, but not before that. Although I suppose we can just fix up the board header to use cpu-sh3/cpu/gpio.h explicitly.

Quoted 16 lines
arch/sh/include/asm/gpio.h +5 -4
@@ -1,19 +1,119 @@
 /*
- *  include/asm-sh/gpio.h
+ * Generic GPIO API using gpiolib and pinmux table support for SuperH.
  *
- *  Copyright (C) 2007 Markus Brunner, Mark Jonas
+ * Copyright (c) 2008 Magnus Damm
  *
- *  Addresses for the Pin Function Controller
+ * Generic GPIO derived from x86 version:
+ * Copyright (c) 2007-2008  MontaVista Software, Inc.
+ * Author: Anton Vorontsov <[email protected]>
  *
- * This file is subject to the terms and conditions of the GNU General Public

arch/sh/include/asm/gpio.h line 17

Quoted 10 lines
arch/sh/include/asm/gpio.h +4 -2
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
+ * 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.
  */
 #ifndef __ASM_SH_GPIO_H
 #define __ASM_SH_GPIO_H
 

I wouldn't bother with the header comments at all, there's nothing profound here and it's almost all pinmux stuff anyways.

Quoted 11 lines
arch/sh/include/asm/gpio.h +11 -0
+static int read_write_reg(unsigned long reg, unsigned long reg_width,
+			  unsigned long field_width, unsigned long in_pos,
+			  unsigned long value, int do_write)
+{
+	unsigned long flags, data, mask, pos;
+
+	flags = 0; /* kill silly warning */
+	data = 0;
+	mask = (1 << field_width) - 1;
+	pos = reg_width - ((in_pos + 1) * field_width);
+

arch/sh/include/asm/gpio.h line 38

Quoted 10 lines
arch/sh/include/asm/gpio.h +10 -0
+#ifdef DEBUG
+	pr_info("sh pinmux: %s, addr = %lx, value = %ld, pos = %ld, "
+		"r_width = %ld, f_width = %ld\n",
+		do_write ? "write" : "read", reg, value, pos,
+		reg_width, field_width);
+#endif
+
+	if (do_write)
+		spin_lock_irqsave(&gpio_register_lock, flags);
+

The locking here is a bit non-obvious, and should be commented. I had to read through this a couple of times to figure out what it was supposed to be doing. You seem to be trying to use a spinlock as a rwlock, which is a bit error prone to say the least.

#2 lore raw
In reply to Magnus Damm
Quoted 6 lines · Paul Mundt
Quoted 5 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This patch adds the pinmux table parser and gpiolib glue. The old SH3 header code is removed.

Quoted 7 lines
Quoted 1 line

For starters, I don't know why you decided to kill off the SH-3 gpio header. It's still in active use by the magicpanelr2 board. Once 7720 and mpr2 are converted over, then we can kill off the header, but not before that. Although I suppose we can just fix up the board header to use cpu-sh3/cpu/gpio.h explicitly.

I suspected the SH3 register definitions would be in use somewhere, but I couldn't find any references to that header file. Now I do. =) I must have forgot searching the asm include directory.

I'll fix that up.

Quoted 20 lines
Quoted 20 lines
arch/sh/include/asm/gpio.h 2008-09-28 02:03:40.000000000 +0900 renamed from arch/sh/include/asm/gpio.h +7 -6
@@ -1,19 +1,119 @@
 /*
- *  include/asm-sh/gpio.h
+ * Generic GPIO API using gpiolib and pinmux table support for SuperH.
  *
- *  Copyright (C) 2007 Markus Brunner, Mark Jonas
+ * Copyright (c) 2008 Magnus Damm
  *
- *  Addresses for the Pin Function Controller
+ * Generic GPIO derived from x86 version:
+ * Copyright (c) 2007-2008  MontaVista Software, Inc.
+ * Author: Anton Vorontsov <[email protected]>
  *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
+ * 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
Quoted 8 lines

arch/sh/include/asm/gpio.h 2008-09-28 02:03:40.000000000 +0900 line 17

Quoted 6 lines
arch/sh/include/asm/gpio.h 2008-09-28 02:03:40.000000000 +0900 renamed from arch/sh/include/asm/gpio.h +2 -0
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  */
 #ifndef __ASM_SH_GPIO_H
 #define __ASM_SH_GPIO_H
 

I wouldn't bother with the header comments at all, there's nothing profound here and it's almost all pinmux stuff anyways.

Yeah.

Quoted 17 lines
Quoted 17 lines
arch/sh/include/asm/gpio.h 2008-09-28 02:03:40.000000000 +0900 renamed from arch/sh/include/asm/gpio.h +17 -0
+static int read_write_reg(unsigned long reg, unsigned long reg_width,
+                       unsigned long field_width, unsigned long in_pos,
+                       unsigned long value, int do_write)
+{
+     unsigned long flags, data, mask, pos;
+
+     flags = 0; /* kill silly warning */
+     data = 0;
+     mask = (1 << field_width) - 1;
+     pos = reg_width - ((in_pos + 1) * field_width);
+
+#ifdef DEBUG
+     pr_info("sh pinmux: %s, addr = %lx, value = %ld, pos = %ld, "
+             "r_width = %ld, f_width = %ld\n",
+             do_write ? "write" : "read", reg, value, pos,
+             reg_width, field_width);
+#endif
Quoted 8 lines

arch/sh/include/asm/gpio.h 2008-09-28 02:03:40.000000000 +0900 line 38

Quoted 4 lines
arch/sh/include/asm/gpio.h 2008-09-28 02:03:40.000000000 +0900 renamed from arch/sh/include/asm/gpio.h +4 -0
+
+     if (do_write)
+             spin_lock_irqsave(&gpio_register_lock, flags);
+

The locking here is a bit non-obvious, and should be commented. I had to read through this a couple of times to figure out what it was supposed to be doing. You seem to be trying to use a spinlock as a rwlock, which is a bit error prone to say the least.

Sorry about the unclear code. This function is used for reading and writing bit fields in registers. The spinlock is protecting the read-modify-write register operation in the write case. No locking is done for the read case.

/ magnus