// SPDX-License-Identifier: GPL-2.0+ /* * USB IR Dongle driver * * Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com) * Copyright (C) 2002 Gary Brubaker (xavyer@ix.netcom.com) * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com) * * This driver allows a USB IrDA device to be used as a "dumb" serial device. * This can be useful if you do not have access to a full IrDA stack on the * other side of the connection. If you do have an IrDA stack on both devices, * please use the usb-irda driver, as it contains the proper error checking and * other goodness of a full IrDA stack. * * Portions of this driver were taken from drivers/net/irda/irda-usb.c, which * was written by Roman Weissgaerber <weissg@vienna.at>, Dag Brattli * <dag@brattli.net>, and Jean Tourrilhes <jt@hpl.hp.com> * * See Documentation/usb/usb-serial.rst for more information on using this * driver
*/
/*------------------------------------------------------------------*/ /* * Function irda_usb_find_class_desc(dev, ifnum) * * Returns instance of IrDA class descriptor, or NULL if not found * * The class descriptor is some extra info that IrDA USB devices will * offer to us, describing their IrDA characteristics. We will use that in * irda_usb_init_qos() * * Based on the same function in drivers/net/irda/irda-usb.c
*/ staticstruct usb_irda_cs_descriptor *
irda_usb_find_class_desc(struct usb_serial *serial, unsignedint ifnum)
{ struct usb_device *dev = serial->dev; struct usb_irda_cs_descriptor *desc; int ret;
desc = kzalloc(sizeof(*desc), GFP_KERNEL); if (!desc) return NULL;
/* reference irda-usb.c */ switch (xbof) { case 48:
result = 0x10; break; case 28: case 24:
result = 0x20; break; default: case 12:
result = 0x30; break; case 5: case 6:
result = 0x40; break; case 3:
result = 0x50; break; case 2:
result = 0x60; break; case 1:
result = 0x70; break; case 0:
result = 0x80; break;
}
return(result);
}
staticint ir_startup(struct usb_serial *serial)
{ struct usb_irda_cs_descriptor *irda_desc; int rates;
irda_desc = irda_usb_find_class_desc(serial, 0); if (!irda_desc) {
dev_err(&serial->dev->dev, "IRDA class descriptor not found, device not bound\n"); return -ENODEV;
}
/* * The first byte of the packet we send to the device contains an * outbound header which indicates an additional number of BOFs and * a baud rate change. * * See section 5.4.2.2 of the USB IrDA spec.
*/
*(u8 *)urb->transfer_buffer = ir_xbof | ir_baud;
if (!urb->actual_length) return; /* * The first byte of the packet we get from the device * contains a busy indicator and baud rate change. * See section 5.4.1.2 of the USB IrDA spec.
*/ if (*data & 0x0f)
ir_baud = *data & 0x0f;
if (urb->actual_length == 1) return;
tty_insert_flip_string(&port->port, data + 1, urb->actual_length - 1);
tty_flip_buffer_push(&port->port);
}
staticvoid ir_set_termios(struct tty_struct *tty, struct usb_serial_port *port, conststruct ktermios *old_termios)
{ struct usb_device *udev = port->serial->dev; unsignedchar *transfer_buffer; int actual_length;
speed_t baud; int ir_baud; int ret;
baud = tty_get_baud_rate(tty);
/* * FIXME, we should compare the baud request against the * capability stated in the IR header that we got in the * startup function.
*/
switch (baud) { case 2400:
ir_baud = USB_IRDA_LS_2400; break; case 9600:
ir_baud = USB_IRDA_LS_9600; break; case 19200:
ir_baud = USB_IRDA_LS_19200; break; case 38400:
ir_baud = USB_IRDA_LS_38400; break; case 57600:
ir_baud = USB_IRDA_LS_57600; break; case 115200:
ir_baud = USB_IRDA_LS_115200; break; case 576000:
ir_baud = USB_IRDA_LS_576000; break; case 1152000:
ir_baud = USB_IRDA_LS_1152000; break; case 4000000:
ir_baud = USB_IRDA_LS_4000000; break; default:
ir_baud = USB_IRDA_LS_9600;
baud = 9600;
}
/* Only speed changes are supported */
tty_termios_copy_hw(&tty->termios, old_termios);
tty_encode_baud_rate(tty, baud, baud);
/* * send the baud change out on an "empty" data packet
*/
transfer_buffer = kmalloc(1, GFP_KERNEL); if (!transfer_buffer) return;
*transfer_buffer = ir_xbof | ir_baud;
ret = usb_bulk_msg(udev,
usb_sndbulkpipe(udev, port->bulk_out_endpointAddress),
transfer_buffer, 1, &actual_length, 5000); if (ret || actual_length != 1) { if (!ret)
ret = -EIO;
dev_err(&port->dev, "failed to change line speed: %d\n", ret);
}
module_param(xbof, int, 0);
MODULE_PARM_DESC(xbof, "Force specific number of XBOFs");
module_param(buffer_size, int, 0);
MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.