Commit 4dbd5a09 authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds

tty-usb-console: tidy the USB console code

Code tidy
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c97611c1
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version * modify it under the terms of the GNU General Public License version
* 2 as published by the Free Software Foundation. * 2 as published by the Free Software Foundation.
* *
* Thanks to Randy Dunlap for the original version of this code. * Thanks to Randy Dunlap for the original version of this code.
* *
*/ */
...@@ -67,7 +67,7 @@ static int usb_console_setup(struct console *co, char *options) ...@@ -67,7 +67,7 @@ static int usb_console_setup(struct console *co, char *options)
struct tty_struct *tty = NULL; struct tty_struct *tty = NULL;
struct ktermios *termios = NULL, dummy; struct ktermios *termios = NULL, dummy;
dbg ("%s", __func__); dbg("%s", __func__);
if (options) { if (options) {
baud = simple_strtoul(options, NULL, 10); baud = simple_strtoul(options, NULL, 10);
...@@ -84,52 +84,52 @@ static int usb_console_setup(struct console *co, char *options) ...@@ -84,52 +84,52 @@ static int usb_console_setup(struct console *co, char *options)
/* build a cflag setting */ /* build a cflag setting */
switch (baud) { switch (baud) {
case 1200: case 1200:
cflag |= B1200; cflag |= B1200;
break; break;
case 2400: case 2400:
cflag |= B2400; cflag |= B2400;
break; break;
case 4800: case 4800:
cflag |= B4800; cflag |= B4800;
break; break;
case 19200: case 19200:
cflag |= B19200; cflag |= B19200;
break; break;
case 38400: case 38400:
cflag |= B38400; cflag |= B38400;
break; break;
case 57600: case 57600:
cflag |= B57600; cflag |= B57600;
break; break;
case 115200: case 115200:
cflag |= B115200; cflag |= B115200;
break; break;
case 9600: case 9600:
default: default:
cflag |= B9600; cflag |= B9600;
/* /*
* Set this to a sane value to prevent a divide error * Set this to a sane value to prevent a divide error
*/ */
baud = 9600; baud = 9600;
break; break;
} }
switch (bits) { switch (bits) {
case 7: case 7:
cflag |= CS7; cflag |= CS7;
break; break;
default: default:
case 8: case 8:
cflag |= CS8; cflag |= CS8;
break; break;
} }
switch (parity) { switch (parity) {
case 'o': case 'O': case 'o': case 'O':
cflag |= PARODD; cflag |= PARODD;
break; break;
case 'e': case 'E': case 'e': case 'E':
cflag |= PARENB; cflag |= PARENB;
break; break;
} }
co->cflag = cflag; co->cflag = cflag;
...@@ -140,7 +140,7 @@ static int usb_console_setup(struct console *co, char *options) ...@@ -140,7 +140,7 @@ static int usb_console_setup(struct console *co, char *options)
serial = usb_serial_get_by_index(co->index); serial = usb_serial_get_by_index(co->index);
if (serial == NULL) { if (serial == NULL) {
/* no device is connected yet, sorry :( */ /* no device is connected yet, sorry :( */
err ("No USB device connected to ttyUSB%i", co->index); err("No USB device connected to ttyUSB%i", co->index);
return -ENODEV; return -ENODEV;
} }
...@@ -148,7 +148,7 @@ static int usb_console_setup(struct console *co, char *options) ...@@ -148,7 +148,7 @@ static int usb_console_setup(struct console *co, char *options)
port->port.tty = NULL; port->port.tty = NULL;
info->port = port; info->port = port;
++port->port.count; ++port->port.count;
if (port->port.count == 1) { if (port->port.count == 1) {
if (serial->type->set_termios) { if (serial->type->set_termios) {
...@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options) ...@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
port->port.tty = tty; port->port.tty = tty;
} }
/* only call the device specific open if this /* only call the device specific open if this
* is the first time the port is opened */ * is the first time the port is opened */
if (serial->type->open) if (serial->type->open)
retval = serial->type->open(NULL, port, NULL); retval = serial->type->open(NULL, port, NULL);
...@@ -211,7 +211,8 @@ reset_open_count: ...@@ -211,7 +211,8 @@ reset_open_count:
goto out; goto out;
} }
static void usb_console_write(struct console *co, const char *buf, unsigned count) static void usb_console_write(struct console *co,
const char *buf, unsigned count)
{ {
static struct usbcons_info *info = &usbcons_info; static struct usbcons_info *info = &usbcons_info;
struct usb_serial_port *port = info->port; struct usb_serial_port *port = info->port;
...@@ -228,7 +229,7 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun ...@@ -228,7 +229,7 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
dbg("%s - port %d, %d byte(s)", __func__, port->number, count); dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
if (!port->port.count) { if (!port->port.count) {
dbg ("%s - port not opened", __func__); dbg("%s - port not opened", __func__);
return; return;
} }
...@@ -236,14 +237,15 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun ...@@ -236,14 +237,15 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
unsigned int i; unsigned int i;
unsigned int lf; unsigned int lf;
/* search for LF so we can insert CR if necessary */ /* search for LF so we can insert CR if necessary */
for (i=0, lf=0 ; i < count ; i++) { for (i = 0, lf = 0 ; i < count ; i++) {
if (*(buf + i) == 10) { if (*(buf + i) == 10) {
lf = 1; lf = 1;
i++; i++;
break; break;
} }
} }
/* pass on to the driver specific version of this function if it is available */ /* pass on to the driver specific version of this function if
it is available */
if (serial->type->write) if (serial->type->write)
retval = serial->type->write(NULL, port, buf, i); retval = serial->type->write(NULL, port, buf, i);
else else
...@@ -253,9 +255,11 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun ...@@ -253,9 +255,11 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
/* append CR after LF */ /* append CR after LF */
unsigned char cr = 13; unsigned char cr = 13;
if (serial->type->write) if (serial->type->write)
retval = serial->type->write(NULL, port, &cr, 1); retval = serial->type->write(NULL,
port, &cr, 1);
else else
retval = usb_serial_generic_write(NULL, port, &cr, 1); retval = usb_serial_generic_write(NULL,
port, &cr, 1);
dbg("%s - return value : %d", __func__, retval); dbg("%s - return value : %d", __func__, retval);
} }
buf += i; buf += i;
...@@ -273,18 +277,19 @@ static struct console usbcons = { ...@@ -273,18 +277,19 @@ static struct console usbcons = {
void usb_serial_console_disconnect(struct usb_serial *serial) void usb_serial_console_disconnect(struct usb_serial *serial)
{ {
if (serial && serial->port && serial->port[0] && serial->port[0] == usbcons_info.port) { if (serial && serial->port && serial->port[0]
&& serial->port[0] == usbcons_info.port) {
usb_serial_console_exit(); usb_serial_console_exit();
usb_serial_put(serial); usb_serial_put(serial);
} }
} }
void usb_serial_console_init (int serial_debug, int minor) void usb_serial_console_init(int serial_debug, int minor)
{ {
debug = serial_debug; debug = serial_debug;
if (minor == 0) { if (minor == 0) {
/* /*
* Call register_console() if this is the first device plugged * Call register_console() if this is the first device plugged
* in. If we call it earlier, then the callback to * in. If we call it earlier, then the callback to
* console_setup() will fail, as there is not a device seen by * console_setup() will fail, as there is not a device seen by
...@@ -293,16 +298,16 @@ void usb_serial_console_init (int serial_debug, int minor) ...@@ -293,16 +298,16 @@ void usb_serial_console_init (int serial_debug, int minor)
/* /*
* Register console. * Register console.
* NOTES: * NOTES:
* console_setup() is called (back) immediately (from register_console). * console_setup() is called (back) immediately (from
* console_write() is called immediately from register_console iff * register_console). console_write() is called immediately
* CON_PRINTBUFFER is set in flags. * from register_console iff CON_PRINTBUFFER is set in flags.
*/ */
dbg ("registering the USB serial console."); dbg("registering the USB serial console.");
register_console(&usbcons); register_console(&usbcons);
} }
} }
void usb_serial_console_exit (void) void usb_serial_console_exit(void)
{ {
if (usbcons_info.port) { if (usbcons_info.port) {
unregister_console(&usbcons); unregister_console(&usbcons);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment