29
29
#include <linux/console.h>
30
30
#include <linux/proc_fs.h>
31
31
#include <linux/seq_file.h>
32
- #include <linux/serial_core.h>
33
32
#include <linux/smp_lock.h>
34
33
#include <linux/device.h>
35
34
#include <linux/serial.h> /* for serial_state and serial_icounter_struct */
35
+ #include <linux/serial_core.h>
36
36
#include <linux/delay.h>
37
37
#include <linux/mutex.h>
38
38
@@ -146,7 +146,7 @@ static int uart_startup(struct uart_state *state, int init_hw)
146
146
unsigned long page ;
147
147
int retval = 0 ;
148
148
149
- if (state -> flags & UIF_INITIALIZED )
149
+ if (port -> flags & ASYNC_INITIALIZED )
150
150
return 0 ;
151
151
152
152
/*
@@ -189,14 +189,14 @@ static int uart_startup(struct uart_state *state, int init_hw)
189
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
193
spin_lock_irq (& uport -> lock );
194
194
if (!(uport -> ops -> get_mctrl (uport ) & TIOCM_CTS ))
195
195
port -> tty -> hw_stopped = 1 ;
196
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
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
*/
215
215
static 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
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
223
if (tty )
224
224
set_bit (TTY_IO_ERROR , & tty -> flags );
225
225
226
- if (state -> flags & UIF_INITIALIZED ) {
227
- state -> flags &= ~UIF_INITIALIZED ;
228
-
226
+ if (test_and_clear_bit (ASYNCB_INITIALIZED , & state -> port .flags )) {
229
227
/*
230
228
* Turn off DTR and RTS early.
231
229
*/
232
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
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
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
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);
429
427
static void
430
428
uart_change_speed (struct uart_state * state , struct ktermios * old_termios )
431
429
{
432
- struct tty_struct * tty = state -> port .tty ;
433
- struct uart_port * port = state -> uart_port ;
430
+ struct tty_port * port = & state -> port ;
431
+ struct tty_struct * tty = port -> tty ;
432
+ struct uart_port * uport = state -> uart_port ;
434
433
struct ktermios * termios ;
435
434
436
435
/*
437
436
* If we have no tty, termios, or the port does not exist,
438
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
440
return ;
442
441
443
442
termios = tty -> termios ;
@@ -446,16 +445,16 @@ uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
446
445
* Set flags based on termios cflag
447
446
*/
448
447
if (termios -> c_cflag & CRTSCTS )
449
- state -> flags |= UIF_CTS_FLOW ;
448
+ set_bit ( ASYNCB_CTS_FLOW , & port -> flags ) ;
450
449
else
451
- state -> flags &= ~ UIF_CTS_FLOW ;
450
+ clear_bit ( ASYNCB_CTS_FLOW , & port -> flags ) ;
452
451
453
452
if (termios -> c_cflag & CLOCAL )
454
- state -> flags &= ~ UIF_CHECK_CD ;
453
+ clear_bit ( ASYNCB_CHECK_CD , & port -> flags ) ;
455
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
461
460
static inline int
@@ -848,7 +847,7 @@ static int uart_set_info(struct uart_state *state,
848
847
retval = 0 ;
849
848
if (uport -> type == PORT_UNKNOWN )
850
849
goto exit ;
851
- if (state -> flags & UIF_INITIALIZED ) {
850
+ if (port -> flags & ASYNC_INITIALIZED ) {
852
851
if (((old_flags ^ uport -> flags ) & UPF_SPD_MASK ) ||
853
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
1305
* At this point, we stop accepting input. To do this, we
1307
1306
* disable the receive line status interrupts.
1308
1307
*/
1309
- if (state -> flags & UIF_INITIALIZED ) {
1308
+ if (port -> flags & ASYNC_INITIALIZED ) {
1310
1309
unsigned long flags ;
1311
1310
spin_lock_irqsave (& port -> lock , flags );
1312
1311
uport -> ops -> stop_rx (uport );
@@ -1337,7 +1336,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1337
1336
/*
1338
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
1340
wake_up_interruptible (& port -> open_wait );
1342
1341
1343
1342
done :
@@ -1418,11 +1417,11 @@ static void uart_hangup(struct tty_struct *tty)
1418
1417
pr_debug ("uart_hangup(%d)\n" , state -> uart_port -> line );
1419
1418
1420
1419
mutex_lock (& state -> mutex );
1421
- if (state -> flags & UIF_NORMAL_ACTIVE ) {
1420
+ if (port -> flags & ASYNC_NORMAL_ACTIVE ) {
1422
1421
uart_flush_buffer (tty );
1423
1422
uart_shutdown (state );
1424
1423
port -> count = 0 ;
1425
- state -> flags &= ~ UIF_NORMAL_ACTIVE ;
1424
+ clear_bit ( ASYNCB_NORMAL_ACTIVE , & port -> flags ) ;
1426
1425
port -> tty = NULL ;
1427
1426
wake_up_interruptible (& port -> open_wait );
1428
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
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
1496
break ;
1498
1497
1499
1498
/*
@@ -1662,8 +1661,8 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1662
1661
/*
1663
1662
* If this is the first open to succeed, adjust things to suit.
1664
1663
*/
1665
- if (retval == 0 && !(state -> flags & UIF_NORMAL_ACTIVE )) {
1666
- state -> flags |= UIF_NORMAL_ACTIVE ;
1664
+ if (retval == 0 && !(port -> flags & ASYNC_NORMAL_ACTIVE )) {
1665
+ set_bit ( ASYNCB_NORMAL_ACTIVE , & port -> flags ) ;
1667
1666
1668
1667
uart_update_termios (state );
1669
1668
}
@@ -1985,63 +1984,64 @@ static int serial_match_port(struct device *dev, void *data)
1985
1984
return dev -> devt == devt ; /* Actually, only one tty per port */
1986
1985
}
1987
1986
1988
- int uart_suspend_port (struct uart_driver * drv , struct uart_port * port )
1987
+ int 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
1991
struct device * tty_dev ;
1992
- struct uart_match match = {port , drv };
1992
+ struct uart_match match = {uport , drv };
1993
1993
1994
1994
mutex_lock (& state -> mutex );
1995
1995
1996
- if (!console_suspend_enabled && uart_console (port )) {
1996
+ if (!console_suspend_enabled && uart_console (uport )) {
1997
1997
/* we're going to avoid suspending serial console */
1998
1998
mutex_unlock (& state -> mutex );
1999
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
2003
if (device_may_wakeup (tty_dev )) {
2004
- enable_irq_wake (port -> irq );
2004
+ enable_irq_wake (uport -> irq );
2005
2005
put_device (tty_dev );
2006
2006
mutex_unlock (& state -> mutex );
2007
2007
return 0 ;
2008
2008
}
2009
- port -> suspended = 1 ;
2009
+ uport -> suspended = 1 ;
2010
2010
2011
- if (state -> flags & UIF_INITIALIZED ) {
2012
- const struct uart_ops * ops = port -> ops ;
2011
+ if (port -> flags & ASYNC_INITIALIZED ) {
2012
+ const struct uart_ops * ops = uport -> ops ;
2013
2013
int tries ;
2014
2014
2015
- state -> flags = ( state -> flags & ~ UIF_INITIALIZED )
2016
- | UIF_SUSPENDED ;
2015
+ set_bit ( ASYNCB_SUSPENDED , & port -> flags );
2016
+ clear_bit ( ASYNCB_INITIALIZED , & port -> flags ) ;
2017
2017
2018
- spin_lock_irq (& port -> lock );
2019
- ops -> stop_tx (port );
2020
- ops -> set_mctrl (port , 0 );
2021
- ops -> stop_rx (port );
2022
- spin_unlock_irq (& port -> lock );
2018
+ spin_lock_irq (& uport -> lock );
2019
+ ops -> stop_tx (uport );
2020
+ ops -> set_mctrl (uport , 0 );
2021
+ ops -> stop_rx (uport );
2022
+ spin_unlock_irq (& uport -> lock );
2023
2023
2024
2024
/*
2025
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
2028
msleep (10 );
2029
2029
if (!tries )
2030
2030
printk (KERN_ERR "%s%s%s%d: Unable to drain "
2031
2031
"transmitter\n" ,
2032
- port -> dev ? dev_name (port -> dev ) : "" ,
2033
- port -> dev ? ": " : "" ,
2032
+ uport -> dev ? dev_name (uport -> dev ) : "" ,
2033
+ uport -> dev ? ": " : "" ,
2034
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
2041
* Disable the console device before suspending.
2042
2042
*/
2043
- if (uart_console (port ))
2044
- console_stop (port -> cons );
2043
+ if (uart_console (uport ))
2044
+ console_stop (uport -> cons );
2045
2045
2046
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
2050
return 0 ;
2051
2051
}
2052
2052
2053
- int uart_resume_port (struct uart_driver * drv , struct uart_port * port )
2053
+ int 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
2057
struct device * tty_dev ;
2057
- struct uart_match match = {port , drv };
2058
+ struct uart_match match = {uport , drv };
2058
2059
2059
2060
mutex_lock (& state -> mutex );
2060
2061
2061
- if (!console_suspend_enabled && uart_console (port )) {
2062
+ if (!console_suspend_enabled && uart_console (uport )) {
2062
2063
/* no need to resume serial console, it wasn't suspended */
2063
2064
mutex_unlock (& state -> mutex );
2064
2065
return 0 ;
2065
2066
}
2066
2067
2067
- tty_dev = device_find_child (port -> dev , & match , serial_match_port );
2068
- if (!port -> suspended && device_may_wakeup (tty_dev )) {
2069
- disable_irq_wake (port -> irq );
2068
+ tty_dev = device_find_child (uport -> dev , & match , serial_match_port );
2069
+ if (!uport -> suspended && device_may_wakeup (tty_dev )) {
2070
+ disable_irq_wake (uport -> irq );
2070
2071
mutex_unlock (& state -> mutex );
2071
2072
return 0 ;
2072
2073
}
2073
- port -> suspended = 0 ;
2074
+ uport -> suspended = 0 ;
2074
2075
2075
2076
/*
2076
2077
* Re-enable the console device after suspending.
2077
2078
*/
2078
- if (uart_console (port )) {
2079
+ if (uart_console (uport )) {
2079
2080
struct ktermios termios ;
2080
2081
2081
2082
/*
2082
2083
* First try to use the console cflag setting.
2083
2084
*/
2084
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
2089
* If that's unset, use the tty termios setting.
2089
2090
*/
2090
- if (state -> port . tty && termios .c_cflag == 0 )
2091
- termios = * state -> port . tty -> termios ;
2091
+ if (port -> tty && termios .c_cflag == 0 )
2092
+ termios = * port -> tty -> termios ;
2092
2093
2093
2094
uart_change_pm (state , 0 );
2094
- port -> ops -> set_termios (port , & termios , NULL );
2095
- console_start (port -> cons );
2095
+ uport -> ops -> set_termios (uport , & termios , NULL );
2096
+ console_start (uport -> cons );
2096
2097
}
2097
2098
2098
- if (state -> flags & UIF_SUSPENDED ) {
2099
- const struct uart_ops * ops = port -> ops ;
2099
+ if (port -> flags & ASYNC_SUSPENDED ) {
2100
+ const struct uart_ops * ops = uport -> ops ;
2100
2101
int ret ;
2101
2102
2102
2103
uart_change_pm (state , 0 );
2103
- spin_lock_irq (& port -> lock );
2104
- ops -> set_mctrl (port , 0 );
2105
- spin_unlock_irq (& port -> lock );
2106
- ret = ops -> startup (port );
2104
+ spin_lock_irq (& uport -> lock );
2105
+ ops -> set_mctrl (uport , 0 );
2106
+ spin_unlock_irq (& uport -> lock );
2107
+ ret = ops -> startup (uport );
2107
2108
if (ret == 0 ) {
2108
2109
uart_change_speed (state , NULL );
2109
- spin_lock_irq (& port -> lock );
2110
- ops -> set_mctrl (port , port -> mctrl );
2111
- ops -> start_tx (port );
2112
- spin_unlock_irq (& port -> lock );
2113
- state -> flags |= UIF_INITIALIZED ;
2110
+ spin_lock_irq (& uport -> lock );
2111
+ ops -> set_mctrl (uport , uport -> mctrl );
2112
+ ops -> start_tx (uport );
2113
+ spin_unlock_irq (& uport -> lock );
2114
+ set_bit ( ASYNCB_INITIALIZED , & port -> flags ) ;
2114
2115
} else {
2115
2116
/*
2116
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
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
2127
mutex_unlock (& state -> mutex );
0 commit comments