Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'tty-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty

Pull tty and serial driver updates from Greg KH:
"Here's the large TTY and Serial driver update for 4.7-rc1.

A few new serial drivers are added here, and Peter has fixed a bunch
of long-standing bugs in the tty layer and serial drivers as normal.
Full details in the shortlog.

All of these have been in linux-next for a while with no reported
issues"

* tag 'tty-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (88 commits)
MAINTAINERS: 8250: remove website reference
serial: core: Fix port mutex assert if lockdep disabled
serial: 8250_dw: fix wrong logic in dw8250_check_lcr()
tty: vt, finish looping on duplicate
tty: vt, return error when con_startup fails
QE-UART: add "fsl,t1040-ucc-uart" to of_device_id
serial: mctrl_gpio: Drop support for out1-gpios and out2-gpios
serial: 8250dw: Add device HID for future AMD UART controller
Fix OpenSSH pty regression on close
serial: mctrl_gpio: add IRQ locking
serial: 8250: Integrate Fintek into 8250_base
serial: mps2-uart: add support for early console
serial: mps2-uart: add MPS2 UART driver
dt-bindings: document the MPS2 UART bindings
serial: sirf: Use generic uart-has-rtscts DT property
serial: sirf: Introduce helper variable struct device_node *np
serial: mxs-auart: Use generic uart-has-rtscts DT property
serial: imx: Use generic uart-has-rtscts DT property
doc: DT: Add Generic Serial Device Tree Bindings
serial: 8250: of: Make tegra_serial_handle_break() static
...

+2526 -1172
+19
Documentation/devicetree/bindings/serial/arm,mps2-uart.txt
··· 1 + ARM MPS2 UART 2 + 3 + Required properties: 4 + - compatible : Should be "arm,mps2-uart" 5 + - reg : Address and length of the register set 6 + - interrupts : Reference to the UART RX, TX and overrun interrupts 7 + 8 + Required clocking property: 9 + - clocks : The input clock of the UART 10 + 11 + 12 + Examples: 13 + 14 + uart0: serial@40004000 { 15 + compatible = "arm,mps2-uart"; 16 + reg = <0x40004000 0x1000>; 17 + interrupts = <0 1 12>; 18 + clocks = <&sysclk>; 19 + };
+2 -2
Documentation/devicetree/bindings/serial/fsl-imx-uart.txt
··· 6 6 - interrupts : Should contain uart interrupt 7 7 8 8 Optional properties: 9 - - fsl,uart-has-rtscts : Indicate the uart has rts and cts 9 + - uart-has-rtscts : Indicate the uart has rts and cts 10 10 - fsl,irda-mode : Indicate the uart supports irda mode 11 11 - fsl,dte-mode : Indicate the uart works in DTE mode. The uart works 12 12 in DCE mode by default. ··· 24 24 compatible = "fsl,imx51-uart", "fsl,imx21-uart"; 25 25 reg = <0x73fbc000 0x4000>; 26 26 interrupts = <31>; 27 - fsl,uart-has-rtscts; 27 + uart-has-rtscts; 28 28 fsl,dte-mode; 29 29 };
+12 -4
Documentation/devicetree/bindings/serial/fsl-mxs-auart.txt
··· 1 1 * Freescale MXS Application UART (AUART) 2 2 3 - Required properties: 4 - - compatible : Should be "fsl,<soc>-auart". The supported SoCs include 5 - imx23 and imx28. 3 + Required properties for all SoCs: 4 + - compatible : Should be one of fallowing variants: 5 + "fsl,imx23-auart" - Freescale i.MX23 6 + "fsl,imx28-auart" - Freescale i.MX28 7 + "alphascale,asm9260-auart" - Alphascale ASM9260 6 8 - reg : Address and length of the register set for the device 7 9 - interrupts : Should contain the auart interrupt numbers 8 10 - dmas: DMA specifier, consisting of a phandle to DMA controller node ··· 12 10 Refer to dma.txt and fsl-mxs-dma.txt for details. 13 11 - dma-names: "rx" for RX channel, "tx" for TX channel. 14 12 13 + Required properties for "alphascale,asm9260-auart": 14 + - clocks : the clocks feeding the watchdog timer. See clock-bindings.txt 15 + - clock-names : should be set to 16 + "mod" - source for tick counter. 17 + "ahb" - ahb gate. 18 + 15 19 Optional properties: 16 - - fsl,uart-has-rtscts : Indicate the UART has RTS and CTS lines 20 + - uart-has-rtscts : Indicate the UART has RTS and CTS lines 17 21 for hardware flow control, 18 22 it also means you enable the DMA support for this UART. 19 23 - {rts,cts,dtr,dsr,rng,dcd}-gpios: specify a GPIO for RTS/CTS/DTR/DSR/RI/DCD
+57
Documentation/devicetree/bindings/serial/serial.txt
··· 1 + Generic Serial DT Bindings 2 + 3 + This document lists a set of generic properties for describing UARTs in a 4 + device tree. Whether these properties apply to a particular device depends on 5 + the DT bindings for the actual device. 6 + 7 + Optional properties: 8 + - cts-gpios: Must contain a GPIO specifier, referring to the GPIO pin to be 9 + used as the UART's CTS line. 10 + - dcd-gpios: Must contain a GPIO specifier, referring to the GPIO pin to be 11 + used as the UART's DCD line. 12 + - dsr-gpios: Must contain a GPIO specifier, referring to the GPIO pin to be 13 + used as the UART's DSR line. 14 + - dtr-gpios: Must contain a GPIO specifier, referring to the GPIO pin to be 15 + used as the UART's DTR line. 16 + - rng-gpios: Must contain a GPIO specifier, referring to the GPIO pin to be 17 + used as the UART's RNG line. 18 + - rts-gpios: Must contain a GPIO specifier, referring to the GPIO pin to be 19 + used as the UART's RTS line. 20 + 21 + - uart-has-rtscts: The presence of this property indicates that the 22 + UART has dedicated lines for RTS/CTS hardware flow control, and that 23 + they are available for use (wired and enabled by pinmux configuration). 24 + This depends on both the UART hardware and the board wiring. 25 + Note that this property is mutually-exclusive with "cts-gpios" and 26 + "rts-gpios" above. 27 + 28 + 29 + Examples: 30 + 31 + uart1: serial@48022000 { 32 + compatible = "ti,am3352-uart", "ti,omap3-uart"; 33 + ti,hwmods = "uart2"; 34 + clock-frequency = <48000000>; 35 + reg = <0x48022000 0x2000>; 36 + interrupts = <73>; 37 + dmas = <&edma 28 0>, <&edma 29 0>; 38 + dma-names = "tx", "rx"; 39 + dtr-gpios = <&gpio2 22 GPIO_ACTIVE_LOW>; 40 + dsr-gpios = <&gpio2 23 GPIO_ACTIVE_LOW>; 41 + dcd-gpios = <&gpio2 24 GPIO_ACTIVE_LOW>; 42 + rng-gpios = <&gpio2 25 GPIO_ACTIVE_LOW>; 43 + cts-gpios = <&gpio0 12 GPIO_ACTIVE_LOW>; 44 + rts-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; 45 + status = "okay"; 46 + }; 47 + 48 + scifa4: serial@e6c80000 { 49 + compatible = "renesas,scifa-sh73a0", "renesas,scifa"; 50 + reg = <0xe6c80000 0x100>; 51 + interrupts = <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>; 52 + clocks = <&mstp2_clks SH73A0_CLK_SCIFA4>; 53 + clock-names = "fck"; 54 + power-domains = <&pd_a3sp>; 55 + uart-has-rtscts; 56 + status = "okay"; 57 + };
+4 -4
Documentation/devicetree/bindings/serial/sirf-uart.txt
··· 9 9 - clocks : Should contain uart clock number 10 10 11 11 Optional properties: 12 - - sirf,uart-has-rtscts: we have hardware flow controller pins in hardware 13 - - rts-gpios: RTS pin for USP-based UART if sirf,uart-has-rtscts is true 14 - - cts-gpios: CTS pin for USP-based UART if sirf,uart-has-rtscts is true 12 + - uart-has-rtscts: we have hardware flow controller pins in hardware 13 + - rts-gpios: RTS pin for USP-based UART if uart-has-rtscts is true 14 + - cts-gpios: CTS pin for USP-based UART if uart-has-rtscts is true 15 15 16 16 Example: 17 17 ··· 28 28 29 29 usp@b0090000 { 30 30 compatible = "sirf,prima2-usp-uart"; 31 - sirf,uart-has-rtscts; 31 + uart-has-rtscts; 32 32 rts-gpios = <&gpio 15 0>; 33 33 cts-gpios = <&gpio 46 0>; 34 34 };
+6
Documentation/kernel-parameters.txt
··· 1054 1054 the driver will use only 32-bit accessors to read/write 1055 1055 the device registers. 1056 1056 1057 + meson,<addr> 1058 + Start an early, polled-mode console on a meson serial 1059 + port at the specified address. The serial port must 1060 + already be setup and configured. Options are not yet 1061 + supported. 1062 + 1057 1063 msm_serial,<addr> 1058 1064 Start an early, polled-mode console on an msm serial 1059 1065 port at the specified address. The serial port
-3
Documentation/serial/tty.txt
··· 210 210 211 211 TTY_OTHER_CLOSED Device is a pty and the other side has closed. 212 212 213 - TTY_OTHER_DONE Device is a pty and the other side has closed and 214 - all pending input processing has been completed. 215 - 216 213 TTY_NO_WRITE_SPLIT Prevent driver from splitting up writes into 217 214 smaller chunks. 218 215
-1
MAINTAINERS
··· 175 175 8250/16?50 (AND CLONE UARTS) SERIAL DRIVER 176 176 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 177 177 L: linux-serial@vger.kernel.org 178 - W: http://serial.sourceforge.net 179 178 S: Maintained 180 179 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git 181 180 F: drivers/tty/serial/8250*
+1 -1
arch/ia64/hp/sim/simserial.c
··· 300 300 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 301 301 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) && 302 302 (cmd != TIOCMIWAIT)) { 303 - if (tty->flags & (1 << TTY_IO_ERROR)) 303 + if (tty_io_error(tty)) 304 304 return -EIO; 305 305 } 306 306
+4 -2
arch/mips/ath79/early_printk.c
··· 31 31 } while (1); 32 32 } 33 33 34 + #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 35 + 34 36 static void prom_putchar_ar71xx(unsigned char ch) 35 37 { 36 38 void __iomem *base = (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE)); 37 39 38 - prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE); 40 + prom_putchar_wait(base + UART_LSR * 4, BOTH_EMPTY, BOTH_EMPTY); 39 41 __raw_writel(ch, base + UART_TX * 4); 40 - prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE); 42 + prom_putchar_wait(base + UART_LSR * 4, BOTH_EMPTY, BOTH_EMPTY); 41 43 } 42 44 43 45 static void prom_putchar_ar933x(unsigned char ch)
+2 -3
drivers/ipack/devices/ipoctal.c
··· 629 629 tty_port_hangup(&channel->tty_port); 630 630 631 631 ipoctal_reset_channel(channel); 632 - 633 - clear_bit(ASYNCB_INITIALIZED, &channel->tty_port.flags); 632 + tty_port_set_initialized(&channel->tty_port, 0); 634 633 wake_up_interruptible(&channel->tty_port.open_wait); 635 634 } 636 635 ··· 641 642 return; 642 643 643 644 ipoctal_reset_channel(channel); 644 - clear_bit(ASYNCB_INITIALIZED, &channel->tty_port.flags); 645 + tty_port_set_initialized(&channel->tty_port, 0); 645 646 } 646 647 647 648 static void ipoctal_cleanup(struct tty_struct *tty)
+19 -25
drivers/isdn/i4l/isdn_tty.c
··· 1043 1043 if (!(cflag & PARODD)) 1044 1044 cval |= UART_LCR_EPAR; 1045 1045 1046 - if (cflag & CLOCAL) 1047 - port->flags &= ~ASYNC_CHECK_CD; 1048 - else { 1049 - port->flags |= ASYNC_CHECK_CD; 1050 - } 1046 + tty_port_set_check_carrier(port, ~cflag & CLOCAL); 1051 1047 } 1052 1048 1053 1049 static int 1054 1050 isdn_tty_startup(modem_info *info) 1055 1051 { 1056 - if (info->port.flags & ASYNC_INITIALIZED) 1052 + if (tty_port_initialized(&info->port)) 1057 1053 return 0; 1058 1054 isdn_lock_drivers(); 1059 1055 #ifdef ISDN_DEBUG_MODEM_OPEN ··· 1066 1070 */ 1067 1071 isdn_tty_change_speed(info); 1068 1072 1069 - info->port.flags |= ASYNC_INITIALIZED; 1073 + tty_port_set_initialized(&info->port, 1); 1070 1074 info->msr |= (UART_MSR_DSR | UART_MSR_CTS); 1071 1075 info->send_outstanding = 0; 1072 1076 return 0; ··· 1079 1083 static void 1080 1084 isdn_tty_shutdown(modem_info *info) 1081 1085 { 1082 - if (!(info->port.flags & ASYNC_INITIALIZED)) 1086 + if (!tty_port_initialized(&info->port)) 1083 1087 return; 1084 1088 #ifdef ISDN_DEBUG_MODEM_OPEN 1085 1089 printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); ··· 1099 1103 if (info->port.tty) 1100 1104 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 1101 1105 1102 - info->port.flags &= ~ASYNC_INITIALIZED; 1106 + tty_port_set_initialized(&info->port, 0); 1103 1107 } 1104 1108 1105 1109 /* isdn_tty_write() is the main send-routine. It is called from the upper ··· 1347 1351 1348 1352 if (isdn_tty_paranoia_check(info, tty->name, __func__)) 1349 1353 return -ENODEV; 1350 - if (tty->flags & (1 << TTY_IO_ERROR)) 1354 + if (tty_io_error(tty)) 1351 1355 return -EIO; 1352 1356 1353 1357 mutex_lock(&modem_info_mutex); ··· 1374 1378 1375 1379 if (isdn_tty_paranoia_check(info, tty->name, __func__)) 1376 1380 return -ENODEV; 1377 - if (tty->flags & (1 << TTY_IO_ERROR)) 1381 + if (tty_io_error(tty)) 1378 1382 return -EIO; 1379 1383 1380 1384 #ifdef ISDN_DEBUG_MODEM_IOCTL ··· 1415 1419 1416 1420 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl")) 1417 1421 return -ENODEV; 1418 - if (tty->flags & (1 << TTY_IO_ERROR)) 1422 + if (tty_io_error(tty)) 1419 1423 return -EIO; 1420 1424 switch (cmd) { 1421 1425 case TCSBRK: /* SVID version: non-zero arg --> no break */ ··· 1577 1581 * interrupt driver to stop checking the data ready bit in the 1578 1582 * line status register. 1579 1583 */ 1580 - if (port->flags & ASYNC_INITIALIZED) { 1584 + if (tty_port_initialized(port)) { 1581 1585 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */ 1582 1586 /* 1583 1587 * Before we drop DTR, make sure the UART transmitter ··· 1618 1622 return; 1619 1623 isdn_tty_shutdown(info); 1620 1624 port->count = 0; 1621 - port->flags &= ~ASYNC_NORMAL_ACTIVE; 1625 + tty_port_set_active(port, 0); 1622 1626 port->tty = NULL; 1623 1627 wake_up_interruptible(&port->open_wait); 1624 1628 } ··· 1975 1979 #endif 1976 1980 if ( 1977 1981 #ifndef FIX_FILE_TRANSFER 1978 - (info->port.flags & ASYNC_NORMAL_ACTIVE) && 1982 + tty_port_active(&info->port) && 1979 1983 #endif 1980 1984 (info->isdn_driver == -1) && 1981 1985 (info->isdn_channel == -1) && ··· 2013 2017 ((dev->drv[di]->flags & DRV_FLAG_REJBUS) && (wret != 2)) ? "rejected" : "ignored"); 2014 2018 return (wret == 2) ? 3 : 0; 2015 2019 } 2016 - 2017 - #define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE) 2018 2020 2019 2021 int 2020 2022 isdn_tty_stat_callback(int i, isdn_ctrl *c) ··· 2071 2077 #ifdef ISDN_TTY_STAT_DEBUG 2072 2078 printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", info->line); 2073 2079 #endif 2074 - if (TTY_IS_ACTIVE(info)) { 2080 + if (tty_port_active(&info->port)) { 2075 2081 if (info->dialing == 1) { 2076 2082 info->dialing = 2; 2077 2083 return 1; ··· 2082 2088 #ifdef ISDN_TTY_STAT_DEBUG 2083 2089 printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line); 2084 2090 #endif 2085 - if (TTY_IS_ACTIVE(info)) { 2091 + if (tty_port_active(&info->port)) { 2086 2092 if (info->dialing == 1) 2087 2093 isdn_tty_modem_result(RESULT_BUSY, info); 2088 2094 if (info->dialing > 1) ··· 2112 2118 * waiting for it and 2113 2119 * set DCD-bit of its modem-status. 2114 2120 */ 2115 - if (TTY_IS_ACTIVE(info) || 2121 + if (tty_port_active(&info->port) || 2116 2122 (info->port.blocked_open && 2117 2123 (info->emu.mdmreg[REG_DCD] & BIT_DCD))) { 2118 2124 info->msr |= UART_MSR_DCD; ··· 2139 2145 #ifdef ISDN_TTY_STAT_DEBUG 2140 2146 printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line); 2141 2147 #endif 2142 - if (TTY_IS_ACTIVE(info)) { 2148 + if (tty_port_active(&info->port)) { 2143 2149 #ifdef ISDN_DEBUG_MODEM_HUP 2144 2150 printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n"); 2145 2151 #endif ··· 2151 2157 #ifdef ISDN_TTY_STAT_DEBUG 2152 2158 printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", info->line); 2153 2159 #endif 2154 - if (TTY_IS_ACTIVE(info)) { 2160 + if (tty_port_active(&info->port)) { 2155 2161 if (info->dialing) { 2156 2162 info->dialing = 0; 2157 2163 info->last_l2 = -1; ··· 2177 2183 return 1; 2178 2184 #ifdef CONFIG_ISDN_TTY_FAX 2179 2185 case ISDN_STAT_FAXIND: 2180 - if (TTY_IS_ACTIVE(info)) { 2186 + if (tty_port_active(&info->port)) { 2181 2187 isdn_tty_fax_command(info, c); 2182 2188 } 2183 2189 break; 2184 2190 #endif 2185 2191 #ifdef CONFIG_ISDN_AUDIO 2186 2192 case ISDN_STAT_AUDIO: 2187 - if (TTY_IS_ACTIVE(info)) { 2193 + if (tty_port_active(&info->port)) { 2188 2194 switch (c->parm.num[0]) { 2189 2195 case ISDN_AUDIO_DTMF: 2190 2196 if (info->vonline) { ··· 2522 2528 if (info->closing || (!info->port.tty)) 2523 2529 return; 2524 2530 2525 - if (info->port.flags & ASYNC_CHECK_CD) 2531 + if (tty_port_check_carrier(&info->port)) 2526 2532 tty_hangup(info->port.tty); 2527 2533 } 2528 2534 }
+1 -1
drivers/mmc/card/sdio_uart.c
··· 895 895 /* Handle transition away from B0 status */ 896 896 if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { 897 897 unsigned int mask = TIOCM_DTR; 898 - if (!(cflag & CRTSCTS) || !test_bit(TTY_THROTTLED, &tty->flags)) 898 + if (!(cflag & CRTSCTS) || !tty_throttled(tty)) 899 899 mask |= TIOCM_RTS; 900 900 sdio_uart_set_mctrl(port, mask); 901 901 }
+1 -1
drivers/net/usb/hso.c
··· 2029 2029 2030 2030 tty = tty_port_tty_get(&serial->port); 2031 2031 2032 - if (tty && test_bit(TTY_THROTTLED, &tty->flags)) { 2032 + if (tty && tty_throttled(tty)) { 2033 2033 tty_kref_put(tty); 2034 2034 return -1; 2035 2035 }
+10 -12
drivers/s390/char/con3215.c
··· 289 289 290 290 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 291 291 raw->flags &= ~RAW3215_TIMER_RUNS; 292 - if (!(raw->port.flags & ASYNC_SUSPENDED)) { 292 + if (!tty_port_suspended(&raw->port)) { 293 293 raw3215_mk_write_req(raw); 294 294 raw3215_start_io(raw); 295 295 if ((raw->queued_read || raw->queued_write) && ··· 311 311 */ 312 312 static inline void raw3215_try_io(struct raw3215_info *raw) 313 313 { 314 - if (!(raw->port.flags & ASYNC_INITIALIZED) || 315 - (raw->port.flags & ASYNC_SUSPENDED)) 314 + if (!tty_port_initialized(&raw->port) || tty_port_suspended(&raw->port)) 316 315 return; 317 316 if (raw->queued_read != NULL) 318 317 raw3215_start_io(raw); ··· 493 494 /* While console is frozen for suspend we have no other 494 495 * choice but to drop message from the buffer to make 495 496 * room for even more messages. */ 496 - if (raw->port.flags & ASYNC_SUSPENDED) { 497 + if (tty_port_suspended(&raw->port)) { 497 498 raw3215_drop_line(raw); 498 499 continue; 499 500 } ··· 615 616 { 616 617 unsigned long flags; 617 618 618 - if (raw->port.flags & ASYNC_INITIALIZED) 619 + if (tty_port_initialized(&raw->port)) 619 620 return 0; 620 621 raw->line_pos = 0; 621 - raw->port.flags |= ASYNC_INITIALIZED; 622 + tty_port_set_initialized(&raw->port, 1); 622 623 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 623 624 raw3215_try_io(raw); 624 625 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); ··· 634 635 DECLARE_WAITQUEUE(wait, current); 635 636 unsigned long flags; 636 637 637 - if (!(raw->port.flags & ASYNC_INITIALIZED) || 638 - (raw->flags & RAW3215_FIXED)) 638 + if (!tty_port_initialized(&raw->port) || (raw->flags & RAW3215_FIXED)) 639 639 return; 640 640 /* Wait for outstanding requests, then free irq */ 641 641 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); ··· 648 650 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 649 651 remove_wait_queue(&raw->empty_wait, &wait); 650 652 set_current_state(TASK_RUNNING); 651 - raw->port.flags &= ~ASYNC_INITIALIZED; 653 + tty_port_set_initialized(&raw->port, 1); 652 654 } 653 655 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); 654 656 } ··· 771 773 raw = dev_get_drvdata(&cdev->dev); 772 774 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 773 775 raw3215_make_room(raw, RAW3215_BUFFER_SIZE); 774 - raw->port.flags |= ASYNC_SUSPENDED; 776 + tty_port_set_suspended(&raw->port, 1); 775 777 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); 776 778 return 0; 777 779 } ··· 784 786 /* Allow I/O again and flush output buffer. */ 785 787 raw = dev_get_drvdata(&cdev->dev); 786 788 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 787 - raw->port.flags &= ~ASYNC_SUSPENDED; 789 + tty_port_set_suspended(&raw->port, 0); 788 790 raw->flags |= RAW3215_FLUSHING; 789 791 raw3215_try_io(raw); 790 792 raw->flags &= ~RAW3215_FLUSHING; ··· 857 859 unsigned long flags; 858 860 859 861 raw = raw3215[0]; /* console 3215 is the first one */ 860 - if (raw->port.flags & ASYNC_SUSPENDED) 862 + if (tty_port_suspended(&raw->port)) 861 863 /* The console is still frozen for suspend. */ 862 864 if (ccw_device_force_console(raw->cdev)) 863 865 /* Forcing didn't work, no panic message .. */
+2 -2
drivers/s390/char/tty3270.c
··· 1860 1860 tp = tty->driver_data; 1861 1861 if (!tp) 1862 1862 return -ENODEV; 1863 - if (tty->flags & (1 << TTY_IO_ERROR)) 1863 + if (tty_io_error(tty)) 1864 1864 return -EIO; 1865 1865 return kbd_ioctl(tp->kbd, cmd, arg); 1866 1866 } ··· 1874 1874 tp = tty->driver_data; 1875 1875 if (!tp) 1876 1876 return -ENODEV; 1877 - if (tty->flags & (1 << TTY_IO_ERROR)) 1877 + if (tty_io_error(tty)) 1878 1878 return -EIO; 1879 1879 return kbd_ioctl(tp->kbd, cmd, (unsigned long)compat_ptr(arg)); 1880 1880 }
+1 -1
drivers/staging/dgnc/dgnc_tty.c
··· 1255 1255 if (file->f_flags & O_NONBLOCK) 1256 1256 break; 1257 1257 1258 - if (tty->flags & (1 << TTY_IO_ERROR)) { 1258 + if (tty_io_error(tty)) { 1259 1259 retval = -EIO; 1260 1260 break; 1261 1261 }
+1 -1
drivers/staging/fwserial/fwserial.c
··· 1305 1305 if ((baud == 0) && (old->c_cflag & CBAUD)) { 1306 1306 port->mctrl &= ~(TIOCM_DTR | TIOCM_RTS); 1307 1307 } else if ((baud != 0) && !(old->c_cflag & CBAUD)) { 1308 - if (C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, &tty->flags)) 1308 + if (C_CRTSCTS(tty) || !tty_throttled(tty)) 1309 1309 port->mctrl |= TIOCM_DTR | TIOCM_RTS; 1310 1310 else 1311 1311 port->mctrl |= TIOCM_DTR;
+1 -1
drivers/staging/speakup/selection.c
··· 150 150 add_wait_queue(&vc->paste_wait, &wait); 151 151 while (sel_buffer && sel_buffer_lth > pasted) { 152 152 set_current_state(TASK_INTERRUPTIBLE); 153 - if (test_bit(TTY_THROTTLED, &tty->flags)) { 153 + if (tty_throttled(tty)) { 154 154 schedule(); 155 155 continue; 156 156 }
+17 -22
drivers/tty/amiserial.c
··· 398 398 wake_up_interruptible(&port->delta_msr_wait); 399 399 } 400 400 401 - if ((port->flags & ASYNC_CHECK_CD) && (dstatus & SER_DCD)) { 401 + if (tty_port_check_carrier(port) && (dstatus & SER_DCD)) { 402 402 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR)) 403 403 printk("ttyS%d CD now %s...", info->line, 404 404 (!(status & SER_DCD)) ? "on" : "off"); ··· 525 525 526 526 local_irq_save(flags); 527 527 528 - if (port->flags & ASYNC_INITIALIZED) { 528 + if (tty_port_initialized(port)) { 529 529 free_page(page); 530 530 goto errout; 531 531 } ··· 586 586 */ 587 587 change_speed(tty, info, NULL); 588 588 589 - port->flags |= ASYNC_INITIALIZED; 589 + tty_port_set_initialized(port, 1); 590 590 local_irq_restore(flags); 591 591 return 0; 592 592 ··· 604 604 unsigned long flags; 605 605 struct serial_state *state; 606 606 607 - if (!(info->tport.flags & ASYNC_INITIALIZED)) 607 + if (!tty_port_initialized(&info->tport)) 608 608 return; 609 609 610 610 state = info; ··· 645 645 646 646 set_bit(TTY_IO_ERROR, &tty->flags); 647 647 648 - info->tport.flags &= ~ASYNC_INITIALIZED; 648 + tty_port_set_initialized(&info->tport, 0); 649 649 local_irq_restore(flags); 650 650 } 651 651 ··· 727 727 info->IER &= ~UART_IER_MSI; 728 728 if (port->flags & ASYNC_HARDPPS_CD) 729 729 info->IER |= UART_IER_MSI; 730 - if (cflag & CRTSCTS) { 731 - port->flags |= ASYNC_CTS_FLOW; 730 + tty_port_set_cts_flow(port, cflag & CRTSCTS); 731 + if (cflag & CRTSCTS) 732 732 info->IER |= UART_IER_MSI; 733 - } else 734 - port->flags &= ~ASYNC_CTS_FLOW; 735 - if (cflag & CLOCAL) 736 - port->flags &= ~ASYNC_CHECK_CD; 737 - else { 738 - port->flags |= ASYNC_CHECK_CD; 733 + tty_port_set_check_carrier(port, ~cflag & CLOCAL); 734 + if (~cflag & CLOCAL) 739 735 info->IER |= UART_IER_MSI; 740 - } 741 736 /* TBD: 742 737 * Does clearing IER_MSI imply that we should disable the VBL interrupt ? 743 738 */ ··· 1084 1089 port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1085 1090 1086 1091 check_and_exit: 1087 - if (port->flags & ASYNC_INITIALIZED) { 1092 + if (tty_port_initialized(port)) { 1088 1093 if (change_spd) { 1089 1094 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1090 1095 tty->alt_speed = 57600; ··· 1138 1143 1139 1144 if (serial_paranoia_check(info, tty->name, "rs_ioctl")) 1140 1145 return -ENODEV; 1141 - if (tty->flags & (1 << TTY_IO_ERROR)) 1146 + if (tty_io_error(tty)) 1142 1147 return -EIO; 1143 1148 1144 1149 control = info->MCR; ··· 1160 1165 1161 1166 if (serial_paranoia_check(info, tty->name, "rs_ioctl")) 1162 1167 return -ENODEV; 1163 - if (tty->flags & (1 << TTY_IO_ERROR)) 1168 + if (tty_io_error(tty)) 1164 1169 return -EIO; 1165 1170 1166 1171 local_irq_save(flags); ··· 1245 1250 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 1246 1251 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) && 1247 1252 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { 1248 - if (tty->flags & (1 << TTY_IO_ERROR)) 1253 + if (tty_io_error(tty)) 1249 1254 return -EIO; 1250 1255 } 1251 1256 ··· 1337 1342 /* Handle transition away from B0 status */ 1338 1343 if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { 1339 1344 info->MCR |= SER_DTR; 1340 - if (!C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, &tty->flags)) 1345 + if (!C_CRTSCTS(tty) || !tty_throttled(tty)) 1341 1346 info->MCR |= SER_RTS; 1342 1347 local_irq_save(flags); 1343 1348 rtsdtr_ctrl(info->MCR); ··· 1390 1395 * line status register. 1391 1396 */ 1392 1397 state->read_status_mask &= ~UART_LSR_DR; 1393 - if (port->flags & ASYNC_INITIALIZED) { 1398 + if (tty_port_initialized(port)) { 1394 1399 /* disable receive interrupts */ 1395 1400 custom.intena = IF_RBF; 1396 1401 mb(); ··· 1490 1495 rs_flush_buffer(tty); 1491 1496 shutdown(tty, info); 1492 1497 info->tport.count = 0; 1493 - info->tport.flags &= ~ASYNC_NORMAL_ACTIVE; 1498 + tty_port_set_active(&info->tport, 0); 1494 1499 info->tport.tty = NULL; 1495 1500 wake_up_interruptible(&info->tport.open_wait); 1496 1501 } ··· 1538 1543 1539 1544 local_irq_save(flags); 1540 1545 status = ciab.pra; 1541 - control = (state->tport.flags & ASYNC_INITIALIZED) ? state->MCR : status; 1546 + control = tty_port_initialized(&state->tport) ? state->MCR : status; 1542 1547 local_irq_restore(flags); 1543 1548 1544 1549 stat_buf[0] = 0;
+15 -23
drivers/tty/cyclades.c
··· 714 714 wake_up_interruptible(&info->port.delta_msr_wait); 715 715 } 716 716 717 - if ((mdm_change & CyDCD) && (info->port.flags & ASYNC_CHECK_CD)) { 717 + if ((mdm_change & CyDCD) && tty_port_check_carrier(&info->port)) { 718 718 if (mdm_status & CyDCD) 719 719 wake_up_interruptible(&info->port.open_wait); 720 720 else ··· 1119 1119 case C_CM_MDCD: 1120 1120 info->icount.dcd++; 1121 1121 delta_count++; 1122 - if (info->port.flags & ASYNC_CHECK_CD) { 1122 + if (tty_port_check_carrier(&info->port)) { 1123 1123 u32 dcd = fw_ver > 241 ? param : 1124 1124 readl(&info->u.cyz.ch_ctrl->rs_status); 1125 1125 if (dcd & C_RS_DCD) ··· 1279 1279 1280 1280 spin_lock_irqsave(&card->card_lock, flags); 1281 1281 1282 - if (info->port.flags & ASYNC_INITIALIZED) 1282 + if (tty_port_initialized(&info->port)) 1283 1283 goto errout; 1284 1284 1285 1285 if (!info->type) { ··· 1364 1364 /* enable send, recv, modem !!! */ 1365 1365 } 1366 1366 1367 - info->port.flags |= ASYNC_INITIALIZED; 1367 + tty_port_set_initialized(&info->port, 1); 1368 1368 1369 1369 clear_bit(TTY_IO_ERROR, &tty->flags); 1370 1370 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; ··· 1424 1424 struct cyclades_card *card; 1425 1425 unsigned long flags; 1426 1426 1427 - if (!(info->port.flags & ASYNC_INITIALIZED)) 1427 + if (!tty_port_initialized(&info->port)) 1428 1428 return; 1429 1429 1430 1430 card = info->card; ··· 1448 1448 some later date (after testing)!!! */ 1449 1449 1450 1450 set_bit(TTY_IO_ERROR, &tty->flags); 1451 - info->port.flags &= ~ASYNC_INITIALIZED; 1451 + tty_port_set_initialized(&info->port, 0); 1452 1452 spin_unlock_irqrestore(&card->card_lock, flags); 1453 1453 } else { 1454 1454 #ifdef CY_DEBUG_OPEN ··· 1473 1473 tty_port_lower_dtr_rts(&info->port); 1474 1474 1475 1475 set_bit(TTY_IO_ERROR, &tty->flags); 1476 - info->port.flags &= ~ASYNC_INITIALIZED; 1476 + tty_port_set_initialized(&info->port, 0); 1477 1477 1478 1478 spin_unlock_irqrestore(&card->card_lock, flags); 1479 1479 } ··· 1711 1711 /* Stop accepting input */ 1712 1712 cyy_writeb(info, CyCAR, channel & 0x03); 1713 1713 cyy_writeb(info, CySRER, cyy_readb(info, CySRER) & ~CyRxData); 1714 - if (info->port.flags & ASYNC_INITIALIZED) { 1714 + if (tty_port_initialized(&info->port)) { 1715 1715 /* Waiting for on-board buffers to be empty before 1716 1716 closing the port */ 1717 1717 spin_unlock_irqrestore(&card->card_lock, flags); ··· 2083 2083 info->cor1 |= CyPARITY_NONE; 2084 2084 2085 2085 /* CTS flow control flag */ 2086 - if (cflag & CRTSCTS) { 2087 - info->port.flags |= ASYNC_CTS_FLOW; 2086 + tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); 2087 + if (cflag & CRTSCTS) 2088 2088 info->cor2 |= CyCtsAE; 2089 - } else { 2090 - info->port.flags &= ~ASYNC_CTS_FLOW; 2091 - info->cor2 &= ~CyCtsAE; 2092 - } 2093 - if (cflag & CLOCAL) 2094 - info->port.flags &= ~ASYNC_CHECK_CD; 2095 2089 else 2096 - info->port.flags |= ASYNC_CHECK_CD; 2090 + info->cor2 &= ~CyCtsAE; 2091 + tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); 2097 2092 2098 2093 /*********************************************** 2099 2094 The hardware option, CyRtsAO, presents RTS when ··· 2229 2234 } 2230 2235 /* As the HW flow control is done in firmware, the driver 2231 2236 doesn't need to care about it */ 2232 - info->port.flags &= ~ASYNC_CTS_FLOW; 2237 + tty_port_set_cts_flow(&info->port, 0); 2233 2238 2234 2239 /* XON/XOFF/XANY flow control flags */ 2235 2240 sw_flow = 0; ··· 2247 2252 } 2248 2253 2249 2254 /* CD sensitivity */ 2250 - if (cflag & CLOCAL) 2251 - info->port.flags &= ~ASYNC_CHECK_CD; 2252 - else 2253 - info->port.flags |= ASYNC_CHECK_CD; 2255 + tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); 2254 2256 2255 2257 if (baud == 0) { /* baud rate is zero, turn off line */ 2256 2258 cy_writel(&ch_ctrl->rs_control, ··· 2334 2342 info->port.closing_wait = new_serial.closing_wait * HZ / 100; 2335 2343 2336 2344 check_and_exit: 2337 - if (info->port.flags & ASYNC_INITIALIZED) { 2345 + if (tty_port_initialized(&info->port)) { 2338 2346 cy_set_line_char(info, tty); 2339 2347 ret = 0; 2340 2348 } else {
+2 -2
drivers/tty/hvc/hvc_console.c
··· 632 632 goto bail; 633 633 634 634 /* Now check if we can get data (are we throttled ?) */ 635 - if (test_bit(TTY_THROTTLED, &tty->flags)) 635 + if (tty_throttled(tty)) 636 636 goto throttled; 637 637 638 638 /* If we aren't notifier driven and aren't throttled, we always ··· 814 814 815 815 n = hp->ops->get_chars(hp->vtermno, &ch, 1); 816 816 817 - if (n == 0) 817 + if (n <= 0) 818 818 return NO_POLL_CHAR; 819 819 820 820 return ch;
+1 -1
drivers/tty/hvc/hvcs.c
··· 600 600 601 601 hvcs_try_write(hvcsd); 602 602 603 - if (!tty || test_bit(TTY_THROTTLED, &tty->flags)) { 603 + if (!tty || tty_throttled(tty)) { 604 604 hvcsd->todo_mask &= ~(HVCS_READ_MASK); 605 605 goto bail; 606 606 } else if (!(hvcsd->todo_mask & (HVCS_READ_MASK)))
+1 -1
drivers/tty/hvc/hvsi.c
··· 509 509 } 510 510 511 511 spin_lock_irqsave(&hp->lock, flags); 512 - if (tty && hp->n_throttle && !test_bit(TTY_THROTTLED, &tty->flags)) { 512 + if (tty && hp->n_throttle && !tty_throttled(tty)) { 513 513 /* we weren't hung up and we weren't throttled, so we can 514 514 * deliver the rest now */ 515 515 hvsi_send_overflow(hp);
+5
drivers/tty/ipwireless/hardware.c
··· 1572 1572 sizeof(struct ipw_setup_reboot_msg_ack), 1573 1573 ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP, 1574 1574 TL_SETUP_SIGNO_REBOOT_MSG_ACK); 1575 + if (!packet) { 1576 + pr_err(IPWIRELESS_PCCARD_NAME 1577 + ": Not enough memory to send reboot packet"); 1578 + break; 1579 + } 1575 1580 packet->header.length = 1576 1581 sizeof(struct TlSetupRebootMsgAck); 1577 1582 send_packet(hw, PRIO_SETUP, &packet->header);
+7 -12
drivers/tty/isicom.c
··· 438 438 439 439 for (; count > 0; count--, port++) { 440 440 /* port not active or tx disabled to force flow control */ 441 - if (!(port->port.flags & ASYNC_INITIALIZED) || 442 - !(port->status & ISI_TXOK)) 441 + if (!tty_port_initialized(&port->port) || 442 + !(port->status & ISI_TXOK)) 443 443 continue; 444 444 445 445 txcount = min_t(short, TX_SIZE, port->xmit_cnt); ··· 553 553 return IRQ_HANDLED; 554 554 } 555 555 port = card->ports + channel; 556 - if (!(port->port.flags & ASYNC_INITIALIZED)) { 556 + if (!tty_port_initialized(&port->port)) { 557 557 outw(0x0000, base+0x04); /* enable interrupts */ 558 558 spin_unlock(&card->card_lock); 559 559 return IRQ_HANDLED; ··· 577 577 header = inw(base); 578 578 switch (header & 0xff) { 579 579 case 0: /* Change in EIA signals */ 580 - if (port->port.flags & ASYNC_CHECK_CD) { 580 + if (tty_port_check_carrier(&port->port)) { 581 581 if (port->status & ISI_DCD) { 582 582 if (!(header & ISI_DCD)) { 583 583 /* Carrier has been lost */ ··· 758 758 outw(channel_setup, base); 759 759 InterruptTheCard(base); 760 760 } 761 - if (C_CLOCAL(tty)) 762 - port->port.flags &= ~ASYNC_CHECK_CD; 763 - else 764 - port->port.flags |= ASYNC_CHECK_CD; 761 + tty_port_set_check_carrier(&port->port, !C_CLOCAL(tty)); 765 762 766 763 /* flow control settings ...*/ 767 764 flow_ctrl = 0; 768 - port->port.flags &= ~ASYNC_CTS_FLOW; 769 - if (C_CRTSCTS(tty)) { 770 - port->port.flags |= ASYNC_CTS_FLOW; 765 + tty_port_set_cts_flow(&port->port, C_CRTSCTS(tty)); 766 + if (C_CRTSCTS(tty)) 771 767 flow_ctrl |= ISICOM_CTSRTS; 772 - } 773 768 if (I_IXON(tty)) 774 769 flow_ctrl |= ISICOM_RESPOND_XONXOFF; 775 770 if (I_IXOFF(tty))
+6 -6
drivers/tty/moxa.c
··· 912 912 913 913 /* pci hot-un-plug support */ 914 914 for (a = 0; a < brd->numPorts; a++) 915 - if (brd->ports[a].port.flags & ASYNC_INITIALIZED) 915 + if (tty_port_initialized(&brd->ports[a].port)) 916 916 tty_port_tty_hangup(&brd->ports[a].port, false); 917 917 918 918 for (a = 0; a < MAX_PORTS_PER_BOARD; a++) ··· 921 921 while (1) { 922 922 opened = 0; 923 923 for (a = 0; a < brd->numPorts; a++) 924 - if (brd->ports[a].port.flags & ASYNC_INITIALIZED) 924 + if (tty_port_initialized(&brd->ports[a].port)) 925 925 opened++; 926 926 mutex_unlock(&moxa_openlock); 927 927 if (!opened) ··· 1192 1192 tty->driver_data = ch; 1193 1193 tty_port_tty_set(&ch->port, tty); 1194 1194 mutex_lock(&ch->port.mutex); 1195 - if (!(ch->port.flags & ASYNC_INITIALIZED)) { 1195 + if (!tty_port_initialized(&ch->port)) { 1196 1196 ch->statusflags = 0; 1197 1197 moxa_set_tty_param(tty, &tty->termios); 1198 1198 MoxaPortLineCtrl(ch, 1, 1); 1199 1199 MoxaPortEnable(ch); 1200 1200 MoxaSetFifo(ch, ch->type == PORT_16550A); 1201 - ch->port.flags |= ASYNC_INITIALIZED; 1201 + tty_port_set_initialized(&ch->port, 1); 1202 1202 } 1203 1203 mutex_unlock(&ch->port.mutex); 1204 1204 mutex_unlock(&moxa_openlock); ··· 1379 1379 { 1380 1380 struct tty_struct *tty = tty_port_tty_get(&p->port); 1381 1381 void __iomem *ofsAddr; 1382 - unsigned int inited = p->port.flags & ASYNC_INITIALIZED; 1382 + unsigned int inited = tty_port_initialized(&p->port); 1383 1383 u16 intr; 1384 1384 1385 1385 if (tty) { ··· 1394 1394 tty_wakeup(tty); 1395 1395 } 1396 1396 1397 - if (inited && !test_bit(TTY_THROTTLED, &tty->flags) && 1397 + if (inited && !tty_throttled(tty) && 1398 1398 MoxaPortRxQueue(p) > 0) { /* RX */ 1399 1399 MoxaPortReadData(p); 1400 1400 tty_schedule_flip(&p->port);
+13 -22
drivers/tty/mxser.c
··· 711 711 /* CTS flow control flag and modem status interrupts */ 712 712 info->IER &= ~UART_IER_MSI; 713 713 info->MCR &= ~UART_MCR_AFE; 714 + tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); 714 715 if (cflag & CRTSCTS) { 715 - info->port.flags |= ASYNC_CTS_FLOW; 716 716 info->IER |= UART_IER_MSI; 717 717 if ((info->type == PORT_16550A) || (info->board->chip_flag)) { 718 718 info->MCR |= UART_MCR_AFE; ··· 744 744 } 745 745 } 746 746 } 747 - } else { 748 - info->port.flags &= ~ASYNC_CTS_FLOW; 749 747 } 750 748 outb(info->MCR, info->ioaddr + UART_MCR); 751 - if (cflag & CLOCAL) { 752 - info->port.flags &= ~ASYNC_CHECK_CD; 753 - } else { 754 - info->port.flags |= ASYNC_CHECK_CD; 749 + tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); 750 + if (~cflag & CLOCAL) 755 751 info->IER |= UART_IER_MSI; 756 - } 757 752 outb(info->IER, info->ioaddr + UART_IER); 758 753 759 754 /* ··· 821 826 port->mon_data.modem_status = status; 822 827 wake_up_interruptible(&port->port.delta_msr_wait); 823 828 824 - if ((port->port.flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) { 829 + if (tty_port_check_carrier(&port->port) && (status & UART_MSR_DDCD)) { 825 830 if (status & UART_MSR_DCD) 826 831 wake_up_interruptible(&port->port.open_wait); 827 832 } ··· 1081 1086 mutex_lock(&port->mutex); 1082 1087 mxser_close_port(port); 1083 1088 mxser_flush_buffer(tty); 1084 - if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { 1085 - if (C_HUPCL(tty)) 1086 - tty_port_lower_dtr_rts(port); 1087 - } 1089 + if (tty_port_initialized(port) && C_HUPCL(tty)) 1090 + tty_port_lower_dtr_rts(port); 1088 1091 mxser_shutdown_port(port); 1089 - clear_bit(ASYNCB_INITIALIZED, &port->flags); 1092 + tty_port_set_initialized(port, 0); 1090 1093 mutex_unlock(&port->mutex); 1091 1094 info->closing = 0; 1092 1095 /* Right now the tty_port set is done outside of the close_end helper ··· 1280 1287 1281 1288 process_txrx_fifo(info); 1282 1289 1283 - if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { 1290 + if (tty_port_initialized(port)) { 1284 1291 if (flags != (port->flags & ASYNC_SPD_MASK)) { 1285 1292 spin_lock_irqsave(&info->slock, sl_flags); 1286 1293 mxser_change_speed(tty, NULL); ··· 1289 1296 } else { 1290 1297 retval = mxser_activate(port, tty); 1291 1298 if (retval == 0) 1292 - set_bit(ASYNCB_INITIALIZED, &port->flags); 1299 + tty_port_set_initialized(port, 1); 1293 1300 } 1294 1301 return retval; 1295 1302 } ··· 1327 1334 1328 1335 if (tty->index == MXSER_PORTS) 1329 1336 return -ENOIOCTLCMD; 1330 - if (test_bit(TTY_IO_ERROR, &tty->flags)) 1337 + if (tty_io_error(tty)) 1331 1338 return -EIO; 1332 1339 1333 1340 control = info->MCR; ··· 1354 1361 1355 1362 if (tty->index == MXSER_PORTS) 1356 1363 return -ENOIOCTLCMD; 1357 - if (test_bit(TTY_IO_ERROR, &tty->flags)) 1364 + if (tty_io_error(tty)) 1358 1365 return -EIO; 1359 1366 1360 1367 spin_lock_irqsave(&info->slock, flags); ··· 1708 1715 return 0; 1709 1716 } 1710 1717 1711 - if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && 1712 - test_bit(TTY_IO_ERROR, &tty->flags)) 1718 + if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && tty_io_error(tty)) 1713 1719 return -EIO; 1714 1720 1715 1721 switch (cmd) { ··· 2249 2257 iir &= MOXA_MUST_IIR_MASK; 2250 2258 tty = tty_port_tty_get(&port->port); 2251 2259 if (!tty || port->closing || 2252 - !(port->port.flags & ASYNC_INITIALIZED)) { 2260 + !tty_port_initialized(&port->port)) { 2253 2261 status = inb(port->ioaddr + UART_LSR); 2254 2262 outb(0x27, port->ioaddr + UART_FCR); 2255 2263 inb(port->ioaddr + UART_MSR); ··· 2392 2400 if (brd->chip_flag != MOXA_OTHER_UART) 2393 2401 mxser_enable_must_enchance_mode(info->ioaddr); 2394 2402 2395 - info->port.flags = ASYNC_SHARE_IRQ; 2396 2403 info->type = brd->uart_type; 2397 2404 2398 2405 process_txrx_fifo(info);
+6 -6
drivers/tty/n_gsm.c
··· 2045 2045 } 2046 2046 } 2047 2047 spin_unlock(&gsm_mux_lock); 2048 - WARN_ON(i == MAX_MUX); 2048 + /* open failed before registering => nothing to do */ 2049 + if (i == MAX_MUX) 2050 + return; 2049 2051 2050 2052 /* In theory disconnecting DLCI 0 is sufficient but for some 2051 2053 modems this is apparently not the case. */ ··· 2949 2947 dlci->modem_rx = 0; 2950 2948 /* We could in theory open and close before we wait - eg if we get 2951 2949 a DM straight back. This is ok as that will have caused a hangup */ 2952 - set_bit(ASYNCB_INITIALIZED, &port->flags); 2950 + tty_port_set_initialized(port, 1); 2953 2951 /* Start sending off SABM messages */ 2954 2952 gsm_dlci_begin_open(dlci); 2955 2953 /* And wait for virtual carrier */ ··· 2972 2970 if (tty_port_close_start(&dlci->port, tty, filp) == 0) 2973 2971 return; 2974 2972 gsm_dlci_begin_close(dlci); 2975 - if (test_bit(ASYNCB_INITIALIZED, &dlci->port.flags)) { 2976 - if (C_HUPCL(tty)) 2977 - tty_port_lower_dtr_rts(&dlci->port); 2978 - } 2973 + if (tty_port_initialized(&dlci->port) && C_HUPCL(tty)) 2974 + tty_port_lower_dtr_rts(&dlci->port); 2979 2975 tty_port_close_end(&dlci->port, tty); 2980 2976 tty_port_tty_set(&dlci->port, NULL); 2981 2977 return;
+2 -2
drivers/tty/n_hdlc.c
··· 599 599 add_wait_queue(&tty->read_wait, &wait); 600 600 601 601 for (;;) { 602 - if (test_bit(TTY_OTHER_DONE, &tty->flags)) { 602 + if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 603 603 ret = -EIO; 604 604 break; 605 605 } ··· 827 827 /* set bits for operations that won't block */ 828 828 if (n_hdlc->rx_buf_list.head) 829 829 mask |= POLLIN | POLLRDNORM; /* readable */ 830 - if (test_bit(TTY_OTHER_DONE, &tty->flags)) 830 + if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) 831 831 mask |= POLLHUP; 832 832 if (tty_hung_up_p(filp)) 833 833 mask |= POLLHUP;
+34 -38
drivers/tty/n_tty.c
··· 1917 1917 return ldata->commit_head - ldata->read_tail >= amt; 1918 1918 } 1919 1919 1920 - static inline int check_other_done(struct tty_struct *tty) 1921 - { 1922 - int done = test_bit(TTY_OTHER_DONE, &tty->flags); 1923 - if (done) { 1924 - /* paired with cmpxchg() in check_other_closed(); ensures 1925 - * read buffer head index is not stale 1926 - */ 1927 - smp_mb__after_atomic(); 1928 - } 1929 - return done; 1930 - } 1931 - 1932 1920 /** 1933 1921 * copy_from_read_buf - copy read data directly 1934 1922 * @tty: terminal device ··· 2112 2124 struct n_tty_data *ldata = tty->disc_data; 2113 2125 unsigned char __user *b = buf; 2114 2126 DEFINE_WAIT_FUNC(wait, woken_wake_function); 2115 - int c, done; 2127 + int c; 2116 2128 int minimum, time; 2117 2129 ssize_t retval = 0; 2118 2130 long timeout; ··· 2171 2183 break; 2172 2184 } 2173 2185 2174 - done = check_other_done(tty); 2175 - 2176 2186 if (!input_available_p(tty, 0)) { 2177 - if (done) { 2178 - retval = -EIO; 2179 - break; 2180 - } 2181 - if (tty_hung_up_p(file)) 2182 - break; 2183 - if (!timeout) 2184 - break; 2185 - if (file->f_flags & O_NONBLOCK) { 2186 - retval = -EAGAIN; 2187 - break; 2188 - } 2189 - if (signal_pending(current)) { 2190 - retval = -ERESTARTSYS; 2191 - break; 2192 - } 2193 2187 up_read(&tty->termios_rwsem); 2194 - 2195 - timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, 2196 - timeout); 2197 - 2188 + tty_buffer_flush_work(tty->port); 2198 2189 down_read(&tty->termios_rwsem); 2199 - continue; 2190 + if (!input_available_p(tty, 0)) { 2191 + if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 2192 + retval = -EIO; 2193 + break; 2194 + } 2195 + if (tty_hung_up_p(file)) 2196 + break; 2197 + if (!timeout) 2198 + break; 2199 + if (file->f_flags & O_NONBLOCK) { 2200 + retval = -EAGAIN; 2201 + break; 2202 + } 2203 + if (signal_pending(current)) { 2204 + retval = -ERESTARTSYS; 2205 + break; 2206 + } 2207 + up_read(&tty->termios_rwsem); 2208 + 2209 + timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, 2210 + timeout); 2211 + 2212 + down_read(&tty->termios_rwsem); 2213 + continue; 2214 + } 2200 2215 } 2201 2216 2202 2217 if (ldata->icanon && !L_EXTPROC(tty)) { ··· 2377 2386 2378 2387 poll_wait(file, &tty->read_wait, wait); 2379 2388 poll_wait(file, &tty->write_wait, wait); 2380 - if (check_other_done(tty)) 2381 - mask |= POLLHUP; 2382 2389 if (input_available_p(tty, 1)) 2383 2390 mask |= POLLIN | POLLRDNORM; 2391 + else { 2392 + tty_buffer_flush_work(tty->port); 2393 + if (input_available_p(tty, 1)) 2394 + mask |= POLLIN | POLLRDNORM; 2395 + } 2384 2396 if (tty->packet && tty->link->ctrl_status) 2385 2397 mask |= POLLPRI | POLLIN | POLLRDNORM; 2398 + if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) 2399 + mask |= POLLHUP; 2386 2400 if (tty_hung_up_p(file)) 2387 2401 mask |= POLLHUP; 2388 2402 if (tty->ops->write && !tty_is_writelocked(tty) &&
+1 -1
drivers/tty/nozomi.c
··· 826 826 size = __le32_to_cpu(readl(addr)); 827 827 /* DBG1( "%d bytes port: %d", size, index); */ 828 828 829 - if (tty && test_bit(TTY_THROTTLED, &tty->flags)) { 829 + if (tty && tty_throttled(tty)) { 830 830 DBG1("No room in tty, don't read data, don't ack interrupt, " 831 831 "disable interrupt"); 832 832
+2 -4
drivers/tty/pty.c
··· 44 44 if (tty->driver->subtype == PTY_TYPE_MASTER) 45 45 WARN_ON(tty->count > 1); 46 46 else { 47 - if (test_bit(TTY_IO_ERROR, &tty->flags)) 47 + if (tty_io_error(tty)) 48 48 return; 49 49 if (tty->count > 2) 50 50 return; ··· 59 59 if (!tty->link) 60 60 return; 61 61 set_bit(TTY_OTHER_CLOSED, &tty->link->flags); 62 - tty_flip_buffer_push(tty->link->port); 62 + wake_up_interruptible(&tty->link->read_wait); 63 63 wake_up_interruptible(&tty->link->write_wait); 64 64 if (tty->driver->subtype == PTY_TYPE_MASTER) { 65 65 set_bit(TTY_OTHER_CLOSED, &tty->flags); ··· 247 247 goto out; 248 248 249 249 clear_bit(TTY_IO_ERROR, &tty->flags); 250 - /* TTY_OTHER_CLOSED must be cleared before TTY_OTHER_DONE */ 251 250 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); 252 - clear_bit(TTY_OTHER_DONE, &tty->link->flags); 253 251 set_bit(TTY_THROTTLED, &tty->flags); 254 252 return 0; 255 253
+9 -7
drivers/tty/rocket.c
··· 495 495 if (!info) 496 496 return; 497 497 498 - if ((info->port.flags & ASYNC_INITIALIZED) == 0) { 498 + if (!tty_port_initialized(&info->port)) { 499 499 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " 500 500 "info->flags & NOT_INIT\n"); 501 501 return; ··· 615 615 * the board. 616 616 * Inputs: board, aiop, chan numbers 617 617 */ 618 - static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev) 618 + static void __init 619 + init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev) 619 620 { 620 621 unsigned rocketMode; 621 622 struct r_port *info; ··· 921 920 /* 922 921 * Info->count is now 1; so it's safe to sleep now. 923 922 */ 924 - if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { 923 + if (!tty_port_initialized(port)) { 925 924 cp = &info->channel; 926 925 sSetRxTrigger(cp, TRIG_1); 927 926 if (sGetChanStatus(cp) & CD_ACT) ··· 945 944 sEnRxFIFO(cp); 946 945 sEnTransmit(cp); 947 946 948 - set_bit(ASYNCB_INITIALIZED, &info->port.flags); 947 + tty_port_set_initialized(&info->port, 1); 949 948 950 949 /* 951 950 * Set up the tty->alt_speed kludge ··· 1043 1042 } 1044 1043 } 1045 1044 spin_lock_irq(&port->lock); 1046 - info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_NORMAL_ACTIVE); 1047 1045 tty->closing = 0; 1048 1046 spin_unlock_irq(&port->lock); 1047 + tty_port_set_initialized(port, 0); 1048 + tty_port_set_active(port, 0); 1049 1049 mutex_unlock(&port->mutex); 1050 1050 tty_port_tty_set(port, NULL); 1051 1051 ··· 1514 1512 sDisCTSFlowCtl(cp); 1515 1513 sDisTxSoftFlowCtl(cp); 1516 1514 sClrTxXOFF(cp); 1517 - clear_bit(ASYNCB_INITIALIZED, &info->port.flags); 1515 + tty_port_set_initialized(&info->port, 0); 1518 1516 1519 1517 wake_up_interruptible(&info->port.open_wait); 1520 1518 } ··· 1626 1624 /* Write remaining data into the port's xmit_buf */ 1627 1625 while (1) { 1628 1626 /* Hung up ? */ 1629 - if (!test_bit(ASYNCB_NORMAL_ACTIVE, &info->port.flags)) 1627 + if (!tty_port_active(&info->port)) 1630 1628 goto end; 1631 1629 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); 1632 1630 c = min(c, XMIT_BUF_SIZE - info->xmit_head);
+11 -4
drivers/tty/serial/8250/8250.h
··· 17 17 18 18 struct uart_8250_dma { 19 19 int (*tx_dma)(struct uart_8250_port *p); 20 - int (*rx_dma)(struct uart_8250_port *p, unsigned int iir); 20 + int (*rx_dma)(struct uart_8250_port *p); 21 21 22 22 /* Filter function */ 23 23 dma_filter_fn fn; ··· 84 84 #define UART_BUG_THRE (1 << 3) /* UART has buggy THRE reassertion */ 85 85 #define UART_BUG_PARITY (1 << 4) /* UART mishandles parity if FIFO enabled */ 86 86 87 - #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8) 88 87 89 88 #ifdef CONFIG_SERIAL_8250_SHARE_IRQ 90 89 #define SERIAL8250_SHARE_IRQS 1 ··· 150 151 static inline void serial8250_pnp_exit(void) { } 151 152 #endif 152 153 154 + #ifdef CONFIG_SERIAL_8250_FINTEK 155 + int fintek_8250_probe(struct uart_8250_port *uart); 156 + #else 157 + static inline int fintek_8250_probe(struct uart_8250_port *uart) { return 0; } 158 + #endif 159 + 153 160 #ifdef CONFIG_ARCH_OMAP1 154 161 static inline int is_omap1_8250(struct uart_8250_port *pt) 155 162 { ··· 195 190 196 191 #ifdef CONFIG_SERIAL_8250_DMA 197 192 extern int serial8250_tx_dma(struct uart_8250_port *); 198 - extern int serial8250_rx_dma(struct uart_8250_port *, unsigned int iir); 193 + extern int serial8250_rx_dma(struct uart_8250_port *); 194 + extern void serial8250_rx_dma_flush(struct uart_8250_port *); 199 195 extern int serial8250_request_dma(struct uart_8250_port *); 200 196 extern void serial8250_release_dma(struct uart_8250_port *); 201 197 #else ··· 204 198 { 205 199 return -1; 206 200 } 207 - static inline int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir) 201 + static inline int serial8250_rx_dma(struct uart_8250_port *p) 208 202 { 209 203 return -1; 210 204 } 205 + static inline void serial8250_rx_dma_flush(struct uart_8250_port *p) { } 211 206 static inline int serial8250_request_dma(struct uart_8250_port *p) 212 207 { 213 208 return -1;
+3
drivers/tty/serial/8250/8250_core.c
··· 830 830 uart.port.handle_irq = p->handle_irq; 831 831 uart.port.handle_break = p->handle_break; 832 832 uart.port.set_termios = p->set_termios; 833 + uart.port.get_mctrl = p->get_mctrl; 833 834 uart.port.pm = p->pm; 834 835 uart.port.dev = &dev->dev; 835 836 uart.port.irqflags |= irqflag; ··· 1023 1022 /* Possibly override set_termios call */ 1024 1023 if (up->port.set_termios) 1025 1024 uart->port.set_termios = up->port.set_termios; 1025 + if (up->port.get_mctrl) 1026 + uart->port.get_mctrl = up->port.get_mctrl; 1026 1027 if (up->port.set_mctrl) 1027 1028 uart->port.set_mctrl = up->port.set_mctrl; 1028 1029 if (up->port.startup)
+42 -26
drivers/tty/serial/8250/8250_dma.c
··· 110 110 return ret; 111 111 } 112 112 113 - int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir) 113 + int serial8250_rx_dma(struct uart_8250_port *p) 114 114 { 115 115 struct uart_8250_dma *dma = p->dma; 116 116 struct dma_async_tx_descriptor *desc; 117 - 118 - switch (iir & 0x3f) { 119 - case UART_IIR_RLSI: 120 - /* 8250_core handles errors and break interrupts */ 121 - return -EIO; 122 - case UART_IIR_RX_TIMEOUT: 123 - /* 124 - * If RCVR FIFO trigger level was not reached, complete the 125 - * transfer and let 8250_core copy the remaining data. 126 - */ 127 - if (dma->rx_running) { 128 - dmaengine_pause(dma->rxchan); 129 - __dma_rx_complete(p); 130 - dmaengine_terminate_all(dma->rxchan); 131 - } 132 - return -ETIMEDOUT; 133 - default: 134 - break; 135 - } 136 117 137 118 if (dma->rx_running) 138 119 return 0; ··· 135 154 return 0; 136 155 } 137 156 157 + void serial8250_rx_dma_flush(struct uart_8250_port *p) 158 + { 159 + struct uart_8250_dma *dma = p->dma; 160 + 161 + if (dma->rx_running) { 162 + dmaengine_pause(dma->rxchan); 163 + __dma_rx_complete(p); 164 + dmaengine_terminate_all(dma->rxchan); 165 + } 166 + } 167 + 138 168 int serial8250_request_dma(struct uart_8250_port *p) 139 169 { 140 170 struct uart_8250_dma *dma = p->dma; 141 171 dma_cap_mask_t mask; 172 + struct dma_slave_caps caps; 173 + int ret; 142 174 143 175 /* Default slave configuration parameters */ 144 176 dma->rxconf.direction = DMA_DEV_TO_MEM; ··· 172 178 if (!dma->rxchan) 173 179 return -ENODEV; 174 180 181 + /* 8250 rx dma requires dmaengine driver to support pause/terminate */ 182 + ret = dma_get_slave_caps(dma->rxchan, &caps); 183 + if (ret) 184 + goto release_rx; 185 + if (!caps.cmd_pause || !caps.cmd_terminate || 186 + caps.residue_granularity == DMA_RESIDUE_GRANULARITY_DESCRIPTOR) { 187 + ret = -EINVAL; 188 + goto release_rx; 189 + } 190 + 175 191 dmaengine_slave_config(dma->rxchan, &dma->rxconf); 176 192 177 193 /* Get a channel for TX */ ··· 189 185 dma->fn, dma->tx_param, 190 186 p->port.dev, "tx"); 191 187 if (!dma->txchan) { 192 - dma_release_channel(dma->rxchan); 193 - return -ENODEV; 188 + ret = -ENODEV; 189 + goto release_rx; 190 + } 191 + 192 + /* 8250 tx dma requires dmaengine driver to support terminate */ 193 + ret = dma_get_slave_caps(dma->txchan, &caps); 194 + if (ret) 195 + goto err; 196 + if (!caps.cmd_terminate) { 197 + ret = -EINVAL; 198 + goto err; 194 199 } 195 200 196 201 dmaengine_slave_config(dma->txchan, &dma->txconf); ··· 210 197 211 198 dma->rx_buf = dma_alloc_coherent(dma->rxchan->device->dev, dma->rx_size, 212 199 &dma->rx_addr, GFP_KERNEL); 213 - if (!dma->rx_buf) 200 + if (!dma->rx_buf) { 201 + ret = -ENOMEM; 214 202 goto err; 203 + } 215 204 216 205 /* TX buffer */ 217 206 dma->tx_addr = dma_map_single(dma->txchan->device->dev, ··· 223 208 if (dma_mapping_error(dma->txchan->device->dev, dma->tx_addr)) { 224 209 dma_free_coherent(dma->rxchan->device->dev, dma->rx_size, 225 210 dma->rx_buf, dma->rx_addr); 211 + ret = -ENOMEM; 226 212 goto err; 227 213 } 228 214 ··· 231 215 232 216 return 0; 233 217 err: 234 - dma_release_channel(dma->rxchan); 235 218 dma_release_channel(dma->txchan); 236 - 237 - return -ENOMEM; 219 + release_rx: 220 + dma_release_channel(dma->rxchan); 221 + return ret; 238 222 } 239 223 EXPORT_SYMBOL_GPL(serial8250_request_dma); 240 224
+5 -3
drivers/tty/serial/8250/8250_dw.c
··· 104 104 dw8250_force_idle(p); 105 105 106 106 #ifdef CONFIG_64BIT 107 - __raw_writeq(value & 0xff, offset); 108 - #else 107 + if (p->type == PORT_OCTEON) 108 + __raw_writeq(value & 0xff, offset); 109 + else 110 + #endif 109 111 if (p->iotype == UPIO_MEM32) 110 112 writel(value, offset); 111 113 else if (p->iotype == UPIO_MEM32BE) 112 114 iowrite32be(value, offset); 113 115 else 114 116 writeb(value, offset); 115 - #endif 116 117 } 117 118 /* 118 119 * FIXME: this deadlocks if port->lock is already held ··· 618 617 { "8086228A", 0 }, 619 618 { "APMC0D08", 0}, 620 619 { "AMD0020", 0 }, 620 + { "AMDI0020", 0 }, 621 621 { }, 622 622 }; 623 623 MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match);
+16 -102
drivers/tty/serial/8250/8250_fintek.c
··· 1 1 /* 2 2 * Probe for F81216A LPC to 4 UART 3 3 * 4 - * Based on drivers/tty/serial/8250_pnp.c, by Russell King, et al 5 - * 6 - * Copyright (C) 2014 Ricardo Ribalda, Qtechnology A/S 4 + * Copyright (C) 2014-2016 Ricardo Ribalda, Qtechnology A/S 7 5 * 8 6 * 9 7 * This program is free software; you can redistribute it and/or modify ··· 36 38 #define RXW4C_IRA BIT(3) 37 39 #define TXW4C_IRA BIT(2) 38 40 39 - #define DRIVER_NAME "8250_fintek" 40 - 41 41 struct fintek_8250 { 42 42 u16 base_port; 43 43 u8 index; 44 44 u8 key; 45 - long line; 46 45 }; 47 46 48 47 static int fintek_8250_enter_key(u16 base_port, u8 key) 49 48 { 50 - 51 - if (!request_muxed_region(base_port, 2, DRIVER_NAME)) 49 + if (!request_muxed_region(base_port, 2, "8250_fintek")) 52 50 return -EBUSY; 53 51 54 52 outb(key, base_port + ADDR_PORT); ··· 132 138 return 0; 133 139 } 134 140 135 - static int fintek_8250_base_port(u16 io_address, u8 *key, u8 *index) 141 + static int find_base_port(struct fintek_8250 *pdata, u16 io_address) 136 142 { 137 143 static const u16 addr[] = {0x4e, 0x2e}; 138 144 static const u8 keys[] = {0x77, 0xa0, 0x87, 0x67}; ··· 162 168 continue; 163 169 164 170 fintek_8250_exit_key(addr[i]); 165 - *key = keys[j]; 166 - *index = k; 167 - return addr[i]; 171 + pdata->key = keys[j]; 172 + pdata->base_port = addr[i]; 173 + pdata->index = k; 174 + 175 + return 0; 168 176 } 177 + 169 178 fintek_8250_exit_key(addr[i]); 170 179 } 171 180 } ··· 176 179 return -ENODEV; 177 180 } 178 181 179 - static int 180 - fintek_8250_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) 182 + int fintek_8250_probe(struct uart_8250_port *uart) 181 183 { 182 - struct uart_8250_port uart; 183 184 struct fintek_8250 *pdata; 184 - int base_port; 185 - u8 key; 186 - u8 index; 185 + struct fintek_8250 probe_data; 187 186 188 - if (!pnp_port_valid(dev, 0)) 187 + if (find_base_port(&probe_data, uart->port.iobase)) 189 188 return -ENODEV; 190 189 191 - base_port = fintek_8250_base_port(pnp_port_start(dev, 0), &key, &index); 192 - if (base_port < 0) 193 - return -ENODEV; 194 - 195 - memset(&uart, 0, sizeof(uart)); 196 - 197 - pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL); 190 + pdata = devm_kzalloc(uart->port.dev, sizeof(*pdata), GFP_KERNEL); 198 191 if (!pdata) 199 192 return -ENOMEM; 200 - uart.port.private_data = pdata; 201 193 202 - if (!pnp_irq_valid(dev, 0)) 203 - return -ENODEV; 204 - uart.port.irq = pnp_irq(dev, 0); 205 - uart.port.iobase = pnp_port_start(dev, 0); 206 - uart.port.iotype = UPIO_PORT; 207 - uart.port.rs485_config = fintek_8250_rs485_config; 194 + memcpy(pdata, &probe_data, sizeof(probe_data)); 195 + uart->port.rs485_config = fintek_8250_rs485_config; 196 + uart->port.private_data = pdata; 208 197 209 - uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; 210 - if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE) 211 - uart.port.flags |= UPF_SHARE_IRQ; 212 - uart.port.uartclk = 1843200; 213 - uart.port.dev = &dev->dev; 214 - 215 - pdata->key = key; 216 - pdata->base_port = base_port; 217 - pdata->index = index; 218 - pdata->line = serial8250_register_8250_port(&uart); 219 - if (pdata->line < 0) 220 - return -ENODEV; 221 - 222 - pnp_set_drvdata(dev, pdata); 223 198 return 0; 224 199 } 225 - 226 - static void fintek_8250_remove(struct pnp_dev *dev) 227 - { 228 - struct fintek_8250 *pdata = pnp_get_drvdata(dev); 229 - 230 - if (pdata) 231 - serial8250_unregister_port(pdata->line); 232 - } 233 - 234 - #ifdef CONFIG_PM 235 - static int fintek_8250_suspend(struct pnp_dev *dev, pm_message_t state) 236 - { 237 - struct fintek_8250 *pdata = pnp_get_drvdata(dev); 238 - 239 - if (!pdata) 240 - return -ENODEV; 241 - serial8250_suspend_port(pdata->line); 242 - return 0; 243 - } 244 - 245 - static int fintek_8250_resume(struct pnp_dev *dev) 246 - { 247 - struct fintek_8250 *pdata = pnp_get_drvdata(dev); 248 - 249 - if (!pdata) 250 - return -ENODEV; 251 - serial8250_resume_port(pdata->line); 252 - return 0; 253 - } 254 - #else 255 - #define fintek_8250_suspend NULL 256 - #define fintek_8250_resume NULL 257 - #endif /* CONFIG_PM */ 258 - 259 - static const struct pnp_device_id fintek_dev_table[] = { 260 - /* Qtechnology Panel PC / IO1000 */ 261 - { "PNP0501"}, 262 - {} 263 - }; 264 - 265 - MODULE_DEVICE_TABLE(pnp, fintek_dev_table); 266 - 267 - static struct pnp_driver fintek_8250_driver = { 268 - .name = DRIVER_NAME, 269 - .probe = fintek_8250_probe, 270 - .remove = fintek_8250_remove, 271 - .suspend = fintek_8250_suspend, 272 - .resume = fintek_8250_resume, 273 - .id_table = fintek_dev_table, 274 - }; 275 - 276 - module_pnp_driver(fintek_8250_driver); 277 - MODULE_DESCRIPTION("Fintek F812164 module"); 278 - MODULE_AUTHOR("Ricardo Ribalda <ricardo.ribalda@gmail.com>"); 279 - MODULE_LICENSE("GPL");
+28 -14
drivers/tty/serial/8250/8250_mid.c
··· 9 9 * published by the Free Software Foundation. 10 10 */ 11 11 12 - #include <linux/rational.h> 12 + #include <linux/bitops.h> 13 13 #include <linux/module.h> 14 14 #include <linux/pci.h> 15 + #include <linux/rational.h> 15 16 16 17 #include <linux/dma/hsu.h> 18 + #include <linux/8250_pci.h> 17 19 18 20 #include "8250.h" 19 21 ··· 26 24 #define PCI_DEVICE_ID_INTEL_DNV_UART 0x19d8 27 25 28 26 /* Intel MID Specific registers */ 27 + #define INTEL_MID_UART_DNV_FISR 0x08 29 28 #define INTEL_MID_UART_PS 0x30 30 29 #define INTEL_MID_UART_MUL 0x34 31 30 #define INTEL_MID_UART_DIV 0x38 ··· 34 31 struct mid8250; 35 32 36 33 struct mid8250_board { 34 + unsigned int flags; 37 35 unsigned long freq; 38 36 unsigned int base_baud; 39 37 int (*setup)(struct mid8250 *, struct uart_port *p); ··· 80 76 struct pci_dev *pdev = to_pci_dev(p->dev); 81 77 int index = PCI_FUNC(pdev->devfn); 82 78 83 - /* Currently no support for HSU port0 */ 79 + /* 80 + * Device 0000:00:04.0 is not a real HSU port. It provides a global 81 + * register set for all HSU ports, although it has the same PCI ID. 82 + * Skip it here. 83 + */ 84 84 if (index-- == 0) 85 85 return -ENODEV; 86 86 ··· 96 88 static int dnv_handle_irq(struct uart_port *p) 97 89 { 98 90 struct mid8250 *mid = p->private_data; 99 - int ret; 91 + unsigned int fisr = serial_port_in(p, INTEL_MID_UART_DNV_FISR); 92 + int ret = IRQ_NONE; 100 93 101 - ret = hsu_dma_irq(&mid->dma_chip, 0); 102 - ret |= hsu_dma_irq(&mid->dma_chip, 1); 103 - 104 - /* For now, letting the HW generate separate interrupt for the UART */ 105 - if (ret) 106 - return ret; 107 - 108 - return serial8250_handle_irq(p, serial_port_in(p, UART_IIR)); 94 + if (fisr & BIT(2)) 95 + ret |= hsu_dma_irq(&mid->dma_chip, 1); 96 + if (fisr & BIT(1)) 97 + ret |= hsu_dma_irq(&mid->dma_chip, 0); 98 + if (fisr & BIT(0)) 99 + ret |= serial8250_handle_irq(p, serial_port_in(p, UART_IIR)); 100 + return ret; 109 101 } 110 102 111 103 #define DNV_DMA_CHAN_OFFSET 0x80 ··· 114 106 { 115 107 struct hsu_dma_chip *chip = &mid->dma_chip; 116 108 struct pci_dev *pdev = to_pci_dev(p->dev); 109 + unsigned int bar = FL_GET_BASE(mid->board->flags); 117 110 int ret; 118 111 119 112 chip->dev = &pdev->dev; 120 113 chip->irq = pdev->irq; 121 114 chip->regs = p->membase; 122 - chip->length = pci_resource_len(pdev, 0); 115 + chip->length = pci_resource_len(pdev, bar); 123 116 chip->offset = DNV_DMA_CHAN_OFFSET; 124 117 125 118 /* Falling back to PIO mode if DMA probing fails */ ··· 226 217 { 227 218 struct uart_8250_port uart; 228 219 struct mid8250 *mid; 220 + unsigned int bar; 229 221 int ret; 230 222 231 223 ret = pcim_enable_device(pdev); ··· 240 230 return -ENOMEM; 241 231 242 232 mid->board = (struct mid8250_board *)id->driver_data; 233 + bar = FL_GET_BASE(mid->board->flags); 243 234 244 235 memset(&uart, 0, sizeof(struct uart_8250_port)); 245 236 ··· 253 242 uart.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT | UPF_FIXED_TYPE; 254 243 uart.port.set_termios = mid8250_set_termios; 255 244 256 - uart.port.mapbase = pci_resource_start(pdev, 0); 257 - uart.port.membase = pcim_iomap(pdev, 0, 0); 245 + uart.port.mapbase = pci_resource_start(pdev, bar); 246 + uart.port.membase = pcim_iomap(pdev, bar, 0); 258 247 if (!uart.port.membase) 259 248 return -ENOMEM; 260 249 ··· 293 282 } 294 283 295 284 static const struct mid8250_board pnw_board = { 285 + .flags = FL_BASE0, 296 286 .freq = 50000000, 297 287 .base_baud = 115200, 298 288 .setup = pnw_setup, 299 289 }; 300 290 301 291 static const struct mid8250_board tng_board = { 292 + .flags = FL_BASE0, 302 293 .freq = 38400000, 303 294 .base_baud = 1843200, 304 295 .setup = tng_setup, 305 296 }; 306 297 307 298 static const struct mid8250_board dnv_board = { 299 + .flags = FL_BASE1, 308 300 .freq = 133333333, 309 301 .base_baud = 115200, 310 302 .setup = dnv_setup,
+1 -1
drivers/tty/serial/8250/8250_of.c
··· 29 29 }; 30 30 31 31 #ifdef CONFIG_ARCH_TEGRA 32 - void tegra_serial_handle_break(struct uart_port *p) 32 + static void tegra_serial_handle_break(struct uart_port *p) 33 33 { 34 34 unsigned int status, tmout = 10000; 35 35
+34 -59
drivers/tty/serial/8250/8250_omap.c
··· 115 115 bool rx_dma_broken; 116 116 }; 117 117 118 + #ifdef CONFIG_SERIAL_8250_DMA 119 + static void omap_8250_rx_dma_flush(struct uart_8250_port *p); 120 + #else 121 + static inline void omap_8250_rx_dma_flush(struct uart_8250_port *p) { } 122 + #endif 123 + 118 124 static u32 uart_read(struct uart_8250_port *up, u32 reg) 119 125 { 120 126 return readl(up->port.membase + (reg << up->port.regshift)); ··· 641 635 serial_out(up, UART_OMAP_WER, priv->wer); 642 636 643 637 if (up->dma) 644 - up->dma->rx_dma(up, 0); 638 + up->dma->rx_dma(up); 645 639 646 640 pm_runtime_mark_last_busy(port->dev); 647 641 pm_runtime_put_autosuspend(port->dev); ··· 660 654 661 655 flush_work(&priv->qos_work); 662 656 if (up->dma) 663 - up->dma->rx_dma(up, UART_IIR_RX_TIMEOUT); 657 + omap_8250_rx_dma_flush(up); 664 658 665 659 pm_runtime_get_sync(port->dev); 666 660 ··· 748 742 } 749 743 750 744 #ifdef CONFIG_SERIAL_8250_DMA 751 - static int omap_8250_rx_dma(struct uart_8250_port *p, unsigned int iir); 745 + static int omap_8250_rx_dma(struct uart_8250_port *p); 752 746 753 - static void __dma_rx_do_complete(struct uart_8250_port *p, bool error) 747 + static void __dma_rx_do_complete(struct uart_8250_port *p) 754 748 { 755 749 struct omap8250_priv *priv = p->port.private_data; 756 750 struct uart_8250_dma *dma = p->dma; ··· 760 754 unsigned long flags; 761 755 int ret; 762 756 763 - dma_sync_single_for_cpu(dma->rxchan->device->dev, dma->rx_addr, 764 - dma->rx_size, DMA_FROM_DEVICE); 765 - 766 757 spin_lock_irqsave(&priv->rx_dma_lock, flags); 767 758 768 759 if (!dma->rx_running) ··· 767 764 768 765 dma->rx_running = 0; 769 766 dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); 770 - dmaengine_terminate_all(dma->rxchan); 771 767 772 768 count = dma->rx_size - state.residue; 773 769 ··· 777 775 unlock: 778 776 spin_unlock_irqrestore(&priv->rx_dma_lock, flags); 779 777 780 - if (!error) 781 - omap_8250_rx_dma(p, 0); 782 - 783 778 tty_flip_buffer_push(tty_port); 784 779 } 785 780 786 781 static void __dma_rx_complete(void *param) 787 782 { 788 - __dma_rx_do_complete(param, false); 783 + __dma_rx_do_complete(param); 784 + omap_8250_rx_dma(param); 789 785 } 790 786 791 787 static void omap_8250_rx_dma_flush(struct uart_8250_port *p) ··· 806 806 807 807 spin_unlock_irqrestore(&priv->rx_dma_lock, flags); 808 808 809 - __dma_rx_do_complete(p, true); 809 + __dma_rx_do_complete(p); 810 + dmaengine_terminate_all(dma->rxchan); 810 811 } 811 812 812 - static int omap_8250_rx_dma(struct uart_8250_port *p, unsigned int iir) 813 + static int omap_8250_rx_dma(struct uart_8250_port *p) 813 814 { 814 815 struct omap8250_priv *priv = p->port.private_data; 815 816 struct uart_8250_dma *dma = p->dma; 816 817 int err = 0; 817 818 struct dma_async_tx_descriptor *desc; 818 819 unsigned long flags; 819 - 820 - switch (iir & 0x3f) { 821 - case UART_IIR_RLSI: 822 - /* 8250_core handles errors and break interrupts */ 823 - omap_8250_rx_dma_flush(p); 824 - return -EIO; 825 - case UART_IIR_RX_TIMEOUT: 826 - /* 827 - * If RCVR FIFO trigger level was not reached, complete the 828 - * transfer and let 8250_core copy the remaining data. 829 - */ 830 - omap_8250_rx_dma_flush(p); 831 - return -ETIMEDOUT; 832 - case UART_IIR_RDI: 833 - /* 834 - * The OMAP UART is a special BEAST. If we receive RDI we _have_ 835 - * a DMA transfer programmed but it didn't work. One reason is 836 - * that we were too slow and there were too many bytes in the 837 - * FIFO, the UART counted wrong and never kicked the DMA engine 838 - * to do anything. That means once we receive RDI on OMAP then 839 - * the DMA won't do anything soon so we have to cancel the DMA 840 - * transfer and purge the FIFO manually. 841 - */ 842 - omap_8250_rx_dma_flush(p); 843 - return -ETIMEDOUT; 844 - 845 - default: 846 - break; 847 - } 848 820 849 821 if (priv->rx_dma_broken) 850 822 return -EINVAL; ··· 839 867 desc->callback_param = p; 840 868 841 869 dma->rx_cookie = dmaengine_submit(desc); 842 - 843 - dma_sync_single_for_device(dma->rxchan->device->dev, dma->rx_addr, 844 - dma->rx_size, DMA_FROM_DEVICE); 845 870 846 871 dma_async_issue_pending(dma->rxchan); 847 872 out: ··· 991 1022 return ret; 992 1023 } 993 1024 1025 + static bool handle_rx_dma(struct uart_8250_port *up, unsigned int iir) 1026 + { 1027 + switch (iir & 0x3f) { 1028 + case UART_IIR_RLSI: 1029 + case UART_IIR_RX_TIMEOUT: 1030 + case UART_IIR_RDI: 1031 + omap_8250_rx_dma_flush(up); 1032 + return true; 1033 + } 1034 + return omap_8250_rx_dma(up); 1035 + } 1036 + 994 1037 /* 995 1038 * This is mostly serial8250_handle_irq(). We have a slightly different DMA 996 1039 * hoook for RX/TX and need different logic for them in the ISR. Therefore we ··· 1014 1033 unsigned char status; 1015 1034 unsigned long flags; 1016 1035 u8 iir; 1017 - int dma_err = 0; 1018 1036 1019 1037 serial8250_rpm_get(up); 1020 1038 ··· 1028 1048 status = serial_port_in(port, UART_LSR); 1029 1049 1030 1050 if (status & (UART_LSR_DR | UART_LSR_BI)) { 1031 - 1032 - dma_err = omap_8250_rx_dma(up, iir); 1033 - if (dma_err) { 1051 + if (handle_rx_dma(up, iir)) { 1034 1052 status = serial8250_rx_chars(up, status); 1035 - omap_8250_rx_dma(up, 0); 1053 + omap_8250_rx_dma(up); 1036 1054 } 1037 1055 } 1038 1056 serial8250_modem_status(up); ··· 1044 1066 * try again due to an earlier failer which 1045 1067 * might have been resolved by now. 1046 1068 */ 1047 - dma_err = omap_8250_tx_dma(up); 1048 - if (dma_err) 1069 + if (omap_8250_tx_dma(up)) 1049 1070 serial8250_tx_chars(up); 1050 1071 } 1051 1072 } ··· 1061 1084 1062 1085 #else 1063 1086 1064 - static inline int omap_8250_rx_dma(struct uart_8250_port *p, unsigned int iir) 1087 + static inline int omap_8250_rx_dma(struct uart_8250_port *p) 1065 1088 { 1066 1089 return -EINVAL; 1067 1090 } ··· 1372 1395 } 1373 1396 1374 1397 if (up->dma && up->dma->rxchan) 1375 - omap_8250_rx_dma(up, UART_IIR_RX_TIMEOUT); 1398 + omap_8250_rx_dma_flush(up); 1376 1399 1377 1400 priv->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; 1378 1401 schedule_work(&priv->qos_work); ··· 1384 1407 { 1385 1408 struct omap8250_priv *priv = dev_get_drvdata(dev); 1386 1409 struct uart_8250_port *up; 1387 - int loss_cntx; 1388 1410 1389 1411 /* In case runtime-pm tries this before we are setup */ 1390 1412 if (!priv) 1391 1413 return 0; 1392 1414 1393 1415 up = serial8250_get_port(priv->line); 1394 - loss_cntx = omap8250_lost_context(up); 1395 1416 1396 - if (loss_cntx) 1417 + if (omap8250_lost_context(up)) 1397 1418 omap8250_restore_regs(up); 1398 1419 1399 1420 if (up->dma && up->dma->rxchan) 1400 - omap_8250_rx_dma(up, 0); 1421 + omap_8250_rx_dma(up); 1401 1422 1402 1423 priv->latency = priv->calc_latency; 1403 1424 schedule_work(&priv->qos_work);
+15
drivers/tty/serial/8250/8250_pci.c
··· 1377 1377 unsigned long m, n; 1378 1378 u32 reg; 1379 1379 1380 + /* Gracefully handle the B0 case: fall back to B9600 */ 1381 + fuart = fuart ? fuart : 9600 * 16; 1382 + 1380 1383 /* Get Fuart closer to Fref */ 1381 1384 fuart *= rounddown_pow_of_two(fref / fuart); 1382 1385 ··· 1414 1411 1415 1412 chan->private = dws; 1416 1413 return true; 1414 + } 1415 + 1416 + static unsigned int 1417 + byt_get_mctrl(struct uart_port *port) 1418 + { 1419 + unsigned int ret = serial8250_do_get_mctrl(port); 1420 + 1421 + /* Force DCD and DSR signals to permanently be reported as active. */ 1422 + ret |= TIOCM_CAR | TIOCM_DSR; 1423 + 1424 + return ret; 1417 1425 } 1418 1426 1419 1427 static int ··· 1491 1477 port->port.type = PORT_16550A; 1492 1478 port->port.flags = (port->port.flags | UPF_FIXED_PORT | UPF_FIXED_TYPE); 1493 1479 port->port.set_termios = byt_set_termios; 1480 + port->port.get_mctrl = byt_get_mctrl; 1494 1481 port->port.fifosize = 64; 1495 1482 port->tx_loadsz = 64; 1496 1483 port->dma = dma;
+30 -8
drivers/tty/serial/8250/8250_port.c
··· 1315 1315 1316 1316 out_lock: 1317 1317 spin_unlock_irqrestore(&port->lock, flags); 1318 + 1319 + /* 1320 + * Check if the device is a Fintek F81216A 1321 + */ 1322 + if (port->type == PORT_16550A) 1323 + fintek_8250_probe(up); 1324 + 1318 1325 if (up->capabilities != old_capabilities) { 1319 1326 pr_warn("ttyS%d: detected caps %08x should be %08x\n", 1320 1327 serial_index(port), old_capabilities, ··· 1795 1788 } 1796 1789 EXPORT_SYMBOL_GPL(serial8250_modem_status); 1797 1790 1791 + static bool handle_rx_dma(struct uart_8250_port *up, unsigned int iir) 1792 + { 1793 + switch (iir & 0x3f) { 1794 + case UART_IIR_RX_TIMEOUT: 1795 + serial8250_rx_dma_flush(up); 1796 + /* fall-through */ 1797 + case UART_IIR_RLSI: 1798 + return true; 1799 + } 1800 + return up->dma->rx_dma(up); 1801 + } 1802 + 1798 1803 /* 1799 1804 * This handles the interrupt from one port. 1800 1805 */ ··· 1815 1796 unsigned char status; 1816 1797 unsigned long flags; 1817 1798 struct uart_8250_port *up = up_to_u8250p(port); 1818 - int dma_err = 0; 1819 1799 1820 1800 if (iir & UART_IIR_NO_INT) 1821 1801 return 0; ··· 1826 1808 DEBUG_INTR("status = %x...", status); 1827 1809 1828 1810 if (status & (UART_LSR_DR | UART_LSR_BI)) { 1829 - if (up->dma) 1830 - dma_err = up->dma->rx_dma(up, iir); 1831 - 1832 - if (!up->dma || dma_err) 1811 + if (!up->dma || handle_rx_dma(up, iir)) 1833 1812 status = serial8250_rx_chars(up, status); 1834 1813 } 1835 1814 serial8250_modem_status(up); 1836 - if ((!up->dma || (up->dma && up->dma->tx_err)) && 1837 - (status & UART_LSR_THRE)) 1815 + if ((!up->dma || up->dma->tx_err) && (status & UART_LSR_THRE)) 1838 1816 serial8250_tx_chars(up); 1839 1817 1840 1818 spin_unlock_irqrestore(&port->lock, flags); ··· 1896 1882 return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0; 1897 1883 } 1898 1884 1899 - static unsigned int serial8250_get_mctrl(struct uart_port *port) 1885 + unsigned int serial8250_do_get_mctrl(struct uart_port *port) 1900 1886 { 1901 1887 struct uart_8250_port *up = up_to_u8250p(port); 1902 1888 unsigned int status; ··· 1916 1902 if (status & UART_MSR_CTS) 1917 1903 ret |= TIOCM_CTS; 1918 1904 return ret; 1905 + } 1906 + EXPORT_SYMBOL_GPL(serial8250_do_get_mctrl); 1907 + 1908 + static unsigned int serial8250_get_mctrl(struct uart_port *port) 1909 + { 1910 + if (port->get_mctrl) 1911 + return port->get_mctrl(port); 1912 + return serial8250_do_get_mctrl(port); 1919 1913 } 1920 1914 1921 1915 void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl)
+1 -1
drivers/tty/serial/8250/8250_uniphier.c
··· 209 209 210 210 irq = platform_get_irq(pdev, 0); 211 211 if (irq < 0) { 212 - dev_err(dev, "failed to get IRQ number"); 212 + dev_err(dev, "failed to get IRQ number\n"); 213 213 return irq; 214 214 } 215 215
+15 -9
drivers/tty/serial/8250/Kconfig
··· 57 57 This builds standard PNP serial support. You may be able to 58 58 disable this feature if you only need legacy serial support. 59 59 60 + config SERIAL_8250_FINTEK 61 + bool "Support for Fintek F81216A LPC to 4 UART RS485 API" 62 + depends on SERIAL_8250 63 + ---help--- 64 + Selecting this option will add support for the RS485 capabilities 65 + of the Fintek F81216A LPC to 4 UART. 66 + 67 + If this option is not selected the device will be configured as a 68 + standard 16550A serial port. 69 + 70 + If unsure, say N. 71 + 60 72 config SERIAL_8250_CONSOLE 61 73 bool "Console on 8250/16550 and compatible serial port" 62 74 depends on SERIAL_8250=y ··· 370 358 not booting kernel because the serial console remains silent in case 371 359 they forgot to update the command line. 372 360 373 - config SERIAL_8250_FINTEK 374 - tristate "Support for Fintek F81216A LPC to 4 UART" 375 - depends on SERIAL_8250 && PNP 376 - help 377 - Selecting this option will add support for the Fintek F81216A 378 - LPC to 4 UART. This device has some RS485 functionality not available 379 - through the PNP driver. If unsure, say N. 380 - 381 361 config SERIAL_8250_LPC18XX 382 362 tristate "NXP LPC18xx/43xx serial port support" 383 363 depends on SERIAL_8250 && OF && (ARCH_LPC18XX || COMPILE_TEST) ··· 402 398 its UARTs, say Y to this option. If unsure, say N. 403 399 404 400 config SERIAL_8250_MID 405 - tristate "Support for serial ports on Intel MID platforms" 401 + tristate "Support for serial ports on Intel MID platforms" if EXPERT 402 + default SERIAL_8250 406 403 depends on SERIAL_8250 && PCI 404 + depends on X86 || COMPILE_TEST 407 405 select HSU_DMA if SERIAL_8250_DMA 408 406 select HSU_DMA_PCI if (HSU_DMA && X86_INTEL_MID) 409 407 select RATIONAL
+1 -1
drivers/tty/serial/8250/Makefile
··· 7 7 8250-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o 8 8 8250_base-y := 8250_port.o 9 9 8250_base-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o 10 + 8250_base-$(CONFIG_SERIAL_8250_FINTEK) += 8250_fintek.o 10 11 obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o 11 12 obj-$(CONFIG_SERIAL_8250_PCI) += 8250_pci.o 12 13 obj-$(CONFIG_SERIAL_8250_HP300) += 8250_hp300.o ··· 24 23 obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o 25 24 obj-$(CONFIG_SERIAL_8250_EM) += 8250_em.o 26 25 obj-$(CONFIG_SERIAL_8250_OMAP) += 8250_omap.o 27 - obj-$(CONFIG_SERIAL_8250_FINTEK) += 8250_fintek.o 28 26 obj-$(CONFIG_SERIAL_8250_LPC18XX) += 8250_lpc18xx.o 29 27 obj-$(CONFIG_SERIAL_8250_MT6577) += 8250_mtk.o 30 28 obj-$(CONFIG_SERIAL_8250_UNIPHIER) += 8250_uniphier.o
+18 -2
drivers/tty/serial/Kconfig
··· 213 213 bool "Support for console on meson" 214 214 depends on SERIAL_MESON=y 215 215 select SERIAL_CORE_CONSOLE 216 + select SERIAL_EARLYCON 216 217 help 217 218 Say Y here if you wish to use a Amlogic MesonX UART as the 218 219 system console (the system console is the device which ··· 1405 1404 config SERIAL_MXS_AUART 1406 1405 tristate "MXS AUART support" 1407 1406 depends on HAS_DMA 1408 - depends on ARCH_MXS || COMPILE_TEST 1407 + depends on ARCH_MXS || MACH_ASM9260 || COMPILE_TEST 1409 1408 select SERIAL_CORE 1410 1409 select SERIAL_MCTRL_GPIO if GPIOLIB 1411 1410 help 1412 - This driver supports the MXS Application UART (AUART) port. 1411 + This driver supports the MXS and Alphascale ASM9260 Application 1412 + UART (AUART) port. 1413 1413 1414 1414 config SERIAL_MXS_AUART_CONSOLE 1415 1415 bool "MXS AUART console support" ··· 1468 1466 help 1469 1467 This driver support the USART and UART ports on 1470 1468 Energy Micro's efm32 SoCs. 1469 + 1470 + config SERIAL_MPS2_UART_CONSOLE 1471 + bool "MPS2 UART console support" 1472 + depends on SERIAL_MPS2_UART 1473 + select SERIAL_CORE_CONSOLE 1474 + select SERIAL_EARLYCON 1475 + 1476 + config SERIAL_MPS2_UART 1477 + bool "MPS2 UART port" 1478 + depends on ARM || COMPILE_TEST 1479 + select SERIAL_CORE 1480 + help 1481 + This driver support the UART ports on ARM MPS2. 1471 1482 1472 1483 config SERIAL_EFM32_UART_CONSOLE 1473 1484 bool "EFM32 UART/USART console support" ··· 1640 1625 1641 1626 config SERIAL_MVEBU_UART 1642 1627 bool "Marvell EBU serial port support" 1628 + depends on ARCH_MVEBU || COMPILE_TEST 1643 1629 select SERIAL_CORE 1644 1630 help 1645 1631 This driver is for Marvell EBU SoC's UART. If you have a machine
+1
drivers/tty/serial/Makefile
··· 92 92 obj-$(CONFIG_SERIAL_STM32) += stm32-usart.o 93 93 obj-$(CONFIG_SERIAL_MVEBU_UART) += mvebu-uart.o 94 94 obj-$(CONFIG_SERIAL_PIC32) += pic32_uart.o 95 + obj-$(CONFIG_SERIAL_MPS2_UART) += mps2-uart.o 95 96 96 97 # GPIOLIB helpers for modem control lines 97 98 obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
+1
drivers/tty/serial/amba-pl011.c
··· 121 121 122 122 static struct vendor_data vendor_sbsa = { 123 123 .reg_offset = pl011_std_offsets, 124 + .access_32b = true, 124 125 .oversampling = false, 125 126 .dma_threshold = false, 126 127 .cts_event_workaround = false,
+13 -1
drivers/tty/serial/atmel_serial.c
··· 274 274 return atmel_port->use_dma_rx; 275 275 } 276 276 277 + static bool atmel_use_fifo(struct uart_port *port) 278 + { 279 + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 280 + 281 + return atmel_port->fifo_size; 282 + } 283 + 277 284 static unsigned int atmel_get_lines_status(struct uart_port *port) 278 285 { 279 286 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); ··· 2097 2090 mode |= ATMEL_US_USMODE_RS485; 2098 2091 } else if (termios->c_cflag & CRTSCTS) { 2099 2092 /* RS232 with hardware handshake (RTS/CTS) */ 2100 - mode |= ATMEL_US_USMODE_HWHS; 2093 + if (atmel_use_dma_rx(port) && !atmel_use_fifo(port)) { 2094 + dev_info(port->dev, "not enabling hardware flow control because DMA is used"); 2095 + termios->c_cflag &= ~CRTSCTS; 2096 + } else { 2097 + mode |= ATMEL_US_USMODE_HWHS; 2098 + } 2101 2099 } else { 2102 2100 /* RS232 without hadware handshake */ 2103 2101 mode |= ATMEL_US_USMODE_NORMAL;
+14 -16
drivers/tty/serial/crisv10.c
··· 2599 2599 2600 2600 /* if it was already initialized, skip this */ 2601 2601 2602 - if (info->port.flags & ASYNC_INITIALIZED) { 2602 + if (tty_port_initialized(&info->port)) { 2603 2603 local_irq_restore(flags); 2604 2604 free_page(xmit_page); 2605 2605 return 0; ··· 2703 2703 e100_rts(info, 1); 2704 2704 e100_dtr(info, 1); 2705 2705 2706 - info->port.flags |= ASYNC_INITIALIZED; 2706 + tty_port_set_initialized(&info->port, 1); 2707 2707 2708 2708 local_irq_restore(flags); 2709 2709 return 0; ··· 2745 2745 info->tr_running = 0; 2746 2746 } 2747 2747 2748 - if (!(info->port.flags & ASYNC_INITIALIZED)) 2748 + if (!tty_port_initialized(&info->port)) 2749 2749 return; 2750 2750 2751 2751 #ifdef SERIAL_DEBUG_OPEN ··· 2776 2776 if (info->port.tty) 2777 2777 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 2778 2778 2779 - info->port.flags &= ~ASYNC_INITIALIZED; 2779 + tty_port_set_initialized(&info->port, 0); 2780 2780 local_irq_restore(flags); 2781 2781 } 2782 2782 ··· 3273 3273 info->port.low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0; 3274 3274 3275 3275 check_and_exit: 3276 - if (info->port.flags & ASYNC_INITIALIZED) { 3276 + if (tty_port_initialized(&info->port)) 3277 3277 change_speed(info); 3278 - } else 3278 + else 3279 3279 retval = startup(info); 3280 3280 return retval; 3281 3281 } ··· 3445 3445 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 3446 3446 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) && 3447 3447 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) { 3448 - if (tty->flags & (1 << TTY_IO_ERROR)) 3448 + if (tty_io_error(tty)) 3449 3449 return -EIO; 3450 3450 } 3451 3451 ··· 3628 3628 e100_disable_rx(info); 3629 3629 e100_disable_rx_irq(info); 3630 3630 3631 - if (info->port.flags & ASYNC_INITIALIZED) { 3631 + if (tty_port_initialized(&info->port)) { 3632 3632 /* 3633 3633 * Before we drop DTR, make sure the UART transmitter 3634 3634 * has completely drained; this is especially ··· 3648 3648 schedule_timeout_interruptible(info->port.close_delay); 3649 3649 wake_up_interruptible(&info->port.open_wait); 3650 3650 } 3651 - info->port.flags &= ~ASYNC_NORMAL_ACTIVE; 3652 3651 local_irq_restore(flags); 3652 + tty_port_set_active(&info->port, 0); 3653 3653 3654 3654 /* port closed */ 3655 3655 ··· 3732 3732 shutdown(info); 3733 3733 info->event = 0; 3734 3734 info->port.count = 0; 3735 - info->port.flags &= ~ASYNC_NORMAL_ACTIVE; 3735 + tty_port_set_active(&info->port, 0); 3736 3736 info->port.tty = NULL; 3737 3737 wake_up_interruptible(&info->port.open_wait); 3738 3738 } ··· 3755 3755 * If non-blocking mode is set, or the port is not enabled, 3756 3756 * then make the check up front and then exit. 3757 3757 */ 3758 - if ((filp->f_flags & O_NONBLOCK) || 3759 - (tty->flags & (1 << TTY_IO_ERROR))) { 3760 - info->port.flags |= ASYNC_NORMAL_ACTIVE; 3758 + if ((filp->f_flags & O_NONBLOCK) || tty_io_error(tty)) { 3759 + tty_port_set_active(&info->port, 1); 3761 3760 return 0; 3762 3761 } 3763 3762 ··· 3787 3788 e100_dtr(info, 1); 3788 3789 local_irq_restore(flags); 3789 3790 set_current_state(TASK_INTERRUPTIBLE); 3790 - if (tty_hung_up_p(filp) || 3791 - !(info->port.flags & ASYNC_INITIALIZED)) { 3791 + if (tty_hung_up_p(filp) || !tty_port_initialized(&info->port)) { 3792 3792 #ifdef SERIAL_DO_RESTART 3793 3793 if (info->port.flags & ASYNC_HUP_NOTIFY) 3794 3794 retval = -EAGAIN; ··· 3824 3826 #endif 3825 3827 if (retval) 3826 3828 return retval; 3827 - info->port.flags |= ASYNC_NORMAL_ACTIVE; 3829 + tty_port_set_active(&info->port, 1); 3828 3830 return 0; 3829 3831 } 3830 3832
+1 -1
drivers/tty/serial/ifx6x60.c
··· 651 651 struct ifx_spi_device *ifx_dev = ctx; 652 652 int length; 653 653 int actual_length; 654 - unsigned char more; 654 + unsigned char more = 0; 655 655 unsigned char cts; 656 656 int local_write_pending = 0; 657 657 int queue_length;
+114 -60
drivers/tty/serial/imx.c
··· 114 114 #define UCR3_RXDSEN (1<<6) /* Receive status interrupt enable */ 115 115 #define UCR3_AIRINTEN (1<<5) /* Async IR wake interrupt enable */ 116 116 #define UCR3_AWAKEN (1<<4) /* Async wake interrupt enable */ 117 + #define UCR3_DTRDEN (1<<3) /* Data Terminal Ready Delta Enable. */ 117 118 #define IMX21_UCR3_RXDMUXSEL (1<<2) /* RXD Muxed Input Select */ 118 119 #define UCR3_INVT (1<<1) /* Inverted Infrared transmission */ 119 120 #define UCR3_BPEN (1<<0) /* Preset registers enable */ ··· 143 142 #define USR1_FRAMERR (1<<10) /* Frame error interrupt flag */ 144 143 #define USR1_RRDY (1<<9) /* Receiver ready interrupt/dma flag */ 145 144 #define USR1_AGTIM (1<<8) /* Ageing timer interrupt flag */ 146 - #define USR1_TIMEOUT (1<<7) /* Receive timeout interrupt status */ 145 + #define USR1_DTRD (1<<7) /* DTR Delta */ 147 146 #define USR1_RXDS (1<<6) /* Receiver idle interrupt flag */ 148 147 #define USR1_AIRINT (1<<5) /* Async IR wake interrupt flag */ 149 148 #define USR1_AWAKE (1<<4) /* Aysnc wake interrupt flag */ ··· 362 361 imx_port_rts_inactive(sport, &temp); 363 362 else 364 363 imx_port_rts_active(sport, &temp); 364 + temp |= UCR2_RXEN; 365 365 writel(temp, port->membase + UCR2); 366 366 367 367 temp = readl(port->membase + UCR4); ··· 570 568 imx_port_rts_inactive(sport, &temp); 571 569 else 572 570 imx_port_rts_active(sport, &temp); 571 + if (!(port->rs485.flags & SER_RS485_RX_DURING_TX)) 572 + temp &= ~UCR2_RXEN; 573 573 writel(temp, port->membase + UCR2); 574 574 575 575 /* enable transmitter and shifter empty irq */ ··· 733 729 spin_unlock_irqrestore(&sport->port.lock, flags); 734 730 } 735 731 732 + /* 733 + * We have a modem side uart, so the meanings of RTS and CTS are inverted. 734 + */ 735 + static unsigned int imx_get_hwmctrl(struct imx_port *sport) 736 + { 737 + unsigned int tmp = TIOCM_DSR; 738 + unsigned usr1 = readl(sport->port.membase + USR1); 739 + 740 + if (usr1 & USR1_RTSS) 741 + tmp |= TIOCM_CTS; 742 + 743 + /* in DCE mode DCDIN is always 0 */ 744 + if (!(usr1 & USR2_DCDIN)) 745 + tmp |= TIOCM_CAR; 746 + 747 + if (sport->dte_mode) 748 + if (!(readl(sport->port.membase + USR2) & USR2_RIIN)) 749 + tmp |= TIOCM_RI; 750 + 751 + return tmp; 752 + } 753 + 754 + /* 755 + * Handle any change of modem status signal since we were last called. 756 + */ 757 + static void imx_mctrl_check(struct imx_port *sport) 758 + { 759 + unsigned int status, changed; 760 + 761 + status = imx_get_hwmctrl(sport); 762 + changed = status ^ sport->old_status; 763 + 764 + if (changed == 0) 765 + return; 766 + 767 + sport->old_status = status; 768 + 769 + if (changed & TIOCM_RI && status & TIOCM_RI) 770 + sport->port.icount.rng++; 771 + if (changed & TIOCM_DSR) 772 + sport->port.icount.dsr++; 773 + if (changed & TIOCM_CAR) 774 + uart_handle_dcd_change(&sport->port, status & TIOCM_CAR); 775 + if (changed & TIOCM_CTS) 776 + uart_handle_cts_change(&sport->port, status & TIOCM_CTS); 777 + 778 + wake_up_interruptible(&sport->port.state->port.delta_msr_wait); 779 + } 780 + 736 781 static irqreturn_t imx_int(int irq, void *dev_id) 737 782 { 738 783 struct imx_port *sport = dev_id; 739 784 unsigned int sts; 740 785 unsigned int sts2; 786 + irqreturn_t ret = IRQ_NONE; 741 787 742 788 sts = readl(sport->port.membase + USR1); 743 789 sts2 = readl(sport->port.membase + USR2); ··· 797 743 imx_dma_rxint(sport); 798 744 else 799 745 imx_rxint(irq, dev_id); 746 + ret = IRQ_HANDLED; 800 747 } 801 748 802 749 if ((sts & USR1_TRDY && 803 750 readl(sport->port.membase + UCR1) & UCR1_TXMPTYEN) || 804 751 (sts2 & USR2_TXDC && 805 - readl(sport->port.membase + UCR4) & UCR4_TCEN)) 752 + readl(sport->port.membase + UCR4) & UCR4_TCEN)) { 806 753 imx_txint(irq, dev_id); 754 + ret = IRQ_HANDLED; 755 + } 807 756 808 - if (sts & USR1_RTSD) 757 + if (sts & USR1_DTRD) { 758 + unsigned long flags; 759 + 760 + if (sts & USR1_DTRD) 761 + writel(USR1_DTRD, sport->port.membase + USR1); 762 + 763 + spin_lock_irqsave(&sport->port.lock, flags); 764 + imx_mctrl_check(sport); 765 + spin_unlock_irqrestore(&sport->port.lock, flags); 766 + 767 + ret = IRQ_HANDLED; 768 + } 769 + 770 + if (sts & USR1_RTSD) { 809 771 imx_rtsint(irq, dev_id); 772 + ret = IRQ_HANDLED; 773 + } 810 774 811 - if (sts & USR1_AWAKE) 775 + if (sts & USR1_AWAKE) { 812 776 writel(USR1_AWAKE, sport->port.membase + USR1); 777 + ret = IRQ_HANDLED; 778 + } 813 779 814 780 if (sts2 & USR2_ORE) { 815 781 sport->port.icount.overrun++; 816 782 writel(USR2_ORE, sport->port.membase + USR2); 783 + ret = IRQ_HANDLED; 817 784 } 818 785 819 - return IRQ_HANDLED; 786 + return ret; 820 787 } 821 788 822 789 /* ··· 855 780 ret = 0; 856 781 857 782 return ret; 858 - } 859 - 860 - /* 861 - * We have a modem side uart, so the meanings of RTS and CTS are inverted. 862 - */ 863 - static unsigned int imx_get_hwmctrl(struct imx_port *sport) 864 - { 865 - unsigned int tmp = TIOCM_DSR; 866 - unsigned usr1 = readl(sport->port.membase + USR1); 867 - 868 - if (usr1 & USR1_RTSS) 869 - tmp |= TIOCM_CTS; 870 - 871 - /* in DCE mode DCDIN is always 0 */ 872 - if (!(usr1 & USR2_DCDIN)) 873 - tmp |= TIOCM_CAR; 874 - 875 - /* in DCE mode RIIN is always 0 */ 876 - if (readl(sport->port.membase + USR2) & USR2_RIIN) 877 - tmp |= TIOCM_RI; 878 - 879 - return tmp; 880 783 } 881 784 882 785 static unsigned int imx_get_mctrl(struct uart_port *port) ··· 911 858 writel(temp, sport->port.membase + UCR1); 912 859 913 860 spin_unlock_irqrestore(&sport->port.lock, flags); 914 - } 915 - 916 - /* 917 - * Handle any change of modem status signal since we were last called. 918 - */ 919 - static void imx_mctrl_check(struct imx_port *sport) 920 - { 921 - unsigned int status, changed; 922 - 923 - status = imx_get_hwmctrl(sport); 924 - changed = status ^ sport->old_status; 925 - 926 - if (changed == 0) 927 - return; 928 - 929 - sport->old_status = status; 930 - 931 - if (changed & TIOCM_RI) 932 - sport->port.icount.rng++; 933 - if (changed & TIOCM_DSR) 934 - sport->port.icount.dsr++; 935 - if (changed & TIOCM_CAR) 936 - uart_handle_dcd_change(&sport->port, status & TIOCM_CAR); 937 - if (changed & TIOCM_CTS) 938 - uart_handle_cts_change(&sport->port, status & TIOCM_CTS); 939 - 940 - wake_up_interruptible(&sport->port.state->port.delta_msr_wait); 941 861 } 942 862 943 863 /* ··· 1219 1193 /* 1220 1194 * Finally, clear and enable interrupts 1221 1195 */ 1222 - writel(USR1_RTSD, sport->port.membase + USR1); 1196 + writel(USR1_RTSD | USR1_DTRD, sport->port.membase + USR1); 1223 1197 writel(USR2_ORE, sport->port.membase + USR2); 1224 1198 1225 1199 if (sport->dma_is_inited && !sport->dma_is_enabled) ··· 1238 1212 temp |= (UCR2_RXEN | UCR2_TXEN); 1239 1213 if (!sport->have_rtscts) 1240 1214 temp |= UCR2_IRTS; 1215 + /* 1216 + * make sure the edge sensitive RTS-irq is disabled, 1217 + * we're using RTSD instead. 1218 + */ 1219 + if (!is_imx1_uart(sport)) 1220 + temp &= ~UCR2_RTSEN; 1241 1221 writel(temp, sport->port.membase + UCR2); 1242 1222 1243 1223 if (!is_imx1_uart(sport)) { 1244 1224 temp = readl(sport->port.membase + UCR3); 1245 - temp |= IMX21_UCR3_RXDMUXSEL | UCR3_ADNIMP; 1225 + 1226 + /* 1227 + * The effect of RI and DCD differs depending on the UFCR_DCEDTE 1228 + * bit. In DCE mode they control the outputs, in DTE mode they 1229 + * enable the respective irqs. At least the DCD irq cannot be 1230 + * cleared on i.MX25 at least, so it's not usable and must be 1231 + * disabled. I don't have test hardware to check if RI has the 1232 + * same problem but I consider this likely so it's disabled for 1233 + * now, too. 1234 + */ 1235 + temp |= IMX21_UCR3_RXDMUXSEL | UCR3_ADNIMP | 1236 + UCR3_DTRDEN | UCR3_RI | UCR3_DCD; 1237 + 1238 + if (sport->dte_mode) 1239 + temp &= ~(UCR3_RI | UCR3_DCD); 1240 + 1246 1241 writel(temp, sport->port.membase + UCR3); 1247 1242 } 1248 1243 ··· 1657 1610 struct serial_rs485 *rs485conf) 1658 1611 { 1659 1612 struct imx_port *sport = (struct imx_port *)port; 1613 + unsigned long temp; 1660 1614 1661 1615 /* unimplemented */ 1662 1616 rs485conf->delay_rts_before_send = 0; 1663 1617 rs485conf->delay_rts_after_send = 0; 1664 - rs485conf->flags |= SER_RS485_RX_DURING_TX; 1665 1618 1666 1619 /* RTS is required to control the transmitter */ 1667 1620 if (!sport->have_rtscts) 1668 1621 rs485conf->flags &= ~SER_RS485_ENABLED; 1669 1622 1670 1623 if (rs485conf->flags & SER_RS485_ENABLED) { 1671 - unsigned long temp; 1672 - 1673 1624 /* disable transmitter */ 1674 1625 temp = readl(sport->port.membase + UCR2); 1675 1626 if (rs485conf->flags & SER_RS485_RTS_AFTER_SEND) 1676 1627 imx_port_rts_inactive(sport, &temp); 1677 1628 else 1678 1629 imx_port_rts_active(sport, &temp); 1630 + writel(temp, sport->port.membase + UCR2); 1631 + } 1632 + 1633 + /* Make sure Rx is enabled in case Tx is active with Rx disabled */ 1634 + if (!(rs485conf->flags & SER_RS485_ENABLED) || 1635 + rs485conf->flags & SER_RS485_RX_DURING_TX) { 1636 + temp = readl(sport->port.membase + UCR2); 1637 + temp |= UCR2_RXEN; 1679 1638 writel(temp, sport->port.membase + UCR2); 1680 1639 } 1681 1640 ··· 1980 1927 } 1981 1928 sport->port.line = ret; 1982 1929 1983 - if (of_get_property(np, "fsl,uart-has-rtscts", NULL)) 1930 + if (of_get_property(np, "uart-has-rtscts", NULL) || 1931 + of_get_property(np, "fsl,uart-has-rtscts", NULL) /* deprecated */) 1984 1932 sport->have_rtscts = 1; 1985 1933 1986 1934 if (of_get_property(np, "fsl,dte-mode", NULL))
+35 -7
drivers/tty/serial/meson_uart.c
··· 481 481 writel(ch, port->membase + AML_UART_WFIFO); 482 482 } 483 483 484 - static void meson_serial_console_write(struct console *co, const char *s, 485 - u_int count) 484 + static void meson_serial_port_write(struct uart_port *port, const char *s, 485 + u_int count) 486 486 { 487 - struct uart_port *port; 488 487 unsigned long flags; 489 488 int locked; 490 489 u32 val, tmp; 491 - 492 - port = meson_ports[co->index]; 493 - if (!port) 494 - return; 495 490 496 491 local_irq_save(flags); 497 492 if (port->sysrq) { ··· 509 514 if (locked) 510 515 spin_unlock(&port->lock); 511 516 local_irq_restore(flags); 517 + } 518 + 519 + static void meson_serial_console_write(struct console *co, const char *s, 520 + u_int count) 521 + { 522 + struct uart_port *port; 523 + 524 + port = meson_ports[co->index]; 525 + if (!port) 526 + return; 527 + 528 + meson_serial_port_write(port, s, count); 512 529 } 513 530 514 531 static int meson_serial_console_setup(struct console *co, char *options) ··· 560 553 return 0; 561 554 } 562 555 console_initcall(meson_serial_console_init); 556 + 557 + static void meson_serial_early_console_write(struct console *co, 558 + const char *s, 559 + u_int count) 560 + { 561 + struct earlycon_device *dev = co->data; 562 + 563 + meson_serial_port_write(&dev->port, s, count); 564 + } 565 + 566 + static int __init 567 + meson_serial_early_console_setup(struct earlycon_device *device, const char *opt) 568 + { 569 + if (!device->port.membase) 570 + return -ENODEV; 571 + 572 + device->con->write = meson_serial_early_console_write; 573 + return 0; 574 + } 575 + OF_EARLYCON_DECLARE(meson, "amlogic,meson-uart", 576 + meson_serial_early_console_setup); 563 577 564 578 #define MESON_SERIAL_CONSOLE (&meson_serial_console) 565 579 #else
+625
drivers/tty/serial/mps2-uart.c
··· 1 + /* 2 + * Copyright (C) 2015 ARM Limited 3 + * 4 + * Author: Vladimir Murzin <vladimir.murzin@arm.com> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + * 10 + * TODO: support for SysRq 11 + */ 12 + 13 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14 + 15 + #include <linux/bitops.h> 16 + #include <linux/clk.h> 17 + #include <linux/console.h> 18 + #include <linux/io.h> 19 + #include <linux/kernel.h> 20 + #include <linux/module.h> 21 + #include <linux/of_device.h> 22 + #include <linux/of.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/serial_core.h> 25 + #include <linux/tty_flip.h> 26 + #include <linux/types.h> 27 + 28 + #define SERIAL_NAME "ttyMPS" 29 + #define DRIVER_NAME "mps2-uart" 30 + #define MAKE_NAME(x) (DRIVER_NAME # x) 31 + 32 + #define UARTn_DATA 0x00 33 + 34 + #define UARTn_STATE 0x04 35 + #define UARTn_STATE_TX_FULL BIT(0) 36 + #define UARTn_STATE_RX_FULL BIT(1) 37 + #define UARTn_STATE_TX_OVERRUN BIT(2) 38 + #define UARTn_STATE_RX_OVERRUN BIT(3) 39 + 40 + #define UARTn_CTRL 0x08 41 + #define UARTn_CTRL_TX_ENABLE BIT(0) 42 + #define UARTn_CTRL_RX_ENABLE BIT(1) 43 + #define UARTn_CTRL_TX_INT_ENABLE BIT(2) 44 + #define UARTn_CTRL_RX_INT_ENABLE BIT(3) 45 + #define UARTn_CTRL_TX_OVERRUN_INT_ENABLE BIT(4) 46 + #define UARTn_CTRL_RX_OVERRUN_INT_ENABLE BIT(5) 47 + 48 + #define UARTn_INT 0x0c 49 + #define UARTn_INT_TX BIT(0) 50 + #define UARTn_INT_RX BIT(1) 51 + #define UARTn_INT_TX_OVERRUN BIT(2) 52 + #define UARTn_INT_RX_OVERRUN BIT(3) 53 + 54 + #define UARTn_BAUDDIV 0x10 55 + #define UARTn_BAUDDIV_MASK GENMASK(20, 0) 56 + 57 + /* 58 + * Helpers to make typical enable/disable operations more readable. 59 + */ 60 + #define UARTn_CTRL_TX_GRP (UARTn_CTRL_TX_ENABLE |\ 61 + UARTn_CTRL_TX_INT_ENABLE |\ 62 + UARTn_CTRL_TX_OVERRUN_INT_ENABLE) 63 + 64 + #define UARTn_CTRL_RX_GRP (UARTn_CTRL_RX_ENABLE |\ 65 + UARTn_CTRL_RX_INT_ENABLE |\ 66 + UARTn_CTRL_RX_OVERRUN_INT_ENABLE) 67 + 68 + #define MPS2_MAX_PORTS 3 69 + 70 + struct mps2_uart_port { 71 + struct uart_port port; 72 + struct clk *clk; 73 + unsigned int tx_irq; 74 + unsigned int rx_irq; 75 + }; 76 + 77 + static inline struct mps2_uart_port *to_mps2_port(struct uart_port *port) 78 + { 79 + return container_of(port, struct mps2_uart_port, port); 80 + } 81 + 82 + static void mps2_uart_write8(struct uart_port *port, u8 val, unsigned int off) 83 + { 84 + struct mps2_uart_port *mps_port = to_mps2_port(port); 85 + 86 + writeb(val, mps_port->port.membase + off); 87 + } 88 + 89 + static u8 mps2_uart_read8(struct uart_port *port, unsigned int off) 90 + { 91 + struct mps2_uart_port *mps_port = to_mps2_port(port); 92 + 93 + return readb(mps_port->port.membase + off); 94 + } 95 + 96 + static void mps2_uart_write32(struct uart_port *port, u32 val, unsigned int off) 97 + { 98 + struct mps2_uart_port *mps_port = to_mps2_port(port); 99 + 100 + writel_relaxed(val, mps_port->port.membase + off); 101 + } 102 + 103 + static unsigned int mps2_uart_tx_empty(struct uart_port *port) 104 + { 105 + u8 status = mps2_uart_read8(port, UARTn_STATE); 106 + 107 + return (status & UARTn_STATE_TX_FULL) ? 0 : TIOCSER_TEMT; 108 + } 109 + 110 + static void mps2_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) 111 + { 112 + } 113 + 114 + static unsigned int mps2_uart_get_mctrl(struct uart_port *port) 115 + { 116 + return TIOCM_CAR | TIOCM_CTS | TIOCM_DSR; 117 + } 118 + 119 + static void mps2_uart_stop_tx(struct uart_port *port) 120 + { 121 + u8 control = mps2_uart_read8(port, UARTn_CTRL); 122 + 123 + control &= ~UARTn_CTRL_TX_INT_ENABLE; 124 + 125 + mps2_uart_write8(port, control, UARTn_CTRL); 126 + } 127 + 128 + static void mps2_uart_tx_chars(struct uart_port *port) 129 + { 130 + struct circ_buf *xmit = &port->state->xmit; 131 + 132 + while (!(mps2_uart_read8(port, UARTn_STATE) & UARTn_STATE_TX_FULL)) { 133 + if (port->x_char) { 134 + mps2_uart_write8(port, port->x_char, UARTn_DATA); 135 + port->x_char = 0; 136 + port->icount.tx++; 137 + continue; 138 + } 139 + 140 + if (uart_circ_empty(xmit) || uart_tx_stopped(port)) 141 + break; 142 + 143 + mps2_uart_write8(port, xmit->buf[xmit->tail], UARTn_DATA); 144 + xmit->tail = (xmit->tail + 1) % UART_XMIT_SIZE; 145 + port->icount.tx++; 146 + } 147 + 148 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 149 + uart_write_wakeup(port); 150 + 151 + if (uart_circ_empty(xmit)) 152 + mps2_uart_stop_tx(port); 153 + } 154 + 155 + static void mps2_uart_start_tx(struct uart_port *port) 156 + { 157 + u8 control = mps2_uart_read8(port, UARTn_CTRL); 158 + 159 + control |= UARTn_CTRL_TX_INT_ENABLE; 160 + 161 + mps2_uart_write8(port, control, UARTn_CTRL); 162 + 163 + /* 164 + * We've just unmasked the TX IRQ and now slow-starting via 165 + * polling; if there is enough data to fill up the internal 166 + * write buffer in one go, the TX IRQ should assert, at which 167 + * point we switch to fully interrupt-driven TX. 168 + */ 169 + 170 + mps2_uart_tx_chars(port); 171 + } 172 + 173 + static void mps2_uart_stop_rx(struct uart_port *port) 174 + { 175 + u8 control = mps2_uart_read8(port, UARTn_CTRL); 176 + 177 + control &= ~UARTn_CTRL_RX_GRP; 178 + 179 + mps2_uart_write8(port, control, UARTn_CTRL); 180 + } 181 + 182 + static void mps2_uart_break_ctl(struct uart_port *port, int ctl) 183 + { 184 + } 185 + 186 + static void mps2_uart_rx_chars(struct uart_port *port) 187 + { 188 + struct tty_port *tport = &port->state->port; 189 + 190 + while (mps2_uart_read8(port, UARTn_STATE) & UARTn_STATE_RX_FULL) { 191 + u8 rxdata = mps2_uart_read8(port, UARTn_DATA); 192 + 193 + port->icount.rx++; 194 + tty_insert_flip_char(&port->state->port, rxdata, TTY_NORMAL); 195 + } 196 + 197 + tty_flip_buffer_push(tport); 198 + } 199 + 200 + static irqreturn_t mps2_uart_rxirq(int irq, void *data) 201 + { 202 + struct uart_port *port = data; 203 + u8 irqflag = mps2_uart_read8(port, UARTn_INT); 204 + 205 + if (unlikely(!(irqflag & UARTn_INT_RX))) 206 + return IRQ_NONE; 207 + 208 + spin_lock(&port->lock); 209 + 210 + mps2_uart_write8(port, UARTn_INT_RX, UARTn_INT); 211 + mps2_uart_rx_chars(port); 212 + 213 + spin_unlock(&port->lock); 214 + 215 + return IRQ_HANDLED; 216 + } 217 + 218 + static irqreturn_t mps2_uart_txirq(int irq, void *data) 219 + { 220 + struct uart_port *port = data; 221 + u8 irqflag = mps2_uart_read8(port, UARTn_INT); 222 + 223 + if (unlikely(!(irqflag & UARTn_INT_TX))) 224 + return IRQ_NONE; 225 + 226 + spin_lock(&port->lock); 227 + 228 + mps2_uart_write8(port, UARTn_INT_TX, UARTn_INT); 229 + mps2_uart_tx_chars(port); 230 + 231 + spin_unlock(&port->lock); 232 + 233 + return IRQ_HANDLED; 234 + } 235 + 236 + static irqreturn_t mps2_uart_oerrirq(int irq, void *data) 237 + { 238 + irqreturn_t handled = IRQ_NONE; 239 + struct uart_port *port = data; 240 + u8 irqflag = mps2_uart_read8(port, UARTn_INT); 241 + 242 + spin_lock(&port->lock); 243 + 244 + if (irqflag & UARTn_INT_RX_OVERRUN) { 245 + struct tty_port *tport = &port->state->port; 246 + 247 + mps2_uart_write8(port, UARTn_INT_RX_OVERRUN, UARTn_INT); 248 + port->icount.overrun++; 249 + tty_insert_flip_char(tport, 0, TTY_OVERRUN); 250 + tty_flip_buffer_push(tport); 251 + handled = IRQ_HANDLED; 252 + } 253 + 254 + /* 255 + * It's never been seen in practice and it never *should* happen since 256 + * we check if there is enough room in TX buffer before sending data. 257 + * So we keep this check in case something suspicious has happened. 258 + */ 259 + if (irqflag & UARTn_INT_TX_OVERRUN) { 260 + mps2_uart_write8(port, UARTn_INT_TX_OVERRUN, UARTn_INT); 261 + handled = IRQ_HANDLED; 262 + } 263 + 264 + spin_unlock(&port->lock); 265 + 266 + return handled; 267 + } 268 + 269 + static int mps2_uart_startup(struct uart_port *port) 270 + { 271 + struct mps2_uart_port *mps_port = to_mps2_port(port); 272 + u8 control = mps2_uart_read8(port, UARTn_CTRL); 273 + int ret; 274 + 275 + control &= ~(UARTn_CTRL_RX_GRP | UARTn_CTRL_TX_GRP); 276 + 277 + mps2_uart_write8(port, control, UARTn_CTRL); 278 + 279 + ret = request_irq(mps_port->rx_irq, mps2_uart_rxirq, 0, 280 + MAKE_NAME(-rx), mps_port); 281 + if (ret) { 282 + dev_err(port->dev, "failed to register rxirq (%d)\n", ret); 283 + return ret; 284 + } 285 + 286 + ret = request_irq(mps_port->tx_irq, mps2_uart_txirq, 0, 287 + MAKE_NAME(-tx), mps_port); 288 + if (ret) { 289 + dev_err(port->dev, "failed to register txirq (%d)\n", ret); 290 + goto err_free_rxirq; 291 + } 292 + 293 + ret = request_irq(port->irq, mps2_uart_oerrirq, IRQF_SHARED, 294 + MAKE_NAME(-overrun), mps_port); 295 + 296 + if (ret) { 297 + dev_err(port->dev, "failed to register oerrirq (%d)\n", ret); 298 + goto err_free_txirq; 299 + } 300 + 301 + control |= UARTn_CTRL_RX_GRP | UARTn_CTRL_TX_GRP; 302 + 303 + mps2_uart_write8(port, control, UARTn_CTRL); 304 + 305 + return 0; 306 + 307 + err_free_txirq: 308 + free_irq(mps_port->tx_irq, mps_port); 309 + err_free_rxirq: 310 + free_irq(mps_port->rx_irq, mps_port); 311 + 312 + return ret; 313 + } 314 + 315 + static void mps2_uart_shutdown(struct uart_port *port) 316 + { 317 + struct mps2_uart_port *mps_port = to_mps2_port(port); 318 + u8 control = mps2_uart_read8(port, UARTn_CTRL); 319 + 320 + control &= ~(UARTn_CTRL_RX_GRP | UARTn_CTRL_TX_GRP); 321 + 322 + mps2_uart_write8(port, control, UARTn_CTRL); 323 + 324 + free_irq(mps_port->rx_irq, mps_port); 325 + free_irq(mps_port->tx_irq, mps_port); 326 + free_irq(port->irq, mps_port); 327 + } 328 + 329 + static void 330 + mps2_uart_set_termios(struct uart_port *port, struct ktermios *termios, 331 + struct ktermios *old) 332 + { 333 + unsigned long flags; 334 + unsigned int baud, bauddiv; 335 + 336 + termios->c_cflag &= ~(CRTSCTS | CMSPAR); 337 + termios->c_cflag &= ~CSIZE; 338 + termios->c_cflag |= CS8; 339 + termios->c_cflag &= ~PARENB; 340 + termios->c_cflag &= ~CSTOPB; 341 + 342 + baud = uart_get_baud_rate(port, termios, old, 343 + DIV_ROUND_CLOSEST(port->uartclk, UARTn_BAUDDIV_MASK), 344 + DIV_ROUND_CLOSEST(port->uartclk, 16)); 345 + 346 + bauddiv = DIV_ROUND_CLOSEST(port->uartclk, baud); 347 + 348 + spin_lock_irqsave(&port->lock, flags); 349 + 350 + uart_update_timeout(port, termios->c_cflag, baud); 351 + mps2_uart_write32(port, bauddiv, UARTn_BAUDDIV); 352 + 353 + spin_unlock_irqrestore(&port->lock, flags); 354 + 355 + if (tty_termios_baud_rate(termios)) 356 + tty_termios_encode_baud_rate(termios, baud, baud); 357 + } 358 + 359 + static const char *mps2_uart_type(struct uart_port *port) 360 + { 361 + return (port->type == PORT_MPS2UART) ? DRIVER_NAME : NULL; 362 + } 363 + 364 + static void mps2_uart_release_port(struct uart_port *port) 365 + { 366 + } 367 + 368 + static int mps2_uart_request_port(struct uart_port *port) 369 + { 370 + return 0; 371 + } 372 + 373 + static void mps2_uart_config_port(struct uart_port *port, int type) 374 + { 375 + if (type & UART_CONFIG_TYPE && !mps2_uart_request_port(port)) 376 + port->type = PORT_MPS2UART; 377 + } 378 + 379 + static int mps2_uart_verify_port(struct uart_port *port, struct serial_struct *serinfo) 380 + { 381 + return -EINVAL; 382 + } 383 + 384 + static const struct uart_ops mps2_uart_pops = { 385 + .tx_empty = mps2_uart_tx_empty, 386 + .set_mctrl = mps2_uart_set_mctrl, 387 + .get_mctrl = mps2_uart_get_mctrl, 388 + .stop_tx = mps2_uart_stop_tx, 389 + .start_tx = mps2_uart_start_tx, 390 + .stop_rx = mps2_uart_stop_rx, 391 + .break_ctl = mps2_uart_break_ctl, 392 + .startup = mps2_uart_startup, 393 + .shutdown = mps2_uart_shutdown, 394 + .set_termios = mps2_uart_set_termios, 395 + .type = mps2_uart_type, 396 + .release_port = mps2_uart_release_port, 397 + .request_port = mps2_uart_request_port, 398 + .config_port = mps2_uart_config_port, 399 + .verify_port = mps2_uart_verify_port, 400 + }; 401 + 402 + static struct mps2_uart_port mps2_uart_ports[MPS2_MAX_PORTS]; 403 + 404 + #ifdef CONFIG_SERIAL_MPS2_UART_CONSOLE 405 + static void mps2_uart_console_putchar(struct uart_port *port, int ch) 406 + { 407 + while (mps2_uart_read8(port, UARTn_STATE) & UARTn_STATE_TX_FULL) 408 + cpu_relax(); 409 + 410 + mps2_uart_write8(port, ch, UARTn_DATA); 411 + } 412 + 413 + static void mps2_uart_console_write(struct console *co, const char *s, unsigned int cnt) 414 + { 415 + struct uart_port *port = &mps2_uart_ports[co->index].port; 416 + 417 + uart_console_write(port, s, cnt, mps2_uart_console_putchar); 418 + } 419 + 420 + static int mps2_uart_console_setup(struct console *co, char *options) 421 + { 422 + struct mps2_uart_port *mps_port; 423 + int baud = 9600; 424 + int bits = 8; 425 + int parity = 'n'; 426 + int flow = 'n'; 427 + 428 + if (co->index < 0 || co->index >= MPS2_MAX_PORTS) 429 + return -ENODEV; 430 + 431 + mps_port = &mps2_uart_ports[co->index]; 432 + 433 + if (options) 434 + uart_parse_options(options, &baud, &parity, &bits, &flow); 435 + 436 + return uart_set_options(&mps_port->port, co, baud, parity, bits, flow); 437 + } 438 + 439 + static struct uart_driver mps2_uart_driver; 440 + 441 + static struct console mps2_uart_console = { 442 + .name = SERIAL_NAME, 443 + .device = uart_console_device, 444 + .write = mps2_uart_console_write, 445 + .setup = mps2_uart_console_setup, 446 + .flags = CON_PRINTBUFFER, 447 + .index = -1, 448 + .data = &mps2_uart_driver, 449 + }; 450 + 451 + #define MPS2_SERIAL_CONSOLE (&mps2_uart_console) 452 + 453 + static void mps2_early_putchar(struct uart_port *port, int ch) 454 + { 455 + while (readb(port->membase + UARTn_STATE) & UARTn_STATE_TX_FULL) 456 + cpu_relax(); 457 + 458 + writeb((unsigned char)ch, port->membase + UARTn_DATA); 459 + } 460 + 461 + static void mps2_early_write(struct console *con, const char *s, unsigned int n) 462 + { 463 + struct earlycon_device *dev = con->data; 464 + 465 + uart_console_write(&dev->port, s, n, mps2_early_putchar); 466 + } 467 + 468 + static int __init mps2_early_console_setup(struct earlycon_device *device, 469 + const char *opt) 470 + { 471 + if (!device->port.membase) 472 + return -ENODEV; 473 + 474 + device->con->write = mps2_early_write; 475 + 476 + return 0; 477 + } 478 + 479 + OF_EARLYCON_DECLARE(mps2, "arm,mps2-uart", mps2_early_console_setup); 480 + 481 + #else 482 + #define MPS2_SERIAL_CONSOLE NULL 483 + #endif 484 + 485 + static struct uart_driver mps2_uart_driver = { 486 + .driver_name = DRIVER_NAME, 487 + .dev_name = SERIAL_NAME, 488 + .nr = MPS2_MAX_PORTS, 489 + .cons = MPS2_SERIAL_CONSOLE, 490 + }; 491 + 492 + static struct mps2_uart_port *mps2_of_get_port(struct platform_device *pdev) 493 + { 494 + struct device_node *np = pdev->dev.of_node; 495 + int id; 496 + 497 + if (!np) 498 + return NULL; 499 + 500 + id = of_alias_get_id(np, "serial"); 501 + if (id < 0) 502 + id = 0; 503 + 504 + if (WARN_ON(id >= MPS2_MAX_PORTS)) 505 + return NULL; 506 + 507 + mps2_uart_ports[id].port.line = id; 508 + return &mps2_uart_ports[id]; 509 + } 510 + 511 + static int mps2_init_port(struct mps2_uart_port *mps_port, 512 + struct platform_device *pdev) 513 + { 514 + struct resource *res; 515 + int ret; 516 + 517 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 518 + mps_port->port.membase = devm_ioremap_resource(&pdev->dev, res); 519 + if (IS_ERR(mps_port->port.membase)) 520 + return PTR_ERR(mps_port->port.membase); 521 + 522 + mps_port->port.mapbase = res->start; 523 + mps_port->port.mapsize = resource_size(res); 524 + 525 + mps_port->rx_irq = platform_get_irq(pdev, 0); 526 + mps_port->tx_irq = platform_get_irq(pdev, 1); 527 + mps_port->port.irq = platform_get_irq(pdev, 2); 528 + 529 + mps_port->port.iotype = UPIO_MEM; 530 + mps_port->port.flags = UPF_BOOT_AUTOCONF; 531 + mps_port->port.fifosize = 1; 532 + mps_port->port.ops = &mps2_uart_pops; 533 + mps_port->port.dev = &pdev->dev; 534 + 535 + mps_port->clk = devm_clk_get(&pdev->dev, NULL); 536 + if (IS_ERR(mps_port->clk)) 537 + return PTR_ERR(mps_port->clk); 538 + 539 + ret = clk_prepare_enable(mps_port->clk); 540 + if (ret) 541 + return ret; 542 + 543 + mps_port->port.uartclk = clk_get_rate(mps_port->clk); 544 + 545 + clk_disable_unprepare(mps_port->clk); 546 + 547 + return ret; 548 + } 549 + 550 + static int mps2_serial_probe(struct platform_device *pdev) 551 + { 552 + struct mps2_uart_port *mps_port; 553 + int ret; 554 + 555 + mps_port = mps2_of_get_port(pdev); 556 + if (!mps_port) 557 + return -ENODEV; 558 + 559 + ret = mps2_init_port(mps_port, pdev); 560 + if (ret) 561 + return ret; 562 + 563 + ret = uart_add_one_port(&mps2_uart_driver, &mps_port->port); 564 + if (ret) 565 + return ret; 566 + 567 + platform_set_drvdata(pdev, mps_port); 568 + 569 + return 0; 570 + } 571 + 572 + static int mps2_serial_remove(struct platform_device *pdev) 573 + { 574 + struct mps2_uart_port *mps_port = platform_get_drvdata(pdev); 575 + 576 + uart_remove_one_port(&mps2_uart_driver, &mps_port->port); 577 + 578 + return 0; 579 + } 580 + 581 + #ifdef CONFIG_OF 582 + static const struct of_device_id mps2_match[] = { 583 + { .compatible = "arm,mps2-uart", }, 584 + {}, 585 + }; 586 + MODULE_DEVICE_TABLE(of, mps2_match); 587 + #endif 588 + 589 + static struct platform_driver mps2_serial_driver = { 590 + .probe = mps2_serial_probe, 591 + .remove = mps2_serial_remove, 592 + 593 + .driver = { 594 + .name = DRIVER_NAME, 595 + .of_match_table = of_match_ptr(mps2_match), 596 + }, 597 + }; 598 + 599 + static int __init mps2_uart_init(void) 600 + { 601 + int ret; 602 + 603 + ret = uart_register_driver(&mps2_uart_driver); 604 + if (ret) 605 + return ret; 606 + 607 + ret = platform_driver_register(&mps2_serial_driver); 608 + if (ret) 609 + uart_unregister_driver(&mps2_uart_driver); 610 + 611 + return ret; 612 + } 613 + module_init(mps2_uart_init); 614 + 615 + static void __exit mps2_uart_exit(void) 616 + { 617 + platform_driver_unregister(&mps2_serial_driver); 618 + uart_unregister_driver(&mps2_uart_driver); 619 + } 620 + module_exit(mps2_uart_exit); 621 + 622 + MODULE_AUTHOR("Vladimir Murzin <vladimir.murzin@arm.com>"); 623 + MODULE_DESCRIPTION("MPS2 UART driver"); 624 + MODULE_LICENSE("GPL v2"); 625 + MODULE_ALIAS("platform:" DRIVER_NAME);
+66 -35
drivers/tty/serial/msm_serial.c
··· 861 861 }; 862 862 863 863 static const struct msm_baud_map * 864 - msm_find_best_baud(struct uart_port *port, unsigned int baud) 864 + msm_find_best_baud(struct uart_port *port, unsigned int baud, 865 + unsigned long *rate) 865 866 { 866 - unsigned int i, divisor; 867 - const struct msm_baud_map *entry; 867 + struct msm_port *msm_port = UART_TO_MSM(port); 868 + unsigned int divisor, result; 869 + unsigned long target, old, best_rate = 0, diff, best_diff = ULONG_MAX; 870 + const struct msm_baud_map *entry, *end, *best; 868 871 static const struct msm_baud_map table[] = { 869 - { 1536, 0x00, 1 }, 870 - { 768, 0x11, 1 }, 871 - { 384, 0x22, 1 }, 872 - { 192, 0x33, 1 }, 873 - { 96, 0x44, 1 }, 874 - { 48, 0x55, 1 }, 875 - { 32, 0x66, 1 }, 876 - { 24, 0x77, 1 }, 877 - { 16, 0x88, 1 }, 878 - { 12, 0x99, 6 }, 879 - { 8, 0xaa, 6 }, 880 - { 6, 0xbb, 6 }, 881 - { 4, 0xcc, 6 }, 882 - { 3, 0xdd, 8 }, 883 - { 2, 0xee, 16 }, 884 872 { 1, 0xff, 31 }, 885 - { 0, 0xff, 31 }, 873 + { 2, 0xee, 16 }, 874 + { 3, 0xdd, 8 }, 875 + { 4, 0xcc, 6 }, 876 + { 6, 0xbb, 6 }, 877 + { 8, 0xaa, 6 }, 878 + { 12, 0x99, 6 }, 879 + { 16, 0x88, 1 }, 880 + { 24, 0x77, 1 }, 881 + { 32, 0x66, 1 }, 882 + { 48, 0x55, 1 }, 883 + { 96, 0x44, 1 }, 884 + { 192, 0x33, 1 }, 885 + { 384, 0x22, 1 }, 886 + { 768, 0x11, 1 }, 887 + { 1536, 0x00, 1 }, 886 888 }; 887 889 888 - divisor = uart_get_divisor(port, baud); 890 + best = table; /* Default to smallest divider */ 891 + target = clk_round_rate(msm_port->clk, 16 * baud); 892 + divisor = DIV_ROUND_CLOSEST(target, 16 * baud); 889 893 890 - for (i = 0, entry = table; i < ARRAY_SIZE(table); i++, entry++) 891 - if (entry->divisor <= divisor) 892 - break; 894 + end = table + ARRAY_SIZE(table); 895 + entry = table; 896 + while (entry < end) { 897 + if (entry->divisor <= divisor) { 898 + result = target / entry->divisor / 16; 899 + diff = abs(result - baud); 893 900 894 - return entry; /* Default to smallest divider */ 901 + /* Keep track of best entry */ 902 + if (diff < best_diff) { 903 + best_diff = diff; 904 + best = entry; 905 + best_rate = target; 906 + } 907 + 908 + if (result == baud) 909 + break; 910 + } else if (entry->divisor > divisor) { 911 + old = target; 912 + target = clk_round_rate(msm_port->clk, old + 1); 913 + /* 914 + * The rate didn't get any faster so we can't do 915 + * better at dividing it down 916 + */ 917 + if (target == old) 918 + break; 919 + 920 + /* Start the divisor search over at this new rate */ 921 + entry = table; 922 + divisor = DIV_ROUND_CLOSEST(target, 16 * baud); 923 + continue; 924 + } 925 + entry++; 926 + } 927 + 928 + *rate = best_rate; 929 + return best; 895 930 } 896 931 897 932 static int msm_set_baud_rate(struct uart_port *port, unsigned int baud, ··· 935 900 unsigned int rxstale, watermark, mask; 936 901 struct msm_port *msm_port = UART_TO_MSM(port); 937 902 const struct msm_baud_map *entry; 938 - unsigned long flags; 939 - 940 - entry = msm_find_best_baud(port, baud); 941 - 942 - msm_write(port, entry->code, UART_CSR); 943 - 944 - if (baud > 460800) 945 - port->uartclk = baud * 16; 903 + unsigned long flags, rate; 946 904 947 905 flags = *saved_flags; 948 906 spin_unlock_irqrestore(&port->lock, flags); 949 907 950 - clk_set_rate(msm_port->clk, port->uartclk); 908 + entry = msm_find_best_baud(port, baud, &rate); 909 + clk_set_rate(msm_port->clk, rate); 910 + baud = rate / 16 / entry->divisor; 951 911 952 912 spin_lock_irqsave(&port->lock, flags); 953 913 *saved_flags = flags; 914 + port->uartclk = rate; 915 + 916 + msm_write(port, entry->code, UART_CSR); 954 917 955 918 /* RX stale watermark */ 956 919 rxstale = entry->rxstale; ··· 1610 1577 msm_port->pclk = devm_clk_get(&pdev->dev, "iface"); 1611 1578 if (IS_ERR(msm_port->pclk)) 1612 1579 return PTR_ERR(msm_port->pclk); 1613 - 1614 - clk_set_rate(msm_port->clk, 1843200); 1615 1580 } 1616 1581 1617 1582 port->uartclk = clk_get_rate(msm_port->clk);
+3 -26
drivers/tty/serial/mvebu-uart.c
··· 1 1 /* 2 2 * *************************************************************************** 3 + * Marvell Armada-3700 Serial Driver 4 + * Author: Wilson Ding <dingwei@marvell.com> 3 5 * Copyright (C) 2015 Marvell International Ltd. 4 6 * *************************************************************************** 5 7 * This program is free software: you can redistribute it and/or modify it ··· 25 23 #include <linux/init.h> 26 24 #include <linux/io.h> 27 25 #include <linux/iopoll.h> 28 - #include <linux/module.h> 29 26 #include <linux/of.h> 30 27 #include <linux/of_address.h> 31 28 #include <linux/of_device.h> ··· 595 594 return 0; 596 595 } 597 596 598 - static int mvebu_uart_remove(struct platform_device *pdev) 599 - { 600 - struct mvebu_uart_data *data = platform_get_drvdata(pdev); 601 - 602 - uart_remove_one_port(&mvebu_uart_driver, data->port); 603 - data->port->private_data = NULL; 604 - data->port->mapbase = 0; 605 - return 0; 606 - } 607 - 608 597 /* Match table for of_platform binding */ 609 598 static const struct of_device_id mvebu_uart_of_match[] = { 610 599 { .compatible = "marvell,armada-3700-uart", }, 611 600 {} 612 601 }; 613 - MODULE_DEVICE_TABLE(of, mvebu_uart_of_match); 614 602 615 603 static struct platform_driver mvebu_uart_platform_driver = { 616 604 .probe = mvebu_uart_probe, 617 - .remove = mvebu_uart_remove, 618 605 .driver = { 619 - .owner = THIS_MODULE, 620 606 .name = "mvebu-uart", 621 607 .of_match_table = of_match_ptr(mvebu_uart_of_match), 608 + .suppress_bind_attrs = true, 622 609 }, 623 610 }; 624 611 ··· 624 635 625 636 return ret; 626 637 } 627 - 628 - static void __exit mvebu_uart_exit(void) 629 - { 630 - platform_driver_unregister(&mvebu_uart_platform_driver); 631 - uart_unregister_driver(&mvebu_uart_driver); 632 - } 633 - 634 638 arch_initcall(mvebu_uart_init); 635 - module_exit(mvebu_uart_exit); 636 - 637 - MODULE_AUTHOR("Wilson Ding <dingwei@marvell.com>"); 638 - MODULE_DESCRIPTION("Marvell Armada-3700 Serial Driver"); 639 - MODULE_LICENSE("GPL");
+519 -125
drivers/tty/serial/mxs-auart.c
··· 1 1 /* 2 - * Freescale STMP37XX/STMP378X Application UART driver 2 + * Application UART driver for: 3 + * Freescale STMP37XX/STMP378X 4 + * Alphascale ASM9260 3 5 * 4 6 * Author: dmitry pervushin <dimka@embeddedalley.com> 5 7 * 8 + * Copyright 2014 Oleksij Rempel <linux@rempel-privat.de> 9 + * Provide Alphascale ASM9260 support. 6 10 * Copyright 2008-2010 Freescale Semiconductor, Inc. 7 11 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved. 8 12 * 9 13 * The code contained herein is licensed under the GNU General Public 10 14 * License. You may obtain a copy of the GNU General Public License 11 15 * Version 2 or later at the following locations: 12 - * 13 - * http://www.opensource.org/licenses/gpl-license.html 14 - * http://www.gnu.org/copyleft/gpl.html 15 16 */ 16 17 17 18 #if defined(CONFIG_SERIAL_MXS_AUART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) ··· 52 51 #define MXS_AUART_PORTS 5 53 52 #define MXS_AUART_FIFO_SIZE 16 54 53 54 + #define SET_REG 0x4 55 + #define CLR_REG 0x8 56 + #define TOG_REG 0xc 57 + 55 58 #define AUART_CTRL0 0x00000000 56 - #define AUART_CTRL0_SET 0x00000004 57 - #define AUART_CTRL0_CLR 0x00000008 58 - #define AUART_CTRL0_TOG 0x0000000c 59 59 #define AUART_CTRL1 0x00000010 60 - #define AUART_CTRL1_SET 0x00000014 61 - #define AUART_CTRL1_CLR 0x00000018 62 - #define AUART_CTRL1_TOG 0x0000001c 63 60 #define AUART_CTRL2 0x00000020 64 - #define AUART_CTRL2_SET 0x00000024 65 - #define AUART_CTRL2_CLR 0x00000028 66 - #define AUART_CTRL2_TOG 0x0000002c 67 61 #define AUART_LINECTRL 0x00000030 68 - #define AUART_LINECTRL_SET 0x00000034 69 - #define AUART_LINECTRL_CLR 0x00000038 70 - #define AUART_LINECTRL_TOG 0x0000003c 71 62 #define AUART_LINECTRL2 0x00000040 72 - #define AUART_LINECTRL2_SET 0x00000044 73 - #define AUART_LINECTRL2_CLR 0x00000048 74 - #define AUART_LINECTRL2_TOG 0x0000004c 75 63 #define AUART_INTR 0x00000050 76 - #define AUART_INTR_SET 0x00000054 77 - #define AUART_INTR_CLR 0x00000058 78 - #define AUART_INTR_TOG 0x0000005c 79 64 #define AUART_DATA 0x00000060 80 65 #define AUART_STAT 0x00000070 81 66 #define AUART_DEBUG 0x00000080 ··· 123 136 #define AUART_STAT_FERR (1 << 16) 124 137 #define AUART_STAT_RXCOUNT_MASK 0xffff 125 138 139 + /* 140 + * Start of Alphascale asm9260 defines 141 + * This list contains only differences of existing bits 142 + * between imx2x and asm9260 143 + */ 144 + #define ASM9260_HW_CTRL0 0x0000 145 + /* 146 + * RW. Tell the UART to execute the RX DMA Command. The 147 + * UART will clear this bit at the end of receive execution. 148 + */ 149 + #define ASM9260_BM_CTRL0_RXDMA_RUN BIT(28) 150 + /* RW. 0 use FIFO for status register; 1 use DMA */ 151 + #define ASM9260_BM_CTRL0_RXTO_SOURCE_STATUS BIT(25) 152 + /* 153 + * RW. RX TIMEOUT Enable. Valid for FIFO and DMA. 154 + * Warning: If this bit is set to 0, the RX timeout will not affect receive DMA 155 + * operation. If this bit is set to 1, a receive timeout will cause the receive 156 + * DMA logic to terminate by filling the remaining DMA bytes with garbage data. 157 + */ 158 + #define ASM9260_BM_CTRL0_RXTO_ENABLE BIT(24) 159 + /* 160 + * RW. Receive Timeout Counter Value: number of 8-bit-time to wait before 161 + * asserting timeout on the RX input. If the RXFIFO is not empty and the RX 162 + * input is idle, then the watchdog counter will decrement each bit-time. Note 163 + * 7-bit-time is added to the programmed value, so a value of zero will set 164 + * the counter to 7-bit-time, a value of 0x1 gives 15-bit-time and so on. Also 165 + * note that the counter is reloaded at the end of each frame, so if the frame 166 + * is 10 bits long and the timeout counter value is zero, then timeout will 167 + * occur (when FIFO is not empty) even if the RX input is not idle. The default 168 + * value is 0x3 (31 bit-time). 169 + */ 170 + #define ASM9260_BM_CTRL0_RXTO_MASK (0xff << 16) 171 + /* TIMEOUT = (100*7+1)*(1/BAUD) */ 172 + #define ASM9260_BM_CTRL0_DEFAULT_RXTIMEOUT (20 << 16) 173 + 174 + /* TX ctrl register */ 175 + #define ASM9260_HW_CTRL1 0x0010 176 + /* 177 + * RW. Tell the UART to execute the TX DMA Command. The 178 + * UART will clear this bit at the end of transmit execution. 179 + */ 180 + #define ASM9260_BM_CTRL1_TXDMA_RUN BIT(28) 181 + 182 + #define ASM9260_HW_CTRL2 0x0020 183 + /* 184 + * RW. Receive Interrupt FIFO Level Select. 185 + * The trigger points for the receive interrupt are as follows: 186 + * ONE_EIGHTHS = 0x0 Trigger on FIFO full to at least 2 of 16 entries. 187 + * ONE_QUARTER = 0x1 Trigger on FIFO full to at least 4 of 16 entries. 188 + * ONE_HALF = 0x2 Trigger on FIFO full to at least 8 of 16 entries. 189 + * THREE_QUARTERS = 0x3 Trigger on FIFO full to at least 12 of 16 entries. 190 + * SEVEN_EIGHTHS = 0x4 Trigger on FIFO full to at least 14 of 16 entries. 191 + */ 192 + #define ASM9260_BM_CTRL2_RXIFLSEL (7 << 20) 193 + #define ASM9260_BM_CTRL2_DEFAULT_RXIFLSEL (3 << 20) 194 + /* RW. Same as RXIFLSEL */ 195 + #define ASM9260_BM_CTRL2_TXIFLSEL (7 << 16) 196 + #define ASM9260_BM_CTRL2_DEFAULT_TXIFLSEL (2 << 16) 197 + /* RW. Set DTR. When this bit is 1, the output is 0. */ 198 + #define ASM9260_BM_CTRL2_DTR BIT(10) 199 + /* RW. Loop Back Enable */ 200 + #define ASM9260_BM_CTRL2_LBE BIT(7) 201 + #define ASM9260_BM_CTRL2_PORT_ENABLE BIT(0) 202 + 203 + #define ASM9260_HW_LINECTRL 0x0030 204 + /* 205 + * RW. Stick Parity Select. When bits 1, 2, and 7 of this register are set, the 206 + * parity bit is transmitted and checked as a 0. When bits 1 and 7 are set, 207 + * and bit 2 is 0, the parity bit is transmitted and checked as a 1. When this 208 + * bit is cleared stick parity is disabled. 209 + */ 210 + #define ASM9260_BM_LCTRL_SPS BIT(7) 211 + /* RW. Word length */ 212 + #define ASM9260_BM_LCTRL_WLEN (3 << 5) 213 + #define ASM9260_BM_LCTRL_CHRL_5 (0 << 5) 214 + #define ASM9260_BM_LCTRL_CHRL_6 (1 << 5) 215 + #define ASM9260_BM_LCTRL_CHRL_7 (2 << 5) 216 + #define ASM9260_BM_LCTRL_CHRL_8 (3 << 5) 217 + 218 + /* 219 + * Interrupt register. 220 + * contains the interrupt enables and the interrupt status bits 221 + */ 222 + #define ASM9260_HW_INTR 0x0040 223 + /* Tx FIFO EMPTY Raw Interrupt enable */ 224 + #define ASM9260_BM_INTR_TFEIEN BIT(27) 225 + /* Overrun Error Interrupt Enable. */ 226 + #define ASM9260_BM_INTR_OEIEN BIT(26) 227 + /* Break Error Interrupt Enable. */ 228 + #define ASM9260_BM_INTR_BEIEN BIT(25) 229 + /* Parity Error Interrupt Enable. */ 230 + #define ASM9260_BM_INTR_PEIEN BIT(24) 231 + /* Framing Error Interrupt Enable. */ 232 + #define ASM9260_BM_INTR_FEIEN BIT(23) 233 + 234 + /* nUARTDSR Modem Interrupt Enable. */ 235 + #define ASM9260_BM_INTR_DSRMIEN BIT(19) 236 + /* nUARTDCD Modem Interrupt Enable. */ 237 + #define ASM9260_BM_INTR_DCDMIEN BIT(18) 238 + /* nUARTRI Modem Interrupt Enable. */ 239 + #define ASM9260_BM_INTR_RIMIEN BIT(16) 240 + /* Auto-Boud Timeout */ 241 + #define ASM9260_BM_INTR_ABTO BIT(13) 242 + #define ASM9260_BM_INTR_ABEO BIT(12) 243 + /* Tx FIFO EMPTY Raw Interrupt state */ 244 + #define ASM9260_BM_INTR_TFEIS BIT(11) 245 + /* Overrun Error */ 246 + #define ASM9260_BM_INTR_OEIS BIT(10) 247 + /* Break Error */ 248 + #define ASM9260_BM_INTR_BEIS BIT(9) 249 + /* Parity Error */ 250 + #define ASM9260_BM_INTR_PEIS BIT(8) 251 + /* Framing Error */ 252 + #define ASM9260_BM_INTR_FEIS BIT(7) 253 + #define ASM9260_BM_INTR_DSRMIS BIT(3) 254 + #define ASM9260_BM_INTR_DCDMIS BIT(2) 255 + #define ASM9260_BM_INTR_RIMIS BIT(0) 256 + 257 + /* 258 + * RW. In DMA mode, up to 4 Received/Transmit characters can be accessed at a 259 + * time. In PIO mode, only one character can be accessed at a time. The status 260 + * register contains the receive data flags and valid bits. 261 + */ 262 + #define ASM9260_HW_DATA 0x0050 263 + 264 + #define ASM9260_HW_STAT 0x0060 265 + /* RO. If 1, UARTAPP is present in this product. */ 266 + #define ASM9260_BM_STAT_PRESENT BIT(31) 267 + /* RO. If 1, HISPEED is present in this product. */ 268 + #define ASM9260_BM_STAT_HISPEED BIT(30) 269 + /* RO. Receive FIFO Full. */ 270 + #define ASM9260_BM_STAT_RXFULL BIT(26) 271 + 272 + /* RO. The UART Debug Register contains the state of the DMA signals. */ 273 + #define ASM9260_HW_DEBUG 0x0070 274 + /* DMA Command Run Status */ 275 + #define ASM9260_BM_DEBUG_TXDMARUN BIT(5) 276 + #define ASM9260_BM_DEBUG_RXDMARUN BIT(4) 277 + /* DMA Command End Status */ 278 + #define ASM9260_BM_DEBUG_TXCMDEND BIT(3) 279 + #define ASM9260_BM_DEBUG_RXCMDEND BIT(2) 280 + /* DMA Request Status */ 281 + #define ASM9260_BM_DEBUG_TXDMARQ BIT(1) 282 + #define ASM9260_BM_DEBUG_RXDMARQ BIT(0) 283 + 284 + #define ASM9260_HW_ILPR 0x0080 285 + 286 + #define ASM9260_HW_RS485CTRL 0x0090 287 + /* 288 + * RW. This bit reverses the polarity of the direction control signal on the RTS 289 + * (or DTR) pin. 290 + * If 0, The direction control pin will be driven to logic ‘0’ when the 291 + * transmitter has data to be sent. It will be driven to logic ‘1’ after the 292 + * last bit of data has been transmitted. 293 + */ 294 + #define ASM9260_BM_RS485CTRL_ONIV BIT(5) 295 + /* RW. Enable Auto Direction Control. */ 296 + #define ASM9260_BM_RS485CTRL_DIR_CTRL BIT(4) 297 + /* 298 + * RW. If 0 and DIR_CTRL = 1, pin RTS is used for direction control. 299 + * If 1 and DIR_CTRL = 1, pin DTR is used for direction control. 300 + */ 301 + #define ASM9260_BM_RS485CTRL_PINSEL BIT(3) 302 + /* RW. Enable Auto Address Detect (AAD). */ 303 + #define ASM9260_BM_RS485CTRL_AADEN BIT(2) 304 + /* RW. Disable receiver. */ 305 + #define ASM9260_BM_RS485CTRL_RXDIS BIT(1) 306 + /* RW. Enable RS-485/EIA-485 Normal Multidrop Mode (NMM) */ 307 + #define ASM9260_BM_RS485CTRL_RS485EN BIT(0) 308 + 309 + #define ASM9260_HW_RS485ADRMATCH 0x00a0 310 + /* Contains the address match value. */ 311 + #define ASM9260_BM_RS485ADRMATCH_MASK (0xff << 0) 312 + 313 + #define ASM9260_HW_RS485DLY 0x00b0 314 + /* 315 + * RW. Contains the direction control (RTS or DTR) delay value. This delay time 316 + * is in periods of the baud clock. 317 + */ 318 + #define ASM9260_BM_RS485DLY_MASK (0xff << 0) 319 + 320 + #define ASM9260_HW_AUTOBAUD 0x00c0 321 + /* WO. Auto-baud time-out interrupt clear bit. */ 322 + #define ASM9260_BM_AUTOBAUD_TO_INT_CLR BIT(9) 323 + /* WO. End of auto-baud interrupt clear bit. */ 324 + #define ASM9260_BM_AUTOBAUD_EO_INT_CLR BIT(8) 325 + /* Restart in case of timeout (counter restarts at next UART Rx falling edge) */ 326 + #define ASM9260_BM_AUTOBAUD_AUTORESTART BIT(2) 327 + /* Auto-baud mode select bit. 0 - Mode 0, 1 - Mode 1. */ 328 + #define ASM9260_BM_AUTOBAUD_MODE BIT(1) 329 + /* 330 + * Auto-baud start (auto-baud is running). Auto-baud run bit. This bit is 331 + * automatically cleared after auto-baud completion. 332 + */ 333 + #define ASM9260_BM_AUTOBAUD_START BIT(0) 334 + 335 + #define ASM9260_HW_CTRL3 0x00d0 336 + #define ASM9260_BM_CTRL3_OUTCLK_DIV_MASK (0xffff << 16) 337 + /* 338 + * RW. Provide clk over OUTCLK pin. In case of asm9260 it can be configured on 339 + * pins 137 and 144. 340 + */ 341 + #define ASM9260_BM_CTRL3_MASTERMODE BIT(6) 342 + /* RW. Baud Rate Mode: 1 - Enable sync mode. 0 - async mode. */ 343 + #define ASM9260_BM_CTRL3_SYNCMODE BIT(4) 344 + /* RW. 1 - MSB bit send frist; 0 - LSB bit frist. */ 345 + #define ASM9260_BM_CTRL3_MSBF BIT(2) 346 + /* RW. 1 - sample rate = 8 x Baudrate; 0 - sample rate = 16 x Baudrate. */ 347 + #define ASM9260_BM_CTRL3_BAUD8 BIT(1) 348 + /* RW. 1 - Set word length to 9bit. 0 - use ASM9260_BM_LCTRL_WLEN */ 349 + #define ASM9260_BM_CTRL3_9BIT BIT(0) 350 + 351 + #define ASM9260_HW_ISO7816_CTRL 0x00e0 352 + /* RW. Enable High Speed mode. */ 353 + #define ASM9260_BM_ISO7816CTRL_HS BIT(12) 354 + /* Disable Successive Receive NACK */ 355 + #define ASM9260_BM_ISO7816CTRL_DS_NACK BIT(8) 356 + #define ASM9260_BM_ISO7816CTRL_MAX_ITER_MASK (0xff << 4) 357 + /* Receive NACK Inhibit */ 358 + #define ASM9260_BM_ISO7816CTRL_INACK BIT(3) 359 + #define ASM9260_BM_ISO7816CTRL_NEG_DATA BIT(2) 360 + /* RW. 1 - ISO7816 mode; 0 - USART mode */ 361 + #define ASM9260_BM_ISO7816CTRL_ENABLE BIT(0) 362 + 363 + #define ASM9260_HW_ISO7816_ERRCNT 0x00f0 364 + /* Parity error counter. Will be cleared after reading */ 365 + #define ASM9260_BM_ISO7816_NB_ERRORS_MASK (0xff << 0) 366 + 367 + #define ASM9260_HW_ISO7816_STATUS 0x0100 368 + /* Max number of Repetitions Reached */ 369 + #define ASM9260_BM_ISO7816_STAT_ITERATION BIT(0) 370 + 371 + /* End of Alphascale asm9260 defines */ 372 + 126 373 static struct uart_driver auart_driver; 127 374 128 375 enum mxs_auart_type { 129 376 IMX23_AUART, 130 377 IMX28_AUART, 378 + ASM9260_AUART, 379 + }; 380 + 381 + struct vendor_data { 382 + const u16 *reg_offset; 383 + }; 384 + 385 + enum { 386 + REG_CTRL0, 387 + REG_CTRL1, 388 + REG_CTRL2, 389 + REG_LINECTRL, 390 + REG_LINECTRL2, 391 + REG_INTR, 392 + REG_DATA, 393 + REG_STAT, 394 + REG_DEBUG, 395 + REG_VERSION, 396 + REG_AUTOBAUD, 397 + 398 + /* The size of the array - must be last */ 399 + REG_ARRAY_SIZE, 400 + }; 401 + 402 + static const u16 mxs_asm9260_offsets[REG_ARRAY_SIZE] = { 403 + [REG_CTRL0] = ASM9260_HW_CTRL0, 404 + [REG_CTRL1] = ASM9260_HW_CTRL1, 405 + [REG_CTRL2] = ASM9260_HW_CTRL2, 406 + [REG_LINECTRL] = ASM9260_HW_LINECTRL, 407 + [REG_INTR] = ASM9260_HW_INTR, 408 + [REG_DATA] = ASM9260_HW_DATA, 409 + [REG_STAT] = ASM9260_HW_STAT, 410 + [REG_DEBUG] = ASM9260_HW_DEBUG, 411 + [REG_AUTOBAUD] = ASM9260_HW_AUTOBAUD, 412 + }; 413 + 414 + static const u16 mxs_stmp37xx_offsets[REG_ARRAY_SIZE] = { 415 + [REG_CTRL0] = AUART_CTRL0, 416 + [REG_CTRL1] = AUART_CTRL1, 417 + [REG_CTRL2] = AUART_CTRL2, 418 + [REG_LINECTRL] = AUART_LINECTRL, 419 + [REG_LINECTRL2] = AUART_LINECTRL2, 420 + [REG_INTR] = AUART_INTR, 421 + [REG_DATA] = AUART_DATA, 422 + [REG_STAT] = AUART_STAT, 423 + [REG_DEBUG] = AUART_DEBUG, 424 + [REG_VERSION] = AUART_VERSION, 425 + [REG_AUTOBAUD] = AUART_AUTOBAUD, 426 + }; 427 + 428 + static const struct vendor_data vendor_alphascale_asm9260 = { 429 + .reg_offset = mxs_asm9260_offsets, 430 + }; 431 + 432 + static const struct vendor_data vendor_freescale_stmp37xx = { 433 + .reg_offset = mxs_stmp37xx_offsets, 131 434 }; 132 435 133 436 struct mxs_auart_port { ··· 430 153 unsigned long flags; 431 154 unsigned int mctrl_prev; 432 155 enum mxs_auart_type devtype; 156 + const struct vendor_data *vendor; 433 157 434 158 struct clk *clk; 159 + struct clk *clk_ahb; 435 160 struct device *dev; 436 161 437 162 /* for DMA */ ··· 453 174 static const struct platform_device_id mxs_auart_devtype[] = { 454 175 { .name = "mxs-auart-imx23", .driver_data = IMX23_AUART }, 455 176 { .name = "mxs-auart-imx28", .driver_data = IMX28_AUART }, 177 + { .name = "as-auart-asm9260", .driver_data = ASM9260_AUART }, 456 178 { /* sentinel */ } 457 179 }; 458 180 MODULE_DEVICE_TABLE(platform, mxs_auart_devtype); ··· 465 185 }, { 466 186 .compatible = "fsl,imx23-auart", 467 187 .data = &mxs_auart_devtype[IMX23_AUART] 188 + }, { 189 + .compatible = "alphascale,asm9260-auart", 190 + .data = &mxs_auart_devtype[ASM9260_AUART] 468 191 }, { /* sentinel */ } 469 192 }; 470 193 MODULE_DEVICE_TABLE(of, mxs_auart_dt_ids); ··· 477 194 return s->devtype == IMX28_AUART; 478 195 } 479 196 197 + static inline int is_asm9260_auart(struct mxs_auart_port *s) 198 + { 199 + return s->devtype == ASM9260_AUART; 200 + } 201 + 480 202 static inline bool auart_dma_enabled(struct mxs_auart_port *s) 481 203 { 482 204 return s->flags & MXS_AUART_DMA_ENABLED; 205 + } 206 + 207 + static unsigned int mxs_reg_to_offset(const struct mxs_auart_port *uap, 208 + unsigned int reg) 209 + { 210 + return uap->vendor->reg_offset[reg]; 211 + } 212 + 213 + static unsigned int mxs_read(const struct mxs_auart_port *uap, 214 + unsigned int reg) 215 + { 216 + void __iomem *addr = uap->port.membase + mxs_reg_to_offset(uap, reg); 217 + 218 + return readl_relaxed(addr); 219 + } 220 + 221 + static void mxs_write(unsigned int val, struct mxs_auart_port *uap, 222 + unsigned int reg) 223 + { 224 + void __iomem *addr = uap->port.membase + mxs_reg_to_offset(uap, reg); 225 + 226 + writel_relaxed(val, addr); 227 + } 228 + 229 + static void mxs_set(unsigned int val, struct mxs_auart_port *uap, 230 + unsigned int reg) 231 + { 232 + void __iomem *addr = uap->port.membase + mxs_reg_to_offset(uap, reg); 233 + 234 + writel_relaxed(val, addr + SET_REG); 235 + } 236 + 237 + static void mxs_clr(unsigned int val, struct mxs_auart_port *uap, 238 + unsigned int reg) 239 + { 240 + void __iomem *addr = uap->port.membase + mxs_reg_to_offset(uap, reg); 241 + 242 + writel_relaxed(val, addr + CLR_REG); 483 243 } 484 244 485 245 static void mxs_auart_stop_tx(struct uart_port *u); ··· 621 295 } 622 296 623 297 624 - while (!(readl(s->port.membase + AUART_STAT) & 625 - AUART_STAT_TXFF)) { 298 + while (!(mxs_read(s, REG_STAT) & AUART_STAT_TXFF)) { 626 299 if (s->port.x_char) { 627 300 s->port.icount.tx++; 628 - writel(s->port.x_char, 629 - s->port.membase + AUART_DATA); 301 + mxs_write(s->port.x_char, s, REG_DATA); 630 302 s->port.x_char = 0; 631 303 continue; 632 304 } 633 305 if (!uart_circ_empty(xmit) && !uart_tx_stopped(&s->port)) { 634 306 s->port.icount.tx++; 635 - writel(xmit->buf[xmit->tail], 636 - s->port.membase + AUART_DATA); 307 + mxs_write(xmit->buf[xmit->tail], s, REG_DATA); 637 308 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 638 309 } else 639 310 break; ··· 639 316 uart_write_wakeup(&s->port); 640 317 641 318 if (uart_circ_empty(&(s->port.state->xmit))) 642 - writel(AUART_INTR_TXIEN, 643 - s->port.membase + AUART_INTR_CLR); 319 + mxs_clr(AUART_INTR_TXIEN, s, REG_INTR); 644 320 else 645 - writel(AUART_INTR_TXIEN, 646 - s->port.membase + AUART_INTR_SET); 321 + mxs_set(AUART_INTR_TXIEN, s, REG_INTR); 647 322 648 323 if (uart_tx_stopped(&s->port)) 649 324 mxs_auart_stop_tx(&s->port); ··· 653 332 u32 stat; 654 333 u8 c; 655 334 656 - c = readl(s->port.membase + AUART_DATA); 657 - stat = readl(s->port.membase + AUART_STAT); 335 + c = mxs_read(s, REG_DATA); 336 + stat = mxs_read(s, REG_STAT); 658 337 659 338 flag = TTY_NORMAL; 660 339 s->port.icount.rx++; ··· 689 368 690 369 uart_insert_char(&s->port, stat, AUART_STAT_OERR, c, flag); 691 370 out: 692 - writel(stat, s->port.membase + AUART_STAT); 371 + mxs_write(stat, s, REG_STAT); 693 372 } 694 373 695 374 static void mxs_auart_rx_chars(struct mxs_auart_port *s) ··· 697 376 u32 stat = 0; 698 377 699 378 for (;;) { 700 - stat = readl(s->port.membase + AUART_STAT); 379 + stat = mxs_read(s, REG_STAT); 701 380 if (stat & AUART_STAT_RXFE) 702 381 break; 703 382 mxs_auart_rx_char(s); 704 383 } 705 384 706 - writel(stat, s->port.membase + AUART_STAT); 385 + mxs_write(stat, s, REG_STAT); 707 386 tty_flip_buffer_push(&s->port.state->port); 708 387 } 709 388 ··· 739 418 { 740 419 struct mxs_auart_port *s = to_auart_port(u); 741 420 742 - u32 ctrl = readl(u->membase + AUART_CTRL2); 421 + u32 ctrl = mxs_read(s, REG_CTRL2); 743 422 744 423 ctrl &= ~(AUART_CTRL2_RTSEN | AUART_CTRL2_RTS); 745 424 if (mctrl & TIOCM_RTS) { ··· 749 428 ctrl |= AUART_CTRL2_RTS; 750 429 } 751 430 752 - writel(ctrl, u->membase + AUART_CTRL2); 431 + mxs_write(ctrl, s, REG_CTRL2); 753 432 754 433 mctrl_gpio_set(s->gpios, mctrl); 755 434 } ··· 780 459 static u32 mxs_auart_get_mctrl(struct uart_port *u) 781 460 { 782 461 struct mxs_auart_port *s = to_auart_port(u); 783 - u32 stat = readl(u->membase + AUART_STAT); 462 + u32 stat = mxs_read(s, REG_STAT); 784 463 u32 mctrl = 0; 785 464 786 465 if (stat & AUART_STAT_CTS) ··· 857 536 858 537 dma_unmap_sg(s->dev, &s->rx_sgl, 1, DMA_FROM_DEVICE); 859 538 860 - stat = readl(s->port.membase + AUART_STAT); 539 + stat = mxs_read(s, REG_STAT); 861 540 stat &= ~(AUART_STAT_OERR | AUART_STAT_BERR | 862 541 AUART_STAT_PERR | AUART_STAT_FERR); 863 542 864 543 count = stat & AUART_STAT_RXCOUNT_MASK; 865 544 tty_insert_flip_string(port, s->rx_dma_buf, count); 866 545 867 - writel(stat, s->port.membase + AUART_STAT); 546 + mxs_write(stat, s, REG_STAT); 868 547 tty_flip_buffer_push(port); 869 548 870 549 /* start the next DMA for RX. */ ··· 927 606 static void mxs_auart_dma_exit(struct mxs_auart_port *s) 928 607 { 929 608 930 - writel(AUART_CTRL2_TXDMAE | AUART_CTRL2_RXDMAE | AUART_CTRL2_DMAONERR, 931 - s->port.membase + AUART_CTRL2_CLR); 609 + mxs_clr(AUART_CTRL2_TXDMAE | AUART_CTRL2_RXDMAE | AUART_CTRL2_DMAONERR, 610 + s, REG_CTRL2); 932 611 933 612 mxs_auart_dma_exit_channel(s); 934 613 s->flags &= ~MXS_AUART_DMA_ENABLED; ··· 987 666 cflag = termios->c_cflag; 988 667 989 668 ctrl = AUART_LINECTRL_FEN; 990 - ctrl2 = readl(u->membase + AUART_CTRL2); 669 + ctrl2 = mxs_read(s, REG_CTRL2); 991 670 992 671 /* byte size */ 993 672 switch (cflag & CSIZE) { ··· 1075 754 } 1076 755 1077 756 /* set baud rate */ 1078 - baud_min = DIV_ROUND_UP(u->uartclk * 32, AUART_LINECTRL_BAUD_DIV_MAX); 1079 - baud_max = u->uartclk * 32 / AUART_LINECTRL_BAUD_DIV_MIN; 1080 - baud = uart_get_baud_rate(u, termios, old, baud_min, baud_max); 1081 - div = u->uartclk * 32 / baud; 757 + if (is_asm9260_auart(s)) { 758 + baud = uart_get_baud_rate(u, termios, old, 759 + u->uartclk * 4 / 0x3FFFFF, 760 + u->uartclk / 16); 761 + div = u->uartclk * 4 / baud; 762 + } else { 763 + baud_min = DIV_ROUND_UP(u->uartclk * 32, 764 + AUART_LINECTRL_BAUD_DIV_MAX); 765 + baud_max = u->uartclk * 32 / AUART_LINECTRL_BAUD_DIV_MIN; 766 + baud = uart_get_baud_rate(u, termios, old, baud_min, baud_max); 767 + div = u->uartclk * 32 / baud; 768 + } 769 + 1082 770 ctrl |= AUART_LINECTRL_BAUD_DIVFRAC(div & 0x3F); 1083 771 ctrl |= AUART_LINECTRL_BAUD_DIVINT(div >> 6); 772 + mxs_write(ctrl, s, REG_LINECTRL); 1084 773 1085 - writel(ctrl, u->membase + AUART_LINECTRL); 1086 - writel(ctrl2, u->membase + AUART_CTRL2); 774 + mxs_write(ctrl2, s, REG_CTRL2); 1087 775 1088 776 uart_update_timeout(u, termios->c_cflag, baud); 1089 777 ··· 1101 771 !test_and_set_bit(MXS_AUART_DMA_RX_READY, &s->flags)) { 1102 772 if (!mxs_auart_dma_prep_rx(s)) { 1103 773 /* Disable the normal RX interrupt. */ 1104 - writel(AUART_INTR_RXIEN | AUART_INTR_RTIEN, 1105 - u->membase + AUART_INTR_CLR); 774 + mxs_clr(AUART_INTR_RXIEN | AUART_INTR_RTIEN, 775 + s, REG_INTR); 1106 776 } else { 1107 777 mxs_auart_dma_exit(s); 1108 778 dev_err(s->dev, "We can not start up the DMA.\n"); ··· 1132 802 u32 istat; 1133 803 struct mxs_auart_port *s = context; 1134 804 u32 mctrl_temp = s->mctrl_prev; 1135 - u32 stat = readl(s->port.membase + AUART_STAT); 805 + u32 stat = mxs_read(s, REG_STAT); 1136 806 1137 - istat = readl(s->port.membase + AUART_INTR); 807 + istat = mxs_read(s, REG_INTR); 1138 808 1139 809 /* ack irq */ 1140 - writel(istat & (AUART_INTR_RTIS 1141 - | AUART_INTR_TXIS 1142 - | AUART_INTR_RXIS 1143 - | AUART_INTR_CTSMIS), 1144 - s->port.membase + AUART_INTR_CLR); 810 + mxs_clr(istat & (AUART_INTR_RTIS | AUART_INTR_TXIS | AUART_INTR_RXIS 811 + | AUART_INTR_CTSMIS), s, REG_INTR); 1145 812 1146 813 /* 1147 814 * Dealing with GPIO interrupt ··· 1154 827 if (CTS_AT_AUART() && s->ms_irq_enabled) 1155 828 uart_handle_cts_change(&s->port, 1156 829 stat & AUART_STAT_CTS); 1157 - writel(AUART_INTR_CTSMIS, 1158 - s->port.membase + AUART_INTR_CLR); 830 + mxs_clr(AUART_INTR_CTSMIS, s, REG_INTR); 1159 831 istat &= ~AUART_INTR_CTSMIS; 1160 832 } 1161 833 ··· 1172 846 return IRQ_HANDLED; 1173 847 } 1174 848 1175 - static void mxs_auart_reset_deassert(struct uart_port *u) 849 + static void mxs_auart_reset_deassert(struct mxs_auart_port *s) 1176 850 { 1177 851 int i; 1178 852 unsigned int reg; 1179 853 1180 - writel(AUART_CTRL0_SFTRST, u->membase + AUART_CTRL0_CLR); 854 + mxs_clr(AUART_CTRL0_SFTRST, s, REG_CTRL0); 1181 855 1182 856 for (i = 0; i < 10000; i++) { 1183 - reg = readl(u->membase + AUART_CTRL0); 857 + reg = mxs_read(s, REG_CTRL0); 1184 858 if (!(reg & AUART_CTRL0_SFTRST)) 1185 859 break; 1186 860 udelay(3); 1187 861 } 1188 - writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_CLR); 862 + mxs_clr(AUART_CTRL0_CLKGATE, s, REG_CTRL0); 1189 863 } 1190 864 1191 - static void mxs_auart_reset_assert(struct uart_port *u) 865 + static void mxs_auart_reset_assert(struct mxs_auart_port *s) 1192 866 { 1193 867 int i; 1194 868 u32 reg; 1195 869 1196 - reg = readl(u->membase + AUART_CTRL0); 870 + reg = mxs_read(s, REG_CTRL0); 1197 871 /* if already in reset state, keep it untouched */ 1198 872 if (reg & AUART_CTRL0_SFTRST) 1199 873 return; 1200 874 1201 - writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_CLR); 1202 - writel(AUART_CTRL0_SFTRST, u->membase + AUART_CTRL0_SET); 875 + mxs_clr(AUART_CTRL0_CLKGATE, s, REG_CTRL0); 876 + mxs_set(AUART_CTRL0_SFTRST, s, REG_CTRL0); 1203 877 1204 878 for (i = 0; i < 1000; i++) { 1205 - reg = readl(u->membase + AUART_CTRL0); 879 + reg = mxs_read(s, REG_CTRL0); 1206 880 /* reset is finished when the clock is gated */ 1207 881 if (reg & AUART_CTRL0_CLKGATE) 1208 882 return; 1209 883 udelay(10); 1210 884 } 1211 885 1212 - dev_err(u->dev, "Failed to reset the unit."); 886 + dev_err(s->dev, "Failed to reset the unit."); 1213 887 } 1214 888 1215 889 static int mxs_auart_startup(struct uart_port *u) ··· 1222 896 return ret; 1223 897 1224 898 if (uart_console(u)) { 1225 - writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_CLR); 899 + mxs_clr(AUART_CTRL0_CLKGATE, s, REG_CTRL0); 1226 900 } else { 1227 901 /* reset the unit to a well known state */ 1228 - mxs_auart_reset_assert(u); 1229 - mxs_auart_reset_deassert(u); 902 + mxs_auart_reset_assert(s); 903 + mxs_auart_reset_deassert(s); 1230 904 } 1231 905 1232 - writel(AUART_CTRL2_UARTEN, u->membase + AUART_CTRL2_SET); 906 + mxs_set(AUART_CTRL2_UARTEN, s, REG_CTRL2); 1233 907 1234 - writel(AUART_INTR_RXIEN | AUART_INTR_RTIEN | AUART_INTR_CTSMIEN, 1235 - u->membase + AUART_INTR); 908 + mxs_write(AUART_INTR_RXIEN | AUART_INTR_RTIEN | AUART_INTR_CTSMIEN, 909 + s, REG_INTR); 1236 910 1237 911 /* Reset FIFO size (it could have changed if DMA was enabled) */ 1238 912 u->fifosize = MXS_AUART_FIFO_SIZE; ··· 1241 915 * Enable fifo so all four bytes of a DMA word are written to 1242 916 * output (otherwise, only the LSB is written, ie. 1 in 4 bytes) 1243 917 */ 1244 - writel(AUART_LINECTRL_FEN, u->membase + AUART_LINECTRL_SET); 918 + mxs_set(AUART_LINECTRL_FEN, s, REG_LINECTRL); 1245 919 1246 920 /* get initial status of modem lines */ 1247 921 mctrl_gpio_get(s->gpios, &s->mctrl_prev); ··· 1260 934 mxs_auart_dma_exit(s); 1261 935 1262 936 if (uart_console(u)) { 1263 - writel(AUART_CTRL2_UARTEN, u->membase + AUART_CTRL2_CLR); 1264 - writel(AUART_INTR_RXIEN | AUART_INTR_RTIEN | AUART_INTR_CTSMIEN, 1265 - u->membase + AUART_INTR_CLR); 1266 - writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_SET); 937 + mxs_clr(AUART_CTRL2_UARTEN, s, REG_CTRL2); 938 + 939 + mxs_clr(AUART_INTR_RXIEN | AUART_INTR_RTIEN | 940 + AUART_INTR_CTSMIEN, s, REG_INTR); 941 + mxs_set(AUART_CTRL0_CLKGATE, s, REG_CTRL0); 1267 942 } else { 1268 - mxs_auart_reset_assert(u); 943 + mxs_auart_reset_assert(s); 1269 944 } 1270 945 1271 946 clk_disable_unprepare(s->clk); ··· 1274 947 1275 948 static unsigned int mxs_auart_tx_empty(struct uart_port *u) 1276 949 { 1277 - if ((readl(u->membase + AUART_STAT) & 950 + struct mxs_auart_port *s = to_auart_port(u); 951 + 952 + if ((mxs_read(s, REG_STAT) & 1278 953 (AUART_STAT_TXFE | AUART_STAT_BUSY)) == AUART_STAT_TXFE) 1279 954 return TIOCSER_TEMT; 1280 955 ··· 1288 959 struct mxs_auart_port *s = to_auart_port(u); 1289 960 1290 961 /* enable transmitter */ 1291 - writel(AUART_CTRL2_TXE, u->membase + AUART_CTRL2_SET); 962 + mxs_set(AUART_CTRL2_TXE, s, REG_CTRL2); 1292 963 1293 964 mxs_auart_tx_chars(s); 1294 965 } 1295 966 1296 967 static void mxs_auart_stop_tx(struct uart_port *u) 1297 968 { 1298 - writel(AUART_CTRL2_TXE, u->membase + AUART_CTRL2_CLR); 969 + struct mxs_auart_port *s = to_auart_port(u); 970 + 971 + mxs_clr(AUART_CTRL2_TXE, s, REG_CTRL2); 1299 972 } 1300 973 1301 974 static void mxs_auart_stop_rx(struct uart_port *u) 1302 975 { 1303 - writel(AUART_CTRL2_RXE, u->membase + AUART_CTRL2_CLR); 976 + struct mxs_auart_port *s = to_auart_port(u); 977 + 978 + mxs_clr(AUART_CTRL2_RXE, s, REG_CTRL2); 1304 979 } 1305 980 1306 981 static void mxs_auart_break_ctl(struct uart_port *u, int ctl) 1307 982 { 983 + struct mxs_auart_port *s = to_auart_port(u); 984 + 1308 985 if (ctl) 1309 - writel(AUART_LINECTRL_BRK, 1310 - u->membase + AUART_LINECTRL_SET); 986 + mxs_set(AUART_LINECTRL_BRK, s, REG_LINECTRL); 1311 987 else 1312 - writel(AUART_LINECTRL_BRK, 1313 - u->membase + AUART_LINECTRL_CLR); 988 + mxs_clr(AUART_LINECTRL_BRK, s, REG_LINECTRL); 1314 989 } 1315 990 1316 991 static struct uart_ops mxs_auart_ops = { ··· 1342 1009 #ifdef CONFIG_SERIAL_MXS_AUART_CONSOLE 1343 1010 static void mxs_auart_console_putchar(struct uart_port *port, int ch) 1344 1011 { 1012 + struct mxs_auart_port *s = to_auart_port(port); 1345 1013 unsigned int to = 1000; 1346 1014 1347 - while (readl(port->membase + AUART_STAT) & AUART_STAT_TXFF) { 1015 + while (mxs_read(s, REG_STAT) & AUART_STAT_TXFF) { 1348 1016 if (!to--) 1349 1017 break; 1350 1018 udelay(1); 1351 1019 } 1352 1020 1353 - writel(ch, port->membase + AUART_DATA); 1021 + mxs_write(ch, s, REG_DATA); 1354 1022 } 1355 1023 1356 1024 static void ··· 1371 1037 clk_enable(s->clk); 1372 1038 1373 1039 /* First save the CR then disable the interrupts */ 1374 - old_ctrl2 = readl(port->membase + AUART_CTRL2); 1375 - old_ctrl0 = readl(port->membase + AUART_CTRL0); 1040 + old_ctrl2 = mxs_read(s, REG_CTRL2); 1041 + old_ctrl0 = mxs_read(s, REG_CTRL0); 1376 1042 1377 - writel(AUART_CTRL0_CLKGATE, 1378 - port->membase + AUART_CTRL0_CLR); 1379 - writel(AUART_CTRL2_UARTEN | AUART_CTRL2_TXE, 1380 - port->membase + AUART_CTRL2_SET); 1043 + mxs_clr(AUART_CTRL0_CLKGATE, s, REG_CTRL0); 1044 + mxs_set(AUART_CTRL2_UARTEN | AUART_CTRL2_TXE, s, REG_CTRL2); 1381 1045 1382 1046 uart_console_write(port, str, count, mxs_auart_console_putchar); 1383 1047 1384 1048 /* Finally, wait for transmitter to become empty ... */ 1385 - while (readl(port->membase + AUART_STAT) & AUART_STAT_BUSY) { 1049 + while (mxs_read(s, REG_STAT) & AUART_STAT_BUSY) { 1386 1050 udelay(1); 1387 1051 if (!to--) 1388 1052 break; ··· 1392 1060 * unused, but that is better than to disable it while it is still 1393 1061 * transmitting. 1394 1062 */ 1395 - if (!(readl(port->membase + AUART_STAT) & AUART_STAT_BUSY)) { 1396 - writel(old_ctrl0, port->membase + AUART_CTRL0); 1397 - writel(old_ctrl2, port->membase + AUART_CTRL2); 1063 + if (!(mxs_read(s, REG_STAT) & AUART_STAT_BUSY)) { 1064 + mxs_write(old_ctrl0, s, REG_CTRL0); 1065 + mxs_write(old_ctrl2, s, REG_CTRL2); 1398 1066 } 1399 1067 1400 1068 clk_disable(s->clk); 1401 1069 } 1402 1070 1403 1071 static void __init 1404 - auart_console_get_options(struct uart_port *port, int *baud, 1072 + auart_console_get_options(struct mxs_auart_port *s, int *baud, 1405 1073 int *parity, int *bits) 1406 1074 { 1075 + struct uart_port *port = &s->port; 1407 1076 unsigned int lcr_h, quot; 1408 1077 1409 - if (!(readl(port->membase + AUART_CTRL2) & AUART_CTRL2_UARTEN)) 1078 + if (!(mxs_read(s, REG_CTRL2) & AUART_CTRL2_UARTEN)) 1410 1079 return; 1411 1080 1412 - lcr_h = readl(port->membase + AUART_LINECTRL); 1081 + lcr_h = mxs_read(s, REG_LINECTRL); 1413 1082 1414 1083 *parity = 'n'; 1415 1084 if (lcr_h & AUART_LINECTRL_PEN) { ··· 1425 1092 else 1426 1093 *bits = 8; 1427 1094 1428 - quot = ((readl(port->membase + AUART_LINECTRL) 1429 - & AUART_LINECTRL_BAUD_DIVINT_MASK)) 1430 - >> (AUART_LINECTRL_BAUD_DIVINT_SHIFT - 6); 1431 - quot |= ((readl(port->membase + AUART_LINECTRL) 1432 - & AUART_LINECTRL_BAUD_DIVFRAC_MASK)) 1433 - >> AUART_LINECTRL_BAUD_DIVFRAC_SHIFT; 1095 + quot = ((mxs_read(s, REG_LINECTRL) & AUART_LINECTRL_BAUD_DIVINT_MASK)) 1096 + >> (AUART_LINECTRL_BAUD_DIVINT_SHIFT - 6); 1097 + quot |= ((mxs_read(s, REG_LINECTRL) & AUART_LINECTRL_BAUD_DIVFRAC_MASK)) 1098 + >> AUART_LINECTRL_BAUD_DIVFRAC_SHIFT; 1434 1099 if (quot == 0) 1435 1100 quot = 1; 1436 1101 ··· 1463 1132 if (options) 1464 1133 uart_parse_options(options, &baud, &parity, &bits, &flow); 1465 1134 else 1466 - auart_console_get_options(&s->port, &baud, &parity, &bits); 1135 + auart_console_get_options(s, &baud, &parity, &bits); 1467 1136 1468 1137 ret = uart_set_options(&s->port, co, baud, parity, bits, flow); 1469 1138 ··· 1495 1164 #endif 1496 1165 }; 1497 1166 1167 + static void mxs_init_regs(struct mxs_auart_port *s) 1168 + { 1169 + if (is_asm9260_auart(s)) 1170 + s->vendor = &vendor_alphascale_asm9260; 1171 + else 1172 + s->vendor = &vendor_freescale_stmp37xx; 1173 + } 1174 + 1175 + static int mxs_get_clks(struct mxs_auart_port *s, 1176 + struct platform_device *pdev) 1177 + { 1178 + int err; 1179 + 1180 + if (!is_asm9260_auart(s)) { 1181 + s->clk = devm_clk_get(&pdev->dev, NULL); 1182 + if (IS_ERR(s->clk)) 1183 + return PTR_ERR(s->clk); 1184 + 1185 + return 0; 1186 + } 1187 + 1188 + s->clk = devm_clk_get(s->dev, "mod"); 1189 + if (IS_ERR(s->clk)) { 1190 + dev_err(s->dev, "Failed to get \"mod\" clk\n"); 1191 + return PTR_ERR(s->clk); 1192 + } 1193 + 1194 + s->clk_ahb = devm_clk_get(s->dev, "ahb"); 1195 + if (IS_ERR(s->clk_ahb)) { 1196 + dev_err(s->dev, "Failed to get \"ahb\" clk\n"); 1197 + return PTR_ERR(s->clk_ahb); 1198 + } 1199 + 1200 + err = clk_prepare_enable(s->clk_ahb); 1201 + if (err) { 1202 + dev_err(s->dev, "Failed to enable ahb_clk!\n"); 1203 + return err; 1204 + } 1205 + 1206 + err = clk_set_rate(s->clk, clk_get_rate(s->clk_ahb)); 1207 + if (err) { 1208 + dev_err(s->dev, "Failed to set rate!\n"); 1209 + return err; 1210 + } 1211 + 1212 + err = clk_prepare_enable(s->clk); 1213 + if (err) { 1214 + dev_err(s->dev, "Failed to enable clk!\n"); 1215 + return err; 1216 + } 1217 + 1218 + return 0; 1219 + } 1220 + 1498 1221 /* 1499 1222 * This function returns 1 if pdev isn't a device instatiated by dt, 0 if it 1500 1223 * could successfully get all information from dt or a negative errno. ··· 1570 1185 } 1571 1186 s->port.line = ret; 1572 1187 1573 - if (of_get_property(np, "fsl,uart-has-rtscts", NULL)) 1188 + if (of_get_property(np, "uart-has-rtscts", NULL) || 1189 + of_get_property(np, "fsl,uart-has-rtscts", NULL) /* deprecated */) 1574 1190 set_bit(MXS_AUART_RTSCTS, &s->flags); 1575 1191 1576 1192 return 0; ··· 1655 1269 if (!s) 1656 1270 return -ENOMEM; 1657 1271 1272 + s->port.dev = &pdev->dev; 1273 + s->dev = &pdev->dev; 1274 + 1658 1275 ret = serial_mxs_probe_dt(s, pdev); 1659 1276 if (ret > 0) 1660 1277 s->port.line = pdev->id < 0 ? 0 : pdev->id; ··· 1669 1280 s->devtype = pdev->id_entry->driver_data; 1670 1281 } 1671 1282 1672 - s->clk = devm_clk_get(&pdev->dev, NULL); 1673 - if (IS_ERR(s->clk)) 1674 - return PTR_ERR(s->clk); 1283 + ret = mxs_get_clks(s, pdev); 1284 + if (ret) 1285 + return ret; 1675 1286 1676 1287 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1677 1288 if (!r) 1678 1289 return -ENXIO; 1679 - 1680 1290 1681 1291 s->port.mapbase = r->start; 1682 1292 s->port.membase = ioremap(r->start, resource_size(r)); ··· 1684 1296 s->port.fifosize = MXS_AUART_FIFO_SIZE; 1685 1297 s->port.uartclk = clk_get_rate(s->clk); 1686 1298 s->port.type = PORT_IMX; 1687 - s->port.dev = s->dev = &pdev->dev; 1299 + 1300 + mxs_init_regs(s); 1688 1301 1689 1302 s->mctrl_prev = 0; 1690 1303 ··· 1716 1327 1717 1328 auart_port[s->port.line] = s; 1718 1329 1719 - mxs_auart_reset_deassert(&s->port); 1330 + mxs_auart_reset_deassert(s); 1720 1331 1721 1332 ret = uart_add_one_port(&auart_driver, &s->port); 1722 1333 if (ret) 1723 1334 goto out_free_gpio_irq; 1724 1335 1725 - version = readl(s->port.membase + AUART_VERSION); 1726 - dev_info(&pdev->dev, "Found APPUART %d.%d.%d\n", 1727 - (version >> 24) & 0xff, 1728 - (version >> 16) & 0xff, version & 0xffff); 1336 + /* ASM9260 don't have version reg */ 1337 + if (is_asm9260_auart(s)) { 1338 + dev_info(&pdev->dev, "Found APPUART ASM9260\n"); 1339 + } else { 1340 + version = mxs_read(s, REG_VERSION); 1341 + dev_info(&pdev->dev, "Found APPUART %d.%d.%d\n", 1342 + (version >> 24) & 0xff, 1343 + (version >> 16) & 0xff, version & 0xffff); 1344 + } 1729 1345 1730 1346 return 0; 1731 1347
+2 -2
drivers/tty/serial/samsung.c
··· 1271 1271 /* check to see if we need to change clock source */ 1272 1272 1273 1273 if (ourport->baudclk != clk) { 1274 + clk_prepare_enable(clk); 1275 + 1274 1276 s3c24xx_serial_setsource(port, clk_sel); 1275 1277 1276 1278 if (!IS_ERR(ourport->baudclk)) { 1277 1279 clk_disable_unprepare(ourport->baudclk); 1278 1280 ourport->baudclk = ERR_PTR(-EINVAL); 1279 1281 } 1280 - 1281 - clk_prepare_enable(clk); 1282 1282 1283 1283 ourport->baudclk = clk; 1284 1284 ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0;
+3 -10
drivers/tty/serial/sc16is7xx.c
··· 666 666 struct uart_port *port = &s->p[portno].port; 667 667 668 668 do { 669 - unsigned int iir, msr, rxlen; 669 + unsigned int iir, rxlen; 670 670 671 671 iir = sc16is7xx_port_read(port, SC16IS7XX_IIR_REG); 672 672 if (iir & SC16IS7XX_IIR_NO_INT_BIT) ··· 682 682 rxlen = sc16is7xx_port_read(port, SC16IS7XX_RXLVL_REG); 683 683 if (rxlen) 684 684 sc16is7xx_handle_rx(port, rxlen, iir); 685 - break; 686 - 687 - case SC16IS7XX_IIR_CTSRTS_SRC: 688 - msr = sc16is7xx_port_read(port, SC16IS7XX_MSR_REG); 689 - uart_handle_cts_change(port, 690 - !!(msr & SC16IS7XX_MSR_DCTS_BIT)); 691 685 break; 692 686 case SC16IS7XX_IIR_THRI_SRC: 693 687 sc16is7xx_handle_tx(port); ··· 1008 1014 SC16IS7XX_EFCR_TXDISABLE_BIT, 1009 1015 0); 1010 1016 1011 - /* Enable RX, TX, CTS change interrupts */ 1012 - val = SC16IS7XX_IER_RDI_BIT | SC16IS7XX_IER_THRI_BIT | 1013 - SC16IS7XX_IER_CTSI_BIT; 1017 + /* Enable RX, TX interrupts */ 1018 + val = SC16IS7XX_IER_RDI_BIT | SC16IS7XX_IER_THRI_BIT; 1014 1019 sc16is7xx_port_write(port, SC16IS7XX_IER_REG, val); 1015 1020 1016 1021 return 0;
-2
drivers/tty/serial/serial-tegra.c
··· 206 206 static void tegra_uart_set_mctrl(struct uart_port *u, unsigned int mctrl) 207 207 { 208 208 struct tegra_uart_port *tup = to_tegra_uport(u); 209 - unsigned long mcr; 210 209 int dtr_enable; 211 210 212 - mcr = tup->mcr_shadow; 213 211 tup->rts_active = !!(mctrl & TIOCM_RTS); 214 212 set_rts(tup, tup->rts_active); 215 213
+288 -142
drivers/tty/serial/serial_core.c
··· 64 64 return !!(uport->status & UPSTAT_DCD_ENABLE); 65 65 } 66 66 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 + 96 + static inline struct uart_port *uart_port_check(struct uart_state *state) 97 + { 98 + lockdep_assert_held(&state->port.mutex); 99 + return state->uart_port; 100 + } 101 + 67 102 /* 68 103 * This routine is used by the interrupt handler to schedule processing in 69 104 * the software interrupt portion of the driver. ··· 117 82 static void uart_stop(struct tty_struct *tty) 118 83 { 119 84 struct uart_state *state = tty->driver_data; 120 - struct uart_port *port = state->uart_port; 85 + struct uart_port *port; 121 86 unsigned long flags; 122 87 123 - spin_lock_irqsave(&port->lock, flags); 124 - port->ops->stop_tx(port); 125 - spin_unlock_irqrestore(&port->lock, flags); 88 + port = uart_port_lock(state, flags); 89 + if (port) 90 + port->ops->stop_tx(port); 91 + uart_port_unlock(port, flags); 126 92 } 127 93 128 94 static void __uart_start(struct tty_struct *tty) ··· 131 95 struct uart_state *state = tty->driver_data; 132 96 struct uart_port *port = state->uart_port; 133 97 134 - if (!uart_tx_stopped(port)) 98 + if (port && !uart_tx_stopped(port)) 135 99 port->ops->start_tx(port); 136 100 } 137 101 138 102 static void uart_start(struct tty_struct *tty) 139 103 { 140 104 struct uart_state *state = tty->driver_data; 141 - struct uart_port *port = state->uart_port; 105 + struct uart_port *port; 142 106 unsigned long flags; 143 107 144 - spin_lock_irqsave(&port->lock, flags); 108 + port = uart_port_lock(state, flags); 145 109 __uart_start(tty); 146 - spin_unlock_irqrestore(&port->lock, flags); 110 + uart_port_unlock(port, flags); 147 111 } 148 112 149 113 static void ··· 170 134 static int uart_port_startup(struct tty_struct *tty, struct uart_state *state, 171 135 int init_hw) 172 136 { 173 - struct uart_port *uport = state->uart_port; 137 + struct uart_port *uport = uart_port_check(state); 174 138 unsigned long page; 175 139 int retval = 0; 176 140 ··· 232 196 struct tty_port *port = &state->port; 233 197 int retval; 234 198 235 - if (port->flags & ASYNC_INITIALIZED) 199 + if (tty_port_initialized(port)) 236 200 return 0; 237 201 238 202 /* ··· 243 207 244 208 retval = uart_port_startup(tty, state, init_hw); 245 209 if (!retval) { 246 - set_bit(ASYNCB_INITIALIZED, &port->flags); 210 + tty_port_set_initialized(port, 1); 247 211 clear_bit(TTY_IO_ERROR, &tty->flags); 248 212 } else if (retval > 0) 249 213 retval = 0; ··· 255 219 * This routine will shutdown a serial port; interrupts are disabled, and 256 220 * DTR is dropped if the hangup on close termio flag is on. Calls to 257 221 * uart_shutdown are serialised by the per-port semaphore. 222 + * 223 + * uport == NULL if uart_port has already been removed 258 224 */ 259 225 static void uart_shutdown(struct tty_struct *tty, struct uart_state *state) 260 226 { 261 - struct uart_port *uport = state->uart_port; 227 + struct uart_port *uport = uart_port_check(state); 262 228 struct tty_port *port = &state->port; 263 229 264 230 /* ··· 269 231 if (tty) 270 232 set_bit(TTY_IO_ERROR, &tty->flags); 271 233 272 - if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) { 234 + if (tty_port_initialized(port)) { 235 + tty_port_set_initialized(port, 0); 236 + 273 237 /* 274 238 * Turn off DTR and RTS early. 275 239 */ 276 - if (uart_console(uport) && tty) 240 + if (uport && uart_console(uport) && tty) 277 241 uport->cons->cflag = tty->termios.c_cflag; 278 242 279 243 if (!tty || C_HUPCL(tty)) ··· 289 249 * a DCD drop (hangup) at just the right time. Clear suspended bit so 290 250 * we don't try to resume a port that has been shutdown. 291 251 */ 292 - clear_bit(ASYNCB_SUSPENDED, &port->flags); 252 + tty_port_set_suspended(port, 0); 293 253 294 254 /* 295 255 * Free the transmit buffer page. ··· 481 441 static void uart_change_speed(struct tty_struct *tty, struct uart_state *state, 482 442 struct ktermios *old_termios) 483 443 { 484 - struct uart_port *uport = state->uart_port; 444 + struct uart_port *uport = uart_port_check(state); 485 445 struct ktermios *termios; 486 446 int hw_stopped; 487 447 ··· 526 486 static int uart_put_char(struct tty_struct *tty, unsigned char c) 527 487 { 528 488 struct uart_state *state = tty->driver_data; 529 - struct uart_port *port = state->uart_port; 489 + struct uart_port *port; 530 490 struct circ_buf *circ; 531 491 unsigned long flags; 532 492 int ret = 0; ··· 535 495 if (!circ->buf) 536 496 return 0; 537 497 538 - spin_lock_irqsave(&port->lock, flags); 539 - if (uart_circ_chars_free(circ) != 0) { 498 + port = uart_port_lock(state, flags); 499 + if (port && uart_circ_chars_free(circ) != 0) { 540 500 circ->buf[circ->head] = c; 541 501 circ->head = (circ->head + 1) & (UART_XMIT_SIZE - 1); 542 502 ret = 1; 543 503 } 544 - spin_unlock_irqrestore(&port->lock, flags); 504 + uart_port_unlock(port, flags); 545 505 return ret; 546 506 } 547 507 ··· 568 528 return -EL3HLT; 569 529 } 570 530 571 - port = state->uart_port; 572 531 circ = &state->xmit; 573 - 574 532 if (!circ->buf) 575 533 return 0; 576 534 577 - spin_lock_irqsave(&port->lock, flags); 578 - while (1) { 535 + port = uart_port_lock(state, flags); 536 + while (port) { 579 537 c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE); 580 538 if (count < c) 581 539 c = count; ··· 587 549 } 588 550 589 551 __uart_start(tty); 590 - spin_unlock_irqrestore(&port->lock, flags); 591 - 552 + uart_port_unlock(port, flags); 592 553 return ret; 593 554 } 594 555 595 556 static int uart_write_room(struct tty_struct *tty) 596 557 { 597 558 struct uart_state *state = tty->driver_data; 559 + struct uart_port *port; 598 560 unsigned long flags; 599 561 int ret; 600 562 601 - spin_lock_irqsave(&state->uart_port->lock, flags); 563 + port = uart_port_lock(state, flags); 602 564 ret = uart_circ_chars_free(&state->xmit); 603 - spin_unlock_irqrestore(&state->uart_port->lock, flags); 565 + uart_port_unlock(port, flags); 604 566 return ret; 605 567 } 606 568 607 569 static int uart_chars_in_buffer(struct tty_struct *tty) 608 570 { 609 571 struct uart_state *state = tty->driver_data; 572 + struct uart_port *port; 610 573 unsigned long flags; 611 574 int ret; 612 575 613 - spin_lock_irqsave(&state->uart_port->lock, flags); 576 + port = uart_port_lock(state, flags); 614 577 ret = uart_circ_chars_pending(&state->xmit); 615 - spin_unlock_irqrestore(&state->uart_port->lock, flags); 578 + uart_port_unlock(port, flags); 616 579 return ret; 617 580 } 618 581 ··· 632 593 return; 633 594 } 634 595 635 - port = state->uart_port; 636 596 pr_debug("uart_flush_buffer(%d) called\n", tty->index); 637 597 638 - spin_lock_irqsave(&port->lock, flags); 598 + port = uart_port_lock(state, flags); 599 + if (!port) 600 + return; 639 601 uart_circ_clear(&state->xmit); 640 602 if (port->ops->flush_buffer) 641 603 port->ops->flush_buffer(port); 642 - spin_unlock_irqrestore(&port->lock, flags); 604 + uart_port_unlock(port, flags); 643 605 tty_wakeup(tty); 644 606 } 645 607 ··· 651 611 static void uart_send_xchar(struct tty_struct *tty, char ch) 652 612 { 653 613 struct uart_state *state = tty->driver_data; 654 - struct uart_port *port = state->uart_port; 614 + struct uart_port *port; 655 615 unsigned long flags; 616 + 617 + port = uart_port_ref(state); 618 + if (!port) 619 + return; 656 620 657 621 if (port->ops->send_xchar) 658 622 port->ops->send_xchar(port, ch); ··· 667 623 port->ops->start_tx(port); 668 624 spin_unlock_irqrestore(&port->lock, flags); 669 625 } 626 + uart_port_deref(port); 670 627 } 671 628 672 629 static void uart_throttle(struct tty_struct *tty) 673 630 { 674 631 struct uart_state *state = tty->driver_data; 675 - struct uart_port *port = state->uart_port; 632 + struct uart_port *port; 676 633 upstat_t mask = 0; 634 + 635 + port = uart_port_ref(state); 636 + if (!port) 637 + return; 677 638 678 639 if (I_IXOFF(tty)) 679 640 mask |= UPSTAT_AUTOXOFF; ··· 695 646 696 647 if (mask & UPSTAT_AUTOXOFF) 697 648 uart_send_xchar(tty, STOP_CHAR(tty)); 649 + 650 + uart_port_deref(port); 698 651 } 699 652 700 653 static void uart_unthrottle(struct tty_struct *tty) 701 654 { 702 655 struct uart_state *state = tty->driver_data; 703 - struct uart_port *port = state->uart_port; 656 + struct uart_port *port; 704 657 upstat_t mask = 0; 658 + 659 + port = uart_port_ref(state); 660 + if (!port) 661 + return; 705 662 706 663 if (I_IXOFF(tty)) 707 664 mask |= UPSTAT_AUTOXOFF; ··· 724 669 725 670 if (mask & UPSTAT_AUTOXOFF) 726 671 uart_send_xchar(tty, START_CHAR(tty)); 672 + 673 + uart_port_deref(port); 727 674 } 728 675 729 - static void uart_get_info(struct tty_port *port, struct serial_struct *retinfo) 676 + static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo) 730 677 { 731 678 struct uart_state *state = container_of(port, struct uart_state, port); 732 - struct uart_port *uport = state->uart_port; 679 + struct uart_port *uport; 680 + int ret = -ENODEV; 733 681 734 682 memset(retinfo, 0, sizeof(*retinfo)); 735 683 ··· 741 683 * occur as we go 742 684 */ 743 685 mutex_lock(&port->mutex); 686 + uport = uart_port_check(state); 687 + if (!uport) 688 + goto out; 689 + 744 690 retinfo->type = uport->type; 745 691 retinfo->line = uport->line; 746 692 retinfo->port = uport->iobase; ··· 763 701 retinfo->io_type = uport->iotype; 764 702 retinfo->iomem_reg_shift = uport->regshift; 765 703 retinfo->iomem_base = (void *)(unsigned long)uport->mapbase; 704 + 705 + ret = 0; 706 + out: 766 707 mutex_unlock(&port->mutex); 708 + return ret; 767 709 } 768 710 769 711 static int uart_get_info_user(struct tty_port *port, ··· 775 709 { 776 710 struct serial_struct tmp; 777 711 778 - uart_get_info(port, &tmp); 712 + if (uart_get_info(port, &tmp) < 0) 713 + return -EIO; 779 714 780 715 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 781 716 return -EFAULT; ··· 787 720 struct uart_state *state, 788 721 struct serial_struct *new_info) 789 722 { 790 - struct uart_port *uport = state->uart_port; 723 + struct uart_port *uport = uart_port_check(state); 791 724 unsigned long new_port; 792 725 unsigned int change_irq, change_port, closing_wait; 793 726 unsigned int old_custom_divisor, close_delay; 794 727 upf_t old_flags, new_flags; 795 728 int retval = 0; 729 + 730 + if (!uport) 731 + return -EIO; 796 732 797 733 new_port = new_info->port; 798 734 if (HIGH_BITS_OFFSET) ··· 956 886 retval = 0; 957 887 if (uport->type == PORT_UNKNOWN) 958 888 goto exit; 959 - if (port->flags & ASYNC_INITIALIZED) { 889 + if (tty_port_initialized(port)) { 960 890 if (((old_flags ^ uport->flags) & UPF_SPD_MASK) || 961 891 old_custom_divisor != uport->custom_divisor) { 962 892 /* ··· 1006 936 * @tty: tty associated with the UART 1007 937 * @state: UART being queried 1008 938 * @value: returned modem value 1009 - * 1010 - * Note: uart_ioctl protects us against hangups. 1011 939 */ 1012 940 static int uart_get_lsr_info(struct tty_struct *tty, 1013 941 struct uart_state *state, unsigned int __user *value) 1014 942 { 1015 - struct uart_port *uport = state->uart_port; 943 + struct uart_port *uport = uart_port_check(state); 1016 944 unsigned int result; 1017 945 1018 946 result = uport->ops->tx_empty(uport); ··· 1033 965 { 1034 966 struct uart_state *state = tty->driver_data; 1035 967 struct tty_port *port = &state->port; 1036 - struct uart_port *uport = state->uart_port; 968 + struct uart_port *uport; 1037 969 int result = -EIO; 1038 970 1039 971 mutex_lock(&port->mutex); 1040 - if (!(tty->flags & (1 << TTY_IO_ERROR))) { 972 + uport = uart_port_check(state); 973 + if (!uport) 974 + goto out; 975 + 976 + if (!tty_io_error(tty)) { 1041 977 result = uport->mctrl; 1042 978 spin_lock_irq(&uport->lock); 1043 979 result |= uport->ops->get_mctrl(uport); 1044 980 spin_unlock_irq(&uport->lock); 1045 981 } 982 + out: 1046 983 mutex_unlock(&port->mutex); 1047 - 1048 984 return result; 1049 985 } 1050 986 ··· 1056 984 uart_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) 1057 985 { 1058 986 struct uart_state *state = tty->driver_data; 1059 - struct uart_port *uport = state->uart_port; 1060 987 struct tty_port *port = &state->port; 988 + struct uart_port *uport; 1061 989 int ret = -EIO; 1062 990 1063 991 mutex_lock(&port->mutex); 1064 - if (!(tty->flags & (1 << TTY_IO_ERROR))) { 992 + uport = uart_port_check(state); 993 + if (!uport) 994 + goto out; 995 + 996 + if (!tty_io_error(tty)) { 1065 997 uart_update_mctrl(uport, set, clear); 1066 998 ret = 0; 1067 999 } 1000 + out: 1068 1001 mutex_unlock(&port->mutex); 1069 1002 return ret; 1070 1003 } ··· 1078 1001 { 1079 1002 struct uart_state *state = tty->driver_data; 1080 1003 struct tty_port *port = &state->port; 1081 - struct uart_port *uport = state->uart_port; 1004 + struct uart_port *uport; 1005 + int ret = -EIO; 1082 1006 1083 1007 mutex_lock(&port->mutex); 1008 + uport = uart_port_check(state); 1009 + if (!uport) 1010 + goto out; 1084 1011 1085 1012 if (uport->type != PORT_UNKNOWN) 1086 1013 uport->ops->break_ctl(uport, break_state); 1087 - 1014 + ret = 0; 1015 + out: 1088 1016 mutex_unlock(&port->mutex); 1089 - return 0; 1017 + return ret; 1090 1018 } 1091 1019 1092 1020 static int uart_do_autoconfig(struct tty_struct *tty,struct uart_state *state) 1093 1021 { 1094 - struct uart_port *uport = state->uart_port; 1095 1022 struct tty_port *port = &state->port; 1023 + struct uart_port *uport; 1096 1024 int flags, ret; 1097 1025 1098 1026 if (!capable(CAP_SYS_ADMIN)) ··· 1110 1028 */ 1111 1029 if (mutex_lock_interruptible(&port->mutex)) 1112 1030 return -ERESTARTSYS; 1031 + 1032 + uport = uart_port_check(state); 1033 + if (!uport) { 1034 + ret = -EIO; 1035 + goto out; 1036 + } 1113 1037 1114 1038 ret = -EBUSY; 1115 1039 if (tty_port_users(port) == 1) { ··· 1140 1052 1141 1053 ret = uart_startup(tty, state, 1); 1142 1054 } 1055 + out: 1143 1056 mutex_unlock(&port->mutex); 1144 1057 return ret; 1145 1058 } ··· 1163 1074 * FIXME: This wants extracting into a common all driver implementation 1164 1075 * of TIOCMWAIT using tty_port. 1165 1076 */ 1166 - static int 1167 - uart_wait_modem_status(struct uart_state *state, unsigned long arg) 1077 + static int uart_wait_modem_status(struct uart_state *state, unsigned long arg) 1168 1078 { 1169 - struct uart_port *uport = state->uart_port; 1079 + struct uart_port *uport; 1170 1080 struct tty_port *port = &state->port; 1171 1081 DECLARE_WAITQUEUE(wait, current); 1172 1082 struct uart_icount cprev, cnow; ··· 1174 1086 /* 1175 1087 * note the counters on entry 1176 1088 */ 1089 + uport = uart_port_ref(state); 1090 + if (!uport) 1091 + return -EIO; 1177 1092 spin_lock_irq(&uport->lock); 1178 1093 memcpy(&cprev, &uport->icount, sizeof(struct uart_icount)); 1179 1094 uart_enable_ms(uport); ··· 1210 1119 } 1211 1120 __set_current_state(TASK_RUNNING); 1212 1121 remove_wait_queue(&port->delta_msr_wait, &wait); 1122 + uart_port_deref(uport); 1213 1123 1214 1124 return ret; 1215 1125 } ··· 1226 1134 { 1227 1135 struct uart_state *state = tty->driver_data; 1228 1136 struct uart_icount cnow; 1229 - struct uart_port *uport = state->uart_port; 1137 + struct uart_port *uport; 1230 1138 1139 + uport = uart_port_ref(state); 1140 + if (!uport) 1141 + return -EIO; 1231 1142 spin_lock_irq(&uport->lock); 1232 1143 memcpy(&cnow, &uport->icount, sizeof(struct uart_icount)); 1233 1144 spin_unlock_irq(&uport->lock); 1145 + uart_port_deref(uport); 1234 1146 1235 1147 icount->cts = cnow.cts; 1236 1148 icount->dsr = cnow.dsr; ··· 1296 1200 * Called via sys_ioctl. We can use spin_lock_irq() here. 1297 1201 */ 1298 1202 static int 1299 - uart_ioctl(struct tty_struct *tty, unsigned int cmd, 1300 - unsigned long arg) 1203 + uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) 1301 1204 { 1302 1205 struct uart_state *state = tty->driver_data; 1303 1206 struct tty_port *port = &state->port; 1207 + struct uart_port *uport; 1304 1208 void __user *uarg = (void __user *)arg; 1305 1209 int ret = -ENOIOCTLCMD; 1306 1210 ··· 1334 1238 if (ret != -ENOIOCTLCMD) 1335 1239 goto out; 1336 1240 1337 - if (tty->flags & (1 << TTY_IO_ERROR)) { 1241 + if (tty_io_error(tty)) { 1338 1242 ret = -EIO; 1339 1243 goto out; 1340 1244 } ··· 1352 1256 goto out; 1353 1257 1354 1258 mutex_lock(&port->mutex); 1259 + uport = uart_port_check(state); 1355 1260 1356 - if (tty->flags & (1 << TTY_IO_ERROR)) { 1261 + if (!uport || tty_io_error(tty)) { 1357 1262 ret = -EIO; 1358 1263 goto out_up; 1359 1264 } ··· 1370 1273 break; 1371 1274 1372 1275 case TIOCGRS485: 1373 - ret = uart_get_rs485_config(state->uart_port, uarg); 1276 + ret = uart_get_rs485_config(uport, uarg); 1374 1277 break; 1375 1278 1376 1279 case TIOCSRS485: 1377 - ret = uart_set_rs485_config(state->uart_port, uarg); 1280 + ret = uart_set_rs485_config(uport, uarg); 1378 1281 break; 1379 - default: { 1380 - struct uart_port *uport = state->uart_port; 1282 + default: 1381 1283 if (uport->ops->ioctl) 1382 1284 ret = uport->ops->ioctl(uport, cmd, arg); 1383 1285 break; 1384 - } 1385 1286 } 1386 1287 out_up: 1387 1288 mutex_unlock(&port->mutex); ··· 1390 1295 static void uart_set_ldisc(struct tty_struct *tty) 1391 1296 { 1392 1297 struct uart_state *state = tty->driver_data; 1393 - struct uart_port *uport = state->uart_port; 1298 + struct uart_port *uport; 1394 1299 1395 - if (uport->ops->set_ldisc) { 1396 - mutex_lock(&state->port.mutex); 1300 + mutex_lock(&state->port.mutex); 1301 + uport = uart_port_check(state); 1302 + if (uport && uport->ops->set_ldisc) 1397 1303 uport->ops->set_ldisc(uport, &tty->termios); 1398 - mutex_unlock(&state->port.mutex); 1399 - } 1304 + mutex_unlock(&state->port.mutex); 1400 1305 } 1401 1306 1402 1307 static void uart_set_termios(struct tty_struct *tty, 1403 1308 struct ktermios *old_termios) 1404 1309 { 1405 1310 struct uart_state *state = tty->driver_data; 1406 - struct uart_port *uport = state->uart_port; 1311 + struct uart_port *uport; 1407 1312 unsigned int cflag = tty->termios.c_cflag; 1408 1313 unsigned int iflag_mask = IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK; 1409 1314 bool sw_changed = false; 1315 + 1316 + mutex_lock(&state->port.mutex); 1317 + uport = uart_port_check(state); 1318 + if (!uport) 1319 + goto out; 1410 1320 1411 1321 /* 1412 1322 * Drivers doing software flow control also need to know ··· 1435 1335 tty->termios.c_ispeed == old_termios->c_ispeed && 1436 1336 ((tty->termios.c_iflag ^ old_termios->c_iflag) & iflag_mask) == 0 && 1437 1337 !sw_changed) { 1438 - return; 1338 + goto out; 1439 1339 } 1440 1340 1441 - mutex_lock(&state->port.mutex); 1442 1341 uart_change_speed(tty, state, old_termios); 1443 - mutex_unlock(&state->port.mutex); 1444 1342 /* reload cflag from termios; port driver may have overriden flags */ 1445 1343 cflag = tty->termios.c_cflag; 1446 1344 ··· 1448 1350 /* Handle transition away from B0 status */ 1449 1351 else if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { 1450 1352 unsigned int mask = TIOCM_DTR; 1451 - if (!(cflag & CRTSCTS) || !test_bit(TTY_THROTTLED, &tty->flags)) 1353 + if (!(cflag & CRTSCTS) || !tty_throttled(tty)) 1452 1354 mask |= TIOCM_RTS; 1453 1355 uart_set_mctrl(uport, mask); 1454 1356 } 1357 + out: 1358 + mutex_unlock(&state->port.mutex); 1455 1359 } 1456 1360 1457 1361 /* 1458 1362 * Calls to uart_close() are serialised via the tty_lock in 1459 1363 * drivers/tty/tty_io.c:tty_release() 1460 1364 * drivers/tty/tty_io.c:do_tty_hangup() 1461 - * This runs from a workqueue and can sleep for a _short_ time only. 1462 1365 */ 1463 1366 static void uart_close(struct tty_struct *tty, struct file *filp) 1464 1367 { ··· 1478 1379 return; 1479 1380 } 1480 1381 1481 - uport = state->uart_port; 1482 1382 port = &state->port; 1483 1383 pr_debug("uart_close(%d) called\n", tty->index); 1484 1384 1485 - if (!port->count || tty_port_close_start(port, tty, filp) == 0) 1385 + if (tty_port_close_start(port, tty, filp) == 0) 1486 1386 return; 1387 + 1388 + mutex_lock(&port->mutex); 1389 + uport = uart_port_check(state); 1487 1390 1488 1391 /* 1489 1392 * At this point, we stop accepting input. To do this, we 1490 1393 * disable the receive line status interrupts. 1491 1394 */ 1492 - if (port->flags & ASYNC_INITIALIZED) { 1395 + if (tty_port_initialized(port) && 1396 + !WARN(!uport, "detached port still initialized!\n")) { 1493 1397 spin_lock_irq(&uport->lock); 1494 1398 uport->ops->stop_rx(uport); 1495 1399 spin_unlock_irq(&uport->lock); ··· 1504 1402 uart_wait_until_sent(tty, uport->timeout); 1505 1403 } 1506 1404 1507 - mutex_lock(&port->mutex); 1508 1405 uart_shutdown(tty, state); 1509 1406 tty_port_tty_set(port, NULL); 1510 1407 ··· 1514 1413 if (port->close_delay) 1515 1414 msleep_interruptible(jiffies_to_msecs(port->close_delay)); 1516 1415 spin_lock_irq(&port->lock); 1517 - } else if (!uart_console(uport)) { 1416 + } else if (uport && !uart_console(uport)) { 1518 1417 spin_unlock_irq(&port->lock); 1519 1418 uart_change_pm(state, UART_PM_STATE_OFF); 1520 1419 spin_lock_irq(&port->lock); 1521 1420 } 1421 + spin_unlock_irq(&port->lock); 1422 + tty_port_set_active(port, 0); 1522 1423 1523 1424 /* 1524 1425 * Wake up anyone trying to open this port. 1525 1426 */ 1526 - clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags); 1527 - spin_unlock_irq(&port->lock); 1528 1427 wake_up_interruptible(&port->open_wait); 1529 1428 1530 1429 mutex_unlock(&port->mutex); ··· 1536 1435 static void uart_wait_until_sent(struct tty_struct *tty, int timeout) 1537 1436 { 1538 1437 struct uart_state *state = tty->driver_data; 1539 - struct uart_port *port = state->uart_port; 1438 + struct uart_port *port; 1540 1439 unsigned long char_time, expire; 1541 1440 1542 - if (port->type == PORT_UNKNOWN || port->fifosize == 0) 1441 + port = uart_port_ref(state); 1442 + if (!port || port->type == PORT_UNKNOWN || port->fifosize == 0) { 1443 + uart_port_deref(port); 1543 1444 return; 1445 + } 1544 1446 1545 1447 /* 1546 1448 * Set the check interval to be 1/5 of the estimated time to ··· 1589 1485 if (time_after(jiffies, expire)) 1590 1486 break; 1591 1487 } 1488 + uart_port_deref(port); 1592 1489 } 1593 1490 1594 1491 /* ··· 1601 1496 { 1602 1497 struct uart_state *state = tty->driver_data; 1603 1498 struct tty_port *port = &state->port; 1499 + struct uart_port *uport; 1604 1500 unsigned long flags; 1605 1501 1606 1502 pr_debug("uart_hangup(%d)\n", tty->index); 1607 1503 1608 1504 mutex_lock(&port->mutex); 1609 - if (port->flags & ASYNC_NORMAL_ACTIVE) { 1505 + uport = uart_port_check(state); 1506 + WARN(!uport, "hangup of detached port!\n"); 1507 + 1508 + if (tty_port_active(port)) { 1610 1509 uart_flush_buffer(tty); 1611 1510 uart_shutdown(tty, state); 1612 1511 spin_lock_irqsave(&port->lock, flags); 1613 1512 port->count = 0; 1614 - clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags); 1615 1513 spin_unlock_irqrestore(&port->lock, flags); 1514 + tty_port_set_active(port, 0); 1616 1515 tty_port_tty_set(port, NULL); 1617 - if (!uart_console(state->uart_port)) 1516 + if (uport && !uart_console(uport)) 1618 1517 uart_change_pm(state, UART_PM_STATE_OFF); 1619 1518 wake_up_interruptible(&port->open_wait); 1620 1519 wake_up_interruptible(&port->delta_msr_wait); ··· 1626 1517 mutex_unlock(&port->mutex); 1627 1518 } 1628 1519 1520 + /* uport == NULL if uart_port has already been removed */ 1629 1521 static void uart_port_shutdown(struct tty_port *port) 1630 1522 { 1631 1523 struct uart_state *state = container_of(port, struct uart_state, port); 1632 - struct uart_port *uport = state->uart_port; 1524 + struct uart_port *uport = uart_port_check(state); 1633 1525 1634 1526 /* 1635 1527 * clear delta_msr_wait queue to avoid mem leaks: we may free ··· 1644 1534 /* 1645 1535 * Free the IRQ and disable the port. 1646 1536 */ 1647 - uport->ops->shutdown(uport); 1537 + if (uport) 1538 + uport->ops->shutdown(uport); 1648 1539 1649 1540 /* 1650 1541 * Ensure that the IRQ handler isn't running on another CPU. 1651 1542 */ 1652 - synchronize_irq(uport->irq); 1543 + if (uport) 1544 + synchronize_irq(uport->irq); 1653 1545 } 1654 1546 1655 1547 static int uart_carrier_raised(struct tty_port *port) 1656 1548 { 1657 1549 struct uart_state *state = container_of(port, struct uart_state, port); 1658 - struct uart_port *uport = state->uart_port; 1550 + struct uart_port *uport; 1659 1551 int mctrl; 1552 + 1553 + uport = uart_port_ref(state); 1554 + /* 1555 + * Should never observe uport == NULL since checks for hangup should 1556 + * abort the tty_port_block_til_ready() loop before checking for carrier 1557 + * raised -- but report carrier raised if it does anyway so open will 1558 + * continue and not sleep 1559 + */ 1560 + if (WARN_ON(!uport)) 1561 + return 1; 1660 1562 spin_lock_irq(&uport->lock); 1661 1563 uart_enable_ms(uport); 1662 1564 mctrl = uport->ops->get_mctrl(uport); 1663 1565 spin_unlock_irq(&uport->lock); 1566 + uart_port_deref(uport); 1664 1567 if (mctrl & TIOCM_CAR) 1665 1568 return 1; 1666 1569 return 0; ··· 1682 1559 static void uart_dtr_rts(struct tty_port *port, int onoff) 1683 1560 { 1684 1561 struct uart_state *state = container_of(port, struct uart_state, port); 1685 - struct uart_port *uport = state->uart_port; 1562 + struct uart_port *uport; 1563 + 1564 + uport = uart_port_ref(state); 1565 + if (!uport) 1566 + return; 1686 1567 1687 1568 if (onoff) 1688 1569 uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS); 1689 1570 else 1690 1571 uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS); 1572 + 1573 + uart_port_deref(uport); 1691 1574 } 1692 1575 1693 1576 /* ··· 1712 1583 int retval, line = tty->index; 1713 1584 struct uart_state *state = drv->state + line; 1714 1585 struct tty_port *port = &state->port; 1586 + struct uart_port *uport; 1715 1587 1716 1588 pr_debug("uart_open(%d) called\n", line); 1717 1589 ··· 1732 1602 goto end; 1733 1603 } 1734 1604 1735 - if (!state->uart_port || state->uart_port->flags & UPF_DEAD) { 1605 + uport = uart_port_check(state); 1606 + if (!uport || uport->flags & UPF_DEAD) { 1736 1607 retval = -ENXIO; 1737 1608 goto err_unlock; 1738 1609 } 1739 1610 1740 1611 tty->driver_data = state; 1741 - state->uart_port->state = state; 1742 - state->port.low_latency = 1743 - (state->uart_port->flags & UPF_LOW_LATENCY) ? 1 : 0; 1612 + uport->state = state; 1613 + port->low_latency = (uport->flags & UPF_LOW_LATENCY) ? 1 : 0; 1744 1614 tty_port_tty_set(port, tty); 1745 1615 1746 1616 /* ··· 1779 1649 struct uart_state *state = drv->state + i; 1780 1650 struct tty_port *port = &state->port; 1781 1651 enum uart_pm_state pm_state; 1782 - struct uart_port *uport = state->uart_port; 1652 + struct uart_port *uport; 1783 1653 char stat_buf[32]; 1784 1654 unsigned int status; 1785 1655 int mmio; 1786 1656 1657 + mutex_lock(&port->mutex); 1658 + uport = uart_port_check(state); 1787 1659 if (!uport) 1788 - return; 1660 + goto out; 1789 1661 1790 1662 mmio = uport->iotype >= UPIO_MEM; 1791 1663 seq_printf(m, "%d: uart:%s %s%08llX irq:%d", ··· 1799 1667 1800 1668 if (uport->type == PORT_UNKNOWN) { 1801 1669 seq_putc(m, '\n'); 1802 - return; 1670 + goto out; 1803 1671 } 1804 1672 1805 1673 if (capable(CAP_SYS_ADMIN)) { 1806 - mutex_lock(&port->mutex); 1807 1674 pm_state = state->pm_state; 1808 1675 if (pm_state != UART_PM_STATE_ON) 1809 1676 uart_change_pm(state, UART_PM_STATE_ON); ··· 1811 1680 spin_unlock_irq(&uport->lock); 1812 1681 if (pm_state != UART_PM_STATE_ON) 1813 1682 uart_change_pm(state, pm_state); 1814 - mutex_unlock(&port->mutex); 1815 1683 1816 1684 seq_printf(m, " tx:%d rx:%d", 1817 1685 uport->icount.tx, uport->icount.rx); ··· 1848 1718 seq_putc(m, '\n'); 1849 1719 #undef STATBIT 1850 1720 #undef INFOBIT 1721 + out: 1722 + mutex_unlock(&port->mutex); 1851 1723 } 1852 1724 1853 1725 static int uart_proc_show(struct seq_file *m, void *v) ··· 2086 1954 static void uart_change_pm(struct uart_state *state, 2087 1955 enum uart_pm_state pm_state) 2088 1956 { 2089 - struct uart_port *port = state->uart_port; 1957 + struct uart_port *port = uart_port_check(state); 2090 1958 2091 1959 if (state->pm_state != pm_state) { 2092 - if (port->ops->pm) 1960 + if (port && port->ops->pm) 2093 1961 port->ops->pm(port, pm_state, state->pm_state); 2094 1962 state->pm_state = pm_state; 2095 1963 } ··· 2135 2003 2136 2004 uport->suspended = 1; 2137 2005 2138 - if (port->flags & ASYNC_INITIALIZED) { 2006 + if (tty_port_initialized(port)) { 2139 2007 const struct uart_ops *ops = uport->ops; 2140 2008 int tries; 2141 2009 2142 - set_bit(ASYNCB_SUSPENDED, &port->flags); 2143 - clear_bit(ASYNCB_INITIALIZED, &port->flags); 2010 + tty_port_set_suspended(port, 1); 2011 + tty_port_set_initialized(port, 0); 2144 2012 2145 2013 spin_lock_irq(&uport->lock); 2146 2014 ops->stop_tx(uport); ··· 2220 2088 console_start(uport->cons); 2221 2089 } 2222 2090 2223 - if (port->flags & ASYNC_SUSPENDED) { 2091 + if (tty_port_suspended(port)) { 2224 2092 const struct uart_ops *ops = uport->ops; 2225 2093 int ret; 2226 2094 ··· 2239 2107 ops->set_mctrl(uport, uport->mctrl); 2240 2108 ops->start_tx(uport); 2241 2109 spin_unlock_irq(&uport->lock); 2242 - set_bit(ASYNCB_INITIALIZED, &port->flags); 2110 + tty_port_set_initialized(port, 1); 2243 2111 } else { 2244 2112 /* 2245 2113 * Failed to resume - maybe hardware went away? ··· 2250 2118 } 2251 2119 } 2252 2120 2253 - clear_bit(ASYNCB_SUSPENDED, &port->flags); 2121 + tty_port_set_suspended(port, 0); 2254 2122 } 2255 2123 2256 2124 mutex_unlock(&port->mutex); ··· 2360 2228 { 2361 2229 struct uart_driver *drv = driver->driver_state; 2362 2230 struct uart_state *state = drv->state + line; 2231 + struct tty_port *tport; 2363 2232 struct uart_port *port; 2364 2233 int baud = 9600; 2365 2234 int bits = 8; 2366 2235 int parity = 'n'; 2367 2236 int flow = 'n'; 2368 - int ret; 2237 + int ret = 0; 2369 2238 2370 - if (!state || !state->uart_port) 2239 + if (!state) 2371 2240 return -1; 2372 2241 2373 - port = state->uart_port; 2374 - if (!(port->ops->poll_get_char && port->ops->poll_put_char)) 2375 - return -1; 2242 + tport = &state->port; 2243 + mutex_lock(&tport->mutex); 2244 + 2245 + port = uart_port_check(state); 2246 + if (!port || !(port->ops->poll_get_char && port->ops->poll_put_char)) { 2247 + ret = -1; 2248 + goto out; 2249 + } 2376 2250 2377 2251 if (port->ops->poll_init) { 2378 - struct tty_port *tport = &state->port; 2379 - 2380 - ret = 0; 2381 - mutex_lock(&tport->mutex); 2382 2252 /* 2383 - * We don't set ASYNCB_INITIALIZED as we only initialized the 2384 - * hw, e.g. state->xmit is still uninitialized. 2253 + * We don't set initialized as we only initialized the hw, 2254 + * e.g. state->xmit is still uninitialized. 2385 2255 */ 2386 - if (!test_bit(ASYNCB_INITIALIZED, &tport->flags)) 2256 + if (!tty_port_initialized(tport)) 2387 2257 ret = port->ops->poll_init(port); 2388 - mutex_unlock(&tport->mutex); 2389 - if (ret) 2390 - return ret; 2391 2258 } 2392 2259 2393 - if (options) { 2260 + if (!ret && options) { 2394 2261 uart_parse_options(options, &baud, &parity, &bits, &flow); 2395 - return uart_set_options(port, NULL, baud, parity, bits, flow); 2262 + ret = uart_set_options(port, NULL, baud, parity, bits, flow); 2396 2263 } 2397 - 2398 - return 0; 2264 + out: 2265 + mutex_unlock(&tport->mutex); 2266 + return ret; 2399 2267 } 2400 2268 2401 2269 static int uart_poll_get_char(struct tty_driver *driver, int line) ··· 2403 2271 struct uart_driver *drv = driver->driver_state; 2404 2272 struct uart_state *state = drv->state + line; 2405 2273 struct uart_port *port; 2274 + int ret = -1; 2406 2275 2407 - if (!state || !state->uart_port) 2408 - return -1; 2409 - 2410 - port = state->uart_port; 2411 - return port->ops->poll_get_char(port); 2276 + if (state) { 2277 + port = uart_port_ref(state); 2278 + if (port) 2279 + ret = port->ops->poll_get_char(port); 2280 + uart_port_deref(port); 2281 + } 2282 + return ret; 2412 2283 } 2413 2284 2414 2285 static void uart_poll_put_char(struct tty_driver *driver, int line, char ch) ··· 2420 2285 struct uart_state *state = drv->state + line; 2421 2286 struct uart_port *port; 2422 2287 2423 - if (!state || !state->uart_port) 2288 + if (!state) 2424 2289 return; 2425 2290 2426 - port = state->uart_port; 2291 + port = uart_port_ref(state); 2292 + if (!port) 2293 + return; 2427 2294 2428 2295 if (ch == '\n') 2429 2296 port->ops->poll_put_char(port, '\r'); 2430 2297 port->ops->poll_put_char(port, ch); 2298 + uart_port_deref(port); 2431 2299 } 2432 2300 #endif 2433 2301 ··· 2777 2639 } 2778 2640 2779 2641 /* Link the port to the driver state table and vice versa */ 2642 + atomic_set(&state->refcount, 1); 2643 + init_waitqueue_head(&state->remove_wait); 2780 2644 state->uart_port = uport; 2781 2645 uport->state = state; 2782 2646 ··· 2851 2711 { 2852 2712 struct uart_state *state = drv->state + uport->line; 2853 2713 struct tty_port *port = &state->port; 2714 + struct uart_port *uart_port; 2854 2715 struct tty_struct *tty; 2855 2716 int ret = 0; 2856 2717 2857 2718 BUG_ON(in_interrupt()); 2858 - 2859 - if (state->uart_port != uport) 2860 - dev_alert(uport->dev, "Removing wrong port: %p != %p\n", 2861 - state->uart_port, uport); 2862 2719 2863 2720 mutex_lock(&port_mutex); 2864 2721 ··· 2864 2727 * succeeding while we shut down the port. 2865 2728 */ 2866 2729 mutex_lock(&port->mutex); 2867 - if (!state->uart_port) { 2730 + uart_port = uart_port_check(state); 2731 + if (uart_port != uport) 2732 + dev_alert(uport->dev, "Removing wrong port: %p != %p\n", 2733 + uart_port, uport); 2734 + 2735 + if (!uart_port) { 2868 2736 mutex_unlock(&port->mutex); 2869 2737 ret = -EINVAL; 2870 2738 goto out; ··· 2906 2764 */ 2907 2765 uport->type = PORT_UNKNOWN; 2908 2766 2767 + mutex_lock(&port->mutex); 2768 + WARN_ON(atomic_dec_return(&state->refcount) < 0); 2769 + wait_event(state->remove_wait, !atomic_read(&state->refcount)); 2909 2770 state->uart_port = NULL; 2771 + mutex_unlock(&port->mutex); 2910 2772 out: 2911 2773 mutex_unlock(&port_mutex); 2912 2774
+5 -2
drivers/tty/serial/serial_mctrl_gpio.c
··· 43 43 { "rng", TIOCM_RNG, false, }, 44 44 { "rts", TIOCM_RTS, true, }, 45 45 { "dtr", TIOCM_DTR, true, }, 46 - { "out1", TIOCM_OUT1, true, }, 47 - { "out2", TIOCM_OUT2, true, }, 48 46 }; 49 47 50 48 void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl) ··· 123 125 struct uart_port *port = gpios->port; 124 126 u32 mctrl = gpios->mctrl_prev; 125 127 u32 mctrl_diff; 128 + unsigned long flags; 126 129 127 130 mctrl_gpio_get(gpios, &mctrl); 131 + 132 + spin_lock_irqsave(&port->lock, flags); 128 133 129 134 mctrl_diff = mctrl ^ gpios->mctrl_prev; 130 135 gpios->mctrl_prev = mctrl; ··· 147 146 148 147 wake_up_interruptible(&port->state->port.delta_msr_wait); 149 148 } 149 + 150 + spin_unlock_irqrestore(&port->lock, flags); 150 151 151 152 return IRQ_HANDLED; 152 153 }
-2
drivers/tty/serial/serial_mctrl_gpio.h
··· 32 32 UART_GPIO_RI = UART_GPIO_RNG, 33 33 UART_GPIO_RTS, 34 34 UART_GPIO_DTR, 35 - UART_GPIO_OUT1, 36 - UART_GPIO_OUT2, 37 35 UART_GPIO_MAX, 38 36 }; 39 37
+19 -20
drivers/tty/serial/sirfsoc_uart.c
··· 1264 1264 1265 1265 static int sirfsoc_uart_probe(struct platform_device *pdev) 1266 1266 { 1267 + struct device_node *np = pdev->dev.of_node; 1267 1268 struct sirfsoc_uart_port *sirfport; 1268 1269 struct uart_port *port; 1269 1270 struct resource *res; ··· 1277 1276 }; 1278 1277 const struct of_device_id *match; 1279 1278 1280 - match = of_match_node(sirfsoc_uart_ids, pdev->dev.of_node); 1279 + match = of_match_node(sirfsoc_uart_ids, np); 1281 1280 sirfport = devm_kzalloc(&pdev->dev, sizeof(*sirfport), GFP_KERNEL); 1282 1281 if (!sirfport) { 1283 1282 ret = -ENOMEM; 1284 1283 goto err; 1285 1284 } 1286 - sirfport->port.line = of_alias_get_id(pdev->dev.of_node, "serial"); 1285 + sirfport->port.line = of_alias_get_id(np, "serial"); 1287 1286 sirf_ports[sirfport->port.line] = sirfport; 1288 1287 sirfport->port.iotype = UPIO_MEM; 1289 1288 sirfport->port.flags = UPF_BOOT_AUTOCONF; ··· 1292 1291 port->private_data = sirfport; 1293 1292 sirfport->uart_reg = (struct sirfsoc_uart_register *)match->data; 1294 1293 1295 - sirfport->hw_flow_ctrl = of_property_read_bool(pdev->dev.of_node, 1296 - "sirf,uart-has-rtscts"); 1297 - if (of_device_is_compatible(pdev->dev.of_node, "sirf,prima2-uart") || 1298 - of_device_is_compatible(pdev->dev.of_node, "sirf,atlas7-uart")) 1294 + sirfport->hw_flow_ctrl = 1295 + of_property_read_bool(np, "uart-has-rtscts") || 1296 + of_property_read_bool(np, "sirf,uart-has-rtscts") /* deprecated */; 1297 + if (of_device_is_compatible(np, "sirf,prima2-uart") || 1298 + of_device_is_compatible(np, "sirf,atlas7-uart")) 1299 1299 sirfport->uart_reg->uart_type = SIRF_REAL_UART; 1300 - if (of_device_is_compatible(pdev->dev.of_node, 1301 - "sirf,prima2-usp-uart") || of_device_is_compatible( 1302 - pdev->dev.of_node, "sirf,atlas7-usp-uart")) { 1300 + if (of_device_is_compatible(np, "sirf,prima2-usp-uart") || 1301 + of_device_is_compatible(np, "sirf,atlas7-usp-uart")) { 1303 1302 sirfport->uart_reg->uart_type = SIRF_USP_UART; 1304 1303 if (!sirfport->hw_flow_ctrl) 1305 1304 goto usp_no_flow_control; 1306 - if (of_find_property(pdev->dev.of_node, "cts-gpios", NULL)) 1307 - sirfport->cts_gpio = of_get_named_gpio( 1308 - pdev->dev.of_node, "cts-gpios", 0); 1305 + if (of_find_property(np, "cts-gpios", NULL)) 1306 + sirfport->cts_gpio = 1307 + of_get_named_gpio(np, "cts-gpios", 0); 1309 1308 else 1310 1309 sirfport->cts_gpio = -1; 1311 - if (of_find_property(pdev->dev.of_node, "rts-gpios", NULL)) 1312 - sirfport->rts_gpio = of_get_named_gpio( 1313 - pdev->dev.of_node, "rts-gpios", 0); 1310 + if (of_find_property(np, "rts-gpios", NULL)) 1311 + sirfport->rts_gpio = 1312 + of_get_named_gpio(np, "rts-gpios", 0); 1314 1313 else 1315 1314 sirfport->rts_gpio = -1; 1316 1315 ··· 1337 1336 gpio_direction_output(sirfport->rts_gpio, 1); 1338 1337 } 1339 1338 usp_no_flow_control: 1340 - if (of_device_is_compatible(pdev->dev.of_node, "sirf,atlas7-uart") || 1341 - of_device_is_compatible(pdev->dev.of_node, "sirf,atlas7-usp-uart")) 1339 + if (of_device_is_compatible(np, "sirf,atlas7-uart") || 1340 + of_device_is_compatible(np, "sirf,atlas7-usp-uart")) 1342 1341 sirfport->is_atlas7 = true; 1343 1342 1344 - if (of_property_read_u32(pdev->dev.of_node, 1345 - "fifosize", 1346 - &port->fifosize)) { 1343 + if (of_property_read_u32(np, "fifosize", &port->fifosize)) { 1347 1344 dev_err(&pdev->dev, 1348 1345 "Unable to find fifosize in uart node.\n"); 1349 1346 ret = -EFAULT;
+6 -6
drivers/tty/serial/uartlite.c
··· 72 72 iowrite32be(val, addr); 73 73 } 74 74 75 - static struct uartlite_reg_ops uartlite_be = { 75 + static const struct uartlite_reg_ops uartlite_be = { 76 76 .in = uartlite_inbe32, 77 77 .out = uartlite_outbe32, 78 78 }; ··· 87 87 iowrite32(val, addr); 88 88 } 89 89 90 - static struct uartlite_reg_ops uartlite_le = { 90 + static const struct uartlite_reg_ops uartlite_le = { 91 91 .in = uartlite_inle32, 92 92 .out = uartlite_outle32, 93 93 }; 94 94 95 95 static inline u32 uart_in32(u32 offset, struct uart_port *port) 96 96 { 97 - struct uartlite_reg_ops *reg_ops = port->private_data; 97 + const struct uartlite_reg_ops *reg_ops = port->private_data; 98 98 99 99 return reg_ops->in(port->membase + offset); 100 100 } 101 101 102 102 static inline void uart_out32(u32 val, u32 offset, struct uart_port *port) 103 103 { 104 - struct uartlite_reg_ops *reg_ops = port->private_data; 104 + const struct uartlite_reg_ops *reg_ops = port->private_data; 105 105 106 106 reg_ops->out(val, port->membase + offset); 107 107 } ··· 345 345 return -EBUSY; 346 346 } 347 347 348 - port->private_data = &uartlite_be; 348 + port->private_data = (void *)&uartlite_be; 349 349 ret = uart_in32(ULITE_CONTROL, port); 350 350 uart_out32(ULITE_CONTROL_RST_TX, ULITE_CONTROL, port); 351 351 ret = uart_in32(ULITE_STATUS, port); 352 352 /* Endianess detection */ 353 353 if ((ret & ULITE_STATUS_TXEMPTY) != ULITE_STATUS_TXEMPTY) 354 - port->private_data = &uartlite_le; 354 + port->private_data = (void *)&uartlite_le; 355 355 356 356 return 0; 357 357 }
+3
drivers/tty/serial/ucc_uart.c
··· 1478 1478 .type = "serial", 1479 1479 .compatible = "ucc_uart", 1480 1480 }, 1481 + { 1482 + .compatible = "fsl,t1040-ucc-uart", 1483 + }, 1481 1484 {}, 1482 1485 }; 1483 1486 MODULE_DEVICE_TABLE(of, ucc_uart_match);
+32 -42
drivers/tty/synclink.c
··· 1340 1340 wake_up_interruptible(&info->status_event_wait_q); 1341 1341 wake_up_interruptible(&info->event_wait_q); 1342 1342 1343 - if ( (info->port.flags & ASYNC_CHECK_CD) && 1343 + if (tty_port_check_carrier(&info->port) && 1344 1344 (status & MISCSTATUS_DCD_LATCHED) ) { 1345 1345 if ( debug_level >= DEBUG_LEVEL_ISR ) 1346 1346 printk("%s CD now %s...", info->device_name, ··· 1361 1361 if (status & MISCSTATUS_CTS) { 1362 1362 if ( debug_level >= DEBUG_LEVEL_ISR ) 1363 1363 printk("CTS tx start..."); 1364 - if (info->port.tty) 1365 - info->port.tty->hw_stopped = 0; 1364 + info->port.tty->hw_stopped = 0; 1366 1365 usc_start_transmitter(info); 1367 1366 info->pending_bh |= BH_TRANSMIT; 1368 1367 return; ··· 1748 1749 static int startup(struct mgsl_struct * info) 1749 1750 { 1750 1751 int retval = 0; 1751 - 1752 + 1752 1753 if ( debug_level >= DEBUG_LEVEL_INFO ) 1753 1754 printk("%s(%d):mgsl_startup(%s)\n",__FILE__,__LINE__,info->device_name); 1754 - 1755 - if (info->port.flags & ASYNC_INITIALIZED) 1755 + 1756 + if (tty_port_initialized(&info->port)) 1756 1757 return 0; 1757 - 1758 + 1758 1759 if (!info->xmit_buf) { 1759 1760 /* allocate a page of memory for a transmit buffer */ 1760 1761 info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); ··· 1787 1788 1788 1789 /* program hardware for current parameters */ 1789 1790 mgsl_change_params(info); 1790 - 1791 + 1791 1792 if (info->port.tty) 1792 1793 clear_bit(TTY_IO_ERROR, &info->port.tty->flags); 1793 1794 1794 - info->port.flags |= ASYNC_INITIALIZED; 1795 - 1795 + tty_port_set_initialized(&info->port, 1); 1796 + 1796 1797 return 0; 1797 - 1798 1798 } /* end of startup() */ 1799 1799 1800 1800 /* shutdown() ··· 1806 1808 static void shutdown(struct mgsl_struct * info) 1807 1809 { 1808 1810 unsigned long flags; 1809 - 1810 - if (!(info->port.flags & ASYNC_INITIALIZED)) 1811 + 1812 + if (!tty_port_initialized(&info->port)) 1811 1813 return; 1812 1814 1813 1815 if (debug_level >= DEBUG_LEVEL_INFO) ··· 1851 1853 1852 1854 spin_unlock_irqrestore(&info->irq_spinlock,flags); 1853 1855 1854 - mgsl_release_resources(info); 1855 - 1856 + mgsl_release_resources(info); 1857 + 1856 1858 if (info->port.tty) 1857 1859 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 1858 1860 1859 - info->port.flags &= ~ASYNC_INITIALIZED; 1860 - 1861 + tty_port_set_initialized(&info->port, 0); 1861 1862 } /* end of shutdown() */ 1862 1863 1863 1864 static void mgsl_program_hw(struct mgsl_struct *info) ··· 1963 1966 } 1964 1967 info->timeout += HZ/50; /* Add .02 seconds of slop */ 1965 1968 1966 - if (cflag & CRTSCTS) 1967 - info->port.flags |= ASYNC_CTS_FLOW; 1968 - else 1969 - info->port.flags &= ~ASYNC_CTS_FLOW; 1970 - 1971 - if (cflag & CLOCAL) 1972 - info->port.flags &= ~ASYNC_CHECK_CD; 1973 - else 1974 - info->port.flags |= ASYNC_CHECK_CD; 1969 + tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); 1970 + tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); 1975 1971 1976 1972 /* process tty input control flags */ 1977 1973 ··· 2962 2972 2963 2973 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 2964 2974 (cmd != TIOCMIWAIT)) { 2965 - if (tty->flags & (1 << TTY_IO_ERROR)) 2975 + if (tty_io_error(tty)) 2966 2976 return -EIO; 2967 2977 } 2968 2978 ··· 3039 3049 /* Handle transition away from B0 status */ 3040 3050 if (!(old_termios->c_cflag & CBAUD) && C_BAUD(tty)) { 3041 3051 info->serial_signals |= SerialSignal_DTR; 3042 - if (!C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, &tty->flags)) 3052 + if (!C_CRTSCTS(tty) || !tty_throttled(tty)) 3043 3053 info->serial_signals |= SerialSignal_RTS; 3044 3054 spin_lock_irqsave(&info->irq_spinlock,flags); 3045 3055 usc_set_serial_signals(info); ··· 3081 3091 goto cleanup; 3082 3092 3083 3093 mutex_lock(&info->port.mutex); 3084 - if (info->port.flags & ASYNC_INITIALIZED) 3094 + if (tty_port_initialized(&info->port)) 3085 3095 mgsl_wait_until_sent(tty, info->timeout); 3086 3096 mgsl_flush_buffer(tty); 3087 3097 tty_ldisc_flush(tty); ··· 3119 3129 if (debug_level >= DEBUG_LEVEL_INFO) 3120 3130 printk("%s(%d):mgsl_wait_until_sent(%s) entry\n", 3121 3131 __FILE__,__LINE__, info->device_name ); 3122 - 3132 + 3123 3133 if (mgsl_paranoia_check(info, tty->name, "mgsl_wait_until_sent")) 3124 3134 return; 3125 3135 3126 - if (!(info->port.flags & ASYNC_INITIALIZED)) 3136 + if (!tty_port_initialized(&info->port)) 3127 3137 goto exit; 3128 - 3138 + 3129 3139 orig_jiffies = jiffies; 3130 - 3140 + 3131 3141 /* Set check interval to 1/5 of estimated time to 3132 3142 * send a character, and make it at least 1. The check 3133 3143 * interval should also be less than the timeout. ··· 3194 3204 shutdown(info); 3195 3205 3196 3206 info->port.count = 0; 3197 - info->port.flags &= ~ASYNC_NORMAL_ACTIVE; 3207 + tty_port_set_active(&info->port, 0); 3198 3208 info->port.tty = NULL; 3199 3209 3200 3210 wake_up_interruptible(&info->port.open_wait); ··· 3260 3270 printk("%s(%d):block_til_ready on %s\n", 3261 3271 __FILE__,__LINE__, tty->driver->name ); 3262 3272 3263 - if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ 3273 + if (filp->f_flags & O_NONBLOCK || tty_io_error(tty)) { 3264 3274 /* nonblock mode is set or port is not enabled */ 3265 - port->flags |= ASYNC_NORMAL_ACTIVE; 3275 + tty_port_set_active(port, 1); 3266 3276 return 0; 3267 3277 } 3268 3278 ··· 3287 3297 port->count--; 3288 3298 spin_unlock_irqrestore(&info->irq_spinlock, flags); 3289 3299 port->blocked_open++; 3290 - 3300 + 3291 3301 while (1) { 3292 - if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags)) 3302 + if (C_BAUD(tty) && tty_port_initialized(port)) 3293 3303 tty_port_raise_dtr_rts(port); 3294 - 3304 + 3295 3305 set_current_state(TASK_INTERRUPTIBLE); 3296 - 3297 - if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){ 3306 + 3307 + if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { 3298 3308 retval = (port->flags & ASYNC_HUP_NOTIFY) ? 3299 3309 -EAGAIN : -ERESTARTSYS; 3300 3310 break; ··· 3331 3341 __FILE__,__LINE__, tty->driver->name, port->count ); 3332 3342 3333 3343 if (!retval) 3334 - port->flags |= ASYNC_NORMAL_ACTIVE; 3344 + tty_port_set_active(port, 1); 3335 3345 3336 3346 return retval; 3337 3347
+17 -24
drivers/tty/synclinkmp.c
··· 812 812 goto cleanup; 813 813 814 814 mutex_lock(&info->port.mutex); 815 - if (info->port.flags & ASYNC_INITIALIZED) 815 + if (tty_port_initialized(&info->port)) 816 816 wait_until_sent(tty, info->timeout); 817 817 818 818 flush_buffer(tty); ··· 849 849 850 850 spin_lock_irqsave(&info->port.lock, flags); 851 851 info->port.count = 0; 852 - info->port.flags &= ~ASYNC_NORMAL_ACTIVE; 853 852 info->port.tty = NULL; 854 853 spin_unlock_irqrestore(&info->port.lock, flags); 854 + tty_port_set_active(&info->port, 1); 855 855 mutex_unlock(&info->port.mutex); 856 856 857 857 wake_up_interruptible(&info->port.open_wait); ··· 881 881 /* Handle transition away from B0 status */ 882 882 if (!(old_termios->c_cflag & CBAUD) && C_BAUD(tty)) { 883 883 info->serial_signals |= SerialSignal_DTR; 884 - if (!C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, &tty->flags)) 884 + if (!C_CRTSCTS(tty) || !tty_throttled(tty)) 885 885 info->serial_signals |= SerialSignal_RTS; 886 886 spin_lock_irqsave(&info->lock,flags); 887 887 set_signals(info); ··· 1061 1061 if (sanity_check(info, tty->name, "wait_until_sent")) 1062 1062 return; 1063 1063 1064 - if (!test_bit(ASYNCB_INITIALIZED, &info->port.flags)) 1064 + if (!tty_port_initialized(&info->port)) 1065 1065 goto exit; 1066 1066 1067 1067 orig_jiffies = jiffies; ··· 1261 1261 1262 1262 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 1263 1263 (cmd != TIOCMIWAIT)) { 1264 - if (tty->flags & (1 << TTY_IO_ERROR)) 1264 + if (tty_io_error(tty)) 1265 1265 return -EIO; 1266 1266 } 1267 1267 ··· 2463 2463 wake_up_interruptible(&info->status_event_wait_q); 2464 2464 wake_up_interruptible(&info->event_wait_q); 2465 2465 2466 - if ( (info->port.flags & ASYNC_CHECK_CD) && 2466 + if (tty_port_check_carrier(&info->port) && 2467 2467 (status & MISCSTATUS_DCD_LATCHED) ) { 2468 2468 if ( debug_level >= DEBUG_LEVEL_ISR ) 2469 2469 printk("%s CD now %s...", info->device_name, ··· 2636 2636 if ( debug_level >= DEBUG_LEVEL_INFO ) 2637 2637 printk("%s(%d):%s tx_releaseup()\n",__FILE__,__LINE__,info->device_name); 2638 2638 2639 - if (info->port.flags & ASYNC_INITIALIZED) 2639 + if (tty_port_initialized(&info->port)) 2640 2640 return 0; 2641 2641 2642 2642 if (!info->tx_buf) { ··· 2662 2662 if (info->port.tty) 2663 2663 clear_bit(TTY_IO_ERROR, &info->port.tty->flags); 2664 2664 2665 - info->port.flags |= ASYNC_INITIALIZED; 2665 + tty_port_set_initialized(&info->port, 1); 2666 2666 2667 2667 return 0; 2668 2668 } ··· 2673 2673 { 2674 2674 unsigned long flags; 2675 2675 2676 - if (!(info->port.flags & ASYNC_INITIALIZED)) 2676 + if (!tty_port_initialized(&info->port)) 2677 2677 return; 2678 2678 2679 2679 if (debug_level >= DEBUG_LEVEL_INFO) ··· 2705 2705 if (info->port.tty) 2706 2706 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 2707 2707 2708 - info->port.flags &= ~ASYNC_INITIALIZED; 2708 + tty_port_set_initialized(&info->port, 0); 2709 2709 } 2710 2710 2711 2711 static void program_hw(SLMP_INFO *info) ··· 2813 2813 } 2814 2814 info->timeout += HZ/50; /* Add .02 seconds of slop */ 2815 2815 2816 - if (cflag & CRTSCTS) 2817 - info->port.flags |= ASYNC_CTS_FLOW; 2818 - else 2819 - info->port.flags &= ~ASYNC_CTS_FLOW; 2820 - 2821 - if (cflag & CLOCAL) 2822 - info->port.flags &= ~ASYNC_CHECK_CD; 2823 - else 2824 - info->port.flags |= ASYNC_CHECK_CD; 2816 + tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); 2817 + tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); 2825 2818 2826 2819 /* process tty input control flags */ 2827 2820 ··· 3278 3285 printk("%s(%d):%s block_til_ready()\n", 3279 3286 __FILE__,__LINE__, tty->driver->name ); 3280 3287 3281 - if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ 3288 + if (filp->f_flags & O_NONBLOCK || tty_io_error(tty)) { 3282 3289 /* nonblock mode is set or port is not enabled */ 3283 3290 /* just verify that callout device is not active */ 3284 - port->flags |= ASYNC_NORMAL_ACTIVE; 3291 + tty_port_set_active(port, 1); 3285 3292 return 0; 3286 3293 } 3287 3294 ··· 3308 3315 port->blocked_open++; 3309 3316 3310 3317 while (1) { 3311 - if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags)) 3318 + if (C_BAUD(tty) && tty_port_initialized(port)) 3312 3319 tty_port_raise_dtr_rts(port); 3313 3320 3314 3321 set_current_state(TASK_INTERRUPTIBLE); 3315 3322 3316 - if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){ 3323 + if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { 3317 3324 retval = (port->flags & ASYNC_HUP_NOTIFY) ? 3318 3325 -EAGAIN : -ERESTARTSYS; 3319 3326 break; ··· 3348 3355 __FILE__,__LINE__, tty->driver->name, port->count ); 3349 3356 3350 3357 if (!retval) 3351 - port->flags |= ASYNC_NORMAL_ACTIVE; 3358 + tty_port_set_active(port, 1); 3352 3359 3353 3360 return retval; 3354 3361 }
+6 -28
drivers/tty/tty_buffer.c
··· 37 37 38 38 #define TTY_BUFFER_PAGE (((PAGE_SIZE - sizeof(struct tty_buffer)) / 2) & ~0xFF) 39 39 40 - /* 41 - * If all tty flip buffers have been processed by flush_to_ldisc() or 42 - * dropped by tty_buffer_flush(), check if the linked pty has been closed. 43 - * If so, wake the reader/poll to process 44 - */ 45 - static inline void check_other_closed(struct tty_struct *tty) 46 - { 47 - unsigned long flags, old; 48 - 49 - /* transition from TTY_OTHER_CLOSED => TTY_OTHER_DONE must be atomic */ 50 - for (flags = ACCESS_ONCE(tty->flags); 51 - test_bit(TTY_OTHER_CLOSED, &flags); 52 - ) { 53 - old = flags; 54 - __set_bit(TTY_OTHER_DONE, &flags); 55 - flags = cmpxchg(&tty->flags, old, flags); 56 - if (old == flags) { 57 - wake_up_interruptible(&tty->read_wait); 58 - break; 59 - } 60 - } 61 - } 62 - 63 40 /** 64 41 * tty_buffer_lock_exclusive - gain exclusive access to buffer 65 42 * tty_buffer_unlock_exclusive - release exclusive access ··· 230 253 231 254 if (ld && ld->ops->flush_buffer) 232 255 ld->ops->flush_buffer(tty); 233 - 234 - check_other_closed(tty); 235 256 236 257 atomic_dec(&buf->priority); 237 258 mutex_unlock(&buf->lock); ··· 497 522 */ 498 523 count = smp_load_acquire(&head->commit) - head->read; 499 524 if (!count) { 500 - if (next == NULL) { 501 - check_other_closed(tty); 525 + if (next == NULL) 502 526 break; 503 - } 504 527 buf->head = next; 505 528 tty_buffer_free(port, head); 506 529 continue; ··· 586 613 bool tty_buffer_cancel_work(struct tty_port *port) 587 614 { 588 615 return cancel_work_sync(&port->buf.work); 616 + } 617 + 618 + void tty_buffer_flush_work(struct tty_port *port) 619 + { 620 + flush_work(&port->buf.work); 589 621 }
+2 -7
drivers/tty/tty_io.c
··· 230 230 tty_free_file(file); 231 231 } 232 232 233 - 234 - #define TTY_NUMBER(tty) ((tty)->index + (tty)->driver->name_base) 235 - 236 233 /** 237 234 * tty_name - return tty naming 238 235 * @tty: tty structure ··· 1067 1070 1068 1071 if (tty_paranoia_check(tty, inode, "tty_read")) 1069 1072 return -EIO; 1070 - if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) 1073 + if (!tty || tty_io_error(tty)) 1071 1074 return -EIO; 1072 1075 1073 1076 /* We want to wait for the line discipline to sort out in this ··· 1242 1245 1243 1246 if (tty_paranoia_check(tty, file_inode(file), "tty_write")) 1244 1247 return -EIO; 1245 - if (!tty || !tty->ops->write || 1246 - (test_bit(TTY_IO_ERROR, &tty->flags))) 1248 + if (!tty || !tty->ops->write || tty_io_error(tty)) 1247 1249 return -EIO; 1248 1250 /* Short term debug to catch buggy drivers */ 1249 1251 if (tty->ops->write_room == NULL) ··· 1960 1964 * tty_lookup_driver - lookup a tty driver for a given device file 1961 1965 * @device: device number 1962 1966 * @filp: file pointer to tty 1963 - * @noctty: set if the device should not become a controlling tty 1964 1967 * @index: index for the device in the @return driver 1965 1968 * @return: driver for this inode (with increased refcount) 1966 1969 *
+2 -2
drivers/tty/tty_ioctl.c
··· 158 158 int ret = 0; 159 159 160 160 mutex_lock(&tty->throttle_mutex); 161 - if (!test_bit(TTY_THROTTLED, &tty->flags)) { 161 + if (!tty_throttled(tty)) { 162 162 if (tty->flow_change != TTY_THROTTLE_SAFE) 163 163 ret = 1; 164 164 else { ··· 189 189 int ret = 0; 190 190 191 191 mutex_lock(&tty->throttle_mutex); 192 - if (test_bit(TTY_THROTTLED, &tty->flags)) { 192 + if (tty_throttled(tty)) { 193 193 if (tty->flow_change != TTY_UNTHROTTLE_SAFE) 194 194 ret = 1; 195 195 else {
+14 -13
drivers/tty/tty_port.c
··· 204 204 if (port->console) 205 205 goto out; 206 206 207 - if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) { 207 + if (tty_port_initialized(port)) { 208 + tty_port_set_initialized(port, 0); 208 209 /* 209 210 * Drop DTR/RTS if HUPCL is set. This causes any attached 210 211 * modem to hang up the line. ··· 237 236 238 237 spin_lock_irqsave(&port->lock, flags); 239 238 port->count = 0; 240 - port->flags &= ~ASYNC_NORMAL_ACTIVE; 241 239 tty = port->tty; 242 240 if (tty) 243 241 set_bit(TTY_IO_ERROR, &tty->flags); 244 242 port->tty = NULL; 245 243 spin_unlock_irqrestore(&port->lock, flags); 244 + tty_port_set_active(port, 0); 246 245 tty_port_shutdown(port, tty); 247 246 tty_kref_put(tty); 248 247 wake_up_interruptible(&port->open_wait); ··· 365 364 366 365 /* if non-blocking mode is set we can pass directly to open unless 367 366 the port has just hung up or is in another error state */ 368 - if (tty->flags & (1 << TTY_IO_ERROR)) { 369 - port->flags |= ASYNC_NORMAL_ACTIVE; 367 + if (tty_io_error(tty)) { 368 + tty_port_set_active(port, 1); 370 369 return 0; 371 370 } 372 371 if (filp->f_flags & O_NONBLOCK) { 373 372 /* Indicate we are open */ 374 373 if (C_BAUD(tty)) 375 374 tty_port_raise_dtr_rts(port); 376 - port->flags |= ASYNC_NORMAL_ACTIVE; 375 + tty_port_set_active(port, 1); 377 376 return 0; 378 377 } 379 378 ··· 394 393 395 394 while (1) { 396 395 /* Indicate we are open */ 397 - if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags)) 396 + if (C_BAUD(tty) && tty_port_initialized(port)) 398 397 tty_port_raise_dtr_rts(port); 399 398 400 399 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); 401 400 /* Check for a hangup or uninitialised port. 402 401 Return accordingly */ 403 - if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { 402 + if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { 404 403 if (port->flags & ASYNC_HUP_NOTIFY) 405 404 retval = -EAGAIN; 406 405 else ··· 431 430 if (!tty_hung_up_p(filp)) 432 431 port->count++; 433 432 port->blocked_open--; 434 - if (retval == 0) 435 - port->flags |= ASYNC_NORMAL_ACTIVE; 436 433 spin_unlock_irqrestore(&port->lock, flags); 434 + if (retval == 0) 435 + tty_port_set_active(port, 1); 437 436 return retval; 438 437 } 439 438 EXPORT_SYMBOL(tty_port_block_til_ready); ··· 481 480 482 481 tty->closing = 1; 483 482 484 - if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { 483 + if (tty_port_initialized(port)) { 485 484 /* Don't block on a stalled port, just pull the chain */ 486 485 if (tty->flow_stopped) 487 486 tty_driver_flush_buffer(tty); ··· 515 514 spin_lock_irqsave(&port->lock, flags); 516 515 wake_up_interruptible(&port->open_wait); 517 516 } 518 - port->flags &= ~ASYNC_NORMAL_ACTIVE; 519 517 spin_unlock_irqrestore(&port->lock, flags); 518 + tty_port_set_active(port, 0); 520 519 } 521 520 EXPORT_SYMBOL(tty_port_close_end); 522 521 ··· 579 578 580 579 mutex_lock(&port->mutex); 581 580 582 - if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { 581 + if (!tty_port_initialized(port)) { 583 582 clear_bit(TTY_IO_ERROR, &tty->flags); 584 583 if (port->ops->activate) { 585 584 int retval = port->ops->activate(port, tty); ··· 588 587 return retval; 589 588 } 590 589 } 591 - set_bit(ASYNCB_INITIALIZED, &port->flags); 590 + tty_port_set_initialized(port, 1); 592 591 } 593 592 mutex_unlock(&port->mutex); 594 593 return tty_port_block_til_ready(port, tty, filp);
+1 -1
drivers/tty/vt/selection.c
··· 354 354 add_wait_queue(&vc->paste_wait, &wait); 355 355 while (sel_buffer && sel_buffer_lth > pasted) { 356 356 set_current_state(TASK_INTERRUPTIBLE); 357 - if (test_bit(TTY_THROTTLED, &tty->flags)) { 357 + if (tty_throttled(tty)) { 358 358 schedule(); 359 359 continue; 360 360 }
+61 -50
drivers/tty/vt/vt.c
··· 760 760 761 761 int vc_allocate(unsigned int currcons) /* return 0 on success */ 762 762 { 763 + struct vt_notifier_param param; 764 + struct vc_data *vc; 765 + 763 766 WARN_CONSOLE_UNLOCKED(); 764 767 765 768 if (currcons >= MAX_NR_CONSOLES) 766 769 return -ENXIO; 767 - if (!vc_cons[currcons].d) { 768 - struct vc_data *vc; 769 - struct vt_notifier_param param; 770 770 771 - /* prevent users from taking too much memory */ 772 - if (currcons >= MAX_NR_USER_CONSOLES && !capable(CAP_SYS_RESOURCE)) 773 - return -EPERM; 771 + if (vc_cons[currcons].d) 772 + return 0; 774 773 775 - /* due to the granularity of kmalloc, we waste some memory here */ 776 - /* the alloc is done in two steps, to optimize the common situation 777 - of a 25x80 console (structsize=216, screenbuf_size=4000) */ 778 - /* although the numbers above are not valid since long ago, the 779 - point is still up-to-date and the comment still has its value 780 - even if only as a historical artifact. --mj, July 1998 */ 781 - param.vc = vc = kzalloc(sizeof(struct vc_data), GFP_KERNEL); 782 - if (!vc) 774 + /* due to the granularity of kmalloc, we waste some memory here */ 775 + /* the alloc is done in two steps, to optimize the common situation 776 + of a 25x80 console (structsize=216, screenbuf_size=4000) */ 777 + /* although the numbers above are not valid since long ago, the 778 + point is still up-to-date and the comment still has its value 779 + even if only as a historical artifact. --mj, July 1998 */ 780 + param.vc = vc = kzalloc(sizeof(struct vc_data), GFP_KERNEL); 781 + if (!vc) 783 782 return -ENOMEM; 784 - vc_cons[currcons].d = vc; 785 - tty_port_init(&vc->port); 786 - INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); 787 - visual_init(vc, currcons, 1); 788 - if (!*vc->vc_uni_pagedir_loc) 783 + 784 + vc_cons[currcons].d = vc; 785 + tty_port_init(&vc->port); 786 + INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); 787 + 788 + visual_init(vc, currcons, 1); 789 + 790 + if (!*vc->vc_uni_pagedir_loc) 789 791 con_set_default_unimap(vc); 790 - vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); 791 - if (!vc->vc_screenbuf) { 792 - kfree(vc); 793 - vc_cons[currcons].d = NULL; 794 - return -ENOMEM; 795 - } 796 792 797 - /* If no drivers have overridden us and the user didn't pass a 798 - boot option, default to displaying the cursor */ 799 - if (global_cursor_default == -1) 800 - global_cursor_default = 1; 793 + vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); 794 + if (!vc->vc_screenbuf) 795 + goto err_free; 801 796 802 - vc_init(vc, vc->vc_rows, vc->vc_cols, 1); 803 - vcs_make_sysfs(currcons); 804 - atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param); 805 - } 797 + /* If no drivers have overridden us and the user didn't pass a 798 + boot option, default to displaying the cursor */ 799 + if (global_cursor_default == -1) 800 + global_cursor_default = 1; 801 + 802 + vc_init(vc, vc->vc_rows, vc->vc_cols, 1); 803 + vcs_make_sysfs(currcons); 804 + atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param); 805 + 806 806 return 0; 807 + err_free: 808 + kfree(vc); 809 + vc_cons[currcons].d = NULL; 810 + return -ENOMEM; 807 811 } 808 812 809 813 static inline int resize_screen(struct vc_data *vc, int width, int height, ··· 1039 1035 #define VT100ID "\033[?1;2c" 1040 1036 #define VT102ID "\033[?6c" 1041 1037 1042 - unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, 1038 + const unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, 1043 1039 8,12,10,14, 9,13,11,15 }; 1044 1040 1045 1041 /* the default colour table, for VGA+ colour systems */ 1046 - int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa, 1047 - 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff}; 1048 - int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa, 1049 - 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff}; 1050 - int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa, 1051 - 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff}; 1042 + unsigned char default_red[] = { 1043 + 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 1044 + 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff 1045 + }; 1046 + module_param_array(default_red, byte, NULL, S_IRUGO | S_IWUSR); 1052 1047 1053 - module_param_array(default_red, int, NULL, S_IRUGO | S_IWUSR); 1054 - module_param_array(default_grn, int, NULL, S_IRUGO | S_IWUSR); 1055 - module_param_array(default_blu, int, NULL, S_IRUGO | S_IWUSR); 1048 + unsigned char default_grn[] = { 1049 + 0x00, 0x00, 0xaa, 0x55, 0x00, 0x00, 0xaa, 0xaa, 1050 + 0x55, 0x55, 0xff, 0xff, 0x55, 0x55, 0xff, 0xff 1051 + }; 1052 + module_param_array(default_grn, byte, NULL, S_IRUGO | S_IWUSR); 1053 + 1054 + unsigned char default_blu[] = { 1055 + 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 1056 + 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff 1057 + }; 1058 + module_param_array(default_blu, byte, NULL, S_IRUGO | S_IWUSR); 1056 1059 1057 1060 /* 1058 1061 * gotoxy() must verify all boundaries, because the arguments ··· 3575 3564 struct module *owner = csw->owner; 3576 3565 struct con_driver *con_driver; 3577 3566 const char *desc; 3578 - int i, retval = 0; 3567 + int i, retval; 3579 3568 3580 3569 WARN_CONSOLE_UNLOCKED(); 3581 3570 ··· 3586 3575 con_driver = &registered_con_driver[i]; 3587 3576 3588 3577 /* already registered */ 3589 - if (con_driver->con == csw) 3578 + if (con_driver->con == csw) { 3590 3579 retval = -EBUSY; 3580 + goto err; 3581 + } 3591 3582 } 3592 3583 3593 - if (retval) 3594 - goto err; 3595 - 3596 3584 desc = csw->con_startup(); 3597 - 3598 - if (!desc) 3585 + if (!desc) { 3586 + retval = -ENODEV; 3599 3587 goto err; 3588 + } 3600 3589 3601 3590 retval = -EINVAL; 3602 3591
+2 -2
drivers/usb/class/cdc-acm.c
··· 1680 1680 if (--acm->susp_count) 1681 1681 goto out; 1682 1682 1683 - if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) { 1683 + if (tty_port_initialized(&acm->port)) { 1684 1684 rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC); 1685 1685 1686 1686 for (;;) { ··· 1710 1710 { 1711 1711 struct acm *acm = usb_get_intfdata(intf); 1712 1712 1713 - if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) 1713 + if (tty_port_initialized(&acm->port)) 1714 1714 tty_port_tty_hangup(&acm->port, false); 1715 1715 1716 1716 return acm_resume(intf);
+2 -2
drivers/usb/gadget/function/u_serial.c
··· 512 512 req = list_first_entry(queue, struct usb_request, list); 513 513 514 514 /* leave data queued if tty was rx throttled */ 515 - if (tty && test_bit(TTY_THROTTLED, &tty->flags)) 515 + if (tty && tty_throttled(tty)) 516 516 break; 517 517 518 518 switch (req->status) { ··· 579 579 * from starving ... but it's not clear that case ever happens. 580 580 */ 581 581 if (!list_empty(queue) && tty) { 582 - if (!test_bit(TTY_THROTTLED, &tty->flags)) { 582 + if (!tty_throttled(tty)) { 583 583 if (do_push) 584 584 tasklet_schedule(&port->push); 585 585 else
+1 -1
drivers/usb/misc/sisusbvga/sisusb_con.c
··· 601 601 602 602 /* interface routine */ 603 603 static int 604 - sisusbcon_set_palette(struct vc_data *c, unsigned char *table) 604 + sisusbcon_set_palette(struct vc_data *c, const unsigned char *table) 605 605 { 606 606 struct sisusb_usb_data *sisusb; 607 607 int i, j;
+2 -2
drivers/usb/serial/console.c
··· 127 127 info->port = port; 128 128 129 129 ++port->port.count; 130 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) { 130 + if (!tty_port_initialized(&port->port)) { 131 131 if (serial->type->set_termios) { 132 132 /* 133 133 * allocate a fake tty so the driver can initialize ··· 168 168 tty_port_tty_set(&port->port, NULL); 169 169 tty_kref_put(tty); 170 170 } 171 - set_bit(ASYNCB_INITIALIZED, &port->port.flags); 171 + tty_port_set_initialized(&port->port, 1); 172 172 } 173 173 /* Now that any required fake tty operations are completed restore 174 174 * the tty port count */
+1 -2
drivers/usb/serial/digi_acceleport.c
··· 699 699 /* don't set RTS if using hardware flow control */ 700 700 /* and throttling input */ 701 701 modem_signals = TIOCM_DTR; 702 - if (!C_CRTSCTS(tty) || 703 - !test_bit(TTY_THROTTLED, &tty->flags)) 702 + if (!C_CRTSCTS(tty) || !tty_throttled(tty)) 704 703 modem_signals |= TIOCM_RTS; 705 704 digi_set_modem_signals(port, modem_signals, 1); 706 705 }
+3 -3
drivers/usb/serial/generic.c
··· 473 473 * Use tty-port initialised flag to detect all hangups including the 474 474 * one generated at USB-device disconnect. 475 475 */ 476 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 476 + if (!tty_port_initialized(&port->port)) 477 477 return true; 478 478 479 479 spin_lock_irqsave(&port->lock, flags); ··· 503 503 504 504 ret = wait_event_interruptible(port->port.delta_msr_wait, 505 505 usb_serial_generic_msr_changed(tty, arg, &cnow)); 506 - if (!ret && !test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 506 + if (!ret && !tty_port_initialized(&port->port)) 507 507 ret = -EIO; 508 508 509 509 return ret; ··· 606 606 607 607 for (i = 0; i < serial->num_ports; i++) { 608 608 port = serial->port[i]; 609 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 609 + if (!tty_port_initialized(&port->port)) 610 610 continue; 611 611 612 612 if (port->bulk_in_size) {
+3 -3
drivers/usb/serial/mxuport.c
··· 503 503 return; 504 504 } 505 505 506 - if (test_bit(ASYNCB_INITIALIZED, &demux_port->port.flags)) { 506 + if (tty_port_initialized(&demux_port->port)) { 507 507 ch = data + HEADER_SIZE; 508 508 mxuport_process_read_urb_data(demux_port, ch, rcv_len); 509 509 } else { ··· 544 544 } 545 545 546 546 demux_port = serial->port[rcv_port]; 547 - if (test_bit(ASYNCB_INITIALIZED, &demux_port->port.flags)) { 547 + if (tty_port_initialized(&demux_port->port)) { 548 548 ch = data + HEADER_SIZE; 549 549 rcv_event = get_unaligned_be16(data + 2); 550 550 mxuport_process_read_urb_event(demux_port, ch, ··· 1339 1339 1340 1340 for (i = 0; i < serial->num_ports; i++) { 1341 1341 port = serial->port[i]; 1342 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 1342 + if (!tty_port_initialized(&port->port)) 1343 1343 continue; 1344 1344 1345 1345 r = usb_serial_generic_write_start(port, GFP_NOIO);
+2 -2
drivers/usb/serial/sierra.c
··· 776 776 777 777 /* 778 778 * Need to take susp_lock to make sure port is not already being 779 - * resumed, but no need to hold it due to ASYNC_INITIALIZED. 779 + * resumed, but no need to hold it due to initialized 780 780 */ 781 781 spin_lock_irq(&intfdata->susp_lock); 782 782 if (--intfdata->open_ports == 0) ··· 1039 1039 for (i = 0; i < serial->num_ports; i++) { 1040 1040 port = serial->port[i]; 1041 1041 1042 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 1042 + if (!tty_port_initialized(&port->port)) 1043 1043 continue; 1044 1044 1045 1045 err = sierra_submit_delayed_urbs(port);
+1 -1
drivers/usb/serial/usb-serial.c
··· 254 254 * 255 255 * Shut down a USB serial port. Serialized against activate by the 256 256 * tport mutex and kept to matching open/close pairs 257 - * of calls by the ASYNCB_INITIALIZED flag. 257 + * of calls by the initialized flag. 258 258 * 259 259 * Not called if tty is console. 260 260 */
+2 -2
drivers/usb/serial/usb_wwan.c
··· 464 464 465 465 /* 466 466 * Need to take susp_lock to make sure port is not already being 467 - * resumed, but no need to hold it due to ASYNC_INITIALIZED. 467 + * resumed, but no need to hold it due to initialized 468 468 */ 469 469 spin_lock_irq(&intfdata->susp_lock); 470 470 if (--intfdata->open_ports == 0) ··· 682 682 for (i = 0; i < serial->num_ports; i++) { 683 683 port = serial->port[i]; 684 684 685 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 685 + if (!tty_port_initialized(&port->port)) 686 686 continue; 687 687 688 688 portdata = usb_get_serial_port_data(port);
+2 -2
drivers/video/console/fbcon.c
··· 170 170 int height, int width); 171 171 static int fbcon_switch(struct vc_data *vc); 172 172 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch); 173 - static int fbcon_set_palette(struct vc_data *vc, unsigned char *table); 173 + static int fbcon_set_palette(struct vc_data *vc, const unsigned char *table); 174 174 static int fbcon_scrolldelta(struct vc_data *vc, int lines); 175 175 176 176 /* ··· 2652 2652 0, 16, palette_red, palette_green, palette_blue, NULL 2653 2653 }; 2654 2654 2655 - static int fbcon_set_palette(struct vc_data *vc, unsigned char *table) 2655 + static int fbcon_set_palette(struct vc_data *vc, const unsigned char *table) 2656 2656 { 2657 2657 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; 2658 2658 int i, j, k, depth;
+1 -1
drivers/video/console/mdacon.c
··· 481 481 return 1; /* redrawing needed */ 482 482 } 483 483 484 - static int mdacon_set_palette(struct vc_data *c, unsigned char *table) 484 + static int mdacon_set_palette(struct vc_data *c, const unsigned char *table) 485 485 { 486 486 return -EINVAL; 487 487 }
+1 -1
drivers/video/console/newport_con.c
··· 574 574 return newport_set_font(vc->vc_num, font); 575 575 } 576 576 577 - static int newport_set_palette(struct vc_data *vc, unsigned char *table) 577 + static int newport_set_palette(struct vc_data *vc, const unsigned char *table) 578 578 { 579 579 return -EINVAL; 580 580 }
+1 -1
drivers/video/console/sticon.c
··· 79 79 return "STI console"; 80 80 } 81 81 82 - static int sticon_set_palette(struct vc_data *c, unsigned char *table) 82 + static int sticon_set_palette(struct vc_data *c, const unsigned char *table) 83 83 { 84 84 return -EINVAL; 85 85 }
+2 -3
drivers/video/console/vgacon.c
··· 80 80 static void vgacon_cursor(struct vc_data *c, int mode); 81 81 static int vgacon_switch(struct vc_data *c); 82 82 static int vgacon_blank(struct vc_data *c, int blank, int mode_switch); 83 - static int vgacon_set_palette(struct vc_data *vc, unsigned char *table); 84 83 static int vgacon_scrolldelta(struct vc_data *c, int lines); 85 84 static int vgacon_set_origin(struct vc_data *c); 86 85 static void vgacon_save_screen(struct vc_data *c); ··· 846 847 return 0; /* Redrawing not needed */ 847 848 } 848 849 849 - static void vga_set_palette(struct vc_data *vc, unsigned char *table) 850 + static void vga_set_palette(struct vc_data *vc, const unsigned char *table) 850 851 { 851 852 int i, j; 852 853 ··· 859 860 } 860 861 } 861 862 862 - static int vgacon_set_palette(struct vc_data *vc, unsigned char *table) 863 + static int vgacon_set_palette(struct vc_data *vc, const unsigned char *table) 863 864 { 864 865 #ifdef CAN_LOAD_PALETTE 865 866 if (vga_video_type != VIDEO_TYPE_VGAC || vga_palette_blanked
+1 -1
include/linux/console.h
··· 47 47 int (*con_font_copy)(struct vc_data *, int); 48 48 int (*con_resize)(struct vc_data *, unsigned int, unsigned int, 49 49 unsigned int); 50 - int (*con_set_palette)(struct vc_data *, unsigned char *); 50 + int (*con_set_palette)(struct vc_data *, const unsigned char *); 51 51 int (*con_scrolldelta)(struct vc_data *, int); 52 52 int (*con_set_origin)(struct vc_data *); 53 53 void (*con_save_screen)(struct vc_data *);
+4 -4
include/linux/selection.h
··· 24 24 25 25 extern int console_blanked; 26 26 27 - extern unsigned char color_table[]; 28 - extern int default_red[]; 29 - extern int default_grn[]; 30 - extern int default_blu[]; 27 + extern const unsigned char color_table[]; 28 + extern unsigned char default_red[]; 29 + extern unsigned char default_grn[]; 30 + extern unsigned char default_blu[]; 31 31 32 32 extern unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed); 33 33 extern u16 screen_glyph(struct vc_data *vc, int offset);
+2
include/linux/serial_8250.h
··· 36 36 void (*set_termios)(struct uart_port *, 37 37 struct ktermios *new, 38 38 struct ktermios *old); 39 + unsigned int (*get_mctrl)(struct uart_port *); 39 40 int (*handle_irq)(struct uart_port *); 40 41 void (*pm)(struct uart_port *, unsigned int state, 41 42 unsigned old); ··· 149 148 const char *options); 150 149 extern void serial8250_do_set_termios(struct uart_port *port, 151 150 struct ktermios *termios, struct ktermios *old); 151 + extern unsigned int serial8250_do_get_mctrl(struct uart_port *port); 152 152 extern int serial8250_do_startup(struct uart_port *port); 153 153 extern void serial8250_do_shutdown(struct uart_port *port); 154 154 extern void serial8250_do_pm(struct uart_port *port, unsigned int state,
+3
include/linux/serial_core.h
··· 123 123 void (*set_termios)(struct uart_port *, 124 124 struct ktermios *new, 125 125 struct ktermios *old); 126 + unsigned int (*get_mctrl)(struct uart_port *); 126 127 void (*set_mctrl)(struct uart_port *, unsigned int); 127 128 int (*startup)(struct uart_port *port); 128 129 void (*shutdown)(struct uart_port *port); ··· 282 281 enum uart_pm_state pm_state; 283 282 struct circ_buf xmit; 284 283 284 + atomic_t refcount; 285 + wait_queue_head_t remove_wait; 285 286 struct uart_port *uart_port; 286 287 }; 287 288
+86 -3
include/linux/tty.h
··· 228 228 int count; /* Usage count */ 229 229 wait_queue_head_t open_wait; /* Open waiters */ 230 230 wait_queue_head_t delta_msr_wait; /* Modem status change */ 231 - unsigned long flags; /* TTY flags ASY_*/ 231 + unsigned long flags; /* User TTY flags ASYNC_ */ 232 + unsigned long iflags; /* Internal flags TTY_PORT_ */ 232 233 unsigned char console:1, /* port is a console */ 233 234 low_latency:1; /* optional: tune for latency */ 234 235 struct mutex mutex; /* Locking */ ··· 242 241 set to size of fifo */ 243 242 struct kref kref; /* Ref counter */ 244 243 }; 244 + 245 + /* tty_port::iflags bits -- use atomic bit ops */ 246 + #define TTY_PORT_INITIALIZED 0 /* device is initialized */ 247 + #define TTY_PORT_SUSPENDED 1 /* device is suspended */ 248 + #define TTY_PORT_ACTIVE 2 /* device is open */ 249 + 250 + /* 251 + * uart drivers: use the uart_port::status field and the UPSTAT_* defines 252 + * for s/w-based flow control steering and carrier detection status 253 + */ 254 + #define TTY_PORT_CTS_FLOW 3 /* h/w flow control enabled */ 255 + #define TTY_PORT_CHECK_CD 4 /* carrier detect enabled */ 245 256 246 257 /* 247 258 * Where all of the state associated with a tty is kept while the tty ··· 351 338 #define TTY_OTHER_CLOSED 2 /* Other side (if any) has closed */ 352 339 #define TTY_EXCLUSIVE 3 /* Exclusive open mode */ 353 340 #define TTY_DO_WRITE_WAKEUP 5 /* Call write_wakeup after queuing new */ 354 - #define TTY_OTHER_DONE 6 /* Closed pty has completed input processing */ 355 341 #define TTY_LDISC_OPEN 11 /* Line discipline is open */ 356 342 #define TTY_PTY_LOCK 16 /* pty private */ 357 343 #define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */ ··· 370 358 { 371 359 tty->flow_change = val; 372 360 smp_mb(); 361 + } 362 + 363 + static inline bool tty_io_error(struct tty_struct *tty) 364 + { 365 + return test_bit(TTY_IO_ERROR, &tty->flags); 366 + } 367 + 368 + static inline bool tty_throttled(struct tty_struct *tty) 369 + { 370 + return test_bit(TTY_THROTTLED, &tty->flags); 373 371 } 374 372 375 373 #ifdef CONFIG_TTY ··· 481 459 extern void tty_buffer_set_lock_subclass(struct tty_port *port); 482 460 extern bool tty_buffer_restart_work(struct tty_port *port); 483 461 extern bool tty_buffer_cancel_work(struct tty_port *port); 462 + extern void tty_buffer_flush_work(struct tty_port *port); 484 463 extern speed_t tty_termios_baud_rate(struct ktermios *termios); 485 464 extern speed_t tty_termios_input_baud_rate(struct ktermios *termios); 486 465 extern void tty_termios_encode_baud_rate(struct ktermios *termios, ··· 562 539 /* If the cts flow control is enabled, return true. */ 563 540 static inline bool tty_port_cts_enabled(struct tty_port *port) 564 541 { 565 - return port->flags & ASYNC_CTS_FLOW; 542 + return test_bit(TTY_PORT_CTS_FLOW, &port->iflags); 543 + } 544 + 545 + static inline void tty_port_set_cts_flow(struct tty_port *port, bool val) 546 + { 547 + if (val) 548 + set_bit(TTY_PORT_CTS_FLOW, &port->iflags); 549 + else 550 + clear_bit(TTY_PORT_CTS_FLOW, &port->iflags); 551 + } 552 + 553 + static inline bool tty_port_active(struct tty_port *port) 554 + { 555 + return test_bit(TTY_PORT_ACTIVE, &port->iflags); 556 + } 557 + 558 + static inline void tty_port_set_active(struct tty_port *port, bool val) 559 + { 560 + if (val) 561 + set_bit(TTY_PORT_ACTIVE, &port->iflags); 562 + else 563 + clear_bit(TTY_PORT_ACTIVE, &port->iflags); 564 + } 565 + 566 + static inline bool tty_port_check_carrier(struct tty_port *port) 567 + { 568 + return test_bit(TTY_PORT_CHECK_CD, &port->iflags); 569 + } 570 + 571 + static inline void tty_port_set_check_carrier(struct tty_port *port, bool val) 572 + { 573 + if (val) 574 + set_bit(TTY_PORT_CHECK_CD, &port->iflags); 575 + else 576 + clear_bit(TTY_PORT_CHECK_CD, &port->iflags); 577 + } 578 + 579 + static inline bool tty_port_suspended(struct tty_port *port) 580 + { 581 + return test_bit(TTY_PORT_SUSPENDED, &port->iflags); 582 + } 583 + 584 + static inline void tty_port_set_suspended(struct tty_port *port, bool val) 585 + { 586 + if (val) 587 + set_bit(TTY_PORT_SUSPENDED, &port->iflags); 588 + else 589 + clear_bit(TTY_PORT_SUSPENDED, &port->iflags); 590 + } 591 + 592 + static inline bool tty_port_initialized(struct tty_port *port) 593 + { 594 + return test_bit(TTY_PORT_INITIALIZED, &port->iflags); 595 + } 596 + 597 + static inline void tty_port_set_initialized(struct tty_port *port, bool val) 598 + { 599 + if (val) 600 + set_bit(TTY_PORT_INITIALIZED, &port->iflags); 601 + else 602 + clear_bit(TTY_PORT_INITIALIZED, &port->iflags); 566 603 } 567 604 568 605 extern struct tty_struct *tty_port_tty_get(struct tty_port *port);
+3
include/uapi/linux/serial_core.h
··· 267 267 /* Microchip PIC32 UART */ 268 268 #define PORT_PIC32 115 269 269 270 + /* MPS2 UART */ 271 + #define PORT_MPS2UART 116 272 + 270 273 #endif /* _UAPILINUX_SERIAL_CORE_H */
+12 -1
include/uapi/linux/tty_flags.h
··· 32 32 #define ASYNCB_MAGIC_MULTIPLIER 16 /* Use special CLK or divisor */ 33 33 #define ASYNCB_LAST_USER 16 34 34 35 - /* Internal flags used only by kernel */ 35 + /* 36 + * Internal flags used only by kernel (read-only) 37 + * 38 + * WARNING: These flags are no longer used and have been superceded by the 39 + * TTY_PORT_ flags in the iflags field (and not userspace-visible) 40 + */ 41 + #ifndef _KERNEL_ 36 42 #define ASYNCB_INITIALIZED 31 /* Serial port was initialized */ 37 43 #define ASYNCB_SUSPENDED 30 /* Serial port is suspended */ 38 44 #define ASYNCB_NORMAL_ACTIVE 29 /* Normal device is active */ ··· 49 43 #define ASYNCB_SHARE_IRQ 24 /* for multifunction cards, no longer used */ 50 44 #define ASYNCB_CONS_FLOW 23 /* flow control for console */ 51 45 #define ASYNCB_FIRST_KERNEL 22 46 + #endif 52 47 48 + /* Masks */ 53 49 #define ASYNC_HUP_NOTIFY (1U << ASYNCB_HUP_NOTIFY) 54 50 #define ASYNC_SUSPENDED (1U << ASYNCB_SUSPENDED) 55 51 #define ASYNC_FOURPORT (1U << ASYNCB_FOURPORT) ··· 80 72 #define ASYNC_SPD_WARP (ASYNC_SPD_HI|ASYNC_SPD_SHI) 81 73 #define ASYNC_SPD_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI|ASYNC_SPD_SHI) 82 74 75 + #ifndef _KERNEL_ 76 + /* These flags are no longer used (and were always masked from userspace) */ 83 77 #define ASYNC_INITIALIZED (1U << ASYNCB_INITIALIZED) 84 78 #define ASYNC_NORMAL_ACTIVE (1U << ASYNCB_NORMAL_ACTIVE) 85 79 #define ASYNC_BOOT_AUTOCONF (1U << ASYNCB_BOOT_AUTOCONF) ··· 91 81 #define ASYNC_SHARE_IRQ (1U << ASYNCB_SHARE_IRQ) 92 82 #define ASYNC_CONS_FLOW (1U << ASYNCB_CONS_FLOW) 93 83 #define ASYNC_INTERNAL_FLAGS (~((1U << ASYNCB_FIRST_KERNEL) - 1)) 84 + #endif 94 85 95 86 #endif
-1
include/uapi/linux/vt.h
··· 8 8 */ 9 9 #define MIN_NR_CONSOLES 1 /* must be at least 1 */ 10 10 #define MAX_NR_CONSOLES 63 /* serial lines start at 64 */ 11 - #define MAX_NR_USER_CONSOLES 63 /* must be root to allocate above this */ 12 11 /* Note: the ioctl VT_GETSTATE does not work for 13 12 consoles 16 and higher (since it returns a short) */ 14 13
+16 -15
net/irda/ircomm/ircomm_tty.c
··· 220 220 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); 221 221 222 222 /* Check if already open */ 223 - if (test_and_set_bit(ASYNCB_INITIALIZED, &self->port.flags)) { 223 + if (tty_port_initialized(&self->port)) { 224 224 pr_debug("%s(), already open so break out!\n", __func__); 225 225 return 0; 226 226 } 227 + tty_port_set_initialized(&self->port, 1); 227 228 228 229 /* Register with IrCOMM */ 229 230 irda_notify_init(&notify); ··· 258 257 259 258 return 0; 260 259 err: 261 - clear_bit(ASYNCB_INITIALIZED, &self->port.flags); 260 + tty_port_set_initialized(&self->port, 0); 262 261 return ret; 263 262 } 264 263 ··· 281 280 * If non-blocking mode is set, or the port is not enabled, 282 281 * then make the check up front and then exit. 283 282 */ 284 - if (test_bit(TTY_IO_ERROR, &tty->flags)) { 285 - port->flags |= ASYNC_NORMAL_ACTIVE; 283 + if (tty_io_error(tty)) { 284 + tty_port_set_active(port, 1); 286 285 return 0; 287 286 } 288 287 ··· 290 289 /* nonblock mode is set */ 291 290 if (C_BAUD(tty)) 292 291 tty_port_raise_dtr_rts(port); 293 - port->flags |= ASYNC_NORMAL_ACTIVE; 292 + tty_port_set_active(port, 1); 294 293 pr_debug("%s(), O_NONBLOCK requested!\n", __func__); 295 294 return 0; 296 295 } ··· 319 318 spin_unlock_irqrestore(&port->lock, flags); 320 319 321 320 while (1) { 322 - if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags)) 321 + if (C_BAUD(tty) && tty_port_initialized(port)) 323 322 tty_port_raise_dtr_rts(port); 324 323 325 324 set_current_state(TASK_INTERRUPTIBLE); 326 325 327 - if (tty_hung_up_p(filp) || 328 - !test_bit(ASYNCB_INITIALIZED, &port->flags)) { 326 + if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { 329 327 retval = (port->flags & ASYNC_HUP_NOTIFY) ? 330 328 -EAGAIN : -ERESTARTSYS; 331 329 break; ··· 365 365 __FILE__, __LINE__, tty->driver->name, port->count); 366 366 367 367 if (!retval) 368 - port->flags |= ASYNC_NORMAL_ACTIVE; 368 + tty_port_set_active(port, 1); 369 369 370 370 return retval; 371 371 } ··· 876 876 IRDA_ASSERT(self != NULL, return;); 877 877 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 878 878 879 - if (!test_and_clear_bit(ASYNCB_INITIALIZED, &self->port.flags)) 879 + if (!tty_port_initialized(&self->port)) 880 880 return; 881 + tty_port_set_initialized(&self->port, 0); 881 882 882 883 ircomm_tty_detach_cable(self); 883 884 ··· 926 925 ircomm_tty_shutdown(self); 927 926 928 927 spin_lock_irqsave(&port->lock, flags); 929 - port->flags &= ~ASYNC_NORMAL_ACTIVE; 930 928 if (port->tty) { 931 929 set_bit(TTY_IO_ERROR, &port->tty->flags); 932 930 tty_kref_put(port->tty); ··· 933 933 port->tty = NULL; 934 934 port->count = 0; 935 935 spin_unlock_irqrestore(&port->lock, flags); 936 + tty_port_set_active(port, 0); 936 937 937 938 wake_up_interruptible(&port->open_wait); 938 939 } ··· 1000 999 if (status & IRCOMM_DCE_DELTA_ANY) { 1001 1000 /*wake_up_interruptible(&self->delta_msr_wait);*/ 1002 1001 } 1003 - if ((self->port.flags & ASYNC_CHECK_CD) && (status & IRCOMM_DELTA_CD)) { 1002 + if (tty_port_check_carrier(&self->port) && (status & IRCOMM_DELTA_CD)) { 1004 1003 pr_debug("%s(), ircomm%d CD now %s...\n", __func__ , self->line, 1005 1004 (status & IRCOMM_CD) ? "on" : "off"); 1006 1005 ··· 1256 1255 seq_printf(m, "%cASYNC_CTS_FLOW", sep); 1257 1256 sep = '|'; 1258 1257 } 1259 - if (self->port.flags & ASYNC_CHECK_CD) { 1258 + if (tty_port_check_carrier(&self->port)) { 1260 1259 seq_printf(m, "%cASYNC_CHECK_CD", sep); 1261 1260 sep = '|'; 1262 1261 } 1263 - if (self->port.flags & ASYNC_INITIALIZED) { 1262 + if (tty_port_initialized(&self->port)) { 1264 1263 seq_printf(m, "%cASYNC_INITIALIZED", sep); 1265 1264 sep = '|'; 1266 1265 } ··· 1268 1267 seq_printf(m, "%cASYNC_LOW_LATENCY", sep); 1269 1268 sep = '|'; 1270 1269 } 1271 - if (self->port.flags & ASYNC_NORMAL_ACTIVE) { 1270 + if (tty_port_active(&self->port)) { 1272 1271 seq_printf(m, "%cASYNC_NORMAL_ACTIVE", sep); 1273 1272 sep = '|'; 1274 1273 }
+1 -1
net/irda/ircomm/ircomm_tty_attach.c
··· 968 968 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); 969 969 ircomm_tty_start_watchdog_timer(self, 3*HZ); 970 970 971 - if (self->port.flags & ASYNC_CHECK_CD) { 971 + if (tty_port_check_carrier(&self->port)) { 972 972 /* Drop carrier */ 973 973 self->settings.dce = IRCOMM_DELTA_CD; 974 974 ircomm_tty_check_modem_status(self);
+7 -11
net/irda/ircomm/ircomm_tty_ioctl.c
··· 86 86 ircomm_param_request(self, IRCOMM_DATA_RATE, FALSE); 87 87 88 88 /* CTS flow control flag and modem status interrupts */ 89 + tty_port_set_cts_flow(&self->port, cflag & CRTSCTS); 89 90 if (cflag & CRTSCTS) { 90 - self->port.flags |= ASYNC_CTS_FLOW; 91 91 self->settings.flow_control |= IRCOMM_RTS_CTS_IN; 92 92 /* This got me. Bummer. Jean II */ 93 93 if (self->service_type == IRCOMM_3_WIRE_RAW) 94 94 net_warn_ratelimited("%s(), enabling RTS/CTS on link that doesn't support it (3-wire-raw)\n", 95 95 __func__); 96 96 } else { 97 - self->port.flags &= ~ASYNC_CTS_FLOW; 98 97 self->settings.flow_control &= ~IRCOMM_RTS_CTS_IN; 99 98 } 100 - if (cflag & CLOCAL) 101 - self->port.flags &= ~ASYNC_CHECK_CD; 102 - else 103 - self->port.flags |= ASYNC_CHECK_CD; 99 + tty_port_set_check_carrier(&self->port, ~cflag & CLOCAL); 104 100 #if 0 105 101 /* 106 102 * Set up parity check flag ··· 162 166 /* Handle transition away from B0 status */ 163 167 if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { 164 168 self->settings.dte |= IRCOMM_DTR; 165 - if (!C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, &tty->flags)) 169 + if (!C_CRTSCTS(tty) || !tty_throttled(tty)) 166 170 self->settings.dte |= IRCOMM_RTS; 167 171 ircomm_param_request(self, IRCOMM_DTE, TRUE); 168 172 } ··· 186 190 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; 187 191 unsigned int result; 188 192 189 - if (tty->flags & (1 << TTY_IO_ERROR)) 193 + if (tty_io_error(tty)) 190 194 return -EIO; 191 195 192 196 result = ((self->settings.dte & IRCOMM_RTS) ? TIOCM_RTS : 0) ··· 209 213 { 210 214 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; 211 215 212 - if (tty->flags & (1 << TTY_IO_ERROR)) 216 + if (tty_io_error(tty)) 213 217 return -EIO; 214 218 215 219 IRDA_ASSERT(self != NULL, return -1;); ··· 324 328 325 329 check_and_exit: 326 330 327 - if (self->flags & ASYNC_INITIALIZED) { 331 + if (tty_port_initialized(self)) { 328 332 if (((old_state.flags & ASYNC_SPD_MASK) != 329 333 (self->flags & ASYNC_SPD_MASK)) || 330 334 (old_driver.custom_divisor != driver->custom_divisor)) { ··· 358 362 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 359 363 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) && 360 364 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { 361 - if (tty->flags & (1 << TTY_IO_ERROR)) 365 + if (tty_io_error(tty)) 362 366 return -EIO; 363 367 } 364 368