Ok, I found it. It's the ->write() call from usb_console_write() - obvious, isn't it. So, now it works without a single attempt to bring out a message on a disconnected console. At the bottom my current version. Certainly, it is not final, but, I think, we may use it as a starting point. It contains some of your fixes, Paul, plus some my hacks:-)
Thanks Guennadi --- Guennadi Liakhovetski Index: drivers/usb/serial/console.c =================================================================== RCS file: /usr/src/cvs/linux-2_6/drivers/usb/serial/console.c,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 console.c --- drivers/usb/serial/console.c 13 Jan 2005 21:09:08 -0000 1.1.1.3 +++ drivers/usb/serial/console.c 11 Apr 2006 18:03:29 -0000 @@ -54,7 +54,7 @@ * serial.c code, except that the specifier is "ttyUSB" instead * of "ttyS". */ -static int __init usb_console_setup(struct console *co, char *options) +static int usb_console_setup(struct console *co, char *options) { struct usbcons_info *info = &usbcons_info; int baud = 9600; @@ -202,7 +202,7 @@ struct usb_serial *serial; int retval = -ENODEV; - if (!port) + if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED) return; serial = port->serial; @@ -213,17 +213,38 @@ if (!port->open_count) { dbg ("%s - port not opened", __FUNCTION__); - goto exit; + return; } - /* pass on to the driver specific version of this function if it is available */ - if (serial->type->write) - retval = serial->type->write(port, buf, count); - else - retval = usb_serial_generic_write(port, buf, count); - -exit: - dbg("%s - return value (if we had one): %d", __FUNCTION__, retval); + while (count) { + unsigned int i; + unsigned int lf; + /* search for LF so we can insert CR if necessary */ + for (i=0, lf=0 ; i < count ; i++) { + if (*(buf + i) == 10) { + lf = 1; + i++; + break; + } + } + /* pass on to the driver specific version of this function if it is available */ + if (serial->type->write) + retval = serial->type->write(port, buf, i); + else + retval = usb_serial_generic_write(port, buf, i); + dbg("%s - return value : %d", __FUNCTION__, retval); + if (lf) { + /* append CR after LF */ + unsigned char cr = 13; + if (serial->type->write) + retval = serial->type->write(port, &cr, 1); + else + retval = usb_serial_generic_write(port, &cr, 1); + dbg("%s - return value : %d", __FUNCTION__, retval); + } + buf += i; + count -= i; + } } static struct console usbcons = { @@ -234,6 +255,14 @@ .index = -1, }; +void usb_serial_console_disconnect(struct usb_serial *serial) +{ + if (serial && serial->port && serial->port[0] && serial->port[0] == usbcons_info.port) { + usbcons_info.port->open_count--; + usbcons_info.port = NULL; + } +} + void usb_serial_console_init (int serial_debug, int minor) { debug = serial_debug; Index: drivers/usb/serial/ftdi_sio.c =================================================================== RCS file: /usr/src/cvs/linux-2_6/drivers/usb/serial/ftdi_sio.c,v retrieving revision 1.1.1.16 diff -u -r1.1.1.16 ftdi_sio.c --- drivers/usb/serial/ftdi_sio.c 30 Mar 2006 19:18:07 -0000 1.1.1.16 +++ drivers/usb/serial/ftdi_sio.c 11 Apr 2006 18:12:53 -0000 @@ -1254,7 +1254,6 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp) { /* ftdi_open */ - struct termios tmp_termios; struct usb_device *dev = port->serial->dev; struct ftdi_private *priv = usb_get_serial_port_data(port); unsigned long flags; @@ -1264,8 +1263,8 @@ dbg("%s", __FUNCTION__); - - port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; + if (port->tty) + port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; /* No error checking for this (will get errors later anyway) */ /* See ftdi_sio.h for description of what is reset */ @@ -1279,7 +1278,8 @@ This is same behaviour as serial.c/rs_open() - Kuba */ /* ftdi_set_termios will send usb control messages */ - ftdi_set_termios(port, &tmp_termios); + if (port->tty) + ftdi_set_termios(port, NULL); /* FIXME: Flow control might be enabled, so it should be checked - we have no control of defaults! */ @@ -1860,7 +1860,7 @@ err("%s urb failed to set baudrate", __FUNCTION__); } /* Ensure RTS and DTR are raised when baudrate changed from 0 */ - if ((old_termios->c_cflag & CBAUD) == B0) { + if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) { set_mctrl(port, TIOCM_DTR | TIOCM_RTS); } } Index: drivers/usb/serial/usb-serial.c =================================================================== RCS file: /usr/src/cvs/linux-2_6/drivers/usb/serial/usb-serial.c,v retrieving revision 1.1.1.12 diff -u -r1.1.1.12 usb-serial.c --- drivers/usb/serial/usb-serial.c 30 Mar 2006 19:18:07 -0000 1.1.1.12 +++ drivers/usb/serial/usb-serial.c 11 Apr 2006 18:02:12 -0000 @@ -197,12 +197,12 @@ ++port->open_count; - if (port->open_count == 1) { + /* set up our port structure making the tty driver + * remember our port object, and us it */ + tty->driver_data = port; + port->tty = tty; - /* set up our port structure making the tty driver - * remember our port object, and us it */ - tty->driver_data = port; - port->tty = tty; + if (port->open_count == 1) { /* lock this module before we call it * this may fail, which means we must bail out, @@ -271,7 +271,7 @@ struct usb_serial_port *port = tty->driver_data; int retval = -EINVAL; - if (!port) + if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED) goto exit; dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count); @@ -982,6 +982,7 @@ struct device *dev = &interface->dev; struct usb_serial_port *port; + usb_serial_console_disconnect(serial); dbg ("%s", __FUNCTION__); usb_set_intfdata (interface, NULL); Index: drivers/usb/serial/usb-serial.h =================================================================== RCS file: /usr/src/cvs/linux-2_6/drivers/usb/serial/usb-serial.h,v retrieving revision 1.1.1.9 diff -u -r1.1.1.9 usb-serial.h --- drivers/usb/serial/usb-serial.h 30 Mar 2006 19:18:07 -0000 1.1.1.9 +++ drivers/usb/serial/usb-serial.h 11 Apr 2006 18:02:12 -0000 @@ -248,9 +248,11 @@ #ifdef CONFIG_USB_SERIAL_CONSOLE extern void usb_serial_console_init (int debug, int minor); extern void usb_serial_console_exit (void); +extern void usb_serial_console_disconnect(struct usb_serial *serial); #else static inline void usb_serial_console_init (int debug, int minor) { } static inline void usb_serial_console_exit (void) { } +static inline void usb_serial_console_disconnect(struct usb_serial *serial) {} #endif /* Functions needed by other parts of the usbserial core */ ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel