evbug.c 2.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * $Id: evbug.c,v 1.10 2001/09/25 10:12:07 vojtech Exp $
 *
 *  Copyright (c) 1999-2001 Vojtech Pavlik
 */

/*
 *  Input driver event debug module - dumps all events into syslog
 */

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17 18 19 20
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
21
 *
22 23 24
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
 *
26 27 28 29 30 31 32 33 34
 * Should you need to contact me, the author, you can do so either by
 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
 */

#include <linux/slab.h>
#include <linux/module.h>
#include <linux/input.h>
#include <linux/init.h>
35
#include <linux/device.h>
36 37

MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
38
MODULE_DESCRIPTION("Input driver event debug module");
39 40
MODULE_LICENSE("GPL");

41 42
static char evbug_name[] = "evbug";

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{
	printk(KERN_DEBUG "evbug.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", handle->dev->phys, type, code, value);
}

static struct input_handle *evbug_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
{
	struct input_handle *handle;

	if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL)))
		return NULL;
	memset(handle, 0, sizeof(struct input_handle));

	handle->dev = dev;
	handle->handler = handler;
58
	handle->name = evbug_name;
59 60 61 62 63 64 65 66 67 68 69

	input_open_device(handle);

	printk(KERN_DEBUG "evbug.c: Connected device: \"%s\", %s\n", dev->name, dev->phys);

	return handle;
}

static void evbug_disconnect(struct input_handle *handle)
{
	printk(KERN_DEBUG "evbug.c: Disconnected device: %s\n", handle->dev->phys);
70

71 72 73 74 75 76
	input_close_device(handle);

	kfree(handle);
}

static struct input_device_id evbug_ids[] = {
77
	{ .driver_info = 1 },	/* Matches all devices */
78 79 80 81
	{ },			/* Terminating zero entry */
};

MODULE_DEVICE_TABLE(input, evbug_ids);
82

83
static struct input_handler evbug_handler = {
84 85 86 87 88
	.event =	evbug_event,
	.connect =	evbug_connect,
	.disconnect =	evbug_disconnect,
	.name =		"evbug",
	.id_table =	evbug_ids,
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
};

int __init evbug_init(void)
{
	input_register_handler(&evbug_handler);
	return 0;
}

void __exit evbug_exit(void)
{
	input_unregister_handler(&evbug_handler);
}

module_init(evbug_init);
module_exit(evbug_exit);