Skip to contentSkip to conversation

Add support for keyboard on SEGA Dreamcast

PATCH In review Adrian McMenamin 3 participants 5 messages Sep 4, 2007 – Sep 7, 2007 Input drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add support for keyboard on SEGA Dreamcast

This patch will add support for the Dreamcast keyboard when used alongside the maple bus patch (http://lkml.org/lkml/2007/9/4/165) and the pvr2 patch.

Signed off by: Adrian McMenamin <[email protected]>

drivers/input/keyboard/Kconfig +10 -0
index c97d5eb..1689f73 100644
@@ -253,4 +253,14 @@ config KEYBOARD_GPIO
 	  To compile this driver as a module, choose M here: the
 	  module will be called gpio-keys.
 
+
+config KEYBOARD_MAPLE
+	tristate "Maple bus keyboard"
+	depends on SH_DREAMCAST && MAPLE
+	help
+	  Say Y here if you have a DreamCast console running Linux and have
+	  a keyboard attached to its Maple bus.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called maple_keyb.	
 endif
drivers/input/keyboard/Makefile +1 -0
index 28d211b..3f775ed 100644
@@ -21,4 +21,5 @@ obj-$(CONFIG_KEYBOARD_OMAP)		+= omap-keypad.o
 obj-$(CONFIG_KEYBOARD_PXA27x)		+= pxa27x_keyboard.o
 obj-$(CONFIG_KEYBOARD_AAED2000)		+= aaed2000_kbd.o
 obj-$(CONFIG_KEYBOARD_GPIO)		+= gpio_keys.o
+obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
 
(quoted diff) +0 -0

b/drivers/input/keyboard/maple_keyb.c
new file mode 100644
index 0000000..12e4692

drivers/input/keyboard/maple_keyb.c new file +222 -0

222 lines not on this page · raw message

include/linux/input.h +1 -0
index e02c6a6..2e65c88 100644
@@ -688,6 +688,7 @@ struct input_absinfo {
 #define BUS_HOST		0x19
 #define BUS_GSC			0x1A
 #define BUS_ATARI		0x1B
+#define BUS_MAPLE		0x1C
 
 /*
  * Values describing the status of a force-feedback effect
#1 lore raw

Hi Adrian,

Quoted 6 lines · Adrian McMenamin

This patch will add support for the Dreamcast keyboard when used alongside the maple bus patch (http://lkml.org/lkml/2007/9/4/165) and the pvr2 patch.

Signed off by: Adrian McMenamin <[email protected]>

Thnank you very much for your patch. Couple of comments:

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static unsigned char dc_kbd_keycode[256] = {

Const?

Quoted 19 lines
drivers/input/keyboard/maple_keyb.c new file +19 -0
+
+static int dc_kbd_connect(struct maple_device *dev)
+{
+	int i, retval;
+	unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
+	struct dc_kbd *kbd;
+	if (dev->function != MAPLE_FUNC_KEYBOARD)
+		return -EINVAL;
+
+	kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
+	if (unlikely(!kbd))
+		return -ENOMEM;
+
+	dev->private_data = kbd;
+	kbd->dev = input_allocate_device();
+	if (unlikely(!kbd->dev))
+		goto cleanup;
+
+	kbd->dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);

drivers/input/keyboard/maple_keyb.c line 151

Quoted 10 lines
drivers/input/keyboard/maple_keyb.c new file +10 -0
+
+	for (i = 0; i < 255; i++)
+		set_bit(dc_kbd_keycode[i], kbd->dev->keybit);
+
+	clear_bit(0, kbd->dev->keybit);
+
+	kbd->dev->private = kbd;
+
+	kbd->dev->name = dev->product_name;
+	kbd->dev->id.bustype = BUS_MAPLE;

Do we really need a new bus type? Would not BUS_HOST suffice?

drivers/input/keyboard/maple_keyb.c line 161

Quoted 10 lines
drivers/input/keyboard/maple_keyb.c new file +10 -0
+
+	retval = input_register_device(kbd->dev);
+	if (unlikely(retval))
+		goto cleanup;
+
+	maple_getcond_callback(dev, dc_kbd_callback, (25 * HZ) / 1000,
+			       MAPLE_FUNC_KEYBOARD);
+
+	printk(KERN_INFO "input: keyboard(0x%lx): %s\n", data,
+	       kbd->dev->name);

Input core already prints a line when a new input device is registered, do we need another one?

drivers/input/keyboard/maple_keyb.c line 167

Quoted 6 lines
drivers/input/keyboard/maple_keyb.c new file +6 -0
+
+	return 0;
+
+      cleanup:
+	kfree(kbd);
+	return -EINVAL;

It loks like call to input_free_device() is missing here. You would leak memory if input_register_device would fail.

I would also get rid of all likelys/unlikelys here - driver registration is not a hot path...

drivers/input/keyboard/maple_keyb.c line 175

Quoted 8 lines
drivers/input/keyboard/maple_keyb.c new file +8 -0
+}
+
+static void dc_kbd_disconnect(struct maple_device *dev)
+{
+	struct dc_kbd *kbd = dev->private_data;
+
+	input_unregister_device(kbd->dev);
+	kfree(kbd);

Are we guaranteed that the dc_kbd_callback is not running in a separate thread?

Please also consider implementing support for changing keyma. Since the keymap is pretty full I think the best way is to copy the vanilla keymap into a per-device memory and set up keymap, keycodesize and keycodemax in input device structure.

Thank you.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 9 lines · Dmitry Torokhov

Are we guaranteed that the dc_kbd_callback is not running in a separate thread?

Please also consider implementing support for changing keyma. Since the keymap is pretty full I think the best way is to copy the vanilla keymap into a per-device memory and set up keymap, keycodesize and keycodemax in input device structure.

Quoted 5 lines

Thank you.

--
Dmitry

Dmitry - have now worked out at least one alternative keymap - for European keyboards. But could you explain the above point? I have to admit I am not too familiar with the input layer - having really taken an old, and bit rot infested 2.4 driver and brought it up to standard for 2.6 - and so I don't follow this point too well!

Can I treat keymaps as firmware and load from userspace? Or is there a way of making this completely user configurable at runtime?

Any help from you, or any other reader, much appreciated.

Adrian

#3 lore raw
In reply to Adrian McMenamin

drivers/input/keyboard/Kconfig config KEYBOARD_GPIO · line 261

Quoted 3 lines · Adrian McMenamin
drivers/input/keyboard/Kconfig +1 -0
+	  Say Y here if you have a DreamCast console running Linux and have

funny caps in Dreamcast

drivers/input/keyboard/maple_keyb.c line 77

Quoted 3 lines
drivers/input/keyboard/maple_keyb.c new file +1 -0
+static void dc_scan_kbd(struct dc_kbd *kbd)

still some funny wrappings in this func ...

drivers/input/keyboard/maple_keyb.c line 106

Quoted 7 lines
drivers/input/keyboard/maple_keyb.c new file +6 -0
+				printk
+				    ("Unknown key (scancode %#x) released.",
+				     kbd->old[i]);
...
+				printk
+				    ("Unknown key (scancode %#x) pressed.",
+				     kbd->new[i]);

missing KERN log levels in those printk's

drivers/input/keyboard/maple_keyb.c line 132

Quoted 6 lines
drivers/input/keyboard/maple_keyb.c new file +4 -0
+static int dc_kbd_connect(struct maple_device *dev)
+{
...
+	struct dc_kbd *kbd;
...
+	kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);

i find this more readable/managable myself:
kbd = kzalloc(*kbd, GFP_KERNEL);

drivers/input/keyboard/maple_keyb.c line 167

Quoted 9 lines
drivers/input/keyboard/maple_keyb.c new file +7 -0
+	kbd->dev = input_allocate_device();
...
+	retval = input_register_device(kbd->dev);
+	if (unlikely(retval))
+		goto cleanup;
...
+      cleanup:
+	kfree(kbd);
+	return -EINVAL;

i'm not familiar with the input layer, but do you need to deallocate that input device if the register fails ? if so, i guess dc_kbd_disconnect() would need tweaking too ...
-mike

#4 lore raw

Hi Mike,

Quoted 10 lines · Mike Frysinger
Quoted 9 lines

+     kbd->dev = input_allocate_device();
...
+     retval = input_register_device(kbd->dev);
+     if (unlikely(retval))
+             goto cleanup;
...
+      cleanup:
+     kfree(kbd);
+     return -EINVAL;

Quoted 3 lines

i'm not familiar with the input layer, but do you need to deallocate that input device if the register fails ?  if so, i guess dc_kbd_disconnect() would need tweaking too ...

No, dc_kbd_disconnect() is fine - the structure is refcounted and so input core will free it when the last reference drops. But you are right, input_free_device() is still needed in error path.

Signature · 1 line
Dmitry