12 #include <linux/kernel.h>
13 #include <linux/errno.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
21 #include <linux/hid.h>
23 #define DRIVER_AUTHOR "Tomoki Sekiyama"
24 #define DRIVER_DESC "Driver for Meywa-Denki & KAYAC YUREX"
26 #define YUREX_VENDOR_ID 0x0c45
27 #define YUREX_PRODUCT_ID 0x1010
30 #define CMD_ANIMATE 'A'
35 #define CMD_VERSION 'V'
37 #define CMD_PADDING 0xff
39 #define YUREX_BUF_SIZE 8
40 #define YUREX_WRITE_TIMEOUT (HZ*2)
49 #ifdef CONFIG_USB_DYNAMIC_MINORS
50 #define YUREX_MINOR_BASE 0
52 #define YUREX_MINOR_BASE 192
74 #define to_yurex_dev(d) container_of(d, struct usb_yurex, kref)
76 static struct usb_driver yurex_driver;
80 static void yurex_control_callback(
struct urb *
urb)
86 dev_err(&urb->dev->dev,
"%s - control failed: %d\n",
94 static void yurex_delete(
struct kref *
kref)
123 static struct usb_class_driver yurex_class = {
129 static void yurex_interrupt(
struct urb *urb)
133 int status = urb->status;
142 "%s - overflow with length %d, actual length is %d\n",
152 "%s - unknown status received: %d\n", __func__, status);
163 for (i = 1; i < 6; i++) {
170 spin_unlock_irqrestore(&dev->
lock, flags);
176 "data format error - no EOF\n");
196 struct usb_host_interface *iface_desc;
205 dev_err(&interface->dev,
"Out of memory\n");
208 kref_init(&dev->
kref);
217 iface_desc = interface->cur_altsetting;
218 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
219 endpoint = &iface_desc->endpoint[
i].desc;
221 if (usb_endpoint_is_int_in(endpoint)) {
228 dev_err(&interface->dev,
"Could not find endpoints\n");
236 dev_err(&interface->dev,
"Could not allocate control URB\n");
243 dev_err(&interface->dev,
"Could not allocate cntl_req\n");
252 dev_err(&interface->dev,
"Could not allocate cntl_buffer\n");
265 usb_sndctrlpipe(dev->
udev, 0),
268 dev->
cntl_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
274 dev_err(&interface->dev,
"Could not allocate URB\n");
282 dev_err(&interface->dev,
"Could not allocate int_buffer\n");
287 usb_fill_int_urb(dev->
urb, dev->
udev,
291 dev->
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
294 dev_err(&interface->dev,
"Could not submitting URB\n");
299 usb_set_intfdata(interface, dev);
305 "Not able to get a minor for this device.\n");
306 usb_set_intfdata(interface,
NULL);
313 "USB YUREX device now attached to Yurex #%d\n",
321 kref_put(&dev->
kref, yurex_delete);
325 static void yurex_disconnect(
struct usb_interface *interface)
328 int minor = interface->minor;
330 dev = usb_get_intfdata(interface);
331 usb_set_intfdata(interface,
NULL);
346 kref_put(&dev->
kref, yurex_delete);
348 dev_info(&interface->dev,
"USB YUREX #%d now disconnected\n", minor);
351 static struct usb_driver yurex_driver = {
353 .probe = yurex_probe,
354 .disconnect = yurex_disconnect,
355 .id_table = yurex_table,
359 static int yurex_fasync(
int fd,
struct file *
file,
int on)
367 static int yurex_open(
struct inode *
inode,
struct file *file)
374 subminor = iminor(inode);
384 dev = usb_get_intfdata(interface);
391 kref_get(&dev->
kref);
402 static int yurex_release(
struct inode *inode,
struct file *file)
410 yurex_fasync(-1, file, 0);
413 kref_put(&dev->
kref, yurex_delete);
417 static ssize_t yurex_read(
struct file *file,
char *
buffer,
size_t count, loff_t *ppos)
434 bytes_read =
snprintf(in_buffer, 20,
"%lld\n", dev->
bbu);
435 spin_unlock_irqrestore(&dev->
lock, flags);
437 if (*ppos < bytes_read) {
438 if (
copy_to_user(buffer, in_buffer + *ppos, bytes_read - *ppos))
441 retval = bytes_read - *ppos;
451 static ssize_t yurex_write(
struct file *file,
const char *user_buffer,
size_t count, loff_t *ppos)
454 int i,
set = 0, retval = 0;
457 unsigned long long c, c2 = 0;
461 count =
min(
sizeof(buffer), count);
502 for (i = 1; i < 6; i++) {
526 "%s - failed to send bulk msg, error %d\n",
532 return timeout ? count : -
EIO;
541 .write = yurex_write,
543 .release = yurex_release,
544 .fasync = yurex_fasync,