Skip to contentSkip to conversation

input: support maple controller on SEGA Dreamcast

PATCH In review Adrian McMenamin 2 participants 5 messages Feb 24, 2008 – Apr 21, 2008

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

PATCH 1/1 input: support maple controller on SEGA Dreamcast

This is a port of the old (never in mainline) 2.4 driver.

(It also fixes some issues with earlier patches which should be discarded for this)

---

b/drivers/input/joystick/Kconfig renamed from a/drivers/input/joystick/Kconfig +13 -0
diff -ruN ./a/drivers/input/joystick/Kconfig ./b/drivers/input/joystick/Kconfig
@@ -282,4 +282,17 @@
 	  This option enables support for the LED which surrounds the Big X on
 	  XBox 360 controller.
 
+config JOYSTICK_MAPLE
+	tristate "Dreamcast control pad"
+	depends on SH_DREAMCAST
+	select MAPLE
+	help
+	  Say Y here if you have a SEGA Dreamcast and want to use your
+	  controller.
+
+	  Most Dreamcast users will say Y.
+
+	  To compile this as a module choose M here: the
+	  module will be called maplecontrol.
+
 endif
b/drivers/input/joystick/Makefile renamed from a/drivers/input/joystick/Makefile +1 -0
diff -ruN ./a/drivers/input/joystick/Makefile ./b/drivers/input/joystick/Makefile
@@ -27,5 +27,6 @@
 obj-$(CONFIG_JOYSTICK_TWIDJOY)		+= twidjoy.o
 obj-$(CONFIG_JOYSTICK_WARRIOR)		+= warrior.o
 obj-$(CONFIG_JOYSTICK_XPAD)		+= xpad.o
+obj-$(CONFIG_JOYSTICK_MAPLE)		+= maplecontrol.o
 
 obj-$(CONFIG_JOYSTICK_IFORCE)		+= iforce/
b/drivers/input/joystick/maplecontrol.c renamed from a/drivers/input/joystick/maplecontrol.c +252 -0

252 lines not on this page · raw message

#1 lore raw

Add support for the Dreamcast maple controller (as a joystick).

Earlier patches caused subdevice detection headaches. Please use this one.

---

b/drivers/input/joystick/Kconfig renamed from a/drivers/input/joystick/Kconfig +13 -0
diff -ruN ./a/drivers/input/joystick/Kconfig ./b/drivers/input/joystick/Kconfig
@@ -282,4 +282,17 @@
 	  This option enables support for the LED which surrounds the Big X on
 	  XBox 360 controller.
 
+config JOYSTICK_MAPLE
+	tristate "Dreamcast control pad"
+	depends on SH_DREAMCAST
+	select MAPLE
+	help
+	  Say Y here if you have a SEGA Dreamcast and want to use your
+	  controller.
+
+	  Most Dreamcast users will say Y.
+
+	  To compile this as a module choose M here: the
+	  module will be called maplecontrol.
+
 endif
b/drivers/input/joystick/Makefile renamed from a/drivers/input/joystick/Makefile +1 -0
diff -ruN ./a/drivers/input/joystick/Makefile ./b/drivers/input/joystick/Makefile
@@ -27,5 +27,6 @@
 obj-$(CONFIG_JOYSTICK_TWIDJOY)		+= twidjoy.o
 obj-$(CONFIG_JOYSTICK_WARRIOR)		+= warrior.o
 obj-$(CONFIG_JOYSTICK_XPAD)		+= xpad.o
+obj-$(CONFIG_JOYSTICK_MAPLE)		+= maplecontrol.o
 
 obj-$(CONFIG_JOYSTICK_IFORCE)		+= iforce/
b/drivers/input/joystick/maplecontrol.c renamed from a/drivers/input/joystick/maplecontrol.c +222 -0

222 lines not on this page · raw message

#2 lore raw

PATCH 1/1 input: support maple controller on SEGA Dreamcast

In reply to Adrian McMenamin

This adds support for the maple controller (as a joystick) on the SEGA Dreamcast.

I've adjusted the polling rate for the controller in comparison to earlier patches and the high rate of polling was locking out hotplugging updates.

---

drivers/input/joystick/Kconfig +13 -0
diff -ruN a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
@@ -282,4 +282,17 @@
 	  This option enables support for the LED which surrounds the Big X on
 	  XBox 360 controller.
 
+config JOYSTICK_MAPLE
+	tristate "Dreamcast control pad"
+	depends on SH_DREAMCAST
+	select MAPLE
+	help
+	  Say Y here if you have a SEGA Dreamcast and want to use your
+	  controller.
+
+	  Most Dreamcast users will say Y.
+
+	  To compile this as a module choose M here: the
+	  module will be called maplecontrol.
+
 endif
drivers/input/joystick/Makefile +1 -0
diff -ruN a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
@@ -27,5 +27,6 @@
 obj-$(CONFIG_JOYSTICK_TWIDJOY)		+= twidjoy.o
 obj-$(CONFIG_JOYSTICK_WARRIOR)		+= warrior.o
 obj-$(CONFIG_JOYSTICK_XPAD)		+= xpad.o
+obj-$(CONFIG_JOYSTICK_MAPLE)		+= maplecontrol.o
 
 obj-$(CONFIG_JOYSTICK_IFORCE)		+= iforce/
drivers/input/joystick/maplecontrol.c +222 -0

222 lines not on this page · raw message

maintainer
#3 lore raw

Hi Adrian,

Quoted 8 lines · Adrian McMenamin

This adds support for the maple controller (as a joystick) on the SEGA Dreamcast.

I've adjusted the polling rate for the controller in comparison to earlier patches and the high rate of polling was locking out hotplugging updates.

Sorry for sittign on the patches for so long, just catching up with my long backlog... Several comments:

drivers/input/joystick/maplecontrol.c line 25

Quoted 5 lines
drivers/input/joystick/maplecontrol.c +5 -0
+
+struct dc_pad {
+	struct input_dev *dev;
+	struct maple_device *mdev;
+	int open;

I don't see "open" being used.

Quoted 4 lines
drivers/input/joystick/maplecontrol.c +4 -0
+	for (i = 0; i < 32; i++)
+		if (data & (1<<i) && btn_bit[i] >= 0)
+			pad->dev->keybit[BIT_WORD(BTN_JOYSTICK)] |= BIT_MASK(btn_bit[i]);
+

drivers/input/joystick/maplecontrol.c line 114

Quoted 10 lines
drivers/input/joystick/maplecontrol.c +10 -0
+	if (pad->dev->keybit[BTN_JOYSTICK/32])
+		pad->dev->evbit[0] |= BIT_MASK(EV_KEY);
+
+	for (i = 0; i < 32; i++)
+		if (data & (1<<i) && abs_bit[i] >= 0)
+			pad->dev->absbit[0] |= BIT_MASK(abs_bit[i]);
+
+	if (pad->dev->absbit[0])
+		pad->dev->evbit[0] |= BIT_MASK(EV_ABS);
+

Just use dev->.. instead of pad->dev->.., it will save a few bytes.

drivers/input/joystick/maplecontrol.c line 121

Quoted 7 lines
drivers/input/joystick/maplecontrol.c +7 -0
+	for (i = ABS_X; i <= ABS_BRAKE; i++) {
+		pad->dev->absmax[i] = 255;
+		pad->dev->absmin[i] = 0;
+		pad->dev->absfuzz[i] = 0;
+		pad->dev->absflat[i] = 0;
+	}
+

I like input_set_abs_params(...), it is more concise and you don't need a separate loop to set up absbits.

Quoted 11 lines
drivers/input/joystick/maplecontrol.c +11 -0
+	for (i = ABS_HAT0X; i <= ABS_HAT3Y; i++) {
+		pad->dev->absmax[i] = 1;
+		pad->dev->absmin[i] = -1;
+		pad->dev->absfuzz[i] = 0;
+		pad->dev->absflat[i] = 0;
+	}
+
+	pad->dev->private = pad;
+	pad->dev->event = NULL;
+	pad->dev->dev.parent = &mdev->dev;
+	pad->dev->name = mdev->product_name;

drivers/input/joystick/maplecontrol.c line 142

Quoted 10 lines
drivers/input/joystick/maplecontrol.c +10 -0
+	pad->dev->id.bustype = BUS_HOST;
+	input_set_drvdata(dev, pad);
+
+	error = input_register_device(pad->dev);
+	if (error)
+		goto fail_register;
+
+	maple_getcond_callback(mdev, dc_pad_callback, HZ/10,
+		MAPLE_FUNC_CONTROLLER);
+	

May I recommend creating maple_open and maple_close and start polling from there? This way we only poll if we have users.

Quoted 65 lines
drivers/input/joystick/maplecontrol.c +65 -0
+	return error;
+
+fail_register:
+	input_free_device(pad->dev);
+fail_nomem_2:
+	kfree(pad);
+fail_nomem_1:
+	return -error;
+}
+
+static void dc_pad_disconnect(struct maple_device *mdev)
+{
+	struct dc_pad *pad = mdev->private_data;
+
+	mdev->callback = NULL;
+	input_unregister_device(pad->dev);
+	kfree(pad);
+}
+
+/* allow the controller to be used */
+static int probe_maple_controller(struct device *dev)
+{
+	struct maple_device *mdev = to_maple_dev(dev);
+	struct maple_driver *mdrv = to_maple_driver(dev->driver);
+	int error;
+
+	error = dc_pad_connect(mdev);
+	if (error)
+		return error;
+
+	mdev->driver = mdrv;
+
+	return 0;
+}
+
+static int remove_maple_controller(struct device *dev)
+{
+	struct maple_device *mdev = to_maple_dev(dev);
+
+	dc_pad_disconnect(mdev);
+	return 0;
+}
+
+static struct maple_driver dc_pad_driver = {
+	.function =	MAPLE_FUNC_CONTROLLER,
+	.connect =	dc_pad_connect,
+	.disconnect =	dc_pad_disconnect,
+	.drv = {
+		.name = "Dreamcast_controller",
+		.probe = probe_maple_controller,
+		.remove = remove_maple_controller,
+	},
+};
+
+static int unplug_maple_control(struct device *dev, void *ignored)
+{
+	/* Please DO NOT really unplug your controller */
+	struct maple_device *mdev;
+
+	mdev = to_maple_dev(dev);
+	if ((mdev->function & MAPLE_FUNC_CONTROLLER)
+		&& (mdev->driver = &dc_pad_driver))
+		remove_maple_controller(dev);
+
+	return 0;

drivers/input/joystick/maplecontrol.c line 217

Quoted 10 lines
drivers/input/joystick/maplecontrol.c +10 -0
+}
+
+static int __init dc_pad_init(void)
+{
+	return 	maple_driver_register(&dc_pad_driver.drv);
+}
+
+static void __exit dc_pad_exit(void)
+{
+	bus_for_each_dev(&maple_bus_type, NULL, NULL, unplug_maple_control);

Why is this needed? As far as I know most driver core will automatically disconnect devices form driver upon driver unregistration, so manually iteracting through all devices on bus is not needed.

drivers/input/joystick/maplecontrol.c line 222

Quoted 7 lines
drivers/input/joystick/maplecontrol.c +5 -0
+	driver_unregister(&dc_pad_driver.drv);
+}
+
+module_init(dc_pad_init);
+module_exit(dc_pad_exit);

Thank you.

Signature · 1 line
Dmitry
#4 lore raw

Have reworked this in (I hope) ways suggested)

Add support for the maple control pad (as a joystick)

---

b/drivers/input/joystick/Kconfig renamed from a/drivers/input/joystick/Kconfig +13 -0
diff -ruN ./a/drivers/input/joystick/Kconfig ./b/drivers/input/joystick/Kconfig
@@ -282,4 +282,17 @@
 	  This option enables support for the LED which surrounds the Big X on
 	  XBox 360 controller.
 
+config JOYSTICK_MAPLE
+	tristate "Dreamcast control pad"
+	depends on SH_DREAMCAST
+	select MAPLE
+	help
+	  Say Y here if you have a SEGA Dreamcast and want to use your
+	  controller.
+
+	  Most Dreamcast users will say Y.
+
+	  To compile this as a module choose M here: the
+	  module will be called maplecontrol.
+
 endif
b/drivers/input/joystick/Makefile renamed from a/drivers/input/joystick/Makefile +1 -0
diff -ruN ./a/drivers/input/joystick/Makefile ./b/drivers/input/joystick/Makefile
@@ -27,5 +27,6 @@
 obj-$(CONFIG_JOYSTICK_TWIDJOY)		+= twidjoy.o
 obj-$(CONFIG_JOYSTICK_WARRIOR)		+= warrior.o
 obj-$(CONFIG_JOYSTICK_XPAD)		+= xpad.o
+obj-$(CONFIG_JOYSTICK_MAPLE)		+= maplecontrol.o
 
 obj-$(CONFIG_JOYSTICK_IFORCE)		+= iforce/
b/drivers/input/joystick/maplecontrol.c renamed from a/drivers/input/joystick/maplecontrol.c +217 -0

217 lines not on this page · raw message