9 #include <linux/kernel.h>
11 #include <linux/tty.h>
12 #include <linux/module.h>
14 #include <linux/errno.h>
15 #include <linux/slab.h>
24 #define DRIVER_VERSION "v1.2.0.0"
25 #define DRIVER_DESC "Metrologic Instruments Inc. - USB-POS driver"
28 #define FOCUS_VENDOR_ID 0x0C2E
29 #define FOCUS_PRODUCT_ID_BI 0x0720
30 #define FOCUS_PRODUCT_ID_UNI 0x0700
32 #define METROUSB_SET_REQUEST_TYPE 0x40
33 #define METROUSB_SET_MODEM_CTRL_REQUEST 10
34 #define METROUSB_SET_BREAK_REQUEST 0x40
35 #define METROUSB_MCR_NONE 0x08
36 #define METROUSB_MCR_RTS 0x0a
37 #define METROUSB_MCR_DTR 0x09
38 #define WDR_TIMEOUT 5000
56 #define UNI_CMD_OPEN 0x80
57 #define UNI_CMD_CLOSE 0xFF
62 port->
serial->dev->descriptor.idProduct);
84 buffer_cmd,
sizeof(cmd),
85 &actual_len, USB_CTRL_SET_TIMEOUT);
91 else if (actual_len !=
sizeof(cmd))
96 static void metrousb_read_int_callback(
struct urb *
urb)
101 unsigned char *
data = urb->transfer_buffer;
104 unsigned long flags = 0;
108 switch (urb->status) {
117 "%s - urb shutting down, error code=%d\n",
118 __func__, urb->status);
122 "%s - non-zero urb received, error code=%d\n",
123 __func__, urb->status);
130 if (tty && urb->actual_length) {
132 tty_insert_flip_string(tty, data, urb->actual_length);
142 spin_unlock_irqrestore(&metro_priv->
lock, flags);
150 metrousb_read_int_callback, port, 1);
156 "%s - failed submitting interrupt in urb, error code=%d\n",
166 "%s - failed submitting interrupt in urb, error code=%d\n",
170 static void metrousb_write_int_callback(
struct urb *urb)
186 if (!port->
serial->disconnected)
195 unsigned long flags = 0;
202 dev_err(&port->
dev,
"%s - interrupt urb not initialized\n",
211 spin_unlock_irqrestore(&metro_priv->
lock, flags);
221 metrousb_read_int_callback, port, 1);
226 "%s - failed submitting interrupt in urb, error code=%d\n",
232 result = metrousb_send_unidirectional_cmd(
UNI_CMD_OPEN, port);
235 "%s - failed to configure device for port number=%d, error code=%d\n",
236 __func__, port->
number, result);
240 dev_dbg(&port->
dev,
"%s - port open\n", __func__);
250 dev_dbg(&serial->
dev->dev,
"%s - control state = %d\n",
251 __func__, control_state);
265 "%s - set modem ctrl=0x%x failed, error code=%d\n",
266 __func__, mcr, retval);
275 metro_priv = kzalloc(
sizeof(*metro_priv),
GFP_KERNEL);
281 usb_set_serial_port_data(port, metro_priv);
290 metro_priv = usb_get_serial_port_data(port);
296 static void metrousb_throttle(
struct tty_struct *tty)
300 unsigned long flags = 0;
307 spin_unlock_irqrestore(&metro_priv->
lock, flags);
310 static int metrousb_tiocmget(
struct tty_struct *tty)
312 unsigned long control_state = 0;
315 unsigned long flags = 0;
321 spin_unlock_irqrestore(&metro_priv->
lock, flags);
326 static int metrousb_tiocmset(
struct tty_struct *tty,
327 unsigned int set,
unsigned int clear)
332 unsigned long flags = 0;
333 unsigned long control_state = 0;
335 dev_dbg(tty->
dev,
"%s - set=%d, clear=%d\n", __func__,
set, clear);
345 if (clear & TIOCM_RTS)
346 control_state &= ~TIOCM_RTS;
347 if (clear & TIOCM_DTR)
348 control_state &= ~TIOCM_DTR;
351 spin_unlock_irqrestore(&metro_priv->
lock, flags);
352 return metrousb_set_modem_ctrl(serial, control_state);
355 static void metrousb_unthrottle(
struct tty_struct *tty)
359 unsigned long flags = 0;
367 spin_unlock_irqrestore(&metro_priv->
lock, flags);
374 "failed submitting interrupt in urb error code=%d\n",
383 .description =
"Metrologic USB to Serial",
386 .open = metrousb_open,
387 .close = metrousb_cleanup,
388 .read_int_callback = metrousb_read_int_callback,
389 .write_int_callback = metrousb_write_int_callback,
390 .port_probe = metrousb_port_probe,
391 .port_remove = metrousb_port_remove,
392 .throttle = metrousb_throttle,
393 .unthrottle = metrousb_unthrottle,
394 .tiocmget = metrousb_tiocmget,
395 .tiocmset = metrousb_tiocmset,