mirror of
https://github.com/torvalds/linux.git
synced 2024-11-05 03:21:32 +00:00
6b3480855a
The maple mouse driver currently in mainline is broken: bash-3.1# modprobe maplemouse [ 56.886378] input: Dreamcast Mouse as /devices/virtual/input/input3 [ 56.918379] Unable to handle kernel NULL pointer dereference at virtual address 00000004 [ 56.930543] pc = c003304e [ 56.934973] *pde = 00000000 [ 56.944948] Oops: 0000 [#1] [ 56.947867] Modules linked in: maplemouse(+) [ 56.952353] [ 56.953921] Pid : 1157, Comm: \0x09\0x09modprobe [ 56.958021] CPU : 0 \0x09\0x09Not tainted (2.6.30-rc2-00130-g3e98f9f #1) [ 56.958052] [ 56.966567] PC is at dc_mouse_open+0xe/0x40 [maplemouse] [ 56.972125] PR is at input_open_device+0x8a/0xc0 [ 56.976944] PC : c003304e SP : 8c88bdcc SR : 40008100 TEA : c0033834 [ 56.983854] R0 : 000006c4 R1 : 00000000 R2 : 40008101 R3 : 00000000 [ 56.990744] R4 : 8c8db800 R5 : c0033080 R6 : 00000005 R7 : 00000200 [ 56.997635] R8 : 8c8db800 R9 : 8c8dbe3c R10 : 00000000 R11 : 8c98881c [ 57.004525] R12 : 8c8dbe64 R13 : 8ca50140 R14 : 8c88bdd4 [ 57.010063] MACH: 00000497 MACL: 00000348 GBR : 29674440 PR : 8c1b4d0a [ 57.016939] ... Here is a fix for this, keeping an open and close, so reducing the load on the system when the mouse is not in use, and also properly referencing the maple device buffer following the recent update. Signed-off-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
151 lines
3.5 KiB
C
151 lines
3.5 KiB
C
/*
|
|
* SEGA Dreamcast mouse driver
|
|
* Based on drivers/usb/usbmouse.c
|
|
*
|
|
* Copyright (c) Yaegashi Takeshi, 2001
|
|
* Copyright (c) Adrian McMenamin, 2008 - 2009
|
|
*/
|
|
|
|
#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>
|
|
|
|
MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk>");
|
|
MODULE_DESCRIPTION("SEGA Dreamcast mouse driver");
|
|
MODULE_LICENSE("GPL");
|
|
|
|
struct dc_mouse {
|
|
struct input_dev *dev;
|
|
struct maple_device *mdev;
|
|
};
|
|
|
|
static void dc_mouse_callback(struct mapleq *mq)
|
|
{
|
|
int buttons, relx, rely, relz;
|
|
struct maple_device *mapledev = mq->dev;
|
|
struct dc_mouse *mse = maple_get_drvdata(mapledev);
|
|
struct input_dev *dev = mse->dev;
|
|
unsigned char *res = mq->recvbuf->buf;
|
|
|
|
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_open(struct input_dev *dev)
|
|
{
|
|
struct dc_mouse *mse = maple_get_drvdata(to_maple_dev(&dev->dev));
|
|
|
|
maple_getcond_callback(mse->mdev, dc_mouse_callback, HZ/50,
|
|
MAPLE_FUNC_MOUSE);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void dc_mouse_close(struct input_dev *dev)
|
|
{
|
|
struct dc_mouse *mse = maple_get_drvdata(to_maple_dev(&dev->dev));
|
|
|
|
maple_getcond_callback(mse->mdev, dc_mouse_callback, 0,
|
|
MAPLE_FUNC_MOUSE);
|
|
}
|
|
|
|
/* allow the mouse to be used */
|
|
static int __devinit 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;
|
|
struct input_dev *input_dev;
|
|
struct dc_mouse *mse;
|
|
|
|
mse = kzalloc(sizeof(struct dc_mouse), GFP_KERNEL);
|
|
if (!mse) {
|
|
error = -ENOMEM;
|
|
goto fail;
|
|
}
|
|
|
|
input_dev = input_allocate_device();
|
|
if (!input_dev) {
|
|
error = -ENOMEM;
|
|
goto fail_nomem;
|
|
}
|
|
|
|
mse->dev = input_dev;
|
|
mse->mdev = mdev;
|
|
|
|
input_set_drvdata(input_dev, mse);
|
|
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->open = dc_mouse_open;
|
|
input_dev->close = dc_mouse_close;
|
|
input_dev->name = mdev->product_name;
|
|
input_dev->id.bustype = BUS_HOST;
|
|
error = input_register_device(input_dev);
|
|
if (error)
|
|
goto fail_register;
|
|
|
|
mdev->driver = mdrv;
|
|
maple_set_drvdata(mdev, mse);
|
|
|
|
return error;
|
|
|
|
fail_register:
|
|
input_free_device(input_dev);
|
|
fail_nomem:
|
|
kfree(mse);
|
|
fail:
|
|
return error;
|
|
}
|
|
|
|
static int __devexit remove_maple_mouse(struct device *dev)
|
|
{
|
|
struct maple_device *mdev = to_maple_dev(dev);
|
|
struct dc_mouse *mse = maple_get_drvdata(mdev);
|
|
|
|
mdev->callback = NULL;
|
|
input_unregister_device(mse->dev);
|
|
maple_set_drvdata(mdev, NULL);
|
|
kfree(mse);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct maple_driver dc_mouse_driver = {
|
|
.function = MAPLE_FUNC_MOUSE,
|
|
.drv = {
|
|
.name = "Dreamcast_mouse",
|
|
.probe = probe_maple_mouse,
|
|
.remove = __devexit_p(remove_maple_mouse),
|
|
},
|
|
};
|
|
|
|
static int __init dc_mouse_init(void)
|
|
{
|
|
return maple_driver_register(&dc_mouse_driver);
|
|
}
|
|
|
|
static void __exit dc_mouse_exit(void)
|
|
{
|
|
maple_driver_unregister(&dc_mouse_driver);
|
|
}
|
|
|
|
module_init(dc_mouse_init);
|
|
module_exit(dc_mouse_exit);
|