Merge tag 'tty-6.15-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 serial and tty driver updates for 6.15-rc1.
Include in here are the following:

- more great tty layer cleanups from Jiri. Someday this will be done,
but that's not going to be any year soon...

- kdb debug driver reverts to fix a reported issue

- lots of .dts binding updates for different devices with serial
devices

- lots of tiny updates and tweaks and a few bugfixes for different
serial drivers.

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

* tag 'tty-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (79 commits)
tty: serial: fsl_lpuart: Fix unused variable 'sport' build warning
serial: stm32: do not deassert RS485 RTS GPIO prematurely
serial: 8250: add driver for NI UARTs
dt-bindings: serial: snps-dw-apb-uart: document RZ/N1 binding without DMA
serial: icom: fix code format problems
serial: sh-sci: Save and restore more registers
tty: serial: pl011: remove incorrect of_match_ptr annotation
dt-bindings: serial: snps-dw-apb-uart: Add support for rk3562
tty: serial: lpuart: only disable CTS instead of overwriting the whole UARTMODIR register
tty: caif: removed unused function debugfs_tx()
serial: 8250_dma: terminate correct DMA in tx_dma_flush()
tty: serial: fsl_lpuart: rename register variables more specifically
tty: serial: fsl_lpuart: use port struct directly to simply code
tty: serial: fsl_lpuart: Use u32 and u8 for register variables
tty: serial: fsl_lpuart: disable transmitter before changing RS485 related registers
tty: serial: 8250: Add Brainboxes XC devices
dt-bindings: serial: fsl-lpuart: support i.MX94
tty: serial: 8250: Add some more device IDs
dt-bindings: serial: samsung: add exynos7870-uart compatible
serial: 8250_dw: Comment possible corner cases in serial_out() implementation
...

+2238 -1462
+1 -1
Documentation/devicetree/bindings/serial/8250.yaml
··· 77 - altr,16550-FIFO64 78 - altr,16550-FIFO128 79 - fsl,16550-FIFO64 80 - - fsl,ns16550 81 - andestech,uart16550 82 - nxp,lpc1850-uart 83 - opencores,uart16550-rtlsvn105 ··· 85 - items: 86 - enum: 87 - ns16750 88 - cavium,octeon-3860-uart 89 - xlnx,xps-uart16550-2.00.b 90 - ralink,rt2880-uart
··· 77 - altr,16550-FIFO64 78 - altr,16550-FIFO128 79 - fsl,16550-FIFO64 80 - andestech,uart16550 81 - nxp,lpc1850-uart 82 - opencores,uart16550-rtlsvn105 ··· 86 - items: 87 - enum: 88 - ns16750 89 + - fsl,ns16550 90 - cavium,octeon-3860-uart 91 - xlnx,xps-uart16550-2.00.b 92 - ralink,rt2880-uart
+1
Documentation/devicetree/bindings/serial/fsl-lpuart.yaml
··· 30 - items: 31 - enum: 32 - fsl,imx93-lpuart 33 - fsl,imx95-lpuart 34 - const: fsl,imx8ulp-lpuart 35 - const: fsl,imx7ulp-lpuart
··· 30 - items: 31 - enum: 32 - fsl,imx93-lpuart 33 + - fsl,imx94-lpuart 34 - fsl,imx95-lpuart 35 - const: fsl,imx8ulp-lpuart 36 - const: fsl,imx7ulp-lpuart
+73
Documentation/devicetree/bindings/serial/nvidia,tegra264-utc.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/nvidia,tegra264-utc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: NVIDIA Tegra UTC (UART Trace Controller) client 8 + 9 + maintainers: 10 + - Kartik Rajput <kkartik@nvidia.com> 11 + - Thierry Reding <thierry.reding@gmail.com> 12 + - Jonathan Hunter <jonathanh@nvidia.com> 13 + 14 + description: 15 + Represents a client interface of the Tegra UTC (UART Trace Controller). The 16 + Tegra UTC allows multiple clients within the Tegra SoC to share a physical 17 + UART interface. It supports up to 16 clients. Each client operates as an 18 + independent UART endpoint with a dedicated interrupt and 128-character TX/RX 19 + FIFOs. 20 + 21 + The Tegra UTC clients use 8-N-1 configuration and operates on a baudrate 22 + configured by the bootloader at the controller level. 23 + 24 + allOf: 25 + - $ref: serial.yaml# 26 + 27 + properties: 28 + compatible: 29 + const: nvidia,tegra264-utc 30 + 31 + reg: 32 + items: 33 + - description: TX region. 34 + - description: RX region. 35 + 36 + reg-names: 37 + items: 38 + - const: tx 39 + - const: rx 40 + 41 + interrupts: 42 + maxItems: 1 43 + 44 + tx-threshold: 45 + minimum: 1 46 + maximum: 128 47 + 48 + rx-threshold: 49 + minimum: 1 50 + maximum: 128 51 + 52 + required: 53 + - compatible 54 + - reg 55 + - reg-names 56 + - interrupts 57 + - tx-threshold 58 + - rx-threshold 59 + 60 + additionalProperties: false 61 + 62 + examples: 63 + - | 64 + #include <dt-bindings/interrupt-controller/arm-gic.h> 65 + 66 + tegra_utc: serial@c4e0000 { 67 + compatible = "nvidia,tegra264-utc"; 68 + reg = <0xc4e0000 0x8000>, <0xc4e8000 0x8000>; 69 + reg-names = "tx", "rx"; 70 + interrupts = <GIC_SPI 514 IRQ_TYPE_LEVEL_HIGH>; 71 + tx-threshold = <4>; 72 + rx-threshold = <4>; 73 + };
+3
Documentation/devicetree/bindings/serial/pl011.yaml
··· 92 3000ms. 93 default: 3000 94 95 resets: 96 maxItems: 1 97
··· 92 3000ms. 93 default: 3000 94 95 + power-domains: 96 + maxItems: 1 97 + 98 resets: 99 maxItems: 1 100
+4
Documentation/devicetree/bindings/serial/samsung_uart.yaml
··· 42 - samsung,exynosautov9-uart 43 - samsung,exynosautov920-uart 44 - const: samsung,exynos850-uart 45 46 reg: 47 maxItems: 1
··· 42 - samsung,exynosautov9-uart 43 - samsung,exynosautov920-uart 44 - const: samsung,exynos850-uart 45 + - items: 46 + - enum: 47 + - samsung,exynos7870-uart 48 + - const: samsung,exynos8895-uart 49 50 reg: 51 maxItems: 1
+21
Documentation/devicetree/bindings/serial/snps-dw-apb-uart.yaml
··· 16 - if: 17 properties: 18 compatible: 19 contains: 20 const: starfive,jh7110-uart 21 then: ··· 44 properties: 45 compatible: 46 oneOf: 47 - items: 48 - enum: 49 - renesas,r9a06g032-uart ··· 71 - rockchip,rk3368-uart 72 - rockchip,rk3399-uart 73 - rockchip,rk3528-uart 74 - rockchip,rk3568-uart 75 - rockchip,rk3576-uart 76 - rockchip,rk3588-uart
··· 16 - if: 17 properties: 18 compatible: 19 + items: 20 + - enum: 21 + - renesas,r9a06g032-uart 22 + - renesas,r9a06g033-uart 23 + - const: renesas,rzn1-uart 24 + - const: snps,dw-apb-uart 25 + then: 26 + properties: 27 + dmas: false 28 + dma-names: false 29 + 30 + - if: 31 + properties: 32 + compatible: 33 contains: 34 const: starfive,jh7110-uart 35 then: ··· 30 properties: 31 compatible: 32 oneOf: 33 + - items: 34 + - enum: 35 + - renesas,r9a06g032-uart 36 + - renesas,r9a06g033-uart 37 + - const: renesas,rzn1-uart 38 + - const: snps,dw-apb-uart 39 - items: 40 - enum: 41 - renesas,r9a06g032-uart ··· 51 - rockchip,rk3368-uart 52 - rockchip,rk3399-uart 53 - rockchip,rk3528-uart 54 + - rockchip,rk3562-uart 55 - rockchip,rk3568-uart 56 - rockchip,rk3576-uart 57 - rockchip,rk3588-uart
+7 -2
Documentation/devicetree/bindings/serial/sprd-uart.yaml
··· 17 oneOf: 18 - items: 19 - enum: 20 - - sprd,sc9632-uart 21 - sprd,sc9860-uart 22 - sprd,sc9863a-uart 23 - sprd,ums512-uart 24 - sprd,ums9620-uart 25 - const: sprd,sc9836-uart 26 - - const: sprd,sc9836-uart 27 28 reg: 29 maxItems: 1
··· 17 oneOf: 18 - items: 19 - enum: 20 + - sprd,ums9632-uart 21 + - const: sprd,sc9632-uart 22 + - items: 23 + - enum: 24 - sprd,sc9860-uart 25 - sprd,sc9863a-uart 26 - sprd,ums512-uart 27 - sprd,ums9620-uart 28 - const: sprd,sc9836-uart 29 + - enum: 30 + - sprd,sc9632-uart 31 + - sprd,sc9836-uart 32 33 reg: 34 maxItems: 1
+2 -2
Documentation/driver-api/serial/driver.rst
··· 101 Some helpers are provided in order to set/get modem control lines via GPIO. 102 103 .. kernel-doc:: drivers/tty/serial/serial_mctrl_gpio.c 104 - :identifiers: mctrl_gpio_init mctrl_gpio_free mctrl_gpio_to_gpiod 105 mctrl_gpio_set mctrl_gpio_get mctrl_gpio_enable_ms 106 - mctrl_gpio_disable_ms
··· 101 Some helpers are provided in order to set/get modem control lines via GPIO. 102 103 .. kernel-doc:: drivers/tty/serial/serial_mctrl_gpio.c 104 + :identifiers: mctrl_gpio_init mctrl_gpio_to_gpiod 105 mctrl_gpio_set mctrl_gpio_get mctrl_gpio_enable_ms 106 + mctrl_gpio_disable_ms_sync mctrl_gpio_disable_ms_no_sync
+3 -1
Documentation/driver-api/tty/tty_driver.rst
··· 25 For reference, both allocation and deallocation functions are explained here in 26 detail: 27 28 .. kernel-doc:: drivers/tty/tty_io.c 29 :identifiers: __tty_alloc_driver tty_driver_kref_put 30 ··· 37 __tty_alloc_driver()): 38 39 .. kernel-doc:: include/linux/tty_driver.h 40 - :doc: TTY Driver Flags 41 42 ---- 43
··· 25 For reference, both allocation and deallocation functions are explained here in 26 detail: 27 28 + .. kernel-doc:: include/linux/tty_driver.h 29 + :identifiers: tty_alloc_driver 30 .. kernel-doc:: drivers/tty/tty_io.c 31 :identifiers: __tty_alloc_driver tty_driver_kref_put 32 ··· 35 __tty_alloc_driver()): 36 37 .. kernel-doc:: include/linux/tty_driver.h 38 + :identifiers: tty_driver_flag 39 40 ---- 41
+1 -1
Documentation/driver-api/tty/tty_struct.rst
··· 72 ================ 73 74 .. kernel-doc:: include/linux/tty.h 75 - :doc: TTY Struct Flags 76 77 TTY Struct Reference 78 ====================
··· 72 ================ 73 74 .. kernel-doc:: include/linux/tty.h 75 + :identifiers: tty_struct_flags 76 77 TTY Struct Reference 78 ====================
+6
MAINTAINERS
··· 16550 F: drivers/mtd/nand/ 16551 F: include/linux/mtd/*nand*.h 16552 16553 NATIVE INSTRUMENTS USB SOUND INTERFACE DRIVER 16554 M: Daniel Mack <zonque@gmail.com> 16555 L: linux-sound@vger.kernel.org
··· 16550 F: drivers/mtd/nand/ 16551 F: include/linux/mtd/*nand*.h 16552 16553 + NATIONAL INSTRUMENTS SERIAL DRIVER 16554 + M: Chaitanya Vadrevu <chaitanya.vadrevu@emerson.com> 16555 + L: linux-serial@vger.kernel.org 16556 + S: Maintained 16557 + F: drivers/tty/serial/8250/8250_ni.c 16558 + 16559 NATIVE INSTRUMENTS USB SOUND INTERFACE DRIVER 16560 M: Daniel Mack <zonque@gmail.com> 16561 L: linux-sound@vger.kernel.org
+30 -26
arch/alpha/kernel/srmcons.c
··· 196 static int __init 197 srmcons_init(void) 198 { 199 timer_setup(&srmcons_singleton.timer, srmcons_receive_chars, 0); 200 - if (srm_is_registered_console) { 201 - struct tty_driver *driver; 202 - int err; 203 204 - driver = tty_alloc_driver(MAX_SRM_CONSOLE_DEVICES, 0); 205 - if (IS_ERR(driver)) 206 - return PTR_ERR(driver); 207 208 - tty_port_init(&srmcons_singleton.port); 209 210 - driver->driver_name = "srm"; 211 - driver->name = "srm"; 212 - driver->major = 0; /* dynamic */ 213 - driver->minor_start = 0; 214 - driver->type = TTY_DRIVER_TYPE_SYSTEM; 215 - driver->subtype = SYSTEM_TYPE_SYSCONS; 216 - driver->init_termios = tty_std_termios; 217 - tty_set_operations(driver, &srmcons_ops); 218 - tty_port_link_device(&srmcons_singleton.port, driver, 0); 219 - err = tty_register_driver(driver); 220 - if (err) { 221 - tty_driver_kref_put(driver); 222 - tty_port_destroy(&srmcons_singleton.port); 223 - return err; 224 - } 225 - srmcons_driver = driver; 226 - } 227 228 - return -ENODEV; 229 } 230 device_initcall(srmcons_init); 231 232 - 233 /* 234 * The console driver 235 */
··· 196 static int __init 197 srmcons_init(void) 198 { 199 + struct tty_driver *driver; 200 + int err; 201 + 202 timer_setup(&srmcons_singleton.timer, srmcons_receive_chars, 0); 203 204 + if (!srm_is_registered_console) 205 + return -ENODEV; 206 207 + driver = tty_alloc_driver(MAX_SRM_CONSOLE_DEVICES, 0); 208 + if (IS_ERR(driver)) 209 + return PTR_ERR(driver); 210 211 + tty_port_init(&srmcons_singleton.port); 212 213 + driver->driver_name = "srm"; 214 + driver->name = "srm"; 215 + driver->major = 0; /* dynamic */ 216 + driver->minor_start = 0; 217 + driver->type = TTY_DRIVER_TYPE_SYSTEM; 218 + driver->subtype = SYSTEM_TYPE_SYSCONS; 219 + driver->init_termios = tty_std_termios; 220 + tty_set_operations(driver, &srmcons_ops); 221 + tty_port_link_device(&srmcons_singleton.port, driver, 0); 222 + err = tty_register_driver(driver); 223 + if (err) 224 + goto err_free_drv; 225 + 226 + srmcons_driver = driver; 227 + 228 + return 0; 229 + err_free_drv: 230 + tty_driver_kref_put(driver); 231 + tty_port_destroy(&srmcons_singleton.port); 232 + 233 + return err; 234 } 235 device_initcall(srmcons_init); 236 237 /* 238 * The console driver 239 */
+1 -1
drivers/net/caif/caif_serial.c
··· 330 ser->tty = tty_kref_get(tty); 331 ser->dev = dev; 332 debugfs_init(ser, tty); 333 - tty->receive_room = N_TTY_BUF_SIZE; 334 tty->disc_data = ser; 335 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 336 rtnl_lock();
··· 330 ser->tty = tty_kref_get(tty); 331 ser->dev = dev; 332 debugfs_init(ser, tty); 333 + tty->receive_room = 4096; 334 tty->disc_data = ser; 335 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 336 rtnl_lock();
+2 -2
drivers/staging/greybus/uart.c
··· 948 { 949 int retval = 0; 950 951 - gb_tty_driver = tty_alloc_driver(GB_NUM_MINORS, 0); 952 if (IS_ERR(gb_tty_driver)) { 953 pr_err("Can not allocate tty driver\n"); 954 retval = -ENOMEM; ··· 962 gb_tty_driver->minor_start = 0; 963 gb_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; 964 gb_tty_driver->subtype = SERIAL_TYPE_NORMAL; 965 - gb_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 966 gb_tty_driver->init_termios = tty_std_termios; 967 gb_tty_driver->init_termios.c_cflag = B9600 | CS8 | 968 CREAD | HUPCL | CLOCAL;
··· 948 { 949 int retval = 0; 950 951 + gb_tty_driver = tty_alloc_driver(GB_NUM_MINORS, TTY_DRIVER_REAL_RAW | 952 + TTY_DRIVER_DYNAMIC_DEV); 953 if (IS_ERR(gb_tty_driver)) { 954 pr_err("Can not allocate tty driver\n"); 955 retval = -ENOMEM; ··· 961 gb_tty_driver->minor_start = 0; 962 gb_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; 963 gb_tty_driver->subtype = SERIAL_TYPE_NORMAL; 964 gb_tty_driver->init_termios = tty_std_termios; 965 gb_tty_driver->init_termios.c_cflag = B9600 | CS8 | 966 CREAD | HUPCL | CLOCAL;
+1 -1
drivers/tty/Kconfig
··· 210 211 config MOXA_INTELLIO 212 tristate "Moxa Intellio support" 213 - depends on SERIAL_NONSTANDARD && (ISA || EISA || PCI) 214 select FW_LOADER 215 help 216 Say Y here if you have a Moxa Intellio multiport serial card.
··· 210 211 config MOXA_INTELLIO 212 tristate "Moxa Intellio support" 213 + depends on SERIAL_NONSTANDARD && PCI 214 select FW_LOADER 215 help 216 Say Y here if you have a Moxa Intellio multiport serial card.
+6 -245
drivers/tty/moxa.c
··· 43 #include <linux/ratelimit.h> 44 45 #include <asm/io.h> 46 - #include <linux/uaccess.h> 47 - 48 - #define MOXA 0x400 49 - #define MOXA_GET_IQUEUE (MOXA + 1) /* get input buffered count */ 50 - #define MOXA_GET_OQUEUE (MOXA + 2) /* get output buffered count */ 51 - #define MOXA_GETDATACOUNT (MOXA + 23) 52 - #define MOXA_GET_IOQUEUE (MOXA + 27) 53 - #define MOXA_FLUSH_QUEUE (MOXA + 28) 54 - #define MOXA_GETMSTATUS (MOXA + 65) 55 56 /* 57 * System Configuration ··· 338 #define MX_PARMARK 0xA0 339 #define MX_PARSPACE 0x20 340 341 - #define MOXA_VERSION "6.0k" 342 - 343 #define MOXA_FW_HDRLEN 32 344 345 #define MOXAMAJOR 172 ··· 346 #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */ 347 #define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD) 348 349 - #define MOXA_IS_320(brd) ((brd)->boardType == MOXA_BOARD_C320_ISA || \ 350 - (brd)->boardType == MOXA_BOARD_C320_PCI) 351 - 352 - /* 353 - * Define the Moxa PCI vendor and device IDs. 354 - */ 355 - #define MOXA_BUS_TYPE_ISA 0 356 - #define MOXA_BUS_TYPE_PCI 1 357 358 enum { 359 MOXA_BOARD_C218_PCI = 1, 360 - MOXA_BOARD_C218_ISA, 361 MOXA_BOARD_C320_PCI, 362 - MOXA_BOARD_C320_ISA, 363 MOXA_BOARD_CP204J, 364 }; 365 366 static char *moxa_brdname[] = 367 { 368 "C218 Turbo PCI series", 369 - "C218 Turbo ISA series", 370 "C320 Turbo PCI series", 371 - "C320 Turbo ISA series", 372 "CP-204J series", 373 }; 374 375 - #ifdef CONFIG_PCI 376 static const struct pci_device_id moxa_pcibrds[] = { 377 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C218), 378 .driver_data = MOXA_BOARD_C218_PCI }, ··· 371 { 0 } 372 }; 373 MODULE_DEVICE_TABLE(pci, moxa_pcibrds); 374 - #endif /* CONFIG_PCI */ 375 376 struct moxa_port; 377 378 static struct moxa_board_conf { 379 int boardType; 380 int numPorts; 381 - int busType; 382 383 unsigned int ready; 384 ··· 387 void __iomem *intPend; 388 void __iomem *intTable; 389 } moxa_boards[MAX_BOARDS]; 390 - 391 - struct mxser_mstatus { 392 - tcflag_t cflag; 393 - int cts; 394 - int dsr; 395 - int ri; 396 - int dcd; 397 - }; 398 - 399 - struct moxaq_str { 400 - int inq; 401 - int outq; 402 - }; 403 404 struct moxa_port { 405 struct tty_port port; ··· 402 u8 lowChkFlag; 403 }; 404 405 - struct mon_str { 406 - int tick; 407 - int rxcnt[MAX_PORTS]; 408 - int txcnt[MAX_PORTS]; 409 - }; 410 - 411 /* statusflags */ 412 #define TXSTOPPED 1 413 #define LOWWAIT 2 ··· 411 #define WAKEUP_CHARS 256 412 413 static int ttymajor = MOXAMAJOR; 414 - static struct mon_str moxaLog; 415 static unsigned int moxaFuncTout = HZ / 2; 416 static unsigned int moxaLowWaterChk; 417 static DEFINE_MUTEX(moxa_openlock); 418 static DEFINE_SPINLOCK(moxa_lock); 419 - 420 - static unsigned long baseaddr[MAX_BOARDS]; 421 - static unsigned int type[MAX_BOARDS]; 422 - static unsigned int numports[MAX_BOARDS]; 423 - static struct tty_port moxa_service_port; 424 425 MODULE_AUTHOR("William Chen"); 426 MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver"); ··· 422 MODULE_FIRMWARE("c218tunx.cod"); 423 MODULE_FIRMWARE("cp204unx.cod"); 424 MODULE_FIRMWARE("c320tunx.cod"); 425 - 426 - module_param_array(type, uint, NULL, 0); 427 - MODULE_PARM_DESC(type, "card type: C218=2, C320=4"); 428 - module_param_hw_array(baseaddr, ulong, ioport, NULL, 0); 429 - MODULE_PARM_DESC(baseaddr, "base address"); 430 - module_param_array(numports, uint, NULL, 0); 431 - MODULE_PARM_DESC(numports, "numports (ignored for C218)"); 432 433 module_param(ttymajor, int, 0); 434 ··· 526 * TTY operations 527 */ 528 529 - static int moxa_ioctl(struct tty_struct *tty, 530 - unsigned int cmd, unsigned long arg) 531 - { 532 - struct moxa_port *ch = tty->driver_data; 533 - void __user *argp = (void __user *)arg; 534 - int status, ret = 0; 535 - 536 - if (tty->index == MAX_PORTS) { 537 - if (cmd != MOXA_GETDATACOUNT && cmd != MOXA_GET_IOQUEUE && 538 - cmd != MOXA_GETMSTATUS) 539 - return -EINVAL; 540 - } else if (!ch) 541 - return -ENODEV; 542 - 543 - switch (cmd) { 544 - case MOXA_GETDATACOUNT: 545 - moxaLog.tick = jiffies; 546 - if (copy_to_user(argp, &moxaLog, sizeof(moxaLog))) 547 - ret = -EFAULT; 548 - break; 549 - case MOXA_FLUSH_QUEUE: 550 - MoxaPortFlushData(ch, arg); 551 - break; 552 - case MOXA_GET_IOQUEUE: { 553 - struct moxaq_str __user *argm = argp; 554 - struct moxaq_str tmp; 555 - struct moxa_port *p; 556 - unsigned int i, j; 557 - 558 - for (i = 0; i < MAX_BOARDS; i++) { 559 - p = moxa_boards[i].ports; 560 - for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) { 561 - memset(&tmp, 0, sizeof(tmp)); 562 - spin_lock_bh(&moxa_lock); 563 - if (moxa_boards[i].ready) { 564 - tmp.inq = MoxaPortRxQueue(p); 565 - tmp.outq = MoxaPortTxQueue(p); 566 - } 567 - spin_unlock_bh(&moxa_lock); 568 - if (copy_to_user(argm, &tmp, sizeof(tmp))) 569 - return -EFAULT; 570 - } 571 - } 572 - break; 573 - } case MOXA_GET_OQUEUE: 574 - status = MoxaPortTxQueue(ch); 575 - ret = put_user(status, (unsigned long __user *)argp); 576 - break; 577 - case MOXA_GET_IQUEUE: 578 - status = MoxaPortRxQueue(ch); 579 - ret = put_user(status, (unsigned long __user *)argp); 580 - break; 581 - case MOXA_GETMSTATUS: { 582 - struct mxser_mstatus __user *argm = argp; 583 - struct mxser_mstatus tmp; 584 - struct moxa_port *p; 585 - unsigned int i, j; 586 - 587 - for (i = 0; i < MAX_BOARDS; i++) { 588 - p = moxa_boards[i].ports; 589 - for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) { 590 - struct tty_struct *ttyp; 591 - memset(&tmp, 0, sizeof(tmp)); 592 - spin_lock_bh(&moxa_lock); 593 - if (!moxa_boards[i].ready) { 594 - spin_unlock_bh(&moxa_lock); 595 - goto copy; 596 - } 597 - 598 - status = MoxaPortLineStatus(p); 599 - spin_unlock_bh(&moxa_lock); 600 - 601 - if (status & 1) 602 - tmp.cts = 1; 603 - if (status & 2) 604 - tmp.dsr = 1; 605 - if (status & 4) 606 - tmp.dcd = 1; 607 - 608 - ttyp = tty_port_tty_get(&p->port); 609 - if (!ttyp) 610 - tmp.cflag = p->cflag; 611 - else 612 - tmp.cflag = ttyp->termios.c_cflag; 613 - tty_kref_put(ttyp); 614 - copy: 615 - if (copy_to_user(argm, &tmp, sizeof(tmp))) 616 - return -EFAULT; 617 - } 618 - } 619 - break; 620 - } 621 - default: 622 - ret = -ENOIOCTLCMD; 623 - } 624 - return ret; 625 - } 626 - 627 static int moxa_break_ctl(struct tty_struct *tty, int state) 628 { 629 struct moxa_port *port = tty->driver_data; ··· 542 .write_room = moxa_write_room, 543 .flush_buffer = moxa_flush_buffer, 544 .chars_in_buffer = moxa_chars_in_buffer, 545 - .ioctl = moxa_ioctl, 546 .set_termios = moxa_set_termios, 547 .stop = moxa_stop, 548 .start = moxa_start, ··· 569 static int moxa_check_fw_model(struct moxa_board_conf *brd, u8 model) 570 { 571 switch (brd->boardType) { 572 - case MOXA_BOARD_C218_ISA: 573 case MOXA_BOARD_C218_PCI: 574 if (model != 1) 575 goto err; ··· 612 msleep(2000); 613 614 switch (brd->boardType) { 615 - case MOXA_BOARD_C218_ISA: 616 case MOXA_BOARD_C218_PCI: 617 tmp = readw(baseAddr + C218_key); 618 if (tmp != C218_KeyCode) ··· 675 676 switch (brd->boardType) { 677 case MOXA_BOARD_CP204J: 678 - case MOXA_BOARD_C218_ISA: 679 case MOXA_BOARD_C218_PCI: 680 key = C218_key; 681 loadbuf = C218_LoadBuf; ··· 739 return -EIO; 740 741 if (MOXA_IS_320(brd)) { 742 - if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */ 743 - writew(0x3800, baseAddr + TMS320_PORT1); 744 - writew(0x3900, baseAddr + TMS320_PORT2); 745 - writew(28499, baseAddr + TMS320_CLOCK); 746 - } else { 747 - writew(0x3200, baseAddr + TMS320_PORT1); 748 - writew(0x3400, baseAddr + TMS320_PORT2); 749 - writew(19999, baseAddr + TMS320_CLOCK); 750 - } 751 } 752 writew(1, baseAddr + Disable_IRQ); 753 writew(0, baseAddr + Magic_no); ··· 792 return retval; 793 794 switch (brd->boardType) { 795 - case MOXA_BOARD_C218_ISA: 796 case MOXA_BOARD_C218_PCI: 797 case MOXA_BOARD_CP204J: 798 port = brd->ports; ··· 975 } 976 977 switch (brd->boardType) { 978 - case MOXA_BOARD_C218_ISA: 979 case MOXA_BOARD_C218_PCI: 980 file = "c218tunx.cod"; 981 break; ··· 1060 kfree(brd->ports); 1061 } 1062 1063 - #ifdef CONFIG_PCI 1064 static int moxa_pci_probe(struct pci_dev *pdev, 1065 const struct pci_device_id *ent) 1066 { ··· 1102 1103 board->boardType = board_type; 1104 switch (board_type) { 1105 - case MOXA_BOARD_C218_ISA: 1106 case MOXA_BOARD_C218_PCI: 1107 board->numPorts = 8; 1108 break; ··· 1113 board->numPorts = 0; 1114 break; 1115 } 1116 - board->busType = MOXA_BUS_TYPE_PCI; 1117 1118 retval = moxa_init_board(board, &pdev->dev); 1119 if (retval) ··· 1148 .probe = moxa_pci_probe, 1149 .remove = moxa_pci_remove 1150 }; 1151 - #endif /* CONFIG_PCI */ 1152 1153 static int __init moxa_init(void) 1154 { 1155 - unsigned int isabrds = 0; 1156 int retval = 0; 1157 - struct moxa_board_conf *brd = moxa_boards; 1158 - unsigned int i; 1159 1160 - printk(KERN_INFO "MOXA Intellio family driver version %s\n", 1161 - MOXA_VERSION); 1162 - 1163 - tty_port_init(&moxa_service_port); 1164 - 1165 - moxaDriver = tty_alloc_driver(MAX_PORTS + 1, 1166 TTY_DRIVER_REAL_RAW | 1167 TTY_DRIVER_DYNAMIC_DEV); 1168 if (IS_ERR(moxaDriver)) ··· 1169 moxaDriver->init_termios.c_ispeed = 9600; 1170 moxaDriver->init_termios.c_ospeed = 9600; 1171 tty_set_operations(moxaDriver, &moxa_ops); 1172 - /* Having one more port only for ioctls is ugly */ 1173 - tty_port_link_device(&moxa_service_port, moxaDriver, MAX_PORTS); 1174 1175 if (tty_register_driver(moxaDriver)) { 1176 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n"); ··· 1176 return -1; 1177 } 1178 1179 - /* Find the boards defined from module args. */ 1180 - 1181 - for (i = 0; i < MAX_BOARDS; i++) { 1182 - if (!baseaddr[i]) 1183 - break; 1184 - if (type[i] == MOXA_BOARD_C218_ISA || 1185 - type[i] == MOXA_BOARD_C320_ISA) { 1186 - pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n", 1187 - isabrds + 1, moxa_brdname[type[i] - 1], 1188 - baseaddr[i]); 1189 - brd->boardType = type[i]; 1190 - brd->numPorts = type[i] == MOXA_BOARD_C218_ISA ? 8 : 1191 - numports[i]; 1192 - brd->busType = MOXA_BUS_TYPE_ISA; 1193 - brd->basemem = ioremap(baseaddr[i], 0x4000); 1194 - if (!brd->basemem) { 1195 - printk(KERN_ERR "MOXA: can't remap %lx\n", 1196 - baseaddr[i]); 1197 - continue; 1198 - } 1199 - if (moxa_init_board(brd, NULL)) { 1200 - iounmap(brd->basemem); 1201 - brd->basemem = NULL; 1202 - continue; 1203 - } 1204 - 1205 - printk(KERN_INFO "MOXA isa board found at 0x%.8lx and " 1206 - "ready (%u ports, firmware loaded)\n", 1207 - baseaddr[i], brd->numPorts); 1208 - 1209 - brd++; 1210 - isabrds++; 1211 - } 1212 - } 1213 - 1214 - #ifdef CONFIG_PCI 1215 retval = pci_register_driver(&moxa_pci_driver); 1216 - if (retval) { 1217 printk(KERN_ERR "Can't register MOXA pci driver!\n"); 1218 - if (isabrds) 1219 - retval = 0; 1220 - } 1221 - #endif 1222 1223 return retval; 1224 } 1225 1226 static void __exit moxa_exit(void) 1227 { 1228 - unsigned int i; 1229 - 1230 - #ifdef CONFIG_PCI 1231 pci_unregister_driver(&moxa_pci_driver); 1232 - #endif 1233 - 1234 - for (i = 0; i < MAX_BOARDS; i++) /* ISA boards */ 1235 - if (moxa_boards[i].ready) 1236 - moxa_board_deinit(&moxa_boards[i]); 1237 1238 del_timer_sync(&moxaTimer); 1239 ··· 1228 int port; 1229 1230 port = tty->index; 1231 - if (port == MAX_PORTS) { 1232 - return capable(CAP_SYS_ADMIN) ? 0 : -EPERM; 1233 - } 1234 if (mutex_lock_interruptible(&moxa_openlock)) 1235 return -ERESTARTSYS; 1236 brd = &moxa_boards[port / MAX_PORTS_PER_BOARD]; ··· 1950 c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask); 1951 if (c > len) 1952 c = len; 1953 - moxaLog.txcnt[port->port.tty->index] += c; 1954 total = c; 1955 if (spage == epage) { 1956 bufhead = readw(ofsAddr + Ofs_txb); ··· 1991 1992 static int MoxaPortReadData(struct moxa_port *port) 1993 { 1994 - struct tty_struct *tty = port->port.tty; 1995 void __iomem *baseAddr, *ofsAddr, *ofs; 1996 u8 *dst; 1997 unsigned int count, len, total; ··· 2009 return 0; 2010 2011 total = count; 2012 - moxaLog.rxcnt[tty->index] += total; 2013 if (spage == epage) { 2014 bufhead = readw(ofsAddr + Ofs_rxb); 2015 writew(spage, baseAddr + Control_reg); ··· 2096 { 2097 struct moxa_port *info = tty->driver_data; 2098 2099 - if (tty->index == MAX_PORTS) 2100 - return -EINVAL; 2101 if (!info) 2102 return -ENODEV; 2103 mutex_lock(&info->port.mutex); ··· 2115 struct moxa_port *info = tty->driver_data; 2116 unsigned int close_delay; 2117 2118 - if (tty->index == MAX_PORTS) 2119 - return -EINVAL; 2120 if (!info) 2121 return -ENODEV; 2122
··· 43 #include <linux/ratelimit.h> 44 45 #include <asm/io.h> 46 47 /* 48 * System Configuration ··· 347 #define MX_PARMARK 0xA0 348 #define MX_PARSPACE 0x20 349 350 #define MOXA_FW_HDRLEN 32 351 352 #define MOXAMAJOR 172 ··· 357 #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */ 358 #define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD) 359 360 + #define MOXA_IS_320(brd) ((brd)->boardType == MOXA_BOARD_C320_PCI) 361 362 enum { 363 MOXA_BOARD_C218_PCI = 1, 364 MOXA_BOARD_C320_PCI, 365 MOXA_BOARD_CP204J, 366 }; 367 368 static char *moxa_brdname[] = 369 { 370 "C218 Turbo PCI series", 371 "C320 Turbo PCI series", 372 "CP-204J series", 373 }; 374 375 static const struct pci_device_id moxa_pcibrds[] = { 376 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C218), 377 .driver_data = MOXA_BOARD_C218_PCI }, ··· 394 { 0 } 395 }; 396 MODULE_DEVICE_TABLE(pci, moxa_pcibrds); 397 398 struct moxa_port; 399 400 static struct moxa_board_conf { 401 int boardType; 402 int numPorts; 403 404 unsigned int ready; 405 ··· 412 void __iomem *intPend; 413 void __iomem *intTable; 414 } moxa_boards[MAX_BOARDS]; 415 416 struct moxa_port { 417 struct tty_port port; ··· 440 u8 lowChkFlag; 441 }; 442 443 /* statusflags */ 444 #define TXSTOPPED 1 445 #define LOWWAIT 2 ··· 455 #define WAKEUP_CHARS 256 456 457 static int ttymajor = MOXAMAJOR; 458 static unsigned int moxaFuncTout = HZ / 2; 459 static unsigned int moxaLowWaterChk; 460 static DEFINE_MUTEX(moxa_openlock); 461 static DEFINE_SPINLOCK(moxa_lock); 462 463 MODULE_AUTHOR("William Chen"); 464 MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver"); ··· 472 MODULE_FIRMWARE("c218tunx.cod"); 473 MODULE_FIRMWARE("cp204unx.cod"); 474 MODULE_FIRMWARE("c320tunx.cod"); 475 476 module_param(ttymajor, int, 0); 477 ··· 583 * TTY operations 584 */ 585 586 static int moxa_break_ctl(struct tty_struct *tty, int state) 587 { 588 struct moxa_port *port = tty->driver_data; ··· 697 .write_room = moxa_write_room, 698 .flush_buffer = moxa_flush_buffer, 699 .chars_in_buffer = moxa_chars_in_buffer, 700 .set_termios = moxa_set_termios, 701 .stop = moxa_stop, 702 .start = moxa_start, ··· 725 static int moxa_check_fw_model(struct moxa_board_conf *brd, u8 model) 726 { 727 switch (brd->boardType) { 728 case MOXA_BOARD_C218_PCI: 729 if (model != 1) 730 goto err; ··· 769 msleep(2000); 770 771 switch (brd->boardType) { 772 case MOXA_BOARD_C218_PCI: 773 tmp = readw(baseAddr + C218_key); 774 if (tmp != C218_KeyCode) ··· 833 834 switch (brd->boardType) { 835 case MOXA_BOARD_CP204J: 836 case MOXA_BOARD_C218_PCI: 837 key = C218_key; 838 loadbuf = C218_LoadBuf; ··· 898 return -EIO; 899 900 if (MOXA_IS_320(brd)) { 901 + writew(0x3800, baseAddr + TMS320_PORT1); 902 + writew(0x3900, baseAddr + TMS320_PORT2); 903 + writew(28499, baseAddr + TMS320_CLOCK); 904 } 905 writew(1, baseAddr + Disable_IRQ); 906 writew(0, baseAddr + Magic_no); ··· 957 return retval; 958 959 switch (brd->boardType) { 960 case MOXA_BOARD_C218_PCI: 961 case MOXA_BOARD_CP204J: 962 port = brd->ports; ··· 1141 } 1142 1143 switch (brd->boardType) { 1144 case MOXA_BOARD_C218_PCI: 1145 file = "c218tunx.cod"; 1146 break; ··· 1227 kfree(brd->ports); 1228 } 1229 1230 static int moxa_pci_probe(struct pci_dev *pdev, 1231 const struct pci_device_id *ent) 1232 { ··· 1270 1271 board->boardType = board_type; 1272 switch (board_type) { 1273 case MOXA_BOARD_C218_PCI: 1274 board->numPorts = 8; 1275 break; ··· 1282 board->numPorts = 0; 1283 break; 1284 } 1285 1286 retval = moxa_init_board(board, &pdev->dev); 1287 if (retval) ··· 1318 .probe = moxa_pci_probe, 1319 .remove = moxa_pci_remove 1320 }; 1321 1322 static int __init moxa_init(void) 1323 { 1324 int retval = 0; 1325 1326 + moxaDriver = tty_alloc_driver(MAX_PORTS, 1327 TTY_DRIVER_REAL_RAW | 1328 TTY_DRIVER_DYNAMIC_DEV); 1329 if (IS_ERR(moxaDriver)) ··· 1348 moxaDriver->init_termios.c_ispeed = 9600; 1349 moxaDriver->init_termios.c_ospeed = 9600; 1350 tty_set_operations(moxaDriver, &moxa_ops); 1351 1352 if (tty_register_driver(moxaDriver)) { 1353 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n"); ··· 1357 return -1; 1358 } 1359 1360 retval = pci_register_driver(&moxa_pci_driver); 1361 + if (retval) 1362 printk(KERN_ERR "Can't register MOXA pci driver!\n"); 1363 1364 return retval; 1365 } 1366 1367 static void __exit moxa_exit(void) 1368 { 1369 pci_unregister_driver(&moxa_pci_driver); 1370 1371 del_timer_sync(&moxaTimer); 1372 ··· 1457 int port; 1458 1459 port = tty->index; 1460 if (mutex_lock_interruptible(&moxa_openlock)) 1461 return -ERESTARTSYS; 1462 brd = &moxa_boards[port / MAX_PORTS_PER_BOARD]; ··· 2182 c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask); 2183 if (c > len) 2184 c = len; 2185 total = c; 2186 if (spage == epage) { 2187 bufhead = readw(ofsAddr + Ofs_txb); ··· 2224 2225 static int MoxaPortReadData(struct moxa_port *port) 2226 { 2227 void __iomem *baseAddr, *ofsAddr, *ofs; 2228 u8 *dst; 2229 unsigned int count, len, total; ··· 2243 return 0; 2244 2245 total = count; 2246 if (spage == epage) { 2247 bufhead = readw(ofsAddr + Ofs_rxb); 2248 writew(spage, baseAddr + Control_reg); ··· 2331 { 2332 struct moxa_port *info = tty->driver_data; 2333 2334 if (!info) 2335 return -ENODEV; 2336 mutex_lock(&info->port.mutex); ··· 2352 struct moxa_port *info = tty->driver_data; 2353 unsigned int close_delay; 2354 2355 if (!info) 2356 return -ENODEV; 2357
+100 -112
drivers/tty/n_tty.c
··· 56 */ 57 #define WAKEUP_CHARS 256 58 59 /* 60 * This defines the low- and high-watermarks for throttling and 61 * unthrottling the TTY driver. These watermarks are used for ··· 80 #define ECHO_COMMIT_WATERMARK 256 81 #define ECHO_BLOCK 256 82 #define ECHO_DISCARD_WATERMARK N_TTY_BUF_SIZE - (ECHO_BLOCK + 32) 83 - 84 - 85 - #undef N_TTY_TRACE 86 - #ifdef N_TTY_TRACE 87 - # define n_tty_trace(f, args...) trace_printk(f, ##args) 88 - #else 89 - # define n_tty_trace(f, args...) no_printk(f, ##args) 90 - #endif 91 92 struct n_tty_data { 93 /* producer-published */ ··· 480 static int process_output(u8 c, struct tty_struct *tty) 481 { 482 struct n_tty_data *ldata = tty->disc_data; 483 - int space, retval; 484 485 - mutex_lock(&ldata->output_lock); 486 487 - space = tty_write_room(tty); 488 - retval = do_output_char(c, tty, space); 489 - 490 - mutex_unlock(&ldata->output_lock); 491 - if (retval < 0) 492 return -1; 493 - else 494 - return 0; 495 } 496 497 /** ··· 511 const u8 *buf, unsigned int nr) 512 { 513 struct n_tty_data *ldata = tty->disc_data; 514 - int space; 515 - int i; 516 const u8 *cp; 517 518 - mutex_lock(&ldata->output_lock); 519 520 space = tty_write_room(tty); 521 - if (space <= 0) { 522 - mutex_unlock(&ldata->output_lock); 523 - return space; 524 - } 525 if (nr > space) 526 nr = space; 527 ··· 531 if (O_ONLRET(tty)) 532 ldata->column = 0; 533 if (O_ONLCR(tty)) 534 - goto break_out; 535 ldata->canon_column = ldata->column; 536 break; 537 case '\r': 538 if (O_ONOCR(tty) && ldata->column == 0) 539 - goto break_out; 540 if (O_OCRNL(tty)) 541 - goto break_out; 542 ldata->canon_column = ldata->column = 0; 543 break; 544 case '\t': 545 - goto break_out; 546 case '\b': 547 if (ldata->column > 0) 548 ldata->column--; ··· 550 default: 551 if (!iscntrl(c)) { 552 if (O_OLCUC(tty)) 553 - goto break_out; 554 if (!is_continuation(c, tty)) 555 ldata->column++; 556 } 557 break; 558 } 559 } 560 - break_out: 561 - i = tty->ops->write(tty, buf, i); 562 - 563 - mutex_unlock(&ldata->output_lock); 564 - return i; 565 } 566 567 static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail, ··· 680 static size_t __process_echoes(struct tty_struct *tty) 681 { 682 struct n_tty_data *ldata = tty->disc_data; 683 - int space, old_space; 684 size_t tail; 685 u8 c; 686 ··· 2018 tail = MASK(ldata->read_tail); 2019 size = min_t(size_t, tail + n, N_TTY_BUF_SIZE); 2020 2021 - n_tty_trace("%s: nr:%zu tail:%zu n:%zu size:%zu\n", 2022 - __func__, *nr, tail, n, size); 2023 - 2024 eol = find_next_bit(ldata->read_flags, size, tail); 2025 more = n - (size - tail); 2026 if (eol == N_TTY_BUF_SIZE && more) { ··· 2034 2035 if (!found || read_buf(ldata, eol) != __DISABLED_CHAR) 2036 n = c; 2037 - 2038 - n_tty_trace("%s: eol:%zu found:%d n:%zu c:%zu tail:%zu more:%zu\n", 2039 - __func__, eol, found, n, c, tail, more); 2040 2041 tty_copy(tty, *kbp, tail, n); 2042 *kbp += n; ··· 2111 return __tty_check_change(tty, SIGTTIN); 2112 } 2113 2114 2115 /** 2116 * n_tty_read - read function for tty ··· 2204 bool packet; 2205 size_t old_tail; 2206 2207 - /* 2208 - * Is this a continuation of a read started earler? 2209 - * 2210 - * If so, we still hold the atomic_read_lock and the 2211 - * termios_rwsem, and can just continue to copy data. 2212 - */ 2213 - if (*cookie) { 2214 - if (ldata->icanon && !L_EXTPROC(tty)) { 2215 - /* 2216 - * If we have filled the user buffer, see 2217 - * if we should skip an EOF character before 2218 - * releasing the lock and returning done. 2219 - */ 2220 - if (!nr) 2221 - canon_skip_eof(ldata); 2222 - else if (canon_copy_from_read_buf(tty, &kb, &nr)) 2223 - return kb - kbuf; 2224 - } else { 2225 - if (copy_from_read_buf(tty, &kb, &nr)) 2226 - return kb - kbuf; 2227 - } 2228 - 2229 - /* No more data - release locks and stop retries */ 2230 - n_tty_kick_worker(tty); 2231 - n_tty_check_unthrottle(tty); 2232 - up_read(&tty->termios_rwsem); 2233 - mutex_unlock(&ldata->atomic_read_lock); 2234 - *cookie = NULL; 2235 - return kb - kbuf; 2236 - } 2237 2238 retval = job_control(tty, file); 2239 if (retval < 0) ··· 2261 tty_buffer_flush_work(tty->port); 2262 down_read(&tty->termios_rwsem); 2263 if (!input_available_p(tty, 0)) { 2264 - if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 2265 - retval = -EIO; 2266 break; 2267 } 2268 - if (tty_hung_up_p(file)) 2269 - break; 2270 - /* 2271 - * Abort readers for ttys which never actually 2272 - * get hung up. See __tty_hangup(). 2273 - */ 2274 - if (test_bit(TTY_HUPPING, &tty->flags)) 2275 - break; 2276 - if (!timeout) 2277 - break; 2278 - if (tty_io_nonblock(tty, file)) { 2279 - retval = -EAGAIN; 2280 - break; 2281 - } 2282 - if (signal_pending(current)) { 2283 - retval = -ERESTARTSYS; 2284 - break; 2285 - } 2286 - up_read(&tty->termios_rwsem); 2287 - 2288 - timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, 2289 - timeout); 2290 - 2291 - down_read(&tty->termios_rwsem); 2292 continue; 2293 } 2294 } ··· 2281 nr--; 2282 } 2283 2284 - /* 2285 - * Copy data, and if there is more to be had 2286 - * and we have nothing more to wait for, then 2287 - * let's mark us for retries. 2288 - * 2289 - * NOTE! We return here with both the termios_sem 2290 - * and atomic_read_lock still held, the retries 2291 - * will release them when done. 2292 - */ 2293 - if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) { 2294 - more_to_be_read: 2295 - remove_wait_queue(&tty->read_wait, &wait); 2296 - *cookie = cookie; 2297 - return kb - kbuf; 2298 - } 2299 } 2300 2301 n_tty_check_unthrottle(tty); ··· 2309 retval = kb - kbuf; 2310 2311 return retval; 2312 } 2313 2314 /**
··· 56 */ 57 #define WAKEUP_CHARS 256 58 59 + #define N_TTY_BUF_SIZE 4096 60 + 61 /* 62 * This defines the low- and high-watermarks for throttling and 63 * unthrottling the TTY driver. These watermarks are used for ··· 78 #define ECHO_COMMIT_WATERMARK 256 79 #define ECHO_BLOCK 256 80 #define ECHO_DISCARD_WATERMARK N_TTY_BUF_SIZE - (ECHO_BLOCK + 32) 81 82 struct n_tty_data { 83 /* producer-published */ ··· 486 static int process_output(u8 c, struct tty_struct *tty) 487 { 488 struct n_tty_data *ldata = tty->disc_data; 489 490 + guard(mutex)(&ldata->output_lock); 491 492 + if (do_output_char(c, tty, tty_write_room(tty)) < 0) 493 return -1; 494 + 495 + return 0; 496 } 497 498 /** ··· 522 const u8 *buf, unsigned int nr) 523 { 524 struct n_tty_data *ldata = tty->disc_data; 525 + unsigned int space, i; 526 const u8 *cp; 527 528 + guard(mutex)(&ldata->output_lock); 529 530 space = tty_write_room(tty); 531 + if (space == 0) 532 + return 0; 533 + 534 if (nr > space) 535 nr = space; 536 ··· 544 if (O_ONLRET(tty)) 545 ldata->column = 0; 546 if (O_ONLCR(tty)) 547 + goto do_write; 548 ldata->canon_column = ldata->column; 549 break; 550 case '\r': 551 if (O_ONOCR(tty) && ldata->column == 0) 552 + goto do_write; 553 if (O_OCRNL(tty)) 554 + goto do_write; 555 ldata->canon_column = ldata->column = 0; 556 break; 557 case '\t': 558 + goto do_write; 559 case '\b': 560 if (ldata->column > 0) 561 ldata->column--; ··· 563 default: 564 if (!iscntrl(c)) { 565 if (O_OLCUC(tty)) 566 + goto do_write; 567 if (!is_continuation(c, tty)) 568 ldata->column++; 569 } 570 break; 571 } 572 } 573 + do_write: 574 + return tty->ops->write(tty, buf, i); 575 } 576 577 static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail, ··· 696 static size_t __process_echoes(struct tty_struct *tty) 697 { 698 struct n_tty_data *ldata = tty->disc_data; 699 + unsigned int space, old_space; 700 size_t tail; 701 u8 c; 702 ··· 2034 tail = MASK(ldata->read_tail); 2035 size = min_t(size_t, tail + n, N_TTY_BUF_SIZE); 2036 2037 eol = find_next_bit(ldata->read_flags, size, tail); 2038 more = n - (size - tail); 2039 if (eol == N_TTY_BUF_SIZE && more) { ··· 2053 2054 if (!found || read_buf(ldata, eol) != __DISABLED_CHAR) 2055 n = c; 2056 2057 tty_copy(tty, *kbp, tail, n); 2058 *kbp += n; ··· 2133 return __tty_check_change(tty, SIGTTIN); 2134 } 2135 2136 + /* 2137 + * We still hold the atomic_read_lock and the termios_rwsem, and can just 2138 + * continue to copy data. 2139 + */ 2140 + static ssize_t n_tty_continue_cookie(struct tty_struct *tty, u8 *kbuf, 2141 + size_t nr, void **cookie) 2142 + { 2143 + struct n_tty_data *ldata = tty->disc_data; 2144 + u8 *kb = kbuf; 2145 + 2146 + if (ldata->icanon && !L_EXTPROC(tty)) { 2147 + /* 2148 + * If we have filled the user buffer, see if we should skip an 2149 + * EOF character before releasing the lock and returning done. 2150 + */ 2151 + if (!nr) 2152 + canon_skip_eof(ldata); 2153 + else if (canon_copy_from_read_buf(tty, &kb, &nr)) 2154 + return kb - kbuf; 2155 + } else { 2156 + if (copy_from_read_buf(tty, &kb, &nr)) 2157 + return kb - kbuf; 2158 + } 2159 + 2160 + /* No more data - release locks and stop retries */ 2161 + n_tty_kick_worker(tty); 2162 + n_tty_check_unthrottle(tty); 2163 + up_read(&tty->termios_rwsem); 2164 + mutex_unlock(&ldata->atomic_read_lock); 2165 + *cookie = NULL; 2166 + 2167 + return kb - kbuf; 2168 + } 2169 + 2170 + static int n_tty_wait_for_input(struct tty_struct *tty, struct file *file, 2171 + struct wait_queue_entry *wait, long *timeout) 2172 + { 2173 + if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) 2174 + return -EIO; 2175 + if (tty_hung_up_p(file)) 2176 + return 0; 2177 + /* 2178 + * Abort readers for ttys which never actually get hung up. 2179 + * See __tty_hangup(). 2180 + */ 2181 + if (test_bit(TTY_HUPPING, &tty->flags)) 2182 + return 0; 2183 + if (!*timeout) 2184 + return 0; 2185 + if (tty_io_nonblock(tty, file)) 2186 + return -EAGAIN; 2187 + if (signal_pending(current)) 2188 + return -ERESTARTSYS; 2189 + 2190 + up_read(&tty->termios_rwsem); 2191 + *timeout = wait_woken(wait, TASK_INTERRUPTIBLE, *timeout); 2192 + down_read(&tty->termios_rwsem); 2193 + 2194 + return 1; 2195 + } 2196 2197 /** 2198 * n_tty_read - read function for tty ··· 2166 bool packet; 2167 size_t old_tail; 2168 2169 + /* Is this a continuation of a read started earlier? */ 2170 + if (*cookie) 2171 + return n_tty_continue_cookie(tty, kbuf, nr, cookie); 2172 2173 retval = job_control(tty, file); 2174 if (retval < 0) ··· 2250 tty_buffer_flush_work(tty->port); 2251 down_read(&tty->termios_rwsem); 2252 if (!input_available_p(tty, 0)) { 2253 + int ret = n_tty_wait_for_input(tty, file, &wait, 2254 + &timeout); 2255 + if (ret <= 0) { 2256 + retval = ret; 2257 break; 2258 } 2259 continue; 2260 } 2261 } ··· 2292 nr--; 2293 } 2294 2295 + if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) 2296 + goto more_to_be_read; 2297 } 2298 2299 n_tty_check_unthrottle(tty); ··· 2333 retval = kb - kbuf; 2334 2335 return retval; 2336 + more_to_be_read: 2337 + /* 2338 + * There is more to be had and we have nothing more to wait for, so 2339 + * let's mark us for retries. 2340 + * 2341 + * NOTE! We return here with both the termios_sem and atomic_read_lock 2342 + * still held, the retries will release them when done. 2343 + */ 2344 + remove_wait_queue(&tty->read_wait, &wait); 2345 + *cookie = cookie; 2346 + 2347 + return kb - kbuf; 2348 } 2349 2350 /**
-11
drivers/tty/serdev/core.c
··· 316 } 317 EXPORT_SYMBOL_GPL(serdev_device_write_flush); 318 319 - int serdev_device_write_room(struct serdev_device *serdev) 320 - { 321 - struct serdev_controller *ctrl = serdev->ctrl; 322 - 323 - if (!ctrl || !ctrl->ops->write_room) 324 - return 0; 325 - 326 - return serdev->ctrl->ops->write_room(ctrl); 327 - } 328 - EXPORT_SYMBOL_GPL(serdev_device_write_room); 329 - 330 unsigned int serdev_device_set_baudrate(struct serdev_device *serdev, unsigned int speed) 331 { 332 struct serdev_controller *ctrl = serdev->ctrl;
··· 316 } 317 EXPORT_SYMBOL_GPL(serdev_device_write_flush); 318 319 unsigned int serdev_device_set_baudrate(struct serdev_device *serdev, unsigned int speed) 320 { 321 struct serdev_controller *ctrl = serdev->ctrl;
-9
drivers/tty/serdev/serdev-ttyport.c
··· 92 tty_driver_flush_buffer(tty); 93 } 94 95 - static int ttyport_write_room(struct serdev_controller *ctrl) 96 - { 97 - struct serport *serport = serdev_controller_get_drvdata(ctrl); 98 - struct tty_struct *tty = serport->tty; 99 - 100 - return tty_write_room(tty); 101 - } 102 - 103 static int ttyport_open(struct serdev_controller *ctrl) 104 { 105 struct serport *serport = serdev_controller_get_drvdata(ctrl); ··· 251 static const struct serdev_controller_ops ctrl_ops = { 252 .write_buf = ttyport_write_buf, 253 .write_flush = ttyport_write_flush, 254 - .write_room = ttyport_write_room, 255 .open = ttyport_open, 256 .close = ttyport_close, 257 .set_flow_control = ttyport_set_flow_control,
··· 92 tty_driver_flush_buffer(tty); 93 } 94 95 static int ttyport_open(struct serdev_controller *ctrl) 96 { 97 struct serport *serport = serdev_controller_get_drvdata(ctrl); ··· 259 static const struct serdev_controller_ops ctrl_ops = { 260 .write_buf = ttyport_write_buf, 261 .write_flush = ttyport_write_flush, 262 .open = ttyport_open, 263 .close = ttyport_close, 264 .set_flow_control = ttyport_set_flow_control,
+1 -1
drivers/tty/serial/8250/8250_dma.c
··· 162 */ 163 dma->tx_size = 0; 164 165 - dmaengine_terminate_async(dma->rxchan); 166 } 167 168 int serial8250_rx_dma(struct uart_8250_port *p)
··· 162 */ 163 dma->tx_size = 0; 164 165 + dmaengine_terminate_async(dma->txchan); 166 } 167 168 int serial8250_rx_dma(struct uart_8250_port *p)
+48 -25
drivers/tty/serial/8250/8250_dw.c
··· 107 return value; 108 } 109 110 static void dw8250_force_idle(struct uart_port *p) 111 { 112 struct uart_8250_port *up = up_to_u8250p(p); 113 unsigned int lsr; 114 115 serial8250_clear_and_reinit_fifos(up); 116 117 /* ··· 132 * enabled. 133 */ 134 if (up->fcr & UART_FCR_ENABLE_FIFO) { 135 - lsr = p->serial_in(p, UART_LSR); 136 if (!(lsr & UART_LSR_DR)) 137 return; 138 } 139 140 - (void)p->serial_in(p, UART_RX); 141 } 142 143 static void dw8250_check_lcr(struct uart_port *p, int offset, int value) 144 { 145 struct dw8250_data *d = to_dw8250_data(p->private_data); ··· 156 157 /* Make sure LCR write wasn't ignored */ 158 while (tries--) { 159 - unsigned int lcr = p->serial_in(p, offset); 160 161 if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR)) 162 return; ··· 277 { 278 struct uart_8250_port *up = up_to_u8250p(p); 279 struct dw8250_data *d = to_dw8250_data(p->private_data); 280 - unsigned int iir = p->serial_in(p, UART_IIR); 281 bool rx_timeout = (iir & 0x3f) == UART_IIR_RX_TIMEOUT; 282 unsigned int quirks = d->pdata->quirks; 283 unsigned int status; ··· 298 status = serial_lsr_in(up); 299 300 if (!(status & (UART_LSR_DR | UART_LSR_BI))) 301 - (void) p->serial_in(p, UART_RX); 302 303 uart_port_unlock_irqrestore(p, flags); 304 } ··· 320 321 if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) { 322 /* Clear the USR */ 323 - (void)p->serial_in(p, d->pdata->usr_reg); 324 325 return 1; 326 } ··· 407 static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios) 408 { 409 struct uart_8250_port *up = up_to_u8250p(p); 410 - unsigned int mcr = p->serial_in(p, UART_MCR); 411 412 if (up->capabilities & UART_CAP_IRDA) { 413 if (termios->c_line == N_IRDA) ··· 415 else 416 mcr &= ~DW_UART_MCR_SIRE; 417 418 - p->serial_out(p, UART_MCR, mcr); 419 } 420 serial8250_do_set_ldisc(p, termios); 421 } ··· 436 static bool dw8250_idma_filter(struct dma_chan *chan, void *param) 437 { 438 return param == chan->device->dev; 439 } 440 441 static u32 dw8250_rzn1_get_dmacr_burst(int max_burst) ··· 488 489 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data) 490 { 491 - unsigned int quirks = data->pdata ? data->pdata->quirks : 0; 492 - u32 cpr_value = data->pdata ? data->pdata->cpr_value : 0; 493 494 if (quirks & DW_UART_QUIRK_CPR_VALUE) 495 data->data.cpr_value = cpr_value; ··· 520 p->serial_in = dw8250_serial_in32; 521 data->uart_16550_compatible = true; 522 } 523 - 524 - /* Platforms with iDMA 64-bit */ 525 - if (platform_get_resource_byname(to_platform_device(p->dev), 526 - IORESOURCE_MEM, "lpss_priv")) { 527 - data->data.dma.rx_param = p->dev->parent; 528 - data->data.dma.tx_param = p->dev->parent; 529 - data->data.dma.fn = dw8250_idma_filter; 530 - } 531 } 532 533 static void dw8250_reset_control_assert(void *data) ··· 541 return dev_err_probe(dev, -EINVAL, "no registers defined\n"); 542 543 spin_lock_init(&p->lock); 544 - p->handle_irq = dw8250_handle_irq; 545 p->pm = dw8250_do_pm; 546 p->type = PORT_8250; 547 p->flags = UPF_FIXED_PORT; ··· 552 if (!data) 553 return -ENOMEM; 554 555 - data->data.dma.fn = dw8250_fallback_dma_filter; 556 - data->pdata = device_get_match_data(p->dev); 557 p->private_data = &data->data; 558 - 559 - data->uart_16550_compatible = device_property_read_bool(dev, 560 - "snps,uart-16550-compatible"); 561 562 p->mapbase = regs->start; 563 p->mapsize = resource_size(regs); ··· 641 if (err) 642 return err; 643 644 - dw8250_quirks(p, data); 645 646 /* If the Busy Functionality is not implemented, don't handle it */ 647 if (data->uart_16550_compatible) 648 p->handle_irq = NULL; 649 650 if (!data->skip_autocfg) 651 dw8250_setup_port(p);
··· 107 return value; 108 } 109 110 + /* 111 + * This function is being called as part of the uart_port::serial_out() 112 + * routine. Hence, it must not call serial_port_out() or serial_out() 113 + * against the modified registers here, i.e. LCR. 114 + */ 115 static void dw8250_force_idle(struct uart_port *p) 116 { 117 struct uart_8250_port *up = up_to_u8250p(p); 118 unsigned int lsr; 119 120 + /* 121 + * The following call currently performs serial_out() 122 + * against the FCR register. Because it differs to LCR 123 + * there will be no infinite loop, but if it ever gets 124 + * modified, we might need a new custom version of it 125 + * that avoids infinite recursion. 126 + */ 127 serial8250_clear_and_reinit_fifos(up); 128 129 /* ··· 120 * enabled. 121 */ 122 if (up->fcr & UART_FCR_ENABLE_FIFO) { 123 + lsr = serial_port_in(p, UART_LSR); 124 if (!(lsr & UART_LSR_DR)) 125 return; 126 } 127 128 + serial_port_in(p, UART_RX); 129 } 130 131 + /* 132 + * This function is being called as part of the uart_port::serial_out() 133 + * routine. Hence, it must not call serial_port_out() or serial_out() 134 + * against the modified registers here, i.e. LCR. 135 + */ 136 static void dw8250_check_lcr(struct uart_port *p, int offset, int value) 137 { 138 struct dw8250_data *d = to_dw8250_data(p->private_data); ··· 139 140 /* Make sure LCR write wasn't ignored */ 141 while (tries--) { 142 + unsigned int lcr = serial_port_in(p, offset); 143 144 if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR)) 145 return; ··· 260 { 261 struct uart_8250_port *up = up_to_u8250p(p); 262 struct dw8250_data *d = to_dw8250_data(p->private_data); 263 + unsigned int iir = serial_port_in(p, UART_IIR); 264 bool rx_timeout = (iir & 0x3f) == UART_IIR_RX_TIMEOUT; 265 unsigned int quirks = d->pdata->quirks; 266 unsigned int status; ··· 281 status = serial_lsr_in(up); 282 283 if (!(status & (UART_LSR_DR | UART_LSR_BI))) 284 + serial_port_in(p, UART_RX); 285 286 uart_port_unlock_irqrestore(p, flags); 287 } ··· 303 304 if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) { 305 /* Clear the USR */ 306 + serial_port_in(p, d->pdata->usr_reg); 307 308 return 1; 309 } ··· 390 static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios) 391 { 392 struct uart_8250_port *up = up_to_u8250p(p); 393 + unsigned int mcr = serial_port_in(p, UART_MCR); 394 395 if (up->capabilities & UART_CAP_IRDA) { 396 if (termios->c_line == N_IRDA) ··· 398 else 399 mcr &= ~DW_UART_MCR_SIRE; 400 401 + serial_port_out(p, UART_MCR, mcr); 402 } 403 serial8250_do_set_ldisc(p, termios); 404 } ··· 419 static bool dw8250_idma_filter(struct dma_chan *chan, void *param) 420 { 421 return param == chan->device->dev; 422 + } 423 + 424 + static void dw8250_setup_dma_filter(struct uart_port *p, struct dw8250_data *data) 425 + { 426 + /* Platforms with iDMA 64-bit */ 427 + if (platform_get_resource_byname(to_platform_device(p->dev), IORESOURCE_MEM, "lpss_priv")) { 428 + data->data.dma.rx_param = p->dev->parent; 429 + data->data.dma.tx_param = p->dev->parent; 430 + data->data.dma.fn = dw8250_idma_filter; 431 + } else { 432 + data->data.dma.fn = dw8250_fallback_dma_filter; 433 + } 434 } 435 436 static u32 dw8250_rzn1_get_dmacr_burst(int max_burst) ··· 459 460 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data) 461 { 462 + unsigned int quirks = data->pdata->quirks; 463 + u32 cpr_value = data->pdata->cpr_value; 464 465 if (quirks & DW_UART_QUIRK_CPR_VALUE) 466 data->data.cpr_value = cpr_value; ··· 491 p->serial_in = dw8250_serial_in32; 492 data->uart_16550_compatible = true; 493 } 494 } 495 496 static void dw8250_reset_control_assert(void *data) ··· 520 return dev_err_probe(dev, -EINVAL, "no registers defined\n"); 521 522 spin_lock_init(&p->lock); 523 p->pm = dw8250_do_pm; 524 p->type = PORT_8250; 525 p->flags = UPF_FIXED_PORT; ··· 532 if (!data) 533 return -ENOMEM; 534 535 p->private_data = &data->data; 536 537 p->mapbase = regs->start; 538 p->mapsize = resource_size(regs); ··· 626 if (err) 627 return err; 628 629 + data->uart_16550_compatible = device_property_read_bool(dev, "snps,uart-16550-compatible"); 630 + 631 + data->pdata = device_get_match_data(p->dev); 632 + if (data->pdata) 633 + dw8250_quirks(p, data); 634 635 /* If the Busy Functionality is not implemented, don't handle it */ 636 if (data->uart_16550_compatible) 637 p->handle_irq = NULL; 638 + else if (data->pdata) 639 + p->handle_irq = dw8250_handle_irq; 640 + 641 + dw8250_setup_dma_filter(p, data); 642 643 if (!data->skip_autocfg) 644 dw8250_setup_port(p);
+4 -4
drivers/tty/serial/8250/8250_fsl.c
··· 32 33 uart_port_lock_irqsave(&up->port, &flags); 34 35 - iir = port->serial_in(port, UART_IIR); 36 if (iir & UART_IIR_NO_INT) { 37 uart_port_unlock_irqrestore(&up->port, flags); 38 return 0; ··· 54 if (unlikely((iir & UART_IIR_ID) == UART_IIR_RLSI && 55 (up->lsr_saved_flags & UART_LSR_BI))) { 56 up->lsr_saved_flags &= ~UART_LSR_BI; 57 - port->serial_in(port, UART_RX); 58 uart_port_unlock_irqrestore(&up->port, flags); 59 return 1; 60 } 61 62 - lsr = orig_lsr = up->port.serial_in(&up->port, UART_LSR); 63 64 /* Process incoming characters first */ 65 if ((lsr & (UART_LSR_DR | UART_LSR_BI)) && ··· 71 if ((orig_lsr & UART_LSR_OE) && (up->overrun_backoff_time_ms > 0)) { 72 unsigned long delay; 73 74 - up->ier = port->serial_in(port, UART_IER); 75 if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) { 76 port->ops->stop_rx(port); 77 } else {
··· 32 33 uart_port_lock_irqsave(&up->port, &flags); 34 35 + iir = serial_port_in(port, UART_IIR); 36 if (iir & UART_IIR_NO_INT) { 37 uart_port_unlock_irqrestore(&up->port, flags); 38 return 0; ··· 54 if (unlikely((iir & UART_IIR_ID) == UART_IIR_RLSI && 55 (up->lsr_saved_flags & UART_LSR_BI))) { 56 up->lsr_saved_flags &= ~UART_LSR_BI; 57 + serial_port_in(port, UART_RX); 58 uart_port_unlock_irqrestore(&up->port, flags); 59 return 1; 60 } 61 62 + lsr = orig_lsr = serial_port_in(port, UART_LSR); 63 64 /* Process incoming characters first */ 65 if ((lsr & (UART_LSR_DR | UART_LSR_BI)) && ··· 71 if ((orig_lsr & UART_LSR_OE) && (up->overrun_backoff_time_ms > 0)) { 72 unsigned long delay; 73 74 + up->ier = serial_port_in(port, UART_IER); 75 if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) { 76 port->ops->stop_rx(port); 77 } else {
+461
drivers/tty/serial/8250/8250_ni.c
···
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * NI 16550 UART Driver 4 + * 5 + * The National Instruments (NI) 16550 is a UART that is compatible with the 6 + * TL16C550C and OX16C950B register interfaces, but has additional functions 7 + * for RS-485 transceiver control. This driver implements support for the 8 + * additional functionality on top of the standard serial8250 core. 9 + * 10 + * Copyright 2012-2023 National Instruments Corporation 11 + */ 12 + 13 + #include <linux/acpi.h> 14 + #include <linux/bitfield.h> 15 + #include <linux/device.h> 16 + #include <linux/io.h> 17 + #include <linux/init.h> 18 + #include <linux/module.h> 19 + #include <linux/property.h> 20 + #include <linux/clk.h> 21 + 22 + #include "8250.h" 23 + 24 + /* Extra bits in UART_ACR */ 25 + #define NI16550_ACR_AUTO_DTR_EN BIT(4) 26 + 27 + /* TFS - TX FIFO Size */ 28 + #define NI16550_TFS_OFFSET 0x0C 29 + /* RFS - RX FIFO Size */ 30 + #define NI16550_RFS_OFFSET 0x0D 31 + 32 + /* PMR - Port Mode Register */ 33 + #define NI16550_PMR_OFFSET 0x0E 34 + /* PMR[1:0] - Port Capabilities */ 35 + #define NI16550_PMR_CAP_MASK GENMASK(1, 0) 36 + #define NI16550_PMR_NOT_IMPL FIELD_PREP(NI16550_PMR_CAP_MASK, 0) /* not implemented */ 37 + #define NI16550_PMR_CAP_RS232 FIELD_PREP(NI16550_PMR_CAP_MASK, 1) /* RS-232 capable */ 38 + #define NI16550_PMR_CAP_RS485 FIELD_PREP(NI16550_PMR_CAP_MASK, 2) /* RS-485 capable */ 39 + #define NI16550_PMR_CAP_DUAL FIELD_PREP(NI16550_PMR_CAP_MASK, 3) /* dual-port */ 40 + /* PMR[4] - Interface Mode */ 41 + #define NI16550_PMR_MODE_MASK GENMASK(4, 4) 42 + #define NI16550_PMR_MODE_RS232 FIELD_PREP(NI16550_PMR_MODE_MASK, 0) /* currently 232 */ 43 + #define NI16550_PMR_MODE_RS485 FIELD_PREP(NI16550_PMR_MODE_MASK, 1) /* currently 485 */ 44 + 45 + /* PCR - Port Control Register */ 46 + /* 47 + * Wire Mode | Tx enabled? | Rx enabled? 48 + * ---------------|----------------------|-------------------------- 49 + * PCR_RS422 | Always | Always 50 + * PCR_ECHO_RS485 | When DTR asserted | Always 51 + * PCR_DTR_RS485 | When DTR asserted | Disabled when TX enabled 52 + * PCR_AUTO_RS485 | When data in TX FIFO | Disabled when TX enabled 53 + */ 54 + #define NI16550_PCR_OFFSET 0x0F 55 + #define NI16550_PCR_WIRE_MODE_MASK GENMASK(1, 0) 56 + #define NI16550_PCR_RS422 FIELD_PREP(NI16550_PCR_WIRE_MODE_MASK, 0) 57 + #define NI16550_PCR_ECHO_RS485 FIELD_PREP(NI16550_PCR_WIRE_MODE_MASK, 1) 58 + #define NI16550_PCR_DTR_RS485 FIELD_PREP(NI16550_PCR_WIRE_MODE_MASK, 2) 59 + #define NI16550_PCR_AUTO_RS485 FIELD_PREP(NI16550_PCR_WIRE_MODE_MASK, 3) 60 + #define NI16550_PCR_TXVR_ENABLE_BIT BIT(3) 61 + #define NI16550_PCR_RS485_TERMINATION_BIT BIT(6) 62 + 63 + /* flags for ni16550_device_info */ 64 + #define NI_HAS_PMR BIT(0) 65 + 66 + struct ni16550_device_info { 67 + u32 uartclk; 68 + u8 prescaler; 69 + u8 flags; 70 + }; 71 + 72 + struct ni16550_data { 73 + int line; 74 + struct clk *clk; 75 + }; 76 + 77 + static int ni16550_enable_transceivers(struct uart_port *port) 78 + { 79 + u8 pcr; 80 + 81 + pcr = port->serial_in(port, NI16550_PCR_OFFSET); 82 + pcr |= NI16550_PCR_TXVR_ENABLE_BIT; 83 + dev_dbg(port->dev, "enable transceivers: write pcr: 0x%02x\n", pcr); 84 + port->serial_out(port, NI16550_PCR_OFFSET, pcr); 85 + 86 + return 0; 87 + } 88 + 89 + static int ni16550_disable_transceivers(struct uart_port *port) 90 + { 91 + u8 pcr; 92 + 93 + pcr = port->serial_in(port, NI16550_PCR_OFFSET); 94 + pcr &= ~NI16550_PCR_TXVR_ENABLE_BIT; 95 + dev_dbg(port->dev, "disable transceivers: write pcr: 0x%02x\n", pcr); 96 + port->serial_out(port, NI16550_PCR_OFFSET, pcr); 97 + 98 + return 0; 99 + } 100 + 101 + static int ni16550_rs485_config(struct uart_port *port, 102 + struct ktermios *termios, 103 + struct serial_rs485 *rs485) 104 + { 105 + struct uart_8250_port *up = container_of(port, struct uart_8250_port, port); 106 + u8 pcr; 107 + 108 + pcr = serial_in(up, NI16550_PCR_OFFSET); 109 + pcr &= ~NI16550_PCR_WIRE_MODE_MASK; 110 + 111 + if ((rs485->flags & SER_RS485_MODE_RS422) || 112 + !(rs485->flags & SER_RS485_ENABLED)) { 113 + /* RS-422 */ 114 + pcr |= NI16550_PCR_RS422; 115 + up->acr &= ~NI16550_ACR_AUTO_DTR_EN; 116 + } else { 117 + /* RS-485 2-wire Auto */ 118 + pcr |= NI16550_PCR_AUTO_RS485; 119 + up->acr |= NI16550_ACR_AUTO_DTR_EN; 120 + } 121 + 122 + dev_dbg(port->dev, "config rs485: write pcr: 0x%02x, acr: %02x\n", pcr, up->acr); 123 + serial_out(up, NI16550_PCR_OFFSET, pcr); 124 + serial_icr_write(up, UART_ACR, up->acr); 125 + 126 + return 0; 127 + } 128 + 129 + static bool is_pmr_rs232_mode(struct uart_8250_port *up) 130 + { 131 + u8 pmr = serial_in(up, NI16550_PMR_OFFSET); 132 + u8 pmr_mode = pmr & NI16550_PMR_MODE_MASK; 133 + u8 pmr_cap = pmr & NI16550_PMR_CAP_MASK; 134 + 135 + /* 136 + * If the PMR is not implemented, then by default NI UARTs are 137 + * connected to RS-485 transceivers 138 + */ 139 + if (pmr_cap == NI16550_PMR_NOT_IMPL) 140 + return false; 141 + 142 + if (pmr_cap == NI16550_PMR_CAP_DUAL) 143 + /* 144 + * If the port is dual-mode capable, then read the mode bit 145 + * to know the current mode 146 + */ 147 + return pmr_mode == NI16550_PMR_MODE_RS232; 148 + /* 149 + * If it is not dual-mode capable, then decide based on the 150 + * capability 151 + */ 152 + return pmr_cap == NI16550_PMR_CAP_RS232; 153 + } 154 + 155 + static void ni16550_config_prescaler(struct uart_8250_port *up, 156 + u8 prescaler) 157 + { 158 + /* 159 + * Page in the Enhanced Mode Registers 160 + * Sets EFR[4] for Enhanced Mode. 161 + */ 162 + u8 lcr_value; 163 + u8 efr_value; 164 + 165 + lcr_value = serial_in(up, UART_LCR); 166 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 167 + 168 + efr_value = serial_in(up, UART_EFR); 169 + efr_value |= UART_EFR_ECB; 170 + 171 + serial_out(up, UART_EFR, efr_value); 172 + 173 + /* Page out the Enhanced Mode Registers */ 174 + serial_out(up, UART_LCR, lcr_value); 175 + 176 + /* Set prescaler to CPR register. */ 177 + serial_out(up, UART_SCR, UART_CPR); 178 + serial_out(up, UART_ICR, prescaler); 179 + } 180 + 181 + static const struct serial_rs485 ni16550_rs485_supported = { 182 + .flags = SER_RS485_ENABLED | SER_RS485_MODE_RS422 | SER_RS485_RTS_ON_SEND | 183 + SER_RS485_RTS_AFTER_SEND, 184 + /* 185 + * delay_rts_* and RX_DURING_TX are not supported. 186 + * 187 + * RTS_{ON,AFTER}_SEND are supported, but ignored; the transceiver 188 + * is connected in only one way and we don't need userspace to tell 189 + * us, but want to retain compatibility with applications that do. 190 + */ 191 + }; 192 + 193 + static void ni16550_rs485_setup(struct uart_port *port) 194 + { 195 + port->rs485_config = ni16550_rs485_config; 196 + port->rs485_supported = ni16550_rs485_supported; 197 + /* 198 + * The hardware comes up by default in 2-wire auto mode and we 199 + * set the flags to represent that 200 + */ 201 + port->rs485.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND; 202 + } 203 + 204 + static int ni16550_port_startup(struct uart_port *port) 205 + { 206 + int ret; 207 + 208 + ret = serial8250_do_startup(port); 209 + if (ret) 210 + return ret; 211 + 212 + return ni16550_enable_transceivers(port); 213 + } 214 + 215 + static void ni16550_port_shutdown(struct uart_port *port) 216 + { 217 + ni16550_disable_transceivers(port); 218 + 219 + serial8250_do_shutdown(port); 220 + } 221 + 222 + static int ni16550_get_regs(struct platform_device *pdev, 223 + struct uart_port *port) 224 + { 225 + struct resource *regs; 226 + 227 + regs = platform_get_resource(pdev, IORESOURCE_IO, 0); 228 + if (regs) { 229 + port->iotype = UPIO_PORT; 230 + port->iobase = regs->start; 231 + 232 + return 0; 233 + } 234 + 235 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 236 + if (regs) { 237 + port->iotype = UPIO_MEM; 238 + port->mapbase = regs->start; 239 + port->mapsize = resource_size(regs); 240 + port->flags |= UPF_IOREMAP; 241 + 242 + port->membase = devm_ioremap(&pdev->dev, port->mapbase, 243 + port->mapsize); 244 + if (!port->membase) 245 + return -ENOMEM; 246 + 247 + return 0; 248 + } 249 + 250 + dev_err(&pdev->dev, "no registers defined\n"); 251 + return -EINVAL; 252 + } 253 + 254 + /* 255 + * Very old implementations don't have the TFS or RFS registers 256 + * defined, so we may read all-0s or all-1s. For such devices, 257 + * assume a FIFO size of 128. 258 + */ 259 + static u8 ni16550_read_fifo_size(struct uart_8250_port *uart, int reg) 260 + { 261 + u8 value = serial_in(uart, reg); 262 + 263 + if (value == 0x00 || value == 0xFF) 264 + return 128; 265 + 266 + return value; 267 + } 268 + 269 + static void ni16550_set_mctrl(struct uart_port *port, unsigned int mctrl) 270 + { 271 + struct uart_8250_port *up = up_to_u8250p(port); 272 + 273 + up->mcr |= UART_MCR_CLKSEL; 274 + serial8250_do_set_mctrl(port, mctrl); 275 + } 276 + 277 + static int ni16550_probe(struct platform_device *pdev) 278 + { 279 + const struct ni16550_device_info *info; 280 + struct device *dev = &pdev->dev; 281 + struct uart_8250_port uart = {}; 282 + unsigned int txfifosz, rxfifosz; 283 + unsigned int prescaler = 0; 284 + struct ni16550_data *data; 285 + const char *portmode; 286 + bool rs232_property; 287 + int ret; 288 + int irq; 289 + 290 + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 291 + if (!data) 292 + return -ENOMEM; 293 + 294 + spin_lock_init(&uart.port.lock); 295 + 296 + irq = platform_get_irq(pdev, 0); 297 + if (irq < 0) 298 + return irq; 299 + 300 + ret = ni16550_get_regs(pdev, &uart.port); 301 + if (ret < 0) 302 + return ret; 303 + 304 + /* early setup so that serial_in()/serial_out() work */ 305 + serial8250_set_defaults(&uart); 306 + 307 + info = device_get_match_data(dev); 308 + 309 + uart.port.dev = dev; 310 + uart.port.irq = irq; 311 + uart.port.irqflags = IRQF_SHARED; 312 + uart.port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF 313 + | UPF_FIXED_PORT | UPF_FIXED_TYPE; 314 + uart.port.startup = ni16550_port_startup; 315 + uart.port.shutdown = ni16550_port_shutdown; 316 + 317 + /* 318 + * Hardware instantiation of FIFO sizes are held in registers. 319 + */ 320 + txfifosz = ni16550_read_fifo_size(&uart, NI16550_TFS_OFFSET); 321 + rxfifosz = ni16550_read_fifo_size(&uart, NI16550_RFS_OFFSET); 322 + 323 + dev_dbg(dev, "NI 16550 has TX FIFO size %u, RX FIFO size %u\n", 324 + txfifosz, rxfifosz); 325 + 326 + uart.port.type = PORT_16550A; 327 + uart.port.fifosize = txfifosz; 328 + uart.tx_loadsz = txfifosz; 329 + uart.fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10; 330 + uart.capabilities = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR; 331 + 332 + /* 333 + * Declaration of the base clock frequency can come from one of: 334 + * - static declaration in this driver (for older ACPI IDs) 335 + * - a "clock-frquency" ACPI 336 + */ 337 + if (info->uartclk) 338 + uart.port.uartclk = info->uartclk; 339 + if (device_property_read_u32(dev, "clock-frequency", 340 + &uart.port.uartclk)) { 341 + data->clk = devm_clk_get_enabled(dev, NULL); 342 + if (!IS_ERR(data->clk)) 343 + uart.port.uartclk = clk_get_rate(data->clk); 344 + } 345 + 346 + if (!uart.port.uartclk) { 347 + dev_err(dev, "unable to determine clock frequency!\n"); 348 + ret = -ENODEV; 349 + goto err; 350 + } 351 + 352 + if (info->prescaler) 353 + prescaler = info->prescaler; 354 + device_property_read_u32(dev, "clock-prescaler", &prescaler); 355 + 356 + if (prescaler != 0) { 357 + uart.port.set_mctrl = ni16550_set_mctrl; 358 + ni16550_config_prescaler(&uart, (u8)prescaler); 359 + } 360 + 361 + /* 362 + * The determination of whether or not this is an RS-485 or RS-232 port 363 + * can come from the PMR (if present), otherwise we're solely an RS-485 364 + * port. 365 + * 366 + * This is a device-specific property, and there are old devices in the 367 + * field using "transceiver" as an ACPI property, so we have to check 368 + * for that as well. 369 + */ 370 + if (!device_property_read_string(dev, "transceiver", &portmode)) { 371 + rs232_property = strncmp(portmode, "RS-232", 6) == 0; 372 + 373 + dev_dbg(dev, "port is in %s mode (via device property)\n", 374 + rs232_property ? "RS-232" : "RS-485"); 375 + } else if (info->flags & NI_HAS_PMR) { 376 + rs232_property = is_pmr_rs232_mode(&uart); 377 + 378 + dev_dbg(dev, "port is in %s mode (via PMR)\n", 379 + rs232_property ? "RS-232" : "RS-485"); 380 + } else { 381 + rs232_property = 0; 382 + 383 + dev_dbg(dev, "port is fixed as RS-485\n"); 384 + } 385 + 386 + if (!rs232_property) { 387 + /* 388 + * Neither the 'transceiver' property nor the PMR indicate 389 + * that this is an RS-232 port, so it must be an RS-485 one. 390 + */ 391 + ni16550_rs485_setup(&uart.port); 392 + } 393 + 394 + ret = serial8250_register_8250_port(&uart); 395 + if (ret < 0) 396 + goto err; 397 + data->line = ret; 398 + 399 + platform_set_drvdata(pdev, data); 400 + return 0; 401 + 402 + err: 403 + return ret; 404 + } 405 + 406 + static void ni16550_remove(struct platform_device *pdev) 407 + { 408 + struct ni16550_data *data = platform_get_drvdata(pdev); 409 + 410 + serial8250_unregister_port(data->line); 411 + } 412 + 413 + #ifdef CONFIG_ACPI 414 + /* NI 16550 RS-485 Interface */ 415 + static const struct ni16550_device_info nic7750 = { 416 + .uartclk = 33333333, 417 + }; 418 + 419 + /* NI CVS-145x RS-485 Interface */ 420 + static const struct ni16550_device_info nic7772 = { 421 + .uartclk = 1843200, 422 + .flags = NI_HAS_PMR, 423 + }; 424 + 425 + /* NI cRIO-904x RS-485 Interface */ 426 + static const struct ni16550_device_info nic792b = { 427 + /* Sets UART clock rate to 22.222 MHz with 1.125 prescale */ 428 + .uartclk = 22222222, 429 + .prescaler = 0x09, 430 + }; 431 + 432 + /* NI sbRIO 96x8 RS-232/485 Interfaces */ 433 + static const struct ni16550_device_info nic7a69 = { 434 + /* Set UART clock rate to 29.629 MHz with 1.125 prescale */ 435 + .uartclk = 29629629, 436 + .prescaler = 0x09, 437 + }; 438 + static const struct acpi_device_id ni16550_acpi_match[] = { 439 + { "NIC7750", (kernel_ulong_t)&nic7750 }, 440 + { "NIC7772", (kernel_ulong_t)&nic7772 }, 441 + { "NIC792B", (kernel_ulong_t)&nic792b }, 442 + { "NIC7A69", (kernel_ulong_t)&nic7a69 }, 443 + { }, 444 + }; 445 + MODULE_DEVICE_TABLE(acpi, ni16550_acpi_match); 446 + #endif 447 + 448 + static struct platform_driver ni16550_driver = { 449 + .driver = { 450 + .name = "ni16550", 451 + .acpi_match_table = ACPI_PTR(ni16550_acpi_match), 452 + }, 453 + .probe = ni16550_probe, 454 + .remove = ni16550_remove, 455 + }; 456 + 457 + module_platform_driver(ni16550_driver); 458 + 459 + MODULE_AUTHOR("Emerson Electric Co."); 460 + MODULE_DESCRIPTION("NI 16550 Driver"); 461 + MODULE_LICENSE("GPL");
+1 -1
drivers/tty/serial/8250/8250_omap.c
··· 692 693 /* Synchronize UART_IER access against the console. */ 694 uart_port_lock(port); 695 - up->ier = port->serial_in(port, UART_IER); 696 if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) { 697 port->ops->stop_rx(port); 698 } else {
··· 692 693 /* Synchronize UART_IER access against the console. */ 694 uart_port_lock(port); 695 + up->ier = serial_port_in(port, UART_IER); 696 if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) { 697 port->ops->stop_rx(port); 698 } else {
+46
drivers/tty/serial/8250/8250_pci.c
··· 2728 .setup = pci_oxsemi_tornado_setup, 2729 }, 2730 { 2731 .vendor = PCI_VENDOR_ID_INTEL, 2732 .device = 0x8811, 2733 .subvendor = PCI_ANY_ID, ··· 5269 PCI_ANY_ID, PCI_ANY_ID, 5270 0, 0, 5271 pbn_b2_2_115200 }, 5272 /* 5273 * Brainboxes UC-235/246 5274 */ ··· 5394 * Brainboxes UC-368 5395 */ 5396 { PCI_VENDOR_ID_INTASHIELD, 0x0C41, 5397 PCI_ANY_ID, PCI_ANY_ID, 5398 0, 0, 5399 pbn_b2_4_115200 }, ··· 5628 0, 0, 5629 pbn_b0_1_115200 }, 5630 { PCI_VENDOR_ID_INTASHIELD, 0x4017, 5631 PCI_ANY_ID, PCI_ANY_ID, 5632 0, 0, 5633 pbn_oxsemi_1_15625000 },
··· 2728 .setup = pci_oxsemi_tornado_setup, 2729 }, 2730 { 2731 + .vendor = PCI_VENDOR_ID_INTASHIELD, 2732 + .device = 0x4026, 2733 + .subvendor = PCI_ANY_ID, 2734 + .subdevice = PCI_ANY_ID, 2735 + .init = pci_oxsemi_tornado_init, 2736 + .setup = pci_oxsemi_tornado_setup, 2737 + }, 2738 + { 2739 + .vendor = PCI_VENDOR_ID_INTASHIELD, 2740 + .device = 0x4021, 2741 + .subvendor = PCI_ANY_ID, 2742 + .subdevice = PCI_ANY_ID, 2743 + .init = pci_oxsemi_tornado_init, 2744 + .setup = pci_oxsemi_tornado_setup, 2745 + }, 2746 + { 2747 .vendor = PCI_VENDOR_ID_INTEL, 2748 .device = 0x8811, 2749 .subvendor = PCI_ANY_ID, ··· 5253 PCI_ANY_ID, PCI_ANY_ID, 5254 0, 0, 5255 pbn_b2_2_115200 }, 5256 + { PCI_VENDOR_ID_INTASHIELD, 0x0BA2, 5257 + PCI_ANY_ID, PCI_ANY_ID, 5258 + 0, 0, 5259 + pbn_b2_2_115200 }, 5260 + { PCI_VENDOR_ID_INTASHIELD, 0x0BA3, 5261 + PCI_ANY_ID, PCI_ANY_ID, 5262 + 0, 0, 5263 + pbn_b2_2_115200 }, 5264 /* 5265 * Brainboxes UC-235/246 5266 */ ··· 5370 * Brainboxes UC-368 5371 */ 5372 { PCI_VENDOR_ID_INTASHIELD, 0x0C41, 5373 + PCI_ANY_ID, PCI_ANY_ID, 5374 + 0, 0, 5375 + pbn_b2_4_115200 }, 5376 + { PCI_VENDOR_ID_INTASHIELD, 0x0C42, 5377 + PCI_ANY_ID, PCI_ANY_ID, 5378 + 0, 0, 5379 + pbn_b2_4_115200 }, 5380 + { PCI_VENDOR_ID_INTASHIELD, 0x0C43, 5381 PCI_ANY_ID, PCI_ANY_ID, 5382 0, 0, 5383 pbn_b2_4_115200 }, ··· 5596 0, 0, 5597 pbn_b0_1_115200 }, 5598 { PCI_VENDOR_ID_INTASHIELD, 0x4017, 5599 + PCI_ANY_ID, PCI_ANY_ID, 5600 + 0, 0, 5601 + pbn_oxsemi_1_15625000 }, 5602 + /* 5603 + * Brainboxes XC-235 5604 + */ 5605 + { PCI_VENDOR_ID_INTASHIELD, 0x4026, 5606 + PCI_ANY_ID, PCI_ANY_ID, 5607 + 0, 0, 5608 + pbn_oxsemi_1_15625000 }, 5609 + /* 5610 + * Brainboxes XC-475 5611 + */ 5612 + { PCI_VENDOR_ID_INTASHIELD, 0x4021, 5613 PCI_ANY_ID, PCI_ANY_ID, 5614 0, 0, 5615 pbn_oxsemi_1_15625000 },
+27 -34
drivers/tty/serial/8250/8250_port.c
··· 1678 if (up->bugs & UART_BUG_NOMSR) 1679 return; 1680 1681 - mctrl_gpio_disable_ms(up->gpios); 1682 1683 up->ier &= ~UART_IER_MSI; 1684 serial_port_out(port, UART_IER, up->ier); ··· 2406 * test if we receive TX irq. This way, we'll never enable 2407 * UART_BUG_TXEN. 2408 */ 2409 - if (up->port.quirks & UPQ_NO_TXEN_TEST) 2410 - goto dont_test_tx_en; 2411 2412 - /* 2413 - * Do a quick test to see if we receive an interrupt when we enable 2414 - * the TX irq. 2415 - */ 2416 - serial_port_out(port, UART_IER, UART_IER_THRI); 2417 - lsr = serial_port_in(port, UART_LSR); 2418 - iir = serial_port_in(port, UART_IIR); 2419 - serial_port_out(port, UART_IER, 0); 2420 - 2421 - if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { 2422 - if (!(up->bugs & UART_BUG_TXEN)) { 2423 - up->bugs |= UART_BUG_TXEN; 2424 - dev_dbg(port->dev, "enabling bad tx status workarounds\n"); 2425 } 2426 - } else { 2427 - up->bugs &= ~UART_BUG_TXEN; 2428 } 2429 2430 - dont_test_tx_en: 2431 uart_port_unlock_irqrestore(port, flags); 2432 2433 /* ··· 2966 { 2967 unsigned int size = serial8250_port_size(up); 2968 struct uart_port *port = &up->port; 2969 - int ret = 0; 2970 2971 switch (port->iotype) { 2972 case UPIO_AU: ··· 2974 case UPIO_MEM32BE: 2975 case UPIO_MEM16: 2976 case UPIO_MEM: 2977 - if (!port->mapbase) { 2978 - ret = -EINVAL; 2979 - break; 2980 - } 2981 2982 - if (!request_mem_region(port->mapbase, size, "serial")) { 2983 - ret = -EBUSY; 2984 - break; 2985 - } 2986 2987 if (port->flags & UPF_IOREMAP) { 2988 port->membase = ioremap(port->mapbase, size); 2989 if (!port->membase) { 2990 release_mem_region(port->mapbase, size); 2991 - ret = -ENOMEM; 2992 } 2993 } 2994 - break; 2995 - 2996 case UPIO_HUB6: 2997 case UPIO_PORT: 2998 if (!request_region(port->iobase, size, "serial")) 2999 - ret = -EBUSY; 3000 - break; 3001 } 3002 - return ret; 3003 } 3004 3005 static void serial8250_release_std_resource(struct uart_8250_port *up)
··· 1678 if (up->bugs & UART_BUG_NOMSR) 1679 return; 1680 1681 + mctrl_gpio_disable_ms_no_sync(up->gpios); 1682 1683 up->ier &= ~UART_IER_MSI; 1684 serial_port_out(port, UART_IER, up->ier); ··· 2406 * test if we receive TX irq. This way, we'll never enable 2407 * UART_BUG_TXEN. 2408 */ 2409 + if (!(up->port.quirks & UPQ_NO_TXEN_TEST)) { 2410 + /* 2411 + * Do a quick test to see if we receive an interrupt when we 2412 + * enable the TX irq. 2413 + */ 2414 + serial_port_out(port, UART_IER, UART_IER_THRI); 2415 + lsr = serial_port_in(port, UART_LSR); 2416 + iir = serial_port_in(port, UART_IIR); 2417 + serial_port_out(port, UART_IER, 0); 2418 2419 + if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { 2420 + if (!(up->bugs & UART_BUG_TXEN)) { 2421 + up->bugs |= UART_BUG_TXEN; 2422 + dev_dbg(port->dev, "enabling bad tx status workarounds\n"); 2423 + } 2424 + } else { 2425 + up->bugs &= ~UART_BUG_TXEN; 2426 } 2427 } 2428 2429 uart_port_unlock_irqrestore(port, flags); 2430 2431 /* ··· 2968 { 2969 unsigned int size = serial8250_port_size(up); 2970 struct uart_port *port = &up->port; 2971 2972 switch (port->iotype) { 2973 case UPIO_AU: ··· 2977 case UPIO_MEM32BE: 2978 case UPIO_MEM16: 2979 case UPIO_MEM: 2980 + if (!port->mapbase) 2981 + return -EINVAL; 2982 2983 + if (!request_mem_region(port->mapbase, size, "serial")) 2984 + return -EBUSY; 2985 2986 if (port->flags & UPF_IOREMAP) { 2987 port->membase = ioremap(port->mapbase, size); 2988 if (!port->membase) { 2989 release_mem_region(port->mapbase, size); 2990 + return -ENOMEM; 2991 } 2992 } 2993 + return 0; 2994 case UPIO_HUB6: 2995 case UPIO_PORT: 2996 if (!request_region(port->iobase, size, "serial")) 2997 + return -EBUSY; 2998 + return 0; 2999 } 3000 + 3001 + return 0; 3002 } 3003 3004 static void serial8250_release_std_resource(struct uart_8250_port *up)
+9 -12
drivers/tty/serial/8250/8250_rsa.c
··· 16 17 static int rsa8250_request_resource(struct uart_8250_port *up) 18 { 19 - unsigned long start = UART_RSA_BASE << up->port.regshift; 20 - unsigned int size = 8 << up->port.regshift; 21 struct uart_port *port = &up->port; 22 - int ret = -EINVAL; 23 24 switch (port->iotype) { 25 case UPIO_HUB6: 26 case UPIO_PORT: 27 start += port->iobase; 28 - if (request_region(start, size, "serial-rsa")) 29 - ret = 0; 30 - else 31 - ret = -EBUSY; 32 - break; 33 } 34 - 35 - return ret; 36 } 37 38 static void rsa8250_release_resource(struct uart_8250_port *up) 39 { 40 - unsigned long offset = UART_RSA_BASE << up->port.regshift; 41 - unsigned int size = 8 << up->port.regshift; 42 struct uart_port *port = &up->port; 43 44 switch (port->iotype) { 45 case UPIO_HUB6:
··· 16 17 static int rsa8250_request_resource(struct uart_8250_port *up) 18 { 19 struct uart_port *port = &up->port; 20 + unsigned long start = UART_RSA_BASE << port->regshift; 21 + unsigned int size = 8 << port->regshift; 22 23 switch (port->iotype) { 24 case UPIO_HUB6: 25 case UPIO_PORT: 26 start += port->iobase; 27 + if (!request_region(start, size, "serial-rsa")) 28 + return -EBUSY; 29 + return 0; 30 + default: 31 + return -EINVAL; 32 } 33 } 34 35 static void rsa8250_release_resource(struct uart_8250_port *up) 36 { 37 struct uart_port *port = &up->port; 38 + unsigned long offset = UART_RSA_BASE << port->regshift; 39 + unsigned int size = 8 << port->regshift; 40 41 switch (port->iotype) { 42 case UPIO_HUB6:
+13
drivers/tty/serial/8250/Kconfig
··· 569 including DMA support and high accuracy BAUD rates, say 570 Y to this option. If unsure, say N. 571 572 config SERIAL_OF_PLATFORM 573 tristate "Devicetree based probing for 8250 ports" 574 depends on SERIAL_8250 && OF
··· 569 including DMA support and high accuracy BAUD rates, say 570 Y to this option. If unsure, say N. 571 572 + config SERIAL_8250_NI 573 + tristate "NI 16550 based serial port" 574 + depends on SERIAL_8250 575 + depends on (X86 && ACPI) || COMPILE_TEST 576 + help 577 + This driver supports the integrated serial ports on National 578 + Instruments (NI) controller hardware. This is required for all NI 579 + controller models with onboard RS-485 or dual-mode RS-485/RS-232 580 + ports. 581 + 582 + To compile this driver as a module, choose M here: the module 583 + will be called 8250_ni. 584 + 585 config SERIAL_OF_PLATFORM 586 tristate "Devicetree based probing for 8250 ports" 587 depends on SERIAL_8250 && OF
+1
drivers/tty/serial/8250/Makefile
··· 40 obj-$(CONFIG_SERIAL_8250_MEN_MCB) += 8250_men_mcb.o 41 obj-$(CONFIG_SERIAL_8250_MID) += 8250_mid.o 42 obj-$(CONFIG_SERIAL_8250_MT6577) += 8250_mtk.o 43 obj-$(CONFIG_SERIAL_OF_PLATFORM) += 8250_of.o 44 obj-$(CONFIG_SERIAL_8250_OMAP) += 8250_omap.o 45 obj-$(CONFIG_SERIAL_8250_PARISC) += 8250_parisc.o
··· 40 obj-$(CONFIG_SERIAL_8250_MEN_MCB) += 8250_men_mcb.o 41 obj-$(CONFIG_SERIAL_8250_MID) += 8250_mid.o 42 obj-$(CONFIG_SERIAL_8250_MT6577) += 8250_mtk.o 43 + obj-$(CONFIG_SERIAL_8250_NI) += 8250_ni.o 44 obj-$(CONFIG_SERIAL_OF_PLATFORM) += 8250_of.o 45 obj-$(CONFIG_SERIAL_8250_OMAP) += 8250_omap.o 46 obj-$(CONFIG_SERIAL_8250_PARISC) += 8250_parisc.o
+23 -19
drivers/tty/serial/Kconfig
··· 179 180 Say Y if you have an external 8250/16C550 UART. If unsure, say N. 181 182 - config SERIAL_KGDB_NMI 183 - bool "Serial console over KGDB NMI debugger port" 184 - depends on KGDB_SERIAL_CONSOLE 185 - help 186 - This special driver allows you to temporary use NMI debugger port 187 - as a normal console (assuming that the port is attached to KGDB). 188 - 189 - Unlike KDB's disable_nmi command, with this driver you are always 190 - able to go back to the debugger using KGDB escape sequence ($3#33). 191 - This is because this console driver processes the input in NMI 192 - context, and thus is able to intercept the magic sequence. 193 - 194 - Note that since the console interprets input and uses polling 195 - communication methods, for things like PPP you still must fully 196 - detach debugger port from the KGDB NMI (i.e. disable_nmi), and 197 - use raw console. 198 - 199 - If unsure, say N. 200 - 201 config SERIAL_MESON 202 tristate "Meson serial port support" 203 depends on ARCH_MESON || COMPILE_TEST ··· 284 system console (the system console is the device which receives all 285 kernel messages and warnings and which allows logins in single user 286 mode). 287 288 If unsure, say Y. 289
··· 179 180 Say Y if you have an external 8250/16C550 UART. If unsure, say N. 181 182 config SERIAL_MESON 183 tristate "Meson serial port support" 184 depends on ARCH_MESON || COMPILE_TEST ··· 303 system console (the system console is the device which receives all 304 kernel messages and warnings and which allows logins in single user 305 mode). 306 + 307 + If unsure, say Y. 308 + 309 + config SERIAL_TEGRA_UTC 310 + tristate "NVIDIA Tegra UART Trace Controller" 311 + depends on ARCH_TEGRA || COMPILE_TEST 312 + select SERIAL_CORE 313 + help 314 + Support for Tegra UTC (UART Trace controller) client serial port. 315 + 316 + UTC is a HW based serial port that allows multiplexing multiple data 317 + streams of up to 16 UTC clients into a single hardware serial port. 318 + 319 + config SERIAL_TEGRA_UTC_CONSOLE 320 + bool "Support for console on a Tegra UTC serial port" 321 + depends on SERIAL_TEGRA_UTC 322 + select SERIAL_CORE_CONSOLE 323 + default SERIAL_TEGRA_UTC 324 + help 325 + If you say Y here, it will be possible to use a Tegra UTC client as 326 + the system console (the system console is the device which receives 327 + all kernel messages and warnings and which allows logins in single 328 + user mode). 329 330 If unsure, say Y. 331
+1 -1
drivers/tty/serial/Makefile
··· 86 obj-$(CONFIG_SERIAL_SUNPLUS) += sunplus-uart.o 87 obj-$(CONFIG_SERIAL_TEGRA) += serial-tegra.o 88 obj-$(CONFIG_SERIAL_TEGRA_TCU) += tegra-tcu.o 89 obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o 90 obj-$(CONFIG_SERIAL_TXX9) += serial_txx9.o 91 obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o ··· 97 # GPIOLIB helpers for modem control lines 98 obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o 99 100 - obj-$(CONFIG_SERIAL_KGDB_NMI) += kgdb_nmi.o 101 obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o 102 obj-$(CONFIG_SERIAL_NUVOTON_MA35D1) += ma35d1_serial.o
··· 86 obj-$(CONFIG_SERIAL_SUNPLUS) += sunplus-uart.o 87 obj-$(CONFIG_SERIAL_TEGRA) += serial-tegra.o 88 obj-$(CONFIG_SERIAL_TEGRA_TCU) += tegra-tcu.o 89 + obj-$(CONFIG_SERIAL_TEGRA_UTC) += tegra-utc.o 90 obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o 91 obj-$(CONFIG_SERIAL_TXX9) += serial_txx9.o 92 obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o ··· 96 # GPIOLIB helpers for modem control lines 97 obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o 98 99 obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o 100 obj-$(CONFIG_SERIAL_NUVOTON_MA35D1) += ma35d1_serial.o
+100 -49
drivers/tty/serial/amba-pl011.c
··· 272 enum pl011_rs485_tx_state rs485_tx_state; 273 struct hrtimer trigger_start_tx; 274 struct hrtimer trigger_stop_tx; 275 #ifdef CONFIG_DMA_ENGINE 276 /* DMA stuff */ 277 unsigned int dmacr; /* dma control reg */ ··· 2367 while (pl011_read(uap, REG_FR) & UART01x_FR_TXFF) 2368 cpu_relax(); 2369 pl011_write(ch, uap, REG_DR); 2370 - } 2371 - 2372 - static void 2373 - pl011_console_write(struct console *co, const char *s, unsigned int count) 2374 - { 2375 - struct uart_amba_port *uap = amba_ports[co->index]; 2376 - unsigned int old_cr = 0, new_cr; 2377 - unsigned long flags; 2378 - int locked = 1; 2379 - 2380 - clk_enable(uap->clk); 2381 - 2382 - if (oops_in_progress) 2383 - locked = uart_port_trylock_irqsave(&uap->port, &flags); 2384 - else 2385 - uart_port_lock_irqsave(&uap->port, &flags); 2386 - 2387 - /* 2388 - * First save the CR then disable the interrupts 2389 - */ 2390 - if (!uap->vendor->always_enabled) { 2391 - old_cr = pl011_read(uap, REG_CR); 2392 - new_cr = old_cr & ~UART011_CR_CTSEN; 2393 - new_cr |= UART01x_CR_UARTEN | UART011_CR_TXE; 2394 - pl011_write(new_cr, uap, REG_CR); 2395 - } 2396 - 2397 - uart_console_write(&uap->port, s, count, pl011_console_putchar); 2398 - 2399 - /* 2400 - * Finally, wait for transmitter to become empty and restore the 2401 - * TCR. Allow feature register bits to be inverted to work around 2402 - * errata. 2403 - */ 2404 - while ((pl011_read(uap, REG_FR) ^ uap->vendor->inv_fr) 2405 - & uap->vendor->fr_busy) 2406 - cpu_relax(); 2407 - if (!uap->vendor->always_enabled) 2408 - pl011_write(old_cr, uap, REG_CR); 2409 - 2410 - if (locked) 2411 - uart_port_unlock_irqrestore(&uap->port, flags); 2412 - 2413 - clk_disable(uap->clk); 2414 } 2415 2416 static void pl011_console_get_options(struct uart_amba_port *uap, int *baud, ··· 2429 ret = clk_prepare(uap->clk); 2430 if (ret) 2431 return ret; 2432 2433 if (dev_get_platdata(uap->port.dev)) { 2434 struct amba_pl011_data *plat; ··· 2515 return -ENODEV; 2516 } 2517 2518 static struct uart_driver amba_reg; 2519 static struct console amba_console = { 2520 .name = "ttyAMA", 2521 - .write = pl011_console_write, 2522 .device = uart_console_device, 2523 .setup = pl011_console_setup, 2524 .match = pl011_console_match, 2525 - .flags = CON_PRINTBUFFER | CON_ANYTIME, 2526 .index = -1, 2527 .data = &amba_reg, 2528 }; ··· 3051 }; 3052 MODULE_DEVICE_TABLE(of, sbsa_uart_of_match); 3053 3054 - static const struct acpi_device_id __maybe_unused sbsa_uart_acpi_match[] = { 3055 { "ARMH0011", 0 }, 3056 { "ARMHB000", 0 }, 3057 {}, ··· 3064 .driver = { 3065 .name = "sbsa-uart", 3066 .pm = &pl011_dev_pm_ops, 3067 - .of_match_table = of_match_ptr(sbsa_uart_of_match), 3068 - .acpi_match_table = ACPI_PTR(sbsa_uart_acpi_match), 3069 .suppress_bind_attrs = IS_BUILTIN(CONFIG_SERIAL_AMBA_PL011), 3070 }, 3071 };
··· 272 enum pl011_rs485_tx_state rs485_tx_state; 273 struct hrtimer trigger_start_tx; 274 struct hrtimer trigger_stop_tx; 275 + bool console_line_ended; 276 #ifdef CONFIG_DMA_ENGINE 277 /* DMA stuff */ 278 unsigned int dmacr; /* dma control reg */ ··· 2366 while (pl011_read(uap, REG_FR) & UART01x_FR_TXFF) 2367 cpu_relax(); 2368 pl011_write(ch, uap, REG_DR); 2369 + uap->console_line_ended = (ch == '\n'); 2370 } 2371 2372 static void pl011_console_get_options(struct uart_amba_port *uap, int *baud, ··· 2471 ret = clk_prepare(uap->clk); 2472 if (ret) 2473 return ret; 2474 + 2475 + uap->console_line_ended = true; 2476 2477 if (dev_get_platdata(uap->port.dev)) { 2478 struct amba_pl011_data *plat; ··· 2555 return -ENODEV; 2556 } 2557 2558 + static void 2559 + pl011_console_write_atomic(struct console *co, struct nbcon_write_context *wctxt) 2560 + { 2561 + struct uart_amba_port *uap = amba_ports[co->index]; 2562 + unsigned int old_cr = 0; 2563 + 2564 + if (!nbcon_enter_unsafe(wctxt)) 2565 + return; 2566 + 2567 + clk_enable(uap->clk); 2568 + 2569 + if (!uap->vendor->always_enabled) { 2570 + old_cr = pl011_read(uap, REG_CR); 2571 + pl011_write((old_cr & ~UART011_CR_CTSEN) | (UART01x_CR_UARTEN | UART011_CR_TXE), 2572 + uap, REG_CR); 2573 + } 2574 + 2575 + if (!uap->console_line_ended) 2576 + uart_console_write(&uap->port, "\n", 1, pl011_console_putchar); 2577 + uart_console_write(&uap->port, wctxt->outbuf, wctxt->len, pl011_console_putchar); 2578 + 2579 + while ((pl011_read(uap, REG_FR) ^ uap->vendor->inv_fr) & uap->vendor->fr_busy) 2580 + cpu_relax(); 2581 + 2582 + if (!uap->vendor->always_enabled) 2583 + pl011_write(old_cr, uap, REG_CR); 2584 + 2585 + clk_disable(uap->clk); 2586 + 2587 + nbcon_exit_unsafe(wctxt); 2588 + } 2589 + 2590 + static void 2591 + pl011_console_write_thread(struct console *co, struct nbcon_write_context *wctxt) 2592 + { 2593 + struct uart_amba_port *uap = amba_ports[co->index]; 2594 + unsigned int old_cr = 0; 2595 + 2596 + if (!nbcon_enter_unsafe(wctxt)) 2597 + return; 2598 + 2599 + clk_enable(uap->clk); 2600 + 2601 + if (!uap->vendor->always_enabled) { 2602 + old_cr = pl011_read(uap, REG_CR); 2603 + pl011_write((old_cr & ~UART011_CR_CTSEN) | (UART01x_CR_UARTEN | UART011_CR_TXE), 2604 + uap, REG_CR); 2605 + } 2606 + 2607 + if (nbcon_exit_unsafe(wctxt)) { 2608 + int i; 2609 + unsigned int len = READ_ONCE(wctxt->len); 2610 + 2611 + for (i = 0; i < len; i++) { 2612 + if (!nbcon_enter_unsafe(wctxt)) 2613 + break; 2614 + uart_console_write(&uap->port, wctxt->outbuf + i, 1, pl011_console_putchar); 2615 + if (!nbcon_exit_unsafe(wctxt)) 2616 + break; 2617 + } 2618 + } 2619 + 2620 + while (!nbcon_enter_unsafe(wctxt)) 2621 + nbcon_reacquire_nobuf(wctxt); 2622 + 2623 + while ((pl011_read(uap, REG_FR) ^ uap->vendor->inv_fr) & uap->vendor->fr_busy) 2624 + cpu_relax(); 2625 + 2626 + if (!uap->vendor->always_enabled) 2627 + pl011_write(old_cr, uap, REG_CR); 2628 + 2629 + clk_disable(uap->clk); 2630 + 2631 + nbcon_exit_unsafe(wctxt); 2632 + } 2633 + 2634 + static void 2635 + pl011_console_device_lock(struct console *co, unsigned long *flags) 2636 + { 2637 + __uart_port_lock_irqsave(&amba_ports[co->index]->port, flags); 2638 + } 2639 + 2640 + static void 2641 + pl011_console_device_unlock(struct console *co, unsigned long flags) 2642 + { 2643 + __uart_port_unlock_irqrestore(&amba_ports[co->index]->port, flags); 2644 + } 2645 + 2646 static struct uart_driver amba_reg; 2647 static struct console amba_console = { 2648 .name = "ttyAMA", 2649 .device = uart_console_device, 2650 .setup = pl011_console_setup, 2651 .match = pl011_console_match, 2652 + .write_atomic = pl011_console_write_atomic, 2653 + .write_thread = pl011_console_write_thread, 2654 + .device_lock = pl011_console_device_lock, 2655 + .device_unlock = pl011_console_device_unlock, 2656 + .flags = CON_PRINTBUFFER | CON_ANYTIME | CON_NBCON, 2657 .index = -1, 2658 .data = &amba_reg, 2659 }; ··· 3000 }; 3001 MODULE_DEVICE_TABLE(of, sbsa_uart_of_match); 3002 3003 + static const struct acpi_device_id sbsa_uart_acpi_match[] = { 3004 { "ARMH0011", 0 }, 3005 { "ARMHB000", 0 }, 3006 {}, ··· 3013 .driver = { 3014 .name = "sbsa-uart", 3015 .pm = &pl011_dev_pm_ops, 3016 + .of_match_table = sbsa_uart_of_match, 3017 + .acpi_match_table = sbsa_uart_acpi_match, 3018 .suppress_bind_attrs = IS_BUILTIN(CONFIG_SERIAL_AMBA_PL011), 3019 }, 3020 };
+1 -1
drivers/tty/serial/atmel_serial.c
··· 700 701 atmel_port->ms_irq_enabled = false; 702 703 - mctrl_gpio_disable_ms(atmel_port->gpios); 704 705 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_CTS)) 706 idr |= ATMEL_US_CTSIC;
··· 700 701 atmel_port->ms_irq_enabled = false; 702 703 + mctrl_gpio_disable_ms_no_sync(atmel_port->gpios); 704 705 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_CTS)) 706 idr |= ATMEL_US_CTSIC;
+249 -240
drivers/tty/serial/fsl_lpuart.c
··· 441 442 static void lpuart_stop_tx(struct uart_port *port) 443 { 444 - unsigned char temp; 445 446 - temp = readb(port->membase + UARTCR2); 447 - temp &= ~(UARTCR2_TIE | UARTCR2_TCIE); 448 - writeb(temp, port->membase + UARTCR2); 449 } 450 451 static void lpuart32_stop_tx(struct uart_port *port) 452 { 453 - unsigned long temp; 454 455 - temp = lpuart32_read(port, UARTCTRL); 456 - temp &= ~(UARTCTRL_TIE | UARTCTRL_TCIE); 457 - lpuart32_write(port, temp, UARTCTRL); 458 } 459 460 static void lpuart_stop_rx(struct uart_port *port) 461 { 462 - unsigned char temp; 463 464 - temp = readb(port->membase + UARTCR2); 465 - writeb(temp & ~UARTCR2_RE, port->membase + UARTCR2); 466 } 467 468 static void lpuart32_stop_rx(struct uart_port *port) 469 { 470 - unsigned long temp; 471 472 - temp = lpuart32_read(port, UARTCTRL); 473 - lpuart32_write(port, temp & ~UARTCTRL_RE, UARTCTRL); 474 } 475 476 static void lpuart_dma_tx(struct lpuart_port *sport) ··· 581 ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig); 582 583 if (ret) { 584 - dev_err(sport->port.dev, 585 "DMA slave config failed, err = %d\n", ret); 586 return ret; 587 } ··· 599 { 600 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 601 struct dma_chan *chan = sport->dma_tx_chan; 602 - u32 val; 603 604 if (sport->lpuart_dma_tx_use) { 605 if (sport->dma_tx_in_progress) { ··· 611 } 612 613 if (lpuart_is_32(sport)) { 614 - val = lpuart32_read(&sport->port, UARTFIFO); 615 - val |= UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH; 616 - lpuart32_write(&sport->port, val, UARTFIFO); 617 } else { 618 - val = readb(sport->port.membase + UARTCFIFO); 619 - val |= UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH; 620 - writeb(val, sport->port.membase + UARTCFIFO); 621 } 622 } 623 ··· 639 640 static int lpuart_poll_init(struct uart_port *port) 641 { 642 - struct lpuart_port *sport = container_of(port, 643 - struct lpuart_port, port); 644 unsigned long flags; 645 - unsigned char temp; 646 647 - sport->port.fifosize = 0; 648 649 - uart_port_lock_irqsave(&sport->port, &flags); 650 /* Disable Rx & Tx */ 651 - writeb(0, sport->port.membase + UARTCR2); 652 653 - temp = readb(sport->port.membase + UARTPFIFO); 654 /* Enable Rx and Tx FIFO */ 655 - writeb(temp | UARTPFIFO_RXFE | UARTPFIFO_TXFE, 656 - sport->port.membase + UARTPFIFO); 657 658 /* flush Tx and Rx FIFO */ 659 writeb(UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH, 660 - sport->port.membase + UARTCFIFO); 661 662 /* explicitly clear RDRF */ 663 - if (readb(sport->port.membase + UARTSR1) & UARTSR1_RDRF) { 664 - readb(sport->port.membase + UARTDR); 665 - writeb(UARTSFIFO_RXUF, sport->port.membase + UARTSFIFO); 666 } 667 668 - writeb(0, sport->port.membase + UARTTWFIFO); 669 - writeb(1, sport->port.membase + UARTRWFIFO); 670 671 /* Enable Rx and Tx */ 672 - writeb(UARTCR2_RE | UARTCR2_TE, sport->port.membase + UARTCR2); 673 - uart_port_unlock_irqrestore(&sport->port, flags); 674 675 return 0; 676 } ··· 691 static int lpuart32_poll_init(struct uart_port *port) 692 { 693 unsigned long flags; 694 - struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 695 - u32 temp; 696 697 - sport->port.fifosize = 0; 698 699 - uart_port_lock_irqsave(&sport->port, &flags); 700 701 /* Disable Rx & Tx */ 702 - lpuart32_write(&sport->port, 0, UARTCTRL); 703 704 - temp = lpuart32_read(&sport->port, UARTFIFO); 705 706 /* Enable Rx and Tx FIFO */ 707 - lpuart32_write(&sport->port, temp | UARTFIFO_RXFE | UARTFIFO_TXFE, UARTFIFO); 708 709 /* flush Tx and Rx FIFO */ 710 - lpuart32_write(&sport->port, UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH, UARTFIFO); 711 712 /* explicitly clear RDRF */ 713 - if (lpuart32_read(&sport->port, UARTSTAT) & UARTSTAT_RDRF) { 714 - lpuart32_read(&sport->port, UARTDATA); 715 - lpuart32_write(&sport->port, UARTFIFO_RXUF, UARTFIFO); 716 } 717 718 /* Enable Rx and Tx */ 719 - lpuart32_write(&sport->port, UARTCTRL_RE | UARTCTRL_TE, UARTCTRL); 720 - uart_port_unlock_irqrestore(&sport->port, flags); 721 722 return 0; 723 } ··· 749 static inline void lpuart32_transmit_buffer(struct lpuart_port *sport) 750 { 751 struct tty_port *tport = &sport->port.state->port; 752 - unsigned long txcnt; 753 unsigned char c; 754 755 if (sport->port.x_char) { ··· 786 { 787 struct lpuart_port *sport = container_of(port, 788 struct lpuart_port, port); 789 - unsigned char temp; 790 791 - temp = readb(port->membase + UARTCR2); 792 - writeb(temp | UARTCR2_TIE, port->membase + UARTCR2); 793 794 if (sport->lpuart_dma_tx_use) { 795 if (!lpuart_stopped_or_empty(port)) ··· 803 static void lpuart32_start_tx(struct uart_port *port) 804 { 805 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 806 - unsigned long temp; 807 808 if (sport->lpuart_dma_tx_use) { 809 if (!lpuart_stopped_or_empty(port)) 810 lpuart_dma_tx(sport); 811 } else { 812 - temp = lpuart32_read(port, UARTCTRL); 813 - lpuart32_write(port, temp | UARTCTRL_TIE, UARTCTRL); 814 815 if (lpuart32_read(port, UARTSTAT) & UARTSTAT_TDRE) 816 lpuart32_transmit_buffer(sport); ··· 836 { 837 struct lpuart_port *sport = container_of(port, 838 struct lpuart_port, port); 839 - unsigned char sr1 = readb(port->membase + UARTSR1); 840 - unsigned char sfifo = readb(port->membase + UARTSFIFO); 841 842 if (sport->dma_tx_in_progress) 843 return 0; ··· 852 { 853 struct lpuart_port *sport = container_of(port, 854 struct lpuart_port, port); 855 - unsigned long stat = lpuart32_read(port, UARTSTAT); 856 - unsigned long sfifo = lpuart32_read(port, UARTFIFO); 857 - unsigned long ctrl = lpuart32_read(port, UARTCTRL); 858 859 if (sport->dma_tx_in_progress) 860 return 0; ··· 881 { 882 unsigned int flg, ignored = 0, overrun = 0; 883 struct tty_port *port = &sport->port.state->port; 884 - unsigned char rx, sr; 885 886 uart_port_lock(&sport->port); 887 ··· 958 { 959 unsigned int flg, ignored = 0; 960 struct tty_port *port = &sport->port.state->port; 961 - unsigned long rx, sr; 962 bool is_break; 963 964 uart_port_lock(&sport->port); ··· 1036 static irqreturn_t lpuart_int(int irq, void *dev_id) 1037 { 1038 struct lpuart_port *sport = dev_id; 1039 - unsigned char sts; 1040 1041 sts = readb(sport->port.membase + UARTSR1); 1042 ··· 1110 int count, copied; 1111 1112 if (lpuart_is_32(sport)) { 1113 - unsigned long sr = lpuart32_read(&sport->port, UARTSTAT); 1114 1115 if (sr & (UARTSTAT_PE | UARTSTAT_FE)) { 1116 /* Clear the error flags */ ··· 1122 sport->port.icount.frame++; 1123 } 1124 } else { 1125 - unsigned char sr = readb(sport->port.membase + UARTSR1); 1126 1127 if (sr & (UARTSR1_PE | UARTSR1_FE)) { 1128 - unsigned char cr2; 1129 1130 /* Disable receiver during this operation... */ 1131 cr2 = readb(sport->port.membase + UARTCR2); ··· 1276 static irqreturn_t lpuart32_int(int irq, void *dev_id) 1277 { 1278 struct lpuart_port *sport = dev_id; 1279 - unsigned long sts, rxcount; 1280 1281 sts = lpuart32_read(&sport->port, UARTSTAT); 1282 rxcount = lpuart32_read(&sport->port, UARTWATER); ··· 1408 dma_async_issue_pending(chan); 1409 1410 if (lpuart_is_32(sport)) { 1411 - unsigned long temp = lpuart32_read(&sport->port, UARTBAUD); 1412 1413 - lpuart32_write(&sport->port, temp | UARTBAUD_RDMAE, UARTBAUD); 1414 1415 if (sport->dma_idle_int) { 1416 - unsigned long ctrl = lpuart32_read(&sport->port, UARTCTRL); 1417 1418 lpuart32_write(&sport->port, ctrl | UARTCTRL_ILIE, UARTCTRL); 1419 } ··· 1446 static int lpuart_config_rs485(struct uart_port *port, struct ktermios *termios, 1447 struct serial_rs485 *rs485) 1448 { 1449 - struct lpuart_port *sport = container_of(port, 1450 - struct lpuart_port, port); 1451 - 1452 - u8 modem = readb(sport->port.membase + UARTMODEM) & 1453 ~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE); 1454 - writeb(modem, sport->port.membase + UARTMODEM); 1455 1456 if (rs485->flags & SER_RS485_ENABLED) { 1457 /* Enable auto RS-485 RTS mode */ ··· 1466 modem &= ~UARTMODEM_TXRTSPOL; 1467 } 1468 1469 - writeb(modem, sport->port.membase + UARTMODEM); 1470 return 0; 1471 } 1472 1473 static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termios, 1474 struct serial_rs485 *rs485) 1475 { 1476 - struct lpuart_port *sport = container_of(port, 1477 - struct lpuart_port, port); 1478 - 1479 - unsigned long modem = lpuart32_read(&sport->port, UARTMODIR) 1480 & ~(UARTMODIR_TXRTSPOL | UARTMODIR_TXRTSE); 1481 - lpuart32_write(&sport->port, modem, UARTMODIR); 1482 1483 if (rs485->flags & SER_RS485_ENABLED) { 1484 /* Enable auto RS-485 RTS mode */ ··· 1506 modem &= ~UARTMODIR_TXRTSPOL; 1507 } 1508 1509 - lpuart32_write(&sport->port, modem, UARTMODIR); 1510 return 0; 1511 } 1512 1513 static unsigned int lpuart_get_mctrl(struct uart_port *port) 1514 { 1515 unsigned int mctrl = 0; 1516 - u8 reg; 1517 1518 - reg = readb(port->membase + UARTCR1); 1519 - if (reg & UARTCR1_LOOPS) 1520 mctrl |= TIOCM_LOOP; 1521 1522 return mctrl; ··· 1529 static unsigned int lpuart32_get_mctrl(struct uart_port *port) 1530 { 1531 unsigned int mctrl = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS; 1532 - u32 reg; 1533 1534 - reg = lpuart32_read(port, UARTCTRL); 1535 - if (reg & UARTCTRL_LOOPS) 1536 mctrl |= TIOCM_LOOP; 1537 1538 return mctrl; ··· 1540 1541 static void lpuart_set_mctrl(struct uart_port *port, unsigned int mctrl) 1542 { 1543 - u8 reg; 1544 1545 - reg = readb(port->membase + UARTCR1); 1546 1547 /* for internal loopback we need LOOPS=1 and RSRC=0 */ 1548 - reg &= ~(UARTCR1_LOOPS | UARTCR1_RSRC); 1549 if (mctrl & TIOCM_LOOP) 1550 - reg |= UARTCR1_LOOPS; 1551 1552 - writeb(reg, port->membase + UARTCR1); 1553 } 1554 1555 static void lpuart32_set_mctrl(struct uart_port *port, unsigned int mctrl) 1556 { 1557 - u32 reg; 1558 1559 - reg = lpuart32_read(port, UARTCTRL); 1560 1561 /* for internal loopback we need LOOPS=1 and RSRC=0 */ 1562 - reg &= ~(UARTCTRL_LOOPS | UARTCTRL_RSRC); 1563 if (mctrl & TIOCM_LOOP) 1564 - reg |= UARTCTRL_LOOPS; 1565 1566 - lpuart32_write(port, reg, UARTCTRL); 1567 } 1568 1569 static void lpuart_break_ctl(struct uart_port *port, int break_state) 1570 { 1571 - unsigned char temp; 1572 1573 - temp = readb(port->membase + UARTCR2) & ~UARTCR2_SBK; 1574 1575 if (break_state != 0) 1576 - temp |= UARTCR2_SBK; 1577 1578 - writeb(temp, port->membase + UARTCR2); 1579 } 1580 1581 static void lpuart32_break_ctl(struct uart_port *port, int break_state) 1582 { 1583 - unsigned long temp; 1584 1585 - temp = lpuart32_read(port, UARTCTRL); 1586 1587 /* 1588 * LPUART IP now has two known bugs, one is CTS has higher priority than the ··· 1599 * Disable the transmitter to prevent any data from being sent out 1600 * during break, then invert the TX line to send break. 1601 */ 1602 - temp &= ~UARTCTRL_TE; 1603 - lpuart32_write(port, temp, UARTCTRL); 1604 - temp |= UARTCTRL_TXINV; 1605 - lpuart32_write(port, temp, UARTCTRL); 1606 } else { 1607 /* Disable the TXINV to turn off break and re-enable transmitter. */ 1608 - temp &= ~UARTCTRL_TXINV; 1609 - lpuart32_write(port, temp, UARTCTRL); 1610 - temp |= UARTCTRL_TE; 1611 - lpuart32_write(port, temp, UARTCTRL); 1612 } 1613 } 1614 1615 static void lpuart_setup_watermark(struct lpuart_port *sport) 1616 { 1617 - unsigned char val, cr2; 1618 - unsigned char cr2_saved; 1619 1620 cr2 = readb(sport->port.membase + UARTCR2); 1621 cr2_saved = cr2; ··· 1622 UARTCR2_RIE | UARTCR2_RE); 1623 writeb(cr2, sport->port.membase + UARTCR2); 1624 1625 - val = readb(sport->port.membase + UARTPFIFO); 1626 - writeb(val | UARTPFIFO_TXFE | UARTPFIFO_RXFE, 1627 sport->port.membase + UARTPFIFO); 1628 1629 /* flush Tx and Rx FIFO */ ··· 1647 1648 static void lpuart_setup_watermark_enable(struct lpuart_port *sport) 1649 { 1650 - unsigned char cr2; 1651 1652 lpuart_setup_watermark(sport); 1653 ··· 1658 1659 static void lpuart32_setup_watermark(struct lpuart_port *sport) 1660 { 1661 - unsigned long val, ctrl; 1662 - unsigned long ctrl_saved; 1663 1664 ctrl = lpuart32_read(&sport->port, UARTCTRL); 1665 ctrl_saved = ctrl; ··· 1693 1694 static void lpuart32_setup_watermark_enable(struct lpuart_port *sport) 1695 { 1696 - u32 temp; 1697 1698 lpuart32_setup_watermark(sport); 1699 1700 - temp = lpuart32_read(&sport->port, UARTCTRL); 1701 - temp |= UARTCTRL_RE | UARTCTRL_TE; 1702 - temp |= FIELD_PREP(UARTCTRL_IDLECFG, 0x7); 1703 - lpuart32_write(&sport->port, temp, UARTCTRL); 1704 } 1705 1706 static void rx_dma_timer_init(struct lpuart_port *sport) ··· 1767 static void lpuart_rx_dma_startup(struct lpuart_port *sport) 1768 { 1769 int ret; 1770 - unsigned char cr3; 1771 1772 if (uart_console(&sport->port)) 1773 goto err; ··· 1817 static int lpuart_startup(struct uart_port *port) 1818 { 1819 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 1820 - unsigned char temp; 1821 1822 /* determine FIFO size and enable FIFO mode */ 1823 - temp = readb(sport->port.membase + UARTPFIFO); 1824 1825 - sport->txfifo_size = UARTFIFO_DEPTH((temp >> UARTPFIFO_TXSIZE_OFF) & 1826 UARTPFIFO_FIFOSIZE_MASK); 1827 - sport->port.fifosize = sport->txfifo_size; 1828 1829 - sport->rxfifo_size = UARTFIFO_DEPTH((temp >> UARTPFIFO_RXSIZE_OFF) & 1830 UARTPFIFO_FIFOSIZE_MASK); 1831 1832 lpuart_request_dma(sport); ··· 1837 1838 static void lpuart32_hw_disable(struct lpuart_port *sport) 1839 { 1840 - unsigned long temp; 1841 1842 - temp = lpuart32_read(&sport->port, UARTCTRL); 1843 - temp &= ~(UARTCTRL_RIE | UARTCTRL_ILIE | UARTCTRL_RE | 1844 UARTCTRL_TIE | UARTCTRL_TE); 1845 - lpuart32_write(&sport->port, temp, UARTCTRL); 1846 } 1847 1848 static void lpuart32_configure(struct lpuart_port *sport) 1849 { 1850 - unsigned long temp; 1851 1852 - temp = lpuart32_read(&sport->port, UARTCTRL); 1853 if (!sport->lpuart_dma_rx_use) 1854 - temp |= UARTCTRL_RIE | UARTCTRL_ILIE; 1855 if (!sport->lpuart_dma_tx_use) 1856 - temp |= UARTCTRL_TIE; 1857 - lpuart32_write(&sport->port, temp, UARTCTRL); 1858 } 1859 1860 static void lpuart32_hw_setup(struct lpuart_port *sport) ··· 1877 static int lpuart32_startup(struct uart_port *port) 1878 { 1879 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 1880 - unsigned long temp; 1881 1882 /* determine FIFO size */ 1883 - temp = lpuart32_read(&sport->port, UARTFIFO); 1884 1885 - sport->txfifo_size = UARTFIFO_DEPTH((temp >> UARTFIFO_TXSIZE_OFF) & 1886 UARTFIFO_FIFOSIZE_MASK); 1887 - sport->port.fifosize = sport->txfifo_size; 1888 1889 - sport->rxfifo_size = UARTFIFO_DEPTH((temp >> UARTFIFO_RXSIZE_OFF) & 1890 UARTFIFO_FIFOSIZE_MASK); 1891 1892 /* ··· 1897 if (is_layerscape_lpuart(sport)) { 1898 sport->rxfifo_size = 16; 1899 sport->txfifo_size = 16; 1900 - sport->port.fifosize = sport->txfifo_size; 1901 } 1902 1903 lpuart_request_dma(sport); ··· 1931 static void lpuart_shutdown(struct uart_port *port) 1932 { 1933 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 1934 - unsigned char temp; 1935 unsigned long flags; 1936 1937 uart_port_lock_irqsave(port, &flags); 1938 1939 /* disable Rx/Tx and interrupts */ 1940 - temp = readb(port->membase + UARTCR2); 1941 - temp &= ~(UARTCR2_TE | UARTCR2_RE | 1942 UARTCR2_TIE | UARTCR2_TCIE | UARTCR2_RIE); 1943 - writeb(temp, port->membase + UARTCR2); 1944 1945 uart_port_unlock_irqrestore(port, flags); 1946 ··· 1951 { 1952 struct lpuart_port *sport = 1953 container_of(port, struct lpuart_port, port); 1954 - unsigned long temp; 1955 unsigned long flags; 1956 1957 uart_port_lock_irqsave(port, &flags); 1958 1959 /* clear status */ 1960 - temp = lpuart32_read(&sport->port, UARTSTAT); 1961 - lpuart32_write(&sport->port, temp, UARTSTAT); 1962 1963 /* disable Rx/Tx DMA */ 1964 temp = lpuart32_read(port, UARTBAUD); ··· 1987 { 1988 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 1989 unsigned long flags; 1990 - unsigned char cr1, old_cr1, old_cr2, cr3, cr4, bdh, modem; 1991 unsigned int baud; 1992 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; 1993 unsigned int sbr, brfa; 1994 1995 - cr1 = old_cr1 = readb(sport->port.membase + UARTCR1); 1996 - old_cr2 = readb(sport->port.membase + UARTCR2); 1997 - cr3 = readb(sport->port.membase + UARTCR3); 1998 - cr4 = readb(sport->port.membase + UARTCR4); 1999 - bdh = readb(sport->port.membase + UARTBDH); 2000 - modem = readb(sport->port.membase + UARTMODEM); 2001 /* 2002 * only support CS8 and CS7, and for CS7 must enable PE. 2003 * supported mode: ··· 2029 * When auto RS-485 RTS mode is enabled, 2030 * hardware flow control need to be disabled. 2031 */ 2032 - if (sport->port.rs485.flags & SER_RS485_ENABLED) 2033 termios->c_cflag &= ~CRTSCTS; 2034 2035 if (termios->c_cflag & CRTSCTS) ··· 2070 * Need to update the Ring buffer length according to the selected 2071 * baud rate and restart Rx DMA path. 2072 * 2073 - * Since timer function acqures sport->port.lock, need to stop before 2074 * acquring same lock because otherwise del_timer_sync() can deadlock. 2075 */ 2076 if (old && sport->lpuart_dma_rx_use) 2077 - lpuart_dma_rx_free(&sport->port); 2078 2079 - uart_port_lock_irqsave(&sport->port, &flags); 2080 2081 - sport->port.read_status_mask = 0; 2082 if (termios->c_iflag & INPCK) 2083 - sport->port.read_status_mask |= UARTSR1_FE | UARTSR1_PE; 2084 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) 2085 - sport->port.read_status_mask |= UARTSR1_FE; 2086 2087 /* characters to ignore */ 2088 - sport->port.ignore_status_mask = 0; 2089 if (termios->c_iflag & IGNPAR) 2090 - sport->port.ignore_status_mask |= UARTSR1_PE; 2091 if (termios->c_iflag & IGNBRK) { 2092 - sport->port.ignore_status_mask |= UARTSR1_FE; 2093 /* 2094 * if we're ignoring parity and break indicators, 2095 * ignore overruns too (for real raw support). 2096 */ 2097 if (termios->c_iflag & IGNPAR) 2098 - sport->port.ignore_status_mask |= UARTSR1_OR; 2099 } 2100 2101 /* update the per-port timeout */ 2102 uart_update_timeout(port, termios->c_cflag, baud); 2103 2104 /* wait transmit engin complete */ 2105 - lpuart_wait_bit_set(&sport->port, UARTSR1, UARTSR1_TC); 2106 2107 /* disable transmit and receive */ 2108 writeb(old_cr2 & ~(UARTCR2_TE | UARTCR2_RE), 2109 - sport->port.membase + UARTCR2); 2110 2111 - sbr = sport->port.uartclk / (16 * baud); 2112 - brfa = ((sport->port.uartclk - (16 * sbr * baud)) * 2) / baud; 2113 bdh &= ~UARTBDH_SBR_MASK; 2114 bdh |= (sbr >> 8) & 0x1F; 2115 cr4 &= ~UARTCR4_BRFA_MASK; 2116 brfa &= UARTCR4_BRFA_MASK; 2117 - writeb(cr4 | brfa, sport->port.membase + UARTCR4); 2118 - writeb(bdh, sport->port.membase + UARTBDH); 2119 - writeb(sbr & 0xFF, sport->port.membase + UARTBDL); 2120 - writeb(cr3, sport->port.membase + UARTCR3); 2121 - writeb(cr1, sport->port.membase + UARTCR1); 2122 - writeb(modem, sport->port.membase + UARTMODEM); 2123 2124 /* restore control register */ 2125 - writeb(old_cr2, sport->port.membase + UARTCR2); 2126 2127 if (old && sport->lpuart_dma_rx_use) { 2128 if (!lpuart_start_rx_dma(sport)) ··· 2131 sport->lpuart_dma_rx_use = false; 2132 } 2133 2134 - uart_port_unlock_irqrestore(&sport->port, flags); 2135 } 2136 2137 static void __lpuart32_serial_setbrg(struct uart_port *port, 2138 unsigned int baudrate, bool use_rx_dma, 2139 bool use_tx_dma) 2140 { 2141 - u32 sbr, osr, baud_diff, tmp_osr, tmp_sbr, tmp_diff, tmp; 2142 u32 clk = port->uartclk; 2143 2144 /* ··· 2167 tmp_diff = clk / (tmp_osr * tmp_sbr) - baudrate; 2168 2169 /* select best values between sbr and sbr+1 */ 2170 - tmp = clk / (tmp_osr * (tmp_sbr + 1)); 2171 - if (tmp_diff > (baudrate - tmp)) { 2172 - tmp_diff = baudrate - tmp; 2173 tmp_sbr++; 2174 } 2175 ··· 2191 dev_warn(port->dev, 2192 "unacceptable baud rate difference of more than 3%%\n"); 2193 2194 - tmp = lpuart32_read(port, UARTBAUD); 2195 2196 if ((osr > 3) && (osr < 8)) 2197 - tmp |= UARTBAUD_BOTHEDGE; 2198 2199 - tmp &= ~(UARTBAUD_OSR_MASK << UARTBAUD_OSR_SHIFT); 2200 - tmp |= ((osr-1) & UARTBAUD_OSR_MASK) << UARTBAUD_OSR_SHIFT; 2201 2202 - tmp &= ~UARTBAUD_SBR_MASK; 2203 - tmp |= sbr & UARTBAUD_SBR_MASK; 2204 2205 if (!use_rx_dma) 2206 - tmp &= ~UARTBAUD_RDMAE; 2207 if (!use_tx_dma) 2208 - tmp &= ~UARTBAUD_TDMAE; 2209 2210 - lpuart32_write(port, tmp, UARTBAUD); 2211 } 2212 2213 static void lpuart32_serial_setbrg(struct lpuart_port *sport, ··· 2225 { 2226 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 2227 unsigned long flags; 2228 - unsigned long ctrl, old_ctrl, bd, modem; 2229 unsigned int baud; 2230 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; 2231 2232 - ctrl = old_ctrl = lpuart32_read(&sport->port, UARTCTRL); 2233 - bd = lpuart32_read(&sport->port, UARTBAUD); 2234 - modem = lpuart32_read(&sport->port, UARTMODIR); 2235 sport->is_cs7 = false; 2236 /* 2237 * only support CS8 and CS7 ··· 2265 * When auto RS-485 RTS mode is enabled, 2266 * hardware flow control need to be disabled. 2267 */ 2268 - if (sport->port.rs485.flags & SER_RS485_ENABLED) 2269 termios->c_cflag &= ~CRTSCTS; 2270 2271 if (termios->c_cflag & CRTSCTS) ··· 2315 * Need to update the Ring buffer length according to the selected 2316 * baud rate and restart Rx DMA path. 2317 * 2318 - * Since timer function acqures sport->port.lock, need to stop before 2319 * acquring same lock because otherwise del_timer_sync() can deadlock. 2320 */ 2321 if (old && sport->lpuart_dma_rx_use) 2322 - lpuart_dma_rx_free(&sport->port); 2323 2324 - uart_port_lock_irqsave(&sport->port, &flags); 2325 2326 - sport->port.read_status_mask = 0; 2327 if (termios->c_iflag & INPCK) 2328 - sport->port.read_status_mask |= UARTSTAT_FE | UARTSTAT_PE; 2329 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) 2330 - sport->port.read_status_mask |= UARTSTAT_FE; 2331 2332 /* characters to ignore */ 2333 - sport->port.ignore_status_mask = 0; 2334 if (termios->c_iflag & IGNPAR) 2335 - sport->port.ignore_status_mask |= UARTSTAT_PE; 2336 if (termios->c_iflag & IGNBRK) { 2337 - sport->port.ignore_status_mask |= UARTSTAT_FE; 2338 /* 2339 * if we're ignoring parity and break indicators, 2340 * ignore overruns too (for real raw support). 2341 */ 2342 if (termios->c_iflag & IGNPAR) 2343 - sport->port.ignore_status_mask |= UARTSTAT_OR; 2344 } 2345 2346 /* update the per-port timeout */ 2347 uart_update_timeout(port, termios->c_cflag, baud); 2348 2349 /* 2350 * LPUART Transmission Complete Flag may never be set while queuing a break 2351 * character, so skip waiting for transmission complete when UARTCTRL_SBK is 2352 * asserted. 2353 */ 2354 - if (!(old_ctrl & UARTCTRL_SBK)) { 2355 - lpuart32_write(&sport->port, 0, UARTMODIR); 2356 - lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC); 2357 - } 2358 2359 /* disable transmit and receive */ 2360 - lpuart32_write(&sport->port, old_ctrl & ~(UARTCTRL_TE | UARTCTRL_RE), 2361 UARTCTRL); 2362 2363 - lpuart32_write(&sport->port, bd, UARTBAUD); 2364 lpuart32_serial_setbrg(sport, baud); 2365 - /* disable CTS before enabling UARTCTRL_TE to avoid pending idle preamble */ 2366 - lpuart32_write(&sport->port, modem & ~UARTMODIR_TXCTSE, UARTMODIR); 2367 /* restore control register */ 2368 - lpuart32_write(&sport->port, ctrl, UARTCTRL); 2369 /* re-enable the CTS if needed */ 2370 - lpuart32_write(&sport->port, modem, UARTMODIR); 2371 2372 if ((ctrl & (UARTCTRL_PE | UARTCTRL_M)) == UARTCTRL_PE) 2373 sport->is_cs7 = true; ··· 2381 sport->lpuart_dma_rx_use = false; 2382 } 2383 2384 - uart_port_unlock_irqrestore(&sport->port, flags); 2385 } 2386 2387 static const char *lpuart_type(struct uart_port *port) ··· 2494 lpuart_console_write(struct console *co, const char *s, unsigned int count) 2495 { 2496 struct lpuart_port *sport = lpuart_ports[co->index]; 2497 - unsigned char old_cr2, cr2; 2498 unsigned long flags; 2499 int locked = 1; 2500 ··· 2524 lpuart32_console_write(struct console *co, const char *s, unsigned int count) 2525 { 2526 struct lpuart_port *sport = lpuart_ports[co->index]; 2527 - unsigned long old_cr, cr; 2528 unsigned long flags; 2529 int locked = 1; 2530 ··· 2558 lpuart_console_get_options(struct lpuart_port *sport, int *baud, 2559 int *parity, int *bits) 2560 { 2561 - unsigned char cr, bdh, bdl, brfa; 2562 unsigned int sbr, uartclk, baud_raw; 2563 2564 cr = readb(sport->port.membase + UARTCR2); ··· 2607 lpuart32_console_get_options(struct lpuart_port *sport, int *baud, 2608 int *parity, int *bits) 2609 { 2610 - unsigned long cr, bd; 2611 unsigned int sbr, uartclk, baud_raw; 2612 2613 cr = lpuart32_read(&sport->port, UARTCTRL); ··· 2813 { 2814 struct uart_port *port = &sport->port; 2815 void __iomem *global_addr; 2816 - unsigned long ctrl, bd; 2817 unsigned int val = 0; 2818 int ret; 2819 2820 ret = clk_prepare_enable(sport->ipg_clk); 2821 if (ret) { 2822 - dev_err(sport->port.dev, "failed to enable uart ipg clk: %d\n", ret); 2823 return ret; 2824 } 2825 ··· 2830 */ 2831 ctrl = lpuart32_read(port, UARTCTRL); 2832 if (ctrl & UARTCTRL_TE) { 2833 - bd = lpuart32_read(&sport->port, UARTBAUD); 2834 if (read_poll_timeout(lpuart32_tx_empty, val, val, 1, 100000, false, 2835 port)) { 2836 - dev_warn(sport->port.dev, 2837 "timeout waiting for transmit engine to complete\n"); 2838 clk_disable_unprepare(sport->ipg_clk); 2839 return 0; ··· 2962 goto failed_attach_port; 2963 2964 ret = devm_request_irq(&pdev->dev, sport->port.irq, handler, 0, 2965 - DRIVER_NAME, sport); 2966 if (ret) 2967 goto failed_irq_request; 2968 ··· 3019 3020 static void serial_lpuart_enable_wakeup(struct lpuart_port *sport, bool on) 3021 { 3022 - unsigned int val, baud; 3023 3024 if (lpuart_is_32(sport)) { 3025 val = lpuart32_read(&sport->port, UARTCTRL); ··· 3084 static int lpuart_resume_noirq(struct device *dev) 3085 { 3086 struct lpuart_port *sport = dev_get_drvdata(dev); 3087 - unsigned int val; 3088 3089 pinctrl_pm_select_default_state(dev); 3090 ··· 3093 3094 /* clear the wakeup flags */ 3095 if (lpuart_is_32(sport)) { 3096 - val = lpuart32_read(&sport->port, UARTSTAT); 3097 - lpuart32_write(&sport->port, val, UARTSTAT); 3098 } 3099 } 3100 ··· 3104 static int lpuart_suspend(struct device *dev) 3105 { 3106 struct lpuart_port *sport = dev_get_drvdata(dev); 3107 - unsigned long temp, flags; 3108 3109 uart_suspend_port(&lpuart_reg, &sport->port); 3110 ··· 3185 * in VLLS mode, or restore console setting here. 3186 */ 3187 if (is_imx7ulp_lpuart(sport) && lpuart_uport_is_active(sport) && 3188 - console_suspend_enabled && uart_console(&sport->port)) { 3189 3190 mutex_lock(&port->mutex); 3191 memset(&termios, 0, sizeof(struct ktermios));
··· 441 442 static void lpuart_stop_tx(struct uart_port *port) 443 { 444 + u8 cr2; 445 446 + cr2 = readb(port->membase + UARTCR2); 447 + cr2 &= ~(UARTCR2_TIE | UARTCR2_TCIE); 448 + writeb(cr2, port->membase + UARTCR2); 449 } 450 451 static void lpuart32_stop_tx(struct uart_port *port) 452 { 453 + u32 ctrl; 454 455 + ctrl = lpuart32_read(port, UARTCTRL); 456 + ctrl &= ~(UARTCTRL_TIE | UARTCTRL_TCIE); 457 + lpuart32_write(port, ctrl, UARTCTRL); 458 } 459 460 static void lpuart_stop_rx(struct uart_port *port) 461 { 462 + u8 cr2; 463 464 + cr2 = readb(port->membase + UARTCR2); 465 + writeb(cr2 & ~UARTCR2_RE, port->membase + UARTCR2); 466 } 467 468 static void lpuart32_stop_rx(struct uart_port *port) 469 { 470 + u32 ctrl; 471 472 + ctrl = lpuart32_read(port, UARTCTRL); 473 + lpuart32_write(port, ctrl & ~UARTCTRL_RE, UARTCTRL); 474 } 475 476 static void lpuart_dma_tx(struct lpuart_port *sport) ··· 581 ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig); 582 583 if (ret) { 584 + dev_err(port->dev, 585 "DMA slave config failed, err = %d\n", ret); 586 return ret; 587 } ··· 599 { 600 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 601 struct dma_chan *chan = sport->dma_tx_chan; 602 + u32 fifo; 603 604 if (sport->lpuart_dma_tx_use) { 605 if (sport->dma_tx_in_progress) { ··· 611 } 612 613 if (lpuart_is_32(sport)) { 614 + fifo = lpuart32_read(port, UARTFIFO); 615 + fifo |= UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH; 616 + lpuart32_write(port, fifo, UARTFIFO); 617 } else { 618 + fifo = readb(port->membase + UARTCFIFO); 619 + fifo |= UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH; 620 + writeb(fifo, port->membase + UARTCFIFO); 621 } 622 } 623 ··· 639 640 static int lpuart_poll_init(struct uart_port *port) 641 { 642 unsigned long flags; 643 + u8 fifo; 644 645 + port->fifosize = 0; 646 647 + uart_port_lock_irqsave(port, &flags); 648 /* Disable Rx & Tx */ 649 + writeb(0, port->membase + UARTCR2); 650 651 + fifo = readb(port->membase + UARTPFIFO); 652 /* Enable Rx and Tx FIFO */ 653 + writeb(fifo | UARTPFIFO_RXFE | UARTPFIFO_TXFE, 654 + port->membase + UARTPFIFO); 655 656 /* flush Tx and Rx FIFO */ 657 writeb(UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH, 658 + port->membase + UARTCFIFO); 659 660 /* explicitly clear RDRF */ 661 + if (readb(port->membase + UARTSR1) & UARTSR1_RDRF) { 662 + readb(port->membase + UARTDR); 663 + writeb(UARTSFIFO_RXUF, port->membase + UARTSFIFO); 664 } 665 666 + writeb(0, port->membase + UARTTWFIFO); 667 + writeb(1, port->membase + UARTRWFIFO); 668 669 /* Enable Rx and Tx */ 670 + writeb(UARTCR2_RE | UARTCR2_TE, port->membase + UARTCR2); 671 + uart_port_unlock_irqrestore(port, flags); 672 673 return 0; 674 } ··· 693 static int lpuart32_poll_init(struct uart_port *port) 694 { 695 unsigned long flags; 696 + u32 fifo; 697 698 + port->fifosize = 0; 699 700 + uart_port_lock_irqsave(port, &flags); 701 702 /* Disable Rx & Tx */ 703 + lpuart32_write(port, 0, UARTCTRL); 704 705 + fifo = lpuart32_read(port, UARTFIFO); 706 707 /* Enable Rx and Tx FIFO */ 708 + lpuart32_write(port, fifo | UARTFIFO_RXFE | UARTFIFO_TXFE, UARTFIFO); 709 710 /* flush Tx and Rx FIFO */ 711 + lpuart32_write(port, UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH, UARTFIFO); 712 713 /* explicitly clear RDRF */ 714 + if (lpuart32_read(port, UARTSTAT) & UARTSTAT_RDRF) { 715 + lpuart32_read(port, UARTDATA); 716 + lpuart32_write(port, UARTFIFO_RXUF, UARTFIFO); 717 } 718 719 /* Enable Rx and Tx */ 720 + lpuart32_write(port, UARTCTRL_RE | UARTCTRL_TE, UARTCTRL); 721 + uart_port_unlock_irqrestore(port, flags); 722 723 return 0; 724 } ··· 752 static inline void lpuart32_transmit_buffer(struct lpuart_port *sport) 753 { 754 struct tty_port *tport = &sport->port.state->port; 755 + u32 txcnt; 756 unsigned char c; 757 758 if (sport->port.x_char) { ··· 789 { 790 struct lpuart_port *sport = container_of(port, 791 struct lpuart_port, port); 792 + u8 cr2; 793 794 + cr2 = readb(port->membase + UARTCR2); 795 + writeb(cr2 | UARTCR2_TIE, port->membase + UARTCR2); 796 797 if (sport->lpuart_dma_tx_use) { 798 if (!lpuart_stopped_or_empty(port)) ··· 806 static void lpuart32_start_tx(struct uart_port *port) 807 { 808 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 809 + u32 ctrl; 810 811 if (sport->lpuart_dma_tx_use) { 812 if (!lpuart_stopped_or_empty(port)) 813 lpuart_dma_tx(sport); 814 } else { 815 + ctrl = lpuart32_read(port, UARTCTRL); 816 + lpuart32_write(port, ctrl | UARTCTRL_TIE, UARTCTRL); 817 818 if (lpuart32_read(port, UARTSTAT) & UARTSTAT_TDRE) 819 lpuart32_transmit_buffer(sport); ··· 839 { 840 struct lpuart_port *sport = container_of(port, 841 struct lpuart_port, port); 842 + u8 sr1 = readb(port->membase + UARTSR1); 843 + u8 sfifo = readb(port->membase + UARTSFIFO); 844 845 if (sport->dma_tx_in_progress) 846 return 0; ··· 855 { 856 struct lpuart_port *sport = container_of(port, 857 struct lpuart_port, port); 858 + u32 stat = lpuart32_read(port, UARTSTAT); 859 + u32 sfifo = lpuart32_read(port, UARTFIFO); 860 + u32 ctrl = lpuart32_read(port, UARTCTRL); 861 862 if (sport->dma_tx_in_progress) 863 return 0; ··· 884 { 885 unsigned int flg, ignored = 0, overrun = 0; 886 struct tty_port *port = &sport->port.state->port; 887 + u8 rx, sr; 888 889 uart_port_lock(&sport->port); 890 ··· 961 { 962 unsigned int flg, ignored = 0; 963 struct tty_port *port = &sport->port.state->port; 964 + u32 rx, sr; 965 bool is_break; 966 967 uart_port_lock(&sport->port); ··· 1039 static irqreturn_t lpuart_int(int irq, void *dev_id) 1040 { 1041 struct lpuart_port *sport = dev_id; 1042 + u8 sts; 1043 1044 sts = readb(sport->port.membase + UARTSR1); 1045 ··· 1113 int count, copied; 1114 1115 if (lpuart_is_32(sport)) { 1116 + u32 sr = lpuart32_read(&sport->port, UARTSTAT); 1117 1118 if (sr & (UARTSTAT_PE | UARTSTAT_FE)) { 1119 /* Clear the error flags */ ··· 1125 sport->port.icount.frame++; 1126 } 1127 } else { 1128 + u8 sr = readb(sport->port.membase + UARTSR1); 1129 1130 if (sr & (UARTSR1_PE | UARTSR1_FE)) { 1131 + u8 cr2; 1132 1133 /* Disable receiver during this operation... */ 1134 cr2 = readb(sport->port.membase + UARTCR2); ··· 1279 static irqreturn_t lpuart32_int(int irq, void *dev_id) 1280 { 1281 struct lpuart_port *sport = dev_id; 1282 + u32 sts, rxcount; 1283 1284 sts = lpuart32_read(&sport->port, UARTSTAT); 1285 rxcount = lpuart32_read(&sport->port, UARTWATER); ··· 1411 dma_async_issue_pending(chan); 1412 1413 if (lpuart_is_32(sport)) { 1414 + u32 baud = lpuart32_read(&sport->port, UARTBAUD); 1415 1416 + lpuart32_write(&sport->port, baud | UARTBAUD_RDMAE, UARTBAUD); 1417 1418 if (sport->dma_idle_int) { 1419 + u32 ctrl = lpuart32_read(&sport->port, UARTCTRL); 1420 1421 lpuart32_write(&sport->port, ctrl | UARTCTRL_ILIE, UARTCTRL); 1422 } ··· 1449 static int lpuart_config_rs485(struct uart_port *port, struct ktermios *termios, 1450 struct serial_rs485 *rs485) 1451 { 1452 + u8 modem = readb(port->membase + UARTMODEM) & 1453 ~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE); 1454 + writeb(modem, port->membase + UARTMODEM); 1455 1456 if (rs485->flags & SER_RS485_ENABLED) { 1457 /* Enable auto RS-485 RTS mode */ ··· 1472 modem &= ~UARTMODEM_TXRTSPOL; 1473 } 1474 1475 + writeb(modem, port->membase + UARTMODEM); 1476 return 0; 1477 } 1478 1479 static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termios, 1480 struct serial_rs485 *rs485) 1481 { 1482 + u32 modem = lpuart32_read(port, UARTMODIR) 1483 & ~(UARTMODIR_TXRTSPOL | UARTMODIR_TXRTSE); 1484 + u32 ctrl; 1485 + 1486 + /* TXRTSE and TXRTSPOL only can be changed when transmitter is disabled. */ 1487 + ctrl = lpuart32_read(port, UARTCTRL); 1488 + if (ctrl & UARTCTRL_TE) { 1489 + /* wait for the transmit engine to complete */ 1490 + lpuart32_wait_bit_set(port, UARTSTAT, UARTSTAT_TC); 1491 + lpuart32_write(port, ctrl & ~UARTCTRL_TE, UARTCTRL); 1492 + 1493 + while (lpuart32_read(port, UARTCTRL) & UARTCTRL_TE) 1494 + cpu_relax(); 1495 + } 1496 + 1497 + lpuart32_write(port, modem, UARTMODIR); 1498 1499 if (rs485->flags & SER_RS485_ENABLED) { 1500 /* Enable auto RS-485 RTS mode */ ··· 1502 modem &= ~UARTMODIR_TXRTSPOL; 1503 } 1504 1505 + lpuart32_write(port, modem, UARTMODIR); 1506 + 1507 + if (ctrl & UARTCTRL_TE) 1508 + lpuart32_write(port, ctrl, UARTCTRL); 1509 + 1510 return 0; 1511 } 1512 1513 static unsigned int lpuart_get_mctrl(struct uart_port *port) 1514 { 1515 unsigned int mctrl = 0; 1516 + u8 cr1; 1517 1518 + cr1 = readb(port->membase + UARTCR1); 1519 + if (cr1 & UARTCR1_LOOPS) 1520 mctrl |= TIOCM_LOOP; 1521 1522 return mctrl; ··· 1521 static unsigned int lpuart32_get_mctrl(struct uart_port *port) 1522 { 1523 unsigned int mctrl = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS; 1524 + u32 ctrl; 1525 1526 + ctrl = lpuart32_read(port, UARTCTRL); 1527 + if (ctrl & UARTCTRL_LOOPS) 1528 mctrl |= TIOCM_LOOP; 1529 1530 return mctrl; ··· 1532 1533 static void lpuart_set_mctrl(struct uart_port *port, unsigned int mctrl) 1534 { 1535 + u8 cr1; 1536 1537 + cr1 = readb(port->membase + UARTCR1); 1538 1539 /* for internal loopback we need LOOPS=1 and RSRC=0 */ 1540 + cr1 &= ~(UARTCR1_LOOPS | UARTCR1_RSRC); 1541 if (mctrl & TIOCM_LOOP) 1542 + cr1 |= UARTCR1_LOOPS; 1543 1544 + writeb(cr1, port->membase + UARTCR1); 1545 } 1546 1547 static void lpuart32_set_mctrl(struct uart_port *port, unsigned int mctrl) 1548 { 1549 + u32 ctrl; 1550 1551 + ctrl = lpuart32_read(port, UARTCTRL); 1552 1553 /* for internal loopback we need LOOPS=1 and RSRC=0 */ 1554 + ctrl &= ~(UARTCTRL_LOOPS | UARTCTRL_RSRC); 1555 if (mctrl & TIOCM_LOOP) 1556 + ctrl |= UARTCTRL_LOOPS; 1557 1558 + lpuart32_write(port, ctrl, UARTCTRL); 1559 } 1560 1561 static void lpuart_break_ctl(struct uart_port *port, int break_state) 1562 { 1563 + u8 cr2; 1564 1565 + cr2 = readb(port->membase + UARTCR2) & ~UARTCR2_SBK; 1566 1567 if (break_state != 0) 1568 + cr2 |= UARTCR2_SBK; 1569 1570 + writeb(cr2, port->membase + UARTCR2); 1571 } 1572 1573 static void lpuart32_break_ctl(struct uart_port *port, int break_state) 1574 { 1575 + u32 ctrl; 1576 1577 + ctrl = lpuart32_read(port, UARTCTRL); 1578 1579 /* 1580 * LPUART IP now has two known bugs, one is CTS has higher priority than the ··· 1591 * Disable the transmitter to prevent any data from being sent out 1592 * during break, then invert the TX line to send break. 1593 */ 1594 + ctrl &= ~UARTCTRL_TE; 1595 + lpuart32_write(port, ctrl, UARTCTRL); 1596 + ctrl |= UARTCTRL_TXINV; 1597 + lpuart32_write(port, ctrl, UARTCTRL); 1598 } else { 1599 /* Disable the TXINV to turn off break and re-enable transmitter. */ 1600 + ctrl &= ~UARTCTRL_TXINV; 1601 + lpuart32_write(port, ctrl, UARTCTRL); 1602 + ctrl |= UARTCTRL_TE; 1603 + lpuart32_write(port, ctrl, UARTCTRL); 1604 } 1605 } 1606 1607 static void lpuart_setup_watermark(struct lpuart_port *sport) 1608 { 1609 + u8 fifo, cr2, cr2_saved; 1610 1611 cr2 = readb(sport->port.membase + UARTCR2); 1612 cr2_saved = cr2; ··· 1615 UARTCR2_RIE | UARTCR2_RE); 1616 writeb(cr2, sport->port.membase + UARTCR2); 1617 1618 + fifo = readb(sport->port.membase + UARTPFIFO); 1619 + writeb(fifo | UARTPFIFO_TXFE | UARTPFIFO_RXFE, 1620 sport->port.membase + UARTPFIFO); 1621 1622 /* flush Tx and Rx FIFO */ ··· 1640 1641 static void lpuart_setup_watermark_enable(struct lpuart_port *sport) 1642 { 1643 + u8 cr2; 1644 1645 lpuart_setup_watermark(sport); 1646 ··· 1651 1652 static void lpuart32_setup_watermark(struct lpuart_port *sport) 1653 { 1654 + u32 val, ctrl, ctrl_saved; 1655 1656 ctrl = lpuart32_read(&sport->port, UARTCTRL); 1657 ctrl_saved = ctrl; ··· 1687 1688 static void lpuart32_setup_watermark_enable(struct lpuart_port *sport) 1689 { 1690 + u32 ctrl; 1691 1692 lpuart32_setup_watermark(sport); 1693 1694 + ctrl = lpuart32_read(&sport->port, UARTCTRL); 1695 + ctrl |= UARTCTRL_RE | UARTCTRL_TE; 1696 + ctrl |= FIELD_PREP(UARTCTRL_IDLECFG, 0x7); 1697 + lpuart32_write(&sport->port, ctrl, UARTCTRL); 1698 } 1699 1700 static void rx_dma_timer_init(struct lpuart_port *sport) ··· 1761 static void lpuart_rx_dma_startup(struct lpuart_port *sport) 1762 { 1763 int ret; 1764 + u8 cr3; 1765 1766 if (uart_console(&sport->port)) 1767 goto err; ··· 1811 static int lpuart_startup(struct uart_port *port) 1812 { 1813 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 1814 + u8 fifo; 1815 1816 /* determine FIFO size and enable FIFO mode */ 1817 + fifo = readb(port->membase + UARTPFIFO); 1818 1819 + sport->txfifo_size = UARTFIFO_DEPTH((fifo >> UARTPFIFO_TXSIZE_OFF) & 1820 UARTPFIFO_FIFOSIZE_MASK); 1821 + port->fifosize = sport->txfifo_size; 1822 1823 + sport->rxfifo_size = UARTFIFO_DEPTH((fifo >> UARTPFIFO_RXSIZE_OFF) & 1824 UARTPFIFO_FIFOSIZE_MASK); 1825 1826 lpuart_request_dma(sport); ··· 1831 1832 static void lpuart32_hw_disable(struct lpuart_port *sport) 1833 { 1834 + u32 ctrl; 1835 1836 + ctrl = lpuart32_read(&sport->port, UARTCTRL); 1837 + ctrl &= ~(UARTCTRL_RIE | UARTCTRL_ILIE | UARTCTRL_RE | 1838 UARTCTRL_TIE | UARTCTRL_TE); 1839 + lpuart32_write(&sport->port, ctrl, UARTCTRL); 1840 } 1841 1842 static void lpuart32_configure(struct lpuart_port *sport) 1843 { 1844 + u32 ctrl; 1845 1846 + ctrl = lpuart32_read(&sport->port, UARTCTRL); 1847 if (!sport->lpuart_dma_rx_use) 1848 + ctrl |= UARTCTRL_RIE | UARTCTRL_ILIE; 1849 if (!sport->lpuart_dma_tx_use) 1850 + ctrl |= UARTCTRL_TIE; 1851 + lpuart32_write(&sport->port, ctrl, UARTCTRL); 1852 } 1853 1854 static void lpuart32_hw_setup(struct lpuart_port *sport) ··· 1871 static int lpuart32_startup(struct uart_port *port) 1872 { 1873 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 1874 + u32 fifo; 1875 1876 /* determine FIFO size */ 1877 + fifo = lpuart32_read(port, UARTFIFO); 1878 1879 + sport->txfifo_size = UARTFIFO_DEPTH((fifo >> UARTFIFO_TXSIZE_OFF) & 1880 UARTFIFO_FIFOSIZE_MASK); 1881 + port->fifosize = sport->txfifo_size; 1882 1883 + sport->rxfifo_size = UARTFIFO_DEPTH((fifo >> UARTFIFO_RXSIZE_OFF) & 1884 UARTFIFO_FIFOSIZE_MASK); 1885 1886 /* ··· 1891 if (is_layerscape_lpuart(sport)) { 1892 sport->rxfifo_size = 16; 1893 sport->txfifo_size = 16; 1894 + port->fifosize = sport->txfifo_size; 1895 } 1896 1897 lpuart_request_dma(sport); ··· 1925 static void lpuart_shutdown(struct uart_port *port) 1926 { 1927 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 1928 + u8 cr2; 1929 unsigned long flags; 1930 1931 uart_port_lock_irqsave(port, &flags); 1932 1933 /* disable Rx/Tx and interrupts */ 1934 + cr2 = readb(port->membase + UARTCR2); 1935 + cr2 &= ~(UARTCR2_TE | UARTCR2_RE | 1936 UARTCR2_TIE | UARTCR2_TCIE | UARTCR2_RIE); 1937 + writeb(cr2, port->membase + UARTCR2); 1938 1939 uart_port_unlock_irqrestore(port, flags); 1940 ··· 1945 { 1946 struct lpuart_port *sport = 1947 container_of(port, struct lpuart_port, port); 1948 + u32 temp; 1949 unsigned long flags; 1950 1951 uart_port_lock_irqsave(port, &flags); 1952 1953 /* clear status */ 1954 + temp = lpuart32_read(port, UARTSTAT); 1955 + lpuart32_write(port, temp, UARTSTAT); 1956 1957 /* disable Rx/Tx DMA */ 1958 temp = lpuart32_read(port, UARTBAUD); ··· 1981 { 1982 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 1983 unsigned long flags; 1984 + u8 cr1, old_cr1, old_cr2, cr3, cr4, bdh, modem; 1985 unsigned int baud; 1986 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; 1987 unsigned int sbr, brfa; 1988 1989 + cr1 = old_cr1 = readb(port->membase + UARTCR1); 1990 + old_cr2 = readb(port->membase + UARTCR2); 1991 + cr3 = readb(port->membase + UARTCR3); 1992 + cr4 = readb(port->membase + UARTCR4); 1993 + bdh = readb(port->membase + UARTBDH); 1994 + modem = readb(port->membase + UARTMODEM); 1995 /* 1996 * only support CS8 and CS7, and for CS7 must enable PE. 1997 * supported mode: ··· 2023 * When auto RS-485 RTS mode is enabled, 2024 * hardware flow control need to be disabled. 2025 */ 2026 + if (port->rs485.flags & SER_RS485_ENABLED) 2027 termios->c_cflag &= ~CRTSCTS; 2028 2029 if (termios->c_cflag & CRTSCTS) ··· 2064 * Need to update the Ring buffer length according to the selected 2065 * baud rate and restart Rx DMA path. 2066 * 2067 + * Since timer function acqures port->lock, need to stop before 2068 * acquring same lock because otherwise del_timer_sync() can deadlock. 2069 */ 2070 if (old && sport->lpuart_dma_rx_use) 2071 + lpuart_dma_rx_free(port); 2072 2073 + uart_port_lock_irqsave(port, &flags); 2074 2075 + port->read_status_mask = 0; 2076 if (termios->c_iflag & INPCK) 2077 + port->read_status_mask |= UARTSR1_FE | UARTSR1_PE; 2078 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) 2079 + port->read_status_mask |= UARTSR1_FE; 2080 2081 /* characters to ignore */ 2082 + port->ignore_status_mask = 0; 2083 if (termios->c_iflag & IGNPAR) 2084 + port->ignore_status_mask |= UARTSR1_PE; 2085 if (termios->c_iflag & IGNBRK) { 2086 + port->ignore_status_mask |= UARTSR1_FE; 2087 /* 2088 * if we're ignoring parity and break indicators, 2089 * ignore overruns too (for real raw support). 2090 */ 2091 if (termios->c_iflag & IGNPAR) 2092 + port->ignore_status_mask |= UARTSR1_OR; 2093 } 2094 2095 /* update the per-port timeout */ 2096 uart_update_timeout(port, termios->c_cflag, baud); 2097 2098 /* wait transmit engin complete */ 2099 + lpuart_wait_bit_set(port, UARTSR1, UARTSR1_TC); 2100 2101 /* disable transmit and receive */ 2102 writeb(old_cr2 & ~(UARTCR2_TE | UARTCR2_RE), 2103 + port->membase + UARTCR2); 2104 2105 + sbr = port->uartclk / (16 * baud); 2106 + brfa = ((port->uartclk - (16 * sbr * baud)) * 2) / baud; 2107 bdh &= ~UARTBDH_SBR_MASK; 2108 bdh |= (sbr >> 8) & 0x1F; 2109 cr4 &= ~UARTCR4_BRFA_MASK; 2110 brfa &= UARTCR4_BRFA_MASK; 2111 + writeb(cr4 | brfa, port->membase + UARTCR4); 2112 + writeb(bdh, port->membase + UARTBDH); 2113 + writeb(sbr & 0xFF, port->membase + UARTBDL); 2114 + writeb(cr3, port->membase + UARTCR3); 2115 + writeb(cr1, port->membase + UARTCR1); 2116 + writeb(modem, port->membase + UARTMODEM); 2117 2118 /* restore control register */ 2119 + writeb(old_cr2, port->membase + UARTCR2); 2120 2121 if (old && sport->lpuart_dma_rx_use) { 2122 if (!lpuart_start_rx_dma(sport)) ··· 2125 sport->lpuart_dma_rx_use = false; 2126 } 2127 2128 + uart_port_unlock_irqrestore(port, flags); 2129 } 2130 2131 static void __lpuart32_serial_setbrg(struct uart_port *port, 2132 unsigned int baudrate, bool use_rx_dma, 2133 bool use_tx_dma) 2134 { 2135 + u32 sbr, osr, baud_diff, tmp_osr, tmp_sbr, tmp_diff, baud; 2136 u32 clk = port->uartclk; 2137 2138 /* ··· 2161 tmp_diff = clk / (tmp_osr * tmp_sbr) - baudrate; 2162 2163 /* select best values between sbr and sbr+1 */ 2164 + baud = clk / (tmp_osr * (tmp_sbr + 1)); 2165 + if (tmp_diff > (baudrate - baud)) { 2166 + tmp_diff = baudrate - baud; 2167 tmp_sbr++; 2168 } 2169 ··· 2185 dev_warn(port->dev, 2186 "unacceptable baud rate difference of more than 3%%\n"); 2187 2188 + baud = lpuart32_read(port, UARTBAUD); 2189 2190 if ((osr > 3) && (osr < 8)) 2191 + baud |= UARTBAUD_BOTHEDGE; 2192 2193 + baud &= ~(UARTBAUD_OSR_MASK << UARTBAUD_OSR_SHIFT); 2194 + baud |= ((osr-1) & UARTBAUD_OSR_MASK) << UARTBAUD_OSR_SHIFT; 2195 2196 + baud &= ~UARTBAUD_SBR_MASK; 2197 + baud |= sbr & UARTBAUD_SBR_MASK; 2198 2199 if (!use_rx_dma) 2200 + baud &= ~UARTBAUD_RDMAE; 2201 if (!use_tx_dma) 2202 + baud &= ~UARTBAUD_TDMAE; 2203 2204 + lpuart32_write(port, baud, UARTBAUD); 2205 } 2206 2207 static void lpuart32_serial_setbrg(struct lpuart_port *sport, ··· 2219 { 2220 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 2221 unsigned long flags; 2222 + u32 ctrl, old_ctrl, bd, modem; 2223 unsigned int baud; 2224 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; 2225 2226 + ctrl = old_ctrl = lpuart32_read(port, UARTCTRL); 2227 + bd = lpuart32_read(port, UARTBAUD); 2228 + modem = lpuart32_read(port, UARTMODIR); 2229 sport->is_cs7 = false; 2230 /* 2231 * only support CS8 and CS7 ··· 2259 * When auto RS-485 RTS mode is enabled, 2260 * hardware flow control need to be disabled. 2261 */ 2262 + if (port->rs485.flags & SER_RS485_ENABLED) 2263 termios->c_cflag &= ~CRTSCTS; 2264 2265 if (termios->c_cflag & CRTSCTS) ··· 2309 * Need to update the Ring buffer length according to the selected 2310 * baud rate and restart Rx DMA path. 2311 * 2312 + * Since timer function acqures port->lock, need to stop before 2313 * acquring same lock because otherwise del_timer_sync() can deadlock. 2314 */ 2315 if (old && sport->lpuart_dma_rx_use) 2316 + lpuart_dma_rx_free(port); 2317 2318 + uart_port_lock_irqsave(port, &flags); 2319 2320 + port->read_status_mask = 0; 2321 if (termios->c_iflag & INPCK) 2322 + port->read_status_mask |= UARTSTAT_FE | UARTSTAT_PE; 2323 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) 2324 + port->read_status_mask |= UARTSTAT_FE; 2325 2326 /* characters to ignore */ 2327 + port->ignore_status_mask = 0; 2328 if (termios->c_iflag & IGNPAR) 2329 + port->ignore_status_mask |= UARTSTAT_PE; 2330 if (termios->c_iflag & IGNBRK) { 2331 + port->ignore_status_mask |= UARTSTAT_FE; 2332 /* 2333 * if we're ignoring parity and break indicators, 2334 * ignore overruns too (for real raw support). 2335 */ 2336 if (termios->c_iflag & IGNPAR) 2337 + port->ignore_status_mask |= UARTSTAT_OR; 2338 } 2339 2340 /* update the per-port timeout */ 2341 uart_update_timeout(port, termios->c_cflag, baud); 2342 2343 /* 2344 + * disable CTS to ensure the transmit engine is not blocked by the flow 2345 + * control when there is dirty data in TX FIFO 2346 + */ 2347 + lpuart32_write(port, modem & ~UARTMODIR_TXCTSE, UARTMODIR); 2348 + 2349 + /* 2350 * LPUART Transmission Complete Flag may never be set while queuing a break 2351 * character, so skip waiting for transmission complete when UARTCTRL_SBK is 2352 * asserted. 2353 */ 2354 + if (!(old_ctrl & UARTCTRL_SBK)) 2355 + lpuart32_wait_bit_set(port, UARTSTAT, UARTSTAT_TC); 2356 2357 /* disable transmit and receive */ 2358 + lpuart32_write(port, old_ctrl & ~(UARTCTRL_TE | UARTCTRL_RE), 2359 UARTCTRL); 2360 2361 + lpuart32_write(port, bd, UARTBAUD); 2362 lpuart32_serial_setbrg(sport, baud); 2363 /* restore control register */ 2364 + lpuart32_write(port, ctrl, UARTCTRL); 2365 /* re-enable the CTS if needed */ 2366 + lpuart32_write(port, modem, UARTMODIR); 2367 2368 if ((ctrl & (UARTCTRL_PE | UARTCTRL_M)) == UARTCTRL_PE) 2369 sport->is_cs7 = true; ··· 2373 sport->lpuart_dma_rx_use = false; 2374 } 2375 2376 + uart_port_unlock_irqrestore(port, flags); 2377 } 2378 2379 static const char *lpuart_type(struct uart_port *port) ··· 2486 lpuart_console_write(struct console *co, const char *s, unsigned int count) 2487 { 2488 struct lpuart_port *sport = lpuart_ports[co->index]; 2489 + u8 old_cr2, cr2; 2490 unsigned long flags; 2491 int locked = 1; 2492 ··· 2516 lpuart32_console_write(struct console *co, const char *s, unsigned int count) 2517 { 2518 struct lpuart_port *sport = lpuart_ports[co->index]; 2519 + u32 old_cr, cr; 2520 unsigned long flags; 2521 int locked = 1; 2522 ··· 2550 lpuart_console_get_options(struct lpuart_port *sport, int *baud, 2551 int *parity, int *bits) 2552 { 2553 + u8 cr, bdh, bdl, brfa; 2554 unsigned int sbr, uartclk, baud_raw; 2555 2556 cr = readb(sport->port.membase + UARTCR2); ··· 2599 lpuart32_console_get_options(struct lpuart_port *sport, int *baud, 2600 int *parity, int *bits) 2601 { 2602 + u32 cr, bd; 2603 unsigned int sbr, uartclk, baud_raw; 2604 2605 cr = lpuart32_read(&sport->port, UARTCTRL); ··· 2805 { 2806 struct uart_port *port = &sport->port; 2807 void __iomem *global_addr; 2808 + u32 ctrl, bd; 2809 unsigned int val = 0; 2810 int ret; 2811 2812 ret = clk_prepare_enable(sport->ipg_clk); 2813 if (ret) { 2814 + dev_err(port->dev, "failed to enable uart ipg clk: %d\n", ret); 2815 return ret; 2816 } 2817 ··· 2822 */ 2823 ctrl = lpuart32_read(port, UARTCTRL); 2824 if (ctrl & UARTCTRL_TE) { 2825 + bd = lpuart32_read(port, UARTBAUD); 2826 if (read_poll_timeout(lpuart32_tx_empty, val, val, 1, 100000, false, 2827 port)) { 2828 + dev_warn(port->dev, 2829 "timeout waiting for transmit engine to complete\n"); 2830 clk_disable_unprepare(sport->ipg_clk); 2831 return 0; ··· 2954 goto failed_attach_port; 2955 2956 ret = devm_request_irq(&pdev->dev, sport->port.irq, handler, 0, 2957 + dev_name(&pdev->dev), sport); 2958 if (ret) 2959 goto failed_irq_request; 2960 ··· 3011 3012 static void serial_lpuart_enable_wakeup(struct lpuart_port *sport, bool on) 3013 { 3014 + u32 val, baud; 3015 3016 if (lpuart_is_32(sport)) { 3017 val = lpuart32_read(&sport->port, UARTCTRL); ··· 3076 static int lpuart_resume_noirq(struct device *dev) 3077 { 3078 struct lpuart_port *sport = dev_get_drvdata(dev); 3079 + u32 stat; 3080 3081 pinctrl_pm_select_default_state(dev); 3082 ··· 3085 3086 /* clear the wakeup flags */ 3087 if (lpuart_is_32(sport)) { 3088 + stat = lpuart32_read(&sport->port, UARTSTAT); 3089 + lpuart32_write(&sport->port, stat, UARTSTAT); 3090 } 3091 } 3092 ··· 3096 static int lpuart_suspend(struct device *dev) 3097 { 3098 struct lpuart_port *sport = dev_get_drvdata(dev); 3099 + u32 temp; 3100 + unsigned long flags; 3101 3102 uart_suspend_port(&lpuart_reg, &sport->port); 3103 ··· 3176 * in VLLS mode, or restore console setting here. 3177 */ 3178 if (is_imx7ulp_lpuart(sport) && lpuart_uport_is_active(sport) && 3179 + console_suspend_enabled && uart_console(uport)) { 3180 3181 mutex_lock(&port->mutex); 3182 memset(&termios, 0, sizeof(struct ktermios));
+4 -5
drivers/tty/serial/icom.c
··· 1764 goto probe_exit1; 1765 } 1766 1767 - /* save off irq and request irq line */ 1768 - retval = request_irq(dev->irq, icom_interrupt, IRQF_SHARED, ICOM_DRIVER_NAME, (void *)icom_adapter); 1769 - if (retval) { 1770 - goto probe_exit2; 1771 - } 1772 1773 retval = icom_load_ports(icom_adapter); 1774
··· 1764 goto probe_exit1; 1765 } 1766 1767 + /* save off irq and request irq line */ 1768 + retval = request_irq(dev->irq, icom_interrupt, IRQF_SHARED, ICOM_DRIVER_NAME, icom_adapter); 1769 + if (retval) 1770 + goto probe_exit2; 1771 1772 retval = icom_load_ports(icom_adapter); 1773
+1 -1
drivers/tty/serial/imx.c
··· 1608 imx_uart_dma_exit(sport); 1609 } 1610 1611 - mctrl_gpio_disable_ms(sport->gpios); 1612 1613 uart_port_lock_irqsave(&sport->port, &flags); 1614 ucr2 = imx_uart_readl(sport, UCR2);
··· 1608 imx_uart_dma_exit(sport); 1609 } 1610 1611 + mctrl_gpio_disable_ms_sync(sport->gpios); 1612 1613 uart_port_lock_irqsave(&sport->port, &flags); 1614 ucr2 = imx_uart_readl(sport, UCR2);
-280
drivers/tty/serial/kgdb_nmi.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * KGDB NMI serial console 4 - * 5 - * Copyright 2010 Google, Inc. 6 - * Arve Hjønnevåg <arve@android.com> 7 - * Colin Cross <ccross@android.com> 8 - * Copyright 2012 Linaro Ltd. 9 - * Anton Vorontsov <anton.vorontsov@linaro.org> 10 - */ 11 - 12 - #include <linux/kernel.h> 13 - #include <linux/module.h> 14 - #include <linux/compiler.h> 15 - #include <linux/slab.h> 16 - #include <linux/errno.h> 17 - #include <linux/atomic.h> 18 - #include <linux/console.h> 19 - #include <linux/tty.h> 20 - #include <linux/tty_driver.h> 21 - #include <linux/tty_flip.h> 22 - #include <linux/serial_core.h> 23 - #include <linux/interrupt.h> 24 - #include <linux/hrtimer.h> 25 - #include <linux/tick.h> 26 - #include <linux/kfifo.h> 27 - #include <linux/kgdb.h> 28 - #include <linux/kdb.h> 29 - 30 - static atomic_t kgdb_nmi_num_readers = ATOMIC_INIT(0); 31 - 32 - static int kgdb_nmi_console_setup(struct console *co, char *options) 33 - { 34 - arch_kgdb_ops.enable_nmi(1); 35 - 36 - /* The NMI console uses the dbg_io_ops to issue console messages. To 37 - * avoid duplicate messages during kdb sessions we must inform kdb's 38 - * I/O utilities that messages sent to the console will automatically 39 - * be displayed on the dbg_io. 40 - */ 41 - dbg_io_ops->cons = co; 42 - 43 - return 0; 44 - } 45 - 46 - static void kgdb_nmi_console_write(struct console *co, const char *s, uint c) 47 - { 48 - int i; 49 - 50 - for (i = 0; i < c; i++) 51 - dbg_io_ops->write_char(s[i]); 52 - } 53 - 54 - static struct tty_driver *kgdb_nmi_tty_driver; 55 - 56 - static struct tty_driver *kgdb_nmi_console_device(struct console *co, int *idx) 57 - { 58 - *idx = co->index; 59 - return kgdb_nmi_tty_driver; 60 - } 61 - 62 - static struct console kgdb_nmi_console = { 63 - .name = "ttyNMI", 64 - .setup = kgdb_nmi_console_setup, 65 - .write = kgdb_nmi_console_write, 66 - .device = kgdb_nmi_console_device, 67 - .flags = CON_PRINTBUFFER | CON_ANYTIME, 68 - .index = -1, 69 - }; 70 - 71 - /* 72 - * This is usually the maximum rate on debug ports. We make fifo large enough 73 - * to make copy-pasting to the terminal usable. 74 - */ 75 - #define KGDB_NMI_BAUD 115200 76 - #define KGDB_NMI_FIFO_SIZE roundup_pow_of_two(KGDB_NMI_BAUD / 8 / HZ) 77 - 78 - struct kgdb_nmi_tty_priv { 79 - struct tty_port port; 80 - struct timer_list timer; 81 - STRUCT_KFIFO(char, KGDB_NMI_FIFO_SIZE) fifo; 82 - }; 83 - 84 - static struct tty_port *kgdb_nmi_port; 85 - 86 - /* 87 - * The tasklet is cheap, it does not cause wakeups when reschedules itself, 88 - * instead it waits for the next tick. 89 - */ 90 - static void kgdb_nmi_tty_receiver(struct timer_list *t) 91 - { 92 - struct kgdb_nmi_tty_priv *priv = from_timer(priv, t, timer); 93 - char ch; 94 - 95 - priv->timer.expires = jiffies + (HZ/100); 96 - add_timer(&priv->timer); 97 - 98 - if (likely(!atomic_read(&kgdb_nmi_num_readers) || 99 - !kfifo_len(&priv->fifo))) 100 - return; 101 - 102 - while (kfifo_out(&priv->fifo, &ch, 1)) 103 - tty_insert_flip_char(&priv->port, ch, TTY_NORMAL); 104 - tty_flip_buffer_push(&priv->port); 105 - } 106 - 107 - static int kgdb_nmi_tty_activate(struct tty_port *port, struct tty_struct *tty) 108 - { 109 - struct kgdb_nmi_tty_priv *priv = 110 - container_of(port, struct kgdb_nmi_tty_priv, port); 111 - 112 - kgdb_nmi_port = port; 113 - priv->timer.expires = jiffies + (HZ/100); 114 - add_timer(&priv->timer); 115 - 116 - return 0; 117 - } 118 - 119 - static void kgdb_nmi_tty_shutdown(struct tty_port *port) 120 - { 121 - struct kgdb_nmi_tty_priv *priv = 122 - container_of(port, struct kgdb_nmi_tty_priv, port); 123 - 124 - del_timer(&priv->timer); 125 - kgdb_nmi_port = NULL; 126 - } 127 - 128 - static const struct tty_port_operations kgdb_nmi_tty_port_ops = { 129 - .activate = kgdb_nmi_tty_activate, 130 - .shutdown = kgdb_nmi_tty_shutdown, 131 - }; 132 - 133 - static int kgdb_nmi_tty_install(struct tty_driver *drv, struct tty_struct *tty) 134 - { 135 - struct kgdb_nmi_tty_priv *priv; 136 - int ret; 137 - 138 - priv = kzalloc(sizeof(*priv), GFP_KERNEL); 139 - if (!priv) 140 - return -ENOMEM; 141 - 142 - INIT_KFIFO(priv->fifo); 143 - timer_setup(&priv->timer, kgdb_nmi_tty_receiver, 0); 144 - tty_port_init(&priv->port); 145 - priv->port.ops = &kgdb_nmi_tty_port_ops; 146 - tty->driver_data = priv; 147 - 148 - ret = tty_port_install(&priv->port, drv, tty); 149 - if (ret) { 150 - pr_err("%s: can't install tty port: %d\n", __func__, ret); 151 - goto err; 152 - } 153 - return 0; 154 - err: 155 - tty_port_destroy(&priv->port); 156 - kfree(priv); 157 - return ret; 158 - } 159 - 160 - static void kgdb_nmi_tty_cleanup(struct tty_struct *tty) 161 - { 162 - struct kgdb_nmi_tty_priv *priv = tty->driver_data; 163 - 164 - tty->driver_data = NULL; 165 - tty_port_destroy(&priv->port); 166 - kfree(priv); 167 - } 168 - 169 - static int kgdb_nmi_tty_open(struct tty_struct *tty, struct file *file) 170 - { 171 - struct kgdb_nmi_tty_priv *priv = tty->driver_data; 172 - unsigned int mode = file->f_flags & O_ACCMODE; 173 - int ret; 174 - 175 - ret = tty_port_open(&priv->port, tty, file); 176 - if (!ret && (mode == O_RDONLY || mode == O_RDWR)) 177 - atomic_inc(&kgdb_nmi_num_readers); 178 - 179 - return ret; 180 - } 181 - 182 - static void kgdb_nmi_tty_close(struct tty_struct *tty, struct file *file) 183 - { 184 - struct kgdb_nmi_tty_priv *priv = tty->driver_data; 185 - unsigned int mode = file->f_flags & O_ACCMODE; 186 - 187 - if (mode == O_RDONLY || mode == O_RDWR) 188 - atomic_dec(&kgdb_nmi_num_readers); 189 - 190 - tty_port_close(&priv->port, tty, file); 191 - } 192 - 193 - static void kgdb_nmi_tty_hangup(struct tty_struct *tty) 194 - { 195 - struct kgdb_nmi_tty_priv *priv = tty->driver_data; 196 - 197 - tty_port_hangup(&priv->port); 198 - } 199 - 200 - static unsigned int kgdb_nmi_tty_write_room(struct tty_struct *tty) 201 - { 202 - /* Actually, we can handle any amount as we use polled writes. */ 203 - return 2048; 204 - } 205 - 206 - static ssize_t kgdb_nmi_tty_write(struct tty_struct *tty, const u8 *buf, 207 - size_t c) 208 - { 209 - int i; 210 - 211 - for (i = 0; i < c; i++) 212 - dbg_io_ops->write_char(buf[i]); 213 - return c; 214 - } 215 - 216 - static const struct tty_operations kgdb_nmi_tty_ops = { 217 - .open = kgdb_nmi_tty_open, 218 - .close = kgdb_nmi_tty_close, 219 - .install = kgdb_nmi_tty_install, 220 - .cleanup = kgdb_nmi_tty_cleanup, 221 - .hangup = kgdb_nmi_tty_hangup, 222 - .write_room = kgdb_nmi_tty_write_room, 223 - .write = kgdb_nmi_tty_write, 224 - }; 225 - 226 - int kgdb_register_nmi_console(void) 227 - { 228 - int ret; 229 - 230 - if (!arch_kgdb_ops.enable_nmi) 231 - return 0; 232 - 233 - kgdb_nmi_tty_driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW); 234 - if (IS_ERR(kgdb_nmi_tty_driver)) { 235 - pr_err("%s: cannot allocate tty\n", __func__); 236 - return PTR_ERR(kgdb_nmi_tty_driver); 237 - } 238 - kgdb_nmi_tty_driver->driver_name = "ttyNMI"; 239 - kgdb_nmi_tty_driver->name = "ttyNMI"; 240 - kgdb_nmi_tty_driver->num = 1; 241 - kgdb_nmi_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; 242 - kgdb_nmi_tty_driver->subtype = SERIAL_TYPE_NORMAL; 243 - kgdb_nmi_tty_driver->init_termios = tty_std_termios; 244 - tty_termios_encode_baud_rate(&kgdb_nmi_tty_driver->init_termios, 245 - KGDB_NMI_BAUD, KGDB_NMI_BAUD); 246 - tty_set_operations(kgdb_nmi_tty_driver, &kgdb_nmi_tty_ops); 247 - 248 - ret = tty_register_driver(kgdb_nmi_tty_driver); 249 - if (ret) { 250 - pr_err("%s: can't register tty driver: %d\n", __func__, ret); 251 - goto err_drv_reg; 252 - } 253 - 254 - register_console(&kgdb_nmi_console); 255 - 256 - return 0; 257 - err_drv_reg: 258 - tty_driver_kref_put(kgdb_nmi_tty_driver); 259 - return ret; 260 - } 261 - EXPORT_SYMBOL_GPL(kgdb_register_nmi_console); 262 - 263 - int kgdb_unregister_nmi_console(void) 264 - { 265 - int ret; 266 - 267 - if (!arch_kgdb_ops.enable_nmi) 268 - return 0; 269 - arch_kgdb_ops.enable_nmi(0); 270 - 271 - ret = unregister_console(&kgdb_nmi_console); 272 - if (ret) 273 - return ret; 274 - 275 - tty_unregister_driver(kgdb_nmi_tty_driver); 276 - tty_driver_kref_put(kgdb_nmi_tty_driver); 277 - 278 - return 0; 279 - } 280 - EXPORT_SYMBOL_GPL(kgdb_unregister_nmi_console);
···
-8
drivers/tty/serial/kgdboc.c
··· 186 if (configured != 1) 187 return; 188 189 - if (kgdb_unregister_nmi_console()) 190 - return; 191 kgdboc_unregister_kbd(); 192 kgdb_unregister_io_module(&kgdboc_io_ops); 193 } ··· 248 if (err) 249 goto noconfig; 250 251 - err = kgdb_register_nmi_console(); 252 - if (err) 253 - goto nmi_con_failed; 254 - 255 configured = 1; 256 257 return 0; 258 259 - nmi_con_failed: 260 - kgdb_unregister_io_module(&kgdboc_io_ops); 261 noconfig: 262 kgdboc_unregister_kbd(); 263 configured = 0;
··· 186 if (configured != 1) 187 return; 188 189 kgdboc_unregister_kbd(); 190 kgdb_unregister_io_module(&kgdboc_io_ops); 191 } ··· 250 if (err) 251 goto noconfig; 252 253 configured = 1; 254 255 return 0; 256 257 noconfig: 258 kgdboc_unregister_kbd(); 259 configured = 0;
+1 -1
drivers/tty/serial/ma35d1_serial.c
··· 799 .resume = ma35d1serial_resume, 800 .driver = { 801 .name = "ma35d1-uart", 802 - .of_match_table = of_match_ptr(ma35d1_serial_of_match), 803 }, 804 }; 805
··· 799 .resume = ma35d1serial_resume, 800 .driver = { 801 .name = "ma35d1-uart", 802 + .of_match_table = ma35d1_serial_of_match, 803 }, 804 }; 805
-1
drivers/tty/serial/mpc52xx_uart.c
··· 1351 .startup = mpc52xx_uart_startup, 1352 .shutdown = mpc52xx_uart_shutdown, 1353 .set_termios = mpc52xx_uart_set_termios, 1354 - /* .pm = mpc52xx_uart_pm, Not supported yet */ 1355 .type = mpc52xx_uart_type, 1356 .release_port = mpc52xx_uart_release_port, 1357 .request_port = mpc52xx_uart_request_port,
··· 1351 .startup = mpc52xx_uart_startup, 1352 .shutdown = mpc52xx_uart_shutdown, 1353 .set_termios = mpc52xx_uart_set_termios, 1354 .type = mpc52xx_uart_type, 1355 .release_port = mpc52xx_uart_release_port, 1356 .request_port = mpc52xx_uart_request_port,
-1
drivers/tty/serial/pch_uart.c
··· 1515 .startup = pch_uart_startup, 1516 .shutdown = pch_uart_shutdown, 1517 .set_termios = pch_uart_set_termios, 1518 - /* .pm = pch_uart_pm, Not supported yet */ 1519 .type = pch_uart_type, 1520 .release_port = pch_uart_release_port, 1521 .request_port = pch_uart_request_port,
··· 1515 .startup = pch_uart_startup, 1516 .shutdown = pch_uart_shutdown, 1517 .set_termios = pch_uart_set_termios, 1518 .type = pch_uart_type, 1519 .release_port = pch_uart_release_port, 1520 .request_port = pch_uart_request_port,
+4 -6
drivers/tty/serial/serial_core.c
··· 895 { 896 struct uart_port *uport = uart_port_check(state); 897 unsigned long new_port; 898 - unsigned int change_irq, change_port, closing_wait; 899 - unsigned int old_custom_divisor, close_delay; 900 upf_t old_flags, new_flags; 901 int retval; 902 ··· 2013 2014 #ifdef CONFIG_PROC_FS 2015 2016 - static void uart_line_info(struct seq_file *m, struct uart_driver *drv, int i) 2017 { 2018 - struct uart_state *state = drv->state + i; 2019 struct tty_port *port = &state->port; 2020 enum uart_pm_state pm_state; 2021 struct uart_port *uport; ··· 2099 2100 seq_printf(m, "serinfo:1.0 driver%s%s revision:%s\n", "", "", ""); 2101 for (i = 0; i < drv->nr; i++) 2102 - uart_line_info(m, drv, i); 2103 return 0; 2104 } 2105 #endif ··· 3155 if (uport->cons && uport->dev) 3156 of_console_check(uport->dev->of_node, uport->cons->name, uport->line); 3157 3158 - tty_port_link_device(port, drv->tty_driver, uport->line); 3159 uart_configure_port(drv, state, uport); 3160 3161 port->console = uart_console(uport);
··· 895 { 896 struct uart_port *uport = uart_port_check(state); 897 unsigned long new_port; 898 + unsigned int old_custom_divisor, close_delay, closing_wait; 899 + bool change_irq, change_port; 900 upf_t old_flags, new_flags; 901 int retval; 902 ··· 2013 2014 #ifdef CONFIG_PROC_FS 2015 2016 + static void uart_line_info(struct seq_file *m, struct uart_state *state) 2017 { 2018 struct tty_port *port = &state->port; 2019 enum uart_pm_state pm_state; 2020 struct uart_port *uport; ··· 2100 2101 seq_printf(m, "serinfo:1.0 driver%s%s revision:%s\n", "", "", ""); 2102 for (i = 0; i < drv->nr; i++) 2103 + uart_line_info(m, drv->state + i); 2104 return 0; 2105 } 2106 #endif ··· 3156 if (uport->cons && uport->dev) 3157 of_console_check(uport->dev->of_node, uport->cons->name, uport->line); 3158 3159 uart_configure_port(drv, state, uport); 3160 3161 port->console = uart_console(uport);
+28 -34
drivers/tty/serial/serial_mctrl_gpio.c
··· 217 * 218 * This will get the {cts,rts,...}-gpios from device tree if they are present 219 * and request them, set direction etc, and return an allocated structure. 220 - * `devm_*` functions are used, so there's no need to call mctrl_gpio_free(). 221 * As this sets up the irq handling, make sure to not handle changes to the 222 * gpio input lines in your driver, too. 223 */ ··· 268 EXPORT_SYMBOL_GPL(mctrl_gpio_init); 269 270 /** 271 - * mctrl_gpio_free - explicitly free uart gpios 272 - * @dev: uart port's device 273 - * @gpios: gpios structure to be freed 274 - * 275 - * This will free the requested gpios in mctrl_gpio_init(). As `devm_*` 276 - * functions are used, there's generally no need to call this function. 277 - */ 278 - void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios) 279 - { 280 - enum mctrl_gpio_idx i; 281 - 282 - if (gpios == NULL) 283 - return; 284 - 285 - for (i = 0; i < UART_GPIO_MAX; i++) { 286 - if (gpios->irq[i]) 287 - devm_free_irq(gpios->port->dev, gpios->irq[i], gpios); 288 - 289 - if (gpios->gpio[i]) 290 - devm_gpiod_put(dev, gpios->gpio[i]); 291 - } 292 - devm_kfree(dev, gpios); 293 - } 294 - EXPORT_SYMBOL_GPL(mctrl_gpio_free); 295 - 296 - /** 297 * mctrl_gpio_enable_ms - enable irqs and handling of changes to the ms lines 298 * @gpios: gpios to enable 299 */ ··· 296 } 297 EXPORT_SYMBOL_GPL(mctrl_gpio_enable_ms); 298 299 - /** 300 - * mctrl_gpio_disable_ms - disable irqs and handling of changes to the ms lines 301 - * @gpios: gpios to disable 302 - */ 303 - void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios) 304 { 305 enum mctrl_gpio_idx i; 306 ··· 312 if (!gpios->irq[i]) 313 continue; 314 315 - disable_irq(gpios->irq[i]); 316 } 317 } 318 - EXPORT_SYMBOL_GPL(mctrl_gpio_disable_ms); 319 320 void mctrl_gpio_enable_irq_wake(struct mctrl_gpios *gpios) 321 {
··· 217 * 218 * This will get the {cts,rts,...}-gpios from device tree if they are present 219 * and request them, set direction etc, and return an allocated structure. 220 + * `devm_*` functions are used, so there's no need to explicitly free. 221 * As this sets up the irq handling, make sure to not handle changes to the 222 * gpio input lines in your driver, too. 223 */ ··· 268 EXPORT_SYMBOL_GPL(mctrl_gpio_init); 269 270 /** 271 * mctrl_gpio_enable_ms - enable irqs and handling of changes to the ms lines 272 * @gpios: gpios to enable 273 */ ··· 322 } 323 EXPORT_SYMBOL_GPL(mctrl_gpio_enable_ms); 324 325 + static void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios, bool sync) 326 { 327 enum mctrl_gpio_idx i; 328 ··· 342 if (!gpios->irq[i]) 343 continue; 344 345 + if (sync) 346 + disable_irq(gpios->irq[i]); 347 + else 348 + disable_irq_nosync(gpios->irq[i]); 349 } 350 } 351 + 352 + /** 353 + * mctrl_gpio_disable_ms_sync - disable irqs and handling of changes to the ms 354 + * lines, and wait for any pending IRQ to be processed 355 + * @gpios: gpios to disable 356 + */ 357 + void mctrl_gpio_disable_ms_sync(struct mctrl_gpios *gpios) 358 + { 359 + mctrl_gpio_disable_ms(gpios, true); 360 + } 361 + EXPORT_SYMBOL_GPL(mctrl_gpio_disable_ms_sync); 362 + 363 + /** 364 + * mctrl_gpio_disable_ms_no_sync - disable irqs and handling of changes to the 365 + * ms lines, and return immediately 366 + * @gpios: gpios to disable 367 + */ 368 + void mctrl_gpio_disable_ms_no_sync(struct mctrl_gpios *gpios) 369 + { 370 + mctrl_gpio_disable_ms(gpios, false); 371 + } 372 + EXPORT_SYMBOL_GPL(mctrl_gpio_disable_ms_no_sync); 373 374 void mctrl_gpio_enable_irq_wake(struct mctrl_gpios *gpios) 375 {
+16 -17
drivers/tty/serial/serial_mctrl_gpio.h
··· 59 /* 60 * Request and set direction of modem control line GPIOs and set up irq 61 * handling. 62 - * devm_* functions are used, so there's no need to call mctrl_gpio_free(). 63 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on 64 * allocation error. 65 */ ··· 67 68 /* 69 * Request and set direction of modem control line GPIOs. 70 - * devm_* functions are used, so there's no need to call mctrl_gpio_free(). 71 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on 72 * allocation error. 73 */ ··· 75 unsigned int idx); 76 77 /* 78 - * Free the mctrl_gpios structure. 79 - * Normally, this function will not be called, as the GPIOs will 80 - * be disposed of by the resource management code. 81 - */ 82 - void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios); 83 - 84 - /* 85 * Enable gpio interrupts to report status line changes. 86 */ 87 void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios); 88 89 /* 90 - * Disable gpio interrupts to report status line changes. 91 */ 92 - void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios); 93 94 /* 95 * Enable gpio wakeup interrupts to enable wake up source. ··· 139 return NULL; 140 } 141 142 - static inline 143 - void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios) 144 - { 145 - } 146 - 147 static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios) 148 { 149 } 150 151 - static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios) 152 { 153 } 154
··· 59 /* 60 * Request and set direction of modem control line GPIOs and set up irq 61 * handling. 62 + * devm_* functions are used, so there's no need to explicitly free. 63 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on 64 * allocation error. 65 */ ··· 67 68 /* 69 * Request and set direction of modem control line GPIOs. 70 + * devm_* functions are used, so there's no need to explicitly free. 71 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on 72 * allocation error. 73 */ ··· 75 unsigned int idx); 76 77 /* 78 * Enable gpio interrupts to report status line changes. 79 */ 80 void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios); 81 82 /* 83 + * Disable gpio interrupts to report status line changes, and block until 84 + * any corresponding IRQ is processed 85 */ 86 + void mctrl_gpio_disable_ms_sync(struct mctrl_gpios *gpios); 87 + 88 + /* 89 + * Disable gpio interrupts to report status line changes, and return 90 + * immediately 91 + */ 92 + void mctrl_gpio_disable_ms_no_sync(struct mctrl_gpios *gpios); 93 94 /* 95 * Enable gpio wakeup interrupts to enable wake up source. ··· 139 return NULL; 140 } 141 142 static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios) 143 { 144 } 145 146 + static inline void mctrl_gpio_disable_ms_sync(struct mctrl_gpios *gpios) 147 + { 148 + } 149 + 150 + static inline void mctrl_gpio_disable_ms_no_sync(struct mctrl_gpios *gpios) 151 { 152 } 153
+95 -3
drivers/tty/serial/sh-sci.c
··· 104 u8 offset, size; 105 }; 106 107 struct sci_port_params { 108 const struct plat_sci_reg regs[SCIx_NR_REGS]; 109 unsigned int fifosize; ··· 148 struct dma_chan *chan_tx; 149 struct dma_chan *chan_rx; 150 151 #ifdef CONFIG_SERIAL_SH_SCI_DMA 152 struct dma_chan *chan_tx_saved; 153 struct dma_chan *chan_rx_saved; ··· 169 int rx_trigger; 170 struct timer_list rx_fifo_timer; 171 int rx_fifo_timeout; 172 u16 hscif_tot; 173 174 bool has_rtscts; ··· 2314 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); 2315 2316 s->autorts = false; 2317 - mctrl_gpio_disable_ms(to_sci_port(port)->gpios); 2318 2319 uart_port_lock_irqsave(port, &flags); 2320 sci_stop_rx(port); ··· 3390 } 3391 3392 sp = &sci_ports[id]; 3393 *dev_id = id; 3394 3395 p->type = SCI_OF_TYPE(data); ··· 3563 return 0; 3564 } 3565 3566 static __maybe_unused int sci_suspend(struct device *dev) 3567 { 3568 struct sci_port *sport = dev_get_drvdata(dev); 3569 3570 - if (sport) 3571 uart_suspend_port(&sci_uart_driver, &sport->port); 3572 3573 return 0; 3574 } ··· 3641 { 3642 struct sci_port *sport = dev_get_drvdata(dev); 3643 3644 - if (sport) 3645 uart_resume_port(&sci_uart_driver, &sport->port); 3646 3647 return 0; 3648 }
··· 104 u8 offset, size; 105 }; 106 107 + struct sci_suspend_regs { 108 + u16 scdl; 109 + u16 sccks; 110 + u16 scsmr; 111 + u16 scscr; 112 + u16 scfcr; 113 + u16 scsptr; 114 + u16 hssrr; 115 + u16 scpcr; 116 + u16 scpdr; 117 + u8 scbrr; 118 + u8 semr; 119 + }; 120 + 121 struct sci_port_params { 122 const struct plat_sci_reg regs[SCIx_NR_REGS]; 123 unsigned int fifosize; ··· 134 struct dma_chan *chan_tx; 135 struct dma_chan *chan_rx; 136 137 + struct reset_control *rstc; 138 + 139 #ifdef CONFIG_SERIAL_SH_SCI_DMA 140 struct dma_chan *chan_tx_saved; 141 struct dma_chan *chan_rx_saved; ··· 153 int rx_trigger; 154 struct timer_list rx_fifo_timer; 155 int rx_fifo_timeout; 156 + struct sci_suspend_regs suspend_regs; 157 u16 hscif_tot; 158 159 bool has_rtscts; ··· 2297 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); 2298 2299 s->autorts = false; 2300 + mctrl_gpio_disable_ms_sync(to_sci_port(port)->gpios); 2301 2302 uart_port_lock_irqsave(port, &flags); 2303 sci_stop_rx(port); ··· 3373 } 3374 3375 sp = &sci_ports[id]; 3376 + sp->rstc = rstc; 3377 *dev_id = id; 3378 3379 p->type = SCI_OF_TYPE(data); ··· 3545 return 0; 3546 } 3547 3548 + static void sci_console_save(struct sci_port *s) 3549 + { 3550 + struct sci_suspend_regs *regs = &s->suspend_regs; 3551 + struct uart_port *port = &s->port; 3552 + 3553 + if (sci_getreg(port, SCDL)->size) 3554 + regs->scdl = sci_serial_in(port, SCDL); 3555 + if (sci_getreg(port, SCCKS)->size) 3556 + regs->sccks = sci_serial_in(port, SCCKS); 3557 + if (sci_getreg(port, SCSMR)->size) 3558 + regs->scsmr = sci_serial_in(port, SCSMR); 3559 + if (sci_getreg(port, SCSCR)->size) 3560 + regs->scscr = sci_serial_in(port, SCSCR); 3561 + if (sci_getreg(port, SCFCR)->size) 3562 + regs->scfcr = sci_serial_in(port, SCFCR); 3563 + if (sci_getreg(port, SCSPTR)->size) 3564 + regs->scsptr = sci_serial_in(port, SCSPTR); 3565 + if (sci_getreg(port, SCBRR)->size) 3566 + regs->scbrr = sci_serial_in(port, SCBRR); 3567 + if (sci_getreg(port, HSSRR)->size) 3568 + regs->hssrr = sci_serial_in(port, HSSRR); 3569 + if (sci_getreg(port, SCPCR)->size) 3570 + regs->scpcr = sci_serial_in(port, SCPCR); 3571 + if (sci_getreg(port, SCPDR)->size) 3572 + regs->scpdr = sci_serial_in(port, SCPDR); 3573 + if (sci_getreg(port, SEMR)->size) 3574 + regs->semr = sci_serial_in(port, SEMR); 3575 + } 3576 + 3577 + static void sci_console_restore(struct sci_port *s) 3578 + { 3579 + struct sci_suspend_regs *regs = &s->suspend_regs; 3580 + struct uart_port *port = &s->port; 3581 + 3582 + if (sci_getreg(port, SCDL)->size) 3583 + sci_serial_out(port, SCDL, regs->scdl); 3584 + if (sci_getreg(port, SCCKS)->size) 3585 + sci_serial_out(port, SCCKS, regs->sccks); 3586 + if (sci_getreg(port, SCSMR)->size) 3587 + sci_serial_out(port, SCSMR, regs->scsmr); 3588 + if (sci_getreg(port, SCSCR)->size) 3589 + sci_serial_out(port, SCSCR, regs->scscr); 3590 + if (sci_getreg(port, SCFCR)->size) 3591 + sci_serial_out(port, SCFCR, regs->scfcr); 3592 + if (sci_getreg(port, SCSPTR)->size) 3593 + sci_serial_out(port, SCSPTR, regs->scsptr); 3594 + if (sci_getreg(port, SCBRR)->size) 3595 + sci_serial_out(port, SCBRR, regs->scbrr); 3596 + if (sci_getreg(port, HSSRR)->size) 3597 + sci_serial_out(port, HSSRR, regs->hssrr); 3598 + if (sci_getreg(port, SCPCR)->size) 3599 + sci_serial_out(port, SCPCR, regs->scpcr); 3600 + if (sci_getreg(port, SCPDR)->size) 3601 + sci_serial_out(port, SCPDR, regs->scpdr); 3602 + if (sci_getreg(port, SEMR)->size) 3603 + sci_serial_out(port, SEMR, regs->semr); 3604 + } 3605 + 3606 static __maybe_unused int sci_suspend(struct device *dev) 3607 { 3608 struct sci_port *sport = dev_get_drvdata(dev); 3609 3610 + if (sport) { 3611 uart_suspend_port(&sci_uart_driver, &sport->port); 3612 + 3613 + if (!console_suspend_enabled && uart_console(&sport->port)) 3614 + sci_console_save(sport); 3615 + else 3616 + return reset_control_assert(sport->rstc); 3617 + } 3618 3619 return 0; 3620 } ··· 3559 { 3560 struct sci_port *sport = dev_get_drvdata(dev); 3561 3562 + if (sport) { 3563 + if (!console_suspend_enabled && uart_console(&sport->port)) { 3564 + sci_console_restore(sport); 3565 + } else { 3566 + int ret = reset_control_deassert(sport->rstc); 3567 + 3568 + if (ret) 3569 + return ret; 3570 + } 3571 + 3572 uart_resume_port(&sci_uart_driver, &sport->port); 3573 + } 3574 3575 return 0; 3576 }
+2 -4
drivers/tty/serial/stm32-usart.c
··· 944 945 static void stm32_usart_disable_ms(struct uart_port *port) 946 { 947 - mctrl_gpio_disable_ms(to_stm32_port(port)->gpios); 948 } 949 950 /* Transmit stop */ ··· 965 { 966 struct tty_port *tport = &port->state->port; 967 968 - if (kfifo_is_empty(&tport->xmit_fifo) && !port->x_char) { 969 - stm32_usart_rs485_rts_disable(port); 970 return; 971 - } 972 973 stm32_usart_rs485_rts_enable(port); 974
··· 944 945 static void stm32_usart_disable_ms(struct uart_port *port) 946 { 947 + mctrl_gpio_disable_ms_sync(to_stm32_port(port)->gpios); 948 } 949 950 /* Transmit stop */ ··· 965 { 966 struct tty_port *tport = &port->state->port; 967 968 + if (kfifo_is_empty(&tport->xmit_fifo) && !port->x_char) 969 return; 970 971 stm32_usart_rs485_rts_enable(port); 972
+77 -101
drivers/tty/serial/sunsu.c
··· 151 } 152 153 /* 154 - * We used to support using pause I/O for certain machines. We 155 - * haven't supported this for a while, but just in case it's badly 156 - * needed for certain old 386 machines, I've left these #define's 157 - * in.... 158 - */ 159 - #define serial_inp(up, offset) serial_in(up, offset) 160 - #define serial_outp(up, offset, value) serial_out(up, offset, value) 161 - 162 - 163 - /* 164 * For the 16C950 165 */ 166 static void serial_icr_write(struct uart_sunsu_port *up, int offset, int value) ··· 158 serial_out(up, UART_SCR, offset); 159 serial_out(up, UART_ICR, value); 160 } 161 - 162 - #if 0 /* Unused currently */ 163 - static unsigned int serial_icr_read(struct uart_sunsu_port *up, int offset) 164 - { 165 - unsigned int value; 166 - 167 - serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD); 168 - serial_out(up, UART_SCR, offset); 169 - value = serial_in(up, UART_ICR); 170 - serial_icr_write(up, UART_ACR, up->acr); 171 - 172 - return value; 173 - } 174 - #endif 175 176 #ifdef CONFIG_SERIAL_8250_RSA 177 /* ··· 169 unsigned char mode; 170 int result; 171 172 - mode = serial_inp(up, UART_RSA_MSR); 173 result = mode & UART_RSA_MSR_FIFO; 174 175 if (!result) { 176 - serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); 177 - mode = serial_inp(up, UART_RSA_MSR); 178 result = mode & UART_RSA_MSR_FIFO; 179 } 180 ··· 193 uart_port_unlock_irq(&up->port); 194 } 195 if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) 196 - serial_outp(up, UART_RSA_FRR, 0); 197 } 198 } 199 ··· 212 up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { 213 uart_port_lock_irq(&up->port); 214 215 - mode = serial_inp(up, UART_RSA_MSR); 216 result = !(mode & UART_RSA_MSR_FIFO); 217 218 if (!result) { 219 - serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); 220 - mode = serial_inp(up, UART_RSA_MSR); 221 result = !(mode & UART_RSA_MSR_FIFO); 222 } 223 ··· 302 int saw_console_brk = 0; 303 304 do { 305 - ch = serial_inp(up, UART_RX); 306 flag = TTY_NORMAL; 307 up->port.icount.rx++; 308 ··· 363 */ 364 tty_insert_flip_char(port, 0, TTY_OVERRUN); 365 ignore_char: 366 - *status = serial_inp(up, UART_LSR); 367 } while ((*status & UART_LSR_DR) && (max_count-- > 0)); 368 369 if (saw_console_brk) ··· 377 int count; 378 379 if (up->port.x_char) { 380 - serial_outp(up, UART_TX, up->port.x_char); 381 up->port.icount.tx++; 382 up->port.x_char = 0; 383 return; ··· 436 uart_port_lock_irqsave(&up->port, &flags); 437 438 do { 439 - status = serial_inp(up, UART_LSR); 440 if (status & UART_LSR_DR) 441 receive_chars(up, &status); 442 check_modem_status(up); ··· 474 static void receive_kbd_ms_chars(struct uart_sunsu_port *up, int is_break) 475 { 476 do { 477 - unsigned char ch = serial_inp(up, UART_RX); 478 479 /* Stop-A is handled by drivers/char/keyboard.c now. */ 480 if (up->su_type == SU_PORT_KBD) { ··· 506 struct uart_sunsu_port *up = dev_id; 507 508 if (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)) { 509 - unsigned char status = serial_inp(up, UART_LSR); 510 511 if ((status & UART_LSR_DR) || (status & UART_LSR_BI)) 512 receive_kbd_ms_chars(up, (status & UART_LSR_BI) != 0); ··· 595 if (up->port.type == PORT_16C950) { 596 /* Wake up and initialize UART */ 597 up->acr = 0; 598 - serial_outp(up, UART_LCR, 0xBF); 599 - serial_outp(up, UART_EFR, UART_EFR_ECB); 600 - serial_outp(up, UART_IER, 0); 601 - serial_outp(up, UART_LCR, 0); 602 serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ 603 - serial_outp(up, UART_LCR, 0xBF); 604 - serial_outp(up, UART_EFR, UART_EFR_ECB); 605 - serial_outp(up, UART_LCR, 0); 606 } 607 608 #ifdef CONFIG_SERIAL_8250_RSA ··· 618 * (they will be reenabled in set_termios()) 619 */ 620 if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) { 621 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 622 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | 623 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 624 - serial_outp(up, UART_FCR, 0); 625 } 626 627 /* 628 * Clear the interrupt registers. 629 */ 630 - (void) serial_inp(up, UART_LSR); 631 - (void) serial_inp(up, UART_RX); 632 - (void) serial_inp(up, UART_IIR); 633 - (void) serial_inp(up, UART_MSR); 634 635 /* 636 * At this point, there's no way the LSR could still be 0xff; ··· 638 * here. 639 */ 640 if (!(up->port.flags & UPF_BUGGY_UART) && 641 - (serial_inp(up, UART_LSR) == 0xff)) { 642 printk("ttyS%d: LSR safety check engaged!\n", up->port.line); 643 return -ENODEV; 644 } ··· 658 /* 659 * Now, initialize the UART 660 */ 661 - serial_outp(up, UART_LCR, UART_LCR_WLEN8); 662 663 uart_port_lock_irqsave(&up->port, &flags); 664 ··· 673 * anyway, so we don't enable them here. 674 */ 675 up->ier = UART_IER_RLSI | UART_IER_RDI; 676 - serial_outp(up, UART_IER, up->ier); 677 678 if (up->port.flags & UPF_FOURPORT) { 679 unsigned int icp; ··· 688 /* 689 * And clear the interrupt registers again for luck. 690 */ 691 - (void) serial_inp(up, UART_LSR); 692 - (void) serial_inp(up, UART_RX); 693 - (void) serial_inp(up, UART_IIR); 694 - (void) serial_inp(up, UART_MSR); 695 696 return 0; 697 } ··· 706 * Disable interrupts from this port 707 */ 708 up->ier = 0; 709 - serial_outp(up, UART_IER, 0); 710 711 uart_port_lock_irqsave(&up->port, &flags); 712 if (up->port.flags & UPF_FOURPORT) { ··· 722 /* 723 * Disable break condition and FIFOs 724 */ 725 - serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC); 726 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | 727 UART_FCR_CLEAR_RCVR | 728 UART_FCR_CLEAR_XMIT); 729 - serial_outp(up, UART_FCR, 0); 730 731 #ifdef CONFIG_SERIAL_8250_RSA 732 /* ··· 848 serial_out(up, UART_IER, up->ier); 849 850 if (uart_config[up->port.type].flags & UART_STARTECH) { 851 - serial_outp(up, UART_LCR, 0xBF); 852 - serial_outp(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0); 853 } 854 - serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */ 855 - serial_outp(up, UART_DLL, quot & 0xff); /* LS of divisor */ 856 - serial_outp(up, UART_DLM, quot >> 8); /* MS of divisor */ 857 if (up->port.type == PORT_16750) 858 - serial_outp(up, UART_FCR, fcr); /* set fcr */ 859 - serial_outp(up, UART_LCR, cval); /* reset DLAB */ 860 up->lcr = cval; /* Save LCR */ 861 if (up->port.type != PORT_16750) { 862 if (fcr & UART_FCR_ENABLE_FIFO) { 863 /* emulated UARTs (Lucent Venus 167x) need two steps */ 864 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 865 } 866 - serial_outp(up, UART_FCR, fcr); /* set fcr */ 867 } 868 869 up->cflag = cflag; ··· 1027 * 0x80 is a non-existent port; which should be safe since 1028 * include/asm/io.h also makes this assumption. 1029 */ 1030 - scratch = serial_inp(up, UART_IER); 1031 - serial_outp(up, UART_IER, 0); 1032 #ifdef __i386__ 1033 outb(0xff, 0x080); 1034 #endif 1035 - scratch2 = serial_inp(up, UART_IER); 1036 - serial_outp(up, UART_IER, 0x0f); 1037 #ifdef __i386__ 1038 outb(0, 0x080); 1039 #endif 1040 - scratch3 = serial_inp(up, UART_IER); 1041 - serial_outp(up, UART_IER, scratch); 1042 if (scratch2 != 0 || scratch3 != 0x0F) 1043 goto out; /* We failed; there's nothing here */ 1044 } ··· 1056 * that conflicts with COM 1-4 --- we hope! 1057 */ 1058 if (!(up->port.flags & UPF_SKIP_TEST)) { 1059 - serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A); 1060 - status1 = serial_inp(up, UART_MSR) & 0xF0; 1061 - serial_outp(up, UART_MCR, save_mcr); 1062 if (status1 != 0x90) 1063 goto out; /* We failed loopback test */ 1064 } 1065 - serial_outp(up, UART_LCR, 0xBF); /* set up for StarTech test */ 1066 - serial_outp(up, UART_EFR, 0); /* EFR is the same as FCR */ 1067 - serial_outp(up, UART_LCR, 0); 1068 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1069 scratch = serial_in(up, UART_IIR) >> 6; 1070 switch (scratch) { 1071 case 0: ··· 1083 } 1084 if (up->port.type == PORT_16550A) { 1085 /* Check for Startech UART's */ 1086 - serial_outp(up, UART_LCR, UART_LCR_DLAB); 1087 if (serial_in(up, UART_EFR) == 0) { 1088 up->port.type = PORT_16650; 1089 } else { 1090 - serial_outp(up, UART_LCR, 0xBF); 1091 if (serial_in(up, UART_EFR) == 0) 1092 up->port.type = PORT_16650V2; 1093 } 1094 } 1095 if (up->port.type == PORT_16550A) { 1096 /* Check for TI 16750 */ 1097 - serial_outp(up, UART_LCR, save_lcr | UART_LCR_DLAB); 1098 - serial_outp(up, UART_FCR, 1099 UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 1100 scratch = serial_in(up, UART_IIR) >> 5; 1101 if (scratch == 7) { ··· 1105 * mode if the UART_FCR7_64BYTE bit was set 1106 * while UART_LCR_DLAB was latched. 1107 */ 1108 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1109 - serial_outp(up, UART_LCR, 0); 1110 - serial_outp(up, UART_FCR, 1111 UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 1112 scratch = serial_in(up, UART_IIR) >> 5; 1113 if (scratch == 6) 1114 up->port.type = PORT_16750; 1115 } 1116 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1117 } 1118 - serial_outp(up, UART_LCR, save_lcr); 1119 if (up->port.type == PORT_16450) { 1120 scratch = serial_in(up, UART_SCR); 1121 - serial_outp(up, UART_SCR, 0xa5); 1122 status1 = serial_in(up, UART_SCR); 1123 - serial_outp(up, UART_SCR, 0x5a); 1124 status2 = serial_in(up, UART_SCR); 1125 - serial_outp(up, UART_SCR, scratch); 1126 1127 if ((status1 != 0xa5) || (status2 != 0x5a)) 1128 up->port.type = PORT_8250; ··· 1139 */ 1140 #ifdef CONFIG_SERIAL_8250_RSA 1141 if (up->port.type == PORT_RSA) 1142 - serial_outp(up, UART_RSA_FRR, 0); 1143 #endif 1144 - serial_outp(up, UART_MCR, save_mcr); 1145 - serial_outp(up, UART_FCR, (UART_FCR_ENABLE_FIFO | 1146 UART_FCR_CLEAR_RCVR | 1147 UART_FCR_CLEAR_XMIT)); 1148 - serial_outp(up, UART_FCR, 0); 1149 (void)serial_in(up, UART_RX); 1150 - serial_outp(up, UART_IER, 0); 1151 1152 out: 1153 uart_port_unlock_irqrestore(&up->port, flags);
··· 151 } 152 153 /* 154 * For the 16C950 155 */ 156 static void serial_icr_write(struct uart_sunsu_port *up, int offset, int value) ··· 168 serial_out(up, UART_SCR, offset); 169 serial_out(up, UART_ICR, value); 170 } 171 172 #ifdef CONFIG_SERIAL_8250_RSA 173 /* ··· 193 unsigned char mode; 194 int result; 195 196 + mode = serial_in(up, UART_RSA_MSR); 197 result = mode & UART_RSA_MSR_FIFO; 198 199 if (!result) { 200 + serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); 201 + mode = serial_in(up, UART_RSA_MSR); 202 result = mode & UART_RSA_MSR_FIFO; 203 } 204 ··· 217 uart_port_unlock_irq(&up->port); 218 } 219 if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) 220 + serial_out(up, UART_RSA_FRR, 0); 221 } 222 } 223 ··· 236 up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { 237 uart_port_lock_irq(&up->port); 238 239 + mode = serial_in(up, UART_RSA_MSR); 240 result = !(mode & UART_RSA_MSR_FIFO); 241 242 if (!result) { 243 + serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); 244 + mode = serial_in(up, UART_RSA_MSR); 245 result = !(mode & UART_RSA_MSR_FIFO); 246 } 247 ··· 326 int saw_console_brk = 0; 327 328 do { 329 + ch = serial_in(up, UART_RX); 330 flag = TTY_NORMAL; 331 up->port.icount.rx++; 332 ··· 387 */ 388 tty_insert_flip_char(port, 0, TTY_OVERRUN); 389 ignore_char: 390 + *status = serial_in(up, UART_LSR); 391 } while ((*status & UART_LSR_DR) && (max_count-- > 0)); 392 393 if (saw_console_brk) ··· 401 int count; 402 403 if (up->port.x_char) { 404 + serial_out(up, UART_TX, up->port.x_char); 405 up->port.icount.tx++; 406 up->port.x_char = 0; 407 return; ··· 460 uart_port_lock_irqsave(&up->port, &flags); 461 462 do { 463 + status = serial_in(up, UART_LSR); 464 if (status & UART_LSR_DR) 465 receive_chars(up, &status); 466 check_modem_status(up); ··· 498 static void receive_kbd_ms_chars(struct uart_sunsu_port *up, int is_break) 499 { 500 do { 501 + unsigned char ch = serial_in(up, UART_RX); 502 503 /* Stop-A is handled by drivers/char/keyboard.c now. */ 504 if (up->su_type == SU_PORT_KBD) { ··· 530 struct uart_sunsu_port *up = dev_id; 531 532 if (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)) { 533 + unsigned char status = serial_in(up, UART_LSR); 534 535 if ((status & UART_LSR_DR) || (status & UART_LSR_BI)) 536 receive_kbd_ms_chars(up, (status & UART_LSR_BI) != 0); ··· 619 if (up->port.type == PORT_16C950) { 620 /* Wake up and initialize UART */ 621 up->acr = 0; 622 + serial_out(up, UART_LCR, 0xBF); 623 + serial_out(up, UART_EFR, UART_EFR_ECB); 624 + serial_out(up, UART_IER, 0); 625 + serial_out(up, UART_LCR, 0); 626 serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ 627 + serial_out(up, UART_LCR, 0xBF); 628 + serial_out(up, UART_EFR, UART_EFR_ECB); 629 + serial_out(up, UART_LCR, 0); 630 } 631 632 #ifdef CONFIG_SERIAL_8250_RSA ··· 642 * (they will be reenabled in set_termios()) 643 */ 644 if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) { 645 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 646 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 647 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 648 + serial_out(up, UART_FCR, 0); 649 } 650 651 /* 652 * Clear the interrupt registers. 653 */ 654 + (void) serial_in(up, UART_LSR); 655 + (void) serial_in(up, UART_RX); 656 + (void) serial_in(up, UART_IIR); 657 + (void) serial_in(up, UART_MSR); 658 659 /* 660 * At this point, there's no way the LSR could still be 0xff; ··· 662 * here. 663 */ 664 if (!(up->port.flags & UPF_BUGGY_UART) && 665 + (serial_in(up, UART_LSR) == 0xff)) { 666 printk("ttyS%d: LSR safety check engaged!\n", up->port.line); 667 return -ENODEV; 668 } ··· 682 /* 683 * Now, initialize the UART 684 */ 685 + serial_out(up, UART_LCR, UART_LCR_WLEN8); 686 687 uart_port_lock_irqsave(&up->port, &flags); 688 ··· 697 * anyway, so we don't enable them here. 698 */ 699 up->ier = UART_IER_RLSI | UART_IER_RDI; 700 + serial_out(up, UART_IER, up->ier); 701 702 if (up->port.flags & UPF_FOURPORT) { 703 unsigned int icp; ··· 712 /* 713 * And clear the interrupt registers again for luck. 714 */ 715 + (void) serial_in(up, UART_LSR); 716 + (void) serial_in(up, UART_RX); 717 + (void) serial_in(up, UART_IIR); 718 + (void) serial_in(up, UART_MSR); 719 720 return 0; 721 } ··· 730 * Disable interrupts from this port 731 */ 732 up->ier = 0; 733 + serial_out(up, UART_IER, 0); 734 735 uart_port_lock_irqsave(&up->port, &flags); 736 if (up->port.flags & UPF_FOURPORT) { ··· 746 /* 747 * Disable break condition and FIFOs 748 */ 749 + serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC); 750 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 751 UART_FCR_CLEAR_RCVR | 752 UART_FCR_CLEAR_XMIT); 753 + serial_out(up, UART_FCR, 0); 754 755 #ifdef CONFIG_SERIAL_8250_RSA 756 /* ··· 872 serial_out(up, UART_IER, up->ier); 873 874 if (uart_config[up->port.type].flags & UART_STARTECH) { 875 + serial_out(up, UART_LCR, 0xBF); 876 + serial_out(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0); 877 } 878 + serial_out(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */ 879 + serial_out(up, UART_DLL, quot & 0xff); /* LS of divisor */ 880 + serial_out(up, UART_DLM, quot >> 8); /* MS of divisor */ 881 if (up->port.type == PORT_16750) 882 + serial_out(up, UART_FCR, fcr); /* set fcr */ 883 + serial_out(up, UART_LCR, cval); /* reset DLAB */ 884 up->lcr = cval; /* Save LCR */ 885 if (up->port.type != PORT_16750) { 886 if (fcr & UART_FCR_ENABLE_FIFO) { 887 /* emulated UARTs (Lucent Venus 167x) need two steps */ 888 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 889 } 890 + serial_out(up, UART_FCR, fcr); /* set fcr */ 891 } 892 893 up->cflag = cflag; ··· 1051 * 0x80 is a non-existent port; which should be safe since 1052 * include/asm/io.h also makes this assumption. 1053 */ 1054 + scratch = serial_in(up, UART_IER); 1055 + serial_out(up, UART_IER, 0); 1056 #ifdef __i386__ 1057 outb(0xff, 0x080); 1058 #endif 1059 + scratch2 = serial_in(up, UART_IER); 1060 + serial_out(up, UART_IER, 0x0f); 1061 #ifdef __i386__ 1062 outb(0, 0x080); 1063 #endif 1064 + scratch3 = serial_in(up, UART_IER); 1065 + serial_out(up, UART_IER, scratch); 1066 if (scratch2 != 0 || scratch3 != 0x0F) 1067 goto out; /* We failed; there's nothing here */ 1068 } ··· 1080 * that conflicts with COM 1-4 --- we hope! 1081 */ 1082 if (!(up->port.flags & UPF_SKIP_TEST)) { 1083 + serial_out(up, UART_MCR, UART_MCR_LOOP | 0x0A); 1084 + status1 = serial_in(up, UART_MSR) & 0xF0; 1085 + serial_out(up, UART_MCR, save_mcr); 1086 if (status1 != 0x90) 1087 goto out; /* We failed loopback test */ 1088 } 1089 + serial_out(up, UART_LCR, 0xBF); /* set up for StarTech test */ 1090 + serial_out(up, UART_EFR, 0); /* EFR is the same as FCR */ 1091 + serial_out(up, UART_LCR, 0); 1092 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1093 scratch = serial_in(up, UART_IIR) >> 6; 1094 switch (scratch) { 1095 case 0: ··· 1107 } 1108 if (up->port.type == PORT_16550A) { 1109 /* Check for Startech UART's */ 1110 + serial_out(up, UART_LCR, UART_LCR_DLAB); 1111 if (serial_in(up, UART_EFR) == 0) { 1112 up->port.type = PORT_16650; 1113 } else { 1114 + serial_out(up, UART_LCR, 0xBF); 1115 if (serial_in(up, UART_EFR) == 0) 1116 up->port.type = PORT_16650V2; 1117 } 1118 } 1119 if (up->port.type == PORT_16550A) { 1120 /* Check for TI 16750 */ 1121 + serial_out(up, UART_LCR, save_lcr | UART_LCR_DLAB); 1122 + serial_out(up, UART_FCR, 1123 UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 1124 scratch = serial_in(up, UART_IIR) >> 5; 1125 if (scratch == 7) { ··· 1129 * mode if the UART_FCR7_64BYTE bit was set 1130 * while UART_LCR_DLAB was latched. 1131 */ 1132 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1133 + serial_out(up, UART_LCR, 0); 1134 + serial_out(up, UART_FCR, 1135 UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 1136 scratch = serial_in(up, UART_IIR) >> 5; 1137 if (scratch == 6) 1138 up->port.type = PORT_16750; 1139 } 1140 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1141 } 1142 + serial_out(up, UART_LCR, save_lcr); 1143 if (up->port.type == PORT_16450) { 1144 scratch = serial_in(up, UART_SCR); 1145 + serial_out(up, UART_SCR, 0xa5); 1146 status1 = serial_in(up, UART_SCR); 1147 + serial_out(up, UART_SCR, 0x5a); 1148 status2 = serial_in(up, UART_SCR); 1149 + serial_out(up, UART_SCR, scratch); 1150 1151 if ((status1 != 0xa5) || (status2 != 0x5a)) 1152 up->port.type = PORT_8250; ··· 1163 */ 1164 #ifdef CONFIG_SERIAL_8250_RSA 1165 if (up->port.type == PORT_RSA) 1166 + serial_out(up, UART_RSA_FRR, 0); 1167 #endif 1168 + serial_out(up, UART_MCR, save_mcr); 1169 + serial_out(up, UART_FCR, (UART_FCR_ENABLE_FIFO | 1170 UART_FCR_CLEAR_RCVR | 1171 UART_FCR_CLEAR_XMIT)); 1172 + serial_out(up, UART_FCR, 0); 1173 (void)serial_in(up, UART_RX); 1174 + serial_out(up, UART_IER, 0); 1175 1176 out: 1177 uart_port_unlock_irqrestore(&up->port, flags);
+625
drivers/tty/serial/tegra-utc.c
···
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + // SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 + // NVIDIA Tegra UTC (UART Trace Controller) driver. 4 + 5 + #include <linux/bits.h> 6 + #include <linux/console.h> 7 + #include <linux/container_of.h> 8 + #include <linux/device.h> 9 + #include <linux/err.h> 10 + #include <linux/iopoll.h> 11 + #include <linux/kfifo.h> 12 + #include <linux/module.h> 13 + #include <linux/mod_devicetable.h> 14 + #include <linux/property.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/serial.h> 17 + #include <linux/serial_core.h> 18 + #include <linux/slab.h> 19 + #include <linux/tty.h> 20 + #include <linux/tty_flip.h> 21 + #include <linux/types.h> 22 + 23 + #define TEGRA_UTC_ENABLE 0x000 24 + #define TEGRA_UTC_ENABLE_CLIENT_ENABLE BIT(0) 25 + 26 + #define TEGRA_UTC_FIFO_THRESHOLD 0x008 27 + 28 + #define TEGRA_UTC_COMMAND 0x00c 29 + #define TEGRA_UTC_COMMAND_RESET BIT(0) 30 + #define TEGRA_UTC_COMMAND_FLUSH BIT(1) 31 + 32 + #define TEGRA_UTC_DATA 0x020 33 + 34 + #define TEGRA_UTC_FIFO_STATUS 0x100 35 + #define TEGRA_UTC_FIFO_EMPTY BIT(0) 36 + #define TEGRA_UTC_FIFO_FULL BIT(1) 37 + #define TEGRA_UTC_FIFO_REQ BIT(2) 38 + #define TEGRA_UTC_FIFO_OVERFLOW BIT(3) 39 + #define TEGRA_UTC_FIFO_TIMEOUT BIT(4) 40 + 41 + #define TEGRA_UTC_FIFO_OCCUPANCY 0x104 42 + 43 + #define TEGRA_UTC_INTR_STATUS 0x108 44 + #define TEGRA_UTC_INTR_SET 0x10c 45 + #define TEGRA_UTC_INTR_MASK 0x110 46 + #define TEGRA_UTC_INTR_CLEAR 0x114 47 + #define TEGRA_UTC_INTR_EMPTY BIT(0) 48 + #define TEGRA_UTC_INTR_FULL BIT(1) 49 + #define TEGRA_UTC_INTR_REQ BIT(2) 50 + #define TEGRA_UTC_INTR_OVERFLOW BIT(3) 51 + #define TEGRA_UTC_INTR_TIMEOUT BIT(4) 52 + 53 + #define TEGRA_UTC_UART_NR 16 54 + 55 + #define TEGRA_UTC_INTR_COMMON (TEGRA_UTC_INTR_REQ | TEGRA_UTC_INTR_FULL | TEGRA_UTC_INTR_EMPTY) 56 + 57 + struct tegra_utc_port { 58 + #if IS_ENABLED(CONFIG_SERIAL_TEGRA_UTC_CONSOLE) 59 + struct console console; 60 + #endif 61 + struct uart_port port; 62 + 63 + void __iomem *rx_base; 64 + void __iomem *tx_base; 65 + 66 + u32 tx_irqmask; 67 + u32 rx_irqmask; 68 + 69 + unsigned int fifosize; 70 + u32 tx_threshold; 71 + u32 rx_threshold; 72 + }; 73 + 74 + static u32 tegra_utc_rx_readl(struct tegra_utc_port *tup, unsigned int offset) 75 + { 76 + void __iomem *addr = tup->rx_base + offset; 77 + 78 + return readl_relaxed(addr); 79 + } 80 + 81 + static void tegra_utc_rx_writel(struct tegra_utc_port *tup, u32 val, unsigned int offset) 82 + { 83 + void __iomem *addr = tup->rx_base + offset; 84 + 85 + writel_relaxed(val, addr); 86 + } 87 + 88 + static u32 tegra_utc_tx_readl(struct tegra_utc_port *tup, unsigned int offset) 89 + { 90 + void __iomem *addr = tup->tx_base + offset; 91 + 92 + return readl_relaxed(addr); 93 + } 94 + 95 + static void tegra_utc_tx_writel(struct tegra_utc_port *tup, u32 val, unsigned int offset) 96 + { 97 + void __iomem *addr = tup->tx_base + offset; 98 + 99 + writel_relaxed(val, addr); 100 + } 101 + 102 + static void tegra_utc_enable_tx_irq(struct tegra_utc_port *tup) 103 + { 104 + tup->tx_irqmask = TEGRA_UTC_INTR_REQ; 105 + 106 + tegra_utc_tx_writel(tup, tup->tx_irqmask, TEGRA_UTC_INTR_MASK); 107 + tegra_utc_tx_writel(tup, tup->tx_irqmask, TEGRA_UTC_INTR_SET); 108 + } 109 + 110 + static void tegra_utc_disable_tx_irq(struct tegra_utc_port *tup) 111 + { 112 + tup->tx_irqmask = 0x0; 113 + 114 + tegra_utc_tx_writel(tup, tup->tx_irqmask, TEGRA_UTC_INTR_MASK); 115 + tegra_utc_tx_writel(tup, tup->tx_irqmask, TEGRA_UTC_INTR_SET); 116 + } 117 + 118 + static void tegra_utc_stop_tx(struct uart_port *port) 119 + { 120 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 121 + 122 + tegra_utc_disable_tx_irq(tup); 123 + } 124 + 125 + static void tegra_utc_init_tx(struct tegra_utc_port *tup) 126 + { 127 + /* Disable TX. */ 128 + tegra_utc_tx_writel(tup, 0x0, TEGRA_UTC_ENABLE); 129 + 130 + /* Update the FIFO Threshold. */ 131 + tegra_utc_tx_writel(tup, tup->tx_threshold, TEGRA_UTC_FIFO_THRESHOLD); 132 + 133 + /* Clear and mask all the interrupts. */ 134 + tegra_utc_tx_writel(tup, TEGRA_UTC_INTR_COMMON, TEGRA_UTC_INTR_CLEAR); 135 + tegra_utc_disable_tx_irq(tup); 136 + 137 + /* Enable TX. */ 138 + tegra_utc_tx_writel(tup, TEGRA_UTC_ENABLE_CLIENT_ENABLE, TEGRA_UTC_ENABLE); 139 + } 140 + 141 + static void tegra_utc_init_rx(struct tegra_utc_port *tup) 142 + { 143 + tup->rx_irqmask = TEGRA_UTC_INTR_REQ | TEGRA_UTC_INTR_TIMEOUT; 144 + 145 + tegra_utc_rx_writel(tup, TEGRA_UTC_COMMAND_RESET, TEGRA_UTC_COMMAND); 146 + tegra_utc_rx_writel(tup, tup->rx_threshold, TEGRA_UTC_FIFO_THRESHOLD); 147 + 148 + /* Clear all the pending interrupts. */ 149 + tegra_utc_rx_writel(tup, TEGRA_UTC_INTR_TIMEOUT | TEGRA_UTC_INTR_OVERFLOW | 150 + TEGRA_UTC_INTR_COMMON, TEGRA_UTC_INTR_CLEAR); 151 + tegra_utc_rx_writel(tup, tup->rx_irqmask, TEGRA_UTC_INTR_MASK); 152 + tegra_utc_rx_writel(tup, tup->rx_irqmask, TEGRA_UTC_INTR_SET); 153 + 154 + /* Enable RX. */ 155 + tegra_utc_rx_writel(tup, TEGRA_UTC_ENABLE_CLIENT_ENABLE, TEGRA_UTC_ENABLE); 156 + } 157 + 158 + static bool tegra_utc_tx_chars(struct tegra_utc_port *tup) 159 + { 160 + struct uart_port *port = &tup->port; 161 + unsigned int pending; 162 + u8 c; 163 + 164 + pending = uart_port_tx(port, c, 165 + !(tegra_utc_tx_readl(tup, TEGRA_UTC_FIFO_STATUS) & TEGRA_UTC_FIFO_FULL), 166 + tegra_utc_tx_writel(tup, c, TEGRA_UTC_DATA)); 167 + 168 + return pending; 169 + } 170 + 171 + static void tegra_utc_rx_chars(struct tegra_utc_port *tup) 172 + { 173 + struct tty_port *port = &tup->port.state->port; 174 + unsigned int max_chars = 256; 175 + u32 status; 176 + int sysrq; 177 + u32 ch; 178 + 179 + while (max_chars--) { 180 + status = tegra_utc_rx_readl(tup, TEGRA_UTC_FIFO_STATUS); 181 + if (status & TEGRA_UTC_FIFO_EMPTY) 182 + break; 183 + 184 + ch = tegra_utc_rx_readl(tup, TEGRA_UTC_DATA); 185 + tup->port.icount.rx++; 186 + 187 + if (status & TEGRA_UTC_FIFO_OVERFLOW) 188 + tup->port.icount.overrun++; 189 + 190 + uart_port_unlock(&tup->port); 191 + sysrq = uart_handle_sysrq_char(&tup->port, ch); 192 + uart_port_lock(&tup->port); 193 + 194 + if (!sysrq) 195 + tty_insert_flip_char(port, ch, TTY_NORMAL); 196 + } 197 + 198 + tty_flip_buffer_push(port); 199 + } 200 + 201 + static irqreturn_t tegra_utc_isr(int irq, void *dev_id) 202 + { 203 + struct tegra_utc_port *tup = dev_id; 204 + unsigned int handled = 0; 205 + u32 status; 206 + 207 + uart_port_lock(&tup->port); 208 + 209 + /* Process RX_REQ and RX_TIMEOUT interrupts. */ 210 + do { 211 + status = tegra_utc_rx_readl(tup, TEGRA_UTC_INTR_STATUS) & tup->rx_irqmask; 212 + if (status) { 213 + tegra_utc_rx_writel(tup, tup->rx_irqmask, TEGRA_UTC_INTR_CLEAR); 214 + tegra_utc_rx_chars(tup); 215 + handled = 1; 216 + } 217 + } while (status); 218 + 219 + /* Process TX_REQ interrupt. */ 220 + do { 221 + status = tegra_utc_tx_readl(tup, TEGRA_UTC_INTR_STATUS) & tup->tx_irqmask; 222 + if (status) { 223 + tegra_utc_tx_writel(tup, tup->tx_irqmask, TEGRA_UTC_INTR_CLEAR); 224 + tegra_utc_tx_chars(tup); 225 + handled = 1; 226 + } 227 + } while (status); 228 + 229 + uart_port_unlock(&tup->port); 230 + 231 + return IRQ_RETVAL(handled); 232 + } 233 + 234 + static unsigned int tegra_utc_tx_empty(struct uart_port *port) 235 + { 236 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 237 + 238 + return tegra_utc_tx_readl(tup, TEGRA_UTC_FIFO_OCCUPANCY) ? 0 : TIOCSER_TEMT; 239 + } 240 + 241 + static void tegra_utc_set_mctrl(struct uart_port *port, unsigned int mctrl) 242 + { 243 + } 244 + 245 + static unsigned int tegra_utc_get_mctrl(struct uart_port *port) 246 + { 247 + return 0; 248 + } 249 + 250 + static void tegra_utc_start_tx(struct uart_port *port) 251 + { 252 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 253 + 254 + if (tegra_utc_tx_chars(tup)) 255 + tegra_utc_enable_tx_irq(tup); 256 + } 257 + 258 + static void tegra_utc_stop_rx(struct uart_port *port) 259 + { 260 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 261 + 262 + tup->rx_irqmask = 0x0; 263 + tegra_utc_rx_writel(tup, tup->rx_irqmask, TEGRA_UTC_INTR_MASK); 264 + tegra_utc_rx_writel(tup, tup->rx_irqmask, TEGRA_UTC_INTR_SET); 265 + } 266 + 267 + static void tegra_utc_hw_init(struct tegra_utc_port *tup) 268 + { 269 + tegra_utc_init_tx(tup); 270 + tegra_utc_init_rx(tup); 271 + } 272 + 273 + static int tegra_utc_startup(struct uart_port *port) 274 + { 275 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 276 + int ret; 277 + 278 + tegra_utc_hw_init(tup); 279 + 280 + /* Interrupt is dedicated to this UTC client. */ 281 + ret = request_irq(port->irq, tegra_utc_isr, 0, dev_name(port->dev), tup); 282 + if (ret < 0) 283 + dev_err(port->dev, "failed to register interrupt handler\n"); 284 + 285 + return ret; 286 + } 287 + 288 + static void tegra_utc_shutdown(struct uart_port *port) 289 + { 290 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 291 + 292 + tegra_utc_rx_writel(tup, 0x0, TEGRA_UTC_ENABLE); 293 + free_irq(port->irq, tup); 294 + } 295 + 296 + static void tegra_utc_set_termios(struct uart_port *port, struct ktermios *termios, 297 + const struct ktermios *old) 298 + { 299 + /* The Tegra UTC clients supports only 8-N-1 configuration without HW flow control */ 300 + termios->c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD); 301 + termios->c_cflag &= ~(CMSPAR | CRTSCTS); 302 + termios->c_cflag |= CS8 | CLOCAL; 303 + } 304 + 305 + #ifdef CONFIG_CONSOLE_POLL 306 + 307 + static int tegra_utc_poll_init(struct uart_port *port) 308 + { 309 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 310 + 311 + tegra_utc_hw_init(tup); 312 + return 0; 313 + } 314 + 315 + static int tegra_utc_get_poll_char(struct uart_port *port) 316 + { 317 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 318 + 319 + if (tegra_utc_rx_readl(tup, TEGRA_UTC_FIFO_STATUS) & TEGRA_UTC_FIFO_EMPTY) 320 + return NO_POLL_CHAR; 321 + 322 + return tegra_utc_rx_readl(tup, TEGRA_UTC_DATA); 323 + } 324 + 325 + static void tegra_utc_put_poll_char(struct uart_port *port, unsigned char ch) 326 + { 327 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 328 + u32 val; 329 + 330 + read_poll_timeout_atomic(tegra_utc_tx_readl, val, !(val & TEGRA_UTC_FIFO_FULL), 331 + 0, USEC_PER_SEC, false, tup, TEGRA_UTC_FIFO_STATUS); 332 + 333 + tegra_utc_tx_writel(tup, ch, TEGRA_UTC_DATA); 334 + } 335 + 336 + #endif 337 + 338 + static const struct uart_ops tegra_utc_uart_ops = { 339 + .tx_empty = tegra_utc_tx_empty, 340 + .set_mctrl = tegra_utc_set_mctrl, 341 + .get_mctrl = tegra_utc_get_mctrl, 342 + .stop_tx = tegra_utc_stop_tx, 343 + .start_tx = tegra_utc_start_tx, 344 + .stop_rx = tegra_utc_stop_rx, 345 + .startup = tegra_utc_startup, 346 + .shutdown = tegra_utc_shutdown, 347 + .set_termios = tegra_utc_set_termios, 348 + #ifdef CONFIG_CONSOLE_POLL 349 + .poll_init = tegra_utc_poll_init, 350 + .poll_get_char = tegra_utc_get_poll_char, 351 + .poll_put_char = tegra_utc_put_poll_char, 352 + #endif 353 + }; 354 + 355 + #if IS_ENABLED(CONFIG_SERIAL_TEGRA_UTC_CONSOLE) 356 + #define TEGRA_UTC_DEFAULT_FIFO_THRESHOLD 4 357 + #define TEGRA_UTC_EARLYCON_MAX_BURST_SIZE 128 358 + 359 + static void tegra_utc_putc(struct uart_port *port, unsigned char c) 360 + { 361 + writel(c, port->membase + TEGRA_UTC_DATA); 362 + } 363 + 364 + static void tegra_utc_early_write(struct console *con, const char *s, unsigned int n) 365 + { 366 + struct earlycon_device *dev = con->data; 367 + 368 + while (n) { 369 + u32 burst_size = TEGRA_UTC_EARLYCON_MAX_BURST_SIZE; 370 + 371 + burst_size -= readl(dev->port.membase + TEGRA_UTC_FIFO_OCCUPANCY); 372 + if (n < burst_size) 373 + burst_size = n; 374 + 375 + uart_console_write(&dev->port, s, burst_size, tegra_utc_putc); 376 + 377 + n -= burst_size; 378 + s += burst_size; 379 + } 380 + } 381 + 382 + static int __init tegra_utc_early_console_setup(struct earlycon_device *device, const char *opt) 383 + { 384 + if (!device->port.membase) 385 + return -ENODEV; 386 + 387 + /* Configure TX */ 388 + writel(TEGRA_UTC_COMMAND_FLUSH | TEGRA_UTC_COMMAND_RESET, 389 + device->port.membase + TEGRA_UTC_COMMAND); 390 + writel(TEGRA_UTC_DEFAULT_FIFO_THRESHOLD, device->port.membase + TEGRA_UTC_FIFO_THRESHOLD); 391 + 392 + /* Clear and mask all the interrupts. */ 393 + writel(TEGRA_UTC_INTR_COMMON, device->port.membase + TEGRA_UTC_INTR_CLEAR); 394 + 395 + writel(0x0, device->port.membase + TEGRA_UTC_INTR_MASK); 396 + writel(0x0, device->port.membase + TEGRA_UTC_INTR_SET); 397 + 398 + /* Enable TX. */ 399 + writel(TEGRA_UTC_ENABLE_CLIENT_ENABLE, device->port.membase + TEGRA_UTC_ENABLE); 400 + 401 + device->con->write = tegra_utc_early_write; 402 + 403 + return 0; 404 + } 405 + OF_EARLYCON_DECLARE(tegra_utc, "nvidia,tegra264-utc", tegra_utc_early_console_setup); 406 + 407 + static void tegra_utc_console_putchar(struct uart_port *port, unsigned char ch) 408 + { 409 + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); 410 + 411 + tegra_utc_tx_writel(tup, ch, TEGRA_UTC_DATA); 412 + } 413 + 414 + static void tegra_utc_console_write_atomic(struct console *cons, struct nbcon_write_context *wctxt) 415 + { 416 + struct tegra_utc_port *tup = container_of(cons, struct tegra_utc_port, console); 417 + unsigned int len; 418 + char *outbuf; 419 + 420 + if (!nbcon_enter_unsafe(wctxt)) 421 + return; 422 + 423 + outbuf = wctxt->outbuf; 424 + len = wctxt->len; 425 + 426 + while (len) { 427 + u32 burst_size = tup->fifosize; 428 + 429 + burst_size -= tegra_utc_tx_readl(tup, TEGRA_UTC_FIFO_OCCUPANCY); 430 + if (len < burst_size) 431 + burst_size = len; 432 + 433 + uart_console_write(&tup->port, outbuf, burst_size, tegra_utc_console_putchar); 434 + 435 + outbuf += burst_size; 436 + len -= burst_size; 437 + }; 438 + 439 + nbcon_exit_unsafe(wctxt); 440 + } 441 + 442 + static void tegra_utc_console_write_thread(struct console *cons, struct nbcon_write_context *wctxt) 443 + { 444 + struct tegra_utc_port *tup = container_of(cons, struct tegra_utc_port, console); 445 + unsigned int len = READ_ONCE(wctxt->len); 446 + unsigned int i; 447 + u32 val; 448 + 449 + for (i = 0; i < len; i++) { 450 + if (!nbcon_enter_unsafe(wctxt)) 451 + break; 452 + 453 + read_poll_timeout_atomic(tegra_utc_tx_readl, val, !(val & TEGRA_UTC_FIFO_FULL), 454 + 0, USEC_PER_SEC, false, tup, TEGRA_UTC_FIFO_STATUS); 455 + uart_console_write(&tup->port, wctxt->outbuf + i, 1, tegra_utc_console_putchar); 456 + 457 + if (!nbcon_exit_unsafe(wctxt)) 458 + break; 459 + } 460 + } 461 + 462 + static void tegra_utc_console_device_lock(struct console *cons, unsigned long *flags) 463 + { 464 + struct tegra_utc_port *tup = container_of(cons, struct tegra_utc_port, console); 465 + struct uart_port *port = &tup->port; 466 + 467 + __uart_port_lock_irqsave(port, flags); 468 + } 469 + 470 + static void tegra_utc_console_device_unlock(struct console *cons, unsigned long flags) 471 + { 472 + struct tegra_utc_port *tup = container_of(cons, struct tegra_utc_port, console); 473 + struct uart_port *port = &tup->port; 474 + 475 + __uart_port_unlock_irqrestore(port, flags); 476 + } 477 + 478 + static int tegra_utc_console_setup(struct console *cons, char *options) 479 + { 480 + struct tegra_utc_port *tup = container_of(cons, struct tegra_utc_port, console); 481 + 482 + tegra_utc_init_tx(tup); 483 + 484 + return 0; 485 + } 486 + #endif 487 + 488 + static struct uart_driver tegra_utc_driver = { 489 + .driver_name = "tegra-utc", 490 + .dev_name = "ttyUTC", 491 + .nr = TEGRA_UTC_UART_NR, 492 + }; 493 + 494 + static int tegra_utc_setup_port(struct device *dev, struct tegra_utc_port *tup) 495 + { 496 + tup->port.dev = dev; 497 + tup->port.fifosize = tup->fifosize; 498 + tup->port.flags = UPF_BOOT_AUTOCONF; 499 + tup->port.iotype = UPIO_MEM; 500 + tup->port.ops = &tegra_utc_uart_ops; 501 + tup->port.type = PORT_TEGRA_TCU; 502 + tup->port.private_data = tup; 503 + 504 + #if IS_ENABLED(CONFIG_SERIAL_TEGRA_UTC_CONSOLE) 505 + strscpy(tup->console.name, "ttyUTC", sizeof(tup->console.name)); 506 + tup->console.write_atomic = tegra_utc_console_write_atomic; 507 + tup->console.write_thread = tegra_utc_console_write_thread; 508 + tup->console.device_lock = tegra_utc_console_device_lock; 509 + tup->console.device_unlock = tegra_utc_console_device_unlock; 510 + tup->console.device = uart_console_device; 511 + tup->console.setup = tegra_utc_console_setup; 512 + tup->console.flags = CON_PRINTBUFFER | CON_NBCON; 513 + tup->console.data = &tegra_utc_driver; 514 + #endif 515 + 516 + return uart_read_port_properties(&tup->port); 517 + } 518 + 519 + static int tegra_utc_register_port(struct tegra_utc_port *tup) 520 + { 521 + int ret; 522 + 523 + ret = uart_add_one_port(&tegra_utc_driver, &tup->port); 524 + if (ret) 525 + return ret; 526 + 527 + #if IS_ENABLED(CONFIG_SERIAL_TEGRA_UTC_CONSOLE) 528 + register_console(&tup->console); 529 + #endif 530 + 531 + return 0; 532 + } 533 + 534 + static int tegra_utc_probe(struct platform_device *pdev) 535 + { 536 + const unsigned int *soc_fifosize; 537 + struct device *dev = &pdev->dev; 538 + struct tegra_utc_port *tup; 539 + int ret; 540 + 541 + tup = devm_kzalloc(dev, sizeof(*tup), GFP_KERNEL); 542 + if (!tup) 543 + return -ENOMEM; 544 + 545 + ret = device_property_read_u32(dev, "tx-threshold", &tup->tx_threshold); 546 + if (ret) 547 + return dev_err_probe(dev, ret, "missing %s property\n", "tx-threshold"); 548 + 549 + ret = device_property_read_u32(dev, "rx-threshold", &tup->rx_threshold); 550 + if (ret) 551 + return dev_err_probe(dev, ret, "missing %s property\n", "rx-threshold"); 552 + 553 + soc_fifosize = device_get_match_data(dev); 554 + tup->fifosize = *soc_fifosize; 555 + 556 + tup->tx_base = devm_platform_ioremap_resource_byname(pdev, "tx"); 557 + if (IS_ERR(tup->tx_base)) 558 + return PTR_ERR(tup->tx_base); 559 + 560 + tup->rx_base = devm_platform_ioremap_resource_byname(pdev, "rx"); 561 + if (IS_ERR(tup->rx_base)) 562 + return PTR_ERR(tup->rx_base); 563 + 564 + ret = tegra_utc_setup_port(dev, tup); 565 + if (ret) 566 + dev_err_probe(dev, ret, "failed to setup uart port\n"); 567 + 568 + platform_set_drvdata(pdev, tup); 569 + 570 + return tegra_utc_register_port(tup); 571 + } 572 + 573 + static void tegra_utc_remove(struct platform_device *pdev) 574 + { 575 + struct tegra_utc_port *tup = platform_get_drvdata(pdev); 576 + 577 + #if IS_ENABLED(CONFIG_SERIAL_TEGRA_UTC_CONSOLE) 578 + unregister_console(&tup->console); 579 + #endif 580 + uart_remove_one_port(&tegra_utc_driver, &tup->port); 581 + } 582 + 583 + static const unsigned int tegra264_utc_soc = 128; 584 + 585 + static const struct of_device_id tegra_utc_of_match[] = { 586 + { .compatible = "nvidia,tegra264-utc", .data = &tegra264_utc_soc }, 587 + {} 588 + }; 589 + MODULE_DEVICE_TABLE(of, tegra_utc_of_match); 590 + 591 + static struct platform_driver tegra_utc_platform_driver = { 592 + .probe = tegra_utc_probe, 593 + .remove = tegra_utc_remove, 594 + .driver = { 595 + .name = "tegra-utc", 596 + .of_match_table = tegra_utc_of_match, 597 + }, 598 + }; 599 + 600 + static int __init tegra_utc_init(void) 601 + { 602 + int ret; 603 + 604 + ret = uart_register_driver(&tegra_utc_driver); 605 + if (ret) 606 + return ret; 607 + 608 + ret = platform_driver_register(&tegra_utc_platform_driver); 609 + if (ret) 610 + uart_unregister_driver(&tegra_utc_driver); 611 + 612 + return ret; 613 + } 614 + module_init(tegra_utc_init); 615 + 616 + static void __exit tegra_utc_exit(void) 617 + { 618 + platform_driver_unregister(&tegra_utc_platform_driver); 619 + uart_unregister_driver(&tegra_utc_driver); 620 + } 621 + module_exit(tegra_utc_exit); 622 + 623 + MODULE_AUTHOR("Kartik Rajput <kkartik@nvidia.com>"); 624 + MODULE_DESCRIPTION("Tegra UART Trace Controller"); 625 + MODULE_LICENSE("GPL");
+6 -4
drivers/tty/tty_audit.c
··· 12 #include <linux/tty.h> 13 #include "tty.h" 14 15 struct tty_audit_buf { 16 struct mutex mutex; /* Protects all data below */ 17 dev_t dev; /* The TTY which the data is from */ 18 bool icanon; 19 size_t valid; 20 - u8 *data; /* Allocated size N_TTY_BUF_SIZE */ 21 }; 22 23 static struct tty_audit_buf *tty_audit_buf_ref(void) ··· 39 if (!buf) 40 goto err; 41 42 - buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL); 43 if (!buf->data) 44 goto err_buf; 45 ··· 237 do { 238 size_t run; 239 240 - run = N_TTY_BUF_SIZE - buf->valid; 241 if (run > size) 242 run = size; 243 memcpy(buf->data + buf->valid, data, run); 244 buf->valid += run; 245 data += run; 246 size -= run; 247 - if (buf->valid == N_TTY_BUF_SIZE) 248 tty_audit_buf_push(buf); 249 } while (size != 0); 250 mutex_unlock(&buf->mutex);
··· 12 #include <linux/tty.h> 13 #include "tty.h" 14 15 + #define TTY_AUDIT_BUF_SIZE 4096 16 + 17 struct tty_audit_buf { 18 struct mutex mutex; /* Protects all data below */ 19 dev_t dev; /* The TTY which the data is from */ 20 bool icanon; 21 size_t valid; 22 + u8 *data; /* Allocated size TTY_AUDIT_BUF_SIZE */ 23 }; 24 25 static struct tty_audit_buf *tty_audit_buf_ref(void) ··· 37 if (!buf) 38 goto err; 39 40 + buf->data = kmalloc(TTY_AUDIT_BUF_SIZE, GFP_KERNEL); 41 if (!buf->data) 42 goto err_buf; 43 ··· 235 do { 236 size_t run; 237 238 + run = TTY_AUDIT_BUF_SIZE - buf->valid; 239 if (run > size) 240 run = size; 241 memcpy(buf->data + buf->valid, data, run); 242 buf->valid += run; 243 data += run; 244 size -= run; 245 + if (buf->valid == TTY_AUDIT_BUF_SIZE) 246 tty_audit_buf_push(buf); 247 } while (size != 0); 248 mutex_unlock(&buf->mutex);
+5 -3
drivers/tty/tty_io.c
··· 3329 * __tty_alloc_driver - allocate tty driver 3330 * @lines: count of lines this driver can handle at most 3331 * @owner: module which is responsible for this driver 3332 - * @flags: some of %TTY_DRIVER_ flags, will be set in driver->flags 3333 * 3334 - * This should not be called directly, some of the provided macros should be 3335 - * used instead. Use IS_ERR() and friends on @retval. 3336 */ 3337 struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner, 3338 unsigned long flags)
··· 3329 * __tty_alloc_driver - allocate tty driver 3330 * @lines: count of lines this driver can handle at most 3331 * @owner: module which is responsible for this driver 3332 + * @flags: some of enum tty_driver_flag, will be set in driver->flags 3333 * 3334 + * This should not be called directly, tty_alloc_driver() should be used 3335 + * instead. 3336 + * 3337 + * Returns: struct tty_driver or a PTR-encoded error (use IS_ERR() and friends). 3338 */ 3339 struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner, 3340 unsigned long flags)
-17
drivers/tty/tty_ldsem.c
··· 367 } 368 369 /* 370 - * trylock for writing -- returns 1 if successful, 0 if contention 371 - */ 372 - int ldsem_down_write_trylock(struct ld_semaphore *sem) 373 - { 374 - long count = atomic_long_read(&sem->count); 375 - 376 - while ((count & LDSEM_ACTIVE_MASK) == 0) { 377 - if (atomic_long_try_cmpxchg(&sem->count, &count, count + LDSEM_WRITE_BIAS)) { 378 - rwsem_acquire(&sem->dep_map, 0, 1, _RET_IP_); 379 - lock_acquired(&sem->dep_map, _RET_IP_); 380 - return 1; 381 - } 382 - } 383 - return 0; 384 - } 385 - 386 - /* 387 * release a read lock 388 */ 389 void ldsem_up_read(struct ld_semaphore *sem)
··· 367 } 368 369 /* 370 * release a read lock 371 */ 372 void ldsem_up_read(struct ld_semaphore *sem)
-11
include/linux/kgdb.h
··· 257 * hardware breakpoints. 258 * @correct_hw_break: Allow an architecture to specify how to correct the 259 * hardware debug registers. 260 - * @enable_nmi: Manage NMI-triggered entry to KGDB 261 */ 262 struct kgdb_arch { 263 unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE]; ··· 269 void (*disable_hw_break)(struct pt_regs *regs); 270 void (*remove_all_hw_break)(void); 271 void (*correct_hw_break)(void); 272 - 273 - void (*enable_nmi)(bool on); 274 }; 275 276 /** ··· 302 extern const struct kgdb_arch arch_kgdb_ops; 303 304 extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs); 305 - 306 - #ifdef CONFIG_SERIAL_KGDB_NMI 307 - extern int kgdb_register_nmi_console(void); 308 - extern int kgdb_unregister_nmi_console(void); 309 - #else 310 - static inline int kgdb_register_nmi_console(void) { return 0; } 311 - static inline int kgdb_unregister_nmi_console(void) { return 0; } 312 - #endif 313 314 extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops); 315 extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
··· 257 * hardware breakpoints. 258 * @correct_hw_break: Allow an architecture to specify how to correct the 259 * hardware debug registers. 260 */ 261 struct kgdb_arch { 262 unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE]; ··· 270 void (*disable_hw_break)(struct pt_regs *regs); 271 void (*remove_all_hw_break)(void); 272 void (*correct_hw_break)(void); 273 }; 274 275 /** ··· 305 extern const struct kgdb_arch arch_kgdb_ops; 306 307 extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs); 308 309 extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops); 310 extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
-6
include/linux/serdev.h
··· 84 struct serdev_controller_ops { 85 ssize_t (*write_buf)(struct serdev_controller *, const u8 *, size_t); 86 void (*write_flush)(struct serdev_controller *); 87 - int (*write_room)(struct serdev_controller *); 88 int (*open)(struct serdev_controller *); 89 void (*close)(struct serdev_controller *); 90 void (*set_flow_control)(struct serdev_controller *, bool); ··· 211 void serdev_device_write_wakeup(struct serdev_device *); 212 ssize_t serdev_device_write(struct serdev_device *, const u8 *, size_t, long); 213 void serdev_device_write_flush(struct serdev_device *); 214 - int serdev_device_write_room(struct serdev_device *); 215 216 /* 217 * serdev device driver functions ··· 271 return -ENODEV; 272 } 273 static inline void serdev_device_write_flush(struct serdev_device *sdev) {} 274 - static inline int serdev_device_write_room(struct serdev_device *sdev) 275 - { 276 - return 0; 277 - } 278 279 #define serdev_device_driver_register(x) 280 #define serdev_device_driver_unregister(x)
··· 84 struct serdev_controller_ops { 85 ssize_t (*write_buf)(struct serdev_controller *, const u8 *, size_t); 86 void (*write_flush)(struct serdev_controller *); 87 int (*open)(struct serdev_controller *); 88 void (*close)(struct serdev_controller *); 89 void (*set_flow_control)(struct serdev_controller *, bool); ··· 212 void serdev_device_write_wakeup(struct serdev_device *); 213 ssize_t serdev_device_write(struct serdev_device *, const u8 *, size_t, long); 214 void serdev_device_write_flush(struct serdev_device *); 215 216 /* 217 * serdev device driver functions ··· 273 return -ENODEV; 274 } 275 static inline void serdev_device_write_flush(struct serdev_device *sdev) {} 276 277 #define serdev_device_driver_register(x) 278 #define serdev_device_driver_unregister(x)
+27 -26
include/linux/tty.h
··· 239 240 struct list_head tty_files; 241 242 - #define N_TTY_BUF_SIZE 4096 243 struct work_struct SAK_work; 244 } __randomize_layout; 245 ··· 250 }; 251 252 /** 253 - * DOC: TTY Struct Flags 254 * 255 * These bits are used in the :c:member:`tty_struct.flags` field. 256 * ··· 259 * tty->write. Thus, you must use the inline functions set_bit() and 260 * clear_bit() to make things atomic. 261 * 262 - * TTY_THROTTLED 263 * Driver input is throttled. The ldisc should call 264 * :c:member:`tty_driver.unthrottle()` in order to resume reception when 265 * it is ready to process more data (at threshold min). 266 * 267 - * TTY_IO_ERROR 268 * If set, causes all subsequent userspace read/write calls on the tty to 269 * fail, returning -%EIO. (May be no ldisc too.) 270 * 271 - * TTY_OTHER_CLOSED 272 * Device is a pty and the other side has closed. 273 * 274 - * TTY_EXCLUSIVE 275 * Exclusive open mode (a single opener). 276 * 277 - * TTY_DO_WRITE_WAKEUP 278 * If set, causes the driver to call the 279 * :c:member:`tty_ldisc_ops.write_wakeup()` method in order to resume 280 * transmission when it can accept more data to transmit. 281 * 282 - * TTY_LDISC_OPEN 283 * Indicates that a line discipline is open. For debugging purposes only. 284 * 285 - * TTY_PTY_LOCK 286 * A flag private to pty code to implement %TIOCSPTLCK/%TIOCGPTLCK logic. 287 * 288 - * TTY_NO_WRITE_SPLIT 289 * Prevent driver from splitting up writes into smaller chunks (preserve 290 * write boundaries to driver). 291 * 292 - * TTY_HUPPED 293 * The TTY was hung up. This is set post :c:member:`tty_driver.hangup()`. 294 * 295 - * TTY_HUPPING 296 * The TTY is in the process of hanging up to abort potential readers. 297 * 298 - * TTY_LDISC_CHANGING 299 * Line discipline for this TTY is being changed. I/O should not block 300 * when this is set. Use tty_io_nonblock() to check. 301 * 302 - * TTY_LDISC_HALTED 303 * Line discipline for this TTY was stopped. No work should be queued to 304 * this ldisc. 305 */ 306 - #define TTY_THROTTLED 0 307 - #define TTY_IO_ERROR 1 308 - #define TTY_OTHER_CLOSED 2 309 - #define TTY_EXCLUSIVE 3 310 - #define TTY_DO_WRITE_WAKEUP 5 311 - #define TTY_LDISC_OPEN 11 312 - #define TTY_PTY_LOCK 16 313 - #define TTY_NO_WRITE_SPLIT 17 314 - #define TTY_HUPPED 18 315 - #define TTY_HUPPING 19 316 - #define TTY_LDISC_CHANGING 20 317 - #define TTY_LDISC_HALTED 22 318 319 static inline bool tty_io_nonblock(struct tty_struct *tty, struct file *file) 320 {
··· 239 240 struct list_head tty_files; 241 242 struct work_struct SAK_work; 243 } __randomize_layout; 244 ··· 251 }; 252 253 /** 254 + * enum tty_struct_flags - TTY Struct Flags 255 * 256 * These bits are used in the :c:member:`tty_struct.flags` field. 257 * ··· 260 * tty->write. Thus, you must use the inline functions set_bit() and 261 * clear_bit() to make things atomic. 262 * 263 + * @TTY_THROTTLED: 264 * Driver input is throttled. The ldisc should call 265 * :c:member:`tty_driver.unthrottle()` in order to resume reception when 266 * it is ready to process more data (at threshold min). 267 * 268 + * @TTY_IO_ERROR: 269 * If set, causes all subsequent userspace read/write calls on the tty to 270 * fail, returning -%EIO. (May be no ldisc too.) 271 * 272 + * @TTY_OTHER_CLOSED: 273 * Device is a pty and the other side has closed. 274 * 275 + * @TTY_EXCLUSIVE: 276 * Exclusive open mode (a single opener). 277 * 278 + * @TTY_DO_WRITE_WAKEUP: 279 * If set, causes the driver to call the 280 * :c:member:`tty_ldisc_ops.write_wakeup()` method in order to resume 281 * transmission when it can accept more data to transmit. 282 * 283 + * @TTY_LDISC_OPEN: 284 * Indicates that a line discipline is open. For debugging purposes only. 285 * 286 + * @TTY_PTY_LOCK: 287 * A flag private to pty code to implement %TIOCSPTLCK/%TIOCGPTLCK logic. 288 * 289 + * @TTY_NO_WRITE_SPLIT: 290 * Prevent driver from splitting up writes into smaller chunks (preserve 291 * write boundaries to driver). 292 * 293 + * @TTY_HUPPED: 294 * The TTY was hung up. This is set post :c:member:`tty_driver.hangup()`. 295 * 296 + * @TTY_HUPPING: 297 * The TTY is in the process of hanging up to abort potential readers. 298 * 299 + * @TTY_LDISC_CHANGING: 300 * Line discipline for this TTY is being changed. I/O should not block 301 * when this is set. Use tty_io_nonblock() to check. 302 * 303 + * @TTY_LDISC_HALTED: 304 * Line discipline for this TTY was stopped. No work should be queued to 305 * this ldisc. 306 */ 307 + enum tty_struct_flags { 308 + TTY_THROTTLED, 309 + TTY_IO_ERROR, 310 + TTY_OTHER_CLOSED, 311 + TTY_EXCLUSIVE, 312 + TTY_DO_WRITE_WAKEUP, 313 + TTY_LDISC_OPEN, 314 + TTY_PTY_LOCK, 315 + TTY_NO_WRITE_SPLIT, 316 + TTY_HUPPED, 317 + TTY_HUPPING, 318 + TTY_LDISC_CHANGING, 319 + TTY_LDISC_HALTED, 320 + }; 321 322 static inline bool tty_io_nonblock(struct tty_struct *tty, struct file *file) 323 {
+97 -83
include/linux/tty_driver.h
··· 17 struct serial_struct; 18 19 /** 20 * struct tty_operations -- interface between driver and tty 21 * 22 * @lookup: ``struct tty_struct *()(struct tty_driver *self, struct file *, ··· 500 * @major: major /dev device number (zero for autoassignment) 501 * @minor_start: the first minor /dev device number 502 * @num: number of devices allocated 503 - * @type: type of tty driver (%TTY_DRIVER_TYPE_) 504 - * @subtype: subtype of tty driver (%SYSTEM_TYPE_, %PTY_TYPE_, %SERIAL_TYPE_) 505 * @init_termios: termios to set to each tty initially (e.g. %tty_std_termios) 506 * @flags: tty driver flags (%TTY_DRIVER_) 507 * @proc_entry: proc fs entry, used internally ··· 533 int major; 534 int minor_start; 535 unsigned int num; 536 - short type; 537 - short subtype; 538 struct ktermios init_termios; 539 unsigned long flags; 540 struct proc_dir_entry *proc_entry; ··· 564 565 void tty_driver_kref_put(struct tty_driver *driver); 566 567 - /* Use TTY_DRIVER_* flags below */ 568 #define tty_alloc_driver(lines, flags) \ 569 __tty_alloc_driver(lines, THIS_MODULE, flags) 570 ··· 585 { 586 driver->ops = op; 587 } 588 - 589 - /** 590 - * DOC: TTY Driver Flags 591 - * 592 - * TTY_DRIVER_RESET_TERMIOS 593 - * Requests the tty layer to reset the termios setting when the last 594 - * process has closed the device. Used for PTYs, in particular. 595 - * 596 - * TTY_DRIVER_REAL_RAW 597 - * Indicates that the driver will guarantee not to set any special 598 - * character handling flags if this is set for the tty: 599 - * 600 - * ``(IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR || !INPCK)`` 601 - * 602 - * That is, if there is no reason for the driver to 603 - * send notifications of parity and break characters up to the line 604 - * driver, it won't do so. This allows the line driver to optimize for 605 - * this case if this flag is set. (Note that there is also a promise, if 606 - * the above case is true, not to signal overruns, either.) 607 - * 608 - * TTY_DRIVER_DYNAMIC_DEV 609 - * The individual tty devices need to be registered with a call to 610 - * tty_register_device() when the device is found in the system and 611 - * unregistered with a call to tty_unregister_device() so the devices will 612 - * be show up properly in sysfs. If not set, all &tty_driver.num entries 613 - * will be created by the tty core in sysfs when tty_register_driver() is 614 - * called. This is to be used by drivers that have tty devices that can 615 - * appear and disappear while the main tty driver is registered with the 616 - * tty core. 617 - * 618 - * TTY_DRIVER_DEVPTS_MEM 619 - * Don't use the standard arrays (&tty_driver.ttys and 620 - * &tty_driver.termios), instead use dynamic memory keyed through the 621 - * devpts filesystem. This is only applicable to the PTY driver. 622 - * 623 - * TTY_DRIVER_HARDWARE_BREAK 624 - * Hardware handles break signals. Pass the requested timeout to the 625 - * &tty_operations.break_ctl instead of using a simple on/off interface. 626 - * 627 - * TTY_DRIVER_DYNAMIC_ALLOC 628 - * Do not allocate structures which are needed per line for this driver 629 - * (&tty_driver.ports) as it would waste memory. The driver will take 630 - * care. This is only applicable to the PTY driver. 631 - * 632 - * TTY_DRIVER_UNNUMBERED_NODE 633 - * Do not create numbered ``/dev`` nodes. For example, create 634 - * ``/dev/ttyprintk`` and not ``/dev/ttyprintk0``. Applicable only when a 635 - * driver for a single tty device is being allocated. 636 - */ 637 - #define TTY_DRIVER_INSTALLED 0x0001 638 - #define TTY_DRIVER_RESET_TERMIOS 0x0002 639 - #define TTY_DRIVER_REAL_RAW 0x0004 640 - #define TTY_DRIVER_DYNAMIC_DEV 0x0008 641 - #define TTY_DRIVER_DEVPTS_MEM 0x0010 642 - #define TTY_DRIVER_HARDWARE_BREAK 0x0020 643 - #define TTY_DRIVER_DYNAMIC_ALLOC 0x0040 644 - #define TTY_DRIVER_UNNUMBERED_NODE 0x0080 645 - 646 - /* tty driver types */ 647 - #define TTY_DRIVER_TYPE_SYSTEM 0x0001 648 - #define TTY_DRIVER_TYPE_CONSOLE 0x0002 649 - #define TTY_DRIVER_TYPE_SERIAL 0x0003 650 - #define TTY_DRIVER_TYPE_PTY 0x0004 651 - #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */ 652 - #define TTY_DRIVER_TYPE_SYSCONS 0x0006 653 - 654 - /* system subtypes (magic, used by tty_io.c) */ 655 - #define SYSTEM_TYPE_TTY 0x0001 656 - #define SYSTEM_TYPE_CONSOLE 0x0002 657 - #define SYSTEM_TYPE_SYSCONS 0x0003 658 - #define SYSTEM_TYPE_SYSPTMX 0x0004 659 - 660 - /* pty subtypes (magic, used by tty_io.c) */ 661 - #define PTY_TYPE_MASTER 0x0001 662 - #define PTY_TYPE_SLAVE 0x0002 663 - 664 - /* serial subtype definitions */ 665 - #define SERIAL_TYPE_NORMAL 1 666 667 int tty_register_driver(struct tty_driver *driver); 668 void tty_unregister_driver(struct tty_driver *driver);
··· 17 struct serial_struct; 18 19 /** 20 + * enum tty_driver_flag -- TTY Driver Flags 21 + * 22 + * These are flags passed to tty_alloc_driver(). 23 + * 24 + * @TTY_DRIVER_INSTALLED: 25 + * Whether this driver was succesfully installed. This is a tty internal 26 + * flag. Do not touch. 27 + * 28 + * @TTY_DRIVER_RESET_TERMIOS: 29 + * Requests the tty layer to reset the termios setting when the last 30 + * process has closed the device. Used for PTYs, in particular. 31 + * 32 + * @TTY_DRIVER_REAL_RAW: 33 + * Indicates that the driver will guarantee not to set any special 34 + * character handling flags if this is set for the tty: 35 + * 36 + * ``(IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR || !INPCK)`` 37 + * 38 + * That is, if there is no reason for the driver to 39 + * send notifications of parity and break characters up to the line 40 + * driver, it won't do so. This allows the line driver to optimize for 41 + * this case if this flag is set. (Note that there is also a promise, if 42 + * the above case is true, not to signal overruns, either.) 43 + * 44 + * @TTY_DRIVER_DYNAMIC_DEV: 45 + * The individual tty devices need to be registered with a call to 46 + * tty_register_device() when the device is found in the system and 47 + * unregistered with a call to tty_unregister_device() so the devices will 48 + * be show up properly in sysfs. If not set, all &tty_driver.num entries 49 + * will be created by the tty core in sysfs when tty_register_driver() is 50 + * called. This is to be used by drivers that have tty devices that can 51 + * appear and disappear while the main tty driver is registered with the 52 + * tty core. 53 + * 54 + * @TTY_DRIVER_DEVPTS_MEM: 55 + * Don't use the standard arrays (&tty_driver.ttys and 56 + * &tty_driver.termios), instead use dynamic memory keyed through the 57 + * devpts filesystem. This is only applicable to the PTY driver. 58 + * 59 + * @TTY_DRIVER_HARDWARE_BREAK: 60 + * Hardware handles break signals. Pass the requested timeout to the 61 + * &tty_operations.break_ctl instead of using a simple on/off interface. 62 + * 63 + * @TTY_DRIVER_DYNAMIC_ALLOC: 64 + * Do not allocate structures which are needed per line for this driver 65 + * (&tty_driver.ports) as it would waste memory. The driver will take 66 + * care. This is only applicable to the PTY driver. 67 + * 68 + * @TTY_DRIVER_UNNUMBERED_NODE: 69 + * Do not create numbered ``/dev`` nodes. For example, create 70 + * ``/dev/ttyprintk`` and not ``/dev/ttyprintk0``. Applicable only when a 71 + * driver for a single tty device is being allocated. 72 + */ 73 + enum tty_driver_flag { 74 + TTY_DRIVER_INSTALLED = BIT(0), 75 + TTY_DRIVER_RESET_TERMIOS = BIT(1), 76 + TTY_DRIVER_REAL_RAW = BIT(2), 77 + TTY_DRIVER_DYNAMIC_DEV = BIT(3), 78 + TTY_DRIVER_DEVPTS_MEM = BIT(4), 79 + TTY_DRIVER_HARDWARE_BREAK = BIT(5), 80 + TTY_DRIVER_DYNAMIC_ALLOC = BIT(6), 81 + TTY_DRIVER_UNNUMBERED_NODE = BIT(7), 82 + }; 83 + 84 + enum tty_driver_type { 85 + TTY_DRIVER_TYPE_SYSTEM, 86 + TTY_DRIVER_TYPE_CONSOLE, 87 + TTY_DRIVER_TYPE_SERIAL, 88 + TTY_DRIVER_TYPE_PTY, 89 + TTY_DRIVER_TYPE_SCC, 90 + TTY_DRIVER_TYPE_SYSCONS, 91 + }; 92 + 93 + enum tty_driver_subtype { 94 + SYSTEM_TYPE_TTY = 1, 95 + SYSTEM_TYPE_CONSOLE, 96 + SYSTEM_TYPE_SYSCONS, 97 + SYSTEM_TYPE_SYSPTMX, 98 + 99 + PTY_TYPE_MASTER = 1, 100 + PTY_TYPE_SLAVE, 101 + 102 + SERIAL_TYPE_NORMAL = 1, 103 + }; 104 + 105 + /** 106 * struct tty_operations -- interface between driver and tty 107 * 108 * @lookup: ``struct tty_struct *()(struct tty_driver *self, struct file *, ··· 414 * @major: major /dev device number (zero for autoassignment) 415 * @minor_start: the first minor /dev device number 416 * @num: number of devices allocated 417 + * @type: type of tty driver (enum tty_driver_type) 418 + * @subtype: subtype of tty driver (enum tty_driver_subtype) 419 * @init_termios: termios to set to each tty initially (e.g. %tty_std_termios) 420 * @flags: tty driver flags (%TTY_DRIVER_) 421 * @proc_entry: proc fs entry, used internally ··· 447 int major; 448 int minor_start; 449 unsigned int num; 450 + enum tty_driver_type type; 451 + enum tty_driver_subtype subtype; 452 struct ktermios init_termios; 453 unsigned long flags; 454 struct proc_dir_entry *proc_entry; ··· 478 479 void tty_driver_kref_put(struct tty_driver *driver); 480 481 + /** 482 + * tty_alloc_driver - allocate tty driver 483 + * @lines: count of lines this driver can handle at most 484 + * @flags: some of enum tty_driver_flag, will be set in driver->flags 485 + * 486 + * Returns: struct tty_driver or a PTR-encoded error (use IS_ERR() and friends). 487 + */ 488 #define tty_alloc_driver(lines, flags) \ 489 __tty_alloc_driver(lines, THIS_MODULE, flags) 490 ··· 493 { 494 driver->ops = op; 495 } 496 497 int tty_register_driver(struct tty_driver *driver); 498 void tty_unregister_driver(struct tty_driver *driver);
-1
include/linux/tty_ldisc.h
··· 39 int ldsem_down_read(struct ld_semaphore *sem, long timeout); 40 int ldsem_down_read_trylock(struct ld_semaphore *sem); 41 int ldsem_down_write(struct ld_semaphore *sem, long timeout); 42 - int ldsem_down_write_trylock(struct ld_semaphore *sem); 43 void ldsem_up_read(struct ld_semaphore *sem); 44 void ldsem_up_write(struct ld_semaphore *sem); 45
··· 39 int ldsem_down_read(struct ld_semaphore *sem, long timeout); 40 int ldsem_down_read_trylock(struct ld_semaphore *sem); 41 int ldsem_down_write(struct ld_semaphore *sem, long timeout); 42 void ldsem_up_read(struct ld_semaphore *sem); 43 void ldsem_up_write(struct ld_semaphore *sem); 44
+3 -11
kernel/debug/debug_core.c
··· 837 { 838 struct kgdb_state kgdb_var; 839 struct kgdb_state *ks = &kgdb_var; 840 - int ret = 0; 841 - 842 - if (arch_kgdb_ops.enable_nmi) 843 - arch_kgdb_ops.enable_nmi(0); 844 /* 845 * Avoid entering the debugger if we were triggered due to an oops 846 * but panic_timeout indicates the system should automatically ··· 854 ks->linux_regs = regs; 855 856 if (kgdb_reenter_check(ks)) 857 - goto out; /* Ouch, double exception ! */ 858 if (kgdb_info[ks->cpu].enter_kgdb != 0) 859 - goto out; 860 861 - ret = kgdb_cpu_enter(ks, regs, DCPU_WANT_MASTER); 862 - out: 863 - if (arch_kgdb_ops.enable_nmi) 864 - arch_kgdb_ops.enable_nmi(1); 865 - return ret; 866 } 867 NOKPROBE_SYMBOL(kgdb_handle_exception); 868
··· 837 { 838 struct kgdb_state kgdb_var; 839 struct kgdb_state *ks = &kgdb_var; 840 /* 841 * Avoid entering the debugger if we were triggered due to an oops 842 * but panic_timeout indicates the system should automatically ··· 858 ks->linux_regs = regs; 859 860 if (kgdb_reenter_check(ks)) 861 + return 0; /* Ouch, double exception ! */ 862 if (kgdb_info[ks->cpu].enter_kgdb != 0) 863 + return 0; 864 865 + return kgdb_cpu_enter(ks, regs, DCPU_WANT_MASTER); 866 } 867 NOKPROBE_SYMBOL(kgdb_handle_exception); 868
-37
kernel/debug/kdb/kdb_main.c
··· 25 #include <linux/smp.h> 26 #include <linux/utsname.h> 27 #include <linux/vmalloc.h> 28 - #include <linux/atomic.h> 29 #include <linux/moduleparam.h> 30 #include <linux/mm.h> 31 #include <linux/init.h> ··· 2086 return 0; 2087 } 2088 #endif /* CONFIG_PRINTK */ 2089 - 2090 - /* Make sure we balance enable/disable calls, must disable first. */ 2091 - static atomic_t kdb_nmi_disabled; 2092 - 2093 - static int kdb_disable_nmi(int argc, const char *argv[]) 2094 - { 2095 - if (atomic_read(&kdb_nmi_disabled)) 2096 - return 0; 2097 - atomic_set(&kdb_nmi_disabled, 1); 2098 - arch_kgdb_ops.enable_nmi(0); 2099 - return 0; 2100 - } 2101 - 2102 - static int kdb_param_enable_nmi(const char *val, const struct kernel_param *kp) 2103 - { 2104 - if (!atomic_add_unless(&kdb_nmi_disabled, -1, 0)) 2105 - return -EINVAL; 2106 - arch_kgdb_ops.enable_nmi(1); 2107 - return 0; 2108 - } 2109 - 2110 - static const struct kernel_param_ops kdb_param_ops_enable_nmi = { 2111 - .set = kdb_param_enable_nmi, 2112 - }; 2113 - module_param_cb(enable_nmi, &kdb_param_ops_enable_nmi, NULL, 0600); 2114 - 2115 /* 2116 * kdb_cpu - This function implements the 'cpu' command. 2117 * cpu [<cpunum>] ··· 2777 }, 2778 }; 2779 2780 - static kdbtab_t nmicmd = { 2781 - .name = "disable_nmi", 2782 - .func = kdb_disable_nmi, 2783 - .usage = "", 2784 - .help = "Disable NMI entry to KDB", 2785 - .flags = KDB_ENABLE_ALWAYS_SAFE, 2786 - }; 2787 - 2788 /* Initialize the kdb command table. */ 2789 static void __init kdb_inittab(void) 2790 { 2791 kdb_register_table(maintab, ARRAY_SIZE(maintab)); 2792 - if (arch_kgdb_ops.enable_nmi) 2793 - kdb_register_table(&nmicmd, 1); 2794 } 2795 2796 /* Execute any commands defined in kdb_cmds. */
··· 25 #include <linux/smp.h> 26 #include <linux/utsname.h> 27 #include <linux/vmalloc.h> 28 #include <linux/moduleparam.h> 29 #include <linux/mm.h> 30 #include <linux/init.h> ··· 2087 return 0; 2088 } 2089 #endif /* CONFIG_PRINTK */ 2090 /* 2091 * kdb_cpu - This function implements the 'cpu' command. 2092 * cpu [<cpunum>] ··· 2804 }, 2805 }; 2806 2807 /* Initialize the kdb command table. */ 2808 static void __init kdb_inittab(void) 2809 { 2810 kdb_register_table(maintab, ARRAY_SIZE(maintab)); 2811 } 2812 2813 /* Execute any commands defined in kdb_cmds. */