Lines Matching +full:usb +full:- +full:to +full:- +full:serial
1 // SPDX-License-Identifier: GPL-2.0+
3 * USB IR Dongle driver
5 * Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com)
9 * This driver allows a USB IrDA device to be used as a "dumb" serial device.
10 * This can be useful if you do not have access to a full IrDA stack on the
12 * please use the usb-irda driver, as it contains the proper error checking and
15 * Portions of this driver were taken from drivers/net/irda/irda-usb.c, which
19 * See Documentation/usb/usb-serial.rst for more information on using this
33 #include <linux/usb.h>
34 #include <linux/usb/serial.h>
35 #include <linux/usb/irda.h>
37 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Johan Hovold <jhovold@gmail.com>"
38 #define DRIVER_DESC "USB IR Dongle driver"
45 static int xbof = -1;
47 static int ir_startup (struct usb_serial *serial);
63 { USB_DEVICE(0x050f, 0x0180) }, /* KC Technology, KC-180 */
65 { USB_DEVICE(0x09c4, 0x0011) }, /* ACTiSys ACT-IR2000U */
70 MODULE_DEVICE_TABLE(usb, ir_id_table);
74 .name = "ir-usb",
93 static inline void irda_usb_dump_class_desc(struct usb_serial *serial, in irda_usb_dump_class_desc() argument
96 struct device *dev = &serial->dev->dev; in irda_usb_dump_class_desc()
98 dev_dbg(dev, "bLength=%x\n", desc->bLength); in irda_usb_dump_class_desc()
99 dev_dbg(dev, "bDescriptorType=%x\n", desc->bDescriptorType); in irda_usb_dump_class_desc()
100 dev_dbg(dev, "bcdSpecRevision=%x\n", __le16_to_cpu(desc->bcdSpecRevision)); in irda_usb_dump_class_desc()
101 dev_dbg(dev, "bmDataSize=%x\n", desc->bmDataSize); in irda_usb_dump_class_desc()
102 dev_dbg(dev, "bmWindowSize=%x\n", desc->bmWindowSize); in irda_usb_dump_class_desc()
103 dev_dbg(dev, "bmMinTurnaroundTime=%d\n", desc->bmMinTurnaroundTime); in irda_usb_dump_class_desc()
104 dev_dbg(dev, "wBaudRate=%x\n", __le16_to_cpu(desc->wBaudRate)); in irda_usb_dump_class_desc()
105 dev_dbg(dev, "bmAdditionalBOFs=%x\n", desc->bmAdditionalBOFs); in irda_usb_dump_class_desc()
106 dev_dbg(dev, "bIrdaRateSniff=%x\n", desc->bIrdaRateSniff); in irda_usb_dump_class_desc()
107 dev_dbg(dev, "bMaxUnicastList=%x\n", desc->bMaxUnicastList); in irda_usb_dump_class_desc()
110 /*------------------------------------------------------------------*/
116 * The class descriptor is some extra info that IrDA USB devices will
117 * offer to us, describing their IrDA characteristics. We will use that in
120 * Based on the same function in drivers/net/irda/irda-usb.c
123 irda_usb_find_class_desc(struct usb_serial *serial, unsigned int ifnum) in irda_usb_find_class_desc() argument
125 struct usb_device *dev = serial->dev; in irda_usb_find_class_desc()
138 dev_dbg(&serial->dev->dev, "%s - ret=%d\n", __func__, ret); in irda_usb_find_class_desc()
140 dev_dbg(&serial->dev->dev, in irda_usb_find_class_desc()
141 "%s - class descriptor read %s (%d)\n", __func__, in irda_usb_find_class_desc()
145 if (desc->bDescriptorType != USB_DT_CS_IRDA) { in irda_usb_find_class_desc()
146 dev_dbg(&serial->dev->dev, "%s - bad class descriptor type\n", in irda_usb_find_class_desc()
151 irda_usb_dump_class_desc(serial, desc); in irda_usb_find_class_desc()
163 /* reference irda-usb.c */ in ir_xbof_change()
197 static int ir_startup(struct usb_serial *serial) in ir_startup() argument
202 irda_desc = irda_usb_find_class_desc(serial, 0); in ir_startup()
204 dev_err(&serial->dev->dev, in ir_startup()
206 return -ENODEV; in ir_startup()
209 rates = le16_to_cpu(irda_desc->wBaudRate); in ir_startup()
211 dev_dbg(&serial->dev->dev, in ir_startup()
212 "%s - Baud rates supported:%s%s%s%s%s%s%s%s%s\n", in ir_startup()
224 switch (irda_desc->bmAdditionalBOFs) { in ir_startup()
265 if (port->bulk_out_size == 0) in ir_write()
266 return -EINVAL; in ir_write()
271 count = min(count, port->bulk_out_size - 1); in ir_write()
273 spin_lock_irqsave(&port->lock, flags); in ir_write()
274 if (__test_and_clear_bit(0, &port->write_urbs_free)) { in ir_write()
275 urb = port->write_urbs[0]; in ir_write()
276 port->tx_bytes += count; in ir_write()
278 spin_unlock_irqrestore(&port->lock, flags); in ir_write()
284 * The first byte of the packet we send to the device contains an in ir_write()
288 * See section 5.4.2.2 of the USB IrDA spec. in ir_write()
290 *(u8 *)urb->transfer_buffer = ir_xbof | ir_baud; in ir_write()
292 memcpy(urb->transfer_buffer + 1, buf, count); in ir_write()
294 urb->transfer_buffer_length = count + 1; in ir_write()
295 urb->transfer_flags = URB_ZERO_PACKET; in ir_write()
299 dev_err(&port->dev, "failed to submit write urb: %d\n", ret); in ir_write()
301 spin_lock_irqsave(&port->lock, flags); in ir_write()
302 __set_bit(0, &port->write_urbs_free); in ir_write()
303 port->tx_bytes -= count; in ir_write()
304 spin_unlock_irqrestore(&port->lock, flags); in ir_write()
314 struct usb_serial_port *port = urb->context; in ir_write_bulk_callback()
315 int status = urb->status; in ir_write_bulk_callback()
318 spin_lock_irqsave(&port->lock, flags); in ir_write_bulk_callback()
319 __set_bit(0, &port->write_urbs_free); in ir_write_bulk_callback()
320 port->tx_bytes -= urb->transfer_buffer_length - 1; in ir_write_bulk_callback()
321 spin_unlock_irqrestore(&port->lock, flags); in ir_write_bulk_callback()
326 case -ENOENT: in ir_write_bulk_callback()
327 case -ECONNRESET: in ir_write_bulk_callback()
328 case -ESHUTDOWN: in ir_write_bulk_callback()
329 dev_dbg(&port->dev, "write urb stopped: %d\n", status); in ir_write_bulk_callback()
331 case -EPIPE: in ir_write_bulk_callback()
332 dev_err(&port->dev, "write urb stopped: %d\n", status); in ir_write_bulk_callback()
335 dev_err(&port->dev, "nonzero write-urb status: %d\n", status); in ir_write_bulk_callback()
344 struct usb_serial_port *port = tty->driver_data; in ir_write_room()
347 if (port->bulk_out_size == 0) in ir_write_room()
350 if (test_bit(0, &port->write_urbs_free)) in ir_write_room()
351 count = port->bulk_out_size - 1; in ir_write_room()
358 struct usb_serial_port *port = urb->context; in ir_process_read_urb()
359 unsigned char *data = urb->transfer_buffer; in ir_process_read_urb()
361 if (!urb->actual_length) in ir_process_read_urb()
366 * See section 5.4.1.2 of the USB IrDA spec. in ir_process_read_urb()
371 if (urb->actual_length == 1) in ir_process_read_urb()
374 tty_insert_flip_string(&port->port, data + 1, urb->actual_length - 1); in ir_process_read_urb()
375 tty_flip_buffer_push(&port->port); in ir_process_read_urb()
382 struct usb_device *udev = port->serial->dev; in ir_set_termios()
430 if (xbof == -1) in ir_set_termios()
436 tty_termios_copy_hw(&tty->termios, old_termios); in ir_set_termios()
449 usb_sndbulkpipe(udev, port->bulk_out_endpointAddress), in ir_set_termios()
453 ret = -EIO; in ir_set_termios()
454 dev_err(&port->dev, "failed to change line speed: %d\n", ret); in ir_set_termios()