]> rtime.felk.cvut.cz Git - socketcan-devel.git/commitdiff
Added first version of functions to register new device by usbcore.
authorJiri Vanek <vanekjir@fel.cvut.cz>
Tue, 6 Mar 2012 16:07:42 +0000 (17:07 +0100)
committerJiri Vanek <vanekjir@fel.cvut.cz>
Tue, 6 Mar 2012 16:07:42 +0000 (17:07 +0100)
kernel/2.6/drivers/net/can/usb/ctu_usbcan.c

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..78f672e0897bdbec1ca4fda024ce8ecd13f9a8a2 100644 (file)
@@ -0,0 +1,76 @@
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/kref.h>
+#include <linux/uaccess.h>
+#include <linux/usb.h>
+#include <linux/mutex.h>
+
+
+#define CTU_USBCAN_VENDOR_ID   0x1669
+#define CTU_USBCAN_PRODUCT_ID  0x1011
+
+
+/* table of devices that work with this driver */
+static struct usb_device_id ctu_usbcan_table [] = {
+       { USB_DEVICE(CTU_USBCAN_VENDOR_ID, CTU_USBCAN_PRODUCT_ID) },
+       { }                                     /* Terminating entry */
+};
+MODULE_DEVICE_TABLE(usb, ctu_usbcan_table);
+
+
+static struct usb_driver ctu_usbcan_driver;
+
+
+static int ctu_usbcan_probe(struct usb_interface *interface, const struct usb_device_id *id)
+{
+
+       printk(KERN_INFO "CTU USBCAN device now attached\n");
+
+       return 0;
+}
+
+/* called by the usb core when the device is removed from the system */
+static void ctu_usbcan_disconnect(struct usb_interface *interface)
+{
+
+       printk(KERN_INFO "CTU USBCAN device now disconnected\n");
+
+}
+
+/* usb specific object needed to register this driver with the usb subsystem */
+static struct usb_driver ctu_usbcan_driver = {
+       .name = "ctu_usbcan",
+       .id_table =     ctu_usbcan_table,
+       .probe =        ctu_usbcan_probe,
+       .disconnect =   ctu_usbcan_disconnect,
+};
+
+static int __init ctu_usbcan_init(void)
+{
+       int result;
+
+       printk(KERN_INFO "CTU USBCAN kernel driver loaded\n");
+
+       /* register this driver with the USB subsystem */
+       result = usb_register(&ctu_usbcan_driver);
+       if (result)
+               err("usb_register failed. Error number %d", result);
+
+       return result;
+}
+
+static void __exit ctu_usbcan_exit(void)
+{
+       printk(KERN_INFO "CTU USBCAN kernel driver unloaded\n");
+
+       /* deregister this driver with the USB subsystem */
+       usb_deregister(&ctu_usbcan_driver);
+}
+
+module_init(ctu_usbcan_init);
+module_exit(ctu_usbcan_exit);
+
+MODULE_LICENSE("GPL");