12 #include <linux/kernel.h>
13 #include <linux/errno.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
21 #define DRIVER_DESC "USB LED Driver"
30 { USB_DEVICE(0x0fc5, 0x1223),
32 { USB_DEVICE(0x1d34, 0x0004),
34 { USB_DEVICE(0x1d34, 0x000a),
61 unsigned char color = 0x07;
70 "blue = %d, red = %d, green = %d, color = %.2x\n",
74 usb_sndctrlpipe(led->
udev, 0),
77 (0x02 * 0x100) + 0x0a,
78 (0x00 * 0x100) + color,
87 "red = %d, green = %d, blue = %d\n",
91 buffer[1] = led->
green;
92 buffer[2] = led->
blue;
93 buffer[3] = buffer[4] = buffer[5] = 0;
98 usb_sndctrlpipe(led->
udev, 0),
117 #define show_set(value) \
118 static ssize_t show_##value(struct device *dev, struct device_attribute *attr,\
121 struct usb_interface *intf = to_usb_interface(dev); \
122 struct usb_led *led = usb_get_intfdata(intf); \
124 return sprintf(buf, "%d\n", led->value); \
126 static ssize_t set_##value(struct device *dev, struct device_attribute *attr,\
127 const char *buf, size_t count) \
129 struct usb_interface *intf = to_usb_interface(dev); \
130 struct usb_led *led = usb_get_intfdata(intf); \
131 int temp = simple_strtoul(buf, NULL, 10); \
137 static DEVICE_ATTR(value, S_IRUGO | S_IWUSR, show_##value, set_##value);
145 struct usb_device *
udev = interface_to_usbdev(interface);
151 dev_err(&interface->dev,
"out of memory\n");
156 dev->
type =
id->driver_info;
158 usb_set_intfdata(interface, dev);
175 dev_err(&interface->dev,
"out of memory\n");
181 usb_sndctrlpipe(udev, 0),
195 dev_info(&interface->dev,
"USB LED device now attached\n");
202 usb_set_intfdata(interface,
NULL);
213 dev = usb_get_intfdata(interface);
220 usb_set_intfdata(interface,
NULL);
226 dev_info(&interface->dev,
"USB LED now disconnected\n");
229 static struct usb_driver led_driver = {
232 .disconnect = led_disconnect,
233 .id_table = id_table,