History

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

Pull tty/serial driver updates from Greg KH: "Here's the big tty/serial driver update for 3.19-rc1. There are a number of TTY core changes/fixes in here from Peter Hurley that have all been teted in linux-next for a long time now. There are also the normal serial driver updates as well, full details in the changelog below" * tag 'tty-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (219 commits) serial: pxa: hold port.lock when reporting modem line changes tty-hvsi_lib: Deletion of an unnecessary check before the function call "tty_kref_put" tty: Deletion of unnecessary checks before two function calls n_tty: Fix read_buf race condition, increment read_head after pushing data serial: of-serial: add PM suspend/resume support Revert "serial: of-serial: add PM suspend/resume support" Revert "serial: of-serial: fix up PM ops on no_console_suspend and port type" serial: 8250: don't attempt a trylock if in sysrq serial: core: Add big-endian iotype serial: samsung: use port->fifosize instead of hardcoded values serial: samsung: prefer to use fifosize from driver data serial: samsung: fix style problems serial: samsung: wait for transfer completion before clock disable serial: icom: fix error return code serial: tegra: clean up tty-flag assignments serial: Fix io address assign flow with Fintek PCI-to-UART Product serial: mxs-auart: fix tx_empty against shift register serial: mxs-auart: fix gpio change detection on interrupt serial: mxs-auart: Fix mxs_auart_set_ldisc() serial: 8250_dw: Use 64-bit access for OCTEON. ...

Linus Torvalds committed 11 years ago

Commit 37da7bb2 parents e7cf773 dd63af1102 files · +4755 −1596Browse files

Unified · Split

102 files
  1. Documentation/devicetree/bindings/serial/bcm63xx-uart.txt +30 −0
  2. Documentation/devicetree/bindings/serial/fsl-mxs-auart.txt +9 −1
  3. Documentation/devicetree/bindings/serial/of-serial.txt +1 −0
  4. Documentation/devicetree/bindings/serial/pl011.txt +16 −4
  5. Documentation/devicetree/bindings/serial/qcom,msm-uartdm.txt +47 −22
  6. Documentation/devicetree/bindings/serial/renesas,sci-serial.txt +7 −2
  7. Documentation/devicetree/bindings/serial/sirf-uart.txt +15 −1
  8. Documentation/serial/driver +4 −2
  9. MAINTAINERS +6 −0
  10. arch/blackfin/include/asm/bfin_serial.h +3 −4
  11. arch/um/drivers/line.c +5 −1
  12. drivers/parport/parport_serial.c +10 −0
  13. drivers/tty/ehv_bytechan.c +2 −2
  14. drivers/tty/goldfish.c +3 −3
  15. drivers/tty/hvc/hvcs.c +1 −1
  16. drivers/tty/hvc/hvsi_lib.c +1 −2
  17. drivers/tty/ipwireless/hardware.c +6 −6
  18. drivers/tty/isicom.c +7 −7
  19. drivers/tty/n_tty.c +37 −44
  20. drivers/tty/pty.c +52 −35
  21. drivers/tty/serial/8250/8250.h +8 −1
  22. drivers/tty/serial/8250/8250_core.c +56 −56
  23. drivers/tty/serial/8250/8250_dma.c +25 −14
  24. drivers/tty/serial/8250/8250_dw.c +55 −14
  25. drivers/tty/serial/8250/8250_em.c +1 −3
  26. drivers/tty/serial/8250/8250_fintek.c +5 −3
  27. drivers/tty/serial/8250/8250_hp300.c +0 −4
  28. drivers/tty/serial/8250/8250_mtk.c +2 −2
  29. drivers/tty/serial/8250/8250_omap.c +1281 −0
  30. drivers/tty/serial/8250/8250_pci.c +153 −45
  31. drivers/tty/serial/8250/Kconfig +10 −1
  32. drivers/tty/serial/8250/Makefile +1 −0
  33. drivers/tty/serial/Kconfig +14 −10
  34. drivers/tty/serial/amba-pl010.c +45 −15
  35. drivers/tty/serial/amba-pl011.c +43 −5
  36. drivers/tty/serial/ar933x_uart.c +20 −10
  37. drivers/tty/serial/atmel_serial.c +110 −120
  38. drivers/tty/serial/bcm63xx_uart.c +33 −22
  39. drivers/tty/serial/bfin_sport_uart.c +3 −2
  40. drivers/tty/serial/bfin_uart.c +3 −2
  41. drivers/tty/serial/clps711x.c +3 −2
  42. drivers/tty/serial/cpm_uart/cpm_uart_core.c +32 −16
  43. drivers/tty/serial/crisv10.c +0 −12
  44. drivers/tty/serial/crisv10.h +0 −1
  45. drivers/tty/serial/earlycon.c +1 −1
  46. drivers/tty/serial/fsl_lpuart.c +17 −8
  47. drivers/tty/serial/icom.c +3 −1
  48. drivers/tty/serial/imx.c +75 −78
  49. drivers/tty/serial/ip22zilog.c +12 −6
  50. drivers/tty/serial/jsm/Makefile +1 −1
  51. drivers/tty/serial/jsm/jsm.h +79 −22
  52. drivers/tty/serial/jsm/jsm_cls.c +982 −0
  53. drivers/tty/serial/jsm/jsm_driver.c +120 −36
  54. drivers/tty/serial/jsm/jsm_neo.c +14 −22
  55. drivers/tty/serial/jsm/jsm_tty.c +23 −16
  56. drivers/tty/serial/lantiq.c +3 −1
  57. drivers/tty/serial/m32r_sio.c +28 −14
  58. drivers/tty/serial/max310x.c +31 −46
  59. drivers/tty/serial/mcf.c +8 −34
  60. drivers/tty/serial/men_z135_uart.c +1 −0
  61. drivers/tty/serial/mfd.c +1 −1
  62. drivers/tty/serial/mpsc.c +26 −13
  63. drivers/tty/serial/mrst_max3110.c +12 −15
  64. drivers/tty/serial/msm_serial.c +58 −53
  65. drivers/tty/serial/msm_serial.h +2 −0
  66. drivers/tty/serial/mxs-auart.c +233 −17
  67. drivers/tty/serial/of_serial.c +74 −1
  68. drivers/tty/serial/omap-serial.c +35 −58
  69. drivers/tty/serial/pmac_zilog.c +6 −3
  70. drivers/tty/serial/pnx8xxx_uart.c +32 −16
  71. drivers/tty/serial/pxa.c +3 −0
  72. drivers/tty/serial/sa1100.c +30 −15
  73. drivers/tty/serial/samsung.c +38 −52
  74. drivers/tty/serial/sc16is7xx.c +12 −45
  75. drivers/tty/serial/serial-tegra.c +19 −17
  76. drivers/tty/serial/serial_core.c +89 −27
  77. drivers/tty/serial/sh-sci.c +1 −4
  78. drivers/tty/serial/sirfsoc_uart.c +27 −7
  79. drivers/tty/serial/sirfsoc_uart.h +4 −0
  80. drivers/tty/serial/sunsab.c +24 −12
  81. drivers/tty/serial/sunsu.c +26 −13
  82. drivers/tty/serial/sunzilog.c +16 −8
  83. drivers/tty/serial/timbuart.c +2 −0
  84. drivers/tty/serial/xilinx_uartps.c +21 −1
  85. drivers/tty/tty_buffer.c +8 −2
  86. drivers/tty/tty_io.c +223 −217
  87. drivers/tty/tty_ioctl.c +6 −32
  88. drivers/tty/tty_ldisc.c +56 −55
  89. drivers/tty/tty_mutex.c +21 −28
  90. drivers/tty/tty_port.c +4 −6
  91. drivers/tty/vt/keyboard.c +3 −3
  92. drivers/tty/vt/vt.c +14 −8
  93. include/linux/kernel.h +0 −3
  94. include/linux/serial_8250.h +0 −3
  95. include/linux/serial_bcm63xx.h +0 −2
  96. include/linux/serial_core.h +44 −23
  97. include/linux/tty.h +6 −22
  98. include/uapi/linux/serial_core.h +2 −1
  99. include/uapi/linux/serial_reg.h +1 −0
  100. include/uapi/linux/tty_flags.h +13 −6
  101. include/uapi/linux/vt.h +0 −3
  102. kernel/exit.c +0 −21
Documentation/devicetree/bindings/serial/bcm63xx-uart.txt+30−0
@@ -0,0 +1,30 @@
1+* BCM63xx UART
2+
3+Required properties:
4+
5+- compatible: "brcm,bcm6345-uart"
6+
7+- reg: The base address of the UART register bank.
8+
9+- interrupts: A single interrupt specifier.
10+
11+- clocks: Clock driving the hardware; used to figure out the baud rate
12+ divisor.
13+
14+Example:
15+
16+ uart0: serial@14e00520 {
17+ compatible = "brcm,bcm6345-uart";
18+ reg = <0x14e00520 0x18>;
19+ interrupt-parent = <&periph_intc>;
20+ interrupts = <2>;
21+ clocks = <&periph_clk>;
22+ };
23+
24+ clocks {
25+ periph_clk: periph_clk@0 {
26+ compatible = "fixed-clock";
27+ #clock-cells = <0>;
28+ clock-frequency = <54000000>;
29+ };
30+ };
Documentation/devicetree/bindings/serial/fsl-mxs-auart.txt+9−1
@@ -11,8 +11,13 @@ Required properties: · 10 unmodified lines
1111 - dma-names: "rx" for RX channel, "tx" for TX channel.
1212
1313 Optional properties:
14−- fsl,uart-has-rtscts : Indicate the UART has RTS and CTS lines,
14+- fsl,uart-has-rtscts : Indicate the UART has RTS and CTS lines
15+ for hardware flow control,
1516 it also means you enable the DMA support for this UART.
17+- {rts,cts,dtr,dsr,rng,dcd}-gpios: specify a GPIO for RTS/CTS/DTR/DSR/RI/DCD
18+ line respectively. It will use specified PIO instead of the peripheral
19+ function pin for the USART feature.
20+ If unsure, don't specify this property.
1621
1722 Example:
1823 auart0: serial@8006a000 {
@@ -21,6 +26,9 @@ auart0: serial@8006a000 { · 2 unmodified lines
2126 interrupts = <112>;
2227 dmas = <&dma_apbx 8>, <&dma_apbx 9>;
2328 dma-names = "rx", "tx";
29+ cts-gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
30+ dsr-gpios = <&gpio1 16 GPIO_ACTIVE_LOW>;
31+ dcd-gpios = <&gpio1 17 GPIO_ACTIVE_LOW>;
2432 };
2533
2634 Note: Each auart port should have an alias correctly numbered in "aliases"
Documentation/devicetree/bindings/serial/of-serial.txt+1−0
@@ -10,6 +10,7 @@ Required properties: · 9 unmodified lines
1010 - "ns16850"
1111 - "nvidia,tegra20-uart"
1212 - "nxp,lpc3220-uart"
13+ - "ralink,rt2880-uart"
1314 - "ibm,qpace-nwp-serial"
1415 - "altr,16550-FIFO32"
1516 - "altr,16550-FIFO64"
Documentation/devicetree/bindings/serial/pl011.txt+16−4
@@ -6,23 +6,35 @@ Required properties: · 5 unmodified lines
66 - interrupts: exactly one interrupt specifier
77
88 Optional properties:
9−- pinctrl: When present, must have one state named "default",
9+- pinctrl:
10+ When present, must have one state named "default",
1011 and may contain a second name named "sleep". The former
1112 state sets up pins for ordinary operation whereas
1213 the latter state will put the associated pins to sleep
1314 when the UART is unused
14−- clocks: When present, the first clock listed must correspond to
15+- clocks:
16+ When present, the first clock listed must correspond to
1517 the clock named UARTCLK on the IP block, i.e. the clock
1618 to the external serial line, whereas the second clock
1719 must correspond to the PCLK clocking the internal logic
1820 of the block. Just listing one clock (the first one) is
1921 deprecated.
20−- clocks-names: When present, the first clock listed must be named
22+- clocks-names:
23+ When present, the first clock listed must be named
2124 "uartclk" and the second clock listed must be named
2225 "apb_pclk"
23−- dmas: When present, may have one or two dma channels.
26+- dmas:
27+ When present, may have one or two dma channels.
2428 The first one must be named "rx", the second one
2529 must be named "tx".
30+- auto-poll:
31+ Enables polling when using RX DMA.
32+- poll-rate-ms:
33+ Rate at which poll occurs when auto-poll is set,
34+ default 100ms.
35+- poll-timeout-ms:
36+ Poll timeout when auto-poll is set, default
37+ 3000ms.
2638
2739 See also bindings/arm/primecell.txt
2840
Documentation/devicetree/bindings/serial/qcom,msm-uartdm.txt+47−22
@@ -27,27 +27,52 @@ Optional properties: · 26 unmodified lines
2727 - dmas: Should contain dma specifiers for transmit and receive channels
2828 - dma-names: Should contain "tx" for transmit and "rx" for receive channels
2929
30+Note: Aliases may be defined to ensure the correct ordering of the UARTs.
31+The alias serialN will result in the UART being assigned port N. If any
32+serialN alias exists, then an alias must exist for each enabled UART. The
33+serialN aliases should be in a .dts file instead of in a .dtsi file.
34+
3035 Examples:
3136
32−A uartdm v1.4 device with dma capabilities.
33−
34−serial@f991e000 {
35− compatible = "qcom,msm-uartdm-v1.4", "qcom,msm-uartdm";
36− reg = <0xf991e000 0x1000>;
37− interrupts = <0 108 0x0>;
38− clocks = <&blsp1_uart2_apps_cxc>, <&blsp1_ahb_cxc>;
39− clock-names = "core", "iface";
40− dmas = <&dma0 0>, <&dma0 1>;
41− dma-names = "tx", "rx";
42−};
43−
44−A uartdm v1.3 device without dma capabilities and part of a GSBI complex.
45−
46−serial@19c40000 {
47− compatible = "qcom,msm-uartdm-v1.3", "qcom,msm-uartdm";
48− reg = <0x19c40000 0x1000>,
49− <0x19c00000 0x1000>;
50− interrupts = <0 195 0x0>;
51− clocks = <&gsbi5_uart_cxc>, <&gsbi5_ahb_cxc>;
52− clock-names = "core", "iface";
53−};
37+- A uartdm v1.4 device with dma capabilities.
38+
39+ serial@f991e000 {
40+ compatible = "qcom,msm-uartdm-v1.4", "qcom,msm-uartdm";
41+ reg = <0xf991e000 0x1000>;
42+ interrupts = <0 108 0x0>;
43+ clocks = <&blsp1_uart2_apps_cxc>, <&blsp1_ahb_cxc>;
44+ clock-names = "core", "iface";
45+ dmas = <&dma0 0>, <&dma0 1>;
46+ dma-names = "tx", "rx";
47+ };
48+
49+- A uartdm v1.3 device without dma capabilities and part of a GSBI complex.
50+
51+ serial@19c40000 {
52+ compatible = "qcom,msm-uartdm-v1.3", "qcom,msm-uartdm";
53+ reg = <0x19c40000 0x1000>,
54+ <0x19c00000 0x1000>;
55+ interrupts = <0 195 0x0>;
56+ clocks = <&gsbi5_uart_cxc>, <&gsbi5_ahb_cxc>;
57+ clock-names = "core", "iface";
58+ };
59+
60+- serialN alias.
61+
62+ aliases {
63+ serial0 = &uarta;
64+ serial1 = &uartc;
65+ serial2 = &uartb;
66+ };
67+
68+ uarta: serial@12490000 {
69+ status = "ok";
70+ };
71+
72+ uartb: serial@16340000 {
73+ status = "ok";
74+ };
75+
76+ uartc: serial@1a240000 {
77+ status = "ok";
78+ };
Documentation/devicetree/bindings/serial/renesas,sci-serial.txt+7−2
@@ -4,8 +4,7 @@ Required properties: · 3 unmodified lines
44
55 - compatible: Must contain one of the following:
66
7− - "renesas,scifa-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFA compatible UART.
8− - "renesas,scifb-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFB compatible UART.
7+ - "renesas,scif-r7s72100" for R7S72100 (RZ/A1H) SCIF compatible UART.
98 - "renesas,scifa-r8a73a4" for R8A73A4 (R-Mobile APE6) SCIFA compatible UART.
109 - "renesas,scifb-r8a73a4" for R8A73A4 (R-Mobile APE6) SCIFB compatible UART.
1110 - "renesas,scifa-r8a7740" for R8A7740 (R-Mobile A1) SCIFA compatible UART.
@@ -20,6 +19,12 @@ Required properties: · 8 unmodified lines
2019 - "renesas,scifa-r8a7791" for R8A7791 (R-Car M2) SCIFA compatible UART.
2120 - "renesas,scifb-r8a7791" for R8A7791 (R-Car M2) SCIFB compatible UART.
2221 - "renesas,hscif-r8a7791" for R8A7791 (R-Car M2) HSCIF compatible UART.
22+ - "renesas,scif-r8a7794" for R8A7794 (R-Car E2) SCIF compatible UART.
23+ - "renesas,scifa-r8a7794" for R8A7794 (R-Car E2) SCIFA compatible UART.
24+ - "renesas,scifb-r8a7794" for R8A7794 (R-Car E2) SCIFB compatible UART.
25+ - "renesas,hscif-r8a7794" for R8A7794 (R-Car E2) HSCIF compatible UART.
26+ - "renesas,scifa-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFA compatible UART.
27+ - "renesas,scifb-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFB compatible UART.
2328 - "renesas,scif" for generic SCIF compatible UART.
2429 - "renesas,scifa" for generic SCIFA compatible UART.
2530 - "renesas,scifb" for generic SCIFB compatible UART.
Documentation/devicetree/bindings/serial/sirf-uart.txt+15−1
@@ -1,7 +1,9 @@
11 * CSR SiRFprimaII/atlasVI Universal Synchronous Asynchronous Receiver/Transmitter *
22
33 Required properties:
4−- compatible : Should be "sirf,prima2-uart" or "sirf, prima2-usp-uart"
4+- compatible : Should be "sirf,prima2-uart", "sirf, prima2-usp-uart",
5+ "sirf,marco-uart" or "sirf,marco-bt-uart" which means
6+ uart located in BT module and used for BT.
57 - reg : Offset and length of the register set for the device
68 - interrupts : Should contain uart interrupt
79 - fifosize : Should define hardware rx/tx fifo size
@@ -31,3 +33,15 @@ usp@b0090000 { · 23 unmodified lines
3133 rts-gpios = <&gpio 15 0>;
3234 cts-gpios = <&gpio 46 0>;
3335 };
36+
37+for uart use in BT module,
38+uart6: uart@11000000 {
39+ cell-index = <6>;
40+ compatible = "sirf,marco-bt-uart", "sirf,marco-uart";
41+ reg = <0x11000000 0x1000>;
42+ interrupts = <0 100 0>;
43+ clocks = <&clks 138>, <&clks 140>, <&clks 141>;
44+ clock-names = "uart", "general", "noc";
45+ fifosize = <128>;
46+ status = "disabled";
47+}
Documentation/serial/driver+4−2
@@ -59,7 +59,9 @@ The core driver uses the info->tmpbuf_sem lock to prevent multi-threaded · 58 unmodified lines
5959 access to the info->tmpbuf bouncebuffer used for port writes.
6060
6161 The port_sem semaphore is used to protect against ports being added/
62−removed or reconfigured at inappropriate times.
62+removed or reconfigured at inappropriate times. Since v2.6.27, this
63+semaphore has been the 'mutex' member of the tty_port struct, and
64+commonly referred to as the port mutex (or port->mutex).
6365
6466
6567 uart_ops
@@ -248,7 +250,7 @@ hardware. · 182 unmodified lines
248250 Other flags may be used (eg, xon/xoff characters) if your
249251 hardware supports hardware "soft" flow control.
250252
251− Locking: none.
253+ Locking: caller holds port->mutex
252254 Interrupts: caller dependent.
253255 This call must not sleep
254256
MAINTAINERS+6−0
@@ -8026,6 +8026,12 @@ S: Maintained · 8025 unmodified lines
80268026 F: Documentation/serial/rocket.txt
80278027 F: drivers/tty/rocket*
80288028
8029+ROCKETPORT EXPRESS/INFINITY DRIVER
8030+M: Kevin Cernekee <cernekee@gmail.com>
8031+L: linux-serial@vger.kernel.org
8032+S: Odd Fixes
8033+F: drivers/tty/serial/rp2.*
8034+
80298035 ROSE NETWORK LAYER
80308036 M: Ralf Baechle <ralf@linux-mips.org>
80318037 L: linux-hams@vger.kernel.org
arch/blackfin/include/asm/bfin_serial.h+3−4
@@ -9,8 +9,11 @@ · 8 unmodified lines
99 #ifndef __BFIN_ASM_SERIAL_H__
1010 #define __BFIN_ASM_SERIAL_H__
1111
12+#include <linux/circ_buf.h>
1213 #include <linux/serial_core.h>
1314 #include <linux/spinlock.h>
15+#include <linux/timer.h>
16+#include <linux/workqueue.h>
1417 #include <mach/anomaly.h>
1518 #include <mach/bfin_serial.h>
1619
@@ -25,10 +28,6 @@ · 8 unmodified lines
2528 # endif
2629 #endif
2730
28−struct circ_buf;
29−struct timer_list;
30−struct work_struct;
31−
3231 struct bfin_serial_port {
3332 struct uart_port port;
3433 unsigned int old_status;
arch/um/drivers/line.c+5−1
@@ -632,6 +632,7 @@ static irqreturn_t winch_interrupt(int irq, void *data) · 631 unmodified lines
632632 int fd = winch->fd;
633633 int err;
634634 char c;
635+ struct pid *pgrp;
635636
636637 if (fd != -1) {
637638 err = generic_read(fd, &c, NULL);
@@ -657,7 +658,10 @@ static irqreturn_t winch_interrupt(int irq, void *data) · 19 unmodified lines
657658 if (line != NULL) {
658659 chan_window_size(line, &tty->winsize.ws_row,
659660 &tty->winsize.ws_col);
660− kill_pgrp(tty->pgrp, SIGWINCH, 1);
661+ pgrp = tty_get_pgrp(tty);
662+ if (pgrp)
663+ kill_pgrp(pgrp, SIGWINCH, 1);
664+ put_pid(pgrp);
661665 }
662666 tty_kref_put(tty);
663667 }
drivers/parport/parport_serial.c+10−0
@@ -64,6 +64,7 @@ enum parport_pc_pci_cards { · 63 unmodified lines
6464 timedia_9079c,
6565 wch_ch353_1s1p,
6666 wch_ch353_2s1p,
67+ wch_ch382_2s1p,
6768 sunix_2s1p,
6869 };
6970
@@ -151,6 +152,7 @@ static struct parport_pc_pci cards[] = { · 81 unmodified lines
151152 /* timedia_9079c */ { 1, { { 2, 3 }, } },
152153 /* wch_ch353_1s1p*/ { 1, { { 1, -1}, } },
153154 /* wch_ch353_2s1p*/ { 1, { { 2, -1}, } },
155+ /* wch_ch382_2s1p*/ { 1, { { 2, -1}, } },
154156 /* sunix_2s1p */ { 1, { { 3, -1 }, } },
155157 };
156158
@@ -257,6 +259,7 @@ static struct pci_device_id parport_serial_pci_tbl[] = { · 100 unmodified lines
257259 /* WCH CARDS */
258260 { 0x4348, 0x5053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, wch_ch353_1s1p},
259261 { 0x4348, 0x7053, 0x4348, 0x3253, 0, 0, wch_ch353_2s1p},
262+ { 0x1c00, 0x3250, 0x1c00, 0x3250, 0, 0, wch_ch382_2s1p},
260263
261264 /*
262265 * More SUNIX variations. At least one of these has part number
@@ -494,6 +497,13 @@ static struct pciserial_board pci_parport_serial_boards[] = { · 231 unmodified lines
494497 .base_baud = 115200,
495498 .uart_offset = 8,
496499 },
500+ [wch_ch382_2s1p] = {
501+ .flags = FL_BASE0,
502+ .num_ports = 2,
503+ .base_baud = 115200,
504+ .uart_offset = 8,
505+ .first_offset = 0xC0,
506+ },
497507 [sunix_2s1p] = {
498508 .flags = FL_BASE0|FL_BASE_BARS,
499509 .num_ports = 2,
drivers/tty/ehv_bytechan.c+2−2
@@ -309,8 +309,8 @@ static int __init ehv_bc_console_init(void) · 308 unmodified lines
309309 * handle for udbg.
310310 */
311311 if (stdout_bc != CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE)
312− pr_warning("ehv-bc: udbg handle %u is not the stdout handle\n",
313− CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE);
312+ pr_warn("ehv-bc: udbg handle %u is not the stdout handle\n",
313+ CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE);
314314 #endif
315315
316316 /* add_preferred_console() must be called before register_console(),
drivers/tty/goldfish.c+3−3
@@ -155,9 +155,9 @@ static struct tty_driver *goldfish_tty_console_device(struct console *c, · 154 unmodified lines
155155
156156 static int goldfish_tty_console_setup(struct console *co, char *options)
157157 {
158− if ((unsigned)co->index > goldfish_tty_line_count)
158+ if ((unsigned)co->index >= goldfish_tty_line_count)
159159 return -ENODEV;
160− if (goldfish_ttys[co->index].base == 0)
160+ if (!goldfish_ttys[co->index].base)
161161 return -ENODEV;
162162 return 0;
163163 }
@@ -317,7 +317,7 @@ static int goldfish_tty_remove(struct platform_device *pdev) · 153 unmodified lines
317317 unregister_console(&qtty->console);
318318 tty_unregister_device(goldfish_tty_driver, pdev->id);
319319 iounmap(qtty->base);
320− qtty->base = 0;
320+ qtty->base = NULL;
321321 free_irq(qtty->irq, pdev);
322322 goldfish_tty_current_line_count--;
323323 if (goldfish_tty_current_line_count == 0)
drivers/tty/hvc/hvcs.c+1−1
@@ -1575,7 +1575,7 @@ static int __init hvcs_module_init(void) · 1574 unmodified lines
15751575 */
15761576 rc = driver_create_file(&(hvcs_vio_driver.driver), &driver_attr_rescan);
15771577 if (rc)
1578− pr_warning(KERN_ERR "HVCS: Failed to create rescan file (err %d)\n", rc);
1578+ pr_warning("HVCS: Failed to create rescan file (err %d)\n", rc);
15791579
15801580 return 0;
15811581 }
drivers/tty/hvc/hvsi_lib.c+1−2
@@ -405,8 +405,7 @@ void hvsilib_close(struct hvsi_priv *pv, struct hvc_struct *hp) · 404 unmodified lines
405405 hvsi_send_close(pv);
406406 }
407407
408− if (pv->tty)
409− tty_kref_put(pv->tty);
408+ tty_kref_put(pv->tty);
410409 pv->tty = NULL;
411410 }
412411
drivers/tty/ipwireless/hardware.c+6−6
@@ -378,9 +378,9 @@ static void swap_packet_bitfield_to_le(unsigned char *data) · 377 unmodified lines
378378 /*
379379 * transform bits from aa.bbb.ccc to ccc.bbb.aa
380380 */
381− ret |= tmp & 0xc0 >> 6;
382− ret |= tmp & 0x38 >> 1;
383− ret |= tmp & 0x07 << 5;
381+ ret |= (tmp & 0xc0) >> 6;
382+ ret |= (tmp & 0x38) >> 1;
383+ ret |= (tmp & 0x07) << 5;
384384 *data = ret & 0xff;
385385 #endif
386386 }
@@ -393,9 +393,9 @@ static void swap_packet_bitfield_from_le(unsigned char *data) · 6 unmodified lines
393393 /*
394394 * transform bits from ccc.bbb.aa to aa.bbb.ccc
395395 */
396− ret |= tmp & 0xe0 >> 5;
397− ret |= tmp & 0x1c << 1;
398− ret |= tmp & 0x03 << 6;
396+ ret |= (tmp & 0xe0) >> 5;
397+ ret |= (tmp & 0x1c) << 1;
398+ ret |= (tmp & 0x03) << 6;
399399 *data = ret & 0xff;
400400 #endif
401401 }
drivers/tty/isicom.c+7−7
@@ -249,7 +249,7 @@ static int lock_card(struct isi_board *card) · 248 unmodified lines
249249 spin_unlock_irqrestore(&card->card_lock, card->flags);
250250 msleep(10);
251251 }
252− pr_warning("Failed to lock Card (0x%lx)\n", card->base);
252+ pr_warn("Failed to lock Card (0x%lx)\n", card->base);
253253
254254 return 0; /* Failed to acquire the card! */
255255 }
@@ -378,13 +378,13 @@ static inline int __isicom_paranoia_check(struct isi_port const *port, · 122 unmodified lines
378378 char *name, const char *routine)
379379 {
380380 if (!port) {
381− pr_warning("Warning: bad isicom magic for dev %s in %s.\n",
382− name, routine);
381+ pr_warn("Warning: bad isicom magic for dev %s in %s\n",
382+ name, routine);
383383 return 1;
384384 }
385385 if (port->magic != ISICOM_MAGIC) {
386− pr_warning("Warning: NULL isicom port for dev %s in %s.\n",
387− name, routine);
386+ pr_warn("Warning: NULL isicom port for dev %s in %s\n",
387+ name, routine);
388388 return 1;
389389 }
390390
@@ -546,8 +546,8 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id) · 155 unmodified lines
546546 byte_count = header & 0xff;
547547
548548 if (channel + 1 > card->port_count) {
549− pr_warning("%s(0x%lx): %d(channel) > port_count.\n",
550− __func__, base, channel+1);
549+ pr_warn("%s(0x%lx): %d(channel) > port_count\n",
550+ __func__, base, channel + 1);
551551 outw(0x0000, base+0x04); /* enable interrupts */
552552 spin_unlock(&card->card_lock);
553553 return IRQ_HANDLED;
drivers/tty/n_tty.c+37−44
@@ -321,7 +321,8 @@ static void n_tty_check_unthrottle(struct tty_struct *tty) · 320 unmodified lines
321321
322322 static inline void put_tty_queue(unsigned char c, struct n_tty_data *ldata)
323323 {
324− *read_buf_addr(ldata, ldata->read_head++) = c;
324+ *read_buf_addr(ldata, ldata->read_head) = c;
325+ ldata->read_head++;
325326 }
326327
327328 /**
@@ -351,13 +352,13 @@ static void n_tty_packet_mode_flush(struct tty_struct *tty) · 23 unmodified lines
351352 {
352353 unsigned long flags;
353354
354− spin_lock_irqsave(&tty->ctrl_lock, flags);
355355 if (tty->link->packet) {
356+ spin_lock_irqsave(&tty->ctrl_lock, flags);
356357 tty->ctrl_status |= TIOCPKT_FLUSHREAD;
358+ spin_unlock_irqrestore(&tty->ctrl_lock, flags);
357359 if (waitqueue_active(&tty->link->read_wait))
358360 wake_up_interruptible(&tty->link->read_wait);
359361 }
360− spin_unlock_irqrestore(&tty->ctrl_lock, flags);
361362 }
362363
363364 /**
@@ -2128,7 +2129,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, · 1764 unmodified lines
21282129 int minimum, time;
21292130 ssize_t retval = 0;
21302131 long timeout;
2131− unsigned long flags;
21322132 int packet;
21332133
21342134 c = job_control(tty, file);
@@ -2174,10 +2174,10 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, · 39 unmodified lines
21742174 unsigned char cs;
21752175 if (b != buf)
21762176 break;
2177− spin_lock_irqsave(&tty->link->ctrl_lock, flags);
2177+ spin_lock_irq(&tty->link->ctrl_lock);
21782178 cs = tty->link->ctrl_status;
21792179 tty->link->ctrl_status = 0;
2180− spin_unlock_irqrestore(&tty->link->ctrl_lock, flags);
2180+ spin_unlock_irq(&tty->link->ctrl_lock);
21812181 if (tty_put_user(tty, cs, b++)) {
21822182 retval = -EFAULT;
21832183 b--;
@@ -2193,45 +2193,29 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, · 9 unmodified lines
21932193
21942194 if (!input_available_p(tty, 0)) {
21952195 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
2196− up_read(&tty->termios_rwsem);
2197− tty_flush_to_ldisc(tty);
2198− down_read(&tty->termios_rwsem);
2199− if (!input_available_p(tty, 0)) {
2200− retval = -EIO;
2201− break;
2202− }
2203− } else {
2204− if (tty_hung_up_p(file))
2205− break;
2206− if (!timeout)
2207− break;
2208− if (file->f_flags & O_NONBLOCK) {
2209− retval = -EAGAIN;
2210− break;
2211− }
2212− if (signal_pending(current)) {
2213− retval = -ERESTARTSYS;
2214− break;
2215− }
2216− n_tty_set_room(tty);
2217− up_read(&tty->termios_rwsem);
2218−
2219− timeout = wait_woken(&wait, TASK_INTERRUPTIBLE,
2220− timeout);
2221−
2222− down_read(&tty->termios_rwsem);
2223− continue;
2196+ retval = -EIO;
2197+ break;
22242198 }
2225− }
2226−
2227− /* Deal with packet mode. */
2228− if (packet && b == buf) {
2229− if (tty_put_user(tty, TIOCPKT_DATA, b++)) {
2230− retval = -EFAULT;
2231− b--;
2199+ if (tty_hung_up_p(file))
2200+ break;
2201+ if (!timeout)
2202+ break;
2203+ if (file->f_flags & O_NONBLOCK) {
2204+ retval = -EAGAIN;
22322205 break;
22332206 }
2234− nr--;
2207+ if (signal_pending(current)) {
2208+ retval = -ERESTARTSYS;
2209+ break;
2210+ }
2211+ n_tty_set_room(tty);
2212+ up_read(&tty->termios_rwsem);
2213+
2214+ timeout = wait_woken(&wait, TASK_INTERRUPTIBLE,
2215+ timeout);
2216+
2217+ down_read(&tty->termios_rwsem);
2218+ continue;
22352219 }
22362220
22372221 if (ldata->icanon && !L_EXTPROC(tty)) {
@@ -2243,8 +2227,17 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, · 5 unmodified lines
22432227 break;
22442228 } else {
22452229 int uncopied;
2246− /* The copy function takes the read lock and handles
2247− locking internally for this case */
2230+
2231+ /* Deal with packet mode. */
2232+ if (packet && b == buf) {
2233+ if (tty_put_user(tty, TIOCPKT_DATA, b++)) {
2234+ retval = -EFAULT;
2235+ b--;
2236+ break;
2237+ }
2238+ nr--;
2239+ }
2240+
22482241 uncopied = copy_from_read_buf(tty, &b, &nr);
22492242 uncopied += copy_from_read_buf(tty, &b, &nr);
22502243 if (uncopied) {
drivers/tty/pty.c+52−35
@@ -47,10 +47,13 @@ static void pty_close(struct tty_struct *tty, struct file *filp) · 46 unmodified lines
4747 set_bit(TTY_IO_ERROR, &tty->flags);
4848 wake_up_interruptible(&tty->read_wait);
4949 wake_up_interruptible(&tty->write_wait);
50+ spin_lock_irq(&tty->ctrl_lock);
5051 tty->packet = 0;
52+ spin_unlock_irq(&tty->ctrl_lock);
5153 /* Review - krefs on tty_link ?? */
5254 if (!tty->link)
5355 return;
56+ tty_flush_to_ldisc(tty->link);
5457 set_bit(TTY_OTHER_CLOSED, &tty->link->flags);
5558 wake_up_interruptible(&tty->link->read_wait);
5659 wake_up_interruptible(&tty->link->write_wait);
@@ -64,9 +67,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp) · 7 unmodified lines
6467 mutex_unlock(&devpts_mutex);
6568 }
6669 #endif
67− tty_unlock(tty);
6870 tty_vhangup(tty->link);
69− tty_lock(tty);
7071 }
7172 }
7273
@@ -178,21 +179,21 @@ static int pty_get_lock(struct tty_struct *tty, int __user *arg) · 105 unmodified lines
178179 /* Set the packet mode on a pty */
179180 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
180181 {
181− unsigned long flags;
182182 int pktmode;
183183
184184 if (get_user(pktmode, arg))
185185 return -EFAULT;
186186
187− spin_lock_irqsave(&tty->ctrl_lock, flags);
187+ spin_lock_irq(&tty->ctrl_lock);
188188 if (pktmode) {
189189 if (!tty->packet) {
190− tty->packet = 1;
191190 tty->link->ctrl_status = 0;
191+ smp_mb();
192+ tty->packet = 1;
192193 }
193194 } else
194195 tty->packet = 0;
195− spin_unlock_irqrestore(&tty->ctrl_lock, flags);
196+ spin_unlock_irq(&tty->ctrl_lock);
196197
197198 return 0;
198199 }
@@ -207,15 +208,12 @@ static int pty_get_pktmode(struct tty_struct *tty, int __user *arg) · 8 unmodified lines
207208 /* Send a signal to the slave */
208209 static int pty_signal(struct tty_struct *tty, int sig)
209210 {
210− unsigned long flags;
211211 struct pid *pgrp;
212212
213213 if (tty->link) {
214− spin_lock_irqsave(&tty->link->ctrl_lock, flags);
215− pgrp = get_pid(tty->link->pgrp);
216− spin_unlock_irqrestore(&tty->link->ctrl_lock, flags);
217−
218− kill_pgrp(pgrp, sig, 1);
214+ pgrp = tty_get_pgrp(tty->link);
215+ if (pgrp)
216+ kill_pgrp(pgrp, sig, 1);
219217 put_pid(pgrp);
220218 }
221219 return 0;
@@ -224,16 +222,15 @@ static int pty_signal(struct tty_struct *tty, int sig) · 2 unmodified lines
224222 static void pty_flush_buffer(struct tty_struct *tty)
225223 {
226224 struct tty_struct *to = tty->link;
227− unsigned long flags;
228225
229226 if (!to)
230227 return;
231228 /* tty_buffer_flush(to); FIXME */
232229 if (to->packet) {
233− spin_lock_irqsave(&tty->ctrl_lock, flags);
230+ spin_lock_irq(&tty->ctrl_lock);
234231 tty->ctrl_status |= TIOCPKT_FLUSHWRITE;
235232 wake_up_interruptible(&to->read_wait);
236− spin_unlock_irqrestore(&tty->ctrl_lock, flags);
233+ spin_unlock_irq(&tty->ctrl_lock);
237234 }
238235 }
239236
@@ -262,6 +259,32 @@ out: · 22 unmodified lines
262259 static void pty_set_termios(struct tty_struct *tty,
263260 struct ktermios *old_termios)
264261 {
262+ /* See if packet mode change of state. */
263+ if (tty->link && tty->link->packet) {
264+ int extproc = (old_termios->c_lflag & EXTPROC) |
265+ (tty->termios.c_lflag & EXTPROC);
266+ int old_flow = ((old_termios->c_iflag & IXON) &&
267+ (old_termios->c_cc[VSTOP] == '\023') &&
268+ (old_termios->c_cc[VSTART] == '\021'));
269+ int new_flow = (I_IXON(tty) &&
270+ STOP_CHAR(tty) == '\023' &&
271+ START_CHAR(tty) == '\021');
272+ if ((old_flow != new_flow) || extproc) {
273+ spin_lock_irq(&tty->ctrl_lock);
274+ if (old_flow != new_flow) {
275+ tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP);
276+ if (new_flow)
277+ tty->ctrl_status |= TIOCPKT_DOSTOP;
278+ else
279+ tty->ctrl_status |= TIOCPKT_NOSTOP;
280+ }
281+ if (extproc)
282+ tty->ctrl_status |= TIOCPKT_IOCTL;
283+ spin_unlock_irq(&tty->ctrl_lock);
284+ wake_up_interruptible(&tty->link->read_wait);
285+ }
286+ }
287+
265288 tty->termios.c_cflag &= ~(CSIZE | PARENB);
266289 tty->termios.c_cflag |= (CS8 | CREAD);
267290 }
@@ -278,7 +301,6 @@ static void pty_set_termios(struct tty_struct *tty, · 10 unmodified lines
278301 static int pty_resize(struct tty_struct *tty, struct winsize *ws)
279302 {
280303 struct pid *pgrp, *rpgrp;
281− unsigned long flags;
282304 struct tty_struct *pty = tty->link;
283305
284306 /* For a PTY we need to lock the tty side */
@@ -286,17 +308,9 @@ static int pty_resize(struct tty_struct *tty, struct winsize *ws) · 1 unmodified line
286308 if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
287309 goto done;
288310
289− /* Get the PID values and reference them so we can
290− avoid holding the tty ctrl lock while sending signals.
291− We need to lock these individually however. */
292−
293− spin_lock_irqsave(&tty->ctrl_lock, flags);
294− pgrp = get_pid(tty->pgrp);
295− spin_unlock_irqrestore(&tty->ctrl_lock, flags);
296−
297− spin_lock_irqsave(&pty->ctrl_lock, flags);
298− rpgrp = get_pid(pty->pgrp);
299− spin_unlock_irqrestore(&pty->ctrl_lock, flags);
311+ /* Signal the foreground process group of both ptys */
312+ pgrp = tty_get_pgrp(tty);
313+ rpgrp = tty_get_pgrp(pty);
300314
301315 if (pgrp)
302316 kill_pgrp(pgrp, SIGWINCH, 1);
@@ -327,26 +341,26 @@ static void pty_start(struct tty_struct *tty) · 24 unmodified lines
327341 {
328342 unsigned long flags;
329343
330− spin_lock_irqsave(&tty->ctrl_lock, flags);
331344 if (tty->link && tty->link->packet) {
345+ spin_lock_irqsave(&tty->ctrl_lock, flags);
332346 tty->ctrl_status &= ~TIOCPKT_STOP;
333347 tty->ctrl_status |= TIOCPKT_START;
348+ spin_unlock_irqrestore(&tty->ctrl_lock, flags);
334349 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
335350 }
336− spin_unlock_irqrestore(&tty->ctrl_lock, flags);
337351 }
338352
339353 static void pty_stop(struct tty_struct *tty)
340354 {
341355 unsigned long flags;
342356
343− spin_lock_irqsave(&tty->ctrl_lock, flags);
344357 if (tty->link && tty->link->packet) {
358+ spin_lock_irqsave(&tty->ctrl_lock, flags);
345359 tty->ctrl_status &= ~TIOCPKT_START;
346360 tty->ctrl_status |= TIOCPKT_STOP;
361+ spin_unlock_irqrestore(&tty->ctrl_lock, flags);
347362 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
348363 }
349− spin_unlock_irqrestore(&tty->ctrl_lock, flags);
350364 }
351365
352366 /**
@@ -368,6 +382,10 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, · 15 unmodified lines
368382 int idx = tty->index;
369383 int retval = -ENOMEM;
370384
385+ /* Opening the slave first has always returned -EIO */
386+ if (driver->subtype != PTY_TYPE_MASTER)
387+ return -EIO;
388+
371389 ports[0] = kmalloc(sizeof **ports, GFP_KERNEL);
372390 ports[1] = kmalloc(sizeof **ports, GFP_KERNEL);
373391 if (!ports[0] || !ports[1])
@@ -380,6 +398,8 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, · 6 unmodified lines
380398 if (!o_tty)
381399 goto err_put_module;
382400
401+ tty_set_lock_subclass(o_tty);
402+
383403 if (legacy) {
384404 /* We always use new tty termios data so we can do this
385405 the easy way .. */
@@ -404,8 +424,6 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, · 18 unmodified lines
404424 * Everything allocated ... set up the o_tty structure.
405425 */
406426 tty_driver_kref_get(driver->other);
407− if (driver->subtype == PTY_TYPE_MASTER)
408− o_tty->count++;
409427 /* Establish the links in both directions */
410428 tty->link = o_tty;
411429 o_tty->link = tty;
@@ -417,6 +435,7 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, · 5 unmodified lines
417435
418436 tty_driver_kref_get(driver);
419437 tty->count++;
438+ o_tty->count++;
420439 return 0;
421440 err_free_termios:
422441 if (legacy)
@@ -489,7 +508,6 @@ static const struct tty_operations master_pty_ops_bsd = { · 66 unmodified lines
489508 .flush_buffer = pty_flush_buffer,
490509 .chars_in_buffer = pty_chars_in_buffer,
491510 .unthrottle = pty_unthrottle,
492− .set_termios = pty_set_termios,
493511 .ioctl = pty_bsd_ioctl,
494512 .cleanup = pty_cleanup,
495513 .resize = pty_resize,
@@ -666,7 +684,6 @@ static const struct tty_operations ptm_unix98_ops = { · 170 unmodified lines
666684 .flush_buffer = pty_flush_buffer,
667685 .chars_in_buffer = pty_chars_in_buffer,
668686 .unthrottle = pty_unthrottle,
669− .set_termios = pty_set_termios,
670687 .ioctl = pty_unix98_ioctl,
671688 .resize = pty_resize,
672689 .shutdown = pty_unix98_shutdown,
drivers/tty/serial/8250/8250.h+8−1
@@ -16,6 +16,9 @@ · 15 unmodified lines
1616 #include <linux/dmaengine.h>
1717
1818 struct uart_8250_dma {
19+ int (*tx_dma)(struct uart_8250_port *p);
20+ int (*rx_dma)(struct uart_8250_port *p, unsigned int iir);
21+
1922 /* Filter function */
2023 dma_filter_fn fn;
2124
@@ -41,6 +44,8 @@ struct uart_8250_dma { · 19 unmodified lines
4144 size_t tx_size;
4245
4346 unsigned char tx_running:1;
47+ unsigned char tx_err: 1;
48+ unsigned char rx_running:1;
4449 };
4550
4651 struct old_serial_port {
@@ -51,7 +56,7 @@ struct old_serial_port { · 4 unmodified lines
5156 unsigned int flags;
5257 unsigned char hub6;
5358 unsigned char io_type;
54− unsigned char *iomem_base;
59+ unsigned char __iomem *iomem_base;
5560 unsigned short iomem_reg_shift;
5661 unsigned long irqflags;
5762 };
@@ -114,6 +119,8 @@ static inline void serial_dl_write(struct uart_8250_port *up, int value) · 56 unmodified lines
114119 }
115120
116121 struct uart_8250_port *serial8250_get_port(int line);
122+void serial8250_rpm_get(struct uart_8250_port *p);
123+void serial8250_rpm_put(struct uart_8250_port *p);
117124
118125 #if defined(__alpha__) && !defined(CONFIG_PCI)
119126 /*
drivers/tty/serial/8250/8250_core.c+56−56
@@ -541,23 +541,25 @@ void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p) · 540 unmodified lines
541541 }
542542 EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos);
543543
544−static void serial8250_rpm_get(struct uart_8250_port *p)
544+void serial8250_rpm_get(struct uart_8250_port *p)
545545 {
546546 if (!(p->capabilities & UART_CAP_RPM))
547547 return;
548548 pm_runtime_get_sync(p->port.dev);
549549 }
550+EXPORT_SYMBOL_GPL(serial8250_rpm_get);
550551
551−static void serial8250_rpm_put(struct uart_8250_port *p)
552+void serial8250_rpm_put(struct uart_8250_port *p)
552553 {
553554 if (!(p->capabilities & UART_CAP_RPM))
554555 return;
555556 pm_runtime_mark_last_busy(p->port.dev);
556557 pm_runtime_put_autosuspend(p->port.dev);
557558 }
559+EXPORT_SYMBOL_GPL(serial8250_rpm_put);
558560
559561 /*
560− * This two wrapper ensure, that enable_runtime_pm_tx() can be called more than
562+ * These two wrappers ensure that enable_runtime_pm_tx() can be called more than
561563 * once and disable_runtime_pm_tx() will still disable RPM because the fifo is
562564 * empty and the HW can idle again.
563565 */
@@ -595,6 +597,7 @@ static void serial8250_rpm_put_tx(struct uart_8250_port *p) · 31 unmodified lines
595597 */
596598 static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
597599 {
600+ unsigned char lcr = 0, efr = 0;
598601 /*
599602 * Exar UARTs have a SLEEP register that enables or disables
600603 * each UART to enter sleep mode separately. On the XR17V35x the
@@ -611,6 +614,8 @@ static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) · 10 unmodified lines
611614
612615 if (p->capabilities & UART_CAP_SLEEP) {
613616 if (p->capabilities & UART_CAP_EFR) {
617+ lcr = serial_in(p, UART_LCR);
618+ efr = serial_in(p, UART_EFR);
614619 serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B);
615620 serial_out(p, UART_EFR, UART_EFR_ECB);
616621 serial_out(p, UART_LCR, 0);
@@ -618,8 +623,8 @@ static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) · 1 unmodified line
618623 serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0);
619624 if (p->capabilities & UART_CAP_EFR) {
620625 serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B);
621− serial_out(p, UART_EFR, 0);
622− serial_out(p, UART_LCR, 0);
626+ serial_out(p, UART_EFR, efr);
627+ serial_out(p, UART_LCR, lcr);
623628 }
624629 }
625630 out:
@@ -1350,7 +1355,7 @@ static void serial8250_start_tx(struct uart_port *port) · 724 unmodified lines
13501355 struct uart_8250_port *up = up_to_u8250p(port);
13511356
13521357 serial8250_rpm_get_tx(up);
1353− if (up->dma && !serial8250_tx_dma(up)) {
1358+ if (up->dma && !up->dma->tx_dma(up)) {
13541359 return;
13551360 } else if (!(up->ier & UART_IER_THRI)) {
13561361 up->ier |= UART_IER_THRI;
@@ -1397,6 +1402,19 @@ static void serial8250_stop_rx(struct uart_port *port) · 40 unmodified lines
13971402 serial8250_rpm_put(up);
13981403 }
13991404
1405+static void serial8250_disable_ms(struct uart_port *port)
1406+{
1407+ struct uart_8250_port *up =
1408+ container_of(port, struct uart_8250_port, port);
1409+
1410+ /* no MSR capabilities */
1411+ if (up->bugs & UART_BUG_NOMSR)
1412+ return;
1413+
1414+ up->ier &= ~UART_IER_MSI;
1415+ serial_port_out(port, UART_IER, up->ier);
1416+}
1417+
14001418 static void serial8250_enable_ms(struct uart_port *port)
14011419 {
14021420 struct uart_8250_port *up = up_to_u8250p(port);
@@ -1483,7 +1501,7 @@ serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr) · 80 unmodified lines
14831501
14841502 ignore_char:
14851503 lsr = serial_in(up, UART_LSR);
1486− } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
1504+ } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (--max_count > 0));
14871505 spin_unlock(&port->lock);
14881506 tty_flip_buffer_push(&port->state->port);
14891507 spin_lock(&port->lock);
@@ -1532,7 +1550,7 @@ void serial8250_tx_chars(struct uart_8250_port *up) · 42 unmodified lines
15321550 DEBUG_INTR("THRE...");
15331551
15341552 /*
1535− * With RPM enabled, we have to wait once the FIFO is empty before the
1553+ * With RPM enabled, we have to wait until the FIFO is empty before the
15361554 * HW can go idle. So we get here once again with empty FIFO and disable
15371555 * the interrupt and RPM in __stop_tx()
15381556 */
@@ -1588,13 +1606,14 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir) · 49 unmodified lines
15881606
15891607 if (status & (UART_LSR_DR | UART_LSR_BI)) {
15901608 if (up->dma)
1591− dma_err = serial8250_rx_dma(up, iir);
1609+ dma_err = up->dma->rx_dma(up, iir);
15921610
15931611 if (!up->dma || dma_err)
15941612 status = serial8250_rx_chars(up, status);
15951613 }
15961614 serial8250_modem_status(up);
1597− if (!up->dma && (status & UART_LSR_THRE))
1615+ if ((!up->dma || (up->dma && up->dma->tx_err)) &&
1616+ (status & UART_LSR_THRE))
15981617 serial8250_tx_chars(up);
15991618
16001619 spin_unlock_irqrestore(&port->lock, flags);
@@ -2603,13 +2622,21 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios, · 1002 unmodified lines
26032622 }
26042623
26052624 static void
2606−serial8250_set_ldisc(struct uart_port *port, int new)
2625+serial8250_set_ldisc(struct uart_port *port, struct ktermios *termios)
26072626 {
2608− if (new == N_PPS) {
2627+ if (termios->c_line == N_PPS) {
26092628 port->flags |= UPF_HARDPPS_CD;
2629+ spin_lock_irq(&port->lock);
26102630 serial8250_enable_ms(port);
2611− } else
2631+ spin_unlock_irq(&port->lock);
2632+ } else {
26122633 port->flags &= ~UPF_HARDPPS_CD;
2634+ if (!UART_ENABLE_MS(port, termios->c_cflag)) {
2635+ spin_lock_irq(&port->lock);
2636+ serial8250_disable_ms(port);
2637+ spin_unlock_irq(&port->lock);
2638+ }
2639+ }
26132640 }
26142641
26152642
@@ -2634,8 +2661,11 @@ serial8250_pm(struct uart_port *port, unsigned int state, · 18 unmodified lines
26342661
26352662 static unsigned int serial8250_port_size(struct uart_8250_port *pt)
26362663 {
2637− if (pt->port.iotype == UPIO_AU)
2664+ if (pt->port.iotype == UPIO_AU) {
2665+ if (pt->port.type == PORT_RT2880)
2666+ return 0x100;
26382667 return 0x1000;
2668+ }
26392669 if (is_omap1_8250(pt))
26402670 return 0x16 << pt->port.regshift;
26412671
@@ -2975,42 +3005,6 @@ serial8250_verify_port(struct uart_port *port, struct serial_struct *ser) · 333 unmodified lines
29753005 return 0;
29763006 }
29773007
2978−static int serial8250_ioctl(struct uart_port *port, unsigned int cmd,
2979− unsigned long arg)
2980−{
2981− struct uart_8250_port *up =
2982− container_of(port, struct uart_8250_port, port);
2983− int ret;
2984− struct serial_rs485 rs485_config;
2985−
2986− if (!up->rs485_config)
2987− return -ENOIOCTLCMD;
2988−
2989− switch (cmd) {
2990− case TIOCSRS485:
2991− if (copy_from_user(&rs485_config, (void __user *)arg,
2992− sizeof(rs485_config)))
2993− return -EFAULT;
2994−
2995− ret = up->rs485_config(up, &rs485_config);
2996− if (ret)
2997− return ret;
2998−
2999− memcpy(&up->rs485, &rs485_config, sizeof(rs485_config));
3000−
3001− return 0;
3002− case TIOCGRS485:
3003− if (copy_to_user((void __user *)arg, &up->rs485,
3004− sizeof(up->rs485)))
3005− return -EFAULT;
3006− return 0;
3007− default:
3008− break;
3009− }
3010−
3011− return -ENOIOCTLCMD;
3012−}
3013−
30143008 static const char *
30153009 serial8250_type(struct uart_port *port)
30163010 {
@@ -3042,7 +3036,6 @@ static struct uart_ops serial8250_pops = { · 25 unmodified lines
30423036 .request_port = serial8250_request_port,
30433037 .config_port = serial8250_config_port,
30443038 .verify_port = serial8250_verify_port,
3045− .ioctl = serial8250_ioctl,
30463039 #ifdef CONFIG_CONSOLE_POLL
30473040 .poll_get_char = serial8250_get_poll_char,
30483041 .poll_put_char = serial8250_put_poll_char,
@@ -3198,7 +3191,9 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count) · 149 unmodified lines
31983191
31993192 serial8250_rpm_get(up);
32003193
3201− if (port->sysrq || oops_in_progress)
3194+ if (port->sysrq)
3195+ locked = 0;
3196+ else if (oops_in_progress)
32023197 locked = spin_trylock_irqsave(&port->lock, flags);
32033198 else
32043199 spin_lock_irqsave(&port->lock, flags);
@@ -3237,7 +3232,7 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count) · 32 unmodified lines
32373232 serial8250_rpm_put(up);
32383233 }
32393234
3240−static int __init serial8250_console_setup(struct console *co, char *options)
3235+static int serial8250_console_setup(struct console *co, char *options)
32413236 {
32423237 struct uart_port *port;
32433238 int baud = 9600;
@@ -3585,10 +3580,10 @@ int serial8250_register_8250_port(struct uart_8250_port *up) · 341 unmodified lines
35853580 uart->port.fifosize = up->port.fifosize;
35863581 uart->tx_loadsz = up->tx_loadsz;
35873582 uart->capabilities = up->capabilities;
3588− uart->rs485_config = up->rs485_config;
3589− uart->rs485 = up->rs485;
35903583 uart->port.throttle = up->port.throttle;
35913584 uart->port.unthrottle = up->port.unthrottle;
3585+ uart->port.rs485_config = up->port.rs485_config;
3586+ uart->port.rs485 = up->port.rs485;
35923587
35933588 /* Take tx_loadsz from fifosize if it wasn't set separately */
35943589 if (uart->port.fifosize && !uart->tx_loadsz)
@@ -3623,8 +3618,13 @@ int serial8250_register_8250_port(struct uart_8250_port *up) · 28 unmodified lines
36233618 uart->dl_read = up->dl_read;
36243619 if (up->dl_write)
36253620 uart->dl_write = up->dl_write;
3626− if (up->dma)
3621+ if (up->dma) {
36273622 uart->dma = up->dma;
3623+ if (!uart->dma->tx_dma)
3624+ uart->dma->tx_dma = serial8250_tx_dma;
3625+ if (!uart->dma->rx_dma)
3626+ uart->dma->rx_dma = serial8250_rx_dma;
3627+ }
36283628
36293629 if (serial8250_isa_config != NULL)
36303630 serial8250_isa_config(0, &uart->port,
drivers/tty/serial/8250/8250_dma.c+25−14
@@ -21,6 +21,7 @@ static void __dma_tx_complete(void *param) · 20 unmodified lines
2121 struct uart_8250_dma *dma = p->dma;
2222 struct circ_buf *xmit = &p->port.state->xmit;
2323 unsigned long flags;
24+ int ret;
2425
2526 dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr,
2627 UART_XMIT_SIZE, DMA_TO_DEVICE);
@@ -36,8 +37,11 @@ static void __dma_tx_complete(void *param) · 9 unmodified lines
3637 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
3738 uart_write_wakeup(&p->port);
3839
39− if (!uart_circ_empty(xmit) && !uart_tx_stopped(&p->port))
40− serial8250_tx_dma(p);
40+ ret = serial8250_tx_dma(p);
41+ if (ret) {
42+ p->ier |= UART_IER_THRI;
43+ serial_port_out(&p->port, UART_IER, p->ier);
44+ }
4145
4246 spin_unlock_irqrestore(&p->port.lock, flags);
4347 }
@@ -53,6 +57,7 @@ static void __dma_rx_complete(void *param) · 9 unmodified lines
5357 dma_sync_single_for_cpu(dma->rxchan->device->dev, dma->rx_addr,
5458 dma->rx_size, DMA_FROM_DEVICE);
5559
60+ dma->rx_running = 0;
5661 dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state);
5762 dmaengine_terminate_all(dma->rxchan);
5863
@@ -69,6 +74,7 @@ int serial8250_tx_dma(struct uart_8250_port *p) · 10 unmodified lines
6974 struct uart_8250_dma *dma = p->dma;
7075 struct circ_buf *xmit = &p->port.state->xmit;
7176 struct dma_async_tx_descriptor *desc;
77+ int ret;
7278
7379 if (uart_tx_stopped(&p->port) || dma->tx_running ||
7480 uart_circ_empty(xmit))
@@ -80,11 +86,12 @@ int serial8250_tx_dma(struct uart_8250_port *p) · 5 unmodified lines
8086 dma->tx_addr + xmit->tail,
8187 dma->tx_size, DMA_MEM_TO_DEV,
8288 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
83− if (!desc)
84− return -EBUSY;
89+ if (!desc) {
90+ ret = -EBUSY;
91+ goto err;
92+ }
8593
8694 dma->tx_running = 1;
87−
8895 desc->callback = __dma_tx_complete;
8996 desc->callback_param = p;
9097
@@ -94,19 +101,23 @@ int serial8250_tx_dma(struct uart_8250_port *p) · 3 unmodified lines
94101 UART_XMIT_SIZE, DMA_TO_DEVICE);
95102
96103 dma_async_issue_pending(dma->txchan);
97−
104+ if (dma->tx_err) {
105+ dma->tx_err = 0;
106+ if (p->ier & UART_IER_THRI) {
107+ p->ier &= ~UART_IER_THRI;
108+ serial_out(p, UART_IER, p->ier);
109+ }
110+ }
98111 return 0;
112+err:
113+ dma->tx_err = 1;
114+ return ret;
99115 }
100−EXPORT_SYMBOL_GPL(serial8250_tx_dma);
101116
102117 int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir)
103118 {
104119 struct uart_8250_dma *dma = p->dma;
105120 struct dma_async_tx_descriptor *desc;
106− struct dma_tx_state state;
107− int dma_status;
108−
109− dma_status = dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state);
110121
111122 switch (iir & 0x3f) {
112123 case UART_IIR_RLSI:
@@ -117,7 +128,7 @@ int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir) · 4 unmodified lines
117128 * If RCVR FIFO trigger level was not reached, complete the
118129 * transfer and let 8250_core copy the remaining data.
119130 */
120− if (dma_status == DMA_IN_PROGRESS) {
131+ if (dma->rx_running) {
121132 dmaengine_pause(dma->rxchan);
122133 __dma_rx_complete(p);
123134 }
@@ -126,7 +137,7 @@ int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir) · 2 unmodified lines
126137 break;
127138 }
128139
129− if (dma_status)
140+ if (dma->rx_running)
130141 return 0;
131142
132143 desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr,
@@ -135,6 +146,7 @@ int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir) · 2 unmodified lines
135146 if (!desc)
136147 return -EBUSY;
137148
149+ dma->rx_running = 1;
138150 desc->callback = __dma_rx_complete;
139151 desc->callback_param = p;
140152
@@ -147,7 +159,6 @@ int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir) · 6 unmodified lines
147159
148160 return 0;
149161 }
150−EXPORT_SYMBOL_GPL(serial8250_rx_dma);
151162
152163 int serial8250_request_dma(struct uart_8250_port *p)
153164 {
drivers/tty/serial/8250/8250_dw.c+55−14
@@ -122,13 +122,44 @@ static unsigned int dw8250_serial_in(struct uart_port *p, int offset) · 121 unmodified lines
122122 return dw8250_modify_msr(p, offset, value);
123123 }
124124
125−/* Read Back (rb) version to ensure register access ording. */
126−static void dw8250_serial_out_rb(struct uart_port *p, int offset, int value)
125+#ifdef CONFIG_64BIT
126+static unsigned int dw8250_serial_inq(struct uart_port *p, int offset)
127127 {
128− dw8250_serial_out(p, offset, value);
129− dw8250_serial_in(p, UART_LCR);
128+ unsigned int value;
129+
130+ value = (u8)__raw_readq(p->membase + (offset << p->regshift));
131+
132+ return dw8250_modify_msr(p, offset, value);
130133 }
131134
135+static void dw8250_serial_outq(struct uart_port *p, int offset, int value)
136+{
137+ struct dw8250_data *d = p->private_data;
138+
139+ if (offset == UART_MCR)
140+ d->last_mcr = value;
141+
142+ value &= 0xff;
143+ __raw_writeq(value, p->membase + (offset << p->regshift));
144+ /* Read back to ensure register write ordering. */
145+ __raw_readq(p->membase + (UART_LCR << p->regshift));
146+
147+ /* Make sure LCR write wasn't ignored */
148+ if (offset == UART_LCR) {
149+ int tries = 1000;
150+ while (tries--) {
151+ unsigned int lcr = p->serial_in(p, UART_LCR);
152+ if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR))
153+ return;
154+ dw8250_force_idle(p);
155+ __raw_writeq(value & 0xff,
156+ p->membase + (UART_LCR << p->regshift));
157+ }
158+ dev_err(p->dev, "Couldn't set LCR to %d\n", value);
159+ }
160+}
161+#endif /* CONFIG_64BIT */
162+
132163 static void dw8250_serial_out32(struct uart_port *p, int offset, int value)
133164 {
134165 struct dw8250_data *d = p->private_data;
@@ -258,22 +289,19 @@ static int dw8250_probe_of(struct uart_port *p, · 123 unmodified lines
258289 struct uart_8250_port *up = up_to_u8250p(p);
259290 u32 val;
260291 bool has_ucv = true;
292+ int id;
261293
294+#ifdef CONFIG_64BIT
262295 if (of_device_is_compatible(np, "cavium,octeon-3860-uart")) {
263−#ifdef __BIG_ENDIAN
264− /*
265− * Low order bits of these 64-bit registers, when
266− * accessed as a byte, are 7 bytes further down in the
267− * address space in big endian mode.
268− */
269− p->membase += 7;
270−#endif
271− p->serial_out = dw8250_serial_out_rb;
296+ p->serial_in = dw8250_serial_inq;
297+ p->serial_out = dw8250_serial_outq;
272298 p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
273299 p->type = PORT_OCTEON;
274300 data->usr_reg = 0x27;
275301 has_ucv = false;
276− } else if (!of_property_read_u32(np, "reg-io-width", &val)) {
302+ } else
303+#endif
304+ if (!of_property_read_u32(np, "reg-io-width", &val)) {
277305 switch (val) {
278306 case 1:
279307 break;
@@ -290,9 +318,22 @@ static int dw8250_probe_of(struct uart_port *p, · 10 unmodified lines
290318 if (has_ucv)
291319 dw8250_setup_port(up);
292320
321+ /* if we have a valid fifosize, try hooking up DMA here */
322+ if (p->fifosize) {
323+ up->dma = &data->dma;
324+
325+ up->dma->rxconf.src_maxburst = p->fifosize / 4;
326+ up->dma->txconf.dst_maxburst = p->fifosize / 4;
327+ }
328+
293329 if (!of_property_read_u32(np, "reg-shift", &val))
294330 p->regshift = val;
295331
332+ /* get index of serial line, if found in DT aliases */
333+ id = of_alias_get_id(np, "serial");
334+ if (id >= 0)
335+ p->line = id;
336+
296337 /* clock got configured through clk api, all done */
297338 if (p->uartclk)
298339 return 0;
drivers/tty/serial/8250/8250_em.c+1−3
@@ -102,10 +102,8 @@ static int serial8250_em_probe(struct platform_device *pdev) · 101 unmodified lines
102102 }
103103
104104 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
105− if (!priv) {
106− dev_err(&pdev->dev, "unable to allocate private data\n");
105+ if (!priv)
107106 return -ENOMEM;
108− }
109107
110108 priv->sclk = devm_clk_get(&pdev->dev, "sclk");
111109 if (IS_ERR(priv->sclk)) {
drivers/tty/serial/8250/8250_fintek.c+5−3
@@ -89,11 +89,11 @@ static int fintek_8250_check_id(void) · 88 unmodified lines
8989 return 0;
9090 }
9191
92−static int fintek_8250_rs4850_config(struct uart_8250_port *uart,
92+static int fintek_8250_rs485_config(struct uart_port *port,
9393 struct serial_rs485 *rs485)
9494 {
9595 uint8_t config = 0;
96− int index = fintek_8250_get_index(uart->port.iobase);
96+ int index = fintek_8250_get_index(port->iobase);
9797
9898 if (index < 0)
9999 return -EINVAL;
@@ -134,6 +134,8 @@ static int fintek_8250_rs4850_config(struct uart_8250_port *uart, · 34 unmodified lines
134134 outb(config, DATA_PORT);
135135 fintek_8250_exit_key();
136136
137+ port->rs485 = *rs485;
138+
137139 return 0;
138140 }
139141
@@ -166,7 +168,7 @@ fintek_8250_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) · 26 unmodified lines
166168 uart.port.irq = pnp_irq(dev, 0);
167169 uart.port.iobase = pnp_port_start(dev, 0);
168170 uart.port.iotype = UPIO_PORT;
169− uart.rs485_config = fintek_8250_rs4850_config;
171+ uart.port.rs485_config = fintek_8250_rs485_config;
170172
171173 uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
172174 if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE)
drivers/tty/serial/8250/8250_hp300.c+0−4
@@ -88,10 +88,6 @@ extern int hp300_uart_scode; · 87 unmodified lines
8888 /*
8989 * Parse the bootinfo to find descriptions for headless console and
9090 * debug serial ports and register them with the 8250 driver.
91− * This function should be called before serial_console_init() is called
92− * to make sure the serial console will be available for use. IA-64 kernel
93− * calls this function from setup_arch() after the EFI and ACPI tables have
94− * been parsed.
9591 */
9692 int __init hp300_setup_serial_console(void)
9793 {
drivers/tty/serial/8250/8250_mtk.c+2−2
@@ -74,14 +74,14 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios, · 73 unmodified lines
7474 /* Set to next lower baudrate supported */
7575 if ((baud == 500000) || (baud == 576000))
7676 baud = 460800;
77− quot = DIV_ROUND_CLOSEST(port->uartclk, 4 * baud);
77+ quot = DIV_ROUND_UP(port->uartclk, 4 * baud);
7878 } else {
7979 serial_port_out(port, UART_MTK_HIGHS, 0x3);
8080
8181 /* Set to highest baudrate supported */
8282 if (baud >= 1152000)
8383 baud = 921600;
84− quot = (port->uartclk / (256 * baud)) + 1;
84+ quot = DIV_ROUND_UP(port->uartclk, 256 * baud);
8585 }
8686
8787 /*
drivers/tty/serial/8250/8250_omap.c+1281−0
@@ -0,0 +1,1281 @@
1+/*
2+ * 8250-core based driver for the OMAP internal UART
3+ *
4+ * based on omap-serial.c, Copyright (C) 2010 Texas Instruments.
5+ *
6+ * Copyright (C) 2014 Sebastian Andrzej Siewior
7+ *
8+ */
9+
10+#include <linux/device.h>
11+#include <linux/io.h>
12+#include <linux/module.h>
13+#include <linux/serial_8250.h>
14+#include <linux/serial_core.h>
15+#include <linux/serial_reg.h>
16+#include <linux/tty_flip.h>
17+#include <linux/platform_device.h>
18+#include <linux/slab.h>
19+#include <linux/of.h>
20+#include <linux/of_gpio.h>
21+#include <linux/of_irq.h>
22+#include <linux/delay.h>
23+#include <linux/pm_runtime.h>
24+#include <linux/console.h>
25+#include <linux/pm_qos.h>
26+#include <linux/dma-mapping.h>
27+
28+#include "8250.h"
29+
30+#define DEFAULT_CLK_SPEED 48000000
31+
32+#define UART_ERRATA_i202_MDR1_ACCESS (1 << 0)
33+#define OMAP_UART_WER_HAS_TX_WAKEUP (1 << 1)
34+#define OMAP_DMA_TX_KICK (1 << 2)
35+
36+#define OMAP_UART_FCR_RX_TRIG 6
37+#define OMAP_UART_FCR_TX_TRIG 4
38+
39+/* SCR register bitmasks */
40+#define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7)
41+#define OMAP_UART_SCR_TX_TRIG_GRANU1_MASK (1 << 6)
42+#define OMAP_UART_SCR_TX_EMPTY (1 << 3)
43+#define OMAP_UART_SCR_DMAMODE_MASK (3 << 1)
44+#define OMAP_UART_SCR_DMAMODE_1 (1 << 1)
45+#define OMAP_UART_SCR_DMAMODE_CTL (1 << 0)
46+
47+/* MVR register bitmasks */
48+#define OMAP_UART_MVR_SCHEME_SHIFT 30
49+#define OMAP_UART_LEGACY_MVR_MAJ_MASK 0xf0
50+#define OMAP_UART_LEGACY_MVR_MAJ_SHIFT 4
51+#define OMAP_UART_LEGACY_MVR_MIN_MASK 0x0f
52+#define OMAP_UART_MVR_MAJ_MASK 0x700
53+#define OMAP_UART_MVR_MAJ_SHIFT 8
54+#define OMAP_UART_MVR_MIN_MASK 0x3f
55+
56+#define UART_TI752_TLR_TX 0
57+#define UART_TI752_TLR_RX 4
58+
59+#define TRIGGER_TLR_MASK(x) ((x & 0x3c) >> 2)
60+#define TRIGGER_FCR_MASK(x) (x & 3)
61+
62+/* Enable XON/XOFF flow control on output */
63+#define OMAP_UART_SW_TX 0x08
64+/* Enable XON/XOFF flow control on input */
65+#define OMAP_UART_SW_RX 0x02
66+
67+#define OMAP_UART_WER_MOD_WKUP 0x7f
68+#define OMAP_UART_TX_WAKEUP_EN (1 << 7)
69+
70+#define TX_TRIGGER 1
71+#define RX_TRIGGER 48
72+
73+#define OMAP_UART_TCR_RESTORE(x) ((x / 4) << 4)
74+#define OMAP_UART_TCR_HALT(x) ((x / 4) << 0)
75+
76+#define UART_BUILD_REVISION(x, y) (((x) << 8) | (y))
77+
78+#define OMAP_UART_REV_46 0x0406
79+#define OMAP_UART_REV_52 0x0502
80+#define OMAP_UART_REV_63 0x0603
81+
82+struct omap8250_priv {
83+ int line;
84+ u8 habit;
85+ u8 mdr1;
86+ u8 efr;
87+ u8 scr;
88+ u8 wer;
89+ u8 xon;
90+ u8 xoff;
91+ u8 delayed_restore;
92+ u16 quot;
93+
94+ bool is_suspending;
95+ int wakeirq;
96+ int wakeups_enabled;
97+ u32 latency;
98+ u32 calc_latency;
99+ struct pm_qos_request pm_qos_request;
100+ struct work_struct qos_work;
101+ struct uart_8250_dma omap8250_dma;
102+};
103+
104+static u32 uart_read(struct uart_8250_port *up, u32 reg)
105+{
106+ return readl(up->port.membase + (reg << up->port.regshift));
107+}
108+
109+/*
110+ * Work Around for Errata i202 (2430, 3430, 3630, 4430 and 4460)
111+ * The access to uart register after MDR1 Access
112+ * causes UART to corrupt data.
113+ *
114+ * Need a delay =
115+ * 5 L4 clock cycles + 5 UART functional clock cycle (@48MHz = ~0.2uS)
116+ * give 10 times as much
117+ */
118+static void omap_8250_mdr1_errataset(struct uart_8250_port *up,
119+ struct omap8250_priv *priv)
120+{
121+ u8 timeout = 255;
122+ u8 old_mdr1;
123+
124+ old_mdr1 = serial_in(up, UART_OMAP_MDR1);
125+ if (old_mdr1 == priv->mdr1)
126+ return;
127+
128+ serial_out(up, UART_OMAP_MDR1, priv->mdr1);
129+ udelay(2);
130+ serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_XMIT |
131+ UART_FCR_CLEAR_RCVR);
132+ /*
133+ * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and
134+ * TX_FIFO_E bit is 1.
135+ */
136+ while (UART_LSR_THRE != (serial_in(up, UART_LSR) &
137+ (UART_LSR_THRE | UART_LSR_DR))) {
138+ timeout--;
139+ if (!timeout) {
140+ /* Should *never* happen. we warn and carry on */
141+ dev_crit(up->port.dev, "Errata i202: timedout %x\n",
142+ serial_in(up, UART_LSR));
143+ break;
144+ }
145+ udelay(1);
146+ }
147+}
148+
149+static void omap_8250_get_divisor(struct uart_port *port, unsigned int baud,
150+ struct omap8250_priv *priv)
151+{
152+ unsigned int uartclk = port->uartclk;
153+ unsigned int div_13, div_16;
154+ unsigned int abs_d13, abs_d16;
155+
156+ /*
157+ * Old custom speed handling.
158+ */
159+ if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) {
160+ priv->quot = port->custom_divisor & 0xffff;
161+ /*
162+ * I assume that nobody is using this. But hey, if somebody
163+ * would like to specify the divisor _and_ the mode then the
164+ * driver is ready and waiting for it.
165+ */
166+ if (port->custom_divisor & (1 << 16))
167+ priv->mdr1 = UART_OMAP_MDR1_13X_MODE;
168+ else
169+ priv->mdr1 = UART_OMAP_MDR1_16X_MODE;
170+ return;
171+ }
172+ div_13 = DIV_ROUND_CLOSEST(uartclk, 13 * baud);
173+ div_16 = DIV_ROUND_CLOSEST(uartclk, 16 * baud);
174+
175+ if (!div_13)
176+ div_13 = 1;
177+ if (!div_16)
178+ div_16 = 1;
179+
180+ abs_d13 = abs(baud - uartclk / 13 / div_13);
181+ abs_d16 = abs(baud - uartclk / 16 / div_16);
182+
183+ if (abs_d13 >= abs_d16) {
184+ priv->mdr1 = UART_OMAP_MDR1_16X_MODE;
185+ priv->quot = div_16;
186+ } else {
187+ priv->mdr1 = UART_OMAP_MDR1_13X_MODE;
188+ priv->quot = div_13;
189+ }
190+}
191+
192+static void omap8250_update_scr(struct uart_8250_port *up,
193+ struct omap8250_priv *priv)
194+{
195+ u8 old_scr;
196+
197+ old_scr = serial_in(up, UART_OMAP_SCR);
198+ if (old_scr == priv->scr)
199+ return;
200+
201+ /*
202+ * The manual recommends not to enable the DMA mode selector in the SCR
203+ * (instead of the FCR) register _and_ selecting the DMA mode as one
204+ * register write because this may lead to malfunction.
205+ */
206+ if (priv->scr & OMAP_UART_SCR_DMAMODE_MASK)
207+ serial_out(up, UART_OMAP_SCR,
208+ priv->scr & ~OMAP_UART_SCR_DMAMODE_MASK);
209+ serial_out(up, UART_OMAP_SCR, priv->scr);
210+}
211+
212+static void omap8250_restore_regs(struct uart_8250_port *up)
213+{
214+ struct omap8250_priv *priv = up->port.private_data;
215+ struct uart_8250_dma *dma = up->dma;
216+
217+ if (dma && dma->tx_running) {
218+ /*
219+ * TCSANOW requests the change to occur immediately however if
220+ * we have a TX-DMA operation in progress then it has been
221+ * observed that it might stall and never complete. Therefore we
222+ * delay DMA completes to prevent this hang from happen.
223+ */
224+ priv->delayed_restore = 1;
225+ return;
226+ }
227+
228+ serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
229+ serial_out(up, UART_EFR, UART_EFR_ECB);
230+
231+ serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
232+ serial_out(up, UART_MCR, UART_MCR_TCRTLR);
233+ serial_out(up, UART_FCR, up->fcr);
234+
235+ omap8250_update_scr(up, priv);
236+
237+ serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
238+
239+ serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_RESTORE(16) |
240+ OMAP_UART_TCR_HALT(52));
241+ serial_out(up, UART_TI752_TLR,
242+ TRIGGER_TLR_MASK(TX_TRIGGER) << UART_TI752_TLR_TX |
243+ TRIGGER_TLR_MASK(RX_TRIGGER) << UART_TI752_TLR_RX);
244+
245+ serial_out(up, UART_LCR, 0);
246+
247+ /* drop TCR + TLR access, we setup XON/XOFF later */
248+ serial_out(up, UART_MCR, up->mcr);
249+ serial_out(up, UART_IER, up->ier);
250+
251+ serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
252+ serial_dl_write(up, priv->quot);
253+
254+ serial_out(up, UART_EFR, priv->efr);
255+
256+ /* Configure flow control */
257+ serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
258+ serial_out(up, UART_XON1, priv->xon);
259+ serial_out(up, UART_XOFF1, priv->xoff);
260+
261+ serial_out(up, UART_LCR, up->lcr);
262+ /* need mode A for FCR */
263+ if (priv->habit & UART_ERRATA_i202_MDR1_ACCESS)
264+ omap_8250_mdr1_errataset(up, priv);
265+ else
266+ serial_out(up, UART_OMAP_MDR1, priv->mdr1);
267+ up->port.ops->set_mctrl(&up->port, up->port.mctrl);
268+}
269+
270+/*
271+ * OMAP can use "CLK / (16 or 13) / div" for baud rate. And then we have have
272+ * some differences in how we want to handle flow control.
273+ */
274+static void omap_8250_set_termios(struct uart_port *port,
275+ struct ktermios *termios,
276+ struct ktermios *old)
277+{
278+ struct uart_8250_port *up =
279+ container_of(port, struct uart_8250_port, port);
280+ struct omap8250_priv *priv = up->port.private_data;
281+ unsigned char cval = 0;
282+ unsigned int baud;
283+
284+ switch (termios->c_cflag & CSIZE) {
285+ case CS5:
286+ cval = UART_LCR_WLEN5;
287+ break;
288+ case CS6:
289+ cval = UART_LCR_WLEN6;
290+ break;
291+ case CS7:
292+ cval = UART_LCR_WLEN7;
293+ break;
294+ default:
295+ case CS8:
296+ cval = UART_LCR_WLEN8;
297+ break;
298+ }
299+
300+ if (termios->c_cflag & CSTOPB)
301+ cval |= UART_LCR_STOP;
302+ if (termios->c_cflag & PARENB)
303+ cval |= UART_LCR_PARITY;
304+ if (!(termios->c_cflag & PARODD))
305+ cval |= UART_LCR_EPAR;
306+ if (termios->c_cflag & CMSPAR)
307+ cval |= UART_LCR_SPAR;
308+
309+ /*
310+ * Ask the core to calculate the divisor for us.
311+ */
312+ baud = uart_get_baud_rate(port, termios, old,
313+ port->uartclk / 16 / 0xffff,
314+ port->uartclk / 13);
315+ omap_8250_get_divisor(port, baud, priv);
316+
317+ /*
318+ * Ok, we're now changing the port state. Do it with
319+ * interrupts disabled.
320+ */
321+ pm_runtime_get_sync(port->dev);
322+ spin_lock_irq(&port->lock);
323+
324+ /*
325+ * Update the per-port timeout.
326+ */
327+ uart_update_timeout(port, termios->c_cflag, baud);
328+
329+ up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
330+ if (termios->c_iflag & INPCK)
331+ up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
332+ if (termios->c_iflag & (IGNBRK | PARMRK))
333+ up->port.read_status_mask |= UART_LSR_BI;
334+
335+ /*
336+ * Characters to ignore
337+ */
338+ up->port.ignore_status_mask = 0;
339+ if (termios->c_iflag & IGNPAR)
340+ up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
341+ if (termios->c_iflag & IGNBRK) {
342+ up->port.ignore_status_mask |= UART_LSR_BI;
343+ /*
344+ * If we're ignoring parity and break indicators,
345+ * ignore overruns too (for real raw support).
346+ */
347+ if (termios->c_iflag & IGNPAR)
348+ up->port.ignore_status_mask |= UART_LSR_OE;
349+ }
350+
351+ /*
352+ * ignore all characters if CREAD is not set
353+ */
354+ if ((termios->c_cflag & CREAD) == 0)
355+ up->port.ignore_status_mask |= UART_LSR_DR;
356+
357+ /*
358+ * Modem status interrupts
359+ */
360+ up->ier &= ~UART_IER_MSI;
361+ if (UART_ENABLE_MS(&up->port, termios->c_cflag))
362+ up->ier |= UART_IER_MSI;
363+
364+ up->lcr = cval;
365+ /* Up to here it was mostly serial8250_do_set_termios() */
366+
367+ /*
368+ * We enable TRIG_GRANU for RX and TX and additionaly we set
369+ * SCR_TX_EMPTY bit. The result is the following:
370+ * - RX_TRIGGER amount of bytes in the FIFO will cause an interrupt.
371+ * - less than RX_TRIGGER number of bytes will also cause an interrupt
372+ * once the UART decides that there no new bytes arriving.
373+ * - Once THRE is enabled, the interrupt will be fired once the FIFO is
374+ * empty - the trigger level is ignored here.
375+ *
376+ * Once DMA is enabled:
377+ * - UART will assert the TX DMA line once there is room for TX_TRIGGER
378+ * bytes in the TX FIFO. On each assert the DMA engine will move
379+ * TX_TRIGGER bytes into the FIFO.
380+ * - UART will assert the RX DMA line once there are RX_TRIGGER bytes in
381+ * the FIFO and move RX_TRIGGER bytes.
382+ * This is because threshold and trigger values are the same.
383+ */
384+ up->fcr = UART_FCR_ENABLE_FIFO;
385+ up->fcr |= TRIGGER_FCR_MASK(TX_TRIGGER) << OMAP_UART_FCR_TX_TRIG;
386+ up->fcr |= TRIGGER_FCR_MASK(RX_TRIGGER) << OMAP_UART_FCR_RX_TRIG;
387+
388+ priv->scr = OMAP_UART_SCR_RX_TRIG_GRANU1_MASK | OMAP_UART_SCR_TX_EMPTY |
389+ OMAP_UART_SCR_TX_TRIG_GRANU1_MASK;
390+
391+ if (up->dma)
392+ priv->scr |= OMAP_UART_SCR_DMAMODE_1 |
393+ OMAP_UART_SCR_DMAMODE_CTL;
394+
395+ priv->xon = termios->c_cc[VSTART];
396+ priv->xoff = termios->c_cc[VSTOP];
397+
398+ priv->efr = 0;
399+ up->mcr &= ~(UART_MCR_RTS | UART_MCR_XONANY);
400+ if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) {
401+ /* Enable AUTORTS and AUTOCTS */
402+ priv->efr |= UART_EFR_CTS | UART_EFR_RTS;
403+
404+ /* Ensure MCR RTS is asserted */
405+ up->mcr |= UART_MCR_RTS;
406+ } else if (up->port.flags & UPF_SOFT_FLOW) {
407+ /*
408+ * IXON Flag:
409+ * Enable XON/XOFF flow control on input.
410+ * Receiver compares XON1, XOFF1.
411+ */
412+ if (termios->c_iflag & IXON)
413+ priv->efr |= OMAP_UART_SW_RX;
414+
415+ /*
416+ * IXOFF Flag:
417+ * Enable XON/XOFF flow control on output.
418+ * Transmit XON1, XOFF1
419+ */
420+ if (termios->c_iflag & IXOFF)
421+ priv->efr |= OMAP_UART_SW_TX;
422+
423+ /*
424+ * IXANY Flag:
425+ * Enable any character to restart output.
426+ * Operation resumes after receiving any
427+ * character after recognition of the XOFF character
428+ */
429+ if (termios->c_iflag & IXANY)
430+ up->mcr |= UART_MCR_XONANY;
431+ }
432+ omap8250_restore_regs(up);
433+
434+ spin_unlock_irq(&up->port.lock);
435+ pm_runtime_mark_last_busy(port->dev);
436+ pm_runtime_put_autosuspend(port->dev);
437+
438+ /* calculate wakeup latency constraint */
439+ priv->calc_latency = USEC_PER_SEC * 64 * 8 / baud;
440+ priv->latency = priv->calc_latency;
441+
442+ schedule_work(&priv->qos_work);
443+
444+ /* Don't rewrite B0 */
445+ if (tty_termios_baud_rate(termios))
446+ tty_termios_encode_baud_rate(termios, baud, baud);
447+}
448+
449+/* same as 8250 except that we may have extra flow bits set in EFR */
450+static void omap_8250_pm(struct uart_port *port, unsigned int state,
451+ unsigned int oldstate)
452+{
453+ struct uart_8250_port *up =
454+ container_of(port, struct uart_8250_port, port);
455+ struct omap8250_priv *priv = up->port.private_data;
456+
457+ pm_runtime_get_sync(port->dev);
458+ serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
459+ serial_out(up, UART_EFR, priv->efr | UART_EFR_ECB);
460+ serial_out(up, UART_LCR, 0);
461+
462+ serial_out(up, UART_IER, (state != 0) ? UART_IERX_SLEEP : 0);
463+ serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
464+ serial_out(up, UART_EFR, priv->efr);
465+ serial_out(up, UART_LCR, 0);
466+
467+ pm_runtime_mark_last_busy(port->dev);
468+ pm_runtime_put_autosuspend(port->dev);
469+}
470+
471+static void omap_serial_fill_features_erratas(struct uart_8250_port *up,
472+ struct omap8250_priv *priv)
473+{
474+ u32 mvr, scheme;
475+ u16 revision, major, minor;
476+
477+ mvr = uart_read(up, UART_OMAP_MVER);
478+
479+ /* Check revision register scheme */
480+ scheme = mvr >> OMAP_UART_MVR_SCHEME_SHIFT;
481+
482+ switch (scheme) {
483+ case 0: /* Legacy Scheme: OMAP2/3 */
484+ /* MINOR_REV[0:4], MAJOR_REV[4:7] */
485+ major = (mvr & OMAP_UART_LEGACY_MVR_MAJ_MASK) >>
486+ OMAP_UART_LEGACY_MVR_MAJ_SHIFT;
487+ minor = (mvr & OMAP_UART_LEGACY_MVR_MIN_MASK);
488+ break;
489+ case 1:
490+ /* New Scheme: OMAP4+ */
491+ /* MINOR_REV[0:5], MAJOR_REV[8:10] */
492+ major = (mvr & OMAP_UART_MVR_MAJ_MASK) >>
493+ OMAP_UART_MVR_MAJ_SHIFT;
494+ minor = (mvr & OMAP_UART_MVR_MIN_MASK);
495+ break;
496+ default:
497+ dev_warn(up->port.dev,
498+ "Unknown revision, defaulting to highest\n");
499+ /* highest possible revision */
500+ major = 0xff;
501+ minor = 0xff;
502+ }
503+ /* normalize revision for the driver */
504+ revision = UART_BUILD_REVISION(major, minor);
505+
506+ switch (revision) {
507+ case OMAP_UART_REV_46:
508+ priv->habit = UART_ERRATA_i202_MDR1_ACCESS;
509+ break;
510+ case OMAP_UART_REV_52:
511+ priv->habit = UART_ERRATA_i202_MDR1_ACCESS |
512+ OMAP_UART_WER_HAS_TX_WAKEUP;
513+ break;
514+ case OMAP_UART_REV_63:
515+ priv->habit = UART_ERRATA_i202_MDR1_ACCESS |
516+ OMAP_UART_WER_HAS_TX_WAKEUP;
517+ break;
518+ default:
519+ break;
520+ }
521+}
522+
523+static void omap8250_uart_qos_work(struct work_struct *work)
524+{
525+ struct omap8250_priv *priv;
526+
527+ priv = container_of(work, struct omap8250_priv, qos_work);
528+ pm_qos_update_request(&priv->pm_qos_request, priv->latency);
529+}
530+
531+static irqreturn_t omap_wake_irq(int irq, void *dev_id)
532+{
533+ struct uart_port *port = dev_id;
534+ int ret;
535+
536+ ret = port->handle_irq(port);
537+ if (ret)
538+ return IRQ_HANDLED;
539+ return IRQ_NONE;
540+}
541+
542+static int omap_8250_startup(struct uart_port *port)
543+{
544+ struct uart_8250_port *up =
545+ container_of(port, struct uart_8250_port, port);
546+ struct omap8250_priv *priv = port->private_data;
547+
548+ int ret;
549+
550+ if (priv->wakeirq) {
551+ ret = request_irq(priv->wakeirq, omap_wake_irq,
552+ port->irqflags, "uart wakeup irq", port);
553+ if (ret)
554+ return ret;
555+ disable_irq(priv->wakeirq);
556+ }
557+
558+ pm_runtime_get_sync(port->dev);
559+
560+ ret = serial8250_do_startup(port);
561+ if (ret)
562+ goto err;
563+
564+#ifdef CONFIG_PM_RUNTIME
565+ up->capabilities |= UART_CAP_RPM;
566+#endif
567+
568+ /* Enable module level wake up */
569+ priv->wer = OMAP_UART_WER_MOD_WKUP;
570+ if (priv->habit & OMAP_UART_WER_HAS_TX_WAKEUP)
571+ priv->wer |= OMAP_UART_TX_WAKEUP_EN;
572+ serial_out(up, UART_OMAP_WER, priv->wer);
573+
574+ if (up->dma)
575+ up->dma->rx_dma(up, 0);
576+
577+ pm_runtime_mark_last_busy(port->dev);
578+ pm_runtime_put_autosuspend(port->dev);
579+ return 0;
580+err:
581+ pm_runtime_mark_last_busy(port->dev);
582+ pm_runtime_put_autosuspend(port->dev);
583+ if (priv->wakeirq)
584+ free_irq(priv->wakeirq, port);
585+ return ret;
586+}
587+
588+static void omap_8250_shutdown(struct uart_port *port)
589+{
590+ struct uart_8250_port *up =
591+ container_of(port, struct uart_8250_port, port);
592+ struct omap8250_priv *priv = port->private_data;
593+
594+ flush_work(&priv->qos_work);
595+ if (up->dma)
596+ up->dma->rx_dma(up, UART_IIR_RX_TIMEOUT);
597+
598+ pm_runtime_get_sync(port->dev);
599+
600+ serial_out(up, UART_OMAP_WER, 0);
601+ serial8250_do_shutdown(port);
602+
603+ pm_runtime_mark_last_busy(port->dev);
604+ pm_runtime_put_autosuspend(port->dev);
605+
606+ if (priv->wakeirq)
607+ free_irq(priv->wakeirq, port);
608+}
609+
610+static void omap_8250_throttle(struct uart_port *port)
611+{
612+ unsigned long flags;
613+ struct uart_8250_port *up =
614+ container_of(port, struct uart_8250_port, port);
615+
616+ pm_runtime_get_sync(port->dev);
617+
618+ spin_lock_irqsave(&port->lock, flags);
619+ up->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
620+ serial_out(up, UART_IER, up->ier);
621+ spin_unlock_irqrestore(&port->lock, flags);
622+
623+ pm_runtime_mark_last_busy(port->dev);
624+ pm_runtime_put_autosuspend(port->dev);
625+}
626+
627+static void omap_8250_unthrottle(struct uart_port *port)
628+{
629+ unsigned long flags;
630+ struct uart_8250_port *up =
631+ container_of(port, struct uart_8250_port, port);
632+
633+ pm_runtime_get_sync(port->dev);
634+
635+ spin_lock_irqsave(&port->lock, flags);
636+ up->ier |= UART_IER_RLSI | UART_IER_RDI;
637+ serial_out(up, UART_IER, up->ier);
638+ spin_unlock_irqrestore(&port->lock, flags);
639+
640+ pm_runtime_mark_last_busy(port->dev);
641+ pm_runtime_put_autosuspend(port->dev);
642+}
643+
644+#ifdef CONFIG_SERIAL_8250_DMA
645+static int omap_8250_rx_dma(struct uart_8250_port *p, unsigned int iir);
646+
647+static void __dma_rx_do_complete(struct uart_8250_port *p, bool error)
648+{
649+ struct uart_8250_dma *dma = p->dma;
650+ struct tty_port *tty_port = &p->port.state->port;
651+ struct dma_tx_state state;
652+ int count;
653+
654+ dma_sync_single_for_cpu(dma->rxchan->device->dev, dma->rx_addr,
655+ dma->rx_size, DMA_FROM_DEVICE);
656+
657+ dma->rx_running = 0;
658+ dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state);
659+ dmaengine_terminate_all(dma->rxchan);
660+
661+ count = dma->rx_size - state.residue;
662+
663+ tty_insert_flip_string(tty_port, dma->rx_buf, count);
664+ p->port.icount.rx += count;
665+ if (!error)
666+ omap_8250_rx_dma(p, 0);
667+
668+ tty_flip_buffer_push(tty_port);
669+}
670+
671+static void __dma_rx_complete(void *param)
672+{
673+ __dma_rx_do_complete(param, false);
674+}
675+
676+static int omap_8250_rx_dma(struct uart_8250_port *p, unsigned int iir)
677+{
678+ struct uart_8250_dma *dma = p->dma;
679+ struct dma_async_tx_descriptor *desc;
680+
681+ switch (iir & 0x3f) {
682+ case UART_IIR_RLSI:
683+ /* 8250_core handles errors and break interrupts */
684+ if (dma->rx_running) {
685+ dmaengine_pause(dma->rxchan);
686+ __dma_rx_do_complete(p, true);
687+ }
688+ return -EIO;
689+ case UART_IIR_RX_TIMEOUT:
690+ /*
691+ * If RCVR FIFO trigger level was not reached, complete the
692+ * transfer and let 8250_core copy the remaining data.
693+ */
694+ if (dma->rx_running) {
695+ dmaengine_pause(dma->rxchan);
696+ __dma_rx_do_complete(p, true);
697+ }
698+ return -ETIMEDOUT;
699+ case UART_IIR_RDI:
700+ /*
701+ * The OMAP UART is a special BEAST. If we receive RDI we _have_
702+ * a DMA transfer programmed but it didn't work. One reason is
703+ * that we were too slow and there were too many bytes in the
704+ * FIFO, the UART counted wrong and never kicked the DMA engine
705+ * to do anything. That means once we receive RDI on OMAP then
706+ * the DMA won't do anything soon so we have to cancel the DMA
707+ * transfer and purge the FIFO manually.
708+ */
709+ if (dma->rx_running) {
710+ dmaengine_pause(dma->rxchan);
711+ __dma_rx_do_complete(p, true);
712+ }
713+ return -ETIMEDOUT;
714+
715+ default:
716+ break;
717+ }
718+
719+ if (dma->rx_running)
720+ return 0;
721+
722+ desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr,
723+ dma->rx_size, DMA_DEV_TO_MEM,
724+ DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
725+ if (!desc)
726+ return -EBUSY;
727+
728+ dma->rx_running = 1;
729+ desc->callback = __dma_rx_complete;
730+ desc->callback_param = p;
731+
732+ dma->rx_cookie = dmaengine_submit(desc);
733+
734+ dma_sync_single_for_device(dma->rxchan->device->dev, dma->rx_addr,
735+ dma->rx_size, DMA_FROM_DEVICE);
736+
737+ dma_async_issue_pending(dma->rxchan);
738+ return 0;
739+}
740+
741+static int omap_8250_tx_dma(struct uart_8250_port *p);
742+
743+static void omap_8250_dma_tx_complete(void *param)
744+{
745+ struct uart_8250_port *p = param;
746+ struct uart_8250_dma *dma = p->dma;
747+ struct circ_buf *xmit = &p->port.state->xmit;
748+ unsigned long flags;
749+ bool en_thri = false;
750+ struct omap8250_priv *priv = p->port.private_data;
751+
752+ dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr,
753+ UART_XMIT_SIZE, DMA_TO_DEVICE);
754+
755+ spin_lock_irqsave(&p->port.lock, flags);
756+
757+ dma->tx_running = 0;
758+
759+ xmit->tail += dma->tx_size;
760+ xmit->tail &= UART_XMIT_SIZE - 1;
761+ p->port.icount.tx += dma->tx_size;
762+
763+ if (priv->delayed_restore) {
764+ priv->delayed_restore = 0;
765+ omap8250_restore_regs(p);
766+ }
767+
768+ if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
769+ uart_write_wakeup(&p->port);
770+
771+ if (!uart_circ_empty(xmit) && !uart_tx_stopped(&p->port)) {
772+ int ret;
773+
774+ ret = omap_8250_tx_dma(p);
775+ if (ret)
776+ en_thri = true;
777+
778+ } else if (p->capabilities & UART_CAP_RPM) {
779+ en_thri = true;
780+ }
781+
782+ if (en_thri) {
783+ dma->tx_err = 1;
784+ p->ier |= UART_IER_THRI;
785+ serial_port_out(&p->port, UART_IER, p->ier);
786+ }
787+
788+ spin_unlock_irqrestore(&p->port.lock, flags);
789+}
790+
791+static int omap_8250_tx_dma(struct uart_8250_port *p)
792+{
793+ struct uart_8250_dma *dma = p->dma;
794+ struct omap8250_priv *priv = p->port.private_data;
795+ struct circ_buf *xmit = &p->port.state->xmit;
796+ struct dma_async_tx_descriptor *desc;
797+ unsigned int skip_byte = 0;
798+ int ret;
799+
800+ if (dma->tx_running)
801+ return 0;
802+ if (uart_tx_stopped(&p->port) || uart_circ_empty(xmit)) {
803+
804+ /*
805+ * Even if no data, we need to return an error for the two cases
806+ * below so serial8250_tx_chars() is invoked and properly clears
807+ * THRI and/or runtime suspend.
808+ */
809+ if (dma->tx_err || p->capabilities & UART_CAP_RPM) {
810+ ret = -EBUSY;
811+ goto err;
812+ }
813+ if (p->ier & UART_IER_THRI) {
814+ p->ier &= ~UART_IER_THRI;
815+ serial_out(p, UART_IER, p->ier);
816+ }
817+ return 0;
818+ }
819+
820+ dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
821+ if (priv->habit & OMAP_DMA_TX_KICK) {
822+ u8 tx_lvl;
823+
824+ /*
825+ * We need to put the first byte into the FIFO in order to start
826+ * the DMA transfer. For transfers smaller than four bytes we
827+ * don't bother doing DMA at all. It seem not matter if there
828+ * are still bytes in the FIFO from the last transfer (in case
829+ * we got here directly from omap_8250_dma_tx_complete()). Bytes
830+ * leaving the FIFO seem not to trigger the DMA transfer. It is
831+ * really the byte that we put into the FIFO.
832+ * If the FIFO is already full then we most likely got here from
833+ * omap_8250_dma_tx_complete(). And this means the DMA engine
834+ * just completed its work. We don't have to wait the complete
835+ * 86us at 115200,8n1 but around 60us (not to mention lower
836+ * baudrates). So in that case we take the interrupt and try
837+ * again with an empty FIFO.
838+ */
839+ tx_lvl = serial_in(p, UART_OMAP_TX_LVL);
840+ if (tx_lvl == p->tx_loadsz) {
841+ ret = -EBUSY;
842+ goto err;
843+ }
844+ if (dma->tx_size < 4) {
845+ ret = -EINVAL;
846+ goto err;
847+ }
848+ skip_byte = 1;
849+ }
850+
851+ desc = dmaengine_prep_slave_single(dma->txchan,
852+ dma->tx_addr + xmit->tail + skip_byte,
853+ dma->tx_size - skip_byte, DMA_MEM_TO_DEV,
854+ DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
855+ if (!desc) {
856+ ret = -EBUSY;
857+ goto err;
858+ }
859+
860+ dma->tx_running = 1;
861+
862+ desc->callback = omap_8250_dma_tx_complete;
863+ desc->callback_param = p;
864+
865+ dma->tx_cookie = dmaengine_submit(desc);
866+
867+ dma_sync_single_for_device(dma->txchan->device->dev, dma->tx_addr,
868+ UART_XMIT_SIZE, DMA_TO_DEVICE);
869+
870+ dma_async_issue_pending(dma->txchan);
871+ if (dma->tx_err)
872+ dma->tx_err = 0;
873+
874+ if (p->ier & UART_IER_THRI) {
875+ p->ier &= ~UART_IER_THRI;
876+ serial_out(p, UART_IER, p->ier);
877+ }
878+ if (skip_byte)
879+ serial_out(p, UART_TX, xmit->buf[xmit->tail]);
880+ return 0;
881+err:
882+ dma->tx_err = 1;
883+ return ret;
884+}
885+
886+/*
887+ * This is mostly serial8250_handle_irq(). We have a slightly different DMA
888+ * hoook for RX/TX and need different logic for them in the ISR. Therefore we
889+ * use the default routine in the non-DMA case and this one for with DMA.
890+ */
891+static int omap_8250_dma_handle_irq(struct uart_port *port)
892+{
893+ struct uart_8250_port *up = up_to_u8250p(port);
894+ unsigned char status;
895+ unsigned long flags;
896+ u8 iir;
897+ int dma_err = 0;
898+
899+ serial8250_rpm_get(up);
900+
901+ iir = serial_port_in(port, UART_IIR);
902+ if (iir & UART_IIR_NO_INT) {
903+ serial8250_rpm_put(up);
904+ return 0;
905+ }
906+
907+ spin_lock_irqsave(&port->lock, flags);
908+
909+ status = serial_port_in(port, UART_LSR);
910+
911+ if (status & (UART_LSR_DR | UART_LSR_BI)) {
912+
913+ dma_err = omap_8250_rx_dma(up, iir);
914+ if (dma_err) {
915+ status = serial8250_rx_chars(up, status);
916+ omap_8250_rx_dma(up, 0);
917+ }
918+ }
919+ serial8250_modem_status(up);
920+ if (status & UART_LSR_THRE && up->dma->tx_err) {
921+ if (uart_tx_stopped(&up->port) ||
922+ uart_circ_empty(&up->port.state->xmit)) {
923+ up->dma->tx_err = 0;
924+ serial8250_tx_chars(up);
925+ } else {
926+ /*
927+ * try again due to an earlier failer which
928+ * might have been resolved by now.
929+ */
930+ dma_err = omap_8250_tx_dma(up);
931+ if (dma_err)
932+ serial8250_tx_chars(up);
933+ }
934+ }
935+
936+ spin_unlock_irqrestore(&port->lock, flags);
937+ serial8250_rpm_put(up);
938+ return 1;
939+}
940+
941+static bool the_no_dma_filter_fn(struct dma_chan *chan, void *param)
942+{
943+ return false;
944+}
945+
946+#else
947+
948+static inline int omap_8250_rx_dma(struct uart_8250_port *p, unsigned int iir)
949+{
950+ return -EINVAL;
951+}
952+#endif
953+
954+static int omap8250_probe(struct platform_device *pdev)
955+{
956+ struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
957+ struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
958+ struct omap8250_priv *priv;
959+ struct uart_8250_port up;
960+ int ret;
961+ void __iomem *membase;
962+
963+ if (!regs || !irq) {
964+ dev_err(&pdev->dev, "missing registers or irq\n");
965+ return -EINVAL;
966+ }
967+
968+ priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
969+ if (!priv)
970+ return -ENOMEM;
971+
972+ membase = devm_ioremap_nocache(&pdev->dev, regs->start,
973+ resource_size(regs));
974+ if (!membase)
975+ return -ENODEV;
976+
977+ memset(&up, 0, sizeof(up));
978+ up.port.dev = &pdev->dev;
979+ up.port.mapbase = regs->start;
980+ up.port.membase = membase;
981+ up.port.irq = irq->start;
982+ /*
983+ * It claims to be 16C750 compatible however it is a little different.
984+ * It has EFR and has no FCR7_64byte bit. The AFE (which it claims to
985+ * have) is enabled via EFR instead of MCR. The type is set here 8250
986+ * just to get things going. UNKNOWN does not work for a few reasons and
987+ * we don't need our own type since we don't use 8250's set_termios()
988+ * or pm callback.
989+ */
990+ up.port.type = PORT_8250;
991+ up.port.iotype = UPIO_MEM;
992+ up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SOFT_FLOW |
993+ UPF_HARD_FLOW;
994+ up.port.private_data = priv;
995+
996+ up.port.regshift = 2;
997+ up.port.fifosize = 64;
998+ up.tx_loadsz = 64;
999+ up.capabilities = UART_CAP_FIFO;
1000+#ifdef CONFIG_PM_RUNTIME
1001+ /*
1002+ * PM_RUNTIME is mostly transparent. However to do it right we need to a
1003+ * TX empty interrupt before we can put the device to auto idle. So if
1004+ * PM_RUNTIME is not enabled we don't add that flag and can spare that
1005+ * one extra interrupt in the TX path.
1006+ */
1007+ up.capabilities |= UART_CAP_RPM;
1008+#endif
1009+ up.port.set_termios = omap_8250_set_termios;
1010+ up.port.pm = omap_8250_pm;
1011+ up.port.startup = omap_8250_startup;
1012+ up.port.shutdown = omap_8250_shutdown;
1013+ up.port.throttle = omap_8250_throttle;
1014+ up.port.unthrottle = omap_8250_unthrottle;
1015+
1016+ if (pdev->dev.of_node) {
1017+ ret = of_alias_get_id(pdev->dev.of_node, "serial");
1018+
1019+ of_property_read_u32(pdev->dev.of_node, "clock-frequency",
1020+ &up.port.uartclk);
1021+ priv->wakeirq = irq_of_parse_and_map(pdev->dev.of_node, 1);
1022+ } else {
1023+ ret = pdev->id;
1024+ }
1025+ if (ret < 0) {
1026+ dev_err(&pdev->dev, "failed to get alias/pdev id\n");
1027+ return ret;
1028+ }
1029+ up.port.line = ret;
1030+
1031+ if (!up.port.uartclk) {
1032+ up.port.uartclk = DEFAULT_CLK_SPEED;
1033+ dev_warn(&pdev->dev,
1034+ "No clock speed specified: using default: %d\n",
1035+ DEFAULT_CLK_SPEED);
1036+ }
1037+
1038+ priv->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
1039+ priv->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
1040+ pm_qos_add_request(&priv->pm_qos_request, PM_QOS_CPU_DMA_LATENCY,
1041+ priv->latency);
1042+ INIT_WORK(&priv->qos_work, omap8250_uart_qos_work);
1043+
1044+ device_init_wakeup(&pdev->dev, true);
1045+ pm_runtime_use_autosuspend(&pdev->dev);
1046+ pm_runtime_set_autosuspend_delay(&pdev->dev, -1);
1047+
1048+ pm_runtime_irq_safe(&pdev->dev);
1049+ pm_runtime_enable(&pdev->dev);
1050+
1051+ pm_runtime_get_sync(&pdev->dev);
1052+
1053+ omap_serial_fill_features_erratas(&up, priv);
1054+#ifdef CONFIG_SERIAL_8250_DMA
1055+ if (pdev->dev.of_node) {
1056+ /*
1057+ * Oh DMA support. If there are no DMA properties in the DT then
1058+ * we will fall back to a generic DMA channel which does not
1059+ * really work here. To ensure that we do not get a generic DMA
1060+ * channel assigned, we have the the_no_dma_filter_fn() here.
1061+ * To avoid "failed to request DMA" messages we check for DMA
1062+ * properties in DT.
1063+ */
1064+ ret = of_property_count_strings(pdev->dev.of_node, "dma-names");
1065+ if (ret == 2) {
1066+ up.dma = &priv->omap8250_dma;
1067+ up.port.handle_irq = omap_8250_dma_handle_irq;
1068+ priv->omap8250_dma.fn = the_no_dma_filter_fn;
1069+ priv->omap8250_dma.tx_dma = omap_8250_tx_dma;
1070+ priv->omap8250_dma.rx_dma = omap_8250_rx_dma;
1071+ priv->omap8250_dma.rx_size = RX_TRIGGER;
1072+ priv->omap8250_dma.rxconf.src_maxburst = RX_TRIGGER;
1073+ priv->omap8250_dma.txconf.dst_maxburst = TX_TRIGGER;
1074+
1075+ if (of_machine_is_compatible("ti,am33xx"))
1076+ priv->habit |= OMAP_DMA_TX_KICK;
1077+ }
1078+ }
1079+#endif
1080+ ret = serial8250_register_8250_port(&up);
1081+ if (ret < 0) {
1082+ dev_err(&pdev->dev, "unable to register 8250 port\n");
1083+ goto err;
1084+ }
1085+ priv->line = ret;
1086+ platform_set_drvdata(pdev, priv);
1087+ pm_runtime_mark_last_busy(&pdev->dev);
1088+ pm_runtime_put_autosuspend(&pdev->dev);
1089+ return 0;
1090+err:
1091+ pm_runtime_put(&pdev->dev);
1092+ pm_runtime_disable(&pdev->dev);
1093+ return ret;
1094+}
1095+
1096+static int omap8250_remove(struct platform_device *pdev)
1097+{
1098+ struct omap8250_priv *priv = platform_get_drvdata(pdev);
1099+
1100+ pm_runtime_put_sync(&pdev->dev);
1101+ pm_runtime_disable(&pdev->dev);
1102+ serial8250_unregister_port(priv->line);
1103+ pm_qos_remove_request(&priv->pm_qos_request);
1104+ device_init_wakeup(&pdev->dev, false);
1105+ return 0;
1106+}
1107+
1108+#if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_RUNTIME)
1109+
1110+static inline void omap8250_enable_wakeirq(struct omap8250_priv *priv,
1111+ bool enable)
1112+{
1113+ if (!priv->wakeirq)
1114+ return;
1115+
1116+ if (enable)
1117+ enable_irq(priv->wakeirq);
1118+ else
1119+ disable_irq_nosync(priv->wakeirq);
1120+}
1121+
1122+static void omap8250_enable_wakeup(struct omap8250_priv *priv,
1123+ bool enable)
1124+{
1125+ if (enable == priv->wakeups_enabled)
1126+ return;
1127+
1128+ omap8250_enable_wakeirq(priv, enable);
1129+ priv->wakeups_enabled = enable;
1130+}
1131+#endif
1132+
1133+#ifdef CONFIG_PM_SLEEP
1134+static int omap8250_prepare(struct device *dev)
1135+{
1136+ struct omap8250_priv *priv = dev_get_drvdata(dev);
1137+
1138+ if (!priv)
1139+ return 0;
1140+ priv->is_suspending = true;
1141+ return 0;
1142+}
1143+
1144+static void omap8250_complete(struct device *dev)
1145+{
1146+ struct omap8250_priv *priv = dev_get_drvdata(dev);
1147+
1148+ if (!priv)
1149+ return;
1150+ priv->is_suspending = false;
1151+}
1152+
1153+static int omap8250_suspend(struct device *dev)
1154+{
1155+ struct omap8250_priv *priv = dev_get_drvdata(dev);
1156+
1157+ serial8250_suspend_port(priv->line);
1158+ flush_work(&priv->qos_work);
1159+
1160+ if (device_may_wakeup(dev))
1161+ omap8250_enable_wakeup(priv, true);
1162+ else
1163+ omap8250_enable_wakeup(priv, false);
1164+ return 0;
1165+}
1166+
1167+static int omap8250_resume(struct device *dev)
1168+{
1169+ struct omap8250_priv *priv = dev_get_drvdata(dev);
1170+
1171+ if (device_may_wakeup(dev))
1172+ omap8250_enable_wakeup(priv, false);
1173+
1174+ serial8250_resume_port(priv->line);
1175+ return 0;
1176+}
1177+#else
1178+#define omap8250_prepare NULL
1179+#define omap8250_complete NULL
1180+#endif
1181+
1182+#ifdef CONFIG_PM_RUNTIME
1183+static int omap8250_lost_context(struct uart_8250_port *up)
1184+{
1185+ u32 val;
1186+
1187+ val = serial_in(up, UART_OMAP_MDR1);
1188+ /*
1189+ * If we lose context, then MDR1 is set to its reset value which is
1190+ * UART_OMAP_MDR1_DISABLE. After set_termios() we set it either to 13x
1191+ * or 16x but never to disable again.
1192+ */
1193+ if (val == UART_OMAP_MDR1_DISABLE)
1194+ return 1;
1195+ return 0;
1196+}
1197+
1198+static int omap8250_runtime_suspend(struct device *dev)
1199+{
1200+ struct omap8250_priv *priv = dev_get_drvdata(dev);
1201+ struct uart_8250_port *up;
1202+
1203+ up = serial8250_get_port(priv->line);
1204+ /*
1205+ * When using 'no_console_suspend', the console UART must not be
1206+ * suspended. Since driver suspend is managed by runtime suspend,
1207+ * preventing runtime suspend (by returning error) will keep device
1208+ * active during suspend.
1209+ */
1210+ if (priv->is_suspending && !console_suspend_enabled) {
1211+ if (uart_console(&up->port))
1212+ return -EBUSY;
1213+ }
1214+
1215+ omap8250_enable_wakeup(priv, true);
1216+ if (up->dma)
1217+ omap_8250_rx_dma(up, UART_IIR_RX_TIMEOUT);
1218+
1219+ priv->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
1220+ schedule_work(&priv->qos_work);
1221+
1222+ return 0;
1223+}
1224+
1225+static int omap8250_runtime_resume(struct device *dev)
1226+{
1227+ struct omap8250_priv *priv = dev_get_drvdata(dev);
1228+ struct uart_8250_port *up;
1229+ int loss_cntx;
1230+
1231+ /* In case runtime-pm tries this before we are setup */
1232+ if (!priv)
1233+ return 0;
1234+
1235+ up = serial8250_get_port(priv->line);
1236+ omap8250_enable_wakeup(priv, false);
1237+ loss_cntx = omap8250_lost_context(up);
1238+
1239+ if (loss_cntx)
1240+ omap8250_restore_regs(up);
1241+
1242+ if (up->dma)
1243+ omap_8250_rx_dma(up, 0);
1244+
1245+ priv->latency = priv->calc_latency;
1246+ schedule_work(&priv->qos_work);
1247+ return 0;
1248+}
1249+#endif
1250+
1251+static const struct dev_pm_ops omap8250_dev_pm_ops = {
1252+ SET_SYSTEM_SLEEP_PM_OPS(omap8250_suspend, omap8250_resume)
1253+ SET_RUNTIME_PM_OPS(omap8250_runtime_suspend,
1254+ omap8250_runtime_resume, NULL)
1255+ .prepare = omap8250_prepare,
1256+ .complete = omap8250_complete,
1257+};
1258+
1259+static const struct of_device_id omap8250_dt_ids[] = {
1260+ { .compatible = "ti,omap2-uart" },
1261+ { .compatible = "ti,omap3-uart" },
1262+ { .compatible = "ti,omap4-uart" },
1263+ {},
1264+};
1265+MODULE_DEVICE_TABLE(of, omap8250_dt_ids);
1266+
1267+static struct platform_driver omap8250_platform_driver = {
1268+ .driver = {
1269+ .name = "omap8250",
1270+ .pm = &omap8250_dev_pm_ops,
1271+ .of_match_table = omap8250_dt_ids,
1272+ .owner = THIS_MODULE,
1273+ },
1274+ .probe = omap8250_probe,
1275+ .remove = omap8250_remove,
1276+};
1277+module_platform_driver(omap8250_platform_driver);
1278+
1279+MODULE_AUTHOR("Sebastian Andrzej Siewior");
1280+MODULE_DESCRIPTION("OMAP 8250 Driver");
1281+MODULE_LICENSE("GPL v2");
drivers/tty/serial/8250/8250_pci.c+153−45
@@ -79,29 +79,24 @@ setup_port(struct serial_private *priv, struct uart_8250_port *port, · 78 unmodified lines
7979 int bar, int offset, int regshift)
8080 {
8181 struct pci_dev *dev = priv->dev;
82− unsigned long base, len;
8382
8483 if (bar >= PCI_NUM_BAR_RESOURCES)
8584 return -EINVAL;
8685
87− base = pci_resource_start(dev, bar);
88−
8986 if (pci_resource_flags(dev, bar) & IORESOURCE_MEM) {
90− len = pci_resource_len(dev, bar);
91−
9287 if (!priv->remapped_bar[bar])
93− priv->remapped_bar[bar] = ioremap_nocache(base, len);
88+ priv->remapped_bar[bar] = pci_ioremap_bar(dev, bar);
9489 if (!priv->remapped_bar[bar])
9590 return -ENOMEM;
9691
9792 port->port.iotype = UPIO_MEM;
9893 port->port.iobase = 0;
99− port->port.mapbase = base + offset;
94+ port->port.mapbase = pci_resource_start(dev, bar) + offset;
10095 port->port.membase = priv->remapped_bar[bar] + offset;
10196 port->port.regshift = regshift;
10297 } else {
10398 port->port.iotype = UPIO_PORT;
104− port->port.iobase = base + offset;
99+ port->port.iobase = pci_resource_start(dev, bar) + offset;
105100 port->port.mapbase = 0;
106101 port->port.membase = NULL;
107102 port->port.regshift = 0;
@@ -317,7 +312,6 @@ static void pci_plx9050_exit(struct pci_dev *dev) · 209 unmodified lines
317312 static void pci_ni8420_exit(struct pci_dev *dev)
318313 {
319314 void __iomem *p;
320− unsigned long base, len;
321315 unsigned int bar = 0;
322316
323317 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) {
@@ -325,9 +319,7 @@ static void pci_ni8420_exit(struct pci_dev *dev) · 1 unmodified line
325319 return;
326320 }
327321
328− base = pci_resource_start(dev, bar);
329− len = pci_resource_len(dev, bar);
330− p = ioremap_nocache(base, len);
322+ p = pci_ioremap_bar(dev, bar);
331323 if (p == NULL)
332324 return;
333325
@@ -349,7 +341,6 @@ static void pci_ni8420_exit(struct pci_dev *dev) · 15 unmodified lines
349341 static void pci_ni8430_exit(struct pci_dev *dev)
350342 {
351343 void __iomem *p;
352− unsigned long base, len;
353344 unsigned int bar = 0;
354345
355346 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) {
@@ -357,9 +348,7 @@ static void pci_ni8430_exit(struct pci_dev *dev) · 1 unmodified line
357348 return;
358349 }
359350
360− base = pci_resource_start(dev, bar);
361− len = pci_resource_len(dev, bar);
362− p = ioremap_nocache(base, len);
351+ p = pci_ioremap_bar(dev, bar);
363352 if (p == NULL)
364353 return;
365354
@@ -682,7 +671,6 @@ static int pci_xircom_init(struct pci_dev *dev) · 316 unmodified lines
682671 static int pci_ni8420_init(struct pci_dev *dev)
683672 {
684673 void __iomem *p;
685− unsigned long base, len;
686674 unsigned int bar = 0;
687675
688676 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) {
@@ -690,9 +678,7 @@ static int pci_ni8420_init(struct pci_dev *dev) · 1 unmodified line
690678 return 0;
691679 }
692680
693− base = pci_resource_start(dev, bar);
694− len = pci_resource_len(dev, bar);
695− p = ioremap_nocache(base, len);
681+ p = pci_ioremap_bar(dev, bar);
696682 if (p == NULL)
697683 return -ENOMEM;
698684
@@ -714,7 +700,7 @@ static int pci_ni8420_init(struct pci_dev *dev) · 15 unmodified lines
714700 static int pci_ni8430_init(struct pci_dev *dev)
715701 {
716702 void __iomem *p;
717− unsigned long base, len;
703+ struct pci_bus_region region;
718704 u32 device_window;
719705 unsigned int bar = 0;
720706
@@ -723,14 +709,17 @@ static int pci_ni8430_init(struct pci_dev *dev) · 2 unmodified lines
723709 return 0;
724710 }
725711
726− base = pci_resource_start(dev, bar);
727− len = pci_resource_len(dev, bar);
728− p = ioremap_nocache(base, len);
712+ p = pci_ioremap_bar(dev, bar);
729713 if (p == NULL)
730714 return -ENOMEM;
731715
732− /* Set device window address and size in BAR0 */
733− device_window = ((base + MITE_IOWBSR1_WIN_OFFSET) & 0xffffff00)
716+ /*
717+ * Set device window address and size in BAR0, while acknowledging that
718+ * the resource structure may contain a translated address that differs
719+ * from the address the device responds to.
720+ */
721+ pcibios_resource_to_bus(dev->bus, &region, &dev->resource[bar]);
722+ device_window = ((region.start + MITE_IOWBSR1_WIN_OFFSET) & 0xffffff00)
734723 | MITE_IOWBSR1_WENAB | MITE_IOWBSR1_WSIZE;
735724 writel(device_window, p + MITE_IOWBSR1);
736725
@@ -757,8 +746,8 @@ pci_ni8430_setup(struct serial_private *priv, · 20 unmodified lines
757746 const struct pciserial_board *board,
758747 struct uart_8250_port *port, int idx)
759748 {
749+ struct pci_dev *dev = priv->dev;
760750 void __iomem *p;
761− unsigned long base, len;
762751 unsigned int bar, offset = board->first_offset;
763752
764753 if (idx >= board->num_ports)
@@ -767,9 +756,9 @@ pci_ni8430_setup(struct serial_private *priv, · 2 unmodified lines
767756 bar = FL_GET_BASE(board->flags);
768757 offset += idx * board->uart_offset;
769758
770− base = pci_resource_start(priv->dev, bar);
771− len = pci_resource_len(priv->dev, bar);
772− p = ioremap_nocache(base, len);
759+ p = pci_ioremap_bar(dev, bar);
760+ if (!p)
761+ return -ENOMEM;
773762
774763 /* enable the transceiver */
775764 writeb(readb(p + offset + NI8430_PORTCON) | NI8430_PORTCON_TXVR_ENABLE,
@@ -1002,6 +991,40 @@ static void pci_ite887x_exit(struct pci_dev *dev) · 226 unmodified lines
1002991 release_region(ioport, ITE_887x_IOSIZE);
1003992 }
1004993
994+/*
995+ * EndRun Technologies.
996+ * Determine the number of ports available on the device.
997+ */
998+#define PCI_VENDOR_ID_ENDRUN 0x7401
999+#define PCI_DEVICE_ID_ENDRUN_1588 0xe100
1000+
1001+static int pci_endrun_init(struct pci_dev *dev)
1002+{
1003+ u8 __iomem *p;
1004+ unsigned long deviceID;
1005+ unsigned int number_uarts = 0;
1006+
1007+ /* EndRun device is all 0xexxx */
1008+ if (dev->vendor == PCI_VENDOR_ID_ENDRUN &&
1009+ (dev->device & 0xf000) != 0xe000)
1010+ return 0;
1011+
1012+ p = pci_iomap(dev, 0, 5);
1013+ if (p == NULL)
1014+ return -ENOMEM;
1015+
1016+ deviceID = ioread32(p);
1017+ /* EndRun device */
1018+ if (deviceID == 0x07000200) {
1019+ number_uarts = ioread8(p + 4);
1020+ dev_dbg(&dev->dev,
1021+ "%d ports detected on EndRun PCI Express device\n",
1022+ number_uarts);
1023+ }
1024+ pci_iounmap(dev, p);
1025+ return number_uarts;
1026+}
1027+
10051028 /*
10061029 * Oxford Semiconductor Inc.
10071030 * Check that device is part of the Tornado range of devices, then determine
@@ -1531,25 +1554,48 @@ static int pci_fintek_setup(struct serial_private *priv, · 523 unmodified lines
15311554 unsigned long iobase;
15321555 unsigned long ciobase = 0;
15331556 u8 config_base;
1557+ u32 bar_data[3];
15341558
15351559 /*
1536− * We are supposed to be able to read these from the PCI config space,
1537− * but the values there don't seem to match what we need to use, so
1538− * just use these hard-coded values for now, as they are correct.
1560+ * Find each UARTs offset in PCI configuraion space
15391561 */
15401562 switch (idx) {
1541− case 0: iobase = 0xe000; config_base = 0x40; break;
1542− case 1: iobase = 0xe008; config_base = 0x48; break;
1543− case 2: iobase = 0xe010; config_base = 0x50; break;
1544− case 3: iobase = 0xe018; config_base = 0x58; break;
1545− case 4: iobase = 0xe020; config_base = 0x60; break;
1546− case 5: iobase = 0xe028; config_base = 0x68; break;
1547− case 6: iobase = 0xe030; config_base = 0x70; break;
1548− case 7: iobase = 0xe038; config_base = 0x78; break;
1549− case 8: iobase = 0xe040; config_base = 0x80; break;
1550− case 9: iobase = 0xe048; config_base = 0x88; break;
1551− case 10: iobase = 0xe050; config_base = 0x90; break;
1552− case 11: iobase = 0xe058; config_base = 0x98; break;
1563+ case 0:
1564+ config_base = 0x40;
1565+ break;
1566+ case 1:
1567+ config_base = 0x48;
1568+ break;
1569+ case 2:
1570+ config_base = 0x50;
1571+ break;
1572+ case 3:
1573+ config_base = 0x58;
1574+ break;
1575+ case 4:
1576+ config_base = 0x60;
1577+ break;
1578+ case 5:
1579+ config_base = 0x68;
1580+ break;
1581+ case 6:
1582+ config_base = 0x70;
1583+ break;
1584+ case 7:
1585+ config_base = 0x78;
1586+ break;
1587+ case 8:
1588+ config_base = 0x80;
1589+ break;
1590+ case 9:
1591+ config_base = 0x88;
1592+ break;
1593+ case 10:
1594+ config_base = 0x90;
1595+ break;
1596+ case 11:
1597+ config_base = 0x98;
1598+ break;
15531599 default:
15541600 /* Unknown number of ports, get out of here */
15551601 return -EINVAL;
@@ -1560,6 +1606,14 @@ static int pci_fintek_setup(struct serial_private *priv, · 4 unmodified lines
15601606 ciobase = (int)(base + (0x8 * idx));
15611607 }
15621608
1609+ /* Get the io address dispatch from the BIOS */
1610+ pci_read_config_dword(pdev, 0x24, &bar_data[0]);
1611+ pci_read_config_dword(pdev, 0x20, &bar_data[1]);
1612+ pci_read_config_dword(pdev, 0x1c, &bar_data[2]);
1613+
1614+ /* Calculate Real IO Port */
1615+ iobase = (bar_data[idx/4] & 0xffffffe0) + (idx % 4) * 8;
1616+
15631617 dev_dbg(&pdev->dev, "%s: idx=%d iobase=0x%lx ciobase=0x%lx config_base=0x%2x\n",
15641618 __func__, idx, iobase, ciobase, config_base);
15651619
@@ -1760,6 +1814,16 @@ pci_wch_ch353_setup(struct serial_private *priv, · 194 unmodified lines
17601814 return pci_default_setup(priv, board, port, idx);
17611815 }
17621816
1817+static int
1818+pci_wch_ch382_setup(struct serial_private *priv,
1819+ const struct pciserial_board *board,
1820+ struct uart_8250_port *port, int idx)
1821+{
1822+ port->port.flags |= UPF_FIXED_TYPE;
1823+ port->port.type = PORT_16850;
1824+ return pci_default_setup(priv, board, port, idx);
1825+}
1826+
17631827 #define PCI_VENDOR_ID_SBSMODULARIO 0x124B
17641828 #define PCI_SUBVENDOR_ID_SBSMODULARIO 0x124B
17651829 #define PCI_DEVICE_ID_OCTPRO 0x0001
@@ -1814,6 +1878,8 @@ pci_wch_ch353_setup(struct serial_private *priv, · 48 unmodified lines
18141878 #define PCI_VENDOR_ID_SUNIX 0x1fd4
18151879 #define PCI_DEVICE_ID_SUNIX_1999 0x1999
18161880
1881+#define PCIE_VENDOR_ID_WCH 0x1c00
1882+#define PCIE_DEVICE_ID_WCH_CH382_2S1P 0x3250
18171883
18181884 /* Unknown vendors/cards - this should not be in linux/pci_ids.h */
18191885 #define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584
@@ -2345,6 +2411,17 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = { · 525 unmodified lines
23452411 .init = pci_netmos_init,
23462412 .setup = pci_netmos_9900_setup,
23472413 },
2414+ /*
2415+ * EndRun Technologies
2416+ */
2417+ {
2418+ .vendor = PCI_VENDOR_ID_ENDRUN,
2419+ .device = PCI_ANY_ID,
2420+ .subvendor = PCI_ANY_ID,
2421+ .subdevice = PCI_ANY_ID,
2422+ .init = pci_endrun_init,
2423+ .setup = pci_default_setup,
2424+ },
23482425 /*
23492426 * For Oxford Semiconductor Tornado based devices
23502427 */
@@ -2494,6 +2571,14 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = { · 143 unmodified lines
24942571 .subdevice = PCI_ANY_ID,
24952572 .setup = pci_wch_ch353_setup,
24962573 },
2574+ /* WCH CH382 2S1P card (16750 clone) */
2575+ {
2576+ .vendor = PCIE_VENDOR_ID_WCH,
2577+ .device = PCIE_DEVICE_ID_WCH_CH382_2S1P,
2578+ .subvendor = PCI_ANY_ID,
2579+ .subdevice = PCI_ANY_ID,
2580+ .setup = pci_wch_ch382_setup,
2581+ },
24972582 /*
24982583 * ASIX devices with FIFO bug
24992584 */
@@ -2754,6 +2839,7 @@ enum pci_board_num_t { · 254 unmodified lines
27542839 pbn_panacom2,
27552840 pbn_panacom4,
27562841 pbn_plx_romulus,
2842+ pbn_endrun_2_4000000,
27572843 pbn_oxsemi,
27582844 pbn_oxsemi_1_4000000,
27592845 pbn_oxsemi_2_4000000,
@@ -3298,6 +3384,20 @@ static struct pciserial_board pci_boards[] = { · 538 unmodified lines
32983384 .first_offset = 0x03,
32993385 },
33003386
3387+ /*
3388+ * EndRun Technologies
3389+ * Uses the size of PCI Base region 0 to
3390+ * signal now many ports are available
3391+ * 2 port 952 Uart support
3392+ */
3393+ [pbn_endrun_2_4000000] = {
3394+ .flags = FL_BASE0,
3395+ .num_ports = 2,
3396+ .base_baud = 4000000,
3397+ .uart_offset = 0x200,
3398+ .first_offset = 0x1000,
3399+ },
3400+
33013401 /*
33023402 * This board uses the size of PCI Base region 0 to
33033403 * signal now many ports are available
@@ -3586,6 +3686,7 @@ static const struct pci_device_id blacklist[] = { · 282 unmodified lines
35863686 /* multi-io cards handled by parport_serial */
35873687 { PCI_DEVICE(0x4348, 0x7053), }, /* WCH CH353 2S1P */
35883688 { PCI_DEVICE(0x4348, 0x5053), }, /* WCH CH353 1S1P */
3689+ { PCI_DEVICE(0x1c00, 0x3250), }, /* WCH CH382 2S1P */
35893690 };
35903691
35913692 /*
@@ -4170,6 +4271,13 @@ static struct pci_device_id serial_pci_tbl[] = { · 578 unmodified lines
41704271 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_ROMULUS,
41714272 0x10b5, 0x106a, 0, 0,
41724273 pbn_plx_romulus },
4274+ /*
4275+ * EndRun Technologies. PCI express device range.
4276+ * EndRun PTP/1588 has 2 Native UARTs.
4277+ */
4278+ { PCI_VENDOR_ID_ENDRUN, PCI_DEVICE_ID_ENDRUN_1588,
4279+ PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4280+ pbn_endrun_2_4000000 },
41734281 /*
41744282 * Quatech cards. These actually have configurable clocks but for
41754283 * now we just use the default.
drivers/tty/serial/8250/Kconfig+10−1
@@ -293,12 +293,21 @@ config SERIAL_8250_EM · 292 unmodified lines
293293
294294 config SERIAL_8250_RT288X
295295 bool "Ralink RT288x/RT305x/RT3662/RT3883 serial port support"
296− depends on SERIAL_8250 && (SOC_RT288X || SOC_RT305X || SOC_RT3883)
296+ depends on SERIAL_8250 && (SOC_RT288X || SOC_RT305X || SOC_RT3883 || SOC_MT7620)
297297 help
298298 If you have a Ralink RT288x/RT305x SoC based board and want to use the
299299 serial port, say Y to this option. The driver can handle up to 2 serial
300300 ports. If unsure, say N.
301301
302+config SERIAL_8250_OMAP
303+ tristate "Support for OMAP internal UART (8250 based driver)"
304+ depends on SERIAL_8250 && ARCH_OMAP2PLUS
305+ help
306+ If you have a machine based on an Texas Instruments OMAP CPU you
307+ can enable its onboard serial ports by enabling this option.
308+
309+ This driver uses ttyS instead of ttyO.
310+
302311 config SERIAL_8250_FINTEK
303312 tristate "Support for Fintek F81216A LPC to 4 UART"
304313 depends on SERIAL_8250 && PNP
drivers/tty/serial/8250/Makefile+1−0
@@ -20,5 +20,6 @@ obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o · 19 unmodified lines
2020 obj-$(CONFIG_SERIAL_8250_FSL) += 8250_fsl.o
2121 obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o
2222 obj-$(CONFIG_SERIAL_8250_EM) += 8250_em.o
23+obj-$(CONFIG_SERIAL_8250_OMAP) += 8250_omap.o
2324 obj-$(CONFIG_SERIAL_8250_FINTEK) += 8250_fintek.o
2425 obj-$(CONFIG_SERIAL_8250_MT6577) += 8250_mtk.o
drivers/tty/serial/Kconfig+14−10
@@ -1029,11 +1029,11 @@ config SERIAL_VR41XX_CONSOLE · 1028 unmodified lines
10291029 a console on a serial port, say Y. Otherwise, say N.
10301030
10311031 config SERIAL_JSM
1032− tristate "Digi International NEO PCI Support"
1032+ tristate "Digi International NEO and Classic PCI Support"
10331033 depends on PCI
10341034 select SERIAL_CORE
10351035 help
1036− This is a driver for Digi International's Neo series
1036+ This is a driver for Digi International's Neo and Classic series
10371037 of cards which provide multiple serial ports. You would need
10381038 something like this to connect more than two modems to your Linux
10391039 box, for instance in order to become a dial-in server. This driver
@@ -1281,22 +1281,25 @@ config SERIAL_TIMBERDALE · 241 unmodified lines
12811281 Add support for UART controller on timberdale.
12821282
12831283 config SERIAL_BCM63XX
1284− tristate "bcm63xx serial port support"
1284+ tristate "Broadcom BCM63xx/BCM33xx UART support"
12851285 select SERIAL_CORE
1286− depends on BCM63XX
1286+ depends on MIPS || ARM || COMPILE_TEST
12871287 help
1288− If you have a bcm63xx CPU, you can enable its onboard
1289− serial port by enabling this options.
1288+ This enables the driver for the onchip UART core found on
1289+ the following chipsets:
12901290
1291− To compile this driver as a module, choose M here: the
1292− module will be called bcm963xx_uart.
1291+ BCM33xx (cable modem)
1292+ BCM63xx/BCM63xxx (DSL)
1293+ BCM68xx (PON)
1294+ BCM7xxx (STB) - DOCSIS console
12931295
12941296 config SERIAL_BCM63XX_CONSOLE
1295− bool "Console on bcm63xx serial port"
1297+ bool "Console on BCM63xx serial port"
12961298 depends on SERIAL_BCM63XX=y
12971299 select SERIAL_CORE_CONSOLE
1300+ select SERIAL_EARLYCON
12981301 help
1299− If you have enabled the serial port on the bcm63xx CPU
1302+ If you have enabled the serial port on the BCM63xx CPU
13001303 you can make it the console by answering Y to this option.
13011304
13021305 config SERIAL_GRLIB_GAISLER_APBUART
@@ -1408,6 +1411,7 @@ config SERIAL_MXS_AUART · 105 unmodified lines
14081411 depends on ARCH_MXS
14091412 tristate "MXS AUART support"
14101413 select SERIAL_CORE
1414+ select SERIAL_MCTRL_GPIO if GPIOLIB
14111415 help
14121416 This driver supports the MXS Application UART (AUART) port.
14131417
drivers/tty/serial/amba-pl010.c+45−15
@@ -75,7 +75,8 @@ struct uart_amba_port { · 74 unmodified lines
7575
7676 static void pl010_stop_tx(struct uart_port *port)
7777 {
78− struct uart_amba_port *uap = (struct uart_amba_port *)port;
78+ struct uart_amba_port *uap =
79+ container_of(port, struct uart_amba_port, port);
7980 unsigned int cr;
8081
8182 cr = readb(uap->port.membase + UART010_CR);
@@ -85,7 +86,8 @@ static void pl010_stop_tx(struct uart_port *port) · 3 unmodified lines
8586
8687 static void pl010_start_tx(struct uart_port *port)
8788 {
88− struct uart_amba_port *uap = (struct uart_amba_port *)port;
89+ struct uart_amba_port *uap =
90+ container_of(port, struct uart_amba_port, port);
8991 unsigned int cr;
9092
9193 cr = readb(uap->port.membase + UART010_CR);
@@ -95,7 +97,8 @@ static void pl010_start_tx(struct uart_port *port) · 3 unmodified lines
9597
9698 static void pl010_stop_rx(struct uart_port *port)
9799 {
98− struct uart_amba_port *uap = (struct uart_amba_port *)port;
100+ struct uart_amba_port *uap =
101+ container_of(port, struct uart_amba_port, port);
99102 unsigned int cr;
100103
101104 cr = readb(uap->port.membase + UART010_CR);
@@ -103,11 +106,22 @@ static void pl010_stop_rx(struct uart_port *port) · 1 unmodified line
103106 writel(cr, uap->port.membase + UART010_CR);
104107 }
105108
106−static void pl010_enable_ms(struct uart_port *port)
109+static void pl010_disable_ms(struct uart_port *port)
107110 {
108111 struct uart_amba_port *uap = (struct uart_amba_port *)port;
109112 unsigned int cr;
110113
114+ cr = readb(uap->port.membase + UART010_CR);
115+ cr &= ~UART010_CR_MSIE;
116+ writel(cr, uap->port.membase + UART010_CR);
117+}
118+
119+static void pl010_enable_ms(struct uart_port *port)
120+{
121+ struct uart_amba_port *uap =
122+ container_of(port, struct uart_amba_port, port);
123+ unsigned int cr;
124+
111125 cr = readb(uap->port.membase + UART010_CR);
112126 cr |= UART010_CR_MSIE;
113127 writel(cr, uap->port.membase + UART010_CR);
@@ -259,14 +273,16 @@ static irqreturn_t pl010_int(int irq, void *dev_id) · 145 unmodified lines
259273
260274 static unsigned int pl010_tx_empty(struct uart_port *port)
261275 {
262− struct uart_amba_port *uap = (struct uart_amba_port *)port;
276+ struct uart_amba_port *uap =
277+ container_of(port, struct uart_amba_port, port);
263278 unsigned int status = readb(uap->port.membase + UART01x_FR);
264279 return status & UART01x_FR_BUSY ? 0 : TIOCSER_TEMT;
265280 }
266281
267282 static unsigned int pl010_get_mctrl(struct uart_port *port)
268283 {
269− struct uart_amba_port *uap = (struct uart_amba_port *)port;
284+ struct uart_amba_port *uap =
285+ container_of(port, struct uart_amba_port, port);
270286 unsigned int result = 0;
271287 unsigned int status;
272288
@@ -283,7 +299,8 @@ static unsigned int pl010_get_mctrl(struct uart_port *port) · 10 unmodified lines
283299
284300 static void pl010_set_mctrl(struct uart_port *port, unsigned int mctrl)
285301 {
286− struct uart_amba_port *uap = (struct uart_amba_port *)port;
302+ struct uart_amba_port *uap =
303+ container_of(port, struct uart_amba_port, port);
287304
288305 if (uap->data)
289306 uap->data->set_mctrl(uap->dev, uap->port.membase, mctrl);
@@ -291,7 +308,8 @@ static void pl010_set_mctrl(struct uart_port *port, unsigned int mctrl) · 1 unmodified line
291308
292309 static void pl010_break_ctl(struct uart_port *port, int break_state)
293310 {
294− struct uart_amba_port *uap = (struct uart_amba_port *)port;
311+ struct uart_amba_port *uap =
312+ container_of(port, struct uart_amba_port, port);
295313 unsigned long flags;
296314 unsigned int lcr_h;
297315
@@ -307,7 +325,8 @@ static void pl010_break_ctl(struct uart_port *port, int break_state) · 9 unmodified lines
307325
308326 static int pl010_startup(struct uart_port *port)
309327 {
310− struct uart_amba_port *uap = (struct uart_amba_port *)port;
328+ struct uart_amba_port *uap =
329+ container_of(port, struct uart_amba_port, port);
311330 int retval;
312331
313332 /*
@@ -347,7 +366,8 @@ static int pl010_startup(struct uart_port *port) · 33 unmodified lines
347366
348367 static void pl010_shutdown(struct uart_port *port)
349368 {
350− struct uart_amba_port *uap = (struct uart_amba_port *)port;
369+ struct uart_amba_port *uap =
370+ container_of(port, struct uart_amba_port, port);
351371
352372 /*
353373 * Free the interrupt
@@ -374,7 +394,8 @@ static void · 20 unmodified lines
374394 pl010_set_termios(struct uart_port *port, struct ktermios *termios,
375395 struct ktermios *old)
376396 {
377− struct uart_amba_port *uap = (struct uart_amba_port *)port;
397+ struct uart_amba_port *uap =
398+ container_of(port, struct uart_amba_port, port);
378399 unsigned int lcr_h, old_cr;
379400 unsigned long flags;
380401 unsigned int baud, quot;
@@ -468,13 +489,21 @@ pl010_set_termios(struct uart_port *port, struct ktermios *termios, · 87 unmodified lines
468489 spin_unlock_irqrestore(&uap->port.lock, flags);
469490 }
470491
471−static void pl010_set_ldisc(struct uart_port *port, int new)
492+static void pl010_set_ldisc(struct uart_port *port, struct ktermios *termios)
472493 {
473− if (new == N_PPS) {
494+ if (termios->c_line == N_PPS) {
474495 port->flags |= UPF_HARDPPS_CD;
496+ spin_lock_irq(&port->lock);
475497 pl010_enable_ms(port);
476− } else
498+ spin_unlock_irq(&port->lock);
499+ } else {
477500 port->flags &= ~UPF_HARDPPS_CD;
501+ if (!UART_ENABLE_MS(port, termios->c_cflag)) {
502+ spin_lock_irq(&port->lock);
503+ pl010_disable_ms(port);
504+ spin_unlock_irq(&port->lock);
505+ }
506+ }
478507 }
479508
480509 static const char *pl010_type(struct uart_port *port)
@@ -551,7 +580,8 @@ static struct uart_amba_port *amba_ports[UART_NR]; · 70 unmodified lines
551580
552581 static void pl010_console_putchar(struct uart_port *port, int ch)
553582 {
554− struct uart_amba_port *uap = (struct uart_amba_port *)port;
583+ struct uart_amba_port *uap =
584+ container_of(port, struct uart_amba_port, port);
555585 unsigned int status;
556586
557587 do {
drivers/tty/serial/amba-pl011.c+43−5
@@ -246,6 +246,7 @@ static int pl011_sgbuf_init(struct dma_chan *chan, struct pl011_sgbuf *sg, · 245 unmodified lines
246246 sg_set_page(&sg->sg, phys_to_page(dma_addr),
247247 PL011_DMA_BUFFER_SIZE, offset_in_page(dma_addr));
248248 sg_dma_address(&sg->sg) = dma_addr;
249+ sg_dma_len(&sg->sg) = PL011_DMA_BUFFER_SIZE;
249250
250251 return 0;
251252 }
@@ -321,10 +322,26 @@ static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port * · 69 unmodified lines
321322 .src_maxburst = uap->fifosize >> 2,
322323 .device_fc = false,
323324 };
325+ struct dma_slave_caps caps;
324326
327+ /*
328+ * Some DMA controllers provide information on their capabilities.
329+ * If the controller does, check for suitable residue processing
330+ * otherwise assime all is well.
331+ */
332+ if (0 == dma_get_slave_caps(chan, &caps)) {
333+ if (caps.residue_granularity ==
334+ DMA_RESIDUE_GRANULARITY_DESCRIPTOR) {
335+ dma_release_channel(chan);
336+ dev_info(uap->port.dev,
337+ "RX DMA disabled - no residue processing\n");
338+ return;
339+ }
340+ }
325341 dmaengine_slave_config(chan, &rx_conf);
326342 uap->dmarx.chan = chan;
327343
344+ uap->dmarx.auto_poll_rate = false;
328345 if (plat && plat->dma_rx_poll_enable) {
329346 /* Set poll rate if specified. */
330347 if (plat->dma_rx_poll_rate) {
@@ -345,9 +362,24 @@ static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port * · 14 unmodified lines
345362 plat->dma_rx_poll_timeout;
346363 else
347364 uap->dmarx.poll_timeout = 3000;
348− } else
349− uap->dmarx.auto_poll_rate = false;
350−
365+ } else if (!plat && dev->of_node) {
366+ uap->dmarx.auto_poll_rate = of_property_read_bool(
367+ dev->of_node, "auto-poll");
368+ if (uap->dmarx.auto_poll_rate) {
369+ u32 x;
370+
371+ if (0 == of_property_read_u32(dev->of_node,
372+ "poll-rate-ms", &x))
373+ uap->dmarx.poll_rate = x;
374+ else
375+ uap->dmarx.poll_rate = 100;
376+ if (0 == of_property_read_u32(dev->of_node,
377+ "poll-timeout-ms", &x))
378+ uap->dmarx.poll_timeout = x;
379+ else
380+ uap->dmarx.poll_timeout = 3000;
381+ }
382+ }
351383 dev_info(uap->port.dev, "DMA channel RX %s\n",
352384 dma_chan_name(uap->dmarx.chan));
353385 }
@@ -501,7 +533,11 @@ static int pl011_dma_tx_refill(struct uart_amba_port *uap) · 147 unmodified lines
501533 memcpy(&dmatx->buf[0], &xmit->buf[xmit->tail], count);
502534 else {
503535 size_t first = UART_XMIT_SIZE - xmit->tail;
504− size_t second = xmit->head;
536+ size_t second;
537+
538+ if (first > count)
539+ first = count;
540+ second = count - first;
505541
506542 memcpy(&dmatx->buf[0], &xmit->buf[xmit->tail], first);
507543 if (second)
@@ -988,7 +1024,7 @@ static void pl011_dma_startup(struct uart_amba_port *uap) · 480 unmodified lines
9881024 if (!uap->dmatx.chan)
9891025 return;
9901026
991− uap->dmatx.buf = kmalloc(PL011_DMA_BUFFER_SIZE, GFP_KERNEL);
1027+ uap->dmatx.buf = kmalloc(PL011_DMA_BUFFER_SIZE, GFP_KERNEL | __GFP_DMA);
9921028 if (!uap->dmatx.buf) {
9931029 dev_err(uap->port.dev, "no memory for DMA TX buffer\n");
9941030 uap->port.fifosize = uap->fifosize;
@@ -1689,6 +1725,8 @@ static void pl011_shutdown(struct uart_port *port) · 694 unmodified lines
16891725 plat->exit();
16901726 }
16911727
1728+ if (uap->port.ops->flush_buffer)
1729+ uap->port.ops->flush_buffer(port);
16921730 }
16931731
16941732 static void
drivers/tty/serial/ar933x_uart.c+20−10
@@ -119,7 +119,8 @@ static inline void ar933x_uart_putc(struct ar933x_uart_port *up, int ch) · 118 unmodified lines
119119
120120 static unsigned int ar933x_uart_tx_empty(struct uart_port *port)
121121 {
122− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
122+ struct ar933x_uart_port *up =
123+ container_of(port, struct ar933x_uart_port, port);
123124 unsigned long flags;
124125 unsigned int rdata;
125126
@@ -141,21 +142,24 @@ static void ar933x_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) · 15 unmodified lines
141142
142143 static void ar933x_uart_start_tx(struct uart_port *port)
143144 {
144− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
145+ struct ar933x_uart_port *up =
146+ container_of(port, struct ar933x_uart_port, port);
145147
146148 ar933x_uart_start_tx_interrupt(up);
147149 }
148150
149151 static void ar933x_uart_stop_tx(struct uart_port *port)
150152 {
151− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
153+ struct ar933x_uart_port *up =
154+ container_of(port, struct ar933x_uart_port, port);
152155
153156 ar933x_uart_stop_tx_interrupt(up);
154157 }
155158
156159 static void ar933x_uart_stop_rx(struct uart_port *port)
157160 {
158− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
161+ struct ar933x_uart_port *up =
162+ container_of(port, struct ar933x_uart_port, port);
159163
160164 up->ier &= ~AR933X_UART_INT_RX_VALID;
161165 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
@@ -163,7 +167,8 @@ static void ar933x_uart_stop_rx(struct uart_port *port) · 1 unmodified line
163167
164168 static void ar933x_uart_break_ctl(struct uart_port *port, int break_state)
165169 {
166− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
170+ struct ar933x_uart_port *up =
171+ container_of(port, struct ar933x_uart_port, port);
167172 unsigned long flags;
168173
169174 spin_lock_irqsave(&up->port.lock, flags);
@@ -231,7 +236,8 @@ static void ar933x_uart_set_termios(struct uart_port *port, · 61 unmodified lines
231236 struct ktermios *new,
232237 struct ktermios *old)
233238 {
234− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
239+ struct ar933x_uart_port *up =
240+ container_of(port, struct ar933x_uart_port, port);
235241 unsigned int cs;
236242 unsigned long flags;
237243 unsigned int baud, scale, step;
@@ -404,7 +410,8 @@ static irqreturn_t ar933x_uart_interrupt(int irq, void *dev_id) · 166 unmodified lines
404410
405411 static int ar933x_uart_startup(struct uart_port *port)
406412 {
407− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
413+ struct ar933x_uart_port *up =
414+ container_of(port, struct ar933x_uart_port, port);
408415 unsigned long flags;
409416 int ret;
410417
@@ -430,7 +437,8 @@ static int ar933x_uart_startup(struct uart_port *port) · 19 unmodified lines
430437
431438 static void ar933x_uart_shutdown(struct uart_port *port)
432439 {
433− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
440+ struct ar933x_uart_port *up =
441+ container_of(port, struct ar933x_uart_port, port);
434442
435443 /* Disable all interrupts */
436444 up->ier = 0;
@@ -468,7 +476,8 @@ static void ar933x_uart_config_port(struct uart_port *port, int flags) · 31 unmodified lines
468476 static int ar933x_uart_verify_port(struct uart_port *port,
469477 struct serial_struct *ser)
470478 {
471− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
479+ struct ar933x_uart_port *up =
480+ container_of(port, struct ar933x_uart_port, port);
472481
473482 if (ser->type != PORT_UNKNOWN &&
474483 ser->type != PORT_AR933X)
@@ -521,7 +530,8 @@ static void ar933x_uart_wait_xmitr(struct ar933x_uart_port *up) · 46 unmodified lines
521530
522531 static void ar933x_uart_console_putchar(struct uart_port *port, int ch)
523532 {
524− struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
533+ struct ar933x_uart_port *up =
534+ container_of(port, struct ar933x_uart_port, port);
525535
526536 ar933x_uart_wait_xmitr(up);
527537 ar933x_uart_putc(up, ch);
drivers/tty/serial/atmel_serial.c+110−120
@@ -167,7 +167,6 @@ struct atmel_uart_port { · 166 unmodified lines
167167
168168 struct circ_buf rx_ring;
169169
170− struct serial_rs485 rs485; /* rs485 settings */
171170 struct mctrl_gpios *gpios;
172171 int gpio_irq[UART_GPIO_MAX];
173172 unsigned int tx_done_mask;
@@ -290,13 +289,11 @@ static unsigned int atmel_get_lines_status(struct uart_port *port) · 116 unmodified lines
290289 }
291290
292291 /* Enable or disable the rs485 support */
293−void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
292+static int atmel_config_rs485(struct uart_port *port,
293+ struct serial_rs485 *rs485conf)
294294 {
295295 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
296296 unsigned int mode;
297− unsigned long flags;
298−
299− spin_lock_irqsave(&port->lock, flags);
300297
301298 /* Disable interrupts */
302299 UART_PUT_IDR(port, atmel_port->tx_done_mask);
@@ -306,7 +303,7 @@ void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) · 3 unmodified lines
306303 /* Resetting serial mode to RS232 (0x0) */
307304 mode &= ~ATMEL_US_USMODE;
308305
309− atmel_port->rs485 = *rs485conf;
306+ port->rs485 = *rs485conf;
310307
311308 if (rs485conf->flags & SER_RS485_ENABLED) {
312309 dev_dbg(port->dev, "Setting UART to RS485\n");
@@ -327,8 +324,7 @@ void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) · 14 unmodified lines
327324 /* Enable interrupts */
328325 UART_PUT_IER(port, atmel_port->tx_done_mask);
329326
330− spin_unlock_irqrestore(&port->lock, flags);
331−
327+ return 0;
332328 }
333329
334330 /*
@@ -372,11 +368,10 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl) · 37 unmodified lines
372368 /* Resetting serial mode to RS232 (0x0) */
373369 mode &= ~ATMEL_US_USMODE;
374370
375− if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
371+ if (port->rs485.flags & SER_RS485_ENABLED) {
376372 dev_dbg(port->dev, "Setting UART to RS485\n");
377− if ((atmel_port->rs485.delay_rts_after_send) > 0)
378− UART_PUT_TTGR(port,
379− atmel_port->rs485.delay_rts_after_send);
373+ if ((port->rs485.delay_rts_after_send) > 0)
374+ UART_PUT_TTGR(port, port->rs485.delay_rts_after_send);
380375 mode |= ATMEL_US_USMODE_RS485;
381376 } else {
382377 dev_dbg(port->dev, "Setting UART to RS232\n");
@@ -423,8 +418,8 @@ static void atmel_stop_tx(struct uart_port *port) · 40 unmodified lines
423418 /* Disable interrupts */
424419 UART_PUT_IDR(port, atmel_port->tx_done_mask);
425420
426− if ((atmel_port->rs485.flags & SER_RS485_ENABLED) &&
427− !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX))
421+ if ((port->rs485.flags & SER_RS485_ENABLED) &&
422+ !(port->rs485.flags & SER_RS485_RX_DURING_TX))
428423 atmel_start_rx(port);
429424 }
430425
@@ -441,8 +436,8 @@ static void atmel_start_tx(struct uart_port *port) · 10 unmodified lines
441436 really need this.*/
442437 return;
443438
444− if ((atmel_port->rs485.flags & SER_RS485_ENABLED) &&
445− !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX))
439+ if ((port->rs485.flags & SER_RS485_ENABLED) &&
440+ !(port->rs485.flags & SER_RS485_RX_DURING_TX))
446441 atmel_stop_rx(port);
447442
448443 /* re-enable PDC transmit */
@@ -807,7 +802,7 @@ static void atmel_tx_dma(struct uart_port *port) · 358 unmodified lines
807802 atmel_port->cookie_tx = dmaengine_submit(desc);
808803
809804 } else {
810− if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
805+ if (port->rs485.flags & SER_RS485_ENABLED) {
811806 /* DMA done, stop TX, start RX for RS485 */
812807 atmel_start_rx(port);
813808 }
@@ -862,9 +857,8 @@ static int atmel_prepare_tx_dma(struct uart_port *port) · 48 unmodified lines
862857 config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
863858 config.dst_addr = port->mapbase + ATMEL_US_THR;
864859
865− ret = dmaengine_device_control(atmel_port->chan_tx,
866− DMA_SLAVE_CONFIG,
867− (unsigned long)&config);
860+ ret = dmaengine_slave_config(atmel_port->chan_tx,
861+ &config);
868862 if (ret) {
869863 dev_err(port->dev, "DMA tx slave configuration failed\n");
870864 goto chan_err;
@@ -880,32 +874,6 @@ chan_err: · 9 unmodified lines
880874 return -EINVAL;
881875 }
882876
883−static void atmel_flip_buffer_rx_dma(struct uart_port *port,
884− char *buf, size_t count)
885−{
886− struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
887− struct tty_port *tport = &port->state->port;
888−
889− dma_sync_sg_for_cpu(port->dev,
890− &atmel_port->sg_rx,
891− 1,
892− DMA_DEV_TO_MEM);
893−
894− tty_insert_flip_string(tport, buf, count);
895−
896− dma_sync_sg_for_device(port->dev,
897− &atmel_port->sg_rx,
898− 1,
899− DMA_DEV_TO_MEM);
900− /*
901− * Drop the lock here since it might end up calling
902− * uart_start(), which takes the lock.
903− */
904− spin_unlock(&port->lock);
905− tty_flip_buffer_push(tport);
906− spin_lock(&port->lock);
907−}
908−
909877 static void atmel_complete_rx_dma(void *arg)
910878 {
911879 struct uart_port *port = arg;
@@ -934,11 +902,12 @@ static void atmel_release_rx_dma(struct uart_port *port) · 22 unmodified lines
934902 static void atmel_rx_from_dma(struct uart_port *port)
935903 {
936904 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
905+ struct tty_port *tport = &port->state->port;
937906 struct circ_buf *ring = &atmel_port->rx_ring;
938907 struct dma_chan *chan = atmel_port->chan_rx;
939908 struct dma_tx_state state;
940909 enum dma_status dmastat;
941− size_t pending, count;
910+ size_t count;
942911
943912
944913 /* Reset the UART timeout early so that we don't miss one */
@@ -953,27 +922,68 @@ static void atmel_rx_from_dma(struct uart_port *port) · 8 unmodified lines
953922 tasklet_schedule(&atmel_port->tasklet);
954923 return;
955924 }
956− /* current transfer size should no larger than dma buffer */
957− pending = sg_dma_len(&atmel_port->sg_rx) - state.residue;
958− BUG_ON(pending > sg_dma_len(&atmel_port->sg_rx));
925+
926+ /* CPU claims ownership of RX DMA buffer */
927+ dma_sync_sg_for_cpu(port->dev,
928+ &atmel_port->sg_rx,
929+ 1,
930+ DMA_DEV_TO_MEM);
959931
960932 /*
961− * This will take the chars we have so far,
962− * ring->head will record the transfer size, only new bytes come
963− * will insert into the framework.
933+ * ring->head points to the end of data already written by the DMA.
934+ * ring->tail points to the beginning of data to be read by the
935+ * framework.
936+ * The current transfer size should not be larger than the dma buffer
937+ * length.
964938 */
965− if (pending > ring->head) {
966− count = pending - ring->head;
939+ ring->head = sg_dma_len(&atmel_port->sg_rx) - state.residue;
940+ BUG_ON(ring->head > sg_dma_len(&atmel_port->sg_rx));
941+ /*
942+ * At this point ring->head may point to the first byte right after the
943+ * last byte of the dma buffer:
944+ * 0 <= ring->head <= sg_dma_len(&atmel_port->sg_rx)
945+ *
946+ * However ring->tail must always points inside the dma buffer:
947+ * 0 <= ring->tail <= sg_dma_len(&atmel_port->sg_rx) - 1
948+ *
949+ * Since we use a ring buffer, we have to handle the case
950+ * where head is lower than tail. In such a case, we first read from
951+ * tail to the end of the buffer then reset tail.
952+ */
953+ if (ring->head < ring->tail) {
954+ count = sg_dma_len(&atmel_port->sg_rx) - ring->tail;
955+
956+ tty_insert_flip_string(tport, ring->buf + ring->tail, count);
957+ ring->tail = 0;
958+ port->icount.rx += count;
959+ }
967960
968− atmel_flip_buffer_rx_dma(port, ring->buf + ring->head, count);
961+ /* Finally we read data from tail to head */
962+ if (ring->tail < ring->head) {
963+ count = ring->head - ring->tail;
969964
970− ring->head += count;
971− if (ring->head == sg_dma_len(&atmel_port->sg_rx))
965+ tty_insert_flip_string(tport, ring->buf + ring->tail, count);
966+ /* Wrap ring->head if needed */
967+ if (ring->head >= sg_dma_len(&atmel_port->sg_rx))
972968 ring->head = 0;
973−
969+ ring->tail = ring->head;
974970 port->icount.rx += count;
975971 }
976972
973+ /* USART retreives ownership of RX DMA buffer */
974+ dma_sync_sg_for_device(port->dev,
975+ &atmel_port->sg_rx,
976+ 1,
977+ DMA_DEV_TO_MEM);
978+
979+ /*
980+ * Drop the lock here since it might end up calling
981+ * uart_start(), which takes the lock.
982+ */
983+ spin_unlock(&port->lock);
984+ tty_flip_buffer_push(tport);
985+ spin_lock(&port->lock);
986+
977987 UART_PUT_IER(port, ATMEL_US_TIMEOUT);
978988 }
979989
@@ -1026,9 +1036,8 @@ static int atmel_prepare_rx_dma(struct uart_port *port) · 46 unmodified lines
10261036 config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
10271037 config.src_addr = port->mapbase + ATMEL_US_RHR;
10281038
1029− ret = dmaengine_device_control(atmel_port->chan_rx,
1030− DMA_SLAVE_CONFIG,
1031− (unsigned long)&config);
1039+ ret = dmaengine_slave_config(atmel_port->chan_rx,
1040+ &config);
10321041 if (ret) {
10331042 dev_err(port->dev, "DMA rx slave configuration failed\n");
10341043 goto chan_err;
@@ -1240,8 +1249,8 @@ static void atmel_tx_pdc(struct uart_port *port) · 205 unmodified lines
12401249 /* Enable interrupts */
12411250 UART_PUT_IER(port, atmel_port->tx_done_mask);
12421251 } else {
1243− if ((atmel_port->rs485.flags & SER_RS485_ENABLED) &&
1244− !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX)) {
1252+ if ((port->rs485.flags & SER_RS485_ENABLED) &&
1253+ !(port->rs485.flags & SER_RS485_RX_DURING_TX)) {
12451254 /* DMA done, stop TX, start RX for RS485 */
12461255 atmel_start_rx(port);
12471256 }
@@ -1552,7 +1561,7 @@ static int atmel_init_property(struct atmel_uart_port *atmel_port, · 304 unmodified lines
15521561 return 0;
15531562 }
15541563
1555−static void atmel_init_rs485(struct atmel_uart_port *atmel_port,
1564+static void atmel_init_rs485(struct uart_port *port,
15561565 struct platform_device *pdev)
15571566 {
15581567 struct device_node *np = pdev->dev.of_node;
@@ -1563,7 +1572,7 @@ static void atmel_init_rs485(struct atmel_uart_port *atmel_port, · 4 unmodified lines
15631572 /* rs485 properties */
15641573 if (of_property_read_u32_array(np, "rs485-rts-delay",
15651574 rs485_delay, 2) == 0) {
1566− struct serial_rs485 *rs485conf = &atmel_port->rs485;
1575+ struct serial_rs485 *rs485conf = &port->rs485;
15671576
15681577 rs485conf->delay_rts_before_send = rs485_delay[0];
15691578 rs485conf->delay_rts_after_send = rs485_delay[1];
@@ -1577,7 +1586,7 @@ static void atmel_init_rs485(struct atmel_uart_port *atmel_port, · 7 unmodified lines
15771586 rs485conf->flags |= SER_RS485_ENABLED;
15781587 }
15791588 } else {
1580− atmel_port->rs485 = pdata->rs485;
1589+ port->rs485 = pdata->rs485;
15811590 }
15821591
15831592 }
@@ -1801,6 +1810,20 @@ free_irq: · 217 unmodified lines
18011810 return retval;
18021811 }
18031812
1813+/*
1814+ * Flush any TX data submitted for DMA. Called when the TX circular
1815+ * buffer is reset.
1816+ */
1817+static void atmel_flush_buffer(struct uart_port *port)
1818+{
1819+ struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
1820+
1821+ if (atmel_use_pdc_tx(port)) {
1822+ UART_PUT_TCR(port, 0);
1823+ atmel_port->pdc_tx.ofs = 0;
1824+ }
1825+}
1826+
18041827 /*
18051828 * Disable the port
18061829 */
@@ -1852,20 +1875,8 @@ static void atmel_shutdown(struct uart_port *port) · 45 unmodified lines
18521875 atmel_free_gpio_irq(port);
18531876
18541877 atmel_port->ms_irq_enabled = false;
1855−}
18561878
1857−/*
1858− * Flush any TX data submitted for DMA. Called when the TX circular
1859− * buffer is reset.
1860− */
1861−static void atmel_flush_buffer(struct uart_port *port)
1862−{
1863− struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
1864−
1865− if (atmel_use_pdc_tx(port)) {
1866− UART_PUT_TCR(port, 0);
1867− atmel_port->pdc_tx.ofs = 0;
1868− }
1879+ atmel_flush_buffer(port);
18691880 }
18701881
18711882 /*
@@ -1911,7 +1922,6 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, · 39 unmodified lines
19111922 {
19121923 unsigned long flags;
19131924 unsigned int mode, imr, quot, baud;
1914− struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
19151925
19161926 /* Get current mode register */
19171927 mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL
@@ -2013,10 +2023,9 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, · 95 unmodified lines
20132023 /* Resetting serial mode to RS232 (0x0) */
20142024 mode &= ~ATMEL_US_USMODE;
20152025
2016− if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
2017− if ((atmel_port->rs485.delay_rts_after_send) > 0)
2018− UART_PUT_TTGR(port,
2019− atmel_port->rs485.delay_rts_after_send);
2026+ if (port->rs485.flags & SER_RS485_ENABLED) {
2027+ if ((port->rs485.delay_rts_after_send) > 0)
2028+ UART_PUT_TTGR(port, port->rs485.delay_rts_after_send);
20202029 mode |= ATMEL_US_USMODE_RS485;
20212030 }
20222031
@@ -2040,13 +2049,20 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, · 17 unmodified lines
20402049 spin_unlock_irqrestore(&port->lock, flags);
20412050 }
20422051
2043−static void atmel_set_ldisc(struct uart_port *port, int new)
2052+static void atmel_set_ldisc(struct uart_port *port, struct ktermios *termios)
20442053 {
2045− if (new == N_PPS) {
2054+ if (termios->c_line == N_PPS) {
20462055 port->flags |= UPF_HARDPPS_CD;
2056+ spin_lock_irq(&port->lock);
20472057 atmel_enable_ms(port);
2058+ spin_unlock_irq(&port->lock);
20482059 } else {
20492060 port->flags &= ~UPF_HARDPPS_CD;
2061+ if (!UART_ENABLE_MS(port, termios->c_cflag)) {
2062+ spin_lock_irq(&port->lock);
2063+ atmel_disable_ms(port);
2064+ spin_unlock_irq(&port->lock);
2065+ }
20502066 }
20512067 }
20522068
@@ -2148,35 +2164,6 @@ static void atmel_poll_put_char(struct uart_port *port, unsigned char ch) · 95 unmodified lines
21482164 }
21492165 #endif
21502166
2151−static int
2152−atmel_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg)
2153−{
2154− struct serial_rs485 rs485conf;
2155−
2156− switch (cmd) {
2157− case TIOCSRS485:
2158− if (copy_from_user(&rs485conf, (struct serial_rs485 *) arg,
2159− sizeof(rs485conf)))
2160− return -EFAULT;
2161−
2162− atmel_config_rs485(port, &rs485conf);
2163− break;
2164−
2165− case TIOCGRS485:
2166− if (copy_to_user((struct serial_rs485 *) arg,
2167− &(to_atmel_uart_port(port)->rs485),
2168− sizeof(rs485conf)))
2169− return -EFAULT;
2170− break;
2171−
2172− default:
2173− return -ENOIOCTLCMD;
2174− }
2175− return 0;
2176−}
2177−
2178−
2179−
21802167 static struct uart_ops atmel_pops = {
21812168 .tx_empty = atmel_tx_empty,
21822169 .set_mctrl = atmel_set_mctrl,
@@ -2197,7 +2184,6 @@ static struct uart_ops atmel_pops = { · 14 unmodified lines
21972184 .config_port = atmel_config_port,
21982185 .verify_port = atmel_verify_port,
21992186 .pm = atmel_serial_pm,
2200− .ioctl = atmel_ioctl,
22012187 #ifdef CONFIG_CONSOLE_POLL
22022188 .poll_get_char = atmel_poll_get_char,
22032189 .poll_put_char = atmel_poll_put_char,
@@ -2217,7 +2203,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port, · 13 unmodified lines
22172203 if (!atmel_init_property(atmel_port, pdev))
22182204 atmel_set_ops(port);
22192205
2220− atmel_init_rs485(atmel_port, pdev);
2206+ atmel_init_rs485(port, pdev);
22212207
22222208 port->iotype = UPIO_MEM;
22232209 port->flags = UPF_BOOT_AUTOCONF;
@@ -2226,6 +2212,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port, · 2 unmodified lines
22262212 port->dev = &pdev->dev;
22272213 port->mapbase = pdev->resource[0].start;
22282214 port->irq = pdev->resource[1].start;
2215+ port->rs485_config = atmel_config_rs485;
22292216
22302217 tasklet_init(&atmel_port->tasklet, atmel_tasklet_func,
22312218 (unsigned long)port);
@@ -2260,7 +2247,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port, · 28 unmodified lines
22602247 }
22612248
22622249 /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
2263− if (atmel_port->rs485.flags & SER_RS485_ENABLED)
2250+ if (port->rs485.flags & SER_RS485_ENABLED)
22642251 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
22652252 else if (atmel_use_pdc_tx(port)) {
22662253 port->fifosize = PDC_BUFFER_SIZE;
@@ -2541,6 +2528,7 @@ static int atmel_serial_probe(struct platform_device *pdev) · 274 unmodified lines
25412528 struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev);
25422529 void *data;
25432530 int ret = -ENODEV;
2531+ bool rs485_enabled;
25442532
25452533 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
25462534
@@ -2588,6 +2576,8 @@ static int atmel_serial_probe(struct platform_device *pdev) · 41 unmodified lines
25882576 port->rx_ring.buf = data;
25892577 }
25902578
2579+ rs485_enabled = port->uart.rs485.flags & SER_RS485_ENABLED;
2580+
25912581 ret = uart_add_one_port(&atmel_uart, &port->uart);
25922582 if (ret)
25932583 goto err_add_port;
@@ -2606,7 +2596,7 @@ static int atmel_serial_probe(struct platform_device *pdev) · 12 unmodified lines
26062596 device_init_wakeup(&pdev->dev, 1);
26072597 platform_set_drvdata(pdev, port);
26082598
2609− if (port->rs485.flags & SER_RS485_ENABLED) {
2599+ if (rs485_enabled) {
26102600 UART_PUT_MR(&port->uart, ATMEL_US_USMODE_NORMAL);
26112601 UART_PUT_CR(&port->uart, ATMEL_US_RTSEN);
26122602 }
drivers/tty/serial/bcm63xx_uart.c+33−22
@@ -588,20 +588,7 @@ static void bcm_uart_set_termios(struct uart_port *port, · 587 unmodified lines
588588 */
589589 static int bcm_uart_request_port(struct uart_port *port)
590590 {
591− unsigned int size;
592−
593− size = UART_REG_SIZE;
594− if (!request_mem_region(port->mapbase, size, "bcm63xx")) {
595− dev_err(port->dev, "Memory region busy\n");
596− return -EBUSY;
597− }
598−
599− port->membase = ioremap(port->mapbase, size);
600− if (!port->membase) {
601− dev_err(port->dev, "Unable to map registers\n");
602− release_mem_region(port->mapbase, size);
603− return -EBUSY;
604− }
591+ /* UARTs always present */
605592 return 0;
606593 }
607594
@@ -610,8 +597,7 @@ static int bcm_uart_request_port(struct uart_port *port) · 2 unmodified lines
610597 */
611598 static void bcm_uart_release_port(struct uart_port *port)
612599 {
613− release_mem_region(port->mapbase, UART_REG_SIZE);
614− iounmap(port->membase);
600+ /* Nothing to release ... */
615601 }
616602
617603 /*
@@ -782,6 +768,26 @@ static int __init bcm63xx_console_init(void) · 164 unmodified lines
782768
783769 console_initcall(bcm63xx_console_init);
784770
771+static void bcm_early_write(struct console *con, const char *s, unsigned n)
772+{
773+ struct earlycon_device *dev = con->data;
774+
775+ uart_console_write(&dev->port, s, n, bcm_console_putchar);
776+ wait_for_xmitr(&dev->port);
777+}
778+
779+static int __init bcm_early_console_setup(struct earlycon_device *device,
780+ const char *opt)
781+{
782+ if (!device->port.membase)
783+ return -ENODEV;
784+
785+ device->con->write = bcm_early_write;
786+ return 0;
787+}
788+
789+OF_EARLYCON_DECLARE(bcm63xx_uart, "brcm,bcm6345-uart", bcm_early_console_setup);
790+
785791 #define BCM63XX_CONSOLE (&bcm63xx_console)
786792 #else
787793 #define BCM63XX_CONSOLE NULL
@@ -813,25 +819,30 @@ static int bcm_uart_probe(struct platform_device *pdev) · 25 unmodified lines
813819 if (pdev->id < 0 || pdev->id >= BCM63XX_NR_UARTS)
814820 return -EINVAL;
815821
816− if (ports[pdev->id].membase)
822+ port = &ports[pdev->id];
823+ if (port->membase)
817824 return -EBUSY;
825+ memset(port, 0, sizeof(*port));
818826
819827 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
820828 if (!res_mem)
821829 return -ENODEV;
822830
831+ port->mapbase = res_mem->start;
832+ port->membase = devm_ioremap_resource(&pdev->dev, res_mem);
833+ if (IS_ERR(port->membase))
834+ return PTR_ERR(port->membase);
835+
823836 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
824837 if (!res_irq)
825838 return -ENODEV;
826839
827− clk = clk_get(&pdev->dev, "periph");
840+ clk = pdev->dev.of_node ? of_clk_get(pdev->dev.of_node, 0) :
841+ clk_get(&pdev->dev, "periph");
828842 if (IS_ERR(clk))
829843 return -ENODEV;
830844
831− port = &ports[pdev->id];
832− memset(port, 0, sizeof(*port));
833845 port->iotype = UPIO_MEM;
834− port->mapbase = res_mem->start;
835846 port->irq = res_irq->start;
836847 port->ops = &bcm_uart_ops;
837848 port->flags = UPF_BOOT_AUTOCONF;
@@ -905,5 +916,5 @@ module_init(bcm_uart_init); · 67 unmodified lines
905916 module_exit(bcm_uart_exit);
906917
907918 MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
908−MODULE_DESCRIPTION("Broadcom 63<xx integrated uart driver");
919+MODULE_DESCRIPTION("Broadcom 63xx integrated uart driver");
909920 MODULE_LICENSE("GPL");
drivers/tty/serial/bfin_sport_uart.c+3−2
@@ -517,14 +517,15 @@ static void sport_set_termios(struct uart_port *port, · 516 unmodified lines
517517 up->csize = 5;
518518 break;
519519 default:
520− pr_warning("requested word length not supported\n");
520+ pr_warn("requested word length not supported\n");
521+ break;
521522 }
522523
523524 if (termios->c_cflag & CSTOPB) {
524525 up->stopb = 1;
525526 }
526527 if (termios->c_cflag & PARENB) {
527− pr_warning("PAREN bits is not supported yet\n");
528+ pr_warn("PAREN bit is not supported yet\n");
528529 /* up->parib = 1; */
529530 }
530531
drivers/tty/serial/bfin_uart.c+3−2
@@ -944,12 +944,13 @@ bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser) · 943 unmodified lines
944944 * Enable the IrDA function if tty->ldisc.num is N_IRDA.
945945 * In other cases, disable IrDA function.
946946 */
947−static void bfin_serial_set_ldisc(struct uart_port *port, int ld)
947+static void bfin_serial_set_ldisc(struct uart_port *port,
948+ struct ktermios *termios)
948949 {
949950 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
950951 unsigned int val;
951952
952− switch (ld) {
953+ switch (termios->c_line) {
953954 case N_IRDA:
954955 val = UART_GET_GCTL(uart);
955956 val |= (UMOD_IRDA | RPOLC);
drivers/tty/serial/clps711x.c+3−2
@@ -225,13 +225,14 @@ static void uart_clps711x_break_ctl(struct uart_port *port, int break_state) · 224 unmodified lines
225225 writel(ubrlcr, port->membase + UBRLCR_OFFSET);
226226 }
227227
228−static void uart_clps711x_set_ldisc(struct uart_port *port, int ld)
228+static void uart_clps711x_set_ldisc(struct uart_port *port,
229+ struct ktermios *termios)
229230 {
230231 if (!port->line) {
231232 struct clps711x_port *s = dev_get_drvdata(port->dev);
232233
233234 regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON1_SIREN,
234− (ld == N_IRDA) ? SYSCON1_SIREN : 0);
235+ (termios->c_line == N_IRDA) ? SYSCON1_SIREN : 0);
235236 }
236237 }
237238
drivers/tty/serial/cpm_uart/cpm_uart_core.c+32−16
@@ -80,7 +80,8 @@ static void cpm_uart_initbd(struct uart_cpm_port *pinfo); · 79 unmodified lines
8080 */
8181 static unsigned int cpm_uart_tx_empty(struct uart_port *port)
8282 {
83− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
83+ struct uart_cpm_port *pinfo =
84+ container_of(port, struct uart_cpm_port, port);
8485 cbd_t __iomem *bdp = pinfo->tx_bd_base;
8586 int ret = 0;
8687
@@ -102,7 +103,8 @@ static unsigned int cpm_uart_tx_empty(struct uart_port *port) · 15 unmodified lines
102103
103104 static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
104105 {
105− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
106+ struct uart_cpm_port *pinfo =
107+ container_of(port, struct uart_cpm_port, port);
106108
107109 if (pinfo->gpios[GPIO_RTS] >= 0)
108110 gpio_set_value(pinfo->gpios[GPIO_RTS], !(mctrl & TIOCM_RTS));
@@ -113,7 +115,8 @@ static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) · 4 unmodified lines
113115
114116 static unsigned int cpm_uart_get_mctrl(struct uart_port *port)
115117 {
116− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
118+ struct uart_cpm_port *pinfo =
119+ container_of(port, struct uart_cpm_port, port);
117120 unsigned int mctrl = TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
118121
119122 if (pinfo->gpios[GPIO_CTS] >= 0) {
@@ -144,7 +147,8 @@ static unsigned int cpm_uart_get_mctrl(struct uart_port *port) · 24 unmodified lines
144147 */
145148 static void cpm_uart_stop_tx(struct uart_port *port)
146149 {
147− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
150+ struct uart_cpm_port *pinfo =
151+ container_of(port, struct uart_cpm_port, port);
148152 smc_t __iomem *smcp = pinfo->smcp;
149153 scc_t __iomem *sccp = pinfo->sccp;
150154
@@ -161,7 +165,8 @@ static void cpm_uart_stop_tx(struct uart_port *port) · 10 unmodified lines
161165 */
162166 static void cpm_uart_start_tx(struct uart_port *port)
163167 {
164− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
168+ struct uart_cpm_port *pinfo =
169+ container_of(port, struct uart_cpm_port, port);
165170 smc_t __iomem *smcp = pinfo->smcp;
166171 scc_t __iomem *sccp = pinfo->sccp;
167172
@@ -189,7 +194,8 @@ static void cpm_uart_start_tx(struct uart_port *port) · 21 unmodified lines
189194 */
190195 static void cpm_uart_stop_rx(struct uart_port *port)
191196 {
192− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
197+ struct uart_cpm_port *pinfo =
198+ container_of(port, struct uart_cpm_port, port);
193199 smc_t __iomem *smcp = pinfo->smcp;
194200 scc_t __iomem *sccp = pinfo->sccp;
195201
@@ -206,7 +212,8 @@ static void cpm_uart_stop_rx(struct uart_port *port) · 10 unmodified lines
206212 */
207213 static void cpm_uart_break_ctl(struct uart_port *port, int break_state)
208214 {
209− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
215+ struct uart_cpm_port *pinfo =
216+ container_of(port, struct uart_cpm_port, port);
210217
211218 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port->line,
212219 break_state);
@@ -240,7 +247,8 @@ static void cpm_uart_int_rx(struct uart_port *port) · 27 unmodified lines
240247 unsigned char ch;
241248 u8 *cp;
242249 struct tty_port *tport = &port->state->port;
243− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
250+ struct uart_cpm_port *pinfo =
251+ container_of(port, struct uart_cpm_port, port);
244252 cbd_t __iomem *bdp;
245253 u16 status;
246254 unsigned int flg;
@@ -397,7 +405,8 @@ static irqreturn_t cpm_uart_int(int irq, void *data) · 150 unmodified lines
397405 static int cpm_uart_startup(struct uart_port *port)
398406 {
399407 int retval;
400− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
408+ struct uart_cpm_port *pinfo =
409+ container_of(port, struct uart_cpm_port, port);
401410
402411 pr_debug("CPM uart[%d]:startup\n", port->line);
403412
@@ -442,7 +451,8 @@ inline void cpm_uart_wait_until_send(struct uart_cpm_port *pinfo) · 38 unmodified lines
442451 */
443452 static void cpm_uart_shutdown(struct uart_port *port)
444453 {
445− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
454+ struct uart_cpm_port *pinfo =
455+ container_of(port, struct uart_cpm_port, port);
446456
447457 pr_debug("CPM uart[%d]:shutdown\n", port->line);
448458
@@ -492,7 +502,8 @@ static void cpm_uart_set_termios(struct uart_port *port, · 43 unmodified lines
492502 unsigned long flags;
493503 u16 cval, scval, prev_mode;
494504 int bits, sbits;
495− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
505+ struct uart_cpm_port *pinfo =
506+ container_of(port, struct uart_cpm_port, port);
496507 smc_t __iomem *smcp = pinfo->smcp;
497508 scc_t __iomem *sccp = pinfo->sccp;
498509 int maxidl;
@@ -675,7 +686,8 @@ static int cpm_uart_tx_pump(struct uart_port *port) · 176 unmodified lines
675686 cbd_t __iomem *bdp;
676687 u8 *p;
677688 int count;
678− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
689+ struct uart_cpm_port *pinfo =
690+ container_of(port, struct uart_cpm_port, port);
679691 struct circ_buf *xmit = &port->state->xmit;
680692
681693 /* Handle xon/xoff */
@@ -906,7 +918,8 @@ static void cpm_uart_init_smc(struct uart_cpm_port *pinfo) · 224 unmodified lines
906918 */
907919 static int cpm_uart_request_port(struct uart_port *port)
908920 {
909− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
921+ struct uart_cpm_port *pinfo =
922+ container_of(port, struct uart_cpm_port, port);
910923 int ret;
911924
912925 pr_debug("CPM uart[%d]:request port\n", port->line);
@@ -938,7 +951,8 @@ static int cpm_uart_request_port(struct uart_port *port) · 25 unmodified lines
938951
939952 static void cpm_uart_release_port(struct uart_port *port)
940953 {
941− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
954+ struct uart_cpm_port *pinfo =
955+ container_of(port, struct uart_cpm_port, port);
942956
943957 if (!(pinfo->flags & FLAG_CONSOLE))
944958 cpm_uart_freebuf(pinfo);
@@ -1082,7 +1096,8 @@ static int poll_wait_key(char *obuf, struct uart_cpm_port *pinfo) · 137 unmodified lines
10821096
10831097 static int cpm_get_poll_char(struct uart_port *port)
10841098 {
1085− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
1099+ struct uart_cpm_port *pinfo =
1100+ container_of(port, struct uart_cpm_port, port);
10861101
10871102 if (!serial_polled) {
10881103 serial_polled = 1;
@@ -1099,7 +1114,8 @@ static int cpm_get_poll_char(struct uart_port *port) · 10 unmodified lines
10991114 static void cpm_put_poll_char(struct uart_port *port,
11001115 unsigned char c)
11011116 {
1102− struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
1117+ struct uart_cpm_port *pinfo =
1118+ container_of(port, struct uart_cpm_port, port);
11031119 static char ch[2];
11041120
11051121 ch[0] = (char)c;
drivers/tty/serial/crisv10.c+0−12
@@ -3675,12 +3675,6 @@ rs_close(struct tty_struct *tty, struct file * filp) · 3674 unmodified lines
36753675 return;
36763676 }
36773677 info->port.flags |= ASYNC_CLOSING;
3678− /*
3679− * Save the termios structure, since this port may have
3680− * separate termios for callout and dialin.
3681− */
3682− if (info->port.flags & ASYNC_NORMAL_ACTIVE)
3683− info->normal_termios = tty->termios;
36843678 /*
36853679 * Now we wait for the transmit buffer to clear; and we notify
36863680 * the line discipline to only process XON/XOFF characters.
@@ -4076,11 +4070,6 @@ rs_open(struct tty_struct *tty, struct file * filp) · 389 unmodified lines
40764070 return retval;
40774071 }
40784072
4079− if ((info->port.count == 1) && (info->port.flags & ASYNC_SPLIT_TERMIOS)) {
4080− tty->termios = info->normal_termios;
4081− change_speed(info);
4082− }
4083−
40844073 #ifdef SERIAL_DEBUG_OPEN
40854074 printk("rs_open ttyS%d successful...\n", info->line);
40864075 #endif
@@ -4327,7 +4316,6 @@ static int __init rs_init(void) · 240 unmodified lines
43274316 info->custom_divisor = 0;
43284317 info->x_char = 0;
43294318 info->event = 0;
4330− info->normal_termios = driver->init_termios;
43314319 info->xmit.buf = NULL;
43324320 info->xmit.tail = info->xmit.head = 0;
43334321 info->first_recv_buffer = info->last_recv_buffer = NULL;
drivers/tty/serial/crisv10.h+0−1
@@ -98,7 +98,6 @@ struct e100_serial { · 97 unmodified lines
9898
9999 struct work_struct work;
100100 struct async_icount icount; /* error-statistics etc.*/
101− struct ktermios normal_termios;
102101
103102 unsigned long char_time_usec; /* The time for 1 char, in usecs */
104103 unsigned long flush_time_usec; /* How often we should flush */
drivers/tty/serial/earlycon.c+1−1
@@ -98,7 +98,7 @@ static int __init parse_options(struct earlycon_device *device, · 97 unmodified lines
9898 strlcpy(device->options, options, length);
9999 }
100100
101− if (mmio || mmio32)
101+ if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM32)
102102 pr_info("Early serial console at MMIO%s 0x%llx (options '%s')\n",
103103 mmio32 ? "32" : "",
104104 (unsigned long long)port->mapbase,
drivers/tty/serial/fsl_lpuart.c+17−8
@@ -1786,15 +1786,13 @@ static int lpuart_probe(struct platform_device *pdev) · 1785 unmodified lines
17861786 }
17871787 sport->port.line = ret;
17881788 sport->lpuart32 = of_device_is_compatible(np, "fsl,ls1021a-lpuart");
1789− res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1790− if (!res)
1791− return -ENODEV;
17921789
1793− sport->port.mapbase = res->start;
1790+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
17941791 sport->port.membase = devm_ioremap_resource(&pdev->dev, res);
17951792 if (IS_ERR(sport->port.membase))
17961793 return PTR_ERR(sport->port.membase);
17971794
1795+ sport->port.mapbase = res->start;
17981796 sport->port.dev = &pdev->dev;
17991797 sport->port.type = PORT_LPUART;
18001798 sport->port.iotype = UPIO_MEM;
@@ -1862,6 +1860,20 @@ static int lpuart_suspend(struct device *dev) · 61 unmodified lines
18621860 static int lpuart_resume(struct device *dev)
18631861 {
18641862 struct lpuart_port *sport = dev_get_drvdata(dev);
1863+ unsigned long temp;
1864+
1865+ if (sport->lpuart32) {
1866+ lpuart32_setup_watermark(sport);
1867+ temp = lpuart32_read(sport->port.membase + UARTCTRL);
1868+ temp |= (UARTCTRL_RIE | UARTCTRL_TIE | UARTCTRL_RE |
1869+ UARTCTRL_TE | UARTCTRL_ILIE);
1870+ lpuart32_write(temp, sport->port.membase + UARTCTRL);
1871+ } else {
1872+ lpuart_setup_watermark(sport);
1873+ temp = readb(sport->port.membase + UARTCR2);
1874+ temp |= (UARTCR2_RIE | UARTCR2_TIE | UARTCR2_RE | UARTCR2_TE);
1875+ writeb(temp, sport->port.membase + UARTCR2);
1876+ }
18651877
18661878 uart_resume_port(&lpuart_reg, &sport->port);
18671879
@@ -1884,11 +1896,8 @@ static struct platform_driver lpuart_driver = { · 16 unmodified lines
18841896
18851897 static int __init lpuart_serial_init(void)
18861898 {
1887− int ret;
1888−
1889− pr_info("serial: Freescale lpuart driver\n");
1899+ int ret = uart_register_driver(&lpuart_reg);
18901900
1891− ret = uart_register_driver(&lpuart_reg);
18921901 if (ret)
18931902 return ret;
18941903
drivers/tty/serial/icom.c+3−1
@@ -1550,8 +1550,10 @@ static int icom_probe(struct pci_dev *dev, · 1549 unmodified lines
15501550
15511551 icom_adapter->base_addr = pci_ioremap_bar(dev, 0);
15521552
1553− if (!icom_adapter->base_addr)
1553+ if (!icom_adapter->base_addr) {
1554+ retval = -ENOMEM;
15541555 goto probe_exit1;
1556+ }
15551557
15561558 /* save off irq and request irq line */
15571559 if ( (retval = request_irq(dev->irq, icom_interrupt,
drivers/tty/serial/imx.c+75−78
@@ -302,7 +302,7 @@ static inline int is_imx6q_uart(struct imx_port *sport) · 301 unmodified lines
302302 /*
303303 * Save and restore functions for UCR1, UCR2 and UCR3 registers
304304 */
305−#if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_IMX_CONSOLE)
305+#if defined(CONFIG_SERIAL_IMX_CONSOLE)
306306 static void imx_port_ucrs_save(struct uart_port *port,
307307 struct imx_port_ucrs *ucr)
308308 {
@@ -991,7 +991,6 @@ static int imx_uart_dma_init(struct imx_port *sport) · 682 unmodified lines
991991
992992 sport->rx_buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
993993 if (!sport->rx_buf) {
994− dev_err(dev, "cannot alloc DMA buffer.\n");
995994 ret = -ENOMEM;
996995 goto err;
997996 }
@@ -1076,11 +1075,11 @@ static int imx_startup(struct uart_port *port) · 78 unmodified lines
10761075
10771076 retval = clk_prepare_enable(sport->clk_per);
10781077 if (retval)
1079− goto error_out1;
1078+ return retval;
10801079 retval = clk_prepare_enable(sport->clk_ipg);
10811080 if (retval) {
10821081 clk_disable_unprepare(sport->clk_per);
1083− goto error_out1;
1082+ return retval;
10841083 }
10851084
10861085 imx_setup_ufcr(sport, 0);
@@ -1109,37 +1108,6 @@ static int imx_startup(struct uart_port *port) · 22 unmodified lines
11091108 while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) && (--i > 0))
11101109 udelay(1);
11111110
1112− /*
1113− * Allocate the IRQ(s) i.MX1 has three interrupts whereas later
1114− * chips only have one interrupt.
1115− */
1116− if (sport->txirq > 0) {
1117− retval = request_irq(sport->rxirq, imx_rxint, 0,
1118− dev_name(port->dev), sport);
1119− if (retval)
1120− goto error_out1;
1121−
1122− retval = request_irq(sport->txirq, imx_txint, 0,
1123− dev_name(port->dev), sport);
1124− if (retval)
1125− goto error_out2;
1126−
1127− /* do not use RTS IRQ on IrDA */
1128− if (!USE_IRDA(sport)) {
1129− retval = request_irq(sport->rtsirq, imx_rtsint, 0,
1130− dev_name(port->dev), sport);
1131− if (retval)
1132− goto error_out3;
1133− }
1134− } else {
1135− retval = request_irq(sport->port.irq, imx_int, 0,
1136− dev_name(port->dev), sport);
1137− if (retval) {
1138− free_irq(sport->port.irq, sport);
1139− goto error_out1;
1140− }
1141− }
1142−
11431111 spin_lock_irqsave(&sport->port.lock, flags);
11441112 /*
11451113 * Finally, clear and enable interrupts
@@ -1201,15 +1169,6 @@ static int imx_startup(struct uart_port *port) · 55 unmodified lines
12011169 }
12021170
12031171 return 0;
1204−
1205−error_out3:
1206− if (sport->txirq)
1207− free_irq(sport->txirq, sport);
1208−error_out2:
1209− if (sport->rxirq)
1210− free_irq(sport->rxirq, sport);
1211−error_out1:
1212− return retval;
12131172 }
12141173
12151174 static void imx_shutdown(struct uart_port *port)
@@ -1254,17 +1213,6 @@ static void imx_shutdown(struct uart_port *port) · 38 unmodified lines
12541213 */
12551214 del_timer_sync(&sport->timer);
12561215
1257− /*
1258− * Free the interrupts
1259− */
1260− if (sport->txirq > 0) {
1261− if (!USE_IRDA(sport))
1262− free_irq(sport->rtsirq, sport);
1263− free_irq(sport->txirq, sport);
1264− free_irq(sport->rxirq, sport);
1265− } else
1266− free_irq(sport->port.irq, sport);
1267−
12681216 /*
12691217 * Disable all interrupts, port and break condition.
12701218 */
@@ -1507,44 +1455,65 @@ imx_verify_port(struct uart_port *port, struct serial_struct *ser) · 236 unmodified lines
15071455 }
15081456
15091457 #if defined(CONFIG_CONSOLE_POLL)
1458+
1459+static int imx_poll_init(struct uart_port *port)
1460+{
1461+ struct imx_port *sport = (struct imx_port *)port;
1462+ unsigned long flags;
1463+ unsigned long temp;
1464+ int retval;
1465+
1466+ retval = clk_prepare_enable(sport->clk_ipg);
1467+ if (retval)
1468+ return retval;
1469+ retval = clk_prepare_enable(sport->clk_per);
1470+ if (retval)
1471+ clk_disable_unprepare(sport->clk_ipg);
1472+
1473+ imx_setup_ufcr(sport, 0);
1474+
1475+ spin_lock_irqsave(&sport->port.lock, flags);
1476+
1477+ temp = readl(sport->port.membase + UCR1);
1478+ if (is_imx1_uart(sport))
1479+ temp |= IMX1_UCR1_UARTCLKEN;
1480+ temp |= UCR1_UARTEN | UCR1_RRDYEN;
1481+ temp &= ~(UCR1_TXMPTYEN | UCR1_RTSDEN);
1482+ writel(temp, sport->port.membase + UCR1);
1483+
1484+ temp = readl(sport->port.membase + UCR2);
1485+ temp |= UCR2_RXEN;
1486+ writel(temp, sport->port.membase + UCR2);
1487+
1488+ spin_unlock_irqrestore(&sport->port.lock, flags);
1489+
1490+ return 0;
1491+}
1492+
15101493 static int imx_poll_get_char(struct uart_port *port)
15111494 {
1512− if (!(readl(port->membase + USR2) & USR2_RDR))
1495+ if (!(readl_relaxed(port->membase + USR2) & USR2_RDR))
15131496 return NO_POLL_CHAR;
15141497
1515− return readl(port->membase + URXD0) & URXD_RX_DATA;
1498+ return readl_relaxed(port->membase + URXD0) & URXD_RX_DATA;
15161499 }
15171500
15181501 static void imx_poll_put_char(struct uart_port *port, unsigned char c)
15191502 {
1520− struct imx_port_ucrs old_ucr;
15211503 unsigned int status;
15221504
1523− /* save control registers */
1524− imx_port_ucrs_save(port, &old_ucr);
1525−
1526− /* disable interrupts */
1527− writel(UCR1_UARTEN, port->membase + UCR1);
1528− writel(old_ucr.ucr2 & ~(UCR2_ATEN | UCR2_RTSEN | UCR2_ESCI),
1529− port->membase + UCR2);
1530− writel(old_ucr.ucr3 & ~(UCR3_DCD | UCR3_RI | UCR3_DTREN),
1531− port->membase + UCR3);
1532−
15331505 /* drain */
15341506 do {
1535− status = readl(port->membase + USR1);
1507+ status = readl_relaxed(port->membase + USR1);
15361508 } while (~status & USR1_TRDY);
15371509
15381510 /* write */
1539− writel(c, port->membase + URTX0);
1511+ writel_relaxed(c, port->membase + URTX0);
15401512
15411513 /* flush */
15421514 do {
1543− status = readl(port->membase + USR2);
1515+ status = readl_relaxed(port->membase + USR2);
15441516 } while (~status & USR2_TXDC);
1545−
1546− /* restore control registers */
1547− imx_port_ucrs_restore(port, &old_ucr);
15481517 }
15491518 #endif
15501519
@@ -1565,6 +1534,7 @@ static struct uart_ops imx_pops = { · 14 unmodified lines
15651534 .config_port = imx_config_port,
15661535 .verify_port = imx_verify_port,
15671536 #if defined(CONFIG_CONSOLE_POLL)
1537+ .poll_init = imx_poll_init,
15681538 .poll_get_char = imx_poll_get_char,
15691539 .poll_put_char = imx_poll_put_char,
15701540 #endif
@@ -1929,6 +1899,36 @@ static int serial_imx_probe(struct platform_device *pdev) · 358 unmodified lines
19291899
19301900 sport->port.uartclk = clk_get_rate(sport->clk_per);
19311901
1902+ /*
1903+ * Allocate the IRQ(s) i.MX1 has three interrupts whereas later
1904+ * chips only have one interrupt.
1905+ */
1906+ if (sport->txirq > 0) {
1907+ ret = devm_request_irq(&pdev->dev, sport->rxirq, imx_rxint, 0,
1908+ dev_name(&pdev->dev), sport);
1909+ if (ret)
1910+ return ret;
1911+
1912+ ret = devm_request_irq(&pdev->dev, sport->txirq, imx_txint, 0,
1913+ dev_name(&pdev->dev), sport);
1914+ if (ret)
1915+ return ret;
1916+
1917+ /* do not use RTS IRQ on IrDA */
1918+ if (!USE_IRDA(sport)) {
1919+ ret = devm_request_irq(&pdev->dev, sport->rtsirq,
1920+ imx_rtsint, 0,
1921+ dev_name(&pdev->dev), sport);
1922+ if (ret)
1923+ return ret;
1924+ }
1925+ } else {
1926+ ret = devm_request_irq(&pdev->dev, sport->port.irq, imx_int, 0,
1927+ dev_name(&pdev->dev), sport);
1928+ if (ret)
1929+ return ret;
1930+ }
1931+
19321932 imx_ports[sport->port.line] = sport;
19331933
19341934 platform_set_drvdata(pdev, sport);
@@ -1959,11 +1959,8 @@ static struct platform_driver serial_imx_driver = { · 24 unmodified lines
19591959
19601960 static int __init imx_serial_init(void)
19611961 {
1962− int ret;
1963−
1964− pr_info("Serial: IMX driver\n");
1962+ int ret = uart_register_driver(&imx_reg);
19651963
1966− ret = uart_register_driver(&imx_reg);
19671964 if (ret)
19681965 return ret;
19691966
drivers/tty/serial/ip22zilog.c+12−6
@@ -544,7 +544,8 @@ static unsigned int ip22zilog_get_mctrl(struct uart_port *port) · 543 unmodified lines
544544 /* The port lock is held and interrupts are disabled. */
545545 static void ip22zilog_set_mctrl(struct uart_port *port, unsigned int mctrl)
546546 {
547− struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
547+ struct uart_ip22zilog_port *up =
548+ container_of(port, struct uart_ip22zilog_port, port);
548549 struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
549550 unsigned char set_bits, clear_bits;
550551
@@ -568,7 +569,8 @@ static void ip22zilog_set_mctrl(struct uart_port *port, unsigned int mctrl) · 17 unmodified lines
568569 /* The port lock is held and interrupts are disabled. */
569570 static void ip22zilog_stop_tx(struct uart_port *port)
570571 {
571− struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
572+ struct uart_ip22zilog_port *up =
573+ container_of(port, struct uart_ip22zilog_port, port);
572574
573575 up->flags |= IP22ZILOG_FLAG_TX_STOPPED;
574576 }
@@ -576,7 +578,8 @@ static void ip22zilog_stop_tx(struct uart_port *port) · 1 unmodified line
576578 /* The port lock is held and interrupts are disabled. */
577579 static void ip22zilog_start_tx(struct uart_port *port)
578580 {
579− struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
581+ struct uart_ip22zilog_port *up =
582+ container_of(port, struct uart_ip22zilog_port, port);
580583 struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
581584 unsigned char status;
582585
@@ -636,7 +639,8 @@ static void ip22zilog_stop_rx(struct uart_port *port) · 53 unmodified lines
636639 /* The port lock is held. */
637640 static void ip22zilog_enable_ms(struct uart_port *port)
638641 {
639− struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
642+ struct uart_ip22zilog_port *up =
643+ container_of(port, struct uart_ip22zilog_port, port);
640644 struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
641645 unsigned char new_reg;
642646
@@ -652,7 +656,8 @@ static void ip22zilog_enable_ms(struct uart_port *port) · 9 unmodified lines
652656 /* The port lock is not held. */
653657 static void ip22zilog_break_ctl(struct uart_port *port, int break_state)
654658 {
655− struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
659+ struct uart_ip22zilog_port *up =
660+ container_of(port, struct uart_ip22zilog_port, port);
656661 struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
657662 unsigned char set_bits, clear_bits, new_reg;
658663 unsigned long flags;
@@ -873,7 +878,8 @@ static void · 214 unmodified lines
873878 ip22zilog_set_termios(struct uart_port *port, struct ktermios *termios,
874879 struct ktermios *old)
875880 {
876− struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
881+ struct uart_ip22zilog_port *up =
882+ container_of(port, struct uart_ip22zilog_port, port);
877883 unsigned long flags;
878884 int baud, brg;
879885
drivers/tty/serial/jsm/Makefile+1−1
@@ -4,5 +4,5 @@ · 3 unmodified lines
44
55 obj-$(CONFIG_SERIAL_JSM) += jsm.o
66
7−jsm-objs := jsm_driver.o jsm_neo.o jsm_tty.o
7+jsm-objs := jsm_driver.o jsm_neo.o jsm_tty.o jsm_cls.o
88
drivers/tty/serial/jsm/jsm.h+79−22
@@ -13,11 +13,6 @@ · 12 unmodified lines
1313 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1414 * PURPOSE. See the GNU General Public License for more details.
1515 *
16− * You should have received a copy of the GNU General Public License
17− * along with this program; if not, write to the Free Software
18− * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
19− * MA 02111-1307, USA.
20− *
2116 * Contact Information:
2217 * Scott H Kilau <Scott_Kilau@digi.com>
2318 * Wendy Xiong <wendyx@us.ibm.com>
@@ -68,6 +63,10 @@ do { \ · 44 unmodified lines
6863 #define MAX_STOPS_SENT 5
6964
7065 /* Board ids */
66+#define PCI_DEVICE_ID_CLASSIC_4 0x0028
67+#define PCI_DEVICE_ID_CLASSIC_8 0x0029
68+#define PCI_DEVICE_ID_CLASSIC_4_422 0x00D0
69+#define PCI_DEVICE_ID_CLASSIC_8_422 0x00D1
7170 #define PCI_DEVICE_ID_NEO_4 0x00B0
7271 #define PCI_DEVICE_ID_NEO_1_422 0x00CC
7372 #define PCI_DEVICE_ID_NEO_1_422_485 0x00CD
@@ -112,21 +111,21 @@ struct jsm_channel; · 38 unmodified lines
112111 ************************************************************************/
113112 struct board_ops {
114113 irq_handler_t intr;
115− void (*uart_init) (struct jsm_channel *ch);
116− void (*uart_off) (struct jsm_channel *ch);
117− void (*param) (struct jsm_channel *ch);
118− void (*assert_modem_signals) (struct jsm_channel *ch);
119− void (*flush_uart_write) (struct jsm_channel *ch);
120− void (*flush_uart_read) (struct jsm_channel *ch);
121− void (*disable_receiver) (struct jsm_channel *ch);
122− void (*enable_receiver) (struct jsm_channel *ch);
123− void (*send_break) (struct jsm_channel *ch);
124− void (*clear_break) (struct jsm_channel *ch, int);
125− void (*send_start_character) (struct jsm_channel *ch);
126− void (*send_stop_character) (struct jsm_channel *ch);
127− void (*copy_data_from_queue_to_uart) (struct jsm_channel *ch);
128− u32 (*get_uart_bytes_left) (struct jsm_channel *ch);
129− void (*send_immediate_char) (struct jsm_channel *ch, unsigned char);
114+ void (*uart_init)(struct jsm_channel *ch);
115+ void (*uart_off)(struct jsm_channel *ch);
116+ void (*param)(struct jsm_channel *ch);
117+ void (*assert_modem_signals)(struct jsm_channel *ch);
118+ void (*flush_uart_write)(struct jsm_channel *ch);
119+ void (*flush_uart_read)(struct jsm_channel *ch);
120+ void (*disable_receiver)(struct jsm_channel *ch);
121+ void (*enable_receiver)(struct jsm_channel *ch);
122+ void (*send_break)(struct jsm_channel *ch);
123+ void (*clear_break)(struct jsm_channel *ch);
124+ void (*send_start_character)(struct jsm_channel *ch);
125+ void (*send_stop_character)(struct jsm_channel *ch);
126+ void (*copy_data_from_queue_to_uart)(struct jsm_channel *ch);
127+ u32 (*get_uart_bytes_left)(struct jsm_channel *ch);
128+ void (*send_immediate_char)(struct jsm_channel *ch, unsigned char);
130129 };
131130
132131
@@ -189,7 +188,7 @@ struct jsm_board · 56 unmodified lines
189188 #define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
190189 #define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
191190
192−/* Our Read/Error/Write queue sizes */
191+/* Our Read/Error queue sizes */
193192 #define RQUEUEMASK 0x1FFF /* 8 K - 1 */
194193 #define EQUEUEMASK 0x1FFF /* 8 K - 1 */
195194 #define RQUEUESIZE (RQUEUEMASK + 1)
@@ -222,7 +221,10 @@ struct jsm_channel { · 26 unmodified lines
222221 u8 ch_mostat; /* FEP output modem status */
223222 u8 ch_mistat; /* FEP input modem status */
224223
225− struct neo_uart_struct __iomem *ch_neo_uart; /* Pointer to the "mapped" UART struct */
224+ /* Pointers to the "mapped" UART structs */
225+ struct neo_uart_struct __iomem *ch_neo_uart; /* NEO card */
226+ struct cls_uart_struct __iomem *ch_cls_uart; /* Classic card */
227+
226228 u8 ch_cached_lsr; /* Cached value of the LSR register */
227229
228230 u8 *ch_rqueue; /* Our read queue buffer - malloc'ed */
@@ -254,6 +256,60 @@ struct jsm_channel { · 25 unmodified lines
254256 u64 ch_xoff_sends; /* Count of xoffs transmitted */
255257 };
256258
259+/************************************************************************
260+ * Per channel/port Classic UART structures *
261+ ************************************************************************
262+ * Base Structure Entries Usage Meanings to Host *
263+ * *
264+ * W = read write R = read only *
265+ * U = Unused. *
266+ ************************************************************************/
267+
268+struct cls_uart_struct {
269+ u8 txrx; /* WR RHR/THR - Holding Reg */
270+ u8 ier; /* WR IER - Interrupt Enable Reg */
271+ u8 isr_fcr; /* WR ISR/FCR - Interrupt Status Reg/Fifo Control Reg*/
272+ u8 lcr; /* WR LCR - Line Control Reg */
273+ u8 mcr; /* WR MCR - Modem Control Reg */
274+ u8 lsr; /* WR LSR - Line Status Reg */
275+ u8 msr; /* WR MSR - Modem Status Reg */
276+ u8 spr; /* WR SPR - Scratch Pad Reg */
277+};
278+
279+/* Where to read the interrupt register (8bits) */
280+#define UART_CLASSIC_POLL_ADDR_OFFSET 0x40
281+
282+#define UART_EXAR654_ENHANCED_REGISTER_SET 0xBF
283+
284+#define UART_16654_FCR_TXTRIGGER_8 0x0
285+#define UART_16654_FCR_TXTRIGGER_16 0x10
286+#define UART_16654_FCR_TXTRIGGER_32 0x20
287+#define UART_16654_FCR_TXTRIGGER_56 0x30
288+
289+#define UART_16654_FCR_RXTRIGGER_8 0x0
290+#define UART_16654_FCR_RXTRIGGER_16 0x40
291+#define UART_16654_FCR_RXTRIGGER_56 0x80
292+#define UART_16654_FCR_RXTRIGGER_60 0xC0
293+
294+#define UART_IIR_CTSRTS 0x20 /* Received CTS/RTS change of state */
295+#define UART_IIR_RDI_TIMEOUT 0x0C /* Receiver data TIMEOUT */
296+
297+/*
298+ * These are the EXTENDED definitions for the Exar 654's Interrupt
299+ * Enable Register.
300+ */
301+#define UART_EXAR654_EFR_ECB 0x10 /* Enhanced control bit */
302+#define UART_EXAR654_EFR_IXON 0x2 /* Receiver compares Xon1/Xoff1 */
303+#define UART_EXAR654_EFR_IXOFF 0x8 /* Transmit Xon1/Xoff1 */
304+#define UART_EXAR654_EFR_RTSDTR 0x40 /* Auto RTS/DTR Flow Control Enable */
305+#define UART_EXAR654_EFR_CTSDSR 0x80 /* Auto CTS/DSR Flow COntrol Enable */
306+
307+#define UART_EXAR654_XOFF_DETECT 0x1 /* Indicates whether chip saw an incoming XOFF char */
308+#define UART_EXAR654_XON_DETECT 0x2 /* Indicates whether chip saw an incoming XON char */
309+
310+#define UART_EXAR654_IER_XOFF 0x20 /* Xoff Interrupt Enable */
311+#define UART_EXAR654_IER_RTSDTR 0x40 /* Output Interrupt Enable */
312+#define UART_EXAR654_IER_CTSDSR 0x80 /* Input Interrupt Enable */
257313
258314 /************************************************************************
259315 * Per channel/port NEO UART structure *
@@ -374,6 +430,7 @@ struct neo_uart_struct { · 114 unmodified lines
374430 */
375431 extern struct uart_driver jsm_uart_driver;
376432 extern struct board_ops jsm_neo_ops;
433+extern struct board_ops jsm_cls_ops;
377434 extern int jsm_debug;
378435
379436 /*************************************************************************
drivers/tty/serial/jsm/jsm_cls.c+982−0
@@ -0,0 +1,982 @@
1+/*
2+ * Copyright 2003 Digi International (www.digi.com)
3+ * Scott H Kilau <Scott_Kilau at digi dot com>
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 2, or (at your option)
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13+ * PURPOSE. See the GNU General Public License for more details.
14+ *
15+ * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
16+ *
17+ * This is shared code between Digi's CVS archive and the
18+ * Linux Kernel sources.
19+ * Changing the source just for reformatting needlessly breaks
20+ * our CVS diff history.
21+ *
22+ * Send any bug fixes/changes to: Eng.Linux at digi dot com.
23+ * Thank you.
24+ *
25+ */
26+
27+#include <linux/delay.h> /* For udelay */
28+#include <linux/io.h> /* For read[bwl]/write[bwl] */
29+#include <linux/serial.h> /* For struct async_serial */
30+#include <linux/serial_reg.h> /* For the various UART offsets */
31+#include <linux/pci.h>
32+#include <linux/tty.h>
33+
34+#include "jsm.h" /* Driver main header file */
35+
36+static struct {
37+ unsigned int rate;
38+ unsigned int cflag;
39+} baud_rates[] = {
40+ { 921600, B921600 },
41+ { 460800, B460800 },
42+ { 230400, B230400 },
43+ { 115200, B115200 },
44+ { 57600, B57600 },
45+ { 38400, B38400 },
46+ { 19200, B19200 },
47+ { 9600, B9600 },
48+ { 4800, B4800 },
49+ { 2400, B2400 },
50+ { 1200, B1200 },
51+ { 600, B600 },
52+ { 300, B300 },
53+ { 200, B200 },
54+ { 150, B150 },
55+ { 134, B134 },
56+ { 110, B110 },
57+ { 75, B75 },
58+ { 50, B50 },
59+};
60+
61+static void cls_set_cts_flow_control(struct jsm_channel *ch)
62+{
63+ u8 lcrb = readb(&ch->ch_cls_uart->lcr);
64+ u8 ier = readb(&ch->ch_cls_uart->ier);
65+ u8 isr_fcr = 0;
66+
67+ /*
68+ * The Enhanced Register Set may only be accessed when
69+ * the Line Control Register is set to 0xBFh.
70+ */
71+ writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
72+
73+ isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
74+
75+ /* Turn on CTS flow control, turn off IXON flow control */
76+ isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_CTSDSR);
77+ isr_fcr &= ~(UART_EXAR654_EFR_IXON);
78+
79+ writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
80+
81+ /* Write old LCR value back out, which turns enhanced access off */
82+ writeb(lcrb, &ch->ch_cls_uart->lcr);
83+
84+ /*
85+ * Enable interrupts for CTS flow, turn off interrupts for
86+ * received XOFF chars
87+ */
88+ ier |= (UART_EXAR654_IER_CTSDSR);
89+ ier &= ~(UART_EXAR654_IER_XOFF);
90+ writeb(ier, &ch->ch_cls_uart->ier);
91+
92+ /* Set the usual FIFO values */
93+ writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
94+
95+ writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 |
96+ UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
97+ &ch->ch_cls_uart->isr_fcr);
98+
99+ ch->ch_t_tlevel = 16;
100+}
101+
102+static void cls_set_ixon_flow_control(struct jsm_channel *ch)
103+{
104+ u8 lcrb = readb(&ch->ch_cls_uart->lcr);
105+ u8 ier = readb(&ch->ch_cls_uart->ier);
106+ u8 isr_fcr = 0;
107+
108+ /*
109+ * The Enhanced Register Set may only be accessed when
110+ * the Line Control Register is set to 0xBFh.
111+ */
112+ writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
113+
114+ isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
115+
116+ /* Turn on IXON flow control, turn off CTS flow control */
117+ isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXON);
118+ isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR);
119+
120+ writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
121+
122+ /* Now set our current start/stop chars while in enhanced mode */
123+ writeb(ch->ch_startc, &ch->ch_cls_uart->mcr);
124+ writeb(0, &ch->ch_cls_uart->lsr);
125+ writeb(ch->ch_stopc, &ch->ch_cls_uart->msr);
126+ writeb(0, &ch->ch_cls_uart->spr);
127+
128+ /* Write old LCR value back out, which turns enhanced access off */
129+ writeb(lcrb, &ch->ch_cls_uart->lcr);
130+
131+ /*
132+ * Disable interrupts for CTS flow, turn on interrupts for
133+ * received XOFF chars
134+ */
135+ ier &= ~(UART_EXAR654_IER_CTSDSR);
136+ ier |= (UART_EXAR654_IER_XOFF);
137+ writeb(ier, &ch->ch_cls_uart->ier);
138+
139+ /* Set the usual FIFO values */
140+ writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
141+
142+ writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
143+ UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
144+ &ch->ch_cls_uart->isr_fcr);
145+}
146+
147+static void cls_set_no_output_flow_control(struct jsm_channel *ch)
148+{
149+ u8 lcrb = readb(&ch->ch_cls_uart->lcr);
150+ u8 ier = readb(&ch->ch_cls_uart->ier);
151+ u8 isr_fcr = 0;
152+
153+ /*
154+ * The Enhanced Register Set may only be accessed when
155+ * the Line Control Register is set to 0xBFh.
156+ */
157+ writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
158+
159+ isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
160+
161+ /* Turn off IXON flow control, turn off CTS flow control */
162+ isr_fcr |= (UART_EXAR654_EFR_ECB);
163+ isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR | UART_EXAR654_EFR_IXON);
164+
165+ writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
166+
167+ /* Write old LCR value back out, which turns enhanced access off */
168+ writeb(lcrb, &ch->ch_cls_uart->lcr);
169+
170+ /*
171+ * Disable interrupts for CTS flow, turn off interrupts for
172+ * received XOFF chars
173+ */
174+ ier &= ~(UART_EXAR654_IER_CTSDSR);
175+ ier &= ~(UART_EXAR654_IER_XOFF);
176+ writeb(ier, &ch->ch_cls_uart->ier);
177+
178+ /* Set the usual FIFO values */
179+ writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
180+
181+ writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
182+ UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
183+ &ch->ch_cls_uart->isr_fcr);
184+
185+ ch->ch_r_watermark = 0;
186+ ch->ch_t_tlevel = 16;
187+ ch->ch_r_tlevel = 16;
188+}
189+
190+static void cls_set_rts_flow_control(struct jsm_channel *ch)
191+{
192+ u8 lcrb = readb(&ch->ch_cls_uart->lcr);
193+ u8 ier = readb(&ch->ch_cls_uart->ier);
194+ u8 isr_fcr = 0;
195+
196+ /*
197+ * The Enhanced Register Set may only be accessed when
198+ * the Line Control Register is set to 0xBFh.
199+ */
200+ writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
201+
202+ isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
203+
204+ /* Turn on RTS flow control, turn off IXOFF flow control */
205+ isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_RTSDTR);
206+ isr_fcr &= ~(UART_EXAR654_EFR_IXOFF);
207+
208+ writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
209+
210+ /* Write old LCR value back out, which turns enhanced access off */
211+ writeb(lcrb, &ch->ch_cls_uart->lcr);
212+
213+ /* Enable interrupts for RTS flow */
214+ ier |= (UART_EXAR654_IER_RTSDTR);
215+ writeb(ier, &ch->ch_cls_uart->ier);
216+
217+ /* Set the usual FIFO values */
218+ writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
219+
220+ writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 |
221+ UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
222+ &ch->ch_cls_uart->isr_fcr);
223+
224+ ch->ch_r_watermark = 4;
225+ ch->ch_r_tlevel = 8;
226+}
227+
228+static void cls_set_ixoff_flow_control(struct jsm_channel *ch)
229+{
230+ u8 lcrb = readb(&ch->ch_cls_uart->lcr);
231+ u8 ier = readb(&ch->ch_cls_uart->ier);
232+ u8 isr_fcr = 0;
233+
234+ /*
235+ * The Enhanced Register Set may only be accessed when
236+ * the Line Control Register is set to 0xBFh.
237+ */
238+ writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
239+
240+ isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
241+
242+ /* Turn on IXOFF flow control, turn off RTS flow control */
243+ isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXOFF);
244+ isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR);
245+
246+ writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
247+
248+ /* Now set our current start/stop chars while in enhanced mode */
249+ writeb(ch->ch_startc, &ch->ch_cls_uart->mcr);
250+ writeb(0, &ch->ch_cls_uart->lsr);
251+ writeb(ch->ch_stopc, &ch->ch_cls_uart->msr);
252+ writeb(0, &ch->ch_cls_uart->spr);
253+
254+ /* Write old LCR value back out, which turns enhanced access off */
255+ writeb(lcrb, &ch->ch_cls_uart->lcr);
256+
257+ /* Disable interrupts for RTS flow */
258+ ier &= ~(UART_EXAR654_IER_RTSDTR);
259+ writeb(ier, &ch->ch_cls_uart->ier);
260+
261+ /* Set the usual FIFO values */
262+ writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
263+
264+ writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
265+ UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
266+ &ch->ch_cls_uart->isr_fcr);
267+}
268+
269+static void cls_set_no_input_flow_control(struct jsm_channel *ch)
270+{
271+ u8 lcrb = readb(&ch->ch_cls_uart->lcr);
272+ u8 ier = readb(&ch->ch_cls_uart->ier);
273+ u8 isr_fcr = 0;
274+
275+ /*
276+ * The Enhanced Register Set may only be accessed when
277+ * the Line Control Register is set to 0xBFh.
278+ */
279+ writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
280+
281+ isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
282+
283+ /* Turn off IXOFF flow control, turn off RTS flow control */
284+ isr_fcr |= (UART_EXAR654_EFR_ECB);
285+ isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR | UART_EXAR654_EFR_IXOFF);
286+
287+ writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
288+
289+ /* Write old LCR value back out, which turns enhanced access off */
290+ writeb(lcrb, &ch->ch_cls_uart->lcr);
291+
292+ /* Disable interrupts for RTS flow */
293+ ier &= ~(UART_EXAR654_IER_RTSDTR);
294+ writeb(ier, &ch->ch_cls_uart->ier);
295+
296+ /* Set the usual FIFO values */
297+ writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
298+
299+ writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
300+ UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
301+ &ch->ch_cls_uart->isr_fcr);
302+
303+ ch->ch_t_tlevel = 16;
304+ ch->ch_r_tlevel = 16;
305+}
306+
307+/*
308+ * cls_clear_break.
309+ * Determines whether its time to shut off break condition.
310+ *
311+ * No locks are assumed to be held when calling this function.
312+ * channel lock is held and released in this function.
313+ */
314+static void cls_clear_break(struct jsm_channel *ch)
315+{
316+ unsigned long lock_flags;
317+
318+ spin_lock_irqsave(&ch->ch_lock, lock_flags);
319+
320+ /* Turn break off, and unset some variables */
321+ if (ch->ch_flags & CH_BREAK_SENDING) {
322+ u8 temp = readb(&ch->ch_cls_uart->lcr);
323+
324+ writeb((temp & ~UART_LCR_SBC), &ch->ch_cls_uart->lcr);
325+
326+ ch->ch_flags &= ~(CH_BREAK_SENDING);
327+ jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
328+ "clear break Finishing UART_LCR_SBC! finished: %lx\n",
329+ jiffies);
330+ }
331+ spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
332+}
333+
334+static void cls_disable_receiver(struct jsm_channel *ch)
335+{
336+ u8 tmp = readb(&ch->ch_cls_uart->ier);
337+
338+ tmp &= ~(UART_IER_RDI);
339+ writeb(tmp, &ch->ch_cls_uart->ier);
340+}
341+
342+static void cls_enable_receiver(struct jsm_channel *ch)
343+{
344+ u8 tmp = readb(&ch->ch_cls_uart->ier);
345+
346+ tmp |= (UART_IER_RDI);
347+ writeb(tmp, &ch->ch_cls_uart->ier);
348+}
349+
350+/* Make the UART raise any of the output signals we want up */
351+static void cls_assert_modem_signals(struct jsm_channel *ch)
352+{
353+ if (!ch)
354+ return;
355+
356+ writeb(ch->ch_mostat, &ch->ch_cls_uart->mcr);
357+}
358+
359+static void cls_copy_data_from_uart_to_queue(struct jsm_channel *ch)
360+{
361+ int qleft = 0;
362+ u8 linestatus = 0;
363+ u8 error_mask = 0;
364+ u16 head;
365+ u16 tail;
366+ unsigned long flags;
367+
368+ if (!ch)
369+ return;
370+
371+ spin_lock_irqsave(&ch->ch_lock, flags);
372+
373+ /* cache head and tail of queue */
374+ head = ch->ch_r_head & RQUEUEMASK;
375+ tail = ch->ch_r_tail & RQUEUEMASK;
376+
377+ /* Get our cached LSR */
378+ linestatus = ch->ch_cached_lsr;
379+ ch->ch_cached_lsr = 0;
380+
381+ /* Store how much space we have left in the queue */
382+ qleft = tail - head - 1;
383+ if (qleft < 0)
384+ qleft += RQUEUEMASK + 1;
385+
386+ /*
387+ * Create a mask to determine whether we should
388+ * insert the character (if any) into our queue.
389+ */
390+ if (ch->ch_c_iflag & IGNBRK)
391+ error_mask |= UART_LSR_BI;
392+
393+ while (1) {
394+ /*
395+ * Grab the linestatus register, we need to
396+ * check to see if there is any data to read
397+ */
398+ linestatus = readb(&ch->ch_cls_uart->lsr);
399+
400+ /* Break out if there is no data to fetch */
401+ if (!(linestatus & UART_LSR_DR))
402+ break;
403+
404+ /*
405+ * Discard character if we are ignoring the error mask
406+ * which in this case is the break signal.
407+ */
408+ if (linestatus & error_mask) {
409+ u8 discard;
410+
411+ linestatus = 0;
412+ discard = readb(&ch->ch_cls_uart->txrx);
413+ continue;
414+ }
415+
416+ /*
417+ * If our queue is full, we have no choice but to drop some
418+ * data. The assumption is that HWFLOW or SWFLOW should have
419+ * stopped things way way before we got to this point.
420+ *
421+ * I decided that I wanted to ditch the oldest data first,
422+ * I hope thats okay with everyone? Yes? Good.
423+ */
424+ while (qleft < 1) {
425+ tail = (tail + 1) & RQUEUEMASK;
426+ ch->ch_r_tail = tail;
427+ ch->ch_err_overrun++;
428+ qleft++;
429+ }
430+
431+ ch->ch_equeue[head] = linestatus & (UART_LSR_BI | UART_LSR_PE
432+ | UART_LSR_FE);
433+ ch->ch_rqueue[head] = readb(&ch->ch_cls_uart->txrx);
434+
435+ qleft--;
436+
437+ if (ch->ch_equeue[head] & UART_LSR_PE)
438+ ch->ch_err_parity++;
439+ if (ch->ch_equeue[head] & UART_LSR_BI)
440+ ch->ch_err_break++;
441+ if (ch->ch_equeue[head] & UART_LSR_FE)
442+ ch->ch_err_frame++;
443+
444+ /* Add to, and flip head if needed */
445+ head = (head + 1) & RQUEUEMASK;
446+ ch->ch_rxcount++;
447+ }
448+
449+ /*
450+ * Write new final heads to channel structure.
451+ */
452+ ch->ch_r_head = head & RQUEUEMASK;
453+ ch->ch_e_head = head & EQUEUEMASK;
454+
455+ spin_unlock_irqrestore(&ch->ch_lock, flags);
456+}
457+
458+static void cls_copy_data_from_queue_to_uart(struct jsm_channel *ch)
459+{
460+ u16 tail;
461+ int n;
462+ int qlen;
463+ u32 len_written = 0;
464+ struct circ_buf *circ;
465+
466+ if (!ch)
467+ return;
468+
469+ circ = &ch->uart_port.state->xmit;
470+
471+ /* No data to write to the UART */
472+ if (uart_circ_empty(circ))
473+ return;
474+
475+ /* If port is "stopped", don't send any data to the UART */
476+ if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_BREAK_SENDING))
477+ return;
478+
479+ /* We have to do it this way, because of the EXAR TXFIFO count bug. */
480+ if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
481+ return;
482+
483+ n = 32;
484+
485+ /* cache tail of queue */
486+ tail = circ->tail & (UART_XMIT_SIZE - 1);
487+ qlen = uart_circ_chars_pending(circ);
488+
489+ /* Find minimum of the FIFO space, versus queue length */
490+ n = min(n, qlen);
491+
492+ while (n > 0) {
493+ writeb(circ->buf[tail], &ch->ch_cls_uart->txrx);
494+ tail = (tail + 1) & (UART_XMIT_SIZE - 1);
495+ n--;
496+ ch->ch_txcount++;
497+ len_written++;
498+ }
499+
500+ /* Update the final tail */
501+ circ->tail = tail & (UART_XMIT_SIZE - 1);
502+
503+ if (len_written > ch->ch_t_tlevel)
504+ ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
505+
506+ if (uart_circ_empty(circ))
507+ uart_write_wakeup(&ch->uart_port);
508+}
509+
510+static void cls_parse_modem(struct jsm_channel *ch, u8 signals)
511+{
512+ u8 msignals = signals;
513+
514+ jsm_dbg(MSIGS, &ch->ch_bd->pci_dev,
515+ "neo_parse_modem: port: %d msignals: %x\n",
516+ ch->ch_portnum, msignals);
517+
518+ /*
519+ * Scrub off lower bits.
520+ * They signify delta's, which I don't care about
521+ * Keep DDCD and DDSR though
522+ */
523+ msignals &= 0xf8;
524+
525+ if (msignals & UART_MSR_DDCD)
526+ uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_DCD);
527+ if (msignals & UART_MSR_DDSR)
528+ uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_CTS);
529+
530+ if (msignals & UART_MSR_DCD)
531+ ch->ch_mistat |= UART_MSR_DCD;
532+ else
533+ ch->ch_mistat &= ~UART_MSR_DCD;
534+
535+ if (msignals & UART_MSR_DSR)
536+ ch->ch_mistat |= UART_MSR_DSR;
537+ else
538+ ch->ch_mistat &= ~UART_MSR_DSR;
539+
540+ if (msignals & UART_MSR_RI)
541+ ch->ch_mistat |= UART_MSR_RI;
542+ else
543+ ch->ch_mistat &= ~UART_MSR_RI;
544+
545+ if (msignals & UART_MSR_CTS)
546+ ch->ch_mistat |= UART_MSR_CTS;
547+ else
548+ ch->ch_mistat &= ~UART_MSR_CTS;
549+
550+ jsm_dbg(MSIGS, &ch->ch_bd->pci_dev,
551+ "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n",
552+ ch->ch_portnum,
553+ !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_DTR),
554+ !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_RTS),
555+ !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_CTS),
556+ !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DSR),
557+ !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_RI),
558+ !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DCD));
559+}
560+
561+/* Parse the ISR register for the specific port */
562+static inline void cls_parse_isr(struct jsm_board *brd, uint port)
563+{
564+ struct jsm_channel *ch;
565+ u8 isr = 0;
566+ unsigned long flags;
567+
568+ /*
569+ * No need to verify board pointer, it was already
570+ * verified in the interrupt routine.
571+ */
572+
573+ if (port > brd->nasync)
574+ return;
575+
576+ ch = brd->channels[port];
577+ if (!ch)
578+ return;
579+
580+ /* Here we try to figure out what caused the interrupt to happen */
581+ while (1) {
582+ isr = readb(&ch->ch_cls_uart->isr_fcr);
583+
584+ /* Bail if no pending interrupt on port */
585+ if (isr & UART_IIR_NO_INT)
586+ break;
587+
588+ /* Receive Interrupt pending */
589+ if (isr & (UART_IIR_RDI | UART_IIR_RDI_TIMEOUT)) {
590+ /* Read data from uart -> queue */
591+ cls_copy_data_from_uart_to_queue(ch);
592+ jsm_check_queue_flow_control(ch);
593+ }
594+
595+ /* Transmit Hold register empty pending */
596+ if (isr & UART_IIR_THRI) {
597+ /* Transfer data (if any) from Write Queue -> UART. */
598+ spin_lock_irqsave(&ch->ch_lock, flags);
599+ ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
600+ spin_unlock_irqrestore(&ch->ch_lock, flags);
601+ cls_copy_data_from_queue_to_uart(ch);
602+ }
603+
604+ /*
605+ * CTS/RTS change of state:
606+ * Don't need to do anything, the cls_parse_modem
607+ * below will grab the updated modem signals.
608+ */
609+
610+ /* Parse any modem signal changes */
611+ cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr));
612+ }
613+}
614+
615+/* Channel lock MUST be held before calling this function! */
616+static void cls_flush_uart_write(struct jsm_channel *ch)
617+{
618+ u8 tmp = 0;
619+ u8 i = 0;
620+
621+ if (!ch)
622+ return;
623+
624+ writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT),
625+ &ch->ch_cls_uart->isr_fcr);
626+
627+ for (i = 0; i < 10; i++) {
628+ /* Check to see if the UART feels it completely flushed FIFO */
629+ tmp = readb(&ch->ch_cls_uart->isr_fcr);
630+ if (tmp & UART_FCR_CLEAR_XMIT) {
631+ jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
632+ "Still flushing TX UART... i: %d\n", i);
633+ udelay(10);
634+ } else
635+ break;
636+ }
637+
638+ ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
639+}
640+
641+/* Channel lock MUST be held before calling this function! */
642+static void cls_flush_uart_read(struct jsm_channel *ch)
643+{
644+ if (!ch)
645+ return;
646+
647+ /*
648+ * For complete POSIX compatibility, we should be purging the
649+ * read FIFO in the UART here.
650+ *
651+ * However, clearing the read FIFO (UART_FCR_CLEAR_RCVR) also
652+ * incorrectly flushes write data as well as just basically trashing the
653+ * FIFO.
654+ *
655+ * Presumably, this is a bug in this UART.
656+ */
657+
658+ udelay(10);
659+}
660+
661+static void cls_send_start_character(struct jsm_channel *ch)
662+{
663+ if (!ch)
664+ return;
665+
666+ if (ch->ch_startc != __DISABLED_CHAR) {
667+ ch->ch_xon_sends++;
668+ writeb(ch->ch_startc, &ch->ch_cls_uart->txrx);
669+ }
670+}
671+
672+static void cls_send_stop_character(struct jsm_channel *ch)
673+{
674+ if (!ch)
675+ return;
676+
677+ if (ch->ch_stopc != __DISABLED_CHAR) {
678+ ch->ch_xoff_sends++;
679+ writeb(ch->ch_stopc, &ch->ch_cls_uart->txrx);
680+ }
681+}
682+
683+/*
684+ * cls_param()
685+ * Send any/all changes to the line to the UART.
686+ */
687+static void cls_param(struct jsm_channel *ch)
688+{
689+ u8 lcr = 0;
690+ u8 uart_lcr = 0;
691+ u8 ier = 0;
692+ u32 baud = 9600;
693+ int quot = 0;
694+ struct jsm_board *bd;
695+ int i;
696+ unsigned int cflag;
697+
698+ bd = ch->ch_bd;
699+ if (!bd)
700+ return;
701+
702+ /*
703+ * If baud rate is zero, flush queues, and set mval to drop DTR.
704+ */
705+ if ((ch->ch_c_cflag & (CBAUD)) == 0) {
706+ ch->ch_r_head = 0;
707+ ch->ch_r_tail = 0;
708+ ch->ch_e_head = 0;
709+ ch->ch_e_tail = 0;
710+
711+ cls_flush_uart_write(ch);
712+ cls_flush_uart_read(ch);
713+
714+ /* The baudrate is B0 so all modem lines are to be dropped. */
715+ ch->ch_flags |= (CH_BAUD0);
716+ ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
717+ cls_assert_modem_signals(ch);
718+ return;
719+ }
720+
721+ cflag = C_BAUD(ch->uart_port.state->port.tty);
722+ baud = 9600;
723+ for (i = 0; i < ARRAY_SIZE(baud_rates); i++) {
724+ if (baud_rates[i].cflag == cflag) {
725+ baud = baud_rates[i].rate;
726+ break;
727+ }
728+ }
729+
730+ if (ch->ch_flags & CH_BAUD0)
731+ ch->ch_flags &= ~(CH_BAUD0);
732+
733+ if (ch->ch_c_cflag & PARENB)
734+ lcr |= UART_LCR_PARITY;
735+
736+ if (!(ch->ch_c_cflag & PARODD))
737+ lcr |= UART_LCR_EPAR;
738+
739+ /*
740+ * Not all platforms support mark/space parity,
741+ * so this will hide behind an ifdef.
742+ */
743+#ifdef CMSPAR
744+ if (ch->ch_c_cflag & CMSPAR)
745+ lcr |= UART_LCR_SPAR;
746+#endif
747+
748+ if (ch->ch_c_cflag & CSTOPB)
749+ lcr |= UART_LCR_STOP;
750+
751+ switch (ch->ch_c_cflag & CSIZE) {
752+ case CS5:
753+ lcr |= UART_LCR_WLEN5;
754+ break;
755+ case CS6:
756+ lcr |= UART_LCR_WLEN6;
757+ break;
758+ case CS7:
759+ lcr |= UART_LCR_WLEN7;
760+ break;
761+ case CS8:
762+ default:
763+ lcr |= UART_LCR_WLEN8;
764+ break;
765+ }
766+
767+ ier = readb(&ch->ch_cls_uart->ier);
768+ uart_lcr = readb(&ch->ch_cls_uart->lcr);
769+
770+ quot = ch->ch_bd->bd_dividend / baud;
771+
772+ if (quot != 0) {
773+ writeb(UART_LCR_DLAB, &ch->ch_cls_uart->lcr);
774+ writeb((quot & 0xff), &ch->ch_cls_uart->txrx);
775+ writeb((quot >> 8), &ch->ch_cls_uart->ier);
776+ writeb(lcr, &ch->ch_cls_uart->lcr);
777+ }
778+
779+ if (uart_lcr != lcr)
780+ writeb(lcr, &ch->ch_cls_uart->lcr);
781+
782+ if (ch->ch_c_cflag & CREAD)
783+ ier |= (UART_IER_RDI | UART_IER_RLSI);
784+
785+ ier |= (UART_IER_THRI | UART_IER_MSI);
786+
787+ writeb(ier, &ch->ch_cls_uart->ier);
788+
789+ if (ch->ch_c_cflag & CRTSCTS)
790+ cls_set_cts_flow_control(ch);
791+ else if (ch->ch_c_iflag & IXON) {
792+ /*
793+ * If start/stop is set to disable,
794+ * then we should disable flow control.
795+ */
796+ if ((ch->ch_startc == __DISABLED_CHAR) ||
797+ (ch->ch_stopc == __DISABLED_CHAR))
798+ cls_set_no_output_flow_control(ch);
799+ else
800+ cls_set_ixon_flow_control(ch);
801+ } else
802+ cls_set_no_output_flow_control(ch);
803+
804+ if (ch->ch_c_cflag & CRTSCTS)
805+ cls_set_rts_flow_control(ch);
806+ else if (ch->ch_c_iflag & IXOFF) {
807+ /*
808+ * If start/stop is set to disable,
809+ * then we should disable flow control.
810+ */
811+ if ((ch->ch_startc == __DISABLED_CHAR) ||
812+ (ch->ch_stopc == __DISABLED_CHAR))
813+ cls_set_no_input_flow_control(ch);
814+ else
815+ cls_set_ixoff_flow_control(ch);
816+ } else
817+ cls_set_no_input_flow_control(ch);
818+
819+ cls_assert_modem_signals(ch);
820+
821+ /* get current status of the modem signals now */
822+ cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr));
823+}
824+
825+/*
826+ * cls_intr()
827+ *
828+ * Classic specific interrupt handler.
829+ */
830+static irqreturn_t cls_intr(int irq, void *voidbrd)
831+{
832+ struct jsm_board *brd = voidbrd;
833+ unsigned long lock_flags;
834+ unsigned char uart_poll;
835+ uint i = 0;
836+
837+ /* Lock out the slow poller from running on this board. */
838+ spin_lock_irqsave(&brd->bd_intr_lock, lock_flags);
839+
840+ /*
841+ * Check the board's global interrupt offset to see if we
842+ * acctually do have an interrupt pending on us.
843+ */
844+ uart_poll = readb(brd->re_map_membase + UART_CLASSIC_POLL_ADDR_OFFSET);
845+
846+ jsm_dbg(INTR, &brd->pci_dev, "%s:%d uart_poll: %x\n",
847+ __FILE__, __LINE__, uart_poll);
848+
849+ if (!uart_poll) {
850+ jsm_dbg(INTR, &brd->pci_dev,
851+ "Kernel interrupted to me, but no pending interrupts...\n");
852+ spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
853+ return IRQ_NONE;
854+ }
855+
856+ /* At this point, we have at least SOMETHING to service, dig further. */
857+
858+ /* Parse each port to find out what caused the interrupt */
859+ for (i = 0; i < brd->nasync; i++)
860+ cls_parse_isr(brd, i);
861+
862+ spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
863+
864+ return IRQ_HANDLED;
865+}
866+
867+/* Inits UART */
868+static void cls_uart_init(struct jsm_channel *ch)
869+{
870+ unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
871+ unsigned char isr_fcr = 0;
872+
873+ writeb(0, &ch->ch_cls_uart->ier);
874+
875+ /*
876+ * The Enhanced Register Set may only be accessed when
877+ * the Line Control Register is set to 0xBFh.
878+ */
879+ writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
880+
881+ isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
882+
883+ /* Turn on Enhanced/Extended controls */
884+ isr_fcr |= (UART_EXAR654_EFR_ECB);
885+
886+ writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
887+
888+ /* Write old LCR value back out, which turns enhanced access off */
889+ writeb(lcrb, &ch->ch_cls_uart->lcr);
890+
891+ /* Clear out UART and FIFO */
892+ readb(&ch->ch_cls_uart->txrx);
893+
894+ writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT),
895+ &ch->ch_cls_uart->isr_fcr);
896+ udelay(10);
897+
898+ ch->ch_flags |= (CH_FIFO_ENABLED | CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
899+
900+ readb(&ch->ch_cls_uart->lsr);
901+ readb(&ch->ch_cls_uart->msr);
902+}
903+
904+/*
905+ * Turns off UART.
906+ */
907+static void cls_uart_off(struct jsm_channel *ch)
908+{
909+ /* Stop all interrupts from accurring. */
910+ writeb(0, &ch->ch_cls_uart->ier);
911+}
912+
913+/*
914+ * cls_get_uarts_bytes_left.
915+ * Returns 0 is nothing left in the FIFO, returns 1 otherwise.
916+ *
917+ * The channel lock MUST be held by the calling function.
918+ */
919+static u32 cls_get_uart_bytes_left(struct jsm_channel *ch)
920+{
921+ u8 left = 0;
922+ u8 lsr = readb(&ch->ch_cls_uart->lsr);
923+
924+ /* Determine whether the Transmitter is empty or not */
925+ if (!(lsr & UART_LSR_TEMT))
926+ left = 1;
927+ else {
928+ ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
929+ left = 0;
930+ }
931+
932+ return left;
933+}
934+
935+/*
936+ * cls_send_break.
937+ * Starts sending a break thru the UART.
938+ *
939+ * The channel lock MUST be held by the calling function.
940+ */
941+static void cls_send_break(struct jsm_channel *ch)
942+{
943+ /* Tell the UART to start sending the break */
944+ if (!(ch->ch_flags & CH_BREAK_SENDING)) {
945+ u8 temp = readb(&ch->ch_cls_uart->lcr);
946+
947+ writeb((temp | UART_LCR_SBC), &ch->ch_cls_uart->lcr);
948+ ch->ch_flags |= (CH_BREAK_SENDING);
949+ }
950+}
951+
952+/*
953+ * cls_send_immediate_char.
954+ * Sends a specific character as soon as possible to the UART,
955+ * jumping over any bytes that might be in the write queue.
956+ *
957+ * The channel lock MUST be held by the calling function.
958+ */
959+static void cls_send_immediate_char(struct jsm_channel *ch, unsigned char c)
960+{
961+ writeb(c, &ch->ch_cls_uart->txrx);
962+}
963+
964+struct board_ops jsm_cls_ops = {
965+ .intr = cls_intr,
966+ .uart_init = cls_uart_init,
967+ .uart_off = cls_uart_off,
968+ .param = cls_param,
969+ .assert_modem_signals = cls_assert_modem_signals,
970+ .flush_uart_write = cls_flush_uart_write,
971+ .flush_uart_read = cls_flush_uart_read,
972+ .disable_receiver = cls_disable_receiver,
973+ .enable_receiver = cls_enable_receiver,
974+ .send_break = cls_send_break,
975+ .clear_break = cls_clear_break,
976+ .send_start_character = cls_send_start_character,
977+ .send_stop_character = cls_send_stop_character,
978+ .copy_data_from_queue_to_uart = cls_copy_data_from_queue_to_uart,
979+ .get_uart_bytes_left = cls_get_uart_bytes_left,
980+ .send_immediate_char = cls_send_immediate_char
981+};
982+
drivers/tty/serial/jsm/jsm_driver.c+120−36
@@ -13,11 +13,6 @@ · 12 unmodified lines
1313 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1414 * PURPOSE. See the GNU General Public License for more details.
1515 *
16− * You should have received a copy of the GNU General Public License
17− * along with this program; if not, write to the Free Software
18− * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
19− * MA 02111-1307, USA.
20− *
2116 * Contact Information:
2217 * Scott H Kilau <Scott_Kilau@digi.com>
2318 * Wendy Xiong <wendyx@us.ibm.com>
@@ -31,8 +26,7 @@ · 7 unmodified lines
3126 #include "jsm.h"
3227
3328 MODULE_AUTHOR("Digi International, http://www.digi.com");
34−MODULE_DESCRIPTION("Driver for the Digi International "
35− "Neo PCI based product line");
29+MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line");
3630 MODULE_LICENSE("GPL");
3731 MODULE_SUPPORTED_DEVICE("jsm");
3832
@@ -50,7 +44,7 @@ struct uart_driver jsm_uart_driver = { · 11 unmodified lines
5044 };
5145
5246 static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
53− pci_channel_state_t state);
47+ pci_channel_state_t state);
5448 static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev);
5549 static void jsm_io_resume(struct pci_dev *pdev);
5650
@@ -68,7 +62,7 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent) · 11 unmodified lines
6862 {
6963 int rc = 0;
7064 struct jsm_board *brd;
71− static int adapter_count = 0;
65+ static int adapter_count;
7266
7367 rc = pci_enable_device(pdev);
7468 if (rc) {
@@ -82,10 +76,8 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent) · 7 unmodified lines
8276 goto out_disable_device;
8377 }
8478
85− brd = kzalloc(sizeof(struct jsm_board), GFP_KERNEL);
79+ brd = kzalloc(sizeof(*brd), GFP_KERNEL);
8680 if (!brd) {
87− dev_err(&pdev->dev,
88− "memory allocation for board structure failed\n");
8981 rc = -ENOMEM;
9082 goto out_release_regions;
9183 }
@@ -95,7 +87,6 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent) · 3 unmodified lines
9587 brd->pci_dev = pdev;
9688
9789 switch (pdev->device) {
98−
9990 case PCI_DEVICE_ID_NEO_2DB9:
10091 case PCI_DEVICE_ID_NEO_2DB9PRI:
10192 case PCI_DEVICE_ID_NEO_2RJ45:
@@ -104,6 +95,8 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent) · 2 unmodified lines
10495 brd->maxports = 2;
10596 break;
10697
98+ case PCI_DEVICE_ID_CLASSIC_4:
99+ case PCI_DEVICE_ID_CLASSIC_4_422:
107100 case PCI_DEVICE_ID_NEO_4:
108101 case PCIE_DEVICE_ID_NEO_4:
109102 case PCIE_DEVICE_ID_NEO_4RJ45:
@@ -111,6 +104,8 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent) · 1 unmodified line
111104 brd->maxports = 4;
112105 break;
113106
107+ case PCI_DEVICE_ID_CLASSIC_8:
108+ case PCI_DEVICE_ID_CLASSIC_8_422:
114109 case PCI_DEVICE_ID_DIGI_NEO_8:
115110 case PCIE_DEVICE_ID_NEO_8:
116111 case PCIE_DEVICE_ID_NEO_8RJ45:
@@ -129,36 +124,109 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent) · 12 unmodified lines
129124
130125 brd->irq = pdev->irq;
131126
132− jsm_dbg(INIT, &brd->pci_dev, "jsm_found_board - NEO adapter\n");
127+ switch (pdev->device) {
128+ case PCI_DEVICE_ID_CLASSIC_4:
129+ case PCI_DEVICE_ID_CLASSIC_4_422:
130+ case PCI_DEVICE_ID_CLASSIC_8:
131+ case PCI_DEVICE_ID_CLASSIC_8_422:
132+
133+ jsm_dbg(INIT, &brd->pci_dev,
134+ "jsm_found_board - Classic adapter\n");
135+
136+ /*
137+ * For PCI ClassicBoards
138+ * PCI Local Address (.i.e. "resource" number) space
139+ * 0 PLX Memory Mapped Config
140+ * 1 PLX I/O Mapped Config
141+ * 2 I/O Mapped UARTs and Status
142+ * 3 Memory Mapped VPD
143+ * 4 Memory Mapped UARTs and Status
144+ */
145+
146+ /* Get the PCI Base Address Registers */
147+ brd->membase = pci_resource_start(pdev, 4);
148+ brd->membase_end = pci_resource_end(pdev, 4);
149+
150+ if (brd->membase & 0x1)
151+ brd->membase &= ~0x3;
152+ else
153+ brd->membase &= ~0xF;
154+
155+ brd->iobase = pci_resource_start(pdev, 1);
156+ brd->iobase_end = pci_resource_end(pdev, 1);
157+ brd->iobase = ((unsigned int)(brd->iobase)) & 0xFFFE;
158+
159+ /* Assign the board_ops struct */
160+ brd->bd_ops = &jsm_cls_ops;
161+
162+ brd->bd_uart_offset = 0x8;
163+ brd->bd_dividend = 921600;
164+
165+ brd->re_map_membase = ioremap(brd->membase,
166+ pci_resource_len(pdev, 4));
167+ if (!brd->re_map_membase) {
168+ dev_err(&pdev->dev,
169+ "Card has no PCI Memory resources, failing board.\n");
170+ rc = -ENOMEM;
171+ goto out_kfree_brd;
172+ }
173+
174+ /*
175+ * Enable Local Interrupt 1 (0x1),
176+ * Local Interrupt 1 Polarity Active high (0x2),
177+ * Enable PCI interrupt (0x43)
178+ */
179+ outb(0x43, brd->iobase + 0x4c);
180+
181+ break;
182+
183+ case PCI_DEVICE_ID_NEO_2DB9:
184+ case PCI_DEVICE_ID_NEO_2DB9PRI:
185+ case PCI_DEVICE_ID_NEO_2RJ45:
186+ case PCI_DEVICE_ID_NEO_2RJ45PRI:
187+ case PCI_DEVICE_ID_NEO_2_422_485:
188+ case PCI_DEVICE_ID_NEO_4:
189+ case PCIE_DEVICE_ID_NEO_4:
190+ case PCIE_DEVICE_ID_NEO_4RJ45:
191+ case PCIE_DEVICE_ID_NEO_4_IBM:
192+ case PCI_DEVICE_ID_DIGI_NEO_8:
193+ case PCIE_DEVICE_ID_NEO_8:
194+ case PCIE_DEVICE_ID_NEO_8RJ45:
195+
196+ jsm_dbg(INIT, &brd->pci_dev, "jsm_found_board - NEO adapter\n");
133197
134− /* get the PCI Base Address Registers */
135− brd->membase = pci_resource_start(pdev, 0);
136− brd->membase_end = pci_resource_end(pdev, 0);
198+ /* get the PCI Base Address Registers */
199+ brd->membase = pci_resource_start(pdev, 0);
200+ brd->membase_end = pci_resource_end(pdev, 0);
137201
138− if (brd->membase & 1)
139− brd->membase &= ~3;
140− else
141− brd->membase &= ~15;
202+ if (brd->membase & 1)
203+ brd->membase &= ~0x3;
204+ else
205+ brd->membase &= ~0xF;
142206
143− /* Assign the board_ops struct */
144− brd->bd_ops = &jsm_neo_ops;
207+ /* Assign the board_ops struct */
208+ brd->bd_ops = &jsm_neo_ops;
145209
146− brd->bd_uart_offset = 0x200;
147− brd->bd_dividend = 921600;
210+ brd->bd_uart_offset = 0x200;
211+ brd->bd_dividend = 921600;
148212
149− brd->re_map_membase = ioremap(brd->membase, pci_resource_len(pdev, 0));
150− if (!brd->re_map_membase) {
151− dev_err(&pdev->dev,
152− "card has no PCI Memory resources, "
153− "failing board.\n");
154− rc = -ENOMEM;
155− goto out_kfree_brd;
213+ brd->re_map_membase = ioremap(brd->membase,
214+ pci_resource_len(pdev, 0));
215+ if (!brd->re_map_membase) {
216+ dev_err(&pdev->dev,
217+ "Card has no PCI Memory resources, failing board.\n");
218+ rc = -ENOMEM;
219+ goto out_kfree_brd;
220+ }
221+
222+ break;
223+ default:
224+ return -ENXIO;
156225 }
157226
158− rc = request_irq(brd->irq, brd->bd_ops->intr,
159− IRQF_SHARED, "JSM", brd);
227+ rc = request_irq(brd->irq, brd->bd_ops->intr, IRQF_SHARED, "JSM", brd);
160228 if (rc) {
161− printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
229+ dev_warn(&pdev->dev, "Failed to hook IRQ %d\n", brd->irq);
162230 goto out_iounmap;
163231 }
164232
@@ -178,7 +246,7 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent) · 13 unmodified lines
178246 }
179247
180248 /* Log the information about the board */
181− dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
249+ dev_info(&pdev->dev, "board %d: Digi Classic/Neo (rev %d), irq %d\n",
182250 adapter_count, brd->rev, brd->irq);
183251
184252 pci_set_drvdata(pdev, brd);
@@ -205,6 +273,18 @@ static void jsm_remove_one(struct pci_dev *pdev) · 20 unmodified lines
205273 struct jsm_board *brd = pci_get_drvdata(pdev);
206274 int i = 0;
207275
276+ switch (pdev->device) {
277+ case PCI_DEVICE_ID_CLASSIC_4:
278+ case PCI_DEVICE_ID_CLASSIC_4_422:
279+ case PCI_DEVICE_ID_CLASSIC_8:
280+ case PCI_DEVICE_ID_CLASSIC_8_422:
281+ /* Tell card not to interrupt anymore. */
282+ outb(0x0, brd->iobase + 0x4c);
283+ break;
284+ default:
285+ break;
286+ }
287+
208288 jsm_remove_uart_port(brd);
209289
210290 free_irq(brd->irq, brd);
@@ -239,6 +319,10 @@ static struct pci_device_id jsm_pci_tbl[] = { · 28 unmodified lines
239319 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4), 0, 0, 11 },
240320 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4RJ45), 0, 0, 12 },
241321 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_8RJ45), 0, 0, 13 },
322+ { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_CLASSIC_4), 0, 0, 14 },
323+ { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_CLASSIC_4_422), 0, 0, 15 },
324+ { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_CLASSIC_8), 0, 0, 16 },
325+ { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_CLASSIC_8_422), 0, 0, 17 },
242326 { 0, }
243327 };
244328 MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
drivers/tty/serial/jsm/jsm_neo.c+14−22
@@ -13,11 +13,6 @@ · 12 unmodified lines
1313 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1414 * PURPOSE. See the GNU General Public License for more details.
1515 *
16− * You should have received a copy of the GNU General Public License
17− * along with this program; if not, write to the Free Software
18− * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
19− * MA 02111-1307, USA.
20− *
2116 * Contact Information:
2217 * Scott H Kilau <Scott_Kilau@digi.com>
2318 * Wendy Xiong <wendyx@us.ibm.com>
@@ -649,7 +644,7 @@ static void neo_flush_uart_write(struct jsm_channel *ch) · 625 unmodified lines
649644
650645 /* Check to see if the UART feels it completely flushed the FIFO. */
651646 tmp = readb(&ch->ch_neo_uart->isr_fcr);
652− if (tmp & 4) {
647+ if (tmp & UART_FCR_CLEAR_XMIT) {
653648 jsm_dbg(IOCTL, &ch->ch_bd->pci_dev,
654649 "Still flushing TX UART... i: %d\n", i);
655650 udelay(10);
@@ -694,7 +689,7 @@ static void neo_flush_uart_read(struct jsm_channel *ch) · 38 unmodified lines
694689 /*
695690 * No locks are assumed to be held when calling this function.
696691 */
697−static void neo_clear_break(struct jsm_channel *ch, int force)
692+static void neo_clear_break(struct jsm_channel *ch)
698693 {
699694 unsigned long lock_flags;
700695
@@ -1024,27 +1019,24 @@ static void neo_param(struct jsm_channel *ch) · 323 unmodified lines
10241019 lcr |= UART_LCR_STOP;
10251020
10261021 switch (ch->ch_c_cflag & CSIZE) {
1027− case CS5:
1028− lcr |= UART_LCR_WLEN5;
1029− break;
1030− case CS6:
1031− lcr |= UART_LCR_WLEN6;
1032− break;
1033− case CS7:
1034− lcr |= UART_LCR_WLEN7;
1035− break;
1036− case CS8:
1037− default:
1038− lcr |= UART_LCR_WLEN8;
1022+ case CS5:
1023+ lcr |= UART_LCR_WLEN5;
10391024 break;
1025+ case CS6:
1026+ lcr |= UART_LCR_WLEN6;
1027+ break;
1028+ case CS7:
1029+ lcr |= UART_LCR_WLEN7;
1030+ break;
1031+ case CS8:
1032+ default:
1033+ lcr |= UART_LCR_WLEN8;
1034+ break;
10401035 }
10411036
10421037 ier = readb(&ch->ch_neo_uart->ier);
10431038 uart_lcr = readb(&ch->ch_neo_uart->lcr);
10441039
1045− if (baud == 0)
1046− baud = 9600;
1047−
10481040 quot = ch->ch_bd->bd_dividend / baud;
10491041
10501042 if (quot != 0) {
drivers/tty/serial/jsm/jsm_tty.c+23−16
@@ -13,11 +13,6 @@ · 12 unmodified lines
1313 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1414 * PURPOSE. See the GNU General Public License for more details.
1515 *
16− * You should have received a copy of the GNU General Public License
17− * along with this program; if not, write to the Free Software
18− * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
19− * MA 02111-1307, USA.
20− *
2116 * Contact Information:
2217 * Scott H Kilau <Scott_Kilau@digi.com>
2318 * Ananda Venkatarman <mansarov@us.ibm.com>
@@ -77,7 +72,8 @@ static unsigned int jsm_tty_tx_empty(struct uart_port *port) · 53 unmodified lines
7772 static unsigned int jsm_tty_get_mctrl(struct uart_port *port)
7873 {
7974 int result;
80− struct jsm_channel *channel = (struct jsm_channel *)port;
75+ struct jsm_channel *channel =
76+ container_of(port, struct jsm_channel, uart_port);
8177
8278 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n");
8379
@@ -98,7 +94,8 @@ static unsigned int jsm_tty_get_mctrl(struct uart_port *port) · 14 unmodified lines
9894 */
9995 static void jsm_tty_set_mctrl(struct uart_port *port, unsigned int mctrl)
10096 {
101− struct jsm_channel *channel = (struct jsm_channel *)port;
97+ struct jsm_channel *channel =
98+ container_of(port, struct jsm_channel, uart_port);
10299
103100 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n");
104101
@@ -133,7 +130,8 @@ static void jsm_tty_write(struct uart_port *port) · 28 unmodified lines
133130
134131 static void jsm_tty_start_tx(struct uart_port *port)
135132 {
136− struct jsm_channel *channel = (struct jsm_channel *)port;
133+ struct jsm_channel *channel =
134+ container_of(port, struct jsm_channel, uart_port);
137135
138136 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n");
139137
@@ -145,7 +143,8 @@ static void jsm_tty_start_tx(struct uart_port *port) · 5 unmodified lines
145143
146144 static void jsm_tty_stop_tx(struct uart_port *port)
147145 {
148− struct jsm_channel *channel = (struct jsm_channel *)port;
146+ struct jsm_channel *channel =
147+ container_of(port, struct jsm_channel, uart_port);
149148
150149 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n");
151150
@@ -157,7 +156,8 @@ static void jsm_tty_stop_tx(struct uart_port *port) · 5 unmodified lines
157156 static void jsm_tty_send_xchar(struct uart_port *port, char ch)
158157 {
159158 unsigned long lock_flags;
160− struct jsm_channel *channel = (struct jsm_channel *)port;
159+ struct jsm_channel *channel =
160+ container_of(port, struct jsm_channel, uart_port);
161161 struct ktermios *termios;
162162
163163 spin_lock_irqsave(&port->lock, lock_flags);
@@ -172,7 +172,8 @@ static void jsm_tty_send_xchar(struct uart_port *port, char ch) · 8 unmodified lines
172172
173173 static void jsm_tty_stop_rx(struct uart_port *port)
174174 {
175− struct jsm_channel *channel = (struct jsm_channel *)port;
175+ struct jsm_channel *channel =
176+ container_of(port, struct jsm_channel, uart_port);
176177
177178 channel->ch_bd->bd_ops->disable_receiver(channel);
178179 }
@@ -180,13 +181,14 @@ static void jsm_tty_stop_rx(struct uart_port *port) · 1 unmodified line
180181 static void jsm_tty_break(struct uart_port *port, int break_state)
181182 {
182183 unsigned long lock_flags;
183− struct jsm_channel *channel = (struct jsm_channel *)port;
184+ struct jsm_channel *channel =
185+ container_of(port, struct jsm_channel, uart_port);
184186
185187 spin_lock_irqsave(&port->lock, lock_flags);
186188 if (break_state == -1)
187189 channel->ch_bd->bd_ops->send_break(channel);
188190 else
189− channel->ch_bd->bd_ops->clear_break(channel, 0);
191+ channel->ch_bd->bd_ops->clear_break(channel);
190192
191193 spin_unlock_irqrestore(&port->lock, lock_flags);
192194 }
@@ -194,7 +196,8 @@ static void jsm_tty_break(struct uart_port *port, int break_state) · 1 unmodified line
194196 static int jsm_tty_open(struct uart_port *port)
195197 {
196198 struct jsm_board *brd;
197− struct jsm_channel *channel = (struct jsm_channel *)port;
199+ struct jsm_channel *channel =
200+ container_of(port, struct jsm_channel, uart_port);
198201 struct ktermios *termios;
199202
200203 /* Get board pointer from our array of majors we have allocated */
@@ -273,7 +276,8 @@ static void jsm_tty_close(struct uart_port *port) · 72 unmodified lines
273276 {
274277 struct jsm_board *bd;
275278 struct ktermios *ts;
276− struct jsm_channel *channel = (struct jsm_channel *)port;
279+ struct jsm_channel *channel =
280+ container_of(port, struct jsm_channel, uart_port);
277281
278282 jsm_dbg(CLOSE, &channel->ch_bd->pci_dev, "start\n");
279283
@@ -307,7 +311,8 @@ static void jsm_tty_set_termios(struct uart_port *port, · 27 unmodified lines
307311 struct ktermios *old_termios)
308312 {
309313 unsigned long lock_flags;
310− struct jsm_channel *channel = (struct jsm_channel *)port;
314+ struct jsm_channel *channel =
315+ container_of(port, struct jsm_channel, uart_port);
311316
312317 spin_lock_irqsave(&port->lock, lock_flags);
313318 channel->ch_c_cflag = termios->c_cflag;
@@ -415,6 +420,8 @@ int jsm_tty_init(struct jsm_board *brd) · 101 unmodified lines
415420
416421 if (brd->bd_uart_offset == 0x200)
417422 ch->ch_neo_uart = vaddr + (brd->bd_uart_offset * i);
423+ else
424+ ch->ch_cls_uart = vaddr + (brd->bd_uart_offset * i);
418425
419426 ch->ch_bd = brd;
420427 ch->ch_portnum = i;
drivers/tty/serial/lantiq.c+3−1
@@ -497,8 +497,10 @@ lqasc_type(struct uart_port *port) · 496 unmodified lines
497497 static void
498498 lqasc_release_port(struct uart_port *port)
499499 {
500+ struct platform_device *pdev = to_platform_device(port->dev);
501+
500502 if (port->flags & UPF_IOREMAP) {
501− iounmap(port->membase);
503+ devm_iounmap(&pdev->dev, port->membase);
502504 port->membase = NULL;
503505 }
504506 }
drivers/tty/serial/m32r_sio.c+28−14
@@ -249,7 +249,8 @@ static void serial_out(struct uart_sio_port *up, int offset, int value) · 248 unmodified lines
249249
250250 static void m32r_sio_stop_tx(struct uart_port *port)
251251 {
252− struct uart_sio_port *up = (struct uart_sio_port *)port;
252+ struct uart_sio_port *up =
253+ container_of(port, struct uart_sio_port, port);
253254
254255 if (up->ier & UART_IER_THRI) {
255256 up->ier &= ~UART_IER_THRI;
@@ -260,7 +261,8 @@ static void m32r_sio_stop_tx(struct uart_port *port) · 4 unmodified lines
260261 static void m32r_sio_start_tx(struct uart_port *port)
261262 {
262263 #ifdef CONFIG_SERIAL_M32R_PLDSIO
263− struct uart_sio_port *up = (struct uart_sio_port *)port;
264+ struct uart_sio_port *up =
265+ container_of(port, struct uart_sio_port, port);
264266 struct circ_buf *xmit = &up->port.state->xmit;
265267
266268 if (!(up->ier & UART_IER_THRI)) {
@@ -274,7 +276,8 @@ static void m32r_sio_start_tx(struct uart_port *port) · 7 unmodified lines
274276 }
275277 while((serial_in(up, UART_LSR) & UART_EMPTY) != UART_EMPTY);
276278 #else
277− struct uart_sio_port *up = (struct uart_sio_port *)port;
279+ struct uart_sio_port *up =
280+ container_of(port, struct uart_sio_port, port);
278281
279282 if (!(up->ier & UART_IER_THRI)) {
280283 up->ier |= UART_IER_THRI;
@@ -285,7 +288,8 @@ static void m32r_sio_start_tx(struct uart_port *port) · 4 unmodified lines
285288
286289 static void m32r_sio_stop_rx(struct uart_port *port)
287290 {
288− struct uart_sio_port *up = (struct uart_sio_port *)port;
291+ struct uart_sio_port *up =
292+ container_of(port, struct uart_sio_port, port);
289293
290294 up->ier &= ~UART_IER_RLSI;
291295 up->port.read_status_mask &= ~UART_LSR_DR;
@@ -294,7 +298,8 @@ static void m32r_sio_stop_rx(struct uart_port *port) · 2 unmodified lines
294298
295299 static void m32r_sio_enable_ms(struct uart_port *port)
296300 {
297− struct uart_sio_port *up = (struct uart_sio_port *)port;
301+ struct uart_sio_port *up =
302+ container_of(port, struct uart_sio_port, port);
298303
299304 up->ier |= UART_IER_MSI;
300305 serial_out(up, UART_IER, up->ier);
@@ -581,7 +586,8 @@ static void m32r_sio_timeout(unsigned long data) · 280 unmodified lines
581586
582587 static unsigned int m32r_sio_tx_empty(struct uart_port *port)
583588 {
584− struct uart_sio_port *up = (struct uart_sio_port *)port;
589+ struct uart_sio_port *up =
590+ container_of(port, struct uart_sio_port, port);
585591 unsigned long flags;
586592 unsigned int ret;
587593
@@ -609,7 +615,8 @@ static void m32r_sio_break_ctl(struct uart_port *port, int break_state) · 21 unmodified lines
609615
610616 static int m32r_sio_startup(struct uart_port *port)
611617 {
612− struct uart_sio_port *up = (struct uart_sio_port *)port;
618+ struct uart_sio_port *up =
619+ container_of(port, struct uart_sio_port, port);
613620 int retval;
614621
615622 sio_init();
@@ -652,7 +659,8 @@ static int m32r_sio_startup(struct uart_port *port) · 36 unmodified lines
652659
653660 static void m32r_sio_shutdown(struct uart_port *port)
654661 {
655− struct uart_sio_port *up = (struct uart_sio_port *)port;
662+ struct uart_sio_port *up =
663+ container_of(port, struct uart_sio_port, port);
656664
657665 /*
658666 * Disable interrupts from this port
@@ -681,7 +689,8 @@ static unsigned int m32r_sio_get_divisor(struct uart_port *port, · 22 unmodified lines
681689 static void m32r_sio_set_termios(struct uart_port *port,
682690 struct ktermios *termios, struct ktermios *old)
683691 {
684− struct uart_sio_port *up = (struct uart_sio_port *)port;
692+ struct uart_sio_port *up =
693+ container_of(port, struct uart_sio_port, port);
685694 unsigned char cval = 0;
686695 unsigned long flags;
687696 unsigned int baud, quot;
@@ -780,7 +789,8 @@ static void m32r_sio_set_termios(struct uart_port *port, · 92 unmodified lines
780789 static void m32r_sio_pm(struct uart_port *port, unsigned int state,
781790 unsigned int oldstate)
782791 {
783− struct uart_sio_port *up = (struct uart_sio_port *)port;
792+ struct uart_sio_port *up =
793+ container_of(port, struct uart_sio_port, port);
784794
785795 if (up->pm)
786796 up->pm(port, state, oldstate);
@@ -825,7 +835,8 @@ m32r_sio_request_std_resource(struct uart_sio_port *up, struct resource **res) · 38 unmodified lines
825835
826836 static void m32r_sio_release_port(struct uart_port *port)
827837 {
828− struct uart_sio_port *up = (struct uart_sio_port *)port;
838+ struct uart_sio_port *up =
839+ container_of(port, struct uart_sio_port, port);
829840 unsigned long start, offset = 0, size = 0;
830841
831842 size <<= up->port.regshift;
@@ -862,7 +873,8 @@ static void m32r_sio_release_port(struct uart_port *port) · 30 unmodified lines
862873
863874 static int m32r_sio_request_port(struct uart_port *port)
864875 {
865− struct uart_sio_port *up = (struct uart_sio_port *)port;
876+ struct uart_sio_port *up =
877+ container_of(port, struct uart_sio_port, port);
866878 struct resource *res = NULL;
867879 int ret = 0;
868880
@@ -889,7 +901,8 @@ static int m32r_sio_request_port(struct uart_port *port) · 20 unmodified lines
889901
890902 static void m32r_sio_config_port(struct uart_port *port, int unused)
891903 {
892− struct uart_sio_port *up = (struct uart_sio_port *)port;
904+ struct uart_sio_port *up =
905+ container_of(port, struct uart_sio_port, port);
893906 unsigned long flags;
894907
895908 spin_lock_irqsave(&up->port.lock, flags);
@@ -1000,7 +1013,8 @@ static inline void wait_for_xmitr(struct uart_sio_port *up) · 104 unmodified lines
10001013
10011014 static void m32r_sio_console_putchar(struct uart_port *port, int ch)
10021015 {
1003− struct uart_sio_port *up = (struct uart_sio_port *)port;
1016+ struct uart_sio_port *up =
1017+ container_of(port, struct uart_sio_port, port);
10041018
10051019 wait_for_xmitr(up);
10061020 sio_out(up, SIOTXB, ch);
drivers/tty/serial/max310x.c+31−46
@@ -346,10 +346,13 @@ static int max3109_detect(struct device *dev) · 345 unmodified lines
346346 unsigned int val = 0;
347347 int ret;
348348
349− ret = regmap_read(s->regmap, MAX310X_REVID_REG, &val);
349+ ret = regmap_write(s->regmap, MAX310X_GLOBALCMD_REG,
350+ MAX310X_EXTREG_ENBL);
350351 if (ret)
351352 return ret;
352353
354+ regmap_read(s->regmap, MAX310X_REVID_EXTREG, &val);
355+ regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, MAX310X_EXTREG_DSBL);
353356 if (((val & MAX310x_REV_MASK) != MAX3109_REV_ID)) {
354357 dev_err(dev,
355358 "%s ID 0x%02x does not match\n", s->devtype->name, val);
@@ -874,55 +877,37 @@ static void max310x_set_termios(struct uart_port *port, · 518 unmodified lines
874877 uart_update_timeout(port, termios->c_cflag, baud);
875878 }
876879
877−static int max310x_ioctl(struct uart_port *port, unsigned int cmd,
878− unsigned long arg)
880+static int max310x_rs485_config(struct uart_port *port,
881+ struct serial_rs485 *rs485)
879882 {
880−#if defined(TIOCSRS485) && defined(TIOCGRS485)
881− struct serial_rs485 rs485;
882883 unsigned int val;
883884
884− switch (cmd) {
885− case TIOCSRS485:
886− if (copy_from_user(&rs485, (void __user *)arg, sizeof(rs485)))
887− return -EFAULT;
888− if (rs485.delay_rts_before_send > 0x0f ||
889− rs485.delay_rts_after_send > 0x0f)
890− return -ERANGE;
891− val = (rs485.delay_rts_before_send << 4) |
892− rs485.delay_rts_after_send;
893− max310x_port_write(port, MAX310X_HDPIXDELAY_REG, val);
894− if (rs485.flags & SER_RS485_ENABLED) {
895− max310x_port_update(port, MAX310X_MODE1_REG,
896− MAX310X_MODE1_TRNSCVCTRL_BIT,
897− MAX310X_MODE1_TRNSCVCTRL_BIT);
898− max310x_port_update(port, MAX310X_MODE2_REG,
899− MAX310X_MODE2_ECHOSUPR_BIT,
900− MAX310X_MODE2_ECHOSUPR_BIT);
901− } else {
902− max310x_port_update(port, MAX310X_MODE1_REG,
903− MAX310X_MODE1_TRNSCVCTRL_BIT, 0);
904− max310x_port_update(port, MAX310X_MODE2_REG,
905− MAX310X_MODE2_ECHOSUPR_BIT, 0);
906− }
907− return 0;
908− case TIOCGRS485:
909− memset(&rs485, 0, sizeof(rs485));
910− val = max310x_port_read(port, MAX310X_MODE1_REG);
911− rs485.flags = (val & MAX310X_MODE1_TRNSCVCTRL_BIT) ?
912− SER_RS485_ENABLED : 0;
913− rs485.flags |= SER_RS485_RTS_ON_SEND;
914− val = max310x_port_read(port, MAX310X_HDPIXDELAY_REG);
915− rs485.delay_rts_before_send = val >> 4;
916− rs485.delay_rts_after_send = val & 0x0f;
917− if (copy_to_user((void __user *)arg, &rs485, sizeof(rs485)))
918− return -EFAULT;
919− return 0;
920− default:
921− break;
885+ if (rs485->delay_rts_before_send > 0x0f ||
886+ rs485->delay_rts_after_send > 0x0f)
887+ return -ERANGE;
888+
889+ val = (rs485->delay_rts_before_send << 4) |
890+ rs485->delay_rts_after_send;
891+ max310x_port_write(port, MAX310X_HDPIXDELAY_REG, val);
892+ if (rs485->flags & SER_RS485_ENABLED) {
893+ max310x_port_update(port, MAX310X_MODE1_REG,
894+ MAX310X_MODE1_TRNSCVCTRL_BIT,
895+ MAX310X_MODE1_TRNSCVCTRL_BIT);
896+ max310x_port_update(port, MAX310X_MODE2_REG,
897+ MAX310X_MODE2_ECHOSUPR_BIT,
898+ MAX310X_MODE2_ECHOSUPR_BIT);
899+ } else {
900+ max310x_port_update(port, MAX310X_MODE1_REG,
901+ MAX310X_MODE1_TRNSCVCTRL_BIT, 0);
902+ max310x_port_update(port, MAX310X_MODE2_REG,
903+ MAX310X_MODE2_ECHOSUPR_BIT, 0);
922904 }
923−#endif
924905
925− return -ENOIOCTLCMD;
906+ rs485->flags &= SER_RS485_RTS_ON_SEND | SER_RS485_ENABLED;
907+ memset(rs485->padding, 0, sizeof(rs485->padding));
908+ port->rs485 = *rs485;
909+
910+ return 0;
926911 }
927912
928913 static int max310x_startup(struct uart_port *port)
@@ -1017,7 +1002,6 @@ static const struct uart_ops max310x_ops = { · 88 unmodified lines
10171002 .release_port = max310x_null_void,
10181003 .config_port = max310x_config_port,
10191004 .verify_port = max310x_verify_port,
1020− .ioctl = max310x_ioctl,
10211005 };
10221006
10231007 static int __maybe_unused max310x_suspend(struct device *dev)
@@ -1218,6 +1202,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, · 194 unmodified lines
12181202 s->p[i].port.iobase = i * 0x20;
12191203 s->p[i].port.membase = (void __iomem *)~0;
12201204 s->p[i].port.uartclk = uartclk;
1205+ s->p[i].port.rs485_config = max310x_rs485_config;
12211206 s->p[i].port.ops = &max310x_ops;
12221207 /* Disable all interrupts */
12231208 max310x_port_write(&s->p[i].port, MAX310X_IRQEN_REG, 0);
drivers/tty/serial/mcf.c+8−34
@@ -57,7 +57,6 @@ struct mcf_uart { · 56 unmodified lines
5757 struct uart_port port;
5858 unsigned int sigs; /* Local copy of line sigs */
5959 unsigned char imr; /* Local IMR mirror */
60− struct serial_rs485 rs485; /* RS485 settings */
6160 };
6261
6362 /****************************************************************************/
@@ -104,7 +103,7 @@ static void mcf_start_tx(struct uart_port *port) · 40 unmodified lines
104103 {
105104 struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
106105
107− if (pp->rs485.flags & SER_RS485_ENABLED) {
106+ if (port->rs485.flags & SER_RS485_ENABLED) {
108107 /* Enable Transmitter */
109108 writeb(MCFUART_UCR_TXENABLE, port->membase + MCFUART_UCR);
110109 /* Manually assert RTS */
@@ -258,12 +257,12 @@ static void mcf_set_termios(struct uart_port *port, struct ktermios *termios, · 147 unmodified lines
258257 mr2 |= MCFUART_MR2_TXCTS;
259258 }
260259
261− if (pp->rs485.flags & SER_RS485_ENABLED) {
260+ spin_lock_irqsave(&port->lock, flags);
261+ if (port->rs485.flags & SER_RS485_ENABLED) {
262262 dev_dbg(port->dev, "Setting UART to RS485\n");
263263 mr2 |= MCFUART_MR2_TXRTS;
264264 }
265265
266− spin_lock_irqsave(&port->lock, flags);
267266 uart_update_timeout(port, termios->c_cflag, baud);
268267 writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
269268 writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
@@ -360,7 +359,7 @@ static void mcf_tx_chars(struct mcf_uart *pp) · 90 unmodified lines
360359 pp->imr &= ~MCFUART_UIR_TXREADY;
361360 writeb(pp->imr, port->membase + MCFUART_UIMR);
362361 /* Disable TX to negate RTS automatically */
363− if (pp->rs485.flags & SER_RS485_ENABLED)
362+ if (port->rs485.flags & SER_RS485_ENABLED)
364363 writeb(MCFUART_UCR_TXDISABLE,
365364 port->membase + MCFUART_UCR);
366365 }
@@ -440,13 +439,11 @@ static int mcf_verify_port(struct uart_port *port, struct serial_struct *ser) · 73 unmodified lines
440439 /****************************************************************************/
441440
442441 /* Enable or disable the RS485 support */
443−static void mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
442+static int mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
444443 {
445444 struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
446− unsigned long flags;
447445 unsigned char mr1, mr2;
448446
449− spin_lock_irqsave(&port->lock, flags);
450447 /* Get mode registers */
451448 mr1 = readb(port->membase + MCFUART_UMR);
452449 mr2 = readb(port->membase + MCFUART_UMR);
@@ -460,32 +457,8 @@ static void mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485) · 7 unmodified lines
460457 }
461458 writeb(mr1, port->membase + MCFUART_UMR);
462459 writeb(mr2, port->membase + MCFUART_UMR);
463− pp->rs485 = *rs485;
464− spin_unlock_irqrestore(&port->lock, flags);
465−}
460+ port->rs485 = *rs485;
466461
467−static int mcf_ioctl(struct uart_port *port, unsigned int cmd,
468− unsigned long arg)
469−{
470− switch (cmd) {
471− case TIOCSRS485: {
472− struct serial_rs485 rs485;
473− if (copy_from_user(&rs485, (struct serial_rs485 *)arg,
474− sizeof(struct serial_rs485)))
475− return -EFAULT;
476− mcf_config_rs485(port, &rs485);
477− break;
478− }
479− case TIOCGRS485: {
480− struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
481− if (copy_to_user((struct serial_rs485 *)arg, &pp->rs485,
482− sizeof(struct serial_rs485)))
483− return -EFAULT;
484− break;
485− }
486− default:
487− return -ENOIOCTLCMD;
488− }
489462 return 0;
490463 }
491464
@@ -510,7 +483,6 @@ static const struct uart_ops mcf_uart_ops = { · 18 unmodified lines
510483 .release_port = mcf_release_port,
511484 .config_port = mcf_config_port,
512485 .verify_port = mcf_verify_port,
513− .ioctl = mcf_ioctl,
514486 };
515487
516488 static struct mcf_uart mcf_ports[4];
@@ -538,6 +510,7 @@ int __init early_mcf_setup(struct mcf_platform_uart *platp) · 21 unmodified lines
538510 port->irq = platp[i].irq;
539511 port->uartclk = MCF_BUSCLK;
540512 port->flags = UPF_BOOT_AUTOCONF;
513+ port->rs485_config = mcf_config_rs485;
541514 port->ops = &mcf_uart_ops;
542515 }
543516
@@ -663,6 +636,7 @@ static int mcf_probe(struct platform_device *pdev) · 119 unmodified lines
663636 port->uartclk = MCF_BUSCLK;
664637 port->ops = &mcf_uart_ops;
665638 port->flags = UPF_BOOT_AUTOCONF;
639+ port->rs485_config = mcf_config_rs485;
666640
667641 uart_add_one_port(&mcf_driver, port);
668642 }
drivers/tty/serial/men_z135_uart.c+1−0
@@ -809,6 +809,7 @@ static void men_z135_remove(struct mcb_device *mdev) · 808 unmodified lines
809809
810810 static const struct mcb_device_id men_z135_ids[] = {
811811 { .device = 0x87 },
812+ { }
812813 };
813814 MODULE_DEVICE_TABLE(mcb, men_z135_ids);
814815
drivers/tty/serial/mfd.c+1−1
@@ -1371,7 +1371,7 @@ static void hsu_global_init(void) · 1370 unmodified lines
13711371 hsu->iolen = 0x1000;
13721372
13731373 if (!(request_mem_region(hsu->paddr, hsu->iolen, "HSU global")))
1374− pr_warning("HSU: error in request mem region\n");
1374+ pr_warn("HSU: error in request mem region\n");
13751375
13761376 hsu->reg = ioremap_nocache((unsigned long)hsu->paddr, hsu->iolen);
13771377 if (!hsu->reg) {
drivers/tty/serial/mpsc.c+26−13
@@ -1246,7 +1246,8 @@ static irqreturn_t mpsc_sdma_intr(int irq, void *dev_id) · 1245 unmodified lines
12461246 */
12471247 static uint mpsc_tx_empty(struct uart_port *port)
12481248 {
1249− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1249+ struct mpsc_port_info *pi =
1250+ container_of(port, struct mpsc_port_info, port);
12501251 ulong iflags;
12511252 uint rc;
12521253
@@ -1264,7 +1265,8 @@ static void mpsc_set_mctrl(struct uart_port *port, uint mctrl) · 11 unmodified lines
12641265
12651266 static uint mpsc_get_mctrl(struct uart_port *port)
12661267 {
1267− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1268+ struct mpsc_port_info *pi =
1269+ container_of(port, struct mpsc_port_info, port);
12681270 u32 mflags, status;
12691271
12701272 status = (pi->mirror_regs) ? pi->MPSC_CHR_10_m
@@ -1281,7 +1283,8 @@ static uint mpsc_get_mctrl(struct uart_port *port) · 10 unmodified lines
12811283
12821284 static void mpsc_stop_tx(struct uart_port *port)
12831285 {
1284− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1286+ struct mpsc_port_info *pi =
1287+ container_of(port, struct mpsc_port_info, port);
12851288
12861289 pr_debug("mpsc_stop_tx[%d]\n", port->line);
12871290
@@ -1290,7 +1293,8 @@ static void mpsc_stop_tx(struct uart_port *port) · 2 unmodified lines
12901293
12911294 static void mpsc_start_tx(struct uart_port *port)
12921295 {
1293− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1296+ struct mpsc_port_info *pi =
1297+ container_of(port, struct mpsc_port_info, port);
12941298 unsigned long iflags;
12951299
12961300 spin_lock_irqsave(&pi->tx_lock, iflags);
@@ -1316,7 +1320,8 @@ static void mpsc_start_rx(struct mpsc_port_info *pi) · 19 unmodified lines
13161320
13171321 static void mpsc_stop_rx(struct uart_port *port)
13181322 {
1319− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1323+ struct mpsc_port_info *pi =
1324+ container_of(port, struct mpsc_port_info, port);
13201325
13211326 pr_debug("mpsc_stop_rx[%d]: Stopping...\n", port->line);
13221327
@@ -1338,7 +1343,8 @@ static void mpsc_stop_rx(struct uart_port *port) · 15 unmodified lines
13381343
13391344 static void mpsc_break_ctl(struct uart_port *port, int ctl)
13401345 {
1341− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1346+ struct mpsc_port_info *pi =
1347+ container_of(port, struct mpsc_port_info, port);
13421348 ulong flags;
13431349 u32 v;
13441350
@@ -1353,7 +1359,8 @@ static void mpsc_break_ctl(struct uart_port *port, int ctl) · 8 unmodified lines
13531359
13541360 static int mpsc_startup(struct uart_port *port)
13551361 {
1356− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1362+ struct mpsc_port_info *pi =
1363+ container_of(port, struct mpsc_port_info, port);
13571364 u32 flag = 0;
13581365 int rc;
13591366
@@ -1383,7 +1390,8 @@ static int mpsc_startup(struct uart_port *port) · 23 unmodified lines
13831390
13841391 static void mpsc_shutdown(struct uart_port *port)
13851392 {
1386− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1393+ struct mpsc_port_info *pi =
1394+ container_of(port, struct mpsc_port_info, port);
13871395
13881396 pr_debug("mpsc_shutdown[%d]: Shutting down MPSC\n", port->line);
13891397
@@ -1394,7 +1402,8 @@ static void mpsc_shutdown(struct uart_port *port) · 4 unmodified lines
13941402 static void mpsc_set_termios(struct uart_port *port, struct ktermios *termios,
13951403 struct ktermios *old)
13961404 {
1397− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1405+ struct mpsc_port_info *pi =
1406+ container_of(port, struct mpsc_port_info, port);
13981407 u32 baud;
13991408 ulong flags;
14001409 u32 chr_bits, stop_bits, par;
@@ -1498,7 +1507,8 @@ static int mpsc_request_port(struct uart_port *port) · 97 unmodified lines
14981507
14991508 static void mpsc_release_port(struct uart_port *port)
15001509 {
1501− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1510+ struct mpsc_port_info *pi =
1511+ container_of(port, struct mpsc_port_info, port);
15021512
15031513 if (pi->ready) {
15041514 mpsc_uninit_rings(pi);
@@ -1513,7 +1523,8 @@ static void mpsc_config_port(struct uart_port *port, int flags) · 8 unmodified lines
15131523
15141524 static int mpsc_verify_port(struct uart_port *port, struct serial_struct *ser)
15151525 {
1516− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1526+ struct mpsc_port_info *pi =
1527+ container_of(port, struct mpsc_port_info, port);
15171528 int rc = 0;
15181529
15191530 pr_debug("mpsc_verify_port[%d]: Verifying port data\n", pi->port.line);
@@ -1548,7 +1559,8 @@ static void mpsc_put_poll_char(struct uart_port *port, · 28 unmodified lines
15481559
15491560 static int mpsc_get_poll_char(struct uart_port *port)
15501561 {
1551− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1562+ struct mpsc_port_info *pi =
1563+ container_of(port, struct mpsc_port_info, port);
15521564 struct mpsc_rx_desc *rxre;
15531565 u32 cmdstat, bytes_in, i;
15541566 u8 *bp;
@@ -1648,7 +1660,8 @@ static int mpsc_get_poll_char(struct uart_port *port) · 93 unmodified lines
16481660 static void mpsc_put_poll_char(struct uart_port *port,
16491661 unsigned char c)
16501662 {
1651− struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1663+ struct mpsc_port_info *pi =
1664+ container_of(port, struct mpsc_port_info, port);
16521665 u32 data;
16531666
16541667 data = readl(pi->mpsc_base + MPSC_MPCR);
drivers/tty/serial/mrst_max3110.c+12−15
@@ -27,6 +27,8 @@ · 26 unmodified lines
2727 * interrupt for a low speed UART device
2828 */
2929
30+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31+
3032 #ifdef CONFIG_MAGIC_SYSRQ
3133 #define SUPPORT_SYSRQ
3234 #endif
@@ -47,8 +49,6 @@ · 14 unmodified lines
4749
4850 #include "mrst_max3110.h"
4951
50−#define PR_FMT "mrst_max3110: "
51−
5252 #define UART_TX_NEEDED 1
5353 #define CON_TX_NEEDED 2
5454 #define BIT_IRQ_PENDING 3
@@ -127,8 +127,8 @@ static int max3110_out(struct uart_max3110 *max, const u16 out) · 72 unmodified lines
127127 *obuf = out;
128128 ret = max3110_write_then_read(max, obuf, ibuf, 2, 1);
129129 if (ret) {
130− pr_warning(PR_FMT "%s(): get err msg %d when sending 0x%x\n",
131− __func__, ret, out);
130+ pr_warn("%s: get err msg %d when sending 0x%x\n",
131+ __func__, ret, out);
132132 goto exit;
133133 }
134134
@@ -153,10 +153,8 @@ static int max3110_read_multi(struct uart_max3110 *max) · 18 unmodified lines
153153
154154 blen = M3110_RX_FIFO_DEPTH * sizeof(u16);
155155 buf = kzalloc(blen * 2, GFP_KERNEL | GFP_DMA);
156− if (!buf) {
157− pr_warning(PR_FMT "%s(): fail to alloc dma buffer\n", __func__);
156+ if (!buf)
158157 return 0;
159− }
160158
161159 /* tx/rx always have the same length */
162160 obuf = buf;
@@ -212,13 +210,13 @@ serial_m3110_con_setup(struct console *co, char *options) · 49 unmodified lines
212210 int parity = 'n';
213211 int flow = 'n';
214212
215− pr_info(PR_FMT "setting up console\n");
213+ pr_info("setting up console\n");
216214
217215 if (co->index == -1)
218216 co->index = 0;
219217
220218 if (!max) {
221− pr_err(PR_FMT "pmax is NULL, return");
219+ pr_err("pmax is NULL, return\n");
222220 return -ENODEV;
223221 }
224222
@@ -296,8 +294,7 @@ static void send_circ_buf(struct uart_max3110 *max, · 71 unmodified lines
296294
297295 ret = max3110_write_then_read(max, obuf, ibuf, blen, 0);
298296 if (ret)
299− pr_warning(PR_FMT "%s(): get err msg %d\n",
300− __func__, ret);
297+ pr_warn("%s: get err msg %d\n", __func__, ret);
301298
302299 receive_chars(max, ibuf, len);
303300
@@ -411,7 +408,7 @@ static int max3110_main_thread(void *_max) · 107 unmodified lines
411408 int ret = 0;
412409 struct circ_buf *xmit = &max->con_xmit;
413410
414− pr_info(PR_FMT "start main thread\n");
411+ pr_info("start main thread\n");
415412
416413 do {
417414 wait_event_interruptible(*wq,
@@ -455,7 +452,7 @@ static int max3110_read_thread(void *_max) · 37 unmodified lines
455452 {
456453 struct uart_max3110 *max = _max;
457454
458− pr_info(PR_FMT "start read thread\n");
455+ pr_info("start read thread\n");
459456 do {
460457 /*
461458 * If can't acquire the mutex, it means the main thread
@@ -481,7 +478,7 @@ static int serial_m3110_startup(struct uart_port *port) · 19 unmodified lines
481478 int ret = 0;
482479
483480 if (port->line != 0) {
484− pr_err(PR_FMT "uart port startup failed\n");
481+ pr_err("uart port startup failed\n");
485482 return -1;
486483 }
487484
@@ -504,7 +501,7 @@ static int serial_m3110_startup(struct uart_port *port) · 16 unmodified lines
504501 if (IS_ERR(max->read_thread)) {
505502 ret = PTR_ERR(max->read_thread);
506503 max->read_thread = NULL;
507− pr_err(PR_FMT "Can't create read thread!\n");
504+ pr_err("Can't create read thread!\n");
508505 return ret;
509506 }
510507 }
drivers/tty/serial/msm_serial.c+58−53
@@ -54,6 +54,7 @@ struct msm_port { · 53 unmodified lines
5454 unsigned int imr;
5555 int is_uartdm;
5656 unsigned int old_snap_state;
57+ bool break_detected;
5758 };
5859
5960 static inline void wait_for_xmitr(struct uart_port *port)
@@ -126,23 +127,38 @@ static void handle_rx_dm(struct uart_port *port, unsigned int misr) · 66 unmodified lines
126127
127128 while (count > 0) {
128129 unsigned char buf[4];
130+ int sysrq, r_count, i;
129131
130132 sr = msm_read(port, UART_SR);
131133 if ((sr & UART_SR_RX_READY) == 0) {
132134 msm_port->old_snap_state -= count;
133135 break;
134136 }
137+
135138 ioread32_rep(port->membase + UARTDM_RF, buf, 1);
136− if (sr & UART_SR_RX_BREAK) {
137− port->icount.brk++;
138− if (uart_handle_break(port))
139− continue;
140− } else if (sr & UART_SR_PAR_FRAME_ERR)
141− port->icount.frame++;
139+ r_count = min_t(int, count, sizeof(buf));
142140
143− /* TODO: handle sysrq */
144− tty_insert_flip_string(tport, buf, min(count, 4));
145− count -= 4;
141+ for (i = 0; i < r_count; i++) {
142+ char flag = TTY_NORMAL;
143+
144+ if (msm_port->break_detected && buf[i] == 0) {
145+ port->icount.brk++;
146+ flag = TTY_BREAK;
147+ msm_port->break_detected = false;
148+ if (uart_handle_break(port))
149+ continue;
150+ }
151+
152+ if (!(port->read_status_mask & UART_SR_RX_BREAK))
153+ flag = TTY_NORMAL;
154+
155+ spin_unlock(&port->lock);
156+ sysrq = uart_handle_sysrq_char(port, buf[i]);
157+ spin_lock(&port->lock);
158+ if (!sysrq)
159+ tty_insert_flip_char(tport, buf[i], flag);
160+ }
161+ count -= r_count;
146162 }
147163
148164 spin_unlock(&port->lock);
@@ -174,6 +190,7 @@ static void handle_rx(struct uart_port *port) · 25 unmodified lines
174190 while ((sr = msm_read(port, UART_SR)) & UART_SR_RX_READY) {
175191 unsigned int c;
176192 char flag = TTY_NORMAL;
193+ int sysrq;
177194
178195 c = msm_read(port, UART_RF);
179196
@@ -195,7 +212,10 @@ static void handle_rx(struct uart_port *port) · 15 unmodified lines
195212 else if (sr & UART_SR_PAR_FRAME_ERR)
196213 flag = TTY_FRAME;
197214
198− if (!uart_handle_sysrq_char(port, c))
215+ spin_unlock(&port->lock);
216+ sysrq = uart_handle_sysrq_char(port, c);
217+ spin_lock(&port->lock);
218+ if (!sysrq)
199219 tty_insert_flip_char(tport, c, flag);
200220 }
201221
@@ -287,6 +307,11 @@ static irqreturn_t msm_irq(int irq, void *dev_id) · 85 unmodified lines
287307 misr = msm_read(port, UART_MISR);
288308 msm_write(port, 0, UART_IMR); /* disable interrupt */
289309
310+ if (misr & UART_IMR_RXBREAK_START) {
311+ msm_port->break_detected = true;
312+ msm_write(port, UART_CR_CMD_RESET_RXBREAK_START, UART_CR);
313+ }
314+
290315 if (misr & (UART_IMR_RXLEV | UART_IMR_RXSTALE)) {
291316 if (msm_port->is_uartdm)
292317 handle_rx_dm(port, misr);
@@ -402,9 +427,6 @@ static int msm_set_baud_rate(struct uart_port *port, unsigned int baud) · 109 unmodified lines
402427
403428 entry = msm_find_best_baud(port, baud);
404429
405− if (msm_port->is_uartdm)
406− msm_write(port, UART_CR_CMD_RESET_RX, UART_CR);
407−
408430 msm_write(port, entry->code, UART_CSR);
409431
410432 /* RX stale watermark */
@@ -421,6 +443,18 @@ static int msm_set_baud_rate(struct uart_port *port, unsigned int baud) · 10 unmodified lines
421443 /* set TX watermark */
422444 msm_write(port, 10, UART_TFWR);
423445
446+ msm_write(port, UART_CR_CMD_PROTECTION_EN, UART_CR);
447+ msm_reset(port);
448+
449+ /* Enable RX and TX */
450+ msm_write(port, UART_CR_TX_ENABLE | UART_CR_RX_ENABLE, UART_CR);
451+
452+ /* turn on RX and CTS interrupts */
453+ msm_port->imr = UART_IMR_RXLEV | UART_IMR_RXSTALE |
454+ UART_IMR_CURRENT_CTS | UART_IMR_RXBREAK_START;
455+
456+ msm_write(port, msm_port->imr, UART_IMR);
457+
424458 if (msm_port->is_uartdm) {
425459 msm_write(port, UART_CR_CMD_RESET_STALE_INT, UART_CR);
426460 msm_write(port, 0xFFFFFF, UARTDM_DMRX);
@@ -467,40 +501,6 @@ static int msm_startup(struct uart_port *port) · 40 unmodified lines
467501 data |= UART_MR1_AUTO_RFR_LEVEL1 & (rfr_level << 2);
468502 data |= UART_MR1_AUTO_RFR_LEVEL0 & rfr_level;
469503 msm_write(port, data, UART_MR1);
470−
471− /* make sure that RXSTALE count is non-zero */
472− data = msm_read(port, UART_IPR);
473− if (unlikely(!data)) {
474− data |= UART_IPR_RXSTALE_LAST;
475− data |= UART_IPR_STALE_LSB;
476− msm_write(port, data, UART_IPR);
477− }
478−
479− data = 0;
480− if (!port->cons || (port->cons && !(port->cons->flags & CON_ENABLED))) {
481− msm_write(port, UART_CR_CMD_PROTECTION_EN, UART_CR);
482− msm_reset(port);
483− data = UART_CR_TX_ENABLE;
484− }
485−
486− data |= UART_CR_RX_ENABLE;
487− msm_write(port, data, UART_CR); /* enable TX & RX */
488−
489− /* Make sure IPR is not 0 to start with*/
490− if (msm_port->is_uartdm)
491− msm_write(port, UART_IPR_STALE_LSB, UART_IPR);
492−
493− /* turn on RX and CTS interrupts */
494− msm_port->imr = UART_IMR_RXLEV | UART_IMR_RXSTALE |
495− UART_IMR_CURRENT_CTS;
496−
497− if (msm_port->is_uartdm) {
498− msm_write(port, 0xFFFFFF, UARTDM_DMRX);
499− msm_write(port, UART_CR_CMD_RESET_STALE_INT, UART_CR);
500− msm_write(port, UART_CR_CMD_STALE_EVENT_ENABLE, UART_CR);
501− }
502−
503− msm_write(port, msm_port->imr, UART_IMR);
504504 return 0;
505505 }
506506
@@ -1044,17 +1044,22 @@ static int msm_serial_probe(struct platform_device *pdev) · 537 unmodified lines
10441044 struct resource *resource;
10451045 struct uart_port *port;
10461046 const struct of_device_id *id;
1047− int irq;
1047+ int irq, line;
1048+
1049+ if (pdev->dev.of_node)
1050+ line = of_alias_get_id(pdev->dev.of_node, "serial");
1051+ else
1052+ line = pdev->id;
10481053
1049− if (pdev->id == -1)
1050− pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
1054+ if (line < 0)
1055+ line = atomic_inc_return(&msm_uart_next_id) - 1;
10511056
1052− if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
1057+ if (unlikely(line < 0 || line >= UART_NR))
10531058 return -ENXIO;
10541059
1055− dev_info(&pdev->dev, "msm_serial: detected port #%d\n", pdev->id);
1060+ dev_info(&pdev->dev, "msm_serial: detected port #%d\n", line);
10561061
1057− port = get_port_from_line(pdev->id);
1062+ port = get_port_from_line(line);
10581063 port->dev = &pdev->dev;
10591064 msm_port = UART_TO_MSM(port);
10601065
drivers/tty/serial/msm_serial.h+2−0
@@ -65,6 +65,7 @@ · 64 unmodified lines
6565 #define UART_CR_TX_ENABLE (1 << 2)
6666 #define UART_CR_RX_DISABLE (1 << 1)
6767 #define UART_CR_RX_ENABLE (1 << 0)
68+#define UART_CR_CMD_RESET_RXBREAK_START ((1 << 11) | (2 << 4))
6869
6970 #define UART_IMR 0x0014
7071 #define UART_IMR_TXLEV (1 << 0)
@@ -72,6 +73,7 @@ · 1 unmodified line
7273 #define UART_IMR_RXLEV (1 << 4)
7374 #define UART_IMR_DELTA_CTS (1 << 5)
7475 #define UART_IMR_CURRENT_CTS (1 << 6)
76+#define UART_IMR_RXBREAK_START (1 << 10)
7577
7678 #define UART_IPR_RXSTALE_LAST 0x20
7779 #define UART_IPR_STALE_LSB 0x1F
drivers/tty/serial/mxs-auart.c+233−17
@@ -14,6 +14,10 @@ · 13 unmodified lines
1414 * http://www.gnu.org/copyleft/gpl.html
1515 */
1616
17+#if defined(CONFIG_SERIAL_MXS_AUART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
18+#define SUPPORT_SYSRQ
19+#endif
20+
1721 #include <linux/kernel.h>
1822 #include <linux/errno.h>
1923 #include <linux/init.h>
@@ -38,6 +42,12 @@ · 18 unmodified lines
3842
3943 #include <asm/cacheflush.h>
4044
45+#include <linux/gpio.h>
46+#include <linux/gpio/consumer.h>
47+#include <linux/err.h>
48+#include <linux/irq.h>
49+#include "serial_mctrl_gpio.h"
50+
4151 #define MXS_AUART_PORTS 5
4252 #define MXS_AUART_FIFO_SIZE 16
4353
@@ -139,7 +149,7 @@ struct mxs_auart_port { · 95 unmodified lines
139149 #define MXS_AUART_DMA_RX_READY 3 /* bit 3 */
140150 #define MXS_AUART_RTSCTS 4 /* bit 4 */
141151 unsigned long flags;
142− unsigned int ctrl;
152+ unsigned int mctrl_prev;
143153 enum mxs_auart_type devtype;
144154
145155 unsigned int irq;
@@ -155,6 +165,10 @@ struct mxs_auart_port { · 9 unmodified lines
155165 struct scatterlist rx_sgl;
156166 struct dma_chan *rx_dma_chan;
157167 void *rx_dma_buf;
168+
169+ struct mctrl_gpios *gpios;
170+ int gpio_irq[UART_GPIO_MAX];
171+ bool ms_irq_enabled;
158172 };
159173
160174 static struct platform_device_id mxs_auart_devtype[] = {
@@ -414,25 +428,102 @@ static void mxs_auart_set_mctrl(struct uart_port *u, unsigned mctrl) · 253 unmodified lines
414428 ctrl |= AUART_CTRL2_RTS;
415429 }
416430
417− s->ctrl = mctrl;
418431 writel(ctrl, u->membase + AUART_CTRL2);
432+
433+ mctrl_gpio_set(s->gpios, mctrl);
434+}
435+
436+#define MCTRL_ANY_DELTA (TIOCM_RI | TIOCM_DSR | TIOCM_CD | TIOCM_CTS)
437+static u32 mxs_auart_modem_status(struct mxs_auart_port *s, u32 mctrl)
438+{
439+ u32 mctrl_diff;
440+
441+ mctrl_diff = mctrl ^ s->mctrl_prev;
442+ s->mctrl_prev = mctrl;
443+ if (mctrl_diff & MCTRL_ANY_DELTA && s->ms_irq_enabled &&
444+ s->port.state != NULL) {
445+ if (mctrl_diff & TIOCM_RI)
446+ s->port.icount.rng++;
447+ if (mctrl_diff & TIOCM_DSR)
448+ s->port.icount.dsr++;
449+ if (mctrl_diff & TIOCM_CD)
450+ uart_handle_dcd_change(&s->port, mctrl & TIOCM_CD);
451+ if (mctrl_diff & TIOCM_CTS)
452+ uart_handle_cts_change(&s->port, mctrl & TIOCM_CTS);
453+
454+ wake_up_interruptible(&s->port.state->port.delta_msr_wait);
455+ }
456+ return mctrl;
419457 }
420458
421459 static u32 mxs_auart_get_mctrl(struct uart_port *u)
422460 {
423461 struct mxs_auart_port *s = to_auart_port(u);
424462 u32 stat = readl(u->membase + AUART_STAT);
425− int ctrl2 = readl(u->membase + AUART_CTRL2);
426− u32 mctrl = s->ctrl;
463+ u32 mctrl = 0;
427464
428− mctrl &= ~TIOCM_CTS;
429465 if (stat & AUART_STAT_CTS)
430466 mctrl |= TIOCM_CTS;
431467
432− if (ctrl2 & AUART_CTRL2_RTS)
433− mctrl |= TIOCM_RTS;
468+ return mctrl_gpio_get(s->gpios, &mctrl);
469+}
470+
471+/*
472+ * Enable modem status interrupts
473+ */
474+static void mxs_auart_enable_ms(struct uart_port *port)
475+{
476+ struct mxs_auart_port *s = to_auart_port(port);
434477
435− return mctrl;
478+ /*
479+ * Interrupt should not be enabled twice
480+ */
481+ if (s->ms_irq_enabled)
482+ return;
483+
484+ s->ms_irq_enabled = true;
485+
486+ if (s->gpio_irq[UART_GPIO_CTS] >= 0)
487+ enable_irq(s->gpio_irq[UART_GPIO_CTS]);
488+ /* TODO: enable AUART_INTR_CTSMIEN otherwise */
489+
490+ if (s->gpio_irq[UART_GPIO_DSR] >= 0)
491+ enable_irq(s->gpio_irq[UART_GPIO_DSR]);
492+
493+ if (s->gpio_irq[UART_GPIO_RI] >= 0)
494+ enable_irq(s->gpio_irq[UART_GPIO_RI]);
495+
496+ if (s->gpio_irq[UART_GPIO_DCD] >= 0)
497+ enable_irq(s->gpio_irq[UART_GPIO_DCD]);
498+}
499+
500+/*
501+ * Disable modem status interrupts
502+ */
503+static void mxs_auart_disable_ms(struct uart_port *port)
504+{
505+ struct mxs_auart_port *s = to_auart_port(port);
506+
507+ /*
508+ * Interrupt should not be disabled twice
509+ */
510+ if (!s->ms_irq_enabled)
511+ return;
512+
513+ s->ms_irq_enabled = false;
514+
515+ if (s->gpio_irq[UART_GPIO_CTS] >= 0)
516+ disable_irq(s->gpio_irq[UART_GPIO_CTS]);
517+ /* TODO: disable AUART_INTR_CTSMIEN otherwise */
518+
519+ if (s->gpio_irq[UART_GPIO_DSR] >= 0)
520+ disable_irq(s->gpio_irq[UART_GPIO_DSR]);
521+
522+ if (s->gpio_irq[UART_GPIO_RI] >= 0)
523+ disable_irq(s->gpio_irq[UART_GPIO_RI]);
524+
525+ if (s->gpio_irq[UART_GPIO_DCD] >= 0)
526+ disable_irq(s->gpio_irq[UART_GPIO_DCD]);
436527 }
437528
438529 static int mxs_auart_dma_prep_rx(struct mxs_auart_port *s);
@@ -560,6 +651,10 @@ err_out: · 121 unmodified lines
560651
561652 }
562653
654+#define RTS_AT_AUART() IS_ERR_OR_NULL(mctrl_gpio_to_gpiod(s->gpios, \
655+ UART_GPIO_RTS))
656+#define CTS_AT_AUART() IS_ERR_OR_NULL(mctrl_gpio_to_gpiod(s->gpios, \
657+ UART_GPIO_CTS))
563658 static void mxs_auart_settermios(struct uart_port *u,
564659 struct ktermios *termios,
565660 struct ktermios *old)
@@ -636,6 +731,7 @@ static void mxs_auart_settermios(struct uart_port *u, · 70 unmodified lines
636731 ctrl |= AUART_LINECTRL_STP2;
637732
638733 /* figure out the hardware flow control settings */
734+ ctrl2 &= ~(AUART_CTRL2_CTSEN | AUART_CTRL2_RTSEN);
639735 if (cflag & CRTSCTS) {
640736 /*
641737 * The DMA has a bug(see errata:2836) in mx23.
@@ -650,9 +746,11 @@ static void mxs_auart_settermios(struct uart_port *u, · 8 unmodified lines
650746 ctrl2 |= AUART_CTRL2_TXDMAE | AUART_CTRL2_RXDMAE
651747 | AUART_CTRL2_DMAONERR;
652748 }
653− ctrl2 |= AUART_CTRL2_CTSEN | AUART_CTRL2_RTSEN;
654− } else {
655− ctrl2 &= ~(AUART_CTRL2_CTSEN | AUART_CTRL2_RTSEN);
749+ /* Even if RTS is GPIO line RTSEN can be enabled because
750+ * the pinctrl configuration decides about RTS pin function */
751+ ctrl2 |= AUART_CTRL2_RTSEN;
752+ if (CTS_AT_AUART())
753+ ctrl2 |= AUART_CTRL2_CTSEN;
656754 }
657755
658756 /* set baud rate */
@@ -678,12 +776,30 @@ static void mxs_auart_settermios(struct uart_port *u, · 19 unmodified lines
678776 dev_err(s->dev, "We can not start up the DMA.\n");
679777 }
680778 }
779+
780+ /* CTS flow-control and modem-status interrupts */
781+ if (UART_ENABLE_MS(u, termios->c_cflag))
782+ mxs_auart_enable_ms(u);
783+ else
784+ mxs_auart_disable_ms(u);
785+}
786+
787+static void mxs_auart_set_ldisc(struct uart_port *port,
788+ struct ktermios *termios)
789+{
790+ if (termios->c_line == N_PPS) {
791+ port->flags |= UPF_HARDPPS_CD;
792+ mxs_auart_enable_ms(port);
793+ } else {
794+ port->flags &= ~UPF_HARDPPS_CD;
795+ }
681796 }
682797
683798 static irqreturn_t mxs_auart_irq_handle(int irq, void *context)
684799 {
685800 u32 istat;
686801 struct mxs_auart_port *s = context;
802+ u32 mctrl_temp = s->mctrl_prev;
687803 u32 stat = readl(s->port.membase + AUART_STAT);
688804
689805 istat = readl(s->port.membase + AUART_INTR);
@@ -695,8 +811,20 @@ static irqreturn_t mxs_auart_irq_handle(int irq, void *context) · 5 unmodified lines
695811 | AUART_INTR_CTSMIS),
696812 s->port.membase + AUART_INTR_CLR);
697813
814+ /*
815+ * Dealing with GPIO interrupt
816+ */
817+ if (irq == s->gpio_irq[UART_GPIO_CTS] ||
818+ irq == s->gpio_irq[UART_GPIO_DCD] ||
819+ irq == s->gpio_irq[UART_GPIO_DSR] ||
820+ irq == s->gpio_irq[UART_GPIO_RI])
821+ mxs_auart_modem_status(s,
822+ mctrl_gpio_get(s->gpios, &mctrl_temp));
823+
698824 if (istat & AUART_INTR_CTSMIS) {
699− uart_handle_cts_change(&s->port, stat & AUART_STAT_CTS);
825+ if (CTS_AT_AUART() && s->ms_irq_enabled)
826+ uart_handle_cts_change(&s->port,
827+ stat & AUART_STAT_CTS);
700828 writel(AUART_INTR_CTSMIS,
701829 s->port.membase + AUART_INTR_CLR);
702830 istat &= ~AUART_INTR_CTSMIS;
@@ -757,6 +885,10 @@ static int mxs_auart_startup(struct uart_port *u) · 54 unmodified lines
757885 */
758886 writel(AUART_LINECTRL_FEN, u->membase + AUART_LINECTRL_SET);
759887
888+ /* get initial status of modem lines */
889+ mctrl_gpio_get(s->gpios, &s->mctrl_prev);
890+
891+ s->ms_irq_enabled = false;
760892 return 0;
761893 }
762894
@@ -764,6 +896,8 @@ static void mxs_auart_shutdown(struct uart_port *u) · 1 unmodified line
764896 {
765897 struct mxs_auart_port *s = to_auart_port(u);
766898
899+ mxs_auart_disable_ms(u);
900+
767901 if (auart_dma_enabled(s))
768902 mxs_auart_dma_exit(s);
769903
@@ -779,10 +913,11 @@ static void mxs_auart_shutdown(struct uart_port *u) · 9 unmodified lines
779913
780914 static unsigned int mxs_auart_tx_empty(struct uart_port *u)
781915 {
782− if (readl(u->membase + AUART_STAT) & AUART_STAT_TXFE)
916+ if ((readl(u->membase + AUART_STAT) &
917+ (AUART_STAT_TXFE | AUART_STAT_BUSY)) == AUART_STAT_TXFE)
783918 return TIOCSER_TEMT;
784− else
785− return 0;
919+
920+ return 0;
786921 }
787922
788923 static void mxs_auart_start_tx(struct uart_port *u)
@@ -820,12 +955,14 @@ static struct uart_ops mxs_auart_ops = { · 31 unmodified lines
820955 .start_tx = mxs_auart_start_tx,
821956 .stop_tx = mxs_auart_stop_tx,
822957 .stop_rx = mxs_auart_stop_rx,
958+ .enable_ms = mxs_auart_enable_ms,
823959 .break_ctl = mxs_auart_break_ctl,
824960 .set_mctrl = mxs_auart_set_mctrl,
825961 .get_mctrl = mxs_auart_get_mctrl,
826962 .startup = mxs_auart_startup,
827963 .shutdown = mxs_auart_shutdown,
828964 .set_termios = mxs_auart_settermios,
965+ .set_ldisc = mxs_auart_set_ldisc,
829966 .type = mxs_auart_type,
830967 .release_port = mxs_auart_release_port,
831968 .request_port = mxs_auart_request_port,
@@ -1020,6 +1157,71 @@ static int serial_mxs_probe_dt(struct mxs_auart_port *s, · 188 unmodified lines
10201157 return 0;
10211158 }
10221159
1160+static bool mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev)
1161+{
1162+ enum mctrl_gpio_idx i;
1163+ struct gpio_desc *gpiod;
1164+
1165+ s->gpios = mctrl_gpio_init(dev, 0);
1166+ if (IS_ERR_OR_NULL(s->gpios))
1167+ return false;
1168+
1169+ /* Block (enabled before) DMA option if RTS or CTS is GPIO line */
1170+ if (!RTS_AT_AUART() || !CTS_AT_AUART()) {
1171+ if (test_bit(MXS_AUART_RTSCTS, &s->flags))
1172+ dev_warn(dev,
1173+ "DMA and flow control via gpio may cause some problems. DMA disabled!\n");
1174+ clear_bit(MXS_AUART_RTSCTS, &s->flags);
1175+ }
1176+
1177+ for (i = 0; i < UART_GPIO_MAX; i++) {
1178+ gpiod = mctrl_gpio_to_gpiod(s->gpios, i);
1179+ if (gpiod && (gpiod_get_direction(gpiod) == GPIOF_DIR_IN))
1180+ s->gpio_irq[i] = gpiod_to_irq(gpiod);
1181+ else
1182+ s->gpio_irq[i] = -EINVAL;
1183+ }
1184+
1185+ return true;
1186+}
1187+
1188+static void mxs_auart_free_gpio_irq(struct mxs_auart_port *s)
1189+{
1190+ enum mctrl_gpio_idx i;
1191+
1192+ for (i = 0; i < UART_GPIO_MAX; i++)
1193+ if (s->gpio_irq[i] >= 0)
1194+ free_irq(s->gpio_irq[i], s);
1195+}
1196+
1197+static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s)
1198+{
1199+ int *irq = s->gpio_irq;
1200+ enum mctrl_gpio_idx i;
1201+ int err = 0;
1202+
1203+ for (i = 0; (i < UART_GPIO_MAX) && !err; i++) {
1204+ if (irq[i] < 0)
1205+ continue;
1206+
1207+ irq_set_status_flags(irq[i], IRQ_NOAUTOEN);
1208+ err = request_irq(irq[i], mxs_auart_irq_handle,
1209+ IRQ_TYPE_EDGE_BOTH, dev_name(s->dev), s);
1210+ if (err)
1211+ dev_err(s->dev, "%s - Can't get %d irq\n",
1212+ __func__, irq[i]);
1213+ }
1214+
1215+ /*
1216+ * If something went wrong, rollback.
1217+ */
1218+ while (err && (--i >= 0))
1219+ if (irq[i] >= 0)
1220+ free_irq(irq[i], s);
1221+
1222+ return err;
1223+}
1224+
10231225 static int mxs_auart_probe(struct platform_device *pdev)
10241226 {
10251227 const struct of_device_id *of_id =
@@ -1067,7 +1269,7 @@ static int mxs_auart_probe(struct platform_device *pdev) · 41 unmodified lines
10671269 s->port.type = PORT_IMX;
10681270 s->port.dev = s->dev = &pdev->dev;
10691271
1070− s->ctrl = 0;
1272+ s->mctrl_prev = 0;
10711273
10721274 s->irq = platform_get_irq(pdev, 0);
10731275 s->port.irq = s->irq;
@@ -1077,13 +1279,24 @@ static int mxs_auart_probe(struct platform_device *pdev) · 3 unmodified lines
10771279
10781280 platform_set_drvdata(pdev, s);
10791281
1282+ if (!mxs_auart_init_gpios(s, &pdev->dev))
1283+ dev_err(&pdev->dev,
1284+ "Failed to initialize GPIOs. The serial port may not work as expected\n");
1285+
1286+ /*
1287+ * Get the GPIO lines IRQ
1288+ */
1289+ ret = mxs_auart_request_gpio_irq(s);
1290+ if (ret)
1291+ goto out_free_irq;
1292+
10801293 auart_port[s->port.line] = s;
10811294
10821295 mxs_auart_reset(&s->port);
10831296
10841297 ret = uart_add_one_port(&auart_driver, &s->port);
10851298 if (ret)
1086− goto out_free_irq;
1299+ goto out_free_gpio_irq;
10871300
10881301 version = readl(s->port.membase + AUART_VERSION);
10891302 dev_info(&pdev->dev, "Found APPUART %d.%d.%d\n",
@@ -1092,6 +1305,8 @@ static int mxs_auart_probe(struct platform_device *pdev) · 2 unmodified lines
10921305
10931306 return 0;
10941307
1308+out_free_gpio_irq:
1309+ mxs_auart_free_gpio_irq(s);
10951310 out_free_irq:
10961311 auart_port[pdev->id] = NULL;
10971312 free_irq(s->irq, s);
@@ -1111,6 +1326,7 @@ static int mxs_auart_remove(struct platform_device *pdev) · 13 unmodified lines
11111326
11121327 auart_port[pdev->id] = NULL;
11131328
1329+ mxs_auart_free_gpio_irq(s);
11141330 clk_put(s->clk);
11151331 free_irq(s->irq, s);
11161332 kfree(s);
drivers/tty/serial/of_serial.c+74−1
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 * 2 of the License, or (at your option) any later version.
1010 *
1111 */
12+#include <linux/console.h>
1213 #include <linux/module.h>
1314 #include <linux/slab.h>
1415 #include <linux/delay.h>
@@ -129,8 +130,15 @@ static int of_platform_serial_setup(struct platform_device *ofdev, · 114 unmodified lines
129130
130131 port->dev = &ofdev->dev;
131132
132− if (type == PORT_TEGRA)
133+ switch (type) {
134+ case PORT_TEGRA:
133135 port->handle_break = tegra_serial_handle_break;
136+ break;
137+
138+ case PORT_RT2880:
139+ port->iotype = UPIO_AU;
140+ break;
141+ }
134142
135143 return 0;
136144 out:
@@ -240,6 +248,70 @@ static int of_platform_serial_remove(struct platform_device *ofdev) · 103 unmodified lines
240248 return 0;
241249 }
242250
251+#ifdef CONFIG_PM_SLEEP
252+#ifdef CONFIG_SERIAL_8250
253+static void of_serial_suspend_8250(struct of_serial_info *info)
254+{
255+ struct uart_8250_port *port8250 = serial8250_get_port(info->line);
256+ struct uart_port *port = &port8250->port;
257+
258+ serial8250_suspend_port(info->line);
259+ if (info->clk && (!uart_console(port) || console_suspend_enabled))
260+ clk_disable_unprepare(info->clk);
261+}
262+
263+static void of_serial_resume_8250(struct of_serial_info *info)
264+{
265+ struct uart_8250_port *port8250 = serial8250_get_port(info->line);
266+ struct uart_port *port = &port8250->port;
267+
268+ if (info->clk && (!uart_console(port) || console_suspend_enabled))
269+ clk_prepare_enable(info->clk);
270+
271+ serial8250_resume_port(info->line);
272+}
273+#else
274+static inline void of_serial_suspend_8250(struct of_serial_info *info)
275+{
276+}
277+
278+static inline void of_serial_resume_8250(struct of_serial_info *info)
279+{
280+}
281+#endif
282+
283+static int of_serial_suspend(struct device *dev)
284+{
285+ struct of_serial_info *info = dev_get_drvdata(dev);
286+
287+ switch (info->type) {
288+ case PORT_8250 ... PORT_MAX_8250:
289+ of_serial_suspend_8250(info);
290+ break;
291+ default:
292+ break;
293+ }
294+
295+ return 0;
296+}
297+
298+static int of_serial_resume(struct device *dev)
299+{
300+ struct of_serial_info *info = dev_get_drvdata(dev);
301+
302+ switch (info->type) {
303+ case PORT_8250 ... PORT_MAX_8250:
304+ of_serial_resume_8250(info);
305+ break;
306+ default:
307+ break;
308+ }
309+
310+ return 0;
311+}
312+#endif
313+static SIMPLE_DEV_PM_OPS(of_serial_pm_ops, of_serial_suspend, of_serial_resume);
314+
243315 /*
244316 * A few common types, add more as needed.
245317 */
@@ -252,6 +324,7 @@ static struct of_device_id of_platform_serial_table[] = { · 6 unmodified lines
252324 { .compatible = "ns16850", .data = (void *)PORT_16850, },
253325 { .compatible = "nvidia,tegra20-uart", .data = (void *)PORT_TEGRA, },
254326 { .compatible = "nxp,lpc3220-uart", .data = (void *)PORT_LPC3220, },
327+ { .compatible = "ralink,rt2880-uart", .data = (void *)PORT_RT2880, },
255328 { .compatible = "altr,16550-FIFO32",
256329 .data = (void *)PORT_ALTR_16550_F32, },
257330 { .compatible = "altr,16550-FIFO64",
drivers/tty/serial/omap-serial.c+35−58
@@ -46,7 +46,7 @@ · 45 unmodified lines
4646
4747 #include <dt-bindings/gpio/gpio.h>
4848
49−#define OMAP_MAX_HSUART_PORTS 6
49+#define OMAP_MAX_HSUART_PORTS 10
5050
5151 #define UART_BUILD_REVISION(x, y) (((x) << 8) | (y))
5252
@@ -163,7 +163,6 @@ struct uart_omap_port { · 110 unmodified lines
163163 u8 wakeups_enabled;
164164 u32 features;
165165
166− struct serial_rs485 rs485;
167166 int rts_gpio;
168167
169168 struct pm_qos_request pm_qos_request;
@@ -316,7 +315,7 @@ static void serial_omap_stop_tx(struct uart_port *port) · 146 unmodified lines
316315 pm_runtime_get_sync(up->dev);
317316
318317 /* Handle RS-485 */
319− if (up->rs485.flags & SER_RS485_ENABLED) {
318+ if (port->rs485.flags & SER_RS485_ENABLED) {
320319 if (up->scr & OMAP_UART_SCR_TX_EMPTY) {
321320 /* THR interrupt is fired when both TX FIFO and TX
322321 * shift register are empty. This means there's nothing
@@ -327,10 +326,12 @@ static void serial_omap_stop_tx(struct uart_port *port) · 4 unmodified lines
327326 */
328327 up->scr &= ~OMAP_UART_SCR_TX_EMPTY;
329328 serial_out(up, UART_OMAP_SCR, up->scr);
330− res = (up->rs485.flags & SER_RS485_RTS_AFTER_SEND) ? 1 : 0;
329+ res = (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) ?
330+ 1 : 0;
331331 if (gpio_get_value(up->rts_gpio) != res) {
332− if (up->rs485.delay_rts_after_send > 0)
333− mdelay(up->rs485.delay_rts_after_send);
332+ if (port->rs485.delay_rts_after_send > 0)
333+ mdelay(
334+ port->rs485.delay_rts_after_send);
334335 gpio_set_value(up->rts_gpio, res);
335336 }
336337 } else {
@@ -353,8 +354,8 @@ static void serial_omap_stop_tx(struct uart_port *port) · 16 unmodified lines
353354 serial_out(up, UART_IER, up->ier);
354355 }
355356
356− if ((up->rs485.flags & SER_RS485_ENABLED) &&
357− !(up->rs485.flags & SER_RS485_RX_DURING_TX)) {
357+ if ((port->rs485.flags & SER_RS485_ENABLED) &&
358+ !(port->rs485.flags & SER_RS485_RX_DURING_TX)) {
358359 /*
359360 * Empty the RX FIFO, we are not interested in anything
360361 * received during the half-duplex transmission.
@@ -429,22 +430,22 @@ static void serial_omap_start_tx(struct uart_port *port) · 68 unmodified lines
429430 pm_runtime_get_sync(up->dev);
430431
431432 /* Handle RS-485 */
432− if (up->rs485.flags & SER_RS485_ENABLED) {
433+ if (port->rs485.flags & SER_RS485_ENABLED) {
433434 /* Fire THR interrupts when FIFO is below trigger level */
434435 up->scr &= ~OMAP_UART_SCR_TX_EMPTY;
435436 serial_out(up, UART_OMAP_SCR, up->scr);
436437
437438 /* if rts not already enabled */
438− res = (up->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0;
439+ res = (port->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0;
439440 if (gpio_get_value(up->rts_gpio) != res) {
440441 gpio_set_value(up->rts_gpio, res);
441− if (up->rs485.delay_rts_before_send > 0)
442− mdelay(up->rs485.delay_rts_before_send);
442+ if (port->rs485.delay_rts_before_send > 0)
443+ mdelay(port->rs485.delay_rts_before_send);
443444 }
444445 }
445446
446− if ((up->rs485.flags & SER_RS485_ENABLED) &&
447− !(up->rs485.flags & SER_RS485_RX_DURING_TX))
447+ if ((port->rs485.flags & SER_RS485_ENABLED) &&
448+ !(port->rs485.flags & SER_RS485_RX_DURING_TX))
448449 serial_omap_stop_rx(port);
449450
450451 serial_omap_enable_ier_thri(up);
@@ -1355,16 +1356,14 @@ static inline void serial_omap_add_console_port(struct uart_omap_port *up) · 904 unmodified lines
13551356 #endif
13561357
13571358 /* Enable or disable the rs485 support */
1358−static void
1359+static int
13591360 serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
13601361 {
13611362 struct uart_omap_port *up = to_uart_omap_port(port);
1362− unsigned long flags;
13631363 unsigned int mode;
13641364 int val;
13651365
13661366 pm_runtime_get_sync(up->dev);
1367− spin_lock_irqsave(&up->port.lock, flags);
13681367
13691368 /* Disable interrupts from this port */
13701369 mode = up->ier;
@@ -1372,7 +1371,7 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) · 1 unmodified line
13721371 serial_out(up, UART_IER, 0);
13731372
13741373 /* store new config */
1375− up->rs485 = *rs485conf;
1374+ port->rs485 = *rs485conf;
13761375
13771376 /*
13781377 * Just as a precaution, only allow rs485
@@ -1380,12 +1379,12 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) · 1 unmodified line
13801379 */
13811380 if (gpio_is_valid(up->rts_gpio)) {
13821381 /* enable / disable rts */
1383− val = (up->rs485.flags & SER_RS485_ENABLED) ?
1382+ val = (port->rs485.flags & SER_RS485_ENABLED) ?
13841383 SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND;
1385− val = (up->rs485.flags & val) ? 1 : 0;
1384+ val = (port->rs485.flags & val) ? 1 : 0;
13861385 gpio_set_value(up->rts_gpio, val);
13871386 } else
1388− up->rs485.flags &= ~SER_RS485_ENABLED;
1387+ port->rs485.flags &= ~SER_RS485_ENABLED;
13891388
13901389 /* Enable interrupts */
13911390 up->ier = mode;
@@ -1394,45 +1393,18 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) · 2 unmodified lines
13941393 /* If RS-485 is disabled, make sure the THR interrupt is fired when
13951394 * TX FIFO is below the trigger level.
13961395 */
1397− if (!(up->rs485.flags & SER_RS485_ENABLED) &&
1396+ if (!(port->rs485.flags & SER_RS485_ENABLED) &&
13981397 (up->scr & OMAP_UART_SCR_TX_EMPTY)) {
13991398 up->scr &= ~OMAP_UART_SCR_TX_EMPTY;
14001399 serial_out(up, UART_OMAP_SCR, up->scr);
14011400 }
14021401
1403− spin_unlock_irqrestore(&up->port.lock, flags);
14041402 pm_runtime_mark_last_busy(up->dev);
14051403 pm_runtime_put_autosuspend(up->dev);
1406−}
1407−
1408−static int
1409−serial_omap_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg)
1410−{
1411− struct serial_rs485 rs485conf;
1412−
1413− switch (cmd) {
1414− case TIOCSRS485:
1415− if (copy_from_user(&rs485conf, (void __user *) arg,
1416− sizeof(rs485conf)))
1417− return -EFAULT;
14181404
1419− serial_omap_config_rs485(port, &rs485conf);
1420− break;
1421−
1422− case TIOCGRS485:
1423− if (copy_to_user((void __user *) arg,
1424− &(to_uart_omap_port(port)->rs485),
1425− sizeof(rs485conf)))
1426− return -EFAULT;
1427− break;
1428−
1429− default:
1430− return -ENOIOCTLCMD;
1431− }
14321405 return 0;
14331406 }
14341407
1435−
14361408 static struct uart_ops serial_omap_pops = {
14371409 .tx_empty = serial_omap_tx_empty,
14381410 .set_mctrl = serial_omap_set_mctrl,
@@ -1453,7 +1425,6 @@ static struct uart_ops serial_omap_pops = { · 14 unmodified lines
14531425 .request_port = serial_omap_request_port,
14541426 .config_port = serial_omap_config_port,
14551427 .verify_port = serial_omap_verify_port,
1456− .ioctl = serial_omap_ioctl,
14571428 #ifdef CONFIG_CONSOLE_POLL
14581429 .poll_put_char = serial_omap_poll_put_char,
14591430 .poll_get_char = serial_omap_poll_get_char,
@@ -1587,7 +1558,7 @@ static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev) · 127 unmodified lines
15871558 static int serial_omap_probe_rs485(struct uart_omap_port *up,
15881559 struct device_node *np)
15891560 {
1590− struct serial_rs485 *rs485conf = &up->rs485;
1561+ struct serial_rs485 *rs485conf = &up->port.rs485;
15911562 u32 rs485_delay[2];
15921563 enum of_gpio_flags flags;
15931564 int ret;
@@ -1682,14 +1653,21 @@ static int serial_omap_probe(struct platform_device *pdev) · 88 unmodified lines
16821653 up->port.ops = &serial_omap_pops;
16831654
16841655 if (pdev->dev.of_node)
1685− up->port.line = of_alias_get_id(pdev->dev.of_node, "serial");
1656+ ret = of_alias_get_id(pdev->dev.of_node, "serial");
16861657 else
1687− up->port.line = pdev->id;
1658+ ret = pdev->id;
16881659
1689− if (up->port.line < 0) {
1660+ if (ret < 0) {
16901661 dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n",
1691− up->port.line);
1692− ret = -ENODEV;
1662+ ret);
1663+ goto err_port_line;
1664+ }
1665+ up->port.line = ret;
1666+
1667+ if (up->port.line >= OMAP_MAX_HSUART_PORTS) {
1668+ dev_err(&pdev->dev, "uart ID %d > MAX %d.\n", up->port.line,
1669+ OMAP_MAX_HSUART_PORTS);
1670+ ret = -ENXIO;
16931671 goto err_port_line;
16941672 }
16951673
@@ -1702,6 +1680,7 @@ static int serial_omap_probe(struct platform_device *pdev) · 6 unmodified lines
17021680 up->port.membase = base;
17031681 up->port.flags = omap_up_info->flags;
17041682 up->port.uartclk = omap_up_info->uartclk;
1683+ up->port.rs485_config = serial_omap_config_rs485;
17051684 if (!up->port.uartclk) {
17061685 up->port.uartclk = DEFAULT_CLK_SPEED;
17071686 dev_warn(&pdev->dev,
@@ -1747,8 +1726,6 @@ err_add_port: · 39 unmodified lines
17471726 pm_runtime_disable(&pdev->dev);
17481727 err_rs485:
17491728 err_port_line:
1750− dev_err(&pdev->dev, "[UART%d]: failure [%s]: %d\n",
1751− pdev->id, __func__, ret);
17521729 return ret;
17531730 }
17541731
drivers/tty/serial/pmac_zilog.c+6−3
@@ -1352,7 +1352,8 @@ static int pmz_verify_port(struct uart_port *port, struct serial_struct *ser) · 1351 unmodified lines
13521352
13531353 static int pmz_poll_get_char(struct uart_port *port)
13541354 {
1355− struct uart_pmac_port *uap = (struct uart_pmac_port *)port;
1355+ struct uart_pmac_port *uap =
1356+ container_of(port, struct uart_pmac_port, port);
13561357 int tries = 2;
13571358
13581359 while (tries) {
@@ -1367,7 +1368,8 @@ static int pmz_poll_get_char(struct uart_port *port) · 8 unmodified lines
13671368
13681369 static void pmz_poll_put_char(struct uart_port *port, unsigned char c)
13691370 {
1370− struct uart_pmac_port *uap = (struct uart_pmac_port *)port;
1371+ struct uart_pmac_port *uap =
1372+ container_of(port, struct uart_pmac_port, port);
13711373
13721374 /* Wait for the transmit buffer to empty. */
13731375 while ((read_zsreg(uap, R0) & Tx_BUF_EMP) == 0)
@@ -1954,7 +1956,8 @@ static void __exit exit_pmz(void) · 580 unmodified lines
19541956
19551957 static void pmz_console_putchar(struct uart_port *port, int ch)
19561958 {
1957− struct uart_pmac_port *uap = (struct uart_pmac_port *)port;
1959+ struct uart_pmac_port *uap =
1960+ container_of(port, struct uart_pmac_port, port);
19581961
19591962 /* Wait for the transmit buffer to empty. */
19601963 while ((read_zsreg(uap, R0) & Tx_BUF_EMP) == 0)
drivers/tty/serial/pnx8xxx_uart.c+32−16
@@ -126,7 +126,8 @@ static void pnx8xxx_timeout(unsigned long data) · 125 unmodified lines
126126 */
127127 static void pnx8xxx_stop_tx(struct uart_port *port)
128128 {
129− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
129+ struct pnx8xxx_port *sport =
130+ container_of(port, struct pnx8xxx_port, port);
130131 u32 ien;
131132
132133 /* Disable TX intr */
@@ -142,7 +143,8 @@ static void pnx8xxx_stop_tx(struct uart_port *port) · 9 unmodified lines
142143 */
143144 static void pnx8xxx_start_tx(struct uart_port *port)
144145 {
145− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
146+ struct pnx8xxx_port *sport =
147+ container_of(port, struct pnx8xxx_port, port);
146148 u32 ien;
147149
148150 /* Clear all pending TX intr */
@@ -158,7 +160,8 @@ static void pnx8xxx_start_tx(struct uart_port *port) · 9 unmodified lines
158160 */
159161 static void pnx8xxx_stop_rx(struct uart_port *port)
160162 {
161− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
163+ struct pnx8xxx_port *sport =
164+ container_of(port, struct pnx8xxx_port, port);
162165 u32 ien;
163166
164167 /* Disable RX intr */
@@ -174,7 +177,8 @@ static void pnx8xxx_stop_rx(struct uart_port *port) · 9 unmodified lines
174177 */
175178 static void pnx8xxx_enable_ms(struct uart_port *port)
176179 {
177− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
180+ struct pnx8xxx_port *sport =
181+ container_of(port, struct pnx8xxx_port, port);
178182
179183 mod_timer(&sport->timer, jiffies);
180184 }
@@ -313,14 +317,16 @@ static irqreturn_t pnx8xxx_int(int irq, void *dev_id) · 132 unmodified lines
313317 */
314318 static unsigned int pnx8xxx_tx_empty(struct uart_port *port)
315319 {
316− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
320+ struct pnx8xxx_port *sport =
321+ container_of(port, struct pnx8xxx_port, port);
317322
318323 return serial_in(sport, PNX8XXX_FIFO) & PNX8XXX_UART_FIFO_TXFIFO_STA ? 0 : TIOCSER_TEMT;
319324 }
320325
321326 static unsigned int pnx8xxx_get_mctrl(struct uart_port *port)
322327 {
323− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
328+ struct pnx8xxx_port *sport =
329+ container_of(port, struct pnx8xxx_port, port);
324330 unsigned int mctrl = TIOCM_DSR;
325331 unsigned int msr;
326332
@@ -347,7 +353,8 @@ static void pnx8xxx_set_mctrl(struct uart_port *port, unsigned int mctrl) · 20 unmodified lines
347353 */
348354 static void pnx8xxx_break_ctl(struct uart_port *port, int break_state)
349355 {
350− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
356+ struct pnx8xxx_port *sport =
357+ container_of(port, struct pnx8xxx_port, port);
351358 unsigned long flags;
352359 unsigned int lcr;
353360
@@ -363,7 +370,8 @@ static void pnx8xxx_break_ctl(struct uart_port *port, int break_state) · 9 unmodified lines
363370
364371 static int pnx8xxx_startup(struct uart_port *port)
365372 {
366− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
373+ struct pnx8xxx_port *sport =
374+ container_of(port, struct pnx8xxx_port, port);
367375 int retval;
368376
369377 /*
@@ -397,7 +405,8 @@ static int pnx8xxx_startup(struct uart_port *port) · 27 unmodified lines
397405
398406 static void pnx8xxx_shutdown(struct uart_port *port)
399407 {
400− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
408+ struct pnx8xxx_port *sport =
409+ container_of(port, struct pnx8xxx_port, port);
401410 int lcr;
402411
403412 /*
@@ -434,7 +443,8 @@ static void · 30 unmodified lines
434443 pnx8xxx_set_termios(struct uart_port *port, struct ktermios *termios,
435444 struct ktermios *old)
436445 {
437− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
446+ struct pnx8xxx_port *sport =
447+ container_of(port, struct pnx8xxx_port, port);
438448 unsigned long flags;
439449 unsigned int lcr_fcr, old_ien, baud, quot;
440450 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
@@ -551,7 +561,8 @@ pnx8xxx_set_termios(struct uart_port *port, struct ktermios *termios, · 110 unmodified lines
551561
552562 static const char *pnx8xxx_type(struct uart_port *port)
553563 {
554− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
564+ struct pnx8xxx_port *sport =
565+ container_of(port, struct pnx8xxx_port, port);
555566
556567 return sport->port.type == PORT_PNX8XXX ? "PNX8XXX" : NULL;
557568 }
@@ -561,7 +572,8 @@ static const char *pnx8xxx_type(struct uart_port *port) · 3 unmodified lines
561572 */
562573 static void pnx8xxx_release_port(struct uart_port *port)
563574 {
564− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
575+ struct pnx8xxx_port *sport =
576+ container_of(port, struct pnx8xxx_port, port);
565577
566578 release_mem_region(sport->port.mapbase, UART_PORT_SIZE);
567579 }
@@ -571,7 +583,8 @@ static void pnx8xxx_release_port(struct uart_port *port) · 3 unmodified lines
571583 */
572584 static int pnx8xxx_request_port(struct uart_port *port)
573585 {
574− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
586+ struct pnx8xxx_port *sport =
587+ container_of(port, struct pnx8xxx_port, port);
575588 return request_mem_region(sport->port.mapbase, UART_PORT_SIZE,
576589 "pnx8xxx-uart") != NULL ? 0 : -EBUSY;
577590 }
@@ -581,7 +594,8 @@ static int pnx8xxx_request_port(struct uart_port *port) · 3 unmodified lines
581594 */
582595 static void pnx8xxx_config_port(struct uart_port *port, int flags)
583596 {
584− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
597+ struct pnx8xxx_port *sport =
598+ container_of(port, struct pnx8xxx_port, port);
585599
586600 if (flags & UART_CONFIG_TYPE &&
587601 pnx8xxx_request_port(&sport->port) == 0)
@@ -596,7 +610,8 @@ static void pnx8xxx_config_port(struct uart_port *port, int flags) · 8 unmodified lines
596610 static int
597611 pnx8xxx_verify_port(struct uart_port *port, struct serial_struct *ser)
598612 {
599− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
613+ struct pnx8xxx_port *sport =
614+ container_of(port, struct pnx8xxx_port, port);
600615 int ret = 0;
601616
602617 if (ser->type != PORT_UNKNOWN && ser->type != PORT_PNX8XXX)
@@ -662,7 +677,8 @@ static void __init pnx8xxx_init_ports(void) · 59 unmodified lines
662677
663678 static void pnx8xxx_console_putchar(struct uart_port *port, int ch)
664679 {
665− struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
680+ struct pnx8xxx_port *sport =
681+ container_of(port, struct pnx8xxx_port, port);
666682 int status;
667683
668684 do {
drivers/tty/serial/pxa.c+3−0
@@ -223,6 +223,7 @@ static void serial_pxa_start_tx(struct uart_port *port) · 222 unmodified lines
223223 }
224224 }
225225
226+/* should hold up->port.lock */
226227 static inline void check_modem_status(struct uart_pxa_port *up)
227228 {
228229 int status;
@@ -255,12 +256,14 @@ static inline irqreturn_t serial_pxa_irq(int irq, void *dev_id) · 26 unmodified lines
255256 iir = serial_in(up, UART_IIR);
256257 if (iir & UART_IIR_NO_INT)
257258 return IRQ_NONE;
259+ spin_lock(&up->port.lock);
258260 lsr = serial_in(up, UART_LSR);
259261 if (lsr & UART_LSR_DR)
260262 receive_chars(up, &lsr);
261263 check_modem_status(up);
262264 if (lsr & UART_LSR_THRE)
263265 transmit_chars(up);
266+ spin_unlock(&up->port.lock);
264267 return IRQ_HANDLED;
265268 }
266269
drivers/tty/serial/sa1100.c+30−15
@@ -142,7 +142,8 @@ static void sa1100_timeout(unsigned long data) · 141 unmodified lines
142142 */
143143 static void sa1100_stop_tx(struct uart_port *port)
144144 {
145− struct sa1100_port *sport = (struct sa1100_port *)port;
145+ struct sa1100_port *sport =
146+ container_of(port, struct sa1100_port, port);
146147 u32 utcr3;
147148
148149 utcr3 = UART_GET_UTCR3(sport);
@@ -155,7 +156,8 @@ static void sa1100_stop_tx(struct uart_port *port) · 6 unmodified lines
155156 */
156157 static void sa1100_start_tx(struct uart_port *port)
157158 {
158− struct sa1100_port *sport = (struct sa1100_port *)port;
159+ struct sa1100_port *sport =
160+ container_of(port, struct sa1100_port, port);
159161 u32 utcr3;
160162
161163 utcr3 = UART_GET_UTCR3(sport);
@@ -168,7 +170,8 @@ static void sa1100_start_tx(struct uart_port *port) · 6 unmodified lines
168170 */
169171 static void sa1100_stop_rx(struct uart_port *port)
170172 {
171− struct sa1100_port *sport = (struct sa1100_port *)port;
173+ struct sa1100_port *sport =
174+ container_of(port, struct sa1100_port, port);
172175 u32 utcr3;
173176
174177 utcr3 = UART_GET_UTCR3(sport);
@@ -180,7 +183,8 @@ static void sa1100_stop_rx(struct uart_port *port) · 5 unmodified lines
180183 */
181184 static void sa1100_enable_ms(struct uart_port *port)
182185 {
183− struct sa1100_port *sport = (struct sa1100_port *)port;
186+ struct sa1100_port *sport =
187+ container_of(port, struct sa1100_port, port);
184188
185189 mod_timer(&sport->timer, jiffies);
186190 }
@@ -323,7 +327,8 @@ static irqreturn_t sa1100_int(int irq, void *dev_id) · 136 unmodified lines
323327 */
324328 static unsigned int sa1100_tx_empty(struct uart_port *port)
325329 {
326− struct sa1100_port *sport = (struct sa1100_port *)port;
330+ struct sa1100_port *sport =
331+ container_of(port, struct sa1100_port, port);
327332
328333 return UART_GET_UTSR1(sport) & UTSR1_TBY ? 0 : TIOCSER_TEMT;
329334 }
@@ -342,7 +347,8 @@ static void sa1100_set_mctrl(struct uart_port *port, unsigned int mctrl) · 12 unmodified lines
342347 */
343348 static void sa1100_break_ctl(struct uart_port *port, int break_state)
344349 {
345− struct sa1100_port *sport = (struct sa1100_port *)port;
350+ struct sa1100_port *sport =
351+ container_of(port, struct sa1100_port, port);
346352 unsigned long flags;
347353 unsigned int utcr3;
348354
@@ -358,7 +364,8 @@ static void sa1100_break_ctl(struct uart_port *port, int break_state) · 9 unmodified lines
358364
359365 static int sa1100_startup(struct uart_port *port)
360366 {
361− struct sa1100_port *sport = (struct sa1100_port *)port;
367+ struct sa1100_port *sport =
368+ container_of(port, struct sa1100_port, port);
362369 int retval;
363370
364371 /*
@@ -387,7 +394,8 @@ static int sa1100_startup(struct uart_port *port) · 22 unmodified lines
387394
388395 static void sa1100_shutdown(struct uart_port *port)
389396 {
390− struct sa1100_port *sport = (struct sa1100_port *)port;
397+ struct sa1100_port *sport =
398+ container_of(port, struct sa1100_port, port);
391399
392400 /*
393401 * Stop our timer.
@@ -409,7 +417,8 @@ static void · 15 unmodified lines
409417 sa1100_set_termios(struct uart_port *port, struct ktermios *termios,
410418 struct ktermios *old)
411419 {
412− struct sa1100_port *sport = (struct sa1100_port *)port;
420+ struct sa1100_port *sport =
421+ container_of(port, struct sa1100_port, port);
413422 unsigned long flags;
414423 unsigned int utcr0, old_utcr3, baud, quot;
415424 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
@@ -512,7 +521,8 @@ sa1100_set_termios(struct uart_port *port, struct ktermios *termios, · 96 unmodified lines
512521
513522 static const char *sa1100_type(struct uart_port *port)
514523 {
515− struct sa1100_port *sport = (struct sa1100_port *)port;
524+ struct sa1100_port *sport =
525+ container_of(port, struct sa1100_port, port);
516526
517527 return sport->port.type == PORT_SA1100 ? "SA1100" : NULL;
518528 }
@@ -522,7 +532,8 @@ static const char *sa1100_type(struct uart_port *port) · 3 unmodified lines
522532 */
523533 static void sa1100_release_port(struct uart_port *port)
524534 {
525− struct sa1100_port *sport = (struct sa1100_port *)port;
535+ struct sa1100_port *sport =
536+ container_of(port, struct sa1100_port, port);
526537
527538 release_mem_region(sport->port.mapbase, UART_PORT_SIZE);
528539 }
@@ -532,7 +543,8 @@ static void sa1100_release_port(struct uart_port *port) · 3 unmodified lines
532543 */
533544 static int sa1100_request_port(struct uart_port *port)
534545 {
535− struct sa1100_port *sport = (struct sa1100_port *)port;
546+ struct sa1100_port *sport =
547+ container_of(port, struct sa1100_port, port);
536548
537549 return request_mem_region(sport->port.mapbase, UART_PORT_SIZE,
538550 "sa11x0-uart") != NULL ? 0 : -EBUSY;
@@ -543,7 +555,8 @@ static int sa1100_request_port(struct uart_port *port) · 4 unmodified lines
543555 */
544556 static void sa1100_config_port(struct uart_port *port, int flags)
545557 {
546− struct sa1100_port *sport = (struct sa1100_port *)port;
558+ struct sa1100_port *sport =
559+ container_of(port, struct sa1100_port, port);
547560
548561 if (flags & UART_CONFIG_TYPE &&
549562 sa1100_request_port(&sport->port) == 0)
@@ -558,7 +571,8 @@ static void sa1100_config_port(struct uart_port *port, int flags) · 8 unmodified lines
558571 static int
559572 sa1100_verify_port(struct uart_port *port, struct serial_struct *ser)
560573 {
561− struct sa1100_port *sport = (struct sa1100_port *)port;
574+ struct sa1100_port *sport =
575+ container_of(port, struct sa1100_port, port);
562576 int ret = 0;
563577
564578 if (ser->type != PORT_UNKNOWN && ser->type != PORT_SA1100)
@@ -691,7 +705,8 @@ void __init sa1100_register_uart(int idx, int port) · 126 unmodified lines
691705 #ifdef CONFIG_SERIAL_SA1100_CONSOLE
692706 static void sa1100_console_putchar(struct uart_port *port, int ch)
693707 {
694− struct sa1100_port *sport = (struct sa1100_port *)port;
708+ struct sa1100_port *sport =
709+ container_of(port, struct sa1100_port, port);
695710
696711 while (!(UART_GET_UTSR1(sport) & UTSR1_TNF))
697712 barrier();
drivers/tty/serial/samsung.c+38−52
@@ -199,12 +199,14 @@ static void s3c24xx_serial_stop_rx(struct uart_port *port) · 198 unmodified lines
199199 }
200200 }
201201
202−static inline struct s3c24xx_uart_info *s3c24xx_port_to_info(struct uart_port *port)
202+static inline struct s3c24xx_uart_info
203+ *s3c24xx_port_to_info(struct uart_port *port)
203204 {
204205 return to_ourport(port)->info;
205206 }
206207
207−static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port)
208+static inline struct s3c2410_uartcfg
209+ *s3c24xx_port_to_cfg(struct uart_port *port)
208210 {
209211 struct s3c24xx_uart_port *ourport;
210212
@@ -237,7 +239,7 @@ s3c24xx_serial_rx_chars(int irq, void *dev_id) · 26 unmodified lines
237239 struct uart_port *port = &ourport->port;
238240 unsigned int ufcon, ch, flag, ufstat, uerstat;
239241 unsigned long flags;
240− int max_count = 64;
242+ int max_count = port->fifosize;
241243
242244 spin_lock_irqsave(&port->lock, flags);
243245
@@ -311,14 +313,14 @@ s3c24xx_serial_rx_chars(int irq, void *dev_id) · 67 unmodified lines
311313 uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN,
312314 ch, flag);
313315
314− ignore_char:
316+ignore_char:
315317 continue;
316318 }
317319
318320 spin_unlock_irqrestore(&port->lock, flags);
319321 tty_flip_buffer_push(&port->state->port);
320322
321− out:
323+out:
322324 return IRQ_HANDLED;
323325 }
324326
@@ -328,7 +330,7 @@ static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id) · 3 unmodified lines
328330 struct uart_port *port = &ourport->port;
329331 struct circ_buf *xmit = &port->state->xmit;
330332 unsigned long flags;
331− int count = 256;
333+ int count = port->fifosize;
332334
333335 spin_lock_irqsave(&port->lock, flags);
334336
@@ -368,7 +370,7 @@ static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id) · 33 unmodified lines
368370 if (uart_circ_empty(xmit))
369371 s3c24xx_serial_stop_tx(port);
370372
371− out:
373+out:
372374 spin_unlock_irqrestore(&port->lock, flags);
373375 return IRQ_HANDLED;
374376 }
@@ -519,7 +521,7 @@ static int s3c24xx_serial_startup(struct uart_port *port) · 144 unmodified lines
519521
520522 return ret;
521523
522− err:
524+err:
523525 s3c24xx_serial_shutdown(port);
524526 return ret;
525527 }
@@ -559,11 +561,15 @@ static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level, · 33 unmodified lines
559561 unsigned int old)
560562 {
561563 struct s3c24xx_uart_port *ourport = to_ourport(port);
564+ int timeout = 10000;
562565
563566 ourport->pm_level = level;
564567
565568 switch (level) {
566569 case 3:
570+ while (--timeout && !s3c24xx_serial_txempty_nofifo(port))
571+ udelay(100);
572+
567573 if (!IS_ERR(ourport->baudclk))
568574 clk_disable_unprepare(ourport->baudclk);
569575
@@ -841,8 +847,8 @@ static void s3c24xx_serial_set_termios(struct uart_port *port, · 271 unmodified lines
841847 */
842848 port->read_status_mask = S3C2410_UERSTAT_OVERRUN;
843849 if (termios->c_iflag & INPCK)
844− port->read_status_mask |= S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_PARITY;
845−
850+ port->read_status_mask |= S3C2410_UERSTAT_FRAME |
851+ S3C2410_UERSTAT_PARITY;
846852 /*
847853 * Which character status flags should we ignore?
848854 */
@@ -969,10 +975,13 @@ static struct uart_driver s3c24xx_uart_drv = { · 120 unmodified lines
969975 .minor = S3C24XX_SERIAL_MINOR,
970976 };
971977
972−static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = {
978+#define __PORT_LOCK_UNLOCKED(i) \
979+ __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[i].port.lock)
980+static struct s3c24xx_uart_port
981+s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = {
973982 [0] = {
974983 .port = {
975− .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock),
984+ .lock = __PORT_LOCK_UNLOCKED(0),
976985 .iotype = UPIO_MEM,
977986 .uartclk = 0,
978987 .fifosize = 16,
@@ -983,7 +992,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS · 4 unmodified lines
983992 },
984993 [1] = {
985994 .port = {
986− .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock),
995+ .lock = __PORT_LOCK_UNLOCKED(1),
987996 .iotype = UPIO_MEM,
988997 .uartclk = 0,
989998 .fifosize = 16,
@@ -996,7 +1005,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS · 6 unmodified lines
9961005
9971006 [2] = {
9981007 .port = {
999− .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock),
1008+ .lock = __PORT_LOCK_UNLOCKED(2),
10001009 .iotype = UPIO_MEM,
10011010 .uartclk = 0,
10021011 .fifosize = 16,
@@ -1009,7 +1018,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS · 6 unmodified lines
10091018 #if CONFIG_SERIAL_SAMSUNG_UARTS > 3
10101019 [3] = {
10111020 .port = {
1012− .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[3].port.lock),
1021+ .lock = __PORT_LOCK_UNLOCKED(3),
10131022 .iotype = UPIO_MEM,
10141023 .uartclk = 0,
10151024 .fifosize = 16,
@@ -1020,6 +1029,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS · 4 unmodified lines
10201029 }
10211030 #endif
10221031 };
1032+#undef __PORT_LOCK_UNLOCKED
10231033
10241034 /* s3c24xx_serial_resetport
10251035 *
@@ -1102,11 +1112,12 @@ static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb, · 76 unmodified lines
11021112 s3c24xx_serial_set_termios(uport, termios, NULL);
11031113 }
11041114
1105− exit:
1115+exit:
11061116 return 0;
11071117 }
11081118
1109−static inline int s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
1119+static inline int
1120+s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
11101121 {
11111122 port->freq_transition.notifier_call = s3c24xx_serial_cpufreq_transition;
11121123
@@ -1114,19 +1125,22 @@ static inline int s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port · 1 unmodified line
11141125 CPUFREQ_TRANSITION_NOTIFIER);
11151126 }
11161127
1117−static inline void s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
1128+static inline void
1129+s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
11181130 {
11191131 cpufreq_unregister_notifier(&port->freq_transition,
11201132 CPUFREQ_TRANSITION_NOTIFIER);
11211133 }
11221134
11231135 #else
1124−static inline int s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
1136+static inline int
1137+s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
11251138 {
11261139 return 0;
11271140 }
11281141
1129−static inline void s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
1142+static inline void
1143+s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
11301144 {
11311145 }
11321146 #endif
@@ -1226,24 +1240,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport, · 93 unmodified lines
12261240 return 0;
12271241 }
12281242
1229−#ifdef CONFIG_SAMSUNG_CLOCK
1230−static ssize_t s3c24xx_serial_show_clksrc(struct device *dev,
1231− struct device_attribute *attr,
1232− char *buf)
1233−{
1234− struct uart_port *port = s3c24xx_dev_to_port(dev);
1235− struct s3c24xx_uart_port *ourport = to_ourport(port);
1236−
1237− if (IS_ERR(ourport->baudclk))
1238− return -EINVAL;
1239−
1240− return snprintf(buf, PAGE_SIZE, "* %s\n",
1241− ourport->baudclk->name ?: "(null)");
1242−}
1243−
1244−static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL);
1245−#endif
1246−
12471243 /* Device driver serial port probe */
12481244
12491245 static const struct of_device_id s3c24xx_uart_dt_match[];
@@ -1296,11 +1292,10 @@ static int s3c24xx_serial_probe(struct platform_device *pdev) · 46 unmodified lines
12961292 of_property_read_u32(np,
12971293 "samsung,uart-fifosize", &ourport->port.fifosize);
12981294
1299− if (!ourport->port.fifosize) {
1300− ourport->port.fifosize = (ourport->info->fifosize) ?
1301− ourport->info->fifosize :
1302− ourport->drv_data->fifosize[index];
1303− }
1295+ if (ourport->drv_data->fifosize[index])
1296+ ourport->port.fifosize = ourport->drv_data->fifosize[index];
1297+ else if (ourport->info->fifosize)
1298+ ourport->port.fifosize = ourport->info->fifosize;
13041299
13051300 probe_index++;
13061301
@@ -1329,12 +1324,6 @@ static int s3c24xx_serial_probe(struct platform_device *pdev) · 22 unmodified lines
13291324 */
13301325 clk_disable_unprepare(ourport->clk);
13311326
1332−#ifdef CONFIG_SAMSUNG_CLOCK
1333− ret = device_create_file(&pdev->dev, &dev_attr_clock_source);
1334− if (ret < 0)
1335− dev_err(&pdev->dev, "failed to add clock source attr.\n");
1336−#endif
1337−
13381327 ret = s3c24xx_serial_cpufreq_register(ourport);
13391328 if (ret < 0)
13401329 dev_err(&pdev->dev, "failed to add cpufreq notifier\n");
@@ -1348,9 +1337,6 @@ static int s3c24xx_serial_remove(struct platform_device *dev) · 7 unmodified lines
13481337
13491338 if (port) {
13501339 s3c24xx_serial_cpufreq_deregister(to_ourport(port));
1351−#ifdef CONFIG_SAMSUNG_CLOCK
1352− device_remove_file(&dev->dev, &dev_attr_clock_source);
1353−#endif
13541340 uart_remove_one_port(&s3c24xx_uart_drv, port);
13551341 }
13561342
drivers/tty/serial/sc16is7xx.c+12−45
@@ -304,8 +304,6 @@ struct sc16is7xx_one { · 303 unmodified lines
304304 struct uart_port port;
305305 struct work_struct tx_work;
306306 struct work_struct md_work;
307−
308− struct serial_rs485 rs485;
309307 };
310308
311309 struct sc16is7xx_port {
@@ -657,15 +655,15 @@ static void sc16is7xx_stop_tx(struct uart_port* port) · 345 unmodified lines
657655 struct circ_buf *xmit = &one->port.state->xmit;
658656
659657 /* handle rs485 */
660− if (one->rs485.flags & SER_RS485_ENABLED) {
658+ if (port->rs485.flags & SER_RS485_ENABLED) {
661659 /* do nothing if current tx not yet completed */
662660 int lsr = sc16is7xx_port_read(port, SC16IS7XX_LSR_REG);
663661 if (!(lsr & SC16IS7XX_LSR_TEMT_BIT))
664662 return;
665663
666664 if (uart_circ_empty(xmit) &&
667− (one->rs485.delay_rts_after_send > 0))
668− mdelay(one->rs485.delay_rts_after_send);
665+ (port->rs485.delay_rts_after_send > 0))
666+ mdelay(port->rs485.delay_rts_after_send);
669667 }
670668
671669 sc16is7xx_port_update(port, SC16IS7XX_IER_REG,
@@ -688,9 +686,9 @@ static void sc16is7xx_start_tx(struct uart_port *port) · 16 unmodified lines
688686 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
689687
690688 /* handle rs485 */
691− if ((one->rs485.flags & SER_RS485_ENABLED) &&
692− (one->rs485.delay_rts_before_send > 0)) {
693− mdelay(one->rs485.delay_rts_before_send);
689+ if ((port->rs485.flags & SER_RS485_ENABLED) &&
690+ (port->rs485.delay_rts_before_send > 0)) {
691+ mdelay(port->rs485.delay_rts_before_send);
694692 }
695693
696694 if (!work_pending(&one->tx_work))
@@ -830,51 +828,20 @@ static void sc16is7xx_set_termios(struct uart_port *port, · 133 unmodified lines
830828 uart_update_timeout(port, termios->c_cflag, baud);
831829 }
832830
833−#if defined(TIOCSRS485) && defined(TIOCGRS485)
834−static void sc16is7xx_config_rs485(struct uart_port *port,
831+static int sc16is7xx_config_rs485(struct uart_port *port,
835832 struct serial_rs485 *rs485)
836833 {
837− struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
838−
839− one->rs485 = *rs485;
840−
841− if (one->rs485.flags & SER_RS485_ENABLED) {
834+ if (port->rs485.flags & SER_RS485_ENABLED)
842835 sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
843836 SC16IS7XX_EFCR_AUTO_RS485_BIT,
844837 SC16IS7XX_EFCR_AUTO_RS485_BIT);
845− } else {
838+ else
846839 sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
847840 SC16IS7XX_EFCR_AUTO_RS485_BIT,
848841 0);
849− }
850−}
851−#endif
852−
853−static int sc16is7xx_ioctl(struct uart_port *port, unsigned int cmd,
854− unsigned long arg)
855−{
856−#if defined(TIOCSRS485) && defined(TIOCGRS485)
857− struct serial_rs485 rs485;
842+ port->rs485 = *rs485;
858843
859− switch (cmd) {
860− case TIOCSRS485:
861− if (copy_from_user(&rs485, (void __user *)arg, sizeof(rs485)))
862− return -EFAULT;
863−
864− sc16is7xx_config_rs485(port, &rs485);
865− return 0;
866− case TIOCGRS485:
867− if (copy_to_user((void __user *)arg,
868− &(to_sc16is7xx_one(port, port)->rs485),
869− sizeof(rs485)))
870− return -EFAULT;
871− return 0;
872− default:
873− break;
874− }
875−#endif
876−
877− return -ENOIOCTLCMD;
844+ return 0;
878845 }
879846
880847 static int sc16is7xx_startup(struct uart_port *port)
@@ -1000,7 +967,6 @@ static const struct uart_ops sc16is7xx_ops = { · 119 unmodified lines
1000967 .release_port = sc16is7xx_null_void,
1001968 .config_port = sc16is7xx_config_port,
1002969 .verify_port = sc16is7xx_verify_port,
1003− .ioctl = sc16is7xx_ioctl,
1004970 .pm = sc16is7xx_pm,
1005971 };
1006972
@@ -1130,6 +1096,7 @@ static int sc16is7xx_probe(struct device *dev, · 123 unmodified lines
11301096 s->p[i].port.flags = UPF_FIXED_TYPE | UPF_LOW_LATENCY;
11311097 s->p[i].port.iotype = UPIO_PORT;
11321098 s->p[i].port.uartclk = freq;
1099+ s->p[i].port.rs485_config = sc16is7xx_config_rs485;
11331100 s->p[i].port.ops = &sc16is7xx_ops;
11341101 /* Disable all interrupts */
11351102 sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_IER_REG, 0);
drivers/tty/serial/serial-tegra.c+19−17
@@ -319,16 +319,16 @@ static char tegra_uart_decode_rx_error(struct tegra_uart_port *tup, · 318 unmodified lines
319319 if (unlikely(lsr & TEGRA_UART_LSR_ANY)) {
320320 if (lsr & UART_LSR_OE) {
321321 /* Overrrun error */
322− flag |= TTY_OVERRUN;
322+ flag = TTY_OVERRUN;
323323 tup->uport.icount.overrun++;
324324 dev_err(tup->uport.dev, "Got overrun errors\n");
325325 } else if (lsr & UART_LSR_PE) {
326326 /* Parity error */
327− flag |= TTY_PARITY;
327+ flag = TTY_PARITY;
328328 tup->uport.icount.parity++;
329329 dev_err(tup->uport.dev, "Got Parity errors\n");
330330 } else if (lsr & UART_LSR_FE) {
331− flag |= TTY_FRAME;
331+ flag = TTY_FRAME;
332332 tup->uport.icount.frame++;
333333 dev_err(tup->uport.dev, "Got frame errors\n");
334334 } else if (lsr & UART_LSR_BI) {
@@ -1034,6 +1034,20 @@ fail_rx_dma: · 699 unmodified lines
10341034 return ret;
10351035 }
10361036
1037+/*
1038+ * Flush any TX data submitted for DMA and PIO. Called when the
1039+ * TX circular buffer is reset.
1040+ */
1041+static void tegra_uart_flush_buffer(struct uart_port *u)
1042+{
1043+ struct tegra_uart_port *tup = to_tegra_uport(u);
1044+
1045+ tup->tx_bytes = 0;
1046+ if (tup->tx_dma_chan)
1047+ dmaengine_terminate_all(tup->tx_dma_chan);
1048+ return;
1049+}
1050+
10371051 static void tegra_uart_shutdown(struct uart_port *u)
10381052 {
10391053 struct tegra_uart_port *tup = to_tegra_uport(u);
@@ -1046,6 +1060,8 @@ static void tegra_uart_shutdown(struct uart_port *u) · 6 unmodified lines
10461060 tegra_uart_dma_channel_free(tup, true);
10471061 tegra_uart_dma_channel_free(tup, false);
10481062 free_irq(u->irq, tup);
1063+
1064+ tegra_uart_flush_buffer(u);
10491065 }
10501066
10511067 static void tegra_uart_enable_ms(struct uart_port *u)
@@ -1174,20 +1190,6 @@ static void tegra_uart_set_termios(struct uart_port *u, · 122 unmodified lines
11741190 return;
11751191 }
11761192
1177−/*
1178− * Flush any TX data submitted for DMA and PIO. Called when the
1179− * TX circular buffer is reset.
1180− */
1181−static void tegra_uart_flush_buffer(struct uart_port *u)
1182−{
1183− struct tegra_uart_port *tup = to_tegra_uport(u);
1184−
1185− tup->tx_bytes = 0;
1186− if (tup->tx_dma_chan)
1187− dmaengine_terminate_all(tup->tx_dma_chan);
1188− return;
1189−}
1190−
11911193 static const char *tegra_uart_type(struct uart_port *u)
11921194 {
11931195 return TEGRA_UART_TYPE;
drivers/tty/serial/serial_core.c+89−27
@@ -61,7 +61,7 @@ static void uart_port_shutdown(struct tty_port *port); · 60 unmodified lines
6161
6262 static int uart_dcd_enabled(struct uart_port *uport)
6363 {
64− return uport->status & UPSTAT_DCD_ENABLE;
64+ return !!(uport->status & UPSTAT_DCD_ENABLE);
6565 }
6666
6767 /*
@@ -436,7 +436,7 @@ uart_get_divisor(struct uart_port *port, unsigned int baud) · 368 unmodified lines
436436
437437 EXPORT_SYMBOL(uart_get_divisor);
438438
439−/* FIXME: Consistent locking policy */
439+/* Caller holds port mutex */
440440 static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
441441 struct ktermios *old_termios)
442442 {
@@ -537,9 +537,10 @@ static int uart_write(struct tty_struct *tty, · 94 unmodified lines
537537 count -= c;
538538 ret += c;
539539 }
540+
541+ __uart_start(tty);
540542 spin_unlock_irqrestore(&port->lock, flags);
541543
542− uart_start(tty);
543544 return ret;
544545 }
545546
@@ -618,7 +619,7 @@ static void uart_throttle(struct tty_struct *tty) · 72 unmodified lines
618619 {
619620 struct uart_state *state = tty->driver_data;
620621 struct uart_port *port = state->uart_port;
621− uint32_t mask = 0;
622+ upf_t mask = 0;
622623
623624 if (I_IXOFF(tty))
624625 mask |= UPF_SOFT_FLOW;
@@ -641,7 +642,7 @@ static void uart_unthrottle(struct tty_struct *tty) · 16 unmodified lines
641642 {
642643 struct uart_state *state = tty->driver_data;
643644 struct uart_port *port = state->uart_port;
644− uint32_t mask = 0;
645+ upf_t mask = 0;
645646
646647 if (I_IXOFF(tty))
647648 mask |= UPF_SOFT_FLOW;
@@ -1151,6 +1152,47 @@ static int uart_get_icount(struct tty_struct *tty, · 503 unmodified lines
11511152 return 0;
11521153 }
11531154
1155+static int uart_get_rs485_config(struct uart_port *port,
1156+ struct serial_rs485 __user *rs485)
1157+{
1158+ unsigned long flags;
1159+ struct serial_rs485 aux;
1160+
1161+ spin_lock_irqsave(&port->lock, flags);
1162+ aux = port->rs485;
1163+ spin_unlock_irqrestore(&port->lock, flags);
1164+
1165+ if (copy_to_user(rs485, &aux, sizeof(aux)))
1166+ return -EFAULT;
1167+
1168+ return 0;
1169+}
1170+
1171+static int uart_set_rs485_config(struct uart_port *port,
1172+ struct serial_rs485 __user *rs485_user)
1173+{
1174+ struct serial_rs485 rs485;
1175+ int ret;
1176+ unsigned long flags;
1177+
1178+ if (!port->rs485_config)
1179+ return -ENOIOCTLCMD;
1180+
1181+ if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
1182+ return -EFAULT;
1183+
1184+ spin_lock_irqsave(&port->lock, flags);
1185+ ret = port->rs485_config(port, &rs485);
1186+ spin_unlock_irqrestore(&port->lock, flags);
1187+ if (ret)
1188+ return ret;
1189+
1190+ if (copy_to_user(rs485_user, &port->rs485, sizeof(port->rs485)))
1191+ return -EFAULT;
1192+
1193+ return 0;
1194+}
1195+
11541196 /*
11551197 * Called via sys_ioctl. We can use spin_lock_irq() here.
11561198 */
@@ -1173,11 +1215,15 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, · 16 unmodified lines
11731215 break;
11741216
11751217 case TIOCSSERIAL:
1218+ down_write(&tty->termios_rwsem);
11761219 ret = uart_set_info_user(tty, state, uarg);
1220+ up_write(&tty->termios_rwsem);
11771221 break;
11781222
11791223 case TIOCSERCONFIG:
1224+ down_write(&tty->termios_rwsem);
11801225 ret = uart_do_autoconfig(tty, state);
1226+ up_write(&tty->termios_rwsem);
11811227 break;
11821228
11831229 case TIOCSERGWILD: /* obsolete */
@@ -1217,11 +1263,19 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, · 33 unmodified lines
12171263 * All these rely on hardware being present and need to be
12181264 * protected against the tty being hung up.
12191265 */
1266+
12201267 switch (cmd) {
12211268 case TIOCSERGETLSR: /* Get line status register */
12221269 ret = uart_get_lsr_info(tty, state, uarg);
12231270 break;
12241271
1272+ case TIOCGRS485:
1273+ ret = uart_get_rs485_config(state->uart_port, uarg);
1274+ break;
1275+
1276+ case TIOCSRS485:
1277+ ret = uart_set_rs485_config(state->uart_port, uarg);
1278+ break;
12251279 default: {
12261280 struct uart_port *uport = state->uart_port;
12271281 if (uport->ops->ioctl)
@@ -1240,8 +1294,11 @@ static void uart_set_ldisc(struct tty_struct *tty) · 12 unmodified lines
12401294 struct uart_state *state = tty->driver_data;
12411295 struct uart_port *uport = state->uart_port;
12421296
1243− if (uport->ops->set_ldisc)
1244− uport->ops->set_ldisc(uport, tty->termios.c_line);
1297+ if (uport->ops->set_ldisc) {
1298+ mutex_lock(&state->port.mutex);
1299+ uport->ops->set_ldisc(uport, &tty->termios);
1300+ mutex_unlock(&state->port.mutex);
1301+ }
12451302 }
12461303
12471304 static void uart_set_termios(struct tty_struct *tty,
@@ -1278,7 +1335,9 @@ static void uart_set_termios(struct tty_struct *tty, · 30 unmodified lines
12781335 return;
12791336 }
12801337
1338+ mutex_lock(&state->port.mutex);
12811339 uart_change_speed(tty, state, old_termios);
1340+ mutex_unlock(&state->port.mutex);
12821341 /* reload cflag from termios; port driver may have overriden flags */
12831342 cflag = tty->termios.c_cflag;
12841343
@@ -1331,8 +1390,16 @@ static void uart_close(struct tty_struct *tty, struct file *filp) · 46 unmodified lines
13311390 struct uart_port *uport;
13321391 unsigned long flags;
13331392
1334− if (!state)
1393+ if (!state) {
1394+ struct uart_driver *drv = tty->driver->driver_state;
1395+
1396+ state = drv->state + tty->index;
1397+ port = &state->port;
1398+ spin_lock_irq(&port->lock);
1399+ --port->count;
1400+ spin_unlock_irq(&port->lock);
13351401 return;
1402+ }
13361403
13371404 uport = state->uart_port;
13381405 port = &state->port;
@@ -1361,10 +1428,6 @@ static void uart_close(struct tty_struct *tty, struct file *filp) · 22 unmodified lines
13611428
13621429 mutex_lock(&port->mutex);
13631430 uart_shutdown(tty, state);
1364− uart_flush_buffer(tty);
1365−
1366− tty_ldisc_flush(tty);
1367−
13681431 tty_port_tty_set(port, NULL);
13691432 tty->closing = 0;
13701433 spin_lock_irqsave(&port->lock, flags);
@@ -1372,8 +1435,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp) · 1 unmodified line
13721435 if (port->blocked_open) {
13731436 spin_unlock_irqrestore(&port->lock, flags);
13741437 if (port->close_delay)
1375− msleep_interruptible(
1376− jiffies_to_msecs(port->close_delay));
1438+ msleep_interruptible(jiffies_to_msecs(port->close_delay));
13771439 spin_lock_irqsave(&port->lock, flags);
13781440 } else if (!uart_console(uport)) {
13791441 spin_unlock_irqrestore(&port->lock, flags);
@@ -1391,6 +1453,8 @@ static void uart_close(struct tty_struct *tty, struct file *filp) · 11 unmodified lines
13911453 wake_up_interruptible(&port->close_wait);
13921454
13931455 mutex_unlock(&port->mutex);
1456+
1457+ tty_ldisc_flush(tty);
13941458 }
13951459
13961460 static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
@@ -1552,6 +1616,10 @@ static int uart_open(struct tty_struct *tty, struct file *filp) · 155 unmodified lines
15521616
15531617 pr_debug("uart_open(%d) called\n", line);
15541618
1619+ spin_lock_irq(&port->lock);
1620+ ++port->count;
1621+ spin_unlock_irq(&port->lock);
1622+
15551623 /*
15561624 * We take the semaphore here to guarantee that we won't be re-entered
15571625 * while allocating the state structure, or while we request any IRQs
@@ -1564,17 +1632,11 @@ static int uart_open(struct tty_struct *tty, struct file *filp) · 6 unmodified lines
15641632 goto end;
15651633 }
15661634
1567− port->count++;
15681635 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
15691636 retval = -ENXIO;
1570− goto err_dec_count;
1637+ goto err_unlock;
15711638 }
15721639
1573− /*
1574− * Once we set tty->driver_data here, we are guaranteed that
1575− * uart_close() will decrement the driver module use count.
1576− * Any failures from here onwards should not touch the count.
1577− */
15781640 tty->driver_data = state;
15791641 state->uart_port->state = state;
15801642 state->port.low_latency =
@@ -1595,8 +1657,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp) · 14 unmodified lines
15951657
15961658 end:
15971659 return retval;
1598−err_dec_count:
1599− port->count--;
1660+err_unlock:
16001661 mutex_unlock(&port->mutex);
16011662 goto end;
16021663 }
@@ -2092,6 +2153,7 @@ uart_report_port(struct uart_driver *drv, struct uart_port *port) · 489 unmodified lines
20922153 break;
20932154 case UPIO_MEM:
20942155 case UPIO_MEM32:
2156+ case UPIO_MEM32BE:
20952157 case UPIO_AU:
20962158 case UPIO_TSI:
20972159 snprintf(address, sizeof(address),
@@ -2339,8 +2401,6 @@ int uart_register_driver(struct uart_driver *drv) · 241 unmodified lines
23392401
23402402 tty_port_init(port);
23412403 port->ops = &uart_port_ops;
2342− port->close_delay = HZ / 2; /* .5 seconds */
2343− port->closing_wait = 30 * HZ;/* 30 seconds */
23442404 }
23452405
23462406 retval = tty_register_driver(normal);
@@ -2589,11 +2649,12 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) · 242 unmodified lines
25892649 goto out;
25902650 }
25912651
2652+ /* Link the port to the driver state table and vice versa */
25922653 state->uart_port = uport;
2593− state->pm_state = UART_PM_STATE_UNDEFINED;
2654+ uport->state = state;
25942655
2656+ state->pm_state = UART_PM_STATE_UNDEFINED;
25952657 uport->cons = drv->cons;
2596− uport->state = state;
25972658
25982659 /*
25992660 * If this port is a console, then the spinlock is already
@@ -2736,6 +2797,7 @@ int uart_match_port(struct uart_port *port1, struct uart_port *port2) · 136 unmodified lines
27362797 (port1->hub6 == port2->hub6);
27372798 case UPIO_MEM:
27382799 case UPIO_MEM32:
2800+ case UPIO_MEM32BE:
27392801 case UPIO_AU:
27402802 case UPIO_TSI:
27412803 return (port1->mapbase == port2->mapbase);
drivers/tty/serial/sh-sci.c+1−4
@@ -1812,9 +1812,6 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, · 1811 unmodified lines
18121812 err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
18131813 (1 << (2 * c + 1)) / 1000)) -
18141814 1000;
1815− if (err < 0)
1816− continue;
1817−
18181815 /* Calc recv margin
18191816 * M: Receive margin (%)
18201817 * N: Ratio of bit rate to clock (N = sampling rate)
@@ -1829,7 +1826,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, · 8 unmodified lines
18291826 */
18301827 recv_margin = abs((500 -
18311828 DIV_ROUND_CLOSEST(1000, sr << 1)) / 10);
1832− if (min_err > err) {
1829+ if (abs(min_err) > abs(err)) {
18331830 min_err = err;
18341831 recv_max_margin = recv_margin;
18351832 } else if ((min_err == err) &&
drivers/tty/serial/sirfsoc_uart.c+27−7
@@ -1032,10 +1032,19 @@ static void sirfsoc_uart_pm(struct uart_port *port, unsigned int state, · 1031 unmodified lines
10321032 unsigned int oldstate)
10331033 {
10341034 struct sirfsoc_uart_port *sirfport = to_sirfport(port);
1035− if (!state)
1035+ if (!state) {
1036+ if (sirfport->is_bt_uart) {
1037+ clk_prepare_enable(sirfport->clk_noc);
1038+ clk_prepare_enable(sirfport->clk_general);
1039+ }
10361040 clk_prepare_enable(sirfport->clk);
1037− else
1041+ } else {
10381042 clk_disable_unprepare(sirfport->clk);
1043+ if (sirfport->is_bt_uart) {
1044+ clk_disable_unprepare(sirfport->clk_general);
1045+ clk_disable_unprepare(sirfport->clk_noc);
1046+ }
1047+ }
10391048 }
10401049
10411050 static int sirfsoc_uart_startup(struct uart_port *port)
@@ -1378,12 +1387,26 @@ usp_no_flow_control: · 336 unmodified lines
13781387 }
13791388 port->irq = res->start;
13801389
1381− sirfport->clk = clk_get(&pdev->dev, NULL);
1390+ sirfport->clk = devm_clk_get(&pdev->dev, NULL);
13821391 if (IS_ERR(sirfport->clk)) {
13831392 ret = PTR_ERR(sirfport->clk);
13841393 goto err;
13851394 }
13861395 port->uartclk = clk_get_rate(sirfport->clk);
1396+ if (of_device_is_compatible(pdev->dev.of_node, "sirf,marco-bt-uart")) {
1397+ sirfport->clk_general = devm_clk_get(&pdev->dev, "general");
1398+ if (IS_ERR(sirfport->clk_general)) {
1399+ ret = PTR_ERR(sirfport->clk_general);
1400+ goto err;
1401+ }
1402+ sirfport->clk_noc = devm_clk_get(&pdev->dev, "noc");
1403+ if (IS_ERR(sirfport->clk_noc)) {
1404+ ret = PTR_ERR(sirfport->clk_noc);
1405+ goto err;
1406+ }
1407+ sirfport->is_bt_uart = true;
1408+ } else
1409+ sirfport->is_bt_uart = false;
13871410
13881411 port->ops = &sirfsoc_uart_ops;
13891412 spin_lock_init(&port->lock);
@@ -1392,7 +1415,7 @@ usp_no_flow_control: · 2 unmodified lines
13921415 ret = uart_add_one_port(&sirfsoc_uart_drv, port);
13931416 if (ret != 0) {
13941417 dev_err(&pdev->dev, "Cannot add UART port(%d).\n", pdev->id);
1395− goto port_err;
1418+ goto err;
13961419 }
13971420
13981421 sirfport->rx_dma_chan = dma_request_slave_channel(port->dev, "rx");
@@ -1421,8 +1444,6 @@ alloc_coherent_err: · 22 unmodified lines
14211444 sirfport->rx_dma_items[j].xmit.buf,
14221445 sirfport->rx_dma_items[j].dma_addr);
14231446 dma_release_channel(sirfport->rx_dma_chan);
1424−port_err:
1425− clk_put(sirfport->clk);
14261447 err:
14271448 return ret;
14281449 }
@@ -1431,7 +1452,6 @@ static int sirfsoc_uart_remove(struct platform_device *pdev) · 2 unmodified lines
14311452 {
14321453 struct sirfsoc_uart_port *sirfport = platform_get_drvdata(pdev);
14331454 struct uart_port *port = &sirfport->port;
1434− clk_put(sirfport->clk);
14351455 uart_remove_one_port(&sirfsoc_uart_drv, port);
14361456 if (sirfport->rx_dma_chan) {
14371457 int i;
drivers/tty/serial/sirfsoc_uart.h+4−0
@@ -417,6 +417,10 @@ struct sirfsoc_uart_port { · 416 unmodified lines
417417
418418 struct uart_port port;
419419 struct clk *clk;
420+ /* UART6 for BT usage in A7DA platform need multi-clock source */
421+ bool is_bt_uart;
422+ struct clk *clk_general;
423+ struct clk *clk_noc;
420424 /* for SiRFmarco, there are SET/CLR for UART_INT_EN */
421425 bool is_marco;
422426 struct sirfsoc_uart_register *uart_reg;
drivers/tty/serial/sunsab.c+24−12
@@ -345,7 +345,8 @@ static irqreturn_t sunsab_interrupt(int irq, void *dev_id) · 344 unmodified lines
345345 /* port->lock is not held. */
346346 static unsigned int sunsab_tx_empty(struct uart_port *port)
347347 {
348− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
348+ struct uart_sunsab_port *up =
349+ container_of(port, struct uart_sunsab_port, port);
349350 int ret;
350351
351352 /* Do not need a lock for a state test like this. */
@@ -360,7 +361,8 @@ static unsigned int sunsab_tx_empty(struct uart_port *port) · 8 unmodified lines
360361 /* port->lock held by caller. */
361362 static void sunsab_set_mctrl(struct uart_port *port, unsigned int mctrl)
362363 {
363− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
364+ struct uart_sunsab_port *up =
365+ container_of(port, struct uart_sunsab_port, port);
364366
365367 if (mctrl & TIOCM_RTS) {
366368 up->cached_mode &= ~SAB82532_MODE_FRTS;
@@ -383,7 +385,8 @@ static void sunsab_set_mctrl(struct uart_port *port, unsigned int mctrl) · 16 unmodified lines
383385 /* port->lock is held by caller and interrupts are disabled. */
384386 static unsigned int sunsab_get_mctrl(struct uart_port *port)
385387 {
386− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
388+ struct uart_sunsab_port *up =
389+ container_of(port, struct uart_sunsab_port, port);
387390 unsigned char val;
388391 unsigned int result;
389392
@@ -404,7 +407,8 @@ static unsigned int sunsab_get_mctrl(struct uart_port *port) · 14 unmodified lines
404407 /* port->lock held by caller. */
405408 static void sunsab_stop_tx(struct uart_port *port)
406409 {
407− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
410+ struct uart_sunsab_port *up =
411+ container_of(port, struct uart_sunsab_port, port);
408412
409413 up->interrupt_mask1 |= SAB82532_IMR1_XPR;
410414 writeb(up->interrupt_mask1, &up->regs->w.imr1);
@@ -432,7 +436,8 @@ static void sunsab_tx_idle(struct uart_sunsab_port *up) · 21 unmodified lines
432436 /* port->lock held by caller. */
433437 static void sunsab_start_tx(struct uart_port *port)
434438 {
435− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
439+ struct uart_sunsab_port *up =
440+ container_of(port, struct uart_sunsab_port, port);
436441 struct circ_buf *xmit = &up->port.state->xmit;
437442 int i;
438443
@@ -465,7 +470,8 @@ static void sunsab_start_tx(struct uart_port *port) · 26 unmodified lines
465470 /* port->lock is not held. */
466471 static void sunsab_send_xchar(struct uart_port *port, char ch)
467472 {
468− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
473+ struct uart_sunsab_port *up =
474+ container_of(port, struct uart_sunsab_port, port);
469475 unsigned long flags;
470476
471477 if (ch == __DISABLED_CHAR)
@@ -482,7 +488,8 @@ static void sunsab_send_xchar(struct uart_port *port, char ch) · 10 unmodified lines
482488 /* port->lock held by caller. */
483489 static void sunsab_stop_rx(struct uart_port *port)
484490 {
485− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
491+ struct uart_sunsab_port *up =
492+ container_of(port, struct uart_sunsab_port, port);
486493
487494 up->interrupt_mask0 |= SAB82532_IMR0_TCD;
488495 writeb(up->interrupt_mask1, &up->regs->w.imr0);
@@ -491,7 +498,8 @@ static void sunsab_stop_rx(struct uart_port *port) · 2 unmodified lines
491498 /* port->lock is not held. */
492499 static void sunsab_break_ctl(struct uart_port *port, int break_state)
493500 {
494− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
501+ struct uart_sunsab_port *up =
502+ container_of(port, struct uart_sunsab_port, port);
495503 unsigned long flags;
496504 unsigned char val;
497505
@@ -514,7 +522,8 @@ static void sunsab_break_ctl(struct uart_port *port, int break_state) · 16 unmodified lines
514522 /* port->lock is not held. */
515523 static int sunsab_startup(struct uart_port *port)
516524 {
517− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
525+ struct uart_sunsab_port *up =
526+ container_of(port, struct uart_sunsab_port, port);
518527 unsigned long flags;
519528 unsigned char tmp;
520529 int err = request_irq(up->port.irq, sunsab_interrupt,
@@ -585,7 +594,8 @@ static int sunsab_startup(struct uart_port *port) · 64 unmodified lines
585594 /* port->lock is not held. */
586595 static void sunsab_shutdown(struct uart_port *port)
587596 {
588− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
597+ struct uart_sunsab_port *up =
598+ container_of(port, struct uart_sunsab_port, port);
589599 unsigned long flags;
590600
591601 spin_lock_irqsave(&up->port.lock, flags);
@@ -771,7 +781,8 @@ static void sunsab_convert_to_sab(struct uart_sunsab_port *up, unsigned int cfla · 179 unmodified lines
771781 static void sunsab_set_termios(struct uart_port *port, struct ktermios *termios,
772782 struct ktermios *old)
773783 {
774− struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
784+ struct uart_sunsab_port *up =
785+ container_of(port, struct uart_sunsab_port, port);
775786 unsigned long flags;
776787 unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
777788 unsigned int quot = uart_get_divisor(port, baud);
@@ -840,7 +851,8 @@ static struct uart_sunsab_port *sunsab_ports; · 62 unmodified lines
840851
841852 static void sunsab_console_putchar(struct uart_port *port, int c)
842853 {
843− struct uart_sunsab_port *up = (struct uart_sunsab_port *)port;
854+ struct uart_sunsab_port *up =
855+ container_of(port, struct uart_sunsab_port, port);
844856
845857 sunsab_tec_wait(up);
846858 writeb(c, &up->regs->w.tic);
drivers/tty/serial/sunsu.c+26−13
@@ -264,7 +264,8 @@ static inline void __stop_tx(struct uart_sunsu_port *p) · 263 unmodified lines
264264
265265 static void sunsu_stop_tx(struct uart_port *port)
266266 {
267− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
267+ struct uart_sunsu_port *up =
268+ container_of(port, struct uart_sunsu_port, port);
268269
269270 __stop_tx(up);
270271
@@ -279,7 +280,8 @@ static void sunsu_stop_tx(struct uart_port *port) · 8 unmodified lines
279280
280281 static void sunsu_start_tx(struct uart_port *port)
281282 {
282− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
283+ struct uart_sunsu_port *up =
284+ container_of(port, struct uart_sunsu_port, port);
283285
284286 if (!(up->ier & UART_IER_THRI)) {
285287 up->ier |= UART_IER_THRI;
@@ -297,7 +299,8 @@ static void sunsu_start_tx(struct uart_port *port) · 11 unmodified lines
297299
298300 static void sunsu_stop_rx(struct uart_port *port)
299301 {
300− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
302+ struct uart_sunsu_port *up =
303+ container_of(port, struct uart_sunsu_port, port);
301304
302305 up->ier &= ~UART_IER_RLSI;
303306 up->port.read_status_mask &= ~UART_LSR_DR;
@@ -306,7 +309,8 @@ static void sunsu_stop_rx(struct uart_port *port) · 2 unmodified lines
306309
307310 static void sunsu_enable_ms(struct uart_port *port)
308311 {
309− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
312+ struct uart_sunsu_port *up =
313+ container_of(port, struct uart_sunsu_port, port);
310314 unsigned long flags;
311315
312316 spin_lock_irqsave(&up->port.lock, flags);
@@ -543,7 +547,8 @@ static irqreturn_t sunsu_kbd_ms_interrupt(int irq, void *dev_id) · 230 unmodified lines
543547
544548 static unsigned int sunsu_tx_empty(struct uart_port *port)
545549 {
546− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
550+ struct uart_sunsu_port *up =
551+ container_of(port, struct uart_sunsu_port, port);
547552 unsigned long flags;
548553 unsigned int ret;
549554
@@ -556,7 +561,8 @@ static unsigned int sunsu_tx_empty(struct uart_port *port) · 6 unmodified lines
556561
557562 static unsigned int sunsu_get_mctrl(struct uart_port *port)
558563 {
559− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
564+ struct uart_sunsu_port *up =
565+ container_of(port, struct uart_sunsu_port, port);
560566 unsigned char status;
561567 unsigned int ret;
562568
@@ -576,7 +582,8 @@ static unsigned int sunsu_get_mctrl(struct uart_port *port) · 13 unmodified lines
576582
577583 static void sunsu_set_mctrl(struct uart_port *port, unsigned int mctrl)
578584 {
579− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
585+ struct uart_sunsu_port *up =
586+ container_of(port, struct uart_sunsu_port, port);
580587 unsigned char mcr = 0;
581588
582589 if (mctrl & TIOCM_RTS)
@@ -595,7 +602,8 @@ static void sunsu_set_mctrl(struct uart_port *port, unsigned int mctrl) · 12 unmodified lines
595602
596603 static void sunsu_break_ctl(struct uart_port *port, int break_state)
597604 {
598− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
605+ struct uart_sunsu_port *up =
606+ container_of(port, struct uart_sunsu_port, port);
599607 unsigned long flags;
600608
601609 spin_lock_irqsave(&up->port.lock, flags);
@@ -609,7 +617,8 @@ static void sunsu_break_ctl(struct uart_port *port, int break_state) · 7 unmodified lines
609617
610618 static int sunsu_startup(struct uart_port *port)
611619 {
612− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
620+ struct uart_sunsu_port *up =
621+ container_of(port, struct uart_sunsu_port, port);
613622 unsigned long flags;
614623 int retval;
615624
@@ -719,7 +728,8 @@ static int sunsu_startup(struct uart_port *port) · 103 unmodified lines
719728
720729 static void sunsu_shutdown(struct uart_port *port)
721730 {
722− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
731+ struct uart_sunsu_port *up =
732+ container_of(port, struct uart_sunsu_port, port);
723733 unsigned long flags;
724734
725735 /*
@@ -767,7 +777,8 @@ static void · 41 unmodified lines
767777 sunsu_change_speed(struct uart_port *port, unsigned int cflag,
768778 unsigned int iflag, unsigned int quot)
769779 {
770− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
780+ struct uart_sunsu_port *up =
781+ container_of(port, struct uart_sunsu_port, port);
771782 unsigned char cval, fcr = 0;
772783 unsigned long flags;
773784
@@ -918,7 +929,8 @@ static int sunsu_request_port(struct uart_port *port) · 144 unmodified lines
918929
919930 static void sunsu_config_port(struct uart_port *port, int flags)
920931 {
921− struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
932+ struct uart_sunsu_port *up =
933+ container_of(port, struct uart_sunsu_port, port);
922934
923935 if (flags & UART_CONFIG_TYPE) {
924936 /*
@@ -1277,7 +1289,8 @@ static __inline__ void wait_for_xmitr(struct uart_sunsu_port *up) · 352 unmodified lines
12771289
12781290 static void sunsu_console_putchar(struct uart_port *port, int ch)
12791291 {
1280− struct uart_sunsu_port *up = (struct uart_sunsu_port *)port;
1292+ struct uart_sunsu_port *up =
1293+ container_of(port, struct uart_sunsu_port, port);
12811294
12821295 wait_for_xmitr(up);
12831296 serial_out(up, UART_TX, ch);
drivers/tty/serial/sunzilog.c+16−8
@@ -644,7 +644,8 @@ static unsigned int sunzilog_get_mctrl(struct uart_port *port) · 643 unmodified lines
644644 /* The port lock is held and interrupts are disabled. */
645645 static void sunzilog_set_mctrl(struct uart_port *port, unsigned int mctrl)
646646 {
647− struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
647+ struct uart_sunzilog_port *up =
648+ container_of(port, struct uart_sunzilog_port, port);
648649 struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port);
649650 unsigned char set_bits, clear_bits;
650651
@@ -668,7 +669,8 @@ static void sunzilog_set_mctrl(struct uart_port *port, unsigned int mctrl) · 17 unmodified lines
668669 /* The port lock is held and interrupts are disabled. */
669670 static void sunzilog_stop_tx(struct uart_port *port)
670671 {
671− struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
672+ struct uart_sunzilog_port *up =
673+ container_of(port, struct uart_sunzilog_port, port);
672674
673675 up->flags |= SUNZILOG_FLAG_TX_STOPPED;
674676 }
@@ -676,7 +678,8 @@ static void sunzilog_stop_tx(struct uart_port *port) · 1 unmodified line
676678 /* The port lock is held and interrupts are disabled. */
677679 static void sunzilog_start_tx(struct uart_port *port)
678680 {
679− struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
681+ struct uart_sunzilog_port *up =
682+ container_of(port, struct uart_sunzilog_port, port);
680683 struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port);
681684 unsigned char status;
682685
@@ -736,7 +739,8 @@ static void sunzilog_stop_rx(struct uart_port *port) · 53 unmodified lines
736739 /* The port lock is held. */
737740 static void sunzilog_enable_ms(struct uart_port *port)
738741 {
739− struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
742+ struct uart_sunzilog_port *up =
743+ container_of(port, struct uart_sunzilog_port, port);
740744 struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port);
741745 unsigned char new_reg;
742746
@@ -752,7 +756,8 @@ static void sunzilog_enable_ms(struct uart_port *port) · 9 unmodified lines
752756 /* The port lock is not held. */
753757 static void sunzilog_break_ctl(struct uart_port *port, int break_state)
754758 {
755− struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
759+ struct uart_sunzilog_port *up =
760+ container_of(port, struct uart_sunzilog_port, port);
756761 struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port);
757762 unsigned char set_bits, clear_bits, new_reg;
758763 unsigned long flags;
@@ -938,7 +943,8 @@ static void · 179 unmodified lines
938943 sunzilog_set_termios(struct uart_port *port, struct ktermios *termios,
939944 struct ktermios *old)
940945 {
941− struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
946+ struct uart_sunzilog_port *up =
947+ container_of(port, struct uart_sunzilog_port, port);
942948 unsigned long flags;
943949 int baud, brg;
944950
@@ -998,7 +1004,8 @@ static int sunzilog_verify_port(struct uart_port *port, struct serial_struct *se · 53 unmodified lines
9981004 static int sunzilog_get_poll_char(struct uart_port *port)
9991005 {
10001006 unsigned char ch, r1;
1001− struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
1007+ struct uart_sunzilog_port *up =
1008+ container_of(port, struct uart_sunzilog_port, port);
10021009 struct zilog_channel __iomem *channel
10031010 = ZILOG_CHANNEL_FROM_PORT(&up->port);
10041011
@@ -1032,7 +1039,8 @@ static int sunzilog_get_poll_char(struct uart_port *port) · 27 unmodified lines
10321039 static void sunzilog_put_poll_char(struct uart_port *port,
10331040 unsigned char ch)
10341041 {
1035− struct uart_sunzilog_port *up = (struct uart_sunzilog_port *)port;
1042+ struct uart_sunzilog_port *up =
1043+ container_of(port, struct uart_sunzilog_port, port);
10361044
10371045 sunzilog_putchar(&up->port, ch);
10381046 }
drivers/tty/serial/timbuart.c+2−0
@@ -273,6 +273,8 @@ static void timbuart_shutdown(struct uart_port *port) · 272 unmodified lines
273273 dev_dbg(port->dev, "%s\n", __func__);
274274 free_irq(port->irq, uart);
275275 iowrite32(0, port->membase + TIMBUART_IER);
276+
277+ timbuart_flush_buffer(port);
276278 }
277279
278280 static int get_bindex(int baud)
drivers/tty/serial/xilinx_uartps.c+21−1
@@ -132,6 +132,15 @@ MODULE_PARM_DESC(rx_timeout, "Rx timeout, 1-255"); · 131 unmodified lines
132132 /* Goes in read_status_mask for break detection as the HW doesn't do it*/
133133 #define CDNS_UART_IXR_BRK 0x80000000
134134
135+/*
136+ * Modem Control register:
137+ * The read/write Modem Control register controls the interface with the modem
138+ * or data set, or a peripheral device emulating a modem.
139+ */
140+#define CDNS_UART_MODEMCR_FCM 0x00000020 /* Automatic flow control mode */
141+#define CDNS_UART_MODEMCR_RTS 0x00000002 /* Request to send output control */
142+#define CDNS_UART_MODEMCR_DTR 0x00000001 /* Data Terminal Ready */
143+
135144 /*
136145 * Channel Status Register:
137146 * The channel status register (CSR) is provided to enable the control logic
@@ -915,7 +924,18 @@ static unsigned int cdns_uart_get_mctrl(struct uart_port *port) · 777 unmodified lines
915924
916925 static void cdns_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
917926 {
918− /* N/A */
927+ u32 val;
928+
929+ val = cdns_uart_readl(CDNS_UART_MODEMCR_OFFSET);
930+
931+ val &= ~(CDNS_UART_MODEMCR_RTS | CDNS_UART_MODEMCR_DTR);
932+
933+ if (mctrl & TIOCM_RTS)
934+ val |= CDNS_UART_MODEMCR_RTS;
935+ if (mctrl & TIOCM_DTR)
936+ val |= CDNS_UART_MODEMCR_DTR;
937+
938+ cdns_uart_writel(val, CDNS_UART_MODEMCR_OFFSET);
919939 }
920940
921941 #ifdef CONFIG_CONSOLE_POLL
drivers/tty/tty_buffer.c+8−2
@@ -202,14 +202,16 @@ static void tty_buffer_free(struct tty_port *port, struct tty_buffer *b) · 201 unmodified lines
202202 /**
203203 * tty_buffer_flush - flush full tty buffers
204204 * @tty: tty to flush
205+ * @ld: optional ldisc ptr (must be referenced)
205206 *
206− * flush all the buffers containing receive data.
207+ * flush all the buffers containing receive data. If ld != NULL,
208+ * flush the ldisc input buffer.
207209 *
208210 * Locking: takes buffer lock to ensure single-threaded flip buffer
209211 * 'consumer'
210212 */
211213
212−void tty_buffer_flush(struct tty_struct *tty)
214+void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld)
213215 {
214216 struct tty_port *port = tty->port;
215217 struct tty_bufhead *buf = &port->buf;
@@ -223,6 +225,10 @@ void tty_buffer_flush(struct tty_struct *tty) · 7 unmodified lines
223225 buf->head = next;
224226 }
225227 buf->head->read = buf->head->commit;
228+
229+ if (ld && ld->ops->flush_buffer)
230+ ld->ops->flush_buffer(tty);
231+
226232 atomic_dec(&buf->priority);
227233 mutex_unlock(&buf->lock);
228234 }
drivers/tty/tty_io.c+223−217
@@ -153,8 +153,6 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd, · 152 unmodified lines
153153 static int __tty_fasync(int fd, struct file *filp, int on);
154154 static int tty_fasync(int fd, struct file *filp, int on);
155155 static void release_tty(struct tty_struct *tty, int idx);
156−static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
157−static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
158156
159157 /**
160158 * free_tty_struct - free a disused tty
@@ -169,8 +167,7 @@ void free_tty_struct(struct tty_struct *tty) · 8 unmodified lines
169167 {
170168 if (!tty)
171169 return;
172− if (tty->dev)
173− put_device(tty->dev);
170+ put_device(tty->dev);
174171 kfree(tty->write_buf);
175172 tty->magic = 0xDEADDEAD;
176173 kfree(tty);
@@ -277,6 +274,7 @@ int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, · 100 unmodified lines
277274 return 0;
278275 }
279276
277+/* Caller must hold tty_lock */
280278 static int check_tty_count(struct tty_struct *tty, const char *routine)
281279 {
282280 #ifdef CHECK_TTY_COUNT
@@ -492,6 +490,78 @@ static const struct file_operations hung_up_tty_fops = { · 209 unmodified lines
492490 static DEFINE_SPINLOCK(redirect_lock);
493491 static struct file *redirect;
494492
493+
494+void proc_clear_tty(struct task_struct *p)
495+{
496+ unsigned long flags;
497+ struct tty_struct *tty;
498+ spin_lock_irqsave(&p->sighand->siglock, flags);
499+ tty = p->signal->tty;
500+ p->signal->tty = NULL;
501+ spin_unlock_irqrestore(&p->sighand->siglock, flags);
502+ tty_kref_put(tty);
503+}
504+
505+/**
506+ * proc_set_tty - set the controlling terminal
507+ *
508+ * Only callable by the session leader and only if it does not already have
509+ * a controlling terminal.
510+ *
511+ * Caller must hold: tty_lock()
512+ * a readlock on tasklist_lock
513+ * sighand lock
514+ */
515+static void __proc_set_tty(struct tty_struct *tty)
516+{
517+ unsigned long flags;
518+
519+ spin_lock_irqsave(&tty->ctrl_lock, flags);
520+ /*
521+ * The session and fg pgrp references will be non-NULL if
522+ * tiocsctty() is stealing the controlling tty
523+ */
524+ put_pid(tty->session);
525+ put_pid(tty->pgrp);
526+ tty->pgrp = get_pid(task_pgrp(current));
527+ spin_unlock_irqrestore(&tty->ctrl_lock, flags);
528+ tty->session = get_pid(task_session(current));
529+ if (current->signal->tty) {
530+ printk(KERN_DEBUG "tty not NULL!!\n");
531+ tty_kref_put(current->signal->tty);
532+ }
533+ put_pid(current->signal->tty_old_pgrp);
534+ current->signal->tty = tty_kref_get(tty);
535+ current->signal->tty_old_pgrp = NULL;
536+}
537+
538+static void proc_set_tty(struct tty_struct *tty)
539+{
540+ spin_lock_irq(&current->sighand->siglock);
541+ __proc_set_tty(tty);
542+ spin_unlock_irq(&current->sighand->siglock);
543+}
544+
545+struct tty_struct *get_current_tty(void)
546+{
547+ struct tty_struct *tty;
548+ unsigned long flags;
549+
550+ spin_lock_irqsave(&current->sighand->siglock, flags);
551+ tty = tty_kref_get(current->signal->tty);
552+ spin_unlock_irqrestore(&current->sighand->siglock, flags);
553+ return tty;
554+}
555+EXPORT_SYMBOL_GPL(get_current_tty);
556+
557+static void session_clear_tty(struct pid *session)
558+{
559+ struct task_struct *p;
560+ do_each_pid_task(session, PIDTYPE_SID, p) {
561+ proc_clear_tty(p);
562+ } while_each_pid_task(session, PIDTYPE_SID, p);
563+}
564+
495565 /**
496566 * tty_wakeup - request more data
497567 * @tty: terminal
@@ -620,9 +690,6 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session) · 122 unmodified lines
620690 return;
621691 }
622692
623− /* some functions below drop BTM, so we need this bit */
624− set_bit(TTY_HUPPING, &tty->flags);
625−
626693 /* inuse_filps is protected by the single tty lock,
627694 this really needs to change if we want to flush the
628695 workqueue with the lock held */
@@ -647,10 +714,6 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session) · 18 unmodified lines
647714 while (refs--)
648715 tty_kref_put(tty);
649716
650− /*
651− * it drops BTM and thus races with reopen
652− * we protect the race by TTY_HUPPING
653− */
654717 tty_ldisc_hangup(tty);
655718
656719 spin_lock_irq(&tty->ctrl_lock);
@@ -682,8 +745,6 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session) · 25 unmodified lines
682745 * can't yet guarantee all that.
683746 */
684747 set_bit(TTY_HUPPED, &tty->flags);
685− clear_bit(TTY_HUPPING, &tty->flags);
686−
687748 tty_unlock(tty);
688749
689750 if (f)
@@ -792,14 +853,6 @@ int tty_hung_up_p(struct file *filp) · 102 unmodified lines
792853
793854 EXPORT_SYMBOL(tty_hung_up_p);
794855
795−static void session_clear_tty(struct pid *session)
796−{
797− struct task_struct *p;
798− do_each_pid_task(session, PIDTYPE_SID, p) {
799− proc_clear_tty(p);
800− } while_each_pid_task(session, PIDTYPE_SID, p);
801−}
802−
803856 /**
804857 * disassociate_ctty - disconnect controlling tty
805858 * @on_exit: true if exiting so need to "hang up" the session
@@ -927,7 +980,7 @@ void __stop_tty(struct tty_struct *tty) · 121 unmodified lines
927980 return;
928981 tty->stopped = 1;
929982 if (tty->ops->stop)
930− (tty->ops->stop)(tty);
983+ tty->ops->stop(tty);
931984 }
932985
933986 void stop_tty(struct tty_struct *tty)
@@ -958,7 +1011,7 @@ void __start_tty(struct tty_struct *tty) · 24 unmodified lines
9581011 return;
9591012 tty->stopped = 0;
9601013 if (tty->ops->start)
961− (tty->ops->start)(tty);
1014+ tty->ops->start(tty);
9621015 tty_wakeup(tty);
9631016 }
9641017
@@ -1012,7 +1065,7 @@ static ssize_t tty_read(struct file *file, char __user *buf, size_t count, · 47 unmodified lines
10121065 situation */
10131066 ld = tty_ldisc_ref_wait(tty);
10141067 if (ld->ops->read)
1015− i = (ld->ops->read)(tty, file, buf, count);
1068+ i = ld->ops->read(tty, file, buf, count);
10161069 else
10171070 i = -EIO;
10181071 tty_ldisc_deref(ld);
@@ -1024,14 +1077,12 @@ static ssize_t tty_read(struct file *file, char __user *buf, size_t count, · 5 unmodified lines
10241077 }
10251078
10261079 static void tty_write_unlock(struct tty_struct *tty)
1027− __releases(&tty->atomic_write_lock)
10281080 {
10291081 mutex_unlock(&tty->atomic_write_lock);
10301082 wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
10311083 }
10321084
10331085 static int tty_write_lock(struct tty_struct *tty, int ndelay)
1034− __acquires(&tty->atomic_write_lock)
10351086 {
10361087 if (!mutex_trylock(&tty->atomic_write_lock)) {
10371088 if (ndelay)
@@ -1146,7 +1197,7 @@ void tty_write_message(struct tty_struct *tty, char *msg) · 108 unmodified lines
11461197 if (tty) {
11471198 mutex_lock(&tty->atomic_write_lock);
11481199 tty_lock(tty);
1149− if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) {
1200+ if (tty->ops->write && tty->count > 0) {
11501201 tty_unlock(tty);
11511202 tty->ops->write(tty, msg, strlen(msg));
11521203 } else
@@ -1293,19 +1344,24 @@ static ssize_t tty_line_name(struct tty_driver *driver, int index, char *p) · 140 unmodified lines
12931344 * @driver: the driver for the tty
12941345 * @idx: the minor number
12951346 *
1296− * Return the tty, if found or ERR_PTR() otherwise.
1347+ * Return the tty, if found. If not found, return NULL or ERR_PTR() if the
1348+ * driver lookup() method returns an error.
12971349 *
1298− * Locking: tty_mutex must be held. If tty is found, the mutex must
1299− * be held until the 'fast-open' is also done. Will change once we
1300− * have refcounting in the driver and per driver locking
1350+ * Locking: tty_mutex must be held. If the tty is found, bump the tty kref.
13011351 */
13021352 static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver,
13031353 struct inode *inode, int idx)
13041354 {
1355+ struct tty_struct *tty;
1356+
13051357 if (driver->ops->lookup)
1306− return driver->ops->lookup(driver, inode, idx);
1358+ tty = driver->ops->lookup(driver, inode, idx);
1359+ else
1360+ tty = driver->ttys[idx];
13071361
1308− return driver->ttys[idx];
1362+ if (!IS_ERR(tty))
1363+ tty_kref_get(tty);
1364+ return tty;
13091365 }
13101366
13111367 /**
@@ -1393,29 +1449,21 @@ void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct *tty) · 81 unmodified lines
13931449 * @tty - the tty to open
13941450 *
13951451 * Return 0 on success, -errno on error.
1452+ * Re-opens on master ptys are not allowed and return -EIO.
13961453 *
1397− * Locking: tty_mutex must be held from the time the tty was found
1398− * till this open completes.
1454+ * Locking: Caller must hold tty_lock
13991455 */
14001456 static int tty_reopen(struct tty_struct *tty)
14011457 {
14021458 struct tty_driver *driver = tty->driver;
14031459
1404− if (test_bit(TTY_CLOSING, &tty->flags) ||
1405− test_bit(TTY_HUPPING, &tty->flags))
1460+ if (!tty->count)
14061461 return -EIO;
14071462
14081463 if (driver->type == TTY_DRIVER_TYPE_PTY &&
1409− driver->subtype == PTY_TYPE_MASTER) {
1410− /*
1411− * special case for PTY masters: only one open permitted,
1412− * and the slave side open count is incremented as well.
1413− */
1414− if (tty->count)
1415− return -EIO;
1464+ driver->subtype == PTY_TYPE_MASTER)
1465+ return -EIO;
14161466
1417− tty->link->count++;
1418− }
14191467 tty->count++;
14201468
14211469 WARN_ON(!tty->ldisc);
@@ -1535,15 +1583,19 @@ void tty_free_termios(struct tty_struct *tty) · 113 unmodified lines
15351583 EXPORT_SYMBOL(tty_free_termios);
15361584
15371585 /**
1538− * tty_flush_works - flush all works of a tty
1539− * @tty: tty device to flush works for
1586+ * tty_flush_works - flush all works of a tty/pty pair
1587+ * @tty: tty device to flush works for (or either end of a pty pair)
15401588 *
1541− * Sync flush all works belonging to @tty.
1589+ * Sync flush all works belonging to @tty (and the 'other' tty).
15421590 */
15431591 static void tty_flush_works(struct tty_struct *tty)
15441592 {
15451593 flush_work(&tty->SAK_work);
15461594 flush_work(&tty->hangup_work);
1595+ if (tty->link) {
1596+ flush_work(&tty->link->SAK_work);
1597+ flush_work(&tty->link->hangup_work);
1598+ }
15471599 }
15481600
15491601 /**
@@ -1635,8 +1687,7 @@ static void release_tty(struct tty_struct *tty, int idx) · 85 unmodified lines
16351687 tty->link->port->itty = NULL;
16361688 cancel_work_sync(&tty->port->buf.work);
16371689
1638− if (tty->link)
1639− tty_kref_put(tty->link);
1690+ tty_kref_put(tty->link);
16401691 tty_kref_put(tty);
16411692 }
16421693
@@ -1649,8 +1700,7 @@ static void release_tty(struct tty_struct *tty, int idx) · 6 unmodified lines
16491700 * Performs some paranoid checking before true release of the @tty.
16501701 * This is a no-op unless TTY_PARANOIA_CHECK is defined.
16511702 */
1652−static int tty_release_checks(struct tty_struct *tty, struct tty_struct *o_tty,
1653− int idx)
1703+static int tty_release_checks(struct tty_struct *tty, int idx)
16541704 {
16551705 #ifdef TTY_PARANOIA_CHECK
16561706 if (idx < 0 || idx >= tty->driver->num) {
@@ -1669,6 +1719,8 @@ static int tty_release_checks(struct tty_struct *tty, struct tty_struct *o_tty, · 12 unmodified lines
16691719 return -1;
16701720 }
16711721 if (tty->driver->other) {
1722+ struct tty_struct *o_tty = tty->link;
1723+
16721724 if (o_tty != tty->driver->other->ttys[idx]) {
16731725 printk(KERN_DEBUG "%s: other->table[%d] not o_tty for (%s)\n",
16741726 __func__, idx, tty->name);
@@ -1705,8 +1757,8 @@ static int tty_release_checks(struct tty_struct *tty, struct tty_struct *o_tty, · 30 unmodified lines
17051757 int tty_release(struct inode *inode, struct file *filp)
17061758 {
17071759 struct tty_struct *tty = file_tty(filp);
1708− struct tty_struct *o_tty;
1709− int pty_master, tty_closing, o_tty_closing, do_sleep;
1760+ struct tty_struct *o_tty = NULL;
1761+ int do_sleep, final;
17101762 int idx;
17111763 char buf[64];
17121764 long timeout = 0;
@@ -1721,12 +1773,11 @@ int tty_release(struct inode *inode, struct file *filp) · 8 unmodified lines
17211773 __tty_fasync(-1, filp, 0);
17221774
17231775 idx = tty->index;
1724− pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1725− tty->driver->subtype == PTY_TYPE_MASTER);
1726− /* Review: parallel close */
1727− o_tty = tty->link;
1776+ if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1777+ tty->driver->subtype == PTY_TYPE_MASTER)
1778+ o_tty = tty->link;
17281779
1729− if (tty_release_checks(tty, o_tty, idx)) {
1780+ if (tty_release_checks(tty, idx)) {
17301781 tty_unlock(tty);
17311782 return 0;
17321783 }
@@ -1739,7 +1790,9 @@ int tty_release(struct inode *inode, struct file *filp) · 6 unmodified lines
17391790 if (tty->ops->close)
17401791 tty->ops->close(tty, filp);
17411792
1742− tty_unlock(tty);
1793+ /* If tty is pty master, lock the slave pty (stable lock order) */
1794+ tty_lock_slave(o_tty);
1795+
17431796 /*
17441797 * Sanity check: if tty->count is going to zero, there shouldn't be
17451798 * any waiters on tty->read_wait or tty->write_wait. We test the
@@ -1750,25 +1803,13 @@ int tty_release(struct inode *inode, struct file *filp) · 4 unmodified lines
17501803 * The test for the o_tty closing is necessary, since the master and
17511804 * slave sides may close in any order. If the slave side closes out
17521805 * first, its count will be one, since the master side holds an open.
1753− * Thus this test wouldn't be triggered at the time the slave closes,
1806+ * Thus this test wouldn't be triggered at the time the slave closed,
17541807 * so we do it now.
1755− *
1756− * Note that it's possible for the tty to be opened again while we're
1757− * flushing out waiters. By recalculating the closing flags before
1758− * each iteration we avoid any problems.
17591808 */
17601809 while (1) {
1761− /* Guard against races with tty->count changes elsewhere and
1762− opens on /dev/tty */
1763−
1764− mutex_lock(&tty_mutex);
1765− tty_lock_pair(tty, o_tty);
1766− tty_closing = tty->count <= 1;
1767− o_tty_closing = o_tty &&
1768− (o_tty->count <= (pty_master ? 1 : 0));
17691810 do_sleep = 0;
17701811
1771− if (tty_closing) {
1812+ if (tty->count <= 1) {
17721813 if (waitqueue_active(&tty->read_wait)) {
17731814 wake_up_poll(&tty->read_wait, POLLIN);
17741815 do_sleep++;
@@ -1778,7 +1819,7 @@ int tty_release(struct inode *inode, struct file *filp) · 3 unmodified lines
17781819 do_sleep++;
17791820 }
17801821 }
1781− if (o_tty_closing) {
1822+ if (o_tty && o_tty->count <= 1) {
17821823 if (waitqueue_active(&o_tty->read_wait)) {
17831824 wake_up_poll(&o_tty->read_wait, POLLIN);
17841825 do_sleep++;
@@ -1796,8 +1837,6 @@ int tty_release(struct inode *inode, struct file *filp) · 11 unmodified lines
17961837 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n",
17971838 __func__, tty_name(tty, buf));
17981839 }
1799− tty_unlock_pair(tty, o_tty);
1800− mutex_unlock(&tty_mutex);
18011840 schedule_timeout_killable(timeout);
18021841 if (timeout < 120 * HZ)
18031842 timeout = 2 * timeout + 1;
@@ -1805,15 +1844,7 @@ int tty_release(struct inode *inode, struct file *filp) · 1 unmodified line
18051844 timeout = MAX_SCHEDULE_TIMEOUT;
18061845 }
18071846
1808− /*
1809− * The closing flags are now consistent with the open counts on
1810− * both sides, and we've completed the last operation that could
1811− * block, so it's safe to proceed with closing.
1812− *
1813− * We must *not* drop the tty_mutex until we ensure that a further
1814− * entry into tty_open can not pick up this tty.
1815− */
1816− if (pty_master) {
1847+ if (o_tty) {
18171848 if (--o_tty->count < 0) {
18181849 printk(KERN_WARNING "%s: bad pty slave count (%d) for %s\n",
18191850 __func__, o_tty->count, tty_name(o_tty, buf));
@@ -1840,21 +1871,11 @@ int tty_release(struct inode *inode, struct file *filp) · 20 unmodified lines
18401871 /*
18411872 * Perform some housekeeping before deciding whether to return.
18421873 *
1843− * Set the TTY_CLOSING flag if this was the last open. In the
1844− * case of a pty we may have to wait around for the other side
1845− * to close, and TTY_CLOSING makes sure we can't be reopened.
1846− */
1847− if (tty_closing)
1848− set_bit(TTY_CLOSING, &tty->flags);
1849− if (o_tty_closing)
1850− set_bit(TTY_CLOSING, &o_tty->flags);
1851−
1852− /*
18531874 * If _either_ side is closing, make sure there aren't any
18541875 * processes that still think tty or o_tty is their controlling
18551876 * tty.
18561877 */
1857− if (tty_closing || o_tty_closing) {
1878+ if (!tty->count) {
18581879 read_lock(&tasklist_lock);
18591880 session_clear_tty(tty->session);
18601881 if (o_tty)
@@ -1862,13 +1883,16 @@ int tty_release(struct inode *inode, struct file *filp) · 1 unmodified line
18621883 read_unlock(&tasklist_lock);
18631884 }
18641885
1865− mutex_unlock(&tty_mutex);
1866− tty_unlock_pair(tty, o_tty);
1867− /* At this point the TTY_CLOSING flag should ensure a dead tty
1886+ /* check whether both sides are closing ... */
1887+ final = !tty->count && !(o_tty && o_tty->count);
1888+
1889+ tty_unlock_slave(o_tty);
1890+ tty_unlock(tty);
1891+
1892+ /* At this point, the tty->count == 0 should ensure a dead tty
18681893 cannot be re-opened by a racing opener */
18691894
1870− /* check whether both sides are closing ... */
1871− if (!tty_closing || (o_tty && !o_tty_closing))
1895+ if (!final)
18721896 return 0;
18731897
18741898 #ifdef TTY_DEBUG_HANGUP
@@ -1877,12 +1901,10 @@ int tty_release(struct inode *inode, struct file *filp) · 2 unmodified lines
18771901 /*
18781902 * Ask the line discipline code to release its structures
18791903 */
1880− tty_ldisc_release(tty, o_tty);
1904+ tty_ldisc_release(tty);
18811905
18821906 /* Wait for pending work before tty destruction commmences */
18831907 tty_flush_works(tty);
1884− if (o_tty)
1885− tty_flush_works(o_tty);
18861908
18871909 #ifdef TTY_DEBUG_HANGUP
18881910 printk(KERN_DEBUG "%s: %s: freeing structure...\n", __func__, tty_name(tty, buf));
@@ -1901,20 +1923,20 @@ int tty_release(struct inode *inode, struct file *filp) · 12 unmodified lines
19011923 }
19021924
19031925 /**
1904− * tty_open_current_tty - get tty of current task for open
1926+ * tty_open_current_tty - get locked tty of current task
19051927 * @device: device number
19061928 * @filp: file pointer to tty
1907− * @return: tty of the current task iff @device is /dev/tty
1929+ * @return: locked tty of the current task iff @device is /dev/tty
1930+ *
1931+ * Performs a re-open of the current task's controlling tty.
19081932 *
19091933 * We cannot return driver and index like for the other nodes because
19101934 * devpts will not work then. It expects inodes to be from devpts FS.
1911− *
1912− * We need to move to returning a refcounted object from all the lookup
1913− * paths including this one.
19141935 */
19151936 static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp)
19161937 {
19171938 struct tty_struct *tty;
1939+ int retval;
19181940
19191941 if (device != MKDEV(TTYAUX_MAJOR, 0))
19201942 return NULL;
@@ -1925,9 +1947,14 @@ static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp) · 4 unmodified lines
19251947
19261948 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
19271949 /* noctty = 1; */
1928− tty_kref_put(tty);
1929− /* FIXME: we put a reference and return a TTY! */
1930− /* This is only safe because the caller holds tty_mutex */
1950+ tty_lock(tty);
1951+ tty_kref_put(tty); /* safe to drop the kref now */
1952+
1953+ retval = tty_reopen(tty);
1954+ if (retval < 0) {
1955+ tty_unlock(tty);
1956+ tty = ERR_PTR(retval);
1957+ }
19311958 return tty;
19321959 }
19331960
@@ -2025,13 +2052,9 @@ retry_open: · 91 unmodified lines
20252052 index = -1;
20262053 retval = 0;
20272054
2028− mutex_lock(&tty_mutex);
2029− /* This is protected by the tty_mutex */
20302055 tty = tty_open_current_tty(device, filp);
2031− if (IS_ERR(tty)) {
2032− retval = PTR_ERR(tty);
2033− goto err_unlock;
2034− } else if (!tty) {
2056+ if (!tty) {
2057+ mutex_lock(&tty_mutex);
20352058 driver = tty_lookup_driver(device, filp, &noctty, &index);
20362059 if (IS_ERR(driver)) {
20372060 retval = PTR_ERR(driver);
@@ -2044,21 +2067,25 @@ retry_open: · 6 unmodified lines
20442067 retval = PTR_ERR(tty);
20452068 goto err_unlock;
20462069 }
2047− }
20482070
2049− if (tty) {
2050− tty_lock(tty);
2051− retval = tty_reopen(tty);
2052− if (retval < 0) {
2053− tty_unlock(tty);
2054− tty = ERR_PTR(retval);
2071+ if (tty) {
2072+ mutex_unlock(&tty_mutex);
2073+ tty_lock(tty);
2074+ /* safe to drop the kref from tty_driver_lookup_tty() */
2075+ tty_kref_put(tty);
2076+ retval = tty_reopen(tty);
2077+ if (retval < 0) {
2078+ tty_unlock(tty);
2079+ tty = ERR_PTR(retval);
2080+ }
2081+ } else { /* Returns with the tty_lock held for now */
2082+ tty = tty_init_dev(driver, index);
2083+ mutex_unlock(&tty_mutex);
20552084 }
2056− } else /* Returns with the tty_lock held for now */
2057− tty = tty_init_dev(driver, index);
20582085
2059− mutex_unlock(&tty_mutex);
2060− if (driver)
20612086 tty_driver_kref_put(driver);
2087+ }
2088+
20622089 if (IS_ERR(tty)) {
20632090 retval = PTR_ERR(tty);
20642091 goto err_file;
@@ -2100,25 +2127,23 @@ retry_open: · 35 unmodified lines
21002127 /*
21012128 * Need to reset f_op in case a hangup happened.
21022129 */
2103− if (filp->f_op == &hung_up_tty_fops)
2130+ if (tty_hung_up_p(filp))
21042131 filp->f_op = &tty_fops;
21052132 goto retry_open;
21062133 }
21072134 clear_bit(TTY_HUPPED, &tty->flags);
2108− tty_unlock(tty);
21092135
21102136
2111− mutex_lock(&tty_mutex);
2112− tty_lock(tty);
2137+ read_lock(&tasklist_lock);
21132138 spin_lock_irq(&current->sighand->siglock);
21142139 if (!noctty &&
21152140 current->signal->leader &&
21162141 !current->signal->tty &&
21172142 tty->session == NULL)
2118− __proc_set_tty(current, tty);
2143+ __proc_set_tty(tty);
21192144 spin_unlock_irq(&current->sighand->siglock);
2145+ read_unlock(&tasklist_lock);
21202146 tty_unlock(tty);
2121− mutex_unlock(&tty_mutex);
21222147 return 0;
21232148 err_unlock:
21242149 mutex_unlock(&tty_mutex);
@@ -2155,7 +2180,7 @@ static unsigned int tty_poll(struct file *filp, poll_table *wait) · 30 unmodified lines
21552180
21562181 ld = tty_ldisc_ref_wait(tty);
21572182 if (ld->ops->poll)
2158− ret = (ld->ops->poll)(tty, filp, wait);
2183+ ret = ld->ops->poll(tty, filp, wait);
21592184 tty_ldisc_deref(ld);
21602185 return ret;
21612186 }
@@ -2283,18 +2308,14 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg) · 121 unmodified lines
22832308 int tty_do_resize(struct tty_struct *tty, struct winsize *ws)
22842309 {
22852310 struct pid *pgrp;
2286− unsigned long flags;
22872311
22882312 /* Lock the tty */
22892313 mutex_lock(&tty->winsize_mutex);
22902314 if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
22912315 goto done;
2292− /* Get the PID values and reference them so we can
2293− avoid holding the tty ctrl lock while sending signals */
2294− spin_lock_irqsave(&tty->ctrl_lock, flags);
2295− pgrp = get_pid(tty->pgrp);
2296− spin_unlock_irqrestore(&tty->ctrl_lock, flags);
22972316
2317+ /* Signal the foreground process group */
2318+ pgrp = tty_get_pgrp(tty);
22982319 if (pgrp)
22992320 kill_pgrp(pgrp, SIGWINCH, 1);
23002321 put_pid(pgrp);
@@ -2403,7 +2424,7 @@ static int fionbio(struct file *file, int __user *p) · 102 unmodified lines
24032424 * leader to set this tty as the controlling tty for the session.
24042425 *
24052426 * Locking:
2406− * Takes tty_mutex() to protect tty instance
2427+ * Takes tty_lock() to serialize proc_set_tty() for this tty
24072428 * Takes tasklist_lock internally to walk sessions
24082429 * Takes ->siglock() when updating signal->tty
24092430 */
@@ -2411,10 +2432,13 @@ static int fionbio(struct file *file, int __user *p) · 1 unmodified line
24112432 static int tiocsctty(struct tty_struct *tty, int arg)
24122433 {
24132434 int ret = 0;
2435+
2436+ tty_lock(tty);
2437+ read_lock(&tasklist_lock);
2438+
24142439 if (current->signal->leader && (task_session(current) == tty->session))
2415− return ret;
2440+ goto unlock;
24162441
2417− mutex_lock(&tty_mutex);
24182442 /*
24192443 * The process must be a session leader and
24202444 * not have a controlling tty already.
@@ -2433,17 +2457,16 @@ static int tiocsctty(struct tty_struct *tty, int arg) · 12 unmodified lines
24332457 /*
24342458 * Steal it away
24352459 */
2436− read_lock(&tasklist_lock);
24372460 session_clear_tty(tty->session);
2438− read_unlock(&tasklist_lock);
24392461 } else {
24402462 ret = -EPERM;
24412463 goto unlock;
24422464 }
24432465 }
2444− proc_set_tty(current, tty);
2466+ proc_set_tty(tty);
24452467 unlock:
2446− mutex_unlock(&tty_mutex);
2468+ read_unlock(&tasklist_lock);
2469+ tty_unlock(tty);
24472470 return ret;
24482471 }
24492472
@@ -2468,6 +2491,27 @@ struct pid *tty_get_pgrp(struct tty_struct *tty) · 18 unmodified lines
24682491 }
24692492 EXPORT_SYMBOL_GPL(tty_get_pgrp);
24702493
2494+/*
2495+ * This checks not only the pgrp, but falls back on the pid if no
2496+ * satisfactory pgrp is found. I dunno - gdb doesn't work correctly
2497+ * without this...
2498+ *
2499+ * The caller must hold rcu lock or the tasklist lock.
2500+ */
2501+static struct pid *session_of_pgrp(struct pid *pgrp)
2502+{
2503+ struct task_struct *p;
2504+ struct pid *sid = NULL;
2505+
2506+ p = pid_task(pgrp, PIDTYPE_PGID);
2507+ if (p == NULL)
2508+ p = pid_task(pgrp, PIDTYPE_PID);
2509+ if (p != NULL)
2510+ sid = task_session(p);
2511+
2512+ return sid;
2513+}
2514+
24712515 /**
24722516 * tiocgpgrp - get process group
24732517 * @tty: tty passed by user
@@ -2714,23 +2758,35 @@ static int tty_tiocgicount(struct tty_struct *tty, void __user *arg) · 240 unmodified lines
27142758 return 0;
27152759 }
27162760
2717−struct tty_struct *tty_pair_get_tty(struct tty_struct *tty)
2761+static void tty_warn_deprecated_flags(struct serial_struct __user *ss)
27182762 {
2719− if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
2720− tty->driver->subtype == PTY_TYPE_MASTER)
2721− tty = tty->link;
2722− return tty;
2763+ static DEFINE_RATELIMIT_STATE(depr_flags,
2764+ DEFAULT_RATELIMIT_INTERVAL,
2765+ DEFAULT_RATELIMIT_BURST);
2766+ char comm[TASK_COMM_LEN];
2767+ int flags;
2768+
2769+ if (get_user(flags, &ss->flags))
2770+ return;
2771+
2772+ flags &= ASYNC_DEPRECATED;
2773+
2774+ if (flags && __ratelimit(&depr_flags))
2775+ pr_warning("%s: '%s' is using deprecated serial flags (with no effect): %.8x\n",
2776+ __func__, get_task_comm(comm, current), flags);
27232777 }
2724−EXPORT_SYMBOL(tty_pair_get_tty);
27252778
2726−struct tty_struct *tty_pair_get_pty(struct tty_struct *tty)
2779+/*
2780+ * if pty, return the slave side (real_tty)
2781+ * otherwise, return self
2782+ */
2783+static struct tty_struct *tty_pair_get_tty(struct tty_struct *tty)
27272784 {
27282785 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
27292786 tty->driver->subtype == PTY_TYPE_MASTER)
2730− return tty;
2731− return tty->link;
2787+ tty = tty->link;
2788+ return tty;
27322789 }
2733−EXPORT_SYMBOL(tty_pair_get_pty);
27342790
27352791 /*
27362792 * Split this up, as gcc can choke on it otherwise..
@@ -2859,13 +2915,16 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 122 unmodified lines
28592915 case TCIFLUSH:
28602916 case TCIOFLUSH:
28612917 /* flush tty buffer and allow ldisc to process ioctl */
2862− tty_buffer_flush(tty);
2918+ tty_buffer_flush(tty, NULL);
28632919 break;
28642920 }
28652921 break;
2922+ case TIOCSSERIAL:
2923+ tty_warn_deprecated_flags(p);
2924+ break;
28662925 }
28672926 if (tty->ops->ioctl) {
2868− retval = (tty->ops->ioctl)(tty, cmd, arg);
2927+ retval = tty->ops->ioctl(tty, cmd, arg);
28692928 if (retval != -ENOIOCTLCMD)
28702929 return retval;
28712930 }
@@ -2892,7 +2951,7 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd, · 20 unmodified lines
28922951 return -EINVAL;
28932952
28942953 if (tty->ops->compat_ioctl) {
2895− retval = (tty->ops->compat_ioctl)(tty, cmd, arg);
2954+ retval = tty->ops->compat_ioctl(tty, cmd, arg);
28962955 if (retval != -ENOIOCTLCMD)
28972956 return retval;
28982957 }
@@ -3443,59 +3502,6 @@ dev_t tty_devnum(struct tty_struct *tty) · 544 unmodified lines
34433502 }
34443503 EXPORT_SYMBOL(tty_devnum);
34453504
3446−void proc_clear_tty(struct task_struct *p)
3447−{
3448− unsigned long flags;
3449− struct tty_struct *tty;
3450− spin_lock_irqsave(&p->sighand->siglock, flags);
3451− tty = p->signal->tty;
3452− p->signal->tty = NULL;
3453− spin_unlock_irqrestore(&p->sighand->siglock, flags);
3454− tty_kref_put(tty);
3455−}
3456−
3457−/* Called under the sighand lock */
3458−
3459−static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3460−{
3461− if (tty) {
3462− unsigned long flags;
3463− /* We should not have a session or pgrp to put here but.... */
3464− spin_lock_irqsave(&tty->ctrl_lock, flags);
3465− put_pid(tty->session);
3466− put_pid(tty->pgrp);
3467− tty->pgrp = get_pid(task_pgrp(tsk));
3468− spin_unlock_irqrestore(&tty->ctrl_lock, flags);
3469− tty->session = get_pid(task_session(tsk));
3470− if (tsk->signal->tty) {
3471− printk(KERN_DEBUG "tty not NULL!!\n");
3472− tty_kref_put(tsk->signal->tty);
3473− }
3474− }
3475− put_pid(tsk->signal->tty_old_pgrp);
3476− tsk->signal->tty = tty_kref_get(tty);
3477− tsk->signal->tty_old_pgrp = NULL;
3478−}
3479−
3480−static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3481−{
3482− spin_lock_irq(&tsk->sighand->siglock);
3483− __proc_set_tty(tsk, tty);
3484− spin_unlock_irq(&tsk->sighand->siglock);
3485−}
3486−
3487−struct tty_struct *get_current_tty(void)
3488−{
3489− struct tty_struct *tty;
3490− unsigned long flags;
3491−
3492− spin_lock_irqsave(&current->sighand->siglock, flags);
3493− tty = tty_kref_get(current->signal->tty);
3494− spin_unlock_irqrestore(&current->sighand->siglock, flags);
3495− return tty;
3496−}
3497−EXPORT_SYMBOL_GPL(get_current_tty);
3498−
34993505 void tty_default_fops(struct file_operations *fops)
35003506 {
35013507 *fops = tty_fops;
drivers/tty/tty_ioctl.c+6−32
@@ -524,9 +524,8 @@ EXPORT_SYMBOL(tty_termios_hw_change); · 523 unmodified lines
524524 * @tty: tty to update
525525 * @new_termios: desired new value
526526 *
527− * Perform updates to the termios values set on this terminal. There
528− * is a bit of layering violation here with n_tty in terms of the
529− * internal knowledge of this function.
527+ * Perform updates to the termios values set on this terminal.
528+ * A master pty's termios should never be set.
530529 *
531530 * Locking: termios_rwsem
532531 */
@@ -535,8 +534,9 @@ int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) · 2 unmodified lines
535534 {
536535 struct ktermios old_termios;
537536 struct tty_ldisc *ld;
538− unsigned long flags;
539537
538+ WARN_ON(tty->driver->type == TTY_DRIVER_TYPE_PTY &&
539+ tty->driver->subtype == PTY_TYPE_MASTER);
540540 /*
541541 * Perform the actual termios internal changes under lock.
542542 */
@@ -549,41 +549,15 @@ int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) · 6 unmodified lines
549549 tty->termios = *new_termios;
550550 unset_locked_termios(&tty->termios, &old_termios, &tty->termios_locked);
551551
552− /* See if packet mode change of state. */
553− if (tty->link && tty->link->packet) {
554− int extproc = (old_termios.c_lflag & EXTPROC) |
555− (tty->termios.c_lflag & EXTPROC);
556− int old_flow = ((old_termios.c_iflag & IXON) &&
557− (old_termios.c_cc[VSTOP] == '\023') &&
558− (old_termios.c_cc[VSTART] == '\021'));
559− int new_flow = (I_IXON(tty) &&
560− STOP_CHAR(tty) == '\023' &&
561− START_CHAR(tty) == '\021');
562− if ((old_flow != new_flow) || extproc) {
563− spin_lock_irqsave(&tty->ctrl_lock, flags);
564− if (old_flow != new_flow) {
565− tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP);
566− if (new_flow)
567− tty->ctrl_status |= TIOCPKT_DOSTOP;
568− else
569− tty->ctrl_status |= TIOCPKT_NOSTOP;
570− }
571− if (extproc)
572− tty->ctrl_status |= TIOCPKT_IOCTL;
573− spin_unlock_irqrestore(&tty->ctrl_lock, flags);
574− wake_up_interruptible(&tty->link->read_wait);
575− }
576− }
577−
578552 if (tty->ops->set_termios)
579− (*tty->ops->set_termios)(tty, &old_termios);
553+ tty->ops->set_termios(tty, &old_termios);
580554 else
581555 tty_termios_copy_hw(&tty->termios, &old_termios);
582556
583557 ld = tty_ldisc_ref(tty);
584558 if (ld != NULL) {
585559 if (ld->ops->set_termios)
586− (ld->ops->set_termios)(tty, &old_termios);
560+ ld->ops->set_termios(tty, &old_termios);
587561 tty_ldisc_deref(ld);
588562 }
589563 up_write(&tty->termios_rwsem);
drivers/tty/tty_ldisc.c+56−55
@@ -308,23 +308,41 @@ EXPORT_SYMBOL_GPL(tty_ldisc_deref); · 307 unmodified lines
308308
309309
310310 static inline int __lockfunc
311−tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout)
311+__tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout)
312312 {
313313 return ldsem_down_write(&tty->ldisc_sem, timeout);
314314 }
315315
316316 static inline int __lockfunc
317−tty_ldisc_lock_nested(struct tty_struct *tty, unsigned long timeout)
317+__tty_ldisc_lock_nested(struct tty_struct *tty, unsigned long timeout)
318318 {
319319 return ldsem_down_write_nested(&tty->ldisc_sem,
320320 LDISC_SEM_OTHER, timeout);
321321 }
322322
323−static inline void tty_ldisc_unlock(struct tty_struct *tty)
323+static inline void __tty_ldisc_unlock(struct tty_struct *tty)
324324 {
325325 return ldsem_up_write(&tty->ldisc_sem);
326326 }
327327
328+static int __lockfunc
329+tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout)
330+{
331+ int ret;
332+
333+ ret = __tty_ldisc_lock(tty, timeout);
334+ if (!ret)
335+ return -EBUSY;
336+ set_bit(TTY_LDISC_HALTED, &tty->flags);
337+ return 0;
338+}
339+
340+static void tty_ldisc_unlock(struct tty_struct *tty)
341+{
342+ clear_bit(TTY_LDISC_HALTED, &tty->flags);
343+ __tty_ldisc_unlock(tty);
344+}
345+
328346 static int __lockfunc
329347 tty_ldisc_lock_pair_timeout(struct tty_struct *tty, struct tty_struct *tty2,
330348 unsigned long timeout)
@@ -332,24 +350,24 @@ tty_ldisc_lock_pair_timeout(struct tty_struct *tty, struct tty_struct *tty2, · 1 unmodified line
332350 int ret;
333351
334352 if (tty < tty2) {
335− ret = tty_ldisc_lock(tty, timeout);
353+ ret = __tty_ldisc_lock(tty, timeout);
336354 if (ret) {
337− ret = tty_ldisc_lock_nested(tty2, timeout);
355+ ret = __tty_ldisc_lock_nested(tty2, timeout);
338356 if (!ret)
339− tty_ldisc_unlock(tty);
357+ __tty_ldisc_unlock(tty);
340358 }
341359 } else {
342360 /* if this is possible, it has lots of implications */
343361 WARN_ON_ONCE(tty == tty2);
344362 if (tty2 && tty != tty2) {
345− ret = tty_ldisc_lock(tty2, timeout);
363+ ret = __tty_ldisc_lock(tty2, timeout);
346364 if (ret) {
347− ret = tty_ldisc_lock_nested(tty, timeout);
365+ ret = __tty_ldisc_lock_nested(tty, timeout);
348366 if (!ret)
349− tty_ldisc_unlock(tty2);
367+ __tty_ldisc_unlock(tty2);
350368 }
351369 } else
352− ret = tty_ldisc_lock(tty, timeout);
370+ ret = __tty_ldisc_lock(tty, timeout);
353371 }
354372
355373 if (!ret)
@@ -370,38 +388,26 @@ tty_ldisc_lock_pair(struct tty_struct *tty, struct tty_struct *tty2) · 14 unmodified lines
370388 static void __lockfunc tty_ldisc_unlock_pair(struct tty_struct *tty,
371389 struct tty_struct *tty2)
372390 {
373− tty_ldisc_unlock(tty);
374− if (tty2)
375− tty_ldisc_unlock(tty2);
376−}
377−
378−static void __lockfunc tty_ldisc_enable_pair(struct tty_struct *tty,
379− struct tty_struct *tty2)
380−{
381− clear_bit(TTY_LDISC_HALTED, &tty->flags);
391+ __tty_ldisc_unlock(tty);
382392 if (tty2)
383− clear_bit(TTY_LDISC_HALTED, &tty2->flags);
384−
385− tty_ldisc_unlock_pair(tty, tty2);
393+ __tty_ldisc_unlock(tty2);
386394 }
387395
388396 /**
389397 * tty_ldisc_flush - flush line discipline queue
390398 * @tty: tty
391399 *
392− * Flush the line discipline queue (if any) for this tty. If there
393− * is no line discipline active this is a no-op.
400+ * Flush the line discipline queue (if any) and the tty flip buffers
401+ * for this tty.
394402 */
395403
396404 void tty_ldisc_flush(struct tty_struct *tty)
397405 {
398406 struct tty_ldisc *ld = tty_ldisc_ref(tty);
399− if (ld) {
400− if (ld->ops->flush_buffer)
401− ld->ops->flush_buffer(tty);
407+
408+ tty_buffer_flush(tty, ld);
409+ if (ld)
402410 tty_ldisc_deref(ld);
403− }
404− tty_buffer_flush(tty);
405411 }
406412 EXPORT_SYMBOL_GPL(tty_ldisc_flush);
407413
@@ -517,15 +523,16 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) · 109 unmodified lines
517523 {
518524 int retval;
519525 struct tty_ldisc *old_ldisc, *new_ldisc;
520− struct tty_struct *o_tty = tty->link;
521526
522527 new_ldisc = tty_ldisc_get(tty, ldisc);
523528 if (IS_ERR(new_ldisc))
524529 return PTR_ERR(new_ldisc);
525530
526− retval = tty_ldisc_lock_pair_timeout(tty, o_tty, 5 * HZ);
531+ tty_lock(tty);
532+ retval = tty_ldisc_lock(tty, 5 * HZ);
527533 if (retval) {
528534 tty_ldisc_put(new_ldisc);
535+ tty_unlock(tty);
529536 return retval;
530537 }
531538
@@ -534,19 +541,18 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) · 2 unmodified lines
534541 */
535542
536543 if (tty->ldisc->ops->num == ldisc) {
537− tty_ldisc_enable_pair(tty, o_tty);
544+ tty_ldisc_unlock(tty);
538545 tty_ldisc_put(new_ldisc);
546+ tty_unlock(tty);
539547 return 0;
540548 }
541549
542550 old_ldisc = tty->ldisc;
543− tty_lock(tty);
544551
545− if (test_bit(TTY_HUPPING, &tty->flags) ||
546− test_bit(TTY_HUPPED, &tty->flags)) {
552+ if (test_bit(TTY_HUPPED, &tty->flags)) {
547553 /* We were raced by the hangup method. It will have stomped
548554 the ldisc data and closed the ldisc down */
549− tty_ldisc_enable_pair(tty, o_tty);
555+ tty_ldisc_unlock(tty);
550556 tty_ldisc_put(new_ldisc);
551557 tty_unlock(tty);
552558 return -EIO;
@@ -566,8 +572,11 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) · 13 unmodified lines
566572 tty_ldisc_restore(tty, old_ldisc);
567573 }
568574
569− if (tty->ldisc->ops->num != old_ldisc->ops->num && tty->ops->set_ldisc)
575+ if (tty->ldisc->ops->num != old_ldisc->ops->num && tty->ops->set_ldisc) {
576+ down_read(&tty->termios_rwsem);
570577 tty->ops->set_ldisc(tty);
578+ up_read(&tty->termios_rwsem);
579+ }
571580
572581 /* At this point we hold a reference to the new ldisc and a
573582 reference to the old ldisc, or we hold two references to
@@ -580,13 +589,11 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) · 6 unmodified lines
580589 /*
581590 * Allow ldisc referencing to occur again
582591 */
583− tty_ldisc_enable_pair(tty, o_tty);
592+ tty_ldisc_unlock(tty);
584593
585594 /* Restart the work queue in case no characters kick it off. Safe if
586595 already running */
587596 schedule_work(&tty->port->buf.work);
588− if (o_tty)
589− schedule_work(&o_tty->port->buf.work);
590597
591598 tty_unlock(tty);
592599 return retval;
@@ -675,16 +682,13 @@ void tty_ldisc_hangup(struct tty_struct *tty) · 82 unmodified lines
675682 wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
676683 wake_up_interruptible_poll(&tty->read_wait, POLLIN);
677684
678− tty_unlock(tty);
679−
680685 /*
681686 * Shutdown the current line discipline, and reset it to
682687 * N_TTY if need be.
683688 *
684689 * Avoid racing set_ldisc or tty_ldisc_release
685690 */
686− tty_ldisc_lock_pair(tty, tty->link);
687− tty_lock(tty);
691+ tty_ldisc_lock(tty, MAX_SCHEDULE_TIMEOUT);
688692
689693 if (tty->ldisc) {
690694
@@ -706,7 +710,7 @@ void tty_ldisc_hangup(struct tty_struct *tty) · 15 unmodified lines
706710 WARN_ON(tty_ldisc_open(tty, tty->ldisc));
707711 }
708712 }
709− tty_ldisc_enable_pair(tty, tty->link);
713+ tty_ldisc_unlock(tty);
710714 if (reset)
711715 tty_reset_termios(tty);
712716
@@ -758,16 +762,17 @@ static void tty_ldisc_kill(struct tty_struct *tty) · 45 unmodified lines
758762
759763 /**
760764 * tty_ldisc_release - release line discipline
761− * @tty: tty being shut down
762− * @o_tty: pair tty for pty/tty pairs
765+ * @tty: tty being shut down (or one end of pty pair)
763766 *
764− * Called during the final close of a tty/pty pair in order to shut down
765− * the line discpline layer. On exit the ldisc assigned is N_TTY and the
766− * ldisc has not been opened.
767+ * Called during the final close of a tty or a pty pair in order to shut
768+ * down the line discpline layer. On exit, each ldisc assigned is N_TTY and
769+ * each ldisc has not been opened.
767770 */
768771
769−void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
772+void tty_ldisc_release(struct tty_struct *tty)
770773 {
774+ struct tty_struct *o_tty = tty->link;
775+
771776 /*
772777 * Shutdown this line discipline. As this is the final close,
773778 * it does not race with the set_ldisc code path.
@@ -776,13 +781,9 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) · 2 unmodified lines
776781 tty_ldisc_debug(tty, "closing ldisc: %p\n", tty->ldisc);
777782
778783 tty_ldisc_lock_pair(tty, o_tty);
779− tty_lock_pair(tty, o_tty);
780−
781784 tty_ldisc_kill(tty);
782785 if (o_tty)
783786 tty_ldisc_kill(o_tty);
784−
785− tty_unlock_pair(tty, o_tty);
786787 tty_ldisc_unlock_pair(tty, o_tty);
787788
788789 /* And the memory resources remaining (buffers, termios) will be
drivers/tty/tty_mutex.c+21−28
@@ -4,19 +4,23 @@ · 3 unmodified lines
44 #include <linux/semaphore.h>
55 #include <linux/sched.h>
66
7+/*
8+ * Nested tty locks are necessary for releasing pty pairs.
9+ * The stable lock order is master pty first, then slave pty.
10+ */
11+
712 /* Legacy tty mutex glue */
813
914 enum {
1015 TTY_MUTEX_NORMAL,
11− TTY_MUTEX_NESTED,
16+ TTY_MUTEX_SLAVE,
1217 };
1318
1419 /*
1520 * Getting the big tty mutex.
1621 */
1722
18−static void __lockfunc tty_lock_nested(struct tty_struct *tty,
19− unsigned int subclass)
23+void __lockfunc tty_lock(struct tty_struct *tty)
2024 {
2125 if (tty->magic != TTY_MAGIC) {
2226 pr_err("L Bad %p\n", tty);
@@ -24,12 +28,7 @@ static void __lockfunc tty_lock_nested(struct tty_struct *tty, · 1 unmodified line
2428 return;
2529 }
2630 tty_kref_get(tty);
27− mutex_lock_nested(&tty->legacy_mutex, subclass);
28−}
29−
30−void __lockfunc tty_lock(struct tty_struct *tty)
31−{
32− return tty_lock_nested(tty, TTY_MUTEX_NORMAL);
31+ mutex_lock(&tty->legacy_mutex);
3332 }
3433 EXPORT_SYMBOL(tty_lock);
3534
@@ -45,29 +44,23 @@ void __lockfunc tty_unlock(struct tty_struct *tty) · 9 unmodified lines
4544 }
4645 EXPORT_SYMBOL(tty_unlock);
4746
48−/*
49− * Getting the big tty mutex for a pair of ttys with lock ordering
50− * On a non pty/tty pair tty2 can be NULL which is just fine.
51− */
52−void __lockfunc tty_lock_pair(struct tty_struct *tty,
53− struct tty_struct *tty2)
47+void __lockfunc tty_lock_slave(struct tty_struct *tty)
5448 {
55− if (tty < tty2) {
49+ if (tty && tty != tty->link) {
50+ WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) ||
51+ !tty->driver->type == TTY_DRIVER_TYPE_PTY ||
52+ !tty->driver->type == PTY_TYPE_SLAVE);
5653 tty_lock(tty);
57− tty_lock_nested(tty2, TTY_MUTEX_NESTED);
58− } else {
59− if (tty2 && tty2 != tty)
60− tty_lock(tty2);
61− tty_lock_nested(tty, TTY_MUTEX_NESTED);
6254 }
6355 }
64−EXPORT_SYMBOL(tty_lock_pair);
6556
66−void __lockfunc tty_unlock_pair(struct tty_struct *tty,
67− struct tty_struct *tty2)
57+void __lockfunc tty_unlock_slave(struct tty_struct *tty)
58+{
59+ if (tty && tty != tty->link)
60+ tty_unlock(tty);
61+}
62+
63+void tty_set_lock_subclass(struct tty_struct *tty)
6864 {
69− tty_unlock(tty);
70− if (tty2 && tty2 != tty)
71− tty_unlock(tty2);
65+ lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE);
7266 }
73−EXPORT_SYMBOL(tty_unlock_pair);
drivers/tty/tty_port.c+4−6
@@ -193,8 +193,7 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) · 192 unmodified lines
193193 unsigned long flags;
194194
195195 spin_lock_irqsave(&port->lock, flags);
196− if (port->tty)
197− tty_kref_put(port->tty);
196+ tty_kref_put(port->tty);
198197 port->tty = tty_kref_get(tty);
199198 spin_unlock_irqrestore(&port->lock, flags);
200199 }
@@ -473,12 +472,10 @@ int tty_port_close_start(struct tty_port *port, · 272 unmodified lines
473472 {
474473 unsigned long flags;
475474
476− spin_lock_irqsave(&port->lock, flags);
477− if (tty_hung_up_p(filp)) {
478− spin_unlock_irqrestore(&port->lock, flags);
475+ if (tty_hung_up_p(filp))
479476 return 0;
480− }
481477
478+ spin_lock_irqsave(&port->lock, flags);
482479 if (tty->count == 1 && port->count != 1) {
483480 printk(KERN_WARNING
484481 "tty_port_close_start: tty->count = 1 port count = %d.\n",
@@ -522,6 +519,7 @@ void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) · 37 unmodified lines
522519 {
523520 unsigned long flags;
524521
522+ tty_ldisc_flush(tty);
525523 tty->closing = 0;
526524
527525 spin_lock_irqsave(&port->lock, flags);
drivers/tty/vt/keyboard.c+3−3
@@ -924,7 +924,7 @@ static void k_brl(struct vc_data *vc, unsigned char value, char up_flag) · 923 unmodified lines
924924
925925 if (kbd->kbdmode != VC_UNICODE) {
926926 if (!up_flag)
927− pr_warning("keyboard mode must be unicode for braille patterns\n");
927+ pr_warn("keyboard mode must be unicode for braille patterns\n");
928928 return;
929929 }
930930
@@ -1253,8 +1253,8 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) · 322 unmodified lines
12531253 if (raw_mode && !hw_raw)
12541254 if (emulate_raw(vc, keycode, !down << 7))
12551255 if (keycode < BTN_MISC && printk_ratelimit())
1256− pr_warning("can't emulate rawmode for keycode %d\n",
1257− keycode);
1256+ pr_warn("can't emulate rawmode for keycode %d\n",
1257+ keycode);
12581258
12591259 #ifdef CONFIG_SPARC
12601260 if (keycode == KEY_A && sparc_l1_a_state) {
drivers/tty/vt/vt.c+14−8
@@ -156,6 +156,8 @@ static void console_callback(struct work_struct *ignored); · 155 unmodified lines
156156 static void blank_screen_t(unsigned long dummy);
157157 static void set_palette(struct vc_data *vc);
158158
159+#define vt_get_kmsg_redirect() vt_kmsg_redirect(-1)
160+
159161 static int printable; /* Is console ready for printing? */
160162 int default_utf8 = true;
161163 module_param(default_utf8, int, S_IRUGO | S_IWUSR);
@@ -1367,9 +1369,11 @@ static void csi_m(struct vc_data *vc) · 1205 unmodified lines
13671369 rgb_from_256(vc->vc_par[i]));
13681370 } else if (vc->vc_par[i] == 2 && /* 24 bit */
13691371 i <= vc->vc_npar + 3) {/* extremely rare */
1370− struct rgb c = {r:vc->vc_par[i+1],
1371− g:vc->vc_par[i+2],
1372− b:vc->vc_par[i+3]};
1372+ struct rgb c = {
1373+ .r = vc->vc_par[i + 1],
1374+ .g = vc->vc_par[i + 2],
1375+ .b = vc->vc_par[i + 3],
1376+ };
13731377 rgb_foreground(vc, c);
13741378 i += 3;
13751379 }
@@ -1388,9 +1392,11 @@ static void csi_m(struct vc_data *vc) · 12 unmodified lines
13881392 rgb_from_256(vc->vc_par[i]));
13891393 } else if (vc->vc_par[i] == 2 && /* 24 bit */
13901394 i <= vc->vc_npar + 3) {
1391− struct rgb c = {r:vc->vc_par[i+1],
1392− g:vc->vc_par[i+2],
1393− b:vc->vc_par[i+3]};
1395+ struct rgb c = {
1396+ .r = vc->vc_par[i + 1],
1397+ .g = vc->vc_par[i + 2],
1398+ .b = vc->vc_par[i + 3],
1399+ };
13941400 rgb_background(vc, c);
13951401 i += 3;
13961402 }
@@ -3849,8 +3855,8 @@ void do_unblank_screen(int leaving_gfx) · 2452 unmodified lines
38493855 return;
38503856 if (!vc_cons_allocated(fg_console)) {
38513857 /* impossible */
3852− pr_warning("unblank_screen: tty %d not allocated ??\n",
3853− fg_console+1);
3858+ pr_warn("unblank_screen: tty %d not allocated ??\n",
3859+ fg_console + 1);
38543860 return;
38553861 }
38563862 vc = vc_cons[fg_console].d;
include/linux/kernel.h+0−3
@@ -416,9 +416,6 @@ extern int __kernel_text_address(unsigned long addr); · 415 unmodified lines
416416 extern int kernel_text_address(unsigned long addr);
417417 extern int func_ptr_is_kernel_text(void *ptr);
418418
419−struct pid;
420−extern struct pid *session_of_pgrp(struct pid *pgrp);
421−
422419 unsigned long int_sqrt(unsigned long);
423420
424421 extern void bust_spinlocks(int yes);
include/linux/serial_8250.h+0−3
@@ -97,13 +97,10 @@ struct uart_8250_port { · 96 unmodified lines
9797 unsigned char msr_saved_flags;
9898
9999 struct uart_8250_dma *dma;
100− struct serial_rs485 rs485;
101100
102101 /* 8250 specific callbacks */
103102 int (*dl_read)(struct uart_8250_port *);
104103 void (*dl_write)(struct uart_8250_port *, int);
105− int (*rs485_config)(struct uart_8250_port *,
106− struct serial_rs485 *rs485);
107104 };
108105
109106 static inline struct uart_8250_port *up_to_u8250p(struct uart_port *up)
include/linux/serial_bcm63xx.h+0−2
@@ -116,6 +116,4 @@ · 115 unmodified lines
116116 UART_FIFO_PARERR_MASK | \
117117 UART_FIFO_BRKDET_MASK)
118118
119−#define UART_REG_SIZE 24
120−
121119 #endif /* _LINUX_SERIAL_BCM63XX_H */
include/linux/serial_core.h+44−23
@@ -63,7 +63,7 @@ struct uart_ops { · 62 unmodified lines
6363 void (*flush_buffer)(struct uart_port *);
6464 void (*set_termios)(struct uart_port *, struct ktermios *new,
6565 struct ktermios *old);
66− void (*set_ldisc)(struct uart_port *, int new);
66+ void (*set_ldisc)(struct uart_port *, struct ktermios *);
6767 void (*pm)(struct uart_port *, unsigned int state,
6868 unsigned int oldstate);
6969
@@ -131,6 +131,8 @@ struct uart_port { · 61 unmodified lines
131131 void (*pm)(struct uart_port *, unsigned int state,
132132 unsigned int old);
133133 void (*handle_break)(struct uart_port *);
134+ int (*rs485_config)(struct uart_port *,
135+ struct serial_rs485 *rs485);
134136 unsigned int irq; /* irq number */
135137 unsigned long irqflags; /* irq flags */
136138 unsigned int uartclk; /* base uart clock */
@@ -140,12 +142,13 @@ struct uart_port { · 3 unmodified lines
140142 unsigned char iotype; /* io access style */
141143 unsigned char unused1;
142144
143−#define UPIO_PORT (0)
144−#define UPIO_HUB6 (1)
145−#define UPIO_MEM (2)
146−#define UPIO_MEM32 (3)
147−#define UPIO_AU (4) /* Au1x00 and RT288x type IO */
148−#define UPIO_TSI (5) /* Tsi108/109 type IO */
145+#define UPIO_PORT (0) /* 8b I/O port access */
146+#define UPIO_HUB6 (1) /* Hub6 ISA card */
147+#define UPIO_MEM (2) /* 8b MMIO access */
148+#define UPIO_MEM32 (3) /* 32b little endian */
149+#define UPIO_MEM32BE (4) /* 32b big endian */
150+#define UPIO_AU (5) /* Au1x00 and RT288x type IO */
151+#define UPIO_TSI (6) /* Tsi108/109 type IO */
149152
150153 unsigned int read_status_mask; /* driver specific */
151154 unsigned int ignore_status_mask; /* driver specific */
@@ -160,21 +163,33 @@ struct uart_port { · 8 unmodified lines
160163 /* flags must be updated while holding port mutex */
161164 upf_t flags;
162165
163−#define UPF_FOURPORT ((__force upf_t) (1 << 1))
164−#define UPF_SAK ((__force upf_t) (1 << 2))
165−#define UPF_SPD_MASK ((__force upf_t) (0x1030))
166−#define UPF_SPD_HI ((__force upf_t) (0x0010))
167−#define UPF_SPD_VHI ((__force upf_t) (0x0020))
168−#define UPF_SPD_CUST ((__force upf_t) (0x0030))
169−#define UPF_SPD_SHI ((__force upf_t) (0x1000))
170−#define UPF_SPD_WARP ((__force upf_t) (0x1010))
171−#define UPF_SKIP_TEST ((__force upf_t) (1 << 6))
172−#define UPF_AUTO_IRQ ((__force upf_t) (1 << 7))
173−#define UPF_HARDPPS_CD ((__force upf_t) (1 << 11))
174−#define UPF_LOW_LATENCY ((__force upf_t) (1 << 13))
175−#define UPF_BUGGY_UART ((__force upf_t) (1 << 14))
166+ /*
167+ * These flags must be equivalent to the flags defined in
168+ * include/uapi/linux/tty_flags.h which are the userspace definitions
169+ * assigned from the serial_struct flags in uart_set_info()
170+ * [for bit definitions in the UPF_CHANGE_MASK]
171+ *
172+ * Bits [0..UPF_LAST_USER] are userspace defined/visible/changeable
173+ * except bit 15 (UPF_NO_TXEN_TEST) which is masked off.
174+ * The remaining bits are serial-core specific and not modifiable by
175+ * userspace.
176+ */
177+#define UPF_FOURPORT ((__force upf_t) ASYNC_FOURPORT /* 1 */ )
178+#define UPF_SAK ((__force upf_t) ASYNC_SAK /* 2 */ )
179+#define UPF_SPD_HI ((__force upf_t) ASYNC_SPD_HI /* 4 */ )
180+#define UPF_SPD_VHI ((__force upf_t) ASYNC_SPD_VHI /* 5 */ )
181+#define UPF_SPD_CUST ((__force upf_t) ASYNC_SPD_CUST /* 0x0030 */ )
182+#define UPF_SPD_WARP ((__force upf_t) ASYNC_SPD_WARP /* 0x1010 */ )
183+#define UPF_SPD_MASK ((__force upf_t) ASYNC_SPD_MASK /* 0x1030 */ )
184+#define UPF_SKIP_TEST ((__force upf_t) ASYNC_SKIP_TEST /* 6 */ )
185+#define UPF_AUTO_IRQ ((__force upf_t) ASYNC_AUTO_IRQ /* 7 */ )
186+#define UPF_HARDPPS_CD ((__force upf_t) ASYNC_HARDPPS_CD /* 11 */ )
187+#define UPF_SPD_SHI ((__force upf_t) ASYNC_SPD_SHI /* 12 */ )
188+#define UPF_LOW_LATENCY ((__force upf_t) ASYNC_LOW_LATENCY /* 13 */ )
189+#define UPF_BUGGY_UART ((__force upf_t) ASYNC_BUGGY_UART /* 14 */ )
176190 #define UPF_NO_TXEN_TEST ((__force upf_t) (1 << 15))
177−#define UPF_MAGIC_MULTIPLIER ((__force upf_t) (1 << 16))
191+#define UPF_MAGIC_MULTIPLIER ((__force upf_t) ASYNC_MAGIC_MULTIPLIER /* 16 */ )
192+
178193 /* Port has hardware-assisted h/w flow control (iow, auto-RTS *not* auto-CTS) */
179194 #define UPF_HARD_FLOW ((__force upf_t) (1 << 21))
180195 /* Port has hardware-assisted s/w flow control */
@@ -190,9 +205,14 @@ struct uart_port { · 9 unmodified lines
190205 #define UPF_DEAD ((__force upf_t) (1 << 30))
191206 #define UPF_IOREMAP ((__force upf_t) (1 << 31))
192207
193−#define UPF_CHANGE_MASK ((__force upf_t) (0x17fff))
208+#define __UPF_CHANGE_MASK 0x17fff
209+#define UPF_CHANGE_MASK ((__force upf_t) __UPF_CHANGE_MASK)
194210 #define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY))
195211
212+#if __UPF_CHANGE_MASK > ASYNC_FLAGS
213+#error Change mask not equivalent to userspace-visible bit defines
214+#endif
215+
196216 /* status must be updated while holding port lock */
197217 upstat_t status;
198218
@@ -214,6 +234,7 @@ struct uart_port { · 15 unmodified lines
214234 unsigned char unused[2];
215235 struct attribute_group *attr_group; /* port specific attributes */
216236 const struct attribute_group **tty_groups; /* all attributes (serial core use only) */
237+ struct serial_rs485 rs485;
217238 void *private_data; /* generic platform data pointer */
218239 };
219240
@@ -367,7 +388,7 @@ static inline int uart_tx_stopped(struct uart_port *port) · 147 unmodified lines
367388
368389 static inline bool uart_cts_enabled(struct uart_port *uport)
369390 {
370− return uport->status & UPSTAT_CTS_ENABLE;
391+ return !!(uport->status & UPSTAT_CTS_ENABLE);
371392 }
372393
373394 /*
include/linux/tty.h+6−22
@@ -284,7 +284,7 @@ struct tty_struct { · 283 unmodified lines
284284
285285 #define N_TTY_BUF_SIZE 4096
286286
287− unsigned char closing:1;
287+ int closing;
288288 unsigned char *write_buf;
289289 int write_cnt;
290290 /* If the tty has a pending do_SAK, queue it here - akpm */
@@ -316,12 +316,10 @@ struct tty_file_private { · 25 unmodified lines
316316 #define TTY_EXCLUSIVE 3 /* Exclusive open mode */
317317 #define TTY_DEBUG 4 /* Debugging */
318318 #define TTY_DO_WRITE_WAKEUP 5 /* Call write_wakeup after queuing new */
319−#define TTY_CLOSING 7 /* ->close() in progress */
320319 #define TTY_LDISC_OPEN 11 /* Line discipline is open */
321320 #define TTY_PTY_LOCK 16 /* pty private */
322321 #define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */
323322 #define TTY_HUPPED 18 /* Post driver->hangup() */
324−#define TTY_HUPPING 21 /* ->hangup() in progress */
325323 #define TTY_LDISC_HALTED 22 /* Line discipline is halted */
326324
327325 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
@@ -437,14 +435,13 @@ extern int is_ignored(int sig); · 109 unmodified lines
437435 extern int tty_signal(int sig, struct tty_struct *tty);
438436 extern void tty_hangup(struct tty_struct *tty);
439437 extern void tty_vhangup(struct tty_struct *tty);
440−extern void tty_unhangup(struct file *filp);
441438 extern int tty_hung_up_p(struct file *filp);
442439 extern void do_SAK(struct tty_struct *tty);
443440 extern void __do_SAK(struct tty_struct *tty);
444441 extern void no_tty(void);
445442 extern void tty_flush_to_ldisc(struct tty_struct *tty);
446443 extern void tty_buffer_free_all(struct tty_port *port);
447−extern void tty_buffer_flush(struct tty_struct *tty);
444+extern void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld);
448445 extern void tty_buffer_init(struct tty_port *port);
449446 extern speed_t tty_termios_baud_rate(struct ktermios *termios);
450447 extern speed_t tty_termios_input_baud_rate(struct ktermios *termios);
@@ -498,9 +495,6 @@ extern int tty_init_termios(struct tty_struct *tty); · 47 unmodified lines
498495 extern int tty_standard_install(struct tty_driver *driver,
499496 struct tty_struct *tty);
500497
501−extern struct tty_struct *tty_pair_get_tty(struct tty_struct *tty);
502−extern struct tty_struct *tty_pair_get_pty(struct tty_struct *tty);
503−
504498 extern struct mutex tty_mutex;
505499 extern spinlock_t tty_files_lock;
506500
@@ -562,7 +556,7 @@ extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc); · 55 unmodified lines
562556 extern int tty_unregister_ldisc(int disc);
563557 extern int tty_set_ldisc(struct tty_struct *tty, int ldisc);
564558 extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);
565−extern void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty);
559+extern void tty_ldisc_release(struct tty_struct *tty);
566560 extern void tty_ldisc_init(struct tty_struct *tty);
567561 extern void tty_ldisc_deinit(struct tty_struct *tty);
568562 extern void tty_ldisc_begin(void);
@@ -623,14 +617,6 @@ extern int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file, · 54 unmodified lines
623617 extern long n_tty_compat_ioctl_helper(struct tty_struct *tty, struct file *file,
624618 unsigned int cmd, unsigned long arg);
625619
626−/* serial.c */
627−
628−extern void serial_console_init(void);
629−
630−/* pcxx.c */
631−
632−extern int pcxe_open(struct tty_struct *tty, struct file *filp);
633−
634620 /* vt.c */
635621
636622 extern int vt_ioctl(struct tty_struct *tty,
@@ -643,11 +629,9 @@ extern long vt_compat_ioctl(struct tty_struct *tty, · 6 unmodified lines
643629 /* functions for preparation of BKL removal */
644630 extern void __lockfunc tty_lock(struct tty_struct *tty);
645631 extern void __lockfunc tty_unlock(struct tty_struct *tty);
646−extern void __lockfunc tty_lock_pair(struct tty_struct *tty,
647− struct tty_struct *tty2);
648−extern void __lockfunc tty_unlock_pair(struct tty_struct *tty,
649− struct tty_struct *tty2);
650−
632+extern void __lockfunc tty_lock_slave(struct tty_struct *tty);
633+extern void __lockfunc tty_unlock_slave(struct tty_struct *tty);
634+extern void tty_set_lock_subclass(struct tty_struct *tty);
651635 /*
652636 * this shall be called only from where BTM is held (like close)
653637 *
include/uapi/linux/serial_core.h+2−1
@@ -54,7 +54,8 @@ · 53 unmodified lines
5454 #define PORT_ALTR_16550_F32 26 /* Altera 16550 UART with 32 FIFOs */
5555 #define PORT_ALTR_16550_F64 27 /* Altera 16550 UART with 64 FIFOs */
5656 #define PORT_ALTR_16550_F128 28 /* Altera 16550 UART with 128 FIFOs */
57−#define PORT_MAX_8250 28 /* max port ID */
57+#define PORT_RT2880 29 /* Ralink RT2880 internal UART */
58+#define PORT_MAX_8250 29 /* max port ID */
5859
5960 /*
6061 * ARM specific type numbers. These are not currently guaranteed
include/uapi/linux/serial_reg.h+1−0
@@ -359,6 +359,7 @@ · 358 unmodified lines
359359 #define UART_OMAP_SYSC 0x15 /* System configuration register */
360360 #define UART_OMAP_SYSS 0x16 /* System status register */
361361 #define UART_OMAP_WER 0x17 /* Wake-up enable register */
362+#define UART_OMAP_TX_LVL 0x1a /* TX FIFO level register */
362363
363364 /*
364365 * These are the definitions for the MDR1 register
include/uapi/linux/tty_flags.h+13−6
@@ -6,27 +6,31 @@ · 5 unmodified lines
66 * shared by the tty_port flags structures.
77 *
88 * Define ASYNCB_* for convenient use with {test,set,clear}_bit.
9+ *
10+ * Bits [0..ASYNCB_LAST_USER] are userspace defined/visible/changeable
11+ * [x] in the bit comments indicates the flag is defunct and no longer used.
912 */
1013 #define ASYNCB_HUP_NOTIFY 0 /* Notify getty on hangups and closes
1114 * on the callout port */
1215 #define ASYNCB_FOURPORT 1 /* Set OU1, OUT2 per AST Fourport settings */
1316 #define ASYNCB_SAK 2 /* Secure Attention Key (Orange book) */
14−#define ASYNCB_SPLIT_TERMIOS 3 /* Separate termios for dialin/callout */
17+#define ASYNCB_SPLIT_TERMIOS 3 /* [x] Separate termios for dialin/callout */
1518 #define ASYNCB_SPD_HI 4 /* Use 56000 instead of 38400 bps */
1619 #define ASYNCB_SPD_VHI 5 /* Use 115200 instead of 38400 bps */
1720 #define ASYNCB_SKIP_TEST 6 /* Skip UART test during autoconfiguration */
1821 #define ASYNCB_AUTO_IRQ 7 /* Do automatic IRQ during
1922 * autoconfiguration */
20−#define ASYNCB_SESSION_LOCKOUT 8 /* Lock out cua opens based on session */
21−#define ASYNCB_PGRP_LOCKOUT 9 /* Lock out cua opens based on pgrp */
22−#define ASYNCB_CALLOUT_NOHUP 10 /* Don't do hangups for cua device */
23+#define ASYNCB_SESSION_LOCKOUT 8 /* [x] Lock out cua opens based on session */
24+#define ASYNCB_PGRP_LOCKOUT 9 /* [x] Lock out cua opens based on pgrp */
25+#define ASYNCB_CALLOUT_NOHUP 10 /* [x] Don't do hangups for cua device */
2326 #define ASYNCB_HARDPPS_CD 11 /* Call hardpps when CD goes high */
2427 #define ASYNCB_SPD_SHI 12 /* Use 230400 instead of 38400 bps */
2528 #define ASYNCB_LOW_LATENCY 13 /* Request low latency behaviour */
2629 #define ASYNCB_BUGGY_UART 14 /* This is a buggy UART, skip some safety
2730 * checks. Note: can be dangerous! */
28−#define ASYNCB_AUTOPROBE 15 /* Port was autoprobed by PCI or PNP code */
29−#define ASYNCB_LAST_USER 15
31+#define ASYNCB_AUTOPROBE 15 /* [x] Port was autoprobed by PCI/PNP code */
32+#define ASYNCB_MAGIC_MULTIPLIER 16 /* Use special CLK or divisor */
33+#define ASYNCB_LAST_USER 16
3034
3135 /* Internal flags used only by kernel */
3236 #define ASYNCB_INITIALIZED 31 /* Serial port was initialized */
@@ -57,8 +61,11 @@ · 24 unmodified lines
5761 #define ASYNC_LOW_LATENCY (1U << ASYNCB_LOW_LATENCY)
5862 #define ASYNC_BUGGY_UART (1U << ASYNCB_BUGGY_UART)
5963 #define ASYNC_AUTOPROBE (1U << ASYNCB_AUTOPROBE)
64+#define ASYNC_MAGIC_MULTIPLIER (1U << ASYNCB_MAGIC_MULTIPLIER)
6065
6166 #define ASYNC_FLAGS ((1U << (ASYNCB_LAST_USER + 1)) - 1)
67+#define ASYNC_DEPRECATED (ASYNC_SESSION_LOCKOUT | ASYNC_PGRP_LOCKOUT | \
68+ ASYNC_CALLOUT_NOHUP | ASYNC_AUTOPROBE)
6269 #define ASYNC_USR_MASK (ASYNC_SPD_MASK|ASYNC_CALLOUT_NOHUP| \
6370 ASYNC_LOW_LATENCY)
6471 #define ASYNC_SPD_CUST (ASYNC_SPD_HI|ASYNC_SPD_VHI)
include/uapi/linux/vt.h+0−3
@@ -84,7 +84,4 @@ struct vt_setactivate { · 83 unmodified lines
8484
8585 #define VT_SETACTIVATE 0x560F /* Activate and set the mode of a console */
8686
87−
88−#define vt_get_kmsg_redirect() vt_kmsg_redirect(-1)
89−
9087 #endif /* _UAPI_LINUX_VT_H */
kernel/exit.c+0−21
@@ -211,27 +211,6 @@ repeat: · 210 unmodified lines
211211 goto repeat;
212212 }
213213
214−/*
215− * This checks not only the pgrp, but falls back on the pid if no
216− * satisfactory pgrp is found. I dunno - gdb doesn't work correctly
217− * without this...
218− *
219− * The caller must hold rcu lock or the tasklist lock.
220− */
221−struct pid *session_of_pgrp(struct pid *pgrp)
222−{
223− struct task_struct *p;
224− struct pid *sid = NULL;
225−
226− p = pid_task(pgrp, PIDTYPE_PGID);
227− if (p == NULL)
228− p = pid_task(pgrp, PIDTYPE_PID);
229− if (p != NULL)
230− sid = task_session(p);
231−
232− return sid;
233−}
234−
235214 /*
236215 * Determine if a process group is "orphaned", according to the POSIX
237216 * definition in 2.2.2.52. Orphaned process groups are not to be affected