diff options
author | Alan Cox <alan@redhat.com> | 2008-07-22 06:09:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-22 16:03:22 -0400 |
commit | 4dbd5a0961ff55cb8a7bce309dd5ef9b04090570 (patch) | |
tree | f053036ffb8b72d46b8dc35f7311fc3b339db12e /drivers/usb/serial/console.c | |
parent | c97611c16d9b3c37fcf3c18cc442dfde3a8b5d43 (diff) |
tty-usb-console: tidy the USB console code
Code tidy
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb/serial/console.c')
-rw-r--r-- | drivers/usb/serial/console.c | 127 |
1 files changed, 66 insertions, 61 deletions
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index 940f5de68980..9a4cd0a932b3 100644 --- a/drivers/usb/serial/console.c +++ b/drivers/usb/serial/console.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License version | 7 | * modify it under the terms of the GNU General Public License version |
8 | * 2 as published by the Free Software Foundation. | 8 | * 2 as published by the Free Software Foundation. |
9 | * | 9 | * |
10 | * Thanks to Randy Dunlap for the original version of this code. | 10 | * Thanks to Randy Dunlap for the original version of this code. |
11 | * | 11 | * |
12 | */ | 12 | */ |
@@ -67,7 +67,7 @@ static int usb_console_setup(struct console *co, char *options) | |||
67 | struct tty_struct *tty = NULL; | 67 | struct tty_struct *tty = NULL; |
68 | struct ktermios *termios = NULL, dummy; | 68 | struct ktermios *termios = NULL, dummy; |
69 | 69 | ||
70 | dbg ("%s", __func__); | 70 | dbg("%s", __func__); |
71 | 71 | ||
72 | if (options) { | 72 | if (options) { |
73 | baud = simple_strtoul(options, NULL, 10); | 73 | baud = simple_strtoul(options, NULL, 10); |
@@ -84,52 +84,52 @@ static int usb_console_setup(struct console *co, char *options) | |||
84 | 84 | ||
85 | /* build a cflag setting */ | 85 | /* build a cflag setting */ |
86 | switch (baud) { | 86 | switch (baud) { |
87 | case 1200: | 87 | case 1200: |
88 | cflag |= B1200; | 88 | cflag |= B1200; |
89 | break; | 89 | break; |
90 | case 2400: | 90 | case 2400: |
91 | cflag |= B2400; | 91 | cflag |= B2400; |
92 | break; | 92 | break; |
93 | case 4800: | 93 | case 4800: |
94 | cflag |= B4800; | 94 | cflag |= B4800; |
95 | break; | 95 | break; |
96 | case 19200: | 96 | case 19200: |
97 | cflag |= B19200; | 97 | cflag |= B19200; |
98 | break; | 98 | break; |
99 | case 38400: | 99 | case 38400: |
100 | cflag |= B38400; | 100 | cflag |= B38400; |
101 | break; | 101 | break; |
102 | case 57600: | 102 | case 57600: |
103 | cflag |= B57600; | 103 | cflag |= B57600; |
104 | break; | 104 | break; |
105 | case 115200: | 105 | case 115200: |
106 | cflag |= B115200; | 106 | cflag |= B115200; |
107 | break; | 107 | break; |
108 | case 9600: | 108 | case 9600: |
109 | default: | 109 | default: |
110 | cflag |= B9600; | 110 | cflag |= B9600; |
111 | /* | 111 | /* |
112 | * Set this to a sane value to prevent a divide error | 112 | * Set this to a sane value to prevent a divide error |
113 | */ | 113 | */ |
114 | baud = 9600; | 114 | baud = 9600; |
115 | break; | 115 | break; |
116 | } | 116 | } |
117 | switch (bits) { | 117 | switch (bits) { |
118 | case 7: | 118 | case 7: |
119 | cflag |= CS7; | 119 | cflag |= CS7; |
120 | break; | 120 | break; |
121 | default: | 121 | default: |
122 | case 8: | 122 | case 8: |
123 | cflag |= CS8; | 123 | cflag |= CS8; |
124 | break; | 124 | break; |
125 | } | 125 | } |
126 | switch (parity) { | 126 | switch (parity) { |
127 | case 'o': case 'O': | 127 | case 'o': case 'O': |
128 | cflag |= PARODD; | 128 | cflag |= PARODD; |
129 | break; | 129 | break; |
130 | case 'e': case 'E': | 130 | case 'e': case 'E': |
131 | cflag |= PARENB; | 131 | cflag |= PARENB; |
132 | break; | 132 | break; |
133 | } | 133 | } |
134 | co->cflag = cflag; | 134 | co->cflag = cflag; |
135 | 135 | ||
@@ -140,7 +140,7 @@ static int usb_console_setup(struct console *co, char *options) | |||
140 | serial = usb_serial_get_by_index(co->index); | 140 | serial = usb_serial_get_by_index(co->index); |
141 | if (serial == NULL) { | 141 | if (serial == NULL) { |
142 | /* no device is connected yet, sorry :( */ | 142 | /* no device is connected yet, sorry :( */ |
143 | err ("No USB device connected to ttyUSB%i", co->index); | 143 | err("No USB device connected to ttyUSB%i", co->index); |
144 | return -ENODEV; | 144 | return -ENODEV; |
145 | } | 145 | } |
146 | 146 | ||
@@ -148,7 +148,7 @@ static int usb_console_setup(struct console *co, char *options) | |||
148 | port->port.tty = NULL; | 148 | port->port.tty = NULL; |
149 | 149 | ||
150 | info->port = port; | 150 | info->port = port; |
151 | 151 | ||
152 | ++port->port.count; | 152 | ++port->port.count; |
153 | if (port->port.count == 1) { | 153 | if (port->port.count == 1) { |
154 | if (serial->type->set_termios) { | 154 | if (serial->type->set_termios) { |
@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options) | |||
174 | port->port.tty = tty; | 174 | port->port.tty = tty; |
175 | } | 175 | } |
176 | 176 | ||
177 | /* only call the device specific open if this | 177 | /* only call the device specific open if this |
178 | * is the first time the port is opened */ | 178 | * is the first time the port is opened */ |
179 | if (serial->type->open) | 179 | if (serial->type->open) |
180 | retval = serial->type->open(NULL, port, NULL); | 180 | retval = serial->type->open(NULL, port, NULL); |
@@ -211,7 +211,8 @@ reset_open_count: | |||
211 | goto out; | 211 | goto out; |
212 | } | 212 | } |
213 | 213 | ||
214 | static void usb_console_write(struct console *co, const char *buf, unsigned count) | 214 | static void usb_console_write(struct console *co, |
215 | const char *buf, unsigned count) | ||
215 | { | 216 | { |
216 | static struct usbcons_info *info = &usbcons_info; | 217 | static struct usbcons_info *info = &usbcons_info; |
217 | struct usb_serial_port *port = info->port; | 218 | 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 | dbg("%s - port %d, %d byte(s)", __func__, port->number, count); | 229 | dbg("%s - port %d, %d byte(s)", __func__, port->number, count); |
229 | 230 | ||
230 | if (!port->port.count) { | 231 | if (!port->port.count) { |
231 | dbg ("%s - port not opened", __func__); | 232 | dbg("%s - port not opened", __func__); |
232 | return; | 233 | return; |
233 | } | 234 | } |
234 | 235 | ||
@@ -236,14 +237,15 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun | |||
236 | unsigned int i; | 237 | unsigned int i; |
237 | unsigned int lf; | 238 | unsigned int lf; |
238 | /* search for LF so we can insert CR if necessary */ | 239 | /* search for LF so we can insert CR if necessary */ |
239 | for (i=0, lf=0 ; i < count ; i++) { | 240 | for (i = 0, lf = 0 ; i < count ; i++) { |
240 | if (*(buf + i) == 10) { | 241 | if (*(buf + i) == 10) { |
241 | lf = 1; | 242 | lf = 1; |
242 | i++; | 243 | i++; |
243 | break; | 244 | break; |
244 | } | 245 | } |
245 | } | 246 | } |
246 | /* pass on to the driver specific version of this function if it is available */ | 247 | /* pass on to the driver specific version of this function if |
248 | it is available */ | ||
247 | if (serial->type->write) | 249 | if (serial->type->write) |
248 | retval = serial->type->write(NULL, port, buf, i); | 250 | retval = serial->type->write(NULL, port, buf, i); |
249 | else | 251 | else |
@@ -253,9 +255,11 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun | |||
253 | /* append CR after LF */ | 255 | /* append CR after LF */ |
254 | unsigned char cr = 13; | 256 | unsigned char cr = 13; |
255 | if (serial->type->write) | 257 | if (serial->type->write) |
256 | retval = serial->type->write(NULL, port, &cr, 1); | 258 | retval = serial->type->write(NULL, |
259 | port, &cr, 1); | ||
257 | else | 260 | else |
258 | retval = usb_serial_generic_write(NULL, port, &cr, 1); | 261 | retval = usb_serial_generic_write(NULL, |
262 | port, &cr, 1); | ||
259 | dbg("%s - return value : %d", __func__, retval); | 263 | dbg("%s - return value : %d", __func__, retval); |
260 | } | 264 | } |
261 | buf += i; | 265 | buf += i; |
@@ -273,18 +277,19 @@ static struct console usbcons = { | |||
273 | 277 | ||
274 | void usb_serial_console_disconnect(struct usb_serial *serial) | 278 | void usb_serial_console_disconnect(struct usb_serial *serial) |
275 | { | 279 | { |
276 | if (serial && serial->port && serial->port[0] && serial->port[0] == usbcons_info.port) { | 280 | if (serial && serial->port && serial->port[0] |
281 | && serial->port[0] == usbcons_info.port) { | ||
277 | usb_serial_console_exit(); | 282 | usb_serial_console_exit(); |
278 | usb_serial_put(serial); | 283 | usb_serial_put(serial); |
279 | } | 284 | } |
280 | } | 285 | } |
281 | 286 | ||
282 | void usb_serial_console_init (int serial_debug, int minor) | 287 | void usb_serial_console_init(int serial_debug, int minor) |
283 | { | 288 | { |
284 | debug = serial_debug; | 289 | debug = serial_debug; |
285 | 290 | ||
286 | if (minor == 0) { | 291 | if (minor == 0) { |
287 | /* | 292 | /* |
288 | * Call register_console() if this is the first device plugged | 293 | * Call register_console() if this is the first device plugged |
289 | * in. If we call it earlier, then the callback to | 294 | * in. If we call it earlier, then the callback to |
290 | * console_setup() will fail, as there is not a device seen by | 295 | * 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 | /* | 298 | /* |
294 | * Register console. | 299 | * Register console. |
295 | * NOTES: | 300 | * NOTES: |
296 | * console_setup() is called (back) immediately (from register_console). | 301 | * console_setup() is called (back) immediately (from |
297 | * console_write() is called immediately from register_console iff | 302 | * register_console). console_write() is called immediately |
298 | * CON_PRINTBUFFER is set in flags. | 303 | * from register_console iff CON_PRINTBUFFER is set in flags. |
299 | */ | 304 | */ |
300 | dbg ("registering the USB serial console."); | 305 | dbg("registering the USB serial console."); |
301 | register_console(&usbcons); | 306 | register_console(&usbcons); |
302 | } | 307 | } |
303 | } | 308 | } |
304 | 309 | ||
305 | void usb_serial_console_exit (void) | 310 | void usb_serial_console_exit(void) |
306 | { | 311 | { |
307 | if (usbcons_info.port) { | 312 | if (usbcons_info.port) { |
308 | unregister_console(&usbcons); | 313 | unregister_console(&usbcons); |