Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | #include <linux/kernel.h> #include <linux/malloc.h> #include <linux/string.h> #include <linux/timer.h> #include <linux/sched.h> #include <linux/module.h> #include "usb.h" static int usb_audio_probe(struct usb_device *dev); static void usb_audio_disconnect(struct usb_device *dev); static LIST_HEAD(usb_audio_list); struct usb_audio { struct usb_device *dev; struct list_head list; }; static struct usb_driver usb_audio_driver = { "audio", usb_audio_probe, usb_audio_disconnect, {NULL, NULL} }; static int usb_audio_irq(int state, void *buffer, int len, void *dev_id) { struct usb_audio *aud = (struct usb_audio*) dev_id; return 1; } static int usb_audio_probe(struct usb_device *dev) { struct usb_interface_descriptor *interface; struct usb_endpoint_descriptor *endpoint; struct usb_audio *aud; int i; int na=0; interface = &dev->config[0].altsetting[0].interface[0]; for(i=0;i<dev->config[0].bNumInterfaces;i++) { int x; endpoint = &interface->endpoint[i]; if(interface->bInterfaceClass != 1) continue; printk(KERN_INFO "USB audio device detected.\n"); switch(interface->bInterfaceSubClass) { case 0x01: printk(KERN_INFO "audio: Control device.\n"); break; case 0x02: printk(KERN_INFO "audio: streaming.\n"); break; case 0x03: printk(KERN_INFO "audio: nonstreaming.\n"); break; } na++; } if(na==0) return -1; aud = kmalloc(sizeof(struct usb_audio), GFP_KERNEL); if(aud) { memset(aud, 0, sizeof(*aud)); aud->dev = dev; dev->private = aud; endpoint = &interface->endpoint[0]; // if (usb_set_configuration(dev, dev->config[0].bConfigurationValue)) { // printk (KERN_INFO " Failed usb_set_configuration: Audio\n"); // break; // } // usb_set_protocol(dev, 0); // usb_set_idle(dev, 0, 0); usb_request_irq(dev, usb_rcvctrlpipe(dev, endpoint->bEndpointAddress), usb_audio_irq, endpoint->bInterval, aud); list_add(&aud->list, &usb_audio_list); return 0; } if (aud) kfree (aud); return -1; } static void usb_audio_disconnect(struct usb_device *dev) { struct usb_audio *aud = (struct usb_audio*) dev->private; if(aud) { dev->private = NULL; list_del(&aud->list); kfree(aud); } printk(KERN_INFO "USB audio driver removed.\n"); } int usb_audio_init(void) { usb_register(&usb_audio_driver); return 0; } /* * Support functions for parsing */ void usb_audio_interface(struct usb_interface_descriptor *interface, u8 *data) { } void usb_audio_endpoint(struct usb_endpoint_descriptor *interface, u8 *data) { } #ifdef MODULE int init_module(void) { return usb_audio_init(); } void cleanup_module(void) { usb_deregister(&usb_audio_driver); } #endif |