]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/usb/serial/cyberjack.c
usb_serial: API all change
[linux-2.6-omap-h63xx.git] / drivers / usb / serial / cyberjack.c
index 4167753ed31fc3efa401bb1366c4e1991e04358b..546178ea6f2d7da059c600ed715186ff2a779ce2 100644 (file)
@@ -57,15 +57,18 @@ static int debug;
 #define CYBERJACK_PRODUCT_ID   0x0100
 
 /* Function prototypes */
-static int cyberjack_startup (struct usb_serial *serial);
-static void cyberjack_shutdown (struct usb_serial *serial);
-static int  cyberjack_open (struct usb_serial_port *port, struct file *filp);
-static void cyberjack_close (struct usb_serial_port *port, struct file *filp);
-static int cyberjack_write (struct usb_serial_port *port, const unsigned char *buf, int count);
-static int cyberjack_write_room( struct usb_serial_port *port );
-static void cyberjack_read_int_callback (struct urb *urb);
-static void cyberjack_read_bulk_callback (struct urb *urb);
-static void cyberjack_write_bulk_callback (struct urb *urb);
+static int cyberjack_startup(struct usb_serial *serial);
+static void cyberjack_shutdown(struct usb_serial *serial);
+static int  cyberjack_open(struct tty_struct *tty,
+                       struct usb_serial_port *port, struct file *filp);
+static void cyberjack_close(struct tty_struct *tty,
+                       struct usb_serial_port *port, struct file *filp);
+static int cyberjack_write(struct tty_struct *tty,
+       struct usb_serial_port *port, const unsigned char *buf, int count);
+static int cyberjack_write_room( struct tty_struct *tty);
+static void cyberjack_read_int_callback(struct urb *urb);
+static void cyberjack_read_bulk_callback(struct urb *urb);
+static void cyberjack_write_bulk_callback(struct urb *urb);
 
 static struct usb_device_id id_table [] = {
        { USB_DEVICE(CYBERJACK_VENDOR_ID, CYBERJACK_PRODUCT_ID) },
@@ -90,9 +93,6 @@ static struct usb_serial_driver cyberjack_device = {
        .description =          "Reiner SCT Cyberjack USB card reader",
        .usb_driver =           &cyberjack_driver,
        .id_table =             id_table,
-       .num_interrupt_in =     1,
-       .num_bulk_in =          1,
-       .num_bulk_out =         1,
        .num_ports =            1,
        .attach =               cyberjack_startup,
        .shutdown =             cyberjack_shutdown,
@@ -114,12 +114,12 @@ struct cyberjack_private {
 };
 
 /* do some startup allocations not currently performed by usb_serial_probe() */
-static int cyberjack_startup (struct usb_serial *serial)
+static int cyberjack_startup(struct usb_serial *serial)
 {
        struct cyberjack_private *priv;
        int i;
 
-       dbg("%s", __FUNCTION__);
+       dbg("%s", __func__);
 
        /* allocate the private data structure */
        priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL);
@@ -142,19 +142,19 @@ static int cyberjack_startup (struct usb_serial *serial)
                                        GFP_KERNEL);
                if (result)
                        err(" usb_submit_urb(read int) failed");
-               dbg("%s - usb_submit_urb(int urb)", __FUNCTION__);
+               dbg("%s - usb_submit_urb(int urb)", __func__);
        }
 
        return( 0 );
 }
 
-static void cyberjack_shutdown (struct usb_serial *serial)
+static void cyberjack_shutdown(struct usb_serial *serial)
 {
        int i;
        
-       dbg("%s", __FUNCTION__);
+       dbg("%s", __func__);
 
-       for (i=0; i < serial->num_ports; ++i) {
+       for (i = 0; i < serial->num_ports; ++i) {
                usb_kill_urb(serial->port[i]->interrupt_in_urb);
                /* My special items, the standard routines free my urbs */
                kfree(usb_get_serial_port_data(serial->port[i]));
@@ -162,22 +162,24 @@ static void cyberjack_shutdown (struct usb_serial *serial)
        }
 }
        
-static int  cyberjack_open (struct usb_serial_port *port, struct file *filp)
+static int  cyberjack_open(struct tty_struct *tty,
+                       struct usb_serial_port *port, struct file *filp)
 {
        struct cyberjack_private *priv;
        unsigned long flags;
        int result = 0;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
-       dbg("%s - usb_clear_halt", __FUNCTION__ );
+       dbg("%s - usb_clear_halt", __func__ );
        usb_clear_halt(port->serial->dev, port->write_urb->pipe);
 
        /* 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 (tty)
+               tty->low_latency = 1;
 
        priv = usb_get_serial_port_data(port);
        spin_lock_irqsave(&priv->lock, flags);
@@ -189,9 +191,10 @@ static int  cyberjack_open (struct usb_serial_port *port, struct file *filp)
        return result;
 }
 
-static void cyberjack_close (struct usb_serial_port *port, struct file *filp)
+static void cyberjack_close(struct tty_struct *tty,
+                       struct usb_serial_port *port, struct file *filp)
 {
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        if (port->serial->dev) {
                /* shutdown any bulk reads that might be going on */
@@ -200,7 +203,8 @@ static void cyberjack_close (struct usb_serial_port *port, struct file *filp)
        }
 }
 
-static int cyberjack_write (struct usb_serial_port *port, const unsigned char *buf, int count)
+static int cyberjack_write(struct tty_struct *tty,
+       struct usb_serial_port *port, const unsigned char *buf, int count)
 {
        struct usb_serial *serial = port->serial;
        struct cyberjack_private *priv = usb_get_serial_port_data(port);
@@ -208,17 +212,17 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
        int result;
        int wrexpected;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        if (count == 0) {
-               dbg("%s - write request of 0 bytes", __FUNCTION__);
-               return (0);
+               dbg("%s - write request of 0 bytes", __func__);
+               return 0;
        }
 
        spin_lock_bh(&port->lock);
        if (port->write_urb_busy) {
                spin_unlock_bh(&port->lock);
-               dbg("%s - already writing", __FUNCTION__);
+               dbg("%s - already writing", __func__);
                return 0;
        }
        port->write_urb_busy = 1;
@@ -226,24 +230,24 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
 
        spin_lock_irqsave(&priv->lock, flags);
 
-       if( (count+priv->wrfilled)>sizeof(priv->wrbuf) ) {
+       if( (count+priv->wrfilled) > sizeof(priv->wrbuf) ) {
                /* To much data for buffer. Reset buffer. */
-               priv->wrfilled=0;
-               spin_unlock_irqrestore(&priv->lock, flags);
+               priv->wrfilled = 0;
                port->write_urb_busy = 0;
-               return (0);
+               spin_unlock_irqrestore(&priv->lock, flags);
+               return 0;
        }
 
        /* Copy data */
        memcpy (priv->wrbuf+priv->wrfilled, buf, count);
 
-       usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count,
+       usb_serial_debug_data(debug, &port->dev, __func__, count,
                priv->wrbuf+priv->wrfilled);
        priv->wrfilled += count;
 
        if( priv->wrfilled >= 3 ) {
                wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
-               dbg("%s - expected data: %d", __FUNCTION__, wrexpected);
+               dbg("%s - expected data: %d", __func__, wrexpected);
        } else {
                wrexpected = sizeof(priv->wrbuf);
        }
@@ -252,7 +256,7 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
                /* We have enough data to begin transmission */
                int length;
 
-               dbg("%s - transmitting data (frame 1)", __FUNCTION__);
+               dbg("%s - transmitting data (frame 1)", __func__);
                length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected;
 
                memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length );
@@ -270,23 +274,23 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
                /* send the data out the bulk port */
                result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
                if (result) {
-                       err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
+                       err("%s - failed submitting write urb, error %d", __func__, result);
                        /* Throw away data. No better idea what to do with it. */
-                       priv->wrfilled=0;
-                       priv->wrsent=0;
+                       priv->wrfilled = 0;
+                       priv->wrsent = 0;
                        spin_unlock_irqrestore(&priv->lock, flags);
                        port->write_urb_busy = 0;
                        return 0;
                }
 
-               dbg("%s - priv->wrsent=%d", __FUNCTION__,priv->wrsent);
-               dbg("%s - priv->wrfilled=%d", __FUNCTION__,priv->wrfilled);
+               dbg("%s - priv->wrsent=%d", __func__,priv->wrsent);
+               dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled);
 
                if( priv->wrsent>=priv->wrfilled ) {
-                       dbg("%s - buffer cleaned", __FUNCTION__);
+                       dbg("%s - buffer cleaned", __func__);
                        memset( priv->wrbuf, 0, sizeof(priv->wrbuf) );
-                       priv->wrfilled=0;
-                       priv->wrsent=0;
+                       priv->wrfilled = 0;
+                       priv->wrsent = 0;
                }
        }
 
@@ -295,30 +299,31 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
        return (count);
 } 
 
-static int cyberjack_write_room( struct usb_serial_port *port )
+static int cyberjack_write_room(struct tty_struct *tty)
 {
+       /* FIXME: .... */
        return CYBERJACK_LOCAL_BUF_SIZE;
 }
 
-static void cyberjack_read_int_callback( struct urb *urb )
+static void cyberjack_read_int_callback(struct urb *urb)
 {
-       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       struct usb_serial_port *port = urb->context;
        struct cyberjack_private *priv = usb_get_serial_port_data(port);
        unsigned char *data = urb->transfer_buffer;
+       int status = urb->status;
        int result;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        /* the urb might have been killed. */
-       if (urb->status)
+       if (status)
                return;
 
-       usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
+       usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
 
        /* React only to interrupts signaling a bulk_in transfer */
-       if( (urb->actual_length==4) && (data[0]==0x01) ) {
+       if( (urb->actual_length == 4) && (data[0] == 0x01) ) {
                short old_rdtodo;
-               int result;
 
                /* This is a announcement of coming bulk_ins. */
                unsigned short size = ((unsigned short)data[3]<<8)+data[2]+3;
@@ -336,7 +341,7 @@ static void cyberjack_read_int_callback( struct urb *urb )
                /* "+=" is probably more fault tollerant than "=" */
                priv->rdtodo += size;
 
-               dbg("%s - rdtodo: %d", __FUNCTION__, priv->rdtodo);
+               dbg("%s - rdtodo: %d", __func__, priv->rdtodo);
 
                spin_unlock(&priv->lock);
 
@@ -344,8 +349,8 @@ static void cyberjack_read_int_callback( struct urb *urb )
                        port->read_urb->dev = port->serial->dev;
                        result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
                        if( result )
-                               err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
-                       dbg("%s - usb_submit_urb(read urb)", __FUNCTION__);
+                               err("%s - failed resubmitting read urb, error %d", __func__, result);
+                       dbg("%s - usb_submit_urb(read urb)", __func__);
                }
        }
 
@@ -354,29 +359,31 @@ resubmit:
        result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
        if (result)
                err(" usb_submit_urb(read int) failed");
-       dbg("%s - usb_submit_urb(int urb)", __FUNCTION__);
+       dbg("%s - usb_submit_urb(int urb)", __func__);
 }
 
-static void cyberjack_read_bulk_callback (struct urb *urb)
+static void cyberjack_read_bulk_callback(struct urb *urb)
 {
-       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       struct usb_serial_port *port = urb->context;
        struct cyberjack_private *priv = usb_get_serial_port_data(port);
        struct tty_struct *tty;
        unsigned char *data = urb->transfer_buffer;
        short todo;
        int result;
+       int status = urb->status;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
-       
-       usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
-       if (urb->status) {
-               dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
+       dbg("%s - port %d", __func__, port->number);
+
+       usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
+       if (status) {
+               dbg("%s - nonzero read bulk status received: %d",
+                   __func__, status);
                return;
        }
 
-       tty = port->tty;
+       tty = port->port.tty;
        if (!tty) {
-               dbg("%s - ignoring since device not open\n", __FUNCTION__);
+               dbg("%s - ignoring since device not open\n", __func__);
                return;
        }
        if (urb->actual_length) {
@@ -395,28 +402,30 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
 
        spin_unlock(&priv->lock);
 
-       dbg("%s - rdtodo: %d", __FUNCTION__, todo);
+       dbg("%s - rdtodo: %d", __func__, todo);
 
        /* Continue to read if we have still urbs to do. */
        if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) {
                port->read_urb->dev = port->serial->dev;
                result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
                if (result)
-                       err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
-               dbg("%s - usb_submit_urb(read urb)", __FUNCTION__);
+                       err("%s - failed resubmitting read urb, error %d", __func__, result);
+               dbg("%s - usb_submit_urb(read urb)", __func__);
        }
 }
 
-static void cyberjack_write_bulk_callback (struct urb *urb)
+static void cyberjack_write_bulk_callback(struct urb *urb)
 {
-       struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
+       struct usb_serial_port *port = urb->context;
        struct cyberjack_private *priv = usb_get_serial_port_data(port);
+       int status = urb->status;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        port->write_urb_busy = 0;
-       if (urb->status) {
-               dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
+       if (status) {
+               dbg("%s - nonzero write bulk status received: %d",
+                   __func__, status);
                return;
        }
 
@@ -426,7 +435,7 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
        if( priv->wrfilled ) {
                int length, blksize, result;
 
-               dbg("%s - transmitting data (frame n)", __FUNCTION__);
+               dbg("%s - transmitting data (frame n)", __func__);
 
                length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
                        port->bulk_out_size : (priv->wrfilled - priv->wrsent);
@@ -447,23 +456,23 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
                /* send the data out the bulk port */
                result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
                if (result) {
-                       err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
+                       err("%s - failed submitting write urb, error %d", __func__, result);
                        /* Throw away data. No better idea what to do with it. */
-                       priv->wrfilled=0;
-                       priv->wrsent=0;
+                       priv->wrfilled = 0;
+                       priv->wrsent = 0;
                        goto exit;
                }
 
-               dbg("%s - priv->wrsent=%d", __FUNCTION__,priv->wrsent);
-               dbg("%s - priv->wrfilled=%d", __FUNCTION__,priv->wrfilled);
+               dbg("%s - priv->wrsent=%d", __func__,priv->wrsent);
+               dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled);
 
                blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
 
                if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) {
-                       dbg("%s - buffer cleaned", __FUNCTION__);
+                       dbg("%s - buffer cleaned", __func__);
                        memset( priv->wrbuf, 0, sizeof(priv->wrbuf) );
-                       priv->wrfilled=0;
-                       priv->wrsent=0;
+                       priv->wrfilled = 0;
+                       priv->wrsent = 0;
                }
        }