2019-05-27 13:55:05 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999-2001 Vojtech Pavlik
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Input driver event debug module - dumps all events into syslog
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
2010-11-30 14:33:07 +07:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
|
|
|
|
MODULE_DESCRIPTION("Input driver event debug module");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
|
|
|
|
{
|
2010-11-30 14:33:07 +07:00
|
|
|
printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n"),
|
|
|
|
dev_name(&handle->dev->dev), type, code, value);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-04-12 12:29:46 +07:00
|
|
|
static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
|
|
|
|
const struct input_device_id *id)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct input_handle *handle;
|
2007-04-12 12:29:46 +07:00
|
|
|
int error;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-04-12 12:29:46 +07:00
|
|
|
handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
|
|
|
|
if (!handle)
|
|
|
|
return -ENOMEM;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
handle->dev = dev;
|
|
|
|
handle->handler = handler;
|
2007-04-12 12:29:46 +07:00
|
|
|
handle->name = "evbug";
|
|
|
|
|
|
|
|
error = input_register_handle(handle);
|
|
|
|
if (error)
|
|
|
|
goto err_free_handle;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-04-12 12:29:46 +07:00
|
|
|
error = input_open_device(handle);
|
|
|
|
if (error)
|
|
|
|
goto err_unregister_handle;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-11-30 14:33:07 +07:00
|
|
|
printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
|
|
|
|
dev_name(&dev->dev),
|
|
|
|
dev->name ?: "unknown",
|
|
|
|
dev->phys ?: "unknown");
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-04-12 12:29:46 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_unregister_handle:
|
|
|
|
input_unregister_handle(handle);
|
|
|
|
err_free_handle:
|
|
|
|
kfree(handle);
|
|
|
|
return error;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void evbug_disconnect(struct input_handle *handle)
|
|
|
|
{
|
2010-11-30 14:33:07 +07:00
|
|
|
printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
|
|
|
|
dev_name(&handle->dev->dev));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
input_close_device(handle);
|
2007-04-12 12:29:46 +07:00
|
|
|
input_unregister_handle(handle);
|
2005-04-17 05:20:36 +07:00
|
|
|
kfree(handle);
|
|
|
|
}
|
|
|
|
|
2006-09-14 12:31:59 +07:00
|
|
|
static const struct input_device_id evbug_ids[] = {
|
2005-04-17 05:20:36 +07:00
|
|
|
{ .driver_info = 1 }, /* Matches all devices */
|
|
|
|
{ }, /* Terminating zero entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(input, evbug_ids);
|
|
|
|
|
|
|
|
static struct input_handler evbug_handler = {
|
|
|
|
.event = evbug_event,
|
|
|
|
.connect = evbug_connect,
|
|
|
|
.disconnect = evbug_disconnect,
|
|
|
|
.name = "evbug",
|
|
|
|
.id_table = evbug_ids,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init evbug_init(void)
|
|
|
|
{
|
2006-09-14 12:32:39 +07:00
|
|
|
return input_register_handler(&evbug_handler);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit evbug_exit(void)
|
|
|
|
{
|
|
|
|
input_unregister_handler(&evbug_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(evbug_init);
|
|
|
|
module_exit(evbug_exit);
|