Skip to contentSkip to conversation

GPIO-Ports on VIA EPIA-SN

PATCH New Stefan Hellermann 4 participants 5 messages Jun 9, 2008 – Jun 10, 2008

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

Hello,

I have a VIA Epia-SN embedded-board with 8 GPIO-connectors. I got the attached documentation from VIA after I asked how to use the GPIO-connectors with Linux.
The GPIO is connected to the VT8251 southbridge, here is lspci-output:

# lspci -vv -s 00:11.0
00:11.0 ISA bridge: VIA Technologies, Inc. VT8251 PCI to ISA Bridge
	Subsystem: VIA Technologies, Inc. VT8251 PCI to ISA Bridge
	Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr-
Stepping- SERR- FastB2B- DisINTx-
	Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort-
<TAbort- <MAbort- >SERR- <PERR- INTx-
	Capabilities: [c0] Power Management version 2
		Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA
PME(D0-,D1-,D2-,D3hot-,D3cold-)
		Status: D0 PME-Enable- DSel=0 DScale=0 PME-

Can anybody help me writing a small kernel-driver for this? I heard of the GPIO-framework, but I have no clue where to start with. I simply want to switch these ports to 0 or 1 :).

I don't know under what license this documentation is, I simply got these 6 pages with sample source code.

Kind Regards
Stefan Hellermann

#1 lore raw
Quoted 3 lines · Stefan Hellermann

I have a VIA Epia-SN embedded-board with 8 GPIO-connectors. I got the attached documentation from VIA after I asked how to use the GPIO-connectors with Linux.

Are you already familiar with the LDD book
(http://lwn.net/Kernel/LDD3/ +
http://lwn.net/Articles/2.6-kernel-api/) ? That book is a good starting point, together with the file Documentation/gpio.txt in the Linux kernel tree.

Bart.

#2 lore raw
Quoted 10 lines · Bart Van Assche
Quoted 3 lines · Stefan Hellermann

I have a VIA Epia-SN embedded-board with 8 GPIO-connectors. I got the attached documentation from VIA after I asked how to use the GPIO-connectors with Linux.

Are you already familiar with the LDD book
(http://lwn.net/Kernel/LDD3/ +
http://lwn.net/Articles/2.6-kernel-api/) ? That book is a good starting point, together with the file Documentation/gpio.txt in the Linux kernel tree.

So in short: you'll want to add a Kconfig option for your board, and when it's selected you'll want to link in some EPIA-specific int logic. That logic will register a gpio_chip, and then you'll be able to use the standard GPIO calls (and whatever uses them).

You will also want something like the appended patch ... but do the "select" commands when your board is selected.

Of course an entirely roll-your-own approach could work too, but I won't recommend that here.

- Dave

===== CUT HERE
DEBUG ONLY -- make X86_PC use gpiolib.

It's not clear to me how the various x86-ish platforms should be made to work here, since there seems to be no convention that each platform type has its own <asm/arch/...> subdir.

---
 arch/x86/Kconfig       |    2 ++
 include/asm-x86/gpio.h |   20 +++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
arch/x86/Kconfig +2 -0
@@ -236,6 +236,8 @@ choice
 
 config X86_PC
 	bool "PC-compatible"
+	select GENERIC_GPIO
+	select HAVE_GPIO_LIB
 	help
 	  Choose this option if your computer is a standard PC or compatible.
 
include/asm-x86/gpio.h +19 -1
@@ -1,6 +1,24 @@
 #ifndef _ASM_I386_GPIO_H
 #define _ASM_I386_GPIO_H
 
-#include <gpio.h>
+// #include <gpio.h>
+
+#include <linux/errno.h>
+#include <asm-generic/gpio.h>           /* cansleep wrappers */
+
+#define gpio_get_value	__gpio_get_value
+#define gpio_set_value	__gpio_set_value
+#define gpio_cansleep	__gpio_cansleep
+
+static inline int gpio_to_irq(unsigned gpio)
+{
+	return -ENOSYS;
+}
+
+static inline int irq_to_gpio(unsigned irq)
+{
+	return -EINVAL;
+}
+
 
 #endif /* _ASM_I386_GPIO_H */
#3 lore raw
In reply to Stefan Hellermann
Quoted 6 lines

Can anybody help me writing a small kernel-driver for this? I heard of the GPIO-framework, but I have no clue where to start with. I simply want to switch these ports to 0 or 1 :).

I don't know under what license this documentation is, I simply got these 6 pages with sample source code.

This is a 5 minute hack on the Nat Semi Geode GPIO driver so you might need to debug it a bit as its untested.

epiapd_gpio: driver for EPIA-PD

From: Alan Cox <[email protected]>

This is a simple driver for the EPIA-PD GPIO lines
---

 drivers/char/Kconfig       |    6 +
 drivers/char/Makefile      |    1 
 drivers/char/epiapd_gpio.c |  182 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 189 insertions(+), 0 deletions(-)
 create mode 100644 drivers/char/epiapd_gpio.c
drivers/char/Kconfig +6 -0
index 595a925..c308e15 100644
@@ -932,6 +932,12 @@ config GPIO_TB0219
 	depends on TANBAC_TB022X
 	select GPIO_VR41XX
 
+config GPIO_EPIAPD
+	tristate "EPIA-PD VT8251 GPIO support"
+	---help---
+	  This driver provides access to the GPI/GPO pins on the VT8251
+	  EPIA-PD board.
+
 source "drivers/char/pcmcia/Kconfig"
 
 config MWAVE
drivers/char/Makefile +1 -0
index 4c1c584..237ebfc 100644
@@ -96,6 +96,7 @@ obj-$(CONFIG_PC8736x_GPIO)	+= pc8736x_gpio.o
 obj-$(CONFIG_NSC_GPIO)		+= nsc_gpio.o
 obj-$(CONFIG_CS5535_GPIO)	+= cs5535_gpio.o
 obj-$(CONFIG_GPIO_VR41XX)	+= vr41xx_giu.o
+obj-$(CONFIG_GPIO_EPIAPD)	+= epiapd_gpio.o
 obj-$(CONFIG_GPIO_TB0219)	+= tb0219.o
 obj-$(CONFIG_TELCLOCK)		+= tlclk.o
 
drivers/char/epiapd_gpio.c new file +182 -0

182 lines not on this page · raw message

#4 lore raw

PATCH 1/1 Add driver for GPIO on Via Epia-SN - vt8251

This is a first version which probably doesn't work. I wrote a small userspace tool which uses the same ioports and it works. I can't test this driver yet, because I don't know how to set or check bits with the GPIO-framework.

---

Quoted 7 lines
Quoted 4 lines

Can anybody help me writing a small kernel-driver for this? I heard of the GPIO-framework, but I have no clue where to start with. I simply want to switch these ports to 0 or 1 :).

This is a 5 minute hack on the Nat Semi Geode GPIO driver so you might need to debug it a bit as its untested.

Thanks a lot for your work! It's so much easier to start with something existing ...

I changed some lines and rewrote epiapd_gpio_set() because the output bits are at position 1,4,6,7, not 0-3.

This is my first patch so please check everything! I already corrected most errors spotted by scripts/checkpatch.pl.

My only problem: How to use this? Are there any sysfs-files I can use to send bits to the device? Probably I have to enable the GPIO-framework for the x86-architecture first. I tried some changes from David Brownell to use gpiolib with x86 but these crashed my machine with irq-failures (or maybe I simply sent the wrong bytes to the wrong registers and then got crashes)

drivers/char/Kconfig +6 -0
index d307bf2..fc4fbec 100644
@@ -932,6 +932,12 @@ config GPIO_TB0219
 	depends on TANBAC_TB022X
 	select GPIO_VR41XX
 
+config GPIO_EPIAPD
+       tristate "EPIA-PD VT8251 GPIO support"
+       ---help---
+         This driver provides access to the GPI/GPO pins on the VT8251
+         EPIA-PD board.
+
 source "drivers/char/pcmcia/Kconfig"
 
 config MWAVE
drivers/char/Makefile +1 -0
index 4c1c584..b1e3234 100644
@@ -96,6 +96,7 @@ obj-$(CONFIG_PC8736x_GPIO)	+= pc8736x_gpio.o
 obj-$(CONFIG_NSC_GPIO)		+= nsc_gpio.o
 obj-$(CONFIG_CS5535_GPIO)	+= cs5535_gpio.o
 obj-$(CONFIG_GPIO_VR41XX)	+= vr41xx_giu.o
+obj-$(CONFIG_GPIO_EPIAPD)      += epiapd_gpio.o
 obj-$(CONFIG_GPIO_TB0219)	+= tb0219.o
 obj-$(CONFIG_TELCLOCK)		+= tlclk.o
 
drivers/char/epiapd_gpio.c new file +202 -0

202 lines not on this page · raw message