X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=drivers%2Fusb%2Fserial%2Fkl5kusb105.c;h=f328948d74e3dfc9cf21439333ef48140eff1af9;hb=c2448278e3be3a43fe0343e138444742af1e99ae;hp=90e3216abd1f006800f0d2ed018a83c12a9b5cc0;hpb=df3d80f5a5c74168be42788364d13cf6c83c7b9c;p=karo-tx-linux.git diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index 90e3216abd1f..f328948d74e3 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include "kl5kusb105.h" @@ -126,9 +127,6 @@ static struct usb_serial_driver kl5kusb105d_device = { .description = "KL5KUSB105D / PalmConnect", .usb_driver = &kl5kusb105d_driver, .id_table = id_table, - .num_interrupt_in = 1, - .num_bulk_in = 1, - .num_bulk_out = 1, .num_ports = 1, .open = klsi_105_open, .close = klsi_105_close, @@ -194,7 +192,7 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port, if (rc < 0) err("Change port settings failed (error = %d)", rc); info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d", - __FUNCTION__, + __func__, settings->pktlen, settings->baudrate, settings->databits, settings->unknown1, settings->unknown2); @@ -225,7 +223,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1}; __u16 status; - info("%s - sending SIO Poll request", __FUNCTION__); + info("%s - sending SIO Poll request", __func__); rc = usb_control_msg(port->serial->dev, usb_rcvctrlpipe(port->serial->dev, 0), KL5KUSB105A_SIO_POLL, @@ -238,9 +236,9 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, if (rc < 0) err("Reading line status failed (error = %d)", rc); else { - status = le16_to_cpu(*(u16 *)status_buf); + status = le16_to_cpu(get_unaligned((__le16 *)status_buf)); - info("%s - read status %x %x", __FUNCTION__, + info("%s - read status %x %x", __func__, status_buf[0], status_buf[1]); *line_state_p = klsi_105_status2linestate(status); @@ -268,7 +266,7 @@ static int klsi_105_startup (struct usb_serial *serial) priv = kmalloc(sizeof(struct klsi_105_private), GFP_KERNEL); if (!priv) { - dbg("%skmalloc for klsi_105_private failed.", __FUNCTION__); + dbg("%skmalloc for klsi_105_private failed.", __func__); i--; goto err_cleanup; } @@ -298,7 +296,7 @@ static int klsi_105_startup (struct usb_serial *serial) urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); if (!urb->transfer_buffer) { - err("%s - out of memory for urb buffers.", __FUNCTION__); + err("%s - out of memory for urb buffers.", __func__); goto err_cleanup; } } @@ -328,7 +326,7 @@ static void klsi_105_shutdown (struct usb_serial *serial) { int i; - dbg("%s", __FUNCTION__); + dbg("%s", __func__); /* stop reads and writes on all ports */ for (i=0; i < serial->num_ports; ++i) { @@ -373,7 +371,7 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp) struct klsi_105_port_settings cfg; unsigned long flags; - dbg("%s port %d", __FUNCTION__, port->number); + dbg("%s port %d", __func__, port->number); /* force low_latency on so that our tty_push actually forces * the data through @@ -419,7 +417,7 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp) rc = usb_submit_urb(port->read_urb, GFP_KERNEL); if (rc) { - err("%s - failed submitting read urb, error %d", __FUNCTION__, rc); + err("%s - failed submitting read urb, error %d", __func__, rc); retval = rc; goto exit; } @@ -437,14 +435,14 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp) err("Enabling read failed (error = %d)", rc); retval = rc; } else - dbg("%s - enabled reading", __FUNCTION__); + dbg("%s - enabled reading", __func__); rc = klsi_105_get_line_state(port, &line_state); if (rc >= 0) { spin_lock_irqsave (&priv->lock, flags); priv->line_state = line_state; spin_unlock_irqrestore (&priv->lock, flags); - dbg("%s - read line state 0x%lx", __FUNCTION__, line_state); + dbg("%s - read line state 0x%lx", __func__, line_state); retval = 0; } else retval = rc; @@ -459,19 +457,23 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp) struct klsi_105_private *priv = usb_get_serial_port_data(port); int rc; - dbg("%s port %d", __FUNCTION__, port->number); - - /* send READ_OFF */ - rc = usb_control_msg (port->serial->dev, - usb_sndctrlpipe(port->serial->dev, 0), - KL5KUSB105A_SIO_CONFIGURE, - USB_TYPE_VENDOR | USB_DIR_OUT, - KL5KUSB105A_SIO_CONFIGURE_READ_OFF, - 0, /* index */ - NULL, 0, - KLSI_TIMEOUT); - if (rc < 0) - err("Disabling read failed (error = %d)", rc); + dbg("%s port %d", __func__, port->number); + + mutex_lock(&port->serial->disc_mutex); + if (!port->serial->disconnected) { + /* send READ_OFF */ + rc = usb_control_msg (port->serial->dev, + usb_sndctrlpipe(port->serial->dev, 0), + KL5KUSB105A_SIO_CONFIGURE, + USB_TYPE_VENDOR | USB_DIR_OUT, + KL5KUSB105A_SIO_CONFIGURE_READ_OFF, + 0, /* index */ + NULL, 0, + KLSI_TIMEOUT); + if (rc < 0) + err("Disabling read failed (error = %d)", rc); + } + mutex_unlock(&port->serial->disc_mutex); /* shutdown our bulk reads and writes */ usb_kill_urb(port->write_urb); @@ -498,7 +500,7 @@ static int klsi_105_write (struct usb_serial_port *port, int result, size; int bytes_sent=0; - dbg("%s - port %d", __FUNCTION__, port->number); + dbg("%s - port %d", __func__, port->number); while (count > 0) { /* try to find a free urb (write 0 bytes if none) */ @@ -510,21 +512,21 @@ static int klsi_105_write (struct usb_serial_port *port, for (i=0; iwrite_urb_pool[i]->status != -EINPROGRESS) { urb = priv->write_urb_pool[i]; - dbg("%s - using pool URB %d", __FUNCTION__, i); + dbg("%s - using pool URB %d", __func__, i); break; } } spin_unlock_irqrestore (&priv->lock, flags); if (urb==NULL) { - dbg("%s - no more free urbs", __FUNCTION__); + dbg("%s - no more free urbs", __func__); goto exit; } if (urb->transfer_buffer == NULL) { urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); if (urb->transfer_buffer == NULL) { - err("%s - no more kernel memory...", __FUNCTION__); + err("%s - no more kernel memory...", __func__); goto exit; } } @@ -550,7 +552,7 @@ static int klsi_105_write (struct usb_serial_port *port, /* send the data out the bulk port */ result = usb_submit_urb(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); goto exit; } buf += size; @@ -566,13 +568,13 @@ exit: static void klsi_105_write_bulk_callback ( struct urb *urb) { - struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + struct usb_serial_port *port = urb->context; int status = urb->status; - dbg("%s - port %d", __FUNCTION__, port->number); + dbg("%s - port %d", __func__, port->number); if (status) { - dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, + dbg("%s - nonzero write bulk status received: %d", __func__, status); return; } @@ -599,7 +601,7 @@ static int klsi_105_chars_in_buffer (struct usb_serial_port *port) spin_unlock_irqrestore (&priv->lock, flags); - dbg("%s - returns %d", __FUNCTION__, chars); + dbg("%s - returns %d", __func__, chars); return (chars); } @@ -619,7 +621,7 @@ static int klsi_105_write_room (struct usb_serial_port *port) spin_unlock_irqrestore (&priv->lock, flags); - dbg("%s - returns %d", __FUNCTION__, room); + dbg("%s - returns %d", __func__, room); return (room); } @@ -627,18 +629,18 @@ static int klsi_105_write_room (struct usb_serial_port *port) static void klsi_105_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 klsi_105_private *priv = usb_get_serial_port_data(port); struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; int rc; int status = urb->status; - dbg("%s - port %d", __FUNCTION__, port->number); + dbg("%s - port %d", __func__, port->number); /* The urb might have been killed. */ if (status) { - dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, + dbg("%s - nonzero read bulk status received: %d", __func__, status); return; } @@ -648,12 +650,12 @@ static void klsi_105_read_bulk_callback (struct urb *urb) */ if (urb->actual_length == 0) { /* empty urbs seem to happen, we ignore them */ - /* dbg("%s - emtpy URB", __FUNCTION__); */ + /* dbg("%s - emtpy URB", __func__); */ ; } else if (urb->actual_length <= 2) { - dbg("%s - size %d URB not understood", __FUNCTION__, + dbg("%s - size %d URB not understood", __func__, urb->actual_length); - usb_serial_debug_data(debug, &port->dev, __FUNCTION__, + usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); } else { int bytes_sent = ((__u8 *) data)[0] + @@ -665,12 +667,12 @@ static void klsi_105_read_bulk_callback (struct urb *urb) * intermixed tty_flip_buffer_push()s * FIXME */ - usb_serial_debug_data(debug, &port->dev, __FUNCTION__, + usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); if (bytes_sent + 2 > urb->actual_length) { dbg("%s - trying to read more data than available" - " (%d vs. %d)", __FUNCTION__, + " (%d vs. %d)", __func__, bytes_sent+2, urb->actual_length); /* cap at implied limit */ bytes_sent = urb->actual_length - 2; @@ -693,7 +695,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb) port); rc = usb_submit_urb(port->read_urb, GFP_ATOMIC); if (rc) - err("%s - failed resubmitting read urb, error %d", __FUNCTION__, rc); + err("%s - failed resubmitting read urb, error %d", __func__, rc); } /* klsi_105_read_bulk_callback */ @@ -701,12 +703,14 @@ static void klsi_105_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) { struct klsi_105_private *priv = usb_get_serial_port_data(port); - unsigned int iflag = port->tty->termios->c_iflag; + struct tty_struct *tty = port->tty; + unsigned int iflag = tty->termios->c_iflag; unsigned int old_iflag = old_termios->c_iflag; - unsigned int cflag = port->tty->termios->c_cflag; + unsigned int cflag = tty->termios->c_cflag; unsigned int old_cflag = old_termios->c_cflag; struct klsi_105_port_settings cfg; unsigned long flags; + speed_t baud; /* lock while we are modifying the settings */ spin_lock_irqsave (&priv->lock, flags); @@ -714,10 +718,12 @@ static void klsi_105_set_termios (struct usb_serial_port *port, /* * Update baud rate */ + baud = tty_get_baud_rate(tty); + if( (cflag & CBAUD) != (old_cflag & CBAUD) ) { /* reassert DTR and (maybe) RTS on transition from B0 */ if( (old_cflag & CBAUD) == B0 ) { - dbg("%s: baud was B0", __FUNCTION__); + dbg("%s: baud was B0", __func__); #if 0 priv->control_state |= TIOCM_DTR; /* don't set RTS if using hardware flow control */ @@ -727,8 +733,8 @@ static void klsi_105_set_termios (struct usb_serial_port *port, mct_u232_set_modem_ctrl(serial, priv->control_state); #endif } - - switch(tty_get_baud_rate(port->tty)) { + } + switch(baud) { case 0: /* handled below */ break; case 1200: @@ -756,35 +762,36 @@ static void klsi_105_set_termios (struct usb_serial_port *port, priv->cfg.baudrate = kl5kusb105a_sio_b115200; break; default: - err("KLSI USB->Serial converter:" + dbg("KLSI USB->Serial converter:" " unsupported baudrate request, using default" " of 9600"); priv->cfg.baudrate = kl5kusb105a_sio_b9600; + baud = 9600; break; - } - if ((cflag & CBAUD) == B0 ) { - dbg("%s: baud is B0", __FUNCTION__); - /* Drop RTS and DTR */ - /* maybe this should be simulated by sending read - * disable and read enable messages? - */ - ; + } + if ((cflag & CBAUD) == B0 ) { + dbg("%s: baud is B0", __func__); + /* Drop RTS and DTR */ + /* maybe this should be simulated by sending read + * disable and read enable messages? + */ + ; #if 0 - priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); - mct_u232_set_modem_ctrl(serial, priv->control_state); + priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); + mct_u232_set_modem_ctrl(serial, priv->control_state); #endif - } } + tty_encode_baud_rate(tty, baud, baud); if ((cflag & CSIZE) != (old_cflag & CSIZE)) { /* set the number of data bits */ switch (cflag & CSIZE) { case CS5: - dbg("%s - 5 bits/byte not supported", __FUNCTION__); + dbg("%s - 5 bits/byte not supported", __func__); spin_unlock_irqrestore (&priv->lock, flags); return ; case CS6: - dbg("%s - 6 bits/byte not supported", __FUNCTION__); + dbg("%s - 6 bits/byte not supported", __func__); spin_unlock_irqrestore (&priv->lock, flags); return ; case CS7: @@ -806,6 +813,8 @@ static void klsi_105_set_termios (struct usb_serial_port *port, if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD)) || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) { + /* Not currently supported */ + tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB); #if 0 priv->last_lcr = 0; @@ -833,6 +842,8 @@ static void klsi_105_set_termios (struct usb_serial_port *port, || (iflag & IXON) != (old_iflag & IXON) || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) { + /* Not currently supported */ + tty->termios->c_cflag &= ~CRTSCTS; /* Drop DTR/RTS if no flow control otherwise assert */ #if 0 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) ) @@ -858,7 +869,7 @@ static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state ) struct mct_u232_private *priv = (struct mct_u232_private *)port->private; unsigned char lcr = priv->last_lcr; - dbg("%sstate=%d", __FUNCTION__, break_state); + dbg("%sstate=%d", __func__, break_state); if (break_state) lcr |= MCT_U232_SET_BREAK; @@ -873,7 +884,7 @@ static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file) unsigned long flags; int rc; unsigned long line_state; - dbg("%s - request, just guessing", __FUNCTION__); + dbg("%s - request, just guessing", __func__); rc = klsi_105_get_line_state(port, &line_state); if (rc < 0) { @@ -885,7 +896,7 @@ static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file) spin_lock_irqsave (&priv->lock, flags); priv->line_state = line_state; spin_unlock_irqrestore (&priv->lock, flags); - dbg("%s - read line state 0x%lx", __FUNCTION__, line_state); + dbg("%s - read line state 0x%lx", __func__, line_state); return (int)line_state; } @@ -894,7 +905,7 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file, { int retval = -EINVAL; - dbg("%s", __FUNCTION__); + dbg("%s", __func__); /* if this ever gets implemented, it should be done something like this: struct usb_serial *serial = port->serial; @@ -920,7 +931,7 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file, static void klsi_105_throttle (struct usb_serial_port *port) { - dbg("%s - port %d", __FUNCTION__, port->number); + dbg("%s - port %d", __func__, port->number); usb_kill_urb(port->read_urb); } @@ -928,12 +939,12 @@ static void klsi_105_unthrottle (struct usb_serial_port *port) { int result; - dbg("%s - port %d", __FUNCTION__, port->number); + dbg("%s - port %d", __func__, port->number); port->read_urb->dev = port->serial->dev; result = usb_submit_urb(port->read_urb, GFP_ATOMIC); if (result) - err("%s - failed submitting read urb, error %d", __FUNCTION__, + err("%s - failed submitting read urb, error %d", __func__, result); }