Commit 459021fe authored by Adrian McMenamin's avatar Adrian McMenamin Committed by Paul Mundt

input: Clean up maple keyboard driver

Have a single probe function instead of a probe and a connect function.
Also tidy a comment.
Signed-off-by: default avatarAdrian McMenamin <adrian@mcmen.demon.co.uk>
Signed-off-by: default avatarPaul Mundt <lethal@linux-sh.org>
parent 86d9d32c
...@@ -143,8 +143,8 @@ static void dc_kbd_callback(struct mapleq *mq) ...@@ -143,8 +143,8 @@ static void dc_kbd_callback(struct mapleq *mq)
unsigned long *buf = mq->recvbuf; unsigned long *buf = mq->recvbuf;
/* /*
* We should always be getting the lock because the only * We should always get the lock because the only
* time it may be locked if driver is in cleanup phase. * time it may be locked is if the driver is in the cleanup phase.
*/ */
if (likely(mutex_trylock(&maple_keyb_mutex))) { if (likely(mutex_trylock(&maple_keyb_mutex))) {
...@@ -157,103 +157,80 @@ static void dc_kbd_callback(struct mapleq *mq) ...@@ -157,103 +157,80 @@ static void dc_kbd_callback(struct mapleq *mq)
} }
} }
static int dc_kbd_connect(struct maple_device *mdev) static int probe_maple_kbd(struct device *dev)
{ {
struct maple_device *mdev = to_maple_dev(dev);
struct maple_driver *mdrv = to_maple_driver(dev->driver);
int i, error; int i, error;
struct dc_kbd *kbd; struct dc_kbd *kbd;
struct input_dev *dev; struct input_dev *idev;
if (!(mdev->function & MAPLE_FUNC_KEYBOARD))
return -EINVAL;
kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL); kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
if (!kbd) { idev = input_allocate_device();
if (!kbd || !idev) {
error = -ENOMEM; error = -ENOMEM;
goto fail_kbd; goto fail;
}
dev = input_allocate_device();
if (!dev) {
error = -ENOMEM;
goto fail_dev;
} }
mdev->private_data = kbd; mdev->private_data = kbd;
kbd->dev = dev; kbd->dev = idev;
memcpy(kbd->keycode, dc_kbd_keycode, sizeof(kbd->keycode)); memcpy(kbd->keycode, dc_kbd_keycode, sizeof(kbd->keycode));
dev->name = mdev->product_name; idev->name = mdev->product_name;
dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
dev->keycode = kbd->keycode; idev->keycode = kbd->keycode;
dev->keycodesize = sizeof(unsigned short); idev->keycodesize = sizeof(unsigned short);
dev->keycodemax = ARRAY_SIZE(kbd->keycode); idev->keycodemax = ARRAY_SIZE(kbd->keycode);
dev->id.bustype = BUS_HOST; idev->id.bustype = BUS_HOST;
dev->dev.parent = &mdev->dev; idev->dev.parent = &mdev->dev;
for (i = 0; i < NR_SCANCODES; i++) for (i = 0; i < NR_SCANCODES; i++)
__set_bit(dc_kbd_keycode[i], dev->keybit); __set_bit(dc_kbd_keycode[i], idev->keybit);
__clear_bit(KEY_RESERVED, dev->keybit); __clear_bit(KEY_RESERVED, idev->keybit);
input_set_capability(dev, EV_MSC, MSC_SCAN); input_set_capability(idev, EV_MSC, MSC_SCAN);
input_set_drvdata(dev, kbd); input_set_drvdata(idev, kbd);
error = input_register_device(dev); error = input_register_device(idev);
if (error) if (error)
goto fail; goto fail;
/* Maple polling is locked to VBLANK - which may be just 50/s */ /* Maple polling is locked to VBLANK - which may be just 50/s */
maple_getcond_callback(mdev, dc_kbd_callback, HZ/50, maple_getcond_callback(mdev, dc_kbd_callback, HZ/50,
MAPLE_FUNC_KEYBOARD); MAPLE_FUNC_KEYBOARD);
return 0;
mdev->driver = mdrv;
return error;
fail: fail:
input_free_device(dev); input_free_device(idev);
fail_dev:
kfree(kbd); kfree(kbd);
fail_kbd:
mdev->private_data = NULL; mdev->private_data = NULL;
return error; return error;
} }
static void dc_kbd_disconnect(struct maple_device *mdev) static int remove_maple_kbd(struct device *dev)
{ {
struct maple_device *mdev = to_maple_dev(dev);
struct dc_kbd *kbd; struct dc_kbd *kbd;
mutex_lock(&maple_keyb_mutex); mutex_lock(&maple_keyb_mutex);
mdev->callback = NULL;
kbd = mdev->private_data; kbd = mdev->private_data;
mdev->private_data = NULL; mdev->private_data = NULL;
input_unregister_device(kbd->dev); input_unregister_device(kbd->dev);
kfree(kbd); kfree(kbd);
mutex_unlock(&maple_keyb_mutex); mutex_unlock(&maple_keyb_mutex);
}
/* allow the keyboard to be used */
static int probe_maple_kbd(struct device *dev)
{
struct maple_device *mdev = to_maple_dev(dev);
struct maple_driver *mdrv = to_maple_driver(dev->driver);
int error;
error = dc_kbd_connect(mdev);
if (error)
return error;
mdev->driver = mdrv;
return 0;
}
static int remove_maple_kbd(struct device *dev)
{
struct maple_device *mdev = to_maple_dev(dev);
dc_kbd_disconnect(mdev);
return 0; return 0;
} }
static struct maple_driver dc_kbd_driver = { static struct maple_driver dc_kbd_driver = {
.function = MAPLE_FUNC_KEYBOARD, .function = MAPLE_FUNC_KEYBOARD,
.connect = dc_kbd_connect,
.disconnect = dc_kbd_disconnect,
.drv = { .drv = {
.name = "Dreamcast_keyboard", .name = "Dreamcast_keyboard",
.probe = probe_maple_kbd, .probe = probe_maple_kbd,
...@@ -261,19 +238,6 @@ static struct maple_driver dc_kbd_driver = { ...@@ -261,19 +238,6 @@ static struct maple_driver dc_kbd_driver = {
}, },
}; };
static int unplug_maple_keyb(struct device *dev, void *ignored)
{
/* Please DO NOT really unplug your keyboard */
struct maple_device *mdev;
mdev = to_maple_dev(dev);
if ((mdev->function & MAPLE_FUNC_KEYBOARD)
&& (mdev->driver == &dc_kbd_driver))
remove_maple_kbd(dev);
return 0;
}
static int __init dc_kbd_init(void) static int __init dc_kbd_init(void)
{ {
return maple_driver_register(&dc_kbd_driver.drv); return maple_driver_register(&dc_kbd_driver.drv);
...@@ -281,7 +245,6 @@ static int __init dc_kbd_init(void) ...@@ -281,7 +245,6 @@ static int __init dc_kbd_init(void)
static void __exit dc_kbd_exit(void) static void __exit dc_kbd_exit(void)
{ {
bus_for_each_dev(&maple_bus_type, NULL, NULL, unplug_maple_keyb);
driver_unregister(&dc_kbd_driver.drv); driver_unregister(&dc_kbd_driver.drv);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment