]> err.no Git - linux-2.6/blobdiff - drivers/usb/serial/aircable.c
Merge branch 'for-2.6.26' of master.kernel.org:/pub/scm/linux/kernel/git/jwboyer...
[linux-2.6] / drivers / usb / serial / aircable.c
index b675735bfbee559718a5fb650bf6dfe814a23a5d..db6f97a93c02c3b813e8feafd17ba6cb2acb1efc 100644 (file)
@@ -9,7 +9,7 @@
  * The device works as an standard CDC device, it has 2 interfaces, the first
  * one is for firmware access and the second is the serial one.
  * The protocol is very simply, there are two posibilities reading or writing.
- * When writting the first urb must have a Header that starts with 0x20 0x29 the
+ * When writing the first urb must have a Header that starts with 0x20 0x29 the
  * next two bytes must say how much data will be sended.
  * When reading the process is almost equal except that the header starts with
  * 0x00 0x20.
@@ -18,7 +18,7 @@
  * buffer: The First and Second byte is used for a Header, the Third and Fourth
  * tells the  device the amount of information the package holds.
  * Packages are 60 bytes long Header Stuff.
- * When writting to the device the first two bytes of the header are 0x20 0x29
+ * When writing to the device the first two bytes of the header are 0x20 0x29
  * When reading the bytes are 0x00 0x20, or 0x00 0x10, there is an strange
  * situation, when too much data arrives to the device because it sends the data
  * but with out the header. I will use a simply hack to override this situation,
@@ -147,7 +147,7 @@ static void serial_buf_free(struct circ_buf *cb)
  */
 static int serial_buf_data_avail(struct circ_buf *cb)
 {
-       return CIRC_CNT(cb->head,cb->tail,AIRCABLE_BUF_SIZE);
+       return CIRC_CNT(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
 }
 
 /*
@@ -171,7 +171,7 @@ static int serial_buf_put(struct circ_buf *cb, const char *buf, int count)
                cb->head = (cb->head + c) & (AIRCABLE_BUF_SIZE-1);
                buf += c;
                count -= c;
-               ret= c;
+               ret = c;
        }
        return ret;
 }
@@ -197,7 +197,7 @@ static int serial_buf_get(struct circ_buf *cb, char *buf, int count)
                cb->tail = (cb->tail + c) & (AIRCABLE_BUF_SIZE-1);
                buf += c;
                count -= c;
-               ret= c;
+               ret = c;
        }
        return ret;
 }
@@ -208,9 +208,9 @@ static void aircable_send(struct usb_serial_port *port)
 {
        int count, result;
        struct aircable_private *priv = usb_get_serial_port_data(port);
-       unsigned charbuf;
-       u16 *dbuf;
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       unsigned char *buf;
+       __le16 *dbuf;
+       dbg("%s - port %d", __func__, port->number);
        if (port->write_urb_busy)
                return;
 
@@ -220,23 +220,24 @@ static void aircable_send(struct usb_serial_port *port)
 
        buf = kzalloc(count + HCI_HEADER_LENGTH, GFP_ATOMIC);
        if (!buf) {
-               err("%s- kzalloc(%d) failed.", __FUNCTION__,
+               err("%s- kzalloc(%d) failed.", __func__,
                    count + HCI_HEADER_LENGTH);
                return;
        }
 
        buf[0] = TX_HEADER_0;
        buf[1] = TX_HEADER_1;
-       dbuf = (u16 *)&buf[2];
+       dbuf = (__le16 *)&buf[2];
        *dbuf = cpu_to_le16((u16)count);
-       serial_buf_get(priv->tx_buf,buf + HCI_HEADER_LENGTH, MAX_HCI_FRAMESIZE);
+       serial_buf_get(priv->tx_buf, buf + HCI_HEADER_LENGTH,
+                                                       MAX_HCI_FRAMESIZE);
 
        memcpy(port->write_urb->transfer_buffer, buf,
               count + HCI_HEADER_LENGTH);
 
        kfree(buf);
        port->write_urb_busy = 1;
-       usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
+       usb_serial_debug_data(debug, &port->dev, __func__,
                              count + HCI_HEADER_LENGTH,
                              port->write_urb->transfer_buffer);
        port->write_urb->transfer_buffer_length = count + HCI_HEADER_LENGTH;
@@ -246,7 +247,7 @@ static void aircable_send(struct usb_serial_port *port)
        if (result) {
                dev_err(&port->dev,
                        "%s - failed submitting write urb, error %d\n",
-                       __FUNCTION__, result);
+                       __func__, result);
                port->write_urb_busy = 0;
        }
 
@@ -261,7 +262,7 @@ static void aircable_read(struct work_struct *work)
        struct tty_struct *tty;
        unsigned char *data;
        int count;
-       if (priv->rx_flags & THROTTLED){
+       if (priv->rx_flags & THROTTLED) {
                if (priv->rx_flags & ACTUALLY_THROTTLED)
                        schedule_work(&priv->rx_work);
                return;
@@ -275,18 +276,18 @@ static void aircable_read(struct work_struct *work)
 
        if (!tty) {
                schedule_work(&priv->rx_work);
-               err("%s - No tty available", __FUNCTION__);
+               err("%s - No tty available", __func__);
                return ;
        }
 
        count = min(64, serial_buf_data_avail(priv->rx_buf));
 
        if (count <= 0)
-               return; //We have finished sending everything.
+               return; /* We have finished sending everything. */
 
        tty_prepare_flip_string(tty, &data, count);
-       if (!data){
-               err("%s- kzalloc(%d) failed.", __FUNCTION__, count);
+       if (!data) {
+               err("%s- kzalloc(%d) failed.", __func__, count);
                return;
        }
 
@@ -304,9 +305,10 @@ static void aircable_read(struct work_struct *work)
 static int aircable_probe(struct usb_serial *serial,
                          const struct usb_device_id *id)
 {
-       struct usb_host_interface *iface_desc = serial->interface->cur_altsetting;
+       struct usb_host_interface *iface_desc = serial->interface->
+                                                               cur_altsetting;
        struct usb_endpoint_descriptor *endpoint;
-       int num_bulk_out=0;
+       int num_bulk_out = 0;
        int i;
 
        for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
@@ -325,14 +327,14 @@ static int aircable_probe(struct usb_serial *serial,
        return 0;
 }
 
-static int aircable_attach (struct usb_serial *serial)
+static int aircable_attach(struct usb_serial *serial)
 {
        struct usb_serial_port *port = serial->port[0];
        struct aircable_private *priv;
 
        priv = kzalloc(sizeof(struct aircable_private), GFP_KERNEL);
-       if (!priv){
-               err("%s- kmalloc(%Zd) failed.", __FUNCTION__,
+       if (!priv) {
+               err("%s- kmalloc(%Zd) failed.", __func__,
                        sizeof(struct aircable_private));
                return -ENOMEM;
        }
@@ -366,7 +368,7 @@ static void aircable_shutdown(struct usb_serial *serial)
        struct usb_serial_port *port = serial->port[0];
        struct aircable_private *priv = usb_get_serial_port_data(port);
 
-       dbg("%s", __FUNCTION__);
+       dbg("%s", __func__);
 
        if (priv) {
                serial_buf_free(priv->tx_buf);
@@ -388,12 +390,12 @@ static int aircable_write(struct usb_serial_port *port,
        struct aircable_private *priv = usb_get_serial_port_data(port);
        int temp;
 
-       dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
+       dbg("%s - port %d, %d bytes", __func__, port->number, count);
 
-       usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, source);
+       usb_serial_debug_data(debug, &port->dev, __func__, count, source);
 
-       if (!count){
-               dbg("%s - write request of 0 bytes", __FUNCTION__);
+       if (!count) {
+               dbg("%s - write request of 0 bytes", __func__);
                return count;
        }
 
@@ -411,37 +413,38 @@ static int aircable_write(struct usb_serial_port *port,
 static void aircable_write_bulk_callback(struct urb *urb)
 {
        struct usb_serial_port *port = urb->context;
+       int status = urb->status;
        int result;
 
-       dbg("%s - urb->status: %d", __FUNCTION__ , urb->status);
+       dbg("%s - urb status: %d", __func__ , status);
 
        /* This has been taken from cypress_m8.c cypress_write_int_callback */
-       switch (urb->status) {
-               case 0:
-                       /* success */
-                       break;
-               case -ECONNRESET:
-               case -ENOENT:
-               case -ESHUTDOWN:
-                       /* this urb is terminated, clean up */
-                       dbg("%s - urb shutting down with status: %d",
-                           __FUNCTION__, urb->status);
-                       port->write_urb_busy = 0;
+       switch (status) {
+       case 0:
+               /* success */
+               break;
+       case -ECONNRESET:
+       case -ENOENT:
+       case -ESHUTDOWN:
+               /* this urb is terminated, clean up */
+               dbg("%s - urb shutting down with status: %d",
+                   __func__, status);
+               port->write_urb_busy = 0;
+               return;
+       default:
+               /* error in the urb, so we have to resubmit it */
+               dbg("%s - Overflow in write", __func__);
+               dbg("%s - nonzero write bulk status received: %d",
+                   __func__, status);
+               port->write_urb->transfer_buffer_length = 1;
+               port->write_urb->dev = port->serial->dev;
+               result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
+               if (result)
+                       dev_err(&urb->dev->dev,
+                           "%s - failed resubmitting write urb, error %d\n",
+                                                       __func__, result);
+               else
                        return;
-               default:
-                       /* error in the urb, so we have to resubmit it */
-                       dbg("%s - Overflow in write", __FUNCTION__);
-                       dbg("%s - nonzero write bulk status received: %d",
-                           __FUNCTION__, urb->status);
-                       port->write_urb->transfer_buffer_length = 1;
-                       port->write_urb->dev = port->serial->dev;
-                       result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
-                       if (result)
-                               dev_err(&urb->dev->dev,
-                                       "%s - failed resubmitting write urb, error %d\n",
-                                       __FUNCTION__, result);
-                       else
-                               return;
        }
 
        port->write_urb_busy = 0;
@@ -457,38 +460,39 @@ static void aircable_read_bulk_callback(struct urb *urb)
        unsigned long no_packages, remaining, package_length, i;
        int result, shift = 0;
        unsigned char *temp;
+       int status = urb->status;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
-       if (urb->status) {
-               dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+       if (status) {
+               dbg("%s - urb status = %d", __func__, status);
                if (!port->open_count) {
-                       dbg("%s - port is closed, exiting.", __FUNCTION__);
+                       dbg("%s - port is closed, exiting.", __func__);
                        return;
                }
-               if (urb->status == -EPROTO) {
+               if (status == -EPROTO) {
                        dbg("%s - caught -EPROTO, resubmitting the urb",
-                           __FUNCTION__);
+                           __func__);
                        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,
-                                         aircable_read_bulk_callback, port);
+                               usb_rcvbulkpipe(port->serial->dev,
+                                       port->bulk_in_endpointAddress),
+                               port->read_urb->transfer_buffer,
+                               port->read_urb->transfer_buffer_length,
+                               aircable_read_bulk_callback, port);
 
                        result = usb_submit_urb(urb, GFP_ATOMIC);
                        if (result)
                                dev_err(&urb->dev->dev,
                                        "%s - failed resubmitting read urb, error %d\n",
-                                       __FUNCTION__, result);
+                                       __func__, result);
                        return;
                }
-               dbg("%s - unable to handle the error, exiting.", __FUNCTION__);
+               dbg("%s - unable to handle the error, exiting.", __func__);
                return;
        }
 
-       usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
-                               urb->actual_length,urb->transfer_buffer);
+       usb_serial_debug_data(debug, &port->dev, __func__,
+                               urb->actual_length, urb->transfer_buffer);
 
        tty = port->tty;
        if (tty && urb->actual_length) {
@@ -505,9 +509,9 @@ static void aircable_read_bulk_callback(struct urb *urb)
                        no_packages = urb->actual_length / (HCI_COMPLETE_FRAME);
 
                        if (urb->actual_length % HCI_COMPLETE_FRAME != 0)
-                               no_packages+=1;
+                               no_packages++;
 
-                       for (i = 0; i < no_packages ;i++) {
+                       for (i = 0; i < no_packagesi++) {
                                if (remaining > (HCI_COMPLETE_FRAME))
                                        package_length = HCI_COMPLETE_FRAME;
                                else
@@ -527,7 +531,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
        if (port->open_count) {
                usb_fill_bulk_urb(port->read_urb, port->serial->dev,
                                  usb_rcvbulkpipe(port->serial->dev,
-                                                 port->bulk_in_endpointAddress),
+                                         port->bulk_in_endpointAddress),
                                  port->read_urb->transfer_buffer,
                                  port->read_urb->transfer_buffer_length,
                                  aircable_read_bulk_callback, port);
@@ -536,7 +540,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
                if (result)
                        dev_err(&urb->dev->dev,
                                "%s - failed resubmitting read urb, error %d\n",
-                               __FUNCTION__, result);
+                               __func__, result);
        }
 
        return;
@@ -548,7 +552,7 @@ static void aircable_throttle(struct usb_serial_port *port)
        struct aircable_private *priv = usb_get_serial_port_data(port);
        unsigned long flags;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        spin_lock_irqsave(&priv->rx_lock, flags);
        priv->rx_flags |= THROTTLED;
@@ -562,7 +566,7 @@ static void aircable_unthrottle(struct usb_serial_port *port)
        int actually_throttled;
        unsigned long flags;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        spin_lock_irqsave(&priv->rx_lock, flags);
        actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
@@ -600,7 +604,7 @@ static struct usb_serial_driver aircable_device = {
        .unthrottle =           aircable_unthrottle,
 };
 
-static int __init aircable_init (void)
+static int __init aircable_init(void)
 {
        int retval;
        retval = usb_serial_register(&aircable_device);
@@ -617,7 +621,7 @@ failed_usb_register:
        return retval;
 }
 
-static void __exit aircable_exit (void)
+static void __exit aircable_exit(void)
 {
        usb_deregister(&aircable_driver);
        usb_serial_deregister(&aircable_device);