X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fusb%2Fserial%2Fconsole.c;h=9386e216d68155caec8c9467ddfe4dd005c61859;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=977da0680491017c61973352af22e104f659e362;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index 977da0680..9386e216d 100644 --- a/drivers/usb/serial/console.c +++ b/drivers/usb/serial/console.c @@ -11,18 +11,16 @@ * */ -#include #include #include #include #include #include #include +#include static int debug; -#include "usb-serial.h" - struct usbcons_info { int magic; int break_flag; @@ -54,7 +52,7 @@ static struct console usbcons; * 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; @@ -67,7 +65,7 @@ static int __init usb_console_setup(struct console *co, char *options) struct usb_serial_port *port; int retval = 0; struct tty_struct *tty; - struct termios *termios; + struct ktermios *termios; dbg ("%s", __FUNCTION__); @@ -137,7 +135,7 @@ static int __init usb_console_setup(struct console *co, char *options) /* grab the first serial port that happens to be connected */ serial = usb_serial_get_by_index(0); - if (serial_paranoia_check (serial, __FUNCTION__)) { + if (serial == NULL) { /* no device is connected yet, sorry :( */ err ("No USB device connected to ttyUSB0"); return -ENODEV; @@ -168,19 +166,17 @@ static int __init usb_console_setup(struct console *co, char *options) if (serial->type->set_termios) { /* build up a fake tty structure so that the open call has something * to look at to get the cflag value */ - tty = kmalloc (sizeof (*tty), GFP_KERNEL); + tty = kzalloc(sizeof(*tty), GFP_KERNEL); if (!tty) { err ("no more memory"); return -ENOMEM; } - termios = kmalloc (sizeof (*termios), GFP_KERNEL); + termios = kzalloc(sizeof(*termios), GFP_KERNEL); if (!termios) { err ("no more memory"); kfree (tty); return -ENOMEM; } - memset (tty, 0x00, sizeof(*tty)); - memset (termios, 0x00, sizeof(*termios)); termios->c_cflag = cflag; tty->termios = termios; port->tty = tty; @@ -199,11 +195,12 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun { static struct usbcons_info *info = &usbcons_info; struct usb_serial_port *port = info->port; - struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); + struct usb_serial *serial; int retval = -ENODEV; - if (!serial || !port) + if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED) return; + serial = port->serial; if (count == 0) return; @@ -212,17 +209,38 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun 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, 0, buf, count); - else - retval = usb_serial_generic_write(port, 0, 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 = { @@ -233,6 +251,14 @@ static struct console usbcons = { .index = -1, }; +void usb_serial_console_disconnect(struct usb_serial *serial) +{ + if (serial && serial->port && serial->port[0] && serial->port[0] == usbcons_info.port) { + usb_serial_console_exit(); + usb_serial_put(serial); + } +} + void usb_serial_console_init (int serial_debug, int minor) { debug = serial_debug; @@ -258,6 +284,11 @@ void usb_serial_console_init (int serial_debug, int minor) void usb_serial_console_exit (void) { - unregister_console(&usbcons); + if (usbcons_info.port) { + unregister_console(&usbcons); + if (usbcons_info.port->open_count) + usbcons_info.port->open_count--; + usbcons_info.port = NULL; + } }