Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Driver core for serial ports |
3 | * | |
4 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. | |
5 | * | |
6 | * Copyright 1999 ARM Limited | |
7 | * Copyright (C) 2000-2001 Deep Blue Solutions Ltd. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 | */ | |
1da177e4 LT |
23 | #include <linux/module.h> |
24 | #include <linux/tty.h> | |
027d7dac | 25 | #include <linux/tty_flip.h> |
1da177e4 LT |
26 | #include <linux/slab.h> |
27 | #include <linux/init.h> | |
28 | #include <linux/console.h> | |
a208ffd2 | 29 | #include <linux/of.h> |
d196a949 AD |
30 | #include <linux/proc_fs.h> |
31 | #include <linux/seq_file.h> | |
1da177e4 LT |
32 | #include <linux/device.h> |
33 | #include <linux/serial.h> /* for serial_state and serial_icounter_struct */ | |
ccce6deb | 34 | #include <linux/serial_core.h> |
1da177e4 | 35 | #include <linux/delay.h> |
f392ecfa | 36 | #include <linux/mutex.h> |
1da177e4 LT |
37 | |
38 | #include <asm/irq.h> | |
39 | #include <asm/uaccess.h> | |
40 | ||
1da177e4 LT |
41 | /* |
42 | * This is used to lock changes in serial line configuration. | |
43 | */ | |
f392ecfa | 44 | static DEFINE_MUTEX(port_mutex); |
1da177e4 | 45 | |
13e83599 IM |
46 | /* |
47 | * lockdep: port->lock is initialized in two places, but we | |
48 | * want only one lock-class: | |
49 | */ | |
50 | static struct lock_class_key port_lock_key; | |
51 | ||
1da177e4 LT |
52 | #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8) |
53 | ||
19225135 | 54 | static void uart_change_speed(struct tty_struct *tty, struct uart_state *state, |
a46c9994 | 55 | struct ktermios *old_termios); |
1f33a51d | 56 | static void uart_wait_until_sent(struct tty_struct *tty, int timeout); |
6f538fe3 LW |
57 | static void uart_change_pm(struct uart_state *state, |
58 | enum uart_pm_state pm_state); | |
1da177e4 | 59 | |
b922e19d JS |
60 | static void uart_port_shutdown(struct tty_port *port); |
61 | ||
299245a1 PH |
62 | static int uart_dcd_enabled(struct uart_port *uport) |
63 | { | |
d4260b51 | 64 | return !!(uport->status & UPSTAT_DCD_ENABLE); |
299245a1 PH |
65 | } |
66 | ||
9ed19428 PH |
67 | static inline struct uart_port *uart_port_ref(struct uart_state *state) |
68 | { | |
69 | if (atomic_add_unless(&state->refcount, 1, 0)) | |
70 | return state->uart_port; | |
71 | return NULL; | |
72 | } | |
73 | ||
74 | static inline void uart_port_deref(struct uart_port *uport) | |
75 | { | |
76 | if (uport && atomic_dec_and_test(&uport->state->refcount)) | |
77 | wake_up(&uport->state->remove_wait); | |
78 | } | |
79 | ||
80 | #define uart_port_lock(state, flags) \ | |
81 | ({ \ | |
82 | struct uart_port *__uport = uart_port_ref(state); \ | |
83 | if (__uport) \ | |
84 | spin_lock_irqsave(&__uport->lock, flags); \ | |
85 | __uport; \ | |
86 | }) | |
87 | ||
88 | #define uart_port_unlock(uport, flags) \ | |
89 | ({ \ | |
90 | struct uart_port *__uport = uport; \ | |
91 | if (__uport) \ | |
92 | spin_unlock_irqrestore(&__uport->lock, flags); \ | |
93 | uart_port_deref(__uport); \ | |
94 | }) | |
95 | ||
4047b371 PH |
96 | static inline struct uart_port *uart_port_check(struct uart_state *state) |
97 | { | |
7da4b8b7 | 98 | lockdep_assert_held(&state->port.mutex); |
4047b371 PH |
99 | return state->uart_port; |
100 | } | |
101 | ||
1da177e4 LT |
102 | /* |
103 | * This routine is used by the interrupt handler to schedule processing in | |
104 | * the software interrupt portion of the driver. | |
105 | */ | |
106 | void uart_write_wakeup(struct uart_port *port) | |
107 | { | |
ebd2c8f6 | 108 | struct uart_state *state = port->state; |
d5f735e5 PM |
109 | /* |
110 | * This means you called this function _after_ the port was | |
111 | * closed. No cookie for you. | |
112 | */ | |
ebd2c8f6 | 113 | BUG_ON(!state); |
6a3e492b | 114 | tty_wakeup(state->port.tty); |
1da177e4 LT |
115 | } |
116 | ||
117 | static void uart_stop(struct tty_struct *tty) | |
118 | { | |
119 | struct uart_state *state = tty->driver_data; | |
9ed19428 | 120 | struct uart_port *port; |
1da177e4 LT |
121 | unsigned long flags; |
122 | ||
9ed19428 PH |
123 | port = uart_port_lock(state, flags); |
124 | if (port) | |
125 | port->ops->stop_tx(port); | |
126 | uart_port_unlock(port, flags); | |
1da177e4 LT |
127 | } |
128 | ||
129 | static void __uart_start(struct tty_struct *tty) | |
130 | { | |
131 | struct uart_state *state = tty->driver_data; | |
ebd2c8f6 | 132 | struct uart_port *port = state->uart_port; |
1da177e4 | 133 | |
9ed19428 | 134 | if (port && !uart_tx_stopped(port)) |
b129a8cc | 135 | port->ops->start_tx(port); |
1da177e4 LT |
136 | } |
137 | ||
138 | static void uart_start(struct tty_struct *tty) | |
139 | { | |
140 | struct uart_state *state = tty->driver_data; | |
9ed19428 | 141 | struct uart_port *port; |
1da177e4 LT |
142 | unsigned long flags; |
143 | ||
9ed19428 | 144 | port = uart_port_lock(state, flags); |
1da177e4 | 145 | __uart_start(tty); |
9ed19428 | 146 | uart_port_unlock(port, flags); |
1da177e4 LT |
147 | } |
148 | ||
f4581cab | 149 | static void |
1da177e4 LT |
150 | uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear) |
151 | { | |
152 | unsigned long flags; | |
153 | unsigned int old; | |
154 | ||
155 | spin_lock_irqsave(&port->lock, flags); | |
156 | old = port->mctrl; | |
157 | port->mctrl = (old & ~clear) | set; | |
158 | if (old != port->mctrl) | |
159 | port->ops->set_mctrl(port, port->mctrl); | |
160 | spin_unlock_irqrestore(&port->lock, flags); | |
161 | } | |
162 | ||
a46c9994 AC |
163 | #define uart_set_mctrl(port, set) uart_update_mctrl(port, set, 0) |
164 | #define uart_clear_mctrl(port, clear) uart_update_mctrl(port, 0, clear) | |
1da177e4 LT |
165 | |
166 | /* | |
167 | * Startup the port. This will be called once per open. All calls | |
df4f4dd4 | 168 | * will be serialised by the per-port mutex. |
1da177e4 | 169 | */ |
c0d92be6 JS |
170 | static int uart_port_startup(struct tty_struct *tty, struct uart_state *state, |
171 | int init_hw) | |
1da177e4 | 172 | { |
4047b371 | 173 | struct uart_port *uport = uart_port_check(state); |
1da177e4 LT |
174 | unsigned long page; |
175 | int retval = 0; | |
176 | ||
46d57a44 | 177 | if (uport->type == PORT_UNKNOWN) |
c0d92be6 | 178 | return 1; |
1da177e4 | 179 | |
7deb39ed TP |
180 | /* |
181 | * Make sure the device is in D0 state. | |
182 | */ | |
183 | uart_change_pm(state, UART_PM_STATE_ON); | |
184 | ||
1da177e4 LT |
185 | /* |
186 | * Initialise and allocate the transmit and temporary | |
187 | * buffer. | |
188 | */ | |
ebd2c8f6 | 189 | if (!state->xmit.buf) { |
df4f4dd4 | 190 | /* This is protected by the per port mutex */ |
1da177e4 LT |
191 | page = get_zeroed_page(GFP_KERNEL); |
192 | if (!page) | |
193 | return -ENOMEM; | |
194 | ||
ebd2c8f6 AC |
195 | state->xmit.buf = (unsigned char *) page; |
196 | uart_circ_clear(&state->xmit); | |
1da177e4 LT |
197 | } |
198 | ||
46d57a44 | 199 | retval = uport->ops->startup(uport); |
1da177e4 | 200 | if (retval == 0) { |
c7d7abff | 201 | if (uart_console(uport) && uport->cons->cflag) { |
adc8d746 | 202 | tty->termios.c_cflag = uport->cons->cflag; |
c7d7abff JS |
203 | uport->cons->cflag = 0; |
204 | } | |
205 | /* | |
206 | * Initialise the hardware port settings. | |
207 | */ | |
208 | uart_change_speed(tty, state, NULL); | |
1da177e4 | 209 | |
9db276f8 PH |
210 | /* |
211 | * Setup the RTS and DTR signals once the | |
212 | * port is open and ready to respond. | |
213 | */ | |
214 | if (init_hw && C_BAUD(tty)) | |
215 | uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR); | |
1da177e4 LT |
216 | } |
217 | ||
0055197e JS |
218 | /* |
219 | * This is to allow setserial on this port. People may want to set | |
220 | * port/irq/type and then reconfigure the port properly if it failed | |
221 | * now. | |
222 | */ | |
1da177e4 | 223 | if (retval && capable(CAP_SYS_ADMIN)) |
c0d92be6 JS |
224 | return 1; |
225 | ||
226 | return retval; | |
227 | } | |
228 | ||
229 | static int uart_startup(struct tty_struct *tty, struct uart_state *state, | |
230 | int init_hw) | |
231 | { | |
232 | struct tty_port *port = &state->port; | |
233 | int retval; | |
234 | ||
d41861ca | 235 | if (tty_port_initialized(port)) |
c0d92be6 JS |
236 | return 0; |
237 | ||
c0d92be6 | 238 | retval = uart_port_startup(tty, state, init_hw); |
b3b57646 RH |
239 | if (retval) |
240 | set_bit(TTY_IO_ERROR, &tty->flags); | |
1da177e4 LT |
241 | |
242 | return retval; | |
243 | } | |
244 | ||
245 | /* | |
246 | * This routine will shutdown a serial port; interrupts are disabled, and | |
247 | * DTR is dropped if the hangup on close termio flag is on. Calls to | |
248 | * uart_shutdown are serialised by the per-port semaphore. | |
af224ca2 PH |
249 | * |
250 | * uport == NULL if uart_port has already been removed | |
1da177e4 | 251 | */ |
19225135 | 252 | static void uart_shutdown(struct tty_struct *tty, struct uart_state *state) |
1da177e4 | 253 | { |
4047b371 | 254 | struct uart_port *uport = uart_port_check(state); |
bdc04e31 | 255 | struct tty_port *port = &state->port; |
1da177e4 | 256 | |
1da177e4 | 257 | /* |
ee31b337 | 258 | * Set the TTY IO error marker |
1da177e4 | 259 | */ |
f751928e AC |
260 | if (tty) |
261 | set_bit(TTY_IO_ERROR, &tty->flags); | |
1da177e4 | 262 | |
d41861ca PH |
263 | if (tty_port_initialized(port)) { |
264 | tty_port_set_initialized(port, 0); | |
265 | ||
ee31b337 RK |
266 | /* |
267 | * Turn off DTR and RTS early. | |
268 | */ | |
af224ca2 | 269 | if (uport && uart_console(uport) && tty) |
ae84db96 PH |
270 | uport->cons->cflag = tty->termios.c_cflag; |
271 | ||
9db276f8 | 272 | if (!tty || C_HUPCL(tty)) |
ccce6deb | 273 | uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS); |
ee31b337 | 274 | |
b922e19d | 275 | uart_port_shutdown(port); |
ee31b337 | 276 | } |
1da177e4 LT |
277 | |
278 | /* | |
d208a3bf DA |
279 | * It's possible for shutdown to be called after suspend if we get |
280 | * a DCD drop (hangup) at just the right time. Clear suspended bit so | |
281 | * we don't try to resume a port that has been shutdown. | |
1da177e4 | 282 | */ |
80f02d54 | 283 | tty_port_set_suspended(port, 0); |
1da177e4 LT |
284 | |
285 | /* | |
286 | * Free the transmit buffer page. | |
287 | */ | |
ebd2c8f6 AC |
288 | if (state->xmit.buf) { |
289 | free_page((unsigned long)state->xmit.buf); | |
290 | state->xmit.buf = NULL; | |
1da177e4 | 291 | } |
1da177e4 LT |
292 | } |
293 | ||
294 | /** | |
295 | * uart_update_timeout - update per-port FIFO timeout. | |
296 | * @port: uart_port structure describing the port | |
297 | * @cflag: termios cflag value | |
298 | * @baud: speed of the port | |
299 | * | |
300 | * Set the port FIFO timeout value. The @cflag value should | |
301 | * reflect the actual hardware settings. | |
302 | */ | |
303 | void | |
304 | uart_update_timeout(struct uart_port *port, unsigned int cflag, | |
305 | unsigned int baud) | |
306 | { | |
307 | unsigned int bits; | |
308 | ||
309 | /* byte size and parity */ | |
310 | switch (cflag & CSIZE) { | |
311 | case CS5: | |
312 | bits = 7; | |
313 | break; | |
314 | case CS6: | |
315 | bits = 8; | |
316 | break; | |
317 | case CS7: | |
318 | bits = 9; | |
319 | break; | |
320 | default: | |
321 | bits = 10; | |
a46c9994 | 322 | break; /* CS8 */ |
1da177e4 LT |
323 | } |
324 | ||
325 | if (cflag & CSTOPB) | |
326 | bits++; | |
327 | if (cflag & PARENB) | |
328 | bits++; | |
329 | ||
330 | /* | |
331 | * The total number of bits to be transmitted in the fifo. | |
332 | */ | |
333 | bits = bits * port->fifosize; | |
334 | ||
335 | /* | |
336 | * Figure the timeout to send the above number of bits. | |
337 | * Add .02 seconds of slop | |
338 | */ | |
339 | port->timeout = (HZ * bits) / baud + HZ/50; | |
340 | } | |
341 | ||
342 | EXPORT_SYMBOL(uart_update_timeout); | |
343 | ||
344 | /** | |
345 | * uart_get_baud_rate - return baud rate for a particular port | |
346 | * @port: uart_port structure describing the port in question. | |
347 | * @termios: desired termios settings. | |
348 | * @old: old termios (or NULL) | |
349 | * @min: minimum acceptable baud rate | |
350 | * @max: maximum acceptable baud rate | |
351 | * | |
352 | * Decode the termios structure into a numeric baud rate, | |
353 | * taking account of the magic 38400 baud rate (with spd_* | |
354 | * flags), and mapping the %B0 rate to 9600 baud. | |
355 | * | |
356 | * If the new baud rate is invalid, try the old termios setting. | |
357 | * If it's still invalid, we try 9600 baud. | |
358 | * | |
359 | * Update the @termios structure to reflect the baud rate | |
eb424fd2 AC |
360 | * we're actually going to be using. Don't do this for the case |
361 | * where B0 is requested ("hang up"). | |
1da177e4 LT |
362 | */ |
363 | unsigned int | |
606d099c AC |
364 | uart_get_baud_rate(struct uart_port *port, struct ktermios *termios, |
365 | struct ktermios *old, unsigned int min, unsigned int max) | |
1da177e4 | 366 | { |
f10a2233 JN |
367 | unsigned int try; |
368 | unsigned int baud; | |
369 | unsigned int altbaud; | |
eb424fd2 | 370 | int hung_up = 0; |
0077d45e | 371 | upf_t flags = port->flags & UPF_SPD_MASK; |
1da177e4 | 372 | |
f10a2233 JN |
373 | switch (flags) { |
374 | case UPF_SPD_HI: | |
1da177e4 | 375 | altbaud = 57600; |
f10a2233 JN |
376 | break; |
377 | case UPF_SPD_VHI: | |
1da177e4 | 378 | altbaud = 115200; |
f10a2233 JN |
379 | break; |
380 | case UPF_SPD_SHI: | |
1da177e4 | 381 | altbaud = 230400; |
f10a2233 JN |
382 | break; |
383 | case UPF_SPD_WARP: | |
1da177e4 | 384 | altbaud = 460800; |
f10a2233 JN |
385 | break; |
386 | default: | |
387 | altbaud = 38400; | |
388 | break; | |
389 | } | |
1da177e4 LT |
390 | |
391 | for (try = 0; try < 2; try++) { | |
392 | baud = tty_termios_baud_rate(termios); | |
393 | ||
394 | /* | |
395 | * The spd_hi, spd_vhi, spd_shi, spd_warp kludge... | |
396 | * Die! Die! Die! | |
397 | */ | |
547039ec | 398 | if (try == 0 && baud == 38400) |
1da177e4 LT |
399 | baud = altbaud; |
400 | ||
401 | /* | |
402 | * Special case: B0 rate. | |
403 | */ | |
eb424fd2 AC |
404 | if (baud == 0) { |
405 | hung_up = 1; | |
1da177e4 | 406 | baud = 9600; |
eb424fd2 | 407 | } |
1da177e4 LT |
408 | |
409 | if (baud >= min && baud <= max) | |
410 | return baud; | |
411 | ||
412 | /* | |
413 | * Oops, the quotient was zero. Try again with | |
414 | * the old baud rate if possible. | |
415 | */ | |
416 | termios->c_cflag &= ~CBAUD; | |
417 | if (old) { | |
6d4d67be | 418 | baud = tty_termios_baud_rate(old); |
eb424fd2 AC |
419 | if (!hung_up) |
420 | tty_termios_encode_baud_rate(termios, | |
421 | baud, baud); | |
1da177e4 LT |
422 | old = NULL; |
423 | continue; | |
424 | } | |
425 | ||
426 | /* | |
16ae2a87 AC |
427 | * As a last resort, if the range cannot be met then clip to |
428 | * the nearest chip supported rate. | |
1da177e4 | 429 | */ |
16ae2a87 AC |
430 | if (!hung_up) { |
431 | if (baud <= min) | |
432 | tty_termios_encode_baud_rate(termios, | |
433 | min + 1, min + 1); | |
434 | else | |
435 | tty_termios_encode_baud_rate(termios, | |
436 | max - 1, max - 1); | |
437 | } | |
1da177e4 | 438 | } |
16ae2a87 AC |
439 | /* Should never happen */ |
440 | WARN_ON(1); | |
1da177e4 LT |
441 | return 0; |
442 | } | |
443 | ||
444 | EXPORT_SYMBOL(uart_get_baud_rate); | |
445 | ||
446 | /** | |
447 | * uart_get_divisor - return uart clock divisor | |
448 | * @port: uart_port structure describing the port. | |
449 | * @baud: desired baud rate | |
450 | * | |
451 | * Calculate the uart clock divisor for the port. | |
452 | */ | |
453 | unsigned int | |
454 | uart_get_divisor(struct uart_port *port, unsigned int baud) | |
455 | { | |
456 | unsigned int quot; | |
457 | ||
458 | /* | |
459 | * Old custom speed handling. | |
460 | */ | |
461 | if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) | |
462 | quot = port->custom_divisor; | |
463 | else | |
97d24634 | 464 | quot = DIV_ROUND_CLOSEST(port->uartclk, 16 * baud); |
1da177e4 LT |
465 | |
466 | return quot; | |
467 | } | |
468 | ||
469 | EXPORT_SYMBOL(uart_get_divisor); | |
470 | ||
7c8ab967 | 471 | /* Caller holds port mutex */ |
19225135 AC |
472 | static void uart_change_speed(struct tty_struct *tty, struct uart_state *state, |
473 | struct ktermios *old_termios) | |
1da177e4 | 474 | { |
4047b371 | 475 | struct uart_port *uport = uart_port_check(state); |
606d099c | 476 | struct ktermios *termios; |
391f93f2 | 477 | int hw_stopped; |
1da177e4 LT |
478 | |
479 | /* | |
480 | * If we have no tty, termios, or the port does not exist, | |
481 | * then we can't set the parameters for this port. | |
482 | */ | |
adc8d746 | 483 | if (!tty || uport->type == PORT_UNKNOWN) |
1da177e4 LT |
484 | return; |
485 | ||
adc8d746 | 486 | termios = &tty->termios; |
c18b55fd | 487 | uport->ops->set_termios(uport, termios, old_termios); |
1da177e4 LT |
488 | |
489 | /* | |
299245a1 | 490 | * Set modem status enables based on termios cflag |
1da177e4 | 491 | */ |
299245a1 | 492 | spin_lock_irq(&uport->lock); |
1da177e4 | 493 | if (termios->c_cflag & CRTSCTS) |
299245a1 | 494 | uport->status |= UPSTAT_CTS_ENABLE; |
1da177e4 | 495 | else |
299245a1 | 496 | uport->status &= ~UPSTAT_CTS_ENABLE; |
1da177e4 LT |
497 | |
498 | if (termios->c_cflag & CLOCAL) | |
299245a1 | 499 | uport->status &= ~UPSTAT_DCD_ENABLE; |
1da177e4 | 500 | else |
299245a1 | 501 | uport->status |= UPSTAT_DCD_ENABLE; |
391f93f2 PH |
502 | |
503 | /* reset sw-assisted CTS flow control based on (possibly) new mode */ | |
504 | hw_stopped = uport->hw_stopped; | |
505 | uport->hw_stopped = uart_softcts_mode(uport) && | |
506 | !(uport->ops->get_mctrl(uport) & TIOCM_CTS); | |
507 | if (uport->hw_stopped) { | |
508 | if (!hw_stopped) | |
509 | uport->ops->stop_tx(uport); | |
510 | } else { | |
511 | if (hw_stopped) | |
512 | __uart_start(tty); | |
513 | } | |
299245a1 | 514 | spin_unlock_irq(&uport->lock); |
1da177e4 LT |
515 | } |
516 | ||
f5291ecc | 517 | static int uart_put_char(struct tty_struct *tty, unsigned char c) |
1da177e4 | 518 | { |
f5291ecc | 519 | struct uart_state *state = tty->driver_data; |
9ed19428 | 520 | struct uart_port *port; |
f5291ecc | 521 | struct circ_buf *circ; |
1da177e4 | 522 | unsigned long flags; |
23d22cea | 523 | int ret = 0; |
1da177e4 | 524 | |
f5291ecc | 525 | circ = &state->xmit; |
1da177e4 | 526 | if (!circ->buf) |
23d22cea | 527 | return 0; |
1da177e4 | 528 | |
9ed19428 PH |
529 | port = uart_port_lock(state, flags); |
530 | if (port && uart_circ_chars_free(circ) != 0) { | |
1da177e4 LT |
531 | circ->buf[circ->head] = c; |
532 | circ->head = (circ->head + 1) & (UART_XMIT_SIZE - 1); | |
23d22cea | 533 | ret = 1; |
1da177e4 | 534 | } |
9ed19428 | 535 | uart_port_unlock(port, flags); |
23d22cea | 536 | return ret; |
1da177e4 LT |
537 | } |
538 | ||
1da177e4 LT |
539 | static void uart_flush_chars(struct tty_struct *tty) |
540 | { | |
541 | uart_start(tty); | |
542 | } | |
543 | ||
19225135 AC |
544 | static int uart_write(struct tty_struct *tty, |
545 | const unsigned char *buf, int count) | |
1da177e4 LT |
546 | { |
547 | struct uart_state *state = tty->driver_data; | |
d5f735e5 PM |
548 | struct uart_port *port; |
549 | struct circ_buf *circ; | |
1da177e4 LT |
550 | unsigned long flags; |
551 | int c, ret = 0; | |
552 | ||
d5f735e5 PM |
553 | /* |
554 | * This means you called this function _after_ the port was | |
555 | * closed. No cookie for you. | |
556 | */ | |
f751928e | 557 | if (!state) { |
d5f735e5 PM |
558 | WARN_ON(1); |
559 | return -EL3HLT; | |
560 | } | |
561 | ||
ebd2c8f6 | 562 | circ = &state->xmit; |
1da177e4 LT |
563 | if (!circ->buf) |
564 | return 0; | |
565 | ||
9ed19428 PH |
566 | port = uart_port_lock(state, flags); |
567 | while (port) { | |
1da177e4 LT |
568 | c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE); |
569 | if (count < c) | |
570 | c = count; | |
571 | if (c <= 0) | |
572 | break; | |
573 | memcpy(circ->buf + circ->head, buf, c); | |
574 | circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1); | |
575 | buf += c; | |
576 | count -= c; | |
577 | ret += c; | |
578 | } | |
64dbee31 PH |
579 | |
580 | __uart_start(tty); | |
9ed19428 | 581 | uart_port_unlock(port, flags); |
1da177e4 LT |
582 | return ret; |
583 | } | |
584 | ||
585 | static int uart_write_room(struct tty_struct *tty) | |
586 | { | |
587 | struct uart_state *state = tty->driver_data; | |
9ed19428 | 588 | struct uart_port *port; |
f34d7a5b AC |
589 | unsigned long flags; |
590 | int ret; | |
1da177e4 | 591 | |
9ed19428 | 592 | port = uart_port_lock(state, flags); |
ebd2c8f6 | 593 | ret = uart_circ_chars_free(&state->xmit); |
9ed19428 | 594 | uart_port_unlock(port, flags); |
f34d7a5b | 595 | return ret; |
1da177e4 LT |
596 | } |
597 | ||
598 | static int uart_chars_in_buffer(struct tty_struct *tty) | |
599 | { | |
600 | struct uart_state *state = tty->driver_data; | |
9ed19428 | 601 | struct uart_port *port; |
f34d7a5b AC |
602 | unsigned long flags; |
603 | int ret; | |
1da177e4 | 604 | |
9ed19428 | 605 | port = uart_port_lock(state, flags); |
ebd2c8f6 | 606 | ret = uart_circ_chars_pending(&state->xmit); |
9ed19428 | 607 | uart_port_unlock(port, flags); |
f34d7a5b | 608 | return ret; |
1da177e4 LT |
609 | } |
610 | ||
611 | static void uart_flush_buffer(struct tty_struct *tty) | |
612 | { | |
613 | struct uart_state *state = tty->driver_data; | |
55d7b689 | 614 | struct uart_port *port; |
1da177e4 LT |
615 | unsigned long flags; |
616 | ||
d5f735e5 PM |
617 | /* |
618 | * This means you called this function _after_ the port was | |
619 | * closed. No cookie for you. | |
620 | */ | |
f751928e | 621 | if (!state) { |
d5f735e5 PM |
622 | WARN_ON(1); |
623 | return; | |
624 | } | |
625 | ||
eb3a1e11 | 626 | pr_debug("uart_flush_buffer(%d) called\n", tty->index); |
1da177e4 | 627 | |
9ed19428 PH |
628 | port = uart_port_lock(state, flags); |
629 | if (!port) | |
630 | return; | |
ebd2c8f6 | 631 | uart_circ_clear(&state->xmit); |
6bb0e3a5 HS |
632 | if (port->ops->flush_buffer) |
633 | port->ops->flush_buffer(port); | |
9ed19428 | 634 | uart_port_unlock(port, flags); |
1da177e4 LT |
635 | tty_wakeup(tty); |
636 | } | |
637 | ||
638 | /* | |
639 | * This function is used to send a high-priority XON/XOFF character to | |
640 | * the device | |
641 | */ | |
642 | static void uart_send_xchar(struct tty_struct *tty, char ch) | |
643 | { | |
644 | struct uart_state *state = tty->driver_data; | |
9ed19428 | 645 | struct uart_port *port; |
1da177e4 LT |
646 | unsigned long flags; |
647 | ||
9ed19428 PH |
648 | port = uart_port_ref(state); |
649 | if (!port) | |
650 | return; | |
651 | ||
1da177e4 LT |
652 | if (port->ops->send_xchar) |
653 | port->ops->send_xchar(port, ch); | |
654 | else { | |
c235ccc1 | 655 | spin_lock_irqsave(&port->lock, flags); |
1da177e4 | 656 | port->x_char = ch; |
c235ccc1 | 657 | if (ch) |
b129a8cc | 658 | port->ops->start_tx(port); |
c235ccc1 | 659 | spin_unlock_irqrestore(&port->lock, flags); |
1da177e4 | 660 | } |
9ed19428 | 661 | uart_port_deref(port); |
1da177e4 LT |
662 | } |
663 | ||
664 | static void uart_throttle(struct tty_struct *tty) | |
665 | { | |
666 | struct uart_state *state = tty->driver_data; | |
9ed19428 | 667 | struct uart_port *port; |
391f93f2 | 668 | upstat_t mask = 0; |
1da177e4 | 669 | |
9ed19428 PH |
670 | port = uart_port_ref(state); |
671 | if (!port) | |
672 | return; | |
673 | ||
1da177e4 | 674 | if (I_IXOFF(tty)) |
391f93f2 | 675 | mask |= UPSTAT_AUTOXOFF; |
9db276f8 | 676 | if (C_CRTSCTS(tty)) |
391f93f2 | 677 | mask |= UPSTAT_AUTORTS; |
9aba8d5b | 678 | |
391f93f2 | 679 | if (port->status & mask) { |
9aba8d5b | 680 | port->ops->throttle(port); |
391f93f2 | 681 | mask &= ~port->status; |
9aba8d5b RK |
682 | } |
683 | ||
391f93f2 | 684 | if (mask & UPSTAT_AUTORTS) |
9aba8d5b | 685 | uart_clear_mctrl(port, TIOCM_RTS); |
b4749b97 PH |
686 | |
687 | if (mask & UPSTAT_AUTOXOFF) | |
688 | uart_send_xchar(tty, STOP_CHAR(tty)); | |
9ed19428 PH |
689 | |
690 | uart_port_deref(port); | |
1da177e4 LT |
691 | } |
692 | ||
693 | static void uart_unthrottle(struct tty_struct *tty) | |
694 | { | |
695 | struct uart_state *state = tty->driver_data; | |
9ed19428 | 696 | struct uart_port *port; |
391f93f2 | 697 | upstat_t mask = 0; |
1da177e4 | 698 | |
9ed19428 PH |
699 | port = uart_port_ref(state); |
700 | if (!port) | |
701 | return; | |
702 | ||
9aba8d5b | 703 | if (I_IXOFF(tty)) |
391f93f2 | 704 | mask |= UPSTAT_AUTOXOFF; |
9db276f8 | 705 | if (C_CRTSCTS(tty)) |
391f93f2 | 706 | mask |= UPSTAT_AUTORTS; |
9aba8d5b | 707 | |
391f93f2 | 708 | if (port->status & mask) { |
9aba8d5b | 709 | port->ops->unthrottle(port); |
391f93f2 | 710 | mask &= ~port->status; |
9aba8d5b | 711 | } |
1da177e4 | 712 | |
391f93f2 | 713 | if (mask & UPSTAT_AUTORTS) |
1da177e4 | 714 | uart_set_mctrl(port, TIOCM_RTS); |
b4749b97 PH |
715 | |
716 | if (mask & UPSTAT_AUTOXOFF) | |
717 | uart_send_xchar(tty, START_CHAR(tty)); | |
9ed19428 PH |
718 | |
719 | uart_port_deref(port); | |
1da177e4 LT |
720 | } |
721 | ||
4047b371 | 722 | static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo) |
1da177e4 | 723 | { |
9f109694 | 724 | struct uart_state *state = container_of(port, struct uart_state, port); |
4047b371 PH |
725 | struct uart_port *uport; |
726 | int ret = -ENODEV; | |
f34d7a5b | 727 | |
37cd0c99 | 728 | memset(retinfo, 0, sizeof(*retinfo)); |
f34d7a5b | 729 | |
3abe8c76 PH |
730 | /* |
731 | * Ensure the state we copy is consistent and no hardware changes | |
732 | * occur as we go | |
733 | */ | |
734 | mutex_lock(&port->mutex); | |
4047b371 PH |
735 | uport = uart_port_check(state); |
736 | if (!uport) | |
737 | goto out; | |
738 | ||
7ba2e769 AC |
739 | retinfo->type = uport->type; |
740 | retinfo->line = uport->line; | |
741 | retinfo->port = uport->iobase; | |
1da177e4 | 742 | if (HIGH_BITS_OFFSET) |
7ba2e769 AC |
743 | retinfo->port_high = (long) uport->iobase >> HIGH_BITS_OFFSET; |
744 | retinfo->irq = uport->irq; | |
745 | retinfo->flags = uport->flags; | |
746 | retinfo->xmit_fifo_size = uport->fifosize; | |
747 | retinfo->baud_base = uport->uartclk / 16; | |
748 | retinfo->close_delay = jiffies_to_msecs(port->close_delay) / 10; | |
749 | retinfo->closing_wait = port->closing_wait == ASYNC_CLOSING_WAIT_NONE ? | |
1da177e4 | 750 | ASYNC_CLOSING_WAIT_NONE : |
4cb0fbfd | 751 | jiffies_to_msecs(port->closing_wait) / 10; |
7ba2e769 AC |
752 | retinfo->custom_divisor = uport->custom_divisor; |
753 | retinfo->hub6 = uport->hub6; | |
754 | retinfo->io_type = uport->iotype; | |
755 | retinfo->iomem_reg_shift = uport->regshift; | |
756 | retinfo->iomem_base = (void *)(unsigned long)uport->mapbase; | |
4047b371 PH |
757 | |
758 | ret = 0; | |
759 | out: | |
a2bceae0 | 760 | mutex_unlock(&port->mutex); |
4047b371 | 761 | return ret; |
9f109694 AC |
762 | } |
763 | ||
764 | static int uart_get_info_user(struct tty_port *port, | |
765 | struct serial_struct __user *retinfo) | |
766 | { | |
767 | struct serial_struct tmp; | |
3abe8c76 | 768 | |
4047b371 PH |
769 | if (uart_get_info(port, &tmp) < 0) |
770 | return -EIO; | |
f34d7a5b | 771 | |
1da177e4 LT |
772 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
773 | return -EFAULT; | |
774 | return 0; | |
775 | } | |
776 | ||
7ba2e769 AC |
777 | static int uart_set_info(struct tty_struct *tty, struct tty_port *port, |
778 | struct uart_state *state, | |
779 | struct serial_struct *new_info) | |
1da177e4 | 780 | { |
4047b371 | 781 | struct uart_port *uport = uart_port_check(state); |
1da177e4 | 782 | unsigned long new_port; |
0077d45e | 783 | unsigned int change_irq, change_port, closing_wait; |
1da177e4 | 784 | unsigned int old_custom_divisor, close_delay; |
0077d45e | 785 | upf_t old_flags, new_flags; |
1da177e4 LT |
786 | int retval = 0; |
787 | ||
4047b371 PH |
788 | if (!uport) |
789 | return -EIO; | |
790 | ||
7ba2e769 | 791 | new_port = new_info->port; |
1da177e4 | 792 | if (HIGH_BITS_OFFSET) |
7ba2e769 | 793 | new_port += (unsigned long) new_info->port_high << HIGH_BITS_OFFSET; |
1da177e4 | 794 | |
7ba2e769 AC |
795 | new_info->irq = irq_canonicalize(new_info->irq); |
796 | close_delay = msecs_to_jiffies(new_info->close_delay * 10); | |
797 | closing_wait = new_info->closing_wait == ASYNC_CLOSING_WAIT_NONE ? | |
4cb0fbfd | 798 | ASYNC_CLOSING_WAIT_NONE : |
7ba2e769 | 799 | msecs_to_jiffies(new_info->closing_wait * 10); |
1da177e4 | 800 | |
1da177e4 | 801 | |
46d57a44 | 802 | change_irq = !(uport->flags & UPF_FIXED_PORT) |
7ba2e769 | 803 | && new_info->irq != uport->irq; |
1da177e4 LT |
804 | |
805 | /* | |
806 | * Since changing the 'type' of the port changes its resource | |
807 | * allocations, we should treat type changes the same as | |
808 | * IO port changes. | |
809 | */ | |
46d57a44 AC |
810 | change_port = !(uport->flags & UPF_FIXED_PORT) |
811 | && (new_port != uport->iobase || | |
7ba2e769 AC |
812 | (unsigned long)new_info->iomem_base != uport->mapbase || |
813 | new_info->hub6 != uport->hub6 || | |
814 | new_info->io_type != uport->iotype || | |
815 | new_info->iomem_reg_shift != uport->regshift || | |
816 | new_info->type != uport->type); | |
46d57a44 AC |
817 | |
818 | old_flags = uport->flags; | |
7ba2e769 | 819 | new_flags = new_info->flags; |
46d57a44 | 820 | old_custom_divisor = uport->custom_divisor; |
1da177e4 LT |
821 | |
822 | if (!capable(CAP_SYS_ADMIN)) { | |
823 | retval = -EPERM; | |
824 | if (change_irq || change_port || | |
7ba2e769 | 825 | (new_info->baud_base != uport->uartclk / 16) || |
46d57a44 AC |
826 | (close_delay != port->close_delay) || |
827 | (closing_wait != port->closing_wait) || | |
7ba2e769 AC |
828 | (new_info->xmit_fifo_size && |
829 | new_info->xmit_fifo_size != uport->fifosize) || | |
0077d45e | 830 | (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0)) |
1da177e4 | 831 | goto exit; |
46d57a44 | 832 | uport->flags = ((uport->flags & ~UPF_USR_MASK) | |
0077d45e | 833 | (new_flags & UPF_USR_MASK)); |
7ba2e769 | 834 | uport->custom_divisor = new_info->custom_divisor; |
1da177e4 LT |
835 | goto check_and_exit; |
836 | } | |
837 | ||
838 | /* | |
839 | * Ask the low level driver to verify the settings. | |
840 | */ | |
46d57a44 | 841 | if (uport->ops->verify_port) |
7ba2e769 | 842 | retval = uport->ops->verify_port(uport, new_info); |
1da177e4 | 843 | |
7ba2e769 AC |
844 | if ((new_info->irq >= nr_irqs) || (new_info->irq < 0) || |
845 | (new_info->baud_base < 9600)) | |
1da177e4 LT |
846 | retval = -EINVAL; |
847 | ||
848 | if (retval) | |
849 | goto exit; | |
850 | ||
851 | if (change_port || change_irq) { | |
852 | retval = -EBUSY; | |
853 | ||
854 | /* | |
855 | * Make sure that we are the sole user of this port. | |
856 | */ | |
b58d13a0 | 857 | if (tty_port_users(port) > 1) |
1da177e4 LT |
858 | goto exit; |
859 | ||
860 | /* | |
861 | * We need to shutdown the serial port at the old | |
862 | * port/type/irq combination. | |
863 | */ | |
19225135 | 864 | uart_shutdown(tty, state); |
1da177e4 LT |
865 | } |
866 | ||
867 | if (change_port) { | |
868 | unsigned long old_iobase, old_mapbase; | |
869 | unsigned int old_type, old_iotype, old_hub6, old_shift; | |
870 | ||
46d57a44 AC |
871 | old_iobase = uport->iobase; |
872 | old_mapbase = uport->mapbase; | |
873 | old_type = uport->type; | |
874 | old_hub6 = uport->hub6; | |
875 | old_iotype = uport->iotype; | |
876 | old_shift = uport->regshift; | |
1da177e4 LT |
877 | |
878 | /* | |
879 | * Free and release old regions | |
880 | */ | |
a7cfaf16 | 881 | if (old_type != PORT_UNKNOWN && uport->ops->release_port) |
46d57a44 | 882 | uport->ops->release_port(uport); |
1da177e4 | 883 | |
46d57a44 | 884 | uport->iobase = new_port; |
7ba2e769 AC |
885 | uport->type = new_info->type; |
886 | uport->hub6 = new_info->hub6; | |
887 | uport->iotype = new_info->io_type; | |
888 | uport->regshift = new_info->iomem_reg_shift; | |
889 | uport->mapbase = (unsigned long)new_info->iomem_base; | |
1da177e4 LT |
890 | |
891 | /* | |
892 | * Claim and map the new regions | |
893 | */ | |
a7cfaf16 | 894 | if (uport->type != PORT_UNKNOWN && uport->ops->request_port) { |
46d57a44 | 895 | retval = uport->ops->request_port(uport); |
1da177e4 LT |
896 | } else { |
897 | /* Always success - Jean II */ | |
898 | retval = 0; | |
899 | } | |
900 | ||
901 | /* | |
902 | * If we fail to request resources for the | |
903 | * new port, try to restore the old settings. | |
904 | */ | |
7deb39ed | 905 | if (retval) { |
46d57a44 AC |
906 | uport->iobase = old_iobase; |
907 | uport->type = old_type; | |
908 | uport->hub6 = old_hub6; | |
909 | uport->iotype = old_iotype; | |
910 | uport->regshift = old_shift; | |
911 | uport->mapbase = old_mapbase; | |
1da177e4 | 912 | |
7deb39ed TP |
913 | if (old_type != PORT_UNKNOWN) { |
914 | retval = uport->ops->request_port(uport); | |
915 | /* | |
916 | * If we failed to restore the old settings, | |
917 | * we fail like this. | |
918 | */ | |
919 | if (retval) | |
920 | uport->type = PORT_UNKNOWN; | |
921 | ||
922 | /* | |
923 | * We failed anyway. | |
924 | */ | |
925 | retval = -EBUSY; | |
926 | } | |
927 | ||
a46c9994 AC |
928 | /* Added to return the correct error -Ram Gupta */ |
929 | goto exit; | |
1da177e4 LT |
930 | } |
931 | } | |
932 | ||
abb4a239 | 933 | if (change_irq) |
7ba2e769 | 934 | uport->irq = new_info->irq; |
46d57a44 | 935 | if (!(uport->flags & UPF_FIXED_PORT)) |
7ba2e769 | 936 | uport->uartclk = new_info->baud_base * 16; |
46d57a44 | 937 | uport->flags = (uport->flags & ~UPF_CHANGE_MASK) | |
0077d45e | 938 | (new_flags & UPF_CHANGE_MASK); |
7ba2e769 | 939 | uport->custom_divisor = new_info->custom_divisor; |
46d57a44 AC |
940 | port->close_delay = close_delay; |
941 | port->closing_wait = closing_wait; | |
7ba2e769 AC |
942 | if (new_info->xmit_fifo_size) |
943 | uport->fifosize = new_info->xmit_fifo_size; | |
d6c53c0e | 944 | port->low_latency = (uport->flags & UPF_LOW_LATENCY) ? 1 : 0; |
1da177e4 LT |
945 | |
946 | check_and_exit: | |
947 | retval = 0; | |
46d57a44 | 948 | if (uport->type == PORT_UNKNOWN) |
1da177e4 | 949 | goto exit; |
d41861ca | 950 | if (tty_port_initialized(port)) { |
46d57a44 AC |
951 | if (((old_flags ^ uport->flags) & UPF_SPD_MASK) || |
952 | old_custom_divisor != uport->custom_divisor) { | |
1da177e4 LT |
953 | /* |
954 | * If they're setting up a custom divisor or speed, | |
955 | * instead of clearing it, then bitch about it. No | |
956 | * need to rate-limit; it's CAP_SYS_ADMIN only. | |
957 | */ | |
46d57a44 | 958 | if (uport->flags & UPF_SPD_MASK) { |
2f2dafe7 SM |
959 | dev_notice(uport->dev, |
960 | "%s sets custom speed on %s. This is deprecated.\n", | |
961 | current->comm, | |
429b4749 | 962 | tty_name(port->tty)); |
1da177e4 | 963 | } |
19225135 | 964 | uart_change_speed(tty, state, NULL); |
1da177e4 | 965 | } |
b3b57646 | 966 | } else { |
19225135 | 967 | retval = uart_startup(tty, state, 1); |
b3b57646 RH |
968 | if (retval > 0) |
969 | retval = 0; | |
970 | } | |
1da177e4 | 971 | exit: |
7ba2e769 AC |
972 | return retval; |
973 | } | |
974 | ||
975 | static int uart_set_info_user(struct tty_struct *tty, struct uart_state *state, | |
976 | struct serial_struct __user *newinfo) | |
977 | { | |
978 | struct serial_struct new_serial; | |
979 | struct tty_port *port = &state->port; | |
980 | int retval; | |
981 | ||
982 | if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) | |
983 | return -EFAULT; | |
984 | ||
985 | /* | |
986 | * This semaphore protects port->count. It is also | |
987 | * very useful to prevent opens. Also, take the | |
988 | * port configuration semaphore to make sure that a | |
989 | * module insertion/removal doesn't change anything | |
990 | * under us. | |
991 | */ | |
992 | mutex_lock(&port->mutex); | |
993 | retval = uart_set_info(tty, port, state, &new_serial); | |
a2bceae0 | 994 | mutex_unlock(&port->mutex); |
1da177e4 LT |
995 | return retval; |
996 | } | |
997 | ||
19225135 AC |
998 | /** |
999 | * uart_get_lsr_info - get line status register info | |
1000 | * @tty: tty associated with the UART | |
1001 | * @state: UART being queried | |
1002 | * @value: returned modem value | |
1da177e4 | 1003 | */ |
19225135 AC |
1004 | static int uart_get_lsr_info(struct tty_struct *tty, |
1005 | struct uart_state *state, unsigned int __user *value) | |
1da177e4 | 1006 | { |
4047b371 | 1007 | struct uart_port *uport = uart_port_check(state); |
1da177e4 LT |
1008 | unsigned int result; |
1009 | ||
46d57a44 | 1010 | result = uport->ops->tx_empty(uport); |
1da177e4 LT |
1011 | |
1012 | /* | |
1013 | * If we're about to load something into the transmit | |
1014 | * register, we'll pretend the transmitter isn't empty to | |
1015 | * avoid a race condition (depending on when the transmit | |
1016 | * interrupt happens). | |
1017 | */ | |
46d57a44 | 1018 | if (uport->x_char || |
ebd2c8f6 | 1019 | ((uart_circ_chars_pending(&state->xmit) > 0) && |
d01f4d18 | 1020 | !uart_tx_stopped(uport))) |
1da177e4 | 1021 | result &= ~TIOCSER_TEMT; |
a46c9994 | 1022 | |
1da177e4 LT |
1023 | return put_user(result, value); |
1024 | } | |
1025 | ||
60b33c13 | 1026 | static int uart_tiocmget(struct tty_struct *tty) |
1da177e4 LT |
1027 | { |
1028 | struct uart_state *state = tty->driver_data; | |
a2bceae0 | 1029 | struct tty_port *port = &state->port; |
4047b371 | 1030 | struct uart_port *uport; |
1da177e4 LT |
1031 | int result = -EIO; |
1032 | ||
a2bceae0 | 1033 | mutex_lock(&port->mutex); |
4047b371 PH |
1034 | uport = uart_port_check(state); |
1035 | if (!uport) | |
1036 | goto out; | |
1037 | ||
18900ca6 | 1038 | if (!tty_io_error(tty)) { |
46d57a44 | 1039 | result = uport->mctrl; |
46d57a44 AC |
1040 | spin_lock_irq(&uport->lock); |
1041 | result |= uport->ops->get_mctrl(uport); | |
1042 | spin_unlock_irq(&uport->lock); | |
1da177e4 | 1043 | } |
4047b371 | 1044 | out: |
a2bceae0 | 1045 | mutex_unlock(&port->mutex); |
1da177e4 LT |
1046 | return result; |
1047 | } | |
1048 | ||
1049 | static int | |
20b9d177 | 1050 | uart_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) |
1da177e4 LT |
1051 | { |
1052 | struct uart_state *state = tty->driver_data; | |
a2bceae0 | 1053 | struct tty_port *port = &state->port; |
4047b371 | 1054 | struct uart_port *uport; |
1da177e4 LT |
1055 | int ret = -EIO; |
1056 | ||
a2bceae0 | 1057 | mutex_lock(&port->mutex); |
4047b371 PH |
1058 | uport = uart_port_check(state); |
1059 | if (!uport) | |
1060 | goto out; | |
1061 | ||
18900ca6 | 1062 | if (!tty_io_error(tty)) { |
46d57a44 | 1063 | uart_update_mctrl(uport, set, clear); |
1da177e4 LT |
1064 | ret = 0; |
1065 | } | |
4047b371 | 1066 | out: |
a2bceae0 | 1067 | mutex_unlock(&port->mutex); |
1da177e4 LT |
1068 | return ret; |
1069 | } | |
1070 | ||
9e98966c | 1071 | static int uart_break_ctl(struct tty_struct *tty, int break_state) |
1da177e4 LT |
1072 | { |
1073 | struct uart_state *state = tty->driver_data; | |
a2bceae0 | 1074 | struct tty_port *port = &state->port; |
4047b371 PH |
1075 | struct uart_port *uport; |
1076 | int ret = -EIO; | |
1da177e4 | 1077 | |
a2bceae0 | 1078 | mutex_lock(&port->mutex); |
4047b371 PH |
1079 | uport = uart_port_check(state); |
1080 | if (!uport) | |
1081 | goto out; | |
1da177e4 | 1082 | |
46d57a44 AC |
1083 | if (uport->type != PORT_UNKNOWN) |
1084 | uport->ops->break_ctl(uport, break_state); | |
4047b371 PH |
1085 | ret = 0; |
1086 | out: | |
a2bceae0 | 1087 | mutex_unlock(&port->mutex); |
4047b371 | 1088 | return ret; |
1da177e4 LT |
1089 | } |
1090 | ||
19225135 | 1091 | static int uart_do_autoconfig(struct tty_struct *tty,struct uart_state *state) |
1da177e4 | 1092 | { |
a2bceae0 | 1093 | struct tty_port *port = &state->port; |
4047b371 | 1094 | struct uart_port *uport; |
1da177e4 LT |
1095 | int flags, ret; |
1096 | ||
1097 | if (!capable(CAP_SYS_ADMIN)) | |
1098 | return -EPERM; | |
1099 | ||
1100 | /* | |
1101 | * Take the per-port semaphore. This prevents count from | |
1102 | * changing, and hence any extra opens of the port while | |
1103 | * we're auto-configuring. | |
1104 | */ | |
a2bceae0 | 1105 | if (mutex_lock_interruptible(&port->mutex)) |
1da177e4 LT |
1106 | return -ERESTARTSYS; |
1107 | ||
4047b371 PH |
1108 | uport = uart_port_check(state); |
1109 | if (!uport) { | |
1110 | ret = -EIO; | |
1111 | goto out; | |
1112 | } | |
1113 | ||
1da177e4 | 1114 | ret = -EBUSY; |
b58d13a0 | 1115 | if (tty_port_users(port) == 1) { |
19225135 | 1116 | uart_shutdown(tty, state); |
1da177e4 LT |
1117 | |
1118 | /* | |
1119 | * If we already have a port type configured, | |
1120 | * we must release its resources. | |
1121 | */ | |
a7cfaf16 | 1122 | if (uport->type != PORT_UNKNOWN && uport->ops->release_port) |
46d57a44 | 1123 | uport->ops->release_port(uport); |
1da177e4 LT |
1124 | |
1125 | flags = UART_CONFIG_TYPE; | |
46d57a44 | 1126 | if (uport->flags & UPF_AUTO_IRQ) |
1da177e4 LT |
1127 | flags |= UART_CONFIG_IRQ; |
1128 | ||
1129 | /* | |
1130 | * This will claim the ports resources if | |
1131 | * a port is found. | |
1132 | */ | |
46d57a44 | 1133 | uport->ops->config_port(uport, flags); |
1da177e4 | 1134 | |
19225135 | 1135 | ret = uart_startup(tty, state, 1); |
b3b57646 RH |
1136 | if (ret > 0) |
1137 | ret = 0; | |
1da177e4 | 1138 | } |
4047b371 | 1139 | out: |
a2bceae0 | 1140 | mutex_unlock(&port->mutex); |
1da177e4 LT |
1141 | return ret; |
1142 | } | |
1143 | ||
1fdc3106 AS |
1144 | static void uart_enable_ms(struct uart_port *uport) |
1145 | { | |
1146 | /* | |
1147 | * Force modem status interrupts on | |
1148 | */ | |
1149 | if (uport->ops->enable_ms) | |
1150 | uport->ops->enable_ms(uport); | |
1151 | } | |
1152 | ||
1da177e4 LT |
1153 | /* |
1154 | * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change | |
1155 | * - mask passed in arg for lines of interest | |
1156 | * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) | |
1157 | * Caller should use TIOCGICOUNT to see which one it was | |
bdc04e31 AC |
1158 | * |
1159 | * FIXME: This wants extracting into a common all driver implementation | |
1160 | * of TIOCMWAIT using tty_port. | |
1da177e4 | 1161 | */ |
9ed19428 | 1162 | static int uart_wait_modem_status(struct uart_state *state, unsigned long arg) |
1da177e4 | 1163 | { |
9ed19428 | 1164 | struct uart_port *uport; |
bdc04e31 | 1165 | struct tty_port *port = &state->port; |
1da177e4 LT |
1166 | DECLARE_WAITQUEUE(wait, current); |
1167 | struct uart_icount cprev, cnow; | |
1168 | int ret; | |
1169 | ||
1170 | /* | |
1171 | * note the counters on entry | |
1172 | */ | |
9ed19428 PH |
1173 | uport = uart_port_ref(state); |
1174 | if (!uport) | |
1175 | return -EIO; | |
46d57a44 AC |
1176 | spin_lock_irq(&uport->lock); |
1177 | memcpy(&cprev, &uport->icount, sizeof(struct uart_icount)); | |
1fdc3106 | 1178 | uart_enable_ms(uport); |
46d57a44 | 1179 | spin_unlock_irq(&uport->lock); |
1da177e4 | 1180 | |
bdc04e31 | 1181 | add_wait_queue(&port->delta_msr_wait, &wait); |
1da177e4 | 1182 | for (;;) { |
46d57a44 AC |
1183 | spin_lock_irq(&uport->lock); |
1184 | memcpy(&cnow, &uport->icount, sizeof(struct uart_icount)); | |
1185 | spin_unlock_irq(&uport->lock); | |
1da177e4 LT |
1186 | |
1187 | set_current_state(TASK_INTERRUPTIBLE); | |
1188 | ||
1189 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || | |
1190 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || | |
1191 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || | |
1192 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { | |
a46c9994 AC |
1193 | ret = 0; |
1194 | break; | |
1da177e4 LT |
1195 | } |
1196 | ||
1197 | schedule(); | |
1198 | ||
1199 | /* see if a signal did it */ | |
1200 | if (signal_pending(current)) { | |
1201 | ret = -ERESTARTSYS; | |
1202 | break; | |
1203 | } | |
1204 | ||
1205 | cprev = cnow; | |
1206 | } | |
97f9f707 | 1207 | __set_current_state(TASK_RUNNING); |
bdc04e31 | 1208 | remove_wait_queue(&port->delta_msr_wait, &wait); |
9ed19428 | 1209 | uart_port_deref(uport); |
1da177e4 LT |
1210 | |
1211 | return ret; | |
1212 | } | |
1213 | ||
1214 | /* | |
1215 | * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) | |
1216 | * Return: write counters to the user passed counter struct | |
1217 | * NB: both 1->0 and 0->1 transitions are counted except for | |
1218 | * RI where only 0->1 is counted. | |
1219 | */ | |
d281da7f AC |
1220 | static int uart_get_icount(struct tty_struct *tty, |
1221 | struct serial_icounter_struct *icount) | |
1da177e4 | 1222 | { |
d281da7f | 1223 | struct uart_state *state = tty->driver_data; |
1da177e4 | 1224 | struct uart_icount cnow; |
9ed19428 | 1225 | struct uart_port *uport; |
1da177e4 | 1226 | |
9ed19428 PH |
1227 | uport = uart_port_ref(state); |
1228 | if (!uport) | |
1229 | return -EIO; | |
46d57a44 AC |
1230 | spin_lock_irq(&uport->lock); |
1231 | memcpy(&cnow, &uport->icount, sizeof(struct uart_icount)); | |
1232 | spin_unlock_irq(&uport->lock); | |
9ed19428 | 1233 | uart_port_deref(uport); |
1da177e4 | 1234 | |
d281da7f AC |
1235 | icount->cts = cnow.cts; |
1236 | icount->dsr = cnow.dsr; | |
1237 | icount->rng = cnow.rng; | |
1238 | icount->dcd = cnow.dcd; | |
1239 | icount->rx = cnow.rx; | |
1240 | icount->tx = cnow.tx; | |
1241 | icount->frame = cnow.frame; | |
1242 | icount->overrun = cnow.overrun; | |
1243 | icount->parity = cnow.parity; | |
1244 | icount->brk = cnow.brk; | |
1245 | icount->buf_overrun = cnow.buf_overrun; | |
1246 | ||
1247 | return 0; | |
1da177e4 LT |
1248 | } |
1249 | ||
a5f276f1 RRD |
1250 | static int uart_get_rs485_config(struct uart_port *port, |
1251 | struct serial_rs485 __user *rs485) | |
1252 | { | |
bd737f87 RRD |
1253 | unsigned long flags; |
1254 | struct serial_rs485 aux; | |
1255 | ||
1256 | spin_lock_irqsave(&port->lock, flags); | |
1257 | aux = port->rs485; | |
1258 | spin_unlock_irqrestore(&port->lock, flags); | |
1259 | ||
1260 | if (copy_to_user(rs485, &aux, sizeof(aux))) | |
a5f276f1 | 1261 | return -EFAULT; |
bd737f87 | 1262 | |
a5f276f1 RRD |
1263 | return 0; |
1264 | } | |
1265 | ||
1266 | static int uart_set_rs485_config(struct uart_port *port, | |
1267 | struct serial_rs485 __user *rs485_user) | |
1268 | { | |
1269 | struct serial_rs485 rs485; | |
1270 | int ret; | |
bd737f87 | 1271 | unsigned long flags; |
a5f276f1 RRD |
1272 | |
1273 | if (!port->rs485_config) | |
1274 | return -ENOIOCTLCMD; | |
1275 | ||
1276 | if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user))) | |
1277 | return -EFAULT; | |
1278 | ||
bd737f87 | 1279 | spin_lock_irqsave(&port->lock, flags); |
a5f276f1 | 1280 | ret = port->rs485_config(port, &rs485); |
bd737f87 | 1281 | spin_unlock_irqrestore(&port->lock, flags); |
a5f276f1 RRD |
1282 | if (ret) |
1283 | return ret; | |
1284 | ||
1285 | if (copy_to_user(rs485_user, &port->rs485, sizeof(port->rs485))) | |
1286 | return -EFAULT; | |
1287 | ||
1288 | return 0; | |
1289 | } | |
1290 | ||
1da177e4 | 1291 | /* |
e5238442 | 1292 | * Called via sys_ioctl. We can use spin_lock_irq() here. |
1da177e4 LT |
1293 | */ |
1294 | static int | |
4047b371 | 1295 | uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) |
1da177e4 LT |
1296 | { |
1297 | struct uart_state *state = tty->driver_data; | |
a2bceae0 | 1298 | struct tty_port *port = &state->port; |
4047b371 | 1299 | struct uart_port *uport; |
1da177e4 LT |
1300 | void __user *uarg = (void __user *)arg; |
1301 | int ret = -ENOIOCTLCMD; | |
1302 | ||
1da177e4 LT |
1303 | |
1304 | /* | |
1305 | * These ioctls don't rely on the hardware to be present. | |
1306 | */ | |
1307 | switch (cmd) { | |
1308 | case TIOCGSERIAL: | |
9f109694 | 1309 | ret = uart_get_info_user(port, uarg); |
1da177e4 LT |
1310 | break; |
1311 | ||
1312 | case TIOCSSERIAL: | |
7c8ab967 | 1313 | down_write(&tty->termios_rwsem); |
7ba2e769 | 1314 | ret = uart_set_info_user(tty, state, uarg); |
7c8ab967 | 1315 | up_write(&tty->termios_rwsem); |
1da177e4 LT |
1316 | break; |
1317 | ||
1318 | case TIOCSERCONFIG: | |
7c8ab967 | 1319 | down_write(&tty->termios_rwsem); |
19225135 | 1320 | ret = uart_do_autoconfig(tty, state); |
7c8ab967 | 1321 | up_write(&tty->termios_rwsem); |
1da177e4 LT |
1322 | break; |
1323 | ||
1324 | case TIOCSERGWILD: /* obsolete */ | |
1325 | case TIOCSERSWILD: /* obsolete */ | |
1326 | ret = 0; | |
1327 | break; | |
1328 | } | |
1329 | ||
1330 | if (ret != -ENOIOCTLCMD) | |
1331 | goto out; | |
1332 | ||
18900ca6 | 1333 | if (tty_io_error(tty)) { |
1da177e4 LT |
1334 | ret = -EIO; |
1335 | goto out; | |
1336 | } | |
1337 | ||
1338 | /* | |
1339 | * The following should only be used when hardware is present. | |
1340 | */ | |
1341 | switch (cmd) { | |
1342 | case TIOCMIWAIT: | |
1343 | ret = uart_wait_modem_status(state, arg); | |
1344 | break; | |
1da177e4 LT |
1345 | } |
1346 | ||
1347 | if (ret != -ENOIOCTLCMD) | |
1348 | goto out; | |
1349 | ||
a2bceae0 | 1350 | mutex_lock(&port->mutex); |
4047b371 | 1351 | uport = uart_port_check(state); |
1da177e4 | 1352 | |
4047b371 | 1353 | if (!uport || tty_io_error(tty)) { |
1da177e4 LT |
1354 | ret = -EIO; |
1355 | goto out_up; | |
1356 | } | |
1357 | ||
1358 | /* | |
1359 | * All these rely on hardware being present and need to be | |
1360 | * protected against the tty being hung up. | |
1361 | */ | |
a9c20a9c | 1362 | |
1da177e4 | 1363 | switch (cmd) { |
a9c20a9c RRD |
1364 | case TIOCSERGETLSR: /* Get line status register */ |
1365 | ret = uart_get_lsr_info(tty, state, uarg); | |
1366 | break; | |
1367 | ||
a5f276f1 | 1368 | case TIOCGRS485: |
4047b371 | 1369 | ret = uart_get_rs485_config(uport, uarg); |
a5f276f1 RRD |
1370 | break; |
1371 | ||
1372 | case TIOCSRS485: | |
4047b371 | 1373 | ret = uart_set_rs485_config(uport, uarg); |
a5f276f1 | 1374 | break; |
4047b371 | 1375 | default: |
46d57a44 AC |
1376 | if (uport->ops->ioctl) |
1377 | ret = uport->ops->ioctl(uport, cmd, arg); | |
1da177e4 LT |
1378 | break; |
1379 | } | |
f34d7a5b | 1380 | out_up: |
a2bceae0 | 1381 | mutex_unlock(&port->mutex); |
f34d7a5b | 1382 | out: |
1da177e4 LT |
1383 | return ret; |
1384 | } | |
1385 | ||
edeb280e | 1386 | static void uart_set_ldisc(struct tty_struct *tty) |
64e9159f AC |
1387 | { |
1388 | struct uart_state *state = tty->driver_data; | |
4047b371 | 1389 | struct uart_port *uport; |
64e9159f | 1390 | |
4047b371 PH |
1391 | mutex_lock(&state->port.mutex); |
1392 | uport = uart_port_check(state); | |
1393 | if (uport && uport->ops->set_ldisc) | |
732a84a0 | 1394 | uport->ops->set_ldisc(uport, &tty->termios); |
4047b371 | 1395 | mutex_unlock(&state->port.mutex); |
64e9159f AC |
1396 | } |
1397 | ||
a46c9994 AC |
1398 | static void uart_set_termios(struct tty_struct *tty, |
1399 | struct ktermios *old_termios) | |
1da177e4 LT |
1400 | { |
1401 | struct uart_state *state = tty->driver_data; | |
4047b371 | 1402 | struct uart_port *uport; |
adc8d746 | 1403 | unsigned int cflag = tty->termios.c_cflag; |
2cbacafd RK |
1404 | unsigned int iflag_mask = IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK; |
1405 | bool sw_changed = false; | |
1da177e4 | 1406 | |
4047b371 PH |
1407 | mutex_lock(&state->port.mutex); |
1408 | uport = uart_port_check(state); | |
1409 | if (!uport) | |
1410 | goto out; | |
1411 | ||
2cbacafd RK |
1412 | /* |
1413 | * Drivers doing software flow control also need to know | |
1414 | * about changes to these input settings. | |
1415 | */ | |
1416 | if (uport->flags & UPF_SOFT_FLOW) { | |
1417 | iflag_mask |= IXANY|IXON|IXOFF; | |
1418 | sw_changed = | |
1419 | tty->termios.c_cc[VSTART] != old_termios->c_cc[VSTART] || | |
1420 | tty->termios.c_cc[VSTOP] != old_termios->c_cc[VSTOP]; | |
1421 | } | |
1da177e4 LT |
1422 | |
1423 | /* | |
1424 | * These are the bits that are used to setup various | |
20620d68 DW |
1425 | * flags in the low level driver. We can ignore the Bfoo |
1426 | * bits in c_cflag; c_[io]speed will always be set | |
1427 | * appropriately by set_termios() in tty_ioctl.c | |
1da177e4 | 1428 | */ |
1da177e4 | 1429 | if ((cflag ^ old_termios->c_cflag) == 0 && |
adc8d746 AC |
1430 | tty->termios.c_ospeed == old_termios->c_ospeed && |
1431 | tty->termios.c_ispeed == old_termios->c_ispeed && | |
2cbacafd RK |
1432 | ((tty->termios.c_iflag ^ old_termios->c_iflag) & iflag_mask) == 0 && |
1433 | !sw_changed) { | |
4047b371 | 1434 | goto out; |
e5238442 | 1435 | } |
1da177e4 | 1436 | |
19225135 | 1437 | uart_change_speed(tty, state, old_termios); |
c18b55fd PH |
1438 | /* reload cflag from termios; port driver may have overriden flags */ |
1439 | cflag = tty->termios.c_cflag; | |
1da177e4 LT |
1440 | |
1441 | /* Handle transition to B0 status */ | |
1442 | if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) | |
dec94e70 | 1443 | uart_clear_mctrl(uport, TIOCM_RTS | TIOCM_DTR); |
1da177e4 | 1444 | /* Handle transition away from B0 status */ |
82cb7ba1 | 1445 | else if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { |
1da177e4 | 1446 | unsigned int mask = TIOCM_DTR; |
97ef38b8 | 1447 | if (!(cflag & CRTSCTS) || !tty_throttled(tty)) |
1da177e4 | 1448 | mask |= TIOCM_RTS; |
dec94e70 | 1449 | uart_set_mctrl(uport, mask); |
1da177e4 | 1450 | } |
4047b371 PH |
1451 | out: |
1452 | mutex_unlock(&state->port.mutex); | |
1da177e4 LT |
1453 | } |
1454 | ||
1455 | /* | |
ef4f527c KC |
1456 | * Calls to uart_close() are serialised via the tty_lock in |
1457 | * drivers/tty/tty_io.c:tty_release() | |
1458 | * drivers/tty/tty_io.c:do_tty_hangup() | |
1da177e4 LT |
1459 | */ |
1460 | static void uart_close(struct tty_struct *tty, struct file *filp) | |
1461 | { | |
1462 | struct uart_state *state = tty->driver_data; | |
46d57a44 | 1463 | struct tty_port *port; |
a46c9994 | 1464 | |
91b32f54 PH |
1465 | if (!state) { |
1466 | struct uart_driver *drv = tty->driver->driver_state; | |
1467 | ||
1468 | state = drv->state + tty->index; | |
1469 | port = &state->port; | |
1470 | spin_lock_irq(&port->lock); | |
1471 | --port->count; | |
1472 | spin_unlock_irq(&port->lock); | |
eea7e17e | 1473 | return; |
91b32f54 | 1474 | } |
eea7e17e | 1475 | |
46d57a44 | 1476 | port = &state->port; |
39b3d892 | 1477 | pr_debug("uart_close(%d) called\n", tty->index); |
1da177e4 | 1478 | |
761ed4a9 RH |
1479 | tty_port_close(tty->port, tty, filp); |
1480 | } | |
1da177e4 | 1481 | |
761ed4a9 RH |
1482 | static void uart_tty_port_shutdown(struct tty_port *port) |
1483 | { | |
1484 | struct uart_state *state = container_of(port, struct uart_state, port); | |
1485 | struct uart_port *uport = uart_port_check(state); | |
af224ca2 | 1486 | |
761ed4a9 | 1487 | spin_lock_irq(&uport->lock); |
1da177e4 LT |
1488 | /* |
1489 | * At this point, we stop accepting input. To do this, we | |
1490 | * disable the receive line status interrupts. | |
1491 | */ | |
761ed4a9 | 1492 | WARN(!uport, "detached port still initialized!\n"); |
1da177e4 | 1493 | |
761ed4a9 | 1494 | uport->ops->stop_rx(uport); |
e144c58c | 1495 | |
761ed4a9 | 1496 | spin_unlock_irq(&uport->lock); |
1da177e4 | 1497 | |
761ed4a9 | 1498 | uart_port_shutdown(port); |
1da177e4 LT |
1499 | |
1500 | /* | |
761ed4a9 RH |
1501 | * It's possible for shutdown to be called after suspend if we get |
1502 | * a DCD drop (hangup) at just the right time. Clear suspended bit so | |
1503 | * we don't try to resume a port that has been shutdown. | |
1da177e4 | 1504 | */ |
761ed4a9 | 1505 | tty_port_set_suspended(port, 0); |
1da177e4 | 1506 | |
761ed4a9 | 1507 | uart_change_pm(state, UART_PM_STATE_OFF); |
2e758910 | 1508 | |
1da177e4 LT |
1509 | } |
1510 | ||
1f33a51d | 1511 | static void uart_wait_until_sent(struct tty_struct *tty, int timeout) |
1da177e4 | 1512 | { |
1f33a51d | 1513 | struct uart_state *state = tty->driver_data; |
9ed19428 | 1514 | struct uart_port *port; |
1da177e4 LT |
1515 | unsigned long char_time, expire; |
1516 | ||
9ed19428 PH |
1517 | port = uart_port_ref(state); |
1518 | if (!port || port->type == PORT_UNKNOWN || port->fifosize == 0) { | |
1519 | uart_port_deref(port); | |
1da177e4 | 1520 | return; |
9ed19428 | 1521 | } |
1da177e4 LT |
1522 | |
1523 | /* | |
1524 | * Set the check interval to be 1/5 of the estimated time to | |
1525 | * send a single character, and make it at least 1. The check | |
1526 | * interval should also be less than the timeout. | |
1527 | * | |
1528 | * Note: we have to use pretty tight timings here to satisfy | |
1529 | * the NIST-PCTS. | |
1530 | */ | |
1531 | char_time = (port->timeout - HZ/50) / port->fifosize; | |
1532 | char_time = char_time / 5; | |
1533 | if (char_time == 0) | |
1534 | char_time = 1; | |
1535 | if (timeout && timeout < char_time) | |
1536 | char_time = timeout; | |
1537 | ||
1538 | /* | |
1539 | * If the transmitter hasn't cleared in twice the approximate | |
1540 | * amount of time to send the entire FIFO, it probably won't | |
1541 | * ever clear. This assumes the UART isn't doing flow | |
1542 | * control, which is currently the case. Hence, if it ever | |
1543 | * takes longer than port->timeout, this is probably due to a | |
1544 | * UART bug of some kind. So, we clamp the timeout parameter at | |
1545 | * 2*port->timeout. | |
1546 | */ | |
1547 | if (timeout == 0 || timeout > 2 * port->timeout) | |
1548 | timeout = 2 * port->timeout; | |
1549 | ||
1550 | expire = jiffies + timeout; | |
1551 | ||
eb3a1e11 | 1552 | pr_debug("uart_wait_until_sent(%d), jiffies=%lu, expire=%lu...\n", |
a46c9994 | 1553 | port->line, jiffies, expire); |
1da177e4 LT |
1554 | |
1555 | /* | |
1556 | * Check whether the transmitter is empty every 'char_time'. | |
1557 | * 'timeout' / 'expire' give us the maximum amount of time | |
1558 | * we wait. | |
1559 | */ | |
1560 | while (!port->ops->tx_empty(port)) { | |
1561 | msleep_interruptible(jiffies_to_msecs(char_time)); | |
1562 | if (signal_pending(current)) | |
1563 | break; | |
1564 | if (time_after(jiffies, expire)) | |
1565 | break; | |
1566 | } | |
9ed19428 | 1567 | uart_port_deref(port); |
20365219 AB |
1568 | } |
1569 | ||
1da177e4 | 1570 | /* |
ef4f527c KC |
1571 | * Calls to uart_hangup() are serialised by the tty_lock in |
1572 | * drivers/tty/tty_io.c:do_tty_hangup() | |
1573 | * This runs from a workqueue and can sleep for a _short_ time only. | |
1da177e4 LT |
1574 | */ |
1575 | static void uart_hangup(struct tty_struct *tty) | |
1576 | { | |
1577 | struct uart_state *state = tty->driver_data; | |
46d57a44 | 1578 | struct tty_port *port = &state->port; |
af224ca2 | 1579 | struct uart_port *uport; |
61cd8a21 | 1580 | unsigned long flags; |
1da177e4 | 1581 | |
39b3d892 | 1582 | pr_debug("uart_hangup(%d)\n", tty->index); |
1da177e4 | 1583 | |
a2bceae0 | 1584 | mutex_lock(&port->mutex); |
af224ca2 PH |
1585 | uport = uart_port_check(state); |
1586 | WARN(!uport, "hangup of detached port!\n"); | |
1587 | ||
807c8d81 | 1588 | if (tty_port_active(port)) { |
1da177e4 | 1589 | uart_flush_buffer(tty); |
19225135 | 1590 | uart_shutdown(tty, state); |
61cd8a21 | 1591 | spin_lock_irqsave(&port->lock, flags); |
91312cdb | 1592 | port->count = 0; |
61cd8a21 | 1593 | spin_unlock_irqrestore(&port->lock, flags); |
807c8d81 | 1594 | tty_port_set_active(port, 0); |
7b01478f | 1595 | tty_port_tty_set(port, NULL); |
af224ca2 | 1596 | if (uport && !uart_console(uport)) |
bf903c0c | 1597 | uart_change_pm(state, UART_PM_STATE_OFF); |
46d57a44 | 1598 | wake_up_interruptible(&port->open_wait); |
bdc04e31 | 1599 | wake_up_interruptible(&port->delta_msr_wait); |
1da177e4 | 1600 | } |
a2bceae0 | 1601 | mutex_unlock(&port->mutex); |
1da177e4 LT |
1602 | } |
1603 | ||
af224ca2 | 1604 | /* uport == NULL if uart_port has already been removed */ |
0b1db830 JS |
1605 | static void uart_port_shutdown(struct tty_port *port) |
1606 | { | |
b922e19d | 1607 | struct uart_state *state = container_of(port, struct uart_state, port); |
4047b371 | 1608 | struct uart_port *uport = uart_port_check(state); |
b922e19d JS |
1609 | |
1610 | /* | |
1611 | * clear delta_msr_wait queue to avoid mem leaks: we may free | |
1612 | * the irq here so the queue might never be woken up. Note | |
1613 | * that we won't end up waiting on delta_msr_wait again since | |
1614 | * any outstanding file descriptors should be pointing at | |
1615 | * hung_up_tty_fops now. | |
1616 | */ | |
1617 | wake_up_interruptible(&port->delta_msr_wait); | |
1618 | ||
1619 | /* | |
1620 | * Free the IRQ and disable the port. | |
1621 | */ | |
af224ca2 PH |
1622 | if (uport) |
1623 | uport->ops->shutdown(uport); | |
b922e19d JS |
1624 | |
1625 | /* | |
1626 | * Ensure that the IRQ handler isn't running on another CPU. | |
1627 | */ | |
af224ca2 PH |
1628 | if (uport) |
1629 | synchronize_irq(uport->irq); | |
0b1db830 JS |
1630 | } |
1631 | ||
de0c8cb3 AC |
1632 | static int uart_carrier_raised(struct tty_port *port) |
1633 | { | |
1634 | struct uart_state *state = container_of(port, struct uart_state, port); | |
9ed19428 | 1635 | struct uart_port *uport; |
de0c8cb3 | 1636 | int mctrl; |
9ed19428 PH |
1637 | |
1638 | uport = uart_port_ref(state); | |
1639 | /* | |
1640 | * Should never observe uport == NULL since checks for hangup should | |
1641 | * abort the tty_port_block_til_ready() loop before checking for carrier | |
1642 | * raised -- but report carrier raised if it does anyway so open will | |
1643 | * continue and not sleep | |
1644 | */ | |
1645 | if (WARN_ON(!uport)) | |
1646 | return 1; | |
de0c8cb3 | 1647 | spin_lock_irq(&uport->lock); |
1fdc3106 | 1648 | uart_enable_ms(uport); |
de0c8cb3 AC |
1649 | mctrl = uport->ops->get_mctrl(uport); |
1650 | spin_unlock_irq(&uport->lock); | |
9ed19428 | 1651 | uart_port_deref(uport); |
de0c8cb3 AC |
1652 | if (mctrl & TIOCM_CAR) |
1653 | return 1; | |
1654 | return 0; | |
1655 | } | |
1656 | ||
1657 | static void uart_dtr_rts(struct tty_port *port, int onoff) | |
1658 | { | |
1659 | struct uart_state *state = container_of(port, struct uart_state, port); | |
9ed19428 PH |
1660 | struct uart_port *uport; |
1661 | ||
1662 | uport = uart_port_ref(state); | |
1663 | if (!uport) | |
1664 | return; | |
24fcc7c8 | 1665 | |
6f5c24ad | 1666 | if (onoff) |
de0c8cb3 AC |
1667 | uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS); |
1668 | else | |
1669 | uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS); | |
9ed19428 PH |
1670 | |
1671 | uart_port_deref(uport); | |
de0c8cb3 AC |
1672 | } |
1673 | ||
1da177e4 | 1674 | /* |
ef4f527c KC |
1675 | * Calls to uart_open are serialised by the tty_lock in |
1676 | * drivers/tty/tty_io.c:tty_open() | |
1da177e4 LT |
1677 | * Note that if this fails, then uart_close() _will_ be called. |
1678 | * | |
1679 | * In time, we want to scrap the "opening nonpresent ports" | |
1680 | * behaviour and implement an alternative way for setserial | |
1681 | * to set base addresses/ports/types. This will allow us to | |
1682 | * get rid of a certain amount of extra tests. | |
1683 | */ | |
1684 | static int uart_open(struct tty_struct *tty, struct file *filp) | |
1685 | { | |
5e388027 | 1686 | struct uart_driver *drv = tty->driver->driver_state; |
1da177e4 | 1687 | int retval, line = tty->index; |
1c7b13c4 | 1688 | struct uart_state *state = drv->state + line; |
1da177e4 | 1689 | |
b3b57646 | 1690 | tty->driver_data = state; |
1da177e4 | 1691 | |
b3b57646 RH |
1692 | retval = tty_port_open(&state->port, tty, filp); |
1693 | if (retval > 0) | |
1694 | retval = 0; | |
91b32f54 | 1695 | |
b3b57646 RH |
1696 | return retval; |
1697 | } | |
1698 | ||
1699 | static int uart_port_activate(struct tty_port *port, struct tty_struct *tty) | |
1700 | { | |
1701 | struct uart_state *state = container_of(port, struct uart_state, port); | |
1702 | struct uart_port *uport; | |
1c7b13c4 | 1703 | |
4047b371 | 1704 | uport = uart_port_check(state); |
b3b57646 RH |
1705 | if (!uport || uport->flags & UPF_DEAD) |
1706 | return -ENXIO; | |
1da177e4 | 1707 | |
4047b371 | 1708 | port->low_latency = (uport->flags & UPF_LOW_LATENCY) ? 1 : 0; |
1da177e4 | 1709 | |
1da177e4 LT |
1710 | /* |
1711 | * Start up the serial port. | |
1712 | */ | |
b3b57646 | 1713 | return uart_startup(tty, state, 0); |
1da177e4 LT |
1714 | } |
1715 | ||
1716 | static const char *uart_type(struct uart_port *port) | |
1717 | { | |
1718 | const char *str = NULL; | |
1719 | ||
1720 | if (port->ops->type) | |
1721 | str = port->ops->type(port); | |
1722 | ||
1723 | if (!str) | |
1724 | str = "unknown"; | |
1725 | ||
1726 | return str; | |
1727 | } | |
1728 | ||
1729 | #ifdef CONFIG_PROC_FS | |
1730 | ||
d196a949 | 1731 | static void uart_line_info(struct seq_file *m, struct uart_driver *drv, int i) |
1da177e4 LT |
1732 | { |
1733 | struct uart_state *state = drv->state + i; | |
a2bceae0 | 1734 | struct tty_port *port = &state->port; |
6f538fe3 | 1735 | enum uart_pm_state pm_state; |
4047b371 | 1736 | struct uart_port *uport; |
1da177e4 LT |
1737 | char stat_buf[32]; |
1738 | unsigned int status; | |
d196a949 | 1739 | int mmio; |
1da177e4 | 1740 | |
4047b371 PH |
1741 | mutex_lock(&port->mutex); |
1742 | uport = uart_port_check(state); | |
a2bceae0 | 1743 | if (!uport) |
4047b371 | 1744 | goto out; |
1da177e4 | 1745 | |
a2bceae0 | 1746 | mmio = uport->iotype >= UPIO_MEM; |
d196a949 | 1747 | seq_printf(m, "%d: uart:%s %s%08llX irq:%d", |
a2bceae0 | 1748 | uport->line, uart_type(uport), |
6c6a2334 | 1749 | mmio ? "mmio:0x" : "port:", |
a2bceae0 AC |
1750 | mmio ? (unsigned long long)uport->mapbase |
1751 | : (unsigned long long)uport->iobase, | |
1752 | uport->irq); | |
1da177e4 | 1753 | |
a2bceae0 | 1754 | if (uport->type == PORT_UNKNOWN) { |
d196a949 | 1755 | seq_putc(m, '\n'); |
4047b371 | 1756 | goto out; |
1da177e4 LT |
1757 | } |
1758 | ||
a46c9994 | 1759 | if (capable(CAP_SYS_ADMIN)) { |
3689a0ec | 1760 | pm_state = state->pm_state; |
6f538fe3 LW |
1761 | if (pm_state != UART_PM_STATE_ON) |
1762 | uart_change_pm(state, UART_PM_STATE_ON); | |
a2bceae0 AC |
1763 | spin_lock_irq(&uport->lock); |
1764 | status = uport->ops->get_mctrl(uport); | |
1765 | spin_unlock_irq(&uport->lock); | |
6f538fe3 | 1766 | if (pm_state != UART_PM_STATE_ON) |
3689a0ec | 1767 | uart_change_pm(state, pm_state); |
1da177e4 | 1768 | |
d196a949 | 1769 | seq_printf(m, " tx:%d rx:%d", |
a2bceae0 AC |
1770 | uport->icount.tx, uport->icount.rx); |
1771 | if (uport->icount.frame) | |
968af298 | 1772 | seq_printf(m, " fe:%d", uport->icount.frame); |
a2bceae0 | 1773 | if (uport->icount.parity) |
968af298 | 1774 | seq_printf(m, " pe:%d", uport->icount.parity); |
a2bceae0 | 1775 | if (uport->icount.brk) |
968af298 | 1776 | seq_printf(m, " brk:%d", uport->icount.brk); |
a2bceae0 | 1777 | if (uport->icount.overrun) |
968af298 | 1778 | seq_printf(m, " oe:%d", uport->icount.overrun); |
a46c9994 AC |
1779 | |
1780 | #define INFOBIT(bit, str) \ | |
a2bceae0 | 1781 | if (uport->mctrl & (bit)) \ |
1da177e4 LT |
1782 | strncat(stat_buf, (str), sizeof(stat_buf) - \ |
1783 | strlen(stat_buf) - 2) | |
a46c9994 | 1784 | #define STATBIT(bit, str) \ |
1da177e4 LT |
1785 | if (status & (bit)) \ |
1786 | strncat(stat_buf, (str), sizeof(stat_buf) - \ | |
1787 | strlen(stat_buf) - 2) | |
1788 | ||
1789 | stat_buf[0] = '\0'; | |
1790 | stat_buf[1] = '\0'; | |
1791 | INFOBIT(TIOCM_RTS, "|RTS"); | |
1792 | STATBIT(TIOCM_CTS, "|CTS"); | |
1793 | INFOBIT(TIOCM_DTR, "|DTR"); | |
1794 | STATBIT(TIOCM_DSR, "|DSR"); | |
1795 | STATBIT(TIOCM_CAR, "|CD"); | |
1796 | STATBIT(TIOCM_RNG, "|RI"); | |
1797 | if (stat_buf[0]) | |
1798 | stat_buf[0] = ' '; | |
a46c9994 | 1799 | |
d196a949 | 1800 | seq_puts(m, stat_buf); |
1da177e4 | 1801 | } |
d196a949 | 1802 | seq_putc(m, '\n'); |
1da177e4 LT |
1803 | #undef STATBIT |
1804 | #undef INFOBIT | |
4047b371 PH |
1805 | out: |
1806 | mutex_unlock(&port->mutex); | |
1da177e4 LT |
1807 | } |
1808 | ||
d196a949 | 1809 | static int uart_proc_show(struct seq_file *m, void *v) |
1da177e4 | 1810 | { |
833bb304 | 1811 | struct tty_driver *ttydrv = m->private; |
1da177e4 | 1812 | struct uart_driver *drv = ttydrv->driver_state; |
d196a949 | 1813 | int i; |
1da177e4 | 1814 | |
968af298 | 1815 | seq_printf(m, "serinfo:1.0 driver%s%s revision:%s\n", "", "", ""); |
d196a949 AD |
1816 | for (i = 0; i < drv->nr; i++) |
1817 | uart_line_info(m, drv, i); | |
1818 | return 0; | |
1da177e4 | 1819 | } |
d196a949 AD |
1820 | |
1821 | static int uart_proc_open(struct inode *inode, struct file *file) | |
1822 | { | |
d9dda78b | 1823 | return single_open(file, uart_proc_show, PDE_DATA(inode)); |
d196a949 AD |
1824 | } |
1825 | ||
1826 | static const struct file_operations uart_proc_fops = { | |
1827 | .owner = THIS_MODULE, | |
1828 | .open = uart_proc_open, | |
1829 | .read = seq_read, | |
1830 | .llseek = seq_lseek, | |
1831 | .release = single_release, | |
1832 | }; | |
1da177e4 LT |
1833 | #endif |
1834 | ||
4a1b5502 | 1835 | #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL) |
1cfe42b7 | 1836 | /** |
d358788f RK |
1837 | * uart_console_write - write a console message to a serial port |
1838 | * @port: the port to write the message | |
1839 | * @s: array of characters | |
1840 | * @count: number of characters in string to write | |
10afbe34 | 1841 | * @putchar: function to write character to port |
d358788f RK |
1842 | */ |
1843 | void uart_console_write(struct uart_port *port, const char *s, | |
1844 | unsigned int count, | |
1845 | void (*putchar)(struct uart_port *, int)) | |
1846 | { | |
1847 | unsigned int i; | |
1848 | ||
1849 | for (i = 0; i < count; i++, s++) { | |
1850 | if (*s == '\n') | |
1851 | putchar(port, '\r'); | |
1852 | putchar(port, *s); | |
1853 | } | |
1854 | } | |
1855 | EXPORT_SYMBOL_GPL(uart_console_write); | |
1856 | ||
1da177e4 LT |
1857 | /* |
1858 | * Check whether an invalid uart number has been specified, and | |
1859 | * if so, search for the first available port that does have | |
1860 | * console support. | |
1861 | */ | |
1862 | struct uart_port * __init | |
1863 | uart_get_console(struct uart_port *ports, int nr, struct console *co) | |
1864 | { | |
1865 | int idx = co->index; | |
1866 | ||
1867 | if (idx < 0 || idx >= nr || (ports[idx].iobase == 0 && | |
1868 | ports[idx].membase == NULL)) | |
1869 | for (idx = 0; idx < nr; idx++) | |
1870 | if (ports[idx].iobase != 0 || | |
1871 | ports[idx].membase != NULL) | |
1872 | break; | |
1873 | ||
1874 | co->index = idx; | |
1875 | ||
1876 | return ports + idx; | |
1877 | } | |
1878 | ||
73abaf87 PH |
1879 | /** |
1880 | * uart_parse_earlycon - Parse earlycon options | |
1881 | * @p: ptr to 2nd field (ie., just beyond '<name>,') | |
1882 | * @iotype: ptr for decoded iotype (out) | |
1883 | * @addr: ptr for decoded mapbase/iobase (out) | |
1884 | * @options: ptr for <options> field; NULL if not present (out) | |
1885 | * | |
1886 | * Decodes earlycon kernel command line parameters of the form | |
bd94c407 MY |
1887 | * earlycon=<name>,io|mmio|mmio16|mmio32|mmio32be|mmio32native,<addr>,<options> |
1888 | * console=<name>,io|mmio|mmio16|mmio32|mmio32be|mmio32native,<addr>,<options> | |
73abaf87 PH |
1889 | * |
1890 | * The optional form | |
1891 | * earlycon=<name>,0x<addr>,<options> | |
1892 | * console=<name>,0x<addr>,<options> | |
1893 | * is also accepted; the returned @iotype will be UPIO_MEM. | |
1894 | * | |
1895 | * Returns 0 on success or -EINVAL on failure | |
1896 | */ | |
1897 | int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr, | |
1898 | char **options) | |
1899 | { | |
1900 | if (strncmp(p, "mmio,", 5) == 0) { | |
1901 | *iotype = UPIO_MEM; | |
1902 | p += 5; | |
bd94c407 MY |
1903 | } else if (strncmp(p, "mmio16,", 7) == 0) { |
1904 | *iotype = UPIO_MEM16; | |
1905 | p += 7; | |
73abaf87 PH |
1906 | } else if (strncmp(p, "mmio32,", 7) == 0) { |
1907 | *iotype = UPIO_MEM32; | |
1908 | p += 7; | |
6e63be3f NC |
1909 | } else if (strncmp(p, "mmio32be,", 9) == 0) { |
1910 | *iotype = UPIO_MEM32BE; | |
1911 | p += 9; | |
d215d809 MF |
1912 | } else if (strncmp(p, "mmio32native,", 13) == 0) { |
1913 | *iotype = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) ? | |
1914 | UPIO_MEM32BE : UPIO_MEM32; | |
1915 | p += 13; | |
73abaf87 PH |
1916 | } else if (strncmp(p, "io,", 3) == 0) { |
1917 | *iotype = UPIO_PORT; | |
1918 | p += 3; | |
1919 | } else if (strncmp(p, "0x", 2) == 0) { | |
1920 | *iotype = UPIO_MEM; | |
1921 | } else { | |
1922 | return -EINVAL; | |
1923 | } | |
1924 | ||
1925 | *addr = simple_strtoul(p, NULL, 0); | |
1926 | p = strchr(p, ','); | |
1927 | if (p) | |
1928 | p++; | |
1929 | ||
1930 | *options = p; | |
1931 | return 0; | |
1932 | } | |
1933 | EXPORT_SYMBOL_GPL(uart_parse_earlycon); | |
1934 | ||
1da177e4 | 1935 | /** |
02088ca6 | 1936 | * uart_parse_options - Parse serial port baud/parity/bits/flow control. |
1da177e4 LT |
1937 | * @options: pointer to option string |
1938 | * @baud: pointer to an 'int' variable for the baud rate. | |
1939 | * @parity: pointer to an 'int' variable for the parity. | |
1940 | * @bits: pointer to an 'int' variable for the number of data bits. | |
1941 | * @flow: pointer to an 'int' variable for the flow control character. | |
1942 | * | |
1943 | * uart_parse_options decodes a string containing the serial console | |
1944 | * options. The format of the string is <baud><parity><bits><flow>, | |
1945 | * eg: 115200n8r | |
1946 | */ | |
f2d937f3 | 1947 | void |
1da177e4 LT |
1948 | uart_parse_options(char *options, int *baud, int *parity, int *bits, int *flow) |
1949 | { | |
1950 | char *s = options; | |
1951 | ||
1952 | *baud = simple_strtoul(s, NULL, 10); | |
1953 | while (*s >= '0' && *s <= '9') | |
1954 | s++; | |
1955 | if (*s) | |
1956 | *parity = *s++; | |
1957 | if (*s) | |
1958 | *bits = *s++ - '0'; | |
1959 | if (*s) | |
1960 | *flow = *s; | |
1961 | } | |
f2d937f3 | 1962 | EXPORT_SYMBOL_GPL(uart_parse_options); |
1da177e4 | 1963 | |
1da177e4 LT |
1964 | /** |
1965 | * uart_set_options - setup the serial console parameters | |
1966 | * @port: pointer to the serial ports uart_port structure | |
1967 | * @co: console pointer | |
1968 | * @baud: baud rate | |
1969 | * @parity: parity character - 'n' (none), 'o' (odd), 'e' (even) | |
1970 | * @bits: number of data bits | |
1971 | * @flow: flow control character - 'r' (rts) | |
1972 | */ | |
f2d937f3 | 1973 | int |
1da177e4 LT |
1974 | uart_set_options(struct uart_port *port, struct console *co, |
1975 | int baud, int parity, int bits, int flow) | |
1976 | { | |
606d099c | 1977 | struct ktermios termios; |
149b36ea | 1978 | static struct ktermios dummy; |
1da177e4 | 1979 | |
976ecd12 RK |
1980 | /* |
1981 | * Ensure that the serial console lock is initialised | |
1982 | * early. | |
42b6a1ba RW |
1983 | * If this port is a console, then the spinlock is already |
1984 | * initialised. | |
976ecd12 | 1985 | */ |
42b6a1ba RW |
1986 | if (!(uart_console(port) && (port->cons->flags & CON_ENABLED))) { |
1987 | spin_lock_init(&port->lock); | |
1988 | lockdep_set_class(&port->lock, &port_lock_key); | |
1989 | } | |
976ecd12 | 1990 | |
606d099c | 1991 | memset(&termios, 0, sizeof(struct ktermios)); |
1da177e4 | 1992 | |
ba47f97a JC |
1993 | termios.c_cflag |= CREAD | HUPCL | CLOCAL; |
1994 | tty_termios_encode_baud_rate(&termios, baud, baud); | |
1da177e4 LT |
1995 | |
1996 | if (bits == 7) | |
1997 | termios.c_cflag |= CS7; | |
1998 | else | |
1999 | termios.c_cflag |= CS8; | |
2000 | ||
2001 | switch (parity) { | |
2002 | case 'o': case 'O': | |
2003 | termios.c_cflag |= PARODD; | |
2004 | /*fall through*/ | |
2005 | case 'e': case 'E': | |
2006 | termios.c_cflag |= PARENB; | |
2007 | break; | |
2008 | } | |
2009 | ||
2010 | if (flow == 'r') | |
2011 | termios.c_cflag |= CRTSCTS; | |
2012 | ||
79492689 YL |
2013 | /* |
2014 | * some uarts on other side don't support no flow control. | |
2015 | * So we set * DTR in host uart to make them happy | |
2016 | */ | |
2017 | port->mctrl |= TIOCM_DTR; | |
2018 | ||
149b36ea | 2019 | port->ops->set_termios(port, &termios, &dummy); |
f2d937f3 JW |
2020 | /* |
2021 | * Allow the setting of the UART parameters with a NULL console | |
2022 | * too: | |
2023 | */ | |
2024 | if (co) | |
2025 | co->cflag = termios.c_cflag; | |
1da177e4 LT |
2026 | |
2027 | return 0; | |
2028 | } | |
f2d937f3 | 2029 | EXPORT_SYMBOL_GPL(uart_set_options); |
1da177e4 LT |
2030 | #endif /* CONFIG_SERIAL_CORE_CONSOLE */ |
2031 | ||
cf75525f JS |
2032 | /** |
2033 | * uart_change_pm - set power state of the port | |
2034 | * | |
2035 | * @state: port descriptor | |
2036 | * @pm_state: new state | |
2037 | * | |
2038 | * Locking: port->mutex has to be held | |
2039 | */ | |
6f538fe3 LW |
2040 | static void uart_change_pm(struct uart_state *state, |
2041 | enum uart_pm_state pm_state) | |
1da177e4 | 2042 | { |
4047b371 | 2043 | struct uart_port *port = uart_port_check(state); |
1281e360 AV |
2044 | |
2045 | if (state->pm_state != pm_state) { | |
4047b371 | 2046 | if (port && port->ops->pm) |
1281e360 AV |
2047 | port->ops->pm(port, pm_state, state->pm_state); |
2048 | state->pm_state = pm_state; | |
2049 | } | |
1da177e4 LT |
2050 | } |
2051 | ||
b3b708fa GL |
2052 | struct uart_match { |
2053 | struct uart_port *port; | |
2054 | struct uart_driver *driver; | |
2055 | }; | |
2056 | ||
2057 | static int serial_match_port(struct device *dev, void *data) | |
2058 | { | |
2059 | struct uart_match *match = data; | |
7ca796f4 GL |
2060 | struct tty_driver *tty_drv = match->driver->tty_driver; |
2061 | dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) + | |
2062 | match->port->line; | |
b3b708fa GL |
2063 | |
2064 | return dev->devt == devt; /* Actually, only one tty per port */ | |
2065 | } | |
2066 | ||
ccce6deb | 2067 | int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport) |
1da177e4 | 2068 | { |
ccce6deb AC |
2069 | struct uart_state *state = drv->state + uport->line; |
2070 | struct tty_port *port = &state->port; | |
b3b708fa | 2071 | struct device *tty_dev; |
ccce6deb | 2072 | struct uart_match match = {uport, drv}; |
1da177e4 | 2073 | |
a2bceae0 | 2074 | mutex_lock(&port->mutex); |
1da177e4 | 2075 | |
ccce6deb | 2076 | tty_dev = device_find_child(uport->dev, &match, serial_match_port); |
b3b708fa | 2077 | if (device_may_wakeup(tty_dev)) { |
3f960dbb G |
2078 | if (!enable_irq_wake(uport->irq)) |
2079 | uport->irq_wake = 1; | |
b3b708fa | 2080 | put_device(tty_dev); |
a2bceae0 | 2081 | mutex_unlock(&port->mutex); |
b3b708fa GL |
2082 | return 0; |
2083 | } | |
5a65dcc0 FV |
2084 | put_device(tty_dev); |
2085 | ||
b164c972 PH |
2086 | /* Nothing to do if the console is not suspending */ |
2087 | if (!console_suspend_enabled && uart_console(uport)) | |
2088 | goto unlock; | |
2089 | ||
2090 | uport->suspended = 1; | |
b3b708fa | 2091 | |
d41861ca | 2092 | if (tty_port_initialized(port)) { |
ccce6deb | 2093 | const struct uart_ops *ops = uport->ops; |
c8c6bfa3 | 2094 | int tries; |
1da177e4 | 2095 | |
80f02d54 | 2096 | tty_port_set_suspended(port, 1); |
d41861ca | 2097 | tty_port_set_initialized(port, 0); |
a6b93a90 | 2098 | |
b164c972 PH |
2099 | spin_lock_irq(&uport->lock); |
2100 | ops->stop_tx(uport); | |
2101 | ops->set_mctrl(uport, 0); | |
2102 | ops->stop_rx(uport); | |
2103 | spin_unlock_irq(&uport->lock); | |
1da177e4 LT |
2104 | |
2105 | /* | |
2106 | * Wait for the transmitter to empty. | |
2107 | */ | |
ccce6deb | 2108 | for (tries = 3; !ops->tx_empty(uport) && tries; tries--) |
1da177e4 | 2109 | msleep(10); |
c8c6bfa3 | 2110 | if (!tries) |
2f2dafe7 SM |
2111 | dev_err(uport->dev, "%s%d: Unable to drain transmitter\n", |
2112 | drv->dev_name, | |
2113 | drv->tty_driver->name_base + uport->line); | |
1da177e4 | 2114 | |
b164c972 | 2115 | ops->shutdown(uport); |
1da177e4 LT |
2116 | } |
2117 | ||
2118 | /* | |
2119 | * Disable the console device before suspending. | |
2120 | */ | |
b164c972 | 2121 | if (uart_console(uport)) |
ccce6deb | 2122 | console_stop(uport->cons); |
1da177e4 | 2123 | |
b164c972 PH |
2124 | uart_change_pm(state, UART_PM_STATE_OFF); |
2125 | unlock: | |
a2bceae0 | 2126 | mutex_unlock(&port->mutex); |
1da177e4 LT |
2127 | |
2128 | return 0; | |
2129 | } | |
2130 | ||
ccce6deb | 2131 | int uart_resume_port(struct uart_driver *drv, struct uart_port *uport) |
1da177e4 | 2132 | { |
ccce6deb AC |
2133 | struct uart_state *state = drv->state + uport->line; |
2134 | struct tty_port *port = &state->port; | |
03a74dcc | 2135 | struct device *tty_dev; |
ccce6deb | 2136 | struct uart_match match = {uport, drv}; |
ba15ab0e | 2137 | struct ktermios termios; |
1da177e4 | 2138 | |
a2bceae0 | 2139 | mutex_lock(&port->mutex); |
1da177e4 | 2140 | |
ccce6deb AC |
2141 | tty_dev = device_find_child(uport->dev, &match, serial_match_port); |
2142 | if (!uport->suspended && device_may_wakeup(tty_dev)) { | |
3f960dbb G |
2143 | if (uport->irq_wake) { |
2144 | disable_irq_wake(uport->irq); | |
2145 | uport->irq_wake = 0; | |
2146 | } | |
5a65dcc0 | 2147 | put_device(tty_dev); |
a2bceae0 | 2148 | mutex_unlock(&port->mutex); |
b3b708fa GL |
2149 | return 0; |
2150 | } | |
5a65dcc0 | 2151 | put_device(tty_dev); |
ccce6deb | 2152 | uport->suspended = 0; |
b3b708fa | 2153 | |
1da177e4 LT |
2154 | /* |
2155 | * Re-enable the console device after suspending. | |
2156 | */ | |
5933a161 | 2157 | if (uart_console(uport)) { |
891b9dd1 JW |
2158 | /* |
2159 | * First try to use the console cflag setting. | |
2160 | */ | |
2161 | memset(&termios, 0, sizeof(struct ktermios)); | |
2162 | termios.c_cflag = uport->cons->cflag; | |
2163 | ||
2164 | /* | |
2165 | * If that's unset, use the tty termios setting. | |
2166 | */ | |
adc8d746 AC |
2167 | if (port->tty && termios.c_cflag == 0) |
2168 | termios = port->tty->termios; | |
891b9dd1 | 2169 | |
94abc56f | 2170 | if (console_suspend_enabled) |
6f538fe3 | 2171 | uart_change_pm(state, UART_PM_STATE_ON); |
ccce6deb | 2172 | uport->ops->set_termios(uport, &termios, NULL); |
5933a161 YK |
2173 | if (console_suspend_enabled) |
2174 | console_start(uport->cons); | |
1da177e4 LT |
2175 | } |
2176 | ||
80f02d54 | 2177 | if (tty_port_suspended(port)) { |
ccce6deb | 2178 | const struct uart_ops *ops = uport->ops; |
ee31b337 | 2179 | int ret; |
1da177e4 | 2180 | |
6f538fe3 | 2181 | uart_change_pm(state, UART_PM_STATE_ON); |
ccce6deb AC |
2182 | spin_lock_irq(&uport->lock); |
2183 | ops->set_mctrl(uport, 0); | |
2184 | spin_unlock_irq(&uport->lock); | |
4547be78 | 2185 | if (console_suspend_enabled || !uart_console(uport)) { |
19225135 AC |
2186 | /* Protected by port mutex for now */ |
2187 | struct tty_struct *tty = port->tty; | |
4547be78 SB |
2188 | ret = ops->startup(uport); |
2189 | if (ret == 0) { | |
19225135 AC |
2190 | if (tty) |
2191 | uart_change_speed(tty, state, NULL); | |
4547be78 SB |
2192 | spin_lock_irq(&uport->lock); |
2193 | ops->set_mctrl(uport, uport->mctrl); | |
2194 | ops->start_tx(uport); | |
2195 | spin_unlock_irq(&uport->lock); | |
d41861ca | 2196 | tty_port_set_initialized(port, 1); |
4547be78 SB |
2197 | } else { |
2198 | /* | |
2199 | * Failed to resume - maybe hardware went away? | |
2200 | * Clear the "initialized" flag so we won't try | |
2201 | * to call the low level drivers shutdown method. | |
2202 | */ | |
19225135 | 2203 | uart_shutdown(tty, state); |
4547be78 | 2204 | } |
ee31b337 | 2205 | } |
a6b93a90 | 2206 | |
80f02d54 | 2207 | tty_port_set_suspended(port, 0); |
1da177e4 LT |
2208 | } |
2209 | ||
a2bceae0 | 2210 | mutex_unlock(&port->mutex); |
1da177e4 LT |
2211 | |
2212 | return 0; | |
2213 | } | |
2214 | ||
2215 | static inline void | |
2216 | uart_report_port(struct uart_driver *drv, struct uart_port *port) | |
2217 | { | |
30b7a3bc RK |
2218 | char address[64]; |
2219 | ||
1da177e4 LT |
2220 | switch (port->iotype) { |
2221 | case UPIO_PORT: | |
9bde10a4 | 2222 | snprintf(address, sizeof(address), "I/O 0x%lx", port->iobase); |
1da177e4 LT |
2223 | break; |
2224 | case UPIO_HUB6: | |
30b7a3bc | 2225 | snprintf(address, sizeof(address), |
9bde10a4 | 2226 | "I/O 0x%lx offset 0x%x", port->iobase, port->hub6); |
1da177e4 LT |
2227 | break; |
2228 | case UPIO_MEM: | |
bd94c407 | 2229 | case UPIO_MEM16: |
1da177e4 | 2230 | case UPIO_MEM32: |
3ffb1a81 | 2231 | case UPIO_MEM32BE: |
21c614a7 | 2232 | case UPIO_AU: |
3be91ec7 | 2233 | case UPIO_TSI: |
30b7a3bc | 2234 | snprintf(address, sizeof(address), |
4f640efb | 2235 | "MMIO 0x%llx", (unsigned long long)port->mapbase); |
30b7a3bc RK |
2236 | break; |
2237 | default: | |
2238 | strlcpy(address, "*unknown*", sizeof(address)); | |
1da177e4 LT |
2239 | break; |
2240 | } | |
30b7a3bc | 2241 | |
68ed7e1c JB |
2242 | printk(KERN_INFO "%s%s%s%d at %s (irq = %d, base_baud = %d) is a %s\n", |
2243 | port->dev ? dev_name(port->dev) : "", | |
2244 | port->dev ? ": " : "", | |
8440838b DM |
2245 | drv->dev_name, |
2246 | drv->tty_driver->name_base + port->line, | |
7d12b976 | 2247 | address, port->irq, port->uartclk / 16, uart_type(port)); |
1da177e4 LT |
2248 | } |
2249 | ||
2250 | static void | |
2251 | uart_configure_port(struct uart_driver *drv, struct uart_state *state, | |
2252 | struct uart_port *port) | |
2253 | { | |
2254 | unsigned int flags; | |
2255 | ||
2256 | /* | |
2257 | * If there isn't a port here, don't do anything further. | |
2258 | */ | |
2259 | if (!port->iobase && !port->mapbase && !port->membase) | |
2260 | return; | |
2261 | ||
2262 | /* | |
2263 | * Now do the auto configuration stuff. Note that config_port | |
2264 | * is expected to claim the resources and map the port for us. | |
2265 | */ | |
8e23fcc8 | 2266 | flags = 0; |
1da177e4 LT |
2267 | if (port->flags & UPF_AUTO_IRQ) |
2268 | flags |= UART_CONFIG_IRQ; | |
2269 | if (port->flags & UPF_BOOT_AUTOCONF) { | |
8e23fcc8 DD |
2270 | if (!(port->flags & UPF_FIXED_TYPE)) { |
2271 | port->type = PORT_UNKNOWN; | |
2272 | flags |= UART_CONFIG_TYPE; | |
2273 | } | |
1da177e4 LT |
2274 | port->ops->config_port(port, flags); |
2275 | } | |
2276 | ||
2277 | if (port->type != PORT_UNKNOWN) { | |
2278 | unsigned long flags; | |
2279 | ||
2280 | uart_report_port(drv, port); | |
2281 | ||
3689a0ec | 2282 | /* Power up port for set_mctrl() */ |
6f538fe3 | 2283 | uart_change_pm(state, UART_PM_STATE_ON); |
3689a0ec | 2284 | |
1da177e4 LT |
2285 | /* |
2286 | * Ensure that the modem control lines are de-activated. | |
c3e4642b | 2287 | * keep the DTR setting that is set in uart_set_options() |
1da177e4 LT |
2288 | * We probably don't need a spinlock around this, but |
2289 | */ | |
2290 | spin_lock_irqsave(&port->lock, flags); | |
c3e4642b | 2291 | port->ops->set_mctrl(port, port->mctrl & TIOCM_DTR); |
1da177e4 LT |
2292 | spin_unlock_irqrestore(&port->lock, flags); |
2293 | ||
97d97224 RK |
2294 | /* |
2295 | * If this driver supports console, and it hasn't been | |
2296 | * successfully registered yet, try to re-register it. | |
2297 | * It may be that the port was not available. | |
2298 | */ | |
2299 | if (port->cons && !(port->cons->flags & CON_ENABLED)) | |
2300 | register_console(port->cons); | |
2301 | ||
1da177e4 LT |
2302 | /* |
2303 | * Power down all ports by default, except the | |
2304 | * console if we have one. | |
2305 | */ | |
2306 | if (!uart_console(port)) | |
6f538fe3 | 2307 | uart_change_pm(state, UART_PM_STATE_OFF); |
1da177e4 LT |
2308 | } |
2309 | } | |
2310 | ||
f2d937f3 JW |
2311 | #ifdef CONFIG_CONSOLE_POLL |
2312 | ||
2313 | static int uart_poll_init(struct tty_driver *driver, int line, char *options) | |
2314 | { | |
2315 | struct uart_driver *drv = driver->driver_state; | |
2316 | struct uart_state *state = drv->state + line; | |
49c02304 | 2317 | struct tty_port *tport; |
f2d937f3 JW |
2318 | struct uart_port *port; |
2319 | int baud = 9600; | |
2320 | int bits = 8; | |
2321 | int parity = 'n'; | |
2322 | int flow = 'n'; | |
49c02304 | 2323 | int ret = 0; |
f2d937f3 | 2324 | |
49c02304 | 2325 | if (!state) |
f2d937f3 JW |
2326 | return -1; |
2327 | ||
49c02304 PH |
2328 | tport = &state->port; |
2329 | mutex_lock(&tport->mutex); | |
2330 | ||
4047b371 PH |
2331 | port = uart_port_check(state); |
2332 | if (!port || !(port->ops->poll_get_char && port->ops->poll_put_char)) { | |
49c02304 PH |
2333 | ret = -1; |
2334 | goto out; | |
2335 | } | |
f2d937f3 | 2336 | |
c7f3e708 | 2337 | if (port->ops->poll_init) { |
c7f3e708 | 2338 | /* |
d41861ca PH |
2339 | * We don't set initialized as we only initialized the hw, |
2340 | * e.g. state->xmit is still uninitialized. | |
c7f3e708 | 2341 | */ |
d41861ca | 2342 | if (!tty_port_initialized(tport)) |
c7f3e708 | 2343 | ret = port->ops->poll_init(port); |
c7f3e708 AV |
2344 | } |
2345 | ||
49c02304 | 2346 | if (!ret && options) { |
f2d937f3 | 2347 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
49c02304 | 2348 | ret = uart_set_options(port, NULL, baud, parity, bits, flow); |
f2d937f3 | 2349 | } |
49c02304 PH |
2350 | out: |
2351 | mutex_unlock(&tport->mutex); | |
2352 | return ret; | |
f2d937f3 JW |
2353 | } |
2354 | ||
2355 | static int uart_poll_get_char(struct tty_driver *driver, int line) | |
2356 | { | |
2357 | struct uart_driver *drv = driver->driver_state; | |
2358 | struct uart_state *state = drv->state + line; | |
2359 | struct uart_port *port; | |
9ed19428 | 2360 | int ret = -1; |
f2d937f3 | 2361 | |
9ed19428 PH |
2362 | if (state) { |
2363 | port = uart_port_ref(state); | |
2364 | if (port) | |
2365 | ret = port->ops->poll_get_char(port); | |
2366 | uart_port_deref(port); | |
2367 | } | |
2368 | return ret; | |
f2d937f3 JW |
2369 | } |
2370 | ||
2371 | static void uart_poll_put_char(struct tty_driver *driver, int line, char ch) | |
2372 | { | |
2373 | struct uart_driver *drv = driver->driver_state; | |
2374 | struct uart_state *state = drv->state + line; | |
2375 | struct uart_port *port; | |
2376 | ||
9ed19428 | 2377 | if (!state) |
f2d937f3 JW |
2378 | return; |
2379 | ||
9ed19428 PH |
2380 | port = uart_port_ref(state); |
2381 | if (!port) | |
2382 | return; | |
c7d44a02 DA |
2383 | |
2384 | if (ch == '\n') | |
2385 | port->ops->poll_put_char(port, '\r'); | |
f2d937f3 | 2386 | port->ops->poll_put_char(port, ch); |
9ed19428 | 2387 | uart_port_deref(port); |
f2d937f3 JW |
2388 | } |
2389 | #endif | |
2390 | ||
b68e31d0 | 2391 | static const struct tty_operations uart_ops = { |
1da177e4 LT |
2392 | .open = uart_open, |
2393 | .close = uart_close, | |
2394 | .write = uart_write, | |
2395 | .put_char = uart_put_char, | |
2396 | .flush_chars = uart_flush_chars, | |
2397 | .write_room = uart_write_room, | |
2398 | .chars_in_buffer= uart_chars_in_buffer, | |
2399 | .flush_buffer = uart_flush_buffer, | |
2400 | .ioctl = uart_ioctl, | |
2401 | .throttle = uart_throttle, | |
2402 | .unthrottle = uart_unthrottle, | |
2403 | .send_xchar = uart_send_xchar, | |
2404 | .set_termios = uart_set_termios, | |
64e9159f | 2405 | .set_ldisc = uart_set_ldisc, |
1da177e4 LT |
2406 | .stop = uart_stop, |
2407 | .start = uart_start, | |
2408 | .hangup = uart_hangup, | |
2409 | .break_ctl = uart_break_ctl, | |
2410 | .wait_until_sent= uart_wait_until_sent, | |
2411 | #ifdef CONFIG_PROC_FS | |
d196a949 | 2412 | .proc_fops = &uart_proc_fops, |
1da177e4 LT |
2413 | #endif |
2414 | .tiocmget = uart_tiocmget, | |
2415 | .tiocmset = uart_tiocmset, | |
d281da7f | 2416 | .get_icount = uart_get_icount, |
f2d937f3 JW |
2417 | #ifdef CONFIG_CONSOLE_POLL |
2418 | .poll_init = uart_poll_init, | |
2419 | .poll_get_char = uart_poll_get_char, | |
2420 | .poll_put_char = uart_poll_put_char, | |
2421 | #endif | |
1da177e4 LT |
2422 | }; |
2423 | ||
de0c8cb3 AC |
2424 | static const struct tty_port_operations uart_port_ops = { |
2425 | .carrier_raised = uart_carrier_raised, | |
2426 | .dtr_rts = uart_dtr_rts, | |
b3b57646 | 2427 | .activate = uart_port_activate, |
761ed4a9 | 2428 | .shutdown = uart_tty_port_shutdown, |
de0c8cb3 AC |
2429 | }; |
2430 | ||
1da177e4 LT |
2431 | /** |
2432 | * uart_register_driver - register a driver with the uart core layer | |
2433 | * @drv: low level driver structure | |
2434 | * | |
2435 | * Register a uart driver with the core driver. We in turn register | |
2436 | * with the tty layer, and initialise the core driver per-port state. | |
2437 | * | |
2438 | * We have a proc file in /proc/tty/driver which is named after the | |
2439 | * normal driver. | |
2440 | * | |
2441 | * drv->port should be NULL, and the per-port structures should be | |
2442 | * registered using uart_add_one_port after this call has succeeded. | |
2443 | */ | |
2444 | int uart_register_driver(struct uart_driver *drv) | |
2445 | { | |
9e845abf | 2446 | struct tty_driver *normal; |
1da177e4 LT |
2447 | int i, retval; |
2448 | ||
2449 | BUG_ON(drv->state); | |
2450 | ||
2451 | /* | |
2452 | * Maybe we should be using a slab cache for this, especially if | |
2453 | * we have a large number of ports to handle. | |
2454 | */ | |
8f31bb39 | 2455 | drv->state = kzalloc(sizeof(struct uart_state) * drv->nr, GFP_KERNEL); |
1da177e4 LT |
2456 | if (!drv->state) |
2457 | goto out; | |
2458 | ||
9e845abf | 2459 | normal = alloc_tty_driver(drv->nr); |
1da177e4 | 2460 | if (!normal) |
9e845abf | 2461 | goto out_kfree; |
1da177e4 LT |
2462 | |
2463 | drv->tty_driver = normal; | |
2464 | ||
1da177e4 | 2465 | normal->driver_name = drv->driver_name; |
1da177e4 LT |
2466 | normal->name = drv->dev_name; |
2467 | normal->major = drv->major; | |
2468 | normal->minor_start = drv->minor; | |
2469 | normal->type = TTY_DRIVER_TYPE_SERIAL; | |
2470 | normal->subtype = SERIAL_TYPE_NORMAL; | |
2471 | normal->init_termios = tty_std_termios; | |
2472 | normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | |
606d099c | 2473 | normal->init_termios.c_ispeed = normal->init_termios.c_ospeed = 9600; |
331b8319 | 2474 | normal->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
1da177e4 LT |
2475 | normal->driver_state = drv; |
2476 | tty_set_operations(normal, &uart_ops); | |
2477 | ||
2478 | /* | |
2479 | * Initialise the UART state(s). | |
2480 | */ | |
2481 | for (i = 0; i < drv->nr; i++) { | |
2482 | struct uart_state *state = drv->state + i; | |
a2bceae0 | 2483 | struct tty_port *port = &state->port; |
1da177e4 | 2484 | |
a2bceae0 | 2485 | tty_port_init(port); |
de0c8cb3 | 2486 | port->ops = &uart_port_ops; |
1da177e4 LT |
2487 | } |
2488 | ||
2489 | retval = tty_register_driver(normal); | |
9e845abf AGR |
2490 | if (retval >= 0) |
2491 | return retval; | |
2492 | ||
191c5f10 JS |
2493 | for (i = 0; i < drv->nr; i++) |
2494 | tty_port_destroy(&drv->state[i].port); | |
9e845abf AGR |
2495 | put_tty_driver(normal); |
2496 | out_kfree: | |
2497 | kfree(drv->state); | |
2498 | out: | |
2499 | return -ENOMEM; | |
1da177e4 LT |
2500 | } |
2501 | ||
2502 | /** | |
2503 | * uart_unregister_driver - remove a driver from the uart core layer | |
2504 | * @drv: low level driver structure | |
2505 | * | |
2506 | * Remove all references to a driver from the core driver. The low | |
2507 | * level driver must have removed all its ports via the | |
2508 | * uart_remove_one_port() if it registered them with uart_add_one_port(). | |
2509 | * (ie, drv->port == NULL) | |
2510 | */ | |
2511 | void uart_unregister_driver(struct uart_driver *drv) | |
2512 | { | |
2513 | struct tty_driver *p = drv->tty_driver; | |
191c5f10 JS |
2514 | unsigned int i; |
2515 | ||
1da177e4 LT |
2516 | tty_unregister_driver(p); |
2517 | put_tty_driver(p); | |
191c5f10 JS |
2518 | for (i = 0; i < drv->nr; i++) |
2519 | tty_port_destroy(&drv->state[i].port); | |
1da177e4 | 2520 | kfree(drv->state); |
1e66cded | 2521 | drv->state = NULL; |
1da177e4 LT |
2522 | drv->tty_driver = NULL; |
2523 | } | |
2524 | ||
2525 | struct tty_driver *uart_console_device(struct console *co, int *index) | |
2526 | { | |
2527 | struct uart_driver *p = co->data; | |
2528 | *index = co->index; | |
2529 | return p->tty_driver; | |
2530 | } | |
2531 | ||
6915c0e4 TH |
2532 | static ssize_t uart_get_attr_uartclk(struct device *dev, |
2533 | struct device_attribute *attr, char *buf) | |
2534 | { | |
bebe73e3 | 2535 | struct serial_struct tmp; |
6915c0e4 | 2536 | struct tty_port *port = dev_get_drvdata(dev); |
6915c0e4 | 2537 | |
9f109694 | 2538 | uart_get_info(port, &tmp); |
bebe73e3 | 2539 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.baud_base * 16); |
6915c0e4 TH |
2540 | } |
2541 | ||
373bac4c AC |
2542 | static ssize_t uart_get_attr_type(struct device *dev, |
2543 | struct device_attribute *attr, char *buf) | |
2544 | { | |
2545 | struct serial_struct tmp; | |
2546 | struct tty_port *port = dev_get_drvdata(dev); | |
2547 | ||
2548 | uart_get_info(port, &tmp); | |
2549 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.type); | |
2550 | } | |
2551 | static ssize_t uart_get_attr_line(struct device *dev, | |
2552 | struct device_attribute *attr, char *buf) | |
2553 | { | |
2554 | struct serial_struct tmp; | |
2555 | struct tty_port *port = dev_get_drvdata(dev); | |
2556 | ||
2557 | uart_get_info(port, &tmp); | |
2558 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.line); | |
2559 | } | |
2560 | ||
2561 | static ssize_t uart_get_attr_port(struct device *dev, | |
2562 | struct device_attribute *attr, char *buf) | |
2563 | { | |
2564 | struct serial_struct tmp; | |
2565 | struct tty_port *port = dev_get_drvdata(dev); | |
fd985e1d | 2566 | unsigned long ioaddr; |
373bac4c AC |
2567 | |
2568 | uart_get_info(port, &tmp); | |
fd985e1d AM |
2569 | ioaddr = tmp.port; |
2570 | if (HIGH_BITS_OFFSET) | |
2571 | ioaddr |= (unsigned long)tmp.port_high << HIGH_BITS_OFFSET; | |
2572 | return snprintf(buf, PAGE_SIZE, "0x%lX\n", ioaddr); | |
373bac4c AC |
2573 | } |
2574 | ||
2575 | static ssize_t uart_get_attr_irq(struct device *dev, | |
2576 | struct device_attribute *attr, char *buf) | |
2577 | { | |
2578 | struct serial_struct tmp; | |
2579 | struct tty_port *port = dev_get_drvdata(dev); | |
2580 | ||
2581 | uart_get_info(port, &tmp); | |
2582 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.irq); | |
2583 | } | |
2584 | ||
2585 | static ssize_t uart_get_attr_flags(struct device *dev, | |
2586 | struct device_attribute *attr, char *buf) | |
2587 | { | |
2588 | struct serial_struct tmp; | |
2589 | struct tty_port *port = dev_get_drvdata(dev); | |
2590 | ||
2591 | uart_get_info(port, &tmp); | |
2592 | return snprintf(buf, PAGE_SIZE, "0x%X\n", tmp.flags); | |
2593 | } | |
2594 | ||
2595 | static ssize_t uart_get_attr_xmit_fifo_size(struct device *dev, | |
2596 | struct device_attribute *attr, char *buf) | |
2597 | { | |
2598 | struct serial_struct tmp; | |
2599 | struct tty_port *port = dev_get_drvdata(dev); | |
2600 | ||
2601 | uart_get_info(port, &tmp); | |
2602 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.xmit_fifo_size); | |
2603 | } | |
2604 | ||
2605 | ||
2606 | static ssize_t uart_get_attr_close_delay(struct device *dev, | |
2607 | struct device_attribute *attr, char *buf) | |
2608 | { | |
2609 | struct serial_struct tmp; | |
2610 | struct tty_port *port = dev_get_drvdata(dev); | |
2611 | ||
2612 | uart_get_info(port, &tmp); | |
2613 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.close_delay); | |
2614 | } | |
2615 | ||
2616 | ||
2617 | static ssize_t uart_get_attr_closing_wait(struct device *dev, | |
2618 | struct device_attribute *attr, char *buf) | |
2619 | { | |
2620 | struct serial_struct tmp; | |
2621 | struct tty_port *port = dev_get_drvdata(dev); | |
2622 | ||
2623 | uart_get_info(port, &tmp); | |
2624 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.closing_wait); | |
2625 | } | |
2626 | ||
2627 | static ssize_t uart_get_attr_custom_divisor(struct device *dev, | |
2628 | struct device_attribute *attr, char *buf) | |
2629 | { | |
2630 | struct serial_struct tmp; | |
2631 | struct tty_port *port = dev_get_drvdata(dev); | |
2632 | ||
2633 | uart_get_info(port, &tmp); | |
2634 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.custom_divisor); | |
2635 | } | |
2636 | ||
2637 | static ssize_t uart_get_attr_io_type(struct device *dev, | |
2638 | struct device_attribute *attr, char *buf) | |
2639 | { | |
2640 | struct serial_struct tmp; | |
2641 | struct tty_port *port = dev_get_drvdata(dev); | |
2642 | ||
2643 | uart_get_info(port, &tmp); | |
2644 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.io_type); | |
2645 | } | |
2646 | ||
2647 | static ssize_t uart_get_attr_iomem_base(struct device *dev, | |
2648 | struct device_attribute *attr, char *buf) | |
2649 | { | |
2650 | struct serial_struct tmp; | |
2651 | struct tty_port *port = dev_get_drvdata(dev); | |
2652 | ||
2653 | uart_get_info(port, &tmp); | |
2654 | return snprintf(buf, PAGE_SIZE, "0x%lX\n", (unsigned long)tmp.iomem_base); | |
2655 | } | |
2656 | ||
2657 | static ssize_t uart_get_attr_iomem_reg_shift(struct device *dev, | |
2658 | struct device_attribute *attr, char *buf) | |
2659 | { | |
2660 | struct serial_struct tmp; | |
2661 | struct tty_port *port = dev_get_drvdata(dev); | |
2662 | ||
2663 | uart_get_info(port, &tmp); | |
2664 | return snprintf(buf, PAGE_SIZE, "%d\n", tmp.iomem_reg_shift); | |
2665 | } | |
2666 | ||
2667 | static DEVICE_ATTR(type, S_IRUSR | S_IRGRP, uart_get_attr_type, NULL); | |
2668 | static DEVICE_ATTR(line, S_IRUSR | S_IRGRP, uart_get_attr_line, NULL); | |
2669 | static DEVICE_ATTR(port, S_IRUSR | S_IRGRP, uart_get_attr_port, NULL); | |
2670 | static DEVICE_ATTR(irq, S_IRUSR | S_IRGRP, uart_get_attr_irq, NULL); | |
2671 | static DEVICE_ATTR(flags, S_IRUSR | S_IRGRP, uart_get_attr_flags, NULL); | |
2672 | static DEVICE_ATTR(xmit_fifo_size, S_IRUSR | S_IRGRP, uart_get_attr_xmit_fifo_size, NULL); | |
6915c0e4 | 2673 | static DEVICE_ATTR(uartclk, S_IRUSR | S_IRGRP, uart_get_attr_uartclk, NULL); |
373bac4c AC |
2674 | static DEVICE_ATTR(close_delay, S_IRUSR | S_IRGRP, uart_get_attr_close_delay, NULL); |
2675 | static DEVICE_ATTR(closing_wait, S_IRUSR | S_IRGRP, uart_get_attr_closing_wait, NULL); | |
2676 | static DEVICE_ATTR(custom_divisor, S_IRUSR | S_IRGRP, uart_get_attr_custom_divisor, NULL); | |
2677 | static DEVICE_ATTR(io_type, S_IRUSR | S_IRGRP, uart_get_attr_io_type, NULL); | |
2678 | static DEVICE_ATTR(iomem_base, S_IRUSR | S_IRGRP, uart_get_attr_iomem_base, NULL); | |
2679 | static DEVICE_ATTR(iomem_reg_shift, S_IRUSR | S_IRGRP, uart_get_attr_iomem_reg_shift, NULL); | |
6915c0e4 TH |
2680 | |
2681 | static struct attribute *tty_dev_attrs[] = { | |
373bac4c AC |
2682 | &dev_attr_type.attr, |
2683 | &dev_attr_line.attr, | |
2684 | &dev_attr_port.attr, | |
2685 | &dev_attr_irq.attr, | |
2686 | &dev_attr_flags.attr, | |
2687 | &dev_attr_xmit_fifo_size.attr, | |
6915c0e4 | 2688 | &dev_attr_uartclk.attr, |
373bac4c AC |
2689 | &dev_attr_close_delay.attr, |
2690 | &dev_attr_closing_wait.attr, | |
2691 | &dev_attr_custom_divisor.attr, | |
2692 | &dev_attr_io_type.attr, | |
2693 | &dev_attr_iomem_base.attr, | |
2694 | &dev_attr_iomem_reg_shift.attr, | |
6915c0e4 TH |
2695 | NULL, |
2696 | }; | |
2697 | ||
b1b79916 | 2698 | static const struct attribute_group tty_dev_attr_group = { |
6915c0e4 TH |
2699 | .attrs = tty_dev_attrs, |
2700 | }; | |
2701 | ||
1da177e4 LT |
2702 | /** |
2703 | * uart_add_one_port - attach a driver-defined port structure | |
2704 | * @drv: pointer to the uart low level driver structure for this port | |
1b9894f3 | 2705 | * @uport: uart port structure to use for this port. |
1da177e4 LT |
2706 | * |
2707 | * This allows the driver to register its own uart_port structure | |
2708 | * with the core driver. The main purpose is to allow the low | |
2709 | * level uart drivers to expand uart_port, rather than having yet | |
2710 | * more levels of structures. | |
2711 | */ | |
a2bceae0 | 2712 | int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) |
1da177e4 LT |
2713 | { |
2714 | struct uart_state *state; | |
a2bceae0 | 2715 | struct tty_port *port; |
1da177e4 | 2716 | int ret = 0; |
b3b708fa | 2717 | struct device *tty_dev; |
266dcff0 | 2718 | int num_groups; |
1da177e4 LT |
2719 | |
2720 | BUG_ON(in_interrupt()); | |
2721 | ||
a2bceae0 | 2722 | if (uport->line >= drv->nr) |
1da177e4 LT |
2723 | return -EINVAL; |
2724 | ||
a2bceae0 AC |
2725 | state = drv->state + uport->line; |
2726 | port = &state->port; | |
1da177e4 | 2727 | |
f392ecfa | 2728 | mutex_lock(&port_mutex); |
a2bceae0 | 2729 | mutex_lock(&port->mutex); |
ebd2c8f6 | 2730 | if (state->uart_port) { |
1da177e4 LT |
2731 | ret = -EINVAL; |
2732 | goto out; | |
2733 | } | |
2734 | ||
2b702b9b | 2735 | /* Link the port to the driver state table and vice versa */ |
9ed19428 PH |
2736 | atomic_set(&state->refcount, 1); |
2737 | init_waitqueue_head(&state->remove_wait); | |
a2bceae0 | 2738 | state->uart_port = uport; |
2b702b9b | 2739 | uport->state = state; |
1da177e4 | 2740 | |
2b702b9b | 2741 | state->pm_state = UART_PM_STATE_UNDEFINED; |
a2bceae0 | 2742 | uport->cons = drv->cons; |
959801fe | 2743 | uport->minor = drv->tty_driver->minor_start + uport->line; |
1da177e4 | 2744 | |
761ed4a9 RH |
2745 | port->console = uart_console(uport); |
2746 | ||
976ecd12 RK |
2747 | /* |
2748 | * If this port is a console, then the spinlock is already | |
2749 | * initialised. | |
2750 | */ | |
a2bceae0 AC |
2751 | if (!(uart_console(uport) && (uport->cons->flags & CON_ENABLED))) { |
2752 | spin_lock_init(&uport->lock); | |
2753 | lockdep_set_class(&uport->lock, &port_lock_key); | |
13e83599 | 2754 | } |
a208ffd2 GL |
2755 | if (uport->cons && uport->dev) |
2756 | of_console_check(uport->dev->of_node, uport->cons->name, uport->line); | |
976ecd12 | 2757 | |
a2bceae0 | 2758 | uart_configure_port(drv, state, uport); |
1da177e4 | 2759 | |
266dcff0 GKH |
2760 | num_groups = 2; |
2761 | if (uport->attr_group) | |
2762 | num_groups++; | |
2763 | ||
c2b703b8 | 2764 | uport->tty_groups = kcalloc(num_groups, sizeof(*uport->tty_groups), |
266dcff0 GKH |
2765 | GFP_KERNEL); |
2766 | if (!uport->tty_groups) { | |
2767 | ret = -ENOMEM; | |
2768 | goto out; | |
2769 | } | |
2770 | uport->tty_groups[0] = &tty_dev_attr_group; | |
2771 | if (uport->attr_group) | |
2772 | uport->tty_groups[1] = uport->attr_group; | |
2773 | ||
1da177e4 LT |
2774 | /* |
2775 | * Register the port whether it's detected or not. This allows | |
015355b7 | 2776 | * setserial to be used to alter this port's parameters. |
1da177e4 | 2777 | */ |
b1b79916 | 2778 | tty_dev = tty_port_register_device_attr(port, drv->tty_driver, |
266dcff0 | 2779 | uport->line, uport->dev, port, uport->tty_groups); |
b3b708fa | 2780 | if (likely(!IS_ERR(tty_dev))) { |
77359835 SG |
2781 | device_set_wakeup_capable(tty_dev, 1); |
2782 | } else { | |
2f2dafe7 | 2783 | dev_err(uport->dev, "Cannot register tty device on line %d\n", |
a2bceae0 | 2784 | uport->line); |
77359835 | 2785 | } |
1da177e4 | 2786 | |
68ac64cd RK |
2787 | /* |
2788 | * Ensure UPF_DEAD is not set. | |
2789 | */ | |
a2bceae0 | 2790 | uport->flags &= ~UPF_DEAD; |
68ac64cd | 2791 | |
1da177e4 | 2792 | out: |
a2bceae0 | 2793 | mutex_unlock(&port->mutex); |
f392ecfa | 2794 | mutex_unlock(&port_mutex); |
1da177e4 LT |
2795 | |
2796 | return ret; | |
2797 | } | |
2798 | ||
2799 | /** | |
2800 | * uart_remove_one_port - detach a driver defined port structure | |
2801 | * @drv: pointer to the uart low level driver structure for this port | |
1b9894f3 | 2802 | * @uport: uart port structure for this port |
1da177e4 LT |
2803 | * |
2804 | * This unhooks (and hangs up) the specified port structure from the | |
2805 | * core driver. No further calls will be made to the low-level code | |
2806 | * for this port. | |
2807 | */ | |
a2bceae0 | 2808 | int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport) |
1da177e4 | 2809 | { |
a2bceae0 AC |
2810 | struct uart_state *state = drv->state + uport->line; |
2811 | struct tty_port *port = &state->port; | |
4047b371 | 2812 | struct uart_port *uart_port; |
4c6d5b4d | 2813 | struct tty_struct *tty; |
b342dd51 | 2814 | int ret = 0; |
1da177e4 LT |
2815 | |
2816 | BUG_ON(in_interrupt()); | |
2817 | ||
f392ecfa | 2818 | mutex_lock(&port_mutex); |
1da177e4 | 2819 | |
68ac64cd RK |
2820 | /* |
2821 | * Mark the port "dead" - this prevents any opens from | |
2822 | * succeeding while we shut down the port. | |
2823 | */ | |
a2bceae0 | 2824 | mutex_lock(&port->mutex); |
4047b371 PH |
2825 | uart_port = uart_port_check(state); |
2826 | if (uart_port != uport) | |
2827 | dev_alert(uport->dev, "Removing wrong port: %p != %p\n", | |
2828 | uart_port, uport); | |
2829 | ||
2830 | if (!uart_port) { | |
b342dd51 CG |
2831 | mutex_unlock(&port->mutex); |
2832 | ret = -EINVAL; | |
2833 | goto out; | |
2834 | } | |
a2bceae0 AC |
2835 | uport->flags |= UPF_DEAD; |
2836 | mutex_unlock(&port->mutex); | |
68ac64cd | 2837 | |
1da177e4 | 2838 | /* |
aa4148cf | 2839 | * Remove the devices from the tty layer |
1da177e4 | 2840 | */ |
a2bceae0 | 2841 | tty_unregister_device(drv->tty_driver, uport->line); |
1da177e4 | 2842 | |
4c6d5b4d GU |
2843 | tty = tty_port_tty_get(port); |
2844 | if (tty) { | |
a2bceae0 | 2845 | tty_vhangup(port->tty); |
4c6d5b4d GU |
2846 | tty_kref_put(tty); |
2847 | } | |
68ac64cd | 2848 | |
5f5c9ae5 GU |
2849 | /* |
2850 | * If the port is used as a console, unregister it | |
2851 | */ | |
2852 | if (uart_console(uport)) | |
2853 | unregister_console(uport->cons); | |
2854 | ||
68ac64cd RK |
2855 | /* |
2856 | * Free the port IO and memory resources, if any. | |
2857 | */ | |
a7cfaf16 | 2858 | if (uport->type != PORT_UNKNOWN && uport->ops->release_port) |
a2bceae0 | 2859 | uport->ops->release_port(uport); |
266dcff0 | 2860 | kfree(uport->tty_groups); |
68ac64cd RK |
2861 | |
2862 | /* | |
2863 | * Indicate that there isn't a port here anymore. | |
2864 | */ | |
a2bceae0 | 2865 | uport->type = PORT_UNKNOWN; |
68ac64cd | 2866 | |
4047b371 | 2867 | mutex_lock(&port->mutex); |
9ed19428 PH |
2868 | WARN_ON(atomic_dec_return(&state->refcount) < 0); |
2869 | wait_event(state->remove_wait, !atomic_read(&state->refcount)); | |
ebd2c8f6 | 2870 | state->uart_port = NULL; |
4047b371 | 2871 | mutex_unlock(&port->mutex); |
b342dd51 | 2872 | out: |
f392ecfa | 2873 | mutex_unlock(&port_mutex); |
1da177e4 | 2874 | |
b342dd51 | 2875 | return ret; |
1da177e4 LT |
2876 | } |
2877 | ||
2878 | /* | |
2879 | * Are the two ports equivalent? | |
2880 | */ | |
2881 | int uart_match_port(struct uart_port *port1, struct uart_port *port2) | |
2882 | { | |
2883 | if (port1->iotype != port2->iotype) | |
2884 | return 0; | |
2885 | ||
2886 | switch (port1->iotype) { | |
2887 | case UPIO_PORT: | |
2888 | return (port1->iobase == port2->iobase); | |
2889 | case UPIO_HUB6: | |
2890 | return (port1->iobase == port2->iobase) && | |
2891 | (port1->hub6 == port2->hub6); | |
2892 | case UPIO_MEM: | |
bd94c407 | 2893 | case UPIO_MEM16: |
d21b55d3 | 2894 | case UPIO_MEM32: |
3ffb1a81 | 2895 | case UPIO_MEM32BE: |
d21b55d3 SS |
2896 | case UPIO_AU: |
2897 | case UPIO_TSI: | |
1624f003 | 2898 | return (port1->mapbase == port2->mapbase); |
1da177e4 LT |
2899 | } |
2900 | return 0; | |
2901 | } | |
2902 | EXPORT_SYMBOL(uart_match_port); | |
2903 | ||
027d7dac JS |
2904 | /** |
2905 | * uart_handle_dcd_change - handle a change of carrier detect state | |
2906 | * @uport: uart_port structure for the open port | |
2907 | * @status: new carrier detect status, nonzero if active | |
4d90bb14 PH |
2908 | * |
2909 | * Caller must hold uport->lock | |
027d7dac JS |
2910 | */ |
2911 | void uart_handle_dcd_change(struct uart_port *uport, unsigned int status) | |
2912 | { | |
42381572 | 2913 | struct tty_port *port = &uport->state->port; |
43eca0ae | 2914 | struct tty_struct *tty = port->tty; |
c993257b | 2915 | struct tty_ldisc *ld; |
027d7dac | 2916 | |
4d90bb14 PH |
2917 | lockdep_assert_held_once(&uport->lock); |
2918 | ||
c993257b PH |
2919 | if (tty) { |
2920 | ld = tty_ldisc_ref(tty); | |
2921 | if (ld) { | |
2922 | if (ld->ops->dcd_change) | |
2923 | ld->ops->dcd_change(tty, status); | |
2924 | tty_ldisc_deref(ld); | |
2925 | } | |
42381572 | 2926 | } |
027d7dac JS |
2927 | |
2928 | uport->icount.dcd++; | |
027d7dac | 2929 | |
299245a1 | 2930 | if (uart_dcd_enabled(uport)) { |
027d7dac JS |
2931 | if (status) |
2932 | wake_up_interruptible(&port->open_wait); | |
43eca0ae AC |
2933 | else if (tty) |
2934 | tty_hangup(tty); | |
027d7dac | 2935 | } |
027d7dac JS |
2936 | } |
2937 | EXPORT_SYMBOL_GPL(uart_handle_dcd_change); | |
2938 | ||
2939 | /** | |
2940 | * uart_handle_cts_change - handle a change of clear-to-send state | |
2941 | * @uport: uart_port structure for the open port | |
2942 | * @status: new clear to send status, nonzero if active | |
4d90bb14 PH |
2943 | * |
2944 | * Caller must hold uport->lock | |
027d7dac JS |
2945 | */ |
2946 | void uart_handle_cts_change(struct uart_port *uport, unsigned int status) | |
2947 | { | |
4d90bb14 PH |
2948 | lockdep_assert_held_once(&uport->lock); |
2949 | ||
027d7dac JS |
2950 | uport->icount.cts++; |
2951 | ||
391f93f2 | 2952 | if (uart_softcts_mode(uport)) { |
d01f4d18 | 2953 | if (uport->hw_stopped) { |
027d7dac | 2954 | if (status) { |
d01f4d18 | 2955 | uport->hw_stopped = 0; |
027d7dac JS |
2956 | uport->ops->start_tx(uport); |
2957 | uart_write_wakeup(uport); | |
2958 | } | |
2959 | } else { | |
2960 | if (!status) { | |
d01f4d18 | 2961 | uport->hw_stopped = 1; |
027d7dac JS |
2962 | uport->ops->stop_tx(uport); |
2963 | } | |
2964 | } | |
391f93f2 | 2965 | |
027d7dac JS |
2966 | } |
2967 | } | |
2968 | EXPORT_SYMBOL_GPL(uart_handle_cts_change); | |
2969 | ||
cf75525f JS |
2970 | /** |
2971 | * uart_insert_char - push a char to the uart layer | |
2972 | * | |
2973 | * User is responsible to call tty_flip_buffer_push when they are done with | |
2974 | * insertion. | |
2975 | * | |
2976 | * @port: corresponding port | |
2977 | * @status: state of the serial port RX buffer (LSR for 8250) | |
2978 | * @overrun: mask of overrun bits in @status | |
2979 | * @ch: character to push | |
2980 | * @flag: flag for the character (see TTY_NORMAL and friends) | |
2981 | */ | |
027d7dac JS |
2982 | void uart_insert_char(struct uart_port *port, unsigned int status, |
2983 | unsigned int overrun, unsigned int ch, unsigned int flag) | |
2984 | { | |
92a19f9c | 2985 | struct tty_port *tport = &port->state->port; |
027d7dac JS |
2986 | |
2987 | if ((status & port->ignore_status_mask & ~overrun) == 0) | |
92a19f9c | 2988 | if (tty_insert_flip_char(tport, ch, flag) == 0) |
dabfb351 | 2989 | ++port->icount.buf_overrun; |
027d7dac JS |
2990 | |
2991 | /* | |
2992 | * Overrun is special. Since it's reported immediately, | |
2993 | * it doesn't affect the current character. | |
2994 | */ | |
2995 | if (status & ~port->ignore_status_mask & overrun) | |
92a19f9c | 2996 | if (tty_insert_flip_char(tport, 0, TTY_OVERRUN) == 0) |
dabfb351 | 2997 | ++port->icount.buf_overrun; |
027d7dac JS |
2998 | } |
2999 | EXPORT_SYMBOL_GPL(uart_insert_char); | |
3000 | ||
1da177e4 LT |
3001 | EXPORT_SYMBOL(uart_write_wakeup); |
3002 | EXPORT_SYMBOL(uart_register_driver); | |
3003 | EXPORT_SYMBOL(uart_unregister_driver); | |
3004 | EXPORT_SYMBOL(uart_suspend_port); | |
3005 | EXPORT_SYMBOL(uart_resume_port); | |
1da177e4 LT |
3006 | EXPORT_SYMBOL(uart_add_one_port); |
3007 | EXPORT_SYMBOL(uart_remove_one_port); | |
3008 | ||
3009 | MODULE_DESCRIPTION("Serial driver core"); | |
3010 | MODULE_LICENSE("GPL"); |