Reputation: 445
#include<linux/init.h>
#include<linux/module.h>
#include <linux/usb/input.h>
#include <linux/hid.h>
/*
* Version information
*/
#define DRIVER_VERSION ""
#define DRIVER_DESC "Hello World module"
#define DRIVER_LICENSE "GPL"
MODULE_LICENSE(DRIVER_LICENSE);
MODULE_AUTHOR(DRIVER_AUTHOR);
static void __exit hello_world_exit(void)
{
pr_debug("Bye!\n");
}
static int __init hello_world_init(void)
{
pr_debug("Hello, USB!");
return 0;
}
static struct usb_device_id usb_kbd_id_table[] = {
{ USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID,
USB_INTERFACE_SUBCLASS_BOOT,
USB_INTERFACE_PROTOCOL_KEYBOARD) },
{}
};
MODULE_DEVICE_TABLE(usb, usb_kbd_id_table);
module_init(hello_world_init);
module_exit(hello_world_exit);
How do I make the kernel load this module load when a USB mouse is plugged in (using the userspace hotplug tools) ? Right now, I have put the hello_world.ko file in /lib/modules/$(uname -r) and run depmod -a.
Upvotes: 1
Views: 2378
Reputation: 18299
In modern Linux the functionality for loading drivers/modules (or invoking any other commands) whenever new hardware is detected is handled by udev
. You will have to write a udev rule for your device that will instruct the kernel to load your module when your device has been detected and the corresponding event has occurred. Read more about it here.
Upvotes: 3