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 #ifdef CONFIG_USB_DEBUG
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/module.h>
21 #include <linux/usb.h>
24 #define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com"
25 #define DRIVER_DESC "USB LED Driver"
27 #define VENDOR_ID 0x0fc5
28 #define PRODUCT_ID 0x1223
30 /* table of devices that work with this driver */
31 static struct usb_device_id id_table
[] = {
32 { USB_DEVICE(VENDOR_ID
, PRODUCT_ID
) },
35 MODULE_DEVICE_TABLE (usb
, id_table
);
38 struct usb_device
* udev
;
47 static void change_color(struct usb_led
*led
)
50 unsigned char color
= 0x07;
51 unsigned char *buffer
;
53 buffer
= kmalloc(8, GFP_KERNEL
);
55 dev_err(&led
->udev
->dev
, "out of memory\n");
65 dev_dbg(&led
->udev
->dev
,
66 "blue = %d, red = %d, green = %d, color = %.2x\n",
67 led
->blue
, led
->red
, led
->green
, color
);
69 retval
= usb_control_msg(led
->udev
,
70 usb_sndctrlpipe(led
->udev
, 0),
73 (0x02 * 0x100) + 0x0a,
74 (0x00 * 0x100) + color
,
79 dev_dbg(&led
->udev
->dev
, "retval = %d\n", retval
);
83 #define show_set(value) \
84 static ssize_t show_##value(struct device *dev, char *buf) \
86 struct usb_interface *intf = to_usb_interface(dev); \
87 struct usb_led *led = usb_get_intfdata(intf); \
89 return sprintf(buf, "%d\n", led->value); \
91 static ssize_t set_##value(struct device *dev, const char *buf, size_t count) \
93 struct usb_interface *intf = to_usb_interface(dev); \
94 struct usb_led *led = usb_get_intfdata(intf); \
95 int temp = simple_strtoul(buf, NULL, 10); \
101 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
106 static int led_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
)
108 struct usb_device
*udev
= interface_to_usbdev(interface
);
109 struct usb_led
*dev
= NULL
;
110 int retval
= -ENOMEM
;
112 dev
= kmalloc(sizeof(struct usb_led
), GFP_KERNEL
);
114 dev_err(&interface
->dev
, "Out of memory\n");
117 memset (dev
, 0x00, sizeof (*dev
));
119 dev
->udev
= usb_get_dev(udev
);
121 usb_set_intfdata (interface
, dev
);
123 device_create_file(&interface
->dev
, &dev_attr_blue
);
124 device_create_file(&interface
->dev
, &dev_attr_red
);
125 device_create_file(&interface
->dev
, &dev_attr_green
);
127 dev_info(&interface
->dev
, "USB LED device now attached\n");
135 static void led_disconnect(struct usb_interface
*interface
)
139 dev
= usb_get_intfdata (interface
);
140 usb_set_intfdata (interface
, NULL
);
142 device_remove_file(&interface
->dev
, &dev_attr_blue
);
143 device_remove_file(&interface
->dev
, &dev_attr_red
);
144 device_remove_file(&interface
->dev
, &dev_attr_green
);
146 usb_put_dev(dev
->udev
);
150 dev_info(&interface
->dev
, "USB LED now disconnected\n");
153 static struct usb_driver led_driver
= {
154 .owner
= THIS_MODULE
,
157 .disconnect
= led_disconnect
,
158 .id_table
= id_table
,
161 static int __init
usb_led_init(void)
165 retval
= usb_register(&led_driver
);
167 err("usb_register failed. Error number %d", retval
);
171 static void __exit
usb_led_exit(void)
173 usb_deregister(&led_driver
);
176 module_init (usb_led_init
);
177 module_exit (usb_led_exit
);
179 MODULE_AUTHOR(DRIVER_AUTHOR
);
180 MODULE_DESCRIPTION(DRIVER_DESC
);
181 MODULE_LICENSE("GPL");