Lines Matching +full:usb +full:- +full:to +full:- +full:serial

1 // SPDX-License-Identifier: GPL-2.0
3 Some of this code is credited to Linux USB open source files that are
13 #include <linux/usb.h>
21 #include <linux/usb/serial.h>
23 #define DRIVER_DESC "Metrologic Instruments Inc. - USB-POS driver"
52 MODULE_DEVICE_TABLE(usb, id_table);
54 /* UNI-Directional mode commands for device configure */
58 static int metrousb_is_unidirectional_mode(struct usb_serial *serial) in metrousb_is_unidirectional_mode() argument
60 u16 product_id = le16_to_cpu(serial->dev->descriptor.idProduct); in metrousb_is_unidirectional_mode()
65 static int metrousb_calc_num_ports(struct usb_serial *serial, in metrousb_calc_num_ports() argument
68 if (metrousb_is_unidirectional_mode(serial)) { in metrousb_calc_num_ports()
69 if (epds->num_interrupt_out == 0) { in metrousb_calc_num_ports()
70 dev_err(&serial->interface->dev, "interrupt-out endpoint missing\n"); in metrousb_calc_num_ports()
71 return -ENODEV; in metrousb_calc_num_ports()
84 if (!metrousb_is_unidirectional_mode(port->serial)) in metrousb_send_unidirectional_cmd()
89 return -ENOMEM; in metrousb_send_unidirectional_cmd()
93 ret = usb_interrupt_msg(port->serial->dev, in metrousb_send_unidirectional_cmd()
94 usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress), in metrousb_send_unidirectional_cmd()
103 return -EIO; in metrousb_send_unidirectional_cmd()
109 struct usb_serial_port *port = urb->context; in metrousb_read_int_callback()
111 unsigned char *data = urb->transfer_buffer; in metrousb_read_int_callback()
116 dev_dbg(&port->dev, "%s\n", __func__); in metrousb_read_int_callback()
118 switch (urb->status) { in metrousb_read_int_callback()
122 case -ECONNRESET: in metrousb_read_int_callback()
123 case -ENOENT: in metrousb_read_int_callback()
124 case -ESHUTDOWN: in metrousb_read_int_callback()
126 dev_dbg(&port->dev, in metrousb_read_int_callback()
127 "%s - urb shutting down, error code=%d\n", in metrousb_read_int_callback()
128 __func__, urb->status); in metrousb_read_int_callback()
131 dev_dbg(&port->dev, in metrousb_read_int_callback()
132 "%s - non-zero urb received, error code=%d\n", in metrousb_read_int_callback()
133 __func__, urb->status); in metrousb_read_int_callback()
138 /* Set the data read from the usb port into the serial port buffer. */ in metrousb_read_int_callback()
139 if (urb->actual_length) { in metrousb_read_int_callback()
140 /* Loop through the data copying each byte to the tty layer. */ in metrousb_read_int_callback()
141 tty_insert_flip_string(&port->port, data, urb->actual_length); in metrousb_read_int_callback()
143 /* Force the data to the tty layer. */ in metrousb_read_int_callback()
144 tty_flip_buffer_push(&port->port); in metrousb_read_int_callback()
148 spin_lock_irqsave(&metro_priv->lock, flags); in metrousb_read_int_callback()
149 throttled = metro_priv->throttled; in metrousb_read_int_callback()
150 spin_unlock_irqrestore(&metro_priv->lock, flags); in metrousb_read_int_callback()
155 /* Try to resubmit the urb. */ in metrousb_read_int_callback()
158 dev_err(&port->dev, in metrousb_read_int_callback()
159 "%s - failed submitting interrupt in urb, error code=%d\n", in metrousb_read_int_callback()
165 usb_kill_urb(port->interrupt_in_urb); in metrousb_cleanup()
172 struct usb_serial *serial = port->serial; in metrousb_open() local
178 spin_lock_irqsave(&metro_priv->lock, flags); in metrousb_open()
179 metro_priv->control_state = 0; in metrousb_open()
180 metro_priv->throttled = 0; in metrousb_open()
181 spin_unlock_irqrestore(&metro_priv->lock, flags); in metrousb_open()
184 usb_clear_halt(serial->dev, port->interrupt_in_urb->pipe); in metrousb_open()
187 usb_fill_int_urb(port->interrupt_in_urb, serial->dev, in metrousb_open()
188 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), in metrousb_open()
189 port->interrupt_in_urb->transfer_buffer, in metrousb_open()
190 port->interrupt_in_urb->transfer_buffer_length, in metrousb_open()
192 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); in metrousb_open()
195 dev_err(&port->dev, in metrousb_open()
196 "%s - failed submitting interrupt in urb, error code=%d\n", in metrousb_open()
201 /* Send activate cmd to device */ in metrousb_open()
204 dev_err(&port->dev, in metrousb_open()
205 "%s - failed to configure device, error code=%d\n", in metrousb_open()
213 usb_kill_urb(port->interrupt_in_urb); in metrousb_open()
218 static int metrousb_set_modem_ctrl(struct usb_serial *serial, unsigned int control_state) in metrousb_set_modem_ctrl() argument
223 dev_dbg(&serial->dev->dev, "%s - control state = %d\n", in metrousb_set_modem_ctrl()
232 /* Send the command to the usb port. */ in metrousb_set_modem_ctrl()
233 retval = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), in metrousb_set_modem_ctrl()
237 dev_err(&serial->dev->dev, in metrousb_set_modem_ctrl()
238 "%s - set modem ctrl=0x%x failed, error code=%d\n", in metrousb_set_modem_ctrl()
250 return -ENOMEM; in metrousb_port_probe()
252 spin_lock_init(&metro_priv->lock); in metrousb_port_probe()
269 struct usb_serial_port *port = tty->driver_data; in metrousb_throttle()
273 /* Set the private information for the port to stop reading data. */ in metrousb_throttle()
274 spin_lock_irqsave(&metro_priv->lock, flags); in metrousb_throttle()
275 metro_priv->throttled = 1; in metrousb_throttle()
276 spin_unlock_irqrestore(&metro_priv->lock, flags); in metrousb_throttle()
282 struct usb_serial_port *port = tty->driver_data; in metrousb_tiocmget()
286 spin_lock_irqsave(&metro_priv->lock, flags); in metrousb_tiocmget()
287 control_state = metro_priv->control_state; in metrousb_tiocmget()
288 spin_unlock_irqrestore(&metro_priv->lock, flags); in metrousb_tiocmget()
296 struct usb_serial_port *port = tty->driver_data; in metrousb_tiocmset()
297 struct usb_serial *serial = port->serial; in metrousb_tiocmset() local
302 dev_dbg(&port->dev, "%s - set=%d, clear=%d\n", __func__, set, clear); in metrousb_tiocmset()
304 spin_lock_irqsave(&metro_priv->lock, flags); in metrousb_tiocmset()
305 control_state = metro_priv->control_state; in metrousb_tiocmset()
317 metro_priv->control_state = control_state; in metrousb_tiocmset()
318 spin_unlock_irqrestore(&metro_priv->lock, flags); in metrousb_tiocmset()
319 return metrousb_set_modem_ctrl(serial, control_state); in metrousb_tiocmset()
324 struct usb_serial_port *port = tty->driver_data; in metrousb_unthrottle()
329 /* Set the private information for the port to resume reading data. */ in metrousb_unthrottle()
330 spin_lock_irqsave(&metro_priv->lock, flags); in metrousb_unthrottle()
331 metro_priv->throttled = 0; in metrousb_unthrottle()
332 spin_unlock_irqrestore(&metro_priv->lock, flags); in metrousb_unthrottle()
334 /* Submit the urb to read from the port. */ in metrousb_unthrottle()
335 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); in metrousb_unthrottle()
337 dev_err(&port->dev, in metrousb_unthrottle()
344 .name = "metro-usb",
346 .description = "Metrologic USB to Serial",