LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/3] input: support maple mouse on Dreamcast
@ 2008-02-24 13:47 Adrian McMenamin
  2008-02-24 13:49 ` [PATCH 2/3] " Adrian McMenamin
  0 siblings, 1 reply; 3+ messages in thread
From: Adrian McMenamin @ 2008-02-24 13:47 UTC (permalink / raw)
  To: Paul Mundt, Dmitry Torokhov; +Cc: linux-sh, LKML

input: support maple mouse on Dreamcast

Signed-off-by: Adrian McMenamin <adrian@mcmen.demon.co.uk>
---

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 7bbea09..d171336 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -232,4 +232,16 @@ config MOUSE_GPIO
 	  To compile this driver as a module, choose M here: the
 	  module will be called gpio_mouse.
 
+config MOUSE_MAPLE
+	tristate "Dreamcast mouse"
+	depends on SH_DREAMCAST
+	select MAPLE
+	help
+	  This driver supports the Maple bus mouse on a SEGA Dreamcast.
+
+	  Most Dreamcast users (with a mouse) will want to say Y here.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called maplemouse.
+
 endif


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/3] input: support maple mouse on Dreamcast
  2008-02-24 13:47 [PATCH 1/3] input: support maple mouse on Dreamcast Adrian McMenamin
@ 2008-02-24 13:49 ` Adrian McMenamin
  2008-02-24 13:51   ` [PATCH 3/3] " Adrian McMenamin
  0 siblings, 1 reply; 3+ messages in thread
From: Adrian McMenamin @ 2008-02-24 13:49 UTC (permalink / raw)
  To: Paul Mundt; +Cc: Dmitry Torokhov, linux-sh, LKML


input: update Makefile to support maple mouse on Dreamcast

Signed-off-by: Adrian McMenamin <adrian@mcmen.demon.co.uk>
---

diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index 9e6e363..5d35939 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_MOUSE_SERIAL)	+= sermouse.o
 obj-$(CONFIG_MOUSE_HIL)		+= hil_ptr.o
 obj-$(CONFIG_MOUSE_VSXXXAA)	+= vsxxxaa.o
 obj-$(CONFIG_MOUSE_GPIO)	+= gpio_mouse.o
+obj-$(CONFIG_MOUSE_MAPLE)	+= maplemouse.o
 
 psmouse-objs := psmouse-base.o synaptics.o


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 3/3] input: support maple mouse on Dreamcast
  2008-02-24 13:49 ` [PATCH 2/3] " Adrian McMenamin
@ 2008-02-24 13:51   ` Adrian McMenamin
  0 siblings, 0 replies; 3+ messages in thread
From: Adrian McMenamin @ 2008-02-24 13:51 UTC (permalink / raw)
  To: Paul Mundt; +Cc: Dmitry Torokhov, linux-sh, LKML

input: add support for maple mouse on Dreamcast

Signed-off-by: Adrian McMenamin <adrian@mcmen.demon.co.uk>
---

diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c
new file mode 100644
index 0000000..08cfb6f
--- /dev/null
+++ b/drivers/input/mouse/maplemouse.c
@@ -0,0 +1,148 @@
+/*
+ *	SEGA Dreamcast mouse driver
+ *	Based on drivers/usb/usbmouse.c
+ *
+ *	Copyright Yaegashi Takeshi, 2001
+ *	Porting to 2.6 and other fixes
+ *	copyright, Adrian McMenamin, 2008
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/maple.h>
+#include <asm/mach/maple.h>
+
+MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>");
+MODULE_DESCRIPTION("SEGA Dreamcast mouse driver");
+MODULE_LICENSE("GPL");
+
+static void dc_mouse_callback(struct mapleq *mq)
+{
+	int buttons, relx, rely, relz;
+	struct maple_device *mapledev = mq->dev;
+	struct input_dev *dev = mapledev->private_data;
+	unsigned char *res = mq->recvbuf;
+
+	buttons = ~res[8];
+	relx = *(unsigned short *)(res + 12) - 512;
+	rely = *(unsigned short *)(res + 14) - 512;
+	relz = *(unsigned short *)(res + 16) - 512;
+
+	input_report_key(dev, BTN_LEFT,   buttons & 4);
+	input_report_key(dev, BTN_MIDDLE, buttons & 9);
+	input_report_key(dev, BTN_RIGHT,  buttons & 2);
+	input_report_rel(dev, REL_X,      relx);
+	input_report_rel(dev, REL_Y,      rely);
+	input_report_rel(dev, REL_WHEEL,  relz);
+	input_sync(dev);
+}
+
+static int dc_mouse_connect(struct maple_device *mdev)
+{
+	struct input_dev *input_dev;
+	int error;
+
+	input_dev = input_allocate_device();
+	if (!input_dev) {
+		error = ENOMEM;
+		goto fail_nomem;
+	}
+	mdev->private_data = input_dev;
+
+	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
+	input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
+
+	input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y) | BIT_MASK(REL_WHEEL);
+
+	input_dev->name = mdev->product_name;
+	input_dev->id.bustype = BUS_HOST;
+
+	error =	input_register_device(input_dev);
+	if (error)
+		goto fail_regdev;
+
+	maple_getcond_callback(mdev, dc_mouse_callback, HZ/50, MAPLE_FUNC_MOUSE);
+
+	return error;
+
+fail_regdev:
+	input_free_device(input_dev);
+fail_nomem:
+	return error;
+}
+
+static void dc_mouse_disconnect(struct maple_device *dev)
+{
+	struct input_dev *input_dev = dev->private_data;
+
+	input_unregister_device(input_dev);
+	kfree(input_dev);
+}
+
+/* allow the mouse to be used */
+static int probe_maple_mouse(struct device *dev)
+{
+	struct maple_device *mdev = to_maple_dev(dev);
+	struct maple_driver *mdrv = to_maple_driver(dev->driver);
+	int error;
+
+	error = dc_mouse_connect(mdev);
+	if (error)
+		return error;
+
+	mdev->driver = mdrv;
+
+	return 0;
+}
+
+
+static int remove_maple_mouse(struct device *dev)
+{
+	struct maple_device *mdev = to_maple_dev(dev);
+
+	dc_mouse_disconnect(mdev);
+	return 0;
+}
+
+static struct maple_driver dc_mouse_driver = {
+	.function =	MAPLE_FUNC_MOUSE,
+	.connect =	dc_mouse_connect,
+	.disconnect =	dc_mouse_disconnect,
+	.drv = {
+		.name = "Dreamcast_mouse",
+		.probe = probe_maple_mouse,
+		.remove = remove_maple_mouse,
+	},
+};
+
+static int unplug_maple_mouse(struct device *dev, void *ignored)
+{
+	/* Please DO NOT really unplug your mouse */
+	struct maple_device *mdev;
+
+	mdev = to_maple_dev(dev);
+	if ((mdev->function & MAPLE_FUNC_MOUSE)
+		&& (mdev->driver == &dc_mouse_driver))
+		remove_maple_mouse(dev);
+
+	return 0;
+}
+
+static int __init dc_mouse_init(void)
+{
+	maple_driver_register(&dc_mouse_driver.drv);
+	return 0;
+}
+
+static void __exit dc_mouse_exit(void)
+{
+	bus_for_each_dev(&maple_bus_type, NULL, NULL, unplug_maple_mouse);
+	driver_unregister(&dc_mouse_driver.drv);
+}
+
+module_init(dc_mouse_init);
+module_exit(dc_mouse_exit);


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-02-24 13:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-24 13:47 [PATCH 1/3] input: support maple mouse on Dreamcast Adrian McMenamin
2008-02-24 13:49 ` [PATCH 2/3] " Adrian McMenamin
2008-02-24 13:51   ` [PATCH 3/3] " Adrian McMenamin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).