6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <linux/usb.h>
21 #define DRIVER_DESC "USB LED Driver"
24 DELCOM_VISUAL_SIGNAL_INDICATOR,
25 DREAM_CHEEKY_WEBMAIL_NOTIFIER,
28 /* table of devices that work with this driver */
29 static const struct usb_device_id id_table[] = {
30 { USB_DEVICE(0x0fc5, 0x1223),
31 .driver_info = DELCOM_VISUAL_SIGNAL_INDICATOR },
32 { USB_DEVICE(0x1d34, 0x0004),
33 .driver_info = DREAM_CHEEKY_WEBMAIL_NOTIFIER },
36 MODULE_DEVICE_TABLE (usb, id_table);
39 struct usb_device * udev;
46 static void change_color(struct usb_led *led)
49 unsigned char *buffer;
51 buffer = kmalloc(8, GFP_KERNEL);
53 dev_err(&led->udev->dev, "out of memory\n");
58 case DELCOM_VISUAL_SIGNAL_INDICATOR: {
59 unsigned char color = 0x07;
67 dev_dbg(&led->udev->dev,
68 "blue = %d, red = %d, green = %d, color = %.2x\n",
69 led->blue, led->red, led->green, color);
71 retval = usb_control_msg(led->udev,
72 usb_sndctrlpipe(led->udev, 0),
75 (0x02 * 0x100) + 0x0a,
76 (0x00 * 0x100) + color,
83 case DREAM_CHEEKY_WEBMAIL_NOTIFIER:
84 dev_dbg(&led->udev->dev,
85 "red = %d, green = %d, blue = %d\n",
86 led->red, led->green, led->blue);
89 buffer[1] = led->green;
90 buffer[2] = led->blue;
91 buffer[3] = buffer[4] = buffer[5] = 0;
95 retval = usb_control_msg(led->udev,
96 usb_sndctrlpipe(led->udev, 0),
107 dev_err(&led->udev->dev, "unknown device type %d\n", led->type);
111 dev_dbg(&led->udev->dev, "retval = %d\n", retval);
115 #define show_set(value) \
116 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
118 struct usb_interface *intf = to_usb_interface(dev); \
119 struct usb_led *led = usb_get_intfdata(intf); \
121 return sprintf(buf, "%d\n", led->value); \
123 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
125 struct usb_interface *intf = to_usb_interface(dev); \
126 struct usb_led *led = usb_get_intfdata(intf); \
127 int temp = simple_strtoul(buf, NULL, 10); \
133 static DEVICE_ATTR(value, S_IRUGO | S_IWUSR, show_##value, set_##value);
138 static int led_probe(struct usb_interface *interface, const struct usb_device_id *id)
140 struct usb_device *udev = interface_to_usbdev(interface);
141 struct usb_led *dev = NULL;
142 int retval = -ENOMEM;
144 dev = kzalloc(sizeof(struct usb_led), GFP_KERNEL);
146 dev_err(&interface->dev, "out of memory\n");
150 dev->udev = usb_get_dev(udev);
151 dev->type = id->driver_info;
153 usb_set_intfdata (interface, dev);
155 retval = device_create_file(&interface->dev, &dev_attr_blue);
158 retval = device_create_file(&interface->dev, &dev_attr_red);
161 retval = device_create_file(&interface->dev, &dev_attr_green);
165 if (dev->type == DREAM_CHEEKY_WEBMAIL_NOTIFIER) {
166 unsigned char *enable;
168 enable = kmemdup("\x1f\x02\0\x5f\0\0\x1a\x03", 8, GFP_KERNEL);
170 dev_err(&interface->dev, "out of memory\n");
175 retval = usb_control_msg(udev,
176 usb_sndctrlpipe(udev, 0),
190 dev_info(&interface->dev, "USB LED device now attached\n");
194 device_remove_file(&interface->dev, &dev_attr_blue);
195 device_remove_file(&interface->dev, &dev_attr_red);
196 device_remove_file(&interface->dev, &dev_attr_green);
197 usb_set_intfdata (interface, NULL);
198 usb_put_dev(dev->udev);
204 static void led_disconnect(struct usb_interface *interface)
208 dev = usb_get_intfdata (interface);
210 device_remove_file(&interface->dev, &dev_attr_blue);
211 device_remove_file(&interface->dev, &dev_attr_red);
212 device_remove_file(&interface->dev, &dev_attr_green);
214 /* first remove the files, then set the pointer to NULL */
215 usb_set_intfdata (interface, NULL);
217 usb_put_dev(dev->udev);
221 dev_info(&interface->dev, "USB LED now disconnected\n");
224 static struct usb_driver led_driver = {
227 .disconnect = led_disconnect,
228 .id_table = id_table,
231 static int __init usb_led_init(void)
235 retval = usb_register(&led_driver);
237 err("usb_register failed. Error number %d", retval);
241 static void __exit usb_led_exit(void)
243 usb_deregister(&led_driver);
246 module_init (usb_led_init);
247 module_exit (usb_led_exit);
249 MODULE_AUTHOR(DRIVER_AUTHOR);
250 MODULE_DESCRIPTION(DRIVER_DESC);
251 MODULE_LICENSE("GPL");