4 * Copyright (C) 2004 Greg Kroah-Hartman (greg@kroah.com)
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/config.h>
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/module.h>
18 #include <linux/usb.h>
21 #define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com"
22 #define DRIVER_DESC "USB LED Driver"
24 #define VENDOR_ID 0x0fc5
25 #define PRODUCT_ID 0x1223
27 /* table of devices that work with this driver */
28 static struct usb_device_id id_table
[] = {
29 { USB_DEVICE(VENDOR_ID
, PRODUCT_ID
) },
32 MODULE_DEVICE_TABLE (usb
, id_table
);
35 struct usb_device
* udev
;
44 static void change_color(struct usb_led
*led
)
47 unsigned char color
= 0x07;
48 unsigned char *buffer
;
50 buffer
= kmalloc(8, GFP_KERNEL
);
52 dev_err(&led
->udev
->dev
, "out of memory\n");
62 dev_dbg(&led
->udev
->dev
,
63 "blue = %d, red = %d, green = %d, color = %.2x\n",
64 led
->blue
, led
->red
, led
->green
, color
);
66 retval
= usb_control_msg(led
->udev
,
67 usb_sndctrlpipe(led
->udev
, 0),
70 (0x02 * 0x100) + 0x0a,
71 (0x00 * 0x100) + color
,
76 dev_dbg(&led
->udev
->dev
, "retval = %d\n", retval
);
80 #define show_set(value) \
81 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
83 struct usb_interface *intf = to_usb_interface(dev); \
84 struct usb_led *led = usb_get_intfdata(intf); \
86 return sprintf(buf, "%d\n", led->value); \
88 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
90 struct usb_interface *intf = to_usb_interface(dev); \
91 struct usb_led *led = usb_get_intfdata(intf); \
92 int temp = simple_strtoul(buf, NULL, 10); \
98 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
103 static int led_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
)
105 struct usb_device
*udev
= interface_to_usbdev(interface
);
106 struct usb_led
*dev
= NULL
;
107 int retval
= -ENOMEM
;
109 dev
= kmalloc(sizeof(struct usb_led
), GFP_KERNEL
);
111 dev_err(&interface
->dev
, "Out of memory\n");
114 memset (dev
, 0x00, sizeof (*dev
));
116 dev
->udev
= usb_get_dev(udev
);
118 usb_set_intfdata (interface
, dev
);
120 device_create_file(&interface
->dev
, &dev_attr_blue
);
121 device_create_file(&interface
->dev
, &dev_attr_red
);
122 device_create_file(&interface
->dev
, &dev_attr_green
);
124 dev_info(&interface
->dev
, "USB LED device now attached\n");
132 static void led_disconnect(struct usb_interface
*interface
)
136 dev
= usb_get_intfdata (interface
);
137 usb_set_intfdata (interface
, NULL
);
139 device_remove_file(&interface
->dev
, &dev_attr_blue
);
140 device_remove_file(&interface
->dev
, &dev_attr_red
);
141 device_remove_file(&interface
->dev
, &dev_attr_green
);
143 usb_put_dev(dev
->udev
);
147 dev_info(&interface
->dev
, "USB LED now disconnected\n");
150 static struct usb_driver led_driver
= {
153 .disconnect
= led_disconnect
,
154 .id_table
= id_table
,
157 static int __init
usb_led_init(void)
161 retval
= usb_register(&led_driver
);
163 err("usb_register failed. Error number %d", retval
);
167 static void __exit
usb_led_exit(void)
169 usb_deregister(&led_driver
);
172 module_init (usb_led_init
);
173 module_exit (usb_led_exit
);
175 MODULE_AUTHOR(DRIVER_AUTHOR
);
176 MODULE_DESCRIPTION(DRIVER_DESC
);
177 MODULE_LICENSE("GPL");