Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 *  Copyright (c) 1999-2001 Vojtech Pavlik
  3 */
  4
  5/*
  6 *  Input driver event debug module - dumps all events into syslog
  7 */
  8
  9/*
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 23 *
 24 * Should you need to contact me, the author, you can do so either by
 25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
 26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
 27 */
 28
 29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 30
 31#include <linux/slab.h>
 32#include <linux/module.h>
 33#include <linux/input.h>
 34#include <linux/init.h>
 35#include <linux/device.h>
 36
 37MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
 38MODULE_DESCRIPTION("Input driver event debug module");
 39MODULE_LICENSE("GPL");
 40
 41static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
 42{
 43	printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n"),
 44	       dev_name(&handle->dev->dev), type, code, value);
 45}
 46
 47static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
 48			 const struct input_device_id *id)
 49{
 50	struct input_handle *handle;
 51	int error;
 52
 53	handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
 54	if (!handle)
 55		return -ENOMEM;
 56
 57	handle->dev = dev;
 58	handle->handler = handler;
 59	handle->name = "evbug";
 60
 61	error = input_register_handle(handle);
 62	if (error)
 63		goto err_free_handle;
 64
 65	error = input_open_device(handle);
 66	if (error)
 67		goto err_unregister_handle;
 68
 69	printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
 70	       dev_name(&dev->dev),
 71	       dev->name ?: "unknown",
 72	       dev->phys ?: "unknown");
 73
 74	return 0;
 75
 76 err_unregister_handle:
 77	input_unregister_handle(handle);
 78 err_free_handle:
 79	kfree(handle);
 80	return error;
 81}
 82
 83static void evbug_disconnect(struct input_handle *handle)
 84{
 85	printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
 86	       dev_name(&handle->dev->dev));
 87
 88	input_close_device(handle);
 89	input_unregister_handle(handle);
 90	kfree(handle);
 91}
 92
 93static const struct input_device_id evbug_ids[] = {
 94	{ .driver_info = 1 },	/* Matches all devices */
 95	{ },			/* Terminating zero entry */
 96};
 97
 98MODULE_DEVICE_TABLE(input, evbug_ids);
 99
100static struct input_handler evbug_handler = {
101	.event =	evbug_event,
102	.connect =	evbug_connect,
103	.disconnect =	evbug_disconnect,
104	.name =		"evbug",
105	.id_table =	evbug_ids,
106};
107
108static int __init evbug_init(void)
109{
110	return input_register_handler(&evbug_handler);
111}
112
113static void __exit evbug_exit(void)
114{
115	input_unregister_handler(&evbug_handler);
116}
117
118module_init(evbug_init);
119module_exit(evbug_exit);
v5.9
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  Copyright (c) 1999-2001 Vojtech Pavlik
  4 */
  5
  6/*
  7 *  Input driver event debug module - dumps all events into syslog
  8 */
  9
 10/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 11 */
 12
 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 14
 15#include <linux/slab.h>
 16#include <linux/module.h>
 17#include <linux/input.h>
 18#include <linux/init.h>
 19#include <linux/device.h>
 20
 21MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
 22MODULE_DESCRIPTION("Input driver event debug module");
 23MODULE_LICENSE("GPL");
 24
 25static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
 26{
 27	printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n"),
 28	       dev_name(&handle->dev->dev), type, code, value);
 29}
 30
 31static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
 32			 const struct input_device_id *id)
 33{
 34	struct input_handle *handle;
 35	int error;
 36
 37	handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
 38	if (!handle)
 39		return -ENOMEM;
 40
 41	handle->dev = dev;
 42	handle->handler = handler;
 43	handle->name = "evbug";
 44
 45	error = input_register_handle(handle);
 46	if (error)
 47		goto err_free_handle;
 48
 49	error = input_open_device(handle);
 50	if (error)
 51		goto err_unregister_handle;
 52
 53	printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
 54	       dev_name(&dev->dev),
 55	       dev->name ?: "unknown",
 56	       dev->phys ?: "unknown");
 57
 58	return 0;
 59
 60 err_unregister_handle:
 61	input_unregister_handle(handle);
 62 err_free_handle:
 63	kfree(handle);
 64	return error;
 65}
 66
 67static void evbug_disconnect(struct input_handle *handle)
 68{
 69	printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
 70	       dev_name(&handle->dev->dev));
 71
 72	input_close_device(handle);
 73	input_unregister_handle(handle);
 74	kfree(handle);
 75}
 76
 77static const struct input_device_id evbug_ids[] = {
 78	{ .driver_info = 1 },	/* Matches all devices */
 79	{ },			/* Terminating zero entry */
 80};
 81
 82MODULE_DEVICE_TABLE(input, evbug_ids);
 83
 84static struct input_handler evbug_handler = {
 85	.event =	evbug_event,
 86	.connect =	evbug_connect,
 87	.disconnect =	evbug_disconnect,
 88	.name =		"evbug",
 89	.id_table =	evbug_ids,
 90};
 91
 92static int __init evbug_init(void)
 93{
 94	return input_register_handler(&evbug_handler);
 95}
 96
 97static void __exit evbug_exit(void)
 98{
 99	input_unregister_handler(&evbug_handler);
100}
101
102module_init(evbug_init);
103module_exit(evbug_exit);