static void ir_close (struct usb_serial_port *port, struct file * filp) { struct usb_serial *serial; if (port_paranoia_check (port, __FUNCTION__)) return; dbg(__FUNCTION__ " - port %d", port->number); serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; down (&port->sem); --port->open_count; if (port->open_count <= 0) { if (serial->dev) { /* shutdown our bulk read */ usb_unlink_urb (port->read_urb); } port->active = 0; port->open_count = 0; } up (&port->sem); MOD_DEC_USE_COUNT; }
static void ir_write_bulk_callback (struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); if (urb->status) { dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); return; } usb_serial_debug_data ( __FILE__, __FUNCTION__, urb->actual_length, urb->transfer_buffer); queue_task(&port->tqueue, &tq_immediate); mark_bh(IMMEDIATE_BH); return; }
static int qt_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial; struct quatech_port *qt_port; int retval = -EINVAL; if (port_paranoia_check(port, __func__)) return -1; serial = get_usb_serial(port, __func__); if (!serial) return -ENODEV; qt_port = qt_get_port_private(port); mutex_lock(&qt_port->lock); if (serial->num_bulk_out) { if (port->write_urb->status != -EINPROGRESS) retval = port->bulk_out_size; } mutex_unlock(&qt_port->lock); return retval; }
/***************************************************************************** * generic devices specific driver functions *****************************************************************************/ static int generic_open (struct usb_serial_port *port, struct file *filp) { struct usb_serial *serial = port->serial; int result = 0; if (port_paranoia_check (port, __FUNCTION__)) return -ENODEV; dbg("%s - port %d", __FUNCTION__, port->number); /* force low_latency on so that our tty_push actually forces the data through, otherwise it is scheduled, and with high data rates (like with OHCI) data can get lost. */ if (port->tty) port->tty->low_latency = 1; /* if we have a bulk interrupt, start reading from it */ if (serial->num_bulk_in) { /* Start reading from the device */ usb_fill_bulk_urb (port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ((serial->type->read_bulk_callback) ? serial->type->read_bulk_callback : generic_read_bulk_callback), port); result = usb_submit_urb(port->read_urb); if (result) err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); } return result; }
static int ir_open (struct usb_serial_port *port, struct file *filp) { struct usb_serial *serial = port->serial; char *buffer; int result = 0; if (port_paranoia_check (port, __FUNCTION__)) return -ENODEV; dbg(__FUNCTION__ " - port %d", port->number); down (&port->sem); ++port->open_count; MOD_INC_USE_COUNT; if (!port->active) { port->active = 1; if (buffer_size) { /* override the default buffer sizes */ buffer = kmalloc (buffer_size, GFP_KERNEL); if (!buffer) { err (__FUNCTION__ " - out of memory."); return -ENOMEM; } kfree (port->read_urb->transfer_buffer); port->read_urb->transfer_buffer = buffer; port->read_urb->transfer_buffer_length = buffer_size; buffer = kmalloc (buffer_size, GFP_KERNEL); if (!buffer) { err (__FUNCTION__ " - out of memory."); return -ENOMEM; } kfree (port->write_urb->transfer_buffer); port->write_urb->transfer_buffer = buffer; port->write_urb->transfer_buffer_length = buffer_size; port->bulk_out_size = buffer_size; } /* Start reading from the device */ FILL_BULK_URB(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ir_read_bulk_callback, port); result = usb_submit_urb(port->read_urb); if (result) err(__FUNCTION__ " - failed submitting read urb, error %d", result); } up (&port->sem); return result; }
static void visor_close (struct usb_serial_port *port, struct file * filp) { struct usb_serial *serial; unsigned char *transfer_buffer; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; if (serial->dev) { /* only send a shutdown message if the * device is still here */ transfer_buffer = kmalloc (0x12, GFP_KERNEL); if (!transfer_buffer) { err("%s - kmalloc(%d) failed.", __FUNCTION__, 0x12); } else { /* send a shutdown message to the device */ usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_CLOSE_NOTIFICATION, 0xc2, 0x0000, 0x0000, transfer_buffer, 0x12, 300); kfree (transfer_buffer); } /* shutdown our urbs */ usb_unlink_urb (port->read_urb); if (port->interrupt_in_urb) usb_unlink_urb (port->interrupt_in_urb); /* Try to send shutdown message, if the device is gone, this will just fail. */ transfer_buffer = kmalloc (0x12, GFP_KERNEL); if (transfer_buffer) { usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_CLOSE_NOTIFICATION, 0xc2, 0x0000, 0x0000, transfer_buffer, 0x12, 300); kfree (transfer_buffer); } } /* Uncomment the following line if you want to see some statistics in your syslog */ info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); }
static void visor_read_bulk_callback (struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; int i; int result; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); if (!serial) { dbg("%s - bad serial pointer, exiting", __FUNCTION__); return; } if (urb->status) { dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); return; } usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data); tty = port->tty; if (tty && urb->actual_length) { for (i = 0; i < urb->actual_length ; ++i) { /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ if(tty->flip.count >= TTY_FLIPBUF_SIZE) { tty_flip_buffer_push(tty); } /* this doesn't actually push the data through unless tty->low_latency is set */ tty_insert_flip_char(tty, data[i], 0); } tty_flip_buffer_push(tty); bytes_in += urb->actual_length; } /* Continue trying to always read */ usb_fill_bulk_urb (port->read_urb, serial->dev, usb_rcvbulkpipe (serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, visor_read_bulk_callback, port); result = usb_submit_urb(port->read_urb); if (result) err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); return; }
/****************************************************************************** * Handspring Visor specific driver functions ******************************************************************************/ static int visor_open (struct usb_serial_port *port, struct file *filp) { struct usb_serial *serial = port->serial; int result = 0; if (port_paranoia_check (port, __FUNCTION__)) return -ENODEV; dbg("%s - port %d", __FUNCTION__, port->number); if (!port->read_urb) { /* this is needed for some brain dead Sony devices */ err ("Device lied about number of ports, please use a lower one."); return -ENODEV; } bytes_in = 0; bytes_out = 0; /* * Force low_latency on so that our tty_push actually forces the data * through, otherwise it is scheduled, and with high data rates (like * with OHCI) data can get lost. */ if (port->tty) port->tty->low_latency = 1; /* Start reading from the device */ usb_fill_bulk_urb (port->read_urb, serial->dev, usb_rcvbulkpipe (serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, visor_read_bulk_callback, port); result = usb_submit_urb(port->read_urb); if (result) { err("%s - failed submitting read urb, error %d", __FUNCTION__, result); goto exit; } if (port->interrupt_in_urb) { dbg("%s - adding interrupt input for treo", __FUNCTION__); result = usb_submit_urb(port->interrupt_in_urb); if (result) err("%s - failed submitting interrupt urb, error %d\n", __FUNCTION__, result); } exit: return result; }
static struct usb_serial *get_usb_serial(struct usb_serial_port *port, const char *function) { /* if no port was specified, or it fails a paranoia check */ if (!port || port_paranoia_check(port, function) || serial_paranoia_check(port->serial, function)) { /* * then say that we dont have a valid usb_serial thing, * which will end up genrating -ENODEV return values */ return NULL; } return port->serial; }
/***************************************************************************** * generic devices specific driver functions *****************************************************************************/ static int generic_open (struct usb_serial_port *port, struct file *filp) { struct usb_serial *serial = port->serial; int result = 0; if (port_paranoia_check (port, __FUNCTION__)) return -ENODEV; /* only increment our usage count, if this device is _really_ a generic device */ if_generic_do(MOD_INC_USE_COUNT); dbg(__FUNCTION__ " - port %d", port->number); down (&port->sem); ++port->open_count; if (!port->active) { port->active = 1; /* force low_latency on so that our tty_push actually forces the data through, otherwise it is scheduled, and with high data rates (like with OHCI) data can get lost. */ port->tty->low_latency = 1; /* if we have a bulk interrupt, start reading from it */ if (serial->num_bulk_in) { /* Start reading from the device */ FILL_BULK_URB(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ((serial->type->read_bulk_callback) ? serial->type->read_bulk_callback : generic_read_bulk_callback), port); result = usb_submit_urb(port->read_urb); if (result) err(__FUNCTION__ " - failed resubmitting read urb, error %d", result); } } up (&port->sem); return result; }
static void visor_close (struct usb_serial_port *port, struct file * filp) { struct usb_serial *serial; unsigned char *transfer_buffer; if (port_paranoia_check (port, __FUNCTION__)) return; dbg(__FUNCTION__ " - port %d", port->number); serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; down (&port->sem); --port->open_count; if (port->open_count <= 0) { if (serial->dev) { /* only send a shutdown message if the * device is still here */ transfer_buffer = kmalloc (0x12, GFP_KERNEL); if (!transfer_buffer) { err(__FUNCTION__ " - kmalloc(%d) failed.", 0x12); } else { /* send a shutdown message to the device */ usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_CLOSE_NOTIFICATION, 0xc2, 0x0000, 0x0000, transfer_buffer, 0x12, 300); kfree (transfer_buffer); } /* shutdown our bulk read */ usb_unlink_urb (port->read_urb); } port->open_count = 0; } up (&port->sem); /* Uncomment the following line if you want to see some statistics in your syslog */ /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */ }
/****************************************************************************** * Handspring Visor specific driver functions ******************************************************************************/ static int visor_open (struct usb_serial_port *port, struct file *filp) { struct usb_serial *serial = port->serial; int result = 0; if (port_paranoia_check (port, __FUNCTION__)) return -ENODEV; dbg(__FUNCTION__ " - port %d", port->number); if (!port->read_urb) { err ("Device lied about number of ports, please use a lower one."); return -ENODEV; } down (&port->sem); ++port->open_count; if (port->open_count == 1) { bytes_in = 0; bytes_out = 0; /* force low_latency on so that our tty_push actually forces the data through, otherwise it is scheduled, and with high data rates (like with OHCI) data can get lost. */ port->tty->low_latency = 1; /* Start reading from the device */ usb_fill_bulk_urb (port->read_urb, serial->dev, usb_rcvbulkpipe (serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, visor_read_bulk_callback, port); result = usb_submit_urb(port->read_urb); if (result) err(__FUNCTION__ " - failed submitting read urb, error %d", result); } up (&port->sem); return result; }
static void visor_write_bulk_callback (struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; if (port_paranoia_check (port, __FUNCTION__)) return; dbg(__FUNCTION__ " - port %d", port->number); if (urb->status) { dbg(__FUNCTION__ " - nonzero write bulk status received: %d", urb->status); return; } queue_task(&port->tqueue, &tq_immediate); mark_bh(IMMEDIATE_BH); return; }
static void empeg_close (struct usb_serial_port *port, struct file * filp) { struct usb_serial *serial; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; if (serial->dev) { /* shutdown our bulk read */ usb_unlink_urb (port->read_urb); } /* Uncomment the following line if you want to see some statistics in your syslog */ /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */ }
static void ir_read_bulk_callback (struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; int result; if (port_paranoia_check (port, __FUNCTION__)) return; dbg(__FUNCTION__ " - port %d", port->number); if (!serial) { dbg(__FUNCTION__ " - bad serial pointer, exiting"); return; } if (urb->status) { dbg(__FUNCTION__ " - nonzero read bulk status received: %d", urb->status); return; } usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data); /* Bypass flip-buffers, and feed the ldisc directly due to our * potentally large buffer size. Since we used to set low_latency, * this is exactly what the tty layer did anyway :) */ tty = port->tty; tty->ldisc.receive_buf(tty, data+1, NULL, urb->actual_length-1); /* Continue trying to always read */ FILL_BULK_URB(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ir_read_bulk_callback, port); result = usb_submit_urb(port->read_urb); if (result) err(__FUNCTION__ " - failed resubmitting read urb, error %d", result); return; }
/****************************************************************************** * Empeg specific driver functions ******************************************************************************/ static int empeg_open (struct usb_serial_port *port, struct file *filp) { struct usb_serial *serial = port->serial; int result = 0;; if (port_paranoia_check (port, __FUNCTION__)) return -ENODEV; dbg("%s - port %d", __FUNCTION__, port->number); /* Force default termio settings */ empeg_set_termios (port, NULL) ; bytes_in = 0; bytes_out = 0; /* Start reading from the device */ FILL_BULK_URB( port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, empeg_read_bulk_callback, port); port->read_urb->transfer_flags |= USB_QUEUE_BULK; result = usb_submit_urb(port->read_urb); if (result) err("%s - failed submitting read urb, error %d", __FUNCTION__, result); return result; }
static int qt_open(struct tty_struct *tty, struct usb_serial_port *port) { struct usb_serial *serial; struct quatech_port *quatech_port; struct quatech_port *port0; struct qt_open_channel_data ChannelData; int result; if (port_paranoia_check(port, __func__)) return -ENODEV; serial = port->serial; if (serial_paranoia_check(serial, __func__)) return -ENODEV; quatech_port = qt_get_port_private(port); port0 = qt_get_port_private(serial->port[0]); if (quatech_port == NULL || port0 == NULL) return -ENODEV; usb_clear_halt(serial->dev, port->write_urb->pipe); usb_clear_halt(serial->dev, port->read_urb->pipe); port0->open_ports++; result = qt_get_device(serial, &port0->DeviceData); /* Port specific setups */ result = qt_open_channel(serial, port->number, &ChannelData); if (result < 0) { dev_dbg(&port->dev, "qt_open_channel failed\n"); return result; } dev_dbg(&port->dev, "qt_open_channel completed.\n"); /* FIXME: are these needed? Does it even do anything useful? */ quatech_port->shadowLSR = ChannelData.line_status & (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | SERIAL_LSR_BI); quatech_port->shadowMSR = ChannelData.modem_status & (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD); /* Set Baud rate to default and turn off (default)flow control here */ result = qt_setuart(serial, port->number, DEFAULT_DIVISOR, DEFAULT_LCR); if (result < 0) { dev_dbg(&port->dev, "qt_setuart failed\n"); return result; } dev_dbg(&port->dev, "qt_setuart completed.\n"); /* * Put this here to make it responsive to stty and defaults set by * the tty layer */ /* Check to see if we've set up our endpoint info yet */ if (port0->open_ports == 1) { if (serial->port[0]->interrupt_in_buffer == NULL) qt_submit_urb_from_open(serial, port); } dev_dbg(&port->dev, "port number is %d\n", port->number); dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor); dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress); dev_dbg(&port->dev, "BulkOut endpoint is %d\n", port->bulk_out_endpointAddress); dev_dbg(&port->dev, "Interrupt endpoint is %d\n", port->interrupt_in_endpointAddress); dev_dbg(&port->dev, "port's number in the device is %d\n", quatech_port->port_num); quatech_port->read_urb = port->read_urb; /* set up our bulk in urb */ usb_fill_bulk_urb(quatech_port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->bulk_in_buffer, quatech_port->read_urb->transfer_buffer_length, qt_read_bulk_callback, quatech_port); dev_dbg(&port->dev, "qt_open: bulkin endpoint is %d\n", port->bulk_in_endpointAddress); quatech_port->read_urb_busy = true; result = usb_submit_urb(quatech_port->read_urb, GFP_KERNEL); if (result) { dev_err(&port->dev, "%s - Error %d submitting control urb\n", __func__, result); quatech_port->read_urb_busy = false; } /* initialize our wait queues */ init_waitqueue_head(&quatech_port->wait); init_waitqueue_head(&quatech_port->msr_wait); /* initialize our icount structure */ memset(&(quatech_port->icount), 0x00, sizeof(quatech_port->icount)); return 0; }
static void qt_read_bulk_callback(struct urb *urb) { struct usb_serial_port *port = urb->context; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port = qt_get_port_private(port); int result; if (urb->status) { qt_port->ReadBulkStopped = 1; dev_dbg(&urb->dev->dev, "%s - nonzero write bulk status received: %d\n", __func__, urb->status); return; } dev_dbg(&port->dev, "%s - port->RxHolding = %d\n", __func__, qt_port->RxHolding); if (port_paranoia_check(port, __func__) != 0) { qt_port->ReadBulkStopped = 1; return; } if (!serial) return; if (qt_port->closePending == 1) { /* Were closing , stop reading */ dev_dbg(&port->dev, "%s - (qt_port->closepending == 1\n", __func__); qt_port->ReadBulkStopped = 1; return; } /* * RxHolding is asserted by throttle, if we assert it, we're not * receiving any more characters and let the box handle the flow * control */ if (qt_port->RxHolding == 1) { qt_port->ReadBulkStopped = 1; return; } if (urb->status) { qt_port->ReadBulkStopped = 1; dev_dbg(&port->dev, "%s - nonzero read bulk status received: %d\n", __func__, urb->status); return; } if (urb->actual_length) qt_status_change_check(urb, qt_port, port); /* Continue trying to always read */ usb_fill_bulk_urb(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, qt_read_bulk_callback, port); result = usb_submit_urb(port->read_urb, GFP_ATOMIC); if (result) dev_dbg(&port->dev, "%s - failed resubmitting read urb, error %d", __func__, result); else { if (urb->actual_length) { tty_flip_buffer_push(&port->port); tty_schedule_flip(&port->port); } } schedule_work(&port->work); }
static void ir_read_bulk_callback (struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; int result; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); if (!serial) { dbg("%s - bad serial pointer, exiting", __FUNCTION__); return; } if (!port->active) { dbg("%s - port closed.", __FUNCTION__); return; } switch (urb->status) { case 0: /* Successful */ /* * 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) > 0) ir_baud = *data & 0x0f; usb_serial_debug_data ( __FILE__, __FUNCTION__, urb->actual_length, data); /* * Bypass flip-buffers, and feed the ldisc directly * due to our potentally large buffer size. Since we * used to set low_latency, this is exactly what the * tty layer did anyway :) */ tty = port->tty; tty->ldisc.receive_buf( tty, data+1, NULL, urb->actual_length-1); /* * No break here. * We want to resubmit the urb so we can read * again. */ case -EPROTO: /* taking inspiration from pl2303.c */ /* Continue trying to always read */ usb_fill_bulk_urb ( port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ir_read_bulk_callback, port); port->read_urb->transfer_flags = USB_QUEUE_BULK; result = usb_submit_urb(port->read_urb); if (result) err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); break ; default: dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); break ; } return; }
static int ir_startup (struct usb_serial *serial) { struct irda_class_desc *irda_desc; irda_desc = irda_usb_find_class_desc (serial->dev, 0); if (irda_desc == NULL) { err ("IRDA class descriptor not found, device not bound"); return -ENODEV; } dbg ("%s - Baud rates supported:%s%s%s%s%s%s%s%s%s", __FUNCTION__, (irda_desc->wBaudRate & 0x0001) ? " 2400" : "", (irda_desc->wBaudRate & 0x0002) ? " 9600" : "", (irda_desc->wBaudRate & 0x0004) ? " 19200" : "", (irda_desc->wBaudRate & 0x0008) ? " 38400" : "", (irda_desc->wBaudRate & 0x0010) ? " 57600" : "", (irda_desc->wBaudRate & 0x0020) ? " 115200" : "", (irda_desc->wBaudRate & 0x0040) ? " 576000" : "", (irda_desc->wBaudRate & 0x0080) ? " 1152000" : "", (irda_desc->wBaudRate & 0x0100) ? " 4000000" : ""); switch( irda_desc->bmAdditionalBOFs ) { case 0x01: ir_add_bof = 48; break; case 0x02: ir_add_bof = 24; break; case 0x04: ir_add_bof = 12; break; case 0x08: ir_add_bof = 6; break; case 0x10: ir_add_bof = 3; break; case 0x20: ir_add_bof = 2; break; case 0x40: ir_add_bof = 1; break; case 0x80: ir_add_bof = 0; break; default: } kfree (irda_desc); return 0; } static int ir_open (struct usb_serial_port *port, struct file *filp) { struct usb_serial *serial = port->serial; char *buffer; int result = 0; if (port_paranoia_check (port, __FUNCTION__)) return -ENODEV; dbg("%s - port %d", __FUNCTION__, port->number); down (&port->sem); ++port->open_count; MOD_INC_USE_COUNT; if (!port->active) { port->active = 1; if (buffer_size) { /* override the default buffer sizes */ buffer = kmalloc (buffer_size, GFP_KERNEL); if (!buffer) { err ("%s - out of memory.", __FUNCTION__); return -ENOMEM; } kfree (port->read_urb->transfer_buffer); port->read_urb->transfer_buffer = buffer; port->read_urb->transfer_buffer_length = buffer_size; buffer = kmalloc (buffer_size, GFP_KERNEL); if (!buffer) { err ("%s - out of memory.", __FUNCTION__); return -ENOMEM; } kfree (port->write_urb->transfer_buffer); port->write_urb->transfer_buffer = buffer; port->write_urb->transfer_buffer_length = buffer_size; port->bulk_out_size = buffer_size; } /* Start reading from the device */ usb_fill_bulk_urb ( port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ir_read_bulk_callback, port); port->read_urb->transfer_flags = USB_QUEUE_BULK; result = usb_submit_urb(port->read_urb); if (result) err("%s - failed submitting read urb, error %d", __FUNCTION__, result); } up (&port->sem); return result; } static void ir_close (struct usb_serial_port *port, struct file * filp) { struct usb_serial *serial; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; down (&port->sem); --port->open_count; if (port->open_count <= 0) { if (serial->dev) { /* shutdown our bulk read */ usb_unlink_urb (port->read_urb); } port->active = 0; port->open_count = 0; } up (&port->sem); MOD_DEC_USE_COUNT; } static int ir_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count) { unsigned char *transfer_buffer; int result; int transfer_size; dbg("%s - port = %d, count = %d", __FUNCTION__, port->number, count); if (!port->tty) { err ("%s - no tty???", __FUNCTION__); return 0; } if (count == 0) return 0; if (port->write_urb->status == -EINPROGRESS) { dbg ("%s - already writing", __FUNCTION__); return 0; } transfer_buffer = port->write_urb->transfer_buffer; transfer_size = min(count, port->bulk_out_size - 1); /* * The first byte of the packet we send to the device contains an * inband header which indicates an additional number of BOFs and * a baud rate change. * * See section 5.4.2.2 of the USB IrDA spec. */ *transfer_buffer = ir_xbof | ir_baud; ++transfer_buffer; if (from_user) { if (copy_from_user (transfer_buffer, buf, transfer_size)) return -EFAULT; } else { memcpy (transfer_buffer, buf, transfer_size); } usb_fill_bulk_urb ( port->write_urb, port->serial->dev, usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), port->write_urb->transfer_buffer, transfer_size + 1, ir_write_bulk_callback, port); port->write_urb->transfer_flags = USB_QUEUE_BULK | USB_ZERO_PACKET; result = usb_submit_urb (port->write_urb); if (result) err("%s - failed submitting write urb, error %d", __FUNCTION__, result); else result = transfer_size; return result; }
static void empeg_read_bulk_callback (struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; int i; int result; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); if (!serial) { dbg("%s - bad serial pointer, exiting", __FUNCTION__); return; } if (urb->status) { dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); return; } usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data); tty = port->tty; if (urb->actual_length) { for (i = 0; i < urb->actual_length ; ++i) { /* gb - 2000/11/13 * If we insert too many characters we'll overflow the buffer. * This means we'll lose bytes - Decidedly bad. */ if(tty->flip.count >= TTY_FLIPBUF_SIZE) { tty_flip_buffer_push(tty); } tty_insert_flip_char(tty, data[i], 0); } /* gb - 2000/11/13 * Goes straight through instead of scheduling - if tty->low_latency is set. */ tty_flip_buffer_push(tty); bytes_in += urb->actual_length; } /* Continue trying to always read */ FILL_BULK_URB( port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, empeg_read_bulk_callback, port); port->read_urb->transfer_flags |= USB_QUEUE_BULK; result = usb_submit_urb(port->read_urb); if (result) err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); return; }