History

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

Pull tty / serial driver updates from Greg KH: "Here is the big set of TTY/Serial driver updates and cleanups for 6.9-rc1. Included in here are: - more tty cleanups from Jiri - loads of 8250 driver cleanups from Andy - max310x driver updates - samsung serial driver updates - uart_prepare_sysrq_char() updates for many drivers - platform driver remove callback void cleanups - stm32 driver updates - other small tty/serial driver updates All of these have been in linux-next for a long time with no reported issues" * tag 'tty-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (199 commits) dt-bindings: serial: stm32: add power-domains property serial: 8250_dw: Replace ACPI device check by a quirk serial: Lock console when calling into driver before registration serial: 8250_uniphier: Switch to use uart_read_port_properties() serial: 8250_tegra: Switch to use uart_read_port_properties() serial: 8250_pxa: Switch to use uart_read_port_properties() serial: 8250_omap: Switch to use uart_read_port_properties() serial: 8250_of: Switch to use uart_read_port_properties() serial: 8250_lpc18xx: Switch to use uart_read_port_properties() serial: 8250_ingenic: Switch to use uart_read_port_properties() serial: 8250_dw: Switch to use uart_read_port_properties() serial: 8250_bcm7271: Switch to use uart_read_port_properties() serial: 8250_bcm2835aux: Switch to use uart_read_port_properties() serial: 8250_aspeed_vuart: Switch to use uart_read_port_properties() serial: port: Introduce a common helper to read properties serial: core: Add UPIO_UNKNOWN constant for unknown port type serial: core: Move struct uart_port::quirks closer to possible values serial: sh-sci: Call sci_serial_{in,out}() directly serial: core: only stop transmit when HW fifo is empty serial: pch: Use uart_prepare_sysrq_char(). ...

Linus Torvalds committed 2 years ago

Commit 3bcb0bf2 parents e09bf86 d6c0d89122 files · +3545 −2524Browse files

Unified · Split

122 files
  1. Documentation/devicetree/bindings/serial/cdns,uart.yaml +1 −0
  2. Documentation/devicetree/bindings/serial/fsl-lpuart.yaml +1 −0
  3. Documentation/devicetree/bindings/serial/renesas,hscif.yaml +1 −0
  4. Documentation/devicetree/bindings/serial/samsung_uart.yaml +2 −0
  5. Documentation/devicetree/bindings/serial/serial.yaml +1 −1
  6. Documentation/devicetree/bindings/serial/st,asc.yaml +55 −0
  7. Documentation/devicetree/bindings/serial/st,stm32-uart.yaml +3 −0
  8. Documentation/devicetree/bindings/serial/st-asc.txt +0 −18
  9. Documentation/devicetree/bindings/w1/w1-uart.yaml +59 −0
  10. Documentation/driver-api/tty/console.rst +45 −0
  11. Documentation/driver-api/tty/index.rst +1 −0
  12. Documentation/w1/masters/index.rst +1 −0
  13. Documentation/w1/masters/w1-uart.rst +54 −0
  14. arch/m68k/amiga/config.c +1 −1
  15. arch/m68k/hp300/config.c +1 −5
  16. drivers/bluetooth/btmtkuart.c +2 −2
  17. drivers/bluetooth/btnxpuart.c +2 −2
  18. drivers/bluetooth/hci_serdev.c +2 −2
  19. drivers/gnss/serial.c +1 −1
  20. drivers/gnss/sirf.c +1 −1
  21. drivers/greybus/gb-beagleplay.c +3 −3
  22. drivers/iio/chemical/pms7003.c +2 −2
  23. drivers/iio/chemical/scd30_serial.c +2 −2
  24. drivers/iio/chemical/sps30_serial.c +2 −2
  25. drivers/iio/imu/bno055/bno055_ser_core.c +2 −2
  26. drivers/input/keyboard/amikbd.c +3 −3
  27. drivers/mfd/rave-sp.c +2 −2
  28. drivers/net/ethernet/qualcomm/qca_uart.c +1 −1
  29. drivers/nfc/pn533/uart.c +2 −2
  30. drivers/nfc/s3fwrn5/uart.c +2 −2
  31. drivers/platform/chrome/cros_ec_uart.c +2 −2
  32. drivers/platform/surface/aggregator/core.c +2 −2
  33. drivers/tty/Kconfig +1 −6
  34. drivers/tty/amiserial.c +2 −4
  35. drivers/tty/goldfish.c +2 −3
  36. drivers/tty/hvc/hvc_iucv.c +5 −1
  37. drivers/tty/serdev/core.c +1 −1
  38. drivers/tty/serdev/serdev-ttyport.c +4 −6
  39. drivers/tty/serial/8250/8250_aspeed_vuart.c +15 −35
  40. drivers/tty/serial/8250/8250_bcm2835aux.c +43 −51
  41. drivers/tty/serial/8250/8250_bcm7271.c +27 −46
  42. drivers/tty/serial/8250/8250_dw.c +55 −66
  43. drivers/tty/serial/8250/8250_exar.c +27 −25
  44. drivers/tty/serial/8250/8250_ingenic.c +7 −13
  45. drivers/tty/serial/8250/8250_lpc18xx.c +8 −12
  46. drivers/tty/serial/8250/8250_of.c +61 −82
  47. drivers/tty/serial/8250/8250_omap.c +10 −19
  48. drivers/tty/serial/8250/8250_pci1xxxx.c +162 −13
  49. drivers/tty/serial/8250/8250_port.c +1 −49
  50. drivers/tty/serial/8250/8250_pxa.c +9 −13
  51. drivers/tty/serial/8250/8250_tegra.c +9 −17
  52. drivers/tty/serial/8250/8250_uniphier.c +4 −13
  53. drivers/tty/serial/8250/Kconfig +1 −0
  54. drivers/tty/serial/amba-pl011.c +8 −16
  55. drivers/tty/serial/ar933x_uart.c +6 −12
  56. drivers/tty/serial/bcm63xx_uart.c +8 −16
  57. drivers/tty/serial/fsl_linflexuart.c +0 −1
  58. drivers/tty/serial/jsm/jsm_cls.c +0 −1
  59. drivers/tty/serial/lpc32xx_hs.c +7 −12
  60. drivers/tty/serial/max310x.c +165 −164
  61. drivers/tty/serial/mcf.c +0 −27
  62. drivers/tty/serial/meson_uart.c +8 −14
  63. drivers/tty/serial/msm_serial.c +10 −23
  64. drivers/tty/serial/omap-serial.c +6 −10
  65. drivers/tty/serial/owl-uart.c +12 −18
  66. drivers/tty/serial/pch_uart.c +19 −51
  67. drivers/tty/serial/pmac_zilog.c +2 −7
  68. drivers/tty/serial/pxa.c +6 −11
  69. drivers/tty/serial/qcom_geni_serial.c +13 −14
  70. drivers/tty/serial/rda-uart.c +10 −18
  71. drivers/tty/serial/samsung_tty.c +153 −117
  72. drivers/tty/serial/serial_base_bus.c +1 −1
  73. drivers/tty/serial/serial_core.c +12 −0
  74. drivers/tty/serial/serial_port.c +145 −0
  75. drivers/tty/serial/serial_txx9.c +2 −1
  76. drivers/tty/serial/sh-sci.c +119 −126
  77. drivers/tty/serial/sifive.c +7 −10
  78. drivers/tty/serial/st-asc.c +24 −16
  79. drivers/tty/serial/stm32-usart.c +136 −87
  80. drivers/tty/serial/stm32-usart.h +24 −14
  81. drivers/tty/serial/sunplus-uart.c +6 −12
  82. drivers/tty/serial/xilinx_uartps.c +215 −21
  83. drivers/tty/tty_buffer.c +1 −0
  84. drivers/tty/vt/Makefile +2 −2
  85. drivers/tty/vt/selection.c +26 −17
  86. drivers/tty/vt/vt.c +831 −700
  87. drivers/tty/vt/vt_ioctl.c +2 −4
  88. drivers/video/console/dummycon.c +21 −17
  89. drivers/video/console/mdacon.c +15 −28
  90. drivers/video/console/newport_con.c +35 −34
  91. drivers/video/console/sticon.c +32 −47
  92. drivers/video/console/vgacon.c +88 −64
  93. drivers/video/fbdev/core/bitblit.c +2 −11
  94. drivers/video/fbdev/core/fbcon.c +44 −79
  95. drivers/video/fbdev/core/fbcon.h +2 −2
  96. drivers/video/fbdev/core/fbcon_ccw.c +2 −11
  97. drivers/video/fbdev/core/fbcon_cw.c +2 −11
  98. drivers/video/fbdev/core/fbcon_ud.c +2 −11
  99. drivers/video/fbdev/core/tileblit.c +2 −2
  100. drivers/video/fbdev/tgafb.c +1 −1
  101. drivers/w1/masters/Kconfig +10 −0
  102. drivers/w1/masters/Makefile +1 −0
  103. drivers/w1/masters/mxc_w1.c +2 −4
  104. drivers/w1/masters/omap_hdq.c +2 −4
  105. drivers/w1/masters/sgi_w1.c +2 −4
  106. drivers/w1/masters/w1-gpio.c +2 −4
  107. drivers/w1/masters/w1-uart.c +415 −0
  108. drivers/w1/w1.c +1 −1
  109. include/linux/console.h +69 −57
  110. include/linux/console_struct.h +0 −1
  111. include/linux/selection.h +26 −30
  112. include/linux/serdev.h +4 −4
  113. include/linux/serial_8250.h +6 −0
  114. include/linux/serial_core.h +9 −3
  115. include/linux/soc/qcom/geni-se.h +1 −0
  116. include/linux/tty.h +0 −1
  117. include/linux/vt_kern.h +8 −4
  118. include/uapi/linux/fb.h +1 −7
  119. include/uapi/linux/vesa.h +18 −0
  120. kernel/printk/printk.c +18 −3
  121. lib/Kconfig.kgdb +1 −1
  122. sound/drivers/serial-generic.c +2 −2
Documentation/devicetree/bindings/serial/cdns,uart.yaml+1−0
@@ -55,6 +55,7 @@ required: · 54 unmodified lines
5555
5656 allOf:
5757 - $ref: serial.yaml#
58+ - $ref: rs485.yaml#
5859 - if:
5960 properties:
6061 compatible:
Documentation/devicetree/bindings/serial/fsl-lpuart.yaml+1−0
@@ -30,6 +30,7 @@ properties: · 29 unmodified lines
3030 - items:
3131 - enum:
3232 - fsl,imx93-lpuart
33+ - fsl,imx95-lpuart
3334 - const: fsl,imx8ulp-lpuart
3435 - const: fsl,imx7ulp-lpuart
3536 - items:
Documentation/devicetree/bindings/serial/renesas,hscif.yaml+1−0
@@ -59,6 +59,7 @@ properties: · 58 unmodified lines
5959 - renesas,hscif-r8a779a0 # R-Car V3U
6060 - renesas,hscif-r8a779f0 # R-Car S4-8
6161 - renesas,hscif-r8a779g0 # R-Car V4H
62+ - renesas,hscif-r8a779h0 # R-Car V4M
6263 - const: renesas,rcar-gen4-hscif # R-Car Gen4
6364 - const: renesas,hscif # generic HSCIF compatible UART
6465
Documentation/devicetree/bindings/serial/samsung_uart.yaml+2−0
@@ -143,6 +143,8 @@ allOf: · 142 unmodified lines
143143 then:
144144 required:
145145 - samsung,uart-fifosize
146+ properties:
147+ reg-io-width: false
146148
147149 unevaluatedProperties: false
148150
Documentation/devicetree/bindings/serial/serial.yaml+1−1
@@ -88,7 +88,7 @@ properties: · 87 unmodified lines
8888 TX FIFO threshold configuration (in bytes).
8989
9090 patternProperties:
91− "^(bluetooth|bluetooth-gnss|gnss|gps|mcu)$":
91+ "^(bluetooth|bluetooth-gnss|gnss|gps|mcu|onewire)$":
9292 if:
9393 type: object
9494 then:
Documentation/devicetree/bindings/serial/st,asc.yaml+55−0
@@ -0,0 +1,55 @@
1+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/serial/st,asc.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: STMicroelectronics STi SoCs Serial Port
8+
9+maintainers:
10+ - Patrice Chotard <patrice.chotard@foss.st.com>
11+
12+allOf:
13+ - $ref: serial.yaml#
14+
15+properties:
16+ compatible:
17+ const: st,asc
18+
19+ reg:
20+ maxItems: 1
21+
22+ interrupts:
23+ maxItems: 1
24+
25+ clocks:
26+ maxItems: 1
27+
28+ st,hw-flow-ctrl:
29+ description: When set, enable hardware flow control.
30+ type: boolean
31+
32+ st,force-m1:
33+ description: When set, force asc to be in Mode-1. This is recommended for
34+ high bit rates above 19.2K.
35+ type: boolean
36+
37+required:
38+ - compatible
39+ - reg
40+ - interrupts
41+ - clocks
42+
43+unevaluatedProperties: false
44+
45+examples:
46+ - |
47+ #include <dt-bindings/clock/stih407-clks.h>
48+ #include <dt-bindings/interrupt-controller/arm-gic.h>
49+ serial@9830000 {
50+ compatible = "st,asc";
51+ reg = <0x9830000 0x2c>;
52+ interrupts = <GIC_SPI 122 IRQ_TYPE_LEVEL_HIGH>;
53+ clocks = <&clk_s_c0_flexgen CLK_EXT2F_A9>;
54+ };
55+...
Documentation/devicetree/bindings/serial/st,stm32-uart.yaml+3−0
@@ -58,6 +58,9 @@ properties: · 57 unmodified lines
5858
5959 wakeup-source: true
6060
61+ power-domains:
62+ maxItems: 1
63+
6164 rx-threshold:
6265 description:
6366 If value is set to 1, RX FIFO threshold is disabled.
Documentation/devicetree/bindings/serial/st-asc.txt+0−18
@@ -1,18 +0,0 @@
1−*st-asc(Serial Port)
2−
3−Required properties:
4−- compatible : Should be "st,asc".
5−- reg, reg-names, interrupts, interrupt-names : Standard way to define device
6− resources with names. look in
7− Documentation/devicetree/bindings/resource-names.txt
8−
9−Optional properties:
10−- st,hw-flow-ctrl bool flag to enable hardware flow control.
11−- st,force-m1 bool flat to force asc to be in Mode-1 recommended
12− for high bit rates (above 19.2K)
13−Example:
14−serial@fe440000{
15− compatible = "st,asc";
16− reg = <0xfe440000 0x2c>;
17− interrupts = <0 209 0>;
18−};
Documentation/devicetree/bindings/w1/w1-uart.yaml+59−0
@@ -0,0 +1,59 @@
1+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: UART 1-Wire Bus
8+
9+maintainers:
10+ - Christoph Winklhofer <cj.winklhofer@gmail.com>
11+
12+description: |
13+ UART 1-wire bus. Utilizes the UART interface via the Serial Device Bus
14+ to create the 1-Wire timing patterns.
15+
16+ The UART peripheral must support full-duplex and operate in open-drain
17+ mode. The timing patterns are generated by a specific combination of
18+ baud-rate and transmitted byte, which corresponds to a 1-Wire read bit,
19+ write bit or reset pulse.
20+
21+ The default baud-rate for reset and presence detection is 9600 and for
22+ a 1-Wire read or write operation 115200. In case the actual baud-rate
23+ is different from the requested one, the transmitted byte is adapted
24+ to generate the 1-Wire timing patterns.
25+
26+ https://www.analog.com/en/technical-articles/using-a-uart-to-implement-a-1wire-bus-master.html
27+
28+properties:
29+ compatible:
30+ const: w1-uart
31+
32+ reset-bps:
33+ default: 9600
34+ description:
35+ The baud rate for the 1-Wire reset and presence detect.
36+
37+ write-0-bps:
38+ default: 115200
39+ description:
40+ The baud rate for the 1-Wire write-0 cycle.
41+
42+ write-1-bps:
43+ default: 115200
44+ description:
45+ The baud rate for the 1-Wire write-1 and read cycle.
46+
47+required:
48+ - compatible
49+
50+additionalProperties:
51+ type: object
52+
53+examples:
54+ - |
55+ serial {
56+ onewire {
57+ compatible = "w1-uart";
58+ };
59+ };
Documentation/driver-api/tty/console.rst+45−0
@@ -0,0 +1,45 @@
1+.. SPDX-License-Identifier: GPL-2.0
2+
3+=======
4+Console
5+=======
6+
7+.. contents:: :local:
8+
9+Struct Console
10+==============
11+
12+.. kernel-doc:: include/linux/console.h
13+ :identifiers: console cons_flags
14+
15+Internals
16+---------
17+
18+.. kernel-doc:: include/linux/console.h
19+ :identifiers: nbcon_state nbcon_prio nbcon_context nbcon_write_context
20+
21+Struct Consw
22+============
23+
24+.. kernel-doc:: include/linux/console.h
25+ :identifiers: consw
26+
27+Console functions
28+=================
29+
30+.. kernel-doc:: include/linux/console.h
31+ :identifiers: console_srcu_read_flags console_srcu_write_flags
32+ console_is_registered for_each_console_srcu for_each_console
33+
34+.. kernel-doc:: drivers/tty/vt/selection.c
35+ :export:
36+.. kernel-doc:: drivers/tty/vt/vt.c
37+ :export:
38+
39+Internals
40+---------
41+
42+.. kernel-doc:: drivers/tty/vt/selection.c
43+ :internal:
44+.. kernel-doc:: drivers/tty/vt/vt.c
45+ :internal:
Documentation/driver-api/tty/index.rst+1−0
@@ -38,6 +38,7 @@ In-detail description of the named TTY structures is in separate documents: · 37 unmodified lines
3838 tty_buffer
3939 tty_ioctl
4040 tty_internals
41+ console
4142
4243 Writing TTY Driver
4344 ==================
Documentation/w1/masters/index.rst+1−0
@@ -12,3 +12,4 @@ · 11 unmodified lines
1212 mxc-w1
1313 omap-hdq
1414 w1-gpio
15+ w1-uart
Documentation/w1/masters/w1-uart.rst+54−0
@@ -0,0 +1,54 @@
1+.. SPDX-License-Identifier: GPL-2.0-or-later
2+
3+=====================
4+Kernel driver w1-uart
5+=====================
6+
7+Author: Christoph Winklhofer <cj.winklhofer@gmail.com>
8+
9+
10+Description
11+-----------
12+
13+UART 1-Wire bus driver. The driver utilizes the UART interface via the
14+Serial Device Bus to create the 1-Wire timing patterns as described in
15+the document `"Using a UART to Implement a 1-Wire Bus Master"`_.
16+
17+.. _"Using a UART to Implement a 1-Wire Bus Master": https://www.analog.com/en/technical-articles/using-a-uart-to-implement-a-1wire-bus-master.html
18+
19+In short, the UART peripheral must support full-duplex and operate in
20+open-drain mode. The timing patterns are generated by a specific
21+combination of baud-rate and transmitted byte, which corresponds to a
22+1-Wire read bit, write bit or reset pulse.
23+
24+For instance the timing pattern for a 1-Wire reset and presence detect uses
25+the baud-rate 9600, i.e. 104.2 us per bit. The transmitted byte 0xf0 over
26+UART (least significant bit first, start-bit low) sets the reset low time
27+for 1-Wire to 521 us. A present 1-Wire device changes the received byte by
28+pulling the line low, which is used by the driver to evaluate the result of
29+the 1-Wire operation.
30+
31+Similar for a 1-Wire read bit or write bit, which uses the baud-rate
32+115200, i.e. 8.7 us per bit. The transmitted byte 0x80 is used for a
33+Write-0 operation (low time 69.6us) and the byte 0xff for Read-0, Read-1
34+and Write-1 (low time 8.7us).
35+
36+The default baud-rate for reset and presence detection is 9600 and for
37+a 1-Wire read or write operation 115200. In case the actual baud-rate
38+is different from the requested one, the transmitted byte is adapted
39+to generate the 1-Wire timing patterns.
40+
41+
42+Usage
43+-----
44+
45+Specify the UART 1-wire bus in the device tree by adding the single child
46+onewire to the serial node (e.g. uart0). For example:
47+::
48+
49+ @uart0 {
50+ ...
51+ onewire {
52+ compatible = "w1-uart";
53+ };
54+ };
arch/m68k/amiga/config.c+1−1
@@ -846,6 +846,6 @@ static void amiga_get_hardware_list(struct seq_file *m) · 845 unmodified lines
846846 * The Amiga keyboard driver needs key_maps, but we cannot export it in
847847 * drivers/char/defkeymap.c, as it is autogenerated
848848 */
849−#ifdef CONFIG_HW_CONSOLE
849+#ifdef CONFIG_VT
850850 EXPORT_SYMBOL_GPL(key_maps);
851851 #endif
arch/m68k/hp300/config.c+1−5
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010
1111 #include <linux/module.h>
1212 #include <linux/init.h>
13+#include <linux/serial_8250.h>
1314 #include <linux/string.h>
1415 #include <linux/kernel.h>
1516 #include <linux/console.h>
@@ -67,9 +68,6 @@ static char *hp300_models[] __initdata = { · 51 unmodified lines
6768 static char hp300_model_name[13] = "HP9000/";
6869
6970 extern void hp300_reset(void);
70−#ifdef CONFIG_SERIAL_8250_CONSOLE
71−extern int hp300_setup_serial_console(void) __init;
72−#endif
7371
7472 int __init hp300_parse_bootinfo(const struct bi_record *record)
7573 {
@@ -263,7 +261,5 @@ void __init config_hp300(void) · 187 unmodified lines
263261 } else {
264262 panic("Unknown HP9000 Model");
265263 }
266−#ifdef CONFIG_SERIAL_8250_CONSOLE
267264 hp300_setup_serial_console();
268−#endif
269265 }
drivers/bluetooth/btmtkuart.c+2−2
@@ -383,8 +383,8 @@ static void btmtkuart_recv(struct hci_dev *hdev, const u8 *data, size_t count) · 382 unmodified lines
383383 }
384384 }
385385
386−static ssize_t btmtkuart_receive_buf(struct serdev_device *serdev,
387− const u8 *data, size_t count)
386+static size_t btmtkuart_receive_buf(struct serdev_device *serdev,
387+ const u8 *data, size_t count)
388388 {
389389 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev);
390390
drivers/bluetooth/btnxpuart.c+2−2
@@ -1285,8 +1285,8 @@ static const struct h4_recv_pkt nxp_recv_pkts[] = { · 1284 unmodified lines
12851285 { NXP_RECV_FW_REQ_V3, .recv = nxp_recv_fw_req_v3 },
12861286 };
12871287
1288−static ssize_t btnxpuart_receive_buf(struct serdev_device *serdev,
1289− const u8 *data, size_t count)
1288+static size_t btnxpuart_receive_buf(struct serdev_device *serdev,
1289+ const u8 *data, size_t count)
12901290 {
12911291 struct btnxpuart_dev *nxpdev = serdev_device_get_drvdata(serdev);
12921292
drivers/bluetooth/hci_serdev.c+2−2
@@ -271,8 +271,8 @@ static void hci_uart_write_wakeup(struct serdev_device *serdev) · 270 unmodified lines
271271 *
272272 * Return: number of processed bytes
273273 */
274−static ssize_t hci_uart_receive_buf(struct serdev_device *serdev,
275− const u8 *data, size_t count)
274+static size_t hci_uart_receive_buf(struct serdev_device *serdev,
275+ const u8 *data, size_t count)
276276 {
277277 struct hci_uart *hu = serdev_device_get_drvdata(serdev);
278278
drivers/gnss/serial.c+1−1
@@ -80,7 +80,7 @@ static const struct gnss_operations gnss_serial_gnss_ops = { · 79 unmodified lines
8080 .write_raw = gnss_serial_write_raw,
8181 };
8282
83−static ssize_t gnss_serial_receive_buf(struct serdev_device *serdev,
83+static size_t gnss_serial_receive_buf(struct serdev_device *serdev,
8484 const u8 *buf, size_t count)
8585 {
8686 struct gnss_serial *gserial = serdev_device_get_drvdata(serdev);
drivers/gnss/sirf.c+1−1
@@ -160,7 +160,7 @@ static const struct gnss_operations sirf_gnss_ops = { · 159 unmodified lines
160160 .write_raw = sirf_write_raw,
161161 };
162162
163−static ssize_t sirf_receive_buf(struct serdev_device *serdev,
163+static size_t sirf_receive_buf(struct serdev_device *serdev,
164164 const u8 *buf, size_t count)
165165 {
166166 struct sirf_data *data = serdev_device_get_drvdata(serdev);
drivers/greybus/gb-beagleplay.c+3−3
@@ -271,7 +271,7 @@ static void hdlc_rx_frame(struct gb_beagleplay *bg) · 270 unmodified lines
271271 }
272272 }
273273
274−static ssize_t hdlc_rx(struct gb_beagleplay *bg, const u8 *data, size_t count)
274+static size_t hdlc_rx(struct gb_beagleplay *bg, const u8 *data, size_t count)
275275 {
276276 size_t i;
277277 u8 c;
@@ -331,8 +331,8 @@ static void hdlc_deinit(struct gb_beagleplay *bg) · 53 unmodified lines
331331 flush_work(&bg->tx_work);
332332 }
333333
334−static ssize_t gb_tty_receive(struct serdev_device *sd, const u8 *data,
335− size_t count)
334+static size_t gb_tty_receive(struct serdev_device *sd, const u8 *data,
335+ size_t count)
336336 {
337337 struct gb_beagleplay *bg = serdev_device_get_drvdata(sd);
338338
drivers/iio/chemical/pms7003.c+2−2
@@ -211,8 +211,8 @@ static bool pms7003_frame_is_okay(struct pms7003_frame *frame) · 210 unmodified lines
211211 return checksum == pms7003_calc_checksum(frame);
212212 }
213213
214−static ssize_t pms7003_receive_buf(struct serdev_device *serdev, const u8 *buf,
215− size_t size)
214+static size_t pms7003_receive_buf(struct serdev_device *serdev, const u8 *buf,
215+ size_t size)
216216 {
217217 struct iio_dev *indio_dev = serdev_device_get_drvdata(serdev);
218218 struct pms7003_state *state = iio_priv(indio_dev);
drivers/iio/chemical/scd30_serial.c+2−2
@@ -174,8 +174,8 @@ static int scd30_serdev_command(struct scd30_state *state, enum scd30_cmd cmd, u · 173 unmodified lines
174174 return 0;
175175 }
176176
177−static ssize_t scd30_serdev_receive_buf(struct serdev_device *serdev,
178− const u8 *buf, size_t size)
177+static size_t scd30_serdev_receive_buf(struct serdev_device *serdev,
178+ const u8 *buf, size_t size)
179179 {
180180 struct iio_dev *indio_dev = serdev_device_get_drvdata(serdev);
181181 struct scd30_serdev_priv *priv;
drivers/iio/chemical/sps30_serial.c+2−2
@@ -210,8 +210,8 @@ static int sps30_serial_command(struct sps30_state *state, unsigned char cmd, · 209 unmodified lines
210210 return rsp_size;
211211 }
212212
213−static ssize_t sps30_serial_receive_buf(struct serdev_device *serdev,
214− const u8 *buf, size_t size)
213+static size_t sps30_serial_receive_buf(struct serdev_device *serdev,
214+ const u8 *buf, size_t size)
215215 {
216216 struct iio_dev *indio_dev = dev_get_drvdata(&serdev->dev);
217217 struct sps30_serial_priv *priv;
drivers/iio/imu/bno055/bno055_ser_core.c+2−2
@@ -378,8 +378,8 @@ static void bno055_ser_handle_rx(struct bno055_ser_priv *priv, int status) · 377 unmodified lines
378378 * Also, we assume to RX one pkt per time (i.e. the HW doesn't send anything
379379 * unless we require to AND we don't queue more than one request per time).
380380 */
381−static ssize_t bno055_ser_receive_buf(struct serdev_device *serdev,
382− const u8 *buf, size_t size)
381+static size_t bno055_ser_receive_buf(struct serdev_device *serdev,
382+ const u8 *buf, size_t size)
383383 {
384384 int status;
385385 struct bno055_ser_priv *priv = serdev_device_get_drvdata(serdev);
drivers/input/keyboard/amikbd.c+3−3
@@ -26,7 +26,7 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); · 25 unmodified lines
2626 MODULE_DESCRIPTION("Amiga keyboard driver");
2727 MODULE_LICENSE("GPL");
2828
29−#ifdef CONFIG_HW_CONSOLE
29+#ifdef CONFIG_VT
3030 static unsigned char amikbd_keycode[0x78] __initdata = {
3131 [0] = KEY_GRAVE,
3232 [1] = KEY_1,
@@ -148,9 +148,9 @@ static void __init amikbd_init_console_keymaps(void) · 115 unmodified lines
148148 memcpy(key_maps[i], temp_map, sizeof(temp_map));
149149 }
150150 }
151−#else /* !CONFIG_HW_CONSOLE */
151+#else /* !CONFIG_VT */
152152 static inline void amikbd_init_console_keymaps(void) {}
153−#endif /* !CONFIG_HW_CONSOLE */
153+#endif /* !CONFIG_VT */
154154
155155 static const char *amikbd_messages[8] = {
156156 [0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
drivers/mfd/rave-sp.c+2−2
@@ -471,8 +471,8 @@ static void rave_sp_receive_frame(struct rave_sp *sp, · 470 unmodified lines
471471 rave_sp_receive_reply(sp, data, length);
472472 }
473473
474−static ssize_t rave_sp_receive_buf(struct serdev_device *serdev,
475− const u8 *buf, size_t size)
474+static size_t rave_sp_receive_buf(struct serdev_device *serdev,
475+ const u8 *buf, size_t size)
476476 {
477477 struct device *dev = &serdev->dev;
478478 struct rave_sp *sp = dev_get_drvdata(dev);
drivers/net/ethernet/qualcomm/qca_uart.c+1−1
@@ -45,7 +45,7 @@ struct qcauart { · 44 unmodified lines
4545 unsigned char *tx_buffer;
4646 };
4747
48−static ssize_t
48+static size_t
4949 qca_tty_receive(struct serdev_device *serdev, const u8 *data, size_t count)
5050 {
5151 struct qcauart *qca = serdev_device_get_drvdata(serdev);
drivers/nfc/pn533/uart.c+2−2
@@ -203,8 +203,8 @@ static int pn532_uart_rx_is_frame(struct sk_buff *skb) · 202 unmodified lines
203203 return 0;
204204 }
205205
206−static ssize_t pn532_receive_buf(struct serdev_device *serdev,
207− const u8 *data, size_t count)
206+static size_t pn532_receive_buf(struct serdev_device *serdev,
207+ const u8 *data, size_t count)
208208 {
209209 struct pn532_uart_phy *dev = serdev_device_get_drvdata(serdev);
210210 size_t i;
drivers/nfc/s3fwrn5/uart.c+2−2
@@ -51,8 +51,8 @@ static const struct s3fwrn5_phy_ops uart_phy_ops = { · 50 unmodified lines
5151 .write = s3fwrn82_uart_write,
5252 };
5353
54−static ssize_t s3fwrn82_uart_read(struct serdev_device *serdev,
55− const u8 *data, size_t count)
54+static size_t s3fwrn82_uart_read(struct serdev_device *serdev,
55+ const u8 *data, size_t count)
5656 {
5757 struct s3fwrn82_uart_phy *phy = serdev_device_get_drvdata(serdev);
5858 size_t i;
drivers/platform/chrome/cros_ec_uart.c+2−2
@@ -81,8 +81,8 @@ struct cros_ec_uart { · 80 unmodified lines
8181 struct response_info response;
8282 };
8383
84−static ssize_t cros_ec_uart_rx_bytes(struct serdev_device *serdev,
85− const u8 *data, size_t count)
84+static size_t cros_ec_uart_rx_bytes(struct serdev_device *serdev,
85+ const u8 *data, size_t count)
8686 {
8787 struct ec_host_response *host_response;
8888 struct cros_ec_device *ec_dev = serdev_device_get_drvdata(serdev);
drivers/platform/surface/aggregator/core.c+2−2
@@ -227,8 +227,8 @@ EXPORT_SYMBOL_GPL(ssam_client_bind); · 226 unmodified lines
227227
228228 /* -- Glue layer (serdev_device -> ssam_controller). ------------------------ */
229229
230−static ssize_t ssam_receive_buf(struct serdev_device *dev, const u8 *buf,
231− size_t n)
230+static size_t ssam_receive_buf(struct serdev_device *dev, const u8 *buf,
231+ size_t n)
232232 {
233233 struct ssam_controller *ctrl;
234234 int ret;
drivers/tty/Kconfig+1−6
@@ -75,14 +75,9 @@ config VT_CONSOLE_SLEEP · 74 unmodified lines
7575 def_bool y
7676 depends on VT_CONSOLE && PM_SLEEP
7777
78−config HW_CONSOLE
79− bool
80− depends on VT
81− default y
82−
8378 config VT_HW_CONSOLE_BINDING
8479 bool "Support for binding and unbinding console drivers"
85− depends on HW_CONSOLE
80+ depends on VT
8681 help
8782 The virtual terminal is the device that interacts with the physical
8883 terminal through console drivers. On these systems, at least one
drivers/tty/amiserial.c+2−4
@@ -1566,7 +1566,7 @@ fail_tty_driver_kref_put: · 1565 unmodified lines
15661566 return error;
15671567 }
15681568
1569−static int __exit amiga_serial_remove(struct platform_device *pdev)
1569+static void __exit amiga_serial_remove(struct platform_device *pdev)
15701570 {
15711571 struct serial_state *state = platform_get_drvdata(pdev);
15721572
@@ -1576,12 +1576,10 @@ static int __exit amiga_serial_remove(struct platform_device *pdev) · 3 unmodified lines
15761576
15771577 free_irq(IRQ_AMIGA_TBE, state);
15781578 free_irq(IRQ_AMIGA_RBF, state);
1579−
1580− return 0;
15811579 }
15821580
15831581 static struct platform_driver amiga_serial_driver = {
1584− .remove = __exit_p(amiga_serial_remove),
1582+ .remove_new = __exit_p(amiga_serial_remove),
15851583 .driver = {
15861584 .name = "amiga-serial",
15871585 },
drivers/tty/goldfish.c+2−3
@@ -408,7 +408,7 @@ err_unmap: · 407 unmodified lines
408408 return ret;
409409 }
410410
411−static int goldfish_tty_remove(struct platform_device *pdev)
411+static void goldfish_tty_remove(struct platform_device *pdev)
412412 {
413413 struct goldfish_tty *qtty = platform_get_drvdata(pdev);
414414
@@ -424,7 +424,6 @@ static int goldfish_tty_remove(struct platform_device *pdev) · 9 unmodified lines
424424 if (goldfish_tty_current_line_count == 0)
425425 goldfish_tty_delete_driver();
426426 mutex_unlock(&goldfish_tty_lock);
427− return 0;
428427 }
429428
430429 #ifdef CONFIG_GOLDFISH_TTY_EARLY_CONSOLE
@@ -462,7 +461,7 @@ MODULE_DEVICE_TABLE(of, goldfish_tty_of_match); · 31 unmodified lines
462461
463462 static struct platform_driver goldfish_tty_platform_driver = {
464463 .probe = goldfish_tty_probe,
465− .remove = goldfish_tty_remove,
464+ .remove_new = goldfish_tty_remove,
466465 .driver = {
467466 .name = "goldfish_tty",
468467 .of_match_table = goldfish_tty_of_match,
drivers/tty/hvc/hvc_iucv.c+5−1
@@ -1035,6 +1035,10 @@ static const struct attribute_group *hvc_iucv_dev_attr_groups[] = { · 1034 unmodified lines
10351035 NULL,
10361036 };
10371037
1038+static void hvc_iucv_free(struct device *data)
1039+{
1040+ kfree(data);
1041+}
10381042
10391043 /**
10401044 * hvc_iucv_alloc() - Allocates a new struct hvc_iucv_private instance
@@ -1097,7 +1101,7 @@ static int __init hvc_iucv_alloc(int id, unsigned int is_console) · 56 unmodified lines
10971101 priv->dev->bus = &iucv_bus;
10981102 priv->dev->parent = iucv_root;
10991103 priv->dev->groups = hvc_iucv_dev_attr_groups;
1100− priv->dev->release = (void (*)(struct device *)) kfree;
1104+ priv->dev->release = hvc_iucv_free;
11011105 rc = device_register(priv->dev);
11021106 if (rc) {
11031107 put_device(priv->dev);
drivers/tty/serdev/core.c+1−1
@@ -431,7 +431,7 @@ static void serdev_drv_remove(struct device *dev) · 430 unmodified lines
431431 dev_pm_domain_detach(dev, true);
432432 }
433433
434−static struct bus_type serdev_bus_type = {
434+static const struct bus_type serdev_bus_type = {
435435 .name = "serial",
436436 .match = serdev_device_match,
437437 .probe = serdev_drv_probe,
drivers/tty/serdev/serdev-ttyport.c+4−6
@@ -27,19 +27,17 @@ static size_t ttyport_receive_buf(struct tty_port *port, const u8 *cp, · 26 unmodified lines
2727 {
2828 struct serdev_controller *ctrl = port->client_data;
2929 struct serport *serport = serdev_controller_get_drvdata(ctrl);
30− int ret;
30+ size_t ret;
3131
3232 if (!test_bit(SERPORT_ACTIVE, &serport->flags))
3333 return 0;
3434
3535 ret = serdev_controller_receive_buf(ctrl, cp, count);
3636
37− dev_WARN_ONCE(&ctrl->dev, ret < 0 || ret > count,
38− "receive_buf returns %d (count = %zu)\n",
37+ dev_WARN_ONCE(&ctrl->dev, ret > count,
38+ "receive_buf returns %zu (count = %zu)\n",
3939 ret, count);
40− if (ret < 0)
41− return 0;
42− else if (ret > count)
40+ if (ret > count)
4341 return count;
4442
4543 return ret;
drivers/tty/serial/8250/8250_aspeed_vuart.c+15−35
@@ -419,8 +419,8 @@ static int aspeed_vuart_probe(struct platform_device *pdev) · 418 unmodified lines
419419 struct aspeed_vuart *vuart;
420420 struct device_node *np;
421421 struct resource *res;
422− u32 clk, prop, sirq[2];
423422 int rc, sirq_polarity;
423+ u32 prop, sirq[2];
424424 struct clk *vclk;
425425
426426 np = pdev->dev.of_node;
@@ -447,53 +447,35 @@ static int aspeed_vuart_probe(struct platform_device *pdev) · 20 unmodified lines
447447 port.port.status = UPSTAT_SYNC_FIFO;
448448 port.port.dev = &pdev->dev;
449449 port.port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE);
450+ port.port.flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP | UPF_FIXED_PORT | UPF_FIXED_TYPE |
451+ UPF_NO_THRE_TEST;
450452 port.bugs |= UART_BUG_TXRACE;
451453
452454 rc = sysfs_create_group(&vuart->dev->kobj, &aspeed_vuart_attr_group);
453455 if (rc < 0)
454456 return rc;
455457
456− if (of_property_read_u32(np, "clock-frequency", &clk)) {
458+ rc = uart_read_port_properties(&port.port);
459+ if (rc)
460+ goto err_sysfs_remove;
461+
462+ /* Get clk rate through clk driver if present */
463+ if (!port.port.uartclk) {
457464 vclk = devm_clk_get_enabled(dev, NULL);
458465 if (IS_ERR(vclk)) {
459466 rc = dev_err_probe(dev, PTR_ERR(vclk), "clk or clock-frequency not defined\n");
460467 goto err_sysfs_remove;
461468 }
462469
463− clk = clk_get_rate(vclk);
470+ port.port.uartclk = clk_get_rate(vclk);
464471 }
465472
466473 /* If current-speed was set, then try not to change it. */
467474 if (of_property_read_u32(np, "current-speed", &prop) == 0)
468− port.port.custom_divisor = clk / (16 * prop);
469−
470− /* Check for shifted address mapping */
471− if (of_property_read_u32(np, "reg-offset", &prop) == 0)
472− port.port.mapbase += prop;
473−
474− /* Check for registers offset within the devices address range */
475− if (of_property_read_u32(np, "reg-shift", &prop) == 0)
476− port.port.regshift = prop;
475+ port.port.custom_divisor = port.port.uartclk / (16 * prop);
477476
478− /* Check for fifo size */
479− if (of_property_read_u32(np, "fifo-size", &prop) == 0)
480− port.port.fifosize = prop;
481−
482− /* Check for a fixed line number */
483− rc = of_alias_get_id(np, "serial");
484− if (rc >= 0)
485− port.port.line = rc;
486−
487− port.port.irq = irq_of_parse_and_map(np, 0);
488477 port.port.handle_irq = aspeed_vuart_handle_irq;
489− port.port.iotype = UPIO_MEM;
490478 port.port.type = PORT_ASPEED_VUART;
491− port.port.uartclk = clk;
492− port.port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
493− | UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_NO_THRE_TEST;
494−
495− if (of_property_read_bool(np, "no-loopback-test"))
496− port.port.flags |= UPF_SKIP_TEST;
497479
498480 if (port.port.fifosize)
499481 port.capabilities = UART_CAP_FIFO;
@@ -503,7 +485,7 @@ static int aspeed_vuart_probe(struct platform_device *pdev) · 3 unmodified lines
503485
504486 rc = serial8250_register_8250_port(&port);
505487 if (rc < 0)
506− goto err_clk_disable;
488+ goto err_sysfs_remove;
507489
508490 vuart->line = rc;
509491 vuart->port = serial8250_get_port(vuart->line);
@@ -529,7 +511,7 @@ static int aspeed_vuart_probe(struct platform_device *pdev) · 19 unmodified lines
529511 rc = aspeed_vuart_set_lpc_address(vuart, prop);
530512 if (rc < 0) {
531513 dev_err_probe(dev, rc, "invalid value in aspeed,lpc-io-reg property\n");
532− goto err_clk_disable;
514+ goto err_sysfs_remove;
533515 }
534516
535517 rc = of_property_read_u32_array(np, "aspeed,lpc-interrupts", sirq, 2);
@@ -541,14 +523,14 @@ static int aspeed_vuart_probe(struct platform_device *pdev) · 5 unmodified lines
541523 rc = aspeed_vuart_set_sirq(vuart, sirq[0]);
542524 if (rc < 0) {
543525 dev_err_probe(dev, rc, "invalid sirq number in aspeed,lpc-interrupts property\n");
544− goto err_clk_disable;
526+ goto err_sysfs_remove;
545527 }
546528
547529 sirq_polarity = aspeed_vuart_map_irq_polarity(sirq[1]);
548530 if (sirq_polarity < 0) {
549531 rc = dev_err_probe(dev, sirq_polarity,
550532 "invalid sirq polarity in aspeed,lpc-interrupts property\n");
551− goto err_clk_disable;
533+ goto err_sysfs_remove;
552534 }
553535
554536 aspeed_vuart_set_sirq_polarity(vuart, sirq_polarity);
@@ -559,8 +541,6 @@ static int aspeed_vuart_probe(struct platform_device *pdev) · 4 unmodified lines
559541
560542 return 0;
561543
562−err_clk_disable:
563− irq_dispose_mapping(port.port.irq);
564544 err_sysfs_remove:
565545 sysfs_remove_group(&vuart->dev->kobj, &aspeed_vuart_attr_group);
566546 return rc;
drivers/tty/serial/8250/8250_bcm2835aux.c+43−51
@@ -45,10 +45,6 @@ struct bcm2835aux_data { · 44 unmodified lines
4545 u32 cntl;
4646 };
4747
48−struct bcm2835_aux_serial_driver_data {
49− resource_size_t offset;
50−};
51−
5248 static void bcm2835aux_rs485_start_tx(struct uart_8250_port *up)
5349 {
5450 if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) {
@@ -85,10 +81,9 @@ static void bcm2835aux_rs485_stop_tx(struct uart_8250_port *up) · 30 unmodified lines
8581
8682 static int bcm2835aux_serial_probe(struct platform_device *pdev)
8783 {
88− const struct bcm2835_aux_serial_driver_data *bcm_data;
84+ const struct software_node *bcm2835_swnode;
8985 struct uart_8250_port up = { };
9086 struct bcm2835aux_data *data;
91− resource_size_t offset = 0;
9287 struct resource *res;
9388 unsigned int uartclk;
9489 int ret;
@@ -101,12 +96,8 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) · 6 unmodified lines
10196 /* initialize data */
10297 up.capabilities = UART_CAP_FIFO | UART_CAP_MINI;
10398 up.port.dev = &pdev->dev;
104− up.port.regshift = 2;
10599 up.port.type = PORT_16550;
106− up.port.iotype = UPIO_MEM;
107− up.port.fifosize = 8;
108− up.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT | UPF_FIXED_TYPE |
109− UPF_SKIP_TEST | UPF_IOREMAP;
100+ up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SKIP_TEST | UPF_IOREMAP;
110101 up.port.rs485_config = serial8250_em485_config;
111102 up.port.rs485_supported = serial8250_em485_supported;
112103 up.rs485_start_tx = bcm2835aux_rs485_start_tx;
@@ -122,12 +113,6 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) · 9 unmodified lines
122113 if (IS_ERR(data->clk))
123114 return dev_err_probe(&pdev->dev, PTR_ERR(data->clk), "could not get clk\n");
124115
125− /* get the interrupt */
126− ret = platform_get_irq(pdev, 0);
127− if (ret < 0)
128− return ret;
129− up.port.irq = ret;
130−
131116 /* map the main registers */
132117 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
133118 if (!res) {
@@ -135,52 +120,40 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) · 1 unmodified line
135120 return -EINVAL;
136121 }
137122
138− bcm_data = device_get_match_data(&pdev->dev);
139−
140− /* Some UEFI implementations (e.g. tianocore/edk2 for the Raspberry Pi)
141− * describe the miniuart with a base address that encompasses the auxiliary
142− * registers shared between the miniuart and spi.
143− *
144− * This is due to historical reasons, see discussion here :
145− * https://edk2.groups.io/g/devel/topic/87501357#84349
146− *
147− * We need to add the offset between the miniuart and auxiliary
148− * registers to get the real miniuart base address.
149− */
150− if (bcm_data)
151− offset = bcm_data->offset;
123+ up.port.mapbase = res->start;
124+ up.port.mapsize = resource_size(res);
125+
126+ bcm2835_swnode = device_get_match_data(&pdev->dev);
127+ if (bcm2835_swnode) {
128+ ret = device_add_software_node(&pdev->dev, bcm2835_swnode);
129+ if (ret)
130+ return ret;
131+ }
152132
153− up.port.mapbase = res->start + offset;
154− up.port.mapsize = resource_size(res) - offset;
133+ ret = uart_read_port_properties(&up.port);
134+ if (ret)
135+ goto rm_swnode;
155136
156− /* Check for a fixed line number */
157− ret = of_alias_get_id(pdev->dev.of_node, "serial");
158− if (ret >= 0)
159− up.port.line = ret;
137+ up.port.regshift = 2;
138+ up.port.fifosize = 8;
160139
161140 /* enable the clock as a last step */
162141 ret = clk_prepare_enable(data->clk);
163142 if (ret) {
164− dev_err(&pdev->dev, "unable to enable uart clock - %d\n",
165− ret);
166− return ret;
143+ dev_err_probe(&pdev->dev, ret, "unable to enable uart clock\n");
144+ goto rm_swnode;
167145 }
168146
169147 uartclk = clk_get_rate(data->clk);
170− if (!uartclk) {
171− ret = device_property_read_u32(&pdev->dev, "clock-frequency", &uartclk);
172− if (ret) {
173− dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
174− goto dis_clk;
175− }
176− }
148+ if (uartclk)
149+ up.port.uartclk = uartclk;
177150
178151 /* the HW-clock divider for bcm2835aux is 8,
179152 * but 8250 expects a divider of 16,
180153 * so we have to multiply the actual clock by 2
181154 * to get identical baudrates.
182155 */
183− up.port.uartclk = uartclk * 2;
156+ up.port.uartclk *= 2;
184157
185158 /* register the port */
186159 ret = serial8250_register_8250_port(&up);
@@ -194,6 +167,8 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) · 7 unmodified lines
194167
195168 dis_clk:
196169 clk_disable_unprepare(data->clk);
170+rm_swnode:
171+ device_remove_software_node(&pdev->dev);
197172 return ret;
198173 }
199174
@@ -203,10 +178,27 @@ static void bcm2835aux_serial_remove(struct platform_device *pdev) · 3 unmodified lines
203178
204179 serial8250_unregister_port(data->line);
205180 clk_disable_unprepare(data->clk);
181+ device_remove_software_node(&pdev->dev);
206182 }
207183
208−static const struct bcm2835_aux_serial_driver_data bcm2835_acpi_data = {
209− .offset = 0x40,
184+/*
185+ * Some UEFI implementations (e.g. tianocore/edk2 for the Raspberry Pi)
186+ * describe the miniuart with a base address that encompasses the auxiliary
187+ * registers shared between the miniuart and spi.
188+ *
189+ * This is due to historical reasons, see discussion here:
190+ * https://edk2.groups.io/g/devel/topic/87501357#84349
191+ *
192+ * We need to add the offset between the miniuart and auxiliary registers
193+ * to get the real miniuart base address.
194+ */
195+static const struct property_entry bcm2835_acpi_properties[] = {
196+ PROPERTY_ENTRY_U32("reg-offset", 0x40),
197+ { }
198+};
199+
200+static const struct software_node bcm2835_acpi_node = {
201+ .properties = bcm2835_acpi_properties,
210202 };
211203
212204 static const struct of_device_id bcm2835aux_serial_match[] = {
@@ -216,7 +208,7 @@ static const struct of_device_id bcm2835aux_serial_match[] = { · 3 unmodified lines
216208 MODULE_DEVICE_TABLE(of, bcm2835aux_serial_match);
217209
218210 static const struct acpi_device_id bcm2835aux_serial_acpi_match[] = {
219− { "BCM2836", (kernel_ulong_t)&bcm2835_acpi_data },
211+ { "BCM2836", (kernel_ulong_t)&bcm2835_acpi_node },
220212 { }
221213 };
222214 MODULE_DEVICE_TABLE(acpi, bcm2835aux_serial_acpi_match);
drivers/tty/serial/8250/8250_bcm7271.c+27−46
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include <linux/delay.h>
2323 #include <linux/clk.h>
2424 #include <linux/debugfs.h>
25+#include <linux/units.h>
2526
2627 #include "8250.h"
2728
@@ -187,21 +188,19 @@ · 159 unmodified lines
187188 #define TX_BUF_SIZE 4096
188189 #define RX_BUF_SIZE 4096
189190 #define RX_BUFS_COUNT 2
190−#define KHZ 1000
191−#define MHZ(x) ((x) * KHZ * KHZ)
192191
193192 static const u32 brcmstb_rate_table[] = {
194− MHZ(81),
195− MHZ(108),
196− MHZ(64), /* Actually 64285715 for some chips */
197− MHZ(48),
193+ 81 * HZ_PER_MHZ,
194+ 108 * HZ_PER_MHZ,
195+ 64 * HZ_PER_MHZ, /* Actually 64285715 for some chips */
196+ 48 * HZ_PER_MHZ,
198197 };
199198
200199 static const u32 brcmstb_rate_table_7278[] = {
201− MHZ(81),
202− MHZ(108),
200+ 81 * HZ_PER_MHZ,
201+ 108 * HZ_PER_MHZ,
203202 0,
204− MHZ(48),
203+ 48 * HZ_PER_MHZ,
205204 };
206205
207206 struct brcmuart_priv {
@@ -936,17 +935,14 @@ static void brcmuart_init_debugfs(struct brcmuart_priv *priv, · 728 unmodified lines
936935 static int brcmuart_probe(struct platform_device *pdev)
937936 {
938937 struct resource *regs;
939− struct device_node *np = pdev->dev.of_node;
940938 const struct of_device_id *of_id = NULL;
941939 struct uart_8250_port *new_port;
942940 struct device *dev = &pdev->dev;
943941 struct brcmuart_priv *priv;
944942 struct clk *baud_mux_clk;
945943 struct uart_8250_port up;
946− int irq;
947944 void __iomem *membase = NULL;
948945 resource_size_t mapbase = 0;
949− u32 clk_rate = 0;
950946 int ret;
951947 int x;
952948 int dma_irq;
@@ -954,15 +950,12 @@ static int brcmuart_probe(struct platform_device *pdev) · 1 unmodified line
954950 "uart", "dma_rx", "dma_tx", "dma_intr2", "dma_arb"
955951 };
956952
957− irq = platform_get_irq(pdev, 0);
958− if (irq < 0)
959− return irq;
960953 priv = devm_kzalloc(dev, sizeof(struct brcmuart_priv),
961954 GFP_KERNEL);
962955 if (!priv)
963956 return -ENOMEM;
964957
965− of_id = of_match_node(brcmuart_dt_ids, np);
958+ of_id = of_match_node(brcmuart_dt_ids, dev->of_node);
966959 if (!of_id || !of_id->data)
967960 priv->rate_table = brcmstb_rate_table;
968961 else
@@ -1012,7 +1005,23 @@ static int brcmuart_probe(struct platform_device *pdev) · 43 unmodified lines
10121005 }
10131006 }
10141007
1015− of_property_read_u32(np, "clock-frequency", &clk_rate);
1008+ dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not ");
1009+
1010+ memset(&up, 0, sizeof(up));
1011+ up.port.type = PORT_BCM7271;
1012+ up.port.dev = dev;
1013+ up.port.mapbase = mapbase;
1014+ up.port.membase = membase;
1015+ up.port.handle_irq = brcmuart_handle_irq;
1016+ up.port.flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_FIXED_TYPE;
1017+ up.port.private_data = priv;
1018+
1019+ ret = uart_read_port_properties(&up.port);
1020+ if (ret)
1021+ goto release_dma;
1022+
1023+ up.port.regshift = 2;
1024+ up.port.iotype = device_is_big_endian(dev) ? UPIO_MEM32BE : UPIO_MEM32;
10161025
10171026 /* See if a Baud clock has been specified */
10181027 baud_mux_clk = devm_clk_get_optional_enabled(dev, "sw_baud");
@@ -1024,39 +1033,11 @@ static int brcmuart_probe(struct platform_device *pdev) · 5 unmodified lines
10241033
10251034 priv->baud_mux_clk = baud_mux_clk;
10261035 init_real_clk_rates(dev, priv);
1027− clk_rate = priv->default_mux_rate;
1036+ up.port.uartclk = priv->default_mux_rate;
10281037 } else {
10291038 dev_dbg(dev, "BAUD MUX clock not specified\n");
10301039 }
10311040
1032− if (clk_rate == 0) {
1033− ret = dev_err_probe(dev, -EINVAL, "clock-frequency or clk not defined\n");
1034− goto release_dma;
1035− }
1036−
1037− dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not ");
1038−
1039− memset(&up, 0, sizeof(up));
1040− up.port.type = PORT_BCM7271;
1041− up.port.uartclk = clk_rate;
1042− up.port.dev = dev;
1043− up.port.mapbase = mapbase;
1044− up.port.membase = membase;
1045− up.port.irq = irq;
1046− up.port.handle_irq = brcmuart_handle_irq;
1047− up.port.regshift = 2;
1048− up.port.iotype = of_device_is_big_endian(np) ?
1049− UPIO_MEM32BE : UPIO_MEM32;
1050− up.port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF
1051− | UPF_FIXED_PORT | UPF_FIXED_TYPE;
1052− up.port.dev = dev;
1053− up.port.private_data = priv;
1054−
1055− /* Check for a fixed line number */
1056− ret = of_alias_get_id(np, "serial");
1057− if (ret >= 0)
1058− up.port.line = ret;
1059−
10601041 /* setup HR timer */
10611042 hrtimer_init(&priv->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
10621043 priv->hrt.function = brcmuart_hrtimer_func;
drivers/tty/serial/8250/8250_dw.c+55−66
@@ -9,7 +9,6 @@ · 8 unmodified lines
99 * LCR is written whilst busy. If it is, then a busy detect interrupt is
1010 * raised, the LCR needs to be rewritten and the uart status register read.
1111 */
12−#include <linux/acpi.h>
1312 #include <linux/clk.h>
1413 #include <linux/delay.h>
1514 #include <linux/device.h>
@@ -17,7 +16,6 @@ · 1 unmodified line
1716 #include <linux/mod_devicetable.h>
1817 #include <linux/module.h>
1918 #include <linux/notifier.h>
20−#include <linux/of.h>
2119 #include <linux/platform_device.h>
2220 #include <linux/pm_runtime.h>
2321 #include <linux/property.h>
@@ -56,6 +54,7 @@ · 32 unmodified lines
5654 #define DW_UART_QUIRK_ARMADA_38X BIT(1)
5755 #define DW_UART_QUIRK_SKIP_SET_RATE BIT(2)
5856 #define DW_UART_QUIRK_IS_DMA_FC BIT(3)
57+#define DW_UART_QUIRK_APMC0D08 BIT(4)
5958
6059 static inline struct dw8250_data *clk_to_dw8250_data(struct notifier_block *nb)
6160 {
@@ -445,44 +444,29 @@ static void dw8250_prepare_rx_dma(struct uart_8250_port *p) · 383 unmodified lines
445444
446445 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
447446 {
448− struct device_node *np = p->dev->of_node;
447+ unsigned int quirks = data->pdata ? data->pdata->quirks : 0;
449448
450− if (np) {
451− unsigned int quirks = data->pdata->quirks;
452− int id;
453−
454− /* get index of serial line, if found in DT aliases */
455− id = of_alias_get_id(np, "serial");
456− if (id >= 0)
457− p->line = id;
458449 #ifdef CONFIG_64BIT
459− if (quirks & DW_UART_QUIRK_OCTEON) {
460− p->serial_in = dw8250_serial_inq;
461− p->serial_out = dw8250_serial_outq;
462− p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
463− p->type = PORT_OCTEON;
464− data->skip_autocfg = true;
465− }
450+ if (quirks & DW_UART_QUIRK_OCTEON) {
451+ p->serial_in = dw8250_serial_inq;
452+ p->serial_out = dw8250_serial_outq;
453+ p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
454+ p->type = PORT_OCTEON;
455+ data->skip_autocfg = true;
456+ }
466457 #endif
467458
468− if (of_device_is_big_endian(np)) {
469− p->iotype = UPIO_MEM32BE;
470− p->serial_in = dw8250_serial_in32be;
471− p->serial_out = dw8250_serial_out32be;
472− }
473−
474− if (quirks & DW_UART_QUIRK_ARMADA_38X)
475− p->serial_out = dw8250_serial_out38x;
476− if (quirks & DW_UART_QUIRK_SKIP_SET_RATE)
477− p->set_termios = dw8250_do_set_termios;
478− if (quirks & DW_UART_QUIRK_IS_DMA_FC) {
479− data->data.dma.txconf.device_fc = 1;
480− data->data.dma.rxconf.device_fc = 1;
481− data->data.dma.prepare_tx_dma = dw8250_prepare_tx_dma;
482− data->data.dma.prepare_rx_dma = dw8250_prepare_rx_dma;
483− }
484−
485− } else if (acpi_dev_present("APMC0D08", NULL, -1)) {
459+ if (quirks & DW_UART_QUIRK_ARMADA_38X)
460+ p->serial_out = dw8250_serial_out38x;
461+ if (quirks & DW_UART_QUIRK_SKIP_SET_RATE)
462+ p->set_termios = dw8250_do_set_termios;
463+ if (quirks & DW_UART_QUIRK_IS_DMA_FC) {
464+ data->data.dma.txconf.device_fc = 1;
465+ data->data.dma.rxconf.device_fc = 1;
466+ data->data.dma.prepare_tx_dma = dw8250_prepare_tx_dma;
467+ data->data.dma.prepare_rx_dma = dw8250_prepare_rx_dma;
468+ }
469+ if (quirks & DW_UART_QUIRK_APMC0D08) {
486470 p->iotype = UPIO_MEM32;
487471 p->regshift = 2;
488472 p->serial_in = dw8250_serial_in32;
@@ -510,39 +494,21 @@ static int dw8250_probe(struct platform_device *pdev) · 21 unmodified lines
510494 struct device *dev = &pdev->dev;
511495 struct dw8250_data *data;
512496 struct resource *regs;
513− int irq;
514497 int err;
515− u32 val;
516498
517499 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
518500 if (!regs)
519501 return dev_err_probe(dev, -EINVAL, "no registers defined\n");
520502
521− irq = platform_get_irq_optional(pdev, 0);
522− /* no interrupt -> fall back to polling */
523− if (irq == -ENXIO)
524− irq = 0;
525− if (irq < 0)
526− return irq;
527−
528503 spin_lock_init(&p->lock);
529− p->mapbase = regs->start;
530− p->irq = irq;
531504 p->handle_irq = dw8250_handle_irq;
532505 p->pm = dw8250_do_pm;
533506 p->type = PORT_8250;
534− p->flags = UPF_SHARE_IRQ | UPF_FIXED_PORT;
507+ p->flags = UPF_FIXED_PORT;
535508 p->dev = dev;
536− p->iotype = UPIO_MEM;
537− p->serial_in = dw8250_serial_in;
538− p->serial_out = dw8250_serial_out;
539509 p->set_ldisc = dw8250_set_ldisc;
540510 p->set_termios = dw8250_set_termios;
541511
542− p->membase = devm_ioremap(dev, regs->start, resource_size(regs));
543− if (!p->membase)
544− return -ENOMEM;
545−
546512 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
547513 if (!data)
548514 return -ENOMEM;
@@ -554,15 +520,35 @@ static int dw8250_probe(struct platform_device *pdev) · 5 unmodified lines
554520 data->uart_16550_compatible = device_property_read_bool(dev,
555521 "snps,uart-16550-compatible");
556522
557− err = device_property_read_u32(dev, "reg-shift", &val);
558− if (!err)
559− p->regshift = val;
523+ p->mapbase = regs->start;
524+ p->mapsize = resource_size(regs);
560525
561− err = device_property_read_u32(dev, "reg-io-width", &val);
562− if (!err && val == 4) {
563− p->iotype = UPIO_MEM32;
526+ p->membase = devm_ioremap(dev, p->mapbase, p->mapsize);
527+ if (!p->membase)
528+ return -ENOMEM;
529+
530+ err = uart_read_port_properties(p);
531+ /* no interrupt -> fall back to polling */
532+ if (err == -ENXIO)
533+ err = 0;
534+ if (err)
535+ return err;
536+
537+ switch (p->iotype) {
538+ case UPIO_MEM:
539+ p->serial_in = dw8250_serial_in;
540+ p->serial_out = dw8250_serial_out;
541+ break;
542+ case UPIO_MEM32:
564543 p->serial_in = dw8250_serial_in32;
565544 p->serial_out = dw8250_serial_out32;
545+ break;
546+ case UPIO_MEM32BE:
547+ p->serial_in = dw8250_serial_in32be;
548+ p->serial_out = dw8250_serial_out32be;
549+ break;
550+ default:
551+ return -ENODEV;
566552 }
567553
568554 if (device_property_read_bool(dev, "dcd-override")) {
@@ -589,15 +575,13 @@ static int dw8250_probe(struct platform_device *pdev) · 20 unmodified lines
589575 data->msr_mask_off |= UART_MSR_TERI;
590576 }
591577
592− /* Always ask for fixed clock rate from a property. */
593− device_property_read_u32(dev, "clock-frequency", &p->uartclk);
594−
595578 /* If there is separate baudclk, get the rate from it. */
596579 data->clk = devm_clk_get_optional_enabled(dev, "baudclk");
597580 if (data->clk == NULL)
598581 data->clk = devm_clk_get_optional_enabled(dev, NULL);
599582 if (IS_ERR(data->clk))
600− return PTR_ERR(data->clk);
583+ return dev_err_probe(dev, PTR_ERR(data->clk),
584+ "failed to get baudclk\n");
601585
602586 INIT_WORK(&data->clk_work, dw8250_clk_work_cb);
603587 data->clk_notifier.notifier_call = dw8250_clk_notifier_cb;
@@ -762,13 +746,18 @@ static const struct of_device_id dw8250_of_match[] = { · 158 unmodified lines
762746 };
763747 MODULE_DEVICE_TABLE(of, dw8250_of_match);
764748
749+static const struct dw8250_platform_data dw8250_apmc0d08 = {
750+ .usr_reg = DW_UART_USR,
751+ .quirks = DW_UART_QUIRK_APMC0D08,
752+};
753+
765754 static const struct acpi_device_id dw8250_acpi_match[] = {
766755 { "80860F0A", (kernel_ulong_t)&dw8250_dw_apb },
767756 { "8086228A", (kernel_ulong_t)&dw8250_dw_apb },
768757 { "AMD0020", (kernel_ulong_t)&dw8250_dw_apb },
769758 { "AMDI0020", (kernel_ulong_t)&dw8250_dw_apb },
770759 { "AMDI0022", (kernel_ulong_t)&dw8250_dw_apb },
771− { "APMC0D08", (kernel_ulong_t)&dw8250_dw_apb},
760+ { "APMC0D08", (kernel_ulong_t)&dw8250_apmc0d08 },
772761 { "BRCM2032", (kernel_ulong_t)&dw8250_dw_apb },
773762 { "HISI0031", (kernel_ulong_t)&dw8250_dw_apb },
774763 { "INT33C4", (kernel_ulong_t)&dw8250_dw_apb },
drivers/tty/serial/8250/8250_exar.c+27−25
@@ -6,23 +6,29 @@ · 5 unmodified lines
66 *
77 * Copyright (C) 2017 Sudip Mukherjee, All Rights Reserved.
88 */
9−#include <linux/acpi.h>
9+#include <linux/bits.h>
10+#include <linux/delay.h>
11+#include <linux/device.h>
1012 #include <linux/dmi.h>
13+#include <linux/interrupt.h>
1114 #include <linux/io.h>
12−#include <linux/kernel.h>
15+#include <linux/math.h>
1316 #include <linux/module.h>
1417 #include <linux/pci.h>
18+#include <linux/platform_device.h>
19+#include <linux/pm.h>
1520 #include <linux/property.h>
21+#include <linux/string.h>
22+#include <linux/types.h>
23+
24+#include <linux/serial_8250.h>
1625 #include <linux/serial_core.h>
1726 #include <linux/serial_reg.h>
18−#include <linux/slab.h>
19−#include <linux/string.h>
20−#include <linux/tty.h>
21−#include <linux/delay.h>
2227
2328 #include <asm/byteorder.h>
2429
2530 #include "8250.h"
31+#include "8250_pcilib.h"
2632
2733 #define PCI_DEVICE_ID_ACCESSIO_COM_2S 0x1052
2834 #define PCI_DEVICE_ID_ACCESSIO_COM_4S 0x105d
@@ -229,13 +235,12 @@ static int default_setup(struct exar8250 *priv, struct pci_dev *pcidev, · 200 unmodified lines
229235 struct uart_8250_port *port)
230236 {
231237 const struct exar8250_board *board = priv->board;
232− unsigned int bar = 0;
233238 unsigned char status;
239+ int err;
234240
235− port->port.iotype = UPIO_MEM;
236− port->port.mapbase = pci_resource_start(pcidev, bar) + offset;
237− port->port.membase = priv->virt + offset;
238− port->port.regshift = board->reg_shift;
241+ err = serial8250_pci_setup_port(pcidev, port, 0, offset, board->reg_shift);
242+ if (err)
243+ return err;
239244
240245 /*
241246 * XR17V35x UARTs have an extra divisor register, DLD that gets enabled
@@ -375,7 +380,7 @@ static struct platform_device *__xr17v35x_register_gpio(struct pci_dev *pcidev, · 133 unmodified lines
375380 return NULL;
376381
377382 pdev->dev.parent = &pcidev->dev;
378− ACPI_COMPANION_SET(&pdev->dev, ACPI_COMPANION(&pcidev->dev));
383+ device_set_node(&pdev->dev, dev_fwnode(&pcidev->dev));
379384
380385 if (device_add_software_node(&pdev->dev, node) < 0 ||
381386 platform_device_add(pdev) < 0) {
@@ -713,14 +718,14 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) · 331 unmodified lines
713718 uart.port.irq = pci_irq_vector(pcidev, 0);
714719 uart.port.dev = &pcidev->dev;
715720
721+ /* Clear interrupts */
722+ exar_misc_clear(priv);
723+
716724 rc = devm_request_irq(&pcidev->dev, uart.port.irq, exar_misc_handler,
717725 IRQF_SHARED, "exar_uart", priv);
718726 if (rc)
719727 return rc;
720728
721− /* Clear interrupts */
722− exar_misc_clear(priv);
723−
724729 for (i = 0; i < nr_ports && i < maxnr; i++) {
725730 rc = board->setup(priv, pcidev, &uart, i);
726731 if (rc) {
@@ -753,28 +758,24 @@ static void exar_pci_remove(struct pci_dev *pcidev) · 26 unmodified lines
753758 for (i = 0; i < priv->nr; i++)
754759 serial8250_unregister_port(priv->line[i]);
755760
761+ /* Ensure that every init quirk is properly torn down */
756762 if (priv->board->exit)
757763 priv->board->exit(pcidev);
758764 }
759765
760−static int __maybe_unused exar_suspend(struct device *dev)
766+static int exar_suspend(struct device *dev)
761767 {
762− struct pci_dev *pcidev = to_pci_dev(dev);
763− struct exar8250 *priv = pci_get_drvdata(pcidev);
768+ struct exar8250 *priv = dev_get_drvdata(dev);
764769 unsigned int i;
765770
766771 for (i = 0; i < priv->nr; i++)
767772 if (priv->line[i] >= 0)
768773 serial8250_suspend_port(priv->line[i]);
769774
770− /* Ensure that every init quirk is properly torn down */
771− if (priv->board->exit)
772− priv->board->exit(pcidev);
773−
774775 return 0;
775776 }
776777
777−static int __maybe_unused exar_resume(struct device *dev)
778+static int exar_resume(struct device *dev)
778779 {
779780 struct exar8250 *priv = dev_get_drvdata(dev);
780781 unsigned int i;
@@ -788,7 +789,7 @@ static int __maybe_unused exar_resume(struct device *dev) · 7 unmodified lines
788789 return 0;
789790 }
790791
791−static SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume);
792+static DEFINE_SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume);
792793
793794 static const struct exar8250_board pbn_fastcom335_2 = {
794795 .num_ports = 2,
@@ -938,12 +939,13 @@ static struct pci_driver exar_pci_driver = { · 143 unmodified lines
938939 .probe = exar_pci_probe,
939940 .remove = exar_pci_remove,
940941 .driver = {
941− .pm = &exar_pci_pm,
942+ .pm = pm_sleep_ptr(&exar_pci_pm),
942943 },
943944 .id_table = exar_pci_tbl,
944945 };
945946 module_pci_driver(exar_pci_driver);
946947
948+MODULE_IMPORT_NS(SERIAL_8250_PCI);
947949 MODULE_LICENSE("GPL");
948950 MODULE_DESCRIPTION("Exar Serial Driver");
949951 MODULE_AUTHOR("Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>");
drivers/tty/serial/8250/8250_ingenic.c+7−13
@@ -234,7 +234,7 @@ static int ingenic_uart_probe(struct platform_device *pdev) · 233 unmodified lines
234234 struct ingenic_uart_data *data;
235235 const struct ingenic_uart_config *cdata;
236236 struct resource *regs;
237− int irq, err, line;
237+ int err;
238238
239239 cdata = of_device_get_match_data(&pdev->dev);
240240 if (!cdata) {
@@ -242,10 +242,6 @@ static int ingenic_uart_probe(struct platform_device *pdev) · 1 unmodified line
242242 return -ENODEV;
243243 }
244244
245− irq = platform_get_irq(pdev, 0);
246− if (irq < 0)
247− return irq;
248−
249245 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
250246 if (!regs) {
251247 dev_err(&pdev->dev, "no registers defined\n");
@@ -259,21 +255,19 @@ static int ingenic_uart_probe(struct platform_device *pdev) · 7 unmodified lines
259255 spin_lock_init(&uart.port.lock);
260256 uart.port.type = PORT_16550A;
261257 uart.port.flags = UPF_SKIP_TEST | UPF_IOREMAP | UPF_FIXED_TYPE;
262− uart.port.iotype = UPIO_MEM;
263258 uart.port.mapbase = regs->start;
264− uart.port.regshift = 2;
265259 uart.port.serial_out = ingenic_uart_serial_out;
266260 uart.port.serial_in = ingenic_uart_serial_in;
267− uart.port.irq = irq;
268261 uart.port.dev = &pdev->dev;
269− uart.port.fifosize = cdata->fifosize;
270262 uart.tx_loadsz = cdata->tx_loadsz;
271263 uart.capabilities = UART_CAP_FIFO | UART_CAP_RTOIE;
272264
273− /* Check for a fixed line number */
274− line = of_alias_get_id(pdev->dev.of_node, "serial");
275− if (line >= 0)
276− uart.port.line = line;
265+ err = uart_read_port_properties(&uart.port);
266+ if (err)
267+ return err;
268+
269+ uart.port.regshift = 2;
270+ uart.port.fifosize = cdata->fifosize;
277271
278272 uart.port.membase = devm_ioremap(&pdev->dev, regs->start,
279273 resource_size(regs));
drivers/tty/serial/8250/8250_lpc18xx.c+8−12
@@ -92,11 +92,7 @@ static int lpc18xx_serial_probe(struct platform_device *pdev) · 91 unmodified lines
9292 struct lpc18xx_uart_data *data;
9393 struct uart_8250_port uart;
9494 struct resource *res;
95− int irq, ret;
96−
97− irq = platform_get_irq(pdev, 0);
98− if (irq < 0)
99− return irq;
95+ int ret;
10096
10197 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
10298 if (!res) {
@@ -139,19 +135,12 @@ static int lpc18xx_serial_probe(struct platform_device *pdev) · 36 unmodified lines
139135 goto dis_clk_reg;
140136 }
141137
142− ret = of_alias_get_id(pdev->dev.of_node, "serial");
143− if (ret >= 0)
144− uart.port.line = ret;
145−
146138 data->dma.rx_param = data;
147139 data->dma.tx_param = data;
148140
149141 spin_lock_init(&uart.port.lock);
150142 uart.port.dev = &pdev->dev;
151− uart.port.irq = irq;
152− uart.port.iotype = UPIO_MEM32;
153143 uart.port.mapbase = res->start;
154− uart.port.regshift = 2;
155144 uart.port.type = PORT_16550A;
156145 uart.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SKIP_TEST;
157146 uart.port.uartclk = clk_get_rate(data->clk_uart);
@@ -160,6 +149,13 @@ static int lpc18xx_serial_probe(struct platform_device *pdev) · 2 unmodified lines
160149 uart.port.rs485_supported = lpc18xx_rs485_supported;
161150 uart.port.serial_out = lpc18xx_uart_serial_out;
162151
152+ ret = uart_read_port_properties(&uart.port);
153+ if (ret)
154+ return ret;
155+
156+ uart.port.iotype = UPIO_MEM32;
157+ uart.port.regshift = 2;
158+
163159 uart.dma = &data->dma;
164160 uart.dma->rxconf.src_maxburst = 1;
165161 uart.dma->txconf.dst_maxburst = 1;
drivers/tty/serial/8250/8250_of.c+61−82
@@ -4,7 +4,10 @@ · 3 unmodified lines
44 *
55 * Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>, IBM Corp.
66 */
7+
8+#include <linux/bits.h>
79 #include <linux/console.h>
10+#include <linux/math.h>
811 #include <linux/module.h>
912 #include <linux/slab.h>
1013 #include <linux/serial_core.h>
@@ -25,6 +28,36 @@ struct of_serial_info { · 14 unmodified lines
2528 int line;
2629 };
2730
31+/* Nuvoton NPCM timeout register */
32+#define UART_NPCM_TOR 7
33+#define UART_NPCM_TOIE BIT(7) /* Timeout Interrupt Enable */
34+
35+static int npcm_startup(struct uart_port *port)
36+{
37+ /*
38+ * Nuvoton calls the scratch register 'UART_TOR' (timeout
39+ * register). Enable it, and set TIOC (timeout interrupt
40+ * comparator) to be 0x20 for correct operation.
41+ */
42+ serial_port_out(port, UART_NPCM_TOR, UART_NPCM_TOIE | 0x20);
43+
44+ return serial8250_do_startup(port);
45+}
46+
47+/* Nuvoton NPCM UARTs have a custom divisor calculation */
48+static unsigned int npcm_get_divisor(struct uart_port *port, unsigned int baud,
49+ unsigned int *frac)
50+{
51+ return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2;
52+}
53+
54+static int npcm_setup(struct uart_port *port)
55+{
56+ port->get_divisor = npcm_get_divisor;
57+ port->startup = npcm_startup;
58+ return 0;
59+}
60+
2861 /*
2962 * Fill a struct uart_port for a given device node
3063 */
@@ -36,37 +69,22 @@ static int of_platform_serial_setup(struct platform_device *ofdev, · 5 unmodified lines
3669 struct device *dev = &ofdev->dev;
3770 struct device_node *np = dev->of_node;
3871 struct uart_port *port = &up->port;
39− u32 clk, spd, prop;
40− int ret, irq;
72+ u32 spd;
73+ int ret;
4174
4275 memset(port, 0, sizeof *port);
4376
4477 pm_runtime_enable(&ofdev->dev);
4578 pm_runtime_get_sync(&ofdev->dev);
4679
47− if (of_property_read_u32(np, "clock-frequency", &clk)) {
48−
49− /* Get clk rate through clk driver if present */
50− info->clk = devm_clk_get_enabled(dev, NULL);
51− if (IS_ERR(info->clk)) {
52− ret = dev_err_probe(dev, PTR_ERR(info->clk), "failed to get clock\n");
53− goto err_pmruntime;
54− }
55−
56− clk = clk_get_rate(info->clk);
57− }
58− /* If current-speed was set, then try not to change it. */
59− if (of_property_read_u32(np, "current-speed", &spd) == 0)
60− port->custom_divisor = clk / (16 * spd);
61−
6280 ret = of_address_to_resource(np, 0, &resource);
6381 if (ret) {
6482 dev_err_probe(dev, ret, "invalid address\n");
6583 goto err_pmruntime;
6684 }
6785
68− port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT |
69− UPF_FIXED_TYPE;
86+ port->dev = &ofdev->dev;
87+ port->flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_FIXED_TYPE;
7088 spin_lock_init(&port->lock);
7189
7290 if (resource_type(&resource) == IORESOURCE_IO) {
@@ -75,70 +93,31 @@ static int of_platform_serial_setup(struct platform_device *ofdev, · 2 unmodified lines
7593 } else {
7694 port->mapbase = resource.start;
7795 port->mapsize = resource_size(&resource);
96+ port->flags |= UPF_IOREMAP;
97+ }
7898
79− /* Check for shifted address mapping */
80− if (of_property_read_u32(np, "reg-offset", &prop) == 0) {
81− if (prop >= port->mapsize) {
82− ret = dev_err_probe(dev, -EINVAL, "reg-offset %u exceeds region size %pa\n",
83− prop, &port->mapsize);
84− goto err_pmruntime;
85− }
99+ ret = uart_read_and_validate_port_properties(port);
100+ if (ret)
101+ goto err_pmruntime;
86102
87− port->mapbase += prop;
88− port->mapsize -= prop;
103+ /* Get clk rate through clk driver if present */
104+ if (!port->uartclk) {
105+ info->clk = devm_clk_get_enabled(dev, NULL);
106+ if (IS_ERR(info->clk)) {
107+ ret = dev_err_probe(dev, PTR_ERR(info->clk), "failed to get clock\n");
108+ goto err_pmruntime;
89109 }
90110
91− port->iotype = UPIO_MEM;
92− if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {
93− switch (prop) {
94− case 1:
95− port->iotype = UPIO_MEM;
96− break;
97− case 2:
98− port->iotype = UPIO_MEM16;
99− break;
100− case 4:
101− port->iotype = of_device_is_big_endian(np) ?
102− UPIO_MEM32BE : UPIO_MEM32;
103− break;
104− default:
105− ret = dev_err_probe(dev, -EINVAL, "unsupported reg-io-width (%u)\n",
106− prop);
107− goto err_pmruntime;
108− }
109− }
110− port->flags |= UPF_IOREMAP;
111+ port->uartclk = clk_get_rate(info->clk);
111112 }
113+ /* If current-speed was set, then try not to change it. */
114+ if (of_property_read_u32(np, "current-speed", &spd) == 0)
115+ port->custom_divisor = port->uartclk / (16 * spd);
112116
113117 /* Compatibility with the deprecated pxa driver and 8250_pxa drivers. */
114118 if (of_device_is_compatible(np, "mrvl,mmp-uart"))
115119 port->regshift = 2;
116120
117− /* Check for registers offset within the devices address range */
118− if (of_property_read_u32(np, "reg-shift", &prop) == 0)
119− port->regshift = prop;
120−
121− /* Check for fifo size */
122− if (of_property_read_u32(np, "fifo-size", &prop) == 0)
123− port->fifosize = prop;
124−
125− /* Check for a fixed line number */
126− ret = of_alias_get_id(np, "serial");
127− if (ret >= 0)
128− port->line = ret;
129−
130− irq = of_irq_get(np, 0);
131− if (irq < 0) {
132− if (irq == -EPROBE_DEFER) {
133− ret = -EPROBE_DEFER;
134− goto err_pmruntime;
135− }
136− /* IRQ support not mandatory */
137− irq = 0;
138− }
139−
140− port->irq = irq;
141−
142121 info->rst = devm_reset_control_get_optional_shared(&ofdev->dev, NULL);
143122 if (IS_ERR(info->rst)) {
144123 ret = PTR_ERR(info->rst);
@@ -150,12 +129,6 @@ static int of_platform_serial_setup(struct platform_device *ofdev, · 5 unmodified lines
150129 goto err_pmruntime;
151130
152131 port->type = type;
153− port->uartclk = clk;
154−
155− if (of_property_read_bool(np, "no-loopback-test"))
156− port->flags |= UPF_SKIP_TEST;
157−
158− port->dev = &ofdev->dev;
159132 port->rs485_config = serial8250_em485_config;
160133 port->rs485_supported = serial8250_em485_supported;
161134 up->rs485_start_tx = serial8250_em485_start_tx;
@@ -164,10 +137,17 @@ static int of_platform_serial_setup(struct platform_device *ofdev, · 2 unmodified lines
164137 switch (type) {
165138 case PORT_RT2880:
166139 ret = rt288x_setup(port);
167− if (ret)
168− goto err_pmruntime;
140+ break;
141+ case PORT_NPCM:
142+ ret = npcm_setup(port);
143+ break;
144+ default:
145+ /* Nothing to do */
146+ ret = 0;
169147 break;
170148 }
149+ if (ret)
150+ goto err_pmruntime;
171151
172152 if (IS_REACHABLE(CONFIG_SERIAL_8250_FSL) &&
173153 (of_device_is_compatible(np, "fsl,ns16550") ||
@@ -240,7 +220,6 @@ static int of_platform_serial_probe(struct platform_device *ofdev) · 66 unmodified lines
240220 platform_set_drvdata(ofdev, info);
241221 return 0;
242222 err_dispose:
243− irq_dispose_mapping(port8250.port.irq);
244223 pm_runtime_put_sync(&ofdev->dev);
245224 pm_runtime_disable(&ofdev->dev);
246225 err_free:
drivers/tty/serial/8250/8250_omap.c+10−19
@@ -1394,11 +1394,7 @@ static int omap8250_probe(struct platform_device *pdev) · 1393 unmodified lines
13941394 struct uart_8250_port up;
13951395 struct resource *regs;
13961396 void __iomem *membase;
1397− int irq, ret;
1398−
1399− irq = platform_get_irq(pdev, 0);
1400− if (irq < 0)
1401− return irq;
1397+ int ret;
14021398
14031399 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
14041400 if (!regs) {
@@ -1419,7 +1415,6 @@ static int omap8250_probe(struct platform_device *pdev) · 14 unmodified lines
14191415 up.port.dev = &pdev->dev;
14201416 up.port.mapbase = regs->start;
14211417 up.port.membase = membase;
1422− up.port.irq = irq;
14231418 /*
14241419 * It claims to be 16C750 compatible however it is a little different.
14251420 * It has EFR and has no FCR7_64byte bit. The AFE (which it claims to
@@ -1429,13 +1424,9 @@ static int omap8250_probe(struct platform_device *pdev) · 3 unmodified lines
14291424 * or pm callback.
14301425 */
14311426 up.port.type = PORT_8250;
1432− up.port.iotype = UPIO_MEM;
1433− up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SOFT_FLOW |
1434− UPF_HARD_FLOW;
1427+ up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SOFT_FLOW | UPF_HARD_FLOW;
14351428 up.port.private_data = priv;
14361429
1437− up.port.regshift = OMAP_UART_REGSHIFT;
1438− up.port.fifosize = 64;
14391430 up.tx_loadsz = 64;
14401431 up.capabilities = UART_CAP_FIFO;
14411432 #ifdef CONFIG_PM
@@ -1461,14 +1452,14 @@ static int omap8250_probe(struct platform_device *pdev) · 19 unmodified lines
14611452 up.rs485_stop_tx = serial8250_em485_stop_tx;
14621453 up.port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE);
14631454
1464− ret = of_alias_get_id(np, "serial");
1465− if (ret < 0) {
1466− dev_err(&pdev->dev, "failed to get alias\n");
1455+ ret = uart_read_port_properties(&up.port);
1456+ if (ret)
14671457 return ret;
1468− }
1469− up.port.line = ret;
14701458
1471− if (of_property_read_u32(np, "clock-frequency", &up.port.uartclk)) {
1459+ up.port.regshift = OMAP_UART_REGSHIFT;
1460+ up.port.fifosize = 64;
1461+
1462+ if (!up.port.uartclk) {
14721463 struct clk *clk;
14731464
14741465 clk = devm_clk_get(&pdev->dev, NULL);
@@ -1560,8 +1551,8 @@ static int omap8250_probe(struct platform_device *pdev) · 85 unmodified lines
15601551 }
15611552 #endif
15621553
1563− irq_set_status_flags(irq, IRQ_NOAUTOEN);
1564− ret = devm_request_irq(&pdev->dev, irq, omap8250_irq, 0,
1554+ irq_set_status_flags(up.port.irq, IRQ_NOAUTOEN);
1555+ ret = devm_request_irq(&pdev->dev, up.port.irq, omap8250_irq, 0,
15651556 dev_name(&pdev->dev), priv);
15661557 if (ret < 0)
15671558 return ret;
drivers/tty/serial/8250/8250_pci1xxxx.c+162−13
@@ -7,23 +7,31 @@ · 6 unmodified lines
77 * Copyright (C) 2022 Microchip Technology Inc., All Rights Reserved.
88 */
99
10+#include <linux/array_size.h>
1011 #include <linux/bitfield.h>
11−#include <linux/bitops.h>
12−#include <linux/delay.h>
12+#include <linux/bits.h>
13+#include <linux/circ_buf.h>
14+#include <linux/device.h>
15+#include <linux/errno.h>
16+#include <linux/gfp_types.h>
1317 #include <linux/io.h>
1418 #include <linux/iopoll.h>
15−#include <linux/kernel.h>
19+#include <linux/minmax.h>
1620 #include <linux/module.h>
21+#include <linux/mutex.h>
22+#include <linux/overflow.h>
1723 #include <linux/pci.h>
24+#include <linux/pm.h>
1825 #include <linux/serial_core.h>
1926 #include <linux/serial_reg.h>
2027 #include <linux/serial_8250.h>
21−#include <linux/slab.h>
28+#include <linux/spinlock.h>
2229 #include <linux/string.h>
23−#include <linux/units.h>
30+#include <linux/time.h>
2431 #include <linux/tty.h>
2532 #include <linux/tty_flip.h>
26−#include <linux/8250_pci.h>
33+#include <linux/types.h>
34+#include <linux/units.h>
2735
2836 #include <asm/byteorder.h>
2937
@@ -67,6 +75,7 @@ · 37 unmodified lines
6775 #define SYSLOCK_RETRY_CNT 1000
6876
6977 #define UART_RX_BYTE_FIFO 0x00
78+#define UART_TX_BYTE_FIFO 0x00
7079 #define UART_FIFO_CTL 0x02
7180
7281 #define UART_ACTV_REG 0x11
@@ -81,10 +90,10 @@ · 8 unmodified lines
8190 #define ADCL_CFG_PIN_SEL BIT(1)
8291 #define ADCL_CFG_EN BIT(0)
8392
84−#define UART_BIT_SAMPLE_CNT 16
93+#define UART_BIT_SAMPLE_CNT_8 8
94+#define UART_BIT_SAMPLE_CNT_16 16
8595 #define BAUD_CLOCK_DIV_INT_MSK GENMASK(31, 8)
8696 #define ADCL_CFG_RTS_DELAY_MASK GENMASK(11, 8)
87−#define UART_CLOCK_DEFAULT (62500 * HZ_PER_KHZ)
8897
8998 #define UART_WAKE_REG 0x8C
9099 #define UART_WAKE_MASK_REG 0x90
@@ -95,13 +104,19 @@ · 4 unmodified lines
95104 (UART_WAKE_N_PIN | UART_WAKE_NCTS | UART_WAKE_INT)
96105
97106 #define UART_BAUD_CLK_DIVISOR_REG 0x54
107+#define FRAC_DIV_CFG_REG 0x58
98108
99109 #define UART_RESET_REG 0x94
100110 #define UART_RESET_D3_RESET_DISABLE BIT(16)
101111
102112 #define UART_BURST_STATUS_REG 0x9C
113+#define UART_TX_BURST_FIFO 0xA0
103114 #define UART_RX_BURST_FIFO 0xA4
104115
116+#define UART_BIT_DIVISOR_8 0x26731000
117+#define UART_BIT_DIVISOR_16 0x6ef71000
118+#define UART_BAUD_4MBPS 4000000
119+
105120 #define MAX_PORTS 4
106121 #define PORT_OFFSET 0x100
107122 #define RX_BUF_SIZE 512
@@ -109,6 +124,7 @@ · 1 unmodified line
109124 #define UART_BURST_SIZE 4
110125
111126 #define UART_BST_STAT_RX_COUNT_MASK 0x00FF
127+#define UART_BST_STAT_TX_COUNT_MASK 0xFF00
112128 #define UART_BST_STAT_IIR_INT_PEND 0x100000
113129 #define UART_LSR_OVERRUN_ERR_CLR 0x43
114130 #define UART_BST_STAT_LSR_RX_MASK 0x9F000000
@@ -116,6 +132,7 @@ · 1 unmodified line
116132 #define UART_BST_STAT_LSR_OVERRUN_ERR 0x2000000
117133 #define UART_BST_STAT_LSR_PARITY_ERR 0x4000000
118134 #define UART_BST_STAT_LSR_FRAME_ERR 0x8000000
135+#define UART_BST_STAT_LSR_THRE 0x20000000
119136
120137 struct pci1xxxx_8250 {
121138 unsigned int nr;
@@ -206,15 +223,21 @@ static int pci1xxxx_get_num_ports(struct pci_dev *dev) · 84 unmodified lines
206223 static unsigned int pci1xxxx_get_divisor(struct uart_port *port,
207224 unsigned int baud, unsigned int *frac)
208225 {
226+ unsigned int uart_sample_cnt;
209227 unsigned int quot;
210228
229+ if (baud >= UART_BAUD_4MBPS)
230+ uart_sample_cnt = UART_BIT_SAMPLE_CNT_8;
231+ else
232+ uart_sample_cnt = UART_BIT_SAMPLE_CNT_16;
233+
211234 /*
212235 * Calculate baud rate sampling period in nanoseconds.
213236 * Fractional part x denotes x/255 parts of a nanosecond.
214237 */
215− quot = NSEC_PER_SEC / (baud * UART_BIT_SAMPLE_CNT);
216− *frac = (NSEC_PER_SEC - quot * baud * UART_BIT_SAMPLE_CNT) *
217− 255 / UART_BIT_SAMPLE_CNT / baud;
238+ quot = NSEC_PER_SEC / (baud * uart_sample_cnt);
239+ *frac = (NSEC_PER_SEC - quot * baud * uart_sample_cnt) *
240+ 255 / uart_sample_cnt / baud;
218241
219242 return quot;
220243 }
@@ -222,6 +245,11 @@ static unsigned int pci1xxxx_get_divisor(struct uart_port *port, · 1 unmodified line
222245 static void pci1xxxx_set_divisor(struct uart_port *port, unsigned int baud,
223246 unsigned int quot, unsigned int frac)
224247 {
248+ if (baud >= UART_BAUD_4MBPS)
249+ writel(UART_BIT_DIVISOR_8, port->membase + FRAC_DIV_CFG_REG);
250+ else
251+ writel(UART_BIT_DIVISOR_16, port->membase + FRAC_DIV_CFG_REG);
252+
225253 writel(FIELD_PREP(BAUD_CLOCK_DIV_INT_MSK, quot) | frac,
226254 port->membase + UART_BAUD_CLK_DIVISOR_REG);
227255 }
@@ -233,7 +261,16 @@ static int pci1xxxx_rs485_config(struct uart_port *port, · 5 unmodified lines
233261 u32 delay_in_baud_periods;
234262 u32 baud_period_in_ns;
235263 u32 mode_cfg = 0;
264+ u32 sample_cnt;
236265 u32 clock_div;
266+ u32 frac_div;
267+
268+ frac_div = readl(port->membase + FRAC_DIV_CFG_REG);
269+
270+ if (frac_div == UART_BIT_DIVISOR_16)
271+ sample_cnt = UART_BIT_SAMPLE_CNT_16;
272+ else
273+ sample_cnt = UART_BIT_SAMPLE_CNT_8;
237274
238275 /*
239276 * pci1xxxx's uart hardware supports only RTS delay after
@@ -249,7 +286,7 @@ static int pci1xxxx_rs485_config(struct uart_port *port, · 9 unmodified lines
249286 clock_div = readl(port->membase + UART_BAUD_CLK_DIVISOR_REG);
250287 baud_period_in_ns =
251288 FIELD_GET(BAUD_CLOCK_DIV_INT_MSK, clock_div) *
252− UART_BIT_SAMPLE_CNT;
289+ sample_cnt;
253290 delay_in_baud_periods =
254291 rs485->delay_rts_after_send * NSEC_PER_MSEC /
255292 baud_period_in_ns;
@@ -344,6 +381,105 @@ static void pci1xxxx_rx_burst(struct uart_port *port, u32 uart_status) · 88 unmodified lines
344381 }
345382 }
346383
384+static void pci1xxxx_process_write_data(struct uart_port *port,
385+ struct circ_buf *xmit,
386+ int *data_empty_count,
387+ u32 *valid_byte_count)
388+{
389+ u32 valid_burst_count = *valid_byte_count / UART_BURST_SIZE;
390+
391+ /*
392+ * Each transaction transfers data in DWORDs. If there are less than
393+ * four remaining valid_byte_count to transfer or if the circular
394+ * buffer has insufficient space for a DWORD, the data is transferred
395+ * one byte at a time.
396+ */
397+ while (valid_burst_count) {
398+ if (*data_empty_count - UART_BURST_SIZE < 0)
399+ break;
400+ if (xmit->tail > (UART_XMIT_SIZE - UART_BURST_SIZE))
401+ break;
402+ writel(*(unsigned int *)&xmit->buf[xmit->tail],
403+ port->membase + UART_TX_BURST_FIFO);
404+ *valid_byte_count -= UART_BURST_SIZE;
405+ *data_empty_count -= UART_BURST_SIZE;
406+ valid_burst_count -= UART_BYTE_SIZE;
407+
408+ xmit->tail = (xmit->tail + UART_BURST_SIZE) &
409+ (UART_XMIT_SIZE - 1);
410+ }
411+
412+ while (*valid_byte_count) {
413+ if (*data_empty_count - UART_BYTE_SIZE < 0)
414+ break;
415+ writeb(xmit->buf[xmit->tail], port->membase +
416+ UART_TX_BYTE_FIFO);
417+ *data_empty_count -= UART_BYTE_SIZE;
418+ *valid_byte_count -= UART_BYTE_SIZE;
419+
420+ /*
421+ * When the tail of the circular buffer is reached, the next
422+ * byte is transferred to the beginning of the buffer.
423+ */
424+ xmit->tail = (xmit->tail + UART_BYTE_SIZE) &
425+ (UART_XMIT_SIZE - 1);
426+
427+ /*
428+ * If there are any pending burst count, data is handled by
429+ * transmitting DWORDs at a time.
430+ */
431+ if (valid_burst_count && (xmit->tail <
432+ (UART_XMIT_SIZE - UART_BURST_SIZE)))
433+ break;
434+ }
435+}
436+
437+static void pci1xxxx_tx_burst(struct uart_port *port, u32 uart_status)
438+{
439+ struct uart_8250_port *up = up_to_u8250p(port);
440+ u32 valid_byte_count;
441+ int data_empty_count;
442+ struct circ_buf *xmit;
443+
444+ xmit = &port->state->xmit;
445+
446+ if (port->x_char) {
447+ writeb(port->x_char, port->membase + UART_TX);
448+ port->icount.tx++;
449+ port->x_char = 0;
450+ return;
451+ }
452+
453+ if ((uart_tx_stopped(port)) || (uart_circ_empty(xmit))) {
454+ port->ops->stop_tx(port);
455+ } else {
456+ data_empty_count = (pci1xxxx_read_burst_status(port) &
457+ UART_BST_STAT_TX_COUNT_MASK) >> 8;
458+ do {
459+ valid_byte_count = uart_circ_chars_pending(xmit);
460+
461+ pci1xxxx_process_write_data(port, xmit,
462+ &data_empty_count,
463+ &valid_byte_count);
464+
465+ port->icount.tx++;
466+ if (uart_circ_empty(xmit))
467+ break;
468+ } while (data_empty_count && valid_byte_count);
469+ }
470+
471+ if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
472+ uart_write_wakeup(port);
473+
474+ /*
475+ * With RPM enabled, we have to wait until the FIFO is empty before
476+ * the HW can go idle. So we get here once again with empty FIFO and
477+ * disable the interrupt and RPM in __stop_tx()
478+ */
479+ if (uart_circ_empty(xmit) && !(up->capabilities & UART_CAP_RPM))
480+ port->ops->stop_tx(port);
481+}
482+
347483 static int pci1xxxx_handle_irq(struct uart_port *port)
348484 {
349485 unsigned long flags;
@@ -359,6 +495,9 @@ static int pci1xxxx_handle_irq(struct uart_port *port) · 9 unmodified lines
359495 if (status & UART_BST_STAT_LSR_RX_MASK)
360496 pci1xxxx_rx_burst(port, status);
361497
498+ if (status & UART_BST_STAT_LSR_THRE)
499+ pci1xxxx_tx_burst(port, status);
500+
362501 spin_unlock_irqrestore(&port->lock, flags);
363502
364503 return 1;
@@ -481,6 +620,17 @@ static int pci1xxxx_setup(struct pci_dev *pdev, · 116 unmodified lines
481620
482621 port->port.flags |= UPF_FIXED_TYPE | UPF_SKIP_TEST;
483622 port->port.type = PORT_MCHP16550A;
623+ /*
624+ * 8250 core considers prescaller value to be always 16.
625+ * The MCHP ports support downscaled mode and hence the
626+ * functional UART clock can be lower, i.e. 62.5MHz, than
627+ * software expects in order to support higher baud rates.
628+ * Assign here 64MHz to support 4Mbps.
629+ *
630+ * The value itself is not really used anywhere except baud
631+ * rate calculations, so we can mangle it as we wish.
632+ */
633+ port->port.uartclk = 64 * HZ_PER_MHZ;
484634 port->port.set_termios = serial8250_do_set_termios;
485635 port->port.get_divisor = pci1xxxx_get_divisor;
486636 port->port.set_divisor = pci1xxxx_set_divisor;
@@ -594,7 +744,6 @@ static int pci1xxxx_serial_probe(struct pci_dev *pdev, · 107 unmodified lines
594744
595745 memset(&uart, 0, sizeof(uart));
596746 uart.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT;
597− uart.port.uartclk = UART_CLOCK_DEFAULT;
598747 uart.port.dev = dev;
599748
600749 if (num_vectors == max_vec_reqd)
drivers/tty/serial/8250/8250_port.c+1−49
@@ -38,10 +38,6 @@ · 37 unmodified lines
3838
3939 #include "8250.h"
4040
41−/* Nuvoton NPCM timeout register */
42−#define UART_NPCM_TOR 7
43−#define UART_NPCM_TOIE BIT(7) /* Timeout Interrupt Enable */
44−
4541 /*
4642 * Debugging.
4743 */
@@ -1329,9 +1325,6 @@ static void autoconfig_irq(struct uart_8250_port *up) · 1281 unmodified lines
13291325 inb_p(ICP);
13301326 }
13311327
1332− if (uart_console(port))
1333− console_lock();
1334−
13351328 /* forget possible initially masked and pending IRQ */
13361329 probe_irq_off(probe_irq_on());
13371330 save_mcr = serial8250_in_MCR(up);
@@ -1371,9 +1364,6 @@ static void autoconfig_irq(struct uart_8250_port *up) · 33 unmodified lines
13711364 if (port->flags & UPF_FOURPORT)
13721365 outb_p(save_ICP, ICP);
13731366
1374− if (uart_console(port))
1375− console_unlock();
1376−
13771367 port->irq = (irq > 0) ? irq : 0;
13781368 }
13791369
@@ -2235,15 +2225,6 @@ int serial8250_do_startup(struct uart_port *port) · 855 unmodified lines
22352225 UART_DA830_PWREMU_MGMT_FREE);
22362226 }
22372227
2238− if (port->type == PORT_NPCM) {
2239− /*
2240− * Nuvoton calls the scratch register 'UART_TOR' (timeout
2241− * register). Enable it, and set TIOC (timeout interrupt
2242− * comparator) to be 0x20 for correct operation.
2243− */
2244− serial_port_out(port, UART_NPCM_TOR, UART_NPCM_TOIE | 0x20);
2245− }
2246−
22472228 #ifdef CONFIG_SERIAL_8250_RSA
22482229 /*
22492230 * If this is an RSA port, see if we can kick it up to the
@@ -2545,15 +2526,6 @@ static void serial8250_shutdown(struct uart_port *port) · 295 unmodified lines
25452526 serial8250_do_shutdown(port);
25462527 }
25472528
2548−/* Nuvoton NPCM UARTs have a custom divisor calculation */
2549−static unsigned int npcm_get_divisor(struct uart_8250_port *up,
2550− unsigned int baud)
2551−{
2552− struct uart_port *port = &up->port;
2553−
2554− return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2;
2555−}
2556−
25572529 static unsigned int serial8250_do_get_divisor(struct uart_port *port,
25582530 unsigned int baud,
25592531 unsigned int *frac)
@@ -2598,8 +2570,6 @@ static unsigned int serial8250_do_get_divisor(struct uart_port *port, · 38 unmodified lines
25982570 quot = 0x8001;
25992571 else if (magic_multiplier && baud >= port->uartclk / 12)
26002572 quot = 0x8002;
2601− else if (up->port.type == PORT_NPCM)
2602− quot = npcm_get_divisor(up, baud);
26032573 else
26042574 quot = uart_get_divisor(port, baud);
26052575
@@ -2714,12 +2684,8 @@ static unsigned int serial8250_get_baud_rate(struct uart_port *port, · 108 unmodified lines
27142684 */
27152685 void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk)
27162686 {
2717− struct uart_8250_port *up = up_to_u8250p(port);
27182687 struct tty_port *tport = &port->state->port;
2719− unsigned int baud, quot, frac = 0;
2720− struct ktermios *termios;
27212688 struct tty_struct *tty;
2722− unsigned long flags;
27232689
27242690 tty = tty_port_tty_get(tport);
27252691 if (!tty) {
@@ -2740,21 +2706,7 @@ void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk) · 14 unmodified lines
27402706 if (!tty_port_initialized(tport))
27412707 goto out_unlock;
27422708
2743− termios = &tty->termios;
2744−
2745− baud = serial8250_get_baud_rate(port, termios, NULL);
2746− quot = serial8250_get_divisor(port, baud, &frac);
2747−
2748− serial8250_rpm_get(up);
2749− uart_port_lock_irqsave(port, &flags);
2750−
2751− uart_update_timeout(port, termios->c_cflag, baud);
2752−
2753− serial8250_set_divisor(port, baud, quot, frac);
2754− serial_port_out(port, UART_LCR, up->lcr);
2755−
2756− uart_port_unlock_irqrestore(port, flags);
2757− serial8250_rpm_put(up);
2709+ serial8250_do_set_termios(port, &tty->termios, NULL);
27582710
27592711 out_unlock:
27602712 mutex_unlock(&tport->mutex);
drivers/tty/serial/8250/8250_pxa.c+9−13
@@ -92,11 +92,7 @@ static int serial_pxa_probe(struct platform_device *pdev) · 91 unmodified lines
9292 struct uart_8250_port uart = {};
9393 struct pxa8250_data *data;
9494 struct resource *mmres;
95− int irq, ret;
96−
97− irq = platform_get_irq(pdev, 0);
98− if (irq < 0)
99− return irq;
95+ int ret;
10096
10197 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
10298 if (!mmres)
@@ -114,21 +110,21 @@ static int serial_pxa_probe(struct platform_device *pdev) · 11 unmodified lines
114110 if (ret)
115111 return ret;
116112
117− ret = of_alias_get_id(pdev->dev.of_node, "serial");
118− if (ret >= 0)
119− uart.port.line = ret;
120−
121113 uart.port.type = PORT_XSCALE;
122− uart.port.iotype = UPIO_MEM32;
123114 uart.port.mapbase = mmres->start;
124− uart.port.regshift = 2;
125− uart.port.irq = irq;
126− uart.port.fifosize = 64;
127115 uart.port.flags = UPF_IOREMAP | UPF_SKIP_TEST | UPF_FIXED_TYPE;
128116 uart.port.dev = &pdev->dev;
129117 uart.port.uartclk = clk_get_rate(data->clk);
130118 uart.port.pm = serial_pxa_pm;
131119 uart.port.private_data = data;
120+
121+ ret = uart_read_port_properties(&uart.port);
122+ if (ret)
123+ return ret;
124+
125+ uart.port.iotype = UPIO_MEM32;
126+ uart.port.regshift = 2;
127+ uart.port.fifosize = 64;
132128 uart.dl_write = serial_pxa_dl_write;
133129
134130 ret = serial8250_register_8250_port(&uart);
drivers/tty/serial/8250/8250_tegra.c+9−17
@@ -57,25 +57,11 @@ static int tegra_uart_probe(struct platform_device *pdev) · 56 unmodified lines
5757 port = &port8250.port;
5858 spin_lock_init(&port->lock);
5959
60− port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT |
61− UPF_FIXED_TYPE;
62− port->iotype = UPIO_MEM32;
63− port->regshift = 2;
60+ port->flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_FIXED_TYPE;
6461 port->type = PORT_TEGRA;
65− port->irqflags |= IRQF_SHARED;
6662 port->dev = &pdev->dev;
6763 port->handle_break = tegra_uart_handle_break;
6864
69− ret = of_alias_get_id(pdev->dev.of_node, "serial");
70− if (ret >= 0)
71− port->line = ret;
72−
73− ret = platform_get_irq(pdev, 0);
74− if (ret < 0)
75− return ret;
76−
77− port->irq = ret;
78−
7965 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8066 if (!res)
8167 return -ENODEV;
@@ -88,12 +74,18 @@ static int tegra_uart_probe(struct platform_device *pdev) · 6 unmodified lines
8874 port->mapbase = res->start;
8975 port->mapsize = resource_size(res);
9076
77+ ret = uart_read_port_properties(port);
78+ if (ret)
79+ return ret;
80+
81+ port->iotype = UPIO_MEM32;
82+ port->regshift = 2;
83+
9184 uart->rst = devm_reset_control_get_optional_shared(&pdev->dev, NULL);
9285 if (IS_ERR(uart->rst))
9386 return PTR_ERR(uart->rst);
9487
95− if (device_property_read_u32(&pdev->dev, "clock-frequency",
96− &port->uartclk)) {
88+ if (!port->uartclk) {
9789 uart->clk = devm_clk_get(&pdev->dev, NULL);
9890 if (IS_ERR(uart->clk)) {
9991 dev_err(&pdev->dev, "failed to get clock!\n");
drivers/tty/serial/8250/8250_uniphier.c+4−13
@@ -162,7 +162,6 @@ static int uniphier_uart_probe(struct platform_device *pdev) · 161 unmodified lines
162162 struct uniphier8250_priv *priv;
163163 struct resource *regs;
164164 void __iomem *membase;
165− int irq;
166165 int ret;
167166
168167 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -175,23 +174,12 @@ static int uniphier_uart_probe(struct platform_device *pdev) · 6 unmodified lines
175174 if (!membase)
176175 return -ENOMEM;
177176
178− irq = platform_get_irq(pdev, 0);
179− if (irq < 0)
180− return irq;
181−
182177 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
183178 if (!priv)
184179 return -ENOMEM;
185180
186181 memset(&up, 0, sizeof(up));
187182
188− ret = of_alias_get_id(dev->of_node, "serial");
189− if (ret < 0) {
190− dev_err(dev, "failed to get alias id\n");
191− return ret;
192− }
193− up.port.line = ret;
194−
195183 priv->clk = devm_clk_get(dev, NULL);
196184 if (IS_ERR(priv->clk)) {
197185 dev_err(dev, "failed to get clock\n");
@@ -211,7 +199,10 @@ static int uniphier_uart_probe(struct platform_device *pdev) · 13 unmodified lines
211199 up.port.mapbase = regs->start;
212200 up.port.mapsize = resource_size(regs);
213201 up.port.membase = membase;
214− up.port.irq = irq;
202+
203+ ret = uart_read_port_properties(&up.port);
204+ if (ret)
205+ return ret;
215206
216207 up.port.type = PORT_16550A;
217208 up.port.iotype = UPIO_MEM32;
drivers/tty/serial/8250/Kconfig+1−0
@@ -149,6 +149,7 @@ config SERIAL_8250_PCI · 148 unmodified lines
149149 config SERIAL_8250_EXAR
150150 tristate "8250/16550 Exar/Commtech PCI/PCIe device support"
151151 depends on SERIAL_8250 && PCI
152+ select SERIAL_8250_PCILIB
152153 default SERIAL_8250
153154 help
154155 This builds support for XR17C1xx, XR17V3xx and some Commtech
drivers/tty/serial/amba-pl011.c+8−16
@@ -348,10 +348,7 @@ static int pl011_fifo_to_tty(struct uart_amba_port *uap) · 347 unmodified lines
348348 flag = TTY_FRAME;
349349 }
350350
351− uart_port_unlock(&uap->port);
352− sysrq = uart_handle_sysrq_char(&uap->port, ch & 255);
353− uart_port_lock(&uap->port);
354−
351+ sysrq = uart_prepare_sysrq_char(&uap->port, ch & 255);
355352 if (!sysrq)
356353 uart_insert_char(&uap->port, ch, UART011_DR_OE, ch, flag);
357354 }
@@ -1017,7 +1014,7 @@ static void pl011_dma_rx_callback(void *data) · 659 unmodified lines
10171014 ret = pl011_dma_rx_trigger_dma(uap);
10181015
10191016 pl011_dma_rx_chars(uap, pending, lastbuf, false);
1020− uart_port_unlock_irq(&uap->port);
1017+ uart_unlock_and_check_sysrq(&uap->port);
10211018 /*
10221019 * Do this check after we picked the DMA chars so we don't
10231020 * get some IRQ immediately from RX.
@@ -1540,11 +1537,10 @@ static void check_apply_cts_event_workaround(struct uart_amba_port *uap) · 516 unmodified lines
15401537 static irqreturn_t pl011_int(int irq, void *dev_id)
15411538 {
15421539 struct uart_amba_port *uap = dev_id;
1543− unsigned long flags;
15441540 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT;
15451541 int handled = 0;
15461542
1547− uart_port_lock_irqsave(&uap->port, &flags);
1543+ uart_port_lock(&uap->port);
15481544 status = pl011_read(uap, REG_RIS) & uap->im;
15491545 if (status) {
15501546 do {
@@ -1573,7 +1569,7 @@ static irqreturn_t pl011_int(int irq, void *dev_id) · 22 unmodified lines
15731569 handled = 1;
15741570 }
15751571
1576− uart_port_unlock_irqrestore(&uap->port, flags);
1572+ uart_unlock_and_check_sysrq(&uap->port);
15771573
15781574 return IRQ_RETVAL(handled);
15791575 }
@@ -2322,13 +2318,10 @@ pl011_console_write(struct console *co, const char *s, unsigned int count) · 742 unmodified lines
23222318
23232319 clk_enable(uap->clk);
23242320
2325− local_irq_save(flags);
2326− if (uap->port.sysrq)
2327− locked = 0;
2328− else if (oops_in_progress)
2329− locked = uart_port_trylock(&uap->port);
2321+ if (oops_in_progress)
2322+ locked = uart_port_trylock_irqsave(&uap->port, &flags);
23302323 else
2331− uart_port_lock(&uap->port);
2324+ uart_port_lock_irqsave(&uap->port, &flags);
23322325
23332326 /*
23342327 * First save the CR then disable the interrupts
@@ -2354,8 +2347,7 @@ pl011_console_write(struct console *co, const char *s, unsigned int count) · 19 unmodified lines
23542347 pl011_write(old_cr, uap, REG_CR);
23552348
23562349 if (locked)
2357− uart_port_unlock(&uap->port);
2358− local_irq_restore(flags);
2350+ uart_port_unlock_irqrestore(&uap->port, flags);
23592351
23602352 clk_disable(uap->clk);
23612353 }
drivers/tty/serial/ar933x_uart.c+6−12
@@ -378,7 +378,7 @@ static void ar933x_uart_rx_chars(struct ar933x_uart_port *up) · 377 unmodified lines
378378 up->port.icount.rx++;
379379 ch = rdata & AR933X_UART_DATA_TX_RX_MASK;
380380
381− if (uart_handle_sysrq_char(&up->port, ch))
381+ if (uart_prepare_sysrq_char(&up->port, ch))
382382 continue;
383383
384384 if ((up->port.ignore_status_mask & AR933X_DUMMY_STATUS_RD) == 0)
@@ -468,7 +468,7 @@ static irqreturn_t ar933x_uart_interrupt(int irq, void *dev_id) · 83 unmodified lines
468468 ar933x_uart_tx_chars(up);
469469 }
470470
471− uart_port_unlock(&up->port);
471+ uart_unlock_and_check_sysrq(&up->port);
472472
473473 return IRQ_HANDLED;
474474 }
@@ -627,14 +627,10 @@ static void ar933x_uart_console_write(struct console *co, const char *s, · 152 unmodified lines
627627 unsigned int int_en;
628628 int locked = 1;
629629
630− local_irq_save(flags);
631−
632− if (up->port.sysrq)
633− locked = 0;
634− else if (oops_in_progress)
635− locked = uart_port_trylock(&up->port);
630+ if (oops_in_progress)
631+ locked = uart_port_trylock_irqsave(&up->port, &flags);
636632 else
637− uart_port_lock(&up->port);
633+ uart_port_lock_irqsave(&up->port, &flags);
638634
639635 /*
640636 * First save the IER then disable the interrupts
@@ -654,9 +650,7 @@ static void ar933x_uart_console_write(struct console *co, const char *s, · 13 unmodified lines
654650 ar933x_uart_write(up, AR933X_UART_INT_REG, AR933X_UART_INT_ALLINTS);
655651
656652 if (locked)
657− uart_port_unlock(&up->port);
658−
659− local_irq_restore(flags);
653+ uart_port_unlock_irqrestore(&up->port, flags);
660654 }
661655
662656 static int ar933x_uart_console_setup(struct console *co, char *options)
drivers/tty/serial/bcm63xx_uart.c+8−16
@@ -285,10 +285,9 @@ static void bcm_uart_do_rx(struct uart_port *port) · 284 unmodified lines
285285 flag = TTY_PARITY;
286286 }
287287
288− if (uart_handle_sysrq_char(port, c))
288+ if (uart_prepare_sysrq_char(port, c))
289289 continue;
290290
291−
292291 if ((cstat & port->ignore_status_mask) == 0)
293292 tty_insert_flip_char(tty_port, c, flag);
294293
@@ -353,7 +352,7 @@ static irqreturn_t bcm_uart_interrupt(int irq, void *dev_id) · 58 unmodified lines
353352 estat & UART_EXTINP_DCD_MASK);
354353 }
355354
356− uart_port_unlock(port);
355+ uart_unlock_and_check_sysrq(port);
357356 return IRQ_HANDLED;
358357 }
359358
@@ -703,20 +702,14 @@ static void bcm_console_write(struct console *co, const char *s, · 343 unmodified lines
703702 {
704703 struct uart_port *port;
705704 unsigned long flags;
706− int locked;
705+ int locked = 1;
707706
708707 port = &ports[co->index];
709708
710− local_irq_save(flags);
711− if (port->sysrq) {
712− /* bcm_uart_interrupt() already took the lock */
713− locked = 0;
714− } else if (oops_in_progress) {
715− locked = uart_port_trylock(port);
716− } else {
717− uart_port_lock(port);
718− locked = 1;
719− }
709+ if (oops_in_progress)
710+ locked = uart_port_trylock_irqsave(port, &flags);
711+ else
712+ uart_port_lock_irqsave(port, &flags);
720713
721714 /* call helper to deal with \r\n */
722715 uart_console_write(port, s, count, bcm_console_putchar);
@@ -725,8 +718,7 @@ static void bcm_console_write(struct console *co, const char *s, · 2 unmodified lines
725718 wait_for_xmitr(port);
726719
727720 if (locked)
728− uart_port_unlock(port);
729− local_irq_restore(flags);
721+ uart_port_unlock_irqrestore(port, flags);
730722 }
731723
732724 /*
drivers/tty/serial/fsl_linflexuart.c+0−1
@@ -837,7 +837,6 @@ static int linflex_probe(struct platform_device *pdev) · 836 unmodified lines
837837 return ret;
838838
839839 sport->dev = &pdev->dev;
840− sport->type = PORT_LINFLEXUART;
841840 sport->iotype = UPIO_MEM;
842841 sport->irq = ret;
843842 sport->ops = &linflex_pops;
drivers/tty/serial/jsm/jsm_cls.c+0−1
@@ -395,7 +395,6 @@ static void cls_copy_data_from_uart_to_queue(struct jsm_channel *ch) · 394 unmodified lines
395395 * which in this case is the break signal.
396396 */
397397 if (linestatus & error_mask) {
398− linestatus = 0;
399398 readb(&ch->ch_cls_uart->txrx);
400399 continue;
401400 }
drivers/tty/serial/lpc32xx_hs.c+7−12
@@ -136,20 +136,16 @@ static void lpc32xx_hsuart_console_write(struct console *co, const char *s, · 135 unmodified lines
136136 int locked = 1;
137137
138138 touch_nmi_watchdog();
139− local_irq_save(flags);
140− if (up->port.sysrq)
141− locked = 0;
142− else if (oops_in_progress)
143− locked = uart_port_trylock(&up->port);
139+ if (oops_in_progress)
140+ locked = uart_port_trylock_irqsave(&up->port, &flags);
144141 else
145− uart_port_lock(&up->port);
142+ uart_port_lock_irqsave(&up->port, &flags);
146143
147144 uart_console_write(&up->port, s, count, lpc32xx_hsuart_console_putchar);
148145 wait_for_xmit_empty(&up->port);
149146
150147 if (locked)
151− uart_port_unlock(&up->port);
152− local_irq_restore(flags);
148+ uart_port_unlock_irqrestore(&up->port, flags);
153149 }
154150
155151 static int __init lpc32xx_hsuart_console_setup(struct console *co,
@@ -233,8 +229,6 @@ static unsigned int __serial_get_clock_div(unsigned long uartclk, · 77 unmodified lines
233229
234230 hsu_rate++;
235231 }
236− if (hsu_rate > 0xFF)
237− hsu_rate = 0xFF;
238232
239233 return goodrate;
240234 }
@@ -268,7 +262,8 @@ static void __serial_lpc32xx_rx(struct uart_port *port) · 27 unmodified lines
268262 tty_insert_flip_char(tport, 0, TTY_FRAME);
269263 }
270264
271− tty_insert_flip_char(tport, (tmp & 0xFF), flag);
265+ if (!uart_prepare_sysrq_char(port, tmp & 0xff))
266+ tty_insert_flip_char(tport, (tmp & 0xFF), flag);
272267
273268 tmp = readl(LPC32XX_HSUART_FIFO(port->membase));
274269 }
@@ -333,7 +328,7 @@ static irqreturn_t serial_lpc32xx_interrupt(int irq, void *dev_id) · 58 unmodified lines
333328 __serial_lpc32xx_tx(port);
334329 }
335330
336− uart_port_unlock(port);
331+ uart_unlock_and_check_sysrq(port);
337332
338333 return IRQ_HANDLED;
339334 }
drivers/tty/serial/max310x.c+165−164
@@ -30,6 +30,7 @@ · 29 unmodified lines
3030 #define MAX310X_MAJOR 204
3131 #define MAX310X_MINOR 209
3232 #define MAX310X_UART_NRMAX 16
33+#define MAX310X_MAX_PORTS 4 /* Maximum number of UART ports per IC. */
3334
3435 /* MAX310X register definitions */
3536 #define MAX310X_RHR_REG (0x00) /* RX FIFO */
@@ -66,6 +67,7 @@ · 30 unmodified lines
6667 #define MAX310X_BRGDIVMSB_REG (0x1d) /* Baud rate divisor MSB */
6768 #define MAX310X_CLKSRC_REG (0x1e) /* Clock source */
6869 #define MAX310X_REG_1F (0x1f)
70+#define MAX310X_EXTREG_START (0x20) /* Only relevant in SPI mode. */
6971
7072 #define MAX310X_REVID_REG MAX310X_REG_1F /* Revision ID */
7173
@@ -73,9 +75,9 @@ · 1 unmodified line
7375 #define MAX310X_GLOBALCMD_REG MAX310X_REG_1F /* Global Command (WO) */
7476
7577 /* Extended registers */
76−#define MAX310X_SPI_REVID_EXTREG MAX310X_REG_05 /* Revision ID */
77−#define MAX310X_I2C_REVID_EXTREG (0x25) /* Revision ID */
78−
78+#define MAX310X_REVID_EXTREG (0x25) /* Revision ID
79+ * (extended addressing space)
80+ */
7981 /* IRQ register bits */
8082 #define MAX310X_IRQ_LSR_BIT (1 << 0) /* LSR interrupt */
8183 #define MAX310X_IRQ_SPCHR_BIT (1 << 1) /* Special char interrupt */
@@ -160,14 +162,14 @@ · 78 unmodified lines
160162 #define MAX310X_IRDA_SIR_BIT (1 << 1) /* SIR mode enable */
161163
162164 /* Flow control trigger level register masks */
163−#define MAX310X_FLOWLVL_HALT_MASK (0x000f) /* Flow control halt level */
164−#define MAX310X_FLOWLVL_RES_MASK (0x00f0) /* Flow control resume level */
165+#define MAX310X_FLOWLVL_HALT_MASK GENMASK(3, 0) /* Flow control halt level */
166+#define MAX310X_FLOWLVL_RES_MASK GENMASK(7, 4) /* Flow control resume level */
165167 #define MAX310X_FLOWLVL_HALT(words) ((words / 8) & 0x0f)
166168 #define MAX310X_FLOWLVL_RES(words) (((words / 8) & 0x0f) << 4)
167169
168170 /* FIFO interrupt trigger level register masks */
169−#define MAX310X_FIFOTRIGLVL_TX_MASK (0x0f) /* TX FIFO trigger level */
170−#define MAX310X_FIFOTRIGLVL_RX_MASK (0xf0) /* RX FIFO trigger level */
171+#define MAX310X_FIFOTRIGLVL_TX_MASK GENMASK(3, 0) /* TX FIFO trigger level */
172+#define MAX310X_FIFOTRIGLVL_RX_MASK GENMASK(7, 4) /* RX FIFO trigger level */
171173 #define MAX310X_FIFOTRIGLVL_TX(words) ((words / 8) & 0x0f)
172174 #define MAX310X_FIFOTRIGLVL_RX(words) (((words / 8) & 0x0f) << 4)
173175
@@ -177,7 +179,8 @@ · 3 unmodified lines
177179 #define MAX310X_FLOWCTRL_GPIADDR_BIT (1 << 2) /* Enables that GPIO inputs
178180 * are used in conjunction with
179181 * XOFF2 for definition of
180− * special character */
182+ * special character
183+ */
181184 #define MAX310X_FLOWCTRL_SWFLOWEN_BIT (1 << 3) /* Auto SW flow ctrl enable */
182185 #define MAX310X_FLOWCTRL_SWFLOW0_BIT (1 << 4) /* SWFLOW bit 0 */
183186 #define MAX310X_FLOWCTRL_SWFLOW1_BIT (1 << 5) /* SWFLOW bit 1
@@ -214,8 +217,8 @@ · 30 unmodified lines
214217 */
215218
216219 /* PLL configuration register masks */
217−#define MAX310X_PLLCFG_PREDIV_MASK (0x3f) /* PLL predivision value */
218−#define MAX310X_PLLCFG_PLLFACTOR_MASK (0xc0) /* PLL multiplication factor */
220+#define MAX310X_PLLCFG_PREDIV_MASK GENMASK(5, 0) /* PLL predivision value */
221+#define MAX310X_PLLCFG_PLLFACTOR_MASK GENMASK(7, 6) /* PLL multiplication factor */
219222
220223 /* Baud rate generator configuration register bits */
221224 #define MAX310X_BRGCFG_2XMODE_BIT (1 << 4) /* Double baud rate */
@@ -234,7 +237,7 @@ · 12 unmodified lines
234237
235238 /* Misc definitions */
236239 #define MAX310X_FIFO_SIZE (128)
237−#define MAX310x_REV_MASK (0xf8)
240+#define MAX310x_REV_MASK GENMASK(7, 3)
238241 #define MAX310X_WRITE_BIT 0x80
239242
240243 /* Port startup definitions */
@@ -257,20 +260,21 @@ · 16 unmodified lines
257260
258261 struct max310x_if_cfg {
259262 int (*extended_reg_enable)(struct device *dev, bool enable);
260−
261− unsigned int rev_id_reg;
263+ u8 rev_id_offset;
262264 };
263265
264266 struct max310x_devtype {
265267 struct {
266268 unsigned short min;
267269 unsigned short max;
268− } slave_addr;
269− char name[9];
270+ } slave_addr; /* Relevant only in I2C mode. */
270271 int nr;
272+ char name[9];
271273 u8 mode1;
272− int (*detect)(struct device *);
273− void (*power)(struct uart_port *, int);
274+ u8 rev_id_val;
275+ u8 rev_id_reg; /* Relevant only if rev_id_val is defined. */
276+ u8 power_reg; /* Register address for power/sleep control. */
277+ u8 power_bit; /* Bit for sleep or power-off mode (active high). */
274278 };
275279
276280 struct max310x_one {
@@ -331,62 +335,52 @@ static void max310x_port_update(struct uart_port *port, u8 reg, u8 mask, u8 val) · 54 unmodified lines
331335 regmap_update_bits(one->regmap, reg, mask, val);
332336 }
333337
334−static int max3107_detect(struct device *dev)
338+static int max310x_detect(struct device *dev)
335339 {
336340 struct max310x_port *s = dev_get_drvdata(dev);
337341 unsigned int val = 0;
338342 int ret;
339343
340− ret = regmap_read(s->regmap, MAX310X_REVID_REG, &val);
341− if (ret)
342− return ret;
344+ /* Check if variant supports REV ID register: */
345+ if (s->devtype->rev_id_val) {
346+ u8 rev_id_reg = s->devtype->rev_id_reg;
343347
344− if (((val & MAX310x_REV_MASK) != MAX3107_REV_ID)) {
345− dev_err(dev,
346− "%s ID 0x%02x does not match\n", s->devtype->name, val);
347− return -ENODEV;
348− }
349−
350− return 0;
351−}
348+ /* Check if REV ID is in extended addressing space: */
349+ if (s->devtype->rev_id_reg >= MAX310X_EXTREG_START) {
350+ ret = s->if_cfg->extended_reg_enable(dev, true);
351+ if (ret)
352+ return ret;
352353
353−static int max3108_detect(struct device *dev)
354−{
355− struct max310x_port *s = dev_get_drvdata(dev);
356− unsigned int val = 0;
357− int ret;
358−
359− /* MAX3108 have not REV ID register, we just check default value
360− * from clocksource register to make sure everything works.
361− */
362− ret = regmap_read(s->regmap, MAX310X_CLKSRC_REG, &val);
363− if (ret)
364− return ret;
365−
366− if (val != (MAX310X_CLKSRC_EXTCLK_BIT | MAX310X_CLKSRC_PLLBYP_BIT)) {
367− dev_err(dev, "%s not present\n", s->devtype->name);
368− return -ENODEV;
369− }
354+ /* Adjust REV ID extended addressing space address: */
355+ if (s->if_cfg->rev_id_offset)
356+ rev_id_reg -= s->if_cfg->rev_id_offset;
357+ }
370358
371− return 0;
372−}
359+ regmap_read(s->regmap, rev_id_reg, &val);
373360
374−static int max3109_detect(struct device *dev)
375−{
376− struct max310x_port *s = dev_get_drvdata(dev);
377− unsigned int val = 0;
378− int ret;
379−
380− ret = s->if_cfg->extended_reg_enable(dev, true);
381− if (ret)
382− return ret;
361+ if (s->devtype->rev_id_reg >= MAX310X_EXTREG_START) {
362+ ret = s->if_cfg->extended_reg_enable(dev, false);
363+ if (ret)
364+ return ret;
365+ }
383366
384− regmap_read(s->regmap, s->if_cfg->rev_id_reg, &val);
385− s->if_cfg->extended_reg_enable(dev, false);
386− if (((val & MAX310x_REV_MASK) != MAX3109_REV_ID)) {
387− dev_err(dev,
388− "%s ID 0x%02x does not match\n", s->devtype->name, val);
389− return -ENODEV;
367+ if (((val & MAX310x_REV_MASK) != s->devtype->rev_id_val))
368+ return dev_err_probe(dev, -ENODEV,
369+ "%s ID 0x%02x does not match\n",
370+ s->devtype->name, val);
371+ } else {
372+ /*
373+ * For variant without REV ID register, just check default value
374+ * from clocksource register to make sure everything works.
375+ */
376+ ret = regmap_read(s->regmap, MAX310X_CLKSRC_REG, &val);
377+ if (ret)
378+ return ret;
379+
380+ if (val != (MAX310X_CLKSRC_EXTCLK_BIT | MAX310X_CLKSRC_PLLBYP_BIT))
381+ return dev_err_probe(dev, -ENODEV,
382+ "%s not present\n",
383+ s->devtype->name);
390384 }
391385
392386 return 0;
@@ -394,39 +388,10 @@ static int max3109_detect(struct device *dev) · 1 unmodified line
394388
395389 static void max310x_power(struct uart_port *port, int on)
396390 {
397− max310x_port_update(port, MAX310X_MODE1_REG,
398− MAX310X_MODE1_FORCESLEEP_BIT,
399− on ? 0 : MAX310X_MODE1_FORCESLEEP_BIT);
400− if (on)
401− msleep(50);
402−}
403−
404−static int max14830_detect(struct device *dev)
405−{
406− struct max310x_port *s = dev_get_drvdata(dev);
407− unsigned int val = 0;
408− int ret;
409−
410− ret = s->if_cfg->extended_reg_enable(dev, true);
411− if (ret)
412− return ret;
413−
414− regmap_read(s->regmap, s->if_cfg->rev_id_reg, &val);
415− s->if_cfg->extended_reg_enable(dev, false);
416− if (((val & MAX310x_REV_MASK) != MAX14830_REV_ID)) {
417− dev_err(dev,
418− "%s ID 0x%02x does not match\n", s->devtype->name, val);
419− return -ENODEV;
420− }
421−
422− return 0;
423−}
391+ struct max310x_port *s = dev_get_drvdata(port->dev);
424392
425−static void max14830_power(struct uart_port *port, int on)
426−{
427− max310x_port_update(port, MAX310X_BRGCFG_REG,
428− MAX14830_BRGCFG_CLKDIS_BIT,
429− on ? 0 : MAX14830_BRGCFG_CLKDIS_BIT);
393+ max310x_port_update(port, s->devtype->power_reg, s->devtype->power_bit,
394+ on ? 0 : s->devtype->power_bit);
430395 if (on)
431396 msleep(50);
432397 }
@@ -435,8 +400,10 @@ static const struct max310x_devtype max3107_devtype = { · 2 unmodified lines
435400 .name = "MAX3107",
436401 .nr = 1,
437402 .mode1 = MAX310X_MODE1_AUTOSLEEP_BIT | MAX310X_MODE1_IRQSEL_BIT,
438− .detect = max3107_detect,
439− .power = max310x_power,
403+ .rev_id_val = MAX3107_REV_ID,
404+ .rev_id_reg = MAX310X_REVID_REG,
405+ .power_reg = MAX310X_MODE1_REG,
406+ .power_bit = MAX310X_MODE1_FORCESLEEP_BIT,
440407 .slave_addr = {
441408 .min = 0x2c,
442409 .max = 0x2f,
@@ -447,8 +414,10 @@ static const struct max310x_devtype max3108_devtype = { · 4 unmodified lines
447414 .name = "MAX3108",
448415 .nr = 1,
449416 .mode1 = MAX310X_MODE1_AUTOSLEEP_BIT,
450− .detect = max3108_detect,
451− .power = max310x_power,
417+ .rev_id_val = 0, /* Unsupported. */
418+ .rev_id_reg = 0, /* Irrelevant when rev_id_val is not defined. */
419+ .power_reg = MAX310X_MODE1_REG,
420+ .power_bit = MAX310X_MODE1_FORCESLEEP_BIT,
452421 .slave_addr = {
453422 .min = 0x60,
454423 .max = 0x6f,
@@ -459,8 +428,10 @@ static const struct max310x_devtype max3109_devtype = { · 4 unmodified lines
459428 .name = "MAX3109",
460429 .nr = 2,
461430 .mode1 = MAX310X_MODE1_AUTOSLEEP_BIT,
462− .detect = max3109_detect,
463− .power = max310x_power,
431+ .rev_id_val = MAX3109_REV_ID,
432+ .rev_id_reg = MAX310X_REVID_EXTREG,
433+ .power_reg = MAX310X_MODE1_REG,
434+ .power_bit = MAX310X_MODE1_FORCESLEEP_BIT,
464435 .slave_addr = {
465436 .min = 0x60,
466437 .max = 0x6f,
@@ -471,8 +442,10 @@ static const struct max310x_devtype max14830_devtype = { · 4 unmodified lines
471442 .name = "MAX14830",
472443 .nr = 4,
473444 .mode1 = MAX310X_MODE1_IRQSEL_BIT,
474− .detect = max14830_detect,
475− .power = max14830_power,
445+ .rev_id_val = MAX14830_REV_ID,
446+ .rev_id_reg = MAX310X_REVID_EXTREG,
447+ .power_reg = MAX310X_BRGCFG_REG,
448+ .power_bit = MAX14830_BRGCFG_CLKDIS_BIT,
476449 .slave_addr = {
477450 .min = 0x60,
478451 .max = 0x6f,
@@ -490,10 +463,8 @@ static bool max310x_reg_writeable(struct device *dev, unsigned int reg) · 11 unmodified lines
490463 case MAX310X_RXFIFOLVL_REG:
491464 return false;
492465 default:
493− break;
466+ return true;
494467 }
495−
496− return true;
497468 }
498469
499470 static bool max310x_reg_volatile(struct device *dev, unsigned int reg)
@@ -512,10 +483,8 @@ static bool max310x_reg_volatile(struct device *dev, unsigned int reg) · 12 unmodified lines
512483 case MAX310X_REG_1F:
513484 return true;
514485 default:
515− break;
486+ return false;
516487 }
517−
518− return false;
519488 }
520489
521490 static bool max310x_reg_precious(struct device *dev, unsigned int reg)
@@ -527,10 +496,8 @@ static bool max310x_reg_precious(struct device *dev, unsigned int reg) · 5 unmodified lines
527496 case MAX310X_STS_IRQSTS_REG:
528497 return true;
529498 default:
530− break;
499+ return false;
531500 }
532−
533− return false;
534501 }
535502
536503 static bool max310x_reg_noinc(struct device *dev, unsigned int reg)
@@ -689,7 +656,8 @@ static void max310x_handle_rx(struct uart_port *port, unsigned int rxlen) · 152 unmodified lines
689656 u8 ch, flag;
690657
691658 if (port->read_status_mask == MAX310X_LSR_RXOVR_BIT) {
692− /* We are just reading, happily ignoring any error conditions.
659+ /*
660+ * We are just reading, happily ignoring any error conditions.
693661 * Break condition, parity checking, framing errors -- they
694662 * are all ignored. That means that we can do a batch-read.
695663 *
@@ -698,7 +666,7 @@ static void max310x_handle_rx(struct uart_port *port, unsigned int rxlen) · 2 unmodified lines
698666 * that the LSR register applies to the "current" character.
699667 * That's also the reason why we cannot do batched reads when
700668 * asked to check the individual statuses.
701− * */
669+ */
702670
703671 sts = max310x_port_read(port, MAX310X_LSR_IRQSTS_REG);
704672 max310x_batch_read(port, one->rx_buf, rxlen);
@@ -802,8 +770,10 @@ static void max310x_handle_tx(struct uart_port *port) · 97 unmodified lines
802770 to_send = (to_send > txlen) ? txlen : to_send;
803771
804772 if (until_end < to_send) {
805− /* It's a circ buffer -- wrap around.
806− * We could do that in one SPI transaction, but meh. */
773+ /*
774+ * It's a circ buffer -- wrap around.
775+ * We could do that in one SPI transaction, but meh.
776+ */
807777 max310x_batch_write(port, xmit->buf + xmit->tail, until_end);
808778 max310x_batch_write(port, xmit->buf, to_send - until_end);
809779 } else {
@@ -848,6 +818,7 @@ static irqreturn_t max310x_port_irq(struct max310x_port *s, int portno) · 38 unmodified lines
848818 if (ists & MAX310X_IRQ_TXEMPTY_BIT)
849819 max310x_start_tx(port);
850820 } while (1);
821+
851822 return res;
852823 }
853824
@@ -892,7 +863,8 @@ static unsigned int max310x_tx_empty(struct uart_port *port) · 38 unmodified lines
892863
893864 static unsigned int max310x_get_mctrl(struct uart_port *port)
894865 {
895− /* DCD and DSR are not wired and CTS/RTS is handled automatically
866+ /*
867+ * DCD and DSR are not wired and CTS/RTS is handled automatically
896868 * so just indicate DSR and CAR asserted
897869 */
898870 return TIOCM_DSR | TIOCM_CAR;
@@ -984,7 +956,8 @@ static void max310x_set_termios(struct uart_port *port, · 85 unmodified lines
984956 max310x_port_write(port, MAX310X_XON1_REG, termios->c_cc[VSTART]);
985957 max310x_port_write(port, MAX310X_XOFF1_REG, termios->c_cc[VSTOP]);
986958
987− /* Disable transmitter before enabling AutoCTS or auto transmitter
959+ /*
960+ * Disable transmitter before enabling AutoCTS or auto transmitter
988961 * flow control
989962 */
990963 if (termios->c_cflag & CRTSCTS || termios->c_iflag & IXOFF) {
@@ -1011,7 +984,8 @@ static void max310x_set_termios(struct uart_port *port, · 20 unmodified lines
1011984 }
1012985 max310x_port_write(port, MAX310X_FLOWCTRL_REG, flow);
1013986
1014− /* Enable transmitter after disabling AutoCTS and auto transmitter
987+ /*
988+ * Enable transmitter after disabling AutoCTS and auto transmitter
1015989 * flow control
1016990 */
1017991 if (!(termios->c_cflag & CRTSCTS) && !(termios->c_iflag & IXOFF)) {
@@ -1072,10 +1046,9 @@ static int max310x_rs485_config(struct uart_port *port, struct ktermios *termios · 54 unmodified lines
10721046
10731047 static int max310x_startup(struct uart_port *port)
10741048 {
1075− struct max310x_port *s = dev_get_drvdata(port->dev);
10761049 unsigned int val;
10771050
1078− s->devtype->power(port, 1);
1051+ max310x_power(port, 1);
10791052
10801053 /* Configure MODE1 register */
10811054 max310x_port_update(port, MAX310X_MODE1_REG,
@@ -1103,8 +1076,11 @@ static int max310x_startup(struct uart_port *port) · 21 unmodified lines
11031076 MAX310X_MODE2_ECHOSUPR_BIT);
11041077 }
11051078
1106− /* Configure flow control levels */
1107− /* Flow control halt level 96, resume level 48 */
1079+ /*
1080+ * Configure flow control levels:
1081+ * resume: 48
1082+ * halt: 96
1083+ */
11081084 max310x_port_write(port, MAX310X_FLOWLVL_REG,
11091085 MAX310X_FLOWLVL_RES(48) | MAX310X_FLOWLVL_HALT(96));
11101086
@@ -1120,12 +1096,10 @@ static int max310x_startup(struct uart_port *port) · 9 unmodified lines
11201096
11211097 static void max310x_shutdown(struct uart_port *port)
11221098 {
1123− struct max310x_port *s = dev_get_drvdata(port->dev);
1124−
11251099 /* Disable all interrupts */
11261100 max310x_port_write(port, MAX310X_IRQEN_REG, 0);
11271101
1128− s->devtype->power(port, 0);
1102+ max310x_power(port, 0);
11291103 }
11301104
11311105 static const char *max310x_type(struct uart_port *port)
@@ -1187,7 +1161,7 @@ static int __maybe_unused max310x_suspend(struct device *dev) · 55 unmodified lines
11871161
11881162 for (i = 0; i < s->devtype->nr; i++) {
11891163 uart_suspend_port(&max310x_uart, &s->p[i].port);
1190− s->devtype->power(&s->p[i].port, 0);
1164+ max310x_power(&s->p[i].port, 0);
11911165 }
11921166
11931167 return 0;
@@ -1199,7 +1173,7 @@ static int __maybe_unused max310x_resume(struct device *dev) · 5 unmodified lines
11991173 int i;
12001174
12011175 for (i = 0; i < s->devtype->nr; i++) {
1202− s->devtype->power(&s->p[i].port, 1);
1176+ max310x_power(&s->p[i].port, 1);
12031177 uart_resume_port(&max310x_uart, &s->p[i].port);
12041178 }
12051179
@@ -1209,7 +1183,7 @@ static int __maybe_unused max310x_resume(struct device *dev) · 3 unmodified lines
12091183 static SIMPLE_DEV_PM_OPS(max310x_pm_ops, max310x_suspend, max310x_resume);
12101184
12111185 #ifdef CONFIG_GPIOLIB
1212−static int max310x_gpio_get(struct gpio_chip *chip, unsigned offset)
1186+static int max310x_gpio_get(struct gpio_chip *chip, unsigned int offset)
12131187 {
12141188 unsigned int val;
12151189 struct max310x_port *s = gpiochip_get_data(chip);
@@ -1220,7 +1194,7 @@ static int max310x_gpio_get(struct gpio_chip *chip, unsigned offset) · 4 unmodified lines
12201194 return !!((val >> 4) & (1 << (offset % 4)));
12211195 }
12221196
1223−static void max310x_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1197+static void max310x_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
12241198 {
12251199 struct max310x_port *s = gpiochip_get_data(chip);
12261200 struct uart_port *port = &s->p[offset / 4].port;
@@ -1229,7 +1203,7 @@ static void max310x_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · 2 unmodified lines
12291203 value ? 1 << (offset % 4) : 0);
12301204 }
12311205
1232−static int max310x_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
1206+static int max310x_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
12331207 {
12341208 struct max310x_port *s = gpiochip_get_data(chip);
12351209 struct uart_port *port = &s->p[offset / 4].port;
@@ -1240,7 +1214,7 @@ static int max310x_gpio_direction_input(struct gpio_chip *chip, unsigned offset) · 4 unmodified lines
12401214 }
12411215
12421216 static int max310x_gpio_direction_output(struct gpio_chip *chip,
1243− unsigned offset, int value)
1217+ unsigned int offset, int value)
12441218 {
12451219 struct max310x_port *s = gpiochip_get_data(chip);
12461220 struct uart_port *port = &s->p[offset / 4].port;
@@ -1296,10 +1270,9 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty · 49 unmodified lines
12961270
12971271 /* Alloc port structure */
12981272 s = devm_kzalloc(dev, struct_size(s, p, devtype->nr), GFP_KERNEL);
1299− if (!s) {
1300− dev_err(dev, "Error allocating port structure\n");
1301− return -ENOMEM;
1302− }
1273+ if (!s)
1274+ return dev_err_probe(dev, -ENOMEM,
1275+ "Error allocating port structure\n");
13031276
13041277 /* Always ask for fixed clock rate from a property. */
13051278 device_property_read_u32(dev, "clock-frequency", &uartclk);
@@ -1320,8 +1293,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty · 14 unmodified lines
13201293 if (freq == 0)
13211294 freq = uartclk;
13221295 if (freq == 0) {
1323− dev_err(dev, "Cannot get clock rate\n");
1324− ret = -EINVAL;
1296+ ret = dev_err_probe(dev, -EINVAL, "Cannot get clock rate\n");
13251297 goto out_clk;
13261298 }
13271299
@@ -1345,7 +1317,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty · 17 unmodified lines
13451317 dev_set_drvdata(dev, s);
13461318
13471319 /* Check device to ensure we are talking to what we expect */
1348− ret = devtype->detect(dev);
1320+ ret = max310x_detect(dev);
13491321 if (ret)
13501322 goto out_clk;
13511323
@@ -1427,14 +1399,13 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty · 75 unmodified lines
14271399
14281400 /* Register port */
14291401 ret = uart_add_one_port(&max310x_uart, &s->p[i].port);
1430− if (ret) {
1431− s->p[i].port.dev = NULL;
1402+ if (ret)
14321403 goto out_uart;
1433− }
1404+
14341405 set_bit(line, max310x_lines);
14351406
14361407 /* Go to suspend mode */
1437− devtype->power(&s->p[i].port, 0);
1408+ max310x_power(&s->p[i].port, 0);
14381409 }
14391410
14401411 #ifdef CONFIG_GPIOLIB
@@ -1461,14 +1432,12 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty · 20 unmodified lines
14611432 if (!ret)
14621433 return 0;
14631434
1464− dev_err(dev, "Unable to reguest IRQ %i\n", irq);
1435+ dev_err(dev, "Unable to request IRQ %i\n", irq);
14651436
14661437 out_uart:
14671438 for (i = 0; i < devtype->nr; i++) {
1468− if (s->p[i].port.dev) {
1439+ if (test_and_clear_bit(s->p[i].port.line, max310x_lines))
14691440 uart_remove_one_port(&max310x_uart, &s->p[i].port);
1470− clear_bit(s->p[i].port.line, max310x_lines);
1471− }
14721441 }
14731442
14741443 out_clk:
@@ -1486,9 +1455,11 @@ static void max310x_remove(struct device *dev) · 11 unmodified lines
14861455 cancel_work_sync(&s->p[i].tx_work);
14871456 cancel_work_sync(&s->p[i].md_work);
14881457 cancel_work_sync(&s->p[i].rs_work);
1489− uart_remove_one_port(&max310x_uart, &s->p[i].port);
1490− clear_bit(s->p[i].port.line, max310x_lines);
1491− s->devtype->power(&s->p[i].port, 0);
1458+
1459+ if (test_and_clear_bit(s->p[i].port.line, max310x_lines))
1460+ uart_remove_one_port(&max310x_uart, &s->p[i].port);
1461+
1462+ max310x_power(&s->p[i].port, 0);
14921463 }
14931464
14941465 clk_disable_unprepare(s->clk);
@@ -1518,6 +1489,19 @@ static struct regmap_config regcfg = { · 23 unmodified lines
15181489 .max_raw_write = MAX310X_FIFO_SIZE,
15191490 };
15201491
1492+static const char *max310x_regmap_name(u8 port_id)
1493+{
1494+ switch (port_id) {
1495+ case 0: return "port0";
1496+ case 1: return "port1";
1497+ case 2: return "port2";
1498+ case 3: return "port3";
1499+ default:
1500+ WARN_ON(true);
1501+ return NULL;
1502+ }
1503+}
1504+
15211505 #ifdef CONFIG_SPI_MASTER
15221506 static int max310x_spi_extended_reg_enable(struct device *dev, bool enable)
15231507 {
@@ -1529,13 +1513,13 @@ static int max310x_spi_extended_reg_enable(struct device *dev, bool enable) · 5 unmodified lines
15291513
15301514 static const struct max310x_if_cfg __maybe_unused max310x_spi_if_cfg = {
15311515 .extended_reg_enable = max310x_spi_extended_reg_enable,
1532− .rev_id_reg = MAX310X_SPI_REVID_EXTREG,
1516+ .rev_id_offset = MAX310X_EXTREG_START,
15331517 };
15341518
15351519 static int max310x_spi_probe(struct spi_device *spi)
15361520 {
15371521 const struct max310x_devtype *devtype;
1538− struct regmap *regmaps[4];
1522+ struct regmap *regmaps[MAX310X_MAX_PORTS];
15391523 unsigned int i;
15401524 int ret;
15411525
@@ -1547,12 +1531,14 @@ static int max310x_spi_probe(struct spi_device *spi) · 5 unmodified lines
15471531 if (ret)
15481532 return ret;
15491533
1550− devtype = device_get_match_data(&spi->dev);
1534+ devtype = spi_get_device_match_data(spi);
15511535 if (!devtype)
1552− devtype = (struct max310x_devtype *)spi_get_device_id(spi)->driver_data;
1536+ return dev_err_probe(&spi->dev, -ENODEV, "Failed to match device\n");
15531537
15541538 for (i = 0; i < devtype->nr; i++) {
15551539 u8 port_mask = i * 0x20;
1540+
1541+ regcfg.name = max310x_regmap_name(i);
15561542 regcfg.read_flag_mask = port_mask;
15571543 regcfg.write_flag_mask = port_mask | MAX310X_WRITE_BIT;
15581544 regmaps[i] = devm_regmap_init_spi(spi, &regcfg);
@@ -1600,7 +1586,7 @@ static struct regmap_config regcfg_i2c = { · 41 unmodified lines
16001586 .writeable_reg = max310x_reg_writeable,
16011587 .volatile_reg = max310x_reg_volatile,
16021588 .precious_reg = max310x_reg_precious,
1603− .max_register = MAX310X_I2C_REVID_EXTREG,
1589+ .max_register = MAX310X_REVID_EXTREG,
16041590 .writeable_noinc_reg = max310x_reg_noinc,
16051591 .readable_noinc_reg = max310x_reg_noinc,
16061592 .max_raw_read = MAX310X_FIFO_SIZE,
@@ -1609,7 +1595,7 @@ static struct regmap_config regcfg_i2c = { · 2 unmodified lines
16091595
16101596 static const struct max310x_if_cfg max310x_i2c_if_cfg = {
16111597 .extended_reg_enable = max310x_i2c_extended_reg_enable,
1612− .rev_id_reg = MAX310X_I2C_REVID_EXTREG,
1598+ .rev_id_offset = 0, /* No offset in I2C mode. */
16131599 };
16141600
16151601 static unsigned short max310x_i2c_slave_addr(unsigned short addr,
@@ -1619,10 +1605,10 @@ static unsigned short max310x_i2c_slave_addr(unsigned short addr, · 3 unmodified lines
16191605 * For MAX14830 and MAX3109, the slave address depends on what the
16201606 * A0 and A1 pins are tied to.
16211607 * See Table I2C Address Map of the datasheet.
1622− * Based on that table, the following formulas were determined.
1623− * UART1 - UART0 = 0x10
1624− * UART2 - UART1 = 0x20 + 0x10
1625− * UART3 - UART2 = 0x10
1608+ * Based on that table, the following formulas were determined:
1609+ * UART1 - UART0 = 0x10
1610+ * UART2 - UART1 = 0x20 + 0x10
1611+ * UART3 - UART2 = 0x10
16261612 */
16271613
16281614 addr -= nr * 0x10;
@@ -1635,20 +1621,24 @@ static unsigned short max310x_i2c_slave_addr(unsigned short addr, · 6 unmodified lines
16351621
16361622 static int max310x_i2c_probe(struct i2c_client *client)
16371623 {
1638− const struct max310x_devtype *devtype =
1639− device_get_match_data(&client->dev);
1624+ const struct max310x_devtype *devtype;
16401625 struct i2c_client *port_client;
1641− struct regmap *regmaps[4];
1626+ struct regmap *regmaps[MAX310X_MAX_PORTS];
16421627 unsigned int i;
16431628 u8 port_addr;
16441629
1630+ devtype = i2c_get_match_data(client);
1631+ if (!devtype)
1632+ return dev_err_probe(&client->dev, -ENODEV, "Failed to match device\n");
1633+
16451634 if (client->addr < devtype->slave_addr.min ||
1646− client->addr > devtype->slave_addr.max)
1635+ client->addr > devtype->slave_addr.max)
16471636 return dev_err_probe(&client->dev, -EINVAL,
16481637 "Slave addr 0x%x outside of range [0x%x, 0x%x]\n",
16491638 client->addr, devtype->slave_addr.min,
16501639 devtype->slave_addr.max);
16511640
1641+ regcfg_i2c.name = max310x_regmap_name(0);
16521642 regmaps[0] = devm_regmap_init_i2c(client, &regcfg_i2c);
16531643
16541644 for (i = 1; i < devtype->nr; i++) {
@@ -1657,6 +1647,7 @@ static int max310x_i2c_probe(struct i2c_client *client) · 2 unmodified lines
16571647 client->adapter,
16581648 port_addr);
16591649
1650+ regcfg_i2c.name = max310x_regmap_name(i);
16601651 regmaps[i] = devm_regmap_init_i2c(port_client, &regcfg_i2c);
16611652 }
16621653
@@ -1669,6 +1660,15 @@ static void max310x_i2c_remove(struct i2c_client *client) · 6 unmodified lines
16691660 max310x_remove(&client->dev);
16701661 }
16711662
1663+static const struct i2c_device_id max310x_i2c_id_table[] = {
1664+ { "max3107", (kernel_ulong_t)&max3107_devtype, },
1665+ { "max3108", (kernel_ulong_t)&max3108_devtype, },
1666+ { "max3109", (kernel_ulong_t)&max3109_devtype, },
1667+ { "max14830", (kernel_ulong_t)&max14830_devtype, },
1668+ { }
1669+};
1670+MODULE_DEVICE_TABLE(i2c, max310x_i2c_id_table);
1671+
16721672 static struct i2c_driver max310x_i2c_driver = {
16731673 .driver = {
16741674 .name = MAX310X_NAME,
@@ -1677,6 +1677,7 @@ static struct i2c_driver max310x_i2c_driver = { · 2 unmodified lines
16771677 },
16781678 .probe = max310x_i2c_probe,
16791679 .remove = max310x_i2c_remove,
1680+ .id_table = max310x_i2c_id_table,
16801681 };
16811682 #endif
16821683
drivers/tty/serial/mcf.c+0−27
@@ -470,33 +470,6 @@ static struct mcf_uart mcf_ports[4]; · 469 unmodified lines
470470 #if defined(CONFIG_SERIAL_MCF_CONSOLE)
471471 /****************************************************************************/
472472
473−int __init early_mcf_setup(struct mcf_platform_uart *platp)
474−{
475− struct uart_port *port;
476− int i;
477−
478− for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {
479− port = &mcf_ports[i].port;
480−
481− port->line = i;
482− port->type = PORT_MCF;
483− port->mapbase = platp[i].mapbase;
484− port->membase = (platp[i].membase) ? platp[i].membase :
485− (unsigned char __iomem *) port->mapbase;
486− port->iotype = SERIAL_IO_MEM;
487− port->irq = platp[i].irq;
488− port->uartclk = MCF_BUSCLK;
489− port->flags = UPF_BOOT_AUTOCONF;
490− port->rs485_config = mcf_config_rs485;
491− port->rs485_supported = mcf_rs485_supported;
492− port->ops = &mcf_uart_ops;
493− }
494−
495− return 0;
496−}
497−
498−/****************************************************************************/
499−
500473 static void mcf_console_putc(struct console *co, const char c)
501474 {
502475 struct uart_port *port = &(mcf_ports + co->index)->port;
drivers/tty/serial/meson_uart.c+8−14
@@ -220,7 +220,7 @@ static void meson_receive_chars(struct uart_port *port) · 219 unmodified lines
220220 continue;
221221 }
222222
223− if (uart_handle_sysrq_char(port, ch))
223+ if (uart_prepare_sysrq_char(port, ch))
224224 continue;
225225
226226 if ((status & port->ignore_status_mask) == 0)
@@ -248,7 +248,7 @@ static irqreturn_t meson_uart_interrupt(int irq, void *dev_id) · 21 unmodified lines
248248 meson_uart_start_tx(port);
249249 }
250250
251− uart_port_unlock(port);
251+ uart_unlock_and_check_sysrq(port);
252252
253253 return IRQ_HANDLED;
254254 }
@@ -556,18 +556,13 @@ static void meson_serial_port_write(struct uart_port *port, const char *s, · 301 unmodified lines
556556 u_int count)
557557 {
558558 unsigned long flags;
559− int locked;
559+ int locked = 1;
560560 u32 val, tmp;
561561
562− local_irq_save(flags);
563− if (port->sysrq) {
564− locked = 0;
565− } else if (oops_in_progress) {
566− locked = uart_port_trylock(port);
567− } else {
568− uart_port_lock(port);
569− locked = 1;
570− }
562+ if (oops_in_progress)
563+ locked = uart_port_trylock_irqsave(port, &flags);
564+ else
565+ uart_port_lock_irqsave(port, &flags);
571566
572567 val = readl(port->membase + AML_UART_CONTROL);
573568 tmp = val & ~(AML_UART_TX_INT_EN | AML_UART_RX_INT_EN);
@@ -577,8 +572,7 @@ static void meson_serial_port_write(struct uart_port *port, const char *s, · 3 unmodified lines
577572 writel(val, port->membase + AML_UART_CONTROL);
578573
579574 if (locked)
580− uart_port_unlock(port);
581− local_irq_restore(flags);
575+ uart_port_unlock_irqrestore(port, flags);
582576 }
583577
584578 static void meson_serial_console_write(struct console *co, const char *s,
drivers/tty/serial/msm_serial.c+10−23
@@ -588,16 +588,14 @@ static void msm_complete_rx_dma(void *args) · 587 unmodified lines
588588 if (!(port->read_status_mask & MSM_UART_SR_RX_BREAK))
589589 flag = TTY_NORMAL;
590590
591− uart_port_unlock_irqrestore(port, flags);
592− sysrq = uart_handle_sysrq_char(port, dma->virt[i]);
593− uart_port_lock_irqsave(port, &flags);
591+ sysrq = uart_prepare_sysrq_char(port, dma->virt[i]);
594592 if (!sysrq)
595593 tty_insert_flip_char(tport, dma->virt[i], flag);
596594 }
597595
598596 msm_start_rx_dma(msm_port);
599597 done:
600− uart_port_unlock_irqrestore(port, flags);
598+ uart_unlock_and_check_sysrq_irqrestore(port, flags);
601599
602600 if (count)
603601 tty_flip_buffer_push(tport);
@@ -763,9 +761,7 @@ static void msm_handle_rx_dm(struct uart_port *port, unsigned int misr) · 159 unmodified lines
763761 if (!(port->read_status_mask & MSM_UART_SR_RX_BREAK))
764762 flag = TTY_NORMAL;
765763
766− uart_port_unlock(port);
767− sysrq = uart_handle_sysrq_char(port, buf[i]);
768− uart_port_lock(port);
764+ sysrq = uart_prepare_sysrq_char(port, buf[i]);
769765 if (!sysrq)
770766 tty_insert_flip_char(tport, buf[i], flag);
771767 }
@@ -825,9 +821,7 @@ static void msm_handle_rx(struct uart_port *port) · 53 unmodified lines
825821 else if (sr & MSM_UART_SR_PAR_FRAME_ERR)
826822 flag = TTY_FRAME;
827823
828− uart_port_unlock(port);
829− sysrq = uart_handle_sysrq_char(port, c);
830− uart_port_lock(port);
824+ sysrq = uart_prepare_sysrq_char(port, c);
831825 if (!sysrq)
832826 tty_insert_flip_char(tport, c, flag);
833827 }
@@ -948,11 +942,10 @@ static irqreturn_t msm_uart_irq(int irq, void *dev_id) · 114 unmodified lines
948942 struct uart_port *port = dev_id;
949943 struct msm_port *msm_port = to_msm_port(port);
950944 struct msm_dma *dma = &msm_port->rx_dma;
951− unsigned long flags;
952945 unsigned int misr;
953946 u32 val;
954947
955− uart_port_lock_irqsave(port, &flags);
948+ uart_port_lock(port);
956949 misr = msm_read(port, MSM_UART_MISR);
957950 msm_write(port, 0, MSM_UART_IMR); /* disable interrupt */
958951
@@ -984,7 +977,7 @@ static irqreturn_t msm_uart_irq(int irq, void *dev_id) · 25 unmodified lines
984977 msm_handle_delta_cts(port);
985978
986979 msm_write(port, msm_port->imr, MSM_UART_IMR); /* restore interrupt */
987− uart_port_unlock_irqrestore(port, flags);
980+ uart_unlock_and_check_sysrq(port);
988981
989982 return IRQ_HANDLED;
990983 }
@@ -1621,14 +1614,10 @@ static void __msm_console_write(struct uart_port *port, const char *s, · 630 unmodified lines
16211614 num_newlines++;
16221615 count += num_newlines;
16231616
1624− local_irq_save(flags);
1625−
1626− if (port->sysrq)
1627− locked = 0;
1628− else if (oops_in_progress)
1629− locked = uart_port_trylock(port);
1617+ if (oops_in_progress)
1618+ locked = uart_port_trylock_irqsave(port, &flags);
16301619 else
1631− uart_port_lock(port);
1620+ uart_port_lock_irqsave(port, &flags);
16321621
16331622 if (is_uartdm)
16341623 msm_reset_dm_count(port, count);
@@ -1667,9 +1656,7 @@ static void __msm_console_write(struct uart_port *port, const char *s, · 32 unmodified lines
16671656 }
16681657
16691658 if (locked)
1670− uart_port_unlock(port);
1671−
1672− local_irq_restore(flags);
1659+ uart_port_unlock_irqrestore(port, flags);
16731660 }
16741661
16751662 static void msm_console_write(struct console *co, const char *s,
drivers/tty/serial/omap-serial.c+6−10
@@ -508,7 +508,7 @@ static void serial_omap_rdi(struct uart_omap_port *up, unsigned int lsr) · 507 unmodified lines
508508
509509 up->port.icount.rx++;
510510
511− if (uart_handle_sysrq_char(&up->port, ch))
511+ if (uart_prepare_sysrq_char(&up->port, ch))
512512 return;
513513
514514 uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, TTY_NORMAL);
@@ -563,7 +563,7 @@ static irqreturn_t serial_omap_irq(int irq, void *dev_id) · 48 unmodified lines
563563 }
564564 } while (max_count--);
565565
566− uart_port_unlock(&up->port);
566+ uart_unlock_and_check_sysrq(&up->port);
567567
568568 tty_flip_buffer_push(&up->port.state->port);
569569
@@ -1212,13 +1212,10 @@ serial_omap_console_write(struct console *co, const char *s, · 642 unmodified lines
12121212 unsigned int ier;
12131213 int locked = 1;
12141214
1215− local_irq_save(flags);
1216− if (up->port.sysrq)
1217− locked = 0;
1218− else if (oops_in_progress)
1219− locked = uart_port_trylock(&up->port);
1215+ if (oops_in_progress)
1216+ locked = uart_port_trylock_irqsave(&up->port, &flags);
12201217 else
1221− uart_port_lock(&up->port);
1218+ uart_port_lock_irqsave(&up->port, &flags);
12221219
12231220 /*
12241221 * First save the IER then disable the interrupts
@@ -1245,8 +1242,7 @@ serial_omap_console_write(struct console *co, const char *s, · 20 unmodified lines
12451242 check_modem_status(up);
12461243
12471244 if (locked)
1248− uart_port_unlock(&up->port);
1249− local_irq_restore(flags);
1245+ uart_port_unlock_irqrestore(&up->port, flags);
12501246 }
12511247
12521248 static int __init
drivers/tty/serial/owl-uart.c+12−18
@@ -199,6 +199,7 @@ static void owl_uart_receive_chars(struct uart_port *port) · 198 unmodified lines
199199 stat = owl_uart_read(port, OWL_UART_STAT);
200200 while (!(stat & OWL_UART_STAT_RFEM)) {
201201 char flag = TTY_NORMAL;
202+ bool sysrq;
202203
203204 if (stat & OWL_UART_STAT_RXER)
204205 port->icount.overrun++;
@@ -217,7 +218,9 @@ static void owl_uart_receive_chars(struct uart_port *port) · 12 unmodified lines
217218 val = owl_uart_read(port, OWL_UART_RXDAT);
218219 val &= 0xff;
219220
220− if ((stat & port->ignore_status_mask) == 0)
221+ sysrq = uart_prepare_sysrq_char(port, val);
222+
223+ if (!sysrq && (stat & port->ignore_status_mask) == 0)
221224 tty_insert_flip_char(&port->state->port, val, flag);
222225
223226 stat = owl_uart_read(port, OWL_UART_STAT);
@@ -229,10 +232,9 @@ static void owl_uart_receive_chars(struct uart_port *port) · 5 unmodified lines
229232 static irqreturn_t owl_uart_irq(int irq, void *dev_id)
230233 {
231234 struct uart_port *port = dev_id;
232− unsigned long flags;
233235 u32 stat;
234236
235− uart_port_lock_irqsave(port, &flags);
237+ uart_port_lock(port);
236238
237239 stat = owl_uart_read(port, OWL_UART_STAT);
238240
@@ -246,7 +248,7 @@ static irqreturn_t owl_uart_irq(int irq, void *dev_id) · 7 unmodified lines
246248 stat |= OWL_UART_STAT_RIP | OWL_UART_STAT_TIP;
247249 owl_uart_write(port, stat, OWL_UART_STAT);
248250
249− uart_port_unlock_irqrestore(port, flags);
251+ uart_unlock_and_check_sysrq(port);
250252
251253 return IRQ_HANDLED;
252254 }
@@ -508,18 +510,12 @@ static void owl_uart_port_write(struct uart_port *port, const char *s, · 255 unmodified lines
508510 {
509511 u32 old_ctl, val;
510512 unsigned long flags;
511− int locked;
513+ int locked = 1;
512514
513− local_irq_save(flags);
514−
515− if (port->sysrq)
516− locked = 0;
517− else if (oops_in_progress)
518− locked = uart_port_trylock(port);
519− else {
520− uart_port_lock(port);
521− locked = 1;
522− }
515+ if (oops_in_progress)
516+ locked = uart_port_trylock_irqsave(port, &flags);
517+ else
518+ uart_port_lock_irqsave(port, &flags);
523519
524520 old_ctl = owl_uart_read(port, OWL_UART_CTL);
525521 val = old_ctl | OWL_UART_CTL_TRFS_TX;
@@ -541,9 +537,7 @@ static void owl_uart_port_write(struct uart_port *port, const char *s, · 15 unmodified lines
541537 owl_uart_write(port, old_ctl, OWL_UART_CTL);
542538
543539 if (locked)
544− uart_port_unlock(port);
545−
546− local_irq_restore(flags);
540+ uart_port_unlock_irqrestore(port, flags);
547541 }
548542
549543 static void owl_uart_console_write(struct console *co, const char *s,
drivers/tty/serial/pch_uart.c+19−51
@@ -237,9 +237,6 @@ struct eg20t_port { · 236 unmodified lines
237237
238238 #define IRQ_NAME_SIZE 17
239239 char irq_name[IRQ_NAME_SIZE];
240−
241− /* protect the eg20t_port private structure and io access to membase */
242− spinlock_t lock;
243240 };
244241
245242 /**
@@ -567,7 +564,7 @@ static int pch_uart_hal_read(struct eg20t_port *priv, unsigned char *buf, · 321 unmodified lines
567564 if (uart_handle_break(port))
568565 continue;
569566 }
570− if (uart_handle_sysrq_char(port, rbr))
567+ if (uart_prepare_sysrq_char(port, rbr))
571568 continue;
572569
573570 buf[i++] = rbr;
@@ -599,16 +596,14 @@ static void pch_uart_hal_set_break(struct eg20t_port *priv, int on) · 25 unmodified lines
599596 iowrite8(lcr, priv->membase + UART_LCR);
600597 }
601598
602−static int push_rx(struct eg20t_port *priv, const unsigned char *buf,
603− int size)
599+static void push_rx(struct eg20t_port *priv, const unsigned char *buf,
600+ int size)
604601 {
605602 struct uart_port *port = &priv->port;
606603 struct tty_port *tport = &port->state->port;
607604
608605 tty_insert_flip_string(tport, buf, size);
609606 tty_flip_buffer_push(tport);
610−
611− return 0;
612607 }
613608
614609 static int dma_push_rx(struct eg20t_port *priv, int size)
@@ -761,7 +756,7 @@ static int handle_rx_to(struct eg20t_port *priv) · 146 unmodified lines
761756 {
762757 struct pch_uart_buffer *buf;
763758 int rx_size;
764− int ret;
759+
765760 if (!priv->start_rx) {
766761 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT |
767762 PCH_UART_HAL_RX_ERR_INT);
@@ -770,19 +765,12 @@ static int handle_rx_to(struct eg20t_port *priv) · 2 unmodified lines
770765 buf = &priv->rxbuf;
771766 do {
772767 rx_size = pch_uart_hal_read(priv, buf->buf, buf->size);
773− ret = push_rx(priv, buf->buf, rx_size);
774− if (ret)
775− return 0;
768+ push_rx(priv, buf->buf, rx_size);
776769 } while (rx_size == buf->size);
777770
778771 return PCH_UART_HANDLED_RX_INT;
779772 }
780773
781−static int handle_rx(struct eg20t_port *priv)
782−{
783− return handle_rx_to(priv);
784−}
785−
786774 static int dma_handle_rx(struct eg20t_port *priv)
787775 {
788776 struct uart_port *port = &priv->port;
@@ -1019,11 +1007,10 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) · 230 unmodified lines
10191007 u8 lsr;
10201008 int ret = 0;
10211009 unsigned char iid;
1022− unsigned long flags;
10231010 int next = 1;
10241011 u8 msr;
10251012
1026− spin_lock_irqsave(&priv->lock, flags);
1013+ uart_port_lock(&priv->port);
10271014 handled = 0;
10281015 while (next) {
10291016 iid = pch_uart_hal_get_iid(priv);
@@ -1051,7 +1038,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) · 21 unmodified lines
10511038 PCH_UART_HAL_RX_INT |
10521039 PCH_UART_HAL_RX_ERR_INT);
10531040 } else {
1054− ret = handle_rx(priv);
1041+ ret = handle_rx_to(priv);
10551042 }
10561043 break;
10571044 case PCH_UART_IID_RDR_TO: /* Received Data Ready
@@ -1083,7 +1070,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) · 25 unmodified lines
10831070 handled |= (unsigned int)ret;
10841071 }
10851072
1086− spin_unlock_irqrestore(&priv->lock, flags);
1073+ uart_unlock_and_check_sysrq(&priv->port);
10871074 return IRQ_RETVAL(handled);
10881075 }
10891076
@@ -1194,9 +1181,9 @@ static void pch_uart_break_ctl(struct uart_port *port, int ctl) · 104 unmodified lines
11941181 unsigned long flags;
11951182
11961183 priv = container_of(port, struct eg20t_port, port);
1197− spin_lock_irqsave(&priv->lock, flags);
1184+ uart_port_lock_irqsave(&priv->port, &flags);
11981185 pch_uart_hal_set_break(priv, ctl);
1199− spin_unlock_irqrestore(&priv->lock, flags);
1186+ uart_port_unlock_irqrestore(&priv->port, flags);
12001187 }
12011188
12021189 /* Grab any interrupt resources and initialise any low level driver state. */
@@ -1346,8 +1333,7 @@ static void pch_uart_set_termios(struct uart_port *port, · 143 unmodified lines
13461333
13471334 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
13481335
1349− spin_lock_irqsave(&priv->lock, flags);
1350− uart_port_lock(port);
1336+ uart_port_lock_irqsave(port, &flags);
13511337
13521338 uart_update_timeout(port, termios->c_cflag, baud);
13531339 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb);
@@ -1360,8 +1346,7 @@ static void pch_uart_set_termios(struct uart_port *port, · 6 unmodified lines
13601346 tty_termios_encode_baud_rate(termios, baud, baud);
13611347
13621348 out:
1363− uart_port_unlock(port);
1364− spin_unlock_irqrestore(&priv->lock, flags);
1349+ uart_port_unlock_irqrestore(port, flags);
13651350 }
13661351
13671352 static const char *pch_uart_type(struct uart_port *port)
@@ -1565,27 +1550,17 @@ pch_console_write(struct console *co, const char *s, unsigned int count) · 197 unmodified lines
15651550 {
15661551 struct eg20t_port *priv;
15671552 unsigned long flags;
1568− int priv_locked = 1;
1569− int port_locked = 1;
1553+ int locked = 1;
15701554 u8 ier;
15711555
15721556 priv = pch_uart_ports[co->index];
15731557
15741558 touch_nmi_watchdog();
15751559
1576− local_irq_save(flags);
1577− if (priv->port.sysrq) {
1578− /* call to uart_handle_sysrq_char already took the priv lock */
1579− priv_locked = 0;
1580− /* serial8250_handle_port() already took the port lock */
1581− port_locked = 0;
1582− } else if (oops_in_progress) {
1583− priv_locked = spin_trylock(&priv->lock);
1584− port_locked = uart_port_trylock(&priv->port);
1585− } else {
1586− spin_lock(&priv->lock);
1587− uart_port_lock(&priv->port);
1588− }
1560+ if (oops_in_progress)
1561+ locked = uart_port_trylock_irqsave(&priv->port, &flags);
1562+ else
1563+ uart_port_lock_irqsave(&priv->port, &flags);
15891564
15901565 /*
15911566 * First save the IER then disable the interrupts
@@ -1603,11 +1578,8 @@ pch_console_write(struct console *co, const char *s, unsigned int count) · 11 unmodified lines
16031578 wait_for_xmitr(priv, UART_LSR_BOTH_EMPTY);
16041579 iowrite8(ier, priv->membase + UART_IER);
16051580
1606− if (port_locked)
1607− uart_port_unlock(&priv->port);
1608− if (priv_locked)
1609− spin_unlock(&priv->lock);
1610− local_irq_restore(flags);
1581+ if (locked)
1582+ uart_port_unlock_irqrestore(&priv->port, flags);
16111583 }
16121584
16131585 static int __init pch_console_setup(struct console *co, char *options)
@@ -1704,8 +1676,6 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev, · 90 unmodified lines
17041676 pci_enable_msi(pdev);
17051677 pci_set_master(pdev);
17061678
1707− spin_lock_init(&priv->lock);
1708−
17091679 iobase = pci_resource_start(pdev, 0);
17101680 mapbase = pci_resource_start(pdev, 1);
17111681 priv->mapbase = mapbase;
@@ -1735,8 +1705,6 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev, · 23 unmodified lines
17351705 KBUILD_MODNAME ":" PCH_UART_DRIVER_DEVICE "%d",
17361706 priv->port.line);
17371707
1738− spin_lock_init(&priv->port.lock);
1739−
17401708 pci_set_drvdata(pdev, priv);
17411709 priv->trigger_level = 1;
17421710 priv->fcr = 0;
drivers/tty/serial/pmac_zilog.c+2−7
@@ -1714,18 +1714,13 @@ static int __init pmz_attach(struct platform_device *pdev) · 1713 unmodified lines
17141714 return uart_add_one_port(&pmz_uart_reg, &uap->port);
17151715 }
17161716
1717−static int __exit pmz_detach(struct platform_device *pdev)
1717+static void __exit pmz_detach(struct platform_device *pdev)
17181718 {
17191719 struct uart_pmac_port *uap = platform_get_drvdata(pdev);
17201720
1721− if (!uap)
1722− return -ENODEV;
1723−
17241721 uart_remove_one_port(&pmz_uart_reg, &uap->port);
17251722
17261723 uap->port.dev = NULL;
1727−
1728− return 0;
17291724 }
17301725
17311726 #endif /* !CONFIG_PPC_PMAC */
@@ -1794,7 +1789,7 @@ static struct macio_driver pmz_driver = { · 62 unmodified lines
17941789 #else
17951790
17961791 static struct platform_driver pmz_driver = {
1797− .remove = __exit_p(pmz_detach),
1792+ .remove_new = __exit_p(pmz_detach),
17981793 .driver = {
17991794 .name = "scc",
18001795 },
drivers/tty/serial/pxa.c+6−11
@@ -151,7 +151,7 @@ static inline void receive_chars(struct uart_pxa_port *up, int *status) · 150 unmodified lines
151151 flag = TTY_FRAME;
152152 }
153153
154− if (uart_handle_sysrq_char(&up->port, ch))
154+ if (uart_prepare_sysrq_char(&up->port, ch))
155155 goto ignore_char;
156156
157157 uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag);
@@ -232,7 +232,7 @@ static inline irqreturn_t serial_pxa_irq(int irq, void *dev_id) · 74 unmodified lines
232232 check_modem_status(up);
233233 if (lsr & UART_LSR_THRE)
234234 transmit_chars(up);
235− uart_port_unlock(&up->port);
235+ uart_unlock_and_check_sysrq(&up->port);
236236 return IRQ_HANDLED;
237237 }
238238
@@ -604,13 +604,10 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count) · 365 unmodified lines
604604 int locked = 1;
605605
606606 clk_enable(up->clk);
607− local_irq_save(flags);
608− if (up->port.sysrq)
609− locked = 0;
610− else if (oops_in_progress)
611− locked = uart_port_trylock(&up->port);
607+ if (oops_in_progress)
608+ locked = uart_port_trylock_irqsave(&up->port, &flags);
612609 else
613− uart_port_lock(&up->port);
610+ uart_port_lock_irqsave(&up->port, &flags);
614611
615612 /*
616613 * First save the IER then disable the interrupts
@@ -628,10 +625,8 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count) · 11 unmodified lines
628625 serial_out(up, UART_IER, ier);
629626
630627 if (locked)
631− uart_port_unlock(&up->port);
632− local_irq_restore(flags);
628+ uart_port_unlock_irqrestore(&up->port, flags);
633629 clk_disable(up->clk);
634−
635630 }
636631
637632 #ifdef CONFIG_CONSOLE_POLL
drivers/tty/serial/qcom_geni_serial.c+13−14
@@ -488,18 +488,16 @@ static void qcom_geni_serial_console_write(struct console *co, const char *s, · 487 unmodified lines
488488
489489 geni_status = readl(uport->membase + SE_GENI_STATUS);
490490
491− /* Cancel the current write to log the fault */
492491 if (!locked) {
493− geni_se_cancel_m_cmd(&port->se);
494− if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
495− M_CMD_CANCEL_EN, true)) {
496− geni_se_abort_m_cmd(&port->se);
497− qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
498− M_CMD_ABORT_EN, true);
499− writel(M_CMD_ABORT_EN, uport->membase +
500− SE_GENI_M_IRQ_CLEAR);
501− }
502− writel(M_CMD_CANCEL_EN, uport->membase + SE_GENI_M_IRQ_CLEAR);
492+ /*
493+ * We can only get here if an oops is in progress then we were
494+ * unable to get the lock. This means we can't safely access
495+ * our state variables like tx_remaining. About the best we
496+ * can do is wait for the FIFO to be empty before we start our
497+ * transfer, so we'll do that.
498+ */
499+ qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
500+ M_TX_FIFO_NOT_EMPTY_EN, false);
503501 } else if ((geni_status & M_GENI_CMD_ACTIVE) && !port->tx_remaining) {
504502 /*
505503 * It seems we can't interrupt existing transfers if all data
@@ -516,11 +514,12 @@ static void qcom_geni_serial_console_write(struct console *co, const char *s, · 10 unmodified lines
516514
517515 __qcom_geni_serial_console_write(uport, s, count);
518516
519− if (port->tx_remaining)
520− qcom_geni_serial_setup_tx(uport, port->tx_remaining);
521517
522− if (locked)
518+ if (locked) {
519+ if (port->tx_remaining)
520+ qcom_geni_serial_setup_tx(uport, port->tx_remaining);
523521 uart_port_unlock_irqrestore(uport, flags);
522+ }
524523 }
525524
526525 static void handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
drivers/tty/serial/rda-uart.c+10−18
@@ -394,7 +394,8 @@ static void rda_uart_receive_chars(struct uart_port *port) · 393 unmodified lines
394394 val &= 0xff;
395395
396396 port->icount.rx++;
397− tty_insert_flip_char(&port->state->port, val, flag);
397+ if (!uart_prepare_sysrq_char(port, val))
398+ tty_insert_flip_char(&port->state->port, val, flag);
398399
399400 status = rda_uart_read(port, RDA_UART_STATUS);
400401 }
@@ -405,10 +406,9 @@ static void rda_uart_receive_chars(struct uart_port *port) · 4 unmodified lines
405406 static irqreturn_t rda_interrupt(int irq, void *dev_id)
406407 {
407408 struct uart_port *port = dev_id;
408− unsigned long flags;
409409 u32 val, irq_mask;
410410
411− uart_port_lock_irqsave(port, &flags);
411+ uart_port_lock(port);
412412
413413 /* Clear IRQ cause */
414414 val = rda_uart_read(port, RDA_UART_IRQ_CAUSE);
@@ -425,7 +425,7 @@ static irqreturn_t rda_interrupt(int irq, void *dev_id) · 10 unmodified lines
425425 rda_uart_send_chars(port);
426426 }
427427
428− uart_port_unlock_irqrestore(port, flags);
428+ uart_unlock_and_check_sysrq(port);
429429
430430 return IRQ_HANDLED;
431431 }
@@ -590,18 +590,12 @@ static void rda_uart_port_write(struct uart_port *port, const char *s, · 158 unmodified lines
590590 {
591591 u32 old_irq_mask;
592592 unsigned long flags;
593− int locked;
594−
595− local_irq_save(flags);
593+ int locked = 1;
596594
597− if (port->sysrq) {
598− locked = 0;
599− } else if (oops_in_progress) {
600− locked = uart_port_trylock(port);
601− } else {
602− uart_port_lock(port);
603− locked = 1;
604− }
595+ if (oops_in_progress)
596+ locked = uart_port_trylock_irqsave(port, &flags);
597+ else
598+ uart_port_lock_irqsave(port, &flags);
605599
606600 old_irq_mask = rda_uart_read(port, RDA_UART_IRQ_MASK);
607601 rda_uart_write(port, 0, RDA_UART_IRQ_MASK);
@@ -615,9 +609,7 @@ static void rda_uart_port_write(struct uart_port *port, const char *s, · 7 unmodified lines
615609 rda_uart_write(port, old_irq_mask, RDA_UART_IRQ_MASK);
616610
617611 if (locked)
618− uart_port_unlock(port);
619−
620− local_irq_restore(flags);
612+ uart_port_unlock_irqrestore(port, flags);
621613 }
622614
623615 static void rda_uart_console_write(struct console *co, const char *s,
drivers/tty/serial/samsung_tty.c+153−117
@@ -21,26 +21,28 @@ · 20 unmodified lines
2121 * BJD, 04-Nov-2004
2222 */
2323
24−#include <linux/dmaengine.h>
24+#include <linux/console.h>
25+#include <linux/clk.h>
26+#include <linux/cpufreq.h>
27+#include <linux/delay.h>
2528 #include <linux/dma-mapping.h>
26−#include <linux/slab.h>
29+#include <linux/dmaengine.h>
30+#include <linux/init.h>
31+#include <linux/io.h>
32+#include <linux/ioport.h>
2733 #include <linux/math.h>
2834 #include <linux/module.h>
29−#include <linux/ioport.h>
30−#include <linux/io.h>
35+#include <linux/of.h>
3136 #include <linux/platform_device.h>
32−#include <linux/init.h>
37+#include <linux/serial.h>
38+#include <linux/serial_core.h>
39+#include <linux/serial_s3c.h>
40+#include <linux/slab.h>
3341 #include <linux/sysrq.h>
34−#include <linux/console.h>
3542 #include <linux/tty.h>
3643 #include <linux/tty_flip.h>
37−#include <linux/serial_core.h>
38−#include <linux/serial.h>
39−#include <linux/serial_s3c.h>
40−#include <linux/delay.h>
41−#include <linux/clk.h>
42−#include <linux/cpufreq.h>
43−#include <linux/of.h>
44+#include <linux/types.h>
45+
4446 #include <asm/irq.h>
4547
4648 /* UART name and device definitions */
@@ -73,21 +75,21 @@ struct s3c24xx_uart_info { · 26 unmodified lines
7375 enum s3c24xx_port_type type;
7476 unsigned int port_type;
7577 unsigned int fifosize;
76− unsigned long rx_fifomask;
77− unsigned long rx_fifoshift;
78− unsigned long rx_fifofull;
79− unsigned long tx_fifomask;
80− unsigned long tx_fifoshift;
81− unsigned long tx_fifofull;
82− unsigned int def_clk_sel;
83− unsigned long num_clks;
84− unsigned long clksel_mask;
85− unsigned long clksel_shift;
86− unsigned long ucon_mask;
78+ u32 rx_fifomask;
79+ u32 rx_fifoshift;
80+ u32 rx_fifofull;
81+ u32 tx_fifomask;
82+ u32 tx_fifoshift;
83+ u32 tx_fifofull;
84+ u32 clksel_mask;
85+ u32 clksel_shift;
86+ u32 ucon_mask;
87+ u8 def_clk_sel;
88+ u8 num_clks;
89+ u8 iotype;
8790
8891 /* uart port features */
89−
90− unsigned int has_divslot:1;
92+ bool has_divslot;
9193 };
9294
9395 struct s3c24xx_serial_drv_data {
@@ -196,7 +198,7 @@ static void wr_reg(const struct uart_port *port, u32 reg, u32 val) · 102 unmodified lines
196198 /* Byte-order aware bit setting/clearing functions. */
197199
198200 static inline void s3c24xx_set_bit(const struct uart_port *port, int idx,
199− unsigned int reg)
201+ u32 reg)
200202 {
201203 unsigned long flags;
202204 u32 val;
@@ -209,7 +211,7 @@ static inline void s3c24xx_set_bit(const struct uart_port *port, int idx, · 6 unmodified lines
209211 }
210212
211213 static inline void s3c24xx_clear_bit(const struct uart_port *port, int idx,
212− unsigned int reg)
214+ u32 reg)
213215 {
214216 unsigned long flags;
215217 u32 val;
@@ -233,7 +235,7 @@ static inline const char *s3c24xx_serial_portname(const struct uart_port *port) · 17 unmodified lines
233235 return to_platform_device(port->dev)->name;
234236 }
235237
236−static int s3c24xx_serial_txempty_nofifo(const struct uart_port *port)
238+static bool s3c24xx_serial_txempty_nofifo(const struct uart_port *port)
237239 {
238240 return rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE;
239241 }
@@ -242,8 +244,8 @@ static void s3c24xx_serial_rx_enable(struct uart_port *port) · 2 unmodified lines
242244 {
243245 struct s3c24xx_uart_port *ourport = to_ourport(port);
244246 unsigned long flags;
245− unsigned int ucon, ufcon;
246247 int count = 10000;
248+ u32 ucon, ufcon;
247249
248250 uart_port_lock_irqsave(port, &flags);
249251
@@ -266,7 +268,7 @@ static void s3c24xx_serial_rx_disable(struct uart_port *port) · 16 unmodified lines
266268 {
267269 struct s3c24xx_uart_port *ourport = to_ourport(port);
268270 unsigned long flags;
269− unsigned int ucon;
271+ u32 ucon;
270272
271273 uart_port_lock_irqsave(port, &flags);
272274
@@ -587,8 +589,8 @@ static inline const struct s3c2410_uartcfg · 314 unmodified lines
587589 return ourport->cfg;
588590 }
589591
590−static int s3c24xx_serial_rx_fifocnt(const struct s3c24xx_uart_port *ourport,
591− unsigned long ufstat)
592+static unsigned int
593+s3c24xx_serial_rx_fifocnt(const struct s3c24xx_uart_port *ourport, u32 ufstat)
592594 {
593595 const struct s3c24xx_uart_info *info = ourport->info;
594596
@@ -660,7 +662,7 @@ static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport) · 65 unmodified lines
660662 static void enable_rx_dma(struct s3c24xx_uart_port *ourport)
661663 {
662664 struct uart_port *port = &ourport->port;
663− unsigned int ucon;
665+ u32 ucon;
664666
665667 /* set Rx mode to DMA mode */
666668 ucon = rd_regl(port, S3C2410_UCON);
@@ -683,7 +685,7 @@ static void enable_rx_dma(struct s3c24xx_uart_port *ourport) · 16 unmodified lines
683685 static void enable_rx_pio(struct s3c24xx_uart_port *ourport)
684686 {
685687 struct uart_port *port = &ourport->port;
686− unsigned int ucon;
688+ u32 ucon;
687689
688690 /* set Rx mode to DMA mode */
689691 ucon = rd_regl(port, S3C2410_UCON);
@@ -708,13 +710,14 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport); · 18 unmodified lines
708710
709711 static irqreturn_t s3c24xx_serial_rx_chars_dma(void *dev_id)
710712 {
711− unsigned int utrstat, received;
712713 struct s3c24xx_uart_port *ourport = dev_id;
713714 struct uart_port *port = &ourport->port;
714715 struct s3c24xx_uart_dma *dma = ourport->dma;
715716 struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port);
716717 struct tty_port *t = &port->state->port;
717718 struct dma_tx_state state;
719+ unsigned int received;
720+ u32 utrstat;
718721
719722 utrstat = rd_regl(port, S3C2410_UTRSTAT);
720723 rd_regl(port, S3C2410_UFSTAT);
@@ -756,9 +759,9 @@ finish: · 35 unmodified lines
756759 static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport)
757760 {
758761 struct uart_port *port = &ourport->port;
759− unsigned int ufcon, ufstat, uerstat;
762+ unsigned int max_count = port->fifosize;
760763 unsigned int fifocnt = 0;
761− int max_count = port->fifosize;
764+ u32 ufcon, ufstat, uerstat;
762765 u8 ch, flag;
763766
764767 while (max_count-- > 0) {
@@ -778,7 +781,7 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport) · 13 unmodified lines
778781 ch = rd_reg(port, S3C2410_URXH);
779782
780783 if (port->flags & UPF_CONS_FLOW) {
781− int txe = s3c24xx_serial_txempty_nofifo(port);
784+ bool txe = s3c24xx_serial_txempty_nofifo(port);
782785
783786 if (ourport->rx_enabled) {
784787 if (!txe) {
@@ -942,7 +945,7 @@ static irqreturn_t s3c64xx_serial_handle_irq(int irq, void *id) · 157 unmodified lines
942945 {
943946 const struct s3c24xx_uart_port *ourport = id;
944947 const struct uart_port *port = &ourport->port;
945− unsigned int pend = rd_regl(port, S3C64XX_UINTP);
948+ u32 pend = rd_regl(port, S3C64XX_UINTP);
946949 irqreturn_t ret = IRQ_HANDLED;
947950
948951 if (pend & S3C64XX_UINTM_RXD_MSK) {
@@ -961,7 +964,7 @@ static irqreturn_t apple_serial_handle_irq(int irq, void *id) · 12 unmodified lines
961964 {
962965 const struct s3c24xx_uart_port *ourport = id;
963966 const struct uart_port *port = &ourport->port;
964− unsigned int pend = rd_regl(port, S3C2410_UTRSTAT);
967+ u32 pend = rd_regl(port, S3C2410_UTRSTAT);
965968 irqreturn_t ret = IRQ_NONE;
966969
967970 if (pend & (APPLE_S5L_UTRSTAT_RXTHRESH | APPLE_S5L_UTRSTAT_RXTO)) {
@@ -980,24 +983,23 @@ static irqreturn_t apple_serial_handle_irq(int irq, void *id) · 12 unmodified lines
980983 static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
981984 {
982985 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
983− unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT);
984− unsigned long ufcon = rd_regl(port, S3C2410_UFCON);
986+ u32 ufstat = rd_regl(port, S3C2410_UFSTAT);
987+ u32 ufcon = rd_regl(port, S3C2410_UFCON);
985988
986989 if (ufcon & S3C2410_UFCON_FIFOMODE) {
987− if ((ufstat & info->tx_fifomask) != 0 ||
990+ if ((ufstat & info->tx_fifomask) ||
988991 (ufstat & info->tx_fifofull))
989992 return 0;
990−
991− return 1;
993+ return TIOCSER_TEMT;
992994 }
993995
994− return s3c24xx_serial_txempty_nofifo(port);
996+ return s3c24xx_serial_txempty_nofifo(port) ? TIOCSER_TEMT : 0;
995997 }
996998
997999 /* no modem control lines */
9981000 static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port)
9991001 {
1000− unsigned int umstat = rd_reg(port, S3C2410_UMSTAT);
1002+ u32 umstat = rd_reg(port, S3C2410_UMSTAT);
10011003
10021004 if (umstat & S3C2410_UMSTAT_CTS)
10031005 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
@@ -1007,8 +1009,8 @@ static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port) · 3 unmodified lines
10071009
10081010 static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
10091011 {
1010− unsigned int umcon = rd_regl(port, S3C2410_UMCON);
1011− unsigned int ucon = rd_regl(port, S3C2410_UCON);
1012+ u32 umcon = rd_regl(port, S3C2410_UMCON);
1013+ u32 ucon = rd_regl(port, S3C2410_UCON);
10121014
10131015 if (mctrl & TIOCM_RTS)
10141016 umcon |= S3C2410_UMCOM_RTS_LOW;
@@ -1028,7 +1030,7 @@ static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl) · 13 unmodified lines
10281030 static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state)
10291031 {
10301032 unsigned long flags;
1031− unsigned int ucon;
1033+ u32 ucon;
10321034
10331035 uart_port_lock_irqsave(port, &flags);
10341036
@@ -1186,7 +1188,7 @@ static void apple_s5l_serial_shutdown(struct uart_port *port) · 151 unmodified lines
11861188 {
11871189 struct s3c24xx_uart_port *ourport = to_ourport(port);
11881190
1189− unsigned int ucon;
1191+ u32 ucon;
11901192
11911193 ucon = rd_regl(port, S3C2410_UCON);
11921194 ucon &= ~(APPLE_S5L_UCON_TXTHRESH_ENA_MSK |
@@ -1212,7 +1214,7 @@ static int s3c64xx_serial_startup(struct uart_port *port) · 19 unmodified lines
12121214 {
12131215 struct s3c24xx_uart_port *ourport = to_ourport(port);
12141216 unsigned long flags;
1215− unsigned int ufcon;
1217+ u32 ufcon;
12161218 int ret;
12171219
12181220 wr_regl(port, S3C64XX_UINTM, 0xf);
@@ -1257,7 +1259,7 @@ static int apple_s5l_serial_startup(struct uart_port *port) · 38 unmodified lines
12571259 {
12581260 struct s3c24xx_uart_port *ourport = to_ourport(port);
12591261 unsigned long flags;
1260− unsigned int ufcon;
1262+ u32 ufcon;
12611263 int ret;
12621264
12631265 wr_regl(port, S3C2410_UTRSTAT, APPLE_S5L_UTRSTAT_ALL_FLAGS);
@@ -1292,8 +1294,6 @@ static int apple_s5l_serial_startup(struct uart_port *port) · 28 unmodified lines
12921294 return ret;
12931295 }
12941296
1295−/* power power management control */
1296−
12971297 static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
12981298 unsigned int old)
12991299 {
@@ -1339,10 +1339,10 @@ static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level, · 39 unmodified lines
13391339
13401340 #define MAX_CLK_NAME_LENGTH 15
13411341
1342−static inline int s3c24xx_serial_getsource(struct uart_port *port)
1342+static inline u8 s3c24xx_serial_getsource(struct uart_port *port)
13431343 {
13441344 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1345− unsigned int ucon;
1345+ u32 ucon;
13461346
13471347 if (info->num_clks == 1)
13481348 return 0;
@@ -1352,11 +1352,10 @@ static inline int s3c24xx_serial_getsource(struct uart_port *port) · 3 unmodified lines
13521352 return ucon >> info->clksel_shift;
13531353 }
13541354
1355−static void s3c24xx_serial_setsource(struct uart_port *port,
1356− unsigned int clk_sel)
1355+static void s3c24xx_serial_setsource(struct uart_port *port, u8 clk_sel)
13571356 {
13581357 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1359− unsigned int ucon;
1358+ u32 ucon;
13601359
13611360 if (info->num_clks == 1)
13621361 return;
@@ -1372,14 +1371,15 @@ static void s3c24xx_serial_setsource(struct uart_port *port, · 9 unmodified lines
13721371
13731372 static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
13741373 unsigned int req_baud, struct clk **best_clk,
1375− unsigned int *clk_num)
1374+ u8 *clk_num)
13761375 {
13771376 const struct s3c24xx_uart_info *info = ourport->info;
13781377 struct clk *clk;
13791378 unsigned long rate;
1380− unsigned int cnt, baud, quot, best_quot = 0;
1379+ unsigned int baud, quot, best_quot = 0;
13811380 char clkname[MAX_CLK_NAME_LENGTH];
13821381 int calc_deviation, deviation = (1 << 30) - 1;
1382+ u8 cnt;
13831383
13841384 for (cnt = 0; cnt < info->num_clks; cnt++) {
13851385 /* Keep selected clock if provided */
@@ -1472,10 +1472,10 @@ static void s3c24xx_serial_set_termios(struct uart_port *port, · 86 unmodified lines
14721472 struct s3c24xx_uart_port *ourport = to_ourport(port);
14731473 struct clk *clk = ERR_PTR(-EINVAL);
14741474 unsigned long flags;
1475− unsigned int baud, quot, clk_sel = 0;
1476− unsigned int ulcon;
1477− unsigned int umcon;
1475+ unsigned int baud, quot;
14781476 unsigned int udivslot = 0;
1477+ u32 ulcon, umcon;
1478+ u8 clk_sel = 0;
14791479
14801480 /*
14811481 * We don't support modem control lines.
@@ -1737,12 +1737,12 @@ static struct uart_driver s3c24xx_uart_drv = { · 255 unmodified lines
17371737
17381738 static struct s3c24xx_uart_port s3c24xx_serial_ports[UART_NR];
17391739
1740−static void s3c24xx_serial_init_port_default(int index) {
1740+static void s3c24xx_serial_init_port_default(int index)
1741+{
17411742 struct uart_port *port = &s3c24xx_serial_ports[index].port;
17421743
17431744 spin_lock_init(&port->lock);
17441745
1745− port->iotype = UPIO_MEM;
17461746 port->uartclk = 0;
17471747 port->fifosize = 16;
17481748 port->flags = UPF_BOOT_AUTOCONF;
@@ -1758,7 +1758,7 @@ static void s3c24xx_serial_resetport(struct uart_port *port, · 9 unmodified lines
17581758 const struct s3c2410_uartcfg *cfg)
17591759 {
17601760 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1761− unsigned long ucon = rd_regl(port, S3C2410_UCON);
1761+ u32 ucon = rd_regl(port, S3C2410_UCON);
17621762
17631763 ucon &= (info->clksel_mask | info->ucon_mask);
17641764 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
@@ -1776,10 +1776,9 @@ static int s3c24xx_serial_enable_baudclk(struct s3c24xx_uart_port *ourport) · 11 unmodified lines
17761776 struct device *dev = ourport->port.dev;
17771777 const struct s3c24xx_uart_info *info = ourport->info;
17781778 char clk_name[MAX_CLK_NAME_LENGTH];
1779− unsigned int clk_sel;
17801779 struct clk *clk;
1781− int clk_num;
17821780 int ret;
1781+ u8 clk_sel, clk_num;
17831782
17841783 clk_sel = ourport->cfg->clk_sel ? : info->def_clk_sel;
17851784 for (clk_num = 0; clk_num < info->num_clks; clk_num++) {
@@ -1904,7 +1903,7 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport, · 118 unmodified lines
19041903 wr_regl(port, S3C64XX_UINTSP, 0xf);
19051904 break;
19061905 case TYPE_APPLE_S5L: {
1907− unsigned int ucon;
1906+ u32 ucon;
19081907
19091908 ucon = rd_regl(port, S3C2410_UCON);
19101909 ucon &= ~(APPLE_S5L_UCON_TXTHRESH_ENA_MSK |
@@ -1952,7 +1951,7 @@ static int s3c24xx_serial_probe(struct platform_device *pdev) · 41 unmodified lines
19521951 struct device_node *np = pdev->dev.of_node;
19531952 struct s3c24xx_uart_port *ourport;
19541953 int index = probe_index;
1955− int ret, prop = 0;
1954+ int ret, prop = 0, fifosize_prop = 1;
19561955
19571956 if (np) {
19581957 ret = of_alias_get_id(np, "serial");
@@ -1989,9 +1988,11 @@ static int s3c24xx_serial_probe(struct platform_device *pdev) · 30 unmodified lines
19891988 break;
19901989 }
19911990
1991+ ourport->port.iotype = ourport->info->iotype;
1992+
19921993 if (np) {
1993− of_property_read_u32(np,
1994− "samsung,uart-fifosize", &ourport->port.fifosize);
1994+ fifosize_prop = of_property_read_u32(np, "samsung,uart-fifosize",
1995+ &ourport->port.fifosize);
19951996
19961997 if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {
19971998 switch (prop) {
@@ -2009,10 +2010,13 @@ static int s3c24xx_serial_probe(struct platform_device *pdev) · 11 unmodified lines
20092010 }
20102011 }
20112012
2012− if (ourport->drv_data->fifosize[index])
2013− ourport->port.fifosize = ourport->drv_data->fifosize[index];
2014− else if (ourport->info->fifosize)
2015− ourport->port.fifosize = ourport->info->fifosize;
2013+ if (fifosize_prop) {
2014+ if (ourport->drv_data->fifosize[index])
2015+ ourport->port.fifosize = ourport->drv_data->fifosize[index];
2016+ else if (ourport->info->fifosize)
2017+ ourport->port.fifosize = ourport->info->fifosize;
2018+ }
2019+
20162020 ourport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SAMSUNG_CONSOLE);
20172021
20182022 /*
@@ -2058,9 +2062,8 @@ static void s3c24xx_serial_remove(struct platform_device *dev) · 39 unmodified lines
20582062 {
20592063 struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
20602064
2061− if (port) {
2065+ if (port)
20622066 uart_remove_one_port(&s3c24xx_uart_drv, port);
2063− }
20642067
20652068 uart_unregister_driver(&s3c24xx_uart_drv);
20662069 }
@@ -2106,7 +2109,7 @@ static int s3c24xx_serial_resume_noirq(struct device *dev) · 39 unmodified lines
21062109 /* restore IRQ mask */
21072110 switch (ourport->info->type) {
21082111 case TYPE_S3C6400: {
2109− unsigned int uintm = 0xf;
2112+ u32 uintm = 0xf;
21102113
21112114 if (ourport->tx_enabled)
21122115 uintm &= ~S3C64XX_UINTM_TXD_MSK;
@@ -2122,7 +2125,7 @@ static int s3c24xx_serial_resume_noirq(struct device *dev) · 9 unmodified lines
21222125 break;
21232126 }
21242127 case TYPE_APPLE_S5L: {
2125− unsigned int ucon;
2128+ u32 ucon;
21262129 int ret;
21272130
21282131 ret = clk_prepare_enable(ourport->clk);
@@ -2183,27 +2186,27 @@ static const struct dev_pm_ops s3c24xx_serial_pm_ops = { · 54 unmodified lines
21832186
21842187 static struct uart_port *cons_uart;
21852188
2186−static int
2187−s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
2189+static bool
2190+s3c24xx_serial_console_txrdy(struct uart_port *port, u32 ufcon)
21882191 {
21892192 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
2190− unsigned long ufstat, utrstat;
2193+ u32 ufstat, utrstat;
21912194
21922195 if (ufcon & S3C2410_UFCON_FIFOMODE) {
21932196 /* fifo mode - check amount of data in fifo registers... */
21942197
21952198 ufstat = rd_regl(port, S3C2410_UFSTAT);
2196− return (ufstat & info->tx_fifofull) ? 0 : 1;
2199+ return !(ufstat & info->tx_fifofull);
21972200 }
21982201
21992202 /* in non-fifo mode, we go and use the tx buffer empty */
22002203
22012204 utrstat = rd_regl(port, S3C2410_UTRSTAT);
2202− return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
2205+ return utrstat & S3C2410_UTRSTAT_TXE;
22032206 }
22042207
22052208 static bool
2206−s3c24xx_port_configured(unsigned int ucon)
2209+s3c24xx_port_configured(u32 ucon)
22072210 {
22082211 /* consider the serial port configured if the tx/rx mode set */
22092212 return (ucon & 0xf) != 0;
@@ -2218,7 +2221,7 @@ s3c24xx_port_configured(unsigned int ucon) · 8 unmodified lines
22182221 static int s3c24xx_serial_get_poll_char(struct uart_port *port)
22192222 {
22202223 const struct s3c24xx_uart_port *ourport = to_ourport(port);
2221− unsigned int ufstat;
2224+ u32 ufstat;
22222225
22232226 ufstat = rd_regl(port, S3C2410_UFSTAT);
22242227 if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
@@ -2230,8 +2233,8 @@ static int s3c24xx_serial_get_poll_char(struct uart_port *port) · 5 unmodified lines
22302233 static void s3c24xx_serial_put_poll_char(struct uart_port *port,
22312234 unsigned char c)
22322235 {
2233− unsigned int ufcon = rd_regl(port, S3C2410_UFCON);
2234− unsigned int ucon = rd_regl(port, S3C2410_UCON);
2236+ u32 ufcon = rd_regl(port, S3C2410_UFCON);
2237+ u32 ucon = rd_regl(port, S3C2410_UCON);
22352238
22362239 /* not possible to xmit on unconfigured port */
22372240 if (!s3c24xx_port_configured(ucon))
@@ -2247,7 +2250,7 @@ static void s3c24xx_serial_put_poll_char(struct uart_port *port, · 9 unmodified lines
22472250 static void
22482251 s3c24xx_serial_console_putchar(struct uart_port *port, unsigned char ch)
22492252 {
2250− unsigned int ufcon = rd_regl(port, S3C2410_UFCON);
2253+ u32 ufcon = rd_regl(port, S3C2410_UFCON);
22512254
22522255 while (!s3c24xx_serial_console_txrdy(port, ufcon))
22532256 cpu_relax();
@@ -2258,7 +2261,7 @@ static void · 4 unmodified lines
22582261 s3c24xx_serial_console_write(struct console *co, const char *s,
22592262 unsigned int count)
22602263 {
2261− unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON);
2264+ u32 ucon = rd_regl(cons_uart, S3C2410_UCON);
22622265 unsigned long flags;
22632266 bool locked = true;
22642267
@@ -2285,12 +2288,10 @@ s3c24xx_serial_get_options(struct uart_port *port, int *baud, · 20 unmodified lines
22852288 int *parity, int *bits)
22862289 {
22872290 struct clk *clk;
2288− unsigned int ulcon;
2289− unsigned int ucon;
2290− unsigned int ubrdiv;
22912291 unsigned long rate;
2292− unsigned int clk_sel;
2292+ u32 ulcon, ucon, ubrdiv;
22932293 char clk_name[MAX_CLK_NAME_LENGTH];
2294+ u8 clk_sel;
22942295
22952296 ulcon = rd_regl(port, S3C2410_ULCON);
22962297 ucon = rd_regl(port, S3C2410_UCON);
@@ -2399,8 +2400,9 @@ static const struct s3c24xx_serial_drv_data s3c6400_serial_drv_data = { · 102 unmodified lines
23992400 .name = "Samsung S3C6400 UART",
24002401 .type = TYPE_S3C6400,
24012402 .port_type = PORT_S3C6400,
2403+ .iotype = UPIO_MEM,
24022404 .fifosize = 64,
2403− .has_divslot = 1,
2405+ .has_divslot = true,
24042406 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
24052407 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
24062408 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
@@ -2428,7 +2430,8 @@ static const struct s3c24xx_serial_drv_data s5pv210_serial_drv_data = { · 21 unmodified lines
24282430 .name = "Samsung S5PV210 UART",
24292431 .type = TYPE_S3C6400,
24302432 .port_type = PORT_S3C6400,
2431− .has_divslot = 1,
2433+ .iotype = UPIO_MEM,
2434+ .has_divslot = true,
24322435 .rx_fifomask = S5PV210_UFSTAT_RXMASK,
24332436 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
24342437 .rx_fifofull = S5PV210_UFSTAT_RXFULL,
@@ -2452,12 +2455,13 @@ static const struct s3c24xx_serial_drv_data s5pv210_serial_drv_data = { · 17 unmodified lines
24522455 #endif
24532456
24542457 #if defined(CONFIG_ARCH_EXYNOS)
2455−#define EXYNOS_COMMON_SERIAL_DRV_DATA() \
2458+#define EXYNOS_COMMON_SERIAL_DRV_DATA \
24562459 .info = { \
24572460 .name = "Samsung Exynos UART", \
24582461 .type = TYPE_S3C6400, \
24592462 .port_type = PORT_S3C6400, \
2460− .has_divslot = 1, \
2463+ .iotype = UPIO_MEM, \
2464+ .has_divslot = true, \
24612465 .rx_fifomask = S5PV210_UFSTAT_RXMASK, \
24622466 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, \
24632467 .rx_fifofull = S5PV210_UFSTAT_RXFULL, \
@@ -2476,39 +2480,57 @@ static const struct s3c24xx_serial_drv_data s5pv210_serial_drv_data = { · 12 unmodified lines
24762480 } \
24772481
24782482 static const struct s3c24xx_serial_drv_data exynos4210_serial_drv_data = {
2479− EXYNOS_COMMON_SERIAL_DRV_DATA(),
2483+ EXYNOS_COMMON_SERIAL_DRV_DATA,
24802484 .fifosize = { 256, 64, 16, 16 },
24812485 };
24822486
24832487 static const struct s3c24xx_serial_drv_data exynos5433_serial_drv_data = {
2484− EXYNOS_COMMON_SERIAL_DRV_DATA(),
2488+ EXYNOS_COMMON_SERIAL_DRV_DATA,
24852489 .fifosize = { 64, 256, 16, 256 },
24862490 };
24872491
24882492 static const struct s3c24xx_serial_drv_data exynos850_serial_drv_data = {
2489− EXYNOS_COMMON_SERIAL_DRV_DATA(),
2493+ EXYNOS_COMMON_SERIAL_DRV_DATA,
24902494 .fifosize = { 256, 64, 64, 64 },
24912495 };
24922496
2493−/*
2494− * Common drv_data struct for platforms that specify samsung,uart-fifosize in
2495− * device tree.
2496− */
2497−static const struct s3c24xx_serial_drv_data exynos_fifoszdt_serial_drv_data = {
2498− EXYNOS_COMMON_SERIAL_DRV_DATA(),
2497+static const struct s3c24xx_serial_drv_data gs101_serial_drv_data = {
2498+ .info = {
2499+ .name = "Google GS101 UART",
2500+ .type = TYPE_S3C6400,
2501+ .port_type = PORT_S3C6400,
2502+ .iotype = UPIO_MEM32,
2503+ .has_divslot = true,
2504+ .rx_fifomask = S5PV210_UFSTAT_RXMASK,
2505+ .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
2506+ .rx_fifofull = S5PV210_UFSTAT_RXFULL,
2507+ .tx_fifofull = S5PV210_UFSTAT_TXFULL,
2508+ .tx_fifomask = S5PV210_UFSTAT_TXMASK,
2509+ .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT,
2510+ .def_clk_sel = S3C2410_UCON_CLKSEL0,
2511+ .num_clks = 1,
2512+ .clksel_mask = 0,
2513+ .clksel_shift = 0,
2514+ },
2515+ .def_cfg = {
2516+ .ucon = S5PV210_UCON_DEFAULT,
2517+ .ufcon = S5PV210_UFCON_DEFAULT,
2518+ .has_fracval = 1,
2519+ },
2520+ /* samsung,uart-fifosize must be specified in the device tree. */
24992521 .fifosize = { 0 },
25002522 };
25012523
25022524 #define EXYNOS4210_SERIAL_DRV_DATA (&exynos4210_serial_drv_data)
25032525 #define EXYNOS5433_SERIAL_DRV_DATA (&exynos5433_serial_drv_data)
25042526 #define EXYNOS850_SERIAL_DRV_DATA (&exynos850_serial_drv_data)
2505−#define EXYNOS_FIFOSZDT_DRV_DATA (&exynos_fifoszdt_serial_drv_data)
2527+#define GS101_SERIAL_DRV_DATA (&gs101_serial_drv_data)
25062528
25072529 #else
25082530 #define EXYNOS4210_SERIAL_DRV_DATA NULL
25092531 #define EXYNOS5433_SERIAL_DRV_DATA NULL
25102532 #define EXYNOS850_SERIAL_DRV_DATA NULL
2511−#define EXYNOS_FIFOSZDT_DRV_DATA NULL
2533+#define GS101_SERIAL_DRV_DATA NULL
25122534 #endif
25132535
25142536 #ifdef CONFIG_ARCH_APPLE
@@ -2517,6 +2539,7 @@ static const struct s3c24xx_serial_drv_data s5l_serial_drv_data = { · 2 unmodified lines
25172539 .name = "Apple S5L UART",
25182540 .type = TYPE_APPLE_S5L,
25192541 .port_type = PORT_8250,
2542+ .iotype = UPIO_MEM,
25202543 .fifosize = 16,
25212544 .rx_fifomask = S3C2410_UFSTAT_RXMASK,
25222545 .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
@@ -2546,8 +2569,9 @@ static const struct s3c24xx_serial_drv_data artpec8_serial_drv_data = { · 23 unmodified lines
25462569 .name = "Axis ARTPEC-8 UART",
25472570 .type = TYPE_S3C6400,
25482571 .port_type = PORT_S3C6400,
2572+ .iotype = UPIO_MEM,
25492573 .fifosize = 64,
2550− .has_divslot = 1,
2574+ .has_divslot = true,
25512575 .rx_fifomask = S5PV210_UFSTAT_RXMASK,
25522576 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
25532577 .rx_fifofull = S5PV210_UFSTAT_RXFULL,
@@ -2594,7 +2618,7 @@ static const struct platform_device_id s3c24xx_serial_driver_ids[] = { · 40 unmodified lines
25942618 .driver_data = (kernel_ulong_t)ARTPEC8_SERIAL_DRV_DATA,
25952619 }, {
25962620 .name = "gs101-uart",
2597− .driver_data = (kernel_ulong_t)EXYNOS_FIFOSZDT_DRV_DATA,
2621+ .driver_data = (kernel_ulong_t)GS101_SERIAL_DRV_DATA,
25982622 },
25992623 { },
26002624 };
@@ -2617,7 +2641,7 @@ static const struct of_device_id s3c24xx_uart_dt_match[] = { · 16 unmodified lines
26172641 { .compatible = "axis,artpec8-uart",
26182642 .data = ARTPEC8_SERIAL_DRV_DATA },
26192643 { .compatible = "google,gs101-uart",
2620− .data = EXYNOS_FIFOSZDT_DRV_DATA },
2644+ .data = GS101_SERIAL_DRV_DATA },
26212645 {},
26222646 };
26232647 MODULE_DEVICE_TABLE(of, s3c24xx_uart_dt_match);
@@ -2716,7 +2740,8 @@ static int samsung_early_read(struct console *con, char *s, unsigned int n) · 92 unmodified lines
27162740 {
27172741 struct earlycon_device *dev = con->data;
27182742 const struct samsung_early_console_data *data = dev->port.private_data;
2719− int ch, ufstat, num_read = 0;
2743+ int num_read = 0;
2744+ u32 ch, ufstat;
27202745
27212746 while (num_read < n) {
27222747 ufstat = rd_regl(&dev->port, S3C2410_UFSTAT);
@@ -2785,6 +2810,17 @@ OF_EARLYCON_DECLARE(exynos4210, "samsung,exynos4210-uart", · 62 unmodified lines
27852810 OF_EARLYCON_DECLARE(artpec8, "axis,artpec8-uart",
27862811 s5pv210_early_console_setup);
27872812
2813+static int __init gs101_early_console_setup(struct earlycon_device *device,
2814+ const char *opt)
2815+{
2816+ /* gs101 always expects MMIO32 register accesses. */
2817+ device->port.iotype = UPIO_MEM32;
2818+
2819+ return s5pv210_early_console_setup(device, opt);
2820+}
2821+
2822+OF_EARLYCON_DECLARE(gs101, "google,gs101-uart", gs101_early_console_setup);
2823+
27882824 /* Apple S5L */
27892825 static int __init apple_s5l_early_console_setup(struct earlycon_device *device,
27902826 const char *opt)
drivers/tty/serial/serial_base_bus.c+1−1
@@ -41,7 +41,7 @@ static int serial_base_match(struct device *dev, struct device_driver *drv) · 40 unmodified lines
4141 return 0;
4242 }
4343
44−static struct bus_type serial_base_bus_type = {
44+static const struct bus_type serial_base_bus_type = {
4545 .name = "serial-base",
4646 .match = serial_base_match,
4747 };
drivers/tty/serial/serial_core.c+12−0
@@ -2608,7 +2608,12 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state, · 2607 unmodified lines
26082608 port->type = PORT_UNKNOWN;
26092609 flags |= UART_CONFIG_TYPE;
26102610 }
2611+ /* Synchronize with possible boot console. */
2612+ if (uart_console(port))
2613+ console_lock();
26112614 port->ops->config_port(port, flags);
2615+ if (uart_console(port))
2616+ console_unlock();
26122617 }
26132618
26142619 if (port->type != PORT_UNKNOWN) {
@@ -2616,6 +2621,10 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state, · 1 unmodified line
26162621
26172622 uart_report_port(drv, port);
26182623
2624+ /* Synchronize with possible boot console. */
2625+ if (uart_console(port))
2626+ console_lock();
2627+
26192628 /* Power up port for set_mctrl() */
26202629 uart_change_pm(state, UART_PM_STATE_ON);
26212630
@@ -2632,6 +2641,9 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state, · 10 unmodified lines
26322641
26332642 uart_rs485_config(port);
26342643
2644+ if (uart_console(port))
2645+ console_unlock();
2646+
26352647 /*
26362648 * If this driver supports console, and it hasn't been
26372649 * successfully registered yet, try to re-register it.
drivers/tty/serial/serial_port.c+145−0
@@ -8,7 +8,10 @@ · 7 unmodified lines
88
99 #include <linux/device.h>
1010 #include <linux/module.h>
11+#include <linux/of.h>
12+#include <linux/platform_device.h>
1113 #include <linux/pm_runtime.h>
14+#include <linux/property.h>
1215 #include <linux/serial_core.h>
1316 #include <linux/spinlock.h>
1417
@@ -105,6 +108,148 @@ void uart_remove_one_port(struct uart_driver *drv, struct uart_port *port) · 90 unmodified lines
105108 }
106109 EXPORT_SYMBOL(uart_remove_one_port);
107110
111+/**
112+ * __uart_read_properties - read firmware properties of the given UART port
113+ * @port: corresponding port
114+ * @use_defaults: apply defaults (when %true) or validate the values (when %false)
115+ *
116+ * The following device properties are supported:
117+ * - clock-frequency (optional)
118+ * - fifo-size (optional)
119+ * - no-loopback-test (optional)
120+ * - reg-shift (defaults may apply)
121+ * - reg-offset (value may be validated)
122+ * - reg-io-width (defaults may apply or value may be validated)
123+ * - interrupts (OF only)
124+ * - serial [alias ID] (OF only)
125+ *
126+ * If the port->dev is of struct platform_device type the interrupt line
127+ * will be retrieved via platform_get_irq() call against that device.
128+ * Otherwise it will be assigned by fwnode_irq_get() call. In both cases
129+ * the index 0 of the resource is used.
130+ *
131+ * The caller is responsible to initialize the following fields of the @port
132+ * ->dev (must be valid)
133+ * ->flags
134+ * ->mapbase
135+ * ->mapsize
136+ * ->regshift (if @use_defaults is false)
137+ * before calling this function. Alternatively the above mentioned fields
138+ * may be zeroed, in such case the only ones, that have associated properties
139+ * found, will be set to the respective values.
140+ *
141+ * If no error happened, the ->irq, ->mapbase, ->mapsize will be altered.
142+ * The ->iotype is always altered.
143+ *
144+ * When @use_defaults is true and the respective property is not found
145+ * the following values will be applied:
146+ * ->regshift = 0
147+ * In this case IRQ must be provided, otherwise an error will be returned.
148+ *
149+ * When @use_defaults is false and the respective property is found
150+ * the following values will be validated:
151+ * - reg-io-width (->iotype)
152+ * - reg-offset (->mapsize against ->mapbase)
153+ *
154+ * Returns: 0 on success or negative errno on failure
155+ */
156+static int __uart_read_properties(struct uart_port *port, bool use_defaults)
157+{
158+ struct device *dev = port->dev;
159+ u32 value;
160+ int ret;
161+
162+ /* Read optional UART functional clock frequency */
163+ device_property_read_u32(dev, "clock-frequency", &port->uartclk);
164+
165+ /* Read the registers alignment (default: 8-bit) */
166+ ret = device_property_read_u32(dev, "reg-shift", &value);
167+ if (ret)
168+ port->regshift = use_defaults ? 0 : port->regshift;
169+ else
170+ port->regshift = value;
171+
172+ /* Read the registers I/O access type (default: MMIO 8-bit) */
173+ ret = device_property_read_u32(dev, "reg-io-width", &value);
174+ if (ret) {
175+ port->iotype = UPIO_MEM;
176+ } else {
177+ switch (value) {
178+ case 1:
179+ port->iotype = UPIO_MEM;
180+ break;
181+ case 2:
182+ port->iotype = UPIO_MEM16;
183+ break;
184+ case 4:
185+ port->iotype = device_is_big_endian(dev) ? UPIO_MEM32BE : UPIO_MEM32;
186+ break;
187+ default:
188+ if (!use_defaults) {
189+ dev_err(dev, "Unsupported reg-io-width (%u)\n", value);
190+ return -EINVAL;
191+ }
192+ port->iotype = UPIO_UNKNOWN;
193+ break;
194+ }
195+ }
196+
197+ /* Read the address mapping base offset (default: no offset) */
198+ ret = device_property_read_u32(dev, "reg-offset", &value);
199+ if (ret)
200+ value = 0;
201+
202+ /* Check for shifted address mapping overflow */
203+ if (!use_defaults && port->mapsize < value) {
204+ dev_err(dev, "reg-offset %u exceeds region size %pa\n", value, &port->mapsize);
205+ return -EINVAL;
206+ }
207+
208+ port->mapbase += value;
209+ port->mapsize -= value;
210+
211+ /* Read optional FIFO size */
212+ device_property_read_u32(dev, "fifo-size", &port->fifosize);
213+
214+ if (device_property_read_bool(dev, "no-loopback-test"))
215+ port->flags |= UPF_SKIP_TEST;
216+
217+ /* Get index of serial line, if found in DT aliases */
218+ ret = of_alias_get_id(dev_of_node(dev), "serial");
219+ if (ret >= 0)
220+ port->line = ret;
221+
222+ if (dev_is_platform(dev))
223+ ret = platform_get_irq(to_platform_device(dev), 0);
224+ else
225+ ret = fwnode_irq_get(dev_fwnode(dev), 0);
226+ if (ret == -EPROBE_DEFER)
227+ return ret;
228+ if (ret > 0)
229+ port->irq = ret;
230+ else if (use_defaults)
231+ /* By default IRQ support is mandatory */
232+ return ret;
233+ else
234+ port->irq = 0;
235+
236+ port->flags |= UPF_SHARE_IRQ;
237+
238+ return 0;
239+}
240+
241+int uart_read_port_properties(struct uart_port *port)
242+{
243+ return __uart_read_properties(port, true);
244+}
245+EXPORT_SYMBOL_GPL(uart_read_port_properties);
246+
247+int uart_read_and_validate_port_properties(struct uart_port *port)
248+{
249+ return __uart_read_properties(port, false);
250+}
251+EXPORT_SYMBOL_GPL(uart_read_and_validate_port_properties);
252+
108253 static struct device_driver serial_port_driver = {
109254 .name = "port",
110255 .suppress_bind_attrs = true,
drivers/tty/serial/serial_txx9.c+2−1
@@ -23,9 +23,10 @@ · 22 unmodified lines
2323 #include <linux/serial.h>
2424 #include <linux/tty.h>
2525 #include <linux/tty_flip.h>
26−
2726 #include <linux/io.h>
2827
28+#include <asm/txx9/generic.h>
29+
2930 #define PASS_LIMIT 256
3031
3132 #if !defined(CONFIG_SERIAL_TXX9_STDSERIAL)
drivers/tty/serial/sh-sci.c+119−126
@@ -576,13 +576,13 @@ static void sci_start_tx(struct uart_port *port) · 575 unmodified lines
576576
577577 #ifdef CONFIG_SERIAL_SH_SCI_DMA
578578 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
579− u16 new, scr = serial_port_in(port, SCSCR);
579+ u16 new, scr = sci_serial_in(port, SCSCR);
580580 if (s->chan_tx)
581581 new = scr | SCSCR_TDRQE;
582582 else
583583 new = scr & ~SCSCR_TDRQE;
584584 if (new != scr)
585− serial_port_out(port, SCSCR, new);
585+ sci_serial_out(port, SCSCR, new);
586586 }
587587
588588 if (s->chan_tx && !uart_circ_empty(&s->port.state->xmit) &&
@@ -599,7 +599,7 @@ static void sci_start_tx(struct uart_port *port) · 10 unmodified lines
599599 if (!s->chan_tx || s->cfg->regtype == SCIx_RZ_SCIFA_REGTYPE ||
600600 port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
601601 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
602− ctrl = serial_port_in(port, SCSCR);
602+ ctrl = sci_serial_in(port, SCSCR);
603603
604604 /*
605605 * For SCI, TE (transmit enable) must be set after setting TIE
@@ -609,7 +609,7 @@ static void sci_start_tx(struct uart_port *port) · 3 unmodified lines
609609 if (port->type == PORT_SCI)
610610 ctrl |= SCSCR_TE;
611611
612− serial_port_out(port, SCSCR, ctrl | SCSCR_TIE);
612+ sci_serial_out(port, SCSCR, ctrl | SCSCR_TIE);
613613 }
614614 }
615615
@@ -618,14 +618,14 @@ static void sci_stop_tx(struct uart_port *port) · 2 unmodified lines
618618 unsigned short ctrl;
619619
620620 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
621− ctrl = serial_port_in(port, SCSCR);
621+ ctrl = sci_serial_in(port, SCSCR);
622622
623623 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
624624 ctrl &= ~SCSCR_TDRQE;
625625
626626 ctrl &= ~SCSCR_TIE;
627627
628− serial_port_out(port, SCSCR, ctrl);
628+ sci_serial_out(port, SCSCR, ctrl);
629629
630630 #ifdef CONFIG_SERIAL_SH_SCI_DMA
631631 if (to_sci_port(port)->chan_tx &&
@@ -640,41 +640,40 @@ static void sci_start_rx(struct uart_port *port) · 8 unmodified lines
640640 {
641641 unsigned short ctrl;
642642
643− ctrl = serial_port_in(port, SCSCR) | port_rx_irq_mask(port);
643+ ctrl = sci_serial_in(port, SCSCR) | port_rx_irq_mask(port);
644644
645645 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
646646 ctrl &= ~SCSCR_RDRQE;
647647
648− serial_port_out(port, SCSCR, ctrl);
648+ sci_serial_out(port, SCSCR, ctrl);
649649 }
650650
651651 static void sci_stop_rx(struct uart_port *port)
652652 {
653653 unsigned short ctrl;
654654
655− ctrl = serial_port_in(port, SCSCR);
655+ ctrl = sci_serial_in(port, SCSCR);
656656
657657 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
658658 ctrl &= ~SCSCR_RDRQE;
659659
660660 ctrl &= ~port_rx_irq_mask(port);
661661
662− serial_port_out(port, SCSCR, ctrl);
662+ sci_serial_out(port, SCSCR, ctrl);
663663 }
664664
665665 static void sci_clear_SCxSR(struct uart_port *port, unsigned int mask)
666666 {
667667 if (port->type == PORT_SCI) {
668668 /* Just store the mask */
669− serial_port_out(port, SCxSR, mask);
669+ sci_serial_out(port, SCxSR, mask);
670670 } else if (to_sci_port(port)->params->overrun_mask == SCIFA_ORER) {
671671 /* SCIFA/SCIFB and SCIF on SH7705/SH7720/SH7721 */
672672 /* Only clear the status bits we want to clear */
673− serial_port_out(port, SCxSR,
674− serial_port_in(port, SCxSR) & mask);
673+ sci_serial_out(port, SCxSR, sci_serial_in(port, SCxSR) & mask);
675674 } else {
676675 /* Store the mask, clear parity/framing errors */
677− serial_port_out(port, SCxSR, mask & ~(SCIF_FERC | SCIF_PERC));
676+ sci_serial_out(port, SCxSR, mask & ~(SCIF_FERC | SCIF_PERC));
678677 }
679678 }
680679
@@ -688,7 +687,7 @@ static int sci_poll_get_char(struct uart_port *port) · 7 unmodified lines
688687 int c;
689688
690689 do {
691− status = serial_port_in(port, SCxSR);
690+ status = sci_serial_in(port, SCxSR);
692691 if (status & SCxSR_ERRORS(port)) {
693692 sci_clear_SCxSR(port, SCxSR_ERROR_CLEAR(port));
694693 continue;
@@ -699,10 +698,10 @@ static int sci_poll_get_char(struct uart_port *port) · 4 unmodified lines
699698 if (!(status & SCxSR_RDxF(port)))
700699 return NO_POLL_CHAR;
701700
702− c = serial_port_in(port, SCxRDR);
701+ c = sci_serial_in(port, SCxRDR);
703702
704703 /* Dummy read */
705− serial_port_in(port, SCxSR);
704+ sci_serial_in(port, SCxSR);
706705 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port));
707706
708707 return c;
@@ -714,10 +713,10 @@ static void sci_poll_put_char(struct uart_port *port, unsigned char c) · 5 unmodified lines
714713 unsigned short status;
715714
716715 do {
717− status = serial_port_in(port, SCxSR);
716+ status = sci_serial_in(port, SCxSR);
718717 } while (!(status & SCxSR_TDxE(port)));
719718
720− serial_port_out(port, SCxTDR, c);
719+ sci_serial_out(port, SCxTDR, c);
721720 sci_clear_SCxSR(port, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
722721 }
723722 #endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE ||
@@ -736,8 +735,8 @@ static void sci_init_pins(struct uart_port *port, unsigned int cflag) · 12 unmodified lines
736735 }
737736
738737 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
739− u16 data = serial_port_in(port, SCPDR);
740− u16 ctrl = serial_port_in(port, SCPCR);
738+ u16 data = sci_serial_in(port, SCPDR);
739+ u16 ctrl = sci_serial_in(port, SCPCR);
741740
742741 /* Enable RXD and TXD pin functions */
743742 ctrl &= ~(SCPCR_RXDC | SCPCR_TXDC);
@@ -756,10 +755,10 @@ static void sci_init_pins(struct uart_port *port, unsigned int cflag) · 12 unmodified lines
756755 /* Enable CTS# pin function */
757756 ctrl &= ~SCPCR_CTSC;
758757 }
759− serial_port_out(port, SCPDR, data);
760− serial_port_out(port, SCPCR, ctrl);
758+ sci_serial_out(port, SCPDR, data);
759+ sci_serial_out(port, SCPCR, ctrl);
761760 } else if (sci_getreg(port, SCSPTR)->size) {
762− u16 status = serial_port_in(port, SCSPTR);
761+ u16 status = sci_serial_in(port, SCSPTR);
763762
764763 /* RTS# is always output; and active low, unless autorts */
765764 status |= SCSPTR_RTSIO;
@@ -769,7 +768,7 @@ static void sci_init_pins(struct uart_port *port, unsigned int cflag) · 3 unmodified lines
769768 status &= ~SCSPTR_RTSDT;
770769 /* CTS# and SCK are inputs */
771770 status &= ~(SCSPTR_CTSIO | SCSPTR_SCKIO);
772− serial_port_out(port, SCSPTR, status);
771+ sci_serial_out(port, SCSPTR, status);
773772 }
774773 }
775774
@@ -781,13 +780,13 @@ static int sci_txfill(struct uart_port *port) · 5 unmodified lines
781780
782781 reg = sci_getreg(port, SCTFDR);
783782 if (reg->size)
784− return serial_port_in(port, SCTFDR) & fifo_mask;
783+ return sci_serial_in(port, SCTFDR) & fifo_mask;
785784
786785 reg = sci_getreg(port, SCFDR);
787786 if (reg->size)
788− return serial_port_in(port, SCFDR) >> 8;
787+ return sci_serial_in(port, SCFDR) >> 8;
789788
790− return !(serial_port_in(port, SCxSR) & SCI_TDRE);
789+ return !(sci_serial_in(port, SCxSR) & SCI_TDRE);
791790 }
792791
793792 static int sci_txroom(struct uart_port *port)
@@ -803,13 +802,13 @@ static int sci_rxfill(struct uart_port *port) · 9 unmodified lines
803802
804803 reg = sci_getreg(port, SCRFDR);
805804 if (reg->size)
806− return serial_port_in(port, SCRFDR) & fifo_mask;
805+ return sci_serial_in(port, SCRFDR) & fifo_mask;
807806
808807 reg = sci_getreg(port, SCFDR);
809808 if (reg->size)
810− return serial_port_in(port, SCFDR) & fifo_mask;
809+ return sci_serial_in(port, SCFDR) & fifo_mask;
811810
812− return (serial_port_in(port, SCxSR) & SCxSR_RDxF(port)) != 0;
811+ return (sci_serial_in(port, SCxSR) & SCxSR_RDxF(port)) != 0;
813812 }
814813
815814 /* ********************************************************************** *
@@ -824,14 +823,14 @@ static void sci_transmit_chars(struct uart_port *port) · 8 unmodified lines
824823 unsigned short ctrl;
825824 int count;
826825
827− status = serial_port_in(port, SCxSR);
826+ status = sci_serial_in(port, SCxSR);
828827 if (!(status & SCxSR_TDxE(port))) {
829− ctrl = serial_port_in(port, SCSCR);
828+ ctrl = sci_serial_in(port, SCSCR);
830829 if (uart_circ_empty(xmit))
831830 ctrl &= ~SCSCR_TIE;
832831 else
833832 ctrl |= SCSCR_TIE;
834− serial_port_out(port, SCSCR, ctrl);
833+ sci_serial_out(port, SCSCR, ctrl);
835834 return;
836835 }
837836
@@ -847,15 +846,15 @@ static void sci_transmit_chars(struct uart_port *port) · 9 unmodified lines
847846 c = xmit->buf[xmit->tail];
848847 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
849848 } else if (port->type == PORT_SCI && uart_circ_empty(xmit)) {
850− ctrl = serial_port_in(port, SCSCR);
849+ ctrl = sci_serial_in(port, SCSCR);
851850 ctrl &= ~SCSCR_TE;
852− serial_port_out(port, SCSCR, ctrl);
851+ sci_serial_out(port, SCSCR, ctrl);
853852 return;
854853 } else {
855854 break;
856855 }
857856
858− serial_port_out(port, SCxTDR, c);
857+ sci_serial_out(port, SCxTDR, c);
859858
860859 port->icount.tx++;
861860 } while (--count > 0);
@@ -866,10 +865,10 @@ static void sci_transmit_chars(struct uart_port *port) · 4 unmodified lines
866865 uart_write_wakeup(port);
867866 if (uart_circ_empty(xmit)) {
868867 if (port->type == PORT_SCI) {
869− ctrl = serial_port_in(port, SCSCR);
868+ ctrl = sci_serial_in(port, SCSCR);
870869 ctrl &= ~SCSCR_TIE;
871870 ctrl |= SCSCR_TEIE;
872− serial_port_out(port, SCSCR, ctrl);
871+ sci_serial_out(port, SCSCR, ctrl);
873872 }
874873
875874 sci_stop_tx(port);
@@ -883,7 +882,7 @@ static void sci_receive_chars(struct uart_port *port) · 7 unmodified lines
883882 unsigned short status;
884883 unsigned char flag;
885884
886− status = serial_port_in(port, SCxSR);
885+ status = sci_serial_in(port, SCxSR);
887886 if (!(status & SCxSR_RDxF(port)))
888887 return;
889888
@@ -896,7 +895,7 @@ static void sci_receive_chars(struct uart_port *port) · 6 unmodified lines
896895 break;
897896
898897 if (port->type == PORT_SCI) {
899− char c = serial_port_in(port, SCxRDR);
898+ char c = sci_serial_in(port, SCxRDR);
900899 if (uart_handle_sysrq_char(port, c))
901900 count = 0;
902901 else
@@ -907,11 +906,11 @@ static void sci_receive_chars(struct uart_port *port) · 4 unmodified lines
907906
908907 if (port->type == PORT_SCIF ||
909908 port->type == PORT_HSCIF) {
910− status = serial_port_in(port, SCxSR);
911− c = serial_port_in(port, SCxRDR);
909+ status = sci_serial_in(port, SCxSR);
910+ c = sci_serial_in(port, SCxRDR);
912911 } else {
913− c = serial_port_in(port, SCxRDR);
914− status = serial_port_in(port, SCxSR);
912+ c = sci_serial_in(port, SCxRDR);
913+ status = sci_serial_in(port, SCxSR);
915914 }
916915 if (uart_handle_sysrq_char(port, c)) {
917916 count--; i--;
@@ -932,7 +931,7 @@ static void sci_receive_chars(struct uart_port *port) · 14 unmodified lines
932931 }
933932 }
934933
935− serial_port_in(port, SCxSR); /* dummy read */
934+ sci_serial_in(port, SCxSR); /* dummy read */
936935 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port));
937936
938937 copied += count;
@@ -944,8 +943,8 @@ static void sci_receive_chars(struct uart_port *port) · 5 unmodified lines
944943 tty_flip_buffer_push(tport);
945944 } else {
946945 /* TTY buffers full; read from RX reg to prevent lockup */
947− serial_port_in(port, SCxRDR);
948− serial_port_in(port, SCxSR); /* dummy read */
946+ sci_serial_in(port, SCxRDR);
947+ sci_serial_in(port, SCxSR); /* dummy read */
949948 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port));
950949 }
951950 }
@@ -953,7 +952,7 @@ static void sci_receive_chars(struct uart_port *port) · 1 unmodified line
953952 static int sci_handle_errors(struct uart_port *port)
954953 {
955954 int copied = 0;
956− unsigned short status = serial_port_in(port, SCxSR);
955+ unsigned short status = sci_serial_in(port, SCxSR);
957956 struct tty_port *tport = &port->state->port;
958957 struct sci_port *s = to_sci_port(port);
959958
@@ -1000,10 +999,10 @@ static int sci_handle_fifo_overrun(struct uart_port *port) · 40 unmodified lines
1000999 if (!reg->size)
10011000 return 0;
10021001
1003− status = serial_port_in(port, s->params->overrun_reg);
1002+ status = sci_serial_in(port, s->params->overrun_reg);
10041003 if (status & s->params->overrun_mask) {
10051004 status &= ~s->params->overrun_mask;
1006− serial_port_out(port, s->params->overrun_reg, status);
1005+ sci_serial_out(port, s->params->overrun_reg, status);
10071006
10081007 port->icount.overrun++;
10091008
@@ -1018,7 +1017,7 @@ static int sci_handle_fifo_overrun(struct uart_port *port) · 8 unmodified lines
10181017 static int sci_handle_breaks(struct uart_port *port)
10191018 {
10201019 int copied = 0;
1021− unsigned short status = serial_port_in(port, SCxSR);
1020+ unsigned short status = sci_serial_in(port, SCxSR);
10221021 struct tty_port *tport = &port->state->port;
10231022
10241023 if (uart_handle_break(port))
@@ -1051,7 +1050,7 @@ static int scif_set_rtrg(struct uart_port *port, int rx_trig) · 26 unmodified lines
10511050
10521051 /* HSCIF can be set to an arbitrary level. */
10531052 if (sci_getreg(port, HSRTRGR)->size) {
1054− serial_port_out(port, HSRTRGR, rx_trig);
1053+ sci_serial_out(port, HSRTRGR, rx_trig);
10551054 return rx_trig;
10561055 }
10571056
@@ -1092,9 +1091,9 @@ static int scif_set_rtrg(struct uart_port *port, int rx_trig) · 34 unmodified lines
10921091 return 1;
10931092 }
10941093
1095− serial_port_out(port, SCFCR,
1096− (serial_port_in(port, SCFCR) &
1097− ~(SCFCR_RTRG1 | SCFCR_RTRG0)) | bits);
1094+ sci_serial_out(port, SCFCR,
1095+ (sci_serial_in(port, SCFCR) &
1096+ ~(SCFCR_RTRG1 | SCFCR_RTRG0)) | bits);
10981097
10991098 return rx_trig;
11001099 }
@@ -1102,9 +1101,9 @@ static int scif_set_rtrg(struct uart_port *port, int rx_trig) · 1 unmodified line
11021101 static int scif_rtrg_enabled(struct uart_port *port)
11031102 {
11041103 if (sci_getreg(port, HSRTRGR)->size)
1105− return serial_port_in(port, HSRTRGR) != 0;
1104+ return sci_serial_in(port, HSRTRGR) != 0;
11061105 else
1107− return (serial_port_in(port, SCFCR) &
1106+ return (sci_serial_in(port, SCFCR) &
11081107 (SCFCR_RTRG0 | SCFCR_RTRG1)) != 0;
11091108 }
11101109
@@ -1219,8 +1218,8 @@ static void sci_dma_tx_complete(void *arg) · 108 unmodified lines
12191218 s->cookie_tx = -EINVAL;
12201219 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB ||
12211220 s->cfg->regtype == SCIx_RZ_SCIFA_REGTYPE) {
1222− u16 ctrl = serial_port_in(port, SCSCR);
1223− serial_port_out(port, SCSCR, ctrl & ~SCSCR_TIE);
1221+ u16 ctrl = sci_serial_in(port, SCSCR);
1222+ sci_serial_out(port, SCSCR, ctrl & ~SCSCR_TIE);
12241223 if (s->cfg->regtype == SCIx_RZ_SCIFA_REGTYPE) {
12251224 /* Switch irq from DMA to SCIF */
12261225 dmaengine_pause(s->chan_tx_saved);
@@ -1296,7 +1295,7 @@ static void sci_dma_rx_reenable_irq(struct sci_port *s) · 69 unmodified lines
12961295 u16 scr;
12971296
12981297 /* Direct new serial port interrupts back to CPU */
1299− scr = serial_port_in(port, SCSCR);
1298+ scr = sci_serial_in(port, SCSCR);
13001299 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB ||
13011300 s->cfg->regtype == SCIx_RZ_SCIFA_REGTYPE) {
13021301 enable_irq(s->irqs[SCIx_RXI_IRQ]);
@@ -1305,7 +1304,7 @@ static void sci_dma_rx_reenable_irq(struct sci_port *s) · 2 unmodified lines
13051304 else
13061305 scr &= ~SCSCR_RDRQE;
13071306 }
1308− serial_port_out(port, SCSCR, scr | SCSCR_RIE);
1307+ sci_serial_out(port, SCSCR, scr | SCSCR_RIE);
13091308 }
13101309
13111310 static void sci_dma_rx_complete(void *arg)
@@ -1714,8 +1713,8 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr) · 402 unmodified lines
17141713
17151714 #ifdef CONFIG_SERIAL_SH_SCI_DMA
17161715 if (s->chan_rx) {
1717− u16 scr = serial_port_in(port, SCSCR);
1718− u16 ssr = serial_port_in(port, SCxSR);
1716+ u16 scr = sci_serial_in(port, SCSCR);
1717+ u16 ssr = sci_serial_in(port, SCxSR);
17191718
17201719 /* Disable future Rx interrupts */
17211720 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB ||
@@ -1733,10 +1732,10 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr) · 11 unmodified lines
17331732
17341733 scr &= ~SCSCR_RIE;
17351734 }
1736− serial_port_out(port, SCSCR, scr);
1735+ sci_serial_out(port, SCSCR, scr);
17371736 /* Clear current interrupt */
1738− serial_port_out(port, SCxSR,
1739− ssr & ~(SCIF_DR | SCxSR_RDxF(port)));
1737+ sci_serial_out(port, SCxSR,
1738+ ssr & ~(SCIF_DR | SCxSR_RDxF(port)));
17401739 dev_dbg(port->dev, "Rx IRQ %lu: setup t-out in %u us\n",
17411740 jiffies, s->rx_timeout);
17421741 start_hrtimer_us(&s->rx_timer, s->rx_timeout);
@@ -1786,9 +1785,9 @@ static irqreturn_t sci_tx_end_interrupt(int irq, void *ptr) · 43 unmodified lines
17861785 return sci_tx_interrupt(irq, ptr);
17871786
17881787 uart_port_lock_irqsave(port, &flags);
1789− ctrl = serial_port_in(port, SCSCR);
1788+ ctrl = sci_serial_in(port, SCSCR);
17901789 ctrl &= ~(SCSCR_TE | SCSCR_TEIE);
1791− serial_port_out(port, SCSCR, ctrl);
1790+ sci_serial_out(port, SCSCR, ctrl);
17921791 uart_port_unlock_irqrestore(port, flags);
17931792
17941793 return IRQ_HANDLED;
@@ -1802,7 +1801,7 @@ static irqreturn_t sci_br_interrupt(int irq, void *ptr) · 7 unmodified lines
18021801 sci_handle_breaks(port);
18031802
18041803 /* drop invalid character received before break was detected */
1805− serial_port_in(port, SCxRDR);
1804+ sci_serial_in(port, SCxRDR);
18061805
18071806 sci_clear_SCxSR(port, SCxSR_BREAK_CLEAR(port));
18081807
@@ -1816,7 +1815,7 @@ static irqreturn_t sci_er_interrupt(int irq, void *ptr) · 7 unmodified lines
18161815
18171816 if (s->irqs[SCIx_ERI_IRQ] == s->irqs[SCIx_BRI_IRQ]) {
18181817 /* Break and Error interrupts are muxed */
1819− unsigned short ssr_status = serial_port_in(port, SCxSR);
1818+ unsigned short ssr_status = sci_serial_in(port, SCxSR);
18201819
18211820 /* Break Interrupt */
18221821 if (ssr_status & SCxSR_BRK(port))
@@ -1831,7 +1830,7 @@ static irqreturn_t sci_er_interrupt(int irq, void *ptr) · 8 unmodified lines
18311830 if (port->type == PORT_SCI) {
18321831 if (sci_handle_errors(port)) {
18331832 /* discard character in rx buffer */
1834− serial_port_in(port, SCxSR);
1833+ sci_serial_in(port, SCxSR);
18351834 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port));
18361835 }
18371836 } else {
@@ -1856,12 +1855,12 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr) · 18 unmodified lines
18561855 struct sci_port *s = to_sci_port(port);
18571856 irqreturn_t ret = IRQ_NONE;
18581857
1859− ssr_status = serial_port_in(port, SCxSR);
1860− scr_status = serial_port_in(port, SCSCR);
1858+ ssr_status = sci_serial_in(port, SCxSR);
1859+ scr_status = sci_serial_in(port, SCSCR);
18611860 if (s->params->overrun_reg == SCxSR)
18621861 orer_status = ssr_status;
18631862 else if (sci_getreg(port, s->params->overrun_reg)->size)
1864− orer_status = serial_port_in(port, s->params->overrun_reg);
1863+ orer_status = sci_serial_in(port, s->params->overrun_reg);
18651864
18661865 err_enabled = scr_status & port_rx_irq_mask(port);
18671866
@@ -2038,7 +2037,7 @@ static void sci_free_irq(struct sci_port *port) · 170 unmodified lines
20382037
20392038 static unsigned int sci_tx_empty(struct uart_port *port)
20402039 {
2041− unsigned short status = serial_port_in(port, SCxSR);
2040+ unsigned short status = sci_serial_in(port, SCxSR);
20422041 unsigned short in_tx_fifo = sci_txfill(port);
20432042
20442043 return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0;
@@ -2047,27 +2046,27 @@ static unsigned int sci_tx_empty(struct uart_port *port) · 2 unmodified lines
20472046 static void sci_set_rts(struct uart_port *port, bool state)
20482047 {
20492048 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
2050− u16 data = serial_port_in(port, SCPDR);
2049+ u16 data = sci_serial_in(port, SCPDR);
20512050
20522051 /* Active low */
20532052 if (state)
20542053 data &= ~SCPDR_RTSD;
20552054 else
20562055 data |= SCPDR_RTSD;
2057− serial_port_out(port, SCPDR, data);
2056+ sci_serial_out(port, SCPDR, data);
20582057
20592058 /* RTS# is output */
2060− serial_port_out(port, SCPCR,
2061− serial_port_in(port, SCPCR) | SCPCR_RTSC);
2059+ sci_serial_out(port, SCPCR,
2060+ sci_serial_in(port, SCPCR) | SCPCR_RTSC);
20622061 } else if (sci_getreg(port, SCSPTR)->size) {
2063− u16 ctrl = serial_port_in(port, SCSPTR);
2062+ u16 ctrl = sci_serial_in(port, SCSPTR);
20642063
20652064 /* Active low */
20662065 if (state)
20672066 ctrl &= ~SCSPTR_RTSDT;
20682067 else
20692068 ctrl |= SCSPTR_RTSDT;
2070− serial_port_out(port, SCSPTR, ctrl);
2069+ sci_serial_out(port, SCSPTR, ctrl);
20712070 }
20722071 }
20732072
@@ -2075,10 +2074,10 @@ static bool sci_get_cts(struct uart_port *port) · 1 unmodified line
20752074 {
20762075 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
20772076 /* Active low */
2078− return !(serial_port_in(port, SCPDR) & SCPDR_CTSD);
2077+ return !(sci_serial_in(port, SCPDR) & SCPDR_CTSD);
20792078 } else if (sci_getreg(port, SCSPTR)->size) {
20802079 /* Active low */
2081− return !(serial_port_in(port, SCSPTR) & SCSPTR_CTSDT);
2080+ return !(sci_serial_in(port, SCSPTR) & SCSPTR_CTSDT);
20822081 }
20832082
20842083 return true;
@@ -2108,9 +2107,8 @@ static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl) · 23 unmodified lines
21082107 */
21092108 reg = sci_getreg(port, SCFCR);
21102109 if (reg->size)
2111− serial_port_out(port, SCFCR,
2112− serial_port_in(port, SCFCR) |
2113− SCFCR_LOOP);
2110+ sci_serial_out(port, SCFCR,
2111+ sci_serial_in(port, SCFCR) | SCFCR_LOOP);
21142112 }
21152113
21162114 mctrl_gpio_set(s->gpios, mctrl);
@@ -2120,21 +2118,21 @@ static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl) · 3 unmodified lines
21202118
21212119 if (!(mctrl & TIOCM_RTS)) {
21222120 /* Disable Auto RTS */
2123− serial_port_out(port, SCFCR,
2124− serial_port_in(port, SCFCR) & ~SCFCR_MCE);
2121+ sci_serial_out(port, SCFCR,
2122+ sci_serial_in(port, SCFCR) & ~SCFCR_MCE);
21252123
21262124 /* Clear RTS */
21272125 sci_set_rts(port, 0);
21282126 } else if (s->autorts) {
21292127 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
21302128 /* Enable RTS# pin function */
2131− serial_port_out(port, SCPCR,
2132− serial_port_in(port, SCPCR) & ~SCPCR_RTSC);
2129+ sci_serial_out(port, SCPCR,
2130+ sci_serial_in(port, SCPCR) & ~SCPCR_RTSC);
21332131 }
21342132
21352133 /* Enable Auto RTS */
2136− serial_port_out(port, SCFCR,
2137− serial_port_in(port, SCFCR) | SCFCR_MCE);
2134+ sci_serial_out(port, SCFCR,
2135+ sci_serial_in(port, SCFCR) | SCFCR_MCE);
21382136 } else {
21392137 /* Set RTS */
21402138 sci_set_rts(port, 1);
@@ -2187,8 +2185,8 @@ static void sci_break_ctl(struct uart_port *port, int break_state) · 46 unmodified lines
21872185 }
21882186
21892187 uart_port_lock_irqsave(port, &flags);
2190− scsptr = serial_port_in(port, SCSPTR);
2191− scscr = serial_port_in(port, SCSCR);
2188+ scsptr = sci_serial_in(port, SCSPTR);
2189+ scscr = sci_serial_in(port, SCSCR);
21922190
21932191 if (break_state == -1) {
21942192 scsptr = (scsptr | SCSPTR_SPB2IO) & ~SCSPTR_SPB2DT;
@@ -2198,8 +2196,8 @@ static void sci_break_ctl(struct uart_port *port, int break_state) · 3 unmodified lines
21982196 scscr |= SCSCR_TE;
21992197 }
22002198
2201− serial_port_out(port, SCSPTR, scsptr);
2202− serial_port_out(port, SCSCR, scscr);
2199+ sci_serial_out(port, SCSPTR, scsptr);
2200+ sci_serial_out(port, SCSCR, scscr);
22032201 uart_port_unlock_irqrestore(port, flags);
22042202 }
22052203
@@ -2239,9 +2237,9 @@ static void sci_shutdown(struct uart_port *port) · 33 unmodified lines
22392237 * Stop RX and TX, disable related interrupts, keep clock source
22402238 * and HSCIF TOT bits
22412239 */
2242− scr = serial_port_in(port, SCSCR);
2243− serial_port_out(port, SCSCR, scr &
2244− (SCSCR_CKE1 | SCSCR_CKE0 | s->hscif_tot));
2240+ scr = sci_serial_in(port, SCSCR);
2241+ sci_serial_out(port, SCSCR,
2242+ scr & (SCSCR_CKE1 | SCSCR_CKE0 | s->hscif_tot));
22452243 uart_port_unlock_irqrestore(port, flags);
22462244
22472245 #ifdef CONFIG_SERIAL_SH_SCI_DMA
@@ -2390,19 +2388,19 @@ static void sci_reset(struct uart_port *port) · 142 unmodified lines
23902388 unsigned int status;
23912389 struct sci_port *s = to_sci_port(port);
23922390
2393− serial_port_out(port, SCSCR, s->hscif_tot); /* TE=0, RE=0, CKE1=0 */
2391+ sci_serial_out(port, SCSCR, s->hscif_tot); /* TE=0, RE=0, CKE1=0 */
23942392
23952393 reg = sci_getreg(port, SCFCR);
23962394 if (reg->size)
2397− serial_port_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
2395+ sci_serial_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
23982396
23992397 sci_clear_SCxSR(port,
24002398 SCxSR_RDxF_CLEAR(port) & SCxSR_ERROR_CLEAR(port) &
24012399 SCxSR_BREAK_CLEAR(port));
24022400 if (sci_getreg(port, SCLSR)->size) {
2403− status = serial_port_in(port, SCLSR);
2401+ status = sci_serial_in(port, SCLSR);
24042402 status &= ~(SCLSR_TO | SCLSR_ORER);
2405− serial_port_out(port, SCLSR, status);
2403+ sci_serial_out(port, SCLSR, status);
24062404 }
24072405
24082406 if (s->rx_trigger > 1) {
@@ -2540,8 +2538,8 @@ done: · 131 unmodified lines
25402538 * It controls the mux to select (H)SCK or frequency divided clock.
25412539 */
25422540 if (best_clk >= 0 && sci_getreg(port, SCCKS)->size) {
2543− serial_port_out(port, SCDL, dl);
2544− serial_port_out(port, SCCKS, sccks);
2541+ sci_serial_out(port, SCDL, dl);
2542+ sci_serial_out(port, SCCKS, sccks);
25452543 }
25462544
25472545 uart_port_lock_irqsave(port, &flags);
@@ -2554,7 +2552,7 @@ done: · 6 unmodified lines
25542552 bits = tty_get_frame_size(termios->c_cflag);
25552553
25562554 if (sci_getreg(port, SEMR)->size)
2557− serial_port_out(port, SEMR, 0);
2555+ sci_serial_out(port, SEMR, 0);
25582556
25592557 if (best_clk >= 0) {
25602558 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
@@ -2569,9 +2567,9 @@ done: · 8 unmodified lines
25692567 case 27: smr_val |= SCSMR_SRC_27; break;
25702568 }
25712569 smr_val |= cks;
2572− serial_port_out(port, SCSCR, scr_val | s->hscif_tot);
2573− serial_port_out(port, SCSMR, smr_val);
2574− serial_port_out(port, SCBRR, brr);
2570+ sci_serial_out(port, SCSCR, scr_val | s->hscif_tot);
2571+ sci_serial_out(port, SCSMR, smr_val);
2572+ sci_serial_out(port, SCBRR, brr);
25752573 if (sci_getreg(port, HSSRR)->size) {
25762574 unsigned int hssrr = srr | HSCIF_SRE;
25772575 /* Calculate deviation from intended rate at the
@@ -2593,7 +2591,7 @@ done: · 15 unmodified lines
25932591 HSCIF_SRHP_MASK;
25942592 hssrr |= HSCIF_SRDE;
25952593 }
2596− serial_port_out(port, HSSRR, hssrr);
2594+ sci_serial_out(port, HSSRR, hssrr);
25972595 }
25982596
25992597 /* Wait one bit interval */
@@ -2601,10 +2599,10 @@ done: · 1 unmodified line
26012599 } else {
26022600 /* Don't touch the bit rate configuration */
26032601 scr_val = s->cfg->scscr & (SCSCR_CKE1 | SCSCR_CKE0);
2604− smr_val |= serial_port_in(port, SCSMR) &
2602+ smr_val |= sci_serial_in(port, SCSMR) &
26052603 (SCSMR_CKEDG | SCSMR_SRC_MASK | SCSMR_CKS);
2606− serial_port_out(port, SCSCR, scr_val | s->hscif_tot);
2607− serial_port_out(port, SCSMR, smr_val);
2604+ sci_serial_out(port, SCSCR, scr_val | s->hscif_tot);
2605+ sci_serial_out(port, SCSMR, smr_val);
26082606 }
26092607
26102608 sci_init_pins(port, termios->c_cflag);
@@ -2613,7 +2611,7 @@ done: · 2 unmodified lines
26132611 s->autorts = false;
26142612 reg = sci_getreg(port, SCFCR);
26152613 if (reg->size) {
2616− unsigned short ctrl = serial_port_in(port, SCFCR);
2614+ unsigned short ctrl = sci_serial_in(port, SCFCR);
26172615
26182616 if ((port->flags & UPF_HARD_FLOW) &&
26192617 (termios->c_cflag & CRTSCTS)) {
@@ -2630,7 +2628,7 @@ done: · 10 unmodified lines
26302628 */
26312629 ctrl &= ~(SCFCR_RFRST | SCFCR_TFRST);
26322630
2633− serial_port_out(port, SCFCR, ctrl);
2631+ sci_serial_out(port, SCFCR, ctrl);
26342632 }
26352633 if (port->flags & UPF_HARD_FLOW) {
26362634 /* Refresh (Auto) RTS */
@@ -2645,7 +2643,7 @@ done: · 8 unmodified lines
26452643 if (port->type != PORT_SCI)
26462644 scr_val |= SCSCR_TE;
26472645 scr_val |= SCSCR_RE | (s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0));
2648− serial_port_out(port, SCSCR, scr_val | s->hscif_tot);
2646+ sci_serial_out(port, SCSCR, scr_val | s->hscif_tot);
26492647 if ((srr + 1 == 5) &&
26502648 (port->type == PORT_SCIFA || port->type == PORT_SCIFB)) {
26512649 /*
@@ -3017,9 +3015,6 @@ static int sci_init_single(struct platform_device *dev, · 365 unmodified lines
30173015 port->irq = sci_port->irqs[SCIx_RXI_IRQ];
30183016 port->irqflags = 0;
30193017
3020− port->serial_in = sci_serial_in;
3021− port->serial_out = sci_serial_out;
3022−
30233018 return 0;
30243019 }
30253020
@@ -3056,21 +3051,21 @@ static void serial_console_write(struct console *co, const char *s, · 30 unmodified lines
30563051 uart_port_lock_irqsave(port, &flags);
30573052
30583053 /* first save SCSCR then disable interrupts, keep clock source */
3059− ctrl = serial_port_in(port, SCSCR);
3054+ ctrl = sci_serial_in(port, SCSCR);
30603055 ctrl_temp = SCSCR_RE | SCSCR_TE |
30613056 (sci_port->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)) |
30623057 (ctrl & (SCSCR_CKE1 | SCSCR_CKE0));
3063− serial_port_out(port, SCSCR, ctrl_temp | sci_port->hscif_tot);
3058+ sci_serial_out(port, SCSCR, ctrl_temp | sci_port->hscif_tot);
30643059
30653060 uart_console_write(port, s, count, serial_console_putchar);
30663061
30673062 /* wait until fifo is empty and last bit has been transmitted */
30683063 bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
3069− while ((serial_port_in(port, SCxSR) & bits) != bits)
3064+ while ((sci_serial_in(port, SCxSR) & bits) != bits)
30703065 cpu_relax();
30713066
30723067 /* restore the SCSCR */
3073− serial_port_out(port, SCSCR, ctrl);
3068+ sci_serial_out(port, SCSCR, ctrl);
30743069
30753070 if (locked)
30763071 uart_port_unlock_irqrestore(port, flags);
@@ -3503,8 +3498,6 @@ static int __init early_console_setup(struct earlycon_device *device, · 426 unmodified lines
35033498 if (!device->port.membase)
35043499 return -ENODEV;
35053500
3506− device->port.serial_in = sci_serial_in;
3507− device->port.serial_out = sci_serial_out;
35083501 device->port.type = type;
35093502 memcpy(&sci_ports[0].port, &device->port, sizeof(struct uart_port));
35103503 port_cfg.type = type;
drivers/tty/serial/sifive.c+7−10
@@ -412,7 +412,8 @@ static void __ssp_receive_chars(struct sifive_serial_port *ssp) · 411 unmodified lines
412412 break;
413413
414414 ssp->port.icount.rx++;
415− uart_insert_char(&ssp->port, 0, 0, ch, TTY_NORMAL);
415+ if (!uart_prepare_sysrq_char(&ssp->port, ch))
416+ uart_insert_char(&ssp->port, 0, 0, ch, TTY_NORMAL);
416417 }
417418
418419 tty_flip_buffer_push(&ssp->port.state->port);
@@ -534,7 +535,7 @@ static irqreturn_t sifive_serial_irq(int irq, void *dev_id) · 115 unmodified lines
534535 if (ip & SIFIVE_SERIAL_IP_TXWM_MASK)
535536 __ssp_transmit_chars(ssp);
536537
537− uart_port_unlock(&ssp->port);
538+ uart_unlock_and_check_sysrq(&ssp->port);
538539
539540 return IRQ_HANDLED;
540541 }
@@ -791,13 +792,10 @@ static void sifive_serial_console_write(struct console *co, const char *s, · 250 unmodified lines
791792 if (!ssp)
792793 return;
793794
794− local_irq_save(flags);
795− if (ssp->port.sysrq)
796− locked = 0;
797− else if (oops_in_progress)
798− locked = uart_port_trylock(&ssp->port);
795+ if (oops_in_progress)
796+ locked = uart_port_trylock_irqsave(&ssp->port, &flags);
799797 else
800− uart_port_lock(&ssp->port);
798+ uart_port_lock_irqsave(&ssp->port, &flags);
801799
802800 ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS);
803801 __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp);
@@ -807,8 +805,7 @@ static void sifive_serial_console_write(struct console *co, const char *s, · 3 unmodified lines
807805 __ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp);
808806
809807 if (locked)
810− uart_port_unlock(&ssp->port);
811− local_irq_restore(flags);
808+ uart_port_unlock_irqrestore(&ssp->port, flags);
812809 }
813810
814811 static int sifive_serial_console_setup(struct console *co, char *options)
drivers/tty/serial/st-asc.c+24−16
@@ -465,6 +465,7 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, · 464 unmodified lines
465465 const struct ktermios *old)
466466 {
467467 struct asc_port *ascport = to_asc_port(port);
468+ bool manual_rts, toggle_rts = false;
468469 struct gpio_desc *gpiod;
469470 unsigned int baud;
470471 u32 ctrl_val;
@@ -518,25 +519,13 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, · 47 unmodified lines
518519
519520 /* If flow-control selected, stop handling RTS manually */
520521 if (ascport->rts) {
521− devm_gpiod_put(port->dev, ascport->rts);
522− ascport->rts = NULL;
523−
524− pinctrl_select_state(ascport->pinctrl,
525− ascport->states[DEFAULT]);
522+ toggle_rts = true;
523+ manual_rts = false;
526524 }
527525 } else {
528526 /* If flow-control disabled, it's safe to handle RTS manually */
529− if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) {
530− pinctrl_select_state(ascport->pinctrl,
531− ascport->states[NO_HW_FLOWCTRL]);
532−
533− gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW);
534− if (!IS_ERR(gpiod)) {
535− gpiod_set_consumer_name(gpiod,
536− port->dev->of_node->name);
537− ascport->rts = gpiod;
538− }
539− }
527+ if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL])
528+ manual_rts = toggle_rts = true;
540529 }
541530
542531 if ((baud < 19200) && !ascport->force_m1) {
@@ -595,6 +584,25 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, · 52 unmodified lines
595584 asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN));
596585
597586 uart_port_unlock_irqrestore(port, flags);
587+
588+ if (toggle_rts) {
589+ if (manual_rts) {
590+ pinctrl_select_state(ascport->pinctrl,
591+ ascport->states[NO_HW_FLOWCTRL]);
592+
593+ gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW);
594+ if (!IS_ERR(gpiod)) {
595+ gpiod_set_consumer_name(gpiod,
596+ port->dev->of_node->name);
597+ ascport->rts = gpiod;
598+ }
599+ } else {
600+ devm_gpiod_put(port->dev, ascport->rts);
601+ ascport->rts = NULL;
602+ pinctrl_select_state(ascport->pinctrl,
603+ ascport->states[DEFAULT]);
604+ }
605+ }
598606 }
599607
600608 static const char *asc_type(struct uart_port *port)
drivers/tty/serial/stm32-usart.c+136−87
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 * Inspired by st-asc.c from STMicroelectronics (c)
1010 */
1111
12+#include <linux/bitfield.h>
1213 #include <linux/clk.h>
1314 #include <linux/console.h>
1415 #include <linux/delay.h>
@@ -39,60 +40,64 @@ · 24 unmodified lines
3940 /* Register offsets */
4041 static struct stm32_usart_info __maybe_unused stm32f4_info = {
4142 .ofs = {
42− .isr = 0x00,
43− .rdr = 0x04,
44− .tdr = 0x04,
45− .brr = 0x08,
46− .cr1 = 0x0c,
47− .cr2 = 0x10,
48− .cr3 = 0x14,
49− .gtpr = 0x18,
50− .rtor = UNDEF_REG,
51− .rqr = UNDEF_REG,
52− .icr = UNDEF_REG,
43+ .isr = 0x00,
44+ .rdr = 0x04,
45+ .tdr = 0x04,
46+ .brr = 0x08,
47+ .cr1 = 0x0c,
48+ .cr2 = 0x10,
49+ .cr3 = 0x14,
50+ .gtpr = 0x18,
51+ .rtor = UNDEF_REG,
52+ .rqr = UNDEF_REG,
53+ .icr = UNDEF_REG,
54+ .presc = UNDEF_REG,
55+ .hwcfgr1 = UNDEF_REG,
5356 },
5457 .cfg = {
5558 .uart_enable_bit = 13,
5659 .has_7bits_data = false,
57− .fifosize = 1,
5860 }
5961 };
6062
6163 static struct stm32_usart_info __maybe_unused stm32f7_info = {
6264 .ofs = {
63− .cr1 = 0x00,
64− .cr2 = 0x04,
65− .cr3 = 0x08,
66− .brr = 0x0c,
67− .gtpr = 0x10,
68− .rtor = 0x14,
69− .rqr = 0x18,
70− .isr = 0x1c,
71− .icr = 0x20,
72− .rdr = 0x24,
73− .tdr = 0x28,
65+ .cr1 = 0x00,
66+ .cr2 = 0x04,
67+ .cr3 = 0x08,
68+ .brr = 0x0c,
69+ .gtpr = 0x10,
70+ .rtor = 0x14,
71+ .rqr = 0x18,
72+ .isr = 0x1c,
73+ .icr = 0x20,
74+ .rdr = 0x24,
75+ .tdr = 0x28,
76+ .presc = UNDEF_REG,
77+ .hwcfgr1 = UNDEF_REG,
7478 },
7579 .cfg = {
7680 .uart_enable_bit = 0,
7781 .has_7bits_data = true,
7882 .has_swap = true,
79− .fifosize = 1,
8083 }
8184 };
8285
8386 static struct stm32_usart_info __maybe_unused stm32h7_info = {
8487 .ofs = {
85− .cr1 = 0x00,
86− .cr2 = 0x04,
87− .cr3 = 0x08,
88− .brr = 0x0c,
89− .gtpr = 0x10,
90− .rtor = 0x14,
91− .rqr = 0x18,
92− .isr = 0x1c,
93− .icr = 0x20,
94− .rdr = 0x24,
95− .tdr = 0x28,
88+ .cr1 = 0x00,
89+ .cr2 = 0x04,
90+ .cr3 = 0x08,
91+ .brr = 0x0c,
92+ .gtpr = 0x10,
93+ .rtor = 0x14,
94+ .rqr = 0x18,
95+ .isr = 0x1c,
96+ .icr = 0x20,
97+ .rdr = 0x24,
98+ .tdr = 0x28,
99+ .presc = 0x2c,
100+ .hwcfgr1 = 0x3f0,
96101 },
97102 .cfg = {
98103 .uart_enable_bit = 0,
@@ -100,7 +105,6 @@ static struct stm32_usart_info __maybe_unused stm32h7_info = { · 1 unmodified line
100105 .has_swap = true,
101106 .has_wakeup = true,
102107 .has_fifo = true,
103− .fifosize = 16,
104108 }
105109 };
106110
@@ -1147,6 +1151,8 @@ static void stm32_usart_shutdown(struct uart_port *port) · 1040 unmodified lines
11471151 free_irq(port->irq, port);
11481152 }
11491153
1154+static const unsigned int stm32_usart_presc_val[] = {1, 2, 4, 6, 8, 10, 12, 16, 32, 64, 128, 256};
1155+
11501156 static void stm32_usart_set_termios(struct uart_port *port,
11511157 struct ktermios *termios,
11521158 const struct ktermios *old)
@@ -1155,17 +1161,19 @@ static void stm32_usart_set_termios(struct uart_port *port, · 2 unmodified lines
11551161 const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs;
11561162 const struct stm32_usart_config *cfg = &stm32_port->info->cfg;
11571163 struct serial_rs485 *rs485conf = &port->rs485;
1158− unsigned int baud, bits;
1164+ unsigned int baud, bits, uart_clk, uart_clk_pres;
11591165 u32 usartdiv, mantissa, fraction, oversampling;
11601166 tcflag_t cflag = termios->c_cflag;
1161− u32 cr1, cr2, cr3, isr;
1167+ u32 cr1, cr2, cr3, isr, brr, presc;
11621168 unsigned long flags;
11631169 int ret;
11641170
11651171 if (!stm32_port->hw_flow_control)
11661172 cflag &= ~CRTSCTS;
11671173
1168− baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 8);
1174+ uart_clk = clk_get_rate(stm32_port->clk);
1175+
1176+ baud = uart_get_baud_rate(port, termios, old, 0, uart_clk / 8);
11691177
11701178 uart_port_lock_irqsave(port, &flags);
11711179
@@ -1267,27 +1275,48 @@ static void stm32_usart_set_termios(struct uart_port *port, · 95 unmodified lines
12671275 cr3 |= USART_CR3_CTSE | USART_CR3_RTSE;
12681276 }
12691277
1270− usartdiv = DIV_ROUND_CLOSEST(port->uartclk, baud);
1278+ for (presc = 0; presc <= USART_PRESC_MAX; presc++) {
1279+ uart_clk_pres = DIV_ROUND_CLOSEST(uart_clk, stm32_usart_presc_val[presc]);
1280+ usartdiv = DIV_ROUND_CLOSEST(uart_clk_pres, baud);
12711281
1272− /*
1273− * The USART supports 16 or 8 times oversampling.
1274− * By default we prefer 16 times oversampling, so that the receiver
1275− * has a better tolerance to clock deviations.
1276− * 8 times oversampling is only used to achieve higher speeds.
1277− */
1278− if (usartdiv < 16) {
1279− oversampling = 8;
1280− cr1 |= USART_CR1_OVER8;
1281− stm32_usart_set_bits(port, ofs->cr1, USART_CR1_OVER8);
1282− } else {
1283− oversampling = 16;
1284− cr1 &= ~USART_CR1_OVER8;
1285− stm32_usart_clr_bits(port, ofs->cr1, USART_CR1_OVER8);
1282+ /*
1283+ * The USART supports 16 or 8 times oversampling.
1284+ * By default we prefer 16 times oversampling, so that the receiver
1285+ * has a better tolerance to clock deviations.
1286+ * 8 times oversampling is only used to achieve higher speeds.
1287+ */
1288+ if (usartdiv < 16) {
1289+ oversampling = 8;
1290+ cr1 |= USART_CR1_OVER8;
1291+ stm32_usart_set_bits(port, ofs->cr1, USART_CR1_OVER8);
1292+ } else {
1293+ oversampling = 16;
1294+ cr1 &= ~USART_CR1_OVER8;
1295+ stm32_usart_clr_bits(port, ofs->cr1, USART_CR1_OVER8);
1296+ }
1297+
1298+ mantissa = (usartdiv / oversampling) << USART_BRR_DIV_M_SHIFT;
1299+ fraction = usartdiv % oversampling;
1300+ brr = mantissa | fraction;
1301+
1302+ if (FIELD_FIT(USART_BRR_MASK, brr)) {
1303+ if (ofs->presc != UNDEF_REG) {
1304+ port->uartclk = uart_clk_pres;
1305+ writel_relaxed(presc, port->membase + ofs->presc);
1306+ } else if (presc) {
1307+ /* We need a prescaler but we don't have it (STM32F4, STM32F7) */
1308+ dev_err(port->dev,
1309+ "unable to set baudrate, input clock is too high");
1310+ }
1311+ break;
1312+ } else if (presc == USART_PRESC_MAX) {
1313+ /* Even with prescaler and brr at max value we can't set baudrate */
1314+ dev_err(port->dev, "unable to set baudrate, input clock is too high");
1315+ break;
1316+ }
12861317 }
12871318
1288− mantissa = (usartdiv / oversampling) << USART_BRR_DIV_M_SHIFT;
1289− fraction = usartdiv % oversampling;
1290− writel_relaxed(mantissa | fraction, port->membase + ofs->brr);
1319+ writel_relaxed(brr, port->membase + ofs->brr);
12911320
12921321 uart_update_timeout(port, cflag, baud);
12931322
@@ -1471,37 +1500,57 @@ static const struct uart_ops stm32_uart_ops = { · 177 unmodified lines
14711500 #endif /* CONFIG_CONSOLE_POLL */
14721501 };
14731502
1474−/*
1475− * STM32H7 RX & TX FIFO threshold configuration (CR3 RXFTCFG / TXFTCFG)
1476− * Note: 1 isn't a valid value in RXFTCFG / TXFTCFG. In this case,
1477− * RXNEIE / TXEIE can be used instead of threshold irqs: RXFTIE / TXFTIE.
1478− * So, RXFTCFG / TXFTCFG bitfields values are encoded as array index + 1.
1479− */
1480−static const u32 stm32h7_usart_fifo_thresh_cfg[] = { 1, 2, 4, 8, 12, 14, 16 };
1503+struct stm32_usart_thresh_ratio {
1504+ int mul;
1505+ int div;
1506+};
1507+
1508+static const struct stm32_usart_thresh_ratio stm32h7_usart_fifo_thresh_cfg[] = {
1509+ {1, 8}, {1, 4}, {1, 2}, {3, 4}, {7, 8}, {1, 1} };
1510+
1511+static int stm32_usart_get_thresh_value(u32 fifo_size, int index)
1512+{
1513+ return fifo_size * stm32h7_usart_fifo_thresh_cfg[index].mul /
1514+ stm32h7_usart_fifo_thresh_cfg[index].div;
1515+}
14811516
1482−static void stm32_usart_get_ftcfg(struct platform_device *pdev, const char *p,
1483− int *ftcfg)
1517+static int stm32_usart_get_ftcfg(struct platform_device *pdev, struct stm32_port *stm32port,
1518+ const char *p, int *ftcfg)
14841519 {
1485− u32 bytes, i;
1520+ const struct stm32_usart_offsets *ofs = &stm32port->info->ofs;
1521+ u32 bytes, i, cfg8;
1522+ int fifo_size;
1523+
1524+ if (WARN_ON(ofs->hwcfgr1 == UNDEF_REG))
1525+ return 1;
1526+
1527+ cfg8 = FIELD_GET(USART_HWCFGR1_CFG8,
1528+ readl_relaxed(stm32port->port.membase + ofs->hwcfgr1));
1529+
1530+ /* On STM32H7, hwcfgr is not present, so returned value will be 0 */
1531+ fifo_size = cfg8 ? 1 << cfg8 : STM32H7_USART_FIFO_SIZE;
14861532
1487− /* DT option to get RX & TX FIFO threshold (default to 8 bytes) */
1533+ /* DT option to get RX & TX FIFO threshold (default to half fifo size) */
14881534 if (of_property_read_u32(pdev->dev.of_node, p, &bytes))
1489− bytes = 8;
1535+ bytes = fifo_size / 2;
14901536
1491− for (i = 0; i < ARRAY_SIZE(stm32h7_usart_fifo_thresh_cfg); i++)
1492− if (stm32h7_usart_fifo_thresh_cfg[i] >= bytes)
1537+ if (bytes < stm32_usart_get_thresh_value(fifo_size, 0)) {
1538+ *ftcfg = -EINVAL;
1539+ return fifo_size;
1540+ }
1541+
1542+ for (i = 0; i < ARRAY_SIZE(stm32h7_usart_fifo_thresh_cfg); i++) {
1543+ if (stm32_usart_get_thresh_value(fifo_size, i) >= bytes)
14931544 break;
1545+ }
14941546 if (i >= ARRAY_SIZE(stm32h7_usart_fifo_thresh_cfg))
14951547 i = ARRAY_SIZE(stm32h7_usart_fifo_thresh_cfg) - 1;
14961548
1497− dev_dbg(&pdev->dev, "%s set to %d bytes\n", p,
1498− stm32h7_usart_fifo_thresh_cfg[i]);
1549+ dev_dbg(&pdev->dev, "%s set to %d/%d bytes\n", p,
1550+ stm32_usart_get_thresh_value(fifo_size, i), fifo_size);
14991551
1500− /* Provide FIFO threshold ftcfg (1 is invalid: threshold irq unused) */
1501− if (i)
1502− *ftcfg = i - 1;
1503− else
1504− *ftcfg = -EINVAL;
1552+ *ftcfg = i;
1553+ return fifo_size;
15051554 }
15061555
15071556 static void stm32_usart_deinit_port(struct stm32_port *stm32port)
@@ -1531,7 +1580,6 @@ static int stm32_usart_init_port(struct stm32_port *stm32port, · 23 unmodified lines
15311580 port->flags = UPF_BOOT_AUTOCONF;
15321581 port->ops = &stm32_uart_ops;
15331582 port->dev = &pdev->dev;
1534− port->fifosize = stm32port->info->cfg.fifosize;
15351583 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_STM32_CONSOLE);
15361584 port->irq = irq;
15371585 port->rs485_config = stm32_usart_config_rs485;
@@ -1547,14 +1595,6 @@ static int stm32_usart_init_port(struct stm32_port *stm32port, · 9 unmodified lines
15471595 stm32port->swap = stm32port->info->cfg.has_swap &&
15481596 of_property_read_bool(pdev->dev.of_node, "rx-tx-swap");
15491597
1550− stm32port->fifoen = stm32port->info->cfg.has_fifo;
1551− if (stm32port->fifoen) {
1552− stm32_usart_get_ftcfg(pdev, "rx-threshold",
1553− &stm32port->rxftcfg);
1554− stm32_usart_get_ftcfg(pdev, "tx-threshold",
1555− &stm32port->txftcfg);
1556− }
1557−
15581598 port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
15591599 if (IS_ERR(port->membase))
15601600 return PTR_ERR(port->membase);
@@ -1577,6 +1617,15 @@ static int stm32_usart_init_port(struct stm32_port *stm32port, · 16 unmodified lines
15771617 goto err_clk;
15781618 }
15791619
1620+ stm32port->fifoen = stm32port->info->cfg.has_fifo;
1621+ if (stm32port->fifoen) {
1622+ stm32_usart_get_ftcfg(pdev, stm32port, "rx-threshold", &stm32port->rxftcfg);
1623+ port->fifosize = stm32_usart_get_ftcfg(pdev, stm32port, "tx-threshold",
1624+ &stm32port->txftcfg);
1625+ } else {
1626+ port->fifosize = 1;
1627+ }
1628+
15801629 stm32port->gpios = mctrl_gpio_init(&stm32port->port, 0);
15811630 if (IS_ERR(stm32port->gpios)) {
15821631 ret = PTR_ERR(stm32port->gpios);
drivers/tty/serial/stm32-usart.h+24−14
@@ -9,17 +9,19 @@ · 8 unmodified lines
99 #define DRIVER_NAME "stm32-usart"
1010
1111 struct stm32_usart_offsets {
12− u8 cr1;
13− u8 cr2;
14− u8 cr3;
15− u8 brr;
16− u8 gtpr;
17− u8 rtor;
18− u8 rqr;
19− u8 isr;
20− u8 icr;
21− u8 rdr;
22− u8 tdr;
12+ u16 cr1;
13+ u16 cr2;
14+ u16 cr3;
15+ u16 brr;
16+ u16 gtpr;
17+ u16 rtor;
18+ u16 rqr;
19+ u16 isr;
20+ u16 icr;
21+ u16 rdr;
22+ u16 tdr;
23+ u16 presc;
24+ u16 hwcfgr1;
2325 };
2426
2527 struct stm32_usart_config {
@@ -28,7 +30,6 @@ struct stm32_usart_config { · 2 unmodified lines
2830 bool has_swap;
2931 bool has_wakeup;
3032 bool has_fifo;
31− int fifosize;
3233 };
3334
3435 struct stm32_usart_info {
@@ -36,7 +37,7 @@ struct stm32_usart_info { · 1 unmodified line
3637 struct stm32_usart_config cfg;
3738 };
3839
39−#define UNDEF_REG 0xff
40+#define UNDEF_REG 0xffff
4041
4142 /* USART_SR (F4) / USART_ISR (F7) */
4243 #define USART_SR_PE BIT(0)
@@ -71,6 +72,7 @@ struct stm32_usart_info { · 28 unmodified lines
7172 #define USART_BRR_DIV_M_MASK GENMASK(15, 4)
7273 #define USART_BRR_DIV_M_SHIFT 4
7374 #define USART_BRR_04_R_SHIFT 1
75+#define USART_BRR_MASK (USART_BRR_DIV_M_MASK | USART_BRR_DIV_F_MASK)
7476
7577 /* USART_CR1 */
7678 #define USART_CR1_SBK BIT(0)
@@ -176,8 +178,16 @@ struct stm32_usart_info { · 99 unmodified lines
176178 #define USART_ICR_CMCF BIT(17) /* F7 */
177179 #define USART_ICR_WUCF BIT(20) /* H7 */
178180
181+/* USART_PRESC */
182+#define USART_PRESC GENMASK(3, 0) /* H7 */
183+#define USART_PRESC_MAX 0b1011
184+
185+/* USART_HWCFCR1 */
186+#define USART_HWCFGR1_CFG8 GENMASK(31, 28) /* MP1 */
187+
179188 #define STM32_SERIAL_NAME "ttySTM"
180−#define STM32_MAX_PORTS 8
189+#define STM32_MAX_PORTS 9
190+#define STM32H7_USART_FIFO_SIZE 16
181191
182192 #define RX_BUF_L 4096 /* dma rx buffer length */
183193 #define RX_BUF_P (RX_BUF_L / 2) /* dma rx buffer period */
drivers/tty/serial/sunplus-uart.c+6−12
@@ -260,7 +260,7 @@ static void receive_chars(struct uart_port *port) · 259 unmodified lines
260260 if (port->ignore_status_mask & SUP_DUMMY_READ)
261261 goto ignore_char;
262262
263− if (uart_handle_sysrq_char(port, ch))
263+ if (uart_prepare_sysrq_char(port, ch))
264264 goto ignore_char;
265265
266266 uart_insert_char(port, lsr, SUP_UART_LSR_OE, ch, flag);
@@ -287,7 +287,7 @@ static irqreturn_t sunplus_uart_irq(int irq, void *args) · 20 unmodified lines
287287 if (isc & SUP_UART_ISC_TX)
288288 transmit_chars(port);
289289
290− uart_port_unlock(port);
290+ uart_unlock_and_check_sysrq(port);
291291
292292 return IRQ_HANDLED;
293293 }
@@ -512,22 +512,16 @@ static void sunplus_console_write(struct console *co, · 218 unmodified lines
512512 unsigned long flags;
513513 int locked = 1;
514514
515− local_irq_save(flags);
516−
517− if (sunplus_console_ports[co->index]->port.sysrq)
518− locked = 0;
519− else if (oops_in_progress)
520− locked = uart_port_trylock(&sunplus_console_ports[co->index]->port);
515+ if (oops_in_progress)
516+ locked = uart_port_trylock_irqsave(&sunplus_console_ports[co->index]->port, &flags);
521517 else
522− uart_port_lock(&sunplus_console_ports[co->index]->port);
518+ uart_port_lock_irqsave(&sunplus_console_ports[co->index]->port, &flags);
523519
524520 uart_console_write(&sunplus_console_ports[co->index]->port, s, count,
525521 sunplus_uart_console_putchar);
526522
527523 if (locked)
528− uart_port_unlock(&sunplus_console_ports[co->index]->port);
529−
530− local_irq_restore(flags);
524+ uart_port_unlock_irqrestore(&sunplus_console_ports[co->index]->port, flags);
531525 }
532526
533527 static int __init sunplus_console_setup(struct console *co, char *options)
drivers/tty/serial/xilinx_uartps.c+215−21
@@ -22,7 +22,9 @@ · 21 unmodified lines
2222 #include <linux/of.h>
2323 #include <linux/module.h>
2424 #include <linux/pm_runtime.h>
25−#include <linux/iopoll.h>
25+#include <linux/gpio.h>
26+#include <linux/gpio/consumer.h>
27+#include <linux/delay.h>
2628
2729 #define CDNS_UART_TTY_NAME "ttyPS"
2830 #define CDNS_UART_NAME "xuartps"
@@ -193,6 +195,9 @@ MODULE_PARM_DESC(rx_timeout, "Rx timeout, 1-255"); · 164 unmodified lines
193195 * @clk_rate_change_nb: Notifier block for clock changes
194196 * @quirks: Flags for RXBS support.
195197 * @cts_override: Modem control state override
198+ * @gpiod_rts: Pointer to the gpio descriptor
199+ * @rs485_tx_started: RS485 tx state
200+ * @tx_timer: Timer for tx
196201 */
197202 struct cdns_uart {
198203 struct uart_port *port;
@@ -203,10 +208,21 @@ struct cdns_uart { · 4 unmodified lines
203208 struct notifier_block clk_rate_change_nb;
204209 u32 quirks;
205210 bool cts_override;
211+ struct gpio_desc *gpiod_rts;
212+ bool rs485_tx_started;
213+ struct hrtimer tx_timer;
206214 };
207215 struct cdns_platform_data {
208216 u32 quirks;
209217 };
218+
219+struct serial_rs485 cdns_rs485_supported = {
220+ .flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND |
221+ SER_RS485_RTS_AFTER_SEND,
222+ .delay_rts_before_send = 1,
223+ .delay_rts_after_send = 1,
224+};
225+
210226 #define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \
211227 clk_rate_change_nb)
212228
@@ -306,17 +322,114 @@ static void cdns_uart_handle_rx(void *dev_id, unsigned int isrstatus) · 93 unmodified lines
306322 }
307323
308324 /**
309− * cdns_uart_handle_tx - Handle the bytes to be Txed.
325+ * cdns_rts_gpio_enable - Configure RTS/GPIO to high/low
326+ * @cdns_uart: Handle to the cdns_uart
327+ * @enable: Value to be set to RTS/GPIO
328+ */
329+static void cdns_rts_gpio_enable(struct cdns_uart *cdns_uart, bool enable)
330+{
331+ u32 val;
332+
333+ if (cdns_uart->gpiod_rts) {
334+ gpiod_set_value(cdns_uart->gpiod_rts, enable);
335+ } else {
336+ val = readl(cdns_uart->port->membase + CDNS_UART_MODEMCR);
337+ if (enable)
338+ val |= CDNS_UART_MODEMCR_RTS;
339+ else
340+ val &= ~CDNS_UART_MODEMCR_RTS;
341+ writel(val, cdns_uart->port->membase + CDNS_UART_MODEMCR);
342+ }
343+}
344+
345+/**
346+ * cdns_rs485_tx_setup - Tx setup specific to rs485
347+ * @cdns_uart: Handle to the cdns_uart
348+ */
349+static void cdns_rs485_tx_setup(struct cdns_uart *cdns_uart)
350+{
351+ bool enable;
352+
353+ enable = cdns_uart->port->rs485.flags & SER_RS485_RTS_ON_SEND;
354+ cdns_rts_gpio_enable(cdns_uart, enable);
355+
356+ cdns_uart->rs485_tx_started = true;
357+}
358+
359+/**
360+ * cdns_rs485_rx_setup - Rx setup specific to rs485
361+ * @cdns_uart: Handle to the cdns_uart
362+ */
363+static void cdns_rs485_rx_setup(struct cdns_uart *cdns_uart)
364+{
365+ bool enable;
366+
367+ enable = cdns_uart->port->rs485.flags & SER_RS485_RTS_AFTER_SEND;
368+ cdns_rts_gpio_enable(cdns_uart, enable);
369+
370+ cdns_uart->rs485_tx_started = false;
371+}
372+
373+/**
374+ * cdns_uart_tx_empty - Check whether TX is empty
375+ * @port: Handle to the uart port structure
376+ *
377+ * Return: TIOCSER_TEMT on success, 0 otherwise
378+ */
379+static unsigned int cdns_uart_tx_empty(struct uart_port *port)
380+{
381+ unsigned int status;
382+
383+ status = readl(port->membase + CDNS_UART_SR);
384+ status &= (CDNS_UART_SR_TXEMPTY | CDNS_UART_SR_TACTIVE);
385+ return (status == CDNS_UART_SR_TXEMPTY) ? TIOCSER_TEMT : 0;
386+}
387+
388+/**
389+ * cdns_rs485_rx_callback - Timer rx callback handler for rs485.
390+ * @t: Handle to the hrtimer structure
391+ */
392+static enum hrtimer_restart cdns_rs485_rx_callback(struct hrtimer *t)
393+{
394+ struct cdns_uart *cdns_uart = container_of(t, struct cdns_uart, tx_timer);
395+
396+ /*
397+ * Default Rx should be setup, because Rx signaling path
398+ * need to enable to receive data.
399+ */
400+ cdns_rs485_rx_setup(cdns_uart);
401+
402+ return HRTIMER_NORESTART;
403+}
404+
405+/**
406+ * cdns_calc_after_tx_delay - calculate delay required for after tx.
407+ * @cdns_uart: Handle to the cdns_uart
408+ */
409+static u64 cdns_calc_after_tx_delay(struct cdns_uart *cdns_uart)
410+{
411+ /*
412+ * Frame time + stop bit time + rs485.delay_rts_after_send
413+ */
414+ return cdns_uart->port->frame_time
415+ + DIV_ROUND_UP(cdns_uart->port->frame_time, 7)
416+ + (u64)cdns_uart->port->rs485.delay_rts_after_send * NSEC_PER_MSEC;
417+}
418+
419+/**
420+ * cdns_uart_handle_tx - Handle the bytes to be transmitted.
310421 * @dev_id: Id of the UART port
311422 * Return: None
312423 */
313424 static void cdns_uart_handle_tx(void *dev_id)
314425 {
315426 struct uart_port *port = (struct uart_port *)dev_id;
427+ struct cdns_uart *cdns_uart = port->private_data;
316428 struct circ_buf *xmit = &port->state->xmit;
317429 unsigned int numbytes;
318430
319− if (uart_circ_empty(xmit)) {
431+ if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
432+ /* Disable the TX Empty interrupt */
320433 writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_IDR);
321434 return;
322435 }
@@ -332,6 +445,16 @@ static void cdns_uart_handle_tx(void *dev_id) · 9 unmodified lines
332445
333446 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
334447 uart_write_wakeup(port);
448+
449+ /* Enable the TX Empty interrupt */
450+ writel(CDNS_UART_IXR_TXEMPTY, cdns_uart->port->membase + CDNS_UART_IER);
451+
452+ if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED &&
453+ (uart_circ_empty(xmit) || uart_tx_stopped(port))) {
454+ cdns_uart->tx_timer.function = &cdns_rs485_rx_callback;
455+ hrtimer_start(&cdns_uart->tx_timer,
456+ ns_to_ktime(cdns_calc_after_tx_delay(cdns_uart)), HRTIMER_MODE_REL);
457+ }
335458 }
336459
337460 /**
@@ -564,6 +687,21 @@ static int cdns_uart_clk_notifier_cb(struct notifier_block *nb, · 226 unmodified lines
564687 }
565688 #endif
566689
690+/**
691+ * cdns_rs485_tx_callback - Timer tx callback handler for rs485.
692+ * @t: Handle to the hrtimer structure
693+ */
694+static enum hrtimer_restart cdns_rs485_tx_callback(struct hrtimer *t)
695+{
696+ struct cdns_uart *cdns_uart = container_of(t, struct cdns_uart, tx_timer);
697+
698+ uart_port_lock(cdns_uart->port);
699+ cdns_uart_handle_tx(cdns_uart->port);
700+ uart_port_unlock(cdns_uart->port);
701+
702+ return HRTIMER_NORESTART;
703+}
704+
567705 /**
568706 * cdns_uart_start_tx - Start transmitting bytes
569707 * @port: Handle to the uart port structure
@@ -571,6 +709,7 @@ static int cdns_uart_clk_notifier_cb(struct notifier_block *nb, · 1 unmodified line
571709 static void cdns_uart_start_tx(struct uart_port *port)
572710 {
573711 unsigned int status;
712+ struct cdns_uart *cdns_uart = port->private_data;
574713
575714 if (uart_tx_stopped(port))
576715 return;
@@ -587,12 +726,19 @@ static void cdns_uart_start_tx(struct uart_port *port) · 10 unmodified lines
587726 if (uart_circ_empty(&port->state->xmit))
588727 return;
589728
729+ /* Clear the TX Empty interrupt */
590730 writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_ISR);
591731
732+ if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED) {
733+ if (!cdns_uart->rs485_tx_started) {
734+ cdns_uart->tx_timer.function = &cdns_rs485_tx_callback;
735+ cdns_rs485_tx_setup(cdns_uart);
736+ return hrtimer_start(&cdns_uart->tx_timer,
737+ ms_to_ktime(port->rs485.delay_rts_before_send),
738+ HRTIMER_MODE_REL);
739+ }
740+ }
592741 cdns_uart_handle_tx(port);
593−
594− /* Enable the TX Empty interrupt */
595− writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_IER);
596742 }
597743
598744 /**
@@ -602,6 +748,10 @@ static void cdns_uart_start_tx(struct uart_port *port) · 3 unmodified lines
602748 static void cdns_uart_stop_tx(struct uart_port *port)
603749 {
604750 unsigned int regval;
751+ struct cdns_uart *cdns_uart = port->private_data;
752+
753+ if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED)
754+ cdns_rs485_rx_setup(cdns_uart);
605755
606756 regval = readl(port->membase + CDNS_UART_CR);
607757 regval |= CDNS_UART_CR_TX_DIS;
@@ -626,21 +776,6 @@ static void cdns_uart_stop_rx(struct uart_port *port) · 18 unmodified lines
626776 writel(regval, port->membase + CDNS_UART_CR);
627777 }
628778
629−/**
630− * cdns_uart_tx_empty - Check whether TX is empty
631− * @port: Handle to the uart port structure
632− *
633− * Return: TIOCSER_TEMT on success, 0 otherwise
634− */
635−static unsigned int cdns_uart_tx_empty(struct uart_port *port)
636−{
637− unsigned int status;
638−
639− status = readl(port->membase + CDNS_UART_SR) &
640− (CDNS_UART_SR_TXEMPTY | CDNS_UART_SR_TACTIVE);
641− return (status == CDNS_UART_SR_TXEMPTY) ? TIOCSER_TEMT : 0;
642−}
643−
644779 /**
645780 * cdns_uart_break_ctl - Based on the input ctl we have to start or stop
646781 * transmitting char breaks
@@ -829,6 +964,9 @@ static int cdns_uart_startup(struct uart_port *port) · 182 unmodified lines
829964 (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST))
830965 cpu_relax();
831966
967+ if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED)
968+ cdns_rs485_rx_setup(cdns_uart);
969+
832970 /*
833971 * Clear the RX disable bit and then set the RX enable bit to enable
834972 * the receiver.
@@ -888,6 +1026,10 @@ static void cdns_uart_shutdown(struct uart_port *port) · 53 unmodified lines
8881026 {
8891027 int status;
8901028 unsigned long flags;
1029+ struct cdns_uart *cdns_uart = port->private_data;
1030+
1031+ if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED)
1032+ hrtimer_cancel(&cdns_uart->tx_timer);
8911033
8921034 uart_port_lock_irqsave(port, &flags);
8931035
@@ -1033,6 +1175,8 @@ static void cdns_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) · 139 unmodified lines
10331175
10341176 if (mctrl & TIOCM_RTS)
10351177 val |= CDNS_UART_MODEMCR_RTS;
1178+ if (cdns_uart_data->gpiod_rts)
1179+ gpiod_set_value(cdns_uart_data->gpiod_rts, !(mctrl & TIOCM_RTS));
10361180 if (mctrl & TIOCM_DTR)
10371181 val |= CDNS_UART_MODEMCR_DTR;
10381182 if (mctrl & TIOCM_LOOP)
@@ -1455,6 +1599,39 @@ MODULE_DEVICE_TABLE(of, cdns_uart_of_match); · 416 unmodified lines
14551599 /* Temporary variable for storing number of instances */
14561600 static int instances;
14571601
1602+/**
1603+ * cdns_rs485_config - Called when an application calls TIOCSRS485 ioctl.
1604+ * @port: Pointer to the uart_port structure
1605+ * @termios: Pointer to the ktermios structure
1606+ * @rs485: Pointer to the serial_rs485 structure
1607+ *
1608+ * Return: 0
1609+ */
1610+static int cdns_rs485_config(struct uart_port *port, struct ktermios *termios,
1611+ struct serial_rs485 *rs485)
1612+{
1613+ u32 val;
1614+ struct cdns_uart *cdns_uart = port->private_data;
1615+
1616+ if (rs485->flags & SER_RS485_ENABLED) {
1617+ dev_dbg(port->dev, "Setting UART to RS485\n");
1618+ /* Make sure auto RTS is disabled */
1619+ val = readl(port->membase + CDNS_UART_MODEMCR);
1620+ val &= ~CDNS_UART_MODEMCR_FCM;
1621+ writel(val, port->membase + CDNS_UART_MODEMCR);
1622+
1623+ /* Timer setup */
1624+ hrtimer_init(&cdns_uart->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1625+ cdns_uart->tx_timer.function = &cdns_rs485_tx_callback;
1626+
1627+ /* Disable transmitter and make Rx setup*/
1628+ cdns_uart_stop_tx(port);
1629+ } else {
1630+ hrtimer_cancel(&cdns_uart->tx_timer);
1631+ }
1632+ return 0;
1633+}
1634+
14581635 /**
14591636 * cdns_uart_probe - Platform driver probe
14601637 * @pdev: Pointer to the platform device structure
@@ -1597,9 +1774,23 @@ static int cdns_uart_probe(struct platform_device *pdev) · 136 unmodified lines
15971774 port->private_data = cdns_uart_data;
15981775 port->read_status_mask = CDNS_UART_IXR_TXEMPTY | CDNS_UART_IXR_RXTRIG |
15991776 CDNS_UART_IXR_OVERRUN | CDNS_UART_IXR_TOUT;
1777+ port->rs485_config = cdns_rs485_config;
1778+ port->rs485_supported = cdns_rs485_supported;
16001779 cdns_uart_data->port = port;
16011780 platform_set_drvdata(pdev, port);
16021781
1782+ rc = uart_get_rs485_mode(port);
1783+ if (rc)
1784+ goto err_out_clk_notifier;
1785+
1786+ cdns_uart_data->gpiod_rts = devm_gpiod_get_optional(&pdev->dev, "rts",
1787+ GPIOD_OUT_LOW);
1788+ if (IS_ERR(cdns_uart_data->gpiod_rts)) {
1789+ rc = PTR_ERR(cdns_uart_data->gpiod_rts);
1790+ dev_err(port->dev, "xuartps: devm_gpiod_get_optional failed\n");
1791+ goto err_out_clk_notifier;
1792+ }
1793+
16031794 pm_runtime_use_autosuspend(&pdev->dev);
16041795 pm_runtime_set_autosuspend_delay(&pdev->dev, UART_AUTOSUSPEND_TIMEOUT);
16051796 pm_runtime_set_active(&pdev->dev);
@@ -1618,6 +1809,8 @@ static int cdns_uart_probe(struct platform_device *pdev) · 12 unmodified lines
16181809 console_port = port;
16191810 }
16201811 #endif
1812+ if (cdns_uart_data->port->rs485.flags & SER_RS485_ENABLED)
1813+ cdns_rs485_rx_setup(cdns_uart_data);
16211814
16221815 rc = uart_add_one_port(&cdns_uart_uart_driver, port);
16231816 if (rc) {
@@ -1646,6 +1839,7 @@ err_out_pm_disable: · 22 unmodified lines
16461839 pm_runtime_disable(&pdev->dev);
16471840 pm_runtime_set_suspended(&pdev->dev);
16481841 pm_runtime_dont_use_autosuspend(&pdev->dev);
1842+err_out_clk_notifier:
16491843 #ifdef CONFIG_COMMON_CLK
16501844 clk_notifier_unregister(cdns_uart_data->uartclk,
16511845 &cdns_uart_data->clk_rate_change_nb);
drivers/tty/tty_buffer.c+1−0
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 #include <linux/errno.h>
88 #include <linux/minmax.h>
99 #include <linux/tty.h>
10+#include <linux/tty_buffer.h>
1011 #include <linux/tty_driver.h>
1112 #include <linux/tty_flip.h>
1213 #include <linux/timer.h>
drivers/tty/vt/Makefile+2−2
@@ -5,9 +5,9 @@ · 4 unmodified lines
55 FONTMAPFILE = cp437.uni
66
77 obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o \
8− selection.o keyboard.o
8+ selection.o keyboard.o \
9+ vt.o defkeymap.o
910 obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o
10−obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
1111
1212 # Files generated that shall be removed upon make clean
1313 clean-files := consolemap_deftbl.c defkeymap.c
drivers/tty/vt/selection.c+26−17
@@ -7,7 +7,7 @@ · 6 unmodified lines
77 * 'int set_selection_kernel(struct tiocl_selection *, struct tty_struct *)'
88 * 'void clear_selection(void)'
99 * 'int paste_selection(struct tty_struct *)'
10− * 'int sel_loadlut(char __user *)'
10+ * 'int sel_loadlut(u32 __user *)'
1111 *
1212 * Now that /dev/vcs exists, most of this can disappear again.
1313 */
@@ -73,10 +73,12 @@ sel_pos(int n, bool unicode) · 59 unmodified lines
7373 }
7474
7575 /**
76− * clear_selection - remove current selection
76+ * clear_selection - remove current selection
7777 *
78− * Remove the current selection highlight, if any from the console
79− * holding the selection. The caller must hold the console lock.
78+ * Remove the current selection highlight, if any from the console holding the
79+ * selection.
80+ *
81+ * Locking: The caller must hold the console lock.
8082 */
8183 void clear_selection(void)
8284 {
@@ -88,7 +90,7 @@ void clear_selection(void) · 5 unmodified lines
8890 }
8991 EXPORT_SYMBOL_GPL(clear_selection);
9092
91−bool vc_is_sel(struct vc_data *vc)
93+bool vc_is_sel(const struct vc_data *vc)
9294 {
9395 return vc == vc_sel.cons;
9496 }
@@ -110,18 +112,25 @@ static inline int inword(const u32 c) · 15 unmodified lines
110112 }
111113
112114 /**
113− * sel_loadlut() - load the LUT table
114− * @p: user table
115+ * sel_loadlut() - load the LUT table
116+ * @lut: user table
117+ *
118+ * Load the LUT table from user space. Make a temporary copy so a partial
119+ * update doesn't make a mess.
115120 *
116− * Load the LUT table from user space. The caller must hold the console
117− * lock. Make a temporary copy so a partial update doesn't make a mess.
121+ * Locking: The console lock is acquired.
118122 */
119−int sel_loadlut(char __user *p)
123+int sel_loadlut(u32 __user *lut)
120124 {
121125 u32 tmplut[ARRAY_SIZE(inwordLut)];
122− if (copy_from_user(tmplut, (u32 __user *)(p+4), sizeof(inwordLut)))
126+
127+ if (copy_from_user(tmplut, lut, sizeof(inwordLut)))
123128 return -EFAULT;
129+
130+ console_lock();
124131 memcpy(inwordLut, tmplut, sizeof(inwordLut));
132+ console_unlock();
133+
125134 return 0;
126135 }
127136
@@ -166,14 +175,14 @@ static int store_utf8(u32 c, char *p) · 38 unmodified lines
166175 }
167176
168177 /**
169− * set_selection_user - set the current selection.
170− * @sel: user selection info
171− * @tty: the console tty
178+ * set_selection_user - set the current selection.
179+ * @sel: user selection info
180+ * @tty: the console tty
172181 *
173− * Invoked by the ioctl handle for the vt layer.
182+ * Invoked by the ioctl handle for the vt layer.
174183 *
175− * The entire selection process is managed under the console_lock. It's
176− * a lot under the lock but its hardly a performance path
184+ * Locking: The entire selection process is managed under the console_lock.
185+ * It's a lot under the lock but its hardly a performance path.
177186 */
178187 int set_selection_user(const struct tiocl_selection __user *sel,
179188 struct tty_struct *tty)
drivers/tty/vt/vt.c+831−700
@@ -145,7 +145,7 @@ static void gotoxy(struct vc_data *vc, int new_x, int new_y); · 144 unmodified lines
145145 static void save_cur(struct vc_data *vc);
146146 static void reset_terminal(struct vc_data *vc, int do_clear);
147147 static void con_flush_chars(struct tty_struct *tty);
148−static int set_vesa_blanking(char __user *p);
148+static int set_vesa_blanking(u8 __user *mode);
149149 static void set_cursor(struct vc_data *vc);
150150 static void hide_cursor(struct vc_data *vc);
151151 static void console_callback(struct work_struct *ignored);
@@ -175,7 +175,7 @@ int do_poke_blanked_console; · 23 unmodified lines
175175 int console_blanked;
176176 EXPORT_SYMBOL(console_blanked);
177177
178−static int vesa_blank_mode; /* 0:none 1:suspendV 2:suspendH 3:powerdown */
178+static enum vesa_blank_mode vesa_blank_mode;
179179 static int vesa_off_interval;
180180 static int blankinterval;
181181 core_param(consoleblank, blankinterval, int, 0444);
@@ -286,18 +286,20 @@ static inline bool con_should_update(const struct vc_data *vc) · 104 unmodified lines
286286 return con_is_visible(vc) && !console_blanked;
287287 }
288288
289−static inline unsigned short *screenpos(const struct vc_data *vc, int offset,
290− bool viewed)
289+static inline u16 *screenpos(const struct vc_data *vc, unsigned int offset,
290+ bool viewed)
291291 {
292− unsigned short *p;
293−
294− if (!viewed)
295− p = (unsigned short *)(vc->vc_origin + offset);
296− else if (!vc->vc_sw->con_screen_pos)
297− p = (unsigned short *)(vc->vc_visible_origin + offset);
292+ unsigned long origin = viewed ? vc->vc_visible_origin : vc->vc_origin;
293+
294+ return (u16 *)(origin + offset);
295+}
296+
297+static void con_putc(struct vc_data *vc, u16 ca, unsigned int y, unsigned int x)
298+{
299+ if (vc->vc_sw->con_putc)
300+ vc->vc_sw->con_putc(vc, ca, y, x);
298301 else
299− p = vc->vc_sw->con_screen_pos(vc, offset);
300− return p;
302+ vc->vc_sw->con_putcs(vc, &ca, 1, y, x);
301303 }
302304
303305 /* Called from the keyboard irq path.. */
@@ -591,18 +593,12 @@ static void con_scroll(struct vc_data *vc, unsigned int top, · 287 unmodified lines
591593 static void do_update_region(struct vc_data *vc, unsigned long start, int count)
592594 {
593595 unsigned int xx, yy, offset;
594− u16 *p;
596+ u16 *p = (u16 *)start;
597+
598+ offset = (start - vc->vc_origin) / 2;
599+ xx = offset % vc->vc_cols;
600+ yy = offset / vc->vc_cols;
595601
596− p = (u16 *) start;
597− if (!vc->vc_sw->con_getxy) {
598− offset = (start - vc->vc_origin) / 2;
599− xx = offset % vc->vc_cols;
600− yy = offset / vc->vc_cols;
601− } else {
602− int nxx, nyy;
603− start = vc->vc_sw->con_getxy(vc, start, &nxx, &nyy);
604− xx = nxx; yy = nyy;
605− }
606602 for(;;) {
607603 u16 attrib = scr_readw(p) & 0xff00;
608604 int startx = xx;
@@ -625,10 +621,6 @@ static void do_update_region(struct vc_data *vc, unsigned long start, int count) · 16 unmodified lines
625621 break;
626622 xx = 0;
627623 yy++;
628− if (vc->vc_sw->con_getxy) {
629− p = (u16 *)start;
630− start = vc->vc_sw->con_getxy(vc, start, NULL, NULL);
631− }
632624 }
633625 }
634626
@@ -703,7 +695,7 @@ static void update_attr(struct vc_data *vc) · 68 unmodified lines
703695 /* Note: inverting the screen twice should revert to the original state */
704696 void invert_screen(struct vc_data *vc, int offset, int count, bool viewed)
705697 {
706− unsigned short *p;
698+ u16 *p;
707699
708700 WARN_CONSOLE_UNLOCKED();
709701
@@ -762,7 +754,7 @@ void complement_pos(struct vc_data *vc, int offset) · 52 unmodified lines
762754 old_offset < vc->vc_screenbuf_size) {
763755 scr_writew(old, screenpos(vc, old_offset, true));
764756 if (con_should_update(vc))
765− vc->vc_sw->con_putc(vc, old, oldy, oldx);
757+ con_putc(vc, old, oldy, oldx);
766758 notify_update(vc);
767759 }
768760
@@ -771,15 +763,14 @@ void complement_pos(struct vc_data *vc, int offset) · 2 unmodified lines
771763 if (offset != -1 && offset >= 0 &&
772764 offset < vc->vc_screenbuf_size) {
773765 unsigned short new;
774− unsigned short *p;
775− p = screenpos(vc, offset, true);
766+ u16 *p = screenpos(vc, offset, true);
776767 old = scr_readw(p);
777768 new = old ^ vc->vc_complement_mask;
778769 scr_writew(new, p);
779770 if (con_should_update(vc)) {
780771 oldx = (offset >> 1) % vc->vc_cols;
781772 oldy = (offset >> 1) / vc->vc_cols;
782− vc->vc_sw->con_putc(vc, new, oldy, oldx);
773+ con_putc(vc, new, oldy, oldx);
783774 }
784775 notify_update(vc);
785776 }
@@ -833,7 +824,7 @@ static void add_softcursor(struct vc_data *vc) · 47 unmodified lines
833824 i ^= CUR_FG;
834825 scr_writew(i, (u16 *)vc->vc_pos);
835826 if (con_should_update(vc))
836− vc->vc_sw->con_putc(vc, i, vc->state.y, vc->state.x);
827+ con_putc(vc, i, vc->state.y, vc->state.x);
837828 }
838829
839830 static void hide_softcursor(struct vc_data *vc)
@@ -841,8 +832,8 @@ static void hide_softcursor(struct vc_data *vc) · 1 unmodified line
841832 if (softcursor_original != -1) {
842833 scr_writew(softcursor_original, (u16 *)vc->vc_pos);
843834 if (con_should_update(vc))
844− vc->vc_sw->con_putc(vc, softcursor_original,
845− vc->state.y, vc->state.x);
835+ con_putc(vc, softcursor_original, vc->state.y,
836+ vc->state.x);
846837 softcursor_original = -1;
847838 }
848839 }
@@ -852,7 +843,7 @@ static void hide_cursor(struct vc_data *vc) · 3 unmodified lines
852843 if (vc_is_sel(vc))
853844 clear_selection();
854845
855− vc->vc_sw->con_cursor(vc, CM_ERASE);
846+ vc->vc_sw->con_cursor(vc, false);
856847 hide_softcursor(vc);
857848 }
858849
@@ -865,7 +856,7 @@ static void set_cursor(struct vc_data *vc) · 6 unmodified lines
865856 clear_selection();
866857 add_softcursor(vc);
867858 if (CUR_SIZE(vc->vc_cursor_type) != CUR_NONE)
868− vc->vc_sw->con_cursor(vc, CM_DRAW);
859+ vc->vc_sw->con_cursor(vc, true);
869860 } else
870861 hide_cursor(vc);
871862 }
@@ -897,21 +888,18 @@ static void flush_scrollback(struct vc_data *vc) · 25 unmodified lines
897888 WARN_CONSOLE_UNLOCKED();
898889
899890 set_origin(vc);
900− if (vc->vc_sw->con_flush_scrollback) {
901− vc->vc_sw->con_flush_scrollback(vc);
902− } else if (con_is_visible(vc)) {
903− /*
904− * When no con_flush_scrollback method is provided then the
905− * legacy way for flushing the scrollback buffer is to use
906− * a side effect of the con_switch method. We do it only on
907− * the foreground console as background consoles have no
908− * scrollback buffers in that case and we obviously don't
909− * want to switch to them.
910− */
911− hide_cursor(vc);
912− vc->vc_sw->con_switch(vc);
913− set_cursor(vc);
914− }
891+ if (!con_is_visible(vc))
892+ return;
893+
894+ /*
895+ * The legacy way for flushing the scrollback buffer is to use a side
896+ * effect of the con_switch method. We do it only on the foreground
897+ * console as background consoles have no scrollback buffers in that
898+ * case and we obviously don't want to switch to them.
899+ */
900+ hide_cursor(vc);
901+ vc->vc_sw->con_switch(vc);
902+ set_cursor(vc);
915903 }
916904
917905 /*
@@ -962,7 +950,7 @@ void redraw_screen(struct vc_data *vc, int is_switch) · 44 unmodified lines
962950 }
963951
964952 if (redraw) {
965− int update;
953+ bool update;
966954 int old_was_color = vc->vc_can_do_color;
967955
968956 set_origin(vc);
@@ -999,7 +987,7 @@ int vc_cons_allocated(unsigned int i) · 30 unmodified lines
999987 return (i < MAX_NR_CONSOLES && vc_cons[i].d);
1000988 }
1001989
1002−static void visual_init(struct vc_data *vc, int num, int init)
990+static void visual_init(struct vc_data *vc, int num, bool init)
1003991 {
1004992 /* ++Geert: vc->vc_sw->con_init determines console size */
1005993 if (vc->vc_sw)
@@ -1083,7 +1071,7 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */ · 77 unmodified lines
10831071 vc->port.ops = &vc_port_ops;
10841072 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK);
10851073
1086− visual_init(vc, currcons, 1);
1074+ visual_init(vc, currcons, true);
10871075
10881076 if (!*vc->uni_pagedict_loc)
10891077 con_set_default_unimap(vc);
@@ -1115,51 +1103,44 @@ err_free: · 25 unmodified lines
11151103 }
11161104
11171105 static inline int resize_screen(struct vc_data *vc, int width, int height,
1118− int user)
1106+ bool from_user)
11191107 {
11201108 /* Resizes the resolution of the display adapater */
11211109 int err = 0;
11221110
11231111 if (vc->vc_sw->con_resize)
1124− err = vc->vc_sw->con_resize(vc, width, height, user);
1112+ err = vc->vc_sw->con_resize(vc, width, height, from_user);
11251113
11261114 return err;
11271115 }
11281116
11291117 /**
1130− * vc_do_resize - resizing method for the tty
1131− * @tty: tty being resized
1132− * @vc: virtual console private data
1133− * @cols: columns
1134− * @lines: lines
1118+ * vc_do_resize - resizing method for the tty
1119+ * @tty: tty being resized
1120+ * @vc: virtual console private data
1121+ * @cols: columns
1122+ * @lines: lines
1123+ * @from_user: invoked by a user?
11351124 *
1136− * Resize a virtual console, clipping according to the actual constraints.
1137− * If the caller passes a tty structure then update the termios winsize
1138− * information and perform any necessary signal handling.
1125+ * Resize a virtual console, clipping according to the actual constraints. If
1126+ * the caller passes a tty structure then update the termios winsize
1127+ * information and perform any necessary signal handling.
11391128 *
1140− * Caller must hold the console semaphore. Takes the termios rwsem and
1141− * ctrl.lock of the tty IFF a tty is passed.
1129+ * Locking: Caller must hold the console semaphore. Takes the termios rwsem and
1130+ * ctrl.lock of the tty IFF a tty is passed.
11421131 */
1143−
11441132 static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
1145− unsigned int cols, unsigned int lines)
1133+ unsigned int cols, unsigned int lines, bool from_user)
11461134 {
11471135 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
11481136 unsigned long end;
11491137 unsigned int old_rows, old_row_size, first_copied_row;
11501138 unsigned int new_cols, new_rows, new_row_size, new_screen_size;
1151− unsigned int user;
11521139 unsigned short *oldscreen, *newscreen;
11531140 u32 **new_uniscr = NULL;
11541141
11551142 WARN_CONSOLE_UNLOCKED();
11561143
1157− if (!vc)
1158− return -ENXIO;
1159−
1160− user = vc->vc_resize_user;
1161− vc->vc_resize_user = 0;
1162−
11631144 if (cols > VC_MAXCOL || lines > VC_MAXROW)
11641145 return -EINVAL;
11651146
@@ -1185,7 +1166,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, · 19 unmodified lines
11851166 * to deal with possible errors from the code below, we call
11861167 * the resize_screen here as well.
11871168 */
1188− return resize_screen(vc, new_cols, new_rows, user);
1169+ return resize_screen(vc, new_cols, new_rows, from_user);
11891170 }
11901171
11911172 if (new_screen_size > KMALLOC_MAX_SIZE || !new_screen_size)
@@ -1208,7 +1189,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, · 16 unmodified lines
12081189 old_rows = vc->vc_rows;
12091190 old_row_size = vc->vc_size_row;
12101191
1211− err = resize_screen(vc, new_cols, new_rows, user);
1192+ err = resize_screen(vc, new_cols, new_rows, from_user);
12121193 if (err) {
12131194 kfree(newscreen);
12141195 vc_uniscr_free(new_uniscr);
@@ -1295,34 +1276,35 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, · 80 unmodified lines
12951276 }
12961277
12971278 /**
1298− * vc_resize - resize a VT
1299− * @vc: virtual console
1300− * @cols: columns
1301− * @rows: rows
1279+ * __vc_resize - resize a VT
1280+ * @vc: virtual console
1281+ * @cols: columns
1282+ * @rows: rows
1283+ * @from_user: invoked by a user?
1284+ *
1285+ * Resize a virtual console as seen from the console end of things. We use the
1286+ * common vc_do_resize() method to update the structures.
13021287 *
1303− * Resize a virtual console as seen from the console end of things. We
1304− * use the common vc_do_resize methods to update the structures. The
1305− * caller must hold the console sem to protect console internals and
1306− * vc->port.tty
1288+ * Locking: The caller must hold the console sem to protect console internals
1289+ * and @vc->port.tty.
13071290 */
1308−
1309−int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows)
1291+int __vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows,
1292+ bool from_user)
13101293 {
1311− return vc_do_resize(vc->port.tty, vc, cols, rows);
1294+ return vc_do_resize(vc->port.tty, vc, cols, rows, from_user);
13121295 }
1313−EXPORT_SYMBOL(vc_resize);
1296+EXPORT_SYMBOL(__vc_resize);
13141297
13151298 /**
1316− * vt_resize - resize a VT
1317− * @tty: tty to resize
1318− * @ws: winsize attributes
1299+ * vt_resize - resize a VT
1300+ * @tty: tty to resize
1301+ * @ws: winsize attributes
13191302 *
1320− * Resize a virtual terminal. This is called by the tty layer as we
1321− * register our own handler for resizing. The mutual helper does all
1322− * the actual work.
1303+ * Resize a virtual terminal. This is called by the tty layer as we register
1304+ * our own handler for resizing. The mutual helper does all the actual work.
13231305 *
1324− * Takes the console sem and the called methods then take the tty
1325− * termios_rwsem and the tty ctrl.lock in that order.
1306+ * Locking: Takes the console sem and the called methods then take the tty
1307+ * termios_rwsem and the tty ctrl.lock in that order.
13261308 */
13271309 static int vt_resize(struct tty_struct *tty, struct winsize *ws)
13281310 {
@@ -1330,7 +1312,7 @@ static int vt_resize(struct tty_struct *tty, struct winsize *ws) · 1 unmodified line
13301312 int ret;
13311313
13321314 console_lock();
1333− ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row);
1315+ ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row, false);
13341316 console_unlock();
13351317 return ret;
13361318 }
@@ -1503,36 +1485,43 @@ static inline void del(struct vc_data *vc) · 166 unmodified lines
15031485 /* ignored */
15041486 }
15051487
1506−static void csi_J(struct vc_data *vc, int vpar)
1488+enum CSI_J {
1489+ CSI_J_CURSOR_TO_END = 0,
1490+ CSI_J_START_TO_CURSOR = 1,
1491+ CSI_J_VISIBLE = 2,
1492+ CSI_J_FULL = 3,
1493+};
1494+
1495+static void csi_J(struct vc_data *vc, enum CSI_J vpar)
15071496 {
1497+ unsigned short *start;
15081498 unsigned int count;
1509− unsigned short * start;
15101499
15111500 switch (vpar) {
1512− case 0: /* erase from cursor to end of display */
1513− vc_uniscr_clear_line(vc, vc->state.x,
1514− vc->vc_cols - vc->state.x);
1515− vc_uniscr_clear_lines(vc, vc->state.y + 1,
1516− vc->vc_rows - vc->state.y - 1);
1517− count = (vc->vc_scr_end - vc->vc_pos) >> 1;
1518− start = (unsigned short *)vc->vc_pos;
1519− break;
1520− case 1: /* erase from start to cursor */
1521− vc_uniscr_clear_line(vc, 0, vc->state.x + 1);
1522− vc_uniscr_clear_lines(vc, 0, vc->state.y);
1523− count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1;
1524− start = (unsigned short *)vc->vc_origin;
1525− break;
1526− case 3: /* include scrollback */
1527− flush_scrollback(vc);
1528− fallthrough;
1529− case 2: /* erase whole display */
1530− vc_uniscr_clear_lines(vc, 0, vc->vc_rows);
1531− count = vc->vc_cols * vc->vc_rows;
1532− start = (unsigned short *)vc->vc_origin;
1533− break;
1534− default:
1535− return;
1501+ case CSI_J_CURSOR_TO_END:
1502+ vc_uniscr_clear_line(vc, vc->state.x,
1503+ vc->vc_cols - vc->state.x);
1504+ vc_uniscr_clear_lines(vc, vc->state.y + 1,
1505+ vc->vc_rows - vc->state.y - 1);
1506+ count = (vc->vc_scr_end - vc->vc_pos) >> 1;
1507+ start = (unsigned short *)vc->vc_pos;
1508+ break;
1509+ case CSI_J_START_TO_CURSOR:
1510+ vc_uniscr_clear_line(vc, 0, vc->state.x + 1);
1511+ vc_uniscr_clear_lines(vc, 0, vc->state.y);
1512+ count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1;
1513+ start = (unsigned short *)vc->vc_origin;
1514+ break;
1515+ case CSI_J_FULL:
1516+ flush_scrollback(vc);
1517+ fallthrough;
1518+ case CSI_J_VISIBLE:
1519+ vc_uniscr_clear_lines(vc, 0, vc->vc_rows);
1520+ count = vc->vc_cols * vc->vc_rows;
1521+ start = (unsigned short *)vc->vc_origin;
1522+ break;
1523+ default:
1524+ return;
15361525 }
15371526 scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
15381527 if (con_should_update(vc))
@@ -1540,27 +1529,33 @@ static void csi_J(struct vc_data *vc, int vpar) · 1 unmodified line
15401529 vc->vc_need_wrap = 0;
15411530 }
15421531
1543−static void csi_K(struct vc_data *vc, int vpar)
1532+enum {
1533+ CSI_K_CURSOR_TO_LINEEND = 0,
1534+ CSI_K_LINESTART_TO_CURSOR = 1,
1535+ CSI_K_LINE = 2,
1536+};
1537+
1538+static void csi_K(struct vc_data *vc)
15441539 {
15451540 unsigned int count;
15461541 unsigned short *start = (unsigned short *)vc->vc_pos;
15471542 int offset;
15481543
1549− switch (vpar) {
1550− case 0: /* erase from cursor to end of line */
1551− offset = 0;
1552− count = vc->vc_cols - vc->state.x;
1553− break;
1554− case 1: /* erase from start of line to cursor */
1555− offset = -vc->state.x;
1556− count = vc->state.x + 1;
1557− break;
1558− case 2: /* erase whole line */
1559− offset = -vc->state.x;
1560− count = vc->vc_cols;
1561− break;
1562− default:
1563− return;
1544+ switch (vc->vc_par[0]) {
1545+ case CSI_K_CURSOR_TO_LINEEND:
1546+ offset = 0;
1547+ count = vc->vc_cols - vc->state.x;
1548+ break;
1549+ case CSI_K_LINESTART_TO_CURSOR:
1550+ offset = -vc->state.x;
1551+ count = vc->state.x + 1;
1552+ break;
1553+ case CSI_K_LINE:
1554+ offset = -vc->state.x;
1555+ count = vc->vc_cols;
1556+ break;
1557+ default:
1558+ return;
15641559 }
15651560 vc_uniscr_clear_line(vc, vc->state.x + offset, count);
15661561 scr_memsetw(start + offset, vc->vc_video_erase_char, 2 * count);
@@ -1569,20 +1564,15 @@ static void csi_K(struct vc_data *vc, int vpar) · 2 unmodified lines
15691564 do_update_region(vc, (unsigned long)(start + offset), count);
15701565 }
15711566
1572−/* erase the following vpar positions */
1573−static void csi_X(struct vc_data *vc, unsigned int vpar)
1567+/* erase the following count positions */
1568+static void csi_X(struct vc_data *vc)
15741569 { /* not vt100? */
1575− unsigned int count;
1576−
1577− if (!vpar)
1578− vpar++;
1579−
1580− count = min(vpar, vc->vc_cols - vc->state.x);
1570+ unsigned int count = clamp(vc->vc_par[0], 1, vc->vc_cols - vc->state.x);
15811571
15821572 vc_uniscr_clear_line(vc, vc->state.x, count);
15831573 scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count);
15841574 if (con_should_update(vc))
1585− vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, 1, count);
1575+ vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, count);
15861576 vc->vc_need_wrap = 0;
15871577 }
15881578
@@ -1598,7 +1588,7 @@ static void default_attr(struct vc_data *vc) · 9 unmodified lines
15981588
15991589 struct rgb { u8 r; u8 g; u8 b; };
16001590
1601−static void rgb_from_256(int i, struct rgb *c)
1591+static void rgb_from_256(unsigned int i, struct rgb *c)
16021592 {
16031593 if (i < 8) { /* Standard colours. */
16041594 c->r = i&1 ? 0xaa : 0x00;
@@ -1609,9 +1599,12 @@ static void rgb_from_256(int i, struct rgb *c) · 4 unmodified lines
16091599 c->g = i&2 ? 0xff : 0x55;
16101600 c->b = i&4 ? 0xff : 0x55;
16111601 } else if (i < 232) { /* 6x6x6 colour cube. */
1612− c->r = (i - 16) / 36 * 85 / 2;
1613− c->g = (i - 16) / 6 % 6 * 85 / 2;
1614− c->b = (i - 16) % 6 * 85 / 2;
1602+ i -= 16;
1603+ c->b = i % 6 * 255 / 6;
1604+ i /= 6;
1605+ c->g = i % 6 * 255 / 6;
1606+ i /= 6;
1607+ c->r = i * 255 / 6;
16151608 } else /* Grayscale ramp. */
16161609 c->r = c->g = c->b = i * 10 - 2312;
16171610 }
@@ -1681,6 +1674,39 @@ static int vc_t416_color(struct vc_data *vc, int i, · 63 unmodified lines
16811674 return i;
16821675 }
16831676
1677+enum {
1678+ CSI_m_DEFAULT = 0,
1679+ CSI_m_BOLD = 1,
1680+ CSI_m_HALF_BRIGHT = 2,
1681+ CSI_m_ITALIC = 3,
1682+ CSI_m_UNDERLINE = 4,
1683+ CSI_m_BLINK = 5,
1684+ CSI_m_REVERSE = 7,
1685+ CSI_m_PRI_FONT = 10,
1686+ CSI_m_ALT_FONT1 = 11,
1687+ CSI_m_ALT_FONT2 = 12,
1688+ CSI_m_DOUBLE_UNDERLINE = 21,
1689+ CSI_m_NORMAL_INTENSITY = 22,
1690+ CSI_m_NO_ITALIC = 23,
1691+ CSI_m_NO_UNDERLINE = 24,
1692+ CSI_m_NO_BLINK = 25,
1693+ CSI_m_NO_REVERSE = 27,
1694+ CSI_m_FG_COLOR_BEG = 30,
1695+ CSI_m_FG_COLOR_END = 37,
1696+ CSI_m_FG_COLOR = 38,
1697+ CSI_m_DEFAULT_FG_COLOR = 39,
1698+ CSI_m_BG_COLOR_BEG = 40,
1699+ CSI_m_BG_COLOR_END = 47,
1700+ CSI_m_BG_COLOR = 48,
1701+ CSI_m_DEFAULT_BG_COLOR = 49,
1702+ CSI_m_BRIGHT_FG_COLOR_BEG = 90,
1703+ CSI_m_BRIGHT_FG_COLOR_END = 97,
1704+ CSI_m_BRIGHT_FG_COLOR_OFF = CSI_m_BRIGHT_FG_COLOR_BEG - CSI_m_FG_COLOR_BEG,
1705+ CSI_m_BRIGHT_BG_COLOR_BEG = 100,
1706+ CSI_m_BRIGHT_BG_COLOR_END = 107,
1707+ CSI_m_BRIGHT_BG_COLOR_OFF = CSI_m_BRIGHT_BG_COLOR_BEG - CSI_m_BG_COLOR_BEG,
1708+};
1709+
16841710 /* console_lock is held */
16851711 static void csi_m(struct vc_data *vc)
16861712 {
@@ -1688,33 +1714,33 @@ static void csi_m(struct vc_data *vc) · 1 unmodified line
16881714
16891715 for (i = 0; i <= vc->vc_npar; i++)
16901716 switch (vc->vc_par[i]) {
1691− case 0: /* all attributes off */
1717+ case CSI_m_DEFAULT: /* all attributes off */
16921718 default_attr(vc);
16931719 break;
1694− case 1:
1720+ case CSI_m_BOLD:
16951721 vc->state.intensity = VCI_BOLD;
16961722 break;
1697− case 2:
1723+ case CSI_m_HALF_BRIGHT:
16981724 vc->state.intensity = VCI_HALF_BRIGHT;
16991725 break;
1700− case 3:
1726+ case CSI_m_ITALIC:
17011727 vc->state.italic = true;
17021728 break;
1703− case 21:
1729+ case CSI_m_DOUBLE_UNDERLINE:
17041730 /*
17051731 * No console drivers support double underline, so
17061732 * convert it to a single underline.
17071733 */
1708− case 4:
1734+ case CSI_m_UNDERLINE:
17091735 vc->state.underline = true;
17101736 break;
1711− case 5:
1737+ case CSI_m_BLINK:
17121738 vc->state.blink = true;
17131739 break;
1714− case 7:
1740+ case CSI_m_REVERSE:
17151741 vc->state.reverse = true;
17161742 break;
1717− case 10: /* ANSI X3.64-1979 (SCO-ish?)
1743+ case CSI_m_PRI_FONT: /* ANSI X3.64-1979 (SCO-ish?)
17181744 * Select primary font, don't display control chars if
17191745 * defined, don't set bit 8 on output.
17201746 */
@@ -1722,7 +1748,7 @@ static void csi_m(struct vc_data *vc) · 1 unmodified line
17221748 vc->vc_disp_ctrl = 0;
17231749 vc->vc_toggle_meta = 0;
17241750 break;
1725− case 11: /* ANSI X3.64-1979 (SCO-ish?)
1751+ case CSI_m_ALT_FONT1: /* ANSI X3.64-1979 (SCO-ish?)
17261752 * Select first alternate font, lets chars < 32 be
17271753 * displayed as ROM chars.
17281754 */
@@ -1730,7 +1756,7 @@ static void csi_m(struct vc_data *vc) · 1 unmodified line
17301756 vc->vc_disp_ctrl = 1;
17311757 vc->vc_toggle_meta = 0;
17321758 break;
1733− case 12: /* ANSI X3.64-1979 (SCO-ish?)
1759+ case CSI_m_ALT_FONT2: /* ANSI X3.64-1979 (SCO-ish?)
17341760 * Select second alternate font, toggle high bit
17351761 * before displaying as ROM char.
17361762 */
@@ -1738,47 +1764,51 @@ static void csi_m(struct vc_data *vc) · 1 unmodified line
17381764 vc->vc_disp_ctrl = 1;
17391765 vc->vc_toggle_meta = 1;
17401766 break;
1741− case 22:
1767+ case CSI_m_NORMAL_INTENSITY:
17421768 vc->state.intensity = VCI_NORMAL;
17431769 break;
1744− case 23:
1770+ case CSI_m_NO_ITALIC:
17451771 vc->state.italic = false;
17461772 break;
1747− case 24:
1773+ case CSI_m_NO_UNDERLINE:
17481774 vc->state.underline = false;
17491775 break;
1750− case 25:
1776+ case CSI_m_NO_BLINK:
17511777 vc->state.blink = false;
17521778 break;
1753− case 27:
1779+ case CSI_m_NO_REVERSE:
17541780 vc->state.reverse = false;
17551781 break;
1756− case 38:
1782+ case CSI_m_FG_COLOR:
17571783 i = vc_t416_color(vc, i, rgb_foreground);
17581784 break;
1759− case 48:
1785+ case CSI_m_BG_COLOR:
17601786 i = vc_t416_color(vc, i, rgb_background);
17611787 break;
1762− case 39:
1788+ case CSI_m_DEFAULT_FG_COLOR:
17631789 vc->state.color = (vc->vc_def_color & 0x0f) |
17641790 (vc->state.color & 0xf0);
17651791 break;
1766− case 49:
1792+ case CSI_m_DEFAULT_BG_COLOR:
17671793 vc->state.color = (vc->vc_def_color & 0xf0) |
17681794 (vc->state.color & 0x0f);
17691795 break;
1770− default:
1771− if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) {
1772− if (vc->vc_par[i] < 100)
1773− vc->state.intensity = VCI_BOLD;
1774− vc->vc_par[i] -= 60;
1775− }
1776− if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37)
1777− vc->state.color = color_table[vc->vc_par[i] - 30]
1778− | (vc->state.color & 0xf0);
1779− else if (vc->vc_par[i] >= 40 && vc->vc_par[i] <= 47)
1780− vc->state.color = (color_table[vc->vc_par[i] - 40] << 4)
1781− | (vc->state.color & 0x0f);
1796+ case CSI_m_BRIGHT_FG_COLOR_BEG ... CSI_m_BRIGHT_FG_COLOR_END:
1797+ vc->state.intensity = VCI_BOLD;
1798+ vc->vc_par[i] -= CSI_m_BRIGHT_FG_COLOR_OFF;
1799+ fallthrough;
1800+ case CSI_m_FG_COLOR_BEG ... CSI_m_FG_COLOR_END:
1801+ vc->vc_par[i] -= CSI_m_FG_COLOR_BEG;
1802+ vc->state.color = color_table[vc->vc_par[i]] |
1803+ (vc->state.color & 0xf0);
1804+ break;
1805+ case CSI_m_BRIGHT_BG_COLOR_BEG ... CSI_m_BRIGHT_BG_COLOR_END:
1806+ vc->vc_par[i] -= CSI_m_BRIGHT_BG_COLOR_OFF;
1807+ fallthrough;
1808+ case CSI_m_BG_COLOR_BEG ... CSI_m_BG_COLOR_END:
1809+ vc->vc_par[i] -= CSI_m_BG_COLOR_BEG;
1810+ vc->state.color = (color_table[vc->vc_par[i]] << 4) |
1811+ (vc->state.color & 0x0f);
17821812 break;
17831813 }
17841814 update_attr(vc);
@@ -1832,133 +1862,175 @@ int mouse_reporting(void) · 47 unmodified lines
18321862 return vc_cons[fg_console].d->vc_report_mouse;
18331863 }
18341864
1865+enum {
1866+ CSI_DEC_hl_CURSOR_KEYS = 1, /* CKM: cursor keys send ^[Ox/^[[x */
1867+ CSI_DEC_hl_132_COLUMNS = 3, /* COLM: 80/132 mode switch */
1868+ CSI_DEC_hl_REVERSE_VIDEO = 5, /* SCNM */
1869+ CSI_DEC_hl_ORIGIN_MODE = 6, /* OM: origin relative/absolute */
1870+ CSI_DEC_hl_AUTOWRAP = 7, /* AWM */
1871+ CSI_DEC_hl_AUTOREPEAT = 8, /* ARM */
1872+ CSI_DEC_hl_MOUSE_X10 = 9,
1873+ CSI_DEC_hl_SHOW_CURSOR = 25, /* TCEM */
1874+ CSI_DEC_hl_MOUSE_VT200 = 1000,
1875+};
1876+
18351877 /* console_lock is held */
1836−static void set_mode(struct vc_data *vc, int on_off)
1878+static void csi_DEC_hl(struct vc_data *vc, bool on_off)
18371879 {
1838− int i;
1880+ unsigned int i;
18391881
18401882 for (i = 0; i <= vc->vc_npar; i++)
1841− if (vc->vc_priv == EPdec) {
1842− switch(vc->vc_par[i]) { /* DEC private modes set/reset */
1843− case 1: /* Cursor keys send ^[Ox/^[[x */
1844− if (on_off)
1845− set_kbd(vc, decckm);
1846− else
1847− clr_kbd(vc, decckm);
1848− break;
1849− case 3: /* 80/132 mode switch unimplemented */
1883+ switch (vc->vc_par[i]) {
1884+ case CSI_DEC_hl_CURSOR_KEYS:
1885+ if (on_off)
1886+ set_kbd(vc, decckm);
1887+ else
1888+ clr_kbd(vc, decckm);
1889+ break;
1890+ case CSI_DEC_hl_132_COLUMNS: /* unimplemented */
18501891 #if 0
1851− vc_resize(deccolm ? 132 : 80, vc->vc_rows);
1852− /* this alone does not suffice; some user mode
1853− utility has to change the hardware regs */
1892+ vc_resize(deccolm ? 132 : 80, vc->vc_rows);
1893+ /* this alone does not suffice; some user mode
1894+ utility has to change the hardware regs */
18541895 #endif
1855− break;
1856− case 5: /* Inverted screen on/off */
1857− if (vc->vc_decscnm != on_off) {
1858− vc->vc_decscnm = on_off;
1859− invert_screen(vc, 0,
1860− vc->vc_screenbuf_size,
1861− false);
1862− update_attr(vc);
1863− }
1864− break;
1865− case 6: /* Origin relative/absolute */
1866− vc->vc_decom = on_off;
1867− gotoxay(vc, 0, 0);
1868− break;
1869− case 7: /* Autowrap on/off */
1870− vc->vc_decawm = on_off;
1871− break;
1872− case 8: /* Autorepeat on/off */
1873− if (on_off)
1874− set_kbd(vc, decarm);
1875− else
1876− clr_kbd(vc, decarm);
1877− break;
1878− case 9:
1879− vc->vc_report_mouse = on_off ? 1 : 0;
1880− break;
1881− case 25: /* Cursor on/off */
1882− vc->vc_deccm = on_off;
1883− break;
1884− case 1000:
1885− vc->vc_report_mouse = on_off ? 2 : 0;
1886− break;
1887− }
1888− } else {
1889− switch(vc->vc_par[i]) { /* ANSI modes set/reset */
1890− case 3: /* Monitor (display ctrls) */
1891− vc->vc_disp_ctrl = on_off;
1892− break;
1893− case 4: /* Insert Mode on/off */
1894− vc->vc_decim = on_off;
1895− break;
1896− case 20: /* Lf, Enter == CrLf/Lf */
1897− if (on_off)
1898− set_kbd(vc, lnm);
1899− else
1900− clr_kbd(vc, lnm);
1901− break;
1896+ break;
1897+ case CSI_DEC_hl_REVERSE_VIDEO:
1898+ if (vc->vc_decscnm != on_off) {
1899+ vc->vc_decscnm = on_off;
1900+ invert_screen(vc, 0, vc->vc_screenbuf_size,
1901+ false);
1902+ update_attr(vc);
19021903 }
1904+ break;
1905+ case CSI_DEC_hl_ORIGIN_MODE:
1906+ vc->vc_decom = on_off;
1907+ gotoxay(vc, 0, 0);
1908+ break;
1909+ case CSI_DEC_hl_AUTOWRAP:
1910+ vc->vc_decawm = on_off;
1911+ break;
1912+ case CSI_DEC_hl_AUTOREPEAT:
1913+ if (on_off)
1914+ set_kbd(vc, decarm);
1915+ else
1916+ clr_kbd(vc, decarm);
1917+ break;
1918+ case CSI_DEC_hl_MOUSE_X10:
1919+ vc->vc_report_mouse = on_off ? 1 : 0;
1920+ break;
1921+ case CSI_DEC_hl_SHOW_CURSOR:
1922+ vc->vc_deccm = on_off;
1923+ break;
1924+ case CSI_DEC_hl_MOUSE_VT200:
1925+ vc->vc_report_mouse = on_off ? 2 : 0;
1926+ break;
19031927 }
19041928 }
19051929
1930+enum {
1931+ CSI_hl_DISPLAY_CTRL = 3, /* handle ansi control chars */
1932+ CSI_hl_INSERT = 4, /* IRM: insert/replace */
1933+ CSI_hl_AUTO_NL = 20, /* LNM: Enter == CrLf/Lf */
1934+};
1935+
19061936 /* console_lock is held */
1907−static void setterm_command(struct vc_data *vc)
1937+static void csi_hl(struct vc_data *vc, bool on_off)
1938+{
1939+ unsigned int i;
1940+
1941+ for (i = 0; i <= vc->vc_npar; i++)
1942+ switch (vc->vc_par[i]) { /* ANSI modes set/reset */
1943+ case CSI_hl_DISPLAY_CTRL:
1944+ vc->vc_disp_ctrl = on_off;
1945+ break;
1946+ case CSI_hl_INSERT:
1947+ vc->vc_decim = on_off;
1948+ break;
1949+ case CSI_hl_AUTO_NL:
1950+ if (on_off)
1951+ set_kbd(vc, lnm);
1952+ else
1953+ clr_kbd(vc, lnm);
1954+ break;
1955+ }
1956+}
1957+
1958+enum CSI_right_square_bracket {
1959+ CSI_RSB_COLOR_FOR_UNDERLINE = 1,
1960+ CSI_RSB_COLOR_FOR_HALF_BRIGHT = 2,
1961+ CSI_RSB_MAKE_CUR_COLOR_DEFAULT = 8,
1962+ CSI_RSB_BLANKING_INTERVAL = 9,
1963+ CSI_RSB_BELL_FREQUENCY = 10,
1964+ CSI_RSB_BELL_DURATION = 11,
1965+ CSI_RSB_BRING_CONSOLE_TO_FRONT = 12,
1966+ CSI_RSB_UNBLANK = 13,
1967+ CSI_RSB_VESA_OFF_INTERVAL = 14,
1968+ CSI_RSB_BRING_PREV_CONSOLE_TO_FRONT = 15,
1969+ CSI_RSB_CURSOR_BLINK_INTERVAL = 16,
1970+};
1971+
1972+/*
1973+ * csi_RSB - csi+] (Right Square Bracket) handler
1974+ *
1975+ * These are linux console private sequences.
1976+ *
1977+ * console_lock is held
1978+ */
1979+static void csi_RSB(struct vc_data *vc)
19081980 {
19091981 switch (vc->vc_par[0]) {
1910− case 1: /* set color for underline mode */
1982+ case CSI_RSB_COLOR_FOR_UNDERLINE:
19111983 if (vc->vc_can_do_color && vc->vc_par[1] < 16) {
19121984 vc->vc_ulcolor = color_table[vc->vc_par[1]];
19131985 if (vc->state.underline)
19141986 update_attr(vc);
19151987 }
19161988 break;
1917− case 2: /* set color for half intensity mode */
1989+ case CSI_RSB_COLOR_FOR_HALF_BRIGHT:
19181990 if (vc->vc_can_do_color && vc->vc_par[1] < 16) {
19191991 vc->vc_halfcolor = color_table[vc->vc_par[1]];
19201992 if (vc->state.intensity == VCI_HALF_BRIGHT)
19211993 update_attr(vc);
19221994 }
19231995 break;
1924− case 8: /* store colors as defaults */
1996+ case CSI_RSB_MAKE_CUR_COLOR_DEFAULT:
19251997 vc->vc_def_color = vc->vc_attr;
19261998 if (vc->vc_hi_font_mask == 0x100)
19271999 vc->vc_def_color >>= 1;
19282000 default_attr(vc);
19292001 update_attr(vc);
19302002 break;
1931− case 9: /* set blanking interval */
2003+ case CSI_RSB_BLANKING_INTERVAL:
19322004 blankinterval = min(vc->vc_par[1], 60U) * 60;
19332005 poke_blanked_console();
19342006 break;
1935− case 10: /* set bell frequency in Hz */
2007+ case CSI_RSB_BELL_FREQUENCY:
19362008 if (vc->vc_npar >= 1)
19372009 vc->vc_bell_pitch = vc->vc_par[1];
19382010 else
19392011 vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
19402012 break;
1941− case 11: /* set bell duration in msec */
2013+ case CSI_RSB_BELL_DURATION:
19422014 if (vc->vc_npar >= 1)
19432015 vc->vc_bell_duration = (vc->vc_par[1] < 2000) ?
19442016 msecs_to_jiffies(vc->vc_par[1]) : 0;
19452017 else
19462018 vc->vc_bell_duration = DEFAULT_BELL_DURATION;
19472019 break;
1948− case 12: /* bring specified console to the front */
2020+ case CSI_RSB_BRING_CONSOLE_TO_FRONT:
19492021 if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1))
19502022 set_console(vc->vc_par[1] - 1);
19512023 break;
1952− case 13: /* unblank the screen */
2024+ case CSI_RSB_UNBLANK:
19532025 poke_blanked_console();
19542026 break;
1955− case 14: /* set vesa powerdown interval */
2027+ case CSI_RSB_VESA_OFF_INTERVAL:
19562028 vesa_off_interval = min(vc->vc_par[1], 60U) * 60 * HZ;
19572029 break;
1958− case 15: /* activate the previous console */
2030+ case CSI_RSB_BRING_PREV_CONSOLE_TO_FRONT:
19592031 set_console(last_console);
19602032 break;
1961− case 16: /* set cursor blink duration in msec */
2033+ case CSI_RSB_CURSOR_BLINK_INTERVAL:
19622034 if (vc->vc_npar >= 1 && vc->vc_par[1] >= 50 &&
19632035 vc->vc_par[1] <= USHRT_MAX)
19642036 vc->vc_cur_blink_ms = vc->vc_par[1];
@@ -1971,41 +2043,32 @@ static void setterm_command(struct vc_data *vc) · 6 unmodified lines
19712043 /* console_lock is held */
19722044 static void csi_at(struct vc_data *vc, unsigned int nr)
19732045 {
1974− if (nr > vc->vc_cols - vc->state.x)
1975− nr = vc->vc_cols - vc->state.x;
1976− else if (!nr)
1977− nr = 1;
2046+ nr = clamp(nr, 1, vc->vc_cols - vc->state.x);
19782047 insert_char(vc, nr);
19792048 }
19802049
19812050 /* console_lock is held */
1982−static void csi_L(struct vc_data *vc, unsigned int nr)
2051+static void csi_L(struct vc_data *vc)
19832052 {
1984− if (nr > vc->vc_rows - vc->state.y)
1985− nr = vc->vc_rows - vc->state.y;
1986− else if (!nr)
1987− nr = 1;
2053+ unsigned int nr = clamp(vc->vc_par[0], 1, vc->vc_rows - vc->state.y);
2054+
19882055 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_DOWN, nr);
19892056 vc->vc_need_wrap = 0;
19902057 }
19912058
19922059 /* console_lock is held */
1993−static void csi_P(struct vc_data *vc, unsigned int nr)
2060+static void csi_P(struct vc_data *vc)
19942061 {
1995− if (nr > vc->vc_cols - vc->state.x)
1996− nr = vc->vc_cols - vc->state.x;
1997− else if (!nr)
1998− nr = 1;
2062+ unsigned int nr = clamp(vc->vc_par[0], 1, vc->vc_cols - vc->state.x);
2063+
19992064 delete_char(vc, nr);
20002065 }
20012066
20022067 /* console_lock is held */
2003−static void csi_M(struct vc_data *vc, unsigned int nr)
2068+static void csi_M(struct vc_data *vc)
20042069 {
2005− if (nr > vc->vc_rows - vc->state.y)
2006− nr = vc->vc_rows - vc->state.y;
2007− else if (!nr)
2008− nr=1;
2070+ unsigned int nr = clamp(vc->vc_par[0], 1, vc->vc_rows - vc->state.y);
2071+
20092072 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_UP, nr);
20102073 vc->vc_need_wrap = 0;
20112074 }
@@ -2028,9 +2091,48 @@ static void restore_cur(struct vc_data *vc) · 16 unmodified lines
20282091 vc->vc_need_wrap = 0;
20292092 }
20302093
2031−enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey,
2032− EShash, ESsetG0, ESsetG1, ESpercent, EScsiignore, ESnonstd,
2033− ESpalette, ESosc, ESapc, ESpm, ESdcs };
2094+/**
2095+ * enum vc_ctl_state - control characters state of a vt
2096+ *
2097+ * @ESnormal: initial state, no control characters parsed
2098+ * @ESesc: ESC parsed
2099+ * @ESsquare: CSI parsed -- modifiers/parameters/ctrl chars expected
2100+ * @ESgetpars: CSI parsed -- parameters/ctrl chars expected
2101+ * @ESfunckey: CSI [ parsed
2102+ * @EShash: ESC # parsed
2103+ * @ESsetG0: ESC ( parsed
2104+ * @ESsetG1: ESC ) parsed
2105+ * @ESpercent: ESC % parsed
2106+ * @EScsiignore: CSI [0x20-0x3f] parsed
2107+ * @ESnonstd: OSC parsed
2108+ * @ESpalette: OSC P parsed
2109+ * @ESosc: OSC [0-9] parsed
2110+ * @ESANSI_first: first state for ignoring ansi control sequences
2111+ * @ESapc: ESC _ parsed
2112+ * @ESpm: ESC ^ parsed
2113+ * @ESdcs: ESC P parsed
2114+ * @ESANSI_last: last state for ignoring ansi control sequences
2115+ */
2116+enum vc_ctl_state {
2117+ ESnormal,
2118+ ESesc,
2119+ ESsquare,
2120+ ESgetpars,
2121+ ESfunckey,
2122+ EShash,
2123+ ESsetG0,
2124+ ESsetG1,
2125+ ESpercent,
2126+ EScsiignore,
2127+ ESnonstd,
2128+ ESpalette,
2129+ ESosc,
2130+ ESANSI_first = ESosc,
2131+ ESapc,
2132+ ESpm,
2133+ ESdcs,
2134+ ESANSI_last = ESdcs,
2135+};
20342136
20352137 /* console_lock is held (except via vc_init()) */
20362138 static void reset_terminal(struct vc_data *vc, int do_clear)
@@ -2078,10 +2180,10 @@ static void reset_terminal(struct vc_data *vc, int do_clear) · 41 unmodified lines
20782180 gotoxy(vc, 0, 0);
20792181 save_cur(vc);
20802182 if (do_clear)
2081− csi_J(vc, 2);
2183+ csi_J(vc, CSI_J_VISIBLE);
20822184 }
20832185
2084−static void vc_setGx(struct vc_data *vc, unsigned int which, int c)
2186+static void vc_setGx(struct vc_data *vc, unsigned int which, u8 c)
20852187 {
20862188 unsigned char *charset = &vc->state.Gx_charset[which];
20872189
@@ -2104,36 +2206,54 @@ static void vc_setGx(struct vc_data *vc, unsigned int which, int c) · 16 unmodified lines
21042206 vc->vc_translate = set_translate(*charset, vc);
21052207 }
21062208
2107−/* is this state an ANSI control string? */
2108−static bool ansi_control_string(unsigned int state)
2209+static bool ansi_control_string(enum vc_ctl_state state)
21092210 {
2110− if (state == ESosc || state == ESapc || state == ESpm || state == ESdcs)
2111− return true;
2112− return false;
2211+ return state >= ESANSI_first && state <= ESANSI_last;
21132212 }
21142213
2115−/* console_lock is held */
2116−static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
2214+enum {
2215+ ASCII_NULL = 0,
2216+ ASCII_BELL = 7,
2217+ ASCII_BACKSPACE = 8,
2218+ ASCII_IGNORE_FIRST = ASCII_BACKSPACE,
2219+ ASCII_HTAB = 9,
2220+ ASCII_LINEFEED = 10,
2221+ ASCII_VTAB = 11,
2222+ ASCII_FORMFEED = 12,
2223+ ASCII_CAR_RET = 13,
2224+ ASCII_IGNORE_LAST = ASCII_CAR_RET,
2225+ ASCII_SHIFTOUT = 14,
2226+ ASCII_SHIFTIN = 15,
2227+ ASCII_CANCEL = 24,
2228+ ASCII_SUBSTITUTE = 26,
2229+ ASCII_ESCAPE = 27,
2230+ ASCII_CSI_IGNORE_FIRST = ' ', /* 0x2x, 0x3a and 0x3c - 0x3f */
2231+ ASCII_CSI_IGNORE_LAST = '?',
2232+ ASCII_DEL = 127,
2233+ ASCII_EXT_CSI = 128 + ASCII_ESCAPE,
2234+};
2235+
2236+/*
2237+ * Handle ascii characters in control sequences and change states accordingly.
2238+ * E.g. ESC sets the state of vc to ESesc.
2239+ *
2240+ * Returns: true if @c handled.
2241+ */
2242+static bool handle_ascii(struct tty_struct *tty, struct vc_data *vc, u8 c)
21172243 {
2118− /*
2119− * Control characters can be used in the _middle_
2120− * of an escape sequence, aside from ANSI control strings.
2121− */
2122− if (ansi_control_string(vc->vc_state) && c >= 8 && c <= 13)
2123− return;
21242244 switch (c) {
2125− case 0:
2126− return;
2127− case 7:
2245+ case ASCII_NULL:
2246+ return true;
2247+ case ASCII_BELL:
21282248 if (ansi_control_string(vc->vc_state))
21292249 vc->vc_state = ESnormal;
21302250 else if (vc->vc_bell_duration)
21312251 kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration);
2132− return;
2133− case 8:
2252+ return true;
2253+ case ASCII_BACKSPACE:
21342254 bs(vc);
2135− return;
2136− case 9:
2255+ return true;
2256+ case ASCII_HTAB:
21372257 vc->vc_pos -= (vc->state.x << 1);
21382258
21392259 vc->state.x = find_next_bit(vc->vc_tab_stop,
@@ -2144,119 +2264,330 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 4 unmodified lines
21442264
21452265 vc->vc_pos += (vc->state.x << 1);
21462266 notify_write(vc, '\t');
2147− return;
2148− case 10: case 11: case 12:
2267+ return true;
2268+ case ASCII_LINEFEED:
2269+ case ASCII_VTAB:
2270+ case ASCII_FORMFEED:
21492271 lf(vc);
21502272 if (!is_kbd(vc, lnm))
2151− return;
2273+ return true;
21522274 fallthrough;
2153− case 13:
2275+ case ASCII_CAR_RET:
21542276 cr(vc);
2155− return;
2156− case 14:
2277+ return true;
2278+ case ASCII_SHIFTOUT:
21572279 vc->state.charset = 1;
21582280 vc->vc_translate = set_translate(vc->state.Gx_charset[1], vc);
21592281 vc->vc_disp_ctrl = 1;
2160− return;
2161− case 15:
2282+ return true;
2283+ case ASCII_SHIFTIN:
21622284 vc->state.charset = 0;
21632285 vc->vc_translate = set_translate(vc->state.Gx_charset[0], vc);
21642286 vc->vc_disp_ctrl = 0;
2165− return;
2166− case 24: case 26:
2287+ return true;
2288+ case ASCII_CANCEL:
2289+ case ASCII_SUBSTITUTE:
21672290 vc->vc_state = ESnormal;
2168− return;
2169− case 27:
2291+ return true;
2292+ case ASCII_ESCAPE:
21702293 vc->vc_state = ESesc;
2171− return;
2172− case 127:
2294+ return true;
2295+ case ASCII_DEL:
21732296 del(vc);
2174− return;
2175− case 128+27:
2297+ return true;
2298+ case ASCII_EXT_CSI:
21762299 vc->vc_state = ESsquare;
2177− return;
2300+ return true;
21782301 }
2179− switch(vc->vc_state) {
2180− case ESesc:
2181− vc->vc_state = ESnormal;
2182− switch (c) {
2183− case '[':
2184− vc->vc_state = ESsquare;
2185− return;
2186− case ']':
2187− vc->vc_state = ESnonstd;
2188− return;
2189− case '_':
2190− vc->vc_state = ESapc;
2191− return;
2192− case '^':
2193− vc->vc_state = ESpm;
2194− return;
2195− case '%':
2196− vc->vc_state = ESpercent;
2197− return;
2198− case 'E':
2199− cr(vc);
2200− lf(vc);
2201− return;
2202− case 'M':
2203− ri(vc);
2204− return;
2205− case 'D':
2206− lf(vc);
2207− return;
2208− case 'H':
2209− if (vc->state.x < VC_TABSTOPS_COUNT)
2210− set_bit(vc->state.x, vc->vc_tab_stop);
2211− return;
2212− case 'P':
2213− vc->vc_state = ESdcs;
2214− return;
2215− case 'Z':
2302+
2303+ return false;
2304+}
2305+
2306+/*
2307+ * Handle a character (@c) following an ESC (when @vc is in the ESesc state).
2308+ * E.g. previous ESC with @c == '[' here yields the ESsquare state (that is:
2309+ * CSI).
2310+ */
2311+static void handle_esc(struct tty_struct *tty, struct vc_data *vc, u8 c)
2312+{
2313+ vc->vc_state = ESnormal;
2314+ switch (c) {
2315+ case '[':
2316+ vc->vc_state = ESsquare;
2317+ break;
2318+ case ']':
2319+ vc->vc_state = ESnonstd;
2320+ break;
2321+ case '_':
2322+ vc->vc_state = ESapc;
2323+ break;
2324+ case '^':
2325+ vc->vc_state = ESpm;
2326+ break;
2327+ case '%':
2328+ vc->vc_state = ESpercent;
2329+ break;
2330+ case 'E':
2331+ cr(vc);
2332+ lf(vc);
2333+ break;
2334+ case 'M':
2335+ ri(vc);
2336+ break;
2337+ case 'D':
2338+ lf(vc);
2339+ break;
2340+ case 'H':
2341+ if (vc->state.x < VC_TABSTOPS_COUNT)
2342+ set_bit(vc->state.x, vc->vc_tab_stop);
2343+ break;
2344+ case 'P':
2345+ vc->vc_state = ESdcs;
2346+ break;
2347+ case 'Z':
2348+ respond_ID(tty);
2349+ break;
2350+ case '7':
2351+ save_cur(vc);
2352+ break;
2353+ case '8':
2354+ restore_cur(vc);
2355+ break;
2356+ case '(':
2357+ vc->vc_state = ESsetG0;
2358+ break;
2359+ case ')':
2360+ vc->vc_state = ESsetG1;
2361+ break;
2362+ case '#':
2363+ vc->vc_state = EShash;
2364+ break;
2365+ case 'c':
2366+ reset_terminal(vc, 1);
2367+ break;
2368+ case '>': /* Numeric keypad */
2369+ clr_kbd(vc, kbdapplic);
2370+ break;
2371+ case '=': /* Appl. keypad */
2372+ set_kbd(vc, kbdapplic);
2373+ break;
2374+ }
2375+}
2376+
2377+/*
2378+ * Handle special DEC control sequences ("ESC [ ? parameters char"). Parameters
2379+ * are in @vc->vc_par and the char is in @c here.
2380+ */
2381+static void csi_DEC(struct tty_struct *tty, struct vc_data *vc, u8 c)
2382+{
2383+ switch (c) {
2384+ case 'h':
2385+ csi_DEC_hl(vc, true);
2386+ break;
2387+ case 'l':
2388+ csi_DEC_hl(vc, false);
2389+ break;
2390+ case 'c':
2391+ if (vc->vc_par[0])
2392+ vc->vc_cursor_type = CUR_MAKE(vc->vc_par[0],
2393+ vc->vc_par[1],
2394+ vc->vc_par[2]);
2395+ else
2396+ vc->vc_cursor_type = cur_default;
2397+ break;
2398+ case 'm':
2399+ clear_selection();
2400+ if (vc->vc_par[0])
2401+ vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1];
2402+ else
2403+ vc->vc_complement_mask = vc->vc_s_complement_mask;
2404+ break;
2405+ case 'n':
2406+ if (vc->vc_par[0] == 5)
2407+ status_report(tty);
2408+ else if (vc->vc_par[0] == 6)
2409+ cursor_report(vc, tty);
2410+ break;
2411+ }
2412+}
2413+
2414+/*
2415+ * Handle Control Sequence Introducer control characters. That is
2416+ * "ESC [ parameters char". Parameters are in @vc->vc_par and the char is in
2417+ * @c here.
2418+ */
2419+static void csi_ECMA(struct tty_struct *tty, struct vc_data *vc, u8 c)
2420+{
2421+ switch (c) {
2422+ case 'G':
2423+ case '`':
2424+ if (vc->vc_par[0])
2425+ vc->vc_par[0]--;
2426+ gotoxy(vc, vc->vc_par[0], vc->state.y);
2427+ break;
2428+ case 'A':
2429+ if (!vc->vc_par[0])
2430+ vc->vc_par[0]++;
2431+ gotoxy(vc, vc->state.x, vc->state.y - vc->vc_par[0]);
2432+ break;
2433+ case 'B':
2434+ case 'e':
2435+ if (!vc->vc_par[0])
2436+ vc->vc_par[0]++;
2437+ gotoxy(vc, vc->state.x, vc->state.y + vc->vc_par[0]);
2438+ break;
2439+ case 'C':
2440+ case 'a':
2441+ if (!vc->vc_par[0])
2442+ vc->vc_par[0]++;
2443+ gotoxy(vc, vc->state.x + vc->vc_par[0], vc->state.y);
2444+ break;
2445+ case 'D':
2446+ if (!vc->vc_par[0])
2447+ vc->vc_par[0]++;
2448+ gotoxy(vc, vc->state.x - vc->vc_par[0], vc->state.y);
2449+ break;
2450+ case 'E':
2451+ if (!vc->vc_par[0])
2452+ vc->vc_par[0]++;
2453+ gotoxy(vc, 0, vc->state.y + vc->vc_par[0]);
2454+ break;
2455+ case 'F':
2456+ if (!vc->vc_par[0])
2457+ vc->vc_par[0]++;
2458+ gotoxy(vc, 0, vc->state.y - vc->vc_par[0]);
2459+ break;
2460+ case 'd':
2461+ if (vc->vc_par[0])
2462+ vc->vc_par[0]--;
2463+ gotoxay(vc, vc->state.x ,vc->vc_par[0]);
2464+ break;
2465+ case 'H':
2466+ case 'f':
2467+ if (vc->vc_par[0])
2468+ vc->vc_par[0]--;
2469+ if (vc->vc_par[1])
2470+ vc->vc_par[1]--;
2471+ gotoxay(vc, vc->vc_par[1], vc->vc_par[0]);
2472+ break;
2473+ case 'J':
2474+ csi_J(vc, vc->vc_par[0]);
2475+ break;
2476+ case 'K':
2477+ csi_K(vc);
2478+ break;
2479+ case 'L':
2480+ csi_L(vc);
2481+ break;
2482+ case 'M':
2483+ csi_M(vc);
2484+ break;
2485+ case 'P':
2486+ csi_P(vc);
2487+ break;
2488+ case 'c':
2489+ if (!vc->vc_par[0])
22162490 respond_ID(tty);
2217− return;
2218− case '7':
2219− save_cur(vc);
2220− return;
2221− case '8':
2222− restore_cur(vc);
2223− return;
2224− case '(':
2225− vc->vc_state = ESsetG0;
2226− return;
2227− case ')':
2228− vc->vc_state = ESsetG1;
2229− return;
2230− case '#':
2231− vc->vc_state = EShash;
2232− return;
2233− case 'c':
2234− reset_terminal(vc, 1);
2235− return;
2236− case '>': /* Numeric keypad */
2237− clr_kbd(vc, kbdapplic);
2238− return;
2239− case '=': /* Appl. keypad */
2240− set_kbd(vc, kbdapplic);
2241− return;
2491+ break;
2492+ case 'g':
2493+ if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT)
2494+ set_bit(vc->state.x, vc->vc_tab_stop);
2495+ else if (vc->vc_par[0] == 3)
2496+ bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
2497+ break;
2498+ case 'h':
2499+ csi_hl(vc, true);
2500+ break;
2501+ case 'l':
2502+ csi_hl(vc, false);
2503+ break;
2504+ case 'm':
2505+ csi_m(vc);
2506+ break;
2507+ case 'n':
2508+ if (vc->vc_par[0] == 5)
2509+ status_report(tty);
2510+ else if (vc->vc_par[0] == 6)
2511+ cursor_report(vc, tty);
2512+ break;
2513+ case 'q': /* DECLL - but only 3 leds */
2514+ /* map 0,1,2,3 to 0,1,2,4 */
2515+ if (vc->vc_par[0] < 4)
2516+ vt_set_led_state(vc->vc_num,
2517+ (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4);
2518+ break;
2519+ case 'r':
2520+ if (!vc->vc_par[0])
2521+ vc->vc_par[0]++;
2522+ if (!vc->vc_par[1])
2523+ vc->vc_par[1] = vc->vc_rows;
2524+ /* Minimum allowed region is 2 lines */
2525+ if (vc->vc_par[0] < vc->vc_par[1] &&
2526+ vc->vc_par[1] <= vc->vc_rows) {
2527+ vc->vc_top = vc->vc_par[0] - 1;
2528+ vc->vc_bottom = vc->vc_par[1];
2529+ gotoxay(vc, 0, 0);
22422530 }
2531+ break;
2532+ case 's':
2533+ save_cur(vc);
2534+ break;
2535+ case 'u':
2536+ restore_cur(vc);
2537+ break;
2538+ case 'X':
2539+ csi_X(vc);
2540+ break;
2541+ case '@':
2542+ csi_at(vc, vc->vc_par[0]);
2543+ break;
2544+ case ']':
2545+ csi_RSB(vc);
2546+ break;
2547+ }
2548+
2549+}
2550+
2551+static void vc_reset_params(struct vc_data *vc)
2552+{
2553+ memset(vc->vc_par, 0, sizeof(vc->vc_par));
2554+ vc->vc_npar = 0;
2555+}
2556+
2557+/* console_lock is held */
2558+static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
2559+{
2560+ /*
2561+ * Control characters can be used in the _middle_
2562+ * of an escape sequence, aside from ANSI control strings.
2563+ */
2564+ if (ansi_control_string(vc->vc_state) && c >= ASCII_IGNORE_FIRST &&
2565+ c <= ASCII_IGNORE_LAST)
2566+ return;
2567+
2568+ if (handle_ascii(tty, vc, c))
2569+ return;
2570+
2571+ switch(vc->vc_state) {
2572+ case ESesc: /* ESC */
2573+ handle_esc(tty, vc, c);
22432574 return;
2244− case ESnonstd:
2245− if (c=='P') { /* palette escape sequence */
2246− for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
2247− vc->vc_par[vc->vc_npar] = 0;
2248− vc->vc_npar = 0;
2575+ case ESnonstd: /* ESC ] aka OSC */
2576+ switch (c) {
2577+ case 'P': /* palette escape sequence */
2578+ vc_reset_params(vc);
22492579 vc->vc_state = ESpalette;
22502580 return;
2251− } else if (c=='R') { /* reset palette */
2581+ case 'R': /* reset palette */
22522582 reset_palette(vc);
2253− vc->vc_state = ESnormal;
2254− } else if (c>='0' && c<='9')
2583+ break;
2584+ case '0' ... '9':
22552585 vc->vc_state = ESosc;
2256− else
2257− vc->vc_state = ESnormal;
2586+ return;
2587+ }
2588+ vc->vc_state = ESnormal;
22582589 return;
2259− case ESpalette:
2590+ case ESpalette: /* ESC ] P aka OSC P */
22602591 if (isxdigit(c)) {
22612592 vc->vc_par[vc->vc_npar++] = hex_to_bin(c);
22622593 if (vc->vc_npar == 7) {
@@ -2273,16 +2604,14 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 10 unmodified lines
22732604 } else
22742605 vc->vc_state = ESnormal;
22752606 return;
2276− case ESsquare:
2277− for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
2278− vc->vc_par[vc->vc_npar] = 0;
2279− vc->vc_npar = 0;
2607+ case ESsquare: /* ESC [ aka CSI, parameters or modifiers expected */
2608+ vc_reset_params(vc);
2609+
22802610 vc->vc_state = ESgetpars;
2281− if (c == '[') { /* Function key */
2282− vc->vc_state=ESfunckey;
2283− return;
2284− }
22852611 switch (c) {
2612+ case '[': /* Function key */
2613+ vc->vc_state = ESfunckey;
2614+ return;
22862615 case '?':
22872616 vc->vc_priv = EPdec;
22882617 return;
@@ -2298,182 +2627,44 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 9 unmodified lines
22982627 }
22992628 vc->vc_priv = EPecma;
23002629 fallthrough;
2301− case ESgetpars:
2302− if (c == ';' && vc->vc_npar < NPAR - 1) {
2303− vc->vc_npar++;
2304− return;
2305− } else if (c>='0' && c<='9') {
2630+ case ESgetpars: /* ESC [ aka CSI, parameters expected */
2631+ switch (c) {
2632+ case ';':
2633+ if (vc->vc_npar < NPAR - 1) {
2634+ vc->vc_npar++;
2635+ return;
2636+ }
2637+ break;
2638+ case '0' ... '9':
23062639 vc->vc_par[vc->vc_npar] *= 10;
23072640 vc->vc_par[vc->vc_npar] += c - '0';
23082641 return;
23092642 }
2310− if (c >= 0x20 && c <= 0x3f) { /* 0x2x, 0x3a and 0x3c - 0x3f */
2643+ if (c >= ASCII_CSI_IGNORE_FIRST && c <= ASCII_CSI_IGNORE_LAST) {
23112644 vc->vc_state = EScsiignore;
23122645 return;
23132646 }
2647+
2648+ /* parameters done, handle the control char @c */
2649+
23142650 vc->vc_state = ESnormal;
2315− switch(c) {
2316− case 'h':
2317− if (vc->vc_priv <= EPdec)
2318− set_mode(vc, 1);
2319− return;
2320− case 'l':
2321− if (vc->vc_priv <= EPdec)
2322− set_mode(vc, 0);
2323− return;
2324− case 'c':
2325− if (vc->vc_priv == EPdec) {
2326− if (vc->vc_par[0])
2327− vc->vc_cursor_type =
2328− CUR_MAKE(vc->vc_par[0],
2329− vc->vc_par[1],
2330− vc->vc_par[2]);
2331− else
2332− vc->vc_cursor_type = cur_default;
2333− return;
2334− }
2335− break;
2336− case 'm':
2337− if (vc->vc_priv == EPdec) {
2338− clear_selection();
2339− if (vc->vc_par[0])
2340− vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1];
2341− else
2342− vc->vc_complement_mask = vc->vc_s_complement_mask;
2343− return;
2344− }
2345− break;
2346− case 'n':
2347− if (vc->vc_priv == EPecma) {
2348− if (vc->vc_par[0] == 5)
2349− status_report(tty);
2350− else if (vc->vc_par[0] == 6)
2351− cursor_report(vc, tty);
2352− }
2353− return;
2354− }
2355− if (vc->vc_priv != EPecma) {
2356− vc->vc_priv = EPecma;
2357− return;
2358− }
2359− switch(c) {
2360− case 'G': case '`':
2361− if (vc->vc_par[0])
2362− vc->vc_par[0]--;
2363− gotoxy(vc, vc->vc_par[0], vc->state.y);
2364− return;
2365− case 'A':
2366− if (!vc->vc_par[0])
2367− vc->vc_par[0]++;
2368− gotoxy(vc, vc->state.x, vc->state.y - vc->vc_par[0]);
2369− return;
2370− case 'B': case 'e':
2371− if (!vc->vc_par[0])
2372− vc->vc_par[0]++;
2373− gotoxy(vc, vc->state.x, vc->state.y + vc->vc_par[0]);
2374− return;
2375− case 'C': case 'a':
2376− if (!vc->vc_par[0])
2377− vc->vc_par[0]++;
2378− gotoxy(vc, vc->state.x + vc->vc_par[0], vc->state.y);
2379− return;
2380− case 'D':
2381− if (!vc->vc_par[0])
2382− vc->vc_par[0]++;
2383− gotoxy(vc, vc->state.x - vc->vc_par[0], vc->state.y);
2384− return;
2385− case 'E':
2386− if (!vc->vc_par[0])
2387− vc->vc_par[0]++;
2388− gotoxy(vc, 0, vc->state.y + vc->vc_par[0]);
2389− return;
2390− case 'F':
2391− if (!vc->vc_par[0])
2392− vc->vc_par[0]++;
2393− gotoxy(vc, 0, vc->state.y - vc->vc_par[0]);
2394− return;
2395− case 'd':
2396− if (vc->vc_par[0])
2397− vc->vc_par[0]--;
2398− gotoxay(vc, vc->state.x ,vc->vc_par[0]);
2399− return;
2400− case 'H': case 'f':
2401− if (vc->vc_par[0])
2402− vc->vc_par[0]--;
2403− if (vc->vc_par[1])
2404− vc->vc_par[1]--;
2405− gotoxay(vc, vc->vc_par[1], vc->vc_par[0]);
2406− return;
2407− case 'J':
2408− csi_J(vc, vc->vc_par[0]);
2409− return;
2410− case 'K':
2411− csi_K(vc, vc->vc_par[0]);
2412− return;
2413− case 'L':
2414− csi_L(vc, vc->vc_par[0]);
2415− return;
2416− case 'M':
2417− csi_M(vc, vc->vc_par[0]);
2418− return;
2419− case 'P':
2420− csi_P(vc, vc->vc_par[0]);
2421− return;
2422− case 'c':
2423− if (!vc->vc_par[0])
2424− respond_ID(tty);
2425− return;
2426− case 'g':
2427− if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT)
2428− set_bit(vc->state.x, vc->vc_tab_stop);
2429− else if (vc->vc_par[0] == 3)
2430− bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
2431− return;
2432− case 'm':
2433− csi_m(vc);
2434− return;
2435− case 'q': /* DECLL - but only 3 leds */
2436− /* map 0,1,2,3 to 0,1,2,4 */
2437− if (vc->vc_par[0] < 4)
2438− vt_set_led_state(vc->vc_num,
2439− (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4);
2440− return;
2441− case 'r':
2442− if (!vc->vc_par[0])
2443− vc->vc_par[0]++;
2444− if (!vc->vc_par[1])
2445− vc->vc_par[1] = vc->vc_rows;
2446− /* Minimum allowed region is 2 lines */
2447− if (vc->vc_par[0] < vc->vc_par[1] &&
2448− vc->vc_par[1] <= vc->vc_rows) {
2449− vc->vc_top = vc->vc_par[0] - 1;
2450− vc->vc_bottom = vc->vc_par[1];
2451− gotoxay(vc, 0, 0);
2452− }
2453− return;
2454− case 's':
2455− save_cur(vc);
2456− return;
2457− case 'u':
2458− restore_cur(vc);
2459− return;
2460− case 'X':
2461− csi_X(vc, vc->vc_par[0]);
2651+
2652+ switch (vc->vc_priv) {
2653+ case EPdec:
2654+ csi_DEC(tty, vc, c);
24622655 return;
2463− case '@':
2464− csi_at(vc, vc->vc_par[0]);
2656+ case EPecma:
2657+ csi_ECMA(tty, vc, c);
24652658 return;
2466− case ']': /* setterm functions */
2467− setterm_command(vc);
2659+ default:
24682660 return;
24692661 }
2470− return;
24712662 case EScsiignore:
2472− if (c >= 20 && c <= 0x3f)
2663+ if (c >= ASCII_CSI_IGNORE_FIRST && c <= ASCII_CSI_IGNORE_LAST)
24732664 return;
24742665 vc->vc_state = ESnormal;
24752666 return;
2476− case ESpercent:
2667+ case ESpercent: /* ESC % */
24772668 vc->vc_state = ESnormal;
24782669 switch (c) {
24792670 case '@': /* defined in ISO 2022 */
@@ -2485,36 +2676,36 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 5 unmodified lines
24852676 return;
24862677 }
24872678 return;
2488− case ESfunckey:
2679+ case ESfunckey: /* ESC [ [ aka CSI [ */
24892680 vc->vc_state = ESnormal;
24902681 return;
2491− case EShash:
2682+ case EShash: /* ESC # */
24922683 vc->vc_state = ESnormal;
24932684 if (c == '8') {
24942685 /* DEC screen alignment test. kludge :-) */
24952686 vc->vc_video_erase_char =
24962687 (vc->vc_video_erase_char & 0xff00) | 'E';
2497− csi_J(vc, 2);
2688+ csi_J(vc, CSI_J_VISIBLE);
24982689 vc->vc_video_erase_char =
24992690 (vc->vc_video_erase_char & 0xff00) | ' ';
25002691 do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
25012692 }
25022693 return;
2503− case ESsetG0:
2694+ case ESsetG0: /* ESC ( */
25042695 vc_setGx(vc, 0, c);
25052696 vc->vc_state = ESnormal;
25062697 return;
2507− case ESsetG1:
2698+ case ESsetG1: /* ESC ) */
25082699 vc_setGx(vc, 1, c);
25092700 vc->vc_state = ESnormal;
25102701 return;
2511− case ESapc:
2702+ case ESapc: /* ESC _ */
25122703 return;
2513− case ESosc:
2704+ case ESosc: /* ESC ] [0-9] aka OSC [0-9] */
25142705 return;
2515− case ESpm:
2706+ case ESpm: /* ESC ^ */
25162707 return;
2517− case ESdcs:
2708+ case ESdcs: /* ESC P */
25182709 return;
25192710 default:
25202711 vc->vc_state = ESnormal;
@@ -2588,33 +2779,39 @@ static inline int vc_translate_ascii(const struct vc_data *vc, int c) · 67 unmodified lines
25882779
25892780
25902781 /**
2591− * vc_sanitize_unicode - Replace invalid Unicode code points with U+FFFD
2592− * @c: the received character, or U+FFFD for invalid sequences.
2782+ * vc_sanitize_unicode - Replace invalid Unicode code points with ``U+FFFD``
2783+ * @c: the received code point
25932784 */
25942785 static inline int vc_sanitize_unicode(const int c)
25952786 {
2596− if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff)
2787+ if (c >= 0xd800 && c <= 0xdfff)
25972788 return 0xfffd;
25982789
25992790 return c;
26002791 }
26012792
26022793 /**
2603− * vc_translate_unicode - Combine UTF-8 into Unicode in @vc_utf_char
2794+ * vc_translate_unicode - Combine UTF-8 into Unicode in &vc_data.vc_utf_char
26042795 * @vc: virtual console
2605− * @c: character to translate
2606− * @rescan: we return true if we need more (continuation) data
2796+ * @c: UTF-8 byte to translate
2797+ * @rescan: set to true iff @c wasn't consumed here and needs to be re-processed
2798+ *
2799+ * * &vc_data.vc_utf_char is the being-constructed Unicode code point.
2800+ * * &vc_data.vc_utf_count is the number of continuation bytes still expected to
2801+ * arrive.
2802+ * * &vc_data.vc_npar is the number of continuation bytes arrived so far.
26072803 *
2608− * @vc_utf_char is the being-constructed unicode character.
2609− * @vc_utf_count is the number of continuation bytes still expected to arrive.
2610− * @vc_npar is the number of continuation bytes arrived so far.
2804+ * Return:
2805+ * * %-1 - Input OK so far, @c consumed, further bytes expected.
2806+ * * %0xFFFD - Possibility 1: input invalid, @c may have been consumed (see
2807+ * desc. of @rescan). Possibility 2: input OK, @c consumed,
2808+ * ``U+FFFD`` is the resulting code point. ``U+FFFD`` is valid,
2809+ * ``REPLACEMENT CHARACTER``.
2810+ * * otherwise - Input OK, @c consumed, resulting code point returned.
26112811 */
26122812 static int vc_translate_unicode(struct vc_data *vc, int c, bool *rescan)
26132813 {
2614− static const u32 utf8_length_changes[] = {
2615− 0x0000007f, 0x000007ff, 0x0000ffff,
2616− 0x001fffff, 0x03ffffff, 0x7fffffff
2617− };
2814+ static const u32 utf8_length_changes[] = {0x7f, 0x7ff, 0xffff, 0x10ffff};
26182815
26192816 /* Continuation byte received */
26202817 if ((c & 0xc0) == 0x80) {
@@ -2660,14 +2857,7 @@ static int vc_translate_unicode(struct vc_data *vc, int c, bool *rescan) · 39 unmodified lines
26602857 } else if ((c & 0xf8) == 0xf0) {
26612858 vc->vc_utf_count = 3;
26622859 vc->vc_utf_char = (c & 0x07);
2663− } else if ((c & 0xfc) == 0xf8) {
2664− vc->vc_utf_count = 4;
2665− vc->vc_utf_char = (c & 0x03);
2666− } else if ((c & 0xfe) == 0xfc) {
2667− vc->vc_utf_count = 5;
2668− vc->vc_utf_char = (c & 0x01);
26692860 } else {
2670− /* 254 and 255 are invalid */
26712861 return 0xfffd;
26722862 }
26732863
@@ -2711,9 +2901,13 @@ static bool vc_is_control(struct vc_data *vc, int tc, int c) · 37 unmodified lines
27112901 * as cursor movement) and should not be displayed as a glyph unless
27122902 * the disp_ctrl mode is explicitly enabled.
27132903 */
2714− static const u32 CTRL_ACTION = 0x0d00ff81;
2904+ static const u32 CTRL_ACTION = BIT(ASCII_NULL) |
2905+ GENMASK(ASCII_SHIFTIN, ASCII_BELL) | BIT(ASCII_CANCEL) |
2906+ BIT(ASCII_SUBSTITUTE) | BIT(ASCII_ESCAPE);
27152907 /* Cannot be overridden by disp_ctrl */
2716− static const u32 CTRL_ALWAYS = 0x0800f501;
2908+ static const u32 CTRL_ALWAYS = BIT(ASCII_NULL) | BIT(ASCII_BACKSPACE) |
2909+ BIT(ASCII_LINEFEED) | BIT(ASCII_SHIFTIN) | BIT(ASCII_SHIFTOUT) |
2910+ BIT(ASCII_CAR_RET) | BIT(ASCII_FORMFEED) | BIT(ASCII_ESCAPE);
27172911
27182912 if (vc->vc_state != ESnormal)
27192913 return true;
@@ -2730,17 +2924,17 @@ static bool vc_is_control(struct vc_data *vc, int tc, int c) · 10 unmodified lines
27302924 * useless without them; to display an arbitrary font position use the
27312925 * direct-to-font zone in UTF-8 mode.
27322926 */
2733− if (c < 32) {
2927+ if (c < BITS_PER_TYPE(CTRL_ALWAYS)) {
27342928 if (vc->vc_disp_ctrl)
27352929 return CTRL_ALWAYS & BIT(c);
27362930 else
27372931 return vc->vc_utf || (CTRL_ACTION & BIT(c));
27382932 }
27392933
2740− if (c == 127 && !vc->vc_disp_ctrl)
2934+ if (c == ASCII_DEL && !vc->vc_disp_ctrl)
27412935 return true;
27422936
2743− if (c == 128 + 27)
2937+ if (c == ASCII_EXT_CSI)
27442938 return true;
27452939
27462940 return false;
@@ -2852,7 +3046,7 @@ static int do_con_write(struct tty_struct *tty, const u8 *buf, int count) · 105 unmodified lines
28523046 };
28533047 int c, tc, n = 0;
28543048 unsigned int currcons;
2855− struct vc_data *vc;
3049+ struct vc_data *vc = tty->driver_data;
28563050 struct vt_notifier_param param;
28573051 bool rescan;
28583052
@@ -2860,13 +3054,6 @@ static int do_con_write(struct tty_struct *tty, const u8 *buf, int count) · 1 unmodified line
28603054 return count;
28613055
28623056 console_lock();
2863− vc = tty->driver_data;
2864− if (vc == NULL) {
2865− pr_err("vt: argh, driver_data is NULL !\n");
2866− console_unlock();
2867− return 0;
2868− }
2869−
28703057 currcons = vc->vc_num;
28713058 if (!vc_cons_allocated(currcons)) {
28723059 /* could this happen? */
@@ -2883,7 +3070,7 @@ static int do_con_write(struct tty_struct *tty, const u8 *buf, int count) · 10 unmodified lines
28833070 param.vc = vc;
28843071
28853072 while (!tty->flow.stopped && count) {
2886− int orig = *buf;
3073+ u8 orig = *buf;
28873074 buf++;
28883075 n++;
28893076 count--;
@@ -2992,16 +3179,16 @@ struct tty_driver *console_driver; · 102 unmodified lines
29923179 #ifdef CONFIG_VT_CONSOLE
29933180
29943181 /**
2995− * vt_kmsg_redirect() - Sets/gets the kernel message console
2996− * @new: The new virtual terminal number or -1 if the console should stay
2997− * unchanged
3182+ * vt_kmsg_redirect() - sets/gets the kernel message console
3183+ * @new: the new virtual terminal number or -1 if the console should stay
3184+ * unchanged
29983185 *
29993186 * By default, the kernel messages are always printed on the current virtual
30003187 * console. However, the user may modify that default with the
3001− * TIOCL_SETKMSGREDIRECT ioctl call.
3188+ * %TIOCL_SETKMSGREDIRECT ioctl call.
30023189 *
30033190 * This function sets the kernel message console to be @new. It returns the old
3004− * virtual console number. The virtual terminal number 0 (both as parameter and
3191+ * virtual console number. The virtual terminal number %0 (both as parameter and
30053192 * return value) means no redirection (i.e. always printed on the currently
30063193 * active console).
30073194 *
@@ -3009,8 +3196,8 @@ struct tty_driver *console_driver; · 1 unmodified line
30093196 * value is not modified. You may use the macro vt_get_kmsg_redirect() in that
30103197 * case to make the code more understandable.
30113198 *
3012− * When the kernel is compiled without CONFIG_VT_CONSOLE, this function ignores
3013− * the parameter and always returns 0.
3199+ * When the kernel is compiled without %CONFIG_VT_CONSOLE, this function ignores
3200+ * the parameter and always returns %0.
30143201 */
30153202 int vt_kmsg_redirect(int new)
30163203 {
@@ -3065,22 +3252,23 @@ static void vt_console_print(struct console *co, const char *b, unsigned count) · 48 unmodified lines
30653252 cnt = 0;
30663253 while (count--) {
30673254 c = *b++;
3068− if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) {
3255+ if (c == ASCII_LINEFEED || c == ASCII_CAR_RET ||
3256+ c == ASCII_BACKSPACE || vc->vc_need_wrap) {
30693257 if (cnt && con_is_visible(vc))
30703258 vc->vc_sw->con_putcs(vc, start, cnt, vc->state.y, start_x);
30713259 cnt = 0;
3072− if (c == 8) { /* backspace */
3260+ if (c == ASCII_BACKSPACE) {
30733261 bs(vc);
30743262 start = (ushort *)vc->vc_pos;
30753263 start_x = vc->state.x;
30763264 continue;
30773265 }
3078− if (c != 13)
3266+ if (c != ASCII_CAR_RET)
30793267 lf(vc);
30803268 cr(vc);
30813269 start = (ushort *)vc->vc_pos;
30823270 start_x = vc->state.x;
3083− if (c == 10 || c == 13)
3271+ if (c == ASCII_LINEFEED || c == ASCII_CAR_RET)
30843272 continue;
30853273 }
30863274 vc_uniscr_putc(vc, c);
@@ -3144,6 +3332,8 @@ int tioclinux(struct tty_struct *tty, unsigned long arg) · 57 unmodified lines
31443332 {
31453333 char type, data;
31463334 char __user *p = (char __user *)arg;
3335+ void __user *param_aligned32 = (u32 __user *)arg + 1;
3336+ void __user *param = (void __user *)arg + 1;
31473337 int lines;
31483338 int ret;
31493339
@@ -3157,8 +3347,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg) · 7 unmodified lines
31573347 case TIOCL_SETSEL:
31583348 if (!capable(CAP_SYS_ADMIN))
31593349 return -EPERM;
3160− return set_selection_user((struct tiocl_selection
3161− __user *)(p+1), tty);
3350+ return set_selection_user(param, tty);
31623351 case TIOCL_PASTESEL:
31633352 if (!capable(CAP_SYS_ADMIN))
31643353 return -EPERM;
@@ -3171,10 +3360,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg) · 6 unmodified lines
31713360 case TIOCL_SELLOADLUT:
31723361 if (!capable(CAP_SYS_ADMIN))
31733362 return -EPERM;
3174− console_lock();
3175− ret = sel_loadlut(p);
3176− console_unlock();
3177− break;
3363+ return sel_loadlut(param_aligned32);
31783364 case TIOCL_GETSHIFTSTATE:
31793365 /*
31803366 * Make it possible to react to Shift+Mousebutton. Note that
@@ -3190,10 +3376,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg) · 9 unmodified lines
31903376 console_unlock();
31913377 return put_user(data, p);
31923378 case TIOCL_SETVESABLANK:
3193− console_lock();
3194− ret = set_vesa_blanking(p);
3195− console_unlock();
3196− break;
3379+ return set_vesa_blanking(param);
31973380 case TIOCL_GETKMSGREDIRECT:
31983381 data = vt_get_kmsg_redirect();
31993382 return put_user(data, p);
@@ -3214,7 +3397,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg) · 14 unmodified lines
32143397 */
32153398 return fg_console;
32163399 case TIOCL_SCROLLCONSOLE:
3217− if (get_user(lines, (s32 __user *)(p+4)))
3400+ if (get_user(lines, (s32 __user *)param_aligned32))
32183401 return -EFAULT;
32193402
32203403 /*
@@ -3312,16 +3495,13 @@ static void con_start(struct tty_struct *tty) · 91 unmodified lines
33123495
33133496 static void con_flush_chars(struct tty_struct *tty)
33143497 {
3315− struct vc_data *vc;
3498+ struct vc_data *vc = tty->driver_data;
33163499
33173500 if (in_interrupt()) /* from flush_to_ldisc */
33183501 return;
33193502
3320− /* if we race with con_close(), vt may be null */
33213503 console_lock();
3322− vc = tty->driver_data;
3323− if (vc)
3324− set_cursor(vc);
3504+ set_cursor(vc);
33253505 console_unlock();
33263506 }
33273507
@@ -3471,7 +3651,7 @@ static int __init con_init(void) · 143 unmodified lines
34713651 vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT);
34723652 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK);
34733653 tty_port_init(&vc->port);
3474− visual_init(vc, currcons, 1);
3654+ visual_init(vc, currcons, true);
34753655 /* Assuming vc->vc_{cols,rows,screenbuf_size} are sane here. */
34763656 vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT);
34773657 vc_init(vc, currcons || !vc->vc_sw->con_save_screen);
@@ -3481,7 +3661,7 @@ static int __init con_init(void) · 3 unmodified lines
34813661 set_origin(vc);
34823662 save_screen(vc);
34833663 gotoxy(vc, vc->state.x, vc->state.y);
3484− csi_J(vc, 0);
3664+ csi_J(vc, CSI_J_CURSOR_TO_END);
34853665 update_screen(vc);
34863666 pr_info("Console: %s %s %dx%d\n",
34873667 vc->vc_can_do_color ? "colour" : "mono",
@@ -3640,7 +3820,7 @@ static int do_bind_con_driver(const struct consw *csw, int first, int last, · 152 unmodified lines
36403820 old_was_color = vc->vc_can_do_color;
36413821 vc->vc_sw->con_deinit(vc);
36423822 vc->vc_origin = (unsigned long)vc->vc_screenbuf;
3643− visual_init(vc, i, 0);
3823+ visual_init(vc, i, false);
36443824 set_origin(vc);
36453825 update_attr(vc);
36463826
@@ -3930,7 +4110,7 @@ static void vtconsole_deinit_device(struct con_driver *con) · 283 unmodified lines
39304110 * RETURNS: zero if unbound, nonzero if bound
39314111 *
39324112 * Drivers can call this and if zero, they should release
3933− * all resources allocated on con_startup()
4113+ * all resources allocated on &consw.con_startup()
39344114 */
39354115 int con_is_bound(const struct consw *csw)
39364116 {
@@ -3970,15 +4150,9 @@ EXPORT_SYMBOL(con_is_visible); · 33 unmodified lines
39704150 * Called when the console is taken over by the kernel debugger, this
39714151 * function needs to save the current console state, then put the console
39724152 * into a state suitable for the kernel debugger.
3973− *
3974− * RETURNS:
3975− * Zero on success, nonzero if a failure occurred when trying to prepare
3976− * the console for the debugger.
39774153 */
3978−int con_debug_enter(struct vc_data *vc)
4154+void con_debug_enter(struct vc_data *vc)
39794155 {
3980− int ret = 0;
3981−
39824156 saved_fg_console = fg_console;
39834157 saved_last_console = last_console;
39844158 saved_want_console = want_console;
@@ -3987,7 +4161,7 @@ int con_debug_enter(struct vc_data *vc) · 2 unmodified lines
39874161 vc->vc_mode = KD_TEXT;
39884162 console_blanked = 0;
39894163 if (vc->vc_sw->con_debug_enter)
3990− ret = vc->vc_sw->con_debug_enter(vc);
4164+ vc->vc_sw->con_debug_enter(vc);
39914165 #ifdef CONFIG_KGDB_KDB
39924166 /* Set the initial LINES variable if it is not already set */
39934167 if (vc->vc_rows < 999) {
@@ -4017,7 +4191,6 @@ int con_debug_enter(struct vc_data *vc) · 23 unmodified lines
40174191 }
40184192 }
40194193 #endif /* CONFIG_KGDB_KDB */
4020− return ret;
40214194 }
40224195 EXPORT_SYMBOL_GPL(con_debug_enter);
40234196
@@ -4026,15 +4199,10 @@ EXPORT_SYMBOL_GPL(con_debug_enter); · 2 unmodified lines
40264199 *
40274200 * Restore the console state to what it was before the kernel debugger
40284201 * was invoked.
4029− *
4030− * RETURNS:
4031− * Zero on success, nonzero if a failure occurred when trying to restore
4032− * the console.
40334202 */
4034−int con_debug_leave(void)
4203+void con_debug_leave(void)
40354204 {
40364205 struct vc_data *vc;
4037− int ret = 0;
40384206
40394207 fg_console = saved_fg_console;
40404208 last_console = saved_last_console;
@@ -4044,8 +4212,7 @@ int con_debug_leave(void) · 3 unmodified lines
40444212
40454213 vc = vc_cons[fg_console].d;
40464214 if (vc->vc_sw->con_debug_leave)
4047− ret = vc->vc_sw->con_debug_leave(vc);
4048− return ret;
4215+ vc->vc_sw->con_debug_leave(vc);
40494216 }
40504217 EXPORT_SYMBOL_GPL(con_debug_leave);
40514218
@@ -4275,14 +4442,17 @@ postcore_initcall(vtconsole_class_init); · 223 unmodified lines
42754442 * Screen blanking
42764443 */
42774444
4278−static int set_vesa_blanking(char __user *p)
4445+static int set_vesa_blanking(u8 __user *mode_user)
42794446 {
4280− unsigned int mode;
4447+ u8 mode;
42814448
4282− if (get_user(mode, p + 1))
4449+ if (get_user(mode, mode_user))
42834450 return -EFAULT;
42844451
4285− vesa_blank_mode = (mode < 4) ? mode : 0;
4452+ console_lock();
4453+ vesa_blank_mode = (mode <= VESA_BLANK_MAX) ? mode : VESA_NO_BLANKING;
4454+ console_unlock();
4455+
42864456 return 0;
42874457 }
42884458
@@ -4307,7 +4477,7 @@ void do_blank_screen(int entering_gfx) · 18 unmodified lines
43074477 if (entering_gfx) {
43084478 hide_cursor(vc);
43094479 save_screen(vc);
4310− vc->vc_sw->con_blank(vc, -1, 1);
4480+ vc->vc_sw->con_blank(vc, VESA_VSYNC_SUSPEND, 1);
43114481 console_blanked = fg_console + 1;
43124482 blank_state = blank_off;
43134483 set_origin(vc);
@@ -4328,7 +4498,8 @@ void do_blank_screen(int entering_gfx) · 14 unmodified lines
43284498
43294499 save_screen(vc);
43304500 /* In case we need to reset origin, blanking hook returns 1 */
4331− i = vc->vc_sw->con_blank(vc, vesa_off_interval ? 1 : (vesa_blank_mode + 1), 0);
4501+ i = vc->vc_sw->con_blank(vc, vesa_off_interval ? VESA_VSYNC_SUSPEND :
4502+ (vesa_blank_mode + 1), 0);
43324503 console_blanked = fg_console + 1;
43334504 if (i)
43344505 set_origin(vc);
@@ -4379,7 +4550,7 @@ void do_unblank_screen(int leaving_gfx) · 44 unmodified lines
43794550 }
43804551
43814552 console_blanked = 0;
4382− if (vc->vc_sw->con_blank(vc, 0, leaving_gfx))
4553+ if (vc->vc_sw->con_blank(vc, VESA_NO_BLANKING, leaving_gfx))
43834554 /* Low-level driver cannot restore -> do it ourselves */
43844555 update_screen(vc);
43854556 if (console_blank_hook)
@@ -4584,7 +4755,7 @@ out: · 198 unmodified lines
45844755 return rc;
45854756 }
45864757
4587−static int con_font_set(struct vc_data *vc, struct console_font_op *op)
4758+static int con_font_set(struct vc_data *vc, const struct console_font_op *op)
45884759 {
45894760 struct console_font font;
45904761 int rc = -EINVAL;
@@ -4748,43 +4919,3 @@ void vcs_scr_updated(struct vc_data *vc) · 157 unmodified lines
47484919 {
47494920 notify_update(vc);
47504921 }
4751−
4752−void vc_scrolldelta_helper(struct vc_data *c, int lines,
4753− unsigned int rolled_over, void *base, unsigned int size)
4754−{
4755− unsigned long ubase = (unsigned long)base;
4756− ptrdiff_t scr_end = (void *)c->vc_scr_end - base;
4757− ptrdiff_t vorigin = (void *)c->vc_visible_origin - base;
4758− ptrdiff_t origin = (void *)c->vc_origin - base;
4759− int margin = c->vc_size_row * 4;
4760− int from, wrap, from_off, avail;
4761−
4762− /* Turn scrollback off */
4763− if (!lines) {
4764− c->vc_visible_origin = c->vc_origin;
4765− return;
4766− }
4767−
4768− /* Do we have already enough to allow jumping from 0 to the end? */
4769− if (rolled_over > scr_end + margin) {
4770− from = scr_end;
4771− wrap = rolled_over + c->vc_size_row;
4772− } else {
4773− from = 0;
4774− wrap = size;
4775− }
4776−
4777− from_off = (vorigin - from + wrap) % wrap + lines * c->vc_size_row;
4778− avail = (origin - from + wrap) % wrap;
4779−
4780− /* Only a little piece would be left? Show all incl. the piece! */
4781− if (avail < 2 * margin)
4782− margin = 0;
4783− if (from_off < margin)
4784− from_off = 0;
4785− if (from_off > avail - margin)
4786− from_off = avail;
4787−
4788− c->vc_visible_origin = ubase + (from + from_off) % wrap;
4789−}
4790−EXPORT_SYMBOL_GPL(vc_scrolldelta_helper);
drivers/tty/vt/vt_ioctl.c+2−4
@@ -714,8 +714,7 @@ static int vt_resizex(struct vc_data *vc, struct vt_consize __user *cs) · 713 unmodified lines
714714 vcp->vc_scan_lines = v.v_vlin;
715715 if (v.v_clin)
716716 vcp->vc_cell_height = v.v_clin;
717− vcp->vc_resize_user = 1;
718− ret = vc_resize(vcp, v.v_cols, v.v_rows);
717+ ret = __vc_resize(vcp, v.v_cols, v.v_rows, true);
719718 if (ret) {
720719 vcp->vc_scan_lines = save_scan_lines;
721720 vcp->vc_cell_height = save_cell_height;
@@ -923,9 +922,8 @@ int vt_ioctl(struct tty_struct *tty, · 201 unmodified lines
923922 vc = vc_cons[i].d;
924923
925924 if (vc) {
926− vc->vc_resize_user = 1;
927925 /* FIXME: review v tty lock */
928− vc_resize(vc_cons[i].d, cc, ll);
926+ __vc_resize(vc_cons[i].d, cc, ll, true);
929927 }
930928 }
931929 console_unlock();
drivers/video/console/dummycon.c+21−17
@@ -50,7 +50,8 @@ void dummycon_unregister_output_notifier(struct notifier_block *nb) · 49 unmodified lines
5050 raw_notifier_chain_unregister(&dummycon_output_nh, nb);
5151 }
5252
53−static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos)
53+static void dummycon_putc(struct vc_data *vc, u16 c, unsigned int y,
54+ unsigned int x)
5455 {
5556 WARN_CONSOLE_UNLOCKED();
5657
@@ -58,10 +59,10 @@ static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos) · 1 unmodified line
5859 raw_notifier_call_chain(&dummycon_output_nh, 0, NULL);
5960 }
6061
61−static void dummycon_putcs(struct vc_data *vc, const unsigned short *s,
62− int count, int ypos, int xpos)
62+static void dummycon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
63+ unsigned int ypos, unsigned int xpos)
6364 {
64− int i;
65+ unsigned int i;
6566
6667 if (!dummycon_putc_called) {
6768 /* Ignore erases */
@@ -78,18 +79,21 @@ static void dummycon_putcs(struct vc_data *vc, const unsigned short *s, · 10 unmodified lines
7879 raw_notifier_call_chain(&dummycon_output_nh, 0, NULL);
7980 }
8081
81−static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch)
82+static bool dummycon_blank(struct vc_data *vc, enum vesa_blank_mode blank,
83+ bool mode_switch)
8284 {
8385 /* Redraw, so that we get putc(s) for output done while blanked */
84− return 1;
86+ return true;
8587 }
8688 #else
87−static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos) { }
88−static void dummycon_putcs(struct vc_data *vc, const unsigned short *s,
89− int count, int ypos, int xpos) { }
90−static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch)
89+static void dummycon_putc(struct vc_data *vc, u16 c, unsigned int y,
90+ unsigned int x) { }
91+static void dummycon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
92+ unsigned int ypos, unsigned int xpos) { }
93+static bool dummycon_blank(struct vc_data *vc, enum vesa_blank_mode blank,
94+ bool mode_switch)
9195 {
92− return 0;
96+ return false;
9397 }
9498 #endif
9599
@@ -98,7 +102,7 @@ static const char *dummycon_startup(void) · 2 unmodified lines
98102 return "dummy device";
99103 }
100104
101−static void dummycon_init(struct vc_data *vc, int init)
105+static void dummycon_init(struct vc_data *vc, bool init)
102106 {
103107 vc->vc_can_do_color = 1;
104108 if (init) {
@@ -109,9 +113,9 @@ static void dummycon_init(struct vc_data *vc, int init) · 4 unmodified lines
109113 }
110114
111115 static void dummycon_deinit(struct vc_data *vc) { }
112−static void dummycon_clear(struct vc_data *vc, int sy, int sx, int height,
113− int width) { }
114−static void dummycon_cursor(struct vc_data *vc, int mode) { }
116+static void dummycon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
117+ unsigned int width) { }
118+static void dummycon_cursor(struct vc_data *vc, bool enable) { }
115119
116120 static bool dummycon_scroll(struct vc_data *vc, unsigned int top,
117121 unsigned int bottom, enum con_scroll dir,
@@ -120,9 +124,9 @@ static bool dummycon_scroll(struct vc_data *vc, unsigned int top, · 2 unmodified lines
120124 return false;
121125 }
122126
123−static int dummycon_switch(struct vc_data *vc)
127+static bool dummycon_switch(struct vc_data *vc)
124128 {
125− return 0;
129+ return false;
126130 }
127131
128132 /*
drivers/video/console/mdacon.c+15−28
@@ -352,7 +352,7 @@ static const char *mdacon_startup(void) · 351 unmodified lines
352352 return "MDA-2";
353353 }
354354
355−static void mdacon_init(struct vc_data *c, int init)
355+static void mdacon_init(struct vc_data *c, bool init)
356356 {
357357 c->vc_complement_mask = 0x0800; /* reverse video */
358358 c->vc_display_fg = &mda_display_fg;
@@ -427,13 +427,8 @@ static inline u16 *mda_addr(unsigned int x, unsigned int y) · 68 unmodified lines
427427 return mda_vram_base + y * mda_num_columns + x;
428428 }
429429
430−static void mdacon_putc(struct vc_data *c, int ch, int y, int x)
431−{
432− scr_writew(mda_convert_attr(ch), mda_addr(x, y));
433−}
434−
435−static void mdacon_putcs(struct vc_data *c, const unsigned short *s,
436− int count, int y, int x)
430+static void mdacon_putcs(struct vc_data *c, const u16 *s, unsigned int count,
431+ unsigned int y, unsigned int x)
437432 {
438433 u16 *dest = mda_addr(x, y);
439434
@@ -442,29 +437,22 @@ static void mdacon_putcs(struct vc_data *c, const unsigned short *s, · 2 unmodified lines
442437 }
443438 }
444439
445−static void mdacon_clear(struct vc_data *c, int y, int x,
446− int height, int width)
440+static void mdacon_clear(struct vc_data *c, unsigned int y, unsigned int x,
441+ unsigned int width)
447442 {
448443 u16 *dest = mda_addr(x, y);
449444 u16 eattr = mda_convert_attr(c->vc_video_erase_char);
450445
451− if (width <= 0 || height <= 0)
452− return;
453−
454− if (x==0 && width==mda_num_columns) {
455− scr_memsetw(dest, eattr, height*width*2);
456− } else {
457− for (; height > 0; height--, dest+=mda_num_columns)
458− scr_memsetw(dest, eattr, width*2);
459− }
446+ scr_memsetw(dest, eattr, width * 2);
460447 }
461−
462−static int mdacon_switch(struct vc_data *c)
448+
449+static bool mdacon_switch(struct vc_data *c)
463450 {
464− return 1; /* redrawing needed */
451+ return true; /* redrawing needed */
465452 }
466453
467−static int mdacon_blank(struct vc_data *c, int blank, int mode_switch)
454+static bool mdacon_blank(struct vc_data *c, enum vesa_blank_mode blank,
455+ bool mode_switch)
468456 {
469457 if (mda_type == TYPE_MDA) {
470458 if (blank)
@@ -472,20 +460,20 @@ static int mdacon_blank(struct vc_data *c, int blank, int mode_switch) · 1 unmodified line
472460 mda_convert_attr(c->vc_video_erase_char),
473461 c->vc_screenbuf_size);
474462 /* Tell console.c that it has to restore the screen itself */
475− return 1;
463+ return true;
476464 } else {
477465 if (blank)
478466 outb_p(0x00, mda_mode_port); /* disable video */
479467 else
480468 outb_p(MDA_MODE_VIDEO_EN | MDA_MODE_BLINK_EN,
481469 mda_mode_port);
482− return 0;
470+ return false;
483471 }
484472 }
485473
486−static void mdacon_cursor(struct vc_data *c, int mode)
474+static void mdacon_cursor(struct vc_data *c, bool enable)
487475 {
488− if (mode == CM_ERASE) {
476+ if (!enable) {
489477 mda_set_cursor(mda_vram_len - 1);
490478 return;
491479 }
@@ -544,7 +532,6 @@ static const struct consw mda_con = { · 52 unmodified lines
544532 .con_init = mdacon_init,
545533 .con_deinit = mdacon_deinit,
546534 .con_clear = mdacon_clear,
547− .con_putc = mdacon_putc,
548535 .con_putcs = mdacon_putcs,
549536 .con_cursor = mdacon_cursor,
550537 .con_scroll = mdacon_scroll,
drivers/video/console/newport_con.c+35−34
@@ -324,7 +324,7 @@ out_unmap: · 323 unmodified lines
324324 return NULL;
325325 }
326326
327−static void newport_init(struct vc_data *vc, int init)
327+static void newport_init(struct vc_data *vc, bool init)
328328 {
329329 int cols, rows;
330330
@@ -346,12 +346,12 @@ static void newport_deinit(struct vc_data *c) · 15 unmodified lines
346346 }
347347 }
348348
349−static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
350− int width)
349+static void newport_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
350+ unsigned int width)
351351 {
352352 int xend = ((sx + width) << 3) - 1;
353353 int ystart = ((sy << 4) + topscan) & 0x3ff;
354− int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
354+ int yend = (((sy + 1) << 4) + topscan - 1) & 0x3ff;
355355
356356 if (logo_active)
357357 return;
@@ -367,8 +367,8 @@ static void newport_clear(struct vc_data *vc, int sy, int sx, int height, · 9 unmodified lines
367367 }
368368 }
369369
370−static void newport_putc(struct vc_data *vc, int charattr, int ypos,
371− int xpos)
370+static void newport_putc(struct vc_data *vc, u16 charattr, unsigned int ypos,
371+ unsigned int xpos)
372372 {
373373 unsigned char *p;
374374
@@ -396,12 +396,13 @@ static void newport_putc(struct vc_data *vc, int charattr, int ypos, · 21 unmodified lines
396396 RENDER(npregs, p);
397397 }
398398
399−static void newport_putcs(struct vc_data *vc, const unsigned short *s,
400− int count, int ypos, int xpos)
399+static void newport_putcs(struct vc_data *vc, const u16 *s,
400+ unsigned int count, unsigned int ypos,
401+ unsigned int xpos)
401402 {
402− int i;
403− int charattr;
404403 unsigned char *p;
404+ unsigned int i;
405+ u16 charattr;
405406
406407 charattr = (scr_readw(s) >> 8) & 0xff;
407408
@@ -437,32 +438,28 @@ static void newport_putcs(struct vc_data *vc, const unsigned short *s, · 29 unmodified lines
437438 }
438439 }
439440
440−static void newport_cursor(struct vc_data *vc, int mode)
441+static void newport_cursor(struct vc_data *vc, bool enable)
441442 {
442443 unsigned short treg;
443444 int xcurs, ycurs;
444445
445− switch (mode) {
446− case CM_ERASE:
447− treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
448− newport_vc2_set(npregs, VC2_IREG_CONTROL,
449− (treg & ~(VC2_CTRL_ECDISP)));
450− break;
446+ treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
451447
452− case CM_MOVE:
453− case CM_DRAW:
454− treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
448+ if (!enable) {
455449 newport_vc2_set(npregs, VC2_IREG_CONTROL,
456− (treg | VC2_CTRL_ECDISP));
457− xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
458− ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
459− xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
460− newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
461− newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
450+ (treg & ~(VC2_CTRL_ECDISP)));
451+ return;
462452 }
453+
454+ newport_vc2_set(npregs, VC2_IREG_CONTROL, (treg | VC2_CTRL_ECDISP));
455+ xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
456+ ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
457+ xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
458+ newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
459+ newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
463460 }
464461
465−static int newport_switch(struct vc_data *vc)
462+static bool newport_switch(struct vc_data *vc)
466463 {
467464 static int logo_drawn = 0;
468465
@@ -476,14 +473,15 @@ static int newport_switch(struct vc_data *vc) · 7 unmodified lines
476473 }
477474 }
478475
479− return 1;
476+ return true;
480477 }
481478
482−static int newport_blank(struct vc_data *c, int blank, int mode_switch)
479+static bool newport_blank(struct vc_data *c, enum vesa_blank_mode blank,
480+ bool mode_switch)
483481 {
484482 unsigned short treg;
485483
486− if (blank == 0) {
484+ if (blank == VESA_NO_BLANKING) {
487485 /* unblank console */
488486 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
489487 newport_vc2_set(npregs, VC2_IREG_CONTROL,
@@ -494,10 +492,12 @@ static int newport_blank(struct vc_data *c, int blank, int mode_switch) · 4 unmodified lines
494492 newport_vc2_set(npregs, VC2_IREG_CONTROL,
495493 (treg & ~(VC2_CTRL_EDISP)));
496494 }
497− return 1;
495+
496+ return true;
498497 }
499498
500−static int newport_set_font(int unit, struct console_font *op, unsigned int vpitch)
499+static int newport_set_font(int unit, const struct console_font *op,
500+ unsigned int vpitch)
501501 {
502502 int w = op->width;
503503 int h = op->height;
@@ -564,12 +564,13 @@ static int newport_set_def_font(int unit, struct console_font *op) · 60 unmodified lines
564564 return 0;
565565 }
566566
567−static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
567+static int newport_font_default(struct vc_data *vc, struct console_font *op,
568+ const char *name)
568569 {
569570 return newport_set_def_font(vc->vc_num, op);
570571 }
571572
572−static int newport_font_set(struct vc_data *vc, struct console_font *font,
573+static int newport_font_set(struct vc_data *vc, const struct console_font *font,
573574 unsigned int vpitch, unsigned int flags)
574575 {
575576 return newport_set_font(vc->vc_num, font, vpitch);
drivers/video/console/sticon.c+32−47
@@ -71,19 +71,8 @@ static const char *sticon_startup(void) · 70 unmodified lines
7171 return "STI console";
7272 }
7373
74−static void sticon_putc(struct vc_data *conp, int c, int ypos, int xpos)
75−{
76− if (vga_is_gfx || console_blanked)
77− return;
78−
79− if (conp->vc_mode != KD_TEXT)
80− return;
81−
82− sti_putc(sticon_sti, c, ypos, xpos, font_data[conp->vc_num]);
83−}
84−
85−static void sticon_putcs(struct vc_data *conp, const unsigned short *s,
86− int count, int ypos, int xpos)
74+static void sticon_putcs(struct vc_data *conp, const u16 *s, unsigned int count,
75+ unsigned int ypos, unsigned int xpos)
8776 {
8877 if (vga_is_gfx || console_blanked)
8978 return;
@@ -97,7 +86,7 @@ static void sticon_putcs(struct vc_data *conp, const unsigned short *s, · 7 unmodified lines
9786 }
9887 }
9988
100−static void sticon_cursor(struct vc_data *conp, int mode)
89+static void sticon_cursor(struct vc_data *conp, bool enable)
10190 {
10291 unsigned short car1;
10392
@@ -106,23 +95,20 @@ static void sticon_cursor(struct vc_data *conp, int mode) · 2 unmodified lines
10695 return;
10796
10897 car1 = conp->vc_screenbuf[conp->state.x + conp->state.y * conp->vc_cols];
109− switch (mode) {
110− case CM_ERASE:
98+ if (!enable) {
11199 sti_putc(sticon_sti, car1, conp->state.y, conp->state.x,
112100 font_data[conp->vc_num]);
113− break;
114− case CM_MOVE:
115− case CM_DRAW:
116− switch (CUR_SIZE(conp->vc_cursor_type)) {
117− case CUR_UNDERLINE:
118− case CUR_LOWER_THIRD:
119− case CUR_LOWER_HALF:
120− case CUR_TWO_THIRDS:
121− case CUR_BLOCK:
122− sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11),
123− conp->state.y, conp->state.x, font_data[conp->vc_num]);
124− break;
125− }
101+ return;
102+ }
103+
104+ switch (CUR_SIZE(conp->vc_cursor_type)) {
105+ case CUR_UNDERLINE:
106+ case CUR_LOWER_THIRD:
107+ case CUR_LOWER_HALF:
108+ case CUR_TWO_THIRDS:
109+ case CUR_BLOCK:
110+ sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11),
111+ conp->state.y, conp->state.x, font_data[conp->vc_num]);
126112 break;
127113 }
128114 }
@@ -135,7 +121,7 @@ static bool sticon_scroll(struct vc_data *conp, unsigned int t, · 6 unmodified lines
135121 if (vga_is_gfx)
136122 return false;
137123
138− sticon_cursor(conp, CM_ERASE);
124+ sticon_cursor(conp, false);
139125
140126 switch (dir) {
141127 case SM_UP:
@@ -167,7 +153,7 @@ static void sticon_set_def_font(int unit) · 25 unmodified lines
167153 }
168154 }
169155
170−static int sticon_set_font(struct vc_data *vc, struct console_font *op,
156+static int sticon_set_font(struct vc_data *vc, const struct console_font *op,
171157 unsigned int vpitch)
172158 {
173159 struct sti_struct *sti = sticon_sti;
@@ -260,20 +246,21 @@ static int sticon_set_font(struct vc_data *vc, struct console_font *op, · 86 unmodified lines
260246 return 0;
261247 }
262248
263−static int sticon_font_default(struct vc_data *vc, struct console_font *op, char *name)
249+static int sticon_font_default(struct vc_data *vc, struct console_font *op,
250+ const char *name)
264251 {
265252 sticon_set_def_font(vc->vc_num);
266253
267254 return 0;
268255 }
269256
270−static int sticon_font_set(struct vc_data *vc, struct console_font *font,
257+static int sticon_font_set(struct vc_data *vc, const struct console_font *font,
271258 unsigned int vpitch, unsigned int flags)
272259 {
273260 return sticon_set_font(vc, font, vpitch);
274261 }
275262
276−static void sticon_init(struct vc_data *c, int init)
263+static void sticon_init(struct vc_data *c, bool init)
277264 {
278265 struct sti_struct *sti = sticon_sti;
279266 int vc_cols, vc_rows;
@@ -300,33 +287,32 @@ static void sticon_deinit(struct vc_data *c) · 20 unmodified lines
300287 sticon_set_def_font(i);
301288 }
302289
303−static void sticon_clear(struct vc_data *conp, int sy, int sx, int height,
304− int width)
290+static void sticon_clear(struct vc_data *conp, unsigned int sy, unsigned int sx,
291+ unsigned int width)
305292 {
306− if (!height || !width)
307− return;
308−
309− sti_clear(sticon_sti, sy, sx, height, width,
293+ sti_clear(sticon_sti, sy, sx, 1, width,
310294 conp->vc_video_erase_char, font_data[conp->vc_num]);
311295 }
312296
313−static int sticon_switch(struct vc_data *conp)
297+static bool sticon_switch(struct vc_data *conp)
314298 {
315− return 1; /* needs refreshing */
299+ return true; /* needs refreshing */
316300 }
317301
318−static int sticon_blank(struct vc_data *c, int blank, int mode_switch)
302+static bool sticon_blank(struct vc_data *c, enum vesa_blank_mode blank,
303+ bool mode_switch)
319304 {
320− if (blank == 0) {
305+ if (blank == VESA_NO_BLANKING) {
321306 if (mode_switch)
322307 vga_is_gfx = 0;
323− return 1;
308+ return true;
324309 }
325310 sti_clear(sticon_sti, 0, 0, c->vc_rows, c->vc_cols, BLANK,
326311 font_data[c->vc_num]);
327312 if (mode_switch)
328313 vga_is_gfx = 1;
329− return 1;
314+
315+ return true;
330316 }
331317
332318 static u8 sticon_build_attr(struct vc_data *conp, u8 color,
@@ -365,7 +351,6 @@ static const struct consw sti_con = { · 32 unmodified lines
365351 .con_init = sticon_init,
366352 .con_deinit = sticon_deinit,
367353 .con_clear = sticon_clear,
368− .con_putc = sticon_putc,
369354 .con_putcs = sticon_putcs,
370355 .con_cursor = sticon_cursor,
371356 .con_scroll = sticon_scroll,
drivers/video/console/vgacon.c+88−64
@@ -65,7 +65,7 @@ static struct vgastate vgastate; · 64 unmodified lines
6565 * Interface used by the world
6666 */
6767
68−static int vgacon_set_origin(struct vc_data *c);
68+static bool vgacon_set_origin(struct vc_data *c);
6969
7070 static struct uni_pagedict *vgacon_uni_pagedir;
7171 static int vgacon_refcount;
@@ -81,7 +81,7 @@ static unsigned int vga_video_num_lines; /* Number of text lines */ · 9 unmodified lines
8181 static bool vga_can_do_color; /* Do we support colors? */
8282 static unsigned int vga_default_font_height __read_mostly; /* Height of default screen font */
8383 static unsigned char vga_video_type __read_mostly; /* Card type */
84−static int vga_vesa_blanked;
84+static enum vesa_blank_mode vga_vesa_blanked;
8585 static bool vga_palette_blanked;
8686 static bool vga_is_gfx;
8787 static bool vga_512_chars;
@@ -138,8 +138,40 @@ static inline void vga_set_mem_top(struct vc_data *c) · 50 unmodified lines
138138
139139 static void vgacon_scrolldelta(struct vc_data *c, int lines)
140140 {
141− vc_scrolldelta_helper(c, lines, vga_rolled_over, (void *)vga_vram_base,
142− vga_vram_size);
141+ unsigned long scr_end = c->vc_scr_end - vga_vram_base;
142+ unsigned long vorigin = c->vc_visible_origin - vga_vram_base;
143+ unsigned long origin = c->vc_origin - vga_vram_base;
144+ int margin = c->vc_size_row * 4;
145+ int from, wrap, from_off, avail;
146+
147+ /* Turn scrollback off */
148+ if (!lines) {
149+ c->vc_visible_origin = c->vc_origin;
150+ return;
151+ }
152+
153+ /* Do we have already enough to allow jumping from 0 to the end? */
154+ if (vga_rolled_over > scr_end + margin) {
155+ from = scr_end;
156+ wrap = vga_rolled_over + c->vc_size_row;
157+ } else {
158+ from = 0;
159+ wrap = vga_vram_size;
160+ }
161+
162+ from_off = (vorigin - from + wrap) % wrap + lines * c->vc_size_row;
163+ avail = (origin - from + wrap) % wrap;
164+
165+ /* Only a little piece would be left? Show all incl. the piece! */
166+ if (avail < 2 * margin)
167+ margin = 0;
168+ if (from_off < margin)
169+ from_off = 0;
170+ if (from_off > avail - margin)
171+ from_off = avail;
172+
173+ c->vc_visible_origin = vga_vram_base + (from + from_off) % wrap;
174+
143175 vga_set_mem_top(c);
144176 }
145177
@@ -335,7 +367,7 @@ static const char *vgacon_startup(void) · 189 unmodified lines
335367 return display_desc;
336368 }
337369
338−static void vgacon_init(struct vc_data *c, int init)
370+static void vgacon_init(struct vc_data *c, bool init)
339371 {
340372 struct uni_pagedict *p;
341373
@@ -352,7 +384,7 @@ static void vgacon_init(struct vc_data *c, int init) · 10 unmodified lines
352384 c->vc_scan_lines = vga_scan_lines;
353385 c->vc_font.height = c->vc_cell_height = vga_video_font_height;
354386
355− /* set dimensions manually if init != 0 since vc_resize() will fail */
387+ /* set dimensions manually if init is true since vc_resize() will fail */
356388 if (init) {
357389 c->vc_cols = vga_video_num_columns;
358390 c->vc_rows = vga_video_num_lines;
@@ -471,7 +503,7 @@ static void vgacon_set_cursor_size(int from, int to) · 112 unmodified lines
471503 raw_spin_unlock_irqrestore(&vga_lock, flags);
472504 }
473505
474−static void vgacon_cursor(struct vc_data *c, int mode)
506+static void vgacon_cursor(struct vc_data *c, bool enable)
475507 {
476508 unsigned int c_height;
477509
@@ -482,47 +514,41 @@ static void vgacon_cursor(struct vc_data *c, int mode) · 4 unmodified lines
482514
483515 c_height = c->vc_cell_height;
484516
485− switch (mode) {
486− case CM_ERASE:
487− write_vga(14, (c->vc_pos - vga_vram_base) / 2);
517+ write_vga(14, (c->vc_pos - vga_vram_base) / 2);
518+
519+ if (!enable) {
488520 if (vga_video_type >= VIDEO_TYPE_VGAC)
489521 vgacon_set_cursor_size(31, 30);
490522 else
491523 vgacon_set_cursor_size(31, 31);
492− break;
524+ return;
525+ }
493526
494− case CM_MOVE:
495− case CM_DRAW:
496− write_vga(14, (c->vc_pos - vga_vram_base) / 2);
497− switch (CUR_SIZE(c->vc_cursor_type)) {
498− case CUR_UNDERLINE:
499− vgacon_set_cursor_size(c_height -
500− (c_height < 10 ? 2 : 3),
501− c_height -
502− (c_height < 10 ? 1 : 2));
503− break;
504− case CUR_TWO_THIRDS:
505− vgacon_set_cursor_size(c_height / 3, c_height -
506− (c_height < 10 ? 1 : 2));
507− break;
508− case CUR_LOWER_THIRD:
509− vgacon_set_cursor_size(c_height * 2 / 3, c_height -
510− (c_height < 10 ? 1 : 2));
511− break;
512− case CUR_LOWER_HALF:
513− vgacon_set_cursor_size(c_height / 2, c_height -
514− (c_height < 10 ? 1 : 2));
515− break;
516− case CUR_NONE:
517− if (vga_video_type >= VIDEO_TYPE_VGAC)
518− vgacon_set_cursor_size(31, 30);
519− else
520− vgacon_set_cursor_size(31, 31);
521− break;
522− default:
523− vgacon_set_cursor_size(1, c_height);
524− break;
525− }
527+ switch (CUR_SIZE(c->vc_cursor_type)) {
528+ case CUR_UNDERLINE:
529+ vgacon_set_cursor_size(c_height - (c_height < 10 ? 2 : 3),
530+ c_height - (c_height < 10 ? 1 : 2));
531+ break;
532+ case CUR_TWO_THIRDS:
533+ vgacon_set_cursor_size(c_height / 3,
534+ c_height - (c_height < 10 ? 1 : 2));
535+ break;
536+ case CUR_LOWER_THIRD:
537+ vgacon_set_cursor_size(c_height * 2 / 3,
538+ c_height - (c_height < 10 ? 1 : 2));
539+ break;
540+ case CUR_LOWER_HALF:
541+ vgacon_set_cursor_size(c_height / 2,
542+ c_height - (c_height < 10 ? 1 : 2));
543+ break;
544+ case CUR_NONE:
545+ if (vga_video_type >= VIDEO_TYPE_VGAC)
546+ vgacon_set_cursor_size(31, 30);
547+ else
548+ vgacon_set_cursor_size(31, 31);
549+ break;
550+ default:
551+ vgacon_set_cursor_size(1, c_height);
526552 break;
527553 }
528554 }
@@ -588,7 +614,7 @@ static void vgacon_doresize(struct vc_data *c, · 59 unmodified lines
588614 raw_spin_unlock_irqrestore(&vga_lock, flags);
589615 }
590616
591−static int vgacon_switch(struct vc_data *c)
617+static bool vgacon_switch(struct vc_data *c)
592618 {
593619 int x = c->vc_cols * VGA_FONTWIDTH;
594620 int y = c->vc_rows * c->vc_cell_height;
@@ -617,7 +643,7 @@ static int vgacon_switch(struct vc_data *c) · 22 unmodified lines
617643 vgacon_doresize(c, c->vc_cols, c->vc_rows);
618644 }
619645
620− return 0; /* Redrawing not needed */
646+ return false; /* Redrawing not needed */
621647 }
622648
623649 static void vga_set_palette(struct vc_data *vc, const unsigned char *table)
@@ -657,7 +683,7 @@ static struct { · 33 unmodified lines
657683 unsigned char ClockingMode; /* Seq-Controller:01h */
658684 } vga_state;
659685
660−static void vga_vesa_blank(struct vgastate *state, int mode)
686+static void vga_vesa_blank(struct vgastate *state, enum vesa_blank_mode mode)
661687 {
662688 /* save original values of VGA controller registers */
663689 if (!vga_vesa_blanked) {
@@ -771,13 +797,14 @@ static void vga_pal_blank(struct vgastate *state) · 107 unmodified lines
771797 }
772798 }
773799
774−static int vgacon_blank(struct vc_data *c, int blank, int mode_switch)
800+static bool vgacon_blank(struct vc_data *c, enum vesa_blank_mode blank,
801+ bool mode_switch)
775802 {
776803 switch (blank) {
777− case 0: /* Unblank */
804+ case VESA_NO_BLANKING: /* Unblank */
778805 if (vga_vesa_blanked) {
779806 vga_vesa_unblank(&vgastate);
780− vga_vesa_blanked = 0;
807+ vga_vesa_blanked = VESA_NO_BLANKING;
781808 }
782809 if (vga_palette_blanked) {
783810 vga_set_palette(c, color_table);
@@ -787,8 +814,7 @@ static int vgacon_blank(struct vc_data *c, int blank, int mode_switch) · 3 unmodified lines
787814 vga_is_gfx = false;
788815 /* Tell console.c that it has to restore the screen itself */
789816 return 1;
790− case 1: /* Normal blanking */
791− case -1: /* Obsolete */
817+ case VESA_VSYNC_SUSPEND: /* Normal blanking */
792818 if (!mode_switch && vga_video_type == VIDEO_TYPE_VGAC) {
793819 vga_pal_blank(&vgastate);
794820 vga_palette_blanked = true;
@@ -1004,7 +1030,7 @@ static int vgacon_adjust_height(struct vc_data *vc, unsigned fontheight) · 209 unmodified lines
10041030 /* void size to cause regs to be rewritten */
10051031 cursor_size_lastfrom = 0;
10061032 cursor_size_lastto = 0;
1007− c->vc_sw->con_cursor(c, CM_DRAW);
1033+ c->vc_sw->con_cursor(c, true);
10081034 }
10091035 c->vc_font.height = c->vc_cell_height = fontheight;
10101036 vc_resize(c, 0, rows); /* Adjust console size */
@@ -1013,7 +1039,7 @@ static int vgacon_adjust_height(struct vc_data *vc, unsigned fontheight) · 2 unmodified lines
10131039 return 0;
10141040 }
10151041
1016−static int vgacon_font_set(struct vc_data *c, struct console_font *font,
1042+static int vgacon_font_set(struct vc_data *c, const struct console_font *font,
10171043 unsigned int vpitch, unsigned int flags)
10181044 {
10191045 unsigned charcount = font->charcount;
@@ -1049,12 +1075,12 @@ static int vgacon_font_get(struct vc_data *c, struct console_font *font, unsigne · 29 unmodified lines
10491075 }
10501076
10511077 static int vgacon_resize(struct vc_data *c, unsigned int width,
1052− unsigned int height, unsigned int user)
1078+ unsigned int height, bool from_user)
10531079 {
10541080 if ((width << 1) * height > vga_vram_size)
10551081 return -EINVAL;
10561082
1057− if (user) {
1083+ if (from_user) {
10581084 /*
10591085 * Ho ho! Someone (svgatextmode, eh?) may have reprogrammed
10601086 * the video mode! Set the new defaults then and go away.
@@ -1074,15 +1100,15 @@ static int vgacon_resize(struct vc_data *c, unsigned int width, · 13 unmodified lines
10741100 return 0;
10751101 }
10761102
1077−static int vgacon_set_origin(struct vc_data *c)
1103+static bool vgacon_set_origin(struct vc_data *c)
10781104 {
10791105 if (vga_is_gfx || /* We don't play origin tricks in graphic modes */
10801106 (console_blanked && !vga_palette_blanked)) /* Nor we write to blanked screens */
1081− return 0;
1107+ return false;
10821108 c->vc_origin = c->vc_visible_origin = vga_vram_base;
10831109 vga_set_mem_top(c);
10841110 vga_rolled_over = 0;
1085− return 1;
1111+ return true;
10861112 }
10871113
10881114 static void vgacon_save_screen(struct vc_data *c)
@@ -1159,11 +1185,10 @@ static bool vgacon_scroll(struct vc_data *c, unsigned int t, unsigned int b, · 70 unmodified lines
11591185 * The console `switch' structure for the VGA based console
11601186 */
11611187
1162−static void vgacon_clear(struct vc_data *vc, int sy, int sx, int height,
1163− int width) { }
1164−static void vgacon_putc(struct vc_data *vc, int c, int ypos, int xpos) { }
1165−static void vgacon_putcs(struct vc_data *vc, const unsigned short *s,
1166− int count, int ypos, int xpos) { }
1188+static void vgacon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
1189+ unsigned int width) { }
1190+static void vgacon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
1191+ unsigned int ypos, unsigned int xpos) { }
11671192
11681193 const struct consw vga_con = {
11691194 .owner = THIS_MODULE,
@@ -1171,7 +1196,6 @@ const struct consw vga_con = { · 1 unmodified line
11711196 .con_init = vgacon_init,
11721197 .con_deinit = vgacon_deinit,
11731198 .con_clear = vgacon_clear,
1174− .con_putc = vgacon_putc,
11751199 .con_putcs = vgacon_putcs,
11761200 .con_cursor = vgacon_cursor,
11771201 .con_scroll = vgacon_scroll,
drivers/video/fbdev/core/bitblit.c+2−11
@@ -233,7 +233,7 @@ static void bit_clear_margins(struct vc_data *vc, struct fb_info *info, · 232 unmodified lines
233233 }
234234 }
235235
236−static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
236+static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
237237 int fg, int bg)
238238 {
239239 struct fb_cursor cursor;
@@ -348,16 +348,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode, · 108 unmodified lines
348348 mask[i++] = msk;
349349 }
350350
351− switch (mode) {
352− case CM_ERASE:
353− ops->cursor_state.enable = 0;
354− break;
355− case CM_DRAW:
356− case CM_MOVE:
357− default:
358− ops->cursor_state.enable = (use_sw) ? 0 : 1;
359− break;
360− }
351+ ops->cursor_state.enable = enable && !use_sw;
361352
362353 cursor.image.data = src;
363354 cursor.image.fg_color = ops->cursor_state.image.fg_color;
drivers/video/fbdev/core/fbcon.c+44−79
@@ -351,7 +351,7 @@ static void fb_flashcursor(struct work_struct *work) · 350 unmodified lines
351351 struct fb_info *info;
352352 struct vc_data *vc = NULL;
353353 int c;
354− int mode;
354+ bool enable;
355355 int ret;
356356
357357 /* FIXME: we should sort out the unbind locking instead */
@@ -375,9 +375,8 @@ static void fb_flashcursor(struct work_struct *work) · 17 unmodified lines
375375 }
376376
377377 c = scr_readw((u16 *) vc->vc_pos);
378− mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
379− CM_ERASE : CM_DRAW;
380− ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
378+ enable = ops->cursor_flash && !ops->cursor_state.enable;
379+ ops->cursor(vc, info, enable, get_color(vc, info, c, 1),
381380 get_color(vc, info, c, 0));
382381 console_unlock();
383382
@@ -920,7 +919,7 @@ static void display_to_var(struct fb_var_screeninfo *var, · 536 unmodified lines
920919
921920 static const char *fbcon_startup(void)
922921 {
923− const char *display_desc = "frame buffer device";
922+ static const char display_desc[] = "frame buffer device";
924923 struct fbcon_display *p = &fb_display[fg_console];
925924 struct vc_data *vc = vc_cons[fg_console].d;
926925 const struct font_desc *font = NULL;
@@ -987,7 +986,7 @@ static const char *fbcon_startup(void) · 60 unmodified lines
987986 return display_desc;
988987 }
989988
990−static void fbcon_init(struct vc_data *vc, int init)
989+static void fbcon_init(struct vc_data *vc, bool init)
991990 {
992991 struct fb_info *info;
993992 struct fbcon_ops *ops;
@@ -1234,8 +1233,8 @@ finished: · 240 unmodified lines
12341233 * restriction is simplicity & efficiency at the moment.
12351234 */
12361235
1237−static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1238− int width)
1236+static void __fbcon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
1237+ unsigned int height, unsigned int width)
12391238 {
12401239 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
12411240 struct fbcon_ops *ops = info->fbcon_par;
@@ -1272,8 +1271,14 @@ static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, · 30 unmodified lines
12721271 ops->clear(vc, info, real_y(p, sy), sx, height, width);
12731272 }
12741273
1275−static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1276− int count, int ypos, int xpos)
1274+static void fbcon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
1275+ unsigned int width)
1276+{
1277+ __fbcon_clear(vc, sy, sx, 1, width);
1278+}
1279+
1280+static void fbcon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
1281+ unsigned int ypos, unsigned int xpos)
12771282 {
12781283 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
12791284 struct fbcon_display *p = &fb_display[vc->vc_num];
@@ -1285,14 +1290,6 @@ static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, · 5 unmodified lines
12851290 get_color(vc, info, scr_readw(s), 0));
12861291 }
12871292
1288−static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1289−{
1290− unsigned short chr;
1291−
1292− scr_writew(c, &chr);
1293− fbcon_putcs(vc, &chr, 1, ypos, xpos);
1294−}
1295−
12961293 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
12971294 {
12981295 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
@@ -1302,7 +1299,7 @@ static void fbcon_clear_margins(struct vc_data *vc, int bottom_only) · 3 unmodified lines
13021299 ops->clear_margins(vc, info, margin_color, bottom_only);
13031300 }
13041301
1305−static void fbcon_cursor(struct vc_data *vc, int mode)
1302+static void fbcon_cursor(struct vc_data *vc, bool enable)
13061303 {
13071304 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
13081305 struct fbcon_ops *ops = info->fbcon_par;
@@ -1318,12 +1315,12 @@ static void fbcon_cursor(struct vc_data *vc, int mode) · 9 unmodified lines
13181315 else
13191316 fbcon_add_cursor_work(info);
13201317
1321− ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1318+ ops->cursor_flash = enable;
13221319
13231320 if (!ops->cursor)
13241321 return;
13251322
1326− ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
1323+ ops->cursor(vc, info, enable, get_color(vc, info, c, 1),
13271324 get_color(vc, info, c, 0));
13281325 }
13291326
@@ -1743,7 +1740,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, · 413 unmodified lines
17431740 if (fbcon_is_inactive(vc, info))
17441741 return true;
17451742
1746− fbcon_cursor(vc, CM_ERASE);
1743+ fbcon_cursor(vc, false);
17471744
17481745 /*
17491746 * ++Geert: Only use ywrap/ypan if the console is in text mode
@@ -1759,7 +1756,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, · 9 unmodified lines
17591756 case SCROLL_MOVE:
17601757 fbcon_redraw_blit(vc, info, p, t, b - t - count,
17611758 count);
1762− fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1759+ __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
17631760 scr_memsetw((unsigned short *) (vc->vc_origin +
17641761 vc->vc_size_row *
17651762 (b - count)),
@@ -1782,7 +1779,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, · 16 unmodified lines
17821779 b - t - count, vc->vc_cols);
17831780 else
17841781 goto redraw_up;
1785− fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1782+ __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
17861783 break;
17871784
17881785 case SCROLL_PAN_REDRAW:
@@ -1800,7 +1797,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, · 11 unmodified lines
18001797 vc->vc_rows - b, b);
18011798 } else
18021799 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1803− fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1800+ __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
18041801 break;
18051802
18061803 case SCROLL_PAN_MOVE:
@@ -1823,14 +1820,14 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, · 16 unmodified lines
18231820 b - t - count, vc->vc_cols);
18241821 else
18251822 goto redraw_up;
1826− fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1823+ __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
18271824 break;
18281825
18291826 case SCROLL_REDRAW:
18301827 redraw_up:
18311828 fbcon_redraw(vc, t, b - t - count,
18321829 count * vc->vc_cols);
1833− fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1830+ __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
18341831 scr_memsetw((unsigned short *) (vc->vc_origin +
18351832 vc->vc_size_row *
18361833 (b - count)),
@@ -1847,7 +1844,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, · 10 unmodified lines
18471844 case SCROLL_MOVE:
18481845 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
18491846 -count);
1850− fbcon_clear(vc, t, 0, count, vc->vc_cols);
1847+ __fbcon_clear(vc, t, 0, count, vc->vc_cols);
18511848 scr_memsetw((unsigned short *) (vc->vc_origin +
18521849 vc->vc_size_row *
18531850 t),
@@ -1870,7 +1867,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, · 16 unmodified lines
18701867 b - t - count, vc->vc_cols);
18711868 else
18721869 goto redraw_down;
1873− fbcon_clear(vc, t, 0, count, vc->vc_cols);
1870+ __fbcon_clear(vc, t, 0, count, vc->vc_cols);
18741871 break;
18751872
18761873 case SCROLL_PAN_MOVE:
@@ -1892,7 +1889,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, · 15 unmodified lines
18921889 b - t - count, vc->vc_cols);
18931890 else
18941891 goto redraw_down;
1895− fbcon_clear(vc, t, 0, count, vc->vc_cols);
1892+ __fbcon_clear(vc, t, 0, count, vc->vc_cols);
18961893 break;
18971894
18981895 case SCROLL_PAN_REDRAW:
@@ -1909,14 +1906,14 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, · 10 unmodified lines
19091906 fbcon_redraw_move(vc, p, count, t, 0);
19101907 } else
19111908 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1912− fbcon_clear(vc, t, 0, count, vc->vc_cols);
1909+ __fbcon_clear(vc, t, 0, count, vc->vc_cols);
19131910 break;
19141911
19151912 case SCROLL_REDRAW:
19161913 redraw_down:
19171914 fbcon_redraw(vc, b - 1, b - t - count,
19181915 -count * vc->vc_cols);
1919− fbcon_clear(vc, t, 0, count, vc->vc_cols);
1916+ __fbcon_clear(vc, t, 0, count, vc->vc_cols);
19201917 scr_memsetw((unsigned short *) (vc->vc_origin +
19211918 vc->vc_size_row *
19221919 t),
@@ -1995,7 +1992,7 @@ static void updatescrollmode(struct fbcon_display *p, · 72 unmodified lines
19951992 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
19961993
19971994 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1998− unsigned int height, unsigned int user)
1995+ unsigned int height, bool from_user)
19991996 {
20001997 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
20011998 struct fbcon_ops *ops = info->fbcon_par;
@@ -2058,7 +2055,7 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width, · 56 unmodified lines
20582055 return 0;
20592056 }
20602057
2061−static int fbcon_switch(struct vc_data *vc)
2058+static bool fbcon_switch(struct vc_data *vc)
20622059 {
20632060 struct fb_info *info, *old_info = NULL;
20642061 struct fbcon_ops *ops;
@@ -2180,9 +2177,9 @@ static int fbcon_switch(struct vc_data *vc) · 115 unmodified lines
21802177 vc->vc_origin + vc->vc_size_row * vc->vc_top,
21812178 vc->vc_size_row * (vc->vc_bottom -
21822179 vc->vc_top) / 2);
2183− return 0;
2180+ return false;
21842181 }
2185− return 1;
2182+ return true;
21862183 }
21872184
21882185 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
@@ -2195,12 +2192,13 @@ static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info, · 6 unmodified lines
21952192
21962193 oldc = vc->vc_video_erase_char;
21972194 vc->vc_video_erase_char &= charmask;
2198− fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2195+ __fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
21992196 vc->vc_video_erase_char = oldc;
22002197 }
22012198 }
22022199
2203−static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2200+static bool fbcon_blank(struct vc_data *vc, enum vesa_blank_mode blank,
2201+ bool mode_switch)
22042202 {
22052203 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
22062204 struct fbcon_ops *ops = info->fbcon_par;
@@ -2222,7 +2220,7 @@ static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch) · 15 unmodified lines
22222220 if (!fbcon_is_inactive(vc, info)) {
22232221 if (ops->blank_state != blank) {
22242222 ops->blank_state = blank;
2225− fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2223+ fbcon_cursor(vc, !blank);
22262224 ops->cursor_flash = (!blank);
22272225
22282226 if (fb_blank(info, blank))
@@ -2239,10 +2237,10 @@ static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch) · 10 unmodified lines
22392237 else
22402238 fbcon_add_cursor_work(info);
22412239
2242− return 0;
2240+ return false;
22432241 }
22442242
2245−static int fbcon_debug_enter(struct vc_data *vc)
2243+static void fbcon_debug_enter(struct vc_data *vc)
22462244 {
22472245 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
22482246 struct fbcon_ops *ops = info->fbcon_par;
@@ -2252,10 +2250,9 @@ static int fbcon_debug_enter(struct vc_data *vc) · 3 unmodified lines
22522250 if (info->fbops->fb_debug_enter)
22532251 info->fbops->fb_debug_enter(info);
22542252 fbcon_set_palette(vc, color_table);
2255− return 0;
22562253 }
22572254
2258−static int fbcon_debug_leave(struct vc_data *vc)
2255+static void fbcon_debug_leave(struct vc_data *vc)
22592256 {
22602257 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
22612258 struct fbcon_ops *ops = info->fbcon_par;
@@ -2263,7 +2260,6 @@ static int fbcon_debug_leave(struct vc_data *vc) · 1 unmodified line
22632260 ops->graphics = ops->save_graphics;
22642261 if (info->fbops->fb_debug_leave)
22652262 info->fbops->fb_debug_leave(info);
2266− return 0;
22672263 }
22682264
22692265 static int fbcon_get_font(struct vc_data *vc, struct console_font *font, unsigned int vpitch)
@@ -2461,7 +2457,7 @@ err_out: · 191 unmodified lines
24612457 * but lets not assume that, since charcount of 512 is small for unicode support.
24622458 */
24632459
2464−static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2460+static int fbcon_set_font(struct vc_data *vc, const struct console_font *font,
24652461 unsigned int vpitch, unsigned int flags)
24662462 {
24672463 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
@@ -2534,7 +2530,8 @@ static int fbcon_set_font(struct vc_data *vc, struct console_font *font, · 66 unmodified lines
25342530 return fbcon_do_set_font(vc, font->width, font->height, charcount, new_data, 1);
25352531 }
25362532
2537−static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2533+static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font,
2534+ const char *name)
25382535 {
25392536 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
25402537 const struct font_desc *f;
@@ -2593,35 +2590,6 @@ static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table) · 52 unmodified lines
25932590 fb_set_cmap(&palette_cmap, info);
25942591 }
25952592
2596−static u16 *fbcon_screen_pos(const struct vc_data *vc, int offset)
2597−{
2598− return (u16 *) (vc->vc_origin + offset);
2599−}
2600−
2601−static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2602− int *px, int *py)
2603−{
2604− unsigned long ret;
2605− int x, y;
2606−
2607− if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2608− unsigned long offset = (pos - vc->vc_origin) / 2;
2609−
2610− x = offset % vc->vc_cols;
2611− y = offset / vc->vc_cols;
2612− ret = pos + (vc->vc_cols - x) * 2;
2613− } else {
2614− /* Should not happen */
2615− x = y = 0;
2616− ret = vc->vc_origin;
2617− }
2618− if (px)
2619− *px = x;
2620− if (py)
2621− *py = y;
2622− return ret;
2623−}
2624−
26252593 /* As we might be inside of softback, we may work with non-contiguous buffer,
26262594 that's why we have to use a separate routine. */
26272595 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
@@ -2650,7 +2618,7 @@ void fbcon_suspended(struct fb_info *info) · 22 unmodified lines
26502618 vc = vc_cons[ops->currcon].d;
26512619
26522620 /* Clear cursor, restore saved data */
2653− fbcon_cursor(vc, CM_ERASE);
2621+ fbcon_cursor(vc, false);
26542622 }
26552623
26562624 void fbcon_resumed(struct fb_info *info)
@@ -3152,7 +3120,6 @@ static const struct consw fb_con = { · 495 unmodified lines
31523120 .con_init = fbcon_init,
31533121 .con_deinit = fbcon_deinit,
31543122 .con_clear = fbcon_clear,
3155− .con_putc = fbcon_putc,
31563123 .con_putcs = fbcon_putcs,
31573124 .con_cursor = fbcon_cursor,
31583125 .con_scroll = fbcon_scroll,
@@ -3163,8 +3130,6 @@ static const struct consw fb_con = { · 4 unmodified lines
31633130 .con_font_default = fbcon_set_def_font,
31643131 .con_set_palette = fbcon_set_palette,
31653132 .con_invert_region = fbcon_invert_region,
3166− .con_screen_pos = fbcon_screen_pos,
3167− .con_getxy = fbcon_getxy,
31683133 .con_resize = fbcon_resize,
31693134 .con_debug_enter = fbcon_debug_enter,
31703135 .con_debug_leave = fbcon_debug_leave,
drivers/video/fbdev/core/fbcon.h+2−2
@@ -61,8 +61,8 @@ struct fbcon_ops { · 60 unmodified lines
6161 int fg, int bg);
6262 void (*clear_margins)(struct vc_data *vc, struct fb_info *info,
6363 int color, int bottom_only);
64− void (*cursor)(struct vc_data *vc, struct fb_info *info, int mode,
65− int fg, int bg);
64+ void (*cursor)(struct vc_data *vc, struct fb_info *info,
65+ bool enable, int fg, int bg);
6666 int (*update_start)(struct fb_info *info);
6767 int (*rotate_font)(struct fb_info *info, struct vc_data *vc);
6868 struct fb_var_screeninfo var; /* copy of the current fb_var_screeninfo */
drivers/video/fbdev/core/fbcon_ccw.c+2−11
@@ -218,7 +218,7 @@ static void ccw_clear_margins(struct vc_data *vc, struct fb_info *info, · 217 unmodified lines
218218 }
219219 }
220220
221−static void ccw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
221+static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
222222 int fg, int bg)
223223 {
224224 struct fb_cursor cursor;
@@ -349,16 +349,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, int mode, · 124 unmodified lines
349349 kfree(tmp);
350350 }
351351
352− switch (mode) {
353− case CM_ERASE:
354− ops->cursor_state.enable = 0;
355− break;
356− case CM_DRAW:
357− case CM_MOVE:
358− default:
359− ops->cursor_state.enable = (use_sw) ? 0 : 1;
360− break;
361− }
352+ ops->cursor_state.enable = enable && !use_sw;
362353
363354 cursor.image.data = src;
364355 cursor.image.fg_color = ops->cursor_state.image.fg_color;
drivers/video/fbdev/core/fbcon_cw.c+2−11
@@ -201,7 +201,7 @@ static void cw_clear_margins(struct vc_data *vc, struct fb_info *info, · 200 unmodified lines
201201 }
202202 }
203203
204−static void cw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
204+static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
205205 int fg, int bg)
206206 {
207207 struct fb_cursor cursor;
@@ -332,16 +332,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, int mode, · 124 unmodified lines
332332 kfree(tmp);
333333 }
334334
335− switch (mode) {
336− case CM_ERASE:
337− ops->cursor_state.enable = 0;
338− break;
339− case CM_DRAW:
340− case CM_MOVE:
341− default:
342− ops->cursor_state.enable = (use_sw) ? 0 : 1;
343− break;
344− }
335+ ops->cursor_state.enable = enable && !use_sw;
345336
346337 cursor.image.data = src;
347338 cursor.image.fg_color = ops->cursor_state.image.fg_color;
drivers/video/fbdev/core/fbcon_ud.c+2−11
@@ -248,7 +248,7 @@ static void ud_clear_margins(struct vc_data *vc, struct fb_info *info, · 247 unmodified lines
248248 }
249249 }
250250
251−static void ud_cursor(struct vc_data *vc, struct fb_info *info, int mode,
251+static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
252252 int fg, int bg)
253253 {
254254 struct fb_cursor cursor;
@@ -372,16 +372,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, int mode, · 117 unmodified lines
372372 mask[i++] = ~msk;
373373 }
374374
375− switch (mode) {
376− case CM_ERASE:
377− ops->cursor_state.enable = 0;
378− break;
379− case CM_DRAW:
380− case CM_MOVE:
381− default:
382− ops->cursor_state.enable = (use_sw) ? 0 : 1;
383− break;
384− }
375+ ops->cursor_state.enable = enable && !use_sw;
385376
386377 cursor.image.data = src;
387378 cursor.image.fg_color = ops->cursor_state.image.fg_color;
drivers/video/fbdev/core/tileblit.c+2−2
@@ -79,7 +79,7 @@ static void tile_clear_margins(struct vc_data *vc, struct fb_info *info, · 78 unmodified lines
7979 return;
8080 }
8181
82−static void tile_cursor(struct vc_data *vc, struct fb_info *info, int mode,
82+static void tile_cursor(struct vc_data *vc, struct fb_info *info, bool enable,
8383 int fg, int bg)
8484 {
8585 struct fb_tilecursor cursor;
@@ -87,7 +87,7 @@ static void tile_cursor(struct vc_data *vc, struct fb_info *info, int mode, · 1 unmodified line
8787
8888 cursor.sx = vc->state.x;
8989 cursor.sy = vc->state.y;
90− cursor.mode = (mode == CM_ERASE || use_sw) ? 0 : 1;
90+ cursor.mode = enable && !use_sw;
9191 cursor.fg = fg;
9292 cursor.bg = bg;
9393
drivers/video/fbdev/tgafb.c+1−1
@@ -380,7 +380,7 @@ tgafb_set_par(struct fb_info *info) · 379 unmodified lines
380380 BT463_LOAD_ADDR(par, 0x0000);
381381 TGA_WRITE_REG(par, BT463_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
382382
383−#ifdef CONFIG_HW_CONSOLE
383+#ifdef CONFIG_VT
384384 for (i = 0; i < 16; i++) {
385385 int j = color_table[i];
386386
drivers/w1/masters/Kconfig+10−0
@@ -78,5 +78,15 @@ config W1_MASTER_SGI · 77 unmodified lines
7878 This support is also available as a module. If so, the module
7979 will be called sgi_w1.
8080
81+config W1_MASTER_UART
82+ tristate "UART 1-wire driver"
83+ depends on SERIAL_DEV_BUS
84+ help
85+ Say Y here if you want to communicate with your 1-wire devices using
86+ UART interface.
87+
88+ This support is also available as a module. If so, the module
89+ will be called w1-uart.
90+
8191 endmenu
8292
drivers/w1/masters/Makefile+1−0
@@ -12,3 +12,4 @@ obj-$(CONFIG_W1_MASTER_MXC) += mxc_w1.o · 11 unmodified lines
1212 obj-$(CONFIG_W1_MASTER_GPIO) += w1-gpio.o
1313 obj-$(CONFIG_HDQ_MASTER_OMAP) += omap_hdq.o
1414 obj-$(CONFIG_W1_MASTER_SGI) += sgi_w1.o
15+obj-$(CONFIG_W1_MASTER_UART) += w1-uart.o
drivers/w1/masters/mxc_w1.c+2−4
@@ -151,15 +151,13 @@ out_disable_clk: · 150 unmodified lines
151151 /*
152152 * disassociate the w1 device from the driver
153153 */
154−static int mxc_w1_remove(struct platform_device *pdev)
154+static void mxc_w1_remove(struct platform_device *pdev)
155155 {
156156 struct mxc_w1_device *mdev = platform_get_drvdata(pdev);
157157
158158 w1_remove_master_device(&mdev->bus_master);
159159
160160 clk_disable_unprepare(mdev->clk);
161−
162− return 0;
163161 }
164162
165163 static const struct of_device_id mxc_w1_dt_ids[] = {
@@ -174,7 +172,7 @@ static struct platform_driver mxc_w1_driver = { · 8 unmodified lines
174172 .of_match_table = mxc_w1_dt_ids,
175173 },
176174 .probe = mxc_w1_probe,
177− .remove = mxc_w1_remove,
175+ .remove_new = mxc_w1_remove,
178176 };
179177 module_platform_driver(mxc_w1_driver);
180178
drivers/w1/masters/omap_hdq.c+2−4
@@ -647,7 +647,7 @@ err_w1: · 646 unmodified lines
647647 return ret;
648648 }
649649
650−static int omap_hdq_remove(struct platform_device *pdev)
650+static void omap_hdq_remove(struct platform_device *pdev)
651651 {
652652 int active;
653653
@@ -661,8 +661,6 @@ static int omap_hdq_remove(struct platform_device *pdev) · 7 unmodified lines
661661 if (active >= 0)
662662 pm_runtime_put_sync(&pdev->dev);
663663 pm_runtime_disable(&pdev->dev);
664−
665− return 0;
666664 }
667665
668666 static const struct of_device_id omap_hdq_dt_ids[] = {
@@ -674,7 +672,7 @@ MODULE_DEVICE_TABLE(of, omap_hdq_dt_ids); · 5 unmodified lines
674672
675673 static struct platform_driver omap_hdq_driver = {
676674 .probe = omap_hdq_probe,
677− .remove = omap_hdq_remove,
675+ .remove_new = omap_hdq_remove,
678676 .driver = {
679677 .name = "omap_hdq",
680678 .of_match_table = omap_hdq_dt_ids,
drivers/w1/masters/sgi_w1.c+2−4
@@ -105,13 +105,11 @@ static int sgi_w1_probe(struct platform_device *pdev) · 104 unmodified lines
105105 /*
106106 * disassociate the w1 device from the driver
107107 */
108−static int sgi_w1_remove(struct platform_device *pdev)
108+static void sgi_w1_remove(struct platform_device *pdev)
109109 {
110110 struct sgi_w1_device *sdev = platform_get_drvdata(pdev);
111111
112112 w1_remove_master_device(&sdev->bus_master);
113−
114− return 0;
115113 }
116114
117115 static struct platform_driver sgi_w1_driver = {
@@ -119,7 +117,7 @@ static struct platform_driver sgi_w1_driver = { · 1 unmodified line
119117 .name = "sgi_w1",
120118 },
121119 .probe = sgi_w1_probe,
122− .remove = sgi_w1_remove,
120+ .remove_new = sgi_w1_remove,
123121 };
124122 module_platform_driver(sgi_w1_driver);
125123
drivers/w1/masters/w1-gpio.c+2−4
@@ -141,7 +141,7 @@ static int w1_gpio_probe(struct platform_device *pdev) · 140 unmodified lines
141141 return 0;
142142 }
143143
144−static int w1_gpio_remove(struct platform_device *pdev)
144+static void w1_gpio_remove(struct platform_device *pdev)
145145 {
146146 struct w1_bus_master *master = platform_get_drvdata(pdev);
147147 struct w1_gpio_ddata *ddata = master->data;
@@ -150,8 +150,6 @@ static int w1_gpio_remove(struct platform_device *pdev) · 2 unmodified lines
150150 gpiod_set_value(ddata->pullup_gpiod, 0);
151151
152152 w1_remove_master_device(master);
153−
154− return 0;
155153 }
156154
157155 static struct platform_driver w1_gpio_driver = {
@@ -160,7 +158,7 @@ static struct platform_driver w1_gpio_driver = { · 2 unmodified lines
160158 .of_match_table = of_match_ptr(w1_gpio_dt_ids),
161159 },
162160 .probe = w1_gpio_probe,
163− .remove = w1_gpio_remove,
161+ .remove_new = w1_gpio_remove,
164162 };
165163
166164 module_platform_driver(w1_gpio_driver);
drivers/w1/masters/w1-uart.c+415−0
@@ -0,0 +1,415 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * w1-uart - UART 1-Wire bus driver
4+ *
5+ * Uses the UART interface (via Serial Device Bus) to create the 1-Wire
6+ * timing patterns. Implements the following 1-Wire master interface:
7+ *
8+ * - reset_bus: requests baud-rate 9600
9+ *
10+ * - touch_bit: requests baud-rate 115200
11+ *
12+ * Author: Christoph Winklhofer <cj.winklhofer@gmail.com>
13+ */
14+
15+#include <linux/completion.h>
16+#include <linux/delay.h>
17+#include <linux/jiffies.h>
18+#include <linux/module.h>
19+#include <linux/mutex.h>
20+#include <linux/of.h>
21+#include <linux/serdev.h>
22+#include <linux/w1.h>
23+
24+/* UART packet contains start and stop bit */
25+#define W1_UART_BITS_PER_PACKET (BITS_PER_BYTE + 2)
26+
27+/* Timeout to wait for completion of serdev-receive */
28+#define W1_UART_TIMEOUT msecs_to_jiffies(500)
29+
30+/**
31+ * struct w1_uart_config - configuration for 1-Wire operation
32+ * @baudrate: baud-rate returned from serdev
33+ * @delay_us: delay to complete a 1-Wire cycle (in us)
34+ * @tx_byte: byte to generate 1-Wire timing pattern
35+ */
36+struct w1_uart_config {
37+ unsigned int baudrate;
38+ unsigned int delay_us;
39+ u8 tx_byte;
40+};
41+
42+/**
43+ * struct w1_uart_device - 1-Wire UART device structure
44+ * @serdev: serial device
45+ * @bus: w1-bus master
46+ * @cfg_reset: config for 1-Wire reset
47+ * @cfg_touch_0: config for 1-Wire write-0 cycle
48+ * @cfg_touch_1: config for 1-Wire write-1 and read cycle
49+ * @rx_byte_received: completion for serdev receive
50+ * @rx_mutex: mutex to protect rx_err and rx_byte
51+ * @rx_err: indicates an error in serdev-receive
52+ * @rx_byte: result byte from serdev-receive
53+ */
54+struct w1_uart_device {
55+ struct serdev_device *serdev;
56+ struct w1_bus_master bus;
57+
58+ struct w1_uart_config cfg_reset;
59+ struct w1_uart_config cfg_touch_0;
60+ struct w1_uart_config cfg_touch_1;
61+
62+ struct completion rx_byte_received;
63+ /*
64+ * protect rx_err and rx_byte from concurrent access in
65+ * w1-callbacks and serdev-receive.
66+ */
67+ struct mutex rx_mutex;
68+ int rx_err;
69+ u8 rx_byte;
70+};
71+
72+/**
73+ * struct w1_uart_limits - limits for 1-Wire operations
74+ * @baudrate: Requested baud-rate to create 1-Wire timing pattern
75+ * @bit_min_us: minimum time for a bit (in us)
76+ * @bit_max_us: maximum time for a bit (in us)
77+ * @sample_us: timespan to sample 1-Wire response
78+ * @cycle_us: duration of the 1-Wire cycle
79+ */
80+struct w1_uart_limits {
81+ unsigned int baudrate;
82+ unsigned int bit_min_us;
83+ unsigned int bit_max_us;
84+ unsigned int sample_us;
85+ unsigned int cycle_us;
86+};
87+
88+static inline unsigned int baud_to_bit_ns(unsigned int baud)
89+{
90+ return NSEC_PER_SEC / baud;
91+}
92+
93+static inline unsigned int to_ns(unsigned int us)
94+{
95+ return us * NSEC_PER_USEC;
96+}
97+
98+/*
99+ * Set baud-rate, delay and tx-byte to create a 1-Wire pulse and adapt
100+ * the tx-byte according to the actual baud-rate.
101+ *
102+ * Reject when:
103+ * - time for a bit outside min/max range
104+ * - a 1-Wire response is not detectable for sent byte
105+ */
106+static int w1_uart_set_config(struct serdev_device *serdev,
107+ const struct w1_uart_limits *limits,
108+ struct w1_uart_config *w1cfg)
109+{
110+ unsigned int packet_ns;
111+ unsigned int bits_low;
112+ unsigned int bit_ns;
113+ unsigned int low_ns;
114+
115+ w1cfg->baudrate = serdev_device_set_baudrate(serdev, limits->baudrate);
116+ if (w1cfg->baudrate == 0)
117+ return -EINVAL;
118+
119+ /* Compute in nanoseconds for accuracy */
120+ bit_ns = baud_to_bit_ns(w1cfg->baudrate);
121+ bits_low = to_ns(limits->bit_min_us) / bit_ns;
122+ /* start bit is always low */
123+ low_ns = bit_ns * (bits_low + 1);
124+
125+ if (low_ns < to_ns(limits->bit_min_us))
126+ return -EINVAL;
127+
128+ if (low_ns > to_ns(limits->bit_max_us))
129+ return -EINVAL;
130+
131+ /* 1-Wire response detectable for sent byte */
132+ if (limits->sample_us > 0 &&
133+ bit_ns * BITS_PER_BYTE < low_ns + to_ns(limits->sample_us))
134+ return -EINVAL;
135+
136+ /* delay: 1-Wire cycle takes longer than the UART packet */
137+ packet_ns = bit_ns * W1_UART_BITS_PER_PACKET;
138+ w1cfg->delay_us = 0;
139+ if (to_ns(limits->cycle_us) > packet_ns)
140+ w1cfg->delay_us =
141+ (to_ns(limits->cycle_us) - packet_ns) / NSEC_PER_USEC;
142+
143+ /* byte to create 1-Wire pulse */
144+ w1cfg->tx_byte = 0xff << bits_low;
145+
146+ return 0;
147+}
148+
149+/*
150+ * Configuration for reset and presence detect
151+ * - bit_min_us is 480us, add margin and use 485us
152+ * - limits for sample time 60us-75us, use 65us
153+ */
154+static int w1_uart_set_config_reset(struct w1_uart_device *w1dev)
155+{
156+ struct serdev_device *serdev = w1dev->serdev;
157+ struct device_node *np = serdev->dev.of_node;
158+
159+ struct w1_uart_limits limits = { .baudrate = 9600,
160+ .bit_min_us = 485,
161+ .bit_max_us = 640,
162+ .sample_us = 65,
163+ .cycle_us = 960 };
164+
165+ of_property_read_u32(np, "reset-bps", &limits.baudrate);
166+
167+ return w1_uart_set_config(serdev, &limits, &w1dev->cfg_reset);
168+}
169+
170+/*
171+ * Configuration for write-0 cycle (touch bit 0)
172+ * - bit_min_us is 60us, add margin and use 65us
173+ * - no sampling required, sample_us = 0
174+ */
175+static int w1_uart_set_config_touch_0(struct w1_uart_device *w1dev)
176+{
177+ struct serdev_device *serdev = w1dev->serdev;
178+ struct device_node *np = serdev->dev.of_node;
179+
180+ struct w1_uart_limits limits = { .baudrate = 115200,
181+ .bit_min_us = 65,
182+ .bit_max_us = 120,
183+ .sample_us = 0,
184+ .cycle_us = 70 };
185+
186+ of_property_read_u32(np, "write-0-bps", &limits.baudrate);
187+
188+ return w1_uart_set_config(serdev, &limits, &w1dev->cfg_touch_0);
189+}
190+
191+/*
192+ * Configuration for write-1 and read cycle (touch bit 1)
193+ * - bit_min_us is 5us, add margin and use 6us
194+ * - limits for sample time 5us-15us, use 15us
195+ */
196+static int w1_uart_set_config_touch_1(struct w1_uart_device *w1dev)
197+{
198+ struct serdev_device *serdev = w1dev->serdev;
199+ struct device_node *np = serdev->dev.of_node;
200+
201+ struct w1_uart_limits limits = { .baudrate = 115200,
202+ .bit_min_us = 6,
203+ .bit_max_us = 15,
204+ .sample_us = 15,
205+ .cycle_us = 70 };
206+
207+ of_property_read_u32(np, "write-1-bps", &limits.baudrate);
208+
209+ return w1_uart_set_config(serdev, &limits, &w1dev->cfg_touch_1);
210+}
211+
212+/*
213+ * Configure and open the serial device
214+ */
215+static int w1_uart_serdev_open(struct w1_uart_device *w1dev)
216+{
217+ struct serdev_device *serdev = w1dev->serdev;
218+ struct device *dev = &serdev->dev;
219+ int ret;
220+
221+ ret = devm_serdev_device_open(dev, serdev);
222+ if (ret < 0)
223+ return ret;
224+
225+ ret = serdev_device_set_parity(serdev, SERDEV_PARITY_NONE);
226+ if (ret < 0) {
227+ dev_err(dev, "set parity failed\n");
228+ return ret;
229+ }
230+
231+ ret = w1_uart_set_config_reset(w1dev);
232+ if (ret < 0) {
233+ dev_err(dev, "config for reset failed\n");
234+ return ret;
235+ }
236+
237+ ret = w1_uart_set_config_touch_0(w1dev);
238+ if (ret < 0) {
239+ dev_err(dev, "config for touch-0 failed\n");
240+ return ret;
241+ }
242+
243+ ret = w1_uart_set_config_touch_1(w1dev);
244+ if (ret < 0) {
245+ dev_err(dev, "config for touch-1 failed\n");
246+ return ret;
247+ }
248+
249+ serdev_device_set_flow_control(serdev, false);
250+
251+ return 0;
252+}
253+
254+/*
255+ * Send one byte (tx_byte) and read one byte (rx_byte) via serdev.
256+ */
257+static int w1_uart_serdev_tx_rx(struct w1_uart_device *w1dev,
258+ const struct w1_uart_config *w1cfg, u8 *rx_byte)
259+{
260+ struct serdev_device *serdev = w1dev->serdev;
261+ int ret;
262+
263+ serdev_device_write_flush(serdev);
264+ serdev_device_set_baudrate(serdev, w1cfg->baudrate);
265+
266+ /* write and immediately read one byte */
267+ reinit_completion(&w1dev->rx_byte_received);
268+ ret = serdev_device_write_buf(serdev, &w1cfg->tx_byte, 1);
269+ if (ret != 1)
270+ return -EIO;
271+ ret = wait_for_completion_interruptible_timeout(
272+ &w1dev->rx_byte_received, W1_UART_TIMEOUT);
273+ if (ret <= 0)
274+ return -EIO;
275+
276+ /* locking could fail when serdev is unexpectedly receiving. */
277+ if (!mutex_trylock(&w1dev->rx_mutex))
278+ return -EIO;
279+
280+ ret = w1dev->rx_err;
281+ if (ret == 0)
282+ *rx_byte = w1dev->rx_byte;
283+
284+ mutex_unlock(&w1dev->rx_mutex);
285+
286+ if (w1cfg->delay_us > 0)
287+ fsleep(w1cfg->delay_us);
288+
289+ return ret;
290+}
291+
292+static size_t w1_uart_serdev_receive_buf(struct serdev_device *serdev,
293+ const u8 *buf, size_t count)
294+{
295+ struct w1_uart_device *w1dev = serdev_device_get_drvdata(serdev);
296+
297+ mutex_lock(&w1dev->rx_mutex);
298+
299+ /* sent a single byte and receive one single byte */
300+ if (count == 1) {
301+ w1dev->rx_byte = buf[0];
302+ w1dev->rx_err = 0;
303+ } else {
304+ w1dev->rx_err = -EIO;
305+ }
306+
307+ mutex_unlock(&w1dev->rx_mutex);
308+ complete(&w1dev->rx_byte_received);
309+
310+ return count;
311+}
312+
313+static const struct serdev_device_ops w1_uart_serdev_ops = {
314+ .receive_buf = w1_uart_serdev_receive_buf,
315+ .write_wakeup = serdev_device_write_wakeup,
316+};
317+
318+/*
319+ * 1-wire reset and presence detect: A present slave will manipulate
320+ * the received byte by pulling the 1-Wire low.
321+ */
322+static u8 w1_uart_reset_bus(void *data)
323+{
324+ struct w1_uart_device *w1dev = data;
325+ const struct w1_uart_config *w1cfg = &w1dev->cfg_reset;
326+ int ret;
327+ u8 val;
328+
329+ ret = w1_uart_serdev_tx_rx(w1dev, w1cfg, &val);
330+ if (ret < 0)
331+ return -1;
332+
333+ /* Device present (0) or no device (1) */
334+ return val != w1cfg->tx_byte ? 0 : 1;
335+}
336+
337+/*
338+ * 1-Wire read and write cycle: Only the read-0 manipulates the
339+ * received byte, all others left the line untouched.
340+ */
341+static u8 w1_uart_touch_bit(void *data, u8 bit)
342+{
343+ struct w1_uart_device *w1dev = data;
344+ const struct w1_uart_config *w1cfg = bit ? &w1dev->cfg_touch_1 :
345+ &w1dev->cfg_touch_0;
346+ int ret;
347+ u8 val;
348+
349+ ret = w1_uart_serdev_tx_rx(w1dev, w1cfg, &val);
350+
351+ /* return inactive bus state on error */
352+ if (ret < 0)
353+ return 1;
354+
355+ return val == w1cfg->tx_byte ? 1 : 0;
356+}
357+
358+static int w1_uart_probe(struct serdev_device *serdev)
359+{
360+ struct device *dev = &serdev->dev;
361+ struct w1_uart_device *w1dev;
362+ int ret;
363+
364+ w1dev = devm_kzalloc(dev, sizeof(*w1dev), GFP_KERNEL);
365+ if (!w1dev)
366+ return -ENOMEM;
367+ w1dev->bus.data = w1dev;
368+ w1dev->bus.reset_bus = w1_uart_reset_bus;
369+ w1dev->bus.touch_bit = w1_uart_touch_bit;
370+ w1dev->serdev = serdev;
371+
372+ init_completion(&w1dev->rx_byte_received);
373+ mutex_init(&w1dev->rx_mutex);
374+
375+ ret = w1_uart_serdev_open(w1dev);
376+ if (ret < 0)
377+ return ret;
378+ serdev_device_set_drvdata(serdev, w1dev);
379+ serdev_device_set_client_ops(serdev, &w1_uart_serdev_ops);
380+
381+ return w1_add_master_device(&w1dev->bus);
382+}
383+
384+static void w1_uart_remove(struct serdev_device *serdev)
385+{
386+ struct w1_uart_device *w1dev = serdev_device_get_drvdata(serdev);
387+
388+ /*
389+ * Waits until w1-uart callbacks are finished, serdev is closed
390+ * and its device data released automatically by devres (waits
391+ * until serdev-receive is finished).
392+ */
393+ w1_remove_master_device(&w1dev->bus);
394+}
395+
396+static const struct of_device_id w1_uart_of_match[] = {
397+ { .compatible = "w1-uart" },
398+ {},
399+};
400+MODULE_DEVICE_TABLE(of, w1_uart_of_match);
401+
402+static struct serdev_device_driver w1_uart_driver = {
403+ .driver = {
404+ .name = "w1-uart",
405+ .of_match_table = w1_uart_of_match,
406+ },
407+ .probe = w1_uart_probe,
408+ .remove = w1_uart_remove,
409+};
410+
411+module_serdev_device_driver(w1_uart_driver);
412+
413+MODULE_DESCRIPTION("UART w1 bus driver");
414+MODULE_AUTHOR("Christoph Winklhofer <cj.winklhofer@gmail.com>");
415+MODULE_LICENSE("GPL");
drivers/w1/w1.c+1−1
@@ -167,7 +167,7 @@ static struct w1_family w1_default_family = { · 166 unmodified lines
167167
168168 static int w1_uevent(const struct device *dev, struct kobj_uevent_env *env);
169169
170−static struct bus_type w1_bus_type = {
170+static const struct bus_type w1_bus_type = {
171171 .name = "w1",
172172 .uevent = w1_uevent,
173173 };
include/linux/console.h+69−57
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 #include <linux/bits.h>
1919 #include <linux/rculist.h>
2020 #include <linux/types.h>
21+#include <linux/vesa.h>
2122
2223 struct vc_data;
2324 struct console_font_op;
@@ -36,63 +37,91 @@ enum vc_intensity; · 12 unmodified lines
3637 /**
3738 * struct consw - callbacks for consoles
3839 *
40+ * @owner: the module to get references of when this console is used
41+ * @con_startup: set up the console and return its name (like VGA, EGA, ...)
42+ * @con_init: initialize the console on @vc. @init is true for the very first
43+ * call on this @vc.
44+ * @con_deinit: deinitialize the console from @vc.
45+ * @con_clear: erase @count characters at [@x, @y] on @vc. @count >= 1.
46+ * @con_putc: emit one character with attributes @ca to [@x, @y] on @vc.
47+ * (optional -- @con_putcs would be called instead)
48+ * @con_putcs: emit @count characters with attributes @s to [@x, @y] on @vc.
49+ * @con_cursor: enable/disable cursor depending on @enable
3950 * @con_scroll: move lines from @top to @bottom in direction @dir by @lines.
4051 * Return true if no generic handling should be done.
4152 * Invoked by csi_M and printing to the console.
42− * @con_set_palette: sets the palette of the console to @table (optional)
53+ * @con_switch: notifier about the console switch; it is supposed to return
54+ * true if a redraw is needed.
55+ * @con_blank: blank/unblank the console. The target mode is passed in @blank.
56+ * @mode_switch is set if changing from/to text/graphics. The hook
57+ * is supposed to return true if a redraw is needed.
58+ * @con_font_set: set console @vc font to @font with height @vpitch. @flags can
59+ * be %KD_FONT_FLAG_DONT_RECALC. (optional)
60+ * @con_font_get: fetch the current font on @vc of height @vpitch into @font.
61+ * (optional)
62+ * @con_font_default: set default font on @vc. @name can be %NULL or font name
63+ * to search for. @font can be filled back. (optional)
64+ * @con_resize: resize the @vc console to @width x @height. @from_user is true
65+ * when this change comes from the user space.
66+ * @con_set_palette: sets the palette of the console @vc to @table (optional)
4367 * @con_scrolldelta: the contents of the console should be scrolled by @lines.
4468 * Invoked by user. (optional)
69+ * @con_set_origin: set origin (see &vc_data::vc_origin) of the @vc. If not
70+ * provided or returns false, the origin is set to
71+ * @vc->vc_screenbuf. (optional)
72+ * @con_save_screen: save screen content into @vc->vc_screenbuf. Called e.g.
73+ * upon entering graphics. (optional)
74+ * @con_build_attr: build attributes based on @color, @intensity and other
75+ * parameters. The result is used for both normal and erase
76+ * characters. (optional)
77+ * @con_invert_region: invert a region of length @count on @vc starting at @p.
78+ * (optional)
79+ * @con_debug_enter: prepare the console for the debugger. This includes, but
80+ * is not limited to, unblanking the console, loading an
81+ * appropriate palette, and allowing debugger generated output.
82+ * (optional)
83+ * @con_debug_leave: restore the console to its pre-debug state as closely as
84+ * possible. (optional)
4585 */
4686 struct consw {
4787 struct module *owner;
4888 const char *(*con_startup)(void);
49− void (*con_init)(struct vc_data *vc, int init);
89+ void (*con_init)(struct vc_data *vc, bool init);
5090 void (*con_deinit)(struct vc_data *vc);
51− void (*con_clear)(struct vc_data *vc, int sy, int sx, int height,
52− int width);
53− void (*con_putc)(struct vc_data *vc, int c, int ypos, int xpos);
54− void (*con_putcs)(struct vc_data *vc, const unsigned short *s,
55− int count, int ypos, int xpos);
56− void (*con_cursor)(struct vc_data *vc, int mode);
91+ void (*con_clear)(struct vc_data *vc, unsigned int y,
92+ unsigned int x, unsigned int count);
93+ void (*con_putc)(struct vc_data *vc, u16 ca, unsigned int y,
94+ unsigned int x);
95+ void (*con_putcs)(struct vc_data *vc, const u16 *s,
96+ unsigned int count, unsigned int ypos,
97+ unsigned int xpos);
98+ void (*con_cursor)(struct vc_data *vc, bool enable);
5799 bool (*con_scroll)(struct vc_data *vc, unsigned int top,
58100 unsigned int bottom, enum con_scroll dir,
59101 unsigned int lines);
60− int (*con_switch)(struct vc_data *vc);
61− int (*con_blank)(struct vc_data *vc, int blank, int mode_switch);
62− int (*con_font_set)(struct vc_data *vc, struct console_font *font,
63− unsigned int vpitch, unsigned int flags);
102+ bool (*con_switch)(struct vc_data *vc);
103+ bool (*con_blank)(struct vc_data *vc, enum vesa_blank_mode blank,
104+ bool mode_switch);
105+ int (*con_font_set)(struct vc_data *vc,
106+ const struct console_font *font,
107+ unsigned int vpitch, unsigned int flags);
64108 int (*con_font_get)(struct vc_data *vc, struct console_font *font,
65109 unsigned int vpitch);
66110 int (*con_font_default)(struct vc_data *vc,
67− struct console_font *font, char *name);
111+ struct console_font *font, const char *name);
68112 int (*con_resize)(struct vc_data *vc, unsigned int width,
69− unsigned int height, unsigned int user);
113+ unsigned int height, bool from_user);
70114 void (*con_set_palette)(struct vc_data *vc,
71115 const unsigned char *table);
72116 void (*con_scrolldelta)(struct vc_data *vc, int lines);
73− int (*con_set_origin)(struct vc_data *vc);
117+ bool (*con_set_origin)(struct vc_data *vc);
74118 void (*con_save_screen)(struct vc_data *vc);
75119 u8 (*con_build_attr)(struct vc_data *vc, u8 color,
76120 enum vc_intensity intensity,
77121 bool blink, bool underline, bool reverse, bool italic);
78122 void (*con_invert_region)(struct vc_data *vc, u16 *p, int count);
79− u16 *(*con_screen_pos)(const struct vc_data *vc, int offset);
80− unsigned long (*con_getxy)(struct vc_data *vc, unsigned long position,
81− int *px, int *py);
82− /*
83− * Flush the video console driver's scrollback buffer
84− */
85− void (*con_flush_scrollback)(struct vc_data *vc);
86− /*
87− * Prepare the console for the debugger. This includes, but is not
88− * limited to, unblanking the console, loading an appropriate
89− * palette, and allowing debugger generated output.
90− */
91− int (*con_debug_enter)(struct vc_data *vc);
92− /*
93− * Restore the console to its pre-debug state as closely as possible.
94− */
95− int (*con_debug_leave)(struct vc_data *vc);
123+ void (*con_debug_enter)(struct vc_data *vc);
124+ void (*con_debug_leave)(struct vc_data *vc);
96125 };
97126
98127 extern const struct consw *conswitchp;
@@ -112,32 +141,21 @@ int con_is_bound(const struct consw *csw); · 13 unmodified lines
112141 int do_unregister_con_driver(const struct consw *csw);
113142 int do_take_over_console(const struct consw *sw, int first, int last, int deflt);
114143 void give_up_console(const struct consw *sw);
115−#ifdef CONFIG_HW_CONSOLE
116−int con_debug_enter(struct vc_data *vc);
117−int con_debug_leave(void);
144+#ifdef CONFIG_VT
145+void con_debug_enter(struct vc_data *vc);
146+void con_debug_leave(void);
118147 #else
119−static inline int con_debug_enter(struct vc_data *vc)
120−{
121− return 0;
122−}
123−static inline int con_debug_leave(void)
124−{
125− return 0;
126−}
148+static inline void con_debug_enter(struct vc_data *vc) { }
149+static inline void con_debug_leave(void) { }
127150 #endif
128151
129−/* cursor */
130−#define CM_DRAW (1)
131−#define CM_ERASE (2)
132−#define CM_MOVE (3)
133−
134152 /*
135153 * The interface for a console, or any other device that wants to capture
136154 * console messages (printer driver?)
137155 */
138156
139157 /**
140− * cons_flags - General console flags
158+ * enum cons_flags - General console flags
141159 * @CON_PRINTBUFFER: Used by newly registered consoles to avoid duplicate
142160 * output of messages that were already shown by boot
143161 * consoles or read by userspace via syslog() syscall.
@@ -218,7 +236,7 @@ struct nbcon_state { · 74 unmodified lines
218236 static_assert(sizeof(struct nbcon_state) <= sizeof(int));
219237
220238 /**
221− * nbcon_prio - console owner priority for nbcon consoles
239+ * enum nbcon_prio - console owner priority for nbcon consoles
222240 * @NBCON_PRIO_NONE: Unused
223241 * @NBCON_PRIO_NORMAL: Normal (non-emergency) usage
224242 * @NBCON_PRIO_EMERGENCY: Emergency output (WARN/OOPS...)
@@ -450,7 +468,7 @@ static inline bool console_is_registered(const struct console *con) · 225 unmodified lines
450468 * for_each_console() - Iterator over registered consoles
451469 * @con: struct console pointer used as loop cursor
452470 *
453− * The console list and the console->flags are immutable while iterating.
471+ * The console list and the &console.flags are immutable while iterating.
454472 *
455473 * Requires console_list_lock to be held.
456474 */
@@ -520,12 +538,6 @@ void vcs_remove_sysfs(int index); · 63 unmodified lines
520538 */
521539 extern atomic_t ignore_console_lock_warning;
522540
523−/* VESA Blanking Levels */
524−#define VESA_NO_BLANKING 0
525−#define VESA_VSYNC_SUSPEND 1
526−#define VESA_HSYNC_SUSPEND 2
527−#define VESA_POWERDOWN 3
528−
529541 extern void console_init(void);
530542
531543 /* For deferred console takeover */
include/linux/console_struct.h+0−1
@@ -151,7 +151,6 @@ struct vc_data { · 150 unmodified lines
151151 DECLARE_BITMAP(vc_tab_stop, VC_TABSTOPS_COUNT); /* Tab stops. 256 columns. */
152152 unsigned char vc_palette[16*3]; /* Colour palette for VGA+ */
153153 unsigned short * vc_translate;
154− unsigned int vc_resize_user; /* resize request from user */
155154 unsigned int vc_bell_pitch; /* Console bell pitch */
156155 unsigned int vc_bell_duration; /* Console bell duration */
157156 unsigned short vc_cur_blink_ms; /* Cursor blink duration */
include/linux/selection.h+26−30
@@ -14,17 +14,16 @@ · 13 unmodified lines
1414 struct tty_struct;
1515 struct vc_data;
1616
17−extern void clear_selection(void);
18−extern int set_selection_user(const struct tiocl_selection __user *sel,
19− struct tty_struct *tty);
20−extern int set_selection_kernel(struct tiocl_selection *v,
21− struct tty_struct *tty);
22−extern int paste_selection(struct tty_struct *tty);
23−extern int sel_loadlut(char __user *p);
24−extern int mouse_reporting(void);
25−extern void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry);
26−
27−bool vc_is_sel(struct vc_data *vc);
17+void clear_selection(void);
18+int set_selection_user(const struct tiocl_selection __user *sel,
19+ struct tty_struct *tty);
20+int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty);
21+int paste_selection(struct tty_struct *tty);
22+int sel_loadlut(u32 __user *lut);
23+int mouse_reporting(void);
24+void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry);
25+
26+bool vc_is_sel(const struct vc_data *vc);
2827
2928 extern int console_blanked;
3029
@@ -33,24 +32,21 @@ extern unsigned char default_red[]; · 2 unmodified lines
3332 extern unsigned char default_grn[];
3433 extern unsigned char default_blu[];
3534
36−extern unsigned short *screen_pos(const struct vc_data *vc, int w_offset,
37− bool viewed);
38−extern u16 screen_glyph(const struct vc_data *vc, int offset);
39−extern u32 screen_glyph_unicode(const struct vc_data *vc, int offset);
40−extern void complement_pos(struct vc_data *vc, int offset);
41−extern void invert_screen(struct vc_data *vc, int offset, int count, bool viewed);
42−
43−extern void getconsxy(const struct vc_data *vc, unsigned char xy[static 2]);
44−extern void putconsxy(struct vc_data *vc, unsigned char xy[static const 2]);
45−
46−extern u16 vcs_scr_readw(const struct vc_data *vc, const u16 *org);
47−extern void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org);
48−extern void vcs_scr_updated(struct vc_data *vc);
49−
50−extern int vc_uniscr_check(struct vc_data *vc);
51−extern void vc_uniscr_copy_line(const struct vc_data *vc, void *dest,
52− bool viewed,
53− unsigned int row, unsigned int col,
54− unsigned int nr);
35+unsigned short *screen_pos(const struct vc_data *vc, int w_offset, bool viewed);
36+u16 screen_glyph(const struct vc_data *vc, int offset);
37+u32 screen_glyph_unicode(const struct vc_data *vc, int offset);
38+void complement_pos(struct vc_data *vc, int offset);
39+void invert_screen(struct vc_data *vc, int offset, int count, bool viewed);
40+
41+void getconsxy(const struct vc_data *vc, unsigned char xy[static 2]);
42+void putconsxy(struct vc_data *vc, unsigned char xy[static const 2]);
43+
44+u16 vcs_scr_readw(const struct vc_data *vc, const u16 *org);
45+void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org);
46+void vcs_scr_updated(struct vc_data *vc);
47+
48+int vc_uniscr_check(struct vc_data *vc);
49+void vc_uniscr_copy_line(const struct vc_data *vc, void *dest, bool viewed,
50+ unsigned int row, unsigned int col, unsigned int nr);
5551
5652 #endif
include/linux/serdev.h+4−4
@@ -27,7 +27,7 @@ struct serdev_device; · 26 unmodified lines
2727 * not sleep.
2828 */
2929 struct serdev_device_ops {
30− ssize_t (*receive_buf)(struct serdev_device *, const u8 *, size_t);
30+ size_t (*receive_buf)(struct serdev_device *, const u8 *, size_t);
3131 void (*write_wakeup)(struct serdev_device *);
3232 };
3333
@@ -185,9 +185,9 @@ static inline void serdev_controller_write_wakeup(struct serdev_controller *ctrl · 151 unmodified lines
185185 serdev->ops->write_wakeup(serdev);
186186 }
187187
188−static inline ssize_t serdev_controller_receive_buf(struct serdev_controller *ctrl,
189− const u8 *data,
190− size_t count)
188+static inline size_t serdev_controller_receive_buf(struct serdev_controller *ctrl,
189+ const u8 *data,
190+ size_t count)
191191 {
192192 struct serdev_device *serdev = ctrl->serdev;
193193
include/linux/serial_8250.h+6−0
@@ -210,6 +210,12 @@ int serial8250_console_exit(struct uart_port *port); · 209 unmodified lines
210210 void serial8250_set_isa_configurator(void (*v)(int port, struct uart_port *up,
211211 u32 *capabilities));
212212
213+#ifdef CONFIG_SERIAL_8250_CONSOLE
214+extern int hp300_setup_serial_console(void) __init;
215+#else
216+static inline int hp300_setup_serial_console(void) { return 0; }
217+#endif
218+
213219 #ifdef CONFIG_SERIAL_8250_RT288X
214220 int rt288x_setup(struct uart_port *p);
215221 int au_platform_setup(struct plat_serial8250_port *p);
include/linux/serial_core.h+9−3
@@ -467,9 +467,10 @@ struct uart_port { · 466 unmodified lines
467467 unsigned int fifosize; /* tx fifo size */
468468 unsigned char x_char; /* xon/xoff char */
469469 unsigned char regshift; /* reg offset shift */
470+
470471 unsigned char iotype; /* io access style */
471− unsigned char quirks; /* internal quirks */
472472
473+#define UPIO_UNKNOWN ((unsigned char)~0U) /* UCHAR_MAX */
473474 #define UPIO_PORT (SERIAL_IO_PORT) /* 8b I/O port access */
474475 #define UPIO_HUB6 (SERIAL_IO_HUB6) /* Hub6 ISA card */
475476 #define UPIO_MEM (SERIAL_IO_MEM) /* driver-specific */
@@ -479,7 +480,9 @@ struct uart_port { · 3 unmodified lines
479480 #define UPIO_MEM32BE (SERIAL_IO_MEM32BE) /* 32b big endian */
480481 #define UPIO_MEM16 (SERIAL_IO_MEM16) /* 16b little endian */
481482
482− /* quirks must be updated while holding port mutex */
483+ unsigned char quirks; /* internal quirks */
484+
485+ /* internal quirks must be updated while holding port mutex */
483486 #define UPQ_NO_TXEN_TEST BIT(0)
484487
485488 unsigned int read_status_mask; /* driver specific */
@@ -786,7 +789,8 @@ enum UART_TX_FLAGS { · 300 unmodified lines
786789 if (pending < WAKEUP_CHARS) { \
787790 uart_write_wakeup(__port); \
788791 \
789− if (!((flags) & UART_TX_NOSTOP) && pending == 0) \
792+ if (!((flags) & UART_TX_NOSTOP) && pending == 0 && \
793+ __port->ops->tx_empty(__port)) \
790794 __port->ops->stop_tx(__port); \
791795 } \
792796 \
@@ -959,6 +963,8 @@ int uart_register_driver(struct uart_driver *uart); · 166 unmodified lines
959963 void uart_unregister_driver(struct uart_driver *uart);
960964 int uart_add_one_port(struct uart_driver *reg, struct uart_port *port);
961965 void uart_remove_one_port(struct uart_driver *reg, struct uart_port *port);
966+int uart_read_port_properties(struct uart_port *port);
967+int uart_read_and_validate_port_properties(struct uart_port *port);
962968 bool uart_match_port(const struct uart_port *port1,
963969 const struct uart_port *port2);
964970
include/linux/soc/qcom/geni-se.h+1−0
@@ -178,6 +178,7 @@ struct geni_se { · 177 unmodified lines
178178 #define M_GP_IRQ_3_EN BIT(12)
179179 #define M_GP_IRQ_4_EN BIT(13)
180180 #define M_GP_IRQ_5_EN BIT(14)
181+#define M_TX_FIFO_NOT_EMPTY_EN BIT(21)
181182 #define M_IO_DATA_DEASSERT_EN BIT(22)
182183 #define M_IO_DATA_ASSERT_EN BIT(23)
183184 #define M_RX_FIFO_RD_ERR_EN BIT(24)
include/linux/tty.h+0−1
@@ -6,7 +6,6 @@ · 5 unmodified lines
66 #include <linux/major.h>
77 #include <linux/termios.h>
88 #include <linux/workqueue.h>
9−#include <linux/tty_buffer.h>
109 #include <linux/tty_driver.h>
1110 #include <linux/tty_ldisc.h>
1211 #include <linux/tty_port.h>
include/linux/vt_kern.h+8−4
@@ -25,7 +25,8 @@ extern int fg_console, last_console, want_console; · 24 unmodified lines
2525
2626 int vc_allocate(unsigned int console);
2727 int vc_cons_allocated(unsigned int console);
28−int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines);
28+int __vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines,
29+ bool from_user);
2930 struct vc_data *vc_deallocate(unsigned int console);
3031 void reset_palette(struct vc_data *vc);
3132 void do_blank_screen(int entering_gfx);
@@ -42,6 +43,12 @@ void redraw_screen(struct vc_data *vc, int is_switch); · 10 unmodified lines
4243 #define update_screen(x) redraw_screen(x, 0)
4344 #define switch_screen(x) redraw_screen(x, 1)
4445
46+static inline int vc_resize(struct vc_data *vc, unsigned int cols,
47+ unsigned int lines)
48+{
49+ return __vc_resize(vc, cols, lines, false);
50+}
51+
4552 struct tty_struct;
4653 int tioclinux(struct tty_struct *tty, unsigned long arg);
4754
@@ -168,7 +175,4 @@ void vt_set_led_state(unsigned int console, int leds); · 120 unmodified lines
168175 void vt_kbd_con_start(unsigned int console);
169176 void vt_kbd_con_stop(unsigned int console);
170177
171−void vc_scrolldelta_helper(struct vc_data *c, int lines,
172− unsigned int rolled_over, void *_base, unsigned int size);
173−
174178 #endif /* _VT_KERN_H */
include/uapi/linux/fb.h+1−7
@@ -4,6 +4,7 @@ · 3 unmodified lines
44
55 #include <linux/types.h>
66 #include <linux/i2c.h>
7+#include <linux/vesa.h>
78
89 /* Definitions of frame buffers */
910
@@ -293,13 +294,6 @@ struct fb_con2fbmap { · 283 unmodified lines
293294 __u32 framebuffer;
294295 };
295296
296−/* VESA Blanking Levels */
297−#define VESA_NO_BLANKING 0
298−#define VESA_VSYNC_SUSPEND 1
299−#define VESA_HSYNC_SUSPEND 2
300−#define VESA_POWERDOWN 3
301−
302−
303297 enum {
304298 /* screen: unblanked, hsync: on, vsync: on */
305299 FB_BLANK_UNBLANK = VESA_NO_BLANKING,
include/uapi/linux/vesa.h+18−0
@@ -0,0 +1,18 @@
1+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+#ifndef _UAPI_LINUX_VESA_H
3+#define _UAPI_LINUX_VESA_H
4+
5+/* VESA Blanking Levels */
6+enum vesa_blank_mode {
7+ VESA_NO_BLANKING = 0,
8+#define VESA_NO_BLANKING VESA_NO_BLANKING
9+ VESA_VSYNC_SUSPEND = 1,
10+#define VESA_VSYNC_SUSPEND VESA_VSYNC_SUSPEND
11+ VESA_HSYNC_SUSPEND = 2,
12+#define VESA_HSYNC_SUSPEND VESA_HSYNC_SUSPEND
13+ VESA_POWERDOWN = VESA_VSYNC_SUSPEND | VESA_HSYNC_SUSPEND,
14+#define VESA_POWERDOWN VESA_POWERDOWN
15+ VESA_BLANK_MAX = VESA_POWERDOWN,
16+};
17+
18+#endif
kernel/printk/printk.c+18−3
@@ -3269,6 +3269,21 @@ static int __init keep_bootcon_setup(char *str) · 3268 unmodified lines
32693269
32703270 early_param("keep_bootcon", keep_bootcon_setup);
32713271
3272+static int console_call_setup(struct console *newcon, char *options)
3273+{
3274+ int err;
3275+
3276+ if (!newcon->setup)
3277+ return 0;
3278+
3279+ /* Synchronize with possible boot console. */
3280+ console_lock();
3281+ err = newcon->setup(newcon, options);
3282+ console_unlock();
3283+
3284+ return err;
3285+}
3286+
32723287 /*
32733288 * This is called by register_console() to try to match
32743289 * the newly registered console with any of the ones selected
@@ -3304,8 +3319,8 @@ static int try_enable_preferred_console(struct console *newcon, · 29 unmodified lines
33043319 if (_braille_register_console(newcon, c))
33053320 return 0;
33063321
3307− if (newcon->setup &&
3308− (err = newcon->setup(newcon, c->options)) != 0)
3322+ err = console_call_setup(newcon, c->options);
3323+ if (err)
33093324 return err;
33103325 }
33113326 newcon->flags |= CON_ENABLED;
@@ -3331,7 +3346,7 @@ static void try_enable_default_console(struct console *newcon) · 19 unmodified lines
33313346 if (newcon->index < 0)
33323347 newcon->index = 0;
33333348
3334− if (newcon->setup && newcon->setup(newcon, NULL) != 0)
3349+ if (console_call_setup(newcon, NULL) != 0)
33353350 return;
33363351
33373352 newcon->flags |= CON_ENABLED;
lib/Kconfig.kgdb+1−1
@@ -43,7 +43,7 @@ config KGDB_SERIAL_CONSOLE · 42 unmodified lines
4343 tristate "KGDB: use kgdb over the serial console"
4444 select CONSOLE_POLL
4545 select MAGIC_SYSRQ
46− depends on TTY && HW_CONSOLE
46+ depends on TTY && VT
4747 default y
4848 help
4949 Share a serial console with kgdb. Sysrq-g must be used
sound/drivers/serial-generic.c+2−2
@@ -100,8 +100,8 @@ static void snd_serial_generic_write_wakeup(struct serdev_device *serdev) · 99 unmodified lines
100100 snd_serial_generic_tx_wakeup(drvdata);
101101 }
102102
103−static ssize_t snd_serial_generic_receive_buf(struct serdev_device *serdev,
104− const u8 *buf, size_t count)
103+static size_t snd_serial_generic_receive_buf(struct serdev_device *serdev,
104+ const u8 *buf, size_t count)
105105 {
106106 int ret;
107107 struct snd_serial_generic *drvdata = serdev_device_get_drvdata(serdev);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t