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

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().
...

+3546 -2525
+1
Documentation/devicetree/bindings/serial/cdns,uart.yaml
··· 55 55 56 56 allOf: 57 57 - $ref: serial.yaml# 58 + - $ref: rs485.yaml# 58 59 - if: 59 60 properties: 60 61 compatible:
+1
Documentation/devicetree/bindings/serial/fsl-lpuart.yaml
··· 30 30 - items: 31 31 - enum: 32 32 - fsl,imx93-lpuart 33 + - fsl,imx95-lpuart 33 34 - const: fsl,imx8ulp-lpuart 34 35 - const: fsl,imx7ulp-lpuart 35 36 - items:
+1
Documentation/devicetree/bindings/serial/renesas,hscif.yaml
··· 59 59 - renesas,hscif-r8a779a0 # R-Car V3U 60 60 - renesas,hscif-r8a779f0 # R-Car S4-8 61 61 - renesas,hscif-r8a779g0 # R-Car V4H 62 + - renesas,hscif-r8a779h0 # R-Car V4M 62 63 - const: renesas,rcar-gen4-hscif # R-Car Gen4 63 64 - const: renesas,hscif # generic HSCIF compatible UART 64 65
+2
Documentation/devicetree/bindings/serial/samsung_uart.yaml
··· 143 143 then: 144 144 required: 145 145 - samsung,uart-fifosize 146 + properties: 147 + reg-io-width: false 146 148 147 149 unevaluatedProperties: false 148 150
+1 -1
Documentation/devicetree/bindings/serial/serial.yaml
··· 88 88 TX FIFO threshold configuration (in bytes). 89 89 90 90 patternProperties: 91 - "^(bluetooth|bluetooth-gnss|gnss|gps|mcu)$": 91 + "^(bluetooth|bluetooth-gnss|gnss|gps|mcu|onewire)$": 92 92 if: 93 93 type: object 94 94 then:
+55
Documentation/devicetree/bindings/serial/st,asc.yaml
··· 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 + ...
+3
Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
··· 58 58 59 59 wakeup-source: true 60 60 61 + power-domains: 62 + maxItems: 1 63 + 61 64 rx-threshold: 62 65 description: 63 66 If value is set to 1, RX FIFO threshold is disabled.
-18
Documentation/devicetree/bindings/serial/st-asc.txt
··· 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 - };
+59
Documentation/devicetree/bindings/w1/w1-uart.yaml
··· 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 + };
+45
Documentation/driver-api/tty/console.rst
··· 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:
+1
Documentation/driver-api/tty/index.rst
··· 38 38 tty_buffer 39 39 tty_ioctl 40 40 tty_internals 41 + console 41 42 42 43 Writing TTY Driver 43 44 ==================
+1
Documentation/w1/masters/index.rst
··· 12 12 mxc-w1 13 13 omap-hdq 14 14 w1-gpio 15 + w1-uart
+54
Documentation/w1/masters/w1-uart.rst
··· 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 + };
+1 -1
arch/m68k/amiga/config.c
··· 846 846 * The Amiga keyboard driver needs key_maps, but we cannot export it in 847 847 * drivers/char/defkeymap.c, as it is autogenerated 848 848 */ 849 - #ifdef CONFIG_HW_CONSOLE 849 + #ifdef CONFIG_VT 850 850 EXPORT_SYMBOL_GPL(key_maps); 851 851 #endif
+1 -5
arch/m68k/hp300/config.c
··· 10 10 11 11 #include <linux/module.h> 12 12 #include <linux/init.h> 13 + #include <linux/serial_8250.h> 13 14 #include <linux/string.h> 14 15 #include <linux/kernel.h> 15 16 #include <linux/console.h> ··· 68 67 static char hp300_model_name[13] = "HP9000/"; 69 68 70 69 extern void hp300_reset(void); 71 - #ifdef CONFIG_SERIAL_8250_CONSOLE 72 - extern int hp300_setup_serial_console(void) __init; 73 - #endif 74 70 75 71 int __init hp300_parse_bootinfo(const struct bi_record *record) 76 72 { ··· 261 263 } else { 262 264 panic("Unknown HP9000 Model"); 263 265 } 264 - #ifdef CONFIG_SERIAL_8250_CONSOLE 265 266 hp300_setup_serial_console(); 266 - #endif 267 267 }
+2 -2
drivers/bluetooth/btmtkuart.c
··· 383 383 } 384 384 } 385 385 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) 388 388 { 389 389 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); 390 390
+2 -2
drivers/bluetooth/btnxpuart.c
··· 1285 1285 { NXP_RECV_FW_REQ_V3, .recv = nxp_recv_fw_req_v3 }, 1286 1286 }; 1287 1287 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) 1290 1290 { 1291 1291 struct btnxpuart_dev *nxpdev = serdev_device_get_drvdata(serdev); 1292 1292
+2 -2
drivers/bluetooth/hci_serdev.c
··· 271 271 * 272 272 * Return: number of processed bytes 273 273 */ 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) 276 276 { 277 277 struct hci_uart *hu = serdev_device_get_drvdata(serdev); 278 278
+1 -1
drivers/gnss/serial.c
··· 80 80 .write_raw = gnss_serial_write_raw, 81 81 }; 82 82 83 - static ssize_t gnss_serial_receive_buf(struct serdev_device *serdev, 83 + static size_t gnss_serial_receive_buf(struct serdev_device *serdev, 84 84 const u8 *buf, size_t count) 85 85 { 86 86 struct gnss_serial *gserial = serdev_device_get_drvdata(serdev);
+1 -1
drivers/gnss/sirf.c
··· 160 160 .write_raw = sirf_write_raw, 161 161 }; 162 162 163 - static ssize_t sirf_receive_buf(struct serdev_device *serdev, 163 + static size_t sirf_receive_buf(struct serdev_device *serdev, 164 164 const u8 *buf, size_t count) 165 165 { 166 166 struct sirf_data *data = serdev_device_get_drvdata(serdev);
+3 -3
drivers/greybus/gb-beagleplay.c
··· 271 271 } 272 272 } 273 273 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) 275 275 { 276 276 size_t i; 277 277 u8 c; ··· 331 331 flush_work(&bg->tx_work); 332 332 } 333 333 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) 336 336 { 337 337 struct gb_beagleplay *bg = serdev_device_get_drvdata(sd); 338 338
+2 -2
drivers/iio/chemical/pms7003.c
··· 211 211 return checksum == pms7003_calc_checksum(frame); 212 212 } 213 213 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) 216 216 { 217 217 struct iio_dev *indio_dev = serdev_device_get_drvdata(serdev); 218 218 struct pms7003_state *state = iio_priv(indio_dev);
+2 -2
drivers/iio/chemical/scd30_serial.c
··· 174 174 return 0; 175 175 } 176 176 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) 179 179 { 180 180 struct iio_dev *indio_dev = serdev_device_get_drvdata(serdev); 181 181 struct scd30_serdev_priv *priv;
+2 -2
drivers/iio/chemical/sps30_serial.c
··· 210 210 return rsp_size; 211 211 } 212 212 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) 215 215 { 216 216 struct iio_dev *indio_dev = dev_get_drvdata(&serdev->dev); 217 217 struct sps30_serial_priv *priv;
+2 -2
drivers/iio/imu/bno055/bno055_ser_core.c
··· 378 378 * Also, we assume to RX one pkt per time (i.e. the HW doesn't send anything 379 379 * unless we require to AND we don't queue more than one request per time). 380 380 */ 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) 383 383 { 384 384 int status; 385 385 struct bno055_ser_priv *priv = serdev_device_get_drvdata(serdev);
+3 -3
drivers/input/keyboard/amikbd.c
··· 26 26 MODULE_DESCRIPTION("Amiga keyboard driver"); 27 27 MODULE_LICENSE("GPL"); 28 28 29 - #ifdef CONFIG_HW_CONSOLE 29 + #ifdef CONFIG_VT 30 30 static unsigned char amikbd_keycode[0x78] __initdata = { 31 31 [0] = KEY_GRAVE, 32 32 [1] = KEY_1, ··· 148 148 memcpy(key_maps[i], temp_map, sizeof(temp_map)); 149 149 } 150 150 } 151 - #else /* !CONFIG_HW_CONSOLE */ 151 + #else /* !CONFIG_VT */ 152 152 static inline void amikbd_init_console_keymaps(void) {} 153 - #endif /* !CONFIG_HW_CONSOLE */ 153 + #endif /* !CONFIG_VT */ 154 154 155 155 static const char *amikbd_messages[8] = { 156 156 [0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
+2 -2
drivers/mfd/rave-sp.c
··· 471 471 rave_sp_receive_reply(sp, data, length); 472 472 } 473 473 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) 476 476 { 477 477 struct device *dev = &serdev->dev; 478 478 struct rave_sp *sp = dev_get_drvdata(dev);
+1 -1
drivers/net/ethernet/qualcomm/qca_uart.c
··· 45 45 unsigned char *tx_buffer; 46 46 }; 47 47 48 - static ssize_t 48 + static size_t 49 49 qca_tty_receive(struct serdev_device *serdev, const u8 *data, size_t count) 50 50 { 51 51 struct qcauart *qca = serdev_device_get_drvdata(serdev);
+2 -2
drivers/nfc/pn533/uart.c
··· 203 203 return 0; 204 204 } 205 205 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) 208 208 { 209 209 struct pn532_uart_phy *dev = serdev_device_get_drvdata(serdev); 210 210 size_t i;
+2 -2
drivers/nfc/s3fwrn5/uart.c
··· 51 51 .write = s3fwrn82_uart_write, 52 52 }; 53 53 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) 56 56 { 57 57 struct s3fwrn82_uart_phy *phy = serdev_device_get_drvdata(serdev); 58 58 size_t i;
+2 -2
drivers/platform/chrome/cros_ec_uart.c
··· 81 81 struct response_info response; 82 82 }; 83 83 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) 86 86 { 87 87 struct ec_host_response *host_response; 88 88 struct cros_ec_device *ec_dev = serdev_device_get_drvdata(serdev);
+2 -2
drivers/platform/surface/aggregator/core.c
··· 227 227 228 228 /* -- Glue layer (serdev_device -> ssam_controller). ------------------------ */ 229 229 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) 232 232 { 233 233 struct ssam_controller *ctrl; 234 234 int ret;
+1 -6
drivers/tty/Kconfig
··· 75 75 def_bool y 76 76 depends on VT_CONSOLE && PM_SLEEP 77 77 78 - config HW_CONSOLE 79 - bool 80 - depends on VT 81 - default y 82 - 83 78 config VT_HW_CONSOLE_BINDING 84 79 bool "Support for binding and unbinding console drivers" 85 - depends on HW_CONSOLE 80 + depends on VT 86 81 help 87 82 The virtual terminal is the device that interacts with the physical 88 83 terminal through console drivers. On these systems, at least one
+2 -4
drivers/tty/amiserial.c
··· 1566 1566 return error; 1567 1567 } 1568 1568 1569 - static int __exit amiga_serial_remove(struct platform_device *pdev) 1569 + static void __exit amiga_serial_remove(struct platform_device *pdev) 1570 1570 { 1571 1571 struct serial_state *state = platform_get_drvdata(pdev); 1572 1572 ··· 1576 1576 1577 1577 free_irq(IRQ_AMIGA_TBE, state); 1578 1578 free_irq(IRQ_AMIGA_RBF, state); 1579 - 1580 - return 0; 1581 1579 } 1582 1580 1583 1581 static struct platform_driver amiga_serial_driver = { 1584 - .remove = __exit_p(amiga_serial_remove), 1582 + .remove_new = __exit_p(amiga_serial_remove), 1585 1583 .driver = { 1586 1584 .name = "amiga-serial", 1587 1585 },
+2 -3
drivers/tty/goldfish.c
··· 408 408 return ret; 409 409 } 410 410 411 - static int goldfish_tty_remove(struct platform_device *pdev) 411 + static void goldfish_tty_remove(struct platform_device *pdev) 412 412 { 413 413 struct goldfish_tty *qtty = platform_get_drvdata(pdev); 414 414 ··· 424 424 if (goldfish_tty_current_line_count == 0) 425 425 goldfish_tty_delete_driver(); 426 426 mutex_unlock(&goldfish_tty_lock); 427 - return 0; 428 427 } 429 428 430 429 #ifdef CONFIG_GOLDFISH_TTY_EARLY_CONSOLE ··· 461 462 462 463 static struct platform_driver goldfish_tty_platform_driver = { 463 464 .probe = goldfish_tty_probe, 464 - .remove = goldfish_tty_remove, 465 + .remove_new = goldfish_tty_remove, 465 466 .driver = { 466 467 .name = "goldfish_tty", 467 468 .of_match_table = goldfish_tty_of_match,
+5 -1
drivers/tty/hvc/hvc_iucv.c
··· 1035 1035 NULL, 1036 1036 }; 1037 1037 1038 + static void hvc_iucv_free(struct device *data) 1039 + { 1040 + kfree(data); 1041 + } 1038 1042 1039 1043 /** 1040 1044 * hvc_iucv_alloc() - Allocates a new struct hvc_iucv_private instance ··· 1101 1097 priv->dev->bus = &iucv_bus; 1102 1098 priv->dev->parent = iucv_root; 1103 1099 priv->dev->groups = hvc_iucv_dev_attr_groups; 1104 - priv->dev->release = (void (*)(struct device *)) kfree; 1100 + priv->dev->release = hvc_iucv_free; 1105 1101 rc = device_register(priv->dev); 1106 1102 if (rc) { 1107 1103 put_device(priv->dev);
+1 -1
drivers/tty/serdev/core.c
··· 431 431 dev_pm_domain_detach(dev, true); 432 432 } 433 433 434 - static struct bus_type serdev_bus_type = { 434 + static const struct bus_type serdev_bus_type = { 435 435 .name = "serial", 436 436 .match = serdev_device_match, 437 437 .probe = serdev_drv_probe,
+4 -6
drivers/tty/serdev/serdev-ttyport.c
··· 27 27 { 28 28 struct serdev_controller *ctrl = port->client_data; 29 29 struct serport *serport = serdev_controller_get_drvdata(ctrl); 30 - int ret; 30 + size_t ret; 31 31 32 32 if (!test_bit(SERPORT_ACTIVE, &serport->flags)) 33 33 return 0; 34 34 35 35 ret = serdev_controller_receive_buf(ctrl, cp, count); 36 36 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", 39 39 ret, count); 40 - if (ret < 0) 41 - return 0; 42 - else if (ret > count) 40 + if (ret > count) 43 41 return count; 44 42 45 43 return ret;
+15 -35
drivers/tty/serial/8250/8250_aspeed_vuart.c
··· 419 419 struct aspeed_vuart *vuart; 420 420 struct device_node *np; 421 421 struct resource *res; 422 - u32 clk, prop, sirq[2]; 423 422 int rc, sirq_polarity; 423 + u32 prop, sirq[2]; 424 424 struct clk *vclk; 425 425 426 426 np = pdev->dev.of_node; ··· 447 447 port.port.status = UPSTAT_SYNC_FIFO; 448 448 port.port.dev = &pdev->dev; 449 449 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; 450 452 port.bugs |= UART_BUG_TXRACE; 451 453 452 454 rc = sysfs_create_group(&vuart->dev->kobj, &aspeed_vuart_attr_group); 453 455 if (rc < 0) 454 456 return rc; 455 457 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) { 457 464 vclk = devm_clk_get_enabled(dev, NULL); 458 465 if (IS_ERR(vclk)) { 459 466 rc = dev_err_probe(dev, PTR_ERR(vclk), "clk or clock-frequency not defined\n"); 460 467 goto err_sysfs_remove; 461 468 } 462 469 463 - clk = clk_get_rate(vclk); 470 + port.port.uartclk = clk_get_rate(vclk); 464 471 } 465 472 466 473 /* If current-speed was set, then try not to change it. */ 467 474 if (of_property_read_u32(np, "current-speed", &prop) == 0) 468 - port.port.custom_divisor = clk / (16 * prop); 475 + port.port.custom_divisor = port.port.uartclk / (16 * prop); 469 476 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; 477 - 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); 488 477 port.port.handle_irq = aspeed_vuart_handle_irq; 489 - port.port.iotype = UPIO_MEM; 490 478 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; 497 479 498 480 if (port.port.fifosize) 499 481 port.capabilities = UART_CAP_FIFO; ··· 485 503 486 504 rc = serial8250_register_8250_port(&port); 487 505 if (rc < 0) 488 - goto err_clk_disable; 506 + goto err_sysfs_remove; 489 507 490 508 vuart->line = rc; 491 509 vuart->port = serial8250_get_port(vuart->line); ··· 511 529 rc = aspeed_vuart_set_lpc_address(vuart, prop); 512 530 if (rc < 0) { 513 531 dev_err_probe(dev, rc, "invalid value in aspeed,lpc-io-reg property\n"); 514 - goto err_clk_disable; 532 + goto err_sysfs_remove; 515 533 } 516 534 517 535 rc = of_property_read_u32_array(np, "aspeed,lpc-interrupts", sirq, 2); ··· 523 541 rc = aspeed_vuart_set_sirq(vuart, sirq[0]); 524 542 if (rc < 0) { 525 543 dev_err_probe(dev, rc, "invalid sirq number in aspeed,lpc-interrupts property\n"); 526 - goto err_clk_disable; 544 + goto err_sysfs_remove; 527 545 } 528 546 529 547 sirq_polarity = aspeed_vuart_map_irq_polarity(sirq[1]); 530 548 if (sirq_polarity < 0) { 531 549 rc = dev_err_probe(dev, sirq_polarity, 532 550 "invalid sirq polarity in aspeed,lpc-interrupts property\n"); 533 - goto err_clk_disable; 551 + goto err_sysfs_remove; 534 552 } 535 553 536 554 aspeed_vuart_set_sirq_polarity(vuart, sirq_polarity); ··· 541 559 542 560 return 0; 543 561 544 - err_clk_disable: 545 - irq_dispose_mapping(port.port.irq); 546 562 err_sysfs_remove: 547 563 sysfs_remove_group(&vuart->dev->kobj, &aspeed_vuart_attr_group); 548 564 return rc;
+42 -50
drivers/tty/serial/8250/8250_bcm2835aux.c
··· 45 45 u32 cntl; 46 46 }; 47 47 48 - struct bcm2835_aux_serial_driver_data { 49 - resource_size_t offset; 50 - }; 51 - 52 48 static void bcm2835aux_rs485_start_tx(struct uart_8250_port *up) 53 49 { 54 50 if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) { ··· 81 85 82 86 static int bcm2835aux_serial_probe(struct platform_device *pdev) 83 87 { 84 - const struct bcm2835_aux_serial_driver_data *bcm_data; 88 + const struct software_node *bcm2835_swnode; 85 89 struct uart_8250_port up = { }; 86 90 struct bcm2835aux_data *data; 87 - resource_size_t offset = 0; 88 91 struct resource *res; 89 92 unsigned int uartclk; 90 93 int ret; ··· 96 101 /* initialize data */ 97 102 up.capabilities = UART_CAP_FIFO | UART_CAP_MINI; 98 103 up.port.dev = &pdev->dev; 99 - up.port.regshift = 2; 100 104 up.port.type = PORT_16550; 101 - up.port.iotype = UPIO_MEM; 102 - up.port.fifosize = 8; 103 - up.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT | UPF_FIXED_TYPE | 104 - UPF_SKIP_TEST | UPF_IOREMAP; 105 + up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SKIP_TEST | UPF_IOREMAP; 105 106 up.port.rs485_config = serial8250_em485_config; 106 107 up.port.rs485_supported = serial8250_em485_supported; 107 108 up.rs485_start_tx = bcm2835aux_rs485_start_tx; ··· 113 122 if (IS_ERR(data->clk)) 114 123 return dev_err_probe(&pdev->dev, PTR_ERR(data->clk), "could not get clk\n"); 115 124 116 - /* get the interrupt */ 117 - ret = platform_get_irq(pdev, 0); 118 - if (ret < 0) 119 - return ret; 120 - up.port.irq = ret; 121 - 122 125 /* map the main registers */ 123 126 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 124 127 if (!res) { ··· 120 135 return -EINVAL; 121 136 } 122 137 123 - bcm_data = device_get_match_data(&pdev->dev); 138 + up.port.mapbase = res->start; 139 + up.port.mapsize = resource_size(res); 124 140 125 - /* Some UEFI implementations (e.g. tianocore/edk2 for the Raspberry Pi) 126 - * describe the miniuart with a base address that encompasses the auxiliary 127 - * registers shared between the miniuart and spi. 128 - * 129 - * This is due to historical reasons, see discussion here : 130 - * https://edk2.groups.io/g/devel/topic/87501357#84349 131 - * 132 - * We need to add the offset between the miniuart and auxiliary 133 - * registers to get the real miniuart base address. 134 - */ 135 - if (bcm_data) 136 - offset = bcm_data->offset; 141 + bcm2835_swnode = device_get_match_data(&pdev->dev); 142 + if (bcm2835_swnode) { 143 + ret = device_add_software_node(&pdev->dev, bcm2835_swnode); 144 + if (ret) 145 + return ret; 146 + } 137 147 138 - up.port.mapbase = res->start + offset; 139 - up.port.mapsize = resource_size(res) - offset; 148 + ret = uart_read_port_properties(&up.port); 149 + if (ret) 150 + goto rm_swnode; 140 151 141 - /* Check for a fixed line number */ 142 - ret = of_alias_get_id(pdev->dev.of_node, "serial"); 143 - if (ret >= 0) 144 - up.port.line = ret; 152 + up.port.regshift = 2; 153 + up.port.fifosize = 8; 145 154 146 155 /* enable the clock as a last step */ 147 156 ret = clk_prepare_enable(data->clk); 148 157 if (ret) { 149 - dev_err(&pdev->dev, "unable to enable uart clock - %d\n", 150 - ret); 151 - return ret; 158 + dev_err_probe(&pdev->dev, ret, "unable to enable uart clock\n"); 159 + goto rm_swnode; 152 160 } 153 161 154 162 uartclk = clk_get_rate(data->clk); 155 - if (!uartclk) { 156 - ret = device_property_read_u32(&pdev->dev, "clock-frequency", &uartclk); 157 - if (ret) { 158 - dev_err_probe(&pdev->dev, ret, "could not get clk rate\n"); 159 - goto dis_clk; 160 - } 161 - } 163 + if (uartclk) 164 + up.port.uartclk = uartclk; 162 165 163 166 /* the HW-clock divider for bcm2835aux is 8, 164 167 * but 8250 expects a divider of 16, 165 168 * so we have to multiply the actual clock by 2 166 169 * to get identical baudrates. 167 170 */ 168 - up.port.uartclk = uartclk * 2; 171 + up.port.uartclk *= 2; 169 172 170 173 /* register the port */ 171 174 ret = serial8250_register_8250_port(&up); ··· 167 194 168 195 dis_clk: 169 196 clk_disable_unprepare(data->clk); 197 + rm_swnode: 198 + device_remove_software_node(&pdev->dev); 170 199 return ret; 171 200 } 172 201 ··· 178 203 179 204 serial8250_unregister_port(data->line); 180 205 clk_disable_unprepare(data->clk); 206 + device_remove_software_node(&pdev->dev); 181 207 } 182 208 183 - static const struct bcm2835_aux_serial_driver_data bcm2835_acpi_data = { 184 - .offset = 0x40, 209 + /* 210 + * Some UEFI implementations (e.g. tianocore/edk2 for the Raspberry Pi) 211 + * describe the miniuart with a base address that encompasses the auxiliary 212 + * registers shared between the miniuart and spi. 213 + * 214 + * This is due to historical reasons, see discussion here: 215 + * https://edk2.groups.io/g/devel/topic/87501357#84349 216 + * 217 + * We need to add the offset between the miniuart and auxiliary registers 218 + * to get the real miniuart base address. 219 + */ 220 + static const struct property_entry bcm2835_acpi_properties[] = { 221 + PROPERTY_ENTRY_U32("reg-offset", 0x40), 222 + { } 223 + }; 224 + 225 + static const struct software_node bcm2835_acpi_node = { 226 + .properties = bcm2835_acpi_properties, 185 227 }; 186 228 187 229 static const struct of_device_id bcm2835aux_serial_match[] = { ··· 208 216 MODULE_DEVICE_TABLE(of, bcm2835aux_serial_match); 209 217 210 218 static const struct acpi_device_id bcm2835aux_serial_acpi_match[] = { 211 - { "BCM2836", (kernel_ulong_t)&bcm2835_acpi_data }, 219 + { "BCM2836", (kernel_ulong_t)&bcm2835_acpi_node }, 212 220 { } 213 221 }; 214 222 MODULE_DEVICE_TABLE(acpi, bcm2835aux_serial_acpi_match);
+27 -46
drivers/tty/serial/8250/8250_bcm7271.c
··· 22 22 #include <linux/delay.h> 23 23 #include <linux/clk.h> 24 24 #include <linux/debugfs.h> 25 + #include <linux/units.h> 25 26 26 27 #include "8250.h" 27 28 ··· 188 187 #define TX_BUF_SIZE 4096 189 188 #define RX_BUF_SIZE 4096 190 189 #define RX_BUFS_COUNT 2 191 - #define KHZ 1000 192 - #define MHZ(x) ((x) * KHZ * KHZ) 193 190 194 191 static const u32 brcmstb_rate_table[] = { 195 - MHZ(81), 196 - MHZ(108), 197 - MHZ(64), /* Actually 64285715 for some chips */ 198 - MHZ(48), 192 + 81 * HZ_PER_MHZ, 193 + 108 * HZ_PER_MHZ, 194 + 64 * HZ_PER_MHZ, /* Actually 64285715 for some chips */ 195 + 48 * HZ_PER_MHZ, 199 196 }; 200 197 201 198 static const u32 brcmstb_rate_table_7278[] = { 202 - MHZ(81), 203 - MHZ(108), 199 + 81 * HZ_PER_MHZ, 200 + 108 * HZ_PER_MHZ, 204 201 0, 205 - MHZ(48), 202 + 48 * HZ_PER_MHZ, 206 203 }; 207 204 208 205 struct brcmuart_priv { ··· 935 936 static int brcmuart_probe(struct platform_device *pdev) 936 937 { 937 938 struct resource *regs; 938 - struct device_node *np = pdev->dev.of_node; 939 939 const struct of_device_id *of_id = NULL; 940 940 struct uart_8250_port *new_port; 941 941 struct device *dev = &pdev->dev; 942 942 struct brcmuart_priv *priv; 943 943 struct clk *baud_mux_clk; 944 944 struct uart_8250_port up; 945 - int irq; 946 945 void __iomem *membase = NULL; 947 946 resource_size_t mapbase = 0; 948 - u32 clk_rate = 0; 949 947 int ret; 950 948 int x; 951 949 int dma_irq; ··· 950 954 "uart", "dma_rx", "dma_tx", "dma_intr2", "dma_arb" 951 955 }; 952 956 953 - irq = platform_get_irq(pdev, 0); 954 - if (irq < 0) 955 - return irq; 956 957 priv = devm_kzalloc(dev, sizeof(struct brcmuart_priv), 957 958 GFP_KERNEL); 958 959 if (!priv) 959 960 return -ENOMEM; 960 961 961 - of_id = of_match_node(brcmuart_dt_ids, np); 962 + of_id = of_match_node(brcmuart_dt_ids, dev->of_node); 962 963 if (!of_id || !of_id->data) 963 964 priv->rate_table = brcmstb_rate_table; 964 965 else ··· 1005 1012 } 1006 1013 } 1007 1014 1008 - of_property_read_u32(np, "clock-frequency", &clk_rate); 1015 + dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not "); 1016 + 1017 + memset(&up, 0, sizeof(up)); 1018 + up.port.type = PORT_BCM7271; 1019 + up.port.dev = dev; 1020 + up.port.mapbase = mapbase; 1021 + up.port.membase = membase; 1022 + up.port.handle_irq = brcmuart_handle_irq; 1023 + up.port.flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_FIXED_TYPE; 1024 + up.port.private_data = priv; 1025 + 1026 + ret = uart_read_port_properties(&up.port); 1027 + if (ret) 1028 + goto release_dma; 1029 + 1030 + up.port.regshift = 2; 1031 + up.port.iotype = device_is_big_endian(dev) ? UPIO_MEM32BE : UPIO_MEM32; 1009 1032 1010 1033 /* See if a Baud clock has been specified */ 1011 1034 baud_mux_clk = devm_clk_get_optional_enabled(dev, "sw_baud"); ··· 1033 1024 1034 1025 priv->baud_mux_clk = baud_mux_clk; 1035 1026 init_real_clk_rates(dev, priv); 1036 - clk_rate = priv->default_mux_rate; 1027 + up.port.uartclk = priv->default_mux_rate; 1037 1028 } else { 1038 1029 dev_dbg(dev, "BAUD MUX clock not specified\n"); 1039 1030 } 1040 - 1041 - if (clk_rate == 0) { 1042 - ret = dev_err_probe(dev, -EINVAL, "clock-frequency or clk not defined\n"); 1043 - goto release_dma; 1044 - } 1045 - 1046 - dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not "); 1047 - 1048 - memset(&up, 0, sizeof(up)); 1049 - up.port.type = PORT_BCM7271; 1050 - up.port.uartclk = clk_rate; 1051 - up.port.dev = dev; 1052 - up.port.mapbase = mapbase; 1053 - up.port.membase = membase; 1054 - up.port.irq = irq; 1055 - up.port.handle_irq = brcmuart_handle_irq; 1056 - up.port.regshift = 2; 1057 - up.port.iotype = of_device_is_big_endian(np) ? 1058 - UPIO_MEM32BE : UPIO_MEM32; 1059 - up.port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF 1060 - | UPF_FIXED_PORT | UPF_FIXED_TYPE; 1061 - up.port.dev = dev; 1062 - up.port.private_data = priv; 1063 - 1064 - /* Check for a fixed line number */ 1065 - ret = of_alias_get_id(np, "serial"); 1066 - if (ret >= 0) 1067 - up.port.line = ret; 1068 1031 1069 1032 /* setup HR timer */ 1070 1033 hrtimer_init(&priv->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
+55 -66
drivers/tty/serial/8250/8250_dw.c
··· 9 9 * LCR is written whilst busy. If it is, then a busy detect interrupt is 10 10 * raised, the LCR needs to be rewritten and the uart status register read. 11 11 */ 12 - #include <linux/acpi.h> 13 12 #include <linux/clk.h> 14 13 #include <linux/delay.h> 15 14 #include <linux/device.h> ··· 16 17 #include <linux/mod_devicetable.h> 17 18 #include <linux/module.h> 18 19 #include <linux/notifier.h> 19 - #include <linux/of.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/pm_runtime.h> 22 22 #include <linux/property.h> ··· 54 56 #define DW_UART_QUIRK_ARMADA_38X BIT(1) 55 57 #define DW_UART_QUIRK_SKIP_SET_RATE BIT(2) 56 58 #define DW_UART_QUIRK_IS_DMA_FC BIT(3) 59 + #define DW_UART_QUIRK_APMC0D08 BIT(4) 57 60 58 61 static inline struct dw8250_data *clk_to_dw8250_data(struct notifier_block *nb) 59 62 { ··· 444 445 445 446 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data) 446 447 { 447 - struct device_node *np = p->dev->of_node; 448 + unsigned int quirks = data->pdata ? data->pdata->quirks : 0; 448 449 449 - if (np) { 450 - unsigned int quirks = data->pdata->quirks; 451 - int id; 452 - 453 - /* get index of serial line, if found in DT aliases */ 454 - id = of_alias_get_id(np, "serial"); 455 - if (id >= 0) 456 - p->line = id; 457 450 #ifdef CONFIG_64BIT 458 - if (quirks & DW_UART_QUIRK_OCTEON) { 459 - p->serial_in = dw8250_serial_inq; 460 - p->serial_out = dw8250_serial_outq; 461 - p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE; 462 - p->type = PORT_OCTEON; 463 - data->skip_autocfg = true; 464 - } 451 + if (quirks & DW_UART_QUIRK_OCTEON) { 452 + p->serial_in = dw8250_serial_inq; 453 + p->serial_out = dw8250_serial_outq; 454 + p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE; 455 + p->type = PORT_OCTEON; 456 + data->skip_autocfg = true; 457 + } 465 458 #endif 466 459 467 - if (of_device_is_big_endian(np)) { 468 - p->iotype = UPIO_MEM32BE; 469 - p->serial_in = dw8250_serial_in32be; 470 - p->serial_out = dw8250_serial_out32be; 471 - } 472 - 473 - if (quirks & DW_UART_QUIRK_ARMADA_38X) 474 - p->serial_out = dw8250_serial_out38x; 475 - if (quirks & DW_UART_QUIRK_SKIP_SET_RATE) 476 - p->set_termios = dw8250_do_set_termios; 477 - if (quirks & DW_UART_QUIRK_IS_DMA_FC) { 478 - data->data.dma.txconf.device_fc = 1; 479 - data->data.dma.rxconf.device_fc = 1; 480 - data->data.dma.prepare_tx_dma = dw8250_prepare_tx_dma; 481 - data->data.dma.prepare_rx_dma = dw8250_prepare_rx_dma; 482 - } 483 - 484 - } else if (acpi_dev_present("APMC0D08", NULL, -1)) { 460 + if (quirks & DW_UART_QUIRK_ARMADA_38X) 461 + p->serial_out = dw8250_serial_out38x; 462 + if (quirks & DW_UART_QUIRK_SKIP_SET_RATE) 463 + p->set_termios = dw8250_do_set_termios; 464 + if (quirks & DW_UART_QUIRK_IS_DMA_FC) { 465 + data->data.dma.txconf.device_fc = 1; 466 + data->data.dma.rxconf.device_fc = 1; 467 + data->data.dma.prepare_tx_dma = dw8250_prepare_tx_dma; 468 + data->data.dma.prepare_rx_dma = dw8250_prepare_rx_dma; 469 + } 470 + if (quirks & DW_UART_QUIRK_APMC0D08) { 485 471 p->iotype = UPIO_MEM32; 486 472 p->regshift = 2; 487 473 p->serial_in = dw8250_serial_in32; ··· 494 510 struct device *dev = &pdev->dev; 495 511 struct dw8250_data *data; 496 512 struct resource *regs; 497 - int irq; 498 513 int err; 499 - u32 val; 500 514 501 515 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 502 516 if (!regs) 503 517 return dev_err_probe(dev, -EINVAL, "no registers defined\n"); 504 518 505 - irq = platform_get_irq_optional(pdev, 0); 506 - /* no interrupt -> fall back to polling */ 507 - if (irq == -ENXIO) 508 - irq = 0; 509 - if (irq < 0) 510 - return irq; 511 - 512 519 spin_lock_init(&p->lock); 513 - p->mapbase = regs->start; 514 - p->irq = irq; 515 520 p->handle_irq = dw8250_handle_irq; 516 521 p->pm = dw8250_do_pm; 517 522 p->type = PORT_8250; 518 - p->flags = UPF_SHARE_IRQ | UPF_FIXED_PORT; 523 + p->flags = UPF_FIXED_PORT; 519 524 p->dev = dev; 520 - p->iotype = UPIO_MEM; 521 - p->serial_in = dw8250_serial_in; 522 - p->serial_out = dw8250_serial_out; 523 525 p->set_ldisc = dw8250_set_ldisc; 524 526 p->set_termios = dw8250_set_termios; 525 - 526 - p->membase = devm_ioremap(dev, regs->start, resource_size(regs)); 527 - if (!p->membase) 528 - return -ENOMEM; 529 527 530 528 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 531 529 if (!data) ··· 520 554 data->uart_16550_compatible = device_property_read_bool(dev, 521 555 "snps,uart-16550-compatible"); 522 556 523 - err = device_property_read_u32(dev, "reg-shift", &val); 524 - if (!err) 525 - p->regshift = val; 557 + p->mapbase = regs->start; 558 + p->mapsize = resource_size(regs); 526 559 527 - err = device_property_read_u32(dev, "reg-io-width", &val); 528 - if (!err && val == 4) { 529 - p->iotype = UPIO_MEM32; 560 + p->membase = devm_ioremap(dev, p->mapbase, p->mapsize); 561 + if (!p->membase) 562 + return -ENOMEM; 563 + 564 + err = uart_read_port_properties(p); 565 + /* no interrupt -> fall back to polling */ 566 + if (err == -ENXIO) 567 + err = 0; 568 + if (err) 569 + return err; 570 + 571 + switch (p->iotype) { 572 + case UPIO_MEM: 573 + p->serial_in = dw8250_serial_in; 574 + p->serial_out = dw8250_serial_out; 575 + break; 576 + case UPIO_MEM32: 530 577 p->serial_in = dw8250_serial_in32; 531 578 p->serial_out = dw8250_serial_out32; 579 + break; 580 + case UPIO_MEM32BE: 581 + p->serial_in = dw8250_serial_in32be; 582 + p->serial_out = dw8250_serial_out32be; 583 + break; 584 + default: 585 + return -ENODEV; 532 586 } 533 587 534 588 if (device_property_read_bool(dev, "dcd-override")) { ··· 575 589 data->msr_mask_off |= UART_MSR_TERI; 576 590 } 577 591 578 - /* Always ask for fixed clock rate from a property. */ 579 - device_property_read_u32(dev, "clock-frequency", &p->uartclk); 580 - 581 592 /* If there is separate baudclk, get the rate from it. */ 582 593 data->clk = devm_clk_get_optional_enabled(dev, "baudclk"); 583 594 if (data->clk == NULL) 584 595 data->clk = devm_clk_get_optional_enabled(dev, NULL); 585 596 if (IS_ERR(data->clk)) 586 - return PTR_ERR(data->clk); 597 + return dev_err_probe(dev, PTR_ERR(data->clk), 598 + "failed to get baudclk\n"); 587 599 588 600 INIT_WORK(&data->clk_work, dw8250_clk_work_cb); 589 601 data->clk_notifier.notifier_call = dw8250_clk_notifier_cb; ··· 746 762 }; 747 763 MODULE_DEVICE_TABLE(of, dw8250_of_match); 748 764 765 + static const struct dw8250_platform_data dw8250_apmc0d08 = { 766 + .usr_reg = DW_UART_USR, 767 + .quirks = DW_UART_QUIRK_APMC0D08, 768 + }; 769 + 749 770 static const struct acpi_device_id dw8250_acpi_match[] = { 750 771 { "80860F0A", (kernel_ulong_t)&dw8250_dw_apb }, 751 772 { "8086228A", (kernel_ulong_t)&dw8250_dw_apb }, 752 773 { "AMD0020", (kernel_ulong_t)&dw8250_dw_apb }, 753 774 { "AMDI0020", (kernel_ulong_t)&dw8250_dw_apb }, 754 775 { "AMDI0022", (kernel_ulong_t)&dw8250_dw_apb }, 755 - { "APMC0D08", (kernel_ulong_t)&dw8250_dw_apb}, 776 + { "APMC0D08", (kernel_ulong_t)&dw8250_apmc0d08 }, 756 777 { "BRCM2032", (kernel_ulong_t)&dw8250_dw_apb }, 757 778 { "HISI0031", (kernel_ulong_t)&dw8250_dw_apb }, 758 779 { "INT33C4", (kernel_ulong_t)&dw8250_dw_apb },
+27 -25
drivers/tty/serial/8250/8250_exar.c
··· 6 6 * 7 7 * Copyright (C) 2017 Sudip Mukherjee, All Rights Reserved. 8 8 */ 9 - #include <linux/acpi.h> 9 + #include <linux/bits.h> 10 + #include <linux/delay.h> 11 + #include <linux/device.h> 10 12 #include <linux/dmi.h> 13 + #include <linux/interrupt.h> 11 14 #include <linux/io.h> 12 - #include <linux/kernel.h> 15 + #include <linux/math.h> 13 16 #include <linux/module.h> 14 17 #include <linux/pci.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/pm.h> 15 20 #include <linux/property.h> 21 + #include <linux/string.h> 22 + #include <linux/types.h> 23 + 24 + #include <linux/serial_8250.h> 16 25 #include <linux/serial_core.h> 17 26 #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> 22 27 23 28 #include <asm/byteorder.h> 24 29 25 30 #include "8250.h" 31 + #include "8250_pcilib.h" 26 32 27 33 #define PCI_DEVICE_ID_ACCESSIO_COM_2S 0x1052 28 34 #define PCI_DEVICE_ID_ACCESSIO_COM_4S 0x105d ··· 235 229 struct uart_8250_port *port) 236 230 { 237 231 const struct exar8250_board *board = priv->board; 238 - unsigned int bar = 0; 239 232 unsigned char status; 233 + int err; 240 234 241 - port->port.iotype = UPIO_MEM; 242 - port->port.mapbase = pci_resource_start(pcidev, bar) + offset; 243 - port->port.membase = priv->virt + offset; 244 - port->port.regshift = board->reg_shift; 235 + err = serial8250_pci_setup_port(pcidev, port, 0, offset, board->reg_shift); 236 + if (err) 237 + return err; 245 238 246 239 /* 247 240 * XR17V35x UARTs have an extra divisor register, DLD that gets enabled ··· 380 375 return NULL; 381 376 382 377 pdev->dev.parent = &pcidev->dev; 383 - ACPI_COMPANION_SET(&pdev->dev, ACPI_COMPANION(&pcidev->dev)); 378 + device_set_node(&pdev->dev, dev_fwnode(&pcidev->dev)); 384 379 385 380 if (device_add_software_node(&pdev->dev, node) < 0 || 386 381 platform_device_add(pdev) < 0) { ··· 718 713 uart.port.irq = pci_irq_vector(pcidev, 0); 719 714 uart.port.dev = &pcidev->dev; 720 715 716 + /* Clear interrupts */ 717 + exar_misc_clear(priv); 718 + 721 719 rc = devm_request_irq(&pcidev->dev, uart.port.irq, exar_misc_handler, 722 720 IRQF_SHARED, "exar_uart", priv); 723 721 if (rc) 724 722 return rc; 725 - 726 - /* Clear interrupts */ 727 - exar_misc_clear(priv); 728 723 729 724 for (i = 0; i < nr_ports && i < maxnr; i++) { 730 725 rc = board->setup(priv, pcidev, &uart, i); ··· 758 753 for (i = 0; i < priv->nr; i++) 759 754 serial8250_unregister_port(priv->line[i]); 760 755 756 + /* Ensure that every init quirk is properly torn down */ 761 757 if (priv->board->exit) 762 758 priv->board->exit(pcidev); 763 759 } 764 760 765 - static int __maybe_unused exar_suspend(struct device *dev) 761 + static int exar_suspend(struct device *dev) 766 762 { 767 - struct pci_dev *pcidev = to_pci_dev(dev); 768 - struct exar8250 *priv = pci_get_drvdata(pcidev); 763 + struct exar8250 *priv = dev_get_drvdata(dev); 769 764 unsigned int i; 770 765 771 766 for (i = 0; i < priv->nr; i++) 772 767 if (priv->line[i] >= 0) 773 768 serial8250_suspend_port(priv->line[i]); 774 769 775 - /* Ensure that every init quirk is properly torn down */ 776 - if (priv->board->exit) 777 - priv->board->exit(pcidev); 778 - 779 770 return 0; 780 771 } 781 772 782 - static int __maybe_unused exar_resume(struct device *dev) 773 + static int exar_resume(struct device *dev) 783 774 { 784 775 struct exar8250 *priv = dev_get_drvdata(dev); 785 776 unsigned int i; ··· 789 788 return 0; 790 789 } 791 790 792 - static SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume); 791 + static DEFINE_SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume); 793 792 794 793 static const struct exar8250_board pbn_fastcom335_2 = { 795 794 .num_ports = 2, ··· 939 938 .probe = exar_pci_probe, 940 939 .remove = exar_pci_remove, 941 940 .driver = { 942 - .pm = &exar_pci_pm, 941 + .pm = pm_sleep_ptr(&exar_pci_pm), 943 942 }, 944 943 .id_table = exar_pci_tbl, 945 944 }; 946 945 module_pci_driver(exar_pci_driver); 947 946 947 + MODULE_IMPORT_NS(SERIAL_8250_PCI); 948 948 MODULE_LICENSE("GPL"); 949 949 MODULE_DESCRIPTION("Exar Serial Driver"); 950 950 MODULE_AUTHOR("Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>");
+7 -13
drivers/tty/serial/8250/8250_ingenic.c
··· 234 234 struct ingenic_uart_data *data; 235 235 const struct ingenic_uart_config *cdata; 236 236 struct resource *regs; 237 - int irq, err, line; 237 + int err; 238 238 239 239 cdata = of_device_get_match_data(&pdev->dev); 240 240 if (!cdata) { 241 241 dev_err(&pdev->dev, "Error: No device match found\n"); 242 242 return -ENODEV; 243 243 } 244 - 245 - irq = platform_get_irq(pdev, 0); 246 - if (irq < 0) 247 - return irq; 248 244 249 245 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 250 246 if (!regs) { ··· 255 259 spin_lock_init(&uart.port.lock); 256 260 uart.port.type = PORT_16550A; 257 261 uart.port.flags = UPF_SKIP_TEST | UPF_IOREMAP | UPF_FIXED_TYPE; 258 - uart.port.iotype = UPIO_MEM; 259 262 uart.port.mapbase = regs->start; 260 - uart.port.regshift = 2; 261 263 uart.port.serial_out = ingenic_uart_serial_out; 262 264 uart.port.serial_in = ingenic_uart_serial_in; 263 - uart.port.irq = irq; 264 265 uart.port.dev = &pdev->dev; 265 - uart.port.fifosize = cdata->fifosize; 266 266 uart.tx_loadsz = cdata->tx_loadsz; 267 267 uart.capabilities = UART_CAP_FIFO | UART_CAP_RTOIE; 268 268 269 - /* Check for a fixed line number */ 270 - line = of_alias_get_id(pdev->dev.of_node, "serial"); 271 - if (line >= 0) 272 - uart.port.line = line; 269 + err = uart_read_port_properties(&uart.port); 270 + if (err) 271 + return err; 272 + 273 + uart.port.regshift = 2; 274 + uart.port.fifosize = cdata->fifosize; 273 275 274 276 uart.port.membase = devm_ioremap(&pdev->dev, regs->start, 275 277 resource_size(regs));
+8 -12
drivers/tty/serial/8250/8250_lpc18xx.c
··· 92 92 struct lpc18xx_uart_data *data; 93 93 struct uart_8250_port uart; 94 94 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; 100 96 101 97 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 102 98 if (!res) { ··· 135 139 goto dis_clk_reg; 136 140 } 137 141 138 - ret = of_alias_get_id(pdev->dev.of_node, "serial"); 139 - if (ret >= 0) 140 - uart.port.line = ret; 141 - 142 142 data->dma.rx_param = data; 143 143 data->dma.tx_param = data; 144 144 145 145 spin_lock_init(&uart.port.lock); 146 146 uart.port.dev = &pdev->dev; 147 - uart.port.irq = irq; 148 - uart.port.iotype = UPIO_MEM32; 149 147 uart.port.mapbase = res->start; 150 - uart.port.regshift = 2; 151 148 uart.port.type = PORT_16550A; 152 149 uart.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SKIP_TEST; 153 150 uart.port.uartclk = clk_get_rate(data->clk_uart); ··· 148 159 uart.port.rs485_config = lpc18xx_rs485_config; 149 160 uart.port.rs485_supported = lpc18xx_rs485_supported; 150 161 uart.port.serial_out = lpc18xx_uart_serial_out; 162 + 163 + ret = uart_read_port_properties(&uart.port); 164 + if (ret) 165 + return ret; 166 + 167 + uart.port.iotype = UPIO_MEM32; 168 + uart.port.regshift = 2; 151 169 152 170 uart.dma = &data->dma; 153 171 uart.dma->rxconf.src_maxburst = 1;
+64 -85
drivers/tty/serial/8250/8250_of.c
··· 4 4 * 5 5 * Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>, IBM Corp. 6 6 */ 7 + 8 + #include <linux/bits.h> 7 9 #include <linux/console.h> 10 + #include <linux/math.h> 8 11 #include <linux/module.h> 9 12 #include <linux/slab.h> 10 13 #include <linux/serial_core.h> ··· 28 25 int line; 29 26 }; 30 27 28 + /* Nuvoton NPCM timeout register */ 29 + #define UART_NPCM_TOR 7 30 + #define UART_NPCM_TOIE BIT(7) /* Timeout Interrupt Enable */ 31 + 32 + static int npcm_startup(struct uart_port *port) 33 + { 34 + /* 35 + * Nuvoton calls the scratch register 'UART_TOR' (timeout 36 + * register). Enable it, and set TIOC (timeout interrupt 37 + * comparator) to be 0x20 for correct operation. 38 + */ 39 + serial_port_out(port, UART_NPCM_TOR, UART_NPCM_TOIE | 0x20); 40 + 41 + return serial8250_do_startup(port); 42 + } 43 + 44 + /* Nuvoton NPCM UARTs have a custom divisor calculation */ 45 + static unsigned int npcm_get_divisor(struct uart_port *port, unsigned int baud, 46 + unsigned int *frac) 47 + { 48 + return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2; 49 + } 50 + 51 + static int npcm_setup(struct uart_port *port) 52 + { 53 + port->get_divisor = npcm_get_divisor; 54 + port->startup = npcm_startup; 55 + return 0; 56 + } 57 + 31 58 /* 32 59 * Fill a struct uart_port for a given device node 33 60 */ ··· 69 36 struct device *dev = &ofdev->dev; 70 37 struct device_node *np = dev->of_node; 71 38 struct uart_port *port = &up->port; 72 - u32 clk, spd, prop; 73 - int ret, irq; 39 + u32 spd; 40 + int ret; 74 41 75 42 memset(port, 0, sizeof *port); 76 43 77 44 pm_runtime_enable(&ofdev->dev); 78 45 pm_runtime_get_sync(&ofdev->dev); 79 - 80 - if (of_property_read_u32(np, "clock-frequency", &clk)) { 81 - 82 - /* Get clk rate through clk driver if present */ 83 - info->clk = devm_clk_get_enabled(dev, NULL); 84 - if (IS_ERR(info->clk)) { 85 - ret = dev_err_probe(dev, PTR_ERR(info->clk), "failed to get clock\n"); 86 - goto err_pmruntime; 87 - } 88 - 89 - clk = clk_get_rate(info->clk); 90 - } 91 - /* If current-speed was set, then try not to change it. */ 92 - if (of_property_read_u32(np, "current-speed", &spd) == 0) 93 - port->custom_divisor = clk / (16 * spd); 94 46 95 47 ret = of_address_to_resource(np, 0, &resource); 96 48 if (ret) { ··· 83 65 goto err_pmruntime; 84 66 } 85 67 86 - port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | 87 - UPF_FIXED_TYPE; 68 + port->dev = &ofdev->dev; 69 + port->flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_FIXED_TYPE; 88 70 spin_lock_init(&port->lock); 89 71 90 72 if (resource_type(&resource) == IORESOURCE_IO) { ··· 93 75 } else { 94 76 port->mapbase = resource.start; 95 77 port->mapsize = resource_size(&resource); 96 - 97 - /* Check for shifted address mapping */ 98 - if (of_property_read_u32(np, "reg-offset", &prop) == 0) { 99 - if (prop >= port->mapsize) { 100 - ret = dev_err_probe(dev, -EINVAL, "reg-offset %u exceeds region size %pa\n", 101 - prop, &port->mapsize); 102 - goto err_pmruntime; 103 - } 104 - 105 - port->mapbase += prop; 106 - port->mapsize -= prop; 107 - } 108 - 109 - port->iotype = UPIO_MEM; 110 - if (of_property_read_u32(np, "reg-io-width", &prop) == 0) { 111 - switch (prop) { 112 - case 1: 113 - port->iotype = UPIO_MEM; 114 - break; 115 - case 2: 116 - port->iotype = UPIO_MEM16; 117 - break; 118 - case 4: 119 - port->iotype = of_device_is_big_endian(np) ? 120 - UPIO_MEM32BE : UPIO_MEM32; 121 - break; 122 - default: 123 - ret = dev_err_probe(dev, -EINVAL, "unsupported reg-io-width (%u)\n", 124 - prop); 125 - goto err_pmruntime; 126 - } 127 - } 128 78 port->flags |= UPF_IOREMAP; 129 79 } 80 + 81 + ret = uart_read_and_validate_port_properties(port); 82 + if (ret) 83 + goto err_pmruntime; 84 + 85 + /* Get clk rate through clk driver if present */ 86 + if (!port->uartclk) { 87 + info->clk = devm_clk_get_enabled(dev, NULL); 88 + if (IS_ERR(info->clk)) { 89 + ret = dev_err_probe(dev, PTR_ERR(info->clk), "failed to get clock\n"); 90 + goto err_pmruntime; 91 + } 92 + 93 + port->uartclk = clk_get_rate(info->clk); 94 + } 95 + /* If current-speed was set, then try not to change it. */ 96 + if (of_property_read_u32(np, "current-speed", &spd) == 0) 97 + port->custom_divisor = port->uartclk / (16 * spd); 130 98 131 99 /* Compatibility with the deprecated pxa driver and 8250_pxa drivers. */ 132 100 if (of_device_is_compatible(np, "mrvl,mmp-uart")) 133 101 port->regshift = 2; 134 - 135 - /* Check for registers offset within the devices address range */ 136 - if (of_property_read_u32(np, "reg-shift", &prop) == 0) 137 - port->regshift = prop; 138 - 139 - /* Check for fifo size */ 140 - if (of_property_read_u32(np, "fifo-size", &prop) == 0) 141 - port->fifosize = prop; 142 - 143 - /* Check for a fixed line number */ 144 - ret = of_alias_get_id(np, "serial"); 145 - if (ret >= 0) 146 - port->line = ret; 147 - 148 - irq = of_irq_get(np, 0); 149 - if (irq < 0) { 150 - if (irq == -EPROBE_DEFER) { 151 - ret = -EPROBE_DEFER; 152 - goto err_pmruntime; 153 - } 154 - /* IRQ support not mandatory */ 155 - irq = 0; 156 - } 157 - 158 - port->irq = irq; 159 102 160 103 info->rst = devm_reset_control_get_optional_shared(&ofdev->dev, NULL); 161 104 if (IS_ERR(info->rst)) { ··· 129 150 goto err_pmruntime; 130 151 131 152 port->type = type; 132 - port->uartclk = clk; 133 - 134 - if (of_property_read_bool(np, "no-loopback-test")) 135 - port->flags |= UPF_SKIP_TEST; 136 - 137 - port->dev = &ofdev->dev; 138 153 port->rs485_config = serial8250_em485_config; 139 154 port->rs485_supported = serial8250_em485_supported; 140 155 up->rs485_start_tx = serial8250_em485_start_tx; ··· 137 164 switch (type) { 138 165 case PORT_RT2880: 139 166 ret = rt288x_setup(port); 140 - if (ret) 141 - goto err_pmruntime; 167 + break; 168 + case PORT_NPCM: 169 + ret = npcm_setup(port); 170 + break; 171 + default: 172 + /* Nothing to do */ 173 + ret = 0; 142 174 break; 143 175 } 176 + if (ret) 177 + goto err_pmruntime; 144 178 145 179 if (IS_REACHABLE(CONFIG_SERIAL_8250_FSL) && 146 180 (of_device_is_compatible(np, "fsl,ns16550") || ··· 220 240 platform_set_drvdata(ofdev, info); 221 241 return 0; 222 242 err_dispose: 223 - irq_dispose_mapping(port8250.port.irq); 224 243 pm_runtime_put_sync(&ofdev->dev); 225 244 pm_runtime_disable(&ofdev->dev); 226 245 err_free:
+10 -19
drivers/tty/serial/8250/8250_omap.c
··· 1394 1394 struct uart_8250_port up; 1395 1395 struct resource *regs; 1396 1396 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; 1402 1398 1403 1399 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1404 1400 if (!regs) { ··· 1415 1419 up.port.dev = &pdev->dev; 1416 1420 up.port.mapbase = regs->start; 1417 1421 up.port.membase = membase; 1418 - up.port.irq = irq; 1419 1422 /* 1420 1423 * It claims to be 16C750 compatible however it is a little different. 1421 1424 * It has EFR and has no FCR7_64byte bit. The AFE (which it claims to ··· 1424 1429 * or pm callback. 1425 1430 */ 1426 1431 up.port.type = PORT_8250; 1427 - up.port.iotype = UPIO_MEM; 1428 - up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SOFT_FLOW | 1429 - UPF_HARD_FLOW; 1432 + up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SOFT_FLOW | UPF_HARD_FLOW; 1430 1433 up.port.private_data = priv; 1431 1434 1432 - up.port.regshift = OMAP_UART_REGSHIFT; 1433 - up.port.fifosize = 64; 1434 1435 up.tx_loadsz = 64; 1435 1436 up.capabilities = UART_CAP_FIFO; 1436 1437 #ifdef CONFIG_PM ··· 1452 1461 up.rs485_stop_tx = serial8250_em485_stop_tx; 1453 1462 up.port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); 1454 1463 1455 - ret = of_alias_get_id(np, "serial"); 1456 - if (ret < 0) { 1457 - dev_err(&pdev->dev, "failed to get alias\n"); 1464 + ret = uart_read_port_properties(&up.port); 1465 + if (ret) 1458 1466 return ret; 1459 - } 1460 - up.port.line = ret; 1461 1467 1462 - if (of_property_read_u32(np, "clock-frequency", &up.port.uartclk)) { 1468 + up.port.regshift = OMAP_UART_REGSHIFT; 1469 + up.port.fifosize = 64; 1470 + 1471 + if (!up.port.uartclk) { 1463 1472 struct clk *clk; 1464 1473 1465 1474 clk = devm_clk_get(&pdev->dev, NULL); ··· 1551 1560 } 1552 1561 #endif 1553 1562 1554 - irq_set_status_flags(irq, IRQ_NOAUTOEN); 1555 - ret = devm_request_irq(&pdev->dev, irq, omap8250_irq, 0, 1563 + irq_set_status_flags(up.port.irq, IRQ_NOAUTOEN); 1564 + ret = devm_request_irq(&pdev->dev, up.port.irq, omap8250_irq, 0, 1556 1565 dev_name(&pdev->dev), priv); 1557 1566 if (ret < 0) 1558 1567 return ret;
+162 -13
drivers/tty/serial/8250/8250_pci1xxxx.c
··· 7 7 * Copyright (C) 2022 Microchip Technology Inc., All Rights Reserved. 8 8 */ 9 9 10 + #include <linux/array_size.h> 10 11 #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> 13 17 #include <linux/io.h> 14 18 #include <linux/iopoll.h> 15 - #include <linux/kernel.h> 19 + #include <linux/minmax.h> 16 20 #include <linux/module.h> 21 + #include <linux/mutex.h> 22 + #include <linux/overflow.h> 17 23 #include <linux/pci.h> 24 + #include <linux/pm.h> 18 25 #include <linux/serial_core.h> 19 26 #include <linux/serial_reg.h> 20 27 #include <linux/serial_8250.h> 21 - #include <linux/slab.h> 28 + #include <linux/spinlock.h> 22 29 #include <linux/string.h> 23 - #include <linux/units.h> 30 + #include <linux/time.h> 24 31 #include <linux/tty.h> 25 32 #include <linux/tty_flip.h> 26 - #include <linux/8250_pci.h> 33 + #include <linux/types.h> 34 + #include <linux/units.h> 27 35 28 36 #include <asm/byteorder.h> 29 37 ··· 75 67 #define SYSLOCK_RETRY_CNT 1000 76 68 77 69 #define UART_RX_BYTE_FIFO 0x00 70 + #define UART_TX_BYTE_FIFO 0x00 78 71 #define UART_FIFO_CTL 0x02 79 72 80 73 #define UART_ACTV_REG 0x11 ··· 90 81 #define ADCL_CFG_PIN_SEL BIT(1) 91 82 #define ADCL_CFG_EN BIT(0) 92 83 93 - #define UART_BIT_SAMPLE_CNT 16 84 + #define UART_BIT_SAMPLE_CNT_8 8 85 + #define UART_BIT_SAMPLE_CNT_16 16 94 86 #define BAUD_CLOCK_DIV_INT_MSK GENMASK(31, 8) 95 87 #define ADCL_CFG_RTS_DELAY_MASK GENMASK(11, 8) 96 - #define UART_CLOCK_DEFAULT (62500 * HZ_PER_KHZ) 97 88 98 89 #define UART_WAKE_REG 0x8C 99 90 #define UART_WAKE_MASK_REG 0x90 ··· 104 95 (UART_WAKE_N_PIN | UART_WAKE_NCTS | UART_WAKE_INT) 105 96 106 97 #define UART_BAUD_CLK_DIVISOR_REG 0x54 98 + #define FRAC_DIV_CFG_REG 0x58 107 99 108 100 #define UART_RESET_REG 0x94 109 101 #define UART_RESET_D3_RESET_DISABLE BIT(16) 110 102 111 103 #define UART_BURST_STATUS_REG 0x9C 104 + #define UART_TX_BURST_FIFO 0xA0 112 105 #define UART_RX_BURST_FIFO 0xA4 106 + 107 + #define UART_BIT_DIVISOR_8 0x26731000 108 + #define UART_BIT_DIVISOR_16 0x6ef71000 109 + #define UART_BAUD_4MBPS 4000000 113 110 114 111 #define MAX_PORTS 4 115 112 #define PORT_OFFSET 0x100 ··· 124 109 #define UART_BURST_SIZE 4 125 110 126 111 #define UART_BST_STAT_RX_COUNT_MASK 0x00FF 112 + #define UART_BST_STAT_TX_COUNT_MASK 0xFF00 127 113 #define UART_BST_STAT_IIR_INT_PEND 0x100000 128 114 #define UART_LSR_OVERRUN_ERR_CLR 0x43 129 115 #define UART_BST_STAT_LSR_RX_MASK 0x9F000000 ··· 132 116 #define UART_BST_STAT_LSR_OVERRUN_ERR 0x2000000 133 117 #define UART_BST_STAT_LSR_PARITY_ERR 0x4000000 134 118 #define UART_BST_STAT_LSR_FRAME_ERR 0x8000000 119 + #define UART_BST_STAT_LSR_THRE 0x20000000 135 120 136 121 struct pci1xxxx_8250 { 137 122 unsigned int nr; ··· 223 206 static unsigned int pci1xxxx_get_divisor(struct uart_port *port, 224 207 unsigned int baud, unsigned int *frac) 225 208 { 209 + unsigned int uart_sample_cnt; 226 210 unsigned int quot; 211 + 212 + if (baud >= UART_BAUD_4MBPS) 213 + uart_sample_cnt = UART_BIT_SAMPLE_CNT_8; 214 + else 215 + uart_sample_cnt = UART_BIT_SAMPLE_CNT_16; 227 216 228 217 /* 229 218 * Calculate baud rate sampling period in nanoseconds. 230 219 * Fractional part x denotes x/255 parts of a nanosecond. 231 220 */ 232 - quot = NSEC_PER_SEC / (baud * UART_BIT_SAMPLE_CNT); 233 - *frac = (NSEC_PER_SEC - quot * baud * UART_BIT_SAMPLE_CNT) * 234 - 255 / UART_BIT_SAMPLE_CNT / baud; 221 + quot = NSEC_PER_SEC / (baud * uart_sample_cnt); 222 + *frac = (NSEC_PER_SEC - quot * baud * uart_sample_cnt) * 223 + 255 / uart_sample_cnt / baud; 235 224 236 225 return quot; 237 226 } ··· 245 222 static void pci1xxxx_set_divisor(struct uart_port *port, unsigned int baud, 246 223 unsigned int quot, unsigned int frac) 247 224 { 225 + if (baud >= UART_BAUD_4MBPS) 226 + writel(UART_BIT_DIVISOR_8, port->membase + FRAC_DIV_CFG_REG); 227 + else 228 + writel(UART_BIT_DIVISOR_16, port->membase + FRAC_DIV_CFG_REG); 229 + 248 230 writel(FIELD_PREP(BAUD_CLOCK_DIV_INT_MSK, quot) | frac, 249 231 port->membase + UART_BAUD_CLK_DIVISOR_REG); 250 232 } ··· 261 233 u32 delay_in_baud_periods; 262 234 u32 baud_period_in_ns; 263 235 u32 mode_cfg = 0; 236 + u32 sample_cnt; 264 237 u32 clock_div; 238 + u32 frac_div; 239 + 240 + frac_div = readl(port->membase + FRAC_DIV_CFG_REG); 241 + 242 + if (frac_div == UART_BIT_DIVISOR_16) 243 + sample_cnt = UART_BIT_SAMPLE_CNT_16; 244 + else 245 + sample_cnt = UART_BIT_SAMPLE_CNT_8; 265 246 266 247 /* 267 248 * pci1xxxx's uart hardware supports only RTS delay after ··· 286 249 clock_div = readl(port->membase + UART_BAUD_CLK_DIVISOR_REG); 287 250 baud_period_in_ns = 288 251 FIELD_GET(BAUD_CLOCK_DIV_INT_MSK, clock_div) * 289 - UART_BIT_SAMPLE_CNT; 252 + sample_cnt; 290 253 delay_in_baud_periods = 291 254 rs485->delay_rts_after_send * NSEC_PER_MSEC / 292 255 baud_period_in_ns; ··· 381 344 } 382 345 } 383 346 347 + static void pci1xxxx_process_write_data(struct uart_port *port, 348 + struct circ_buf *xmit, 349 + int *data_empty_count, 350 + u32 *valid_byte_count) 351 + { 352 + u32 valid_burst_count = *valid_byte_count / UART_BURST_SIZE; 353 + 354 + /* 355 + * Each transaction transfers data in DWORDs. If there are less than 356 + * four remaining valid_byte_count to transfer or if the circular 357 + * buffer has insufficient space for a DWORD, the data is transferred 358 + * one byte at a time. 359 + */ 360 + while (valid_burst_count) { 361 + if (*data_empty_count - UART_BURST_SIZE < 0) 362 + break; 363 + if (xmit->tail > (UART_XMIT_SIZE - UART_BURST_SIZE)) 364 + break; 365 + writel(*(unsigned int *)&xmit->buf[xmit->tail], 366 + port->membase + UART_TX_BURST_FIFO); 367 + *valid_byte_count -= UART_BURST_SIZE; 368 + *data_empty_count -= UART_BURST_SIZE; 369 + valid_burst_count -= UART_BYTE_SIZE; 370 + 371 + xmit->tail = (xmit->tail + UART_BURST_SIZE) & 372 + (UART_XMIT_SIZE - 1); 373 + } 374 + 375 + while (*valid_byte_count) { 376 + if (*data_empty_count - UART_BYTE_SIZE < 0) 377 + break; 378 + writeb(xmit->buf[xmit->tail], port->membase + 379 + UART_TX_BYTE_FIFO); 380 + *data_empty_count -= UART_BYTE_SIZE; 381 + *valid_byte_count -= UART_BYTE_SIZE; 382 + 383 + /* 384 + * When the tail of the circular buffer is reached, the next 385 + * byte is transferred to the beginning of the buffer. 386 + */ 387 + xmit->tail = (xmit->tail + UART_BYTE_SIZE) & 388 + (UART_XMIT_SIZE - 1); 389 + 390 + /* 391 + * If there are any pending burst count, data is handled by 392 + * transmitting DWORDs at a time. 393 + */ 394 + if (valid_burst_count && (xmit->tail < 395 + (UART_XMIT_SIZE - UART_BURST_SIZE))) 396 + break; 397 + } 398 + } 399 + 400 + static void pci1xxxx_tx_burst(struct uart_port *port, u32 uart_status) 401 + { 402 + struct uart_8250_port *up = up_to_u8250p(port); 403 + u32 valid_byte_count; 404 + int data_empty_count; 405 + struct circ_buf *xmit; 406 + 407 + xmit = &port->state->xmit; 408 + 409 + if (port->x_char) { 410 + writeb(port->x_char, port->membase + UART_TX); 411 + port->icount.tx++; 412 + port->x_char = 0; 413 + return; 414 + } 415 + 416 + if ((uart_tx_stopped(port)) || (uart_circ_empty(xmit))) { 417 + port->ops->stop_tx(port); 418 + } else { 419 + data_empty_count = (pci1xxxx_read_burst_status(port) & 420 + UART_BST_STAT_TX_COUNT_MASK) >> 8; 421 + do { 422 + valid_byte_count = uart_circ_chars_pending(xmit); 423 + 424 + pci1xxxx_process_write_data(port, xmit, 425 + &data_empty_count, 426 + &valid_byte_count); 427 + 428 + port->icount.tx++; 429 + if (uart_circ_empty(xmit)) 430 + break; 431 + } while (data_empty_count && valid_byte_count); 432 + } 433 + 434 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 435 + uart_write_wakeup(port); 436 + 437 + /* 438 + * With RPM enabled, we have to wait until the FIFO is empty before 439 + * the HW can go idle. So we get here once again with empty FIFO and 440 + * disable the interrupt and RPM in __stop_tx() 441 + */ 442 + if (uart_circ_empty(xmit) && !(up->capabilities & UART_CAP_RPM)) 443 + port->ops->stop_tx(port); 444 + } 445 + 384 446 static int pci1xxxx_handle_irq(struct uart_port *port) 385 447 { 386 448 unsigned long flags; ··· 494 358 495 359 if (status & UART_BST_STAT_LSR_RX_MASK) 496 360 pci1xxxx_rx_burst(port, status); 361 + 362 + if (status & UART_BST_STAT_LSR_THRE) 363 + pci1xxxx_tx_burst(port, status); 497 364 498 365 spin_unlock_irqrestore(&port->lock, flags); 499 366 ··· 620 481 621 482 port->port.flags |= UPF_FIXED_TYPE | UPF_SKIP_TEST; 622 483 port->port.type = PORT_MCHP16550A; 484 + /* 485 + * 8250 core considers prescaller value to be always 16. 486 + * The MCHP ports support downscaled mode and hence the 487 + * functional UART clock can be lower, i.e. 62.5MHz, than 488 + * software expects in order to support higher baud rates. 489 + * Assign here 64MHz to support 4Mbps. 490 + * 491 + * The value itself is not really used anywhere except baud 492 + * rate calculations, so we can mangle it as we wish. 493 + */ 494 + port->port.uartclk = 64 * HZ_PER_MHZ; 623 495 port->port.set_termios = serial8250_do_set_termios; 624 496 port->port.get_divisor = pci1xxxx_get_divisor; 625 497 port->port.set_divisor = pci1xxxx_set_divisor; ··· 744 594 745 595 memset(&uart, 0, sizeof(uart)); 746 596 uart.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT; 747 - uart.port.uartclk = UART_CLOCK_DEFAULT; 748 597 uart.port.dev = dev; 749 598 750 599 if (num_vectors == max_vec_reqd)
+1 -49
drivers/tty/serial/8250/8250_port.c
··· 38 38 39 39 #include "8250.h" 40 40 41 - /* Nuvoton NPCM timeout register */ 42 - #define UART_NPCM_TOR 7 43 - #define UART_NPCM_TOIE BIT(7) /* Timeout Interrupt Enable */ 44 - 45 41 /* 46 42 * Debugging. 47 43 */ ··· 1325 1329 inb_p(ICP); 1326 1330 } 1327 1331 1328 - if (uart_console(port)) 1329 - console_lock(); 1330 - 1331 1332 /* forget possible initially masked and pending IRQ */ 1332 1333 probe_irq_off(probe_irq_on()); 1333 1334 save_mcr = serial8250_in_MCR(up); ··· 1363 1370 1364 1371 if (port->flags & UPF_FOURPORT) 1365 1372 outb_p(save_ICP, ICP); 1366 - 1367 - if (uart_console(port)) 1368 - console_unlock(); 1369 1373 1370 1374 port->irq = (irq > 0) ? irq : 0; 1371 1375 } ··· 2225 2235 UART_DA830_PWREMU_MGMT_FREE); 2226 2236 } 2227 2237 2228 - if (port->type == PORT_NPCM) { 2229 - /* 2230 - * Nuvoton calls the scratch register 'UART_TOR' (timeout 2231 - * register). Enable it, and set TIOC (timeout interrupt 2232 - * comparator) to be 0x20 for correct operation. 2233 - */ 2234 - serial_port_out(port, UART_NPCM_TOR, UART_NPCM_TOIE | 0x20); 2235 - } 2236 - 2237 2238 #ifdef CONFIG_SERIAL_8250_RSA 2238 2239 /* 2239 2240 * If this is an RSA port, see if we can kick it up to the ··· 2526 2545 serial8250_do_shutdown(port); 2527 2546 } 2528 2547 2529 - /* Nuvoton NPCM UARTs have a custom divisor calculation */ 2530 - static unsigned int npcm_get_divisor(struct uart_8250_port *up, 2531 - unsigned int baud) 2532 - { 2533 - struct uart_port *port = &up->port; 2534 - 2535 - return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2; 2536 - } 2537 - 2538 2548 static unsigned int serial8250_do_get_divisor(struct uart_port *port, 2539 2549 unsigned int baud, 2540 2550 unsigned int *frac) ··· 2570 2598 quot = 0x8001; 2571 2599 else if (magic_multiplier && baud >= port->uartclk / 12) 2572 2600 quot = 0x8002; 2573 - else if (up->port.type == PORT_NPCM) 2574 - quot = npcm_get_divisor(up, baud); 2575 2601 else 2576 2602 quot = uart_get_divisor(port, baud); 2577 2603 ··· 2684 2714 */ 2685 2715 void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk) 2686 2716 { 2687 - struct uart_8250_port *up = up_to_u8250p(port); 2688 2717 struct tty_port *tport = &port->state->port; 2689 - unsigned int baud, quot, frac = 0; 2690 - struct ktermios *termios; 2691 2718 struct tty_struct *tty; 2692 - unsigned long flags; 2693 2719 2694 2720 tty = tty_port_tty_get(tport); 2695 2721 if (!tty) { ··· 2706 2740 if (!tty_port_initialized(tport)) 2707 2741 goto out_unlock; 2708 2742 2709 - termios = &tty->termios; 2710 - 2711 - baud = serial8250_get_baud_rate(port, termios, NULL); 2712 - quot = serial8250_get_divisor(port, baud, &frac); 2713 - 2714 - serial8250_rpm_get(up); 2715 - uart_port_lock_irqsave(port, &flags); 2716 - 2717 - uart_update_timeout(port, termios->c_cflag, baud); 2718 - 2719 - serial8250_set_divisor(port, baud, quot, frac); 2720 - serial_port_out(port, UART_LCR, up->lcr); 2721 - 2722 - uart_port_unlock_irqrestore(port, flags); 2723 - serial8250_rpm_put(up); 2743 + serial8250_do_set_termios(port, &tty->termios, NULL); 2724 2744 2725 2745 out_unlock: 2726 2746 mutex_unlock(&tport->mutex);
+9 -13
drivers/tty/serial/8250/8250_pxa.c
··· 92 92 struct uart_8250_port uart = {}; 93 93 struct pxa8250_data *data; 94 94 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; 100 96 101 97 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0); 102 98 if (!mmres) ··· 110 114 if (ret) 111 115 return ret; 112 116 113 - ret = of_alias_get_id(pdev->dev.of_node, "serial"); 114 - if (ret >= 0) 115 - uart.port.line = ret; 116 - 117 117 uart.port.type = PORT_XSCALE; 118 - uart.port.iotype = UPIO_MEM32; 119 118 uart.port.mapbase = mmres->start; 120 - uart.port.regshift = 2; 121 - uart.port.irq = irq; 122 - uart.port.fifosize = 64; 123 119 uart.port.flags = UPF_IOREMAP | UPF_SKIP_TEST | UPF_FIXED_TYPE; 124 120 uart.port.dev = &pdev->dev; 125 121 uart.port.uartclk = clk_get_rate(data->clk); 126 122 uart.port.pm = serial_pxa_pm; 127 123 uart.port.private_data = data; 124 + 125 + ret = uart_read_port_properties(&uart.port); 126 + if (ret) 127 + return ret; 128 + 129 + uart.port.iotype = UPIO_MEM32; 130 + uart.port.regshift = 2; 131 + uart.port.fifosize = 64; 128 132 uart.dl_write = serial_pxa_dl_write; 129 133 130 134 ret = serial8250_register_8250_port(&uart);
+9 -17
drivers/tty/serial/8250/8250_tegra.c
··· 57 57 port = &port8250.port; 58 58 spin_lock_init(&port->lock); 59 59 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; 64 61 port->type = PORT_TEGRA; 65 - port->irqflags |= IRQF_SHARED; 66 62 port->dev = &pdev->dev; 67 63 port->handle_break = tegra_uart_handle_break; 68 - 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 64 79 65 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 80 66 if (!res) ··· 74 88 port->mapbase = res->start; 75 89 port->mapsize = resource_size(res); 76 90 91 + ret = uart_read_port_properties(port); 92 + if (ret) 93 + return ret; 94 + 95 + port->iotype = UPIO_MEM32; 96 + port->regshift = 2; 97 + 77 98 uart->rst = devm_reset_control_get_optional_shared(&pdev->dev, NULL); 78 99 if (IS_ERR(uart->rst)) 79 100 return PTR_ERR(uart->rst); 80 101 81 - if (device_property_read_u32(&pdev->dev, "clock-frequency", 82 - &port->uartclk)) { 102 + if (!port->uartclk) { 83 103 uart->clk = devm_clk_get(&pdev->dev, NULL); 84 104 if (IS_ERR(uart->clk)) { 85 105 dev_err(&pdev->dev, "failed to get clock!\n");
+4 -13
drivers/tty/serial/8250/8250_uniphier.c
··· 162 162 struct uniphier8250_priv *priv; 163 163 struct resource *regs; 164 164 void __iomem *membase; 165 - int irq; 166 165 int ret; 167 166 168 167 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 174 175 if (!membase) 175 176 return -ENOMEM; 176 177 177 - irq = platform_get_irq(pdev, 0); 178 - if (irq < 0) 179 - return irq; 180 - 181 178 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 182 179 if (!priv) 183 180 return -ENOMEM; 184 181 185 182 memset(&up, 0, sizeof(up)); 186 - 187 - ret = of_alias_get_id(dev->of_node, "serial"); 188 - if (ret < 0) { 189 - dev_err(dev, "failed to get alias id\n"); 190 - return ret; 191 - } 192 - up.port.line = ret; 193 183 194 184 priv->clk = devm_clk_get(dev, NULL); 195 185 if (IS_ERR(priv->clk)) { ··· 199 211 up.port.mapbase = regs->start; 200 212 up.port.mapsize = resource_size(regs); 201 213 up.port.membase = membase; 202 - up.port.irq = irq; 214 + 215 + ret = uart_read_port_properties(&up.port); 216 + if (ret) 217 + return ret; 203 218 204 219 up.port.type = PORT_16550A; 205 220 up.port.iotype = UPIO_MEM32;
+1
drivers/tty/serial/8250/Kconfig
··· 149 149 config SERIAL_8250_EXAR 150 150 tristate "8250/16550 Exar/Commtech PCI/PCIe device support" 151 151 depends on SERIAL_8250 && PCI 152 + select SERIAL_8250_PCILIB 152 153 default SERIAL_8250 153 154 help 154 155 This builds support for XR17C1xx, XR17V3xx and some Commtech
+8 -16
drivers/tty/serial/amba-pl011.c
··· 348 348 flag = TTY_FRAME; 349 349 } 350 350 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); 355 352 if (!sysrq) 356 353 uart_insert_char(&uap->port, ch, UART011_DR_OE, ch, flag); 357 354 } ··· 1014 1017 ret = pl011_dma_rx_trigger_dma(uap); 1015 1018 1016 1019 pl011_dma_rx_chars(uap, pending, lastbuf, false); 1017 - uart_port_unlock_irq(&uap->port); 1020 + uart_unlock_and_check_sysrq(&uap->port); 1018 1021 /* 1019 1022 * Do this check after we picked the DMA chars so we don't 1020 1023 * get some IRQ immediately from RX. ··· 1537 1540 static irqreturn_t pl011_int(int irq, void *dev_id) 1538 1541 { 1539 1542 struct uart_amba_port *uap = dev_id; 1540 - unsigned long flags; 1541 1543 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; 1542 1544 int handled = 0; 1543 1545 1544 - uart_port_lock_irqsave(&uap->port, &flags); 1546 + uart_port_lock(&uap->port); 1545 1547 status = pl011_read(uap, REG_RIS) & uap->im; 1546 1548 if (status) { 1547 1549 do { ··· 1569 1573 handled = 1; 1570 1574 } 1571 1575 1572 - uart_port_unlock_irqrestore(&uap->port, flags); 1576 + uart_unlock_and_check_sysrq(&uap->port); 1573 1577 1574 1578 return IRQ_RETVAL(handled); 1575 1579 } ··· 2318 2322 2319 2323 clk_enable(uap->clk); 2320 2324 2321 - local_irq_save(flags); 2322 - if (uap->port.sysrq) 2323 - locked = 0; 2324 - else if (oops_in_progress) 2325 - locked = uart_port_trylock(&uap->port); 2325 + if (oops_in_progress) 2326 + locked = uart_port_trylock_irqsave(&uap->port, &flags); 2326 2327 else 2327 - uart_port_lock(&uap->port); 2328 + uart_port_lock_irqsave(&uap->port, &flags); 2328 2329 2329 2330 /* 2330 2331 * First save the CR then disable the interrupts ··· 2347 2354 pl011_write(old_cr, uap, REG_CR); 2348 2355 2349 2356 if (locked) 2350 - uart_port_unlock(&uap->port); 2351 - local_irq_restore(flags); 2357 + uart_port_unlock_irqrestore(&uap->port, flags); 2352 2358 2353 2359 clk_disable(uap->clk); 2354 2360 }
+6 -12
drivers/tty/serial/ar933x_uart.c
··· 378 378 up->port.icount.rx++; 379 379 ch = rdata & AR933X_UART_DATA_TX_RX_MASK; 380 380 381 - if (uart_handle_sysrq_char(&up->port, ch)) 381 + if (uart_prepare_sysrq_char(&up->port, ch)) 382 382 continue; 383 383 384 384 if ((up->port.ignore_status_mask & AR933X_DUMMY_STATUS_RD) == 0) ··· 468 468 ar933x_uart_tx_chars(up); 469 469 } 470 470 471 - uart_port_unlock(&up->port); 471 + uart_unlock_and_check_sysrq(&up->port); 472 472 473 473 return IRQ_HANDLED; 474 474 } ··· 627 627 unsigned int int_en; 628 628 int locked = 1; 629 629 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); 636 632 else 637 - uart_port_lock(&up->port); 633 + uart_port_lock_irqsave(&up->port, &flags); 638 634 639 635 /* 640 636 * First save the IER then disable the interrupts ··· 650 654 ar933x_uart_write(up, AR933X_UART_INT_REG, AR933X_UART_INT_ALLINTS); 651 655 652 656 if (locked) 653 - uart_port_unlock(&up->port); 654 - 655 - local_irq_restore(flags); 657 + uart_port_unlock_irqrestore(&up->port, flags); 656 658 } 657 659 658 660 static int ar933x_uart_console_setup(struct console *co, char *options)
+8 -16
drivers/tty/serial/bcm63xx_uart.c
··· 285 285 flag = TTY_PARITY; 286 286 } 287 287 288 - if (uart_handle_sysrq_char(port, c)) 288 + if (uart_prepare_sysrq_char(port, c)) 289 289 continue; 290 - 291 290 292 291 if ((cstat & port->ignore_status_mask) == 0) 293 292 tty_insert_flip_char(tty_port, c, flag); ··· 352 353 estat & UART_EXTINP_DCD_MASK); 353 354 } 354 355 355 - uart_port_unlock(port); 356 + uart_unlock_and_check_sysrq(port); 356 357 return IRQ_HANDLED; 357 358 } 358 359 ··· 702 703 { 703 704 struct uart_port *port; 704 705 unsigned long flags; 705 - int locked; 706 + int locked = 1; 706 707 707 708 port = &ports[co->index]; 708 709 709 - local_irq_save(flags); 710 - if (port->sysrq) { 711 - /* bcm_uart_interrupt() already took the lock */ 712 - locked = 0; 713 - } else if (oops_in_progress) { 714 - locked = uart_port_trylock(port); 715 - } else { 716 - uart_port_lock(port); 717 - locked = 1; 718 - } 710 + if (oops_in_progress) 711 + locked = uart_port_trylock_irqsave(port, &flags); 712 + else 713 + uart_port_lock_irqsave(port, &flags); 719 714 720 715 /* call helper to deal with \r\n */ 721 716 uart_console_write(port, s, count, bcm_console_putchar); ··· 718 725 wait_for_xmitr(port); 719 726 720 727 if (locked) 721 - uart_port_unlock(port); 722 - local_irq_restore(flags); 728 + uart_port_unlock_irqrestore(port, flags); 723 729 } 724 730 725 731 /*
-1
drivers/tty/serial/fsl_linflexuart.c
··· 837 837 return ret; 838 838 839 839 sport->dev = &pdev->dev; 840 - sport->type = PORT_LINFLEXUART; 841 840 sport->iotype = UPIO_MEM; 842 841 sport->irq = ret; 843 842 sport->ops = &linflex_pops;
-1
drivers/tty/serial/jsm/jsm_cls.c
··· 395 395 * which in this case is the break signal. 396 396 */ 397 397 if (linestatus & error_mask) { 398 - linestatus = 0; 399 398 readb(&ch->ch_cls_uart->txrx); 400 399 continue; 401 400 }
+7 -12
drivers/tty/serial/lpc32xx_hs.c
··· 136 136 int locked = 1; 137 137 138 138 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); 144 141 else 145 - uart_port_lock(&up->port); 142 + uart_port_lock_irqsave(&up->port, &flags); 146 143 147 144 uart_console_write(&up->port, s, count, lpc32xx_hsuart_console_putchar); 148 145 wait_for_xmit_empty(&up->port); 149 146 150 147 if (locked) 151 - uart_port_unlock(&up->port); 152 - local_irq_restore(flags); 148 + uart_port_unlock_irqrestore(&up->port, flags); 153 149 } 154 150 155 151 static int __init lpc32xx_hsuart_console_setup(struct console *co, ··· 229 233 230 234 hsu_rate++; 231 235 } 232 - if (hsu_rate > 0xFF) 233 - hsu_rate = 0xFF; 234 236 235 237 return goodrate; 236 238 } ··· 262 268 tty_insert_flip_char(tport, 0, TTY_FRAME); 263 269 } 264 270 265 - tty_insert_flip_char(tport, (tmp & 0xFF), flag); 271 + if (!uart_prepare_sysrq_char(port, tmp & 0xff)) 272 + tty_insert_flip_char(tport, (tmp & 0xFF), flag); 266 273 267 274 tmp = readl(LPC32XX_HSUART_FIFO(port->membase)); 268 275 } ··· 328 333 __serial_lpc32xx_tx(port); 329 334 } 330 335 331 - uart_port_unlock(port); 336 + uart_unlock_and_check_sysrq(port); 332 337 333 338 return IRQ_HANDLED; 334 339 }
+164 -163
drivers/tty/serial/max310x.c
··· 30 30 #define MAX310X_MAJOR 204 31 31 #define MAX310X_MINOR 209 32 32 #define MAX310X_UART_NRMAX 16 33 + #define MAX310X_MAX_PORTS 4 /* Maximum number of UART ports per IC. */ 33 34 34 35 /* MAX310X register definitions */ 35 36 #define MAX310X_RHR_REG (0x00) /* RX FIFO */ ··· 67 66 #define MAX310X_BRGDIVMSB_REG (0x1d) /* Baud rate divisor MSB */ 68 67 #define MAX310X_CLKSRC_REG (0x1e) /* Clock source */ 69 68 #define MAX310X_REG_1F (0x1f) 69 + #define MAX310X_EXTREG_START (0x20) /* Only relevant in SPI mode. */ 70 70 71 71 #define MAX310X_REVID_REG MAX310X_REG_1F /* Revision ID */ 72 72 ··· 75 73 #define MAX310X_GLOBALCMD_REG MAX310X_REG_1F /* Global Command (WO) */ 76 74 77 75 /* Extended registers */ 78 - #define MAX310X_SPI_REVID_EXTREG MAX310X_REG_05 /* Revision ID */ 79 - #define MAX310X_I2C_REVID_EXTREG (0x25) /* Revision ID */ 80 - 76 + #define MAX310X_REVID_EXTREG (0x25) /* Revision ID 77 + * (extended addressing space) 78 + */ 81 79 /* IRQ register bits */ 82 80 #define MAX310X_IRQ_LSR_BIT (1 << 0) /* LSR interrupt */ 83 81 #define MAX310X_IRQ_SPCHR_BIT (1 << 1) /* Special char interrupt */ ··· 162 160 #define MAX310X_IRDA_SIR_BIT (1 << 1) /* SIR mode enable */ 163 161 164 162 /* Flow control trigger level register masks */ 165 - #define MAX310X_FLOWLVL_HALT_MASK (0x000f) /* Flow control halt level */ 166 - #define MAX310X_FLOWLVL_RES_MASK (0x00f0) /* Flow control resume level */ 163 + #define MAX310X_FLOWLVL_HALT_MASK GENMASK(3, 0) /* Flow control halt level */ 164 + #define MAX310X_FLOWLVL_RES_MASK GENMASK(7, 4) /* Flow control resume level */ 167 165 #define MAX310X_FLOWLVL_HALT(words) ((words / 8) & 0x0f) 168 166 #define MAX310X_FLOWLVL_RES(words) (((words / 8) & 0x0f) << 4) 169 167 170 168 /* FIFO interrupt trigger level register masks */ 171 - #define MAX310X_FIFOTRIGLVL_TX_MASK (0x0f) /* TX FIFO trigger level */ 172 - #define MAX310X_FIFOTRIGLVL_RX_MASK (0xf0) /* RX FIFO trigger level */ 169 + #define MAX310X_FIFOTRIGLVL_TX_MASK GENMASK(3, 0) /* TX FIFO trigger level */ 170 + #define MAX310X_FIFOTRIGLVL_RX_MASK GENMASK(7, 4) /* RX FIFO trigger level */ 173 171 #define MAX310X_FIFOTRIGLVL_TX(words) ((words / 8) & 0x0f) 174 172 #define MAX310X_FIFOTRIGLVL_RX(words) (((words / 8) & 0x0f) << 4) 175 173 ··· 179 177 #define MAX310X_FLOWCTRL_GPIADDR_BIT (1 << 2) /* Enables that GPIO inputs 180 178 * are used in conjunction with 181 179 * XOFF2 for definition of 182 - * special character */ 180 + * special character 181 + */ 183 182 #define MAX310X_FLOWCTRL_SWFLOWEN_BIT (1 << 3) /* Auto SW flow ctrl enable */ 184 183 #define MAX310X_FLOWCTRL_SWFLOW0_BIT (1 << 4) /* SWFLOW bit 0 */ 185 184 #define MAX310X_FLOWCTRL_SWFLOW1_BIT (1 << 5) /* SWFLOW bit 1 ··· 217 214 */ 218 215 219 216 /* PLL configuration register masks */ 220 - #define MAX310X_PLLCFG_PREDIV_MASK (0x3f) /* PLL predivision value */ 221 - #define MAX310X_PLLCFG_PLLFACTOR_MASK (0xc0) /* PLL multiplication factor */ 217 + #define MAX310X_PLLCFG_PREDIV_MASK GENMASK(5, 0) /* PLL predivision value */ 218 + #define MAX310X_PLLCFG_PLLFACTOR_MASK GENMASK(7, 6) /* PLL multiplication factor */ 222 219 223 220 /* Baud rate generator configuration register bits */ 224 221 #define MAX310X_BRGCFG_2XMODE_BIT (1 << 4) /* Double baud rate */ ··· 237 234 238 235 /* Misc definitions */ 239 236 #define MAX310X_FIFO_SIZE (128) 240 - #define MAX310x_REV_MASK (0xf8) 237 + #define MAX310x_REV_MASK GENMASK(7, 3) 241 238 #define MAX310X_WRITE_BIT 0x80 242 239 243 240 /* Port startup definitions */ ··· 260 257 261 258 struct max310x_if_cfg { 262 259 int (*extended_reg_enable)(struct device *dev, bool enable); 263 - 264 - unsigned int rev_id_reg; 260 + u8 rev_id_offset; 265 261 }; 266 262 267 263 struct max310x_devtype { 268 264 struct { 269 265 unsigned short min; 270 266 unsigned short max; 271 - } slave_addr; 272 - char name[9]; 267 + } slave_addr; /* Relevant only in I2C mode. */ 273 268 int nr; 269 + char name[9]; 274 270 u8 mode1; 275 - int (*detect)(struct device *); 276 - void (*power)(struct uart_port *, int); 271 + u8 rev_id_val; 272 + u8 rev_id_reg; /* Relevant only if rev_id_val is defined. */ 273 + u8 power_reg; /* Register address for power/sleep control. */ 274 + u8 power_bit; /* Bit for sleep or power-off mode (active high). */ 277 275 }; 278 276 279 277 struct max310x_one { ··· 335 331 regmap_update_bits(one->regmap, reg, mask, val); 336 332 } 337 333 338 - static int max3107_detect(struct device *dev) 334 + static int max310x_detect(struct device *dev) 339 335 { 340 336 struct max310x_port *s = dev_get_drvdata(dev); 341 337 unsigned int val = 0; 342 338 int ret; 343 339 344 - ret = regmap_read(s->regmap, MAX310X_REVID_REG, &val); 345 - if (ret) 346 - return ret; 340 + /* Check if variant supports REV ID register: */ 341 + if (s->devtype->rev_id_val) { 342 + u8 rev_id_reg = s->devtype->rev_id_reg; 347 343 348 - if (((val & MAX310x_REV_MASK) != MAX3107_REV_ID)) { 349 - dev_err(dev, 350 - "%s ID 0x%02x does not match\n", s->devtype->name, val); 351 - return -ENODEV; 352 - } 344 + /* Check if REV ID is in extended addressing space: */ 345 + if (s->devtype->rev_id_reg >= MAX310X_EXTREG_START) { 346 + ret = s->if_cfg->extended_reg_enable(dev, true); 347 + if (ret) 348 + return ret; 353 349 354 - return 0; 355 - } 350 + /* Adjust REV ID extended addressing space address: */ 351 + if (s->if_cfg->rev_id_offset) 352 + rev_id_reg -= s->if_cfg->rev_id_offset; 353 + } 356 354 357 - static int max3108_detect(struct device *dev) 358 - { 359 - struct max310x_port *s = dev_get_drvdata(dev); 360 - unsigned int val = 0; 361 - int ret; 355 + regmap_read(s->regmap, rev_id_reg, &val); 362 356 363 - /* MAX3108 have not REV ID register, we just check default value 364 - * from clocksource register to make sure everything works. 365 - */ 366 - ret = regmap_read(s->regmap, MAX310X_CLKSRC_REG, &val); 367 - if (ret) 368 - return ret; 357 + if (s->devtype->rev_id_reg >= MAX310X_EXTREG_START) { 358 + ret = s->if_cfg->extended_reg_enable(dev, false); 359 + if (ret) 360 + return ret; 361 + } 369 362 370 - if (val != (MAX310X_CLKSRC_EXTCLK_BIT | MAX310X_CLKSRC_PLLBYP_BIT)) { 371 - dev_err(dev, "%s not present\n", s->devtype->name); 372 - return -ENODEV; 373 - } 363 + if (((val & MAX310x_REV_MASK) != s->devtype->rev_id_val)) 364 + return dev_err_probe(dev, -ENODEV, 365 + "%s ID 0x%02x does not match\n", 366 + s->devtype->name, val); 367 + } else { 368 + /* 369 + * For variant without REV ID register, just check default value 370 + * from clocksource register to make sure everything works. 371 + */ 372 + ret = regmap_read(s->regmap, MAX310X_CLKSRC_REG, &val); 373 + if (ret) 374 + return ret; 374 375 375 - return 0; 376 - } 377 - 378 - static int max3109_detect(struct device *dev) 379 - { 380 - struct max310x_port *s = dev_get_drvdata(dev); 381 - unsigned int val = 0; 382 - int ret; 383 - 384 - ret = s->if_cfg->extended_reg_enable(dev, true); 385 - if (ret) 386 - return ret; 387 - 388 - regmap_read(s->regmap, s->if_cfg->rev_id_reg, &val); 389 - s->if_cfg->extended_reg_enable(dev, false); 390 - if (((val & MAX310x_REV_MASK) != MAX3109_REV_ID)) { 391 - dev_err(dev, 392 - "%s ID 0x%02x does not match\n", s->devtype->name, val); 393 - return -ENODEV; 376 + if (val != (MAX310X_CLKSRC_EXTCLK_BIT | MAX310X_CLKSRC_PLLBYP_BIT)) 377 + return dev_err_probe(dev, -ENODEV, 378 + "%s not present\n", 379 + s->devtype->name); 394 380 } 395 381 396 382 return 0; ··· 388 394 389 395 static void max310x_power(struct uart_port *port, int on) 390 396 { 391 - max310x_port_update(port, MAX310X_MODE1_REG, 392 - MAX310X_MODE1_FORCESLEEP_BIT, 393 - on ? 0 : MAX310X_MODE1_FORCESLEEP_BIT); 394 - if (on) 395 - msleep(50); 396 - } 397 + struct max310x_port *s = dev_get_drvdata(port->dev); 397 398 398 - static int max14830_detect(struct device *dev) 399 - { 400 - struct max310x_port *s = dev_get_drvdata(dev); 401 - unsigned int val = 0; 402 - int ret; 403 - 404 - ret = s->if_cfg->extended_reg_enable(dev, true); 405 - if (ret) 406 - return ret; 407 - 408 - regmap_read(s->regmap, s->if_cfg->rev_id_reg, &val); 409 - s->if_cfg->extended_reg_enable(dev, false); 410 - if (((val & MAX310x_REV_MASK) != MAX14830_REV_ID)) { 411 - dev_err(dev, 412 - "%s ID 0x%02x does not match\n", s->devtype->name, val); 413 - return -ENODEV; 414 - } 415 - 416 - return 0; 417 - } 418 - 419 - static void max14830_power(struct uart_port *port, int on) 420 - { 421 - max310x_port_update(port, MAX310X_BRGCFG_REG, 422 - MAX14830_BRGCFG_CLKDIS_BIT, 423 - on ? 0 : MAX14830_BRGCFG_CLKDIS_BIT); 399 + max310x_port_update(port, s->devtype->power_reg, s->devtype->power_bit, 400 + on ? 0 : s->devtype->power_bit); 424 401 if (on) 425 402 msleep(50); 426 403 } ··· 400 435 .name = "MAX3107", 401 436 .nr = 1, 402 437 .mode1 = MAX310X_MODE1_AUTOSLEEP_BIT | MAX310X_MODE1_IRQSEL_BIT, 403 - .detect = max3107_detect, 404 - .power = max310x_power, 438 + .rev_id_val = MAX3107_REV_ID, 439 + .rev_id_reg = MAX310X_REVID_REG, 440 + .power_reg = MAX310X_MODE1_REG, 441 + .power_bit = MAX310X_MODE1_FORCESLEEP_BIT, 405 442 .slave_addr = { 406 443 .min = 0x2c, 407 444 .max = 0x2f, ··· 414 447 .name = "MAX3108", 415 448 .nr = 1, 416 449 .mode1 = MAX310X_MODE1_AUTOSLEEP_BIT, 417 - .detect = max3108_detect, 418 - .power = max310x_power, 450 + .rev_id_val = 0, /* Unsupported. */ 451 + .rev_id_reg = 0, /* Irrelevant when rev_id_val is not defined. */ 452 + .power_reg = MAX310X_MODE1_REG, 453 + .power_bit = MAX310X_MODE1_FORCESLEEP_BIT, 419 454 .slave_addr = { 420 455 .min = 0x60, 421 456 .max = 0x6f, ··· 428 459 .name = "MAX3109", 429 460 .nr = 2, 430 461 .mode1 = MAX310X_MODE1_AUTOSLEEP_BIT, 431 - .detect = max3109_detect, 432 - .power = max310x_power, 462 + .rev_id_val = MAX3109_REV_ID, 463 + .rev_id_reg = MAX310X_REVID_EXTREG, 464 + .power_reg = MAX310X_MODE1_REG, 465 + .power_bit = MAX310X_MODE1_FORCESLEEP_BIT, 433 466 .slave_addr = { 434 467 .min = 0x60, 435 468 .max = 0x6f, ··· 442 471 .name = "MAX14830", 443 472 .nr = 4, 444 473 .mode1 = MAX310X_MODE1_IRQSEL_BIT, 445 - .detect = max14830_detect, 446 - .power = max14830_power, 474 + .rev_id_val = MAX14830_REV_ID, 475 + .rev_id_reg = MAX310X_REVID_EXTREG, 476 + .power_reg = MAX310X_BRGCFG_REG, 477 + .power_bit = MAX14830_BRGCFG_CLKDIS_BIT, 447 478 .slave_addr = { 448 479 .min = 0x60, 449 480 .max = 0x6f, ··· 463 490 case MAX310X_RXFIFOLVL_REG: 464 491 return false; 465 492 default: 466 - break; 493 + return true; 467 494 } 468 - 469 - return true; 470 495 } 471 496 472 497 static bool max310x_reg_volatile(struct device *dev, unsigned int reg) ··· 483 512 case MAX310X_REG_1F: 484 513 return true; 485 514 default: 486 - break; 515 + return false; 487 516 } 488 - 489 - return false; 490 517 } 491 518 492 519 static bool max310x_reg_precious(struct device *dev, unsigned int reg) ··· 496 527 case MAX310X_STS_IRQSTS_REG: 497 528 return true; 498 529 default: 499 - break; 530 + return false; 500 531 } 501 - 502 - return false; 503 532 } 504 533 505 534 static bool max310x_reg_noinc(struct device *dev, unsigned int reg) ··· 656 689 u8 ch, flag; 657 690 658 691 if (port->read_status_mask == MAX310X_LSR_RXOVR_BIT) { 659 - /* We are just reading, happily ignoring any error conditions. 692 + /* 693 + * We are just reading, happily ignoring any error conditions. 660 694 * Break condition, parity checking, framing errors -- they 661 695 * are all ignored. That means that we can do a batch-read. 662 696 * ··· 666 698 * that the LSR register applies to the "current" character. 667 699 * That's also the reason why we cannot do batched reads when 668 700 * asked to check the individual statuses. 669 - * */ 701 + */ 670 702 671 703 sts = max310x_port_read(port, MAX310X_LSR_IRQSTS_REG); 672 704 max310x_batch_read(port, one->rx_buf, rxlen); ··· 770 802 to_send = (to_send > txlen) ? txlen : to_send; 771 803 772 804 if (until_end < to_send) { 773 - /* It's a circ buffer -- wrap around. 774 - * We could do that in one SPI transaction, but meh. */ 805 + /* 806 + * It's a circ buffer -- wrap around. 807 + * We could do that in one SPI transaction, but meh. 808 + */ 775 809 max310x_batch_write(port, xmit->buf + xmit->tail, until_end); 776 810 max310x_batch_write(port, xmit->buf, to_send - until_end); 777 811 } else { ··· 818 848 if (ists & MAX310X_IRQ_TXEMPTY_BIT) 819 849 max310x_start_tx(port); 820 850 } while (1); 851 + 821 852 return res; 822 853 } 823 854 ··· 863 892 864 893 static unsigned int max310x_get_mctrl(struct uart_port *port) 865 894 { 866 - /* DCD and DSR are not wired and CTS/RTS is handled automatically 895 + /* 896 + * DCD and DSR are not wired and CTS/RTS is handled automatically 867 897 * so just indicate DSR and CAR asserted 868 898 */ 869 899 return TIOCM_DSR | TIOCM_CAR; ··· 956 984 max310x_port_write(port, MAX310X_XON1_REG, termios->c_cc[VSTART]); 957 985 max310x_port_write(port, MAX310X_XOFF1_REG, termios->c_cc[VSTOP]); 958 986 959 - /* Disable transmitter before enabling AutoCTS or auto transmitter 987 + /* 988 + * Disable transmitter before enabling AutoCTS or auto transmitter 960 989 * flow control 961 990 */ 962 991 if (termios->c_cflag & CRTSCTS || termios->c_iflag & IXOFF) { ··· 984 1011 } 985 1012 max310x_port_write(port, MAX310X_FLOWCTRL_REG, flow); 986 1013 987 - /* Enable transmitter after disabling AutoCTS and auto transmitter 1014 + /* 1015 + * Enable transmitter after disabling AutoCTS and auto transmitter 988 1016 * flow control 989 1017 */ 990 1018 if (!(termios->c_cflag & CRTSCTS) && !(termios->c_iflag & IXOFF)) { ··· 1046 1072 1047 1073 static int max310x_startup(struct uart_port *port) 1048 1074 { 1049 - struct max310x_port *s = dev_get_drvdata(port->dev); 1050 1075 unsigned int val; 1051 1076 1052 - s->devtype->power(port, 1); 1077 + max310x_power(port, 1); 1053 1078 1054 1079 /* Configure MODE1 register */ 1055 1080 max310x_port_update(port, MAX310X_MODE1_REG, ··· 1076 1103 MAX310X_MODE2_ECHOSUPR_BIT); 1077 1104 } 1078 1105 1079 - /* Configure flow control levels */ 1080 - /* Flow control halt level 96, resume level 48 */ 1106 + /* 1107 + * Configure flow control levels: 1108 + * resume: 48 1109 + * halt: 96 1110 + */ 1081 1111 max310x_port_write(port, MAX310X_FLOWLVL_REG, 1082 1112 MAX310X_FLOWLVL_RES(48) | MAX310X_FLOWLVL_HALT(96)); 1083 1113 ··· 1096 1120 1097 1121 static void max310x_shutdown(struct uart_port *port) 1098 1122 { 1099 - struct max310x_port *s = dev_get_drvdata(port->dev); 1100 - 1101 1123 /* Disable all interrupts */ 1102 1124 max310x_port_write(port, MAX310X_IRQEN_REG, 0); 1103 1125 1104 - s->devtype->power(port, 0); 1126 + max310x_power(port, 0); 1105 1127 } 1106 1128 1107 1129 static const char *max310x_type(struct uart_port *port) ··· 1161 1187 1162 1188 for (i = 0; i < s->devtype->nr; i++) { 1163 1189 uart_suspend_port(&max310x_uart, &s->p[i].port); 1164 - s->devtype->power(&s->p[i].port, 0); 1190 + max310x_power(&s->p[i].port, 0); 1165 1191 } 1166 1192 1167 1193 return 0; ··· 1173 1199 int i; 1174 1200 1175 1201 for (i = 0; i < s->devtype->nr; i++) { 1176 - s->devtype->power(&s->p[i].port, 1); 1202 + max310x_power(&s->p[i].port, 1); 1177 1203 uart_resume_port(&max310x_uart, &s->p[i].port); 1178 1204 } 1179 1205 ··· 1183 1209 static SIMPLE_DEV_PM_OPS(max310x_pm_ops, max310x_suspend, max310x_resume); 1184 1210 1185 1211 #ifdef CONFIG_GPIOLIB 1186 - static int max310x_gpio_get(struct gpio_chip *chip, unsigned offset) 1212 + static int max310x_gpio_get(struct gpio_chip *chip, unsigned int offset) 1187 1213 { 1188 1214 unsigned int val; 1189 1215 struct max310x_port *s = gpiochip_get_data(chip); ··· 1194 1220 return !!((val >> 4) & (1 << (offset % 4))); 1195 1221 } 1196 1222 1197 - static void max310x_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 1223 + static void max310x_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) 1198 1224 { 1199 1225 struct max310x_port *s = gpiochip_get_data(chip); 1200 1226 struct uart_port *port = &s->p[offset / 4].port; ··· 1203 1229 value ? 1 << (offset % 4) : 0); 1204 1230 } 1205 1231 1206 - static int max310x_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 1232 + static int max310x_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) 1207 1233 { 1208 1234 struct max310x_port *s = gpiochip_get_data(chip); 1209 1235 struct uart_port *port = &s->p[offset / 4].port; ··· 1214 1240 } 1215 1241 1216 1242 static int max310x_gpio_direction_output(struct gpio_chip *chip, 1217 - unsigned offset, int value) 1243 + unsigned int offset, int value) 1218 1244 { 1219 1245 struct max310x_port *s = gpiochip_get_data(chip); 1220 1246 struct uart_port *port = &s->p[offset / 4].port; ··· 1270 1296 1271 1297 /* Alloc port structure */ 1272 1298 s = devm_kzalloc(dev, struct_size(s, p, devtype->nr), GFP_KERNEL); 1273 - if (!s) { 1274 - dev_err(dev, "Error allocating port structure\n"); 1275 - return -ENOMEM; 1276 - } 1299 + if (!s) 1300 + return dev_err_probe(dev, -ENOMEM, 1301 + "Error allocating port structure\n"); 1277 1302 1278 1303 /* Always ask for fixed clock rate from a property. */ 1279 1304 device_property_read_u32(dev, "clock-frequency", &uartclk); ··· 1293 1320 if (freq == 0) 1294 1321 freq = uartclk; 1295 1322 if (freq == 0) { 1296 - dev_err(dev, "Cannot get clock rate\n"); 1297 - ret = -EINVAL; 1323 + ret = dev_err_probe(dev, -EINVAL, "Cannot get clock rate\n"); 1298 1324 goto out_clk; 1299 1325 } 1300 1326 ··· 1317 1345 dev_set_drvdata(dev, s); 1318 1346 1319 1347 /* Check device to ensure we are talking to what we expect */ 1320 - ret = devtype->detect(dev); 1348 + ret = max310x_detect(dev); 1321 1349 if (ret) 1322 1350 goto out_clk; 1323 1351 ··· 1399 1427 1400 1428 /* Register port */ 1401 1429 ret = uart_add_one_port(&max310x_uart, &s->p[i].port); 1402 - if (ret) { 1403 - s->p[i].port.dev = NULL; 1430 + if (ret) 1404 1431 goto out_uart; 1405 - } 1432 + 1406 1433 set_bit(line, max310x_lines); 1407 1434 1408 1435 /* Go to suspend mode */ 1409 - devtype->power(&s->p[i].port, 0); 1436 + max310x_power(&s->p[i].port, 0); 1410 1437 } 1411 1438 1412 1439 #ifdef CONFIG_GPIOLIB ··· 1432 1461 if (!ret) 1433 1462 return 0; 1434 1463 1435 - dev_err(dev, "Unable to reguest IRQ %i\n", irq); 1464 + dev_err(dev, "Unable to request IRQ %i\n", irq); 1436 1465 1437 1466 out_uart: 1438 1467 for (i = 0; i < devtype->nr; i++) { 1439 - if (s->p[i].port.dev) { 1468 + if (test_and_clear_bit(s->p[i].port.line, max310x_lines)) 1440 1469 uart_remove_one_port(&max310x_uart, &s->p[i].port); 1441 - clear_bit(s->p[i].port.line, max310x_lines); 1442 - } 1443 1470 } 1444 1471 1445 1472 out_clk: ··· 1455 1486 cancel_work_sync(&s->p[i].tx_work); 1456 1487 cancel_work_sync(&s->p[i].md_work); 1457 1488 cancel_work_sync(&s->p[i].rs_work); 1458 - uart_remove_one_port(&max310x_uart, &s->p[i].port); 1459 - clear_bit(s->p[i].port.line, max310x_lines); 1460 - s->devtype->power(&s->p[i].port, 0); 1489 + 1490 + if (test_and_clear_bit(s->p[i].port.line, max310x_lines)) 1491 + uart_remove_one_port(&max310x_uart, &s->p[i].port); 1492 + 1493 + max310x_power(&s->p[i].port, 0); 1461 1494 } 1462 1495 1463 1496 clk_disable_unprepare(s->clk); ··· 1489 1518 .max_raw_write = MAX310X_FIFO_SIZE, 1490 1519 }; 1491 1520 1521 + static const char *max310x_regmap_name(u8 port_id) 1522 + { 1523 + switch (port_id) { 1524 + case 0: return "port0"; 1525 + case 1: return "port1"; 1526 + case 2: return "port2"; 1527 + case 3: return "port3"; 1528 + default: 1529 + WARN_ON(true); 1530 + return NULL; 1531 + } 1532 + } 1533 + 1492 1534 #ifdef CONFIG_SPI_MASTER 1493 1535 static int max310x_spi_extended_reg_enable(struct device *dev, bool enable) 1494 1536 { ··· 1513 1529 1514 1530 static const struct max310x_if_cfg __maybe_unused max310x_spi_if_cfg = { 1515 1531 .extended_reg_enable = max310x_spi_extended_reg_enable, 1516 - .rev_id_reg = MAX310X_SPI_REVID_EXTREG, 1532 + .rev_id_offset = MAX310X_EXTREG_START, 1517 1533 }; 1518 1534 1519 1535 static int max310x_spi_probe(struct spi_device *spi) 1520 1536 { 1521 1537 const struct max310x_devtype *devtype; 1522 - struct regmap *regmaps[4]; 1538 + struct regmap *regmaps[MAX310X_MAX_PORTS]; 1523 1539 unsigned int i; 1524 1540 int ret; 1525 1541 ··· 1531 1547 if (ret) 1532 1548 return ret; 1533 1549 1534 - devtype = device_get_match_data(&spi->dev); 1550 + devtype = spi_get_device_match_data(spi); 1535 1551 if (!devtype) 1536 - devtype = (struct max310x_devtype *)spi_get_device_id(spi)->driver_data; 1552 + return dev_err_probe(&spi->dev, -ENODEV, "Failed to match device\n"); 1537 1553 1538 1554 for (i = 0; i < devtype->nr; i++) { 1539 1555 u8 port_mask = i * 0x20; 1556 + 1557 + regcfg.name = max310x_regmap_name(i); 1540 1558 regcfg.read_flag_mask = port_mask; 1541 1559 regcfg.write_flag_mask = port_mask | MAX310X_WRITE_BIT; 1542 1560 regmaps[i] = devm_regmap_init_spi(spi, &regcfg); ··· 1586 1600 .writeable_reg = max310x_reg_writeable, 1587 1601 .volatile_reg = max310x_reg_volatile, 1588 1602 .precious_reg = max310x_reg_precious, 1589 - .max_register = MAX310X_I2C_REVID_EXTREG, 1603 + .max_register = MAX310X_REVID_EXTREG, 1590 1604 .writeable_noinc_reg = max310x_reg_noinc, 1591 1605 .readable_noinc_reg = max310x_reg_noinc, 1592 1606 .max_raw_read = MAX310X_FIFO_SIZE, ··· 1595 1609 1596 1610 static const struct max310x_if_cfg max310x_i2c_if_cfg = { 1597 1611 .extended_reg_enable = max310x_i2c_extended_reg_enable, 1598 - .rev_id_reg = MAX310X_I2C_REVID_EXTREG, 1612 + .rev_id_offset = 0, /* No offset in I2C mode. */ 1599 1613 }; 1600 1614 1601 1615 static unsigned short max310x_i2c_slave_addr(unsigned short addr, ··· 1605 1619 * For MAX14830 and MAX3109, the slave address depends on what the 1606 1620 * A0 and A1 pins are tied to. 1607 1621 * See Table I2C Address Map of the datasheet. 1608 - * Based on that table, the following formulas were determined. 1609 - * UART1 - UART0 = 0x10 1610 - * UART2 - UART1 = 0x20 + 0x10 1611 - * UART3 - UART2 = 0x10 1622 + * Based on that table, the following formulas were determined: 1623 + * UART1 - UART0 = 0x10 1624 + * UART2 - UART1 = 0x20 + 0x10 1625 + * UART3 - UART2 = 0x10 1612 1626 */ 1613 1627 1614 1628 addr -= nr * 0x10; ··· 1621 1635 1622 1636 static int max310x_i2c_probe(struct i2c_client *client) 1623 1637 { 1624 - const struct max310x_devtype *devtype = 1625 - device_get_match_data(&client->dev); 1638 + const struct max310x_devtype *devtype; 1626 1639 struct i2c_client *port_client; 1627 - struct regmap *regmaps[4]; 1640 + struct regmap *regmaps[MAX310X_MAX_PORTS]; 1628 1641 unsigned int i; 1629 1642 u8 port_addr; 1630 1643 1644 + devtype = i2c_get_match_data(client); 1645 + if (!devtype) 1646 + return dev_err_probe(&client->dev, -ENODEV, "Failed to match device\n"); 1647 + 1631 1648 if (client->addr < devtype->slave_addr.min || 1632 - client->addr > devtype->slave_addr.max) 1649 + client->addr > devtype->slave_addr.max) 1633 1650 return dev_err_probe(&client->dev, -EINVAL, 1634 1651 "Slave addr 0x%x outside of range [0x%x, 0x%x]\n", 1635 1652 client->addr, devtype->slave_addr.min, 1636 1653 devtype->slave_addr.max); 1637 1654 1655 + regcfg_i2c.name = max310x_regmap_name(0); 1638 1656 regmaps[0] = devm_regmap_init_i2c(client, &regcfg_i2c); 1639 1657 1640 1658 for (i = 1; i < devtype->nr; i++) { ··· 1647 1657 client->adapter, 1648 1658 port_addr); 1649 1659 1660 + regcfg_i2c.name = max310x_regmap_name(i); 1650 1661 regmaps[i] = devm_regmap_init_i2c(port_client, &regcfg_i2c); 1651 1662 } 1652 1663 ··· 1660 1669 max310x_remove(&client->dev); 1661 1670 } 1662 1671 1672 + static const struct i2c_device_id max310x_i2c_id_table[] = { 1673 + { "max3107", (kernel_ulong_t)&max3107_devtype, }, 1674 + { "max3108", (kernel_ulong_t)&max3108_devtype, }, 1675 + { "max3109", (kernel_ulong_t)&max3109_devtype, }, 1676 + { "max14830", (kernel_ulong_t)&max14830_devtype, }, 1677 + { } 1678 + }; 1679 + MODULE_DEVICE_TABLE(i2c, max310x_i2c_id_table); 1680 + 1663 1681 static struct i2c_driver max310x_i2c_driver = { 1664 1682 .driver = { 1665 1683 .name = MAX310X_NAME, ··· 1677 1677 }, 1678 1678 .probe = max310x_i2c_probe, 1679 1679 .remove = max310x_i2c_remove, 1680 + .id_table = max310x_i2c_id_table, 1680 1681 }; 1681 1682 #endif 1682 1683
-27
drivers/tty/serial/mcf.c
··· 470 470 #if defined(CONFIG_SERIAL_MCF_CONSOLE) 471 471 /****************************************************************************/ 472 472 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 - 500 473 static void mcf_console_putc(struct console *co, const char c) 501 474 { 502 475 struct uart_port *port = &(mcf_ports + co->index)->port;
+8 -14
drivers/tty/serial/meson_uart.c
··· 220 220 continue; 221 221 } 222 222 223 - if (uart_handle_sysrq_char(port, ch)) 223 + if (uart_prepare_sysrq_char(port, ch)) 224 224 continue; 225 225 226 226 if ((status & port->ignore_status_mask) == 0) ··· 248 248 meson_uart_start_tx(port); 249 249 } 250 250 251 - uart_port_unlock(port); 251 + uart_unlock_and_check_sysrq(port); 252 252 253 253 return IRQ_HANDLED; 254 254 } ··· 556 556 u_int count) 557 557 { 558 558 unsigned long flags; 559 - int locked; 559 + int locked = 1; 560 560 u32 val, tmp; 561 561 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); 571 566 572 567 val = readl(port->membase + AML_UART_CONTROL); 573 568 tmp = val & ~(AML_UART_TX_INT_EN | AML_UART_RX_INT_EN); ··· 572 577 writel(val, port->membase + AML_UART_CONTROL); 573 578 574 579 if (locked) 575 - uart_port_unlock(port); 576 - local_irq_restore(flags); 580 + uart_port_unlock_irqrestore(port, flags); 577 581 } 578 582 579 583 static void meson_serial_console_write(struct console *co, const char *s,
+10 -23
drivers/tty/serial/msm_serial.c
··· 588 588 if (!(port->read_status_mask & MSM_UART_SR_RX_BREAK)) 589 589 flag = TTY_NORMAL; 590 590 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]); 594 592 if (!sysrq) 595 593 tty_insert_flip_char(tport, dma->virt[i], flag); 596 594 } 597 595 598 596 msm_start_rx_dma(msm_port); 599 597 done: 600 - uart_port_unlock_irqrestore(port, flags); 598 + uart_unlock_and_check_sysrq_irqrestore(port, flags); 601 599 602 600 if (count) 603 601 tty_flip_buffer_push(tport); ··· 761 763 if (!(port->read_status_mask & MSM_UART_SR_RX_BREAK)) 762 764 flag = TTY_NORMAL; 763 765 764 - uart_port_unlock(port); 765 - sysrq = uart_handle_sysrq_char(port, buf[i]); 766 - uart_port_lock(port); 766 + sysrq = uart_prepare_sysrq_char(port, buf[i]); 767 767 if (!sysrq) 768 768 tty_insert_flip_char(tport, buf[i], flag); 769 769 } ··· 821 825 else if (sr & MSM_UART_SR_PAR_FRAME_ERR) 822 826 flag = TTY_FRAME; 823 827 824 - uart_port_unlock(port); 825 - sysrq = uart_handle_sysrq_char(port, c); 826 - uart_port_lock(port); 828 + sysrq = uart_prepare_sysrq_char(port, c); 827 829 if (!sysrq) 828 830 tty_insert_flip_char(tport, c, flag); 829 831 } ··· 942 948 struct uart_port *port = dev_id; 943 949 struct msm_port *msm_port = to_msm_port(port); 944 950 struct msm_dma *dma = &msm_port->rx_dma; 945 - unsigned long flags; 946 951 unsigned int misr; 947 952 u32 val; 948 953 949 - uart_port_lock_irqsave(port, &flags); 954 + uart_port_lock(port); 950 955 misr = msm_read(port, MSM_UART_MISR); 951 956 msm_write(port, 0, MSM_UART_IMR); /* disable interrupt */ 952 957 ··· 977 984 msm_handle_delta_cts(port); 978 985 979 986 msm_write(port, msm_port->imr, MSM_UART_IMR); /* restore interrupt */ 980 - uart_port_unlock_irqrestore(port, flags); 987 + uart_unlock_and_check_sysrq(port); 981 988 982 989 return IRQ_HANDLED; 983 990 } ··· 1614 1621 num_newlines++; 1615 1622 count += num_newlines; 1616 1623 1617 - local_irq_save(flags); 1618 - 1619 - if (port->sysrq) 1620 - locked = 0; 1621 - else if (oops_in_progress) 1622 - locked = uart_port_trylock(port); 1624 + if (oops_in_progress) 1625 + locked = uart_port_trylock_irqsave(port, &flags); 1623 1626 else 1624 - uart_port_lock(port); 1627 + uart_port_lock_irqsave(port, &flags); 1625 1628 1626 1629 if (is_uartdm) 1627 1630 msm_reset_dm_count(port, count); ··· 1656 1667 } 1657 1668 1658 1669 if (locked) 1659 - uart_port_unlock(port); 1660 - 1661 - local_irq_restore(flags); 1670 + uart_port_unlock_irqrestore(port, flags); 1662 1671 } 1663 1672 1664 1673 static void msm_console_write(struct console *co, const char *s,
+6 -10
drivers/tty/serial/omap-serial.c
··· 508 508 509 509 up->port.icount.rx++; 510 510 511 - if (uart_handle_sysrq_char(&up->port, ch)) 511 + if (uart_prepare_sysrq_char(&up->port, ch)) 512 512 return; 513 513 514 514 uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, TTY_NORMAL); ··· 563 563 } 564 564 } while (max_count--); 565 565 566 - uart_port_unlock(&up->port); 566 + uart_unlock_and_check_sysrq(&up->port); 567 567 568 568 tty_flip_buffer_push(&up->port.state->port); 569 569 ··· 1212 1212 unsigned int ier; 1213 1213 int locked = 1; 1214 1214 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); 1220 1217 else 1221 - uart_port_lock(&up->port); 1218 + uart_port_lock_irqsave(&up->port, &flags); 1222 1219 1223 1220 /* 1224 1221 * First save the IER then disable the interrupts ··· 1242 1245 check_modem_status(up); 1243 1246 1244 1247 if (locked) 1245 - uart_port_unlock(&up->port); 1246 - local_irq_restore(flags); 1248 + uart_port_unlock_irqrestore(&up->port, flags); 1247 1249 } 1248 1250 1249 1251 static int __init
+12 -18
drivers/tty/serial/owl-uart.c
··· 199 199 stat = owl_uart_read(port, OWL_UART_STAT); 200 200 while (!(stat & OWL_UART_STAT_RFEM)) { 201 201 char flag = TTY_NORMAL; 202 + bool sysrq; 202 203 203 204 if (stat & OWL_UART_STAT_RXER) 204 205 port->icount.overrun++; ··· 218 217 val = owl_uart_read(port, OWL_UART_RXDAT); 219 218 val &= 0xff; 220 219 221 - if ((stat & port->ignore_status_mask) == 0) 220 + sysrq = uart_prepare_sysrq_char(port, val); 221 + 222 + if (!sysrq && (stat & port->ignore_status_mask) == 0) 222 223 tty_insert_flip_char(&port->state->port, val, flag); 223 224 224 225 stat = owl_uart_read(port, OWL_UART_STAT); ··· 232 229 static irqreturn_t owl_uart_irq(int irq, void *dev_id) 233 230 { 234 231 struct uart_port *port = dev_id; 235 - unsigned long flags; 236 232 u32 stat; 237 233 238 - uart_port_lock_irqsave(port, &flags); 234 + uart_port_lock(port); 239 235 240 236 stat = owl_uart_read(port, OWL_UART_STAT); 241 237 ··· 248 246 stat |= OWL_UART_STAT_RIP | OWL_UART_STAT_TIP; 249 247 owl_uart_write(port, stat, OWL_UART_STAT); 250 248 251 - uart_port_unlock_irqrestore(port, flags); 249 + uart_unlock_and_check_sysrq(port); 252 250 253 251 return IRQ_HANDLED; 254 252 } ··· 510 508 { 511 509 u32 old_ctl, val; 512 510 unsigned long flags; 513 - int locked; 511 + int locked = 1; 514 512 515 - local_irq_save(flags); 516 - 517 - if (port->sysrq) 518 - locked = 0; 519 - else if (oops_in_progress) 520 - locked = uart_port_trylock(port); 521 - else { 522 - uart_port_lock(port); 523 - locked = 1; 524 - } 513 + if (oops_in_progress) 514 + locked = uart_port_trylock_irqsave(port, &flags); 515 + else 516 + uart_port_lock_irqsave(port, &flags); 525 517 526 518 old_ctl = owl_uart_read(port, OWL_UART_CTL); 527 519 val = old_ctl | OWL_UART_CTL_TRFS_TX; ··· 537 541 owl_uart_write(port, old_ctl, OWL_UART_CTL); 538 542 539 543 if (locked) 540 - uart_port_unlock(port); 541 - 542 - local_irq_restore(flags); 544 + uart_port_unlock_irqrestore(port, flags); 543 545 } 544 546 545 547 static void owl_uart_console_write(struct console *co, const char *s,
+19 -51
drivers/tty/serial/pch_uart.c
··· 237 237 238 238 #define IRQ_NAME_SIZE 17 239 239 char irq_name[IRQ_NAME_SIZE]; 240 - 241 - /* protect the eg20t_port private structure and io access to membase */ 242 - spinlock_t lock; 243 240 }; 244 241 245 242 /** ··· 564 567 if (uart_handle_break(port)) 565 568 continue; 566 569 } 567 - if (uart_handle_sysrq_char(port, rbr)) 570 + if (uart_prepare_sysrq_char(port, rbr)) 568 571 continue; 569 572 570 573 buf[i++] = rbr; ··· 596 599 iowrite8(lcr, priv->membase + UART_LCR); 597 600 } 598 601 599 - static int push_rx(struct eg20t_port *priv, const unsigned char *buf, 600 - int size) 602 + static void push_rx(struct eg20t_port *priv, const unsigned char *buf, 603 + int size) 601 604 { 602 605 struct uart_port *port = &priv->port; 603 606 struct tty_port *tport = &port->state->port; 604 607 605 608 tty_insert_flip_string(tport, buf, size); 606 609 tty_flip_buffer_push(tport); 607 - 608 - return 0; 609 610 } 610 611 611 612 static int dma_push_rx(struct eg20t_port *priv, int size) ··· 756 761 { 757 762 struct pch_uart_buffer *buf; 758 763 int rx_size; 759 - int ret; 764 + 760 765 if (!priv->start_rx) { 761 766 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT | 762 767 PCH_UART_HAL_RX_ERR_INT); ··· 765 770 buf = &priv->rxbuf; 766 771 do { 767 772 rx_size = pch_uart_hal_read(priv, buf->buf, buf->size); 768 - ret = push_rx(priv, buf->buf, rx_size); 769 - if (ret) 770 - return 0; 773 + push_rx(priv, buf->buf, rx_size); 771 774 } while (rx_size == buf->size); 772 775 773 776 return PCH_UART_HANDLED_RX_INT; 774 - } 775 - 776 - static int handle_rx(struct eg20t_port *priv) 777 - { 778 - return handle_rx_to(priv); 779 777 } 780 778 781 779 static int dma_handle_rx(struct eg20t_port *priv) ··· 1007 1019 u8 lsr; 1008 1020 int ret = 0; 1009 1021 unsigned char iid; 1010 - unsigned long flags; 1011 1022 int next = 1; 1012 1023 u8 msr; 1013 1024 1014 - spin_lock_irqsave(&priv->lock, flags); 1025 + uart_port_lock(&priv->port); 1015 1026 handled = 0; 1016 1027 while (next) { 1017 1028 iid = pch_uart_hal_get_iid(priv); ··· 1038 1051 PCH_UART_HAL_RX_INT | 1039 1052 PCH_UART_HAL_RX_ERR_INT); 1040 1053 } else { 1041 - ret = handle_rx(priv); 1054 + ret = handle_rx_to(priv); 1042 1055 } 1043 1056 break; 1044 1057 case PCH_UART_IID_RDR_TO: /* Received Data Ready ··· 1070 1083 handled |= (unsigned int)ret; 1071 1084 } 1072 1085 1073 - spin_unlock_irqrestore(&priv->lock, flags); 1086 + uart_unlock_and_check_sysrq(&priv->port); 1074 1087 return IRQ_RETVAL(handled); 1075 1088 } 1076 1089 ··· 1181 1194 unsigned long flags; 1182 1195 1183 1196 priv = container_of(port, struct eg20t_port, port); 1184 - spin_lock_irqsave(&priv->lock, flags); 1197 + uart_port_lock_irqsave(&priv->port, &flags); 1185 1198 pch_uart_hal_set_break(priv, ctl); 1186 - spin_unlock_irqrestore(&priv->lock, flags); 1199 + uart_port_unlock_irqrestore(&priv->port, flags); 1187 1200 } 1188 1201 1189 1202 /* Grab any interrupt resources and initialise any low level driver state. */ ··· 1333 1346 1334 1347 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); 1335 1348 1336 - spin_lock_irqsave(&priv->lock, flags); 1337 - uart_port_lock(port); 1349 + uart_port_lock_irqsave(port, &flags); 1338 1350 1339 1351 uart_update_timeout(port, termios->c_cflag, baud); 1340 1352 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb); ··· 1346 1360 tty_termios_encode_baud_rate(termios, baud, baud); 1347 1361 1348 1362 out: 1349 - uart_port_unlock(port); 1350 - spin_unlock_irqrestore(&priv->lock, flags); 1363 + uart_port_unlock_irqrestore(port, flags); 1351 1364 } 1352 1365 1353 1366 static const char *pch_uart_type(struct uart_port *port) ··· 1550 1565 { 1551 1566 struct eg20t_port *priv; 1552 1567 unsigned long flags; 1553 - int priv_locked = 1; 1554 - int port_locked = 1; 1568 + int locked = 1; 1555 1569 u8 ier; 1556 1570 1557 1571 priv = pch_uart_ports[co->index]; 1558 1572 1559 1573 touch_nmi_watchdog(); 1560 1574 1561 - local_irq_save(flags); 1562 - if (priv->port.sysrq) { 1563 - /* call to uart_handle_sysrq_char already took the priv lock */ 1564 - priv_locked = 0; 1565 - /* serial8250_handle_port() already took the port lock */ 1566 - port_locked = 0; 1567 - } else if (oops_in_progress) { 1568 - priv_locked = spin_trylock(&priv->lock); 1569 - port_locked = uart_port_trylock(&priv->port); 1570 - } else { 1571 - spin_lock(&priv->lock); 1572 - uart_port_lock(&priv->port); 1573 - } 1575 + if (oops_in_progress) 1576 + locked = uart_port_trylock_irqsave(&priv->port, &flags); 1577 + else 1578 + uart_port_lock_irqsave(&priv->port, &flags); 1574 1579 1575 1580 /* 1576 1581 * First save the IER then disable the interrupts ··· 1578 1603 wait_for_xmitr(priv, UART_LSR_BOTH_EMPTY); 1579 1604 iowrite8(ier, priv->membase + UART_IER); 1580 1605 1581 - if (port_locked) 1582 - uart_port_unlock(&priv->port); 1583 - if (priv_locked) 1584 - spin_unlock(&priv->lock); 1585 - local_irq_restore(flags); 1606 + if (locked) 1607 + uart_port_unlock_irqrestore(&priv->port, flags); 1586 1608 } 1587 1609 1588 1610 static int __init pch_console_setup(struct console *co, char *options) ··· 1676 1704 pci_enable_msi(pdev); 1677 1705 pci_set_master(pdev); 1678 1706 1679 - spin_lock_init(&priv->lock); 1680 - 1681 1707 iobase = pci_resource_start(pdev, 0); 1682 1708 mapbase = pci_resource_start(pdev, 1); 1683 1709 priv->mapbase = mapbase; ··· 1704 1734 snprintf(priv->irq_name, IRQ_NAME_SIZE, 1705 1735 KBUILD_MODNAME ":" PCH_UART_DRIVER_DEVICE "%d", 1706 1736 priv->port.line); 1707 - 1708 - spin_lock_init(&priv->port.lock); 1709 1737 1710 1738 pci_set_drvdata(pdev, priv); 1711 1739 priv->trigger_level = 1;
+2 -7
drivers/tty/serial/pmac_zilog.c
··· 1714 1714 return uart_add_one_port(&pmz_uart_reg, &uap->port); 1715 1715 } 1716 1716 1717 - static int __exit pmz_detach(struct platform_device *pdev) 1717 + static void __exit pmz_detach(struct platform_device *pdev) 1718 1718 { 1719 1719 struct uart_pmac_port *uap = platform_get_drvdata(pdev); 1720 - 1721 - if (!uap) 1722 - return -ENODEV; 1723 1720 1724 1721 uart_remove_one_port(&pmz_uart_reg, &uap->port); 1725 1722 1726 1723 uap->port.dev = NULL; 1727 - 1728 - return 0; 1729 1724 } 1730 1725 1731 1726 #endif /* !CONFIG_PPC_PMAC */ ··· 1789 1794 #else 1790 1795 1791 1796 static struct platform_driver pmz_driver = { 1792 - .remove = __exit_p(pmz_detach), 1797 + .remove_new = __exit_p(pmz_detach), 1793 1798 .driver = { 1794 1799 .name = "scc", 1795 1800 },
+6 -11
drivers/tty/serial/pxa.c
··· 151 151 flag = TTY_FRAME; 152 152 } 153 153 154 - if (uart_handle_sysrq_char(&up->port, ch)) 154 + if (uart_prepare_sysrq_char(&up->port, ch)) 155 155 goto ignore_char; 156 156 157 157 uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag); ··· 232 232 check_modem_status(up); 233 233 if (lsr & UART_LSR_THRE) 234 234 transmit_chars(up); 235 - uart_port_unlock(&up->port); 235 + uart_unlock_and_check_sysrq(&up->port); 236 236 return IRQ_HANDLED; 237 237 } 238 238 ··· 604 604 int locked = 1; 605 605 606 606 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); 612 609 else 613 - uart_port_lock(&up->port); 610 + uart_port_lock_irqsave(&up->port, &flags); 614 611 615 612 /* 616 613 * First save the IER then disable the interrupts ··· 625 628 serial_out(up, UART_IER, ier); 626 629 627 630 if (locked) 628 - uart_port_unlock(&up->port); 629 - local_irq_restore(flags); 631 + uart_port_unlock_irqrestore(&up->port, flags); 630 632 clk_disable(up->clk); 631 - 632 633 } 633 634 634 635 #ifdef CONFIG_CONSOLE_POLL
+13 -14
drivers/tty/serial/qcom_geni_serial.c
··· 488 488 489 489 geni_status = readl(uport->membase + SE_GENI_STATUS); 490 490 491 - /* Cancel the current write to log the fault */ 492 491 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); 503 501 } else if ((geni_status & M_GENI_CMD_ACTIVE) && !port->tx_remaining) { 504 502 /* 505 503 * It seems we can't interrupt existing transfers if all data ··· 514 516 515 517 __qcom_geni_serial_console_write(uport, s, count); 516 518 517 - if (port->tx_remaining) 518 - qcom_geni_serial_setup_tx(uport, port->tx_remaining); 519 519 520 - if (locked) 520 + if (locked) { 521 + if (port->tx_remaining) 522 + qcom_geni_serial_setup_tx(uport, port->tx_remaining); 521 523 uart_port_unlock_irqrestore(uport, flags); 524 + } 522 525 } 523 526 524 527 static void handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
+10 -18
drivers/tty/serial/rda-uart.c
··· 394 394 val &= 0xff; 395 395 396 396 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); 398 399 399 400 status = rda_uart_read(port, RDA_UART_STATUS); 400 401 } ··· 406 405 static irqreturn_t rda_interrupt(int irq, void *dev_id) 407 406 { 408 407 struct uart_port *port = dev_id; 409 - unsigned long flags; 410 408 u32 val, irq_mask; 411 409 412 - uart_port_lock_irqsave(port, &flags); 410 + uart_port_lock(port); 413 411 414 412 /* Clear IRQ cause */ 415 413 val = rda_uart_read(port, RDA_UART_IRQ_CAUSE); ··· 425 425 rda_uart_send_chars(port); 426 426 } 427 427 428 - uart_port_unlock_irqrestore(port, flags); 428 + uart_unlock_and_check_sysrq(port); 429 429 430 430 return IRQ_HANDLED; 431 431 } ··· 590 590 { 591 591 u32 old_irq_mask; 592 592 unsigned long flags; 593 - int locked; 593 + int locked = 1; 594 594 595 - local_irq_save(flags); 596 - 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); 605 599 606 600 old_irq_mask = rda_uart_read(port, RDA_UART_IRQ_MASK); 607 601 rda_uart_write(port, 0, RDA_UART_IRQ_MASK); ··· 609 615 rda_uart_write(port, old_irq_mask, RDA_UART_IRQ_MASK); 610 616 611 617 if (locked) 612 - uart_port_unlock(port); 613 - 614 - local_irq_restore(flags); 618 + uart_port_unlock_irqrestore(port, flags); 615 619 } 616 620 617 621 static void rda_uart_console_write(struct console *co, const char *s,
+156 -120
drivers/tty/serial/samsung_tty.c
··· 21 21 * BJD, 04-Nov-2004 22 22 */ 23 23 24 - #include <linux/dmaengine.h> 25 - #include <linux/dma-mapping.h> 26 - #include <linux/slab.h> 27 - #include <linux/math.h> 28 - #include <linux/module.h> 29 - #include <linux/ioport.h> 30 - #include <linux/io.h> 31 - #include <linux/platform_device.h> 32 - #include <linux/init.h> 33 - #include <linux/sysrq.h> 34 24 #include <linux/console.h> 35 - #include <linux/tty.h> 36 - #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 25 #include <linux/clk.h> 42 26 #include <linux/cpufreq.h> 27 + #include <linux/delay.h> 28 + #include <linux/dma-mapping.h> 29 + #include <linux/dmaengine.h> 30 + #include <linux/init.h> 31 + #include <linux/io.h> 32 + #include <linux/ioport.h> 33 + #include <linux/math.h> 34 + #include <linux/module.h> 43 35 #include <linux/of.h> 36 + #include <linux/platform_device.h> 37 + #include <linux/serial.h> 38 + #include <linux/serial_core.h> 39 + #include <linux/serial_s3c.h> 40 + #include <linux/slab.h> 41 + #include <linux/sysrq.h> 42 + #include <linux/tty.h> 43 + #include <linux/tty_flip.h> 44 + #include <linux/types.h> 45 + 44 46 #include <asm/irq.h> 45 47 46 48 /* UART name and device definitions */ ··· 75 73 enum s3c24xx_port_type type; 76 74 unsigned int port_type; 77 75 unsigned int fifosize; 78 - unsigned long rx_fifomask; 79 - unsigned long rx_fifoshift; 80 - unsigned long rx_fifofull; 81 - unsigned long tx_fifomask; 82 - unsigned long tx_fifoshift; 83 - unsigned long tx_fifofull; 84 - unsigned int def_clk_sel; 85 - unsigned long num_clks; 86 - unsigned long clksel_mask; 87 - unsigned long clksel_shift; 88 - unsigned long ucon_mask; 76 + u32 rx_fifomask; 77 + u32 rx_fifoshift; 78 + u32 rx_fifofull; 79 + u32 tx_fifomask; 80 + u32 tx_fifoshift; 81 + u32 tx_fifofull; 82 + u32 clksel_mask; 83 + u32 clksel_shift; 84 + u32 ucon_mask; 85 + u8 def_clk_sel; 86 + u8 num_clks; 87 + u8 iotype; 89 88 90 89 /* uart port features */ 91 - 92 - unsigned int has_divslot:1; 90 + bool has_divslot; 93 91 }; 94 92 95 93 struct s3c24xx_serial_drv_data { ··· 198 196 /* Byte-order aware bit setting/clearing functions. */ 199 197 200 198 static inline void s3c24xx_set_bit(const struct uart_port *port, int idx, 201 - unsigned int reg) 199 + u32 reg) 202 200 { 203 201 unsigned long flags; 204 202 u32 val; ··· 211 209 } 212 210 213 211 static inline void s3c24xx_clear_bit(const struct uart_port *port, int idx, 214 - unsigned int reg) 212 + u32 reg) 215 213 { 216 214 unsigned long flags; 217 215 u32 val; ··· 235 233 return to_platform_device(port->dev)->name; 236 234 } 237 235 238 - static int s3c24xx_serial_txempty_nofifo(const struct uart_port *port) 236 + static bool s3c24xx_serial_txempty_nofifo(const struct uart_port *port) 239 237 { 240 238 return rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE; 241 239 } ··· 244 242 { 245 243 struct s3c24xx_uart_port *ourport = to_ourport(port); 246 244 unsigned long flags; 247 - unsigned int ucon, ufcon; 248 245 int count = 10000; 246 + u32 ucon, ufcon; 249 247 250 248 uart_port_lock_irqsave(port, &flags); 251 249 ··· 268 266 { 269 267 struct s3c24xx_uart_port *ourport = to_ourport(port); 270 268 unsigned long flags; 271 - unsigned int ucon; 269 + u32 ucon; 272 270 273 271 uart_port_lock_irqsave(port, &flags); 274 272 ··· 589 587 return ourport->cfg; 590 588 } 591 589 592 - static int s3c24xx_serial_rx_fifocnt(const struct s3c24xx_uart_port *ourport, 593 - unsigned long ufstat) 590 + static unsigned int 591 + s3c24xx_serial_rx_fifocnt(const struct s3c24xx_uart_port *ourport, u32 ufstat) 594 592 { 595 593 const struct s3c24xx_uart_info *info = ourport->info; 596 594 ··· 662 660 static void enable_rx_dma(struct s3c24xx_uart_port *ourport) 663 661 { 664 662 struct uart_port *port = &ourport->port; 665 - unsigned int ucon; 663 + u32 ucon; 666 664 667 665 /* set Rx mode to DMA mode */ 668 666 ucon = rd_regl(port, S3C2410_UCON); ··· 685 683 static void enable_rx_pio(struct s3c24xx_uart_port *ourport) 686 684 { 687 685 struct uart_port *port = &ourport->port; 688 - unsigned int ucon; 686 + u32 ucon; 689 687 690 688 /* set Rx mode to DMA mode */ 691 689 ucon = rd_regl(port, S3C2410_UCON); ··· 710 708 711 709 static irqreturn_t s3c24xx_serial_rx_chars_dma(void *dev_id) 712 710 { 713 - unsigned int utrstat, received; 714 711 struct s3c24xx_uart_port *ourport = dev_id; 715 712 struct uart_port *port = &ourport->port; 716 713 struct s3c24xx_uart_dma *dma = ourport->dma; 717 714 struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port); 718 715 struct tty_port *t = &port->state->port; 719 716 struct dma_tx_state state; 717 + unsigned int received; 718 + u32 utrstat; 720 719 721 720 utrstat = rd_regl(port, S3C2410_UTRSTAT); 722 721 rd_regl(port, S3C2410_UFSTAT); ··· 759 756 static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport) 760 757 { 761 758 struct uart_port *port = &ourport->port; 762 - unsigned int ufcon, ufstat, uerstat; 759 + unsigned int max_count = port->fifosize; 763 760 unsigned int fifocnt = 0; 764 - int max_count = port->fifosize; 761 + u32 ufcon, ufstat, uerstat; 765 762 u8 ch, flag; 766 763 767 764 while (max_count-- > 0) { ··· 781 778 ch = rd_reg(port, S3C2410_URXH); 782 779 783 780 if (port->flags & UPF_CONS_FLOW) { 784 - int txe = s3c24xx_serial_txempty_nofifo(port); 781 + bool txe = s3c24xx_serial_txempty_nofifo(port); 785 782 786 783 if (ourport->rx_enabled) { 787 784 if (!txe) { ··· 945 942 { 946 943 const struct s3c24xx_uart_port *ourport = id; 947 944 const struct uart_port *port = &ourport->port; 948 - unsigned int pend = rd_regl(port, S3C64XX_UINTP); 945 + u32 pend = rd_regl(port, S3C64XX_UINTP); 949 946 irqreturn_t ret = IRQ_HANDLED; 950 947 951 948 if (pend & S3C64XX_UINTM_RXD_MSK) { ··· 964 961 { 965 962 const struct s3c24xx_uart_port *ourport = id; 966 963 const struct uart_port *port = &ourport->port; 967 - unsigned int pend = rd_regl(port, S3C2410_UTRSTAT); 964 + u32 pend = rd_regl(port, S3C2410_UTRSTAT); 968 965 irqreturn_t ret = IRQ_NONE; 969 966 970 967 if (pend & (APPLE_S5L_UTRSTAT_RXTHRESH | APPLE_S5L_UTRSTAT_RXTO)) { ··· 983 980 static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port) 984 981 { 985 982 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); 986 - unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT); 987 - unsigned long ufcon = rd_regl(port, S3C2410_UFCON); 983 + u32 ufstat = rd_regl(port, S3C2410_UFSTAT); 984 + u32 ufcon = rd_regl(port, S3C2410_UFCON); 988 985 989 986 if (ufcon & S3C2410_UFCON_FIFOMODE) { 990 - if ((ufstat & info->tx_fifomask) != 0 || 987 + if ((ufstat & info->tx_fifomask) || 991 988 (ufstat & info->tx_fifofull)) 992 989 return 0; 993 - 994 - return 1; 990 + return TIOCSER_TEMT; 995 991 } 996 992 997 - return s3c24xx_serial_txempty_nofifo(port); 993 + return s3c24xx_serial_txempty_nofifo(port) ? TIOCSER_TEMT : 0; 998 994 } 999 995 1000 996 /* no modem control lines */ 1001 997 static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port) 1002 998 { 1003 - unsigned int umstat = rd_reg(port, S3C2410_UMSTAT); 999 + u32 umstat = rd_reg(port, S3C2410_UMSTAT); 1004 1000 1005 1001 if (umstat & S3C2410_UMSTAT_CTS) 1006 1002 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS; ··· 1009 1007 1010 1008 static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl) 1011 1009 { 1012 - unsigned int umcon = rd_regl(port, S3C2410_UMCON); 1013 - unsigned int ucon = rd_regl(port, S3C2410_UCON); 1010 + u32 umcon = rd_regl(port, S3C2410_UMCON); 1011 + u32 ucon = rd_regl(port, S3C2410_UCON); 1014 1012 1015 1013 if (mctrl & TIOCM_RTS) 1016 1014 umcon |= S3C2410_UMCOM_RTS_LOW; ··· 1030 1028 static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state) 1031 1029 { 1032 1030 unsigned long flags; 1033 - unsigned int ucon; 1031 + u32 ucon; 1034 1032 1035 1033 uart_port_lock_irqsave(port, &flags); 1036 1034 ··· 1188 1186 { 1189 1187 struct s3c24xx_uart_port *ourport = to_ourport(port); 1190 1188 1191 - unsigned int ucon; 1189 + u32 ucon; 1192 1190 1193 1191 ucon = rd_regl(port, S3C2410_UCON); 1194 1192 ucon &= ~(APPLE_S5L_UCON_TXTHRESH_ENA_MSK | ··· 1214 1212 { 1215 1213 struct s3c24xx_uart_port *ourport = to_ourport(port); 1216 1214 unsigned long flags; 1217 - unsigned int ufcon; 1215 + u32 ufcon; 1218 1216 int ret; 1219 1217 1220 1218 wr_regl(port, S3C64XX_UINTM, 0xf); ··· 1259 1257 { 1260 1258 struct s3c24xx_uart_port *ourport = to_ourport(port); 1261 1259 unsigned long flags; 1262 - unsigned int ufcon; 1260 + u32 ufcon; 1263 1261 int ret; 1264 1262 1265 1263 wr_regl(port, S3C2410_UTRSTAT, APPLE_S5L_UTRSTAT_ALL_FLAGS); ··· 1293 1291 1294 1292 return ret; 1295 1293 } 1296 - 1297 - /* power power management control */ 1298 1294 1299 1295 static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level, 1300 1296 unsigned int old) ··· 1339 1339 1340 1340 #define MAX_CLK_NAME_LENGTH 15 1341 1341 1342 - static inline int s3c24xx_serial_getsource(struct uart_port *port) 1342 + static inline u8 s3c24xx_serial_getsource(struct uart_port *port) 1343 1343 { 1344 1344 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); 1345 - unsigned int ucon; 1345 + u32 ucon; 1346 1346 1347 1347 if (info->num_clks == 1) 1348 1348 return 0; ··· 1352 1352 return ucon >> info->clksel_shift; 1353 1353 } 1354 1354 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) 1357 1356 { 1358 1357 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); 1359 - unsigned int ucon; 1358 + u32 ucon; 1360 1359 1361 1360 if (info->num_clks == 1) 1362 1361 return; ··· 1371 1372 1372 1373 static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport, 1373 1374 unsigned int req_baud, struct clk **best_clk, 1374 - unsigned int *clk_num) 1375 + u8 *clk_num) 1375 1376 { 1376 1377 const struct s3c24xx_uart_info *info = ourport->info; 1377 1378 struct clk *clk; 1378 1379 unsigned long rate; 1379 - unsigned int cnt, baud, quot, best_quot = 0; 1380 + unsigned int baud, quot, best_quot = 0; 1380 1381 char clkname[MAX_CLK_NAME_LENGTH]; 1381 1382 int calc_deviation, deviation = (1 << 30) - 1; 1383 + u8 cnt; 1382 1384 1383 1385 for (cnt = 0; cnt < info->num_clks; cnt++) { 1384 1386 /* Keep selected clock if provided */ ··· 1472 1472 struct s3c24xx_uart_port *ourport = to_ourport(port); 1473 1473 struct clk *clk = ERR_PTR(-EINVAL); 1474 1474 unsigned long flags; 1475 - unsigned int baud, quot, clk_sel = 0; 1476 - unsigned int ulcon; 1477 - unsigned int umcon; 1475 + unsigned int baud, quot; 1478 1476 unsigned int udivslot = 0; 1477 + u32 ulcon, umcon; 1478 + u8 clk_sel = 0; 1479 1479 1480 1480 /* 1481 1481 * We don't support modem control lines. ··· 1737 1737 1738 1738 static struct s3c24xx_uart_port s3c24xx_serial_ports[UART_NR]; 1739 1739 1740 - static void s3c24xx_serial_init_port_default(int index) { 1740 + static void s3c24xx_serial_init_port_default(int index) 1741 + { 1741 1742 struct uart_port *port = &s3c24xx_serial_ports[index].port; 1742 1743 1743 1744 spin_lock_init(&port->lock); 1744 1745 1745 - port->iotype = UPIO_MEM; 1746 1746 port->uartclk = 0; 1747 1747 port->fifosize = 16; 1748 1748 port->flags = UPF_BOOT_AUTOCONF; ··· 1758 1758 const struct s3c2410_uartcfg *cfg) 1759 1759 { 1760 1760 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); 1762 1762 1763 1763 ucon &= (info->clksel_mask | info->ucon_mask); 1764 1764 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon); ··· 1776 1776 struct device *dev = ourport->port.dev; 1777 1777 const struct s3c24xx_uart_info *info = ourport->info; 1778 1778 char clk_name[MAX_CLK_NAME_LENGTH]; 1779 - unsigned int clk_sel; 1780 1779 struct clk *clk; 1781 - int clk_num; 1782 1780 int ret; 1781 + u8 clk_sel, clk_num; 1783 1782 1784 1783 clk_sel = ourport->cfg->clk_sel ? : info->def_clk_sel; 1785 1784 for (clk_num = 0; clk_num < info->num_clks; clk_num++) { ··· 1903 1904 wr_regl(port, S3C64XX_UINTSP, 0xf); 1904 1905 break; 1905 1906 case TYPE_APPLE_S5L: { 1906 - unsigned int ucon; 1907 + u32 ucon; 1907 1908 1908 1909 ucon = rd_regl(port, S3C2410_UCON); 1909 1910 ucon &= ~(APPLE_S5L_UCON_TXTHRESH_ENA_MSK | ··· 1951 1952 struct device_node *np = pdev->dev.of_node; 1952 1953 struct s3c24xx_uart_port *ourport; 1953 1954 int index = probe_index; 1954 - int ret, prop = 0; 1955 + int ret, prop = 0, fifosize_prop = 1; 1955 1956 1956 1957 if (np) { 1957 1958 ret = of_alias_get_id(np, "serial"); ··· 1988 1989 break; 1989 1990 } 1990 1991 1992 + ourport->port.iotype = ourport->info->iotype; 1993 + 1991 1994 if (np) { 1992 - of_property_read_u32(np, 1993 - "samsung,uart-fifosize", &ourport->port.fifosize); 1995 + fifosize_prop = of_property_read_u32(np, "samsung,uart-fifosize", 1996 + &ourport->port.fifosize); 1994 1997 1995 1998 if (of_property_read_u32(np, "reg-io-width", &prop) == 0) { 1996 1999 switch (prop) { ··· 2010 2009 } 2011 2010 } 2012 2011 2013 - if (ourport->drv_data->fifosize[index]) 2014 - ourport->port.fifosize = ourport->drv_data->fifosize[index]; 2015 - else if (ourport->info->fifosize) 2016 - ourport->port.fifosize = ourport->info->fifosize; 2012 + if (fifosize_prop) { 2013 + if (ourport->drv_data->fifosize[index]) 2014 + ourport->port.fifosize = ourport->drv_data->fifosize[index]; 2015 + else if (ourport->info->fifosize) 2016 + ourport->port.fifosize = ourport->info->fifosize; 2017 + } 2018 + 2017 2019 ourport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SAMSUNG_CONSOLE); 2018 2020 2019 2021 /* ··· 2062 2058 { 2063 2059 struct uart_port *port = s3c24xx_dev_to_port(&dev->dev); 2064 2060 2065 - if (port) { 2061 + if (port) 2066 2062 uart_remove_one_port(&s3c24xx_uart_drv, port); 2067 - } 2068 2063 2069 2064 uart_unregister_driver(&s3c24xx_uart_drv); 2070 2065 } ··· 2109 2106 /* restore IRQ mask */ 2110 2107 switch (ourport->info->type) { 2111 2108 case TYPE_S3C6400: { 2112 - unsigned int uintm = 0xf; 2109 + u32 uintm = 0xf; 2113 2110 2114 2111 if (ourport->tx_enabled) 2115 2112 uintm &= ~S3C64XX_UINTM_TXD_MSK; ··· 2125 2122 break; 2126 2123 } 2127 2124 case TYPE_APPLE_S5L: { 2128 - unsigned int ucon; 2125 + u32 ucon; 2129 2126 int ret; 2130 2127 2131 2128 ret = clk_prepare_enable(ourport->clk); ··· 2186 2183 2187 2184 static struct uart_port *cons_uart; 2188 2185 2189 - static int 2190 - s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon) 2186 + static bool 2187 + s3c24xx_serial_console_txrdy(struct uart_port *port, u32 ufcon) 2191 2188 { 2192 2189 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); 2193 - unsigned long ufstat, utrstat; 2190 + u32 ufstat, utrstat; 2194 2191 2195 2192 if (ufcon & S3C2410_UFCON_FIFOMODE) { 2196 2193 /* fifo mode - check amount of data in fifo registers... */ 2197 2194 2198 2195 ufstat = rd_regl(port, S3C2410_UFSTAT); 2199 - return (ufstat & info->tx_fifofull) ? 0 : 1; 2196 + return !(ufstat & info->tx_fifofull); 2200 2197 } 2201 2198 2202 2199 /* in non-fifo mode, we go and use the tx buffer empty */ 2203 2200 2204 2201 utrstat = rd_regl(port, S3C2410_UTRSTAT); 2205 - return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0; 2202 + return utrstat & S3C2410_UTRSTAT_TXE; 2206 2203 } 2207 2204 2208 2205 static bool 2209 - s3c24xx_port_configured(unsigned int ucon) 2206 + s3c24xx_port_configured(u32 ucon) 2210 2207 { 2211 2208 /* consider the serial port configured if the tx/rx mode set */ 2212 2209 return (ucon & 0xf) != 0; ··· 2221 2218 static int s3c24xx_serial_get_poll_char(struct uart_port *port) 2222 2219 { 2223 2220 const struct s3c24xx_uart_port *ourport = to_ourport(port); 2224 - unsigned int ufstat; 2221 + u32 ufstat; 2225 2222 2226 2223 ufstat = rd_regl(port, S3C2410_UFSTAT); 2227 2224 if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0) ··· 2233 2230 static void s3c24xx_serial_put_poll_char(struct uart_port *port, 2234 2231 unsigned char c) 2235 2232 { 2236 - unsigned int ufcon = rd_regl(port, S3C2410_UFCON); 2237 - unsigned int ucon = rd_regl(port, S3C2410_UCON); 2233 + u32 ufcon = rd_regl(port, S3C2410_UFCON); 2234 + u32 ucon = rd_regl(port, S3C2410_UCON); 2238 2235 2239 2236 /* not possible to xmit on unconfigured port */ 2240 2237 if (!s3c24xx_port_configured(ucon)) ··· 2250 2247 static void 2251 2248 s3c24xx_serial_console_putchar(struct uart_port *port, unsigned char ch) 2252 2249 { 2253 - unsigned int ufcon = rd_regl(port, S3C2410_UFCON); 2250 + u32 ufcon = rd_regl(port, S3C2410_UFCON); 2254 2251 2255 2252 while (!s3c24xx_serial_console_txrdy(port, ufcon)) 2256 2253 cpu_relax(); ··· 2261 2258 s3c24xx_serial_console_write(struct console *co, const char *s, 2262 2259 unsigned int count) 2263 2260 { 2264 - unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON); 2261 + u32 ucon = rd_regl(cons_uart, S3C2410_UCON); 2265 2262 unsigned long flags; 2266 2263 bool locked = true; 2267 2264 ··· 2288 2285 int *parity, int *bits) 2289 2286 { 2290 2287 struct clk *clk; 2291 - unsigned int ulcon; 2292 - unsigned int ucon; 2293 - unsigned int ubrdiv; 2294 2288 unsigned long rate; 2295 - unsigned int clk_sel; 2289 + u32 ulcon, ucon, ubrdiv; 2296 2290 char clk_name[MAX_CLK_NAME_LENGTH]; 2291 + u8 clk_sel; 2297 2292 2298 2293 ulcon = rd_regl(port, S3C2410_ULCON); 2299 2294 ucon = rd_regl(port, S3C2410_UCON); ··· 2400 2399 .name = "Samsung S3C6400 UART", 2401 2400 .type = TYPE_S3C6400, 2402 2401 .port_type = PORT_S3C6400, 2402 + .iotype = UPIO_MEM, 2403 2403 .fifosize = 64, 2404 - .has_divslot = 1, 2404 + .has_divslot = true, 2405 2405 .rx_fifomask = S3C2440_UFSTAT_RXMASK, 2406 2406 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT, 2407 2407 .rx_fifofull = S3C2440_UFSTAT_RXFULL, ··· 2430 2428 .name = "Samsung S5PV210 UART", 2431 2429 .type = TYPE_S3C6400, 2432 2430 .port_type = PORT_S3C6400, 2433 - .has_divslot = 1, 2431 + .iotype = UPIO_MEM, 2432 + .has_divslot = true, 2434 2433 .rx_fifomask = S5PV210_UFSTAT_RXMASK, 2435 2434 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, 2436 2435 .rx_fifofull = S5PV210_UFSTAT_RXFULL, ··· 2455 2452 #endif 2456 2453 2457 2454 #if defined(CONFIG_ARCH_EXYNOS) 2458 - #define EXYNOS_COMMON_SERIAL_DRV_DATA() \ 2455 + #define EXYNOS_COMMON_SERIAL_DRV_DATA \ 2459 2456 .info = { \ 2460 2457 .name = "Samsung Exynos UART", \ 2461 2458 .type = TYPE_S3C6400, \ 2462 2459 .port_type = PORT_S3C6400, \ 2463 - .has_divslot = 1, \ 2460 + .iotype = UPIO_MEM, \ 2461 + .has_divslot = true, \ 2464 2462 .rx_fifomask = S5PV210_UFSTAT_RXMASK, \ 2465 2463 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, \ 2466 2464 .rx_fifofull = S5PV210_UFSTAT_RXFULL, \ ··· 2480 2476 } \ 2481 2477 2482 2478 static const struct s3c24xx_serial_drv_data exynos4210_serial_drv_data = { 2483 - EXYNOS_COMMON_SERIAL_DRV_DATA(), 2479 + EXYNOS_COMMON_SERIAL_DRV_DATA, 2484 2480 .fifosize = { 256, 64, 16, 16 }, 2485 2481 }; 2486 2482 2487 2483 static const struct s3c24xx_serial_drv_data exynos5433_serial_drv_data = { 2488 - EXYNOS_COMMON_SERIAL_DRV_DATA(), 2484 + EXYNOS_COMMON_SERIAL_DRV_DATA, 2489 2485 .fifosize = { 64, 256, 16, 256 }, 2490 2486 }; 2491 2487 2492 2488 static const struct s3c24xx_serial_drv_data exynos850_serial_drv_data = { 2493 - EXYNOS_COMMON_SERIAL_DRV_DATA(), 2489 + EXYNOS_COMMON_SERIAL_DRV_DATA, 2494 2490 .fifosize = { 256, 64, 64, 64 }, 2495 2491 }; 2496 2492 2497 - /* 2498 - * Common drv_data struct for platforms that specify samsung,uart-fifosize in 2499 - * device tree. 2500 - */ 2501 - static const struct s3c24xx_serial_drv_data exynos_fifoszdt_serial_drv_data = { 2502 - EXYNOS_COMMON_SERIAL_DRV_DATA(), 2493 + static const struct s3c24xx_serial_drv_data gs101_serial_drv_data = { 2494 + .info = { 2495 + .name = "Google GS101 UART", 2496 + .type = TYPE_S3C6400, 2497 + .port_type = PORT_S3C6400, 2498 + .iotype = UPIO_MEM32, 2499 + .has_divslot = true, 2500 + .rx_fifomask = S5PV210_UFSTAT_RXMASK, 2501 + .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, 2502 + .rx_fifofull = S5PV210_UFSTAT_RXFULL, 2503 + .tx_fifofull = S5PV210_UFSTAT_TXFULL, 2504 + .tx_fifomask = S5PV210_UFSTAT_TXMASK, 2505 + .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT, 2506 + .def_clk_sel = S3C2410_UCON_CLKSEL0, 2507 + .num_clks = 1, 2508 + .clksel_mask = 0, 2509 + .clksel_shift = 0, 2510 + }, 2511 + .def_cfg = { 2512 + .ucon = S5PV210_UCON_DEFAULT, 2513 + .ufcon = S5PV210_UFCON_DEFAULT, 2514 + .has_fracval = 1, 2515 + }, 2516 + /* samsung,uart-fifosize must be specified in the device tree. */ 2503 2517 .fifosize = { 0 }, 2504 2518 }; 2505 2519 2506 2520 #define EXYNOS4210_SERIAL_DRV_DATA (&exynos4210_serial_drv_data) 2507 2521 #define EXYNOS5433_SERIAL_DRV_DATA (&exynos5433_serial_drv_data) 2508 2522 #define EXYNOS850_SERIAL_DRV_DATA (&exynos850_serial_drv_data) 2509 - #define EXYNOS_FIFOSZDT_DRV_DATA (&exynos_fifoszdt_serial_drv_data) 2523 + #define GS101_SERIAL_DRV_DATA (&gs101_serial_drv_data) 2510 2524 2511 2525 #else 2512 2526 #define EXYNOS4210_SERIAL_DRV_DATA NULL 2513 2527 #define EXYNOS5433_SERIAL_DRV_DATA NULL 2514 2528 #define EXYNOS850_SERIAL_DRV_DATA NULL 2515 - #define EXYNOS_FIFOSZDT_DRV_DATA NULL 2529 + #define GS101_SERIAL_DRV_DATA NULL 2516 2530 #endif 2517 2531 2518 2532 #ifdef CONFIG_ARCH_APPLE ··· 2539 2517 .name = "Apple S5L UART", 2540 2518 .type = TYPE_APPLE_S5L, 2541 2519 .port_type = PORT_8250, 2520 + .iotype = UPIO_MEM, 2542 2521 .fifosize = 16, 2543 2522 .rx_fifomask = S3C2410_UFSTAT_RXMASK, 2544 2523 .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT, ··· 2569 2546 .name = "Axis ARTPEC-8 UART", 2570 2547 .type = TYPE_S3C6400, 2571 2548 .port_type = PORT_S3C6400, 2549 + .iotype = UPIO_MEM, 2572 2550 .fifosize = 64, 2573 - .has_divslot = 1, 2551 + .has_divslot = true, 2574 2552 .rx_fifomask = S5PV210_UFSTAT_RXMASK, 2575 2553 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, 2576 2554 .rx_fifofull = S5PV210_UFSTAT_RXFULL, ··· 2618 2594 .driver_data = (kernel_ulong_t)ARTPEC8_SERIAL_DRV_DATA, 2619 2595 }, { 2620 2596 .name = "gs101-uart", 2621 - .driver_data = (kernel_ulong_t)EXYNOS_FIFOSZDT_DRV_DATA, 2597 + .driver_data = (kernel_ulong_t)GS101_SERIAL_DRV_DATA, 2622 2598 }, 2623 2599 { }, 2624 2600 }; ··· 2641 2617 { .compatible = "axis,artpec8-uart", 2642 2618 .data = ARTPEC8_SERIAL_DRV_DATA }, 2643 2619 { .compatible = "google,gs101-uart", 2644 - .data = EXYNOS_FIFOSZDT_DRV_DATA }, 2620 + .data = GS101_SERIAL_DRV_DATA }, 2645 2621 {}, 2646 2622 }; 2647 2623 MODULE_DEVICE_TABLE(of, s3c24xx_uart_dt_match); ··· 2740 2716 { 2741 2717 struct earlycon_device *dev = con->data; 2742 2718 const struct samsung_early_console_data *data = dev->port.private_data; 2743 - int ch, ufstat, num_read = 0; 2719 + int num_read = 0; 2720 + u32 ch, ufstat; 2744 2721 2745 2722 while (num_read < n) { 2746 2723 ufstat = rd_regl(&dev->port, S3C2410_UFSTAT); ··· 2809 2784 s5pv210_early_console_setup); 2810 2785 OF_EARLYCON_DECLARE(artpec8, "axis,artpec8-uart", 2811 2786 s5pv210_early_console_setup); 2787 + 2788 + static int __init gs101_early_console_setup(struct earlycon_device *device, 2789 + const char *opt) 2790 + { 2791 + /* gs101 always expects MMIO32 register accesses. */ 2792 + device->port.iotype = UPIO_MEM32; 2793 + 2794 + return s5pv210_early_console_setup(device, opt); 2795 + } 2796 + 2797 + OF_EARLYCON_DECLARE(gs101, "google,gs101-uart", gs101_early_console_setup); 2812 2798 2813 2799 /* Apple S5L */ 2814 2800 static int __init apple_s5l_early_console_setup(struct earlycon_device *device,
+1 -1
drivers/tty/serial/serial_base_bus.c
··· 41 41 return 0; 42 42 } 43 43 44 - static struct bus_type serial_base_bus_type = { 44 + static const struct bus_type serial_base_bus_type = { 45 45 .name = "serial-base", 46 46 .match = serial_base_match, 47 47 };
+12
drivers/tty/serial/serial_core.c
··· 2608 2608 port->type = PORT_UNKNOWN; 2609 2609 flags |= UART_CONFIG_TYPE; 2610 2610 } 2611 + /* Synchronize with possible boot console. */ 2612 + if (uart_console(port)) 2613 + console_lock(); 2611 2614 port->ops->config_port(port, flags); 2615 + if (uart_console(port)) 2616 + console_unlock(); 2612 2617 } 2613 2618 2614 2619 if (port->type != PORT_UNKNOWN) { 2615 2620 unsigned long flags; 2616 2621 2617 2622 uart_report_port(drv, port); 2623 + 2624 + /* Synchronize with possible boot console. */ 2625 + if (uart_console(port)) 2626 + console_lock(); 2618 2627 2619 2628 /* Power up port for set_mctrl() */ 2620 2629 uart_change_pm(state, UART_PM_STATE_ON); ··· 2640 2631 uart_port_unlock_irqrestore(port, flags); 2641 2632 2642 2633 uart_rs485_config(port); 2634 + 2635 + if (uart_console(port)) 2636 + console_unlock(); 2643 2637 2644 2638 /* 2645 2639 * If this driver supports console, and it hasn't been
+145
drivers/tty/serial/serial_port.c
··· 8 8 9 9 #include <linux/device.h> 10 10 #include <linux/module.h> 11 + #include <linux/of.h> 12 + #include <linux/platform_device.h> 11 13 #include <linux/pm_runtime.h> 14 + #include <linux/property.h> 12 15 #include <linux/serial_core.h> 13 16 #include <linux/spinlock.h> 14 17 ··· 107 104 serial_ctrl_unregister_port(drv, port); 108 105 } 109 106 EXPORT_SYMBOL(uart_remove_one_port); 107 + 108 + /** 109 + * __uart_read_properties - read firmware properties of the given UART port 110 + * @port: corresponding port 111 + * @use_defaults: apply defaults (when %true) or validate the values (when %false) 112 + * 113 + * The following device properties are supported: 114 + * - clock-frequency (optional) 115 + * - fifo-size (optional) 116 + * - no-loopback-test (optional) 117 + * - reg-shift (defaults may apply) 118 + * - reg-offset (value may be validated) 119 + * - reg-io-width (defaults may apply or value may be validated) 120 + * - interrupts (OF only) 121 + * - serial [alias ID] (OF only) 122 + * 123 + * If the port->dev is of struct platform_device type the interrupt line 124 + * will be retrieved via platform_get_irq() call against that device. 125 + * Otherwise it will be assigned by fwnode_irq_get() call. In both cases 126 + * the index 0 of the resource is used. 127 + * 128 + * The caller is responsible to initialize the following fields of the @port 129 + * ->dev (must be valid) 130 + * ->flags 131 + * ->mapbase 132 + * ->mapsize 133 + * ->regshift (if @use_defaults is false) 134 + * before calling this function. Alternatively the above mentioned fields 135 + * may be zeroed, in such case the only ones, that have associated properties 136 + * found, will be set to the respective values. 137 + * 138 + * If no error happened, the ->irq, ->mapbase, ->mapsize will be altered. 139 + * The ->iotype is always altered. 140 + * 141 + * When @use_defaults is true and the respective property is not found 142 + * the following values will be applied: 143 + * ->regshift = 0 144 + * In this case IRQ must be provided, otherwise an error will be returned. 145 + * 146 + * When @use_defaults is false and the respective property is found 147 + * the following values will be validated: 148 + * - reg-io-width (->iotype) 149 + * - reg-offset (->mapsize against ->mapbase) 150 + * 151 + * Returns: 0 on success or negative errno on failure 152 + */ 153 + static int __uart_read_properties(struct uart_port *port, bool use_defaults) 154 + { 155 + struct device *dev = port->dev; 156 + u32 value; 157 + int ret; 158 + 159 + /* Read optional UART functional clock frequency */ 160 + device_property_read_u32(dev, "clock-frequency", &port->uartclk); 161 + 162 + /* Read the registers alignment (default: 8-bit) */ 163 + ret = device_property_read_u32(dev, "reg-shift", &value); 164 + if (ret) 165 + port->regshift = use_defaults ? 0 : port->regshift; 166 + else 167 + port->regshift = value; 168 + 169 + /* Read the registers I/O access type (default: MMIO 8-bit) */ 170 + ret = device_property_read_u32(dev, "reg-io-width", &value); 171 + if (ret) { 172 + port->iotype = UPIO_MEM; 173 + } else { 174 + switch (value) { 175 + case 1: 176 + port->iotype = UPIO_MEM; 177 + break; 178 + case 2: 179 + port->iotype = UPIO_MEM16; 180 + break; 181 + case 4: 182 + port->iotype = device_is_big_endian(dev) ? UPIO_MEM32BE : UPIO_MEM32; 183 + break; 184 + default: 185 + if (!use_defaults) { 186 + dev_err(dev, "Unsupported reg-io-width (%u)\n", value); 187 + return -EINVAL; 188 + } 189 + port->iotype = UPIO_UNKNOWN; 190 + break; 191 + } 192 + } 193 + 194 + /* Read the address mapping base offset (default: no offset) */ 195 + ret = device_property_read_u32(dev, "reg-offset", &value); 196 + if (ret) 197 + value = 0; 198 + 199 + /* Check for shifted address mapping overflow */ 200 + if (!use_defaults && port->mapsize < value) { 201 + dev_err(dev, "reg-offset %u exceeds region size %pa\n", value, &port->mapsize); 202 + return -EINVAL; 203 + } 204 + 205 + port->mapbase += value; 206 + port->mapsize -= value; 207 + 208 + /* Read optional FIFO size */ 209 + device_property_read_u32(dev, "fifo-size", &port->fifosize); 210 + 211 + if (device_property_read_bool(dev, "no-loopback-test")) 212 + port->flags |= UPF_SKIP_TEST; 213 + 214 + /* Get index of serial line, if found in DT aliases */ 215 + ret = of_alias_get_id(dev_of_node(dev), "serial"); 216 + if (ret >= 0) 217 + port->line = ret; 218 + 219 + if (dev_is_platform(dev)) 220 + ret = platform_get_irq(to_platform_device(dev), 0); 221 + else 222 + ret = fwnode_irq_get(dev_fwnode(dev), 0); 223 + if (ret == -EPROBE_DEFER) 224 + return ret; 225 + if (ret > 0) 226 + port->irq = ret; 227 + else if (use_defaults) 228 + /* By default IRQ support is mandatory */ 229 + return ret; 230 + else 231 + port->irq = 0; 232 + 233 + port->flags |= UPF_SHARE_IRQ; 234 + 235 + return 0; 236 + } 237 + 238 + int uart_read_port_properties(struct uart_port *port) 239 + { 240 + return __uart_read_properties(port, true); 241 + } 242 + EXPORT_SYMBOL_GPL(uart_read_port_properties); 243 + 244 + int uart_read_and_validate_port_properties(struct uart_port *port) 245 + { 246 + return __uart_read_properties(port, false); 247 + } 248 + EXPORT_SYMBOL_GPL(uart_read_and_validate_port_properties); 110 249 111 250 static struct device_driver serial_port_driver = { 112 251 .name = "port",
+2 -1
drivers/tty/serial/serial_txx9.c
··· 23 23 #include <linux/serial.h> 24 24 #include <linux/tty.h> 25 25 #include <linux/tty_flip.h> 26 - 27 26 #include <linux/io.h> 27 + 28 + #include <asm/txx9/generic.h> 28 29 29 30 #define PASS_LIMIT 256 30 31
+119 -126
drivers/tty/serial/sh-sci.c
··· 576 576 577 577 #ifdef CONFIG_SERIAL_SH_SCI_DMA 578 578 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); 580 580 if (s->chan_tx) 581 581 new = scr | SCSCR_TDRQE; 582 582 else 583 583 new = scr & ~SCSCR_TDRQE; 584 584 if (new != scr) 585 - serial_port_out(port, SCSCR, new); 585 + sci_serial_out(port, SCSCR, new); 586 586 } 587 587 588 588 if (s->chan_tx && !uart_circ_empty(&s->port.state->xmit) && ··· 599 599 if (!s->chan_tx || s->cfg->regtype == SCIx_RZ_SCIFA_REGTYPE || 600 600 port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 601 601 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */ 602 - ctrl = serial_port_in(port, SCSCR); 602 + ctrl = sci_serial_in(port, SCSCR); 603 603 604 604 /* 605 605 * For SCI, TE (transmit enable) must be set after setting TIE ··· 609 609 if (port->type == PORT_SCI) 610 610 ctrl |= SCSCR_TE; 611 611 612 - serial_port_out(port, SCSCR, ctrl | SCSCR_TIE); 612 + sci_serial_out(port, SCSCR, ctrl | SCSCR_TIE); 613 613 } 614 614 } 615 615 ··· 618 618 unsigned short ctrl; 619 619 620 620 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */ 621 - ctrl = serial_port_in(port, SCSCR); 621 + ctrl = sci_serial_in(port, SCSCR); 622 622 623 623 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 624 624 ctrl &= ~SCSCR_TDRQE; 625 625 626 626 ctrl &= ~SCSCR_TIE; 627 627 628 - serial_port_out(port, SCSCR, ctrl); 628 + sci_serial_out(port, SCSCR, ctrl); 629 629 630 630 #ifdef CONFIG_SERIAL_SH_SCI_DMA 631 631 if (to_sci_port(port)->chan_tx && ··· 640 640 { 641 641 unsigned short ctrl; 642 642 643 - ctrl = serial_port_in(port, SCSCR) | port_rx_irq_mask(port); 643 + ctrl = sci_serial_in(port, SCSCR) | port_rx_irq_mask(port); 644 644 645 645 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 646 646 ctrl &= ~SCSCR_RDRQE; 647 647 648 - serial_port_out(port, SCSCR, ctrl); 648 + sci_serial_out(port, SCSCR, ctrl); 649 649 } 650 650 651 651 static void sci_stop_rx(struct uart_port *port) 652 652 { 653 653 unsigned short ctrl; 654 654 655 - ctrl = serial_port_in(port, SCSCR); 655 + ctrl = sci_serial_in(port, SCSCR); 656 656 657 657 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 658 658 ctrl &= ~SCSCR_RDRQE; 659 659 660 660 ctrl &= ~port_rx_irq_mask(port); 661 661 662 - serial_port_out(port, SCSCR, ctrl); 662 + sci_serial_out(port, SCSCR, ctrl); 663 663 } 664 664 665 665 static void sci_clear_SCxSR(struct uart_port *port, unsigned int mask) 666 666 { 667 667 if (port->type == PORT_SCI) { 668 668 /* Just store the mask */ 669 - serial_port_out(port, SCxSR, mask); 669 + sci_serial_out(port, SCxSR, mask); 670 670 } else if (to_sci_port(port)->params->overrun_mask == SCIFA_ORER) { 671 671 /* SCIFA/SCIFB and SCIF on SH7705/SH7720/SH7721 */ 672 672 /* 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); 675 674 } else { 676 675 /* 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)); 678 677 } 679 678 } 680 679 ··· 687 688 int c; 688 689 689 690 do { 690 - status = serial_port_in(port, SCxSR); 691 + status = sci_serial_in(port, SCxSR); 691 692 if (status & SCxSR_ERRORS(port)) { 692 693 sci_clear_SCxSR(port, SCxSR_ERROR_CLEAR(port)); 693 694 continue; ··· 698 699 if (!(status & SCxSR_RDxF(port))) 699 700 return NO_POLL_CHAR; 700 701 701 - c = serial_port_in(port, SCxRDR); 702 + c = sci_serial_in(port, SCxRDR); 702 703 703 704 /* Dummy read */ 704 - serial_port_in(port, SCxSR); 705 + sci_serial_in(port, SCxSR); 705 706 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port)); 706 707 707 708 return c; ··· 713 714 unsigned short status; 714 715 715 716 do { 716 - status = serial_port_in(port, SCxSR); 717 + status = sci_serial_in(port, SCxSR); 717 718 } while (!(status & SCxSR_TDxE(port))); 718 719 719 - serial_port_out(port, SCxTDR, c); 720 + sci_serial_out(port, SCxTDR, c); 720 721 sci_clear_SCxSR(port, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port)); 721 722 } 722 723 #endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE || ··· 735 736 } 736 737 737 738 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 738 - u16 data = serial_port_in(port, SCPDR); 739 - u16 ctrl = serial_port_in(port, SCPCR); 739 + u16 data = sci_serial_in(port, SCPDR); 740 + u16 ctrl = sci_serial_in(port, SCPCR); 740 741 741 742 /* Enable RXD and TXD pin functions */ 742 743 ctrl &= ~(SCPCR_RXDC | SCPCR_TXDC); ··· 755 756 /* Enable CTS# pin function */ 756 757 ctrl &= ~SCPCR_CTSC; 757 758 } 758 - serial_port_out(port, SCPDR, data); 759 - serial_port_out(port, SCPCR, ctrl); 759 + sci_serial_out(port, SCPDR, data); 760 + sci_serial_out(port, SCPCR, ctrl); 760 761 } else if (sci_getreg(port, SCSPTR)->size) { 761 - u16 status = serial_port_in(port, SCSPTR); 762 + u16 status = sci_serial_in(port, SCSPTR); 762 763 763 764 /* RTS# is always output; and active low, unless autorts */ 764 765 status |= SCSPTR_RTSIO; ··· 768 769 status &= ~SCSPTR_RTSDT; 769 770 /* CTS# and SCK are inputs */ 770 771 status &= ~(SCSPTR_CTSIO | SCSPTR_SCKIO); 771 - serial_port_out(port, SCSPTR, status); 772 + sci_serial_out(port, SCSPTR, status); 772 773 } 773 774 } 774 775 ··· 780 781 781 782 reg = sci_getreg(port, SCTFDR); 782 783 if (reg->size) 783 - return serial_port_in(port, SCTFDR) & fifo_mask; 784 + return sci_serial_in(port, SCTFDR) & fifo_mask; 784 785 785 786 reg = sci_getreg(port, SCFDR); 786 787 if (reg->size) 787 - return serial_port_in(port, SCFDR) >> 8; 788 + return sci_serial_in(port, SCFDR) >> 8; 788 789 789 - return !(serial_port_in(port, SCxSR) & SCI_TDRE); 790 + return !(sci_serial_in(port, SCxSR) & SCI_TDRE); 790 791 } 791 792 792 793 static int sci_txroom(struct uart_port *port) ··· 802 803 803 804 reg = sci_getreg(port, SCRFDR); 804 805 if (reg->size) 805 - return serial_port_in(port, SCRFDR) & fifo_mask; 806 + return sci_serial_in(port, SCRFDR) & fifo_mask; 806 807 807 808 reg = sci_getreg(port, SCFDR); 808 809 if (reg->size) 809 - return serial_port_in(port, SCFDR) & fifo_mask; 810 + return sci_serial_in(port, SCFDR) & fifo_mask; 810 811 811 - return (serial_port_in(port, SCxSR) & SCxSR_RDxF(port)) != 0; 812 + return (sci_serial_in(port, SCxSR) & SCxSR_RDxF(port)) != 0; 812 813 } 813 814 814 815 /* ********************************************************************** * ··· 823 824 unsigned short ctrl; 824 825 int count; 825 826 826 - status = serial_port_in(port, SCxSR); 827 + status = sci_serial_in(port, SCxSR); 827 828 if (!(status & SCxSR_TDxE(port))) { 828 - ctrl = serial_port_in(port, SCSCR); 829 + ctrl = sci_serial_in(port, SCSCR); 829 830 if (uart_circ_empty(xmit)) 830 831 ctrl &= ~SCSCR_TIE; 831 832 else 832 833 ctrl |= SCSCR_TIE; 833 - serial_port_out(port, SCSCR, ctrl); 834 + sci_serial_out(port, SCSCR, ctrl); 834 835 return; 835 836 } 836 837 ··· 846 847 c = xmit->buf[xmit->tail]; 847 848 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 848 849 } else if (port->type == PORT_SCI && uart_circ_empty(xmit)) { 849 - ctrl = serial_port_in(port, SCSCR); 850 + ctrl = sci_serial_in(port, SCSCR); 850 851 ctrl &= ~SCSCR_TE; 851 - serial_port_out(port, SCSCR, ctrl); 852 + sci_serial_out(port, SCSCR, ctrl); 852 853 return; 853 854 } else { 854 855 break; 855 856 } 856 857 857 - serial_port_out(port, SCxTDR, c); 858 + sci_serial_out(port, SCxTDR, c); 858 859 859 860 port->icount.tx++; 860 861 } while (--count > 0); ··· 865 866 uart_write_wakeup(port); 866 867 if (uart_circ_empty(xmit)) { 867 868 if (port->type == PORT_SCI) { 868 - ctrl = serial_port_in(port, SCSCR); 869 + ctrl = sci_serial_in(port, SCSCR); 869 870 ctrl &= ~SCSCR_TIE; 870 871 ctrl |= SCSCR_TEIE; 871 - serial_port_out(port, SCSCR, ctrl); 872 + sci_serial_out(port, SCSCR, ctrl); 872 873 } 873 874 874 875 sci_stop_tx(port); ··· 882 883 unsigned short status; 883 884 unsigned char flag; 884 885 885 - status = serial_port_in(port, SCxSR); 886 + status = sci_serial_in(port, SCxSR); 886 887 if (!(status & SCxSR_RDxF(port))) 887 888 return; 888 889 ··· 895 896 break; 896 897 897 898 if (port->type == PORT_SCI) { 898 - char c = serial_port_in(port, SCxRDR); 899 + char c = sci_serial_in(port, SCxRDR); 899 900 if (uart_handle_sysrq_char(port, c)) 900 901 count = 0; 901 902 else ··· 906 907 907 908 if (port->type == PORT_SCIF || 908 909 port->type == PORT_HSCIF) { 909 - status = serial_port_in(port, SCxSR); 910 - c = serial_port_in(port, SCxRDR); 910 + status = sci_serial_in(port, SCxSR); 911 + c = sci_serial_in(port, SCxRDR); 911 912 } else { 912 - c = serial_port_in(port, SCxRDR); 913 - status = serial_port_in(port, SCxSR); 913 + c = sci_serial_in(port, SCxRDR); 914 + status = sci_serial_in(port, SCxSR); 914 915 } 915 916 if (uart_handle_sysrq_char(port, c)) { 916 917 count--; i--; ··· 931 932 } 932 933 } 933 934 934 - serial_port_in(port, SCxSR); /* dummy read */ 935 + sci_serial_in(port, SCxSR); /* dummy read */ 935 936 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port)); 936 937 937 938 copied += count; ··· 943 944 tty_flip_buffer_push(tport); 944 945 } else { 945 946 /* TTY buffers full; read from RX reg to prevent lockup */ 946 - serial_port_in(port, SCxRDR); 947 - serial_port_in(port, SCxSR); /* dummy read */ 947 + sci_serial_in(port, SCxRDR); 948 + sci_serial_in(port, SCxSR); /* dummy read */ 948 949 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port)); 949 950 } 950 951 } ··· 952 953 static int sci_handle_errors(struct uart_port *port) 953 954 { 954 955 int copied = 0; 955 - unsigned short status = serial_port_in(port, SCxSR); 956 + unsigned short status = sci_serial_in(port, SCxSR); 956 957 struct tty_port *tport = &port->state->port; 957 958 struct sci_port *s = to_sci_port(port); 958 959 ··· 999 1000 if (!reg->size) 1000 1001 return 0; 1001 1002 1002 - status = serial_port_in(port, s->params->overrun_reg); 1003 + status = sci_serial_in(port, s->params->overrun_reg); 1003 1004 if (status & s->params->overrun_mask) { 1004 1005 status &= ~s->params->overrun_mask; 1005 - serial_port_out(port, s->params->overrun_reg, status); 1006 + sci_serial_out(port, s->params->overrun_reg, status); 1006 1007 1007 1008 port->icount.overrun++; 1008 1009 ··· 1017 1018 static int sci_handle_breaks(struct uart_port *port) 1018 1019 { 1019 1020 int copied = 0; 1020 - unsigned short status = serial_port_in(port, SCxSR); 1021 + unsigned short status = sci_serial_in(port, SCxSR); 1021 1022 struct tty_port *tport = &port->state->port; 1022 1023 1023 1024 if (uart_handle_break(port)) ··· 1050 1051 1051 1052 /* HSCIF can be set to an arbitrary level. */ 1052 1053 if (sci_getreg(port, HSRTRGR)->size) { 1053 - serial_port_out(port, HSRTRGR, rx_trig); 1054 + sci_serial_out(port, HSRTRGR, rx_trig); 1054 1055 return rx_trig; 1055 1056 } 1056 1057 ··· 1091 1092 return 1; 1092 1093 } 1093 1094 1094 - serial_port_out(port, SCFCR, 1095 - (serial_port_in(port, SCFCR) & 1096 - ~(SCFCR_RTRG1 | SCFCR_RTRG0)) | bits); 1095 + sci_serial_out(port, SCFCR, 1096 + (sci_serial_in(port, SCFCR) & 1097 + ~(SCFCR_RTRG1 | SCFCR_RTRG0)) | bits); 1097 1098 1098 1099 return rx_trig; 1099 1100 } ··· 1101 1102 static int scif_rtrg_enabled(struct uart_port *port) 1102 1103 { 1103 1104 if (sci_getreg(port, HSRTRGR)->size) 1104 - return serial_port_in(port, HSRTRGR) != 0; 1105 + return sci_serial_in(port, HSRTRGR) != 0; 1105 1106 else 1106 - return (serial_port_in(port, SCFCR) & 1107 + return (sci_serial_in(port, SCFCR) & 1107 1108 (SCFCR_RTRG0 | SCFCR_RTRG1)) != 0; 1108 1109 } 1109 1110 ··· 1218 1219 s->cookie_tx = -EINVAL; 1219 1220 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB || 1220 1221 s->cfg->regtype == SCIx_RZ_SCIFA_REGTYPE) { 1221 - u16 ctrl = serial_port_in(port, SCSCR); 1222 - serial_port_out(port, SCSCR, ctrl & ~SCSCR_TIE); 1222 + u16 ctrl = sci_serial_in(port, SCSCR); 1223 + sci_serial_out(port, SCSCR, ctrl & ~SCSCR_TIE); 1223 1224 if (s->cfg->regtype == SCIx_RZ_SCIFA_REGTYPE) { 1224 1225 /* Switch irq from DMA to SCIF */ 1225 1226 dmaengine_pause(s->chan_tx_saved); ··· 1295 1296 u16 scr; 1296 1297 1297 1298 /* Direct new serial port interrupts back to CPU */ 1298 - scr = serial_port_in(port, SCSCR); 1299 + scr = sci_serial_in(port, SCSCR); 1299 1300 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB || 1300 1301 s->cfg->regtype == SCIx_RZ_SCIFA_REGTYPE) { 1301 1302 enable_irq(s->irqs[SCIx_RXI_IRQ]); ··· 1304 1305 else 1305 1306 scr &= ~SCSCR_RDRQE; 1306 1307 } 1307 - serial_port_out(port, SCSCR, scr | SCSCR_RIE); 1308 + sci_serial_out(port, SCSCR, scr | SCSCR_RIE); 1308 1309 } 1309 1310 1310 1311 static void sci_dma_rx_complete(void *arg) ··· 1713 1714 1714 1715 #ifdef CONFIG_SERIAL_SH_SCI_DMA 1715 1716 if (s->chan_rx) { 1716 - u16 scr = serial_port_in(port, SCSCR); 1717 - u16 ssr = serial_port_in(port, SCxSR); 1717 + u16 scr = sci_serial_in(port, SCSCR); 1718 + u16 ssr = sci_serial_in(port, SCxSR); 1718 1719 1719 1720 /* Disable future Rx interrupts */ 1720 1721 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB || ··· 1732 1733 1733 1734 scr &= ~SCSCR_RIE; 1734 1735 } 1735 - serial_port_out(port, SCSCR, scr); 1736 + sci_serial_out(port, SCSCR, scr); 1736 1737 /* Clear current interrupt */ 1737 - serial_port_out(port, SCxSR, 1738 - ssr & ~(SCIF_DR | SCxSR_RDxF(port))); 1738 + sci_serial_out(port, SCxSR, 1739 + ssr & ~(SCIF_DR | SCxSR_RDxF(port))); 1739 1740 dev_dbg(port->dev, "Rx IRQ %lu: setup t-out in %u us\n", 1740 1741 jiffies, s->rx_timeout); 1741 1742 start_hrtimer_us(&s->rx_timer, s->rx_timeout); ··· 1785 1786 return sci_tx_interrupt(irq, ptr); 1786 1787 1787 1788 uart_port_lock_irqsave(port, &flags); 1788 - ctrl = serial_port_in(port, SCSCR); 1789 + ctrl = sci_serial_in(port, SCSCR); 1789 1790 ctrl &= ~(SCSCR_TE | SCSCR_TEIE); 1790 - serial_port_out(port, SCSCR, ctrl); 1791 + sci_serial_out(port, SCSCR, ctrl); 1791 1792 uart_port_unlock_irqrestore(port, flags); 1792 1793 1793 1794 return IRQ_HANDLED; ··· 1801 1802 sci_handle_breaks(port); 1802 1803 1803 1804 /* drop invalid character received before break was detected */ 1804 - serial_port_in(port, SCxRDR); 1805 + sci_serial_in(port, SCxRDR); 1805 1806 1806 1807 sci_clear_SCxSR(port, SCxSR_BREAK_CLEAR(port)); 1807 1808 ··· 1815 1816 1816 1817 if (s->irqs[SCIx_ERI_IRQ] == s->irqs[SCIx_BRI_IRQ]) { 1817 1818 /* Break and Error interrupts are muxed */ 1818 - unsigned short ssr_status = serial_port_in(port, SCxSR); 1819 + unsigned short ssr_status = sci_serial_in(port, SCxSR); 1819 1820 1820 1821 /* Break Interrupt */ 1821 1822 if (ssr_status & SCxSR_BRK(port)) ··· 1830 1831 if (port->type == PORT_SCI) { 1831 1832 if (sci_handle_errors(port)) { 1832 1833 /* discard character in rx buffer */ 1833 - serial_port_in(port, SCxSR); 1834 + sci_serial_in(port, SCxSR); 1834 1835 sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port)); 1835 1836 } 1836 1837 } else { ··· 1855 1856 struct sci_port *s = to_sci_port(port); 1856 1857 irqreturn_t ret = IRQ_NONE; 1857 1858 1858 - ssr_status = serial_port_in(port, SCxSR); 1859 - scr_status = serial_port_in(port, SCSCR); 1859 + ssr_status = sci_serial_in(port, SCxSR); 1860 + scr_status = sci_serial_in(port, SCSCR); 1860 1861 if (s->params->overrun_reg == SCxSR) 1861 1862 orer_status = ssr_status; 1862 1863 else if (sci_getreg(port, s->params->overrun_reg)->size) 1863 - orer_status = serial_port_in(port, s->params->overrun_reg); 1864 + orer_status = sci_serial_in(port, s->params->overrun_reg); 1864 1865 1865 1866 err_enabled = scr_status & port_rx_irq_mask(port); 1866 1867 ··· 2037 2038 2038 2039 static unsigned int sci_tx_empty(struct uart_port *port) 2039 2040 { 2040 - unsigned short status = serial_port_in(port, SCxSR); 2041 + unsigned short status = sci_serial_in(port, SCxSR); 2041 2042 unsigned short in_tx_fifo = sci_txfill(port); 2042 2043 2043 2044 return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0; ··· 2046 2047 static void sci_set_rts(struct uart_port *port, bool state) 2047 2048 { 2048 2049 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 2049 - u16 data = serial_port_in(port, SCPDR); 2050 + u16 data = sci_serial_in(port, SCPDR); 2050 2051 2051 2052 /* Active low */ 2052 2053 if (state) 2053 2054 data &= ~SCPDR_RTSD; 2054 2055 else 2055 2056 data |= SCPDR_RTSD; 2056 - serial_port_out(port, SCPDR, data); 2057 + sci_serial_out(port, SCPDR, data); 2057 2058 2058 2059 /* RTS# is output */ 2059 - serial_port_out(port, SCPCR, 2060 - serial_port_in(port, SCPCR) | SCPCR_RTSC); 2060 + sci_serial_out(port, SCPCR, 2061 + sci_serial_in(port, SCPCR) | SCPCR_RTSC); 2061 2062 } else if (sci_getreg(port, SCSPTR)->size) { 2062 - u16 ctrl = serial_port_in(port, SCSPTR); 2063 + u16 ctrl = sci_serial_in(port, SCSPTR); 2063 2064 2064 2065 /* Active low */ 2065 2066 if (state) 2066 2067 ctrl &= ~SCSPTR_RTSDT; 2067 2068 else 2068 2069 ctrl |= SCSPTR_RTSDT; 2069 - serial_port_out(port, SCSPTR, ctrl); 2070 + sci_serial_out(port, SCSPTR, ctrl); 2070 2071 } 2071 2072 } 2072 2073 ··· 2074 2075 { 2075 2076 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 2076 2077 /* Active low */ 2077 - return !(serial_port_in(port, SCPDR) & SCPDR_CTSD); 2078 + return !(sci_serial_in(port, SCPDR) & SCPDR_CTSD); 2078 2079 } else if (sci_getreg(port, SCSPTR)->size) { 2079 2080 /* Active low */ 2080 - return !(serial_port_in(port, SCSPTR) & SCSPTR_CTSDT); 2081 + return !(sci_serial_in(port, SCSPTR) & SCSPTR_CTSDT); 2081 2082 } 2082 2083 2083 2084 return true; ··· 2107 2108 */ 2108 2109 reg = sci_getreg(port, SCFCR); 2109 2110 if (reg->size) 2110 - serial_port_out(port, SCFCR, 2111 - serial_port_in(port, SCFCR) | 2112 - SCFCR_LOOP); 2111 + sci_serial_out(port, SCFCR, 2112 + sci_serial_in(port, SCFCR) | SCFCR_LOOP); 2113 2113 } 2114 2114 2115 2115 mctrl_gpio_set(s->gpios, mctrl); ··· 2118 2120 2119 2121 if (!(mctrl & TIOCM_RTS)) { 2120 2122 /* Disable Auto RTS */ 2121 - serial_port_out(port, SCFCR, 2122 - serial_port_in(port, SCFCR) & ~SCFCR_MCE); 2123 + sci_serial_out(port, SCFCR, 2124 + sci_serial_in(port, SCFCR) & ~SCFCR_MCE); 2123 2125 2124 2126 /* Clear RTS */ 2125 2127 sci_set_rts(port, 0); 2126 2128 } else if (s->autorts) { 2127 2129 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 2128 2130 /* Enable RTS# pin function */ 2129 - serial_port_out(port, SCPCR, 2130 - serial_port_in(port, SCPCR) & ~SCPCR_RTSC); 2131 + sci_serial_out(port, SCPCR, 2132 + sci_serial_in(port, SCPCR) & ~SCPCR_RTSC); 2131 2133 } 2132 2134 2133 2135 /* Enable Auto RTS */ 2134 - serial_port_out(port, SCFCR, 2135 - serial_port_in(port, SCFCR) | SCFCR_MCE); 2136 + sci_serial_out(port, SCFCR, 2137 + sci_serial_in(port, SCFCR) | SCFCR_MCE); 2136 2138 } else { 2137 2139 /* Set RTS */ 2138 2140 sci_set_rts(port, 1); ··· 2185 2187 } 2186 2188 2187 2189 uart_port_lock_irqsave(port, &flags); 2188 - scsptr = serial_port_in(port, SCSPTR); 2189 - scscr = serial_port_in(port, SCSCR); 2190 + scsptr = sci_serial_in(port, SCSPTR); 2191 + scscr = sci_serial_in(port, SCSCR); 2190 2192 2191 2193 if (break_state == -1) { 2192 2194 scsptr = (scsptr | SCSPTR_SPB2IO) & ~SCSPTR_SPB2DT; ··· 2196 2198 scscr |= SCSCR_TE; 2197 2199 } 2198 2200 2199 - serial_port_out(port, SCSPTR, scsptr); 2200 - serial_port_out(port, SCSCR, scscr); 2201 + sci_serial_out(port, SCSPTR, scsptr); 2202 + sci_serial_out(port, SCSCR, scscr); 2201 2203 uart_port_unlock_irqrestore(port, flags); 2202 2204 } 2203 2205 ··· 2237 2239 * Stop RX and TX, disable related interrupts, keep clock source 2238 2240 * and HSCIF TOT bits 2239 2241 */ 2240 - scr = serial_port_in(port, SCSCR); 2241 - serial_port_out(port, SCSCR, scr & 2242 - (SCSCR_CKE1 | SCSCR_CKE0 | s->hscif_tot)); 2242 + scr = sci_serial_in(port, SCSCR); 2243 + sci_serial_out(port, SCSCR, 2244 + scr & (SCSCR_CKE1 | SCSCR_CKE0 | s->hscif_tot)); 2243 2245 uart_port_unlock_irqrestore(port, flags); 2244 2246 2245 2247 #ifdef CONFIG_SERIAL_SH_SCI_DMA ··· 2388 2390 unsigned int status; 2389 2391 struct sci_port *s = to_sci_port(port); 2390 2392 2391 - serial_port_out(port, SCSCR, s->hscif_tot); /* TE=0, RE=0, CKE1=0 */ 2393 + sci_serial_out(port, SCSCR, s->hscif_tot); /* TE=0, RE=0, CKE1=0 */ 2392 2394 2393 2395 reg = sci_getreg(port, SCFCR); 2394 2396 if (reg->size) 2395 - serial_port_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST); 2397 + sci_serial_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST); 2396 2398 2397 2399 sci_clear_SCxSR(port, 2398 2400 SCxSR_RDxF_CLEAR(port) & SCxSR_ERROR_CLEAR(port) & 2399 2401 SCxSR_BREAK_CLEAR(port)); 2400 2402 if (sci_getreg(port, SCLSR)->size) { 2401 - status = serial_port_in(port, SCLSR); 2403 + status = sci_serial_in(port, SCLSR); 2402 2404 status &= ~(SCLSR_TO | SCLSR_ORER); 2403 - serial_port_out(port, SCLSR, status); 2405 + sci_serial_out(port, SCLSR, status); 2404 2406 } 2405 2407 2406 2408 if (s->rx_trigger > 1) { ··· 2538 2540 * It controls the mux to select (H)SCK or frequency divided clock. 2539 2541 */ 2540 2542 if (best_clk >= 0 && sci_getreg(port, SCCKS)->size) { 2541 - serial_port_out(port, SCDL, dl); 2542 - serial_port_out(port, SCCKS, sccks); 2543 + sci_serial_out(port, SCDL, dl); 2544 + sci_serial_out(port, SCCKS, sccks); 2543 2545 } 2544 2546 2545 2547 uart_port_lock_irqsave(port, &flags); ··· 2552 2554 bits = tty_get_frame_size(termios->c_cflag); 2553 2555 2554 2556 if (sci_getreg(port, SEMR)->size) 2555 - serial_port_out(port, SEMR, 0); 2557 + sci_serial_out(port, SEMR, 0); 2556 2558 2557 2559 if (best_clk >= 0) { 2558 2560 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) ··· 2567 2569 case 27: smr_val |= SCSMR_SRC_27; break; 2568 2570 } 2569 2571 smr_val |= cks; 2570 - serial_port_out(port, SCSCR, scr_val | s->hscif_tot); 2571 - serial_port_out(port, SCSMR, smr_val); 2572 - serial_port_out(port, SCBRR, brr); 2572 + sci_serial_out(port, SCSCR, scr_val | s->hscif_tot); 2573 + sci_serial_out(port, SCSMR, smr_val); 2574 + sci_serial_out(port, SCBRR, brr); 2573 2575 if (sci_getreg(port, HSSRR)->size) { 2574 2576 unsigned int hssrr = srr | HSCIF_SRE; 2575 2577 /* Calculate deviation from intended rate at the ··· 2591 2593 HSCIF_SRHP_MASK; 2592 2594 hssrr |= HSCIF_SRDE; 2593 2595 } 2594 - serial_port_out(port, HSSRR, hssrr); 2596 + sci_serial_out(port, HSSRR, hssrr); 2595 2597 } 2596 2598 2597 2599 /* Wait one bit interval */ ··· 2599 2601 } else { 2600 2602 /* Don't touch the bit rate configuration */ 2601 2603 scr_val = s->cfg->scscr & (SCSCR_CKE1 | SCSCR_CKE0); 2602 - smr_val |= serial_port_in(port, SCSMR) & 2604 + smr_val |= sci_serial_in(port, SCSMR) & 2603 2605 (SCSMR_CKEDG | SCSMR_SRC_MASK | SCSMR_CKS); 2604 - serial_port_out(port, SCSCR, scr_val | s->hscif_tot); 2605 - serial_port_out(port, SCSMR, smr_val); 2606 + sci_serial_out(port, SCSCR, scr_val | s->hscif_tot); 2607 + sci_serial_out(port, SCSMR, smr_val); 2606 2608 } 2607 2609 2608 2610 sci_init_pins(port, termios->c_cflag); ··· 2611 2613 s->autorts = false; 2612 2614 reg = sci_getreg(port, SCFCR); 2613 2615 if (reg->size) { 2614 - unsigned short ctrl = serial_port_in(port, SCFCR); 2616 + unsigned short ctrl = sci_serial_in(port, SCFCR); 2615 2617 2616 2618 if ((port->flags & UPF_HARD_FLOW) && 2617 2619 (termios->c_cflag & CRTSCTS)) { ··· 2628 2630 */ 2629 2631 ctrl &= ~(SCFCR_RFRST | SCFCR_TFRST); 2630 2632 2631 - serial_port_out(port, SCFCR, ctrl); 2633 + sci_serial_out(port, SCFCR, ctrl); 2632 2634 } 2633 2635 if (port->flags & UPF_HARD_FLOW) { 2634 2636 /* Refresh (Auto) RTS */ ··· 2643 2645 if (port->type != PORT_SCI) 2644 2646 scr_val |= SCSCR_TE; 2645 2647 scr_val |= SCSCR_RE | (s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)); 2646 - serial_port_out(port, SCSCR, scr_val | s->hscif_tot); 2648 + sci_serial_out(port, SCSCR, scr_val | s->hscif_tot); 2647 2649 if ((srr + 1 == 5) && 2648 2650 (port->type == PORT_SCIFA || port->type == PORT_SCIFB)) { 2649 2651 /* ··· 3015 3017 port->irq = sci_port->irqs[SCIx_RXI_IRQ]; 3016 3018 port->irqflags = 0; 3017 3019 3018 - port->serial_in = sci_serial_in; 3019 - port->serial_out = sci_serial_out; 3020 - 3021 3020 return 0; 3022 3021 } 3023 3022 ··· 3051 3056 uart_port_lock_irqsave(port, &flags); 3052 3057 3053 3058 /* first save SCSCR then disable interrupts, keep clock source */ 3054 - ctrl = serial_port_in(port, SCSCR); 3059 + ctrl = sci_serial_in(port, SCSCR); 3055 3060 ctrl_temp = SCSCR_RE | SCSCR_TE | 3056 3061 (sci_port->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)) | 3057 3062 (ctrl & (SCSCR_CKE1 | SCSCR_CKE0)); 3058 - serial_port_out(port, SCSCR, ctrl_temp | sci_port->hscif_tot); 3063 + sci_serial_out(port, SCSCR, ctrl_temp | sci_port->hscif_tot); 3059 3064 3060 3065 uart_console_write(port, s, count, serial_console_putchar); 3061 3066 3062 3067 /* wait until fifo is empty and last bit has been transmitted */ 3063 3068 bits = SCxSR_TDxE(port) | SCxSR_TEND(port); 3064 - while ((serial_port_in(port, SCxSR) & bits) != bits) 3069 + while ((sci_serial_in(port, SCxSR) & bits) != bits) 3065 3070 cpu_relax(); 3066 3071 3067 3072 /* restore the SCSCR */ 3068 - serial_port_out(port, SCSCR, ctrl); 3073 + sci_serial_out(port, SCSCR, ctrl); 3069 3074 3070 3075 if (locked) 3071 3076 uart_port_unlock_irqrestore(port, flags); ··· 3498 3503 if (!device->port.membase) 3499 3504 return -ENODEV; 3500 3505 3501 - device->port.serial_in = sci_serial_in; 3502 - device->port.serial_out = sci_serial_out; 3503 3506 device->port.type = type; 3504 3507 memcpy(&sci_ports[0].port, &device->port, sizeof(struct uart_port)); 3505 3508 port_cfg.type = type;
+7 -10
drivers/tty/serial/sifive.c
··· 412 412 break; 413 413 414 414 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); 416 417 } 417 418 418 419 tty_flip_buffer_push(&ssp->port.state->port); ··· 535 534 if (ip & SIFIVE_SERIAL_IP_TXWM_MASK) 536 535 __ssp_transmit_chars(ssp); 537 536 538 - uart_port_unlock(&ssp->port); 537 + uart_unlock_and_check_sysrq(&ssp->port); 539 538 540 539 return IRQ_HANDLED; 541 540 } ··· 792 791 if (!ssp) 793 792 return; 794 793 795 - local_irq_save(flags); 796 - if (ssp->port.sysrq) 797 - locked = 0; 798 - else if (oops_in_progress) 799 - locked = uart_port_trylock(&ssp->port); 794 + if (oops_in_progress) 795 + locked = uart_port_trylock_irqsave(&ssp->port, &flags); 800 796 else 801 - uart_port_lock(&ssp->port); 797 + uart_port_lock_irqsave(&ssp->port, &flags); 802 798 803 799 ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS); 804 800 __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp); ··· 805 807 __ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp); 806 808 807 809 if (locked) 808 - uart_port_unlock(&ssp->port); 809 - local_irq_restore(flags); 810 + uart_port_unlock_irqrestore(&ssp->port, flags); 810 811 } 811 812 812 813 static int sifive_serial_console_setup(struct console *co, char *options)
+24 -16
drivers/tty/serial/st-asc.c
··· 465 465 const struct ktermios *old) 466 466 { 467 467 struct asc_port *ascport = to_asc_port(port); 468 + bool manual_rts, toggle_rts = false; 468 469 struct gpio_desc *gpiod; 469 470 unsigned int baud; 470 471 u32 ctrl_val; ··· 519 518 520 519 /* If flow-control selected, stop handling RTS manually */ 521 520 if (ascport->rts) { 522 - devm_gpiod_put(port->dev, ascport->rts); 523 - ascport->rts = NULL; 524 - 525 - pinctrl_select_state(ascport->pinctrl, 526 - ascport->states[DEFAULT]); 521 + toggle_rts = true; 522 + manual_rts = false; 527 523 } 528 524 } else { 529 525 /* If flow-control disabled, it's safe to handle RTS manually */ 530 - if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) { 531 - pinctrl_select_state(ascport->pinctrl, 532 - ascport->states[NO_HW_FLOWCTRL]); 533 - 534 - gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW); 535 - if (!IS_ERR(gpiod)) { 536 - gpiod_set_consumer_name(gpiod, 537 - port->dev->of_node->name); 538 - ascport->rts = gpiod; 539 - } 540 - } 526 + if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) 527 + manual_rts = toggle_rts = true; 541 528 } 542 529 543 530 if ((baud < 19200) && !ascport->force_m1) { ··· 584 595 asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN)); 585 596 586 597 uart_port_unlock_irqrestore(port, flags); 598 + 599 + if (toggle_rts) { 600 + if (manual_rts) { 601 + pinctrl_select_state(ascport->pinctrl, 602 + ascport->states[NO_HW_FLOWCTRL]); 603 + 604 + gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW); 605 + if (!IS_ERR(gpiod)) { 606 + gpiod_set_consumer_name(gpiod, 607 + port->dev->of_node->name); 608 + ascport->rts = gpiod; 609 + } 610 + } else { 611 + devm_gpiod_put(port->dev, ascport->rts); 612 + ascport->rts = NULL; 613 + pinctrl_select_state(ascport->pinctrl, 614 + ascport->states[DEFAULT]); 615 + } 616 + } 587 617 } 588 618 589 619 static const char *asc_type(struct uart_port *port)
+136 -87
drivers/tty/serial/stm32-usart.c
··· 9 9 * Inspired by st-asc.c from STMicroelectronics (c) 10 10 */ 11 11 12 + #include <linux/bitfield.h> 12 13 #include <linux/clk.h> 13 14 #include <linux/console.h> 14 15 #include <linux/delay.h> ··· 40 39 /* Register offsets */ 41 40 static struct stm32_usart_info __maybe_unused stm32f4_info = { 42 41 .ofs = { 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, 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, 53 + .presc = UNDEF_REG, 54 + .hwcfgr1 = UNDEF_REG, 54 55 }, 55 56 .cfg = { 56 57 .uart_enable_bit = 13, 57 58 .has_7bits_data = false, 58 - .fifosize = 1, 59 59 } 60 60 }; 61 61 62 62 static struct stm32_usart_info __maybe_unused stm32f7_info = { 63 63 .ofs = { 64 - .cr1 = 0x00, 65 - .cr2 = 0x04, 66 - .cr3 = 0x08, 67 - .brr = 0x0c, 68 - .gtpr = 0x10, 69 - .rtor = 0x14, 70 - .rqr = 0x18, 71 - .isr = 0x1c, 72 - .icr = 0x20, 73 - .rdr = 0x24, 74 - .tdr = 0x28, 64 + .cr1 = 0x00, 65 + .cr2 = 0x04, 66 + .cr3 = 0x08, 67 + .brr = 0x0c, 68 + .gtpr = 0x10, 69 + .rtor = 0x14, 70 + .rqr = 0x18, 71 + .isr = 0x1c, 72 + .icr = 0x20, 73 + .rdr = 0x24, 74 + .tdr = 0x28, 75 + .presc = UNDEF_REG, 76 + .hwcfgr1 = UNDEF_REG, 75 77 }, 76 78 .cfg = { 77 79 .uart_enable_bit = 0, 78 80 .has_7bits_data = true, 79 81 .has_swap = true, 80 - .fifosize = 1, 81 82 } 82 83 }; 83 84 84 85 static struct stm32_usart_info __maybe_unused stm32h7_info = { 85 86 .ofs = { 86 - .cr1 = 0x00, 87 - .cr2 = 0x04, 88 - .cr3 = 0x08, 89 - .brr = 0x0c, 90 - .gtpr = 0x10, 91 - .rtor = 0x14, 92 - .rqr = 0x18, 93 - .isr = 0x1c, 94 - .icr = 0x20, 95 - .rdr = 0x24, 96 - .tdr = 0x28, 87 + .cr1 = 0x00, 88 + .cr2 = 0x04, 89 + .cr3 = 0x08, 90 + .brr = 0x0c, 91 + .gtpr = 0x10, 92 + .rtor = 0x14, 93 + .rqr = 0x18, 94 + .isr = 0x1c, 95 + .icr = 0x20, 96 + .rdr = 0x24, 97 + .tdr = 0x28, 98 + .presc = 0x2c, 99 + .hwcfgr1 = 0x3f0, 97 100 }, 98 101 .cfg = { 99 102 .uart_enable_bit = 0, ··· 105 100 .has_swap = true, 106 101 .has_wakeup = true, 107 102 .has_fifo = true, 108 - .fifosize = 16, 109 103 } 110 104 }; 111 105 ··· 1151 1147 free_irq(port->irq, port); 1152 1148 } 1153 1149 1150 + static const unsigned int stm32_usart_presc_val[] = {1, 2, 4, 6, 8, 10, 12, 16, 32, 64, 128, 256}; 1151 + 1154 1152 static void stm32_usart_set_termios(struct uart_port *port, 1155 1153 struct ktermios *termios, 1156 1154 const struct ktermios *old) ··· 1161 1155 const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1162 1156 const struct stm32_usart_config *cfg = &stm32_port->info->cfg; 1163 1157 struct serial_rs485 *rs485conf = &port->rs485; 1164 - unsigned int baud, bits; 1158 + unsigned int baud, bits, uart_clk, uart_clk_pres; 1165 1159 u32 usartdiv, mantissa, fraction, oversampling; 1166 1160 tcflag_t cflag = termios->c_cflag; 1167 - u32 cr1, cr2, cr3, isr; 1161 + u32 cr1, cr2, cr3, isr, brr, presc; 1168 1162 unsigned long flags; 1169 1163 int ret; 1170 1164 1171 1165 if (!stm32_port->hw_flow_control) 1172 1166 cflag &= ~CRTSCTS; 1173 1167 1174 - baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 8); 1168 + uart_clk = clk_get_rate(stm32_port->clk); 1169 + 1170 + baud = uart_get_baud_rate(port, termios, old, 0, uart_clk / 8); 1175 1171 1176 1172 uart_port_lock_irqsave(port, &flags); 1177 1173 ··· 1275 1267 cr3 |= USART_CR3_CTSE | USART_CR3_RTSE; 1276 1268 } 1277 1269 1278 - usartdiv = DIV_ROUND_CLOSEST(port->uartclk, baud); 1270 + for (presc = 0; presc <= USART_PRESC_MAX; presc++) { 1271 + uart_clk_pres = DIV_ROUND_CLOSEST(uart_clk, stm32_usart_presc_val[presc]); 1272 + usartdiv = DIV_ROUND_CLOSEST(uart_clk_pres, baud); 1279 1273 1280 - /* 1281 - * The USART supports 16 or 8 times oversampling. 1282 - * By default we prefer 16 times oversampling, so that the receiver 1283 - * has a better tolerance to clock deviations. 1284 - * 8 times oversampling is only used to achieve higher speeds. 1285 - */ 1286 - if (usartdiv < 16) { 1287 - oversampling = 8; 1288 - cr1 |= USART_CR1_OVER8; 1289 - stm32_usart_set_bits(port, ofs->cr1, USART_CR1_OVER8); 1290 - } else { 1291 - oversampling = 16; 1292 - cr1 &= ~USART_CR1_OVER8; 1293 - stm32_usart_clr_bits(port, ofs->cr1, USART_CR1_OVER8); 1274 + /* 1275 + * The USART supports 16 or 8 times oversampling. 1276 + * By default we prefer 16 times oversampling, so that the receiver 1277 + * has a better tolerance to clock deviations. 1278 + * 8 times oversampling is only used to achieve higher speeds. 1279 + */ 1280 + if (usartdiv < 16) { 1281 + oversampling = 8; 1282 + cr1 |= USART_CR1_OVER8; 1283 + stm32_usart_set_bits(port, ofs->cr1, USART_CR1_OVER8); 1284 + } else { 1285 + oversampling = 16; 1286 + cr1 &= ~USART_CR1_OVER8; 1287 + stm32_usart_clr_bits(port, ofs->cr1, USART_CR1_OVER8); 1288 + } 1289 + 1290 + mantissa = (usartdiv / oversampling) << USART_BRR_DIV_M_SHIFT; 1291 + fraction = usartdiv % oversampling; 1292 + brr = mantissa | fraction; 1293 + 1294 + if (FIELD_FIT(USART_BRR_MASK, brr)) { 1295 + if (ofs->presc != UNDEF_REG) { 1296 + port->uartclk = uart_clk_pres; 1297 + writel_relaxed(presc, port->membase + ofs->presc); 1298 + } else if (presc) { 1299 + /* We need a prescaler but we don't have it (STM32F4, STM32F7) */ 1300 + dev_err(port->dev, 1301 + "unable to set baudrate, input clock is too high"); 1302 + } 1303 + break; 1304 + } else if (presc == USART_PRESC_MAX) { 1305 + /* Even with prescaler and brr at max value we can't set baudrate */ 1306 + dev_err(port->dev, "unable to set baudrate, input clock is too high"); 1307 + break; 1308 + } 1294 1309 } 1295 1310 1296 - mantissa = (usartdiv / oversampling) << USART_BRR_DIV_M_SHIFT; 1297 - fraction = usartdiv % oversampling; 1298 - writel_relaxed(mantissa | fraction, port->membase + ofs->brr); 1311 + writel_relaxed(brr, port->membase + ofs->brr); 1299 1312 1300 1313 uart_update_timeout(port, cflag, baud); 1301 1314 ··· 1500 1471 #endif /* CONFIG_CONSOLE_POLL */ 1501 1472 }; 1502 1473 1503 - /* 1504 - * STM32H7 RX & TX FIFO threshold configuration (CR3 RXFTCFG / TXFTCFG) 1505 - * Note: 1 isn't a valid value in RXFTCFG / TXFTCFG. In this case, 1506 - * RXNEIE / TXEIE can be used instead of threshold irqs: RXFTIE / TXFTIE. 1507 - * So, RXFTCFG / TXFTCFG bitfields values are encoded as array index + 1. 1508 - */ 1509 - static const u32 stm32h7_usart_fifo_thresh_cfg[] = { 1, 2, 4, 8, 12, 14, 16 }; 1474 + struct stm32_usart_thresh_ratio { 1475 + int mul; 1476 + int div; 1477 + }; 1510 1478 1511 - static void stm32_usart_get_ftcfg(struct platform_device *pdev, const char *p, 1512 - int *ftcfg) 1479 + static const struct stm32_usart_thresh_ratio stm32h7_usart_fifo_thresh_cfg[] = { 1480 + {1, 8}, {1, 4}, {1, 2}, {3, 4}, {7, 8}, {1, 1} }; 1481 + 1482 + static int stm32_usart_get_thresh_value(u32 fifo_size, int index) 1513 1483 { 1514 - u32 bytes, i; 1484 + return fifo_size * stm32h7_usart_fifo_thresh_cfg[index].mul / 1485 + stm32h7_usart_fifo_thresh_cfg[index].div; 1486 + } 1515 1487 1516 - /* DT option to get RX & TX FIFO threshold (default to 8 bytes) */ 1488 + static int stm32_usart_get_ftcfg(struct platform_device *pdev, struct stm32_port *stm32port, 1489 + const char *p, int *ftcfg) 1490 + { 1491 + const struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 1492 + u32 bytes, i, cfg8; 1493 + int fifo_size; 1494 + 1495 + if (WARN_ON(ofs->hwcfgr1 == UNDEF_REG)) 1496 + return 1; 1497 + 1498 + cfg8 = FIELD_GET(USART_HWCFGR1_CFG8, 1499 + readl_relaxed(stm32port->port.membase + ofs->hwcfgr1)); 1500 + 1501 + /* On STM32H7, hwcfgr is not present, so returned value will be 0 */ 1502 + fifo_size = cfg8 ? 1 << cfg8 : STM32H7_USART_FIFO_SIZE; 1503 + 1504 + /* DT option to get RX & TX FIFO threshold (default to half fifo size) */ 1517 1505 if (of_property_read_u32(pdev->dev.of_node, p, &bytes)) 1518 - bytes = 8; 1506 + bytes = fifo_size / 2; 1519 1507 1520 - for (i = 0; i < ARRAY_SIZE(stm32h7_usart_fifo_thresh_cfg); i++) 1521 - if (stm32h7_usart_fifo_thresh_cfg[i] >= bytes) 1508 + if (bytes < stm32_usart_get_thresh_value(fifo_size, 0)) { 1509 + *ftcfg = -EINVAL; 1510 + return fifo_size; 1511 + } 1512 + 1513 + for (i = 0; i < ARRAY_SIZE(stm32h7_usart_fifo_thresh_cfg); i++) { 1514 + if (stm32_usart_get_thresh_value(fifo_size, i) >= bytes) 1522 1515 break; 1516 + } 1523 1517 if (i >= ARRAY_SIZE(stm32h7_usart_fifo_thresh_cfg)) 1524 1518 i = ARRAY_SIZE(stm32h7_usart_fifo_thresh_cfg) - 1; 1525 1519 1526 - dev_dbg(&pdev->dev, "%s set to %d bytes\n", p, 1527 - stm32h7_usart_fifo_thresh_cfg[i]); 1520 + dev_dbg(&pdev->dev, "%s set to %d/%d bytes\n", p, 1521 + stm32_usart_get_thresh_value(fifo_size, i), fifo_size); 1528 1522 1529 - /* Provide FIFO threshold ftcfg (1 is invalid: threshold irq unused) */ 1530 - if (i) 1531 - *ftcfg = i - 1; 1532 - else 1533 - *ftcfg = -EINVAL; 1523 + *ftcfg = i; 1524 + return fifo_size; 1534 1525 } 1535 1526 1536 1527 static void stm32_usart_deinit_port(struct stm32_port *stm32port) ··· 1580 1531 port->flags = UPF_BOOT_AUTOCONF; 1581 1532 port->ops = &stm32_uart_ops; 1582 1533 port->dev = &pdev->dev; 1583 - port->fifosize = stm32port->info->cfg.fifosize; 1584 1534 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_STM32_CONSOLE); 1585 1535 port->irq = irq; 1586 1536 port->rs485_config = stm32_usart_config_rs485; ··· 1594 1546 1595 1547 stm32port->swap = stm32port->info->cfg.has_swap && 1596 1548 of_property_read_bool(pdev->dev.of_node, "rx-tx-swap"); 1597 - 1598 - stm32port->fifoen = stm32port->info->cfg.has_fifo; 1599 - if (stm32port->fifoen) { 1600 - stm32_usart_get_ftcfg(pdev, "rx-threshold", 1601 - &stm32port->rxftcfg); 1602 - stm32_usart_get_ftcfg(pdev, "tx-threshold", 1603 - &stm32port->txftcfg); 1604 - } 1605 1549 1606 1550 port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 1607 1551 if (IS_ERR(port->membase)) ··· 1615 1575 if (!stm32port->port.uartclk) { 1616 1576 ret = -EINVAL; 1617 1577 goto err_clk; 1578 + } 1579 + 1580 + stm32port->fifoen = stm32port->info->cfg.has_fifo; 1581 + if (stm32port->fifoen) { 1582 + stm32_usart_get_ftcfg(pdev, stm32port, "rx-threshold", &stm32port->rxftcfg); 1583 + port->fifosize = stm32_usart_get_ftcfg(pdev, stm32port, "tx-threshold", 1584 + &stm32port->txftcfg); 1585 + } else { 1586 + port->fifosize = 1; 1618 1587 } 1619 1588 1620 1589 stm32port->gpios = mctrl_gpio_init(&stm32port->port, 0);
+24 -14
drivers/tty/serial/stm32-usart.h
··· 9 9 #define DRIVER_NAME "stm32-usart" 10 10 11 11 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; 23 25 }; 24 26 25 27 struct stm32_usart_config { ··· 30 28 bool has_swap; 31 29 bool has_wakeup; 32 30 bool has_fifo; 33 - int fifosize; 34 31 }; 35 32 36 33 struct stm32_usart_info { ··· 37 36 struct stm32_usart_config cfg; 38 37 }; 39 38 40 - #define UNDEF_REG 0xff 39 + #define UNDEF_REG 0xffff 41 40 42 41 /* USART_SR (F4) / USART_ISR (F7) */ 43 42 #define USART_SR_PE BIT(0) ··· 72 71 #define USART_BRR_DIV_M_MASK GENMASK(15, 4) 73 72 #define USART_BRR_DIV_M_SHIFT 4 74 73 #define USART_BRR_04_R_SHIFT 1 74 + #define USART_BRR_MASK (USART_BRR_DIV_M_MASK | USART_BRR_DIV_F_MASK) 75 75 76 76 /* USART_CR1 */ 77 77 #define USART_CR1_SBK BIT(0) ··· 178 176 #define USART_ICR_CMCF BIT(17) /* F7 */ 179 177 #define USART_ICR_WUCF BIT(20) /* H7 */ 180 178 179 + /* USART_PRESC */ 180 + #define USART_PRESC GENMASK(3, 0) /* H7 */ 181 + #define USART_PRESC_MAX 0b1011 182 + 183 + /* USART_HWCFCR1 */ 184 + #define USART_HWCFGR1_CFG8 GENMASK(31, 28) /* MP1 */ 185 + 181 186 #define STM32_SERIAL_NAME "ttySTM" 182 - #define STM32_MAX_PORTS 8 187 + #define STM32_MAX_PORTS 9 188 + #define STM32H7_USART_FIFO_SIZE 16 183 189 184 190 #define RX_BUF_L 4096 /* dma rx buffer length */ 185 191 #define RX_BUF_P (RX_BUF_L / 2) /* dma rx buffer period */
+6 -12
drivers/tty/serial/sunplus-uart.c
··· 260 260 if (port->ignore_status_mask & SUP_DUMMY_READ) 261 261 goto ignore_char; 262 262 263 - if (uart_handle_sysrq_char(port, ch)) 263 + if (uart_prepare_sysrq_char(port, ch)) 264 264 goto ignore_char; 265 265 266 266 uart_insert_char(port, lsr, SUP_UART_LSR_OE, ch, flag); ··· 287 287 if (isc & SUP_UART_ISC_TX) 288 288 transmit_chars(port); 289 289 290 - uart_port_unlock(port); 290 + uart_unlock_and_check_sysrq(port); 291 291 292 292 return IRQ_HANDLED; 293 293 } ··· 512 512 unsigned long flags; 513 513 int locked = 1; 514 514 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); 521 517 else 522 - uart_port_lock(&sunplus_console_ports[co->index]->port); 518 + uart_port_lock_irqsave(&sunplus_console_ports[co->index]->port, &flags); 523 519 524 520 uart_console_write(&sunplus_console_ports[co->index]->port, s, count, 525 521 sunplus_uart_console_putchar); 526 522 527 523 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); 531 525 } 532 526 533 527 static int __init sunplus_console_setup(struct console *co, char *options)
+215 -21
drivers/tty/serial/xilinx_uartps.c
··· 22 22 #include <linux/of.h> 23 23 #include <linux/module.h> 24 24 #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> 26 28 27 29 #define CDNS_UART_TTY_NAME "ttyPS" 28 30 #define CDNS_UART_NAME "xuartps" ··· 195 193 * @clk_rate_change_nb: Notifier block for clock changes 196 194 * @quirks: Flags for RXBS support. 197 195 * @cts_override: Modem control state override 196 + * @gpiod_rts: Pointer to the gpio descriptor 197 + * @rs485_tx_started: RS485 tx state 198 + * @tx_timer: Timer for tx 198 199 */ 199 200 struct cdns_uart { 200 201 struct uart_port *port; ··· 208 203 struct notifier_block clk_rate_change_nb; 209 204 u32 quirks; 210 205 bool cts_override; 206 + struct gpio_desc *gpiod_rts; 207 + bool rs485_tx_started; 208 + struct hrtimer tx_timer; 211 209 }; 212 210 struct cdns_platform_data { 213 211 u32 quirks; 214 212 }; 213 + 214 + struct serial_rs485 cdns_rs485_supported = { 215 + .flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | 216 + SER_RS485_RTS_AFTER_SEND, 217 + .delay_rts_before_send = 1, 218 + .delay_rts_after_send = 1, 219 + }; 220 + 215 221 #define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \ 216 222 clk_rate_change_nb) 217 223 ··· 322 306 } 323 307 324 308 /** 325 - * cdns_uart_handle_tx - Handle the bytes to be Txed. 309 + * cdns_rts_gpio_enable - Configure RTS/GPIO to high/low 310 + * @cdns_uart: Handle to the cdns_uart 311 + * @enable: Value to be set to RTS/GPIO 312 + */ 313 + static void cdns_rts_gpio_enable(struct cdns_uart *cdns_uart, bool enable) 314 + { 315 + u32 val; 316 + 317 + if (cdns_uart->gpiod_rts) { 318 + gpiod_set_value(cdns_uart->gpiod_rts, enable); 319 + } else { 320 + val = readl(cdns_uart->port->membase + CDNS_UART_MODEMCR); 321 + if (enable) 322 + val |= CDNS_UART_MODEMCR_RTS; 323 + else 324 + val &= ~CDNS_UART_MODEMCR_RTS; 325 + writel(val, cdns_uart->port->membase + CDNS_UART_MODEMCR); 326 + } 327 + } 328 + 329 + /** 330 + * cdns_rs485_tx_setup - Tx setup specific to rs485 331 + * @cdns_uart: Handle to the cdns_uart 332 + */ 333 + static void cdns_rs485_tx_setup(struct cdns_uart *cdns_uart) 334 + { 335 + bool enable; 336 + 337 + enable = cdns_uart->port->rs485.flags & SER_RS485_RTS_ON_SEND; 338 + cdns_rts_gpio_enable(cdns_uart, enable); 339 + 340 + cdns_uart->rs485_tx_started = true; 341 + } 342 + 343 + /** 344 + * cdns_rs485_rx_setup - Rx setup specific to rs485 345 + * @cdns_uart: Handle to the cdns_uart 346 + */ 347 + static void cdns_rs485_rx_setup(struct cdns_uart *cdns_uart) 348 + { 349 + bool enable; 350 + 351 + enable = cdns_uart->port->rs485.flags & SER_RS485_RTS_AFTER_SEND; 352 + cdns_rts_gpio_enable(cdns_uart, enable); 353 + 354 + cdns_uart->rs485_tx_started = false; 355 + } 356 + 357 + /** 358 + * cdns_uart_tx_empty - Check whether TX is empty 359 + * @port: Handle to the uart port structure 360 + * 361 + * Return: TIOCSER_TEMT on success, 0 otherwise 362 + */ 363 + static unsigned int cdns_uart_tx_empty(struct uart_port *port) 364 + { 365 + unsigned int status; 366 + 367 + status = readl(port->membase + CDNS_UART_SR); 368 + status &= (CDNS_UART_SR_TXEMPTY | CDNS_UART_SR_TACTIVE); 369 + return (status == CDNS_UART_SR_TXEMPTY) ? TIOCSER_TEMT : 0; 370 + } 371 + 372 + /** 373 + * cdns_rs485_rx_callback - Timer rx callback handler for rs485. 374 + * @t: Handle to the hrtimer structure 375 + */ 376 + static enum hrtimer_restart cdns_rs485_rx_callback(struct hrtimer *t) 377 + { 378 + struct cdns_uart *cdns_uart = container_of(t, struct cdns_uart, tx_timer); 379 + 380 + /* 381 + * Default Rx should be setup, because Rx signaling path 382 + * need to enable to receive data. 383 + */ 384 + cdns_rs485_rx_setup(cdns_uart); 385 + 386 + return HRTIMER_NORESTART; 387 + } 388 + 389 + /** 390 + * cdns_calc_after_tx_delay - calculate delay required for after tx. 391 + * @cdns_uart: Handle to the cdns_uart 392 + */ 393 + static u64 cdns_calc_after_tx_delay(struct cdns_uart *cdns_uart) 394 + { 395 + /* 396 + * Frame time + stop bit time + rs485.delay_rts_after_send 397 + */ 398 + return cdns_uart->port->frame_time 399 + + DIV_ROUND_UP(cdns_uart->port->frame_time, 7) 400 + + (u64)cdns_uart->port->rs485.delay_rts_after_send * NSEC_PER_MSEC; 401 + } 402 + 403 + /** 404 + * cdns_uart_handle_tx - Handle the bytes to be transmitted. 326 405 * @dev_id: Id of the UART port 327 406 * Return: None 328 407 */ 329 408 static void cdns_uart_handle_tx(void *dev_id) 330 409 { 331 410 struct uart_port *port = (struct uart_port *)dev_id; 411 + struct cdns_uart *cdns_uart = port->private_data; 332 412 struct circ_buf *xmit = &port->state->xmit; 333 413 unsigned int numbytes; 334 414 335 - if (uart_circ_empty(xmit)) { 415 + if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 416 + /* Disable the TX Empty interrupt */ 336 417 writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_IDR); 337 418 return; 338 419 } ··· 445 332 446 333 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 447 334 uart_write_wakeup(port); 335 + 336 + /* Enable the TX Empty interrupt */ 337 + writel(CDNS_UART_IXR_TXEMPTY, cdns_uart->port->membase + CDNS_UART_IER); 338 + 339 + if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED && 340 + (uart_circ_empty(xmit) || uart_tx_stopped(port))) { 341 + cdns_uart->tx_timer.function = &cdns_rs485_rx_callback; 342 + hrtimer_start(&cdns_uart->tx_timer, 343 + ns_to_ktime(cdns_calc_after_tx_delay(cdns_uart)), HRTIMER_MODE_REL); 344 + } 448 345 } 449 346 450 347 /** ··· 688 565 #endif 689 566 690 567 /** 568 + * cdns_rs485_tx_callback - Timer tx callback handler for rs485. 569 + * @t: Handle to the hrtimer structure 570 + */ 571 + static enum hrtimer_restart cdns_rs485_tx_callback(struct hrtimer *t) 572 + { 573 + struct cdns_uart *cdns_uart = container_of(t, struct cdns_uart, tx_timer); 574 + 575 + uart_port_lock(cdns_uart->port); 576 + cdns_uart_handle_tx(cdns_uart->port); 577 + uart_port_unlock(cdns_uart->port); 578 + 579 + return HRTIMER_NORESTART; 580 + } 581 + 582 + /** 691 583 * cdns_uart_start_tx - Start transmitting bytes 692 584 * @port: Handle to the uart port structure 693 585 */ 694 586 static void cdns_uart_start_tx(struct uart_port *port) 695 587 { 696 588 unsigned int status; 589 + struct cdns_uart *cdns_uart = port->private_data; 697 590 698 591 if (uart_tx_stopped(port)) 699 592 return; ··· 726 587 if (uart_circ_empty(&port->state->xmit)) 727 588 return; 728 589 590 + /* Clear the TX Empty interrupt */ 729 591 writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_ISR); 730 592 593 + if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED) { 594 + if (!cdns_uart->rs485_tx_started) { 595 + cdns_uart->tx_timer.function = &cdns_rs485_tx_callback; 596 + cdns_rs485_tx_setup(cdns_uart); 597 + return hrtimer_start(&cdns_uart->tx_timer, 598 + ms_to_ktime(port->rs485.delay_rts_before_send), 599 + HRTIMER_MODE_REL); 600 + } 601 + } 731 602 cdns_uart_handle_tx(port); 732 - 733 - /* Enable the TX Empty interrupt */ 734 - writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_IER); 735 603 } 736 604 737 605 /** ··· 748 602 static void cdns_uart_stop_tx(struct uart_port *port) 749 603 { 750 604 unsigned int regval; 605 + struct cdns_uart *cdns_uart = port->private_data; 606 + 607 + if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED) 608 + cdns_rs485_rx_setup(cdns_uart); 751 609 752 610 regval = readl(port->membase + CDNS_UART_CR); 753 611 regval |= CDNS_UART_CR_TX_DIS; ··· 774 624 regval = readl(port->membase + CDNS_UART_CR); 775 625 regval |= CDNS_UART_CR_RX_DIS; 776 626 writel(regval, port->membase + CDNS_UART_CR); 777 - } 778 - 779 - /** 780 - * cdns_uart_tx_empty - Check whether TX is empty 781 - * @port: Handle to the uart port structure 782 - * 783 - * Return: TIOCSER_TEMT on success, 0 otherwise 784 - */ 785 - static unsigned int cdns_uart_tx_empty(struct uart_port *port) 786 - { 787 - unsigned int status; 788 - 789 - status = readl(port->membase + CDNS_UART_SR) & 790 - (CDNS_UART_SR_TXEMPTY | CDNS_UART_SR_TACTIVE); 791 - return (status == CDNS_UART_SR_TXEMPTY) ? TIOCSER_TEMT : 0; 792 627 } 793 628 794 629 /** ··· 964 829 (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST)) 965 830 cpu_relax(); 966 831 832 + if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED) 833 + cdns_rs485_rx_setup(cdns_uart); 834 + 967 835 /* 968 836 * Clear the RX disable bit and then set the RX enable bit to enable 969 837 * the receiver. ··· 1026 888 { 1027 889 int status; 1028 890 unsigned long flags; 891 + struct cdns_uart *cdns_uart = port->private_data; 892 + 893 + if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED) 894 + hrtimer_cancel(&cdns_uart->tx_timer); 1029 895 1030 896 uart_port_lock_irqsave(port, &flags); 1031 897 ··· 1175 1033 1176 1034 if (mctrl & TIOCM_RTS) 1177 1035 val |= CDNS_UART_MODEMCR_RTS; 1036 + if (cdns_uart_data->gpiod_rts) 1037 + gpiod_set_value(cdns_uart_data->gpiod_rts, !(mctrl & TIOCM_RTS)); 1178 1038 if (mctrl & TIOCM_DTR) 1179 1039 val |= CDNS_UART_MODEMCR_DTR; 1180 1040 if (mctrl & TIOCM_LOOP) ··· 1600 1456 static int instances; 1601 1457 1602 1458 /** 1459 + * cdns_rs485_config - Called when an application calls TIOCSRS485 ioctl. 1460 + * @port: Pointer to the uart_port structure 1461 + * @termios: Pointer to the ktermios structure 1462 + * @rs485: Pointer to the serial_rs485 structure 1463 + * 1464 + * Return: 0 1465 + */ 1466 + static int cdns_rs485_config(struct uart_port *port, struct ktermios *termios, 1467 + struct serial_rs485 *rs485) 1468 + { 1469 + u32 val; 1470 + struct cdns_uart *cdns_uart = port->private_data; 1471 + 1472 + if (rs485->flags & SER_RS485_ENABLED) { 1473 + dev_dbg(port->dev, "Setting UART to RS485\n"); 1474 + /* Make sure auto RTS is disabled */ 1475 + val = readl(port->membase + CDNS_UART_MODEMCR); 1476 + val &= ~CDNS_UART_MODEMCR_FCM; 1477 + writel(val, port->membase + CDNS_UART_MODEMCR); 1478 + 1479 + /* Timer setup */ 1480 + hrtimer_init(&cdns_uart->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 1481 + cdns_uart->tx_timer.function = &cdns_rs485_tx_callback; 1482 + 1483 + /* Disable transmitter and make Rx setup*/ 1484 + cdns_uart_stop_tx(port); 1485 + } else { 1486 + hrtimer_cancel(&cdns_uart->tx_timer); 1487 + } 1488 + return 0; 1489 + } 1490 + 1491 + /** 1603 1492 * cdns_uart_probe - Platform driver probe 1604 1493 * @pdev: Pointer to the platform device structure 1605 1494 * ··· 1774 1597 port->private_data = cdns_uart_data; 1775 1598 port->read_status_mask = CDNS_UART_IXR_TXEMPTY | CDNS_UART_IXR_RXTRIG | 1776 1599 CDNS_UART_IXR_OVERRUN | CDNS_UART_IXR_TOUT; 1600 + port->rs485_config = cdns_rs485_config; 1601 + port->rs485_supported = cdns_rs485_supported; 1777 1602 cdns_uart_data->port = port; 1778 1603 platform_set_drvdata(pdev, port); 1604 + 1605 + rc = uart_get_rs485_mode(port); 1606 + if (rc) 1607 + goto err_out_clk_notifier; 1608 + 1609 + cdns_uart_data->gpiod_rts = devm_gpiod_get_optional(&pdev->dev, "rts", 1610 + GPIOD_OUT_LOW); 1611 + if (IS_ERR(cdns_uart_data->gpiod_rts)) { 1612 + rc = PTR_ERR(cdns_uart_data->gpiod_rts); 1613 + dev_err(port->dev, "xuartps: devm_gpiod_get_optional failed\n"); 1614 + goto err_out_clk_notifier; 1615 + } 1779 1616 1780 1617 pm_runtime_use_autosuspend(&pdev->dev); 1781 1618 pm_runtime_set_autosuspend_delay(&pdev->dev, UART_AUTOSUSPEND_TIMEOUT); ··· 1809 1618 console_port = port; 1810 1619 } 1811 1620 #endif 1621 + if (cdns_uart_data->port->rs485.flags & SER_RS485_ENABLED) 1622 + cdns_rs485_rx_setup(cdns_uart_data); 1812 1623 1813 1624 rc = uart_add_one_port(&cdns_uart_uart_driver, port); 1814 1625 if (rc) { ··· 1839 1646 pm_runtime_disable(&pdev->dev); 1840 1647 pm_runtime_set_suspended(&pdev->dev); 1841 1648 pm_runtime_dont_use_autosuspend(&pdev->dev); 1649 + err_out_clk_notifier: 1842 1650 #ifdef CONFIG_COMMON_CLK 1843 1651 clk_notifier_unregister(cdns_uart_data->uartclk, 1844 1652 &cdns_uart_data->clk_rate_change_nb);
+1
drivers/tty/tty_buffer.c
··· 7 7 #include <linux/errno.h> 8 8 #include <linux/minmax.h> 9 9 #include <linux/tty.h> 10 + #include <linux/tty_buffer.h> 10 11 #include <linux/tty_driver.h> 11 12 #include <linux/tty_flip.h> 12 13 #include <linux/timer.h>
+2 -2
drivers/tty/vt/Makefile
··· 5 5 FONTMAPFILE = cp437.uni 6 6 7 7 obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o \ 8 - selection.o keyboard.o 8 + selection.o keyboard.o \ 9 + vt.o defkeymap.o 9 10 obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o 10 - obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o 11 11 12 12 # Files generated that shall be removed upon make clean 13 13 clean-files := consolemap_deftbl.c defkeymap.c
+26 -17
drivers/tty/vt/selection.c
··· 7 7 * 'int set_selection_kernel(struct tiocl_selection *, struct tty_struct *)' 8 8 * 'void clear_selection(void)' 9 9 * 'int paste_selection(struct tty_struct *)' 10 - * 'int sel_loadlut(char __user *)' 10 + * 'int sel_loadlut(u32 __user *)' 11 11 * 12 12 * Now that /dev/vcs exists, most of this can disappear again. 13 13 */ ··· 73 73 } 74 74 75 75 /** 76 - * clear_selection - remove current selection 76 + * clear_selection - remove current selection 77 77 * 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. 80 82 */ 81 83 void clear_selection(void) 82 84 { ··· 90 88 } 91 89 EXPORT_SYMBOL_GPL(clear_selection); 92 90 93 - bool vc_is_sel(struct vc_data *vc) 91 + bool vc_is_sel(const struct vc_data *vc) 94 92 { 95 93 return vc == vc_sel.cons; 96 94 } ··· 112 110 } 113 111 114 112 /** 115 - * sel_loadlut() - load the LUT table 116 - * @p: user table 113 + * sel_loadlut() - load the LUT table 114 + * @lut: user table 117 115 * 118 - * Load the LUT table from user space. The caller must hold the console 119 - * lock. Make a temporary copy so a partial update doesn't make a mess. 116 + * Load the LUT table from user space. Make a temporary copy so a partial 117 + * update doesn't make a mess. 118 + * 119 + * Locking: The console lock is acquired. 120 120 */ 121 - int sel_loadlut(char __user *p) 121 + int sel_loadlut(u32 __user *lut) 122 122 { 123 123 u32 tmplut[ARRAY_SIZE(inwordLut)]; 124 - if (copy_from_user(tmplut, (u32 __user *)(p+4), sizeof(inwordLut))) 124 + 125 + if (copy_from_user(tmplut, lut, sizeof(inwordLut))) 125 126 return -EFAULT; 127 + 128 + console_lock(); 126 129 memcpy(inwordLut, tmplut, sizeof(inwordLut)); 130 + console_unlock(); 131 + 127 132 return 0; 128 133 } 129 134 ··· 175 166 } 176 167 177 168 /** 178 - * set_selection_user - set the current selection. 179 - * @sel: user selection info 180 - * @tty: the console tty 169 + * set_selection_user - set the current selection. 170 + * @sel: user selection info 171 + * @tty: the console tty 181 172 * 182 - * Invoked by the ioctl handle for the vt layer. 173 + * Invoked by the ioctl handle for the vt layer. 183 174 * 184 - * The entire selection process is managed under the console_lock. It's 185 - * a lot under the lock but its hardly a performance path 175 + * Locking: The entire selection process is managed under the console_lock. 176 + * It's a lot under the lock but its hardly a performance path. 186 177 */ 187 178 int set_selection_user(const struct tiocl_selection __user *sel, 188 179 struct tty_struct *tty)
+831 -700
drivers/tty/vt/vt.c
··· 145 145 static void save_cur(struct vc_data *vc); 146 146 static void reset_terminal(struct vc_data *vc, int do_clear); 147 147 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); 149 149 static void set_cursor(struct vc_data *vc); 150 150 static void hide_cursor(struct vc_data *vc); 151 151 static void console_callback(struct work_struct *ignored); ··· 175 175 int console_blanked; 176 176 EXPORT_SYMBOL(console_blanked); 177 177 178 - static int vesa_blank_mode; /* 0:none 1:suspendV 2:suspendH 3:powerdown */ 178 + static enum vesa_blank_mode vesa_blank_mode; 179 179 static int vesa_off_interval; 180 180 static int blankinterval; 181 181 core_param(consoleblank, blankinterval, int, 0444); ··· 286 286 return con_is_visible(vc) && !console_blanked; 287 287 } 288 288 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) 291 291 { 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); 298 301 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); 301 303 } 302 304 303 305 /* Called from the keyboard irq path.. */ ··· 593 591 static void do_update_region(struct vc_data *vc, unsigned long start, int count) 594 592 { 595 593 unsigned int xx, yy, offset; 596 - u16 *p; 594 + u16 *p = (u16 *)start; 597 595 598 - p = (u16 *) start; 599 - if (!vc->vc_sw->con_getxy) { 600 - offset = (start - vc->vc_origin) / 2; 601 - xx = offset % vc->vc_cols; 602 - yy = offset / vc->vc_cols; 603 - } else { 604 - int nxx, nyy; 605 - start = vc->vc_sw->con_getxy(vc, start, &nxx, &nyy); 606 - xx = nxx; yy = nyy; 607 - } 596 + offset = (start - vc->vc_origin) / 2; 597 + xx = offset % vc->vc_cols; 598 + yy = offset / vc->vc_cols; 599 + 608 600 for(;;) { 609 601 u16 attrib = scr_readw(p) & 0xff00; 610 602 int startx = xx; ··· 621 625 break; 622 626 xx = 0; 623 627 yy++; 624 - if (vc->vc_sw->con_getxy) { 625 - p = (u16 *)start; 626 - start = vc->vc_sw->con_getxy(vc, start, NULL, NULL); 627 - } 628 628 } 629 629 } 630 630 ··· 695 703 /* Note: inverting the screen twice should revert to the original state */ 696 704 void invert_screen(struct vc_data *vc, int offset, int count, bool viewed) 697 705 { 698 - unsigned short *p; 706 + u16 *p; 699 707 700 708 WARN_CONSOLE_UNLOCKED(); 701 709 ··· 754 762 old_offset < vc->vc_screenbuf_size) { 755 763 scr_writew(old, screenpos(vc, old_offset, true)); 756 764 if (con_should_update(vc)) 757 - vc->vc_sw->con_putc(vc, old, oldy, oldx); 765 + con_putc(vc, old, oldy, oldx); 758 766 notify_update(vc); 759 767 } 760 768 ··· 763 771 if (offset != -1 && offset >= 0 && 764 772 offset < vc->vc_screenbuf_size) { 765 773 unsigned short new; 766 - unsigned short *p; 767 - p = screenpos(vc, offset, true); 774 + u16 *p = screenpos(vc, offset, true); 768 775 old = scr_readw(p); 769 776 new = old ^ vc->vc_complement_mask; 770 777 scr_writew(new, p); 771 778 if (con_should_update(vc)) { 772 779 oldx = (offset >> 1) % vc->vc_cols; 773 780 oldy = (offset >> 1) / vc->vc_cols; 774 - vc->vc_sw->con_putc(vc, new, oldy, oldx); 781 + con_putc(vc, new, oldy, oldx); 775 782 } 776 783 notify_update(vc); 777 784 } ··· 824 833 i ^= CUR_FG; 825 834 scr_writew(i, (u16 *)vc->vc_pos); 826 835 if (con_should_update(vc)) 827 - vc->vc_sw->con_putc(vc, i, vc->state.y, vc->state.x); 836 + con_putc(vc, i, vc->state.y, vc->state.x); 828 837 } 829 838 830 839 static void hide_softcursor(struct vc_data *vc) ··· 832 841 if (softcursor_original != -1) { 833 842 scr_writew(softcursor_original, (u16 *)vc->vc_pos); 834 843 if (con_should_update(vc)) 835 - vc->vc_sw->con_putc(vc, softcursor_original, 836 - vc->state.y, vc->state.x); 844 + con_putc(vc, softcursor_original, vc->state.y, 845 + vc->state.x); 837 846 softcursor_original = -1; 838 847 } 839 848 } ··· 843 852 if (vc_is_sel(vc)) 844 853 clear_selection(); 845 854 846 - vc->vc_sw->con_cursor(vc, CM_ERASE); 855 + vc->vc_sw->con_cursor(vc, false); 847 856 hide_softcursor(vc); 848 857 } 849 858 ··· 856 865 clear_selection(); 857 866 add_softcursor(vc); 858 867 if (CUR_SIZE(vc->vc_cursor_type) != CUR_NONE) 859 - vc->vc_sw->con_cursor(vc, CM_DRAW); 868 + vc->vc_sw->con_cursor(vc, true); 860 869 } else 861 870 hide_cursor(vc); 862 871 } ··· 888 897 WARN_CONSOLE_UNLOCKED(); 889 898 890 899 set_origin(vc); 891 - if (vc->vc_sw->con_flush_scrollback) { 892 - vc->vc_sw->con_flush_scrollback(vc); 893 - } else if (con_is_visible(vc)) { 894 - /* 895 - * When no con_flush_scrollback method is provided then the 896 - * legacy way for flushing the scrollback buffer is to use 897 - * a side effect of the con_switch method. We do it only on 898 - * the foreground console as background consoles have no 899 - * scrollback buffers in that case and we obviously don't 900 - * want to switch to them. 901 - */ 902 - hide_cursor(vc); 903 - vc->vc_sw->con_switch(vc); 904 - set_cursor(vc); 905 - } 900 + if (!con_is_visible(vc)) 901 + return; 902 + 903 + /* 904 + * The legacy way for flushing the scrollback buffer is to use a side 905 + * effect of the con_switch method. We do it only on the foreground 906 + * console as background consoles have no scrollback buffers in that 907 + * case and we obviously don't want to switch to them. 908 + */ 909 + hide_cursor(vc); 910 + vc->vc_sw->con_switch(vc); 911 + set_cursor(vc); 906 912 } 907 913 908 914 /* ··· 950 962 } 951 963 952 964 if (redraw) { 953 - int update; 965 + bool update; 954 966 int old_was_color = vc->vc_can_do_color; 955 967 956 968 set_origin(vc); ··· 987 999 return (i < MAX_NR_CONSOLES && vc_cons[i].d); 988 1000 } 989 1001 990 - static void visual_init(struct vc_data *vc, int num, int init) 1002 + static void visual_init(struct vc_data *vc, int num, bool init) 991 1003 { 992 1004 /* ++Geert: vc->vc_sw->con_init determines console size */ 993 1005 if (vc->vc_sw) ··· 1071 1083 vc->port.ops = &vc_port_ops; 1072 1084 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); 1073 1085 1074 - visual_init(vc, currcons, 1); 1086 + visual_init(vc, currcons, true); 1075 1087 1076 1088 if (!*vc->uni_pagedict_loc) 1077 1089 con_set_default_unimap(vc); ··· 1103 1115 } 1104 1116 1105 1117 static inline int resize_screen(struct vc_data *vc, int width, int height, 1106 - int user) 1118 + bool from_user) 1107 1119 { 1108 1120 /* Resizes the resolution of the display adapater */ 1109 1121 int err = 0; 1110 1122 1111 1123 if (vc->vc_sw->con_resize) 1112 - err = vc->vc_sw->con_resize(vc, width, height, user); 1124 + err = vc->vc_sw->con_resize(vc, width, height, from_user); 1113 1125 1114 1126 return err; 1115 1127 } 1116 1128 1117 1129 /** 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 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 1135 + * @from_user: invoked by a user? 1123 1136 * 1124 - * Resize a virtual console, clipping according to the actual constraints. 1125 - * If the caller passes a tty structure then update the termios winsize 1126 - * information and perform any necessary signal handling. 1137 + * Resize a virtual console, clipping according to the actual constraints. If 1138 + * the caller passes a tty structure then update the termios winsize 1139 + * information and perform any necessary signal handling. 1127 1140 * 1128 - * Caller must hold the console semaphore. Takes the termios rwsem and 1129 - * ctrl.lock of the tty IFF a tty is passed. 1141 + * Locking: Caller must hold the console semaphore. Takes the termios rwsem and 1142 + * ctrl.lock of the tty IFF a tty is passed. 1130 1143 */ 1131 - 1132 1144 static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, 1133 - unsigned int cols, unsigned int lines) 1145 + unsigned int cols, unsigned int lines, bool from_user) 1134 1146 { 1135 1147 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0; 1136 1148 unsigned long end; 1137 1149 unsigned int old_rows, old_row_size, first_copied_row; 1138 1150 unsigned int new_cols, new_rows, new_row_size, new_screen_size; 1139 - unsigned int user; 1140 1151 unsigned short *oldscreen, *newscreen; 1141 1152 u32 **new_uniscr = NULL; 1142 1153 1143 1154 WARN_CONSOLE_UNLOCKED(); 1144 - 1145 - if (!vc) 1146 - return -ENXIO; 1147 - 1148 - user = vc->vc_resize_user; 1149 - vc->vc_resize_user = 0; 1150 1155 1151 1156 if (cols > VC_MAXCOL || lines > VC_MAXROW) 1152 1157 return -EINVAL; ··· 1166 1185 * to deal with possible errors from the code below, we call 1167 1186 * the resize_screen here as well. 1168 1187 */ 1169 - return resize_screen(vc, new_cols, new_rows, user); 1188 + return resize_screen(vc, new_cols, new_rows, from_user); 1170 1189 } 1171 1190 1172 1191 if (new_screen_size > KMALLOC_MAX_SIZE || !new_screen_size) ··· 1189 1208 old_rows = vc->vc_rows; 1190 1209 old_row_size = vc->vc_size_row; 1191 1210 1192 - err = resize_screen(vc, new_cols, new_rows, user); 1211 + err = resize_screen(vc, new_cols, new_rows, from_user); 1193 1212 if (err) { 1194 1213 kfree(newscreen); 1195 1214 vc_uniscr_free(new_uniscr); ··· 1276 1295 } 1277 1296 1278 1297 /** 1279 - * vc_resize - resize a VT 1280 - * @vc: virtual console 1281 - * @cols: columns 1282 - * @rows: rows 1298 + * __vc_resize - resize a VT 1299 + * @vc: virtual console 1300 + * @cols: columns 1301 + * @rows: rows 1302 + * @from_user: invoked by a user? 1283 1303 * 1284 - * Resize a virtual console as seen from the console end of things. We 1285 - * use the common vc_do_resize methods to update the structures. The 1286 - * caller must hold the console sem to protect console internals and 1287 - * vc->port.tty 1304 + * Resize a virtual console as seen from the console end of things. We use the 1305 + * common vc_do_resize() method to update the structures. 1306 + * 1307 + * Locking: The caller must hold the console sem to protect console internals 1308 + * and @vc->port.tty. 1288 1309 */ 1289 - 1290 - int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows) 1310 + int __vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows, 1311 + bool from_user) 1291 1312 { 1292 - return vc_do_resize(vc->port.tty, vc, cols, rows); 1313 + return vc_do_resize(vc->port.tty, vc, cols, rows, from_user); 1293 1314 } 1294 - EXPORT_SYMBOL(vc_resize); 1315 + EXPORT_SYMBOL(__vc_resize); 1295 1316 1296 1317 /** 1297 - * vt_resize - resize a VT 1298 - * @tty: tty to resize 1299 - * @ws: winsize attributes 1318 + * vt_resize - resize a VT 1319 + * @tty: tty to resize 1320 + * @ws: winsize attributes 1300 1321 * 1301 - * Resize a virtual terminal. This is called by the tty layer as we 1302 - * register our own handler for resizing. The mutual helper does all 1303 - * the actual work. 1322 + * Resize a virtual terminal. This is called by the tty layer as we register 1323 + * our own handler for resizing. The mutual helper does all the actual work. 1304 1324 * 1305 - * Takes the console sem and the called methods then take the tty 1306 - * termios_rwsem and the tty ctrl.lock in that order. 1325 + * Locking: Takes the console sem and the called methods then take the tty 1326 + * termios_rwsem and the tty ctrl.lock in that order. 1307 1327 */ 1308 1328 static int vt_resize(struct tty_struct *tty, struct winsize *ws) 1309 1329 { ··· 1312 1330 int ret; 1313 1331 1314 1332 console_lock(); 1315 - ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row); 1333 + ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row, false); 1316 1334 console_unlock(); 1317 1335 return ret; 1318 1336 } ··· 1485 1503 /* ignored */ 1486 1504 } 1487 1505 1488 - static void csi_J(struct vc_data *vc, int vpar) 1506 + enum CSI_J { 1507 + CSI_J_CURSOR_TO_END = 0, 1508 + CSI_J_START_TO_CURSOR = 1, 1509 + CSI_J_VISIBLE = 2, 1510 + CSI_J_FULL = 3, 1511 + }; 1512 + 1513 + static void csi_J(struct vc_data *vc, enum CSI_J vpar) 1489 1514 { 1515 + unsigned short *start; 1490 1516 unsigned int count; 1491 - unsigned short * start; 1492 1517 1493 1518 switch (vpar) { 1494 - case 0: /* erase from cursor to end of display */ 1495 - vc_uniscr_clear_line(vc, vc->state.x, 1496 - vc->vc_cols - vc->state.x); 1497 - vc_uniscr_clear_lines(vc, vc->state.y + 1, 1498 - vc->vc_rows - vc->state.y - 1); 1499 - count = (vc->vc_scr_end - vc->vc_pos) >> 1; 1500 - start = (unsigned short *)vc->vc_pos; 1501 - break; 1502 - case 1: /* erase from start to cursor */ 1503 - vc_uniscr_clear_line(vc, 0, vc->state.x + 1); 1504 - vc_uniscr_clear_lines(vc, 0, vc->state.y); 1505 - count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1; 1506 - start = (unsigned short *)vc->vc_origin; 1507 - break; 1508 - case 3: /* include scrollback */ 1509 - flush_scrollback(vc); 1510 - fallthrough; 1511 - case 2: /* erase whole display */ 1512 - vc_uniscr_clear_lines(vc, 0, vc->vc_rows); 1513 - count = vc->vc_cols * vc->vc_rows; 1514 - start = (unsigned short *)vc->vc_origin; 1515 - break; 1516 - default: 1517 - return; 1519 + case CSI_J_CURSOR_TO_END: 1520 + vc_uniscr_clear_line(vc, vc->state.x, 1521 + vc->vc_cols - vc->state.x); 1522 + vc_uniscr_clear_lines(vc, vc->state.y + 1, 1523 + vc->vc_rows - vc->state.y - 1); 1524 + count = (vc->vc_scr_end - vc->vc_pos) >> 1; 1525 + start = (unsigned short *)vc->vc_pos; 1526 + break; 1527 + case CSI_J_START_TO_CURSOR: 1528 + vc_uniscr_clear_line(vc, 0, vc->state.x + 1); 1529 + vc_uniscr_clear_lines(vc, 0, vc->state.y); 1530 + count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1; 1531 + start = (unsigned short *)vc->vc_origin; 1532 + break; 1533 + case CSI_J_FULL: 1534 + flush_scrollback(vc); 1535 + fallthrough; 1536 + case CSI_J_VISIBLE: 1537 + vc_uniscr_clear_lines(vc, 0, vc->vc_rows); 1538 + count = vc->vc_cols * vc->vc_rows; 1539 + start = (unsigned short *)vc->vc_origin; 1540 + break; 1541 + default: 1542 + return; 1518 1543 } 1519 1544 scr_memsetw(start, vc->vc_video_erase_char, 2 * count); 1520 1545 if (con_should_update(vc)) ··· 1529 1540 vc->vc_need_wrap = 0; 1530 1541 } 1531 1542 1532 - static void csi_K(struct vc_data *vc, int vpar) 1543 + enum { 1544 + CSI_K_CURSOR_TO_LINEEND = 0, 1545 + CSI_K_LINESTART_TO_CURSOR = 1, 1546 + CSI_K_LINE = 2, 1547 + }; 1548 + 1549 + static void csi_K(struct vc_data *vc) 1533 1550 { 1534 1551 unsigned int count; 1535 1552 unsigned short *start = (unsigned short *)vc->vc_pos; 1536 1553 int offset; 1537 1554 1538 - switch (vpar) { 1539 - case 0: /* erase from cursor to end of line */ 1540 - offset = 0; 1541 - count = vc->vc_cols - vc->state.x; 1542 - break; 1543 - case 1: /* erase from start of line to cursor */ 1544 - offset = -vc->state.x; 1545 - count = vc->state.x + 1; 1546 - break; 1547 - case 2: /* erase whole line */ 1548 - offset = -vc->state.x; 1549 - count = vc->vc_cols; 1550 - break; 1551 - default: 1552 - return; 1555 + switch (vc->vc_par[0]) { 1556 + case CSI_K_CURSOR_TO_LINEEND: 1557 + offset = 0; 1558 + count = vc->vc_cols - vc->state.x; 1559 + break; 1560 + case CSI_K_LINESTART_TO_CURSOR: 1561 + offset = -vc->state.x; 1562 + count = vc->state.x + 1; 1563 + break; 1564 + case CSI_K_LINE: 1565 + offset = -vc->state.x; 1566 + count = vc->vc_cols; 1567 + break; 1568 + default: 1569 + return; 1553 1570 } 1554 1571 vc_uniscr_clear_line(vc, vc->state.x + offset, count); 1555 1572 scr_memsetw(start + offset, vc->vc_video_erase_char, 2 * count); ··· 1564 1569 do_update_region(vc, (unsigned long)(start + offset), count); 1565 1570 } 1566 1571 1567 - /* erase the following vpar positions */ 1568 - static void csi_X(struct vc_data *vc, unsigned int vpar) 1572 + /* erase the following count positions */ 1573 + static void csi_X(struct vc_data *vc) 1569 1574 { /* not vt100? */ 1570 - unsigned int count; 1571 - 1572 - if (!vpar) 1573 - vpar++; 1574 - 1575 - count = min(vpar, vc->vc_cols - vc->state.x); 1575 + unsigned int count = clamp(vc->vc_par[0], 1, vc->vc_cols - vc->state.x); 1576 1576 1577 1577 vc_uniscr_clear_line(vc, vc->state.x, count); 1578 1578 scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count); 1579 1579 if (con_should_update(vc)) 1580 - vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, 1, count); 1580 + vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, count); 1581 1581 vc->vc_need_wrap = 0; 1582 1582 } 1583 1583 ··· 1588 1598 1589 1599 struct rgb { u8 r; u8 g; u8 b; }; 1590 1600 1591 - static void rgb_from_256(int i, struct rgb *c) 1601 + static void rgb_from_256(unsigned int i, struct rgb *c) 1592 1602 { 1593 1603 if (i < 8) { /* Standard colours. */ 1594 1604 c->r = i&1 ? 0xaa : 0x00; ··· 1599 1609 c->g = i&2 ? 0xff : 0x55; 1600 1610 c->b = i&4 ? 0xff : 0x55; 1601 1611 } else if (i < 232) { /* 6x6x6 colour cube. */ 1602 - c->r = (i - 16) / 36 * 85 / 2; 1603 - c->g = (i - 16) / 6 % 6 * 85 / 2; 1604 - c->b = (i - 16) % 6 * 85 / 2; 1612 + i -= 16; 1613 + c->b = i % 6 * 255 / 6; 1614 + i /= 6; 1615 + c->g = i % 6 * 255 / 6; 1616 + i /= 6; 1617 + c->r = i * 255 / 6; 1605 1618 } else /* Grayscale ramp. */ 1606 1619 c->r = c->g = c->b = i * 10 - 2312; 1607 1620 } ··· 1674 1681 return i; 1675 1682 } 1676 1683 1684 + enum { 1685 + CSI_m_DEFAULT = 0, 1686 + CSI_m_BOLD = 1, 1687 + CSI_m_HALF_BRIGHT = 2, 1688 + CSI_m_ITALIC = 3, 1689 + CSI_m_UNDERLINE = 4, 1690 + CSI_m_BLINK = 5, 1691 + CSI_m_REVERSE = 7, 1692 + CSI_m_PRI_FONT = 10, 1693 + CSI_m_ALT_FONT1 = 11, 1694 + CSI_m_ALT_FONT2 = 12, 1695 + CSI_m_DOUBLE_UNDERLINE = 21, 1696 + CSI_m_NORMAL_INTENSITY = 22, 1697 + CSI_m_NO_ITALIC = 23, 1698 + CSI_m_NO_UNDERLINE = 24, 1699 + CSI_m_NO_BLINK = 25, 1700 + CSI_m_NO_REVERSE = 27, 1701 + CSI_m_FG_COLOR_BEG = 30, 1702 + CSI_m_FG_COLOR_END = 37, 1703 + CSI_m_FG_COLOR = 38, 1704 + CSI_m_DEFAULT_FG_COLOR = 39, 1705 + CSI_m_BG_COLOR_BEG = 40, 1706 + CSI_m_BG_COLOR_END = 47, 1707 + CSI_m_BG_COLOR = 48, 1708 + CSI_m_DEFAULT_BG_COLOR = 49, 1709 + CSI_m_BRIGHT_FG_COLOR_BEG = 90, 1710 + CSI_m_BRIGHT_FG_COLOR_END = 97, 1711 + CSI_m_BRIGHT_FG_COLOR_OFF = CSI_m_BRIGHT_FG_COLOR_BEG - CSI_m_FG_COLOR_BEG, 1712 + CSI_m_BRIGHT_BG_COLOR_BEG = 100, 1713 + CSI_m_BRIGHT_BG_COLOR_END = 107, 1714 + CSI_m_BRIGHT_BG_COLOR_OFF = CSI_m_BRIGHT_BG_COLOR_BEG - CSI_m_BG_COLOR_BEG, 1715 + }; 1716 + 1677 1717 /* console_lock is held */ 1678 1718 static void csi_m(struct vc_data *vc) 1679 1719 { ··· 1714 1688 1715 1689 for (i = 0; i <= vc->vc_npar; i++) 1716 1690 switch (vc->vc_par[i]) { 1717 - case 0: /* all attributes off */ 1691 + case CSI_m_DEFAULT: /* all attributes off */ 1718 1692 default_attr(vc); 1719 1693 break; 1720 - case 1: 1694 + case CSI_m_BOLD: 1721 1695 vc->state.intensity = VCI_BOLD; 1722 1696 break; 1723 - case 2: 1697 + case CSI_m_HALF_BRIGHT: 1724 1698 vc->state.intensity = VCI_HALF_BRIGHT; 1725 1699 break; 1726 - case 3: 1700 + case CSI_m_ITALIC: 1727 1701 vc->state.italic = true; 1728 1702 break; 1729 - case 21: 1703 + case CSI_m_DOUBLE_UNDERLINE: 1730 1704 /* 1731 1705 * No console drivers support double underline, so 1732 1706 * convert it to a single underline. 1733 1707 */ 1734 - case 4: 1708 + case CSI_m_UNDERLINE: 1735 1709 vc->state.underline = true; 1736 1710 break; 1737 - case 5: 1711 + case CSI_m_BLINK: 1738 1712 vc->state.blink = true; 1739 1713 break; 1740 - case 7: 1714 + case CSI_m_REVERSE: 1741 1715 vc->state.reverse = true; 1742 1716 break; 1743 - case 10: /* ANSI X3.64-1979 (SCO-ish?) 1717 + case CSI_m_PRI_FONT: /* ANSI X3.64-1979 (SCO-ish?) 1744 1718 * Select primary font, don't display control chars if 1745 1719 * defined, don't set bit 8 on output. 1746 1720 */ ··· 1748 1722 vc->vc_disp_ctrl = 0; 1749 1723 vc->vc_toggle_meta = 0; 1750 1724 break; 1751 - case 11: /* ANSI X3.64-1979 (SCO-ish?) 1725 + case CSI_m_ALT_FONT1: /* ANSI X3.64-1979 (SCO-ish?) 1752 1726 * Select first alternate font, lets chars < 32 be 1753 1727 * displayed as ROM chars. 1754 1728 */ ··· 1756 1730 vc->vc_disp_ctrl = 1; 1757 1731 vc->vc_toggle_meta = 0; 1758 1732 break; 1759 - case 12: /* ANSI X3.64-1979 (SCO-ish?) 1733 + case CSI_m_ALT_FONT2: /* ANSI X3.64-1979 (SCO-ish?) 1760 1734 * Select second alternate font, toggle high bit 1761 1735 * before displaying as ROM char. 1762 1736 */ ··· 1764 1738 vc->vc_disp_ctrl = 1; 1765 1739 vc->vc_toggle_meta = 1; 1766 1740 break; 1767 - case 22: 1741 + case CSI_m_NORMAL_INTENSITY: 1768 1742 vc->state.intensity = VCI_NORMAL; 1769 1743 break; 1770 - case 23: 1744 + case CSI_m_NO_ITALIC: 1771 1745 vc->state.italic = false; 1772 1746 break; 1773 - case 24: 1747 + case CSI_m_NO_UNDERLINE: 1774 1748 vc->state.underline = false; 1775 1749 break; 1776 - case 25: 1750 + case CSI_m_NO_BLINK: 1777 1751 vc->state.blink = false; 1778 1752 break; 1779 - case 27: 1753 + case CSI_m_NO_REVERSE: 1780 1754 vc->state.reverse = false; 1781 1755 break; 1782 - case 38: 1756 + case CSI_m_FG_COLOR: 1783 1757 i = vc_t416_color(vc, i, rgb_foreground); 1784 1758 break; 1785 - case 48: 1759 + case CSI_m_BG_COLOR: 1786 1760 i = vc_t416_color(vc, i, rgb_background); 1787 1761 break; 1788 - case 39: 1762 + case CSI_m_DEFAULT_FG_COLOR: 1789 1763 vc->state.color = (vc->vc_def_color & 0x0f) | 1790 1764 (vc->state.color & 0xf0); 1791 1765 break; 1792 - case 49: 1766 + case CSI_m_DEFAULT_BG_COLOR: 1793 1767 vc->state.color = (vc->vc_def_color & 0xf0) | 1794 1768 (vc->state.color & 0x0f); 1795 1769 break; 1796 - default: 1797 - if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) { 1798 - if (vc->vc_par[i] < 100) 1799 - vc->state.intensity = VCI_BOLD; 1800 - vc->vc_par[i] -= 60; 1801 - } 1802 - if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37) 1803 - vc->state.color = color_table[vc->vc_par[i] - 30] 1804 - | (vc->state.color & 0xf0); 1805 - else if (vc->vc_par[i] >= 40 && vc->vc_par[i] <= 47) 1806 - vc->state.color = (color_table[vc->vc_par[i] - 40] << 4) 1807 - | (vc->state.color & 0x0f); 1770 + case CSI_m_BRIGHT_FG_COLOR_BEG ... CSI_m_BRIGHT_FG_COLOR_END: 1771 + vc->state.intensity = VCI_BOLD; 1772 + vc->vc_par[i] -= CSI_m_BRIGHT_FG_COLOR_OFF; 1773 + fallthrough; 1774 + case CSI_m_FG_COLOR_BEG ... CSI_m_FG_COLOR_END: 1775 + vc->vc_par[i] -= CSI_m_FG_COLOR_BEG; 1776 + vc->state.color = color_table[vc->vc_par[i]] | 1777 + (vc->state.color & 0xf0); 1778 + break; 1779 + case CSI_m_BRIGHT_BG_COLOR_BEG ... CSI_m_BRIGHT_BG_COLOR_END: 1780 + vc->vc_par[i] -= CSI_m_BRIGHT_BG_COLOR_OFF; 1781 + fallthrough; 1782 + case CSI_m_BG_COLOR_BEG ... CSI_m_BG_COLOR_END: 1783 + vc->vc_par[i] -= CSI_m_BG_COLOR_BEG; 1784 + vc->state.color = (color_table[vc->vc_par[i]] << 4) | 1785 + (vc->state.color & 0x0f); 1808 1786 break; 1809 1787 } 1810 1788 update_attr(vc); ··· 1862 1832 return vc_cons[fg_console].d->vc_report_mouse; 1863 1833 } 1864 1834 1835 + enum { 1836 + CSI_DEC_hl_CURSOR_KEYS = 1, /* CKM: cursor keys send ^[Ox/^[[x */ 1837 + CSI_DEC_hl_132_COLUMNS = 3, /* COLM: 80/132 mode switch */ 1838 + CSI_DEC_hl_REVERSE_VIDEO = 5, /* SCNM */ 1839 + CSI_DEC_hl_ORIGIN_MODE = 6, /* OM: origin relative/absolute */ 1840 + CSI_DEC_hl_AUTOWRAP = 7, /* AWM */ 1841 + CSI_DEC_hl_AUTOREPEAT = 8, /* ARM */ 1842 + CSI_DEC_hl_MOUSE_X10 = 9, 1843 + CSI_DEC_hl_SHOW_CURSOR = 25, /* TCEM */ 1844 + CSI_DEC_hl_MOUSE_VT200 = 1000, 1845 + }; 1846 + 1865 1847 /* console_lock is held */ 1866 - static void set_mode(struct vc_data *vc, int on_off) 1848 + static void csi_DEC_hl(struct vc_data *vc, bool on_off) 1867 1849 { 1868 - int i; 1850 + unsigned int i; 1869 1851 1870 1852 for (i = 0; i <= vc->vc_npar; i++) 1871 - if (vc->vc_priv == EPdec) { 1872 - switch(vc->vc_par[i]) { /* DEC private modes set/reset */ 1873 - case 1: /* Cursor keys send ^[Ox/^[[x */ 1874 - if (on_off) 1875 - set_kbd(vc, decckm); 1876 - else 1877 - clr_kbd(vc, decckm); 1878 - break; 1879 - case 3: /* 80/132 mode switch unimplemented */ 1853 + switch (vc->vc_par[i]) { 1854 + case CSI_DEC_hl_CURSOR_KEYS: 1855 + if (on_off) 1856 + set_kbd(vc, decckm); 1857 + else 1858 + clr_kbd(vc, decckm); 1859 + break; 1860 + case CSI_DEC_hl_132_COLUMNS: /* unimplemented */ 1880 1861 #if 0 1881 - vc_resize(deccolm ? 132 : 80, vc->vc_rows); 1882 - /* this alone does not suffice; some user mode 1883 - utility has to change the hardware regs */ 1862 + vc_resize(deccolm ? 132 : 80, vc->vc_rows); 1863 + /* this alone does not suffice; some user mode 1864 + utility has to change the hardware regs */ 1884 1865 #endif 1885 - break; 1886 - case 5: /* Inverted screen on/off */ 1887 - if (vc->vc_decscnm != on_off) { 1888 - vc->vc_decscnm = on_off; 1889 - invert_screen(vc, 0, 1890 - vc->vc_screenbuf_size, 1891 - false); 1892 - update_attr(vc); 1893 - } 1894 - break; 1895 - case 6: /* Origin relative/absolute */ 1896 - vc->vc_decom = on_off; 1897 - gotoxay(vc, 0, 0); 1898 - break; 1899 - case 7: /* Autowrap on/off */ 1900 - vc->vc_decawm = on_off; 1901 - break; 1902 - case 8: /* Autorepeat on/off */ 1903 - if (on_off) 1904 - set_kbd(vc, decarm); 1905 - else 1906 - clr_kbd(vc, decarm); 1907 - break; 1908 - case 9: 1909 - vc->vc_report_mouse = on_off ? 1 : 0; 1910 - break; 1911 - case 25: /* Cursor on/off */ 1912 - vc->vc_deccm = on_off; 1913 - break; 1914 - case 1000: 1915 - vc->vc_report_mouse = on_off ? 2 : 0; 1916 - break; 1866 + break; 1867 + case CSI_DEC_hl_REVERSE_VIDEO: 1868 + if (vc->vc_decscnm != on_off) { 1869 + vc->vc_decscnm = on_off; 1870 + invert_screen(vc, 0, vc->vc_screenbuf_size, 1871 + false); 1872 + update_attr(vc); 1917 1873 } 1918 - } else { 1919 - switch(vc->vc_par[i]) { /* ANSI modes set/reset */ 1920 - case 3: /* Monitor (display ctrls) */ 1921 - vc->vc_disp_ctrl = on_off; 1922 - break; 1923 - case 4: /* Insert Mode on/off */ 1924 - vc->vc_decim = on_off; 1925 - break; 1926 - case 20: /* Lf, Enter == CrLf/Lf */ 1927 - if (on_off) 1928 - set_kbd(vc, lnm); 1929 - else 1930 - clr_kbd(vc, lnm); 1931 - break; 1932 - } 1874 + break; 1875 + case CSI_DEC_hl_ORIGIN_MODE: 1876 + vc->vc_decom = on_off; 1877 + gotoxay(vc, 0, 0); 1878 + break; 1879 + case CSI_DEC_hl_AUTOWRAP: 1880 + vc->vc_decawm = on_off; 1881 + break; 1882 + case CSI_DEC_hl_AUTOREPEAT: 1883 + if (on_off) 1884 + set_kbd(vc, decarm); 1885 + else 1886 + clr_kbd(vc, decarm); 1887 + break; 1888 + case CSI_DEC_hl_MOUSE_X10: 1889 + vc->vc_report_mouse = on_off ? 1 : 0; 1890 + break; 1891 + case CSI_DEC_hl_SHOW_CURSOR: 1892 + vc->vc_deccm = on_off; 1893 + break; 1894 + case CSI_DEC_hl_MOUSE_VT200: 1895 + vc->vc_report_mouse = on_off ? 2 : 0; 1896 + break; 1933 1897 } 1934 1898 } 1935 1899 1900 + enum { 1901 + CSI_hl_DISPLAY_CTRL = 3, /* handle ansi control chars */ 1902 + CSI_hl_INSERT = 4, /* IRM: insert/replace */ 1903 + CSI_hl_AUTO_NL = 20, /* LNM: Enter == CrLf/Lf */ 1904 + }; 1905 + 1936 1906 /* console_lock is held */ 1937 - static void setterm_command(struct vc_data *vc) 1907 + static void csi_hl(struct vc_data *vc, bool on_off) 1908 + { 1909 + unsigned int i; 1910 + 1911 + for (i = 0; i <= vc->vc_npar; i++) 1912 + switch (vc->vc_par[i]) { /* ANSI modes set/reset */ 1913 + case CSI_hl_DISPLAY_CTRL: 1914 + vc->vc_disp_ctrl = on_off; 1915 + break; 1916 + case CSI_hl_INSERT: 1917 + vc->vc_decim = on_off; 1918 + break; 1919 + case CSI_hl_AUTO_NL: 1920 + if (on_off) 1921 + set_kbd(vc, lnm); 1922 + else 1923 + clr_kbd(vc, lnm); 1924 + break; 1925 + } 1926 + } 1927 + 1928 + enum CSI_right_square_bracket { 1929 + CSI_RSB_COLOR_FOR_UNDERLINE = 1, 1930 + CSI_RSB_COLOR_FOR_HALF_BRIGHT = 2, 1931 + CSI_RSB_MAKE_CUR_COLOR_DEFAULT = 8, 1932 + CSI_RSB_BLANKING_INTERVAL = 9, 1933 + CSI_RSB_BELL_FREQUENCY = 10, 1934 + CSI_RSB_BELL_DURATION = 11, 1935 + CSI_RSB_BRING_CONSOLE_TO_FRONT = 12, 1936 + CSI_RSB_UNBLANK = 13, 1937 + CSI_RSB_VESA_OFF_INTERVAL = 14, 1938 + CSI_RSB_BRING_PREV_CONSOLE_TO_FRONT = 15, 1939 + CSI_RSB_CURSOR_BLINK_INTERVAL = 16, 1940 + }; 1941 + 1942 + /* 1943 + * csi_RSB - csi+] (Right Square Bracket) handler 1944 + * 1945 + * These are linux console private sequences. 1946 + * 1947 + * console_lock is held 1948 + */ 1949 + static void csi_RSB(struct vc_data *vc) 1938 1950 { 1939 1951 switch (vc->vc_par[0]) { 1940 - case 1: /* set color for underline mode */ 1952 + case CSI_RSB_COLOR_FOR_UNDERLINE: 1941 1953 if (vc->vc_can_do_color && vc->vc_par[1] < 16) { 1942 1954 vc->vc_ulcolor = color_table[vc->vc_par[1]]; 1943 1955 if (vc->state.underline) 1944 1956 update_attr(vc); 1945 1957 } 1946 1958 break; 1947 - case 2: /* set color for half intensity mode */ 1959 + case CSI_RSB_COLOR_FOR_HALF_BRIGHT: 1948 1960 if (vc->vc_can_do_color && vc->vc_par[1] < 16) { 1949 1961 vc->vc_halfcolor = color_table[vc->vc_par[1]]; 1950 1962 if (vc->state.intensity == VCI_HALF_BRIGHT) 1951 1963 update_attr(vc); 1952 1964 } 1953 1965 break; 1954 - case 8: /* store colors as defaults */ 1966 + case CSI_RSB_MAKE_CUR_COLOR_DEFAULT: 1955 1967 vc->vc_def_color = vc->vc_attr; 1956 1968 if (vc->vc_hi_font_mask == 0x100) 1957 1969 vc->vc_def_color >>= 1; 1958 1970 default_attr(vc); 1959 1971 update_attr(vc); 1960 1972 break; 1961 - case 9: /* set blanking interval */ 1973 + case CSI_RSB_BLANKING_INTERVAL: 1962 1974 blankinterval = min(vc->vc_par[1], 60U) * 60; 1963 1975 poke_blanked_console(); 1964 1976 break; 1965 - case 10: /* set bell frequency in Hz */ 1977 + case CSI_RSB_BELL_FREQUENCY: 1966 1978 if (vc->vc_npar >= 1) 1967 1979 vc->vc_bell_pitch = vc->vc_par[1]; 1968 1980 else 1969 1981 vc->vc_bell_pitch = DEFAULT_BELL_PITCH; 1970 1982 break; 1971 - case 11: /* set bell duration in msec */ 1983 + case CSI_RSB_BELL_DURATION: 1972 1984 if (vc->vc_npar >= 1) 1973 1985 vc->vc_bell_duration = (vc->vc_par[1] < 2000) ? 1974 1986 msecs_to_jiffies(vc->vc_par[1]) : 0; 1975 1987 else 1976 1988 vc->vc_bell_duration = DEFAULT_BELL_DURATION; 1977 1989 break; 1978 - case 12: /* bring specified console to the front */ 1990 + case CSI_RSB_BRING_CONSOLE_TO_FRONT: 1979 1991 if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1)) 1980 1992 set_console(vc->vc_par[1] - 1); 1981 1993 break; 1982 - case 13: /* unblank the screen */ 1994 + case CSI_RSB_UNBLANK: 1983 1995 poke_blanked_console(); 1984 1996 break; 1985 - case 14: /* set vesa powerdown interval */ 1997 + case CSI_RSB_VESA_OFF_INTERVAL: 1986 1998 vesa_off_interval = min(vc->vc_par[1], 60U) * 60 * HZ; 1987 1999 break; 1988 - case 15: /* activate the previous console */ 2000 + case CSI_RSB_BRING_PREV_CONSOLE_TO_FRONT: 1989 2001 set_console(last_console); 1990 2002 break; 1991 - case 16: /* set cursor blink duration in msec */ 2003 + case CSI_RSB_CURSOR_BLINK_INTERVAL: 1992 2004 if (vc->vc_npar >= 1 && vc->vc_par[1] >= 50 && 1993 2005 vc->vc_par[1] <= USHRT_MAX) 1994 2006 vc->vc_cur_blink_ms = vc->vc_par[1]; ··· 2043 1971 /* console_lock is held */ 2044 1972 static void csi_at(struct vc_data *vc, unsigned int nr) 2045 1973 { 2046 - if (nr > vc->vc_cols - vc->state.x) 2047 - nr = vc->vc_cols - vc->state.x; 2048 - else if (!nr) 2049 - nr = 1; 1974 + nr = clamp(nr, 1, vc->vc_cols - vc->state.x); 2050 1975 insert_char(vc, nr); 2051 1976 } 2052 1977 2053 1978 /* console_lock is held */ 2054 - static void csi_L(struct vc_data *vc, unsigned int nr) 1979 + static void csi_L(struct vc_data *vc) 2055 1980 { 2056 - if (nr > vc->vc_rows - vc->state.y) 2057 - nr = vc->vc_rows - vc->state.y; 2058 - else if (!nr) 2059 - nr = 1; 1981 + unsigned int nr = clamp(vc->vc_par[0], 1, vc->vc_rows - vc->state.y); 1982 + 2060 1983 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_DOWN, nr); 2061 1984 vc->vc_need_wrap = 0; 2062 1985 } 2063 1986 2064 1987 /* console_lock is held */ 2065 - static void csi_P(struct vc_data *vc, unsigned int nr) 1988 + static void csi_P(struct vc_data *vc) 2066 1989 { 2067 - if (nr > vc->vc_cols - vc->state.x) 2068 - nr = vc->vc_cols - vc->state.x; 2069 - else if (!nr) 2070 - nr = 1; 1990 + unsigned int nr = clamp(vc->vc_par[0], 1, vc->vc_cols - vc->state.x); 1991 + 2071 1992 delete_char(vc, nr); 2072 1993 } 2073 1994 2074 1995 /* console_lock is held */ 2075 - static void csi_M(struct vc_data *vc, unsigned int nr) 1996 + static void csi_M(struct vc_data *vc) 2076 1997 { 2077 - if (nr > vc->vc_rows - vc->state.y) 2078 - nr = vc->vc_rows - vc->state.y; 2079 - else if (!nr) 2080 - nr=1; 1998 + unsigned int nr = clamp(vc->vc_par[0], 1, vc->vc_rows - vc->state.y); 1999 + 2081 2000 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_UP, nr); 2082 2001 vc->vc_need_wrap = 0; 2083 2002 } ··· 2091 2028 vc->vc_need_wrap = 0; 2092 2029 } 2093 2030 2094 - enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey, 2095 - EShash, ESsetG0, ESsetG1, ESpercent, EScsiignore, ESnonstd, 2096 - ESpalette, ESosc, ESapc, ESpm, ESdcs }; 2031 + /** 2032 + * enum vc_ctl_state - control characters state of a vt 2033 + * 2034 + * @ESnormal: initial state, no control characters parsed 2035 + * @ESesc: ESC parsed 2036 + * @ESsquare: CSI parsed -- modifiers/parameters/ctrl chars expected 2037 + * @ESgetpars: CSI parsed -- parameters/ctrl chars expected 2038 + * @ESfunckey: CSI [ parsed 2039 + * @EShash: ESC # parsed 2040 + * @ESsetG0: ESC ( parsed 2041 + * @ESsetG1: ESC ) parsed 2042 + * @ESpercent: ESC % parsed 2043 + * @EScsiignore: CSI [0x20-0x3f] parsed 2044 + * @ESnonstd: OSC parsed 2045 + * @ESpalette: OSC P parsed 2046 + * @ESosc: OSC [0-9] parsed 2047 + * @ESANSI_first: first state for ignoring ansi control sequences 2048 + * @ESapc: ESC _ parsed 2049 + * @ESpm: ESC ^ parsed 2050 + * @ESdcs: ESC P parsed 2051 + * @ESANSI_last: last state for ignoring ansi control sequences 2052 + */ 2053 + enum vc_ctl_state { 2054 + ESnormal, 2055 + ESesc, 2056 + ESsquare, 2057 + ESgetpars, 2058 + ESfunckey, 2059 + EShash, 2060 + ESsetG0, 2061 + ESsetG1, 2062 + ESpercent, 2063 + EScsiignore, 2064 + ESnonstd, 2065 + ESpalette, 2066 + ESosc, 2067 + ESANSI_first = ESosc, 2068 + ESapc, 2069 + ESpm, 2070 + ESdcs, 2071 + ESANSI_last = ESdcs, 2072 + }; 2097 2073 2098 2074 /* console_lock is held (except via vc_init()) */ 2099 2075 static void reset_terminal(struct vc_data *vc, int do_clear) ··· 2180 2078 gotoxy(vc, 0, 0); 2181 2079 save_cur(vc); 2182 2080 if (do_clear) 2183 - csi_J(vc, 2); 2081 + csi_J(vc, CSI_J_VISIBLE); 2184 2082 } 2185 2083 2186 - static void vc_setGx(struct vc_data *vc, unsigned int which, int c) 2084 + static void vc_setGx(struct vc_data *vc, unsigned int which, u8 c) 2187 2085 { 2188 2086 unsigned char *charset = &vc->state.Gx_charset[which]; 2189 2087 ··· 2206 2104 vc->vc_translate = set_translate(*charset, vc); 2207 2105 } 2208 2106 2209 - /* is this state an ANSI control string? */ 2210 - static bool ansi_control_string(unsigned int state) 2107 + static bool ansi_control_string(enum vc_ctl_state state) 2211 2108 { 2212 - if (state == ESosc || state == ESapc || state == ESpm || state == ESdcs) 2213 - return true; 2214 - return false; 2109 + return state >= ESANSI_first && state <= ESANSI_last; 2215 2110 } 2216 2111 2217 - /* console_lock is held */ 2218 - static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) 2112 + enum { 2113 + ASCII_NULL = 0, 2114 + ASCII_BELL = 7, 2115 + ASCII_BACKSPACE = 8, 2116 + ASCII_IGNORE_FIRST = ASCII_BACKSPACE, 2117 + ASCII_HTAB = 9, 2118 + ASCII_LINEFEED = 10, 2119 + ASCII_VTAB = 11, 2120 + ASCII_FORMFEED = 12, 2121 + ASCII_CAR_RET = 13, 2122 + ASCII_IGNORE_LAST = ASCII_CAR_RET, 2123 + ASCII_SHIFTOUT = 14, 2124 + ASCII_SHIFTIN = 15, 2125 + ASCII_CANCEL = 24, 2126 + ASCII_SUBSTITUTE = 26, 2127 + ASCII_ESCAPE = 27, 2128 + ASCII_CSI_IGNORE_FIRST = ' ', /* 0x2x, 0x3a and 0x3c - 0x3f */ 2129 + ASCII_CSI_IGNORE_LAST = '?', 2130 + ASCII_DEL = 127, 2131 + ASCII_EXT_CSI = 128 + ASCII_ESCAPE, 2132 + }; 2133 + 2134 + /* 2135 + * Handle ascii characters in control sequences and change states accordingly. 2136 + * E.g. ESC sets the state of vc to ESesc. 2137 + * 2138 + * Returns: true if @c handled. 2139 + */ 2140 + static bool handle_ascii(struct tty_struct *tty, struct vc_data *vc, u8 c) 2219 2141 { 2220 - /* 2221 - * Control characters can be used in the _middle_ 2222 - * of an escape sequence, aside from ANSI control strings. 2223 - */ 2224 - if (ansi_control_string(vc->vc_state) && c >= 8 && c <= 13) 2225 - return; 2226 2142 switch (c) { 2227 - case 0: 2228 - return; 2229 - case 7: 2143 + case ASCII_NULL: 2144 + return true; 2145 + case ASCII_BELL: 2230 2146 if (ansi_control_string(vc->vc_state)) 2231 2147 vc->vc_state = ESnormal; 2232 2148 else if (vc->vc_bell_duration) 2233 2149 kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration); 2234 - return; 2235 - case 8: 2150 + return true; 2151 + case ASCII_BACKSPACE: 2236 2152 bs(vc); 2237 - return; 2238 - case 9: 2153 + return true; 2154 + case ASCII_HTAB: 2239 2155 vc->vc_pos -= (vc->state.x << 1); 2240 2156 2241 2157 vc->state.x = find_next_bit(vc->vc_tab_stop, ··· 2264 2144 2265 2145 vc->vc_pos += (vc->state.x << 1); 2266 2146 notify_write(vc, '\t'); 2267 - return; 2268 - case 10: case 11: case 12: 2147 + return true; 2148 + case ASCII_LINEFEED: 2149 + case ASCII_VTAB: 2150 + case ASCII_FORMFEED: 2269 2151 lf(vc); 2270 2152 if (!is_kbd(vc, lnm)) 2271 - return; 2153 + return true; 2272 2154 fallthrough; 2273 - case 13: 2155 + case ASCII_CAR_RET: 2274 2156 cr(vc); 2275 - return; 2276 - case 14: 2157 + return true; 2158 + case ASCII_SHIFTOUT: 2277 2159 vc->state.charset = 1; 2278 2160 vc->vc_translate = set_translate(vc->state.Gx_charset[1], vc); 2279 2161 vc->vc_disp_ctrl = 1; 2280 - return; 2281 - case 15: 2162 + return true; 2163 + case ASCII_SHIFTIN: 2282 2164 vc->state.charset = 0; 2283 2165 vc->vc_translate = set_translate(vc->state.Gx_charset[0], vc); 2284 2166 vc->vc_disp_ctrl = 0; 2285 - return; 2286 - case 24: case 26: 2167 + return true; 2168 + case ASCII_CANCEL: 2169 + case ASCII_SUBSTITUTE: 2287 2170 vc->vc_state = ESnormal; 2288 - return; 2289 - case 27: 2171 + return true; 2172 + case ASCII_ESCAPE: 2290 2173 vc->vc_state = ESesc; 2291 - return; 2292 - case 127: 2174 + return true; 2175 + case ASCII_DEL: 2293 2176 del(vc); 2294 - return; 2295 - case 128+27: 2177 + return true; 2178 + case ASCII_EXT_CSI: 2296 2179 vc->vc_state = ESsquare; 2297 - return; 2180 + return true; 2298 2181 } 2299 - switch(vc->vc_state) { 2300 - case ESesc: 2301 - vc->vc_state = ESnormal; 2302 - switch (c) { 2303 - case '[': 2304 - vc->vc_state = ESsquare; 2305 - return; 2306 - case ']': 2307 - vc->vc_state = ESnonstd; 2308 - return; 2309 - case '_': 2310 - vc->vc_state = ESapc; 2311 - return; 2312 - case '^': 2313 - vc->vc_state = ESpm; 2314 - return; 2315 - case '%': 2316 - vc->vc_state = ESpercent; 2317 - return; 2318 - case 'E': 2319 - cr(vc); 2320 - lf(vc); 2321 - return; 2322 - case 'M': 2323 - ri(vc); 2324 - return; 2325 - case 'D': 2326 - lf(vc); 2327 - return; 2328 - case 'H': 2329 - if (vc->state.x < VC_TABSTOPS_COUNT) 2330 - set_bit(vc->state.x, vc->vc_tab_stop); 2331 - return; 2332 - case 'P': 2333 - vc->vc_state = ESdcs; 2334 - return; 2335 - case 'Z': 2182 + 2183 + return false; 2184 + } 2185 + 2186 + /* 2187 + * Handle a character (@c) following an ESC (when @vc is in the ESesc state). 2188 + * E.g. previous ESC with @c == '[' here yields the ESsquare state (that is: 2189 + * CSI). 2190 + */ 2191 + static void handle_esc(struct tty_struct *tty, struct vc_data *vc, u8 c) 2192 + { 2193 + vc->vc_state = ESnormal; 2194 + switch (c) { 2195 + case '[': 2196 + vc->vc_state = ESsquare; 2197 + break; 2198 + case ']': 2199 + vc->vc_state = ESnonstd; 2200 + break; 2201 + case '_': 2202 + vc->vc_state = ESapc; 2203 + break; 2204 + case '^': 2205 + vc->vc_state = ESpm; 2206 + break; 2207 + case '%': 2208 + vc->vc_state = ESpercent; 2209 + break; 2210 + case 'E': 2211 + cr(vc); 2212 + lf(vc); 2213 + break; 2214 + case 'M': 2215 + ri(vc); 2216 + break; 2217 + case 'D': 2218 + lf(vc); 2219 + break; 2220 + case 'H': 2221 + if (vc->state.x < VC_TABSTOPS_COUNT) 2222 + set_bit(vc->state.x, vc->vc_tab_stop); 2223 + break; 2224 + case 'P': 2225 + vc->vc_state = ESdcs; 2226 + break; 2227 + case 'Z': 2228 + respond_ID(tty); 2229 + break; 2230 + case '7': 2231 + save_cur(vc); 2232 + break; 2233 + case '8': 2234 + restore_cur(vc); 2235 + break; 2236 + case '(': 2237 + vc->vc_state = ESsetG0; 2238 + break; 2239 + case ')': 2240 + vc->vc_state = ESsetG1; 2241 + break; 2242 + case '#': 2243 + vc->vc_state = EShash; 2244 + break; 2245 + case 'c': 2246 + reset_terminal(vc, 1); 2247 + break; 2248 + case '>': /* Numeric keypad */ 2249 + clr_kbd(vc, kbdapplic); 2250 + break; 2251 + case '=': /* Appl. keypad */ 2252 + set_kbd(vc, kbdapplic); 2253 + break; 2254 + } 2255 + } 2256 + 2257 + /* 2258 + * Handle special DEC control sequences ("ESC [ ? parameters char"). Parameters 2259 + * are in @vc->vc_par and the char is in @c here. 2260 + */ 2261 + static void csi_DEC(struct tty_struct *tty, struct vc_data *vc, u8 c) 2262 + { 2263 + switch (c) { 2264 + case 'h': 2265 + csi_DEC_hl(vc, true); 2266 + break; 2267 + case 'l': 2268 + csi_DEC_hl(vc, false); 2269 + break; 2270 + case 'c': 2271 + if (vc->vc_par[0]) 2272 + vc->vc_cursor_type = CUR_MAKE(vc->vc_par[0], 2273 + vc->vc_par[1], 2274 + vc->vc_par[2]); 2275 + else 2276 + vc->vc_cursor_type = cur_default; 2277 + break; 2278 + case 'm': 2279 + clear_selection(); 2280 + if (vc->vc_par[0]) 2281 + vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1]; 2282 + else 2283 + vc->vc_complement_mask = vc->vc_s_complement_mask; 2284 + break; 2285 + case 'n': 2286 + if (vc->vc_par[0] == 5) 2287 + status_report(tty); 2288 + else if (vc->vc_par[0] == 6) 2289 + cursor_report(vc, tty); 2290 + break; 2291 + } 2292 + } 2293 + 2294 + /* 2295 + * Handle Control Sequence Introducer control characters. That is 2296 + * "ESC [ parameters char". Parameters are in @vc->vc_par and the char is in 2297 + * @c here. 2298 + */ 2299 + static void csi_ECMA(struct tty_struct *tty, struct vc_data *vc, u8 c) 2300 + { 2301 + switch (c) { 2302 + case 'G': 2303 + case '`': 2304 + if (vc->vc_par[0]) 2305 + vc->vc_par[0]--; 2306 + gotoxy(vc, vc->vc_par[0], vc->state.y); 2307 + break; 2308 + case 'A': 2309 + if (!vc->vc_par[0]) 2310 + vc->vc_par[0]++; 2311 + gotoxy(vc, vc->state.x, vc->state.y - vc->vc_par[0]); 2312 + break; 2313 + case 'B': 2314 + case 'e': 2315 + if (!vc->vc_par[0]) 2316 + vc->vc_par[0]++; 2317 + gotoxy(vc, vc->state.x, vc->state.y + vc->vc_par[0]); 2318 + break; 2319 + case 'C': 2320 + case 'a': 2321 + if (!vc->vc_par[0]) 2322 + vc->vc_par[0]++; 2323 + gotoxy(vc, vc->state.x + vc->vc_par[0], vc->state.y); 2324 + break; 2325 + case 'D': 2326 + if (!vc->vc_par[0]) 2327 + vc->vc_par[0]++; 2328 + gotoxy(vc, vc->state.x - vc->vc_par[0], vc->state.y); 2329 + break; 2330 + case 'E': 2331 + if (!vc->vc_par[0]) 2332 + vc->vc_par[0]++; 2333 + gotoxy(vc, 0, vc->state.y + vc->vc_par[0]); 2334 + break; 2335 + case 'F': 2336 + if (!vc->vc_par[0]) 2337 + vc->vc_par[0]++; 2338 + gotoxy(vc, 0, vc->state.y - vc->vc_par[0]); 2339 + break; 2340 + case 'd': 2341 + if (vc->vc_par[0]) 2342 + vc->vc_par[0]--; 2343 + gotoxay(vc, vc->state.x ,vc->vc_par[0]); 2344 + break; 2345 + case 'H': 2346 + case 'f': 2347 + if (vc->vc_par[0]) 2348 + vc->vc_par[0]--; 2349 + if (vc->vc_par[1]) 2350 + vc->vc_par[1]--; 2351 + gotoxay(vc, vc->vc_par[1], vc->vc_par[0]); 2352 + break; 2353 + case 'J': 2354 + csi_J(vc, vc->vc_par[0]); 2355 + break; 2356 + case 'K': 2357 + csi_K(vc); 2358 + break; 2359 + case 'L': 2360 + csi_L(vc); 2361 + break; 2362 + case 'M': 2363 + csi_M(vc); 2364 + break; 2365 + case 'P': 2366 + csi_P(vc); 2367 + break; 2368 + case 'c': 2369 + if (!vc->vc_par[0]) 2336 2370 respond_ID(tty); 2337 - return; 2338 - case '7': 2339 - save_cur(vc); 2340 - return; 2341 - case '8': 2342 - restore_cur(vc); 2343 - return; 2344 - case '(': 2345 - vc->vc_state = ESsetG0; 2346 - return; 2347 - case ')': 2348 - vc->vc_state = ESsetG1; 2349 - return; 2350 - case '#': 2351 - vc->vc_state = EShash; 2352 - return; 2353 - case 'c': 2354 - reset_terminal(vc, 1); 2355 - return; 2356 - case '>': /* Numeric keypad */ 2357 - clr_kbd(vc, kbdapplic); 2358 - return; 2359 - case '=': /* Appl. keypad */ 2360 - set_kbd(vc, kbdapplic); 2361 - return; 2371 + break; 2372 + case 'g': 2373 + if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT) 2374 + set_bit(vc->state.x, vc->vc_tab_stop); 2375 + else if (vc->vc_par[0] == 3) 2376 + bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT); 2377 + break; 2378 + case 'h': 2379 + csi_hl(vc, true); 2380 + break; 2381 + case 'l': 2382 + csi_hl(vc, false); 2383 + break; 2384 + case 'm': 2385 + csi_m(vc); 2386 + break; 2387 + case 'n': 2388 + if (vc->vc_par[0] == 5) 2389 + status_report(tty); 2390 + else if (vc->vc_par[0] == 6) 2391 + cursor_report(vc, tty); 2392 + break; 2393 + case 'q': /* DECLL - but only 3 leds */ 2394 + /* map 0,1,2,3 to 0,1,2,4 */ 2395 + if (vc->vc_par[0] < 4) 2396 + vt_set_led_state(vc->vc_num, 2397 + (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4); 2398 + break; 2399 + case 'r': 2400 + if (!vc->vc_par[0]) 2401 + vc->vc_par[0]++; 2402 + if (!vc->vc_par[1]) 2403 + vc->vc_par[1] = vc->vc_rows; 2404 + /* Minimum allowed region is 2 lines */ 2405 + if (vc->vc_par[0] < vc->vc_par[1] && 2406 + vc->vc_par[1] <= vc->vc_rows) { 2407 + vc->vc_top = vc->vc_par[0] - 1; 2408 + vc->vc_bottom = vc->vc_par[1]; 2409 + gotoxay(vc, 0, 0); 2362 2410 } 2411 + break; 2412 + case 's': 2413 + save_cur(vc); 2414 + break; 2415 + case 'u': 2416 + restore_cur(vc); 2417 + break; 2418 + case 'X': 2419 + csi_X(vc); 2420 + break; 2421 + case '@': 2422 + csi_at(vc, vc->vc_par[0]); 2423 + break; 2424 + case ']': 2425 + csi_RSB(vc); 2426 + break; 2427 + } 2428 + 2429 + } 2430 + 2431 + static void vc_reset_params(struct vc_data *vc) 2432 + { 2433 + memset(vc->vc_par, 0, sizeof(vc->vc_par)); 2434 + vc->vc_npar = 0; 2435 + } 2436 + 2437 + /* console_lock is held */ 2438 + static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c) 2439 + { 2440 + /* 2441 + * Control characters can be used in the _middle_ 2442 + * of an escape sequence, aside from ANSI control strings. 2443 + */ 2444 + if (ansi_control_string(vc->vc_state) && c >= ASCII_IGNORE_FIRST && 2445 + c <= ASCII_IGNORE_LAST) 2363 2446 return; 2364 - case ESnonstd: 2365 - if (c=='P') { /* palette escape sequence */ 2366 - for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++) 2367 - vc->vc_par[vc->vc_npar] = 0; 2368 - vc->vc_npar = 0; 2447 + 2448 + if (handle_ascii(tty, vc, c)) 2449 + return; 2450 + 2451 + switch(vc->vc_state) { 2452 + case ESesc: /* ESC */ 2453 + handle_esc(tty, vc, c); 2454 + return; 2455 + case ESnonstd: /* ESC ] aka OSC */ 2456 + switch (c) { 2457 + case 'P': /* palette escape sequence */ 2458 + vc_reset_params(vc); 2369 2459 vc->vc_state = ESpalette; 2370 2460 return; 2371 - } else if (c=='R') { /* reset palette */ 2461 + case 'R': /* reset palette */ 2372 2462 reset_palette(vc); 2373 - vc->vc_state = ESnormal; 2374 - } else if (c>='0' && c<='9') 2463 + break; 2464 + case '0' ... '9': 2375 2465 vc->vc_state = ESosc; 2376 - else 2377 - vc->vc_state = ESnormal; 2466 + return; 2467 + } 2468 + vc->vc_state = ESnormal; 2378 2469 return; 2379 - case ESpalette: 2470 + case ESpalette: /* ESC ] P aka OSC P */ 2380 2471 if (isxdigit(c)) { 2381 2472 vc->vc_par[vc->vc_npar++] = hex_to_bin(c); 2382 2473 if (vc->vc_npar == 7) { ··· 2604 2273 } else 2605 2274 vc->vc_state = ESnormal; 2606 2275 return; 2607 - case ESsquare: 2608 - for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++) 2609 - vc->vc_par[vc->vc_npar] = 0; 2610 - vc->vc_npar = 0; 2276 + case ESsquare: /* ESC [ aka CSI, parameters or modifiers expected */ 2277 + vc_reset_params(vc); 2278 + 2611 2279 vc->vc_state = ESgetpars; 2612 - if (c == '[') { /* Function key */ 2613 - vc->vc_state=ESfunckey; 2614 - return; 2615 - } 2616 2280 switch (c) { 2281 + case '[': /* Function key */ 2282 + vc->vc_state = ESfunckey; 2283 + return; 2617 2284 case '?': 2618 2285 vc->vc_priv = EPdec; 2619 2286 return; ··· 2627 2298 } 2628 2299 vc->vc_priv = EPecma; 2629 2300 fallthrough; 2630 - case ESgetpars: 2631 - if (c == ';' && vc->vc_npar < NPAR - 1) { 2632 - vc->vc_npar++; 2633 - return; 2634 - } else if (c>='0' && c<='9') { 2301 + case ESgetpars: /* ESC [ aka CSI, parameters expected */ 2302 + switch (c) { 2303 + case ';': 2304 + if (vc->vc_npar < NPAR - 1) { 2305 + vc->vc_npar++; 2306 + return; 2307 + } 2308 + break; 2309 + case '0' ... '9': 2635 2310 vc->vc_par[vc->vc_npar] *= 10; 2636 2311 vc->vc_par[vc->vc_npar] += c - '0'; 2637 2312 return; 2638 2313 } 2639 - if (c >= 0x20 && c <= 0x3f) { /* 0x2x, 0x3a and 0x3c - 0x3f */ 2314 + if (c >= ASCII_CSI_IGNORE_FIRST && c <= ASCII_CSI_IGNORE_LAST) { 2640 2315 vc->vc_state = EScsiignore; 2641 2316 return; 2642 2317 } 2318 + 2319 + /* parameters done, handle the control char @c */ 2320 + 2643 2321 vc->vc_state = ESnormal; 2644 - switch(c) { 2645 - case 'h': 2646 - if (vc->vc_priv <= EPdec) 2647 - set_mode(vc, 1); 2322 + 2323 + switch (vc->vc_priv) { 2324 + case EPdec: 2325 + csi_DEC(tty, vc, c); 2648 2326 return; 2649 - case 'l': 2650 - if (vc->vc_priv <= EPdec) 2651 - set_mode(vc, 0); 2327 + case EPecma: 2328 + csi_ECMA(tty, vc, c); 2652 2329 return; 2653 - case 'c': 2654 - if (vc->vc_priv == EPdec) { 2655 - if (vc->vc_par[0]) 2656 - vc->vc_cursor_type = 2657 - CUR_MAKE(vc->vc_par[0], 2658 - vc->vc_par[1], 2659 - vc->vc_par[2]); 2660 - else 2661 - vc->vc_cursor_type = cur_default; 2662 - return; 2663 - } 2664 - break; 2665 - case 'm': 2666 - if (vc->vc_priv == EPdec) { 2667 - clear_selection(); 2668 - if (vc->vc_par[0]) 2669 - vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1]; 2670 - else 2671 - vc->vc_complement_mask = vc->vc_s_complement_mask; 2672 - return; 2673 - } 2674 - break; 2675 - case 'n': 2676 - if (vc->vc_priv == EPecma) { 2677 - if (vc->vc_par[0] == 5) 2678 - status_report(tty); 2679 - else if (vc->vc_par[0] == 6) 2680 - cursor_report(vc, tty); 2681 - } 2330 + default: 2682 2331 return; 2683 2332 } 2684 - if (vc->vc_priv != EPecma) { 2685 - vc->vc_priv = EPecma; 2686 - return; 2687 - } 2688 - switch(c) { 2689 - case 'G': case '`': 2690 - if (vc->vc_par[0]) 2691 - vc->vc_par[0]--; 2692 - gotoxy(vc, vc->vc_par[0], vc->state.y); 2693 - return; 2694 - case 'A': 2695 - if (!vc->vc_par[0]) 2696 - vc->vc_par[0]++; 2697 - gotoxy(vc, vc->state.x, vc->state.y - vc->vc_par[0]); 2698 - return; 2699 - case 'B': case 'e': 2700 - if (!vc->vc_par[0]) 2701 - vc->vc_par[0]++; 2702 - gotoxy(vc, vc->state.x, vc->state.y + vc->vc_par[0]); 2703 - return; 2704 - case 'C': case 'a': 2705 - if (!vc->vc_par[0]) 2706 - vc->vc_par[0]++; 2707 - gotoxy(vc, vc->state.x + vc->vc_par[0], vc->state.y); 2708 - return; 2709 - case 'D': 2710 - if (!vc->vc_par[0]) 2711 - vc->vc_par[0]++; 2712 - gotoxy(vc, vc->state.x - vc->vc_par[0], vc->state.y); 2713 - return; 2714 - case 'E': 2715 - if (!vc->vc_par[0]) 2716 - vc->vc_par[0]++; 2717 - gotoxy(vc, 0, vc->state.y + vc->vc_par[0]); 2718 - return; 2719 - case 'F': 2720 - if (!vc->vc_par[0]) 2721 - vc->vc_par[0]++; 2722 - gotoxy(vc, 0, vc->state.y - vc->vc_par[0]); 2723 - return; 2724 - case 'd': 2725 - if (vc->vc_par[0]) 2726 - vc->vc_par[0]--; 2727 - gotoxay(vc, vc->state.x ,vc->vc_par[0]); 2728 - return; 2729 - case 'H': case 'f': 2730 - if (vc->vc_par[0]) 2731 - vc->vc_par[0]--; 2732 - if (vc->vc_par[1]) 2733 - vc->vc_par[1]--; 2734 - gotoxay(vc, vc->vc_par[1], vc->vc_par[0]); 2735 - return; 2736 - case 'J': 2737 - csi_J(vc, vc->vc_par[0]); 2738 - return; 2739 - case 'K': 2740 - csi_K(vc, vc->vc_par[0]); 2741 - return; 2742 - case 'L': 2743 - csi_L(vc, vc->vc_par[0]); 2744 - return; 2745 - case 'M': 2746 - csi_M(vc, vc->vc_par[0]); 2747 - return; 2748 - case 'P': 2749 - csi_P(vc, vc->vc_par[0]); 2750 - return; 2751 - case 'c': 2752 - if (!vc->vc_par[0]) 2753 - respond_ID(tty); 2754 - return; 2755 - case 'g': 2756 - if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT) 2757 - set_bit(vc->state.x, vc->vc_tab_stop); 2758 - else if (vc->vc_par[0] == 3) 2759 - bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT); 2760 - return; 2761 - case 'm': 2762 - csi_m(vc); 2763 - return; 2764 - case 'q': /* DECLL - but only 3 leds */ 2765 - /* map 0,1,2,3 to 0,1,2,4 */ 2766 - if (vc->vc_par[0] < 4) 2767 - vt_set_led_state(vc->vc_num, 2768 - (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4); 2769 - return; 2770 - case 'r': 2771 - if (!vc->vc_par[0]) 2772 - vc->vc_par[0]++; 2773 - if (!vc->vc_par[1]) 2774 - vc->vc_par[1] = vc->vc_rows; 2775 - /* Minimum allowed region is 2 lines */ 2776 - if (vc->vc_par[0] < vc->vc_par[1] && 2777 - vc->vc_par[1] <= vc->vc_rows) { 2778 - vc->vc_top = vc->vc_par[0] - 1; 2779 - vc->vc_bottom = vc->vc_par[1]; 2780 - gotoxay(vc, 0, 0); 2781 - } 2782 - return; 2783 - case 's': 2784 - save_cur(vc); 2785 - return; 2786 - case 'u': 2787 - restore_cur(vc); 2788 - return; 2789 - case 'X': 2790 - csi_X(vc, vc->vc_par[0]); 2791 - return; 2792 - case '@': 2793 - csi_at(vc, vc->vc_par[0]); 2794 - return; 2795 - case ']': /* setterm functions */ 2796 - setterm_command(vc); 2797 - return; 2798 - } 2799 - return; 2800 2333 case EScsiignore: 2801 - if (c >= 20 && c <= 0x3f) 2334 + if (c >= ASCII_CSI_IGNORE_FIRST && c <= ASCII_CSI_IGNORE_LAST) 2802 2335 return; 2803 2336 vc->vc_state = ESnormal; 2804 2337 return; 2805 - case ESpercent: 2338 + case ESpercent: /* ESC % */ 2806 2339 vc->vc_state = ESnormal; 2807 2340 switch (c) { 2808 2341 case '@': /* defined in ISO 2022 */ ··· 2676 2485 return; 2677 2486 } 2678 2487 return; 2679 - case ESfunckey: 2488 + case ESfunckey: /* ESC [ [ aka CSI [ */ 2680 2489 vc->vc_state = ESnormal; 2681 2490 return; 2682 - case EShash: 2491 + case EShash: /* ESC # */ 2683 2492 vc->vc_state = ESnormal; 2684 2493 if (c == '8') { 2685 2494 /* DEC screen alignment test. kludge :-) */ 2686 2495 vc->vc_video_erase_char = 2687 2496 (vc->vc_video_erase_char & 0xff00) | 'E'; 2688 - csi_J(vc, 2); 2497 + csi_J(vc, CSI_J_VISIBLE); 2689 2498 vc->vc_video_erase_char = 2690 2499 (vc->vc_video_erase_char & 0xff00) | ' '; 2691 2500 do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2); 2692 2501 } 2693 2502 return; 2694 - case ESsetG0: 2503 + case ESsetG0: /* ESC ( */ 2695 2504 vc_setGx(vc, 0, c); 2696 2505 vc->vc_state = ESnormal; 2697 2506 return; 2698 - case ESsetG1: 2507 + case ESsetG1: /* ESC ) */ 2699 2508 vc_setGx(vc, 1, c); 2700 2509 vc->vc_state = ESnormal; 2701 2510 return; 2702 - case ESapc: 2511 + case ESapc: /* ESC _ */ 2703 2512 return; 2704 - case ESosc: 2513 + case ESosc: /* ESC ] [0-9] aka OSC [0-9] */ 2705 2514 return; 2706 - case ESpm: 2515 + case ESpm: /* ESC ^ */ 2707 2516 return; 2708 - case ESdcs: 2517 + case ESdcs: /* ESC P */ 2709 2518 return; 2710 2519 default: 2711 2520 vc->vc_state = ESnormal; ··· 2779 2588 2780 2589 2781 2590 /** 2782 - * vc_sanitize_unicode - Replace invalid Unicode code points with U+FFFD 2783 - * @c: the received character, or U+FFFD for invalid sequences. 2591 + * vc_sanitize_unicode - Replace invalid Unicode code points with ``U+FFFD`` 2592 + * @c: the received code point 2784 2593 */ 2785 2594 static inline int vc_sanitize_unicode(const int c) 2786 2595 { 2787 - if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff) 2596 + if (c >= 0xd800 && c <= 0xdfff) 2788 2597 return 0xfffd; 2789 2598 2790 2599 return c; 2791 2600 } 2792 2601 2793 2602 /** 2794 - * vc_translate_unicode - Combine UTF-8 into Unicode in @vc_utf_char 2603 + * vc_translate_unicode - Combine UTF-8 into Unicode in &vc_data.vc_utf_char 2795 2604 * @vc: virtual console 2796 - * @c: character to translate 2797 - * @rescan: we return true if we need more (continuation) data 2605 + * @c: UTF-8 byte to translate 2606 + * @rescan: set to true iff @c wasn't consumed here and needs to be re-processed 2798 2607 * 2799 - * @vc_utf_char is the being-constructed unicode character. 2800 - * @vc_utf_count is the number of continuation bytes still expected to arrive. 2801 - * @vc_npar is the number of continuation bytes arrived so far. 2608 + * * &vc_data.vc_utf_char is the being-constructed Unicode code point. 2609 + * * &vc_data.vc_utf_count is the number of continuation bytes still expected to 2610 + * arrive. 2611 + * * &vc_data.vc_npar is the number of continuation bytes arrived so far. 2612 + * 2613 + * Return: 2614 + * * %-1 - Input OK so far, @c consumed, further bytes expected. 2615 + * * %0xFFFD - Possibility 1: input invalid, @c may have been consumed (see 2616 + * desc. of @rescan). Possibility 2: input OK, @c consumed, 2617 + * ``U+FFFD`` is the resulting code point. ``U+FFFD`` is valid, 2618 + * ``REPLACEMENT CHARACTER``. 2619 + * * otherwise - Input OK, @c consumed, resulting code point returned. 2802 2620 */ 2803 2621 static int vc_translate_unicode(struct vc_data *vc, int c, bool *rescan) 2804 2622 { 2805 - static const u32 utf8_length_changes[] = { 2806 - 0x0000007f, 0x000007ff, 0x0000ffff, 2807 - 0x001fffff, 0x03ffffff, 0x7fffffff 2808 - }; 2623 + static const u32 utf8_length_changes[] = {0x7f, 0x7ff, 0xffff, 0x10ffff}; 2809 2624 2810 2625 /* Continuation byte received */ 2811 2626 if ((c & 0xc0) == 0x80) { ··· 2857 2660 } else if ((c & 0xf8) == 0xf0) { 2858 2661 vc->vc_utf_count = 3; 2859 2662 vc->vc_utf_char = (c & 0x07); 2860 - } else if ((c & 0xfc) == 0xf8) { 2861 - vc->vc_utf_count = 4; 2862 - vc->vc_utf_char = (c & 0x03); 2863 - } else if ((c & 0xfe) == 0xfc) { 2864 - vc->vc_utf_count = 5; 2865 - vc->vc_utf_char = (c & 0x01); 2866 2663 } else { 2867 - /* 254 and 255 are invalid */ 2868 2664 return 0xfffd; 2869 2665 } 2870 2666 ··· 2901 2711 * as cursor movement) and should not be displayed as a glyph unless 2902 2712 * the disp_ctrl mode is explicitly enabled. 2903 2713 */ 2904 - static const u32 CTRL_ACTION = 0x0d00ff81; 2714 + static const u32 CTRL_ACTION = BIT(ASCII_NULL) | 2715 + GENMASK(ASCII_SHIFTIN, ASCII_BELL) | BIT(ASCII_CANCEL) | 2716 + BIT(ASCII_SUBSTITUTE) | BIT(ASCII_ESCAPE); 2905 2717 /* Cannot be overridden by disp_ctrl */ 2906 - static const u32 CTRL_ALWAYS = 0x0800f501; 2718 + static const u32 CTRL_ALWAYS = BIT(ASCII_NULL) | BIT(ASCII_BACKSPACE) | 2719 + BIT(ASCII_LINEFEED) | BIT(ASCII_SHIFTIN) | BIT(ASCII_SHIFTOUT) | 2720 + BIT(ASCII_CAR_RET) | BIT(ASCII_FORMFEED) | BIT(ASCII_ESCAPE); 2907 2721 2908 2722 if (vc->vc_state != ESnormal) 2909 2723 return true; ··· 2924 2730 * useless without them; to display an arbitrary font position use the 2925 2731 * direct-to-font zone in UTF-8 mode. 2926 2732 */ 2927 - if (c < 32) { 2733 + if (c < BITS_PER_TYPE(CTRL_ALWAYS)) { 2928 2734 if (vc->vc_disp_ctrl) 2929 2735 return CTRL_ALWAYS & BIT(c); 2930 2736 else 2931 2737 return vc->vc_utf || (CTRL_ACTION & BIT(c)); 2932 2738 } 2933 2739 2934 - if (c == 127 && !vc->vc_disp_ctrl) 2740 + if (c == ASCII_DEL && !vc->vc_disp_ctrl) 2935 2741 return true; 2936 2742 2937 - if (c == 128 + 27) 2743 + if (c == ASCII_EXT_CSI) 2938 2744 return true; 2939 2745 2940 2746 return false; ··· 3046 2852 }; 3047 2853 int c, tc, n = 0; 3048 2854 unsigned int currcons; 3049 - struct vc_data *vc; 2855 + struct vc_data *vc = tty->driver_data; 3050 2856 struct vt_notifier_param param; 3051 2857 bool rescan; 3052 2858 ··· 3054 2860 return count; 3055 2861 3056 2862 console_lock(); 3057 - vc = tty->driver_data; 3058 - if (vc == NULL) { 3059 - pr_err("vt: argh, driver_data is NULL !\n"); 3060 - console_unlock(); 3061 - return 0; 3062 - } 3063 - 3064 2863 currcons = vc->vc_num; 3065 2864 if (!vc_cons_allocated(currcons)) { 3066 2865 /* could this happen? */ ··· 3070 2883 param.vc = vc; 3071 2884 3072 2885 while (!tty->flow.stopped && count) { 3073 - int orig = *buf; 2886 + u8 orig = *buf; 3074 2887 buf++; 3075 2888 n++; 3076 2889 count--; ··· 3179 2992 #ifdef CONFIG_VT_CONSOLE 3180 2993 3181 2994 /** 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 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 3185 2998 * 3186 2999 * By default, the kernel messages are always printed on the current virtual 3187 3000 * console. However, the user may modify that default with the 3188 - * TIOCL_SETKMSGREDIRECT ioctl call. 3001 + * %TIOCL_SETKMSGREDIRECT ioctl call. 3189 3002 * 3190 3003 * This function sets the kernel message console to be @new. It returns the old 3191 - * virtual console number. The virtual terminal number 0 (both as parameter and 3004 + * virtual console number. The virtual terminal number %0 (both as parameter and 3192 3005 * return value) means no redirection (i.e. always printed on the currently 3193 3006 * active console). 3194 3007 * ··· 3196 3009 * value is not modified. You may use the macro vt_get_kmsg_redirect() in that 3197 3010 * case to make the code more understandable. 3198 3011 * 3199 - * When the kernel is compiled without CONFIG_VT_CONSOLE, this function ignores 3200 - * the parameter and always returns 0. 3012 + * When the kernel is compiled without %CONFIG_VT_CONSOLE, this function ignores 3013 + * the parameter and always returns %0. 3201 3014 */ 3202 3015 int vt_kmsg_redirect(int new) 3203 3016 { ··· 3252 3065 cnt = 0; 3253 3066 while (count--) { 3254 3067 c = *b++; 3255 - if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) { 3068 + if (c == ASCII_LINEFEED || c == ASCII_CAR_RET || 3069 + c == ASCII_BACKSPACE || vc->vc_need_wrap) { 3256 3070 if (cnt && con_is_visible(vc)) 3257 3071 vc->vc_sw->con_putcs(vc, start, cnt, vc->state.y, start_x); 3258 3072 cnt = 0; 3259 - if (c == 8) { /* backspace */ 3073 + if (c == ASCII_BACKSPACE) { 3260 3074 bs(vc); 3261 3075 start = (ushort *)vc->vc_pos; 3262 3076 start_x = vc->state.x; 3263 3077 continue; 3264 3078 } 3265 - if (c != 13) 3079 + if (c != ASCII_CAR_RET) 3266 3080 lf(vc); 3267 3081 cr(vc); 3268 3082 start = (ushort *)vc->vc_pos; 3269 3083 start_x = vc->state.x; 3270 - if (c == 10 || c == 13) 3084 + if (c == ASCII_LINEFEED || c == ASCII_CAR_RET) 3271 3085 continue; 3272 3086 } 3273 3087 vc_uniscr_putc(vc, c); ··· 3332 3144 { 3333 3145 char type, data; 3334 3146 char __user *p = (char __user *)arg; 3147 + void __user *param_aligned32 = (u32 __user *)arg + 1; 3148 + void __user *param = (void __user *)arg + 1; 3335 3149 int lines; 3336 3150 int ret; 3337 3151 ··· 3347 3157 case TIOCL_SETSEL: 3348 3158 if (!capable(CAP_SYS_ADMIN)) 3349 3159 return -EPERM; 3350 - return set_selection_user((struct tiocl_selection 3351 - __user *)(p+1), tty); 3160 + return set_selection_user(param, tty); 3352 3161 case TIOCL_PASTESEL: 3353 3162 if (!capable(CAP_SYS_ADMIN)) 3354 3163 return -EPERM; ··· 3360 3171 case TIOCL_SELLOADLUT: 3361 3172 if (!capable(CAP_SYS_ADMIN)) 3362 3173 return -EPERM; 3363 - console_lock(); 3364 - ret = sel_loadlut(p); 3365 - console_unlock(); 3366 - break; 3174 + return sel_loadlut(param_aligned32); 3367 3175 case TIOCL_GETSHIFTSTATE: 3368 3176 /* 3369 3177 * Make it possible to react to Shift+Mousebutton. Note that ··· 3376 3190 console_unlock(); 3377 3191 return put_user(data, p); 3378 3192 case TIOCL_SETVESABLANK: 3379 - console_lock(); 3380 - ret = set_vesa_blanking(p); 3381 - console_unlock(); 3382 - break; 3193 + return set_vesa_blanking(param); 3383 3194 case TIOCL_GETKMSGREDIRECT: 3384 3195 data = vt_get_kmsg_redirect(); 3385 3196 return put_user(data, p); ··· 3397 3214 */ 3398 3215 return fg_console; 3399 3216 case TIOCL_SCROLLCONSOLE: 3400 - if (get_user(lines, (s32 __user *)(p+4))) 3217 + if (get_user(lines, (s32 __user *)param_aligned32)) 3401 3218 return -EFAULT; 3402 3219 3403 3220 /* ··· 3495 3312 3496 3313 static void con_flush_chars(struct tty_struct *tty) 3497 3314 { 3498 - struct vc_data *vc; 3315 + struct vc_data *vc = tty->driver_data; 3499 3316 3500 3317 if (in_interrupt()) /* from flush_to_ldisc */ 3501 3318 return; 3502 3319 3503 - /* if we race with con_close(), vt may be null */ 3504 3320 console_lock(); 3505 - vc = tty->driver_data; 3506 - if (vc) 3507 - set_cursor(vc); 3321 + set_cursor(vc); 3508 3322 console_unlock(); 3509 3323 } 3510 3324 ··· 3651 3471 vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT); 3652 3472 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); 3653 3473 tty_port_init(&vc->port); 3654 - visual_init(vc, currcons, 1); 3474 + visual_init(vc, currcons, true); 3655 3475 /* Assuming vc->vc_{cols,rows,screenbuf_size} are sane here. */ 3656 3476 vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT); 3657 3477 vc_init(vc, currcons || !vc->vc_sw->con_save_screen); ··· 3661 3481 set_origin(vc); 3662 3482 save_screen(vc); 3663 3483 gotoxy(vc, vc->state.x, vc->state.y); 3664 - csi_J(vc, 0); 3484 + csi_J(vc, CSI_J_CURSOR_TO_END); 3665 3485 update_screen(vc); 3666 3486 pr_info("Console: %s %s %dx%d\n", 3667 3487 vc->vc_can_do_color ? "colour" : "mono", ··· 3820 3640 old_was_color = vc->vc_can_do_color; 3821 3641 vc->vc_sw->con_deinit(vc); 3822 3642 vc->vc_origin = (unsigned long)vc->vc_screenbuf; 3823 - visual_init(vc, i, 0); 3643 + visual_init(vc, i, false); 3824 3644 set_origin(vc); 3825 3645 update_attr(vc); 3826 3646 ··· 4110 3930 * RETURNS: zero if unbound, nonzero if bound 4111 3931 * 4112 3932 * Drivers can call this and if zero, they should release 4113 - * all resources allocated on con_startup() 3933 + * all resources allocated on &consw.con_startup() 4114 3934 */ 4115 3935 int con_is_bound(const struct consw *csw) 4116 3936 { ··· 4150 3970 * Called when the console is taken over by the kernel debugger, this 4151 3971 * function needs to save the current console state, then put the console 4152 3972 * into a state suitable for the kernel debugger. 4153 - * 4154 - * RETURNS: 4155 - * Zero on success, nonzero if a failure occurred when trying to prepare 4156 - * the console for the debugger. 4157 3973 */ 4158 - int con_debug_enter(struct vc_data *vc) 3974 + void con_debug_enter(struct vc_data *vc) 4159 3975 { 4160 - int ret = 0; 4161 - 4162 3976 saved_fg_console = fg_console; 4163 3977 saved_last_console = last_console; 4164 3978 saved_want_console = want_console; ··· 4161 3987 vc->vc_mode = KD_TEXT; 4162 3988 console_blanked = 0; 4163 3989 if (vc->vc_sw->con_debug_enter) 4164 - ret = vc->vc_sw->con_debug_enter(vc); 3990 + vc->vc_sw->con_debug_enter(vc); 4165 3991 #ifdef CONFIG_KGDB_KDB 4166 3992 /* Set the initial LINES variable if it is not already set */ 4167 3993 if (vc->vc_rows < 999) { ··· 4191 4017 } 4192 4018 } 4193 4019 #endif /* CONFIG_KGDB_KDB */ 4194 - return ret; 4195 4020 } 4196 4021 EXPORT_SYMBOL_GPL(con_debug_enter); 4197 4022 ··· 4199 4026 * 4200 4027 * Restore the console state to what it was before the kernel debugger 4201 4028 * was invoked. 4202 - * 4203 - * RETURNS: 4204 - * Zero on success, nonzero if a failure occurred when trying to restore 4205 - * the console. 4206 4029 */ 4207 - int con_debug_leave(void) 4030 + void con_debug_leave(void) 4208 4031 { 4209 4032 struct vc_data *vc; 4210 - int ret = 0; 4211 4033 4212 4034 fg_console = saved_fg_console; 4213 4035 last_console = saved_last_console; ··· 4212 4044 4213 4045 vc = vc_cons[fg_console].d; 4214 4046 if (vc->vc_sw->con_debug_leave) 4215 - ret = vc->vc_sw->con_debug_leave(vc); 4216 - return ret; 4047 + vc->vc_sw->con_debug_leave(vc); 4217 4048 } 4218 4049 EXPORT_SYMBOL_GPL(con_debug_leave); 4219 4050 ··· 4442 4275 * Screen blanking 4443 4276 */ 4444 4277 4445 - static int set_vesa_blanking(char __user *p) 4278 + static int set_vesa_blanking(u8 __user *mode_user) 4446 4279 { 4447 - unsigned int mode; 4280 + u8 mode; 4448 4281 4449 - if (get_user(mode, p + 1)) 4282 + if (get_user(mode, mode_user)) 4450 4283 return -EFAULT; 4451 4284 4452 - vesa_blank_mode = (mode < 4) ? mode : 0; 4285 + console_lock(); 4286 + vesa_blank_mode = (mode <= VESA_BLANK_MAX) ? mode : VESA_NO_BLANKING; 4287 + console_unlock(); 4288 + 4453 4289 return 0; 4454 4290 } 4455 4291 ··· 4477 4307 if (entering_gfx) { 4478 4308 hide_cursor(vc); 4479 4309 save_screen(vc); 4480 - vc->vc_sw->con_blank(vc, -1, 1); 4310 + vc->vc_sw->con_blank(vc, VESA_VSYNC_SUSPEND, 1); 4481 4311 console_blanked = fg_console + 1; 4482 4312 blank_state = blank_off; 4483 4313 set_origin(vc); ··· 4498 4328 4499 4329 save_screen(vc); 4500 4330 /* In case we need to reset origin, blanking hook returns 1 */ 4501 - i = vc->vc_sw->con_blank(vc, vesa_off_interval ? 1 : (vesa_blank_mode + 1), 0); 4331 + i = vc->vc_sw->con_blank(vc, vesa_off_interval ? VESA_VSYNC_SUSPEND : 4332 + (vesa_blank_mode + 1), 0); 4502 4333 console_blanked = fg_console + 1; 4503 4334 if (i) 4504 4335 set_origin(vc); ··· 4550 4379 } 4551 4380 4552 4381 console_blanked = 0; 4553 - if (vc->vc_sw->con_blank(vc, 0, leaving_gfx)) 4382 + if (vc->vc_sw->con_blank(vc, VESA_NO_BLANKING, leaving_gfx)) 4554 4383 /* Low-level driver cannot restore -> do it ourselves */ 4555 4384 update_screen(vc); 4556 4385 if (console_blank_hook) ··· 4755 4584 return rc; 4756 4585 } 4757 4586 4758 - static int con_font_set(struct vc_data *vc, struct console_font_op *op) 4587 + static int con_font_set(struct vc_data *vc, const struct console_font_op *op) 4759 4588 { 4760 4589 struct console_font font; 4761 4590 int rc = -EINVAL; ··· 4919 4748 { 4920 4749 notify_update(vc); 4921 4750 } 4922 - 4923 - void vc_scrolldelta_helper(struct vc_data *c, int lines, 4924 - unsigned int rolled_over, void *base, unsigned int size) 4925 - { 4926 - unsigned long ubase = (unsigned long)base; 4927 - ptrdiff_t scr_end = (void *)c->vc_scr_end - base; 4928 - ptrdiff_t vorigin = (void *)c->vc_visible_origin - base; 4929 - ptrdiff_t origin = (void *)c->vc_origin - base; 4930 - int margin = c->vc_size_row * 4; 4931 - int from, wrap, from_off, avail; 4932 - 4933 - /* Turn scrollback off */ 4934 - if (!lines) { 4935 - c->vc_visible_origin = c->vc_origin; 4936 - return; 4937 - } 4938 - 4939 - /* Do we have already enough to allow jumping from 0 to the end? */ 4940 - if (rolled_over > scr_end + margin) { 4941 - from = scr_end; 4942 - wrap = rolled_over + c->vc_size_row; 4943 - } else { 4944 - from = 0; 4945 - wrap = size; 4946 - } 4947 - 4948 - from_off = (vorigin - from + wrap) % wrap + lines * c->vc_size_row; 4949 - avail = (origin - from + wrap) % wrap; 4950 - 4951 - /* Only a little piece would be left? Show all incl. the piece! */ 4952 - if (avail < 2 * margin) 4953 - margin = 0; 4954 - if (from_off < margin) 4955 - from_off = 0; 4956 - if (from_off > avail - margin) 4957 - from_off = avail; 4958 - 4959 - c->vc_visible_origin = ubase + (from + from_off) % wrap; 4960 - } 4961 - EXPORT_SYMBOL_GPL(vc_scrolldelta_helper);
+2 -4
drivers/tty/vt/vt_ioctl.c
··· 714 714 vcp->vc_scan_lines = v.v_vlin; 715 715 if (v.v_clin) 716 716 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); 719 718 if (ret) { 720 719 vcp->vc_scan_lines = save_scan_lines; 721 720 vcp->vc_cell_height = save_cell_height; ··· 922 923 vc = vc_cons[i].d; 923 924 924 925 if (vc) { 925 - vc->vc_resize_user = 1; 926 926 /* FIXME: review v tty lock */ 927 - vc_resize(vc_cons[i].d, cc, ll); 927 + __vc_resize(vc_cons[i].d, cc, ll, true); 928 928 } 929 929 } 930 930 console_unlock();
+21 -17
drivers/video/console/dummycon.c
··· 50 50 raw_notifier_chain_unregister(&dummycon_output_nh, nb); 51 51 } 52 52 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) 54 55 { 55 56 WARN_CONSOLE_UNLOCKED(); 56 57 ··· 59 58 raw_notifier_call_chain(&dummycon_output_nh, 0, NULL); 60 59 } 61 60 62 - static void dummycon_putcs(struct vc_data *vc, const unsigned short *s, 63 - int count, int ypos, int xpos) 61 + static void dummycon_putcs(struct vc_data *vc, const u16 *s, unsigned int count, 62 + unsigned int ypos, unsigned int xpos) 64 63 { 65 - int i; 64 + unsigned int i; 66 65 67 66 if (!dummycon_putc_called) { 68 67 /* Ignore erases */ ··· 79 78 raw_notifier_call_chain(&dummycon_output_nh, 0, NULL); 80 79 } 81 80 82 - static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch) 81 + static bool dummycon_blank(struct vc_data *vc, enum vesa_blank_mode blank, 82 + bool mode_switch) 83 83 { 84 84 /* Redraw, so that we get putc(s) for output done while blanked */ 85 - return 1; 85 + return true; 86 86 } 87 87 #else 88 - static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos) { } 89 - static void dummycon_putcs(struct vc_data *vc, const unsigned short *s, 90 - int count, int ypos, int xpos) { } 91 - static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch) 88 + static void dummycon_putc(struct vc_data *vc, u16 c, unsigned int y, 89 + unsigned int x) { } 90 + static void dummycon_putcs(struct vc_data *vc, const u16 *s, unsigned int count, 91 + unsigned int ypos, unsigned int xpos) { } 92 + static bool dummycon_blank(struct vc_data *vc, enum vesa_blank_mode blank, 93 + bool mode_switch) 92 94 { 93 - return 0; 95 + return false; 94 96 } 95 97 #endif 96 98 ··· 102 98 return "dummy device"; 103 99 } 104 100 105 - static void dummycon_init(struct vc_data *vc, int init) 101 + static void dummycon_init(struct vc_data *vc, bool init) 106 102 { 107 103 vc->vc_can_do_color = 1; 108 104 if (init) { ··· 113 109 } 114 110 115 111 static void dummycon_deinit(struct vc_data *vc) { } 116 - static void dummycon_clear(struct vc_data *vc, int sy, int sx, int height, 117 - int width) { } 118 - static void dummycon_cursor(struct vc_data *vc, int mode) { } 112 + static void dummycon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx, 113 + unsigned int width) { } 114 + static void dummycon_cursor(struct vc_data *vc, bool enable) { } 119 115 120 116 static bool dummycon_scroll(struct vc_data *vc, unsigned int top, 121 117 unsigned int bottom, enum con_scroll dir, ··· 124 120 return false; 125 121 } 126 122 127 - static int dummycon_switch(struct vc_data *vc) 123 + static bool dummycon_switch(struct vc_data *vc) 128 124 { 129 - return 0; 125 + return false; 130 126 } 131 127 132 128 /*
+15 -28
drivers/video/console/mdacon.c
··· 352 352 return "MDA-2"; 353 353 } 354 354 355 - static void mdacon_init(struct vc_data *c, int init) 355 + static void mdacon_init(struct vc_data *c, bool init) 356 356 { 357 357 c->vc_complement_mask = 0x0800; /* reverse video */ 358 358 c->vc_display_fg = &mda_display_fg; ··· 427 427 return mda_vram_base + y * mda_num_columns + x; 428 428 } 429 429 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) 437 432 { 438 433 u16 *dest = mda_addr(x, y); 439 434 ··· 437 442 } 438 443 } 439 444 440 - static void mdacon_clear(struct vc_data *c, int y, int x, 441 - int height, int width) 445 + static void mdacon_clear(struct vc_data *c, unsigned int y, unsigned int x, 446 + unsigned int width) 442 447 { 443 448 u16 *dest = mda_addr(x, y); 444 449 u16 eattr = mda_convert_attr(c->vc_video_erase_char); 445 450 446 - if (width <= 0 || height <= 0) 447 - return; 448 - 449 - if (x==0 && width==mda_num_columns) { 450 - scr_memsetw(dest, eattr, height*width*2); 451 - } else { 452 - for (; height > 0; height--, dest+=mda_num_columns) 453 - scr_memsetw(dest, eattr, width*2); 454 - } 451 + scr_memsetw(dest, eattr, width * 2); 455 452 } 456 - 457 - static int mdacon_switch(struct vc_data *c) 453 + 454 + static bool mdacon_switch(struct vc_data *c) 458 455 { 459 - return 1; /* redrawing needed */ 456 + return true; /* redrawing needed */ 460 457 } 461 458 462 - static int mdacon_blank(struct vc_data *c, int blank, int mode_switch) 459 + static bool mdacon_blank(struct vc_data *c, enum vesa_blank_mode blank, 460 + bool mode_switch) 463 461 { 464 462 if (mda_type == TYPE_MDA) { 465 463 if (blank) ··· 460 472 mda_convert_attr(c->vc_video_erase_char), 461 473 c->vc_screenbuf_size); 462 474 /* Tell console.c that it has to restore the screen itself */ 463 - return 1; 475 + return true; 464 476 } else { 465 477 if (blank) 466 478 outb_p(0x00, mda_mode_port); /* disable video */ 467 479 else 468 480 outb_p(MDA_MODE_VIDEO_EN | MDA_MODE_BLINK_EN, 469 481 mda_mode_port); 470 - return 0; 482 + return false; 471 483 } 472 484 } 473 485 474 - static void mdacon_cursor(struct vc_data *c, int mode) 486 + static void mdacon_cursor(struct vc_data *c, bool enable) 475 487 { 476 - if (mode == CM_ERASE) { 488 + if (!enable) { 477 489 mda_set_cursor(mda_vram_len - 1); 478 490 return; 479 491 } ··· 532 544 .con_init = mdacon_init, 533 545 .con_deinit = mdacon_deinit, 534 546 .con_clear = mdacon_clear, 535 - .con_putc = mdacon_putc, 536 547 .con_putcs = mdacon_putcs, 537 548 .con_cursor = mdacon_cursor, 538 549 .con_scroll = mdacon_scroll,
+35 -34
drivers/video/console/newport_con.c
··· 324 324 return NULL; 325 325 } 326 326 327 - static void newport_init(struct vc_data *vc, int init) 327 + static void newport_init(struct vc_data *vc, bool init) 328 328 { 329 329 int cols, rows; 330 330 ··· 346 346 } 347 347 } 348 348 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) 351 351 { 352 352 int xend = ((sx + width) << 3) - 1; 353 353 int ystart = ((sy << 4) + topscan) & 0x3ff; 354 - int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff; 354 + int yend = (((sy + 1) << 4) + topscan - 1) & 0x3ff; 355 355 356 356 if (logo_active) 357 357 return; ··· 367 367 } 368 368 } 369 369 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) 372 372 { 373 373 unsigned char *p; 374 374 ··· 396 396 RENDER(npregs, p); 397 397 } 398 398 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) 401 402 { 402 - int i; 403 - int charattr; 404 403 unsigned char *p; 404 + unsigned int i; 405 + u16 charattr; 405 406 406 407 charattr = (scr_readw(s) >> 8) & 0xff; 407 408 ··· 438 437 } 439 438 } 440 439 441 - static void newport_cursor(struct vc_data *vc, int mode) 440 + static void newport_cursor(struct vc_data *vc, bool enable) 442 441 { 443 442 unsigned short treg; 444 443 int xcurs, ycurs; 445 444 446 - switch (mode) { 447 - case CM_ERASE: 448 - treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); 445 + treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); 446 + 447 + if (!enable) { 449 448 newport_vc2_set(npregs, VC2_IREG_CONTROL, 450 449 (treg & ~(VC2_CTRL_ECDISP))); 451 - break; 452 - 453 - case CM_MOVE: 454 - case CM_DRAW: 455 - treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); 456 - newport_vc2_set(npregs, VC2_IREG_CONTROL, 457 - (treg | VC2_CTRL_ECDISP)); 458 - xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2; 459 - ycurs = ((xcurs / vc->vc_cols) << 4) + 31; 460 - xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction; 461 - newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs); 462 - newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs); 450 + return; 463 451 } 452 + 453 + newport_vc2_set(npregs, VC2_IREG_CONTROL, (treg | VC2_CTRL_ECDISP)); 454 + xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2; 455 + ycurs = ((xcurs / vc->vc_cols) << 4) + 31; 456 + xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction; 457 + newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs); 458 + newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs); 464 459 } 465 460 466 - static int newport_switch(struct vc_data *vc) 461 + static bool newport_switch(struct vc_data *vc) 467 462 { 468 463 static int logo_drawn = 0; 469 464 ··· 473 476 } 474 477 } 475 478 476 - return 1; 479 + return true; 477 480 } 478 481 479 - static int newport_blank(struct vc_data *c, int blank, int mode_switch) 482 + static bool newport_blank(struct vc_data *c, enum vesa_blank_mode blank, 483 + bool mode_switch) 480 484 { 481 485 unsigned short treg; 482 486 483 - if (blank == 0) { 487 + if (blank == VESA_NO_BLANKING) { 484 488 /* unblank console */ 485 489 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); 486 490 newport_vc2_set(npregs, VC2_IREG_CONTROL, ··· 492 494 newport_vc2_set(npregs, VC2_IREG_CONTROL, 493 495 (treg & ~(VC2_CTRL_EDISP))); 494 496 } 495 - return 1; 497 + 498 + return true; 496 499 } 497 500 498 - static int newport_set_font(int unit, struct console_font *op, unsigned int vpitch) 501 + static int newport_set_font(int unit, const struct console_font *op, 502 + unsigned int vpitch) 499 503 { 500 504 int w = op->width; 501 505 int h = op->height; ··· 564 564 return 0; 565 565 } 566 566 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) 568 569 { 569 570 return newport_set_def_font(vc->vc_num, op); 570 571 } 571 572 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, 573 574 unsigned int vpitch, unsigned int flags) 574 575 { 575 576 return newport_set_font(vc->vc_num, font, vpitch);
+32 -47
drivers/video/console/sticon.c
··· 71 71 return "STI console"; 72 72 } 73 73 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) 87 76 { 88 77 if (vga_is_gfx || console_blanked) 89 78 return; ··· 86 97 } 87 98 } 88 99 89 - static void sticon_cursor(struct vc_data *conp, int mode) 100 + static void sticon_cursor(struct vc_data *conp, bool enable) 90 101 { 91 102 unsigned short car1; 92 103 ··· 95 106 return; 96 107 97 108 car1 = conp->vc_screenbuf[conp->state.x + conp->state.y * conp->vc_cols]; 98 - switch (mode) { 99 - case CM_ERASE: 109 + if (!enable) { 100 110 sti_putc(sticon_sti, car1, conp->state.y, conp->state.x, 101 111 font_data[conp->vc_num]); 102 - break; 103 - case CM_MOVE: 104 - case CM_DRAW: 105 - switch (CUR_SIZE(conp->vc_cursor_type)) { 106 - case CUR_UNDERLINE: 107 - case CUR_LOWER_THIRD: 108 - case CUR_LOWER_HALF: 109 - case CUR_TWO_THIRDS: 110 - case CUR_BLOCK: 111 - sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11), 112 - conp->state.y, conp->state.x, font_data[conp->vc_num]); 113 - break; 114 - } 112 + return; 113 + } 114 + 115 + switch (CUR_SIZE(conp->vc_cursor_type)) { 116 + case CUR_UNDERLINE: 117 + case CUR_LOWER_THIRD: 118 + case CUR_LOWER_HALF: 119 + case CUR_TWO_THIRDS: 120 + case CUR_BLOCK: 121 + sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11), 122 + conp->state.y, conp->state.x, font_data[conp->vc_num]); 115 123 break; 116 124 } 117 125 } ··· 121 135 if (vga_is_gfx) 122 136 return false; 123 137 124 - sticon_cursor(conp, CM_ERASE); 138 + sticon_cursor(conp, false); 125 139 126 140 switch (dir) { 127 141 case SM_UP: ··· 153 167 } 154 168 } 155 169 156 - static int sticon_set_font(struct vc_data *vc, struct console_font *op, 170 + static int sticon_set_font(struct vc_data *vc, const struct console_font *op, 157 171 unsigned int vpitch) 158 172 { 159 173 struct sti_struct *sti = sticon_sti; ··· 246 260 return 0; 247 261 } 248 262 249 - static int sticon_font_default(struct vc_data *vc, struct console_font *op, char *name) 263 + static int sticon_font_default(struct vc_data *vc, struct console_font *op, 264 + const char *name) 250 265 { 251 266 sticon_set_def_font(vc->vc_num); 252 267 253 268 return 0; 254 269 } 255 270 256 - static int sticon_font_set(struct vc_data *vc, struct console_font *font, 271 + static int sticon_font_set(struct vc_data *vc, const struct console_font *font, 257 272 unsigned int vpitch, unsigned int flags) 258 273 { 259 274 return sticon_set_font(vc, font, vpitch); 260 275 } 261 276 262 - static void sticon_init(struct vc_data *c, int init) 277 + static void sticon_init(struct vc_data *c, bool init) 263 278 { 264 279 struct sti_struct *sti = sticon_sti; 265 280 int vc_cols, vc_rows; ··· 287 300 sticon_set_def_font(i); 288 301 } 289 302 290 - static void sticon_clear(struct vc_data *conp, int sy, int sx, int height, 291 - int width) 303 + static void sticon_clear(struct vc_data *conp, unsigned int sy, unsigned int sx, 304 + unsigned int width) 292 305 { 293 - if (!height || !width) 294 - return; 295 - 296 - sti_clear(sticon_sti, sy, sx, height, width, 306 + sti_clear(sticon_sti, sy, sx, 1, width, 297 307 conp->vc_video_erase_char, font_data[conp->vc_num]); 298 308 } 299 309 300 - static int sticon_switch(struct vc_data *conp) 310 + static bool sticon_switch(struct vc_data *conp) 301 311 { 302 - return 1; /* needs refreshing */ 312 + return true; /* needs refreshing */ 303 313 } 304 314 305 - static int sticon_blank(struct vc_data *c, int blank, int mode_switch) 315 + static bool sticon_blank(struct vc_data *c, enum vesa_blank_mode blank, 316 + bool mode_switch) 306 317 { 307 - if (blank == 0) { 318 + if (blank == VESA_NO_BLANKING) { 308 319 if (mode_switch) 309 320 vga_is_gfx = 0; 310 - return 1; 321 + return true; 311 322 } 312 323 sti_clear(sticon_sti, 0, 0, c->vc_rows, c->vc_cols, BLANK, 313 324 font_data[c->vc_num]); 314 325 if (mode_switch) 315 326 vga_is_gfx = 1; 316 - return 1; 327 + 328 + return true; 317 329 } 318 330 319 331 static u8 sticon_build_attr(struct vc_data *conp, u8 color, ··· 351 365 .con_init = sticon_init, 352 366 .con_deinit = sticon_deinit, 353 367 .con_clear = sticon_clear, 354 - .con_putc = sticon_putc, 355 368 .con_putcs = sticon_putcs, 356 369 .con_cursor = sticon_cursor, 357 370 .con_scroll = sticon_scroll,
+88 -64
drivers/video/console/vgacon.c
··· 65 65 * Interface used by the world 66 66 */ 67 67 68 - static int vgacon_set_origin(struct vc_data *c); 68 + static bool vgacon_set_origin(struct vc_data *c); 69 69 70 70 static struct uni_pagedict *vgacon_uni_pagedir; 71 71 static int vgacon_refcount; ··· 81 81 static bool vga_can_do_color; /* Do we support colors? */ 82 82 static unsigned int vga_default_font_height __read_mostly; /* Height of default screen font */ 83 83 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; 85 85 static bool vga_palette_blanked; 86 86 static bool vga_is_gfx; 87 87 static bool vga_512_chars; ··· 138 138 139 139 static void vgacon_scrolldelta(struct vc_data *c, int lines) 140 140 { 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 + 143 175 vga_set_mem_top(c); 144 176 } 145 177 ··· 367 335 return display_desc; 368 336 } 369 337 370 - static void vgacon_init(struct vc_data *c, int init) 338 + static void vgacon_init(struct vc_data *c, bool init) 371 339 { 372 340 struct uni_pagedict *p; 373 341 ··· 384 352 c->vc_scan_lines = vga_scan_lines; 385 353 c->vc_font.height = c->vc_cell_height = vga_video_font_height; 386 354 387 - /* set dimensions manually if init != 0 since vc_resize() will fail */ 355 + /* set dimensions manually if init is true since vc_resize() will fail */ 388 356 if (init) { 389 357 c->vc_cols = vga_video_num_columns; 390 358 c->vc_rows = vga_video_num_lines; ··· 503 471 raw_spin_unlock_irqrestore(&vga_lock, flags); 504 472 } 505 473 506 - static void vgacon_cursor(struct vc_data *c, int mode) 474 + static void vgacon_cursor(struct vc_data *c, bool enable) 507 475 { 508 476 unsigned int c_height; 509 477 ··· 514 482 515 483 c_height = c->vc_cell_height; 516 484 517 - switch (mode) { 518 - case CM_ERASE: 519 - write_vga(14, (c->vc_pos - vga_vram_base) / 2); 485 + write_vga(14, (c->vc_pos - vga_vram_base) / 2); 486 + 487 + if (!enable) { 520 488 if (vga_video_type >= VIDEO_TYPE_VGAC) 521 489 vgacon_set_cursor_size(31, 30); 522 490 else 523 491 vgacon_set_cursor_size(31, 31); 524 - break; 492 + return; 493 + } 525 494 526 - case CM_MOVE: 527 - case CM_DRAW: 528 - write_vga(14, (c->vc_pos - vga_vram_base) / 2); 529 - switch (CUR_SIZE(c->vc_cursor_type)) { 530 - case CUR_UNDERLINE: 531 - vgacon_set_cursor_size(c_height - 532 - (c_height < 10 ? 2 : 3), 533 - c_height - 534 - (c_height < 10 ? 1 : 2)); 535 - break; 536 - case CUR_TWO_THIRDS: 537 - vgacon_set_cursor_size(c_height / 3, c_height - 538 - (c_height < 10 ? 1 : 2)); 539 - break; 540 - case CUR_LOWER_THIRD: 541 - vgacon_set_cursor_size(c_height * 2 / 3, c_height - 542 - (c_height < 10 ? 1 : 2)); 543 - break; 544 - case CUR_LOWER_HALF: 545 - vgacon_set_cursor_size(c_height / 2, c_height - 546 - (c_height < 10 ? 1 : 2)); 547 - break; 548 - case CUR_NONE: 549 - if (vga_video_type >= VIDEO_TYPE_VGAC) 550 - vgacon_set_cursor_size(31, 30); 551 - else 552 - vgacon_set_cursor_size(31, 31); 553 - break; 554 - default: 555 - vgacon_set_cursor_size(1, c_height); 556 - break; 557 - } 495 + switch (CUR_SIZE(c->vc_cursor_type)) { 496 + case CUR_UNDERLINE: 497 + vgacon_set_cursor_size(c_height - (c_height < 10 ? 2 : 3), 498 + c_height - (c_height < 10 ? 1 : 2)); 499 + break; 500 + case CUR_TWO_THIRDS: 501 + vgacon_set_cursor_size(c_height / 3, 502 + c_height - (c_height < 10 ? 1 : 2)); 503 + break; 504 + case CUR_LOWER_THIRD: 505 + vgacon_set_cursor_size(c_height * 2 / 3, 506 + c_height - (c_height < 10 ? 1 : 2)); 507 + break; 508 + case CUR_LOWER_HALF: 509 + vgacon_set_cursor_size(c_height / 2, 510 + c_height - (c_height < 10 ? 1 : 2)); 511 + break; 512 + case CUR_NONE: 513 + if (vga_video_type >= VIDEO_TYPE_VGAC) 514 + vgacon_set_cursor_size(31, 30); 515 + else 516 + vgacon_set_cursor_size(31, 31); 517 + break; 518 + default: 519 + vgacon_set_cursor_size(1, c_height); 558 520 break; 559 521 } 560 522 } ··· 614 588 raw_spin_unlock_irqrestore(&vga_lock, flags); 615 589 } 616 590 617 - static int vgacon_switch(struct vc_data *c) 591 + static bool vgacon_switch(struct vc_data *c) 618 592 { 619 593 int x = c->vc_cols * VGA_FONTWIDTH; 620 594 int y = c->vc_rows * c->vc_cell_height; ··· 643 617 vgacon_doresize(c, c->vc_cols, c->vc_rows); 644 618 } 645 619 646 - return 0; /* Redrawing not needed */ 620 + return false; /* Redrawing not needed */ 647 621 } 648 622 649 623 static void vga_set_palette(struct vc_data *vc, const unsigned char *table) ··· 683 657 unsigned char ClockingMode; /* Seq-Controller:01h */ 684 658 } vga_state; 685 659 686 - static void vga_vesa_blank(struct vgastate *state, int mode) 660 + static void vga_vesa_blank(struct vgastate *state, enum vesa_blank_mode mode) 687 661 { 688 662 /* save original values of VGA controller registers */ 689 663 if (!vga_vesa_blanked) { ··· 797 771 } 798 772 } 799 773 800 - static int vgacon_blank(struct vc_data *c, int blank, int mode_switch) 774 + static bool vgacon_blank(struct vc_data *c, enum vesa_blank_mode blank, 775 + bool mode_switch) 801 776 { 802 777 switch (blank) { 803 - case 0: /* Unblank */ 778 + case VESA_NO_BLANKING: /* Unblank */ 804 779 if (vga_vesa_blanked) { 805 780 vga_vesa_unblank(&vgastate); 806 - vga_vesa_blanked = 0; 781 + vga_vesa_blanked = VESA_NO_BLANKING; 807 782 } 808 783 if (vga_palette_blanked) { 809 784 vga_set_palette(c, color_table); ··· 814 787 vga_is_gfx = false; 815 788 /* Tell console.c that it has to restore the screen itself */ 816 789 return 1; 817 - case 1: /* Normal blanking */ 818 - case -1: /* Obsolete */ 790 + case VESA_VSYNC_SUSPEND: /* Normal blanking */ 819 791 if (!mode_switch && vga_video_type == VIDEO_TYPE_VGAC) { 820 792 vga_pal_blank(&vgastate); 821 793 vga_palette_blanked = true; ··· 1030 1004 /* void size to cause regs to be rewritten */ 1031 1005 cursor_size_lastfrom = 0; 1032 1006 cursor_size_lastto = 0; 1033 - c->vc_sw->con_cursor(c, CM_DRAW); 1007 + c->vc_sw->con_cursor(c, true); 1034 1008 } 1035 1009 c->vc_font.height = c->vc_cell_height = fontheight; 1036 1010 vc_resize(c, 0, rows); /* Adjust console size */ ··· 1039 1013 return 0; 1040 1014 } 1041 1015 1042 - static int vgacon_font_set(struct vc_data *c, struct console_font *font, 1016 + static int vgacon_font_set(struct vc_data *c, const struct console_font *font, 1043 1017 unsigned int vpitch, unsigned int flags) 1044 1018 { 1045 1019 unsigned charcount = font->charcount; ··· 1075 1049 } 1076 1050 1077 1051 static int vgacon_resize(struct vc_data *c, unsigned int width, 1078 - unsigned int height, unsigned int user) 1052 + unsigned int height, bool from_user) 1079 1053 { 1080 1054 if ((width << 1) * height > vga_vram_size) 1081 1055 return -EINVAL; 1082 1056 1083 - if (user) { 1057 + if (from_user) { 1084 1058 /* 1085 1059 * Ho ho! Someone (svgatextmode, eh?) may have reprogrammed 1086 1060 * the video mode! Set the new defaults then and go away. ··· 1100 1074 return 0; 1101 1075 } 1102 1076 1103 - static int vgacon_set_origin(struct vc_data *c) 1077 + static bool vgacon_set_origin(struct vc_data *c) 1104 1078 { 1105 1079 if (vga_is_gfx || /* We don't play origin tricks in graphic modes */ 1106 1080 (console_blanked && !vga_palette_blanked)) /* Nor we write to blanked screens */ 1107 - return 0; 1081 + return false; 1108 1082 c->vc_origin = c->vc_visible_origin = vga_vram_base; 1109 1083 vga_set_mem_top(c); 1110 1084 vga_rolled_over = 0; 1111 - return 1; 1085 + return true; 1112 1086 } 1113 1087 1114 1088 static void vgacon_save_screen(struct vc_data *c) ··· 1185 1159 * The console `switch' structure for the VGA based console 1186 1160 */ 1187 1161 1188 - static void vgacon_clear(struct vc_data *vc, int sy, int sx, int height, 1189 - int width) { } 1190 - static void vgacon_putc(struct vc_data *vc, int c, int ypos, int xpos) { } 1191 - static void vgacon_putcs(struct vc_data *vc, const unsigned short *s, 1192 - int count, int ypos, int xpos) { } 1162 + static void vgacon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx, 1163 + unsigned int width) { } 1164 + static void vgacon_putcs(struct vc_data *vc, const u16 *s, unsigned int count, 1165 + unsigned int ypos, unsigned int xpos) { } 1193 1166 1194 1167 const struct consw vga_con = { 1195 1168 .owner = THIS_MODULE, ··· 1196 1171 .con_init = vgacon_init, 1197 1172 .con_deinit = vgacon_deinit, 1198 1173 .con_clear = vgacon_clear, 1199 - .con_putc = vgacon_putc, 1200 1174 .con_putcs = vgacon_putcs, 1201 1175 .con_cursor = vgacon_cursor, 1202 1176 .con_scroll = vgacon_scroll,
+2 -11
drivers/video/fbdev/core/bitblit.c
··· 233 233 } 234 234 } 235 235 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, 237 237 int fg, int bg) 238 238 { 239 239 struct fb_cursor cursor; ··· 348 348 mask[i++] = msk; 349 349 } 350 350 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; 361 352 362 353 cursor.image.data = src; 363 354 cursor.image.fg_color = ops->cursor_state.image.fg_color;
+44 -79
drivers/video/fbdev/core/fbcon.c
··· 351 351 struct fb_info *info; 352 352 struct vc_data *vc = NULL; 353 353 int c; 354 - int mode; 354 + bool enable; 355 355 int ret; 356 356 357 357 /* FIXME: we should sort out the unbind locking instead */ ··· 375 375 } 376 376 377 377 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), 381 380 get_color(vc, info, c, 0)); 382 381 console_unlock(); 383 382 ··· 919 920 920 921 static const char *fbcon_startup(void) 921 922 { 922 - const char *display_desc = "frame buffer device"; 923 + static const char display_desc[] = "frame buffer device"; 923 924 struct fbcon_display *p = &fb_display[fg_console]; 924 925 struct vc_data *vc = vc_cons[fg_console].d; 925 926 const struct font_desc *font = NULL; ··· 986 987 return display_desc; 987 988 } 988 989 989 - static void fbcon_init(struct vc_data *vc, int init) 990 + static void fbcon_init(struct vc_data *vc, bool init) 990 991 { 991 992 struct fb_info *info; 992 993 struct fbcon_ops *ops; ··· 1233 1234 * restriction is simplicity & efficiency at the moment. 1234 1235 */ 1235 1236 1236 - static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, 1237 - int width) 1237 + static void __fbcon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx, 1238 + unsigned int height, unsigned int width) 1238 1239 { 1239 1240 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 1240 1241 struct fbcon_ops *ops = info->fbcon_par; ··· 1271 1272 ops->clear(vc, info, real_y(p, sy), sx, height, width); 1272 1273 } 1273 1274 1274 - static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, 1275 - int count, int ypos, int xpos) 1275 + static void fbcon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx, 1276 + unsigned int width) 1277 + { 1278 + __fbcon_clear(vc, sy, sx, 1, width); 1279 + } 1280 + 1281 + static void fbcon_putcs(struct vc_data *vc, const u16 *s, unsigned int count, 1282 + unsigned int ypos, unsigned int xpos) 1276 1283 { 1277 1284 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 1278 1285 struct fbcon_display *p = &fb_display[vc->vc_num]; ··· 1290 1285 get_color(vc, info, scr_readw(s), 0)); 1291 1286 } 1292 1287 1293 - static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos) 1294 - { 1295 - unsigned short chr; 1296 - 1297 - scr_writew(c, &chr); 1298 - fbcon_putcs(vc, &chr, 1, ypos, xpos); 1299 - } 1300 - 1301 1288 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only) 1302 1289 { 1303 1290 struct fb_info *info = fbcon_info_from_console(vc->vc_num); ··· 1299 1302 ops->clear_margins(vc, info, margin_color, bottom_only); 1300 1303 } 1301 1304 1302 - static void fbcon_cursor(struct vc_data *vc, int mode) 1305 + static void fbcon_cursor(struct vc_data *vc, bool enable) 1303 1306 { 1304 1307 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 1305 1308 struct fbcon_ops *ops = info->fbcon_par; ··· 1315 1318 else 1316 1319 fbcon_add_cursor_work(info); 1317 1320 1318 - ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1; 1321 + ops->cursor_flash = enable; 1319 1322 1320 1323 if (!ops->cursor) 1321 1324 return; 1322 1325 1323 - ops->cursor(vc, info, mode, get_color(vc, info, c, 1), 1326 + ops->cursor(vc, info, enable, get_color(vc, info, c, 1), 1324 1327 get_color(vc, info, c, 0)); 1325 1328 } 1326 1329 ··· 1740 1743 if (fbcon_is_inactive(vc, info)) 1741 1744 return true; 1742 1745 1743 - fbcon_cursor(vc, CM_ERASE); 1746 + fbcon_cursor(vc, false); 1744 1747 1745 1748 /* 1746 1749 * ++Geert: Only use ywrap/ypan if the console is in text mode ··· 1756 1759 case SCROLL_MOVE: 1757 1760 fbcon_redraw_blit(vc, info, p, t, b - t - count, 1758 1761 count); 1759 - fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1762 + __fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1760 1763 scr_memsetw((unsigned short *) (vc->vc_origin + 1761 1764 vc->vc_size_row * 1762 1765 (b - count)), ··· 1779 1782 b - t - count, vc->vc_cols); 1780 1783 else 1781 1784 goto redraw_up; 1782 - fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1785 + __fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1783 1786 break; 1784 1787 1785 1788 case SCROLL_PAN_REDRAW: ··· 1797 1800 vc->vc_rows - b, b); 1798 1801 } else 1799 1802 fbcon_redraw_move(vc, p, t + count, b - t - count, t); 1800 - fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1803 + __fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1801 1804 break; 1802 1805 1803 1806 case SCROLL_PAN_MOVE: ··· 1820 1823 b - t - count, vc->vc_cols); 1821 1824 else 1822 1825 goto redraw_up; 1823 - fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1826 + __fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1824 1827 break; 1825 1828 1826 1829 case SCROLL_REDRAW: 1827 1830 redraw_up: 1828 1831 fbcon_redraw(vc, t, b - t - count, 1829 1832 count * vc->vc_cols); 1830 - fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1833 + __fbcon_clear(vc, b - count, 0, count, vc->vc_cols); 1831 1834 scr_memsetw((unsigned short *) (vc->vc_origin + 1832 1835 vc->vc_size_row * 1833 1836 (b - count)), ··· 1844 1847 case SCROLL_MOVE: 1845 1848 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count, 1846 1849 -count); 1847 - fbcon_clear(vc, t, 0, count, vc->vc_cols); 1850 + __fbcon_clear(vc, t, 0, count, vc->vc_cols); 1848 1851 scr_memsetw((unsigned short *) (vc->vc_origin + 1849 1852 vc->vc_size_row * 1850 1853 t), ··· 1867 1870 b - t - count, vc->vc_cols); 1868 1871 else 1869 1872 goto redraw_down; 1870 - fbcon_clear(vc, t, 0, count, vc->vc_cols); 1873 + __fbcon_clear(vc, t, 0, count, vc->vc_cols); 1871 1874 break; 1872 1875 1873 1876 case SCROLL_PAN_MOVE: ··· 1889 1892 b - t - count, vc->vc_cols); 1890 1893 else 1891 1894 goto redraw_down; 1892 - fbcon_clear(vc, t, 0, count, vc->vc_cols); 1895 + __fbcon_clear(vc, t, 0, count, vc->vc_cols); 1893 1896 break; 1894 1897 1895 1898 case SCROLL_PAN_REDRAW: ··· 1906 1909 fbcon_redraw_move(vc, p, count, t, 0); 1907 1910 } else 1908 1911 fbcon_redraw_move(vc, p, t, b - t - count, t + count); 1909 - fbcon_clear(vc, t, 0, count, vc->vc_cols); 1912 + __fbcon_clear(vc, t, 0, count, vc->vc_cols); 1910 1913 break; 1911 1914 1912 1915 case SCROLL_REDRAW: 1913 1916 redraw_down: 1914 1917 fbcon_redraw(vc, b - 1, b - t - count, 1915 1918 -count * vc->vc_cols); 1916 - fbcon_clear(vc, t, 0, count, vc->vc_cols); 1919 + __fbcon_clear(vc, t, 0, count, vc->vc_cols); 1917 1920 scr_memsetw((unsigned short *) (vc->vc_origin + 1918 1921 vc->vc_size_row * 1919 1922 t), ··· 1992 1995 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */ 1993 1996 1994 1997 static int fbcon_resize(struct vc_data *vc, unsigned int width, 1995 - unsigned int height, unsigned int user) 1998 + unsigned int height, bool from_user) 1996 1999 { 1997 2000 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 1998 2001 struct fbcon_ops *ops = info->fbcon_par; ··· 2055 2058 return 0; 2056 2059 } 2057 2060 2058 - static int fbcon_switch(struct vc_data *vc) 2061 + static bool fbcon_switch(struct vc_data *vc) 2059 2062 { 2060 2063 struct fb_info *info, *old_info = NULL; 2061 2064 struct fbcon_ops *ops; ··· 2177 2180 vc->vc_origin + vc->vc_size_row * vc->vc_top, 2178 2181 vc->vc_size_row * (vc->vc_bottom - 2179 2182 vc->vc_top) / 2); 2180 - return 0; 2183 + return false; 2181 2184 } 2182 - return 1; 2185 + return true; 2183 2186 } 2184 2187 2185 2188 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info, ··· 2192 2195 2193 2196 oldc = vc->vc_video_erase_char; 2194 2197 vc->vc_video_erase_char &= charmask; 2195 - fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols); 2198 + __fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols); 2196 2199 vc->vc_video_erase_char = oldc; 2197 2200 } 2198 2201 } 2199 2202 2200 - static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch) 2203 + static bool fbcon_blank(struct vc_data *vc, enum vesa_blank_mode blank, 2204 + bool mode_switch) 2201 2205 { 2202 2206 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 2203 2207 struct fbcon_ops *ops = info->fbcon_par; ··· 2220 2222 if (!fbcon_is_inactive(vc, info)) { 2221 2223 if (ops->blank_state != blank) { 2222 2224 ops->blank_state = blank; 2223 - fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW); 2225 + fbcon_cursor(vc, !blank); 2224 2226 ops->cursor_flash = (!blank); 2225 2227 2226 2228 if (fb_blank(info, blank)) ··· 2237 2239 else 2238 2240 fbcon_add_cursor_work(info); 2239 2241 2240 - return 0; 2242 + return false; 2241 2243 } 2242 2244 2243 - static int fbcon_debug_enter(struct vc_data *vc) 2245 + static void fbcon_debug_enter(struct vc_data *vc) 2244 2246 { 2245 2247 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 2246 2248 struct fbcon_ops *ops = info->fbcon_par; ··· 2250 2252 if (info->fbops->fb_debug_enter) 2251 2253 info->fbops->fb_debug_enter(info); 2252 2254 fbcon_set_palette(vc, color_table); 2253 - return 0; 2254 2255 } 2255 2256 2256 - static int fbcon_debug_leave(struct vc_data *vc) 2257 + static void fbcon_debug_leave(struct vc_data *vc) 2257 2258 { 2258 2259 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 2259 2260 struct fbcon_ops *ops = info->fbcon_par; ··· 2260 2263 ops->graphics = ops->save_graphics; 2261 2264 if (info->fbops->fb_debug_leave) 2262 2265 info->fbops->fb_debug_leave(info); 2263 - return 0; 2264 2266 } 2265 2267 2266 2268 static int fbcon_get_font(struct vc_data *vc, struct console_font *font, unsigned int vpitch) ··· 2457 2461 * but lets not assume that, since charcount of 512 is small for unicode support. 2458 2462 */ 2459 2463 2460 - static int fbcon_set_font(struct vc_data *vc, struct console_font *font, 2464 + static int fbcon_set_font(struct vc_data *vc, const struct console_font *font, 2461 2465 unsigned int vpitch, unsigned int flags) 2462 2466 { 2463 2467 struct fb_info *info = fbcon_info_from_console(vc->vc_num); ··· 2530 2534 return fbcon_do_set_font(vc, font->width, font->height, charcount, new_data, 1); 2531 2535 } 2532 2536 2533 - static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name) 2537 + static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, 2538 + const char *name) 2534 2539 { 2535 2540 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 2536 2541 const struct font_desc *f; ··· 2590 2593 fb_set_cmap(&palette_cmap, info); 2591 2594 } 2592 2595 2593 - static u16 *fbcon_screen_pos(const struct vc_data *vc, int offset) 2594 - { 2595 - return (u16 *) (vc->vc_origin + offset); 2596 - } 2597 - 2598 - static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos, 2599 - int *px, int *py) 2600 - { 2601 - unsigned long ret; 2602 - int x, y; 2603 - 2604 - if (pos >= vc->vc_origin && pos < vc->vc_scr_end) { 2605 - unsigned long offset = (pos - vc->vc_origin) / 2; 2606 - 2607 - x = offset % vc->vc_cols; 2608 - y = offset / vc->vc_cols; 2609 - ret = pos + (vc->vc_cols - x) * 2; 2610 - } else { 2611 - /* Should not happen */ 2612 - x = y = 0; 2613 - ret = vc->vc_origin; 2614 - } 2615 - if (px) 2616 - *px = x; 2617 - if (py) 2618 - *py = y; 2619 - return ret; 2620 - } 2621 - 2622 2596 /* As we might be inside of softback, we may work with non-contiguous buffer, 2623 2597 that's why we have to use a separate routine. */ 2624 2598 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt) ··· 2618 2650 vc = vc_cons[ops->currcon].d; 2619 2651 2620 2652 /* Clear cursor, restore saved data */ 2621 - fbcon_cursor(vc, CM_ERASE); 2653 + fbcon_cursor(vc, false); 2622 2654 } 2623 2655 2624 2656 void fbcon_resumed(struct fb_info *info) ··· 3120 3152 .con_init = fbcon_init, 3121 3153 .con_deinit = fbcon_deinit, 3122 3154 .con_clear = fbcon_clear, 3123 - .con_putc = fbcon_putc, 3124 3155 .con_putcs = fbcon_putcs, 3125 3156 .con_cursor = fbcon_cursor, 3126 3157 .con_scroll = fbcon_scroll, ··· 3130 3163 .con_font_default = fbcon_set_def_font, 3131 3164 .con_set_palette = fbcon_set_palette, 3132 3165 .con_invert_region = fbcon_invert_region, 3133 - .con_screen_pos = fbcon_screen_pos, 3134 - .con_getxy = fbcon_getxy, 3135 3166 .con_resize = fbcon_resize, 3136 3167 .con_debug_enter = fbcon_debug_enter, 3137 3168 .con_debug_leave = fbcon_debug_leave,
+2 -2
drivers/video/fbdev/core/fbcon.h
··· 61 61 int fg, int bg); 62 62 void (*clear_margins)(struct vc_data *vc, struct fb_info *info, 63 63 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); 66 66 int (*update_start)(struct fb_info *info); 67 67 int (*rotate_font)(struct fb_info *info, struct vc_data *vc); 68 68 struct fb_var_screeninfo var; /* copy of the current fb_var_screeninfo */
+2 -11
drivers/video/fbdev/core/fbcon_ccw.c
··· 218 218 } 219 219 } 220 220 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, 222 222 int fg, int bg) 223 223 { 224 224 struct fb_cursor cursor; ··· 349 349 kfree(tmp); 350 350 } 351 351 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; 362 353 363 354 cursor.image.data = src; 364 355 cursor.image.fg_color = ops->cursor_state.image.fg_color;
+2 -11
drivers/video/fbdev/core/fbcon_cw.c
··· 201 201 } 202 202 } 203 203 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, 205 205 int fg, int bg) 206 206 { 207 207 struct fb_cursor cursor; ··· 332 332 kfree(tmp); 333 333 } 334 334 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; 345 336 346 337 cursor.image.data = src; 347 338 cursor.image.fg_color = ops->cursor_state.image.fg_color;
+2 -11
drivers/video/fbdev/core/fbcon_ud.c
··· 248 248 } 249 249 } 250 250 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, 252 252 int fg, int bg) 253 253 { 254 254 struct fb_cursor cursor; ··· 372 372 mask[i++] = ~msk; 373 373 } 374 374 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; 385 376 386 377 cursor.image.data = src; 387 378 cursor.image.fg_color = ops->cursor_state.image.fg_color;
+2 -2
drivers/video/fbdev/core/tileblit.c
··· 79 79 return; 80 80 } 81 81 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, 83 83 int fg, int bg) 84 84 { 85 85 struct fb_tilecursor cursor; ··· 87 87 88 88 cursor.sx = vc->state.x; 89 89 cursor.sy = vc->state.y; 90 - cursor.mode = (mode == CM_ERASE || use_sw) ? 0 : 1; 90 + cursor.mode = enable && !use_sw; 91 91 cursor.fg = fg; 92 92 cursor.bg = bg; 93 93
+1 -1
drivers/video/fbdev/tgafb.c
··· 380 380 BT463_LOAD_ADDR(par, 0x0000); 381 381 TGA_WRITE_REG(par, BT463_PALETTE << 2, TGA_RAMDAC_SETUP_REG); 382 382 383 - #ifdef CONFIG_HW_CONSOLE 383 + #ifdef CONFIG_VT 384 384 for (i = 0; i < 16; i++) { 385 385 int j = color_table[i]; 386 386
+10
drivers/w1/masters/Kconfig
··· 78 78 This support is also available as a module. If so, the module 79 79 will be called sgi_w1. 80 80 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 + 81 91 endmenu 82 92
+1
drivers/w1/masters/Makefile
··· 12 12 obj-$(CONFIG_W1_MASTER_GPIO) += w1-gpio.o 13 13 obj-$(CONFIG_HDQ_MASTER_OMAP) += omap_hdq.o 14 14 obj-$(CONFIG_W1_MASTER_SGI) += sgi_w1.o 15 + obj-$(CONFIG_W1_MASTER_UART) += w1-uart.o
+2 -4
drivers/w1/masters/mxc_w1.c
··· 151 151 /* 152 152 * disassociate the w1 device from the driver 153 153 */ 154 - static int mxc_w1_remove(struct platform_device *pdev) 154 + static void mxc_w1_remove(struct platform_device *pdev) 155 155 { 156 156 struct mxc_w1_device *mdev = platform_get_drvdata(pdev); 157 157 158 158 w1_remove_master_device(&mdev->bus_master); 159 159 160 160 clk_disable_unprepare(mdev->clk); 161 - 162 - return 0; 163 161 } 164 162 165 163 static const struct of_device_id mxc_w1_dt_ids[] = { ··· 172 174 .of_match_table = mxc_w1_dt_ids, 173 175 }, 174 176 .probe = mxc_w1_probe, 175 - .remove = mxc_w1_remove, 177 + .remove_new = mxc_w1_remove, 176 178 }; 177 179 module_platform_driver(mxc_w1_driver); 178 180
+2 -4
drivers/w1/masters/omap_hdq.c
··· 647 647 return ret; 648 648 } 649 649 650 - static int omap_hdq_remove(struct platform_device *pdev) 650 + static void omap_hdq_remove(struct platform_device *pdev) 651 651 { 652 652 int active; 653 653 ··· 661 661 if (active >= 0) 662 662 pm_runtime_put_sync(&pdev->dev); 663 663 pm_runtime_disable(&pdev->dev); 664 - 665 - return 0; 666 664 } 667 665 668 666 static const struct of_device_id omap_hdq_dt_ids[] = { ··· 672 674 673 675 static struct platform_driver omap_hdq_driver = { 674 676 .probe = omap_hdq_probe, 675 - .remove = omap_hdq_remove, 677 + .remove_new = omap_hdq_remove, 676 678 .driver = { 677 679 .name = "omap_hdq", 678 680 .of_match_table = omap_hdq_dt_ids,
+2 -4
drivers/w1/masters/sgi_w1.c
··· 105 105 /* 106 106 * disassociate the w1 device from the driver 107 107 */ 108 - static int sgi_w1_remove(struct platform_device *pdev) 108 + static void sgi_w1_remove(struct platform_device *pdev) 109 109 { 110 110 struct sgi_w1_device *sdev = platform_get_drvdata(pdev); 111 111 112 112 w1_remove_master_device(&sdev->bus_master); 113 - 114 - return 0; 115 113 } 116 114 117 115 static struct platform_driver sgi_w1_driver = { ··· 117 119 .name = "sgi_w1", 118 120 }, 119 121 .probe = sgi_w1_probe, 120 - .remove = sgi_w1_remove, 122 + .remove_new = sgi_w1_remove, 121 123 }; 122 124 module_platform_driver(sgi_w1_driver); 123 125
+2 -4
drivers/w1/masters/w1-gpio.c
··· 141 141 return 0; 142 142 } 143 143 144 - static int w1_gpio_remove(struct platform_device *pdev) 144 + static void w1_gpio_remove(struct platform_device *pdev) 145 145 { 146 146 struct w1_bus_master *master = platform_get_drvdata(pdev); 147 147 struct w1_gpio_ddata *ddata = master->data; ··· 150 150 gpiod_set_value(ddata->pullup_gpiod, 0); 151 151 152 152 w1_remove_master_device(master); 153 - 154 - return 0; 155 153 } 156 154 157 155 static struct platform_driver w1_gpio_driver = { ··· 158 160 .of_match_table = of_match_ptr(w1_gpio_dt_ids), 159 161 }, 160 162 .probe = w1_gpio_probe, 161 - .remove = w1_gpio_remove, 163 + .remove_new = w1_gpio_remove, 162 164 }; 163 165 164 166 module_platform_driver(w1_gpio_driver);
+415
drivers/w1/masters/w1-uart.c
··· 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");
+1 -1
drivers/w1/w1.c
··· 167 167 168 168 static int w1_uevent(const struct device *dev, struct kobj_uevent_env *env); 169 169 170 - static struct bus_type w1_bus_type = { 170 + static const struct bus_type w1_bus_type = { 171 171 .name = "w1", 172 172 .uevent = w1_uevent, 173 173 };
+69 -57
include/linux/console.h
··· 18 18 #include <linux/bits.h> 19 19 #include <linux/rculist.h> 20 20 #include <linux/types.h> 21 + #include <linux/vesa.h> 21 22 22 23 struct vc_data; 23 24 struct console_font_op; ··· 37 36 /** 38 37 * struct consw - callbacks for consoles 39 38 * 39 + * @owner: the module to get references of when this console is used 40 + * @con_startup: set up the console and return its name (like VGA, EGA, ...) 41 + * @con_init: initialize the console on @vc. @init is true for the very first 42 + * call on this @vc. 43 + * @con_deinit: deinitialize the console from @vc. 44 + * @con_clear: erase @count characters at [@x, @y] on @vc. @count >= 1. 45 + * @con_putc: emit one character with attributes @ca to [@x, @y] on @vc. 46 + * (optional -- @con_putcs would be called instead) 47 + * @con_putcs: emit @count characters with attributes @s to [@x, @y] on @vc. 48 + * @con_cursor: enable/disable cursor depending on @enable 40 49 * @con_scroll: move lines from @top to @bottom in direction @dir by @lines. 41 50 * Return true if no generic handling should be done. 42 51 * Invoked by csi_M and printing to the console. 43 - * @con_set_palette: sets the palette of the console to @table (optional) 52 + * @con_switch: notifier about the console switch; it is supposed to return 53 + * true if a redraw is needed. 54 + * @con_blank: blank/unblank the console. The target mode is passed in @blank. 55 + * @mode_switch is set if changing from/to text/graphics. The hook 56 + * is supposed to return true if a redraw is needed. 57 + * @con_font_set: set console @vc font to @font with height @vpitch. @flags can 58 + * be %KD_FONT_FLAG_DONT_RECALC. (optional) 59 + * @con_font_get: fetch the current font on @vc of height @vpitch into @font. 60 + * (optional) 61 + * @con_font_default: set default font on @vc. @name can be %NULL or font name 62 + * to search for. @font can be filled back. (optional) 63 + * @con_resize: resize the @vc console to @width x @height. @from_user is true 64 + * when this change comes from the user space. 65 + * @con_set_palette: sets the palette of the console @vc to @table (optional) 44 66 * @con_scrolldelta: the contents of the console should be scrolled by @lines. 45 67 * Invoked by user. (optional) 68 + * @con_set_origin: set origin (see &vc_data::vc_origin) of the @vc. If not 69 + * provided or returns false, the origin is set to 70 + * @vc->vc_screenbuf. (optional) 71 + * @con_save_screen: save screen content into @vc->vc_screenbuf. Called e.g. 72 + * upon entering graphics. (optional) 73 + * @con_build_attr: build attributes based on @color, @intensity and other 74 + * parameters. The result is used for both normal and erase 75 + * characters. (optional) 76 + * @con_invert_region: invert a region of length @count on @vc starting at @p. 77 + * (optional) 78 + * @con_debug_enter: prepare the console for the debugger. This includes, but 79 + * is not limited to, unblanking the console, loading an 80 + * appropriate palette, and allowing debugger generated output. 81 + * (optional) 82 + * @con_debug_leave: restore the console to its pre-debug state as closely as 83 + * possible. (optional) 46 84 */ 47 85 struct consw { 48 86 struct module *owner; 49 87 const char *(*con_startup)(void); 50 - void (*con_init)(struct vc_data *vc, int init); 88 + void (*con_init)(struct vc_data *vc, bool init); 51 89 void (*con_deinit)(struct vc_data *vc); 52 - void (*con_clear)(struct vc_data *vc, int sy, int sx, int height, 53 - int width); 54 - void (*con_putc)(struct vc_data *vc, int c, int ypos, int xpos); 55 - void (*con_putcs)(struct vc_data *vc, const unsigned short *s, 56 - int count, int ypos, int xpos); 57 - void (*con_cursor)(struct vc_data *vc, int mode); 90 + void (*con_clear)(struct vc_data *vc, unsigned int y, 91 + unsigned int x, unsigned int count); 92 + void (*con_putc)(struct vc_data *vc, u16 ca, unsigned int y, 93 + unsigned int x); 94 + void (*con_putcs)(struct vc_data *vc, const u16 *s, 95 + unsigned int count, unsigned int ypos, 96 + unsigned int xpos); 97 + void (*con_cursor)(struct vc_data *vc, bool enable); 58 98 bool (*con_scroll)(struct vc_data *vc, unsigned int top, 59 99 unsigned int bottom, enum con_scroll dir, 60 100 unsigned int lines); 61 - int (*con_switch)(struct vc_data *vc); 62 - int (*con_blank)(struct vc_data *vc, int blank, int mode_switch); 63 - int (*con_font_set)(struct vc_data *vc, struct console_font *font, 64 - unsigned int vpitch, unsigned int flags); 101 + bool (*con_switch)(struct vc_data *vc); 102 + bool (*con_blank)(struct vc_data *vc, enum vesa_blank_mode blank, 103 + bool mode_switch); 104 + int (*con_font_set)(struct vc_data *vc, 105 + const struct console_font *font, 106 + unsigned int vpitch, unsigned int flags); 65 107 int (*con_font_get)(struct vc_data *vc, struct console_font *font, 66 108 unsigned int vpitch); 67 109 int (*con_font_default)(struct vc_data *vc, 68 - struct console_font *font, char *name); 110 + struct console_font *font, const char *name); 69 111 int (*con_resize)(struct vc_data *vc, unsigned int width, 70 - unsigned int height, unsigned int user); 112 + unsigned int height, bool from_user); 71 113 void (*con_set_palette)(struct vc_data *vc, 72 114 const unsigned char *table); 73 115 void (*con_scrolldelta)(struct vc_data *vc, int lines); 74 - int (*con_set_origin)(struct vc_data *vc); 116 + bool (*con_set_origin)(struct vc_data *vc); 75 117 void (*con_save_screen)(struct vc_data *vc); 76 118 u8 (*con_build_attr)(struct vc_data *vc, u8 color, 77 119 enum vc_intensity intensity, 78 120 bool blink, bool underline, bool reverse, bool italic); 79 121 void (*con_invert_region)(struct vc_data *vc, u16 *p, int count); 80 - u16 *(*con_screen_pos)(const struct vc_data *vc, int offset); 81 - unsigned long (*con_getxy)(struct vc_data *vc, unsigned long position, 82 - int *px, int *py); 83 - /* 84 - * Flush the video console driver's scrollback buffer 85 - */ 86 - void (*con_flush_scrollback)(struct vc_data *vc); 87 - /* 88 - * Prepare the console for the debugger. This includes, but is not 89 - * limited to, unblanking the console, loading an appropriate 90 - * palette, and allowing debugger generated output. 91 - */ 92 - int (*con_debug_enter)(struct vc_data *vc); 93 - /* 94 - * Restore the console to its pre-debug state as closely as possible. 95 - */ 96 - int (*con_debug_leave)(struct vc_data *vc); 122 + void (*con_debug_enter)(struct vc_data *vc); 123 + void (*con_debug_leave)(struct vc_data *vc); 97 124 }; 98 125 99 126 extern const struct consw *conswitchp; ··· 141 112 int do_unregister_con_driver(const struct consw *csw); 142 113 int do_take_over_console(const struct consw *sw, int first, int last, int deflt); 143 114 void give_up_console(const struct consw *sw); 144 - #ifdef CONFIG_HW_CONSOLE 145 - int con_debug_enter(struct vc_data *vc); 146 - int con_debug_leave(void); 115 + #ifdef CONFIG_VT 116 + void con_debug_enter(struct vc_data *vc); 117 + void con_debug_leave(void); 147 118 #else 148 - static inline int con_debug_enter(struct vc_data *vc) 149 - { 150 - return 0; 151 - } 152 - static inline int con_debug_leave(void) 153 - { 154 - return 0; 155 - } 119 + static inline void con_debug_enter(struct vc_data *vc) { } 120 + static inline void con_debug_leave(void) { } 156 121 #endif 157 - 158 - /* cursor */ 159 - #define CM_DRAW (1) 160 - #define CM_ERASE (2) 161 - #define CM_MOVE (3) 162 122 163 123 /* 164 124 * The interface for a console, or any other device that wants to capture ··· 155 137 */ 156 138 157 139 /** 158 - * cons_flags - General console flags 140 + * enum cons_flags - General console flags 159 141 * @CON_PRINTBUFFER: Used by newly registered consoles to avoid duplicate 160 142 * output of messages that were already shown by boot 161 143 * consoles or read by userspace via syslog() syscall. ··· 236 218 static_assert(sizeof(struct nbcon_state) <= sizeof(int)); 237 219 238 220 /** 239 - * nbcon_prio - console owner priority for nbcon consoles 221 + * enum nbcon_prio - console owner priority for nbcon consoles 240 222 * @NBCON_PRIO_NONE: Unused 241 223 * @NBCON_PRIO_NORMAL: Normal (non-emergency) usage 242 224 * @NBCON_PRIO_EMERGENCY: Emergency output (WARN/OOPS...) ··· 468 450 * for_each_console() - Iterator over registered consoles 469 451 * @con: struct console pointer used as loop cursor 470 452 * 471 - * The console list and the console->flags are immutable while iterating. 453 + * The console list and the &console.flags are immutable while iterating. 472 454 * 473 455 * Requires console_list_lock to be held. 474 456 */ ··· 537 519 * WARN_CONSOLE_UNLOCKED() for debugging purposes. 538 520 */ 539 521 extern atomic_t ignore_console_lock_warning; 540 - 541 - /* VESA Blanking Levels */ 542 - #define VESA_NO_BLANKING 0 543 - #define VESA_VSYNC_SUSPEND 1 544 - #define VESA_HSYNC_SUSPEND 2 545 - #define VESA_POWERDOWN 3 546 522 547 523 extern void console_init(void); 548 524
-1
include/linux/console_struct.h
··· 151 151 DECLARE_BITMAP(vc_tab_stop, VC_TABSTOPS_COUNT); /* Tab stops. 256 columns. */ 152 152 unsigned char vc_palette[16*3]; /* Colour palette for VGA+ */ 153 153 unsigned short * vc_translate; 154 - unsigned int vc_resize_user; /* resize request from user */ 155 154 unsigned int vc_bell_pitch; /* Console bell pitch */ 156 155 unsigned int vc_bell_duration; /* Console bell duration */ 157 156 unsigned short vc_cur_blink_ms; /* Cursor blink duration */
+22 -26
include/linux/selection.h
··· 14 14 struct tty_struct; 15 15 struct vc_data; 16 16 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); 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); 26 25 27 - bool vc_is_sel(struct vc_data *vc); 26 + bool vc_is_sel(const struct vc_data *vc); 28 27 29 28 extern int console_blanked; 30 29 ··· 32 33 extern unsigned char default_grn[]; 33 34 extern unsigned char default_blu[]; 34 35 35 - extern unsigned short *screen_pos(const struct vc_data *vc, int w_offset, 36 - bool viewed); 37 - extern u16 screen_glyph(const struct vc_data *vc, int offset); 38 - extern u32 screen_glyph_unicode(const struct vc_data *vc, int offset); 39 - extern void complement_pos(struct vc_data *vc, int offset); 40 - extern void invert_screen(struct vc_data *vc, int offset, int count, bool viewed); 36 + unsigned short *screen_pos(const struct vc_data *vc, int w_offset, bool viewed); 37 + u16 screen_glyph(const struct vc_data *vc, int offset); 38 + u32 screen_glyph_unicode(const struct vc_data *vc, int offset); 39 + void complement_pos(struct vc_data *vc, int offset); 40 + void invert_screen(struct vc_data *vc, int offset, int count, bool viewed); 41 41 42 - extern void getconsxy(const struct vc_data *vc, unsigned char xy[static 2]); 43 - extern void putconsxy(struct vc_data *vc, unsigned char xy[static const 2]); 42 + void getconsxy(const struct vc_data *vc, unsigned char xy[static 2]); 43 + void putconsxy(struct vc_data *vc, unsigned char xy[static const 2]); 44 44 45 - extern u16 vcs_scr_readw(const struct vc_data *vc, const u16 *org); 46 - extern void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org); 47 - extern void vcs_scr_updated(struct vc_data *vc); 45 + u16 vcs_scr_readw(const struct vc_data *vc, const u16 *org); 46 + void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org); 47 + void vcs_scr_updated(struct vc_data *vc); 48 48 49 - extern int vc_uniscr_check(struct vc_data *vc); 50 - extern void vc_uniscr_copy_line(const struct vc_data *vc, void *dest, 51 - bool viewed, 52 - unsigned int row, unsigned int col, 53 - unsigned int nr); 49 + int vc_uniscr_check(struct vc_data *vc); 50 + void vc_uniscr_copy_line(const struct vc_data *vc, void *dest, bool viewed, 51 + unsigned int row, unsigned int col, unsigned int nr); 54 52 55 53 #endif
+4 -4
include/linux/serdev.h
··· 27 27 * not sleep. 28 28 */ 29 29 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); 31 31 void (*write_wakeup)(struct serdev_device *); 32 32 }; 33 33 ··· 185 185 serdev->ops->write_wakeup(serdev); 186 186 } 187 187 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) 191 191 { 192 192 struct serdev_device *serdev = ctrl->serdev; 193 193
+6
include/linux/serial_8250.h
··· 210 210 void serial8250_set_isa_configurator(void (*v)(int port, struct uart_port *up, 211 211 u32 *capabilities)); 212 212 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 + 213 219 #ifdef CONFIG_SERIAL_8250_RT288X 214 220 int rt288x_setup(struct uart_port *p); 215 221 int au_platform_setup(struct plat_serial8250_port *p);
+10 -4
include/linux/serial_core.h
··· 467 467 unsigned int fifosize; /* tx fifo size */ 468 468 unsigned char x_char; /* xon/xoff char */ 469 469 unsigned char regshift; /* reg offset shift */ 470 - unsigned char iotype; /* io access style */ 471 - unsigned char quirks; /* internal quirks */ 472 470 471 + unsigned char iotype; /* io access style */ 472 + 473 + #define UPIO_UNKNOWN ((unsigned char)~0U) /* UCHAR_MAX */ 473 474 #define UPIO_PORT (SERIAL_IO_PORT) /* 8b I/O port access */ 474 475 #define UPIO_HUB6 (SERIAL_IO_HUB6) /* Hub6 ISA card */ 475 476 #define UPIO_MEM (SERIAL_IO_MEM) /* driver-specific */ ··· 480 479 #define UPIO_MEM32BE (SERIAL_IO_MEM32BE) /* 32b big endian */ 481 480 #define UPIO_MEM16 (SERIAL_IO_MEM16) /* 16b little endian */ 482 481 483 - /* quirks must be updated while holding port mutex */ 482 + unsigned char quirks; /* internal quirks */ 483 + 484 + /* internal quirks must be updated while holding port mutex */ 484 485 #define UPQ_NO_TXEN_TEST BIT(0) 485 486 486 487 unsigned int read_status_mask; /* driver specific */ ··· 789 786 if (pending < WAKEUP_CHARS) { \ 790 787 uart_write_wakeup(__port); \ 791 788 \ 792 - if (!((flags) & UART_TX_NOSTOP) && pending == 0) \ 789 + if (!((flags) & UART_TX_NOSTOP) && pending == 0 && \ 790 + __port->ops->tx_empty(__port)) \ 793 791 __port->ops->stop_tx(__port); \ 794 792 } \ 795 793 \ ··· 963 959 void uart_unregister_driver(struct uart_driver *uart); 964 960 int uart_add_one_port(struct uart_driver *reg, struct uart_port *port); 965 961 void uart_remove_one_port(struct uart_driver *reg, struct uart_port *port); 962 + int uart_read_port_properties(struct uart_port *port); 963 + int uart_read_and_validate_port_properties(struct uart_port *port); 966 964 bool uart_match_port(const struct uart_port *port1, 967 965 const struct uart_port *port2); 968 966
+1
include/linux/soc/qcom/geni-se.h
··· 178 178 #define M_GP_IRQ_3_EN BIT(12) 179 179 #define M_GP_IRQ_4_EN BIT(13) 180 180 #define M_GP_IRQ_5_EN BIT(14) 181 + #define M_TX_FIFO_NOT_EMPTY_EN BIT(21) 181 182 #define M_IO_DATA_DEASSERT_EN BIT(22) 182 183 #define M_IO_DATA_ASSERT_EN BIT(23) 183 184 #define M_RX_FIFO_RD_ERR_EN BIT(24)
-1
include/linux/tty.h
··· 6 6 #include <linux/major.h> 7 7 #include <linux/termios.h> 8 8 #include <linux/workqueue.h> 9 - #include <linux/tty_buffer.h> 10 9 #include <linux/tty_driver.h> 11 10 #include <linux/tty_ldisc.h> 12 11 #include <linux/tty_port.h>
+8 -4
include/linux/vt_kern.h
··· 25 25 26 26 int vc_allocate(unsigned int console); 27 27 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); 29 30 struct vc_data *vc_deallocate(unsigned int console); 30 31 void reset_palette(struct vc_data *vc); 31 32 void do_blank_screen(int entering_gfx); ··· 42 41 void redraw_screen(struct vc_data *vc, int is_switch); 43 42 #define update_screen(x) redraw_screen(x, 0) 44 43 #define switch_screen(x) redraw_screen(x, 1) 44 + 45 + static inline int vc_resize(struct vc_data *vc, unsigned int cols, 46 + unsigned int lines) 47 + { 48 + return __vc_resize(vc, cols, lines, false); 49 + } 45 50 46 51 struct tty_struct; 47 52 int tioclinux(struct tty_struct *tty, unsigned long arg); ··· 174 167 void vt_set_led_state(unsigned int console, int leds); 175 168 void vt_kbd_con_start(unsigned int console); 176 169 void vt_kbd_con_stop(unsigned int console); 177 - 178 - void vc_scrolldelta_helper(struct vc_data *c, int lines, 179 - unsigned int rolled_over, void *_base, unsigned int size); 180 170 181 171 #endif /* _VT_KERN_H */
+1 -7
include/uapi/linux/fb.h
··· 4 4 5 5 #include <linux/types.h> 6 6 #include <linux/i2c.h> 7 + #include <linux/vesa.h> 7 8 8 9 /* Definitions of frame buffers */ 9 10 ··· 293 292 __u32 console; 294 293 __u32 framebuffer; 295 294 }; 296 - 297 - /* VESA Blanking Levels */ 298 - #define VESA_NO_BLANKING 0 299 - #define VESA_VSYNC_SUSPEND 1 300 - #define VESA_HSYNC_SUSPEND 2 301 - #define VESA_POWERDOWN 3 302 - 303 295 304 296 enum { 305 297 /* screen: unblanked, hsync: on, vsync: on */
+18
include/uapi/linux/vesa.h
··· 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
+18 -3
kernel/printk/printk.c
··· 3269 3269 3270 3270 early_param("keep_bootcon", keep_bootcon_setup); 3271 3271 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 + 3272 3287 /* 3273 3288 * This is called by register_console() to try to match 3274 3289 * the newly registered console with any of the ones selected ··· 3319 3304 if (_braille_register_console(newcon, c)) 3320 3305 return 0; 3321 3306 3322 - if (newcon->setup && 3323 - (err = newcon->setup(newcon, c->options)) != 0) 3307 + err = console_call_setup(newcon, c->options); 3308 + if (err) 3324 3309 return err; 3325 3310 } 3326 3311 newcon->flags |= CON_ENABLED; ··· 3346 3331 if (newcon->index < 0) 3347 3332 newcon->index = 0; 3348 3333 3349 - if (newcon->setup && newcon->setup(newcon, NULL) != 0) 3334 + if (console_call_setup(newcon, NULL) != 0) 3350 3335 return; 3351 3336 3352 3337 newcon->flags |= CON_ENABLED;
+1 -1
lib/Kconfig.kgdb
··· 43 43 tristate "KGDB: use kgdb over the serial console" 44 44 select CONSOLE_POLL 45 45 select MAGIC_SYSRQ 46 - depends on TTY && HW_CONSOLE 46 + depends on TTY && VT 47 47 default y 48 48 help 49 49 Share a serial console with kgdb. Sysrq-g must be used
+2 -2
sound/drivers/serial-generic.c
··· 100 100 snd_serial_generic_tx_wakeup(drvdata); 101 101 } 102 102 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) 105 105 { 106 106 int ret; 107 107 struct snd_serial_generic *drvdata = serdev_device_get_drvdata(serdev);