Commit f4a4cbb2 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

USB: ir-usb: reimplement using generic framework

Compile-only tested.
Signed-off-by: default avatarJohan Hovold <jhovold@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent df66e8a2
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* *
* Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com) * Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com)
* Copyright (C) 2002 Gary Brubaker (xavyer@ix.netcom.com) * Copyright (C) 2002 Gary Brubaker (xavyer@ix.netcom.com)
* Copyright (C) 2010 Johan Hovold (jhovold@gmail.com)
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -72,8 +73,8 @@ ...@@ -72,8 +73,8 @@
/* /*
* Version Information * Version Information
*/ */
#define DRIVER_VERSION "v0.4" #define DRIVER_VERSION "v0.5"
#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>" #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Johan Hovold <jhovold@gmail.com>"
#define DRIVER_DESC "USB IR Dongle driver" #define DRIVER_DESC "USB IR Dongle driver"
static int debug; static int debug;
...@@ -87,11 +88,9 @@ static int xbof = -1; ...@@ -87,11 +88,9 @@ static int xbof = -1;
static int ir_startup (struct usb_serial *serial); static int ir_startup (struct usb_serial *serial);
static int ir_open(struct tty_struct *tty, struct usb_serial_port *port); static int ir_open(struct tty_struct *tty, struct usb_serial_port *port);
static void ir_close(struct usb_serial_port *port); static int ir_prepare_write_buffer(struct usb_serial_port *port,
static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, void *dest, size_t size);
const unsigned char *buf, int count); static void ir_process_read_urb(struct urb *urb);
static void ir_write_bulk_callback (struct urb *urb);
static void ir_read_bulk_callback (struct urb *urb);
static void ir_set_termios(struct tty_struct *tty, static void ir_set_termios(struct tty_struct *tty,
struct usb_serial_port *port, struct ktermios *old_termios); struct usb_serial_port *port, struct ktermios *old_termios);
...@@ -130,10 +129,8 @@ static struct usb_serial_driver ir_device = { ...@@ -130,10 +129,8 @@ static struct usb_serial_driver ir_device = {
.set_termios = ir_set_termios, .set_termios = ir_set_termios,
.attach = ir_startup, .attach = ir_startup,
.open = ir_open, .open = ir_open,
.close = ir_close, .prepare_write_buffer = ir_prepare_write_buffer,
.write = ir_write, .process_read_urb = ir_process_read_urb,
.write_bulk_callback = ir_write_bulk_callback,
.read_bulk_callback = ir_read_bulk_callback,
}; };
static inline void irda_usb_dump_class_desc(struct usb_irda_cs_descriptor *desc) static inline void irda_usb_dump_class_desc(struct usb_irda_cs_descriptor *desc)
...@@ -198,7 +195,6 @@ irda_usb_find_class_desc(struct usb_device *dev, unsigned int ifnum) ...@@ -198,7 +195,6 @@ irda_usb_find_class_desc(struct usb_device *dev, unsigned int ifnum)
return NULL; return NULL;
} }
static u8 ir_xbof_change(u8 xbof) static u8 ir_xbof_change(u8 xbof)
{ {
u8 result; u8 result;
...@@ -237,7 +233,6 @@ static u8 ir_xbof_change(u8 xbof) ...@@ -237,7 +233,6 @@ static u8 ir_xbof_change(u8 xbof)
return(result); return(result);
} }
static int ir_startup(struct usb_serial *serial) static int ir_startup(struct usb_serial *serial)
{ {
struct usb_irda_cs_descriptor *irda_desc; struct usb_irda_cs_descriptor *irda_desc;
...@@ -297,60 +292,21 @@ static int ir_startup(struct usb_serial *serial) ...@@ -297,60 +292,21 @@ static int ir_startup(struct usb_serial *serial)
static int ir_open(struct tty_struct *tty, struct usb_serial_port *port) static int ir_open(struct tty_struct *tty, struct usb_serial_port *port)
{ {
int result = 0; int i;
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
/* Start reading from the device */ for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
usb_fill_bulk_urb( port->write_urbs[i]->transfer_flags = URB_ZERO_PACKET;
port->read_urb,
port->serial->dev,
usb_rcvbulkpipe(port->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, GFP_KERNEL);
if (result)
dev_err(&port->dev,
"%s - failed submitting read urb, error %d\n",
__func__, result);
return result;
}
static void ir_close(struct usb_serial_port *port)
{
dbg("%s - port %d", __func__, port->number);
/* shutdown our bulk read */ /* Start reading from the device */
usb_kill_urb(port->read_urb); return usb_serial_generic_open(tty, port);
} }
static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, static int ir_prepare_write_buffer(struct usb_serial_port *port,
const unsigned char *buf, int count) void *dest, size_t size)
{ {
unsigned char *transfer_buffer; unsigned char *buf = dest;
int result;
int transfer_size;
dbg("%s - port = %d, count = %d", __func__, port->number, count);
if (count == 0)
return 0;
spin_lock_bh(&port->lock);
if (port->write_urb_busy) {
spin_unlock_bh(&port->lock);
dbg("%s - already writing", __func__);
return 0;
}
port->write_urb_busy = 1;
spin_unlock_bh(&port->lock);
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 * The first byte of the packet we send to the device contains an
...@@ -359,114 +315,37 @@ static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, ...@@ -359,114 +315,37 @@ static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
* *
* See section 5.4.2.2 of the USB IrDA spec. * See section 5.4.2.2 of the USB IrDA spec.
*/ */
*transfer_buffer = ir_xbof | ir_baud; *buf = ir_xbof | ir_baud;
++transfer_buffer;
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 = URB_ZERO_PACKET; return kfifo_out_locked(&port->write_fifo, buf + 1, size - 1,
&port->lock);
result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
if (result) {
port->write_urb_busy = 0;
dev_err(&port->dev,
"%s - failed submitting write urb, error %d\n",
__func__, result);
} else
result = transfer_size;
return result;
} }
static void ir_write_bulk_callback(struct urb *urb) static void ir_process_read_urb(struct urb *urb)
{ {
struct usb_serial_port *port = urb->context; struct usb_serial_port *port = urb->context;
int status = urb->status; unsigned char *data = urb->transfer_buffer;
struct tty_struct *tty;
dbg("%s - port %d", __func__, port->number);
port->write_urb_busy = 0; if (!urb->actual_length)
if (status) {
dbg("%s - nonzero write bulk status received: %d",
__func__, status);
return; return;
} /*
* The first byte of the packet we get from the device
usb_serial_debug_data( * contains a busy indicator and baud rate change.
debug, * See section 5.4.1.2 of the USB IrDA spec.
&port->dev, */
__func__, if (*data & 0x0f)
urb->actual_length, ir_baud = *data & 0x0f;
urb->transfer_buffer);
usb_serial_port_softint(port);
}
static void ir_read_bulk_callback(struct urb *urb)
{
struct usb_serial_port *port = urb->context;
struct tty_struct *tty;
unsigned char *data = urb->transfer_buffer;
int result;
int status = urb->status;
dbg("%s - port %d", __func__, port->number); if (urb->actual_length == 1)
return;
switch (status) { tty = tty_port_tty_get(&port->port);
case 0: /* Successful */ if (!tty)
/* return;
* The first byte of the packet we get from the device tty_insert_flip_string(tty, data + 1, urb->actual_length - 1);
* contains a busy indicator and baud rate change. tty_flip_buffer_push(tty);
* See section 5.4.1.2 of the USB IrDA spec. tty_kref_put(tty);
*/
if ((*data & 0x0f) > 0)
ir_baud = *data & 0x0f;
usb_serial_debug_data(debug, &port->dev, __func__,
urb->actual_length, data);
tty = tty_port_tty_get(&port->port);
tty_insert_flip_string(tty, data+1, urb->actual_length - 1);
tty_flip_buffer_push(tty);
tty_kref_put(tty);
/*
* 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,
port->serial->dev,
usb_rcvbulkpipe(port->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, GFP_ATOMIC);
if (result)
dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
__func__, result);
break ;
default:
dbg("%s - nonzero read bulk status received: %d",
__func__, status);
break ;
}
return;
} }
static void ir_set_termios_callback(struct urb *urb) static void ir_set_termios_callback(struct urb *urb)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment