fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / usb / serial / kl5kusb105.c
index c5207d1..5c4b06a 100644 (file)
@@ -45,7 +45,6 @@
  */
 
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/init.h>
@@ -56,7 +55,7 @@
 #include <linux/module.h>
 #include <asm/uaccess.h>
 #include <linux/usb.h>
-#include "usb-serial.h"
+#include <linux/usb/serial.h>
 #include "kl5kusb105.h"
 
 static int debug;
@@ -79,20 +78,15 @@ static int  klsi_105_open            (struct usb_serial_port *port,
 static void klsi_105_close              (struct usb_serial_port *port,
                                          struct file *filp);
 static int  klsi_105_write              (struct usb_serial_port *port,
-                                         int from_user,
                                          const unsigned char *buf,
                                          int count);
-static void klsi_105_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
+static void klsi_105_write_bulk_callback (struct urb *urb);
 static int  klsi_105_chars_in_buffer     (struct usb_serial_port *port);
 static int  klsi_105_write_room          (struct usb_serial_port *port);
 
-static void klsi_105_read_bulk_callback  (struct urb *urb, struct pt_regs *regs);
+static void klsi_105_read_bulk_callback  (struct urb *urb);
 static void klsi_105_set_termios         (struct usb_serial_port *port,
-                                         struct termios * old);
-static int  klsi_105_ioctl              (struct usb_serial_port *port,
-                                         struct file * file,
-                                         unsigned int cmd,
-                                         unsigned long arg);
+                                         struct ktermios *old);
 static void klsi_105_throttle           (struct usb_serial_port *port);
 static void klsi_105_unthrottle                 (struct usb_serial_port *port);
 /*
@@ -117,17 +111,19 @@ static struct usb_device_id id_table [] = {
 MODULE_DEVICE_TABLE (usb, id_table);
 
 static struct usb_driver kl5kusb105d_driver = {
-       .owner =        THIS_MODULE,
        .name =         "kl5kusb105d",
        .probe =        usb_serial_probe,
        .disconnect =   usb_serial_disconnect,
        .id_table =     id_table,
+       .no_dynamic_id =        1,
 };
 
-static struct usb_serial_device_type kl5kusb105d_device = {
-       .owner =             THIS_MODULE,
-       .name =              "KL5KUSB105D / PalmConnect",
-       .short_name =        "kl5kusb105d",
+static struct usb_serial_driver kl5kusb105d_device = {
+       .driver = {
+               .owner =        THIS_MODULE,
+               .name =         "kl5kusb105d",
+       },
+       .description =       "KL5KUSB105D / PalmConnect",
        .id_table =          id_table,
        .num_interrupt_in =  1,
        .num_bulk_in =       1,
@@ -140,7 +136,6 @@ static struct usb_serial_device_type kl5kusb105d_device = {
        .chars_in_buffer =   klsi_105_chars_in_buffer,
        .write_room =        klsi_105_write_room,
        .read_bulk_callback =klsi_105_read_bulk_callback,
-       .ioctl =             klsi_105_ioctl,
        .set_termios =       klsi_105_set_termios,
        /*.break_ctl =       klsi_105_break_ctl,*/
        .tiocmget =          klsi_105_tiocmget,
@@ -164,7 +159,7 @@ struct klsi_105_port_settings {
 #define URB_TRANSFER_BUFFER_SIZE       64
 struct klsi_105_private {
        struct klsi_105_port_settings   cfg;
-       struct termios                  termios;
+       struct ktermios                 termios;
        unsigned long                   line_state; /* modem line settings */
        /* write pool */
        struct urb *                    write_urb_pool[NUM_URBS];
@@ -179,7 +174,7 @@ struct klsi_105_private {
  */
 
 
-#define KLSI_TIMEOUT    (HZ * 5 ) /* default urb timeout */
+#define KLSI_TIMEOUT    5000 /* default urb timeout */
 
 static int klsi_105_chg_port_settings(struct usb_serial_port *port,
                                      struct klsi_105_port_settings *settings)
@@ -237,7 +232,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
                             0, /* value */
                             0, /* index */
                             status_buf, KLSI_STATUSBUF_LEN,
-                            10*HZ
+                            10000
                             );
        if (rc < 0)
                err("Reading line status failed (error = %d)", rc);
@@ -336,14 +331,13 @@ static void klsi_105_shutdown (struct usb_serial *serial)
                        for (j = 0; j < NUM_URBS; j++) {
                                if (write_urbs[j]) {
                                        /* FIXME - uncomment the following
-                                        * usb_unlink_urb call when the host
+                                        * usb_kill_urb call when the host
                                         * controllers get fixed to set
                                         * urb->dev = NULL after the urb is
                                         * finished.  Otherwise this call
                                         * oopses. */
-                                       /* usb_unlink_urb(write_urbs[j]); */
-                                       if (write_urbs[j]->transfer_buffer)
-                                                   kfree(write_urbs[j]->transfer_buffer);
+                                       /* usb_kill_urb(write_urbs[j]); */
+                                       kfree(write_urbs[j]->transfer_buffer);
                                        usb_free_urb (write_urbs[j]);
                                }
                        }
@@ -467,12 +461,12 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
                    err("Disabling read failed (error = %d)", rc);
 
        /* shutdown our bulk reads and writes */
-       usb_unlink_urb (port->write_urb);
-       usb_unlink_urb (port->read_urb);
+       usb_kill_urb(port->write_urb);
+       usb_kill_urb(port->read_urb);
        /* unlink our write pool */
        /* FIXME */
        /* wgg - do I need this? I think so. */
-       usb_unlink_urb (port->interrupt_in_urb);
+       usb_kill_urb(port->interrupt_in_urb);
        info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out);
 } /* klsi_105_close */
 
@@ -484,7 +478,7 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
 #define KLSI_105_DATA_OFFSET   2   /* in the bulk urb data block */
 
 
-static int klsi_105_write (struct usb_serial_port *port, int from_user,
+static int klsi_105_write (struct usb_serial_port *port,
                           const unsigned char *buf, int count)
 {
        struct klsi_105_private *priv = usb_get_serial_port_data(port);
@@ -525,15 +519,7 @@ static int klsi_105_write (struct usb_serial_port *port, int from_user,
                size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
                size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET);
 
-               if (from_user) {
-                       if (copy_from_user(urb->transfer_buffer
-                                          + KLSI_105_DATA_OFFSET, buf, size)) {
-                               return -EFAULT;
-                       }
-               } else {
-                       memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET,
-                               buf, size);
-               }
+               memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
 
                /* write payload size into transfer buffer */
                ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
@@ -565,7 +551,7 @@ exit:
        return bytes_sent;      /* that's how much we wrote */
 } /* klsi_105_write */
 
-static void klsi_105_write_bulk_callback ( struct urb *urb, struct pt_regs *regs)
+static void klsi_105_write_bulk_callback ( struct urb *urb)
 {
        struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
 
@@ -577,8 +563,7 @@ static void klsi_105_write_bulk_callback ( struct urb *urb, struct pt_regs *regs
                return;
        }
 
-       /* from generic_write_bulk_callback */
-       schedule_work(&port->work);
+       usb_serial_port_softint(port);
 } /* klsi_105_write_bulk_completion_callback */
 
 
@@ -626,7 +611,7 @@ static int klsi_105_write_room (struct usb_serial_port *port)
 
 
 
-static void klsi_105_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
+static void klsi_105_read_bulk_callback (struct urb *urb)
 {
        struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
        struct klsi_105_private *priv = usb_get_serial_port_data(port);
@@ -656,7 +641,6 @@ static void klsi_105_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
                usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
                                      urb->actual_length, data);
        } else {
-               int i;
                int bytes_sent = ((__u8 *) data)[0] +
                                 ((unsigned int) ((__u8 *) data)[1] << 8);
                tty = port->tty;
@@ -677,16 +661,8 @@ static void klsi_105_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
                        bytes_sent = urb->actual_length - 2;
                }
 
-               for (i = 2; i < 2+bytes_sent; 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, ((__u8*) data)[i], 0);
-               }
+               tty_buffer_request_room(tty, bytes_sent);
+               tty_insert_flip_string(tty, data + 2, bytes_sent);
                tty_flip_buffer_push(tty);
 
                /* again lockless, but debug info only */
@@ -707,7 +683,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
 
 
 static void klsi_105_set_termios (struct usb_serial_port *port,
-                                 struct termios *old_termios)
+                                 struct ktermios *old_termios)
 {
        struct klsi_105_private *priv = usb_get_serial_port_data(port);
        unsigned int iflag = port->tty->termios->c_iflag;
@@ -782,9 +758,11 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
                switch (cflag & CSIZE) {
                case CS5:
                        dbg("%s - 5 bits/byte not supported", __FUNCTION__);
+                       spin_unlock_irqrestore (&priv->lock, flags);
                        return ;
                case CS6:
                        dbg("%s - 6 bits/byte not supported", __FUNCTION__);
+                       spin_unlock_irqrestore (&priv->lock, flags);
                        return ;
                case CS7:
                        priv->cfg.databits = kl5kusb105a_dtb_7;
@@ -916,85 +894,11 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
 */
        return retval;
 }
-                                       
-static int klsi_105_ioctl (struct usb_serial_port *port, struct file * file,
-                          unsigned int cmd, unsigned long arg)
-{
-       struct klsi_105_private *priv = usb_get_serial_port_data(port);
-       void __user *user_arg = (void __user *)arg;
-       
-       dbg("%scmd=0x%x", __FUNCTION__, cmd);
-
-       /* Based on code from acm.c and others */
-       switch (cmd) {
-       case TIOCMIWAIT:
-               /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
-               /* TODO */
-               dbg("%s - TIOCMIWAIT not handled", __FUNCTION__);
-               return -ENOIOCTLCMD;
-
-       case TIOCGICOUNT:
-               /* return count of modemline transitions */
-               /* TODO */
-               dbg("%s - TIOCGICOUNT not handled", __FUNCTION__);
-               return -ENOIOCTLCMD;
-       case TCGETS: {
-            /* return current info to caller */
-            int retval;
-
-            dbg("%s - TCGETS data faked/incomplete", __FUNCTION__);
-
-            retval = verify_area(VERIFY_WRITE, user_arg,
-                                 sizeof(struct termios));
-            if (retval)
-                        return retval;
-
-            if (kernel_termios_to_user_termios((struct termios __user *)arg,
-                                               &priv->termios))
-                    return -EFAULT;
-            return(0);
-            }
-       case TCSETS: {
-               /* set port termios to the one given by the user */
-               int retval;
-
-               dbg("%s - TCSETS not handled", __FUNCTION__);
-
-               retval = verify_area(VERIFY_READ, user_arg,
-                                    sizeof(struct termios));
-               if (retval)
-                           return retval;
-
-               if (user_termios_to_kernel_termios(&priv->termios,
-                                                 (struct termios __user *)arg))
-                       return -EFAULT;
-               klsi_105_set_termios(port, &priv->termios);
-               return(0);
-            }
-       case TCSETSW: {
-               /* set port termios and try to wait for completion of last
-                * write operation */
-               /* We guess here. If there are not too many write urbs
-                * outstanding, we lie. */
-               /* what is the right way to wait here? schedule() ? */
-               /*
-               while (klsi_105_chars_in_buffer(port) > (NUM_URBS / 4 ) * URB_TRANSFER_BUFFER_SIZE)
-                           schedule();
-                */
-               return -ENOIOCTLCMD;
-                     }
-       default:
-               dbg("%s: arg not supported - 0x%04x", __FUNCTION__,cmd);
-               return(-ENOIOCTLCMD);
-               break;
-       }
-       return 0;
-} /* klsi_105_ioctl */
 
 static void klsi_105_throttle (struct usb_serial_port *port)
 {
        dbg("%s - port %d", __FUNCTION__, port->number);
-       usb_unlink_urb (port->read_urb);
+       usb_kill_urb(port->read_urb);
 }
 
 static void klsi_105_unthrottle (struct usb_serial_port *port)