13 #include <linux/kernel.h>
15 #include <linux/tty.h>
17 #include <linux/slab.h>
19 #include <linux/serial.h>
20 #include <linux/module.h>
25 #define CONTROL_RTS 0x02
26 #define RESEND_CTS_STATE 0x03
29 #define URB_UPPER_LIMIT 8
33 #define DRIVER_DESC "Opticon USB barcode to serial driver (1D)"
36 { USB_DEVICE(0x065a, 0x0009) },
60 static void opticon_read_bulk_callback(
struct urb *
urb)
63 unsigned char *
data = urb->transfer_buffer;
79 dev_dbg(&priv->
udev->dev,
"%s - urb shutting down with status: %d\n",
83 dev_dbg(&priv->
udev->dev,
"%s - nonzero urb status received: %d\n",
88 usb_serial_debug_data(&port->
dev, __func__, urb->actual_length, data);
90 if (urb->actual_length > 2) {
91 data_length = urb->actual_length - 2;
102 if ((data[0] == 0x00) && (data[1] == 0x00)) {
106 tty_insert_flip_string(tty, data + 2,
112 if ((data[0] == 0x00) && (data[1] == 0x01)) {
119 spin_unlock_irqrestore(&priv->
lock, flags);
122 "Unknown data packet received from the device:"
129 "Improper amount of data received from the device, "
130 "%d bytes", urb->actual_length);
134 spin_lock(&priv->
lock);
139 usb_rcvbulkpipe(priv->
udev,
142 opticon_read_bulk_callback, priv);
146 "%s - failed resubmitting read urb, error %d\n",
150 spin_unlock(&priv->
lock);
187 spin_unlock_irqrestore(&priv->
lock, flags);
194 usb_rcvbulkpipe(priv->
udev,
197 opticon_read_bulk_callback, priv);
205 "%s - failed resubmitting read urb, error %d\n",
221 static void opticon_write_control_callback(
struct urb *urb)
224 int status = urb->status;
228 kfree(urb->transfer_buffer);
231 kfree(urb->setup_packet);
234 dev_dbg(&priv->
udev->dev,
"%s - nonzero write bulk status received: %d\n",
239 spin_unlock_irqrestore(&priv->
lock, flags);
245 const unsigned char *
buf,
int count)
257 spin_unlock_irqrestore(&priv->
lock, flags);
258 dev_dbg(&port->
dev,
"%s - write limit hit\n", __func__);
262 spin_unlock_irqrestore(&priv->
lock, flags);
269 goto error_no_buffer;
279 memcpy(buffer, buf, count);
281 usb_serial_debug_data(&port->
dev, __func__, count, buffer);
298 usb_fill_control_urb(urb, serial->
dev,
299 usb_sndctrlpipe(serial->
dev, 0),
300 (
unsigned char *)dr, buffer, count,
301 opticon_write_control_callback, priv);
307 "%s - usb_submit_urb(write endpoint) failed status = %d\n",
327 spin_unlock_irqrestore(&priv->
lock, flags);
331 static int opticon_write_room(
struct tty_struct *tty)
344 spin_unlock_irqrestore(&priv->
lock, flags);
345 dev_dbg(&port->
dev,
"%s - write limit hit\n", __func__);
348 spin_unlock_irqrestore(&priv->
lock, flags);
353 static void opticon_throttle(
struct tty_struct *tty)
361 spin_unlock_irqrestore(&priv->
lock, flags);
365 static void opticon_unthrottle(
struct tty_struct *tty)
370 int result, was_throttled;
376 spin_unlock_irqrestore(&priv->
lock, flags);
382 "%s - failed submitting read urb, error %d\n",
387 static int opticon_tiocmget(
struct tty_struct *tty)
399 spin_unlock_irqrestore(&priv->
lock, flags);
401 dev_dbg(&port->
dev,
"%s - %x\n", __func__, result);
405 static int opticon_tiocmset(
struct tty_struct *tty,
406 unsigned int set,
unsigned int clear)
424 changed = rts ^ priv->
rts;
425 spin_unlock_irqrestore(&priv->
lock, flags);
457 tmp.xmit_fifo_size = 1024;
458 tmp.baud_base = 9600;
459 tmp.close_delay = 5*
HZ;
460 tmp.closing_wait = 30*
HZ;
467 static int opticon_ioctl(
struct tty_struct *tty,
468 unsigned int cmd,
unsigned long arg)
473 dev_dbg(&port->
dev,
"%s - port %d, cmd = 0x%x\n", __func__, port->
number, cmd);
477 return get_serial_info(priv,
484 static int opticon_startup(
struct usb_serial *serial)
487 struct usb_host_interface *
intf;
490 bool bulk_in_found =
false;
495 dev_err(&serial->
dev->dev,
"%s - Out of memory\n", __func__);
506 for (i = 0; i < intf->desc.bNumEndpoints; ++
i) {
509 endpoint = &intf->endpoint[
i].desc;
510 if (!usb_endpoint_is_bulk_in(endpoint))
519 priv->
buffer_size = usb_endpoint_maxp(endpoint) * 2;
528 bulk_in_found =
true;
532 if (!bulk_in_found) {
534 "Error - the proper endpoints were not found!\n");
538 usb_set_serial_data(serial, priv);
548 static void opticon_disconnect(
struct usb_serial *serial)
556 static void opticon_release(
struct usb_serial *serial)
572 static int opticon_resume(
struct usb_serial *serial)
595 .attach = opticon_startup,
596 .open = opticon_open,
597 .close = opticon_close,
598 .write = opticon_write,
599 .write_room = opticon_write_room,
600 .disconnect = opticon_disconnect,
601 .release = opticon_release,
602 .throttle = opticon_throttle,
603 .unthrottle = opticon_unthrottle,
604 .ioctl = opticon_ioctl,
605 .tiocmget = opticon_tiocmget,
606 .tiocmset = opticon_tiocmset,
607 .suspend = opticon_suspend,
608 .resume = opticon_resume,
612 &opticon_device,
NULL