aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial
diff options
context:
space:
mode:
authorAlan Cox <alan@linux.intel.com>2009-09-19 16:13:30 -0400
committerLive-CD User <linux@linux.site>2009-09-19 16:13:30 -0400
commitccce6debb62d94964e3878f978a56b0f3e32d94f (patch)
treec6df089e5b4394d841819090921b1673901d7a3a /drivers/serial
parent91312cdb4fcd832341e425f74f49938e0503c929 (diff)
serial: move the flags into the tty_port field
Fortunately the serial layer was designed to use the same flag values but with different names. It has its own SUSPENDED flag which is a free slot in the ASYNC flags so we allocate it in the ASYNC flags instead. Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/serial')
-rw-r--r--drivers/serial/serial_core.c153
1 files changed, 77 insertions, 76 deletions
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 4af3364dd811..744dec9301fb 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -29,10 +29,10 @@
29#include <linux/console.h> 29#include <linux/console.h>
30#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/serial_core.h>
33#include <linux/smp_lock.h> 32#include <linux/smp_lock.h>
34#include <linux/device.h> 33#include <linux/device.h>
35#include <linux/serial.h> /* for serial_state and serial_icounter_struct */ 34#include <linux/serial.h> /* for serial_state and serial_icounter_struct */
35#include <linux/serial_core.h>
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/mutex.h> 37#include <linux/mutex.h>
38 38
@@ -146,7 +146,7 @@ static int uart_startup(struct uart_state *state, int init_hw)
146 unsigned long page; 146 unsigned long page;
147 int retval = 0; 147 int retval = 0;
148 148
149 if (state->flags & UIF_INITIALIZED) 149 if (port->flags & ASYNC_INITIALIZED)
150 return 0; 150 return 0;
151 151
152 /* 152 /*
@@ -189,14 +189,14 @@ static int uart_startup(struct uart_state *state, int init_hw)
189 uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR); 189 uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR);
190 } 190 }
191 191
192 if (state->flags & UIF_CTS_FLOW) { 192 if (port->flags & ASYNC_CTS_FLOW) {
193 spin_lock_irq(&uport->lock); 193 spin_lock_irq(&uport->lock);
194 if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS)) 194 if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS))
195 port->tty->hw_stopped = 1; 195 port->tty->hw_stopped = 1;
196 spin_unlock_irq(&uport->lock); 196 spin_unlock_irq(&uport->lock);
197 } 197 }
198 198
199 state->flags |= UIF_INITIALIZED; 199 set_bit(ASYNCB_INITIALIZED, &port->flags);
200 200
201 clear_bit(TTY_IO_ERROR, &port->tty->flags); 201 clear_bit(TTY_IO_ERROR, &port->tty->flags);
202 } 202 }
@@ -214,7 +214,7 @@ static int uart_startup(struct uart_state *state, int init_hw)
214 */ 214 */
215static void uart_shutdown(struct uart_state *state) 215static void uart_shutdown(struct uart_state *state)
216{ 216{
217 struct uart_port *port = state->uart_port; 217 struct uart_port *uport = state->uart_port;
218 struct tty_struct *tty = state->port.tty; 218 struct tty_struct *tty = state->port.tty;
219 219
220 /* 220 /*
@@ -223,14 +223,12 @@ static void uart_shutdown(struct uart_state *state)
223 if (tty) 223 if (tty)
224 set_bit(TTY_IO_ERROR, &tty->flags); 224 set_bit(TTY_IO_ERROR, &tty->flags);
225 225
226 if (state->flags & UIF_INITIALIZED) { 226 if (test_and_clear_bit(ASYNCB_INITIALIZED, &state->port.flags)) {
227 state->flags &= ~UIF_INITIALIZED;
228
229 /* 227 /*
230 * Turn off DTR and RTS early. 228 * Turn off DTR and RTS early.
231 */ 229 */
232 if (!tty || (tty->termios->c_cflag & HUPCL)) 230 if (!tty || (tty->termios->c_cflag & HUPCL))
233 uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 231 uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
234 232
235 /* 233 /*
236 * clear delta_msr_wait queue to avoid mem leaks: we may free 234 * clear delta_msr_wait queue to avoid mem leaks: we may free
@@ -244,12 +242,12 @@ static void uart_shutdown(struct uart_state *state)
244 /* 242 /*
245 * Free the IRQ and disable the port. 243 * Free the IRQ and disable the port.
246 */ 244 */
247 port->ops->shutdown(port); 245 uport->ops->shutdown(uport);
248 246
249 /* 247 /*
250 * Ensure that the IRQ handler isn't running on another CPU. 248 * Ensure that the IRQ handler isn't running on another CPU.
251 */ 249 */
252 synchronize_irq(port->irq); 250 synchronize_irq(uport->irq);
253 } 251 }
254 252
255 /* 253 /*
@@ -429,15 +427,16 @@ EXPORT_SYMBOL(uart_get_divisor);
429static void 427static void
430uart_change_speed(struct uart_state *state, struct ktermios *old_termios) 428uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
431{ 429{
432 struct tty_struct *tty = state->port.tty; 430 struct tty_port *port = &state->port;
433 struct uart_port *port = state->uart_port; 431 struct tty_struct *tty = port->tty;
432 struct uart_port *uport = state->uart_port;
434 struct ktermios *termios; 433 struct ktermios *termios;
435 434
436 /* 435 /*
437 * If we have no tty, termios, or the port does not exist, 436 * If we have no tty, termios, or the port does not exist,
438 * then we can't set the parameters for this port. 437 * then we can't set the parameters for this port.
439 */ 438 */
440 if (!tty || !tty->termios || port->type == PORT_UNKNOWN) 439 if (!tty || !tty->termios || uport->type == PORT_UNKNOWN)
441 return; 440 return;
442 441
443 termios = tty->termios; 442 termios = tty->termios;
@@ -446,16 +445,16 @@ uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
446 * Set flags based on termios cflag 445 * Set flags based on termios cflag
447 */ 446 */
448 if (termios->c_cflag & CRTSCTS) 447 if (termios->c_cflag & CRTSCTS)
449 state->flags |= UIF_CTS_FLOW; 448 set_bit(ASYNCB_CTS_FLOW, &port->flags);
450 else 449 else
451 state->flags &= ~UIF_CTS_FLOW; 450 clear_bit(ASYNCB_CTS_FLOW, &port->flags);
452 451
453 if (termios->c_cflag & CLOCAL) 452 if (termios->c_cflag & CLOCAL)
454 state->flags &= ~UIF_CHECK_CD; 453 clear_bit(ASYNCB_CHECK_CD, &port->flags);
455 else 454 else
456 state->flags |= UIF_CHECK_CD; 455 set_bit(ASYNCB_CHECK_CD, &port->flags);
457 456
458 port->ops->set_termios(port, termios, old_termios); 457 uport->ops->set_termios(uport, termios, old_termios);
459} 458}
460 459
461static inline int 460static inline int
@@ -848,7 +847,7 @@ static int uart_set_info(struct uart_state *state,
848 retval = 0; 847 retval = 0;
849 if (uport->type == PORT_UNKNOWN) 848 if (uport->type == PORT_UNKNOWN)
850 goto exit; 849 goto exit;
851 if (state->flags & UIF_INITIALIZED) { 850 if (port->flags & ASYNC_INITIALIZED) {
852 if (((old_flags ^ uport->flags) & UPF_SPD_MASK) || 851 if (((old_flags ^ uport->flags) & UPF_SPD_MASK) ||
853 old_custom_divisor != uport->custom_divisor) { 852 old_custom_divisor != uport->custom_divisor) {
854 /* 853 /*
@@ -1306,7 +1305,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1306 * At this point, we stop accepting input. To do this, we 1305 * At this point, we stop accepting input. To do this, we
1307 * disable the receive line status interrupts. 1306 * disable the receive line status interrupts.
1308 */ 1307 */
1309 if (state->flags & UIF_INITIALIZED) { 1308 if (port->flags & ASYNC_INITIALIZED) {
1310 unsigned long flags; 1309 unsigned long flags;
1311 spin_lock_irqsave(&port->lock, flags); 1310 spin_lock_irqsave(&port->lock, flags);
1312 uport->ops->stop_rx(uport); 1311 uport->ops->stop_rx(uport);
@@ -1337,7 +1336,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1337 /* 1336 /*
1338 * Wake up anyone trying to open this port. 1337 * Wake up anyone trying to open this port.
1339 */ 1338 */
1340 state->flags &= ~UIF_NORMAL_ACTIVE; 1339 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
1341 wake_up_interruptible(&port->open_wait); 1340 wake_up_interruptible(&port->open_wait);
1342 1341
1343done: 1342done:
@@ -1418,11 +1417,11 @@ static void uart_hangup(struct tty_struct *tty)
1418 pr_debug("uart_hangup(%d)\n", state->uart_port->line); 1417 pr_debug("uart_hangup(%d)\n", state->uart_port->line);
1419 1418
1420 mutex_lock(&state->mutex); 1419 mutex_lock(&state->mutex);
1421 if (state->flags & UIF_NORMAL_ACTIVE) { 1420 if (port->flags & ASYNC_NORMAL_ACTIVE) {
1422 uart_flush_buffer(tty); 1421 uart_flush_buffer(tty);
1423 uart_shutdown(state); 1422 uart_shutdown(state);
1424 port->count = 0; 1423 port->count = 0;
1425 state->flags &= ~UIF_NORMAL_ACTIVE; 1424 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
1426 port->tty = NULL; 1425 port->tty = NULL;
1427 wake_up_interruptible(&port->open_wait); 1426 wake_up_interruptible(&port->open_wait);
1428 wake_up_interruptible(&state->delta_msr_wait); 1427 wake_up_interruptible(&state->delta_msr_wait);
@@ -1493,7 +1492,7 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
1493 /* 1492 /*
1494 * If the port has been closed, tell userspace/restart open. 1493 * If the port has been closed, tell userspace/restart open.
1495 */ 1494 */
1496 if (!(state->flags & UIF_INITIALIZED)) 1495 if (!(port->flags & ASYNC_INITIALIZED))
1497 break; 1496 break;
1498 1497
1499 /* 1498 /*
@@ -1662,8 +1661,8 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1662 /* 1661 /*
1663 * If this is the first open to succeed, adjust things to suit. 1662 * If this is the first open to succeed, adjust things to suit.
1664 */ 1663 */
1665 if (retval == 0 && !(state->flags & UIF_NORMAL_ACTIVE)) { 1664 if (retval == 0 && !(port->flags & ASYNC_NORMAL_ACTIVE)) {
1666 state->flags |= UIF_NORMAL_ACTIVE; 1665 set_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
1667 1666
1668 uart_update_termios(state); 1667 uart_update_termios(state);
1669 } 1668 }
@@ -1985,63 +1984,64 @@ static int serial_match_port(struct device *dev, void *data)
1985 return dev->devt == devt; /* Actually, only one tty per port */ 1984 return dev->devt == devt; /* Actually, only one tty per port */
1986} 1985}
1987 1986
1988int uart_suspend_port(struct uart_driver *drv, struct uart_port *port) 1987int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport)
1989{ 1988{
1990 struct uart_state *state = drv->state + port->line; 1989 struct uart_state *state = drv->state + uport->line;
1990 struct tty_port *port = &state->port;
1991 struct device *tty_dev; 1991 struct device *tty_dev;
1992 struct uart_match match = {port, drv}; 1992 struct uart_match match = {uport, drv};
1993 1993
1994 mutex_lock(&state->mutex); 1994 mutex_lock(&state->mutex);
1995 1995
1996 if (!console_suspend_enabled && uart_console(port)) { 1996 if (!console_suspend_enabled && uart_console(uport)) {
1997 /* we're going to avoid suspending serial console */ 1997 /* we're going to avoid suspending serial console */
1998 mutex_unlock(&state->mutex); 1998 mutex_unlock(&state->mutex);
1999 return 0; 1999 return 0;
2000 } 2000 }
2001 2001
2002 tty_dev = device_find_child(port->dev, &match, serial_match_port); 2002 tty_dev = device_find_child(uport->dev, &match, serial_match_port);
2003 if (device_may_wakeup(tty_dev)) { 2003 if (device_may_wakeup(tty_dev)) {
2004 enable_irq_wake(port->irq); 2004 enable_irq_wake(uport->irq);
2005 put_device(tty_dev); 2005 put_device(tty_dev);
2006 mutex_unlock(&state->mutex); 2006 mutex_unlock(&state->mutex);
2007 return 0; 2007 return 0;
2008 } 2008 }
2009 port->suspended = 1; 2009 uport->suspended = 1;
2010 2010
2011 if (state->flags & UIF_INITIALIZED) { 2011 if (port->flags & ASYNC_INITIALIZED) {
2012 const struct uart_ops *ops = port->ops; 2012 const struct uart_ops *ops = uport->ops;
2013 int tries; 2013 int tries;
2014 2014
2015 state->flags = (state->flags & ~UIF_INITIALIZED) 2015 set_bit(ASYNCB_SUSPENDED, &port->flags);
2016 | UIF_SUSPENDED; 2016 clear_bit(ASYNCB_INITIALIZED, &port->flags);
2017 2017
2018 spin_lock_irq(&port->lock); 2018 spin_lock_irq(&uport->lock);
2019 ops->stop_tx(port); 2019 ops->stop_tx(uport);
2020 ops->set_mctrl(port, 0); 2020 ops->set_mctrl(uport, 0);
2021 ops->stop_rx(port); 2021 ops->stop_rx(uport);
2022 spin_unlock_irq(&port->lock); 2022 spin_unlock_irq(&uport->lock);
2023 2023
2024 /* 2024 /*
2025 * Wait for the transmitter to empty. 2025 * Wait for the transmitter to empty.
2026 */ 2026 */
2027 for (tries = 3; !ops->tx_empty(port) && tries; tries--) 2027 for (tries = 3; !ops->tx_empty(uport) && tries; tries--)
2028 msleep(10); 2028 msleep(10);
2029 if (!tries) 2029 if (!tries)
2030 printk(KERN_ERR "%s%s%s%d: Unable to drain " 2030 printk(KERN_ERR "%s%s%s%d: Unable to drain "
2031 "transmitter\n", 2031 "transmitter\n",
2032 port->dev ? dev_name(port->dev) : "", 2032 uport->dev ? dev_name(uport->dev) : "",
2033 port->dev ? ": " : "", 2033 uport->dev ? ": " : "",
2034 drv->dev_name, 2034 drv->dev_name,
2035 drv->tty_driver->name_base + port->line); 2035 drv->tty_driver->name_base + uport->line);
2036 2036
2037 ops->shutdown(port); 2037 ops->shutdown(uport);
2038 } 2038 }
2039 2039
2040 /* 2040 /*
2041 * Disable the console device before suspending. 2041 * Disable the console device before suspending.
2042 */ 2042 */
2043 if (uart_console(port)) 2043 if (uart_console(uport))
2044 console_stop(port->cons); 2044 console_stop(uport->cons);
2045 2045
2046 uart_change_pm(state, 3); 2046 uart_change_pm(state, 3);
2047 2047
@@ -2050,67 +2050,68 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
2050 return 0; 2050 return 0;
2051} 2051}
2052 2052
2053int uart_resume_port(struct uart_driver *drv, struct uart_port *port) 2053int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
2054{ 2054{
2055 struct uart_state *state = drv->state + port->line; 2055 struct uart_state *state = drv->state + uport->line;
2056 struct tty_port *port = &state->port;
2056 struct device *tty_dev; 2057 struct device *tty_dev;
2057 struct uart_match match = {port, drv}; 2058 struct uart_match match = {uport, drv};
2058 2059
2059 mutex_lock(&state->mutex); 2060 mutex_lock(&state->mutex);
2060 2061
2061 if (!console_suspend_enabled && uart_console(port)) { 2062 if (!console_suspend_enabled && uart_console(uport)) {
2062 /* no need to resume serial console, it wasn't suspended */ 2063 /* no need to resume serial console, it wasn't suspended */
2063 mutex_unlock(&state->mutex); 2064 mutex_unlock(&state->mutex);
2064 return 0; 2065 return 0;
2065 } 2066 }
2066 2067
2067 tty_dev = device_find_child(port->dev, &match, serial_match_port); 2068 tty_dev = device_find_child(uport->dev, &match, serial_match_port);
2068 if (!port->suspended && device_may_wakeup(tty_dev)) { 2069 if (!uport->suspended && device_may_wakeup(tty_dev)) {
2069 disable_irq_wake(port->irq); 2070 disable_irq_wake(uport->irq);
2070 mutex_unlock(&state->mutex); 2071 mutex_unlock(&state->mutex);
2071 return 0; 2072 return 0;
2072 } 2073 }
2073 port->suspended = 0; 2074 uport->suspended = 0;
2074 2075
2075 /* 2076 /*
2076 * Re-enable the console device after suspending. 2077 * Re-enable the console device after suspending.
2077 */ 2078 */
2078 if (uart_console(port)) { 2079 if (uart_console(uport)) {
2079 struct ktermios termios; 2080 struct ktermios termios;
2080 2081
2081 /* 2082 /*
2082 * First try to use the console cflag setting. 2083 * First try to use the console cflag setting.
2083 */ 2084 */
2084 memset(&termios, 0, sizeof(struct ktermios)); 2085 memset(&termios, 0, sizeof(struct ktermios));
2085 termios.c_cflag = port->cons->cflag; 2086 termios.c_cflag = uport->cons->cflag;
2086 2087
2087 /* 2088 /*
2088 * If that's unset, use the tty termios setting. 2089 * If that's unset, use the tty termios setting.
2089 */ 2090 */
2090 if (state->port.tty && termios.c_cflag == 0) 2091 if (port->tty && termios.c_cflag == 0)
2091 termios = *state->port.tty->termios; 2092 termios = *port->tty->termios;
2092 2093
2093 uart_change_pm(state, 0); 2094 uart_change_pm(state, 0);
2094 port->ops->set_termios(port, &termios, NULL); 2095 uport->ops->set_termios(uport, &termios, NULL);
2095 console_start(port->cons); 2096 console_start(uport->cons);
2096 } 2097 }
2097 2098
2098 if (state->flags & UIF_SUSPENDED) { 2099 if (port->flags & ASYNC_SUSPENDED) {
2099 const struct uart_ops *ops = port->ops; 2100 const struct uart_ops *ops = uport->ops;
2100 int ret; 2101 int ret;
2101 2102
2102 uart_change_pm(state, 0); 2103 uart_change_pm(state, 0);
2103 spin_lock_irq(&port->lock); 2104 spin_lock_irq(&uport->lock);
2104 ops->set_mctrl(port, 0); 2105 ops->set_mctrl(uport, 0);
2105 spin_unlock_irq(&port->lock); 2106 spin_unlock_irq(&uport->lock);
2106 ret = ops->startup(port); 2107 ret = ops->startup(uport);
2107 if (ret == 0) { 2108 if (ret == 0) {
2108 uart_change_speed(state, NULL); 2109 uart_change_speed(state, NULL);
2109 spin_lock_irq(&port->lock); 2110 spin_lock_irq(&uport->lock);
2110 ops->set_mctrl(port, port->mctrl); 2111 ops->set_mctrl(uport, uport->mctrl);
2111 ops->start_tx(port); 2112 ops->start_tx(uport);
2112 spin_unlock_irq(&port->lock); 2113 spin_unlock_irq(&uport->lock);
2113 state->flags |= UIF_INITIALIZED; 2114 set_bit(ASYNCB_INITIALIZED, &port->flags);
2114 } else { 2115 } else {
2115 /* 2116 /*
2116 * Failed to resume - maybe hardware went away? 2117 * Failed to resume - maybe hardware went away?
@@ -2120,7 +2121,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
2120 uart_shutdown(state); 2121 uart_shutdown(state);
2121 } 2122 }
2122 2123
2123 state->flags &= ~UIF_SUSPENDED; 2124 clear_bit(ASYNCB_SUSPENDED, &port->flags);
2124 } 2125 }
2125 2126
2126 mutex_unlock(&state->mutex); 2127 mutex_unlock(&state->mutex);