Skip to contentSkip to conversation

omap1: Amstrad Delta: add support for external keyboard

RFC PATCH Superseded Janusz Krzysztofik 3 participants 12 messages Mar 29, 2010 – Apr 12, 2010 1 message not in the archive

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover omap1: Amstrad Delta: add support for external keyboard

This series of patches adds support for an external keyboard (called mailboard) connected to the Amstrad Delta (E3) videophone.

The series is based on a patch by Matt Callow, created against linux-omap-2.6.19[1], initially submitted to the e3-hacking mailing list in April 2006[2].

Since the keyboard serial clock line is connected to a GPIO line, it generates interrupts every single bit received. In order to handle this correctly, the code makes use of a FIQ hardware feature. Since all GPIO generated interrupts would be converted to FIQ, the handler must include support for all supported GPIO connected devices: the keyboard, a modem and a hook switch.

My modifications to the original patch include:
- split into several patches,
- refresh against a recent linux version,
- a lot of cleanups, mainly to get rid of checkpatch reported issues,
- add support for handling interrupts generated by a GPIO line that the meanwhile activated hook switch hangs off.
v2 changes:
- remove scan code to key code mapping from the serio driver, that doesn't belong here and should be set up from userspace; thanks to Dmitry Torokhov for advising this,
- no funtional changes in FIQ part (there were no comments in round 1).

There is still one minor issue that I was not able to deal with: when built with CONFIG_OMAP_RESET_CLOCKS=y, the keyboard driver stops working. I have no idea how I could find which clock I should enable to get it working regardless of boot loader used. Any suggestions?

Created and tested against linux-2.6.34-rc2.

Janusz Krzysztofik(5)
omap1: Amstrad Delta: add FIQ handler for serial keyboard port interrupt
processing
omap1: Amstrad Delta: add a handler for processing interrupts generated by
the FIQ routine
omap1: Amstrad Delta: use FIQ for processing GPIO interrupts
input: serio: add support for Amstrad Delta serial keyboard port
omap1: Amstrad Delta: modify defconfig for external keyboard support

 arch/arm/configs/ams_delta_defconfig             |    2
 arch/arm/mach-omap1/Kconfig                      |    8
 arch/arm/mach-omap1/Makefile                     |    3
 arch/arm/mach-omap1/ams-delta-fiq-handler.S      |  342 +++++++++++++++++++++++
 arch/arm/mach-omap1/ams-delta-fiq.c              |  175 +++++++++++
 arch/arm/mach-omap1/board-ams-delta.c            |    6
 arch/arm/mach-omap1/include/mach/ams-delta-fiq.h |   57 +++
 arch/arm/plat-omap/include/plat/irqs.h           |    4
 drivers/input/serio/Kconfig                      |    9
 drivers/input/serio/Makefile                     |    1
 drivers/input/serio/ams_delta_keyboard.c         |  171 +++++++++++
 11 files changed, 777 insertions(+), 1 deletion(-)

Thanks,
Janusz

[1] http://the.earth.li/pub/e3/2.6.19/ams-delta-keyboard.patch
[2] http://www.earth.li/pipermail/e3-hacking/2006-April/000453.html

#1 lore raw

RFC PATCH v2 1/5 omap1: Amstrad Delta: add FIQ handler for serial keyboard port interrupt processing

This patch introduces a Fast Interrupt Request (FIQ) handler for Amstrad Delta (E3) videophone. The handler's purpose is to process interrupts generated by a GPIO line that a serial keyboard clock hangs off. It collects consecutive bits into bytes, pushing them into a buffer, then requests a higher level interrupt after one or more characters are ready for further processing by a keyboard port driver.

The handler also processes interrupts generated by two other GPIO lines, used by other on-board supported devices, by simply requesting a higher level interrupt, that in turn should invoke those device's specific irq handlers.

32k timer IRQ line, not used for any purpose by the on-board hardware, has been choosen as a higher level interrupt source.

Created and tested against linux-2.6.34-rc2.

---
v2 changes:
- no functional changes,
- refresh against linux-2.6.34-rc2.

 arch/arm/mach-omap1/Kconfig                 |    8
 arch/arm/mach-omap1/Makefile                |    1
 arch/arm/mach-omap1/ams-delta-fiq-handler.S |  342 ++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/plat/irqs.h      |    4
 4 files changed, 355 insertions(+)
arch/arm/mach-omap1/Kconfig +8 -0
diff -uprN git.orig/arch/arm/mach-omap1/Kconfig git/arch/arm/mach-omap1/Kconfig
@@ -152,6 +152,14 @@ config MACH_AMS_DELTA
 	  Support for the Amstrad E3 (codename Delta) videophone. Say Y here
 	  if you have such a device.
 
+config AMS_DELTA_FIQ
+	bool "Fast Interrupt Request (FIQ) support for the E3"
+	depends on MACH_AMS_DELTA
+	select FIQ
+	help
+	  Provide a FIQ handler for the E3. This redirects the gpio IRQ to FIQ
+	  And is required to use the E3 mailboard
+
 config MACH_OMAP_GENERIC
 	bool "Generic OMAP board"
 	depends on ARCH_OMAP1 && (ARCH_OMAP15XX || ARCH_OMAP16XX)
arch/arm/mach-omap1/Makefile +1 -0
diff -uprN git.orig/arch/arm/mach-omap1/Makefile git/arch/arm/mach-omap1/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_MACH_OMAP_PALMZ71)		+= boar
 obj-$(CONFIG_MACH_OMAP_PALMTT)		+= board-palmtt.o
 obj-$(CONFIG_MACH_NOKIA770)		+= board-nokia770.o
 obj-$(CONFIG_MACH_AMS_DELTA)		+= board-ams-delta.o
+obj-$(CONFIG_AMS_DELTA_FIQ)		+= ams-delta-fiq-handler.o
 obj-$(CONFIG_MACH_SX1)			+= board-sx1.o board-sx1-mmc.o
 obj-$(CONFIG_MACH_HERALD)		+= board-htcherald.o
 
arch/arm/mach-omap1/ams-delta-fiq-handler.S +342 -0

342 lines not on this page · raw message

arch/arm/plat-omap/include/plat/irqs.h +4 -0
diff -uprN git.orig/arch/arm/plat-omap/include/plat/irqs.h git/arch/arm/plat-omap/include/plat/irqs.h
@@ -430,4 +430,8 @@ void omap3_intc_resume_idle(void);
 
 #include <mach/hardware.h>
 
+#ifdef CONFIG_FIQ
+#define FIQ_START		1024
+#endif
+
 #endif

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

RFC PATCH v2 1/5 omap1: Amstrad Delta: add FIQ handler for serial keyboard port interrupt processing

Quoted 5 lines · Monday 29 March 2010 20:32:11 Ralph Corderoy wrote:

Hi Janusz,

My ARM's not used much these days so I don't know how much this matters and may be incorrect so I've cut down the CC list, but given it's a FIQ handler and speed matters...

Hi Ralph,

Not only speed; there is a very low size limit for FIQ handler and I already have had problems with fitting into the available space with the code, so your hints are really appreciated.

And thanks for pushing me into reading the ARM Assembly Language book, so I would be able to do more than just understanding and copy-pasting the code ;).

Quoted 8 lines

arch/arm/mach-omap1/ams-delta-fiq-handler.S line 156

Quoted 5 lines
arch/arm/mach-omap1/ams-delta-fiq-handler.S +5 -0
+key:	@Is it a keyboard interrupt?
+	ldr r11, [r12,#GPIO_INTERRUPT_STATUS]	@ get GPIO interrupt status
+	and r10, r11, #MBRD_CLK_MASK		@ reveal keyboard bit
+	cmp r10, #MBRD_CLK_MASK 		@ is keyboard bit low?
+	bne mdm					@ no - spurious - try mdm

Couldn't that be an `ands' instruction if MBRD_CLK_MASK has one-bit set? Then the cmp could be deleted.

Agree.

Quoted 6 lines

arch/arm/mach-omap1/ams-delta-fiq-handler.S line 169

Quoted 4 lines
arch/arm/mach-omap1/ams-delta-fiq-handler.S +4 -0
+state:
+	ldr r10, [r9,#FIQ_STATE]
+	cmp r10, #0				@ are we expecting start bit?
+	bne data				@ no - in data processing state

Similarly, an `ldrs' here would make the cmp redundant.

I'm not sure if the S suffix is also valid for memory transfer instructions, so I readd linux-omap and linux-arm-kernel to the CC list.

Quoted 1 line

There's other similar bits elsewhere.

Yes, I'll try to recognize and optimize them all for next version.

Thanks,
Janusz

#4 lore raw

RFC PATCH v2 1/5 omap1: Amstrad Delta: add FIQ handler for serial keyboard port interrupt processing

Hi Janusz,

Quoted 3 lines

And thanks for pushing me into reading the ARM Assembly Language book, so I would be able to do more than just understanding and copy-pasting the code ;).

It's a lovely instruction set compared to many others.

Quoted 9 lines
Quoted 6 lines

arch/arm/mach-omap1/ams-delta-fiq-handler.S line 169

Quoted 4 lines
arch/arm/mach-omap1/ams-delta-fiq-handler.S +4 -0
+state:
+	ldr r10, [r9,#FIQ_STATE]
+	cmp r10, #0				@ are we expecting start bit?
+	bne data				@ no - in data processing state

Similarly, an `ldrs' here would make the cmp redundant.

I'm not sure if the S suffix is also valid for memory transfer instructions

No, you're correct. Memory transfers can't do the "set ALU flags" S-bit. Sorry to mislead.

Cheers,
Ralph.

#5 lore raw

RFC PATCH v2 2/5 omap1: Amstrad Delta: add a handler for processing interrupts generated by the FIQ routine

In reply to Janusz Krzysztofik

This patch introduces an IRQ handler used for processing interrupts generated by the FIQ handler when it decides there are data ready for processing.

The handler further invokes device specific interrupt routines based on an interrupt source as passed from the FIQ handler.

It can be registered by the board as a handler for the otherwise unused 32k timer interrupt.

Applies on top of patch 1/5 from this series:
omap1: Amstrad Delta: add FIQ handler for serial keyboard port interrupt processing

Created and tested against linux-2.6.34-rc2.

---
v2 changes:
- add fiq_buffer[] declaration missing from the header file,
- refresh against 2.6.34-rc2.

 arch/arm/mach-omap1/Makefile                     |    2
 arch/arm/mach-omap1/ams-delta-fiq.c              |  175 +++++++++++++++++++++++
 arch/arm/mach-omap1/include/mach/ams-delta-fiq.h |   57 +++++++
 3 files changed, 233 insertions(+), 1 deletion(-)
arch/arm/mach-omap1/Makefile +1 -1
diff -uprN git.orig/arch/arm/mach-omap1/Makefile git/arch/arm/mach-omap1/Makefile
@@ -37,7 +37,7 @@ obj-$(CONFIG_MACH_OMAP_PALMZ71)		+= boar
 obj-$(CONFIG_MACH_OMAP_PALMTT)		+= board-palmtt.o
 obj-$(CONFIG_MACH_NOKIA770)		+= board-nokia770.o
 obj-$(CONFIG_MACH_AMS_DELTA)		+= board-ams-delta.o
-obj-$(CONFIG_AMS_DELTA_FIQ)		+= ams-delta-fiq-handler.o
+obj-$(CONFIG_AMS_DELTA_FIQ)		+= ams-delta-fiq.o ams-delta-fiq-handler.o
 obj-$(CONFIG_MACH_SX1)			+= board-sx1.o board-sx1-mmc.o
 obj-$(CONFIG_MACH_HERALD)		+= board-htcherald.o
 
arch/arm/mach-omap1/ams-delta-fiq.c +175 -0

175 lines not on this page · raw message

arch/arm/mach-omap1/include/mach/ams-delta-fiq.h +57 -0

57 lines not on this page · raw message

#6 lore raw

RFC PATCH v2 3/5 omap1: Amstrad Delta: use FIQ for processing GPIO interrupts

In reply to Janusz Krzysztofik

The patch adds initialization of FIQ related handlers to the Amstrad Delta videophone board code. FIQ will be used instead of a traditional IRQ for processing all GPIO generated interrupts, including a keyboard serial clock line.

Amstrad Delta defconfig is modified to use FIQ by default.

Compiles and works on top of patch 2/5 from this series:
omap1: Amstrad Delta: add a handler for processing interrupts generated by the FIQ routine

Created and tested against linux-2.6.34-rc2.

---
v2 changes:
- no functional changes,
- refreshed against linux-2.6.34-rc2.

 arch/arm/configs/ams_delta_defconfig  |    1 +
 arch/arm/mach-omap1/board-ams-delta.c |    6 ++++++
 2 files changed, 7 insertions(+)
arch/arm/configs/ams_delta_defconfig +1 -0
diff -uprN git.orig/arch/arm/configs/ams_delta_defconfig git/arch/arm/configs/ams_delta_defconfig
@@ -195,6 +195,7 @@ CONFIG_ARCH_OMAP15XX=y
 # CONFIG_MACH_OMAP_PALMTT is not set
 # CONFIG_MACH_SX1 is not set
 CONFIG_MACH_AMS_DELTA=y
+CONFIG_AMS_DELTA_FIQ=y
 # CONFIG_MACH_OMAP_GENERIC is not set
 
 #
arch/arm/mach-omap1/board-ams-delta.c +6 -0
diff -uprN git.orig/arch/arm/mach-omap1/board-ams-delta.c git/arch/arm/mach-omap1/board-ams-delta.c
@@ -33,6 +33,8 @@
 #include <plat/board.h>
 #include <plat/common.h>
 
+#include <mach/ams-delta-fiq.h>
+
 static u8 ams_delta_latch1_reg;
 static u16 ams_delta_latch2_reg;
 
@@ -236,6 +238,10 @@ static void __init ams_delta_init(void)
 	omap_usb_init(&ams_delta_usb_config);
 	platform_add_devices(ams_delta_devices, ARRAY_SIZE(ams_delta_devices));
 
+#ifdef CONFIG_AMS_DELTA_FIQ
+	ams_delta_init_fiq();
+#endif
+
 	omap_writew(omap_readw(ARM_RSTCT1) | 0x0004, ARM_RSTCT1);
 }
 
#7 lore raw

RFC PATCH v2 4/5 input: serio: add support for Amstrad Delta serial keyboard port

In reply to Janusz Krzysztofik

The patch introduces a serio driver that supports a keyboard serial port found on the Amstrad Delta videophone board.

After initializing the hardware, the driver reads its input data from a buffer filled in by the board FIQ (Fast Interrupt Request) handler.

Standard AT keyboard driver (atkbd) will be used on top of the serio layer for handling the E3 keyboard (called mailboard) connected to the port. Since the device generated scancodes differ from what the atkbd expects, a custom key code to scan code table must be loaded from userspace for the keyboard to be useable.

Compiles and works on to of patch 3/5:
omap1: Amstrad Delta: use FIQ for processing GPIO interrupts

Created and tested against linux-2.6.34-rc2.

---
v2 changes:
- use correct variable name for return value in ams_delta_kbd_init(),
- remove scan code to key code mapping,
- refreshed against linux-2.6.34-rc2.

 drivers/input/serio/Kconfig              |    9 +
 drivers/input/serio/Makefile             |    1
 drivers/input/serio/ams_delta_keyboard.c |  171 +++++++++++++++++++++++++++++++
 3 files changed, 181 insertions(+)
drivers/input/serio/Kconfig +9 -0
diff -uprN git.orig/drivers/input/serio/Kconfig git/drivers/input/serio/Kconfig
@@ -209,4 +209,13 @@ config SERIO_ALTERA_PS2
 	  To compile this driver as a module, choose M here: the
 	  module will be called altera_ps2.
 
+config SERIO_AMS_DELTA
+	tristate "Amstrad Delta (E3) keyboard support"
+	depends on MACH_AMS_DELTA && AMS_DELTA_FIQ
+	---help---
+	  Say Y here if has an E3 and want to use the separate keyboard
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ams_delta_keyboard
+
 endif
drivers/input/serio/Makefile +1 -0
diff -uprN git.orig/drivers/input/serio/Makefile git/drivers/input/serio/Makefile
@@ -21,5 +21,6 @@ obj-$(CONFIG_SERIO_PCIPS2)	+= pcips2.o
 obj-$(CONFIG_SERIO_MACEPS2)	+= maceps2.o
 obj-$(CONFIG_SERIO_LIBPS2)	+= libps2.o
 obj-$(CONFIG_SERIO_RAW)		+= serio_raw.o
+obj-$(CONFIG_SERIO_AMS_DELTA)	+= ams_delta_keyboard.o
 obj-$(CONFIG_SERIO_XILINX_XPS_PS2)	+= xilinx_ps2.o
 obj-$(CONFIG_SERIO_ALTERA_PS2)	+= altera_ps2.o
drivers/input/serio/ams_delta_keyboard.c +171 -0

171 lines not on this page · raw message

maintainer
#8 lore raw

Re: [RFC][PATCH v2 4/5] input: serio: add support for Amstrad Delta serial keyboard port

Quoted 84 lines · Janusz Krzysztofik

The patch introduces a serio driver that supports a keyboard serial port found on the Amstrad Delta videophone board.

After initializing the hardware, the driver reads its input data from a buffer filled in by the board FIQ (Fast Interrupt Request) handler.

Standard AT keyboard driver (atkbd) will be used on top of the serio layer for handling the E3 keyboard (called mailboard) connected to the port. Since the device generated scancodes differ from what the atkbd expects, a custom key code to scan code table must be loaded from userspace for the keyboard to be useable.

Compiles and works on to of patch 3/5:
omap1: Amstrad Delta: use FIQ for processing GPIO interrupts

Created and tested against linux-2.6.34-rc2.

---
v2 changes:
- use correct variable name for return value in ams_delta_kbd_init(),
- remove scan code to key code mapping,
- refreshed against linux-2.6.34-rc2.

 drivers/input/serio/Kconfig              |    9 +
 drivers/input/serio/Makefile             |    1
 drivers/input/serio/ams_delta_keyboard.c |  171 +++++++++++++++++++++++++++++++
 3 files changed, 181 insertions(+)

diff -uprN git.orig/drivers/input/serio/Kconfig git/drivers/input/serio/Kconfig

drivers/input/serio/Kconfig +9 -0
@@ -209,4 +209,13 @@ config SERIO_ALTERA_PS2
 	  To compile this driver as a module, choose M here: the
 	  module will be called altera_ps2.
 
+config SERIO_AMS_DELTA
+	tristate "Amstrad Delta (E3) keyboard support"
+	depends on MACH_AMS_DELTA && AMS_DELTA_FIQ
+	---help---
+	  Say Y here if has an E3 and want to use the separate keyboard
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ams_delta_keyboard
+
 endif

diff -uprN git.orig/drivers/input/serio/Makefile git/drivers/input/serio/Makefile

drivers/input/serio/Makefile +1 -0
@@ -21,5 +21,6 @@ obj-$(CONFIG_SERIO_PCIPS2)	+= pcips2.o
 obj-$(CONFIG_SERIO_MACEPS2)	+= maceps2.o
 obj-$(CONFIG_SERIO_LIBPS2)	+= libps2.o
 obj-$(CONFIG_SERIO_RAW)		+= serio_raw.o
+obj-$(CONFIG_SERIO_AMS_DELTA)	+= ams_delta_keyboard.o
 obj-$(CONFIG_SERIO_XILINX_XPS_PS2)	+= xilinx_ps2.o
 obj-$(CONFIG_SERIO_ALTERA_PS2)	+= altera_ps2.o

diff -uprN git.orig/drivers/input/serio/ams_delta_keyboard.c git/drivers/input/serio/ams_delta_keyboard.c

drivers/input/serio/ams_delta_keyboard.c +24 -0
@@ -0,0 +1,171 @@
+/*
+ *  Amstrad E3 (delta) keyboard driver
+ *
+ *  Copyright (c) 2006 Matt Callow
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * Thanks to Cliff Lawson for his help
+ *
+ * The Amstrad Delta keyboard (or mailboard) is connected to GPIO 0 (clock)
+ * and GPIO 1 (data). It uses normal PC-AT style serial transmission,
+ * but the data and clock lines are inverted on the E3 mainboard,
+ * and the scancodes produced are non-standard
+ *
+ * Due to the strict timing requirements of the interface,
+ * the serial data stream is read using a FIQ handler, and then
+ * the resulting byte stream passed to this driver via a circular buffer.
+ */
+#include <linux/gpio.h>
+#include <linux/init.h>
+#include <linux/irq.h>
+#include <linux/module.h>

drivers/input/serio/ams_delta_keyboard.c line 34

Quoted 10 lines
drivers/input/serio/ams_delta_keyboard.c +10 -0
+#include <linux/serio.h>
+#include <asm/fiq.h>
+#include <plat/board-ams-delta.h>
+#include <mach/ams-delta-fiq.h>
+
+MODULE_AUTHOR("Matt Callow");
+MODULE_DESCRIPTION("AMS Delta (E3) Keyboard driver");
+MODULE_LICENSE("GPL");
+
+#define MAX_SCANCODE 0x84

Not needed anymore?

drivers/input/serio/ams_delta_keyboard.c line 47

Quoted 13 lines
drivers/input/serio/ams_delta_keyboard.c +13 -0
+
+static struct serio *ams_delta_kbd_port;
+
+static int check_data(int data)
+{
+	int i;
+	int parity = 0;
+
+	/* check valid stop bit */
+	if (!(data & 0x400)) {
+		printk(KERN_WARNING
+				"Invalid stop bit in AMS keyboard"
+				" data=0x%X\r\n", data);

Consider switching top dev_err(), dev_warning(), etc. Also do not split text strings, even if you run over 80 column limit. BTW, why "\r\n" in the message?

Quoted 39 lines
drivers/input/serio/ams_delta_keyboard.c +39 -0
+		return 0;
+	}
+	/* calculate the parity */
+	for (i = 1; i < 10; i++) {
+		if (data & (1 << i))
+			parity++;
+	}
+	/* it should be odd */
+	if (!(parity & 0x01)) {
+		printk(KERN_WARNING
+				"Paritiy check failed in AMS keyboard "
+				" data=0x%X parity 0x%X\r\n", data, parity);
+	}
+	return 1;
+}
+
+static irqreturn_t ams_delta_kbd_interrupt(int irq, void *dev_id,
+		struct pt_regs *regs)
+{
+	int *circ_buff = &fiq_buffer[FIQ_CIRC_BUFF];
+	/*
+	 * Read data from the CIRC buffer, check it, translate the scancode
+	 * and then pass it on the serio
+	 */
+	fiq_buffer[FIQ_IRQ_PEND] = 0;
+
+	while (fiq_buffer[FIQ_CHAR_CNT] > 0) {
+		int data;
+		u8 scancode;
+
+		data = circ_buff[fiq_buffer[FIQ_BACK_OFFSET]] ;
+		fiq_buffer[FIQ_BACK_OFFSET]++;
+		fiq_buffer[FIQ_CHAR_CNT]--;
+		if (fiq_buffer[FIQ_BACK_OFFSET] == fiq_buffer[FIQ_BUF_LEN])
+			fiq_buffer[FIQ_BACK_OFFSET] = 0;
+
+		if (check_data(data)) {
+			scancode = (u8) (data >> 1) & 0xFF;
+			serio_interrupt(ams_delta_kbd_port, scancode, 0);

drivers/input/serio/ams_delta_keyboard.c line 96

Quoted 10 lines
drivers/input/serio/ams_delta_keyboard.c +10 -0
+		}
+	}
+	return IRQ_HANDLED;
+}
+
+static struct serio * __init ams_delta_kbd_allocate_serio(void)
+{
+	struct serio *serio;
+
+	serio = kmalloc(sizeof(struct serio), GFP_KERNEL);

kzalloc() please.

drivers/input/serio/ams_delta_keyboard.c line 102

Quoted 6 lines
drivers/input/serio/ams_delta_keyboard.c +6 -0
+	if (serio) {
+		memset(serio, 0, sizeof(struct serio));
+		serio->id.type = SERIO_8042;
+		strlcpy(serio->name, "AMS DELTA keyboard adapter",
+				sizeof(serio->name));
+		snprintf(serio->phys, sizeof(serio->phys), "%s/serio0", "GPIO");

strlcpy(serio->phys, "GPIO/serio0", sizeof(serio->phys)); ?

Quoted 8 lines
drivers/input/serio/ams_delta_keyboard.c +8 -0
+	}
+
+	return serio;
+}
+
+static int __init ams_delta_kbd_init(void)
+{
+	int err;

drivers/input/serio/ams_delta_keyboard.c line 120

Quoted 10 lines
drivers/input/serio/ams_delta_keyboard.c +10 -0
+
+	ams_delta_kbd_port = ams_delta_kbd_allocate_serio();
+	if (!ams_delta_kbd_port) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	if (gpio_request(AMS_DELTA_GPIO_PIN_KEYBRD_DATA, "kbd-data")) {
+		printk(KERN_ERR "Couldn't request gpio pin for keyboard data");
+		err = -EINVAL;

Why do you mangle return value of gpio_request()? Just return what it reported. Same goes for request_irq() below.

Quoted 14 lines
drivers/input/serio/ams_delta_keyboard.c +14 -0
+		goto serio;
+	}
+	gpio_direction_input(AMS_DELTA_GPIO_PIN_KEYBRD_DATA);
+
+	if (gpio_request(AMS_DELTA_GPIO_PIN_KEYBRD_CLK, "kbd-clock")) {
+		printk(KERN_ERR "Couldn't request gpio pin for keyboard clock");
+		err = -EINVAL;
+		goto gpio_data;
+	}
+	gpio_direction_input(AMS_DELTA_GPIO_PIN_KEYBRD_CLK);
+
+	if (request_irq(OMAP_GPIO_IRQ(AMS_DELTA_GPIO_PIN_KEYBRD_CLK),
+		    ams_delta_kbd_interrupt, 0, "ams-delta-keyboard", 0) < 0) {
+		printk(KERN_ERR "Couldn't request gpio interrupt %d",

drivers/input/serio/ams_delta_keyboard.c line 144

Quoted 10 lines
drivers/input/serio/ams_delta_keyboard.c +10 -0
+				OMAP_GPIO_IRQ(AMS_DELTA_GPIO_PIN_KEYBRD_CLK));
+		err = -EINVAL;
+		goto gpio_clk;
+	}
+	set_irq_type(OMAP_GPIO_IRQ(AMS_DELTA_GPIO_PIN_KEYBRD_CLK),
+			IRQ_TYPE_EDGE_RISING);
+
+	/* enable keyboard */
+	ams_delta_latch2_write(AMD_DELTA_LATCH2_KEYBRD_PWR,
+			AMD_DELTA_LATCH2_KEYBRD_PWR);

This shoukd probably go into open() method of the serio port.

Quoted 11 lines
drivers/input/serio/ams_delta_keyboard.c +11 -0
+
+	serio_register_port(ams_delta_kbd_port);
+	printk(KERN_INFO "serio: AMS DELTA keyboard adapter\n");
+
+	return 0;
+gpio_clk:
+	gpio_free(AMS_DELTA_GPIO_PIN_KEYBRD_CLK);
+gpio_data:
+	gpio_free(AMS_DELTA_GPIO_PIN_KEYBRD_DATA);
+serio:
+	kfree(ams_delta_kbd_port);

drivers/input/serio/ams_delta_keyboard.c line 165

Quoted 10 lines
drivers/input/serio/ams_delta_keyboard.c +10 -0
+err:
+	return err;
+}
+module_init(ams_delta_kbd_init);
+
+static void __exit ams_delta_kbd_exit(void)
+{
+	serio_unregister_port(ams_delta_kbd_port);
+	/* disable keyboard */
+	ams_delta_latch2_write(AMD_DELTA_LATCH2_KEYBRD_PWR, 0);

And this into close().

drivers/input/serio/ams_delta_keyboard.c line 171

Quoted 6 lines
drivers/input/serio/ams_delta_keyboard.c +6 -0
+	free_irq(OMAP_GPIO_IRQ(AMS_DELTA_GPIO_PIN_KEYBRD_CLK), 0);
+	gpio_free(AMS_DELTA_GPIO_PIN_KEYBRD_CLK);
+	gpio_free(AMS_DELTA_GPIO_PIN_KEYBRD_DATA);
+	kfree(ams_delta_kbd_port);
+}
+module_exit(ams_delta_kbd_exit);

Thanks.

Signature · 1 line
Dmitry
#9 lore raw

Re: [RFC][PATCH v2 4/5] input: serio: add support for Amstrad Delta serial keyboard port

Quoted 4 lines · Tuesday 30 March 2010 08:56:19 Dmitry Torokhov wrote:
Quoted 3 lines · Janusz Krzysztofik

The patch introduces a serio driver that supports a keyboard serial port found on the Amstrad Delta videophone board.

[snip]

Quoted 4 lines
Quoted 1 line

+#define MAX_SCANCODE 0x84

Not needed anymore?

[snip]

Quoted 8 lines

drivers/input/serio/ams_delta_keyboard.c line 47

Quoted 3 lines
drivers/input/serio/ams_delta_keyboard.c +3 -0
+		printk(KERN_WARNING
+				"Invalid stop bit in AMS keyboard"
+				" data=0x%X\r\n", data);

Consider switching top dev_err(), dev_warning(), etc. Also do not split text strings, even if you run over 80 column limit. BTW, why "\r\n" in the message?

[snip]

Quoted 4 lines

drivers/input/serio/ams_delta_keyboard.c line 96

Quoted 1 line
drivers/input/serio/ams_delta_keyboard.c +1 -0
+	serio = kmalloc(sizeof(struct serio), GFP_KERNEL);

kzalloc() please.

[snip]

Quoted 4 lines

drivers/input/serio/ams_delta_keyboard.c line 102

Quoted 1 line
drivers/input/serio/ams_delta_keyboard.c +1 -0
+		snprintf(serio->phys, sizeof(serio->phys), "%s/serio0", "GPIO");

strlcpy(serio->phys, "GPIO/serio0", sizeof(serio->phys)); ?

[snip]

Quoted 7 lines

drivers/input/serio/ams_delta_keyboard.c line 120

Quoted 3 lines
drivers/input/serio/ams_delta_keyboard.c +3 -0
+	if (gpio_request(AMS_DELTA_GPIO_PIN_KEYBRD_DATA, "kbd-data")) {
+		printk(KERN_ERR "Couldn't request gpio pin for keyboard data");
+		err = -EINVAL;

Why do you mangle return value of gpio_request()? Just return what it reported. Same goes for request_irq() below.

[snip]

Quoted 6 lines

drivers/input/serio/ams_delta_keyboard.c line 144

Quoted 3 lines
drivers/input/serio/ams_delta_keyboard.c +3 -0
+	/* enable keyboard */
+	ams_delta_latch2_write(AMD_DELTA_LATCH2_KEYBRD_PWR,
+			AMD_DELTA_LATCH2_KEYBRD_PWR);

This shoukd probably go into open() method of the serio port.

[snip]

Quoted 5 lines

drivers/input/serio/ams_delta_keyboard.c line 165

Quoted 2 lines
drivers/input/serio/ams_delta_keyboard.c +2 -0
+	/* disable keyboard */
+	ams_delta_latch2_write(AMD_DELTA_LATCH2_KEYBRD_PWR, 0);

And this into close().

Hi Dmitry,
Thanks for your review time. I agree with all your comments and will address them in next version.

Regards,
Janusz

#10 lore raw

RFC PATCH v2 5/5 omap1: Amstrad Delta: modify defconfig for external keyboard support

In reply to Janusz Krzysztofik

The patch adds a CONFIG directive required for supporting the Amstrad Delta connected external keyboard by default.

Works on top of patch 4/5:
input: serio: add support for Amstrad Delta serial keyboard port

Created and tested against linux-2.6.34-rc2.

---
v2 changes:
- no functional changes,
- refreshed against linux-2.6.34-rc2.

 arch/arm/configs/ams_delta_defconfig |    1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/ams_delta_defconfig +1 -0
diff -uprN git.orig/arch/arm/configs/ams_delta_defconfig git/arch/arm/configs/ams_delta_defconfig
@@ -700,6 +700,7 @@ CONFIG_SERIO=y
 CONFIG_SERIO_SERPORT=y
 CONFIG_SERIO_LIBPS2=y
 # CONFIG_SERIO_RAW is not set
+CONFIG_SERIO_AMS_DELTA=y
 # CONFIG_GAMEPORT is not set
 
 #
#11 lore raw
In reply to Janusz Krzysztofik

Monday 29 March 2010 16:19:23 Janusz Krzysztofik napisał(a):

Quoted 14 lines

This series of patches adds support for an external keyboard (called mailboard) connected to the Amstrad Delta (E3) videophone.

The series is based on a patch by Matt Callow, created against linux-omap-2.6.19[1], initially submitted to the e3-hacking mailing list in April 2006[2].

Since the keyboard serial clock line is connected to a GPIO line, it generates interrupts every single bit received. In order to handle this correctly, the code makes use of a FIQ hardware feature. Since all GPIO generated interrupts would be converted to FIQ, the handler must include support for all supported GPIO connected devices: the keyboard, a modem and a hook switch.

Quoted 9 lines

My modifications to the original patch include:
- split into several patches,
- refresh against a recent linux version,
- a lot of cleanups, mainly to get rid of checkpatch reported issues,
- add support for handling interrupts generated by a GPIO line that the meanwhile activated hook switch hangs off.
v2 changes:
- remove scan code to key code mapping from the serio driver, that doesn't belong here and should be set up from userspace;

Hi,

For those of you who would like to do some testing:

You'll need a utility for installing a key table. Given no single hint from linux-input team, I ended up using input-kbd, that is part of input-utils package, at least on Gentoo and Debian. Other possibilities I know of:
- V4L guys provided linux/Documentation/DocBook/v4l/keytable.c.xml example,
- http://0pointer.de/lennart/projects/keyfuzz/

My input-kbd compatible /etc/mailboard.map for my Delta looks like this:
-------------------------
112 = KEY_ESC
122 = KEY_F1
70 = KEY_F2
124 = KEY_F3
119 = KEY_F4
114 = KEY_F5
105 = KEY_F6
26 = KEY_F7
42 = KEY_F8
28 = KEY_F9
21 = KEY_F10
113 = KEY_TAB
116 = KEY_1
115 = KEY_2
107 = KEY_3
34 = KEY_4
27 = KEY_5
29 = KEY_6
30 = KEY_7
121 = KEY_8
125 = KEY_9
117 = KEY_0
108 = KEY_BACKSPACE
33 = KEY_Q
35 = KEY_W
36 = KEY_E
38 = KEY_R
82 = KEY_T
93 = KEY_Y
13 = KEY_U
14 = KEY_I
50 = KEY_O
52 = KEY_P
44 = KEY_ENTER
49 = KEY_A
51 = KEY_S
53 = KEY_D
54 = KEY_F
41 = KEY_G
91 = KEY_H
3 = KEY_J
118 = KEY_K
58 = KEY_L
59 = KEY_BACKSLASH # there is no KEY_AT
60 = KEY_LEFTSHIFT
61 = KEY_Z
78 = KEY_X
84 = KEY_C
11 = KEY_V
5 = KEY_B
65 = KEY_N
66 = KEY_M
67 = KEY_DOT
62 = KEY_UP
85 = KEY_RIGHTSHIFT
259 = KEY_LEFTCTRL
6 = KEY_LEFTALT
73 = KEY_RIGHTMETA
75 = KEY_SPACE
68 = KEY_COMMA
22 = KEY_LEFT
46 = KEY_DOWN
9 = KEY_RIGHT
-------------------------
You may want to adopt it to better suit your taste.

My udev installs it up automatically for me with this simple rule:
-------------------------

ACTION=="add", KERNEL=="event[0-9]*", \ 
	ATTRS{phys}=="GPIO/serio[0-9]*/input[0-9]*", \ 
	RUN+="/usr/bin/input-kbd -f /etc/mailboard.map %n"

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

If you are using Angstrom (or other OpenEmbedded generated distribution), you may want to give my simple recipes/input-utils/input-utils.bb recipe a try:
-------------------------
PV = "20081014-${SRCREV}"
SRCREV = "101501"

SRC_URI = "http://dl.bytesex.org/cvs-snapshots/input-${PV}.tar.gz \
	file://fix-makefiles.patch;patch=1"

LICENSE = "GPL"
inherit autotools
S = "${WORKDIR}/input"
PACKAGES_prepend = "input-kbd input-remote " FILES_input-kbd = "/usr/bin/input-kbd" FILES_input-remote = "/usr/bin/input-send /usr/bin/input-recv"
--------------------------

and recipes/input-utils/files/fix-makefiles.patch:
--------------------------

mk/Variables.mk renamed from mk/Variables.mk.orig +1 -1
@@ -30,7 +30,7 @@ MOC             ?= $(if $(QTDIR),$(QTDIR
 
 STRIP		?= -s
 INSTALL		?= install
-INSTALL_BINARY  := $(INSTALL) $(STRIP)
+INSTALL_BINARY  := $(INSTALL)
 INSTALL_SCRIPT  := $(INSTALL)
 INSTALL_DATA	:= $(INSTALL) -m 644
 INSTALL_DIR	:= $(INSTALL) -d

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

After putting the above two files in your local OE overlay, building the package(s) with "bitbake input-utils" and refreshing your repository Packeges list, all you need is running "opkg install input-kbd" on your Delta.

Have fun,
Janusz

Quoted 33 lines

thanks to Dmitry
Torokhov for advising this,
- no funtional changes in FIQ part (there were no comments in round 1).

There is still one minor issue that I was not able to deal with: when built with CONFIG_OMAP_RESET_CLOCKS=y, the keyboard driver stops working. I have no idea how I could find which clock I should enable to get it working regardless of boot loader used. Any suggestions?

Created and tested against linux-2.6.34-rc2.

Janusz Krzysztofik(5)
omap1: Amstrad Delta: add FIQ handler for serial keyboard port interrupt
processing
omap1: Amstrad Delta: add a handler for processing interrupts generated by
the FIQ routine
omap1: Amstrad Delta: use FIQ for processing GPIO interrupts
input: serio: add support for Amstrad Delta serial keyboard port
omap1: Amstrad Delta: modify defconfig for external keyboard support

 arch/arm/configs/ams_delta_defconfig             |    2
 arch/arm/mach-omap1/Kconfig                      |    8
 arch/arm/mach-omap1/Makefile                     |    3
 arch/arm/mach-omap1/ams-delta-fiq-handler.S      |  342
+++++++++++++++++++++++ arch/arm/mach-omap1/ams-delta-fiq.c              | 
175 +++++++++++ arch/arm/mach-omap1/board-ams-delta.c            |    6
 arch/arm/mach-omap1/include/mach/ams-delta-fiq.h |   57 +++
 arch/arm/plat-omap/include/plat/irqs.h           |    4
 drivers/input/serio/Kconfig                      |    9
 drivers/input/serio/Makefile                     |    1
 drivers/input/serio/ams_delta_keyboard.c         |  171 +++++++++++
 11 files changed, 777 insertions(+), 1 deletion(-)
Quoted 5 lines

Thanks,
Janusz

[1] http://the.earth.li/pub/e3/2.6.19/ams-delta-keyboard.patch
[2] http://www.earth.li/pipermail/e3-hacking/2006-April/000453.html

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#12 lore raw
Quoted 26 lines · Janusz Krzysztofik

Monday 29 March 2010 16:19:23 Janusz Krzysztofik napisał(a):

Quoted 14 lines

This series of patches adds support for an external keyboard (called mailboard) connected to the Amstrad Delta (E3) videophone.

The series is based on a patch by Matt Callow, created against linux-omap-2.6.19[1], initially submitted to the e3-hacking mailing list in April 2006[2].

Since the keyboard serial clock line is connected to a GPIO line, it generates interrupts every single bit received. In order to handle this correctly, the code makes use of a FIQ hardware feature. Since all GPIO generated interrupts would be converted to FIQ, the handler must include support for all supported GPIO connected devices: the keyboard, a modem and a hook switch.

Quoted 9 lines

My modifications to the original patch include:
- split into several patches,
- refresh against a recent linux version,
- a lot of cleanups, mainly to get rid of checkpatch reported issues,
- add support for handling interrupts generated by a GPIO line that the meanwhile activated hook switch hangs off.
v2 changes:
- remove scan code to key code mapping from the serio driver, that doesn't belong here and should be set up from userspace;

Quoted 6 lines

Hi,

For those of you who would like to do some testing:

You'll need a utility for installing a key table. Given no single hint from linux-input team,

Sorry about that.

Quoted 5 lines

I ended up using input-kbd, that is part of input-utils package, at least on Gentoo and Debian. Other possibilities I know of:
- V4L guys provided linux/Documentation/DocBook/v4l/keytable.c.xml example,
- http://0pointer.de/lennart/projects/keyfuzz/

HAL used to be responsible for loading custom keymaps on modern distros but I believe now that task is moved into udev (see extras/keymap).

Signature · 5 lines
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html