1*5fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * USB IR Dongle driver 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com) 61da177e4SLinus Torvalds * Copyright (C) 2002 Gary Brubaker (xavyer@ix.netcom.com) 7f4a4cbb2SJohan Hovold * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com) 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 101da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 111da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 121da177e4SLinus Torvalds * (at your option) any later version. 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * This driver allows a USB IrDA device to be used as a "dumb" serial device. 151da177e4SLinus Torvalds * This can be useful if you do not have access to a full IrDA stack on the 161da177e4SLinus Torvalds * other side of the connection. If you do have an IrDA stack on both devices, 171da177e4SLinus Torvalds * please use the usb-irda driver, as it contains the proper error checking and 181da177e4SLinus Torvalds * other goodness of a full IrDA stack. 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * Portions of this driver were taken from drivers/net/irda/irda-usb.c, which 211da177e4SLinus Torvalds * was written by Roman Weissgaerber <weissg@vienna.at>, Dag Brattli 221da177e4SLinus Torvalds * <dag@brattli.net>, and Jean Tourrilhes <jt@hpl.hp.com> 231da177e4SLinus Torvalds * 24e0d795e4SFelipe Balbi * See Documentation/usb/usb-serial.txt for more information on using this 25e0d795e4SFelipe Balbi * driver 261da177e4SLinus Torvalds */ 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds #include <linux/kernel.h> 291da177e4SLinus Torvalds #include <linux/errno.h> 301da177e4SLinus Torvalds #include <linux/init.h> 311da177e4SLinus Torvalds #include <linux/slab.h> 321da177e4SLinus Torvalds #include <linux/tty.h> 331da177e4SLinus Torvalds #include <linux/tty_driver.h> 341da177e4SLinus Torvalds #include <linux/tty_flip.h> 351da177e4SLinus Torvalds #include <linux/module.h> 361da177e4SLinus Torvalds #include <linux/spinlock.h> 37e0d795e4SFelipe Balbi #include <linux/uaccess.h> 381da177e4SLinus Torvalds #include <linux/usb.h> 39a969888cSGreg Kroah-Hartman #include <linux/usb/serial.h> 40e0d795e4SFelipe Balbi #include <linux/usb/irda.h> 411da177e4SLinus Torvalds 42f4a4cbb2SJohan Hovold #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Johan Hovold <jhovold@gmail.com>" 431da177e4SLinus Torvalds #define DRIVER_DESC "USB IR Dongle driver" 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds /* if overridden by the user, then use their value for the size of the read and 461da177e4SLinus Torvalds * write urbs */ 471da177e4SLinus Torvalds static int buffer_size; 48e0d795e4SFelipe Balbi 491da177e4SLinus Torvalds /* if overridden by the user, then use the specified number of XBOFs */ 501da177e4SLinus Torvalds static int xbof = -1; 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds static int ir_startup (struct usb_serial *serial); 53a509a7e4SAlan Cox static int ir_open(struct tty_struct *tty, struct usb_serial_port *port); 54f4a4cbb2SJohan Hovold static int ir_prepare_write_buffer(struct usb_serial_port *port, 55f4a4cbb2SJohan Hovold void *dest, size_t size); 56f4a4cbb2SJohan Hovold static void ir_process_read_urb(struct urb *urb); 5795da310eSAlan Cox static void ir_set_termios(struct tty_struct *tty, 5895da310eSAlan Cox struct usb_serial_port *port, struct ktermios *old_termios); 591da177e4SLinus Torvalds 60a6ea438bSAlan Cox /* Not that this lot means you can only have one per system */ 61e0d795e4SFelipe Balbi static u8 ir_baud; 62e0d795e4SFelipe Balbi static u8 ir_xbof; 63e0d795e4SFelipe Balbi static u8 ir_add_bof; 641da177e4SLinus Torvalds 657d40d7e8SNémeth Márton static const struct usb_device_id ir_id_table[] = { 661da177e4SLinus Torvalds { USB_DEVICE(0x050f, 0x0180) }, /* KC Technology, KC-180 */ 671da177e4SLinus Torvalds { USB_DEVICE(0x08e9, 0x0100) }, /* XTNDAccess */ 681da177e4SLinus Torvalds { USB_DEVICE(0x09c4, 0x0011) }, /* ACTiSys ACT-IR2000U */ 69e0d795e4SFelipe Balbi { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC, USB_SUBCLASS_IRDA, 0) }, 701da177e4SLinus Torvalds { } /* Terminating entry */ 711da177e4SLinus Torvalds }; 721da177e4SLinus Torvalds 73e0d795e4SFelipe Balbi MODULE_DEVICE_TABLE(usb, ir_id_table); 741da177e4SLinus Torvalds 75ea65370dSGreg Kroah-Hartman static struct usb_serial_driver ir_device = { 7618fcac35SGreg Kroah-Hartman .driver = { 771da177e4SLinus Torvalds .owner = THIS_MODULE, 78269bda1cSGreg Kroah-Hartman .name = "ir-usb", 7918fcac35SGreg Kroah-Hartman }, 80269bda1cSGreg Kroah-Hartman .description = "IR Dongle", 81e0d795e4SFelipe Balbi .id_table = ir_id_table, 821da177e4SLinus Torvalds .num_ports = 1, 831da177e4SLinus Torvalds .set_termios = ir_set_termios, 841da177e4SLinus Torvalds .attach = ir_startup, 851da177e4SLinus Torvalds .open = ir_open, 86f4a4cbb2SJohan Hovold .prepare_write_buffer = ir_prepare_write_buffer, 87f4a4cbb2SJohan Hovold .process_read_urb = ir_process_read_urb, 881da177e4SLinus Torvalds }; 891da177e4SLinus Torvalds 907dbe2460SAlan Stern static struct usb_serial_driver * const serial_drivers[] = { 917dbe2460SAlan Stern &ir_device, NULL 927dbe2460SAlan Stern }; 937dbe2460SAlan Stern 949f857ae9SGreg Kroah-Hartman static inline void irda_usb_dump_class_desc(struct usb_serial *serial, 959f857ae9SGreg Kroah-Hartman struct usb_irda_cs_descriptor *desc) 961da177e4SLinus Torvalds { 979f857ae9SGreg Kroah-Hartman struct device *dev = &serial->dev->dev; 989f857ae9SGreg Kroah-Hartman 999f857ae9SGreg Kroah-Hartman dev_dbg(dev, "bLength=%x\n", desc->bLength); 1009f857ae9SGreg Kroah-Hartman dev_dbg(dev, "bDescriptorType=%x\n", desc->bDescriptorType); 1019f857ae9SGreg Kroah-Hartman dev_dbg(dev, "bcdSpecRevision=%x\n", __le16_to_cpu(desc->bcdSpecRevision)); 1029f857ae9SGreg Kroah-Hartman dev_dbg(dev, "bmDataSize=%x\n", desc->bmDataSize); 1039f857ae9SGreg Kroah-Hartman dev_dbg(dev, "bmWindowSize=%x\n", desc->bmWindowSize); 1049f857ae9SGreg Kroah-Hartman dev_dbg(dev, "bmMinTurnaroundTime=%d\n", desc->bmMinTurnaroundTime); 1059f857ae9SGreg Kroah-Hartman dev_dbg(dev, "wBaudRate=%x\n", __le16_to_cpu(desc->wBaudRate)); 1069f857ae9SGreg Kroah-Hartman dev_dbg(dev, "bmAdditionalBOFs=%x\n", desc->bmAdditionalBOFs); 1079f857ae9SGreg Kroah-Hartman dev_dbg(dev, "bIrdaRateSniff=%x\n", desc->bIrdaRateSniff); 1089f857ae9SGreg Kroah-Hartman dev_dbg(dev, "bMaxUnicastList=%x\n", desc->bMaxUnicastList); 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /*------------------------------------------------------------------*/ 1121da177e4SLinus Torvalds /* 1131da177e4SLinus Torvalds * Function irda_usb_find_class_desc(dev, ifnum) 1141da177e4SLinus Torvalds * 1151da177e4SLinus Torvalds * Returns instance of IrDA class descriptor, or NULL if not found 1161da177e4SLinus Torvalds * 1171da177e4SLinus Torvalds * The class descriptor is some extra info that IrDA USB devices will 1181da177e4SLinus Torvalds * offer to us, describing their IrDA characteristics. We will use that in 1191da177e4SLinus Torvalds * irda_usb_init_qos() 1201da177e4SLinus Torvalds * 1211da177e4SLinus Torvalds * Based on the same function in drivers/net/irda/irda-usb.c 1221da177e4SLinus Torvalds */ 123e0d795e4SFelipe Balbi static struct usb_irda_cs_descriptor * 1249f857ae9SGreg Kroah-Hartman irda_usb_find_class_desc(struct usb_serial *serial, unsigned int ifnum) 1251da177e4SLinus Torvalds { 1269f857ae9SGreg Kroah-Hartman struct usb_device *dev = serial->dev; 127e0d795e4SFelipe Balbi struct usb_irda_cs_descriptor *desc; 1281da177e4SLinus Torvalds int ret; 1291da177e4SLinus Torvalds 130e0d795e4SFelipe Balbi desc = kzalloc(sizeof(*desc), GFP_KERNEL); 131e0d795e4SFelipe Balbi if (!desc) 1321da177e4SLinus Torvalds return NULL; 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 135e0d795e4SFelipe Balbi USB_REQ_CS_IRDA_GET_CLASS_DESC, 1361da177e4SLinus Torvalds USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 1371da177e4SLinus Torvalds 0, ifnum, desc, sizeof(*desc), 1000); 1381da177e4SLinus Torvalds 1399f857ae9SGreg Kroah-Hartman dev_dbg(&serial->dev->dev, "%s - ret=%d\n", __func__, ret); 1401da177e4SLinus Torvalds if (ret < sizeof(*desc)) { 1419f857ae9SGreg Kroah-Hartman dev_dbg(&serial->dev->dev, 1429f857ae9SGreg Kroah-Hartman "%s - class descriptor read %s (%d)\n", __func__, 1439f857ae9SGreg Kroah-Hartman (ret < 0) ? "failed" : "too short", ret); 1441da177e4SLinus Torvalds goto error; 1451da177e4SLinus Torvalds } 146e0d795e4SFelipe Balbi if (desc->bDescriptorType != USB_DT_CS_IRDA) { 1479f857ae9SGreg Kroah-Hartman dev_dbg(&serial->dev->dev, "%s - bad class descriptor type\n", 1489f857ae9SGreg Kroah-Hartman __func__); 1491da177e4SLinus Torvalds goto error; 1501da177e4SLinus Torvalds } 1511da177e4SLinus Torvalds 1529f857ae9SGreg Kroah-Hartman irda_usb_dump_class_desc(serial, desc); 1531da177e4SLinus Torvalds return desc; 154e0d795e4SFelipe Balbi 1551da177e4SLinus Torvalds error: 1561da177e4SLinus Torvalds kfree(desc); 1571da177e4SLinus Torvalds return NULL; 1581da177e4SLinus Torvalds } 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds static u8 ir_xbof_change(u8 xbof) 1611da177e4SLinus Torvalds { 1621da177e4SLinus Torvalds u8 result; 163e0d795e4SFelipe Balbi 1641da177e4SLinus Torvalds /* reference irda-usb.c */ 1651da177e4SLinus Torvalds switch (xbof) { 166e0d795e4SFelipe Balbi case 48: 167e0d795e4SFelipe Balbi result = 0x10; 168e0d795e4SFelipe Balbi break; 1691da177e4SLinus Torvalds case 28: 170e0d795e4SFelipe Balbi case 24: 171e0d795e4SFelipe Balbi result = 0x20; 172e0d795e4SFelipe Balbi break; 1731da177e4SLinus Torvalds default: 174e0d795e4SFelipe Balbi case 12: 175e0d795e4SFelipe Balbi result = 0x30; 176e0d795e4SFelipe Balbi break; 1771da177e4SLinus Torvalds case 5: 178e0d795e4SFelipe Balbi case 6: 179e0d795e4SFelipe Balbi result = 0x40; 180e0d795e4SFelipe Balbi break; 181e0d795e4SFelipe Balbi case 3: 182e0d795e4SFelipe Balbi result = 0x50; 183e0d795e4SFelipe Balbi break; 184e0d795e4SFelipe Balbi case 2: 185e0d795e4SFelipe Balbi result = 0x60; 186e0d795e4SFelipe Balbi break; 187e0d795e4SFelipe Balbi case 1: 188e0d795e4SFelipe Balbi result = 0x70; 189e0d795e4SFelipe Balbi break; 190e0d795e4SFelipe Balbi case 0: 191e0d795e4SFelipe Balbi result = 0x80; 192e0d795e4SFelipe Balbi break; 1931da177e4SLinus Torvalds } 194e0d795e4SFelipe Balbi 1951da177e4SLinus Torvalds return(result); 1961da177e4SLinus Torvalds } 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds static int ir_startup(struct usb_serial *serial) 1991da177e4SLinus Torvalds { 200e0d795e4SFelipe Balbi struct usb_irda_cs_descriptor *irda_desc; 201ad0ccac7SJohan Hovold int rates; 2021da177e4SLinus Torvalds 2039f857ae9SGreg Kroah-Hartman irda_desc = irda_usb_find_class_desc(serial, 0); 204e0d795e4SFelipe Balbi if (!irda_desc) { 205e0d795e4SFelipe Balbi dev_err(&serial->dev->dev, 206e0d795e4SFelipe Balbi "IRDA class descriptor not found, device not bound\n"); 2071da177e4SLinus Torvalds return -ENODEV; 2081da177e4SLinus Torvalds } 2091da177e4SLinus Torvalds 210ad0ccac7SJohan Hovold rates = le16_to_cpu(irda_desc->wBaudRate); 211ad0ccac7SJohan Hovold 2129f857ae9SGreg Kroah-Hartman dev_dbg(&serial->dev->dev, 2139f857ae9SGreg Kroah-Hartman "%s - Baud rates supported:%s%s%s%s%s%s%s%s%s\n", 214441b62c1SHarvey Harrison __func__, 215ad0ccac7SJohan Hovold (rates & USB_IRDA_BR_2400) ? " 2400" : "", 216ad0ccac7SJohan Hovold (rates & USB_IRDA_BR_9600) ? " 9600" : "", 217ad0ccac7SJohan Hovold (rates & USB_IRDA_BR_19200) ? " 19200" : "", 218ad0ccac7SJohan Hovold (rates & USB_IRDA_BR_38400) ? " 38400" : "", 219ad0ccac7SJohan Hovold (rates & USB_IRDA_BR_57600) ? " 57600" : "", 220ad0ccac7SJohan Hovold (rates & USB_IRDA_BR_115200) ? " 115200" : "", 221ad0ccac7SJohan Hovold (rates & USB_IRDA_BR_576000) ? " 576000" : "", 222ad0ccac7SJohan Hovold (rates & USB_IRDA_BR_1152000) ? " 1152000" : "", 223ad0ccac7SJohan Hovold (rates & USB_IRDA_BR_4000000) ? " 4000000" : ""); 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds switch (irda_desc->bmAdditionalBOFs) { 226e0d795e4SFelipe Balbi case USB_IRDA_AB_48: 227e0d795e4SFelipe Balbi ir_add_bof = 48; 228e0d795e4SFelipe Balbi break; 229e0d795e4SFelipe Balbi case USB_IRDA_AB_24: 230e0d795e4SFelipe Balbi ir_add_bof = 24; 231e0d795e4SFelipe Balbi break; 232e0d795e4SFelipe Balbi case USB_IRDA_AB_12: 233e0d795e4SFelipe Balbi ir_add_bof = 12; 234e0d795e4SFelipe Balbi break; 235e0d795e4SFelipe Balbi case USB_IRDA_AB_6: 236e0d795e4SFelipe Balbi ir_add_bof = 6; 237e0d795e4SFelipe Balbi break; 238e0d795e4SFelipe Balbi case USB_IRDA_AB_3: 239e0d795e4SFelipe Balbi ir_add_bof = 3; 240e0d795e4SFelipe Balbi break; 241e0d795e4SFelipe Balbi case USB_IRDA_AB_2: 242e0d795e4SFelipe Balbi ir_add_bof = 2; 243e0d795e4SFelipe Balbi break; 244e0d795e4SFelipe Balbi case USB_IRDA_AB_1: 245e0d795e4SFelipe Balbi ir_add_bof = 1; 246e0d795e4SFelipe Balbi break; 247e0d795e4SFelipe Balbi case USB_IRDA_AB_0: 248e0d795e4SFelipe Balbi ir_add_bof = 0; 249e0d795e4SFelipe Balbi break; 250e0d795e4SFelipe Balbi default: 251e0d795e4SFelipe Balbi break; 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds kfree(irda_desc); 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds return 0; 2571da177e4SLinus Torvalds } 2581da177e4SLinus Torvalds 259a509a7e4SAlan Cox static int ir_open(struct tty_struct *tty, struct usb_serial_port *port) 2601da177e4SLinus Torvalds { 261f4a4cbb2SJohan Hovold int i; 2621da177e4SLinus Torvalds 263f4a4cbb2SJohan Hovold for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) 264f4a4cbb2SJohan Hovold port->write_urbs[i]->transfer_flags = URB_ZERO_PACKET; 265f4a4cbb2SJohan Hovold 2661da177e4SLinus Torvalds /* Start reading from the device */ 267f4a4cbb2SJohan Hovold return usb_serial_generic_open(tty, port); 2681da177e4SLinus Torvalds } 2691da177e4SLinus Torvalds 270f4a4cbb2SJohan Hovold static int ir_prepare_write_buffer(struct usb_serial_port *port, 271f4a4cbb2SJohan Hovold void *dest, size_t size) 2721da177e4SLinus Torvalds { 273f4a4cbb2SJohan Hovold unsigned char *buf = dest; 274e421fe97SJohan Hovold int count; 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds /* 2771da177e4SLinus Torvalds * The first byte of the packet we send to the device contains an 278e0d795e4SFelipe Balbi * inbound header which indicates an additional number of BOFs and 2791da177e4SLinus Torvalds * a baud rate change. 2801da177e4SLinus Torvalds * 2811da177e4SLinus Torvalds * See section 5.4.2.2 of the USB IrDA spec. 2821da177e4SLinus Torvalds */ 283f4a4cbb2SJohan Hovold *buf = ir_xbof | ir_baud; 2841da177e4SLinus Torvalds 285e421fe97SJohan Hovold count = kfifo_out_locked(&port->write_fifo, buf + 1, size - 1, 286f4a4cbb2SJohan Hovold &port->lock); 287e421fe97SJohan Hovold return count + 1; 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds 290f4a4cbb2SJohan Hovold static void ir_process_read_urb(struct urb *urb) 2911da177e4SLinus Torvalds { 292cdc97792SMing Lei struct usb_serial_port *port = urb->context; 2931da177e4SLinus Torvalds unsigned char *data = urb->transfer_buffer; 2941da177e4SLinus Torvalds 295f4a4cbb2SJohan Hovold if (!urb->actual_length) 296f4a4cbb2SJohan Hovold return; 2971da177e4SLinus Torvalds /* 2981da177e4SLinus Torvalds * The first byte of the packet we get from the device 2991da177e4SLinus Torvalds * contains a busy indicator and baud rate change. 3001da177e4SLinus Torvalds * See section 5.4.1.2 of the USB IrDA spec. 3011da177e4SLinus Torvalds */ 302f4a4cbb2SJohan Hovold if (*data & 0x0f) 3031da177e4SLinus Torvalds ir_baud = *data & 0x0f; 304f4a4cbb2SJohan Hovold 305f4a4cbb2SJohan Hovold if (urb->actual_length == 1) 306f4a4cbb2SJohan Hovold return; 307f4a4cbb2SJohan Hovold 30805c7cd39SJiri Slaby tty_insert_flip_string(&port->port, data + 1, urb->actual_length - 1); 3092e124b4aSJiri Slaby tty_flip_buffer_push(&port->port); 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds 312df66e8a2SJohan Hovold static void ir_set_termios_callback(struct urb *urb) 313df66e8a2SJohan Hovold { 314df66e8a2SJohan Hovold kfree(urb->transfer_buffer); 315df66e8a2SJohan Hovold 316b9783555SGreg Kroah-Hartman if (urb->status) 3179f857ae9SGreg Kroah-Hartman dev_dbg(&urb->dev->dev, "%s - non-zero urb status: %d\n", 3189f857ae9SGreg Kroah-Hartman __func__, urb->status); 319df66e8a2SJohan Hovold } 320df66e8a2SJohan Hovold 32195da310eSAlan Cox static void ir_set_termios(struct tty_struct *tty, 32295da310eSAlan Cox struct usb_serial_port *port, struct ktermios *old_termios) 3231da177e4SLinus Torvalds { 324df66e8a2SJohan Hovold struct urb *urb; 3251da177e4SLinus Torvalds unsigned char *transfer_buffer; 3261da177e4SLinus Torvalds int result; 327a6ea438bSAlan Cox speed_t baud; 328a6ea438bSAlan Cox int ir_baud; 3291da177e4SLinus Torvalds 33095da310eSAlan Cox baud = tty_get_baud_rate(tty); 3311da177e4SLinus Torvalds 3321da177e4SLinus Torvalds /* 3331da177e4SLinus Torvalds * FIXME, we should compare the baud request against the 3341da177e4SLinus Torvalds * capability stated in the IR header that we got in the 3351da177e4SLinus Torvalds * startup function. 3361da177e4SLinus Torvalds */ 337a6ea438bSAlan Cox 338a6ea438bSAlan Cox switch (baud) { 339e0d795e4SFelipe Balbi case 2400: 340e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_2400; 341e0d795e4SFelipe Balbi break; 342e0d795e4SFelipe Balbi case 9600: 343e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_9600; 344e0d795e4SFelipe Balbi break; 345e0d795e4SFelipe Balbi case 19200: 346e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_19200; 347e0d795e4SFelipe Balbi break; 348e0d795e4SFelipe Balbi case 38400: 349e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_38400; 350e0d795e4SFelipe Balbi break; 351e0d795e4SFelipe Balbi case 57600: 352e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_57600; 353e0d795e4SFelipe Balbi break; 354e0d795e4SFelipe Balbi case 115200: 355e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_115200; 356e0d795e4SFelipe Balbi break; 357e0d795e4SFelipe Balbi case 576000: 358e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_576000; 359e0d795e4SFelipe Balbi break; 360e0d795e4SFelipe Balbi case 1152000: 361e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_1152000; 362e0d795e4SFelipe Balbi break; 363e0d795e4SFelipe Balbi case 4000000: 364e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_4000000; 365a6ea438bSAlan Cox break; 3661da177e4SLinus Torvalds default: 367e0d795e4SFelipe Balbi ir_baud = USB_IRDA_BR_9600; 368a6ea438bSAlan Cox baud = 9600; 3691da177e4SLinus Torvalds } 3701da177e4SLinus Torvalds 371a6ea438bSAlan Cox if (xbof == -1) 3721da177e4SLinus Torvalds ir_xbof = ir_xbof_change(ir_add_bof); 373a6ea438bSAlan Cox else 3741da177e4SLinus Torvalds ir_xbof = ir_xbof_change(xbof) ; 3751da177e4SLinus Torvalds 376560aac22SAlan Cox /* Only speed changes are supported */ 377adc8d746SAlan Cox tty_termios_copy_hw(&tty->termios, old_termios); 37895da310eSAlan Cox tty_encode_baud_rate(tty, baud, baud); 379df66e8a2SJohan Hovold 380df66e8a2SJohan Hovold /* 381df66e8a2SJohan Hovold * send the baud change out on an "empty" data packet 382df66e8a2SJohan Hovold */ 383df66e8a2SJohan Hovold urb = usb_alloc_urb(0, GFP_KERNEL); 38410c642d0SJohan Hovold if (!urb) 385df66e8a2SJohan Hovold return; 38610c642d0SJohan Hovold 387df66e8a2SJohan Hovold transfer_buffer = kmalloc(1, GFP_KERNEL); 38810c642d0SJohan Hovold if (!transfer_buffer) 389df66e8a2SJohan Hovold goto err_buf; 390df66e8a2SJohan Hovold 391df66e8a2SJohan Hovold *transfer_buffer = ir_xbof | ir_baud; 392df66e8a2SJohan Hovold 393df66e8a2SJohan Hovold usb_fill_bulk_urb( 394df66e8a2SJohan Hovold urb, 395df66e8a2SJohan Hovold port->serial->dev, 396df66e8a2SJohan Hovold usb_sndbulkpipe(port->serial->dev, 397df66e8a2SJohan Hovold port->bulk_out_endpointAddress), 398df66e8a2SJohan Hovold transfer_buffer, 399df66e8a2SJohan Hovold 1, 400df66e8a2SJohan Hovold ir_set_termios_callback, 401df66e8a2SJohan Hovold port); 402df66e8a2SJohan Hovold 403df66e8a2SJohan Hovold urb->transfer_flags = URB_ZERO_PACKET; 404df66e8a2SJohan Hovold 405df66e8a2SJohan Hovold result = usb_submit_urb(urb, GFP_KERNEL); 406df66e8a2SJohan Hovold if (result) { 407df66e8a2SJohan Hovold dev_err(&port->dev, "%s - failed to submit urb: %d\n", 408df66e8a2SJohan Hovold __func__, result); 409df66e8a2SJohan Hovold goto err_subm; 410df66e8a2SJohan Hovold } 411df66e8a2SJohan Hovold 412df66e8a2SJohan Hovold usb_free_urb(urb); 413df66e8a2SJohan Hovold 414df66e8a2SJohan Hovold return; 415df66e8a2SJohan Hovold err_subm: 416df66e8a2SJohan Hovold kfree(transfer_buffer); 417df66e8a2SJohan Hovold err_buf: 418df66e8a2SJohan Hovold usb_free_urb(urb); 4191da177e4SLinus Torvalds } 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds static int __init ir_init(void) 4221da177e4SLinus Torvalds { 4236f6ed696SJohan Hovold if (buffer_size) { 4246f6ed696SJohan Hovold ir_device.bulk_in_size = buffer_size; 4256f6ed696SJohan Hovold ir_device.bulk_out_size = buffer_size; 4266f6ed696SJohan Hovold } 4276f6ed696SJohan Hovold 4287663e308SGreg Kroah-Hartman return usb_serial_register_drivers(serial_drivers, KBUILD_MODNAME, ir_id_table); 4291da177e4SLinus Torvalds } 4301da177e4SLinus Torvalds 4311da177e4SLinus Torvalds static void __exit ir_exit(void) 4321da177e4SLinus Torvalds { 43368e24113SGreg Kroah-Hartman usb_serial_deregister_drivers(serial_drivers); 4341da177e4SLinus Torvalds } 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvalds module_init(ir_init); 4381da177e4SLinus Torvalds module_exit(ir_exit); 4391da177e4SLinus Torvalds 4401da177e4SLinus Torvalds MODULE_AUTHOR(DRIVER_AUTHOR); 4411da177e4SLinus Torvalds MODULE_DESCRIPTION(DRIVER_DESC); 4421da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvalds module_param(xbof, int, 0); 4451da177e4SLinus Torvalds MODULE_PARM_DESC(xbof, "Force specific number of XBOFs"); 4461da177e4SLinus Torvalds module_param(buffer_size, int, 0); 4471da177e4SLinus Torvalds MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers"); 4481da177e4SLinus Torvalds 449