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

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

Pull tty/serial driver updates from Greg KH:
"Here's the big tty/serial driver update for 3.19-rc1.

There are a number of TTY core changes/fixes in here from Peter Hurley
that have all been teted in linux-next for a long time now. There are
also the normal serial driver updates as well, full details in the
changelog below"

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

+4762 -1603
+30
Documentation/devicetree/bindings/serial/bcm63xx-uart.txt
··· 1 + * BCM63xx UART 2 + 3 + Required properties: 4 + 5 + - compatible: "brcm,bcm6345-uart" 6 + 7 + - reg: The base address of the UART register bank. 8 + 9 + - interrupts: A single interrupt specifier. 10 + 11 + - clocks: Clock driving the hardware; used to figure out the baud rate 12 + divisor. 13 + 14 + Example: 15 + 16 + uart0: serial@14e00520 { 17 + compatible = "brcm,bcm6345-uart"; 18 + reg = <0x14e00520 0x18>; 19 + interrupt-parent = <&periph_intc>; 20 + interrupts = <2>; 21 + clocks = <&periph_clk>; 22 + }; 23 + 24 + clocks { 25 + periph_clk: periph_clk@0 { 26 + compatible = "fixed-clock"; 27 + #clock-cells = <0>; 28 + clock-frequency = <54000000>; 29 + }; 30 + };
+9 -1
Documentation/devicetree/bindings/serial/fsl-mxs-auart.txt
··· 11 11 - dma-names: "rx" for RX channel, "tx" for TX channel. 12 12 13 13 Optional properties: 14 - - fsl,uart-has-rtscts : Indicate the UART has RTS and CTS lines, 14 + - fsl,uart-has-rtscts : Indicate the UART has RTS and CTS lines 15 + for hardware flow control, 15 16 it also means you enable the DMA support for this UART. 17 + - {rts,cts,dtr,dsr,rng,dcd}-gpios: specify a GPIO for RTS/CTS/DTR/DSR/RI/DCD 18 + line respectively. It will use specified PIO instead of the peripheral 19 + function pin for the USART feature. 20 + If unsure, don't specify this property. 16 21 17 22 Example: 18 23 auart0: serial@8006a000 { ··· 26 21 interrupts = <112>; 27 22 dmas = <&dma_apbx 8>, <&dma_apbx 9>; 28 23 dma-names = "rx", "tx"; 24 + cts-gpios = <&gpio1 15 GPIO_ACTIVE_LOW>; 25 + dsr-gpios = <&gpio1 16 GPIO_ACTIVE_LOW>; 26 + dcd-gpios = <&gpio1 17 GPIO_ACTIVE_LOW>; 29 27 }; 30 28 31 29 Note: Each auart port should have an alias correctly numbered in "aliases"
+1
Documentation/devicetree/bindings/serial/of-serial.txt
··· 10 10 - "ns16850" 11 11 - "nvidia,tegra20-uart" 12 12 - "nxp,lpc3220-uart" 13 + - "ralink,rt2880-uart" 13 14 - "ibm,qpace-nwp-serial" 14 15 - "altr,16550-FIFO32" 15 16 - "altr,16550-FIFO64"
+16 -4
Documentation/devicetree/bindings/serial/pl011.txt
··· 6 6 - interrupts: exactly one interrupt specifier 7 7 8 8 Optional properties: 9 - - pinctrl: When present, must have one state named "default", 9 + - pinctrl: 10 + When present, must have one state named "default", 10 11 and may contain a second name named "sleep". The former 11 12 state sets up pins for ordinary operation whereas 12 13 the latter state will put the associated pins to sleep 13 14 when the UART is unused 14 - - clocks: When present, the first clock listed must correspond to 15 + - clocks: 16 + When present, the first clock listed must correspond to 15 17 the clock named UARTCLK on the IP block, i.e. the clock 16 18 to the external serial line, whereas the second clock 17 19 must correspond to the PCLK clocking the internal logic 18 20 of the block. Just listing one clock (the first one) is 19 21 deprecated. 20 - - clocks-names: When present, the first clock listed must be named 22 + - clocks-names: 23 + When present, the first clock listed must be named 21 24 "uartclk" and the second clock listed must be named 22 25 "apb_pclk" 23 - - dmas: When present, may have one or two dma channels. 26 + - dmas: 27 + When present, may have one or two dma channels. 24 28 The first one must be named "rx", the second one 25 29 must be named "tx". 30 + - auto-poll: 31 + Enables polling when using RX DMA. 32 + - poll-rate-ms: 33 + Rate at which poll occurs when auto-poll is set, 34 + default 100ms. 35 + - poll-timeout-ms: 36 + Poll timeout when auto-poll is set, default 37 + 3000ms. 26 38 27 39 See also bindings/arm/primecell.txt 28 40
+44 -19
Documentation/devicetree/bindings/serial/qcom,msm-uartdm.txt
··· 27 27 - dmas: Should contain dma specifiers for transmit and receive channels 28 28 - dma-names: Should contain "tx" for transmit and "rx" for receive channels 29 29 30 + Note: Aliases may be defined to ensure the correct ordering of the UARTs. 31 + The alias serialN will result in the UART being assigned port N. If any 32 + serialN alias exists, then an alias must exist for each enabled UART. The 33 + serialN aliases should be in a .dts file instead of in a .dtsi file. 34 + 30 35 Examples: 31 36 32 - A uartdm v1.4 device with dma capabilities. 37 + - A uartdm v1.4 device with dma capabilities. 33 38 34 - serial@f991e000 { 35 - compatible = "qcom,msm-uartdm-v1.4", "qcom,msm-uartdm"; 36 - reg = <0xf991e000 0x1000>; 37 - interrupts = <0 108 0x0>; 38 - clocks = <&blsp1_uart2_apps_cxc>, <&blsp1_ahb_cxc>; 39 - clock-names = "core", "iface"; 40 - dmas = <&dma0 0>, <&dma0 1>; 41 - dma-names = "tx", "rx"; 42 - }; 39 + serial@f991e000 { 40 + compatible = "qcom,msm-uartdm-v1.4", "qcom,msm-uartdm"; 41 + reg = <0xf991e000 0x1000>; 42 + interrupts = <0 108 0x0>; 43 + clocks = <&blsp1_uart2_apps_cxc>, <&blsp1_ahb_cxc>; 44 + clock-names = "core", "iface"; 45 + dmas = <&dma0 0>, <&dma0 1>; 46 + dma-names = "tx", "rx"; 47 + }; 43 48 44 - A uartdm v1.3 device without dma capabilities and part of a GSBI complex. 49 + - A uartdm v1.3 device without dma capabilities and part of a GSBI complex. 45 50 46 - serial@19c40000 { 47 - compatible = "qcom,msm-uartdm-v1.3", "qcom,msm-uartdm"; 48 - reg = <0x19c40000 0x1000>, 49 - <0x19c00000 0x1000>; 50 - interrupts = <0 195 0x0>; 51 - clocks = <&gsbi5_uart_cxc>, <&gsbi5_ahb_cxc>; 52 - clock-names = "core", "iface"; 53 - }; 51 + serial@19c40000 { 52 + compatible = "qcom,msm-uartdm-v1.3", "qcom,msm-uartdm"; 53 + reg = <0x19c40000 0x1000>, 54 + <0x19c00000 0x1000>; 55 + interrupts = <0 195 0x0>; 56 + clocks = <&gsbi5_uart_cxc>, <&gsbi5_ahb_cxc>; 57 + clock-names = "core", "iface"; 58 + }; 59 + 60 + - serialN alias. 61 + 62 + aliases { 63 + serial0 = &uarta; 64 + serial1 = &uartc; 65 + serial2 = &uartb; 66 + }; 67 + 68 + uarta: serial@12490000 { 69 + status = "ok"; 70 + }; 71 + 72 + uartb: serial@16340000 { 73 + status = "ok"; 74 + }; 75 + 76 + uartc: serial@1a240000 { 77 + status = "ok"; 78 + };
+7 -2
Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
··· 4 4 5 5 - compatible: Must contain one of the following: 6 6 7 - - "renesas,scifa-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFA compatible UART. 8 - - "renesas,scifb-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFB compatible UART. 7 + - "renesas,scif-r7s72100" for R7S72100 (RZ/A1H) SCIF compatible UART. 9 8 - "renesas,scifa-r8a73a4" for R8A73A4 (R-Mobile APE6) SCIFA compatible UART. 10 9 - "renesas,scifb-r8a73a4" for R8A73A4 (R-Mobile APE6) SCIFB compatible UART. 11 10 - "renesas,scifa-r8a7740" for R8A7740 (R-Mobile A1) SCIFA compatible UART. ··· 19 20 - "renesas,scifa-r8a7791" for R8A7791 (R-Car M2) SCIFA compatible UART. 20 21 - "renesas,scifb-r8a7791" for R8A7791 (R-Car M2) SCIFB compatible UART. 21 22 - "renesas,hscif-r8a7791" for R8A7791 (R-Car M2) HSCIF compatible UART. 23 + - "renesas,scif-r8a7794" for R8A7794 (R-Car E2) SCIF compatible UART. 24 + - "renesas,scifa-r8a7794" for R8A7794 (R-Car E2) SCIFA compatible UART. 25 + - "renesas,scifb-r8a7794" for R8A7794 (R-Car E2) SCIFB compatible UART. 26 + - "renesas,hscif-r8a7794" for R8A7794 (R-Car E2) HSCIF compatible UART. 27 + - "renesas,scifa-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFA compatible UART. 28 + - "renesas,scifb-sh73a0" for SH73A0 (SH-Mobile AG5) SCIFB compatible UART. 22 29 - "renesas,scif" for generic SCIF compatible UART. 23 30 - "renesas,scifa" for generic SCIFA compatible UART. 24 31 - "renesas,scifb" for generic SCIFB compatible UART.
+15 -1
Documentation/devicetree/bindings/serial/sirf-uart.txt
··· 1 1 * CSR SiRFprimaII/atlasVI Universal Synchronous Asynchronous Receiver/Transmitter * 2 2 3 3 Required properties: 4 - - compatible : Should be "sirf,prima2-uart" or "sirf, prima2-usp-uart" 4 + - compatible : Should be "sirf,prima2-uart", "sirf, prima2-usp-uart", 5 + "sirf,marco-uart" or "sirf,marco-bt-uart" which means 6 + uart located in BT module and used for BT. 5 7 - reg : Offset and length of the register set for the device 6 8 - interrupts : Should contain uart interrupt 7 9 - fifosize : Should define hardware rx/tx fifo size ··· 33 31 rts-gpios = <&gpio 15 0>; 34 32 cts-gpios = <&gpio 46 0>; 35 33 }; 34 + 35 + for uart use in BT module, 36 + uart6: uart@11000000 { 37 + cell-index = <6>; 38 + compatible = "sirf,marco-bt-uart", "sirf,marco-uart"; 39 + reg = <0x11000000 0x1000>; 40 + interrupts = <0 100 0>; 41 + clocks = <&clks 138>, <&clks 140>, <&clks 141>; 42 + clock-names = "uart", "general", "noc"; 43 + fifosize = <128>; 44 + status = "disabled"; 45 + }
+4 -2
Documentation/serial/driver
··· 59 59 access to the info->tmpbuf bouncebuffer used for port writes. 60 60 61 61 The port_sem semaphore is used to protect against ports being added/ 62 - removed or reconfigured at inappropriate times. 62 + removed or reconfigured at inappropriate times. Since v2.6.27, this 63 + semaphore has been the 'mutex' member of the tty_port struct, and 64 + commonly referred to as the port mutex (or port->mutex). 63 65 64 66 65 67 uart_ops ··· 250 248 Other flags may be used (eg, xon/xoff characters) if your 251 249 hardware supports hardware "soft" flow control. 252 250 253 - Locking: none. 251 + Locking: caller holds port->mutex 254 252 Interrupts: caller dependent. 255 253 This call must not sleep 256 254
+6
MAINTAINERS
··· 8026 8026 F: Documentation/serial/rocket.txt 8027 8027 F: drivers/tty/rocket* 8028 8028 8029 + ROCKETPORT EXPRESS/INFINITY DRIVER 8030 + M: Kevin Cernekee <cernekee@gmail.com> 8031 + L: linux-serial@vger.kernel.org 8032 + S: Odd Fixes 8033 + F: drivers/tty/serial/rp2.* 8034 + 8029 8035 ROSE NETWORK LAYER 8030 8036 M: Ralf Baechle <ralf@linux-mips.org> 8031 8037 L: linux-hams@vger.kernel.org
+3 -4
arch/blackfin/include/asm/bfin_serial.h
··· 9 9 #ifndef __BFIN_ASM_SERIAL_H__ 10 10 #define __BFIN_ASM_SERIAL_H__ 11 11 12 + #include <linux/circ_buf.h> 12 13 #include <linux/serial_core.h> 13 14 #include <linux/spinlock.h> 15 + #include <linux/timer.h> 16 + #include <linux/workqueue.h> 14 17 #include <mach/anomaly.h> 15 18 #include <mach/bfin_serial.h> 16 19 ··· 27 24 # define CONFIG_SERIAL_BFIN_CTSRTS 28 25 # endif 29 26 #endif 30 - 31 - struct circ_buf; 32 - struct timer_list; 33 - struct work_struct; 34 27 35 28 struct bfin_serial_port { 36 29 struct uart_port port;
+5 -1
arch/um/drivers/line.c
··· 632 632 int fd = winch->fd; 633 633 int err; 634 634 char c; 635 + struct pid *pgrp; 635 636 636 637 if (fd != -1) { 637 638 err = generic_read(fd, &c, NULL); ··· 658 657 if (line != NULL) { 659 658 chan_window_size(line, &tty->winsize.ws_row, 660 659 &tty->winsize.ws_col); 661 - kill_pgrp(tty->pgrp, SIGWINCH, 1); 660 + pgrp = tty_get_pgrp(tty); 661 + if (pgrp) 662 + kill_pgrp(pgrp, SIGWINCH, 1); 663 + put_pid(pgrp); 662 664 } 663 665 tty_kref_put(tty); 664 666 }
+10
drivers/parport/parport_serial.c
··· 64 64 timedia_9079c, 65 65 wch_ch353_1s1p, 66 66 wch_ch353_2s1p, 67 + wch_ch382_2s1p, 67 68 sunix_2s1p, 68 69 }; 69 70 ··· 152 151 /* timedia_9079c */ { 1, { { 2, 3 }, } }, 153 152 /* wch_ch353_1s1p*/ { 1, { { 1, -1}, } }, 154 153 /* wch_ch353_2s1p*/ { 1, { { 2, -1}, } }, 154 + /* wch_ch382_2s1p*/ { 1, { { 2, -1}, } }, 155 155 /* sunix_2s1p */ { 1, { { 3, -1 }, } }, 156 156 }; 157 157 ··· 259 257 /* WCH CARDS */ 260 258 { 0x4348, 0x5053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, wch_ch353_1s1p}, 261 259 { 0x4348, 0x7053, 0x4348, 0x3253, 0, 0, wch_ch353_2s1p}, 260 + { 0x1c00, 0x3250, 0x1c00, 0x3250, 0, 0, wch_ch382_2s1p}, 262 261 263 262 /* 264 263 * More SUNIX variations. At least one of these has part number ··· 496 493 .num_ports = 2, 497 494 .base_baud = 115200, 498 495 .uart_offset = 8, 496 + }, 497 + [wch_ch382_2s1p] = { 498 + .flags = FL_BASE0, 499 + .num_ports = 2, 500 + .base_baud = 115200, 501 + .uart_offset = 8, 502 + .first_offset = 0xC0, 499 503 }, 500 504 [sunix_2s1p] = { 501 505 .flags = FL_BASE0|FL_BASE_BARS,
+2 -2
drivers/tty/ehv_bytechan.c
··· 309 309 * handle for udbg. 310 310 */ 311 311 if (stdout_bc != CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE) 312 - pr_warning("ehv-bc: udbg handle %u is not the stdout handle\n", 313 - CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE); 312 + pr_warn("ehv-bc: udbg handle %u is not the stdout handle\n", 313 + CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE); 314 314 #endif 315 315 316 316 /* add_preferred_console() must be called before register_console(),
+3 -3
drivers/tty/goldfish.c
··· 155 155 156 156 static int goldfish_tty_console_setup(struct console *co, char *options) 157 157 { 158 - if ((unsigned)co->index > goldfish_tty_line_count) 158 + if ((unsigned)co->index >= goldfish_tty_line_count) 159 159 return -ENODEV; 160 - if (goldfish_ttys[co->index].base == 0) 160 + if (!goldfish_ttys[co->index].base) 161 161 return -ENODEV; 162 162 return 0; 163 163 } ··· 317 317 unregister_console(&qtty->console); 318 318 tty_unregister_device(goldfish_tty_driver, pdev->id); 319 319 iounmap(qtty->base); 320 - qtty->base = 0; 320 + qtty->base = NULL; 321 321 free_irq(qtty->irq, pdev); 322 322 goldfish_tty_current_line_count--; 323 323 if (goldfish_tty_current_line_count == 0)
+1 -1
drivers/tty/hvc/hvcs.c
··· 1575 1575 */ 1576 1576 rc = driver_create_file(&(hvcs_vio_driver.driver), &driver_attr_rescan); 1577 1577 if (rc) 1578 - pr_warning(KERN_ERR "HVCS: Failed to create rescan file (err %d)\n", rc); 1578 + pr_warning("HVCS: Failed to create rescan file (err %d)\n", rc); 1579 1579 1580 1580 return 0; 1581 1581 }
+1 -2
drivers/tty/hvc/hvsi_lib.c
··· 405 405 hvsi_send_close(pv); 406 406 } 407 407 408 - if (pv->tty) 409 - tty_kref_put(pv->tty); 408 + tty_kref_put(pv->tty); 410 409 pv->tty = NULL; 411 410 } 412 411
+6 -6
drivers/tty/ipwireless/hardware.c
··· 378 378 /* 379 379 * transform bits from aa.bbb.ccc to ccc.bbb.aa 380 380 */ 381 - ret |= tmp & 0xc0 >> 6; 382 - ret |= tmp & 0x38 >> 1; 383 - ret |= tmp & 0x07 << 5; 381 + ret |= (tmp & 0xc0) >> 6; 382 + ret |= (tmp & 0x38) >> 1; 383 + ret |= (tmp & 0x07) << 5; 384 384 *data = ret & 0xff; 385 385 #endif 386 386 } ··· 393 393 /* 394 394 * transform bits from ccc.bbb.aa to aa.bbb.ccc 395 395 */ 396 - ret |= tmp & 0xe0 >> 5; 397 - ret |= tmp & 0x1c << 1; 398 - ret |= tmp & 0x03 << 6; 396 + ret |= (tmp & 0xe0) >> 5; 397 + ret |= (tmp & 0x1c) << 1; 398 + ret |= (tmp & 0x03) << 6; 399 399 *data = ret & 0xff; 400 400 #endif 401 401 }
+7 -7
drivers/tty/isicom.c
··· 249 249 spin_unlock_irqrestore(&card->card_lock, card->flags); 250 250 msleep(10); 251 251 } 252 - pr_warning("Failed to lock Card (0x%lx)\n", card->base); 252 + pr_warn("Failed to lock Card (0x%lx)\n", card->base); 253 253 254 254 return 0; /* Failed to acquire the card! */ 255 255 } ··· 378 378 char *name, const char *routine) 379 379 { 380 380 if (!port) { 381 - pr_warning("Warning: bad isicom magic for dev %s in %s.\n", 382 - name, routine); 381 + pr_warn("Warning: bad isicom magic for dev %s in %s\n", 382 + name, routine); 383 383 return 1; 384 384 } 385 385 if (port->magic != ISICOM_MAGIC) { 386 - pr_warning("Warning: NULL isicom port for dev %s in %s.\n", 387 - name, routine); 386 + pr_warn("Warning: NULL isicom port for dev %s in %s\n", 387 + name, routine); 388 388 return 1; 389 389 } 390 390 ··· 546 546 byte_count = header & 0xff; 547 547 548 548 if (channel + 1 > card->port_count) { 549 - pr_warning("%s(0x%lx): %d(channel) > port_count.\n", 550 - __func__, base, channel+1); 549 + pr_warn("%s(0x%lx): %d(channel) > port_count\n", 550 + __func__, base, channel + 1); 551 551 outw(0x0000, base+0x04); /* enable interrupts */ 552 552 spin_unlock(&card->card_lock); 553 553 return IRQ_HANDLED;
+38 -45
drivers/tty/n_tty.c
··· 321 321 322 322 static inline void put_tty_queue(unsigned char c, struct n_tty_data *ldata) 323 323 { 324 - *read_buf_addr(ldata, ldata->read_head++) = c; 324 + *read_buf_addr(ldata, ldata->read_head) = c; 325 + ldata->read_head++; 325 326 } 326 327 327 328 /** ··· 352 351 { 353 352 unsigned long flags; 354 353 355 - spin_lock_irqsave(&tty->ctrl_lock, flags); 356 354 if (tty->link->packet) { 355 + spin_lock_irqsave(&tty->ctrl_lock, flags); 357 356 tty->ctrl_status |= TIOCPKT_FLUSHREAD; 357 + spin_unlock_irqrestore(&tty->ctrl_lock, flags); 358 358 if (waitqueue_active(&tty->link->read_wait)) 359 359 wake_up_interruptible(&tty->link->read_wait); 360 360 } 361 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 362 361 } 363 362 364 363 /** ··· 2129 2128 int minimum, time; 2130 2129 ssize_t retval = 0; 2131 2130 long timeout; 2132 - unsigned long flags; 2133 2131 int packet; 2134 2132 2135 2133 c = job_control(tty, file); ··· 2174 2174 unsigned char cs; 2175 2175 if (b != buf) 2176 2176 break; 2177 - spin_lock_irqsave(&tty->link->ctrl_lock, flags); 2177 + spin_lock_irq(&tty->link->ctrl_lock); 2178 2178 cs = tty->link->ctrl_status; 2179 2179 tty->link->ctrl_status = 0; 2180 - spin_unlock_irqrestore(&tty->link->ctrl_lock, flags); 2180 + spin_unlock_irq(&tty->link->ctrl_lock); 2181 2181 if (tty_put_user(tty, cs, b++)) { 2182 2182 retval = -EFAULT; 2183 2183 b--; ··· 2193 2193 2194 2194 if (!input_available_p(tty, 0)) { 2195 2195 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 2196 - up_read(&tty->termios_rwsem); 2197 - tty_flush_to_ldisc(tty); 2198 - down_read(&tty->termios_rwsem); 2199 - if (!input_available_p(tty, 0)) { 2200 - retval = -EIO; 2201 - break; 2202 - } 2203 - } else { 2204 - if (tty_hung_up_p(file)) 2205 - break; 2206 - if (!timeout) 2207 - break; 2208 - if (file->f_flags & O_NONBLOCK) { 2209 - retval = -EAGAIN; 2210 - break; 2211 - } 2212 - if (signal_pending(current)) { 2213 - retval = -ERESTARTSYS; 2214 - break; 2215 - } 2216 - n_tty_set_room(tty); 2217 - up_read(&tty->termios_rwsem); 2218 - 2219 - timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, 2220 - timeout); 2221 - 2222 - down_read(&tty->termios_rwsem); 2223 - continue; 2224 - } 2225 - } 2226 - 2227 - /* Deal with packet mode. */ 2228 - if (packet && b == buf) { 2229 - if (tty_put_user(tty, TIOCPKT_DATA, b++)) { 2230 - retval = -EFAULT; 2231 - b--; 2196 + retval = -EIO; 2232 2197 break; 2233 2198 } 2234 - nr--; 2199 + if (tty_hung_up_p(file)) 2200 + break; 2201 + if (!timeout) 2202 + break; 2203 + if (file->f_flags & O_NONBLOCK) { 2204 + retval = -EAGAIN; 2205 + break; 2206 + } 2207 + if (signal_pending(current)) { 2208 + retval = -ERESTARTSYS; 2209 + break; 2210 + } 2211 + n_tty_set_room(tty); 2212 + up_read(&tty->termios_rwsem); 2213 + 2214 + timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, 2215 + timeout); 2216 + 2217 + down_read(&tty->termios_rwsem); 2218 + continue; 2235 2219 } 2236 2220 2237 2221 if (ldata->icanon && !L_EXTPROC(tty)) { ··· 2227 2243 break; 2228 2244 } else { 2229 2245 int uncopied; 2230 - /* The copy function takes the read lock and handles 2231 - locking internally for this case */ 2246 + 2247 + /* Deal with packet mode. */ 2248 + if (packet && b == buf) { 2249 + if (tty_put_user(tty, TIOCPKT_DATA, b++)) { 2250 + retval = -EFAULT; 2251 + b--; 2252 + break; 2253 + } 2254 + nr--; 2255 + } 2256 + 2232 2257 uncopied = copy_from_read_buf(tty, &b, &nr); 2233 2258 uncopied += copy_from_read_buf(tty, &b, &nr); 2234 2259 if (uncopied) {
+52 -35
drivers/tty/pty.c
··· 47 47 set_bit(TTY_IO_ERROR, &tty->flags); 48 48 wake_up_interruptible(&tty->read_wait); 49 49 wake_up_interruptible(&tty->write_wait); 50 + spin_lock_irq(&tty->ctrl_lock); 50 51 tty->packet = 0; 52 + spin_unlock_irq(&tty->ctrl_lock); 51 53 /* Review - krefs on tty_link ?? */ 52 54 if (!tty->link) 53 55 return; 56 + tty_flush_to_ldisc(tty->link); 54 57 set_bit(TTY_OTHER_CLOSED, &tty->link->flags); 55 58 wake_up_interruptible(&tty->link->read_wait); 56 59 wake_up_interruptible(&tty->link->write_wait); ··· 67 64 mutex_unlock(&devpts_mutex); 68 65 } 69 66 #endif 70 - tty_unlock(tty); 71 67 tty_vhangup(tty->link); 72 - tty_lock(tty); 73 68 } 74 69 } 75 70 ··· 179 178 /* Set the packet mode on a pty */ 180 179 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg) 181 180 { 182 - unsigned long flags; 183 181 int pktmode; 184 182 185 183 if (get_user(pktmode, arg)) 186 184 return -EFAULT; 187 185 188 - spin_lock_irqsave(&tty->ctrl_lock, flags); 186 + spin_lock_irq(&tty->ctrl_lock); 189 187 if (pktmode) { 190 188 if (!tty->packet) { 191 - tty->packet = 1; 192 189 tty->link->ctrl_status = 0; 190 + smp_mb(); 191 + tty->packet = 1; 193 192 } 194 193 } else 195 194 tty->packet = 0; 196 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 195 + spin_unlock_irq(&tty->ctrl_lock); 197 196 198 197 return 0; 199 198 } ··· 208 207 /* Send a signal to the slave */ 209 208 static int pty_signal(struct tty_struct *tty, int sig) 210 209 { 211 - unsigned long flags; 212 210 struct pid *pgrp; 213 211 214 212 if (tty->link) { 215 - spin_lock_irqsave(&tty->link->ctrl_lock, flags); 216 - pgrp = get_pid(tty->link->pgrp); 217 - spin_unlock_irqrestore(&tty->link->ctrl_lock, flags); 218 - 219 - kill_pgrp(pgrp, sig, 1); 213 + pgrp = tty_get_pgrp(tty->link); 214 + if (pgrp) 215 + kill_pgrp(pgrp, sig, 1); 220 216 put_pid(pgrp); 221 217 } 222 218 return 0; ··· 222 224 static void pty_flush_buffer(struct tty_struct *tty) 223 225 { 224 226 struct tty_struct *to = tty->link; 225 - unsigned long flags; 226 227 227 228 if (!to) 228 229 return; 229 230 /* tty_buffer_flush(to); FIXME */ 230 231 if (to->packet) { 231 - spin_lock_irqsave(&tty->ctrl_lock, flags); 232 + spin_lock_irq(&tty->ctrl_lock); 232 233 tty->ctrl_status |= TIOCPKT_FLUSHWRITE; 233 234 wake_up_interruptible(&to->read_wait); 234 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 235 + spin_unlock_irq(&tty->ctrl_lock); 235 236 } 236 237 } 237 238 ··· 259 262 static void pty_set_termios(struct tty_struct *tty, 260 263 struct ktermios *old_termios) 261 264 { 265 + /* See if packet mode change of state. */ 266 + if (tty->link && tty->link->packet) { 267 + int extproc = (old_termios->c_lflag & EXTPROC) | 268 + (tty->termios.c_lflag & EXTPROC); 269 + int old_flow = ((old_termios->c_iflag & IXON) && 270 + (old_termios->c_cc[VSTOP] == '\023') && 271 + (old_termios->c_cc[VSTART] == '\021')); 272 + int new_flow = (I_IXON(tty) && 273 + STOP_CHAR(tty) == '\023' && 274 + START_CHAR(tty) == '\021'); 275 + if ((old_flow != new_flow) || extproc) { 276 + spin_lock_irq(&tty->ctrl_lock); 277 + if (old_flow != new_flow) { 278 + tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP); 279 + if (new_flow) 280 + tty->ctrl_status |= TIOCPKT_DOSTOP; 281 + else 282 + tty->ctrl_status |= TIOCPKT_NOSTOP; 283 + } 284 + if (extproc) 285 + tty->ctrl_status |= TIOCPKT_IOCTL; 286 + spin_unlock_irq(&tty->ctrl_lock); 287 + wake_up_interruptible(&tty->link->read_wait); 288 + } 289 + } 290 + 262 291 tty->termios.c_cflag &= ~(CSIZE | PARENB); 263 292 tty->termios.c_cflag |= (CS8 | CREAD); 264 293 } ··· 301 278 static int pty_resize(struct tty_struct *tty, struct winsize *ws) 302 279 { 303 280 struct pid *pgrp, *rpgrp; 304 - unsigned long flags; 305 281 struct tty_struct *pty = tty->link; 306 282 307 283 /* For a PTY we need to lock the tty side */ ··· 308 286 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) 309 287 goto done; 310 288 311 - /* Get the PID values and reference them so we can 312 - avoid holding the tty ctrl lock while sending signals. 313 - We need to lock these individually however. */ 314 - 315 - spin_lock_irqsave(&tty->ctrl_lock, flags); 316 - pgrp = get_pid(tty->pgrp); 317 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 318 - 319 - spin_lock_irqsave(&pty->ctrl_lock, flags); 320 - rpgrp = get_pid(pty->pgrp); 321 - spin_unlock_irqrestore(&pty->ctrl_lock, flags); 289 + /* Signal the foreground process group of both ptys */ 290 + pgrp = tty_get_pgrp(tty); 291 + rpgrp = tty_get_pgrp(pty); 322 292 323 293 if (pgrp) 324 294 kill_pgrp(pgrp, SIGWINCH, 1); ··· 341 327 { 342 328 unsigned long flags; 343 329 344 - spin_lock_irqsave(&tty->ctrl_lock, flags); 345 330 if (tty->link && tty->link->packet) { 331 + spin_lock_irqsave(&tty->ctrl_lock, flags); 346 332 tty->ctrl_status &= ~TIOCPKT_STOP; 347 333 tty->ctrl_status |= TIOCPKT_START; 334 + spin_unlock_irqrestore(&tty->ctrl_lock, flags); 348 335 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN); 349 336 } 350 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 351 337 } 352 338 353 339 static void pty_stop(struct tty_struct *tty) 354 340 { 355 341 unsigned long flags; 356 342 357 - spin_lock_irqsave(&tty->ctrl_lock, flags); 358 343 if (tty->link && tty->link->packet) { 344 + spin_lock_irqsave(&tty->ctrl_lock, flags); 359 345 tty->ctrl_status &= ~TIOCPKT_START; 360 346 tty->ctrl_status |= TIOCPKT_STOP; 347 + spin_unlock_irqrestore(&tty->ctrl_lock, flags); 361 348 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN); 362 349 } 363 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 364 350 } 365 351 366 352 /** ··· 382 368 int idx = tty->index; 383 369 int retval = -ENOMEM; 384 370 371 + /* Opening the slave first has always returned -EIO */ 372 + if (driver->subtype != PTY_TYPE_MASTER) 373 + return -EIO; 374 + 385 375 ports[0] = kmalloc(sizeof **ports, GFP_KERNEL); 386 376 ports[1] = kmalloc(sizeof **ports, GFP_KERNEL); 387 377 if (!ports[0] || !ports[1]) ··· 397 379 o_tty = alloc_tty_struct(driver->other, idx); 398 380 if (!o_tty) 399 381 goto err_put_module; 382 + 383 + tty_set_lock_subclass(o_tty); 400 384 401 385 if (legacy) { 402 386 /* We always use new tty termios data so we can do this ··· 424 404 * Everything allocated ... set up the o_tty structure. 425 405 */ 426 406 tty_driver_kref_get(driver->other); 427 - if (driver->subtype == PTY_TYPE_MASTER) 428 - o_tty->count++; 429 407 /* Establish the links in both directions */ 430 408 tty->link = o_tty; 431 409 o_tty->link = tty; ··· 435 417 436 418 tty_driver_kref_get(driver); 437 419 tty->count++; 420 + o_tty->count++; 438 421 return 0; 439 422 err_free_termios: 440 423 if (legacy) ··· 508 489 .flush_buffer = pty_flush_buffer, 509 490 .chars_in_buffer = pty_chars_in_buffer, 510 491 .unthrottle = pty_unthrottle, 511 - .set_termios = pty_set_termios, 512 492 .ioctl = pty_bsd_ioctl, 513 493 .cleanup = pty_cleanup, 514 494 .resize = pty_resize, ··· 684 666 .flush_buffer = pty_flush_buffer, 685 667 .chars_in_buffer = pty_chars_in_buffer, 686 668 .unthrottle = pty_unthrottle, 687 - .set_termios = pty_set_termios, 688 669 .ioctl = pty_unix98_ioctl, 689 670 .resize = pty_resize, 690 671 .shutdown = pty_unix98_shutdown,
+8 -1
drivers/tty/serial/8250/8250.h
··· 16 16 #include <linux/dmaengine.h> 17 17 18 18 struct uart_8250_dma { 19 + int (*tx_dma)(struct uart_8250_port *p); 20 + int (*rx_dma)(struct uart_8250_port *p, unsigned int iir); 21 + 19 22 /* Filter function */ 20 23 dma_filter_fn fn; 21 24 ··· 44 41 size_t tx_size; 45 42 46 43 unsigned char tx_running:1; 44 + unsigned char tx_err: 1; 45 + unsigned char rx_running:1; 47 46 }; 48 47 49 48 struct old_serial_port { ··· 56 51 unsigned int flags; 57 52 unsigned char hub6; 58 53 unsigned char io_type; 59 - unsigned char *iomem_base; 54 + unsigned char __iomem *iomem_base; 60 55 unsigned short iomem_reg_shift; 61 56 unsigned long irqflags; 62 57 }; ··· 119 114 } 120 115 121 116 struct uart_8250_port *serial8250_get_port(int line); 117 + void serial8250_rpm_get(struct uart_8250_port *p); 118 + void serial8250_rpm_put(struct uart_8250_port *p); 122 119 123 120 #if defined(__alpha__) && !defined(CONFIG_PCI) 124 121 /*
+56 -56
drivers/tty/serial/8250/8250_core.c
··· 541 541 } 542 542 EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos); 543 543 544 - static void serial8250_rpm_get(struct uart_8250_port *p) 544 + void serial8250_rpm_get(struct uart_8250_port *p) 545 545 { 546 546 if (!(p->capabilities & UART_CAP_RPM)) 547 547 return; 548 548 pm_runtime_get_sync(p->port.dev); 549 549 } 550 + EXPORT_SYMBOL_GPL(serial8250_rpm_get); 550 551 551 - static void serial8250_rpm_put(struct uart_8250_port *p) 552 + void serial8250_rpm_put(struct uart_8250_port *p) 552 553 { 553 554 if (!(p->capabilities & UART_CAP_RPM)) 554 555 return; 555 556 pm_runtime_mark_last_busy(p->port.dev); 556 557 pm_runtime_put_autosuspend(p->port.dev); 557 558 } 559 + EXPORT_SYMBOL_GPL(serial8250_rpm_put); 558 560 559 561 /* 560 - * This two wrapper ensure, that enable_runtime_pm_tx() can be called more than 562 + * These two wrappers ensure that enable_runtime_pm_tx() can be called more than 561 563 * once and disable_runtime_pm_tx() will still disable RPM because the fifo is 562 564 * empty and the HW can idle again. 563 565 */ ··· 597 595 */ 598 596 static void serial8250_set_sleep(struct uart_8250_port *p, int sleep) 599 597 { 598 + unsigned char lcr = 0, efr = 0; 600 599 /* 601 600 * Exar UARTs have a SLEEP register that enables or disables 602 601 * each UART to enter sleep mode separately. On the XR17V35x the ··· 614 611 615 612 if (p->capabilities & UART_CAP_SLEEP) { 616 613 if (p->capabilities & UART_CAP_EFR) { 614 + lcr = serial_in(p, UART_LCR); 615 + efr = serial_in(p, UART_EFR); 617 616 serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 618 617 serial_out(p, UART_EFR, UART_EFR_ECB); 619 618 serial_out(p, UART_LCR, 0); ··· 623 618 serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); 624 619 if (p->capabilities & UART_CAP_EFR) { 625 620 serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 626 - serial_out(p, UART_EFR, 0); 627 - serial_out(p, UART_LCR, 0); 621 + serial_out(p, UART_EFR, efr); 622 + serial_out(p, UART_LCR, lcr); 628 623 } 629 624 } 630 625 out: ··· 1355 1350 struct uart_8250_port *up = up_to_u8250p(port); 1356 1351 1357 1352 serial8250_rpm_get_tx(up); 1358 - if (up->dma && !serial8250_tx_dma(up)) { 1353 + if (up->dma && !up->dma->tx_dma(up)) { 1359 1354 return; 1360 1355 } else if (!(up->ier & UART_IER_THRI)) { 1361 1356 up->ier |= UART_IER_THRI; ··· 1400 1395 serial_port_out(port, UART_IER, up->ier); 1401 1396 1402 1397 serial8250_rpm_put(up); 1398 + } 1399 + 1400 + static void serial8250_disable_ms(struct uart_port *port) 1401 + { 1402 + struct uart_8250_port *up = 1403 + container_of(port, struct uart_8250_port, port); 1404 + 1405 + /* no MSR capabilities */ 1406 + if (up->bugs & UART_BUG_NOMSR) 1407 + return; 1408 + 1409 + up->ier &= ~UART_IER_MSI; 1410 + serial_port_out(port, UART_IER, up->ier); 1403 1411 } 1404 1412 1405 1413 static void serial8250_enable_ms(struct uart_port *port) ··· 1501 1483 1502 1484 ignore_char: 1503 1485 lsr = serial_in(up, UART_LSR); 1504 - } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0)); 1486 + } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (--max_count > 0)); 1505 1487 spin_unlock(&port->lock); 1506 1488 tty_flip_buffer_push(&port->state->port); 1507 1489 spin_lock(&port->lock); ··· 1550 1532 DEBUG_INTR("THRE..."); 1551 1533 1552 1534 /* 1553 - * With RPM enabled, we have to wait once the FIFO is empty before the 1535 + * With RPM enabled, we have to wait until the FIFO is empty before the 1554 1536 * HW can go idle. So we get here once again with empty FIFO and disable 1555 1537 * the interrupt and RPM in __stop_tx() 1556 1538 */ ··· 1606 1588 1607 1589 if (status & (UART_LSR_DR | UART_LSR_BI)) { 1608 1590 if (up->dma) 1609 - dma_err = serial8250_rx_dma(up, iir); 1591 + dma_err = up->dma->rx_dma(up, iir); 1610 1592 1611 1593 if (!up->dma || dma_err) 1612 1594 status = serial8250_rx_chars(up, status); 1613 1595 } 1614 1596 serial8250_modem_status(up); 1615 - if (!up->dma && (status & UART_LSR_THRE)) 1597 + if ((!up->dma || (up->dma && up->dma->tx_err)) && 1598 + (status & UART_LSR_THRE)) 1616 1599 serial8250_tx_chars(up); 1617 1600 1618 1601 spin_unlock_irqrestore(&port->lock, flags); ··· 2622 2603 } 2623 2604 2624 2605 static void 2625 - serial8250_set_ldisc(struct uart_port *port, int new) 2606 + serial8250_set_ldisc(struct uart_port *port, struct ktermios *termios) 2626 2607 { 2627 - if (new == N_PPS) { 2608 + if (termios->c_line == N_PPS) { 2628 2609 port->flags |= UPF_HARDPPS_CD; 2610 + spin_lock_irq(&port->lock); 2629 2611 serial8250_enable_ms(port); 2630 - } else 2612 + spin_unlock_irq(&port->lock); 2613 + } else { 2631 2614 port->flags &= ~UPF_HARDPPS_CD; 2615 + if (!UART_ENABLE_MS(port, termios->c_cflag)) { 2616 + spin_lock_irq(&port->lock); 2617 + serial8250_disable_ms(port); 2618 + spin_unlock_irq(&port->lock); 2619 + } 2620 + } 2632 2621 } 2633 2622 2634 2623 ··· 2661 2634 2662 2635 static unsigned int serial8250_port_size(struct uart_8250_port *pt) 2663 2636 { 2664 - if (pt->port.iotype == UPIO_AU) 2637 + if (pt->port.iotype == UPIO_AU) { 2638 + if (pt->port.type == PORT_RT2880) 2639 + return 0x100; 2665 2640 return 0x1000; 2641 + } 2666 2642 if (is_omap1_8250(pt)) 2667 2643 return 0x16 << pt->port.regshift; 2668 2644 ··· 3005 2975 return 0; 3006 2976 } 3007 2977 3008 - static int serial8250_ioctl(struct uart_port *port, unsigned int cmd, 3009 - unsigned long arg) 3010 - { 3011 - struct uart_8250_port *up = 3012 - container_of(port, struct uart_8250_port, port); 3013 - int ret; 3014 - struct serial_rs485 rs485_config; 3015 - 3016 - if (!up->rs485_config) 3017 - return -ENOIOCTLCMD; 3018 - 3019 - switch (cmd) { 3020 - case TIOCSRS485: 3021 - if (copy_from_user(&rs485_config, (void __user *)arg, 3022 - sizeof(rs485_config))) 3023 - return -EFAULT; 3024 - 3025 - ret = up->rs485_config(up, &rs485_config); 3026 - if (ret) 3027 - return ret; 3028 - 3029 - memcpy(&up->rs485, &rs485_config, sizeof(rs485_config)); 3030 - 3031 - return 0; 3032 - case TIOCGRS485: 3033 - if (copy_to_user((void __user *)arg, &up->rs485, 3034 - sizeof(up->rs485))) 3035 - return -EFAULT; 3036 - return 0; 3037 - default: 3038 - break; 3039 - } 3040 - 3041 - return -ENOIOCTLCMD; 3042 - } 3043 - 3044 2978 static const char * 3045 2979 serial8250_type(struct uart_port *port) 3046 2980 { ··· 3036 3042 .request_port = serial8250_request_port, 3037 3043 .config_port = serial8250_config_port, 3038 3044 .verify_port = serial8250_verify_port, 3039 - .ioctl = serial8250_ioctl, 3040 3045 #ifdef CONFIG_CONSOLE_POLL 3041 3046 .poll_get_char = serial8250_get_poll_char, 3042 3047 .poll_put_char = serial8250_put_poll_char, ··· 3191 3198 3192 3199 serial8250_rpm_get(up); 3193 3200 3194 - if (port->sysrq || oops_in_progress) 3201 + if (port->sysrq) 3202 + locked = 0; 3203 + else if (oops_in_progress) 3195 3204 locked = spin_trylock_irqsave(&port->lock, flags); 3196 3205 else 3197 3206 spin_lock_irqsave(&port->lock, flags); ··· 3232 3237 serial8250_rpm_put(up); 3233 3238 } 3234 3239 3235 - static int __init serial8250_console_setup(struct console *co, char *options) 3240 + static int serial8250_console_setup(struct console *co, char *options) 3236 3241 { 3237 3242 struct uart_port *port; 3238 3243 int baud = 9600; ··· 3580 3585 uart->port.fifosize = up->port.fifosize; 3581 3586 uart->tx_loadsz = up->tx_loadsz; 3582 3587 uart->capabilities = up->capabilities; 3583 - uart->rs485_config = up->rs485_config; 3584 - uart->rs485 = up->rs485; 3585 3588 uart->port.throttle = up->port.throttle; 3586 3589 uart->port.unthrottle = up->port.unthrottle; 3590 + uart->port.rs485_config = up->port.rs485_config; 3591 + uart->port.rs485 = up->port.rs485; 3587 3592 3588 3593 /* Take tx_loadsz from fifosize if it wasn't set separately */ 3589 3594 if (uart->port.fifosize && !uart->tx_loadsz) ··· 3618 3623 uart->dl_read = up->dl_read; 3619 3624 if (up->dl_write) 3620 3625 uart->dl_write = up->dl_write; 3621 - if (up->dma) 3626 + if (up->dma) { 3622 3627 uart->dma = up->dma; 3628 + if (!uart->dma->tx_dma) 3629 + uart->dma->tx_dma = serial8250_tx_dma; 3630 + if (!uart->dma->rx_dma) 3631 + uart->dma->rx_dma = serial8250_rx_dma; 3632 + } 3623 3633 3624 3634 if (serial8250_isa_config != NULL) 3625 3635 serial8250_isa_config(0, &uart->port,
+25 -14
drivers/tty/serial/8250/8250_dma.c
··· 21 21 struct uart_8250_dma *dma = p->dma; 22 22 struct circ_buf *xmit = &p->port.state->xmit; 23 23 unsigned long flags; 24 + int ret; 24 25 25 26 dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr, 26 27 UART_XMIT_SIZE, DMA_TO_DEVICE); ··· 37 36 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 38 37 uart_write_wakeup(&p->port); 39 38 40 - if (!uart_circ_empty(xmit) && !uart_tx_stopped(&p->port)) 41 - serial8250_tx_dma(p); 39 + ret = serial8250_tx_dma(p); 40 + if (ret) { 41 + p->ier |= UART_IER_THRI; 42 + serial_port_out(&p->port, UART_IER, p->ier); 43 + } 42 44 43 45 spin_unlock_irqrestore(&p->port.lock, flags); 44 46 } ··· 57 53 dma_sync_single_for_cpu(dma->rxchan->device->dev, dma->rx_addr, 58 54 dma->rx_size, DMA_FROM_DEVICE); 59 55 56 + dma->rx_running = 0; 60 57 dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); 61 58 dmaengine_terminate_all(dma->rxchan); 62 59 ··· 74 69 struct uart_8250_dma *dma = p->dma; 75 70 struct circ_buf *xmit = &p->port.state->xmit; 76 71 struct dma_async_tx_descriptor *desc; 72 + int ret; 77 73 78 74 if (uart_tx_stopped(&p->port) || dma->tx_running || 79 75 uart_circ_empty(xmit)) ··· 86 80 dma->tx_addr + xmit->tail, 87 81 dma->tx_size, DMA_MEM_TO_DEV, 88 82 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 89 - if (!desc) 90 - return -EBUSY; 83 + if (!desc) { 84 + ret = -EBUSY; 85 + goto err; 86 + } 91 87 92 88 dma->tx_running = 1; 93 - 94 89 desc->callback = __dma_tx_complete; 95 90 desc->callback_param = p; 96 91 ··· 101 94 UART_XMIT_SIZE, DMA_TO_DEVICE); 102 95 103 96 dma_async_issue_pending(dma->txchan); 104 - 97 + if (dma->tx_err) { 98 + dma->tx_err = 0; 99 + if (p->ier & UART_IER_THRI) { 100 + p->ier &= ~UART_IER_THRI; 101 + serial_out(p, UART_IER, p->ier); 102 + } 103 + } 105 104 return 0; 105 + err: 106 + dma->tx_err = 1; 107 + return ret; 106 108 } 107 - EXPORT_SYMBOL_GPL(serial8250_tx_dma); 108 109 109 110 int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir) 110 111 { 111 112 struct uart_8250_dma *dma = p->dma; 112 113 struct dma_async_tx_descriptor *desc; 113 - struct dma_tx_state state; 114 - int dma_status; 115 - 116 - dma_status = dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); 117 114 118 115 switch (iir & 0x3f) { 119 116 case UART_IIR_RLSI: ··· 128 117 * If RCVR FIFO trigger level was not reached, complete the 129 118 * transfer and let 8250_core copy the remaining data. 130 119 */ 131 - if (dma_status == DMA_IN_PROGRESS) { 120 + if (dma->rx_running) { 132 121 dmaengine_pause(dma->rxchan); 133 122 __dma_rx_complete(p); 134 123 } ··· 137 126 break; 138 127 } 139 128 140 - if (dma_status) 129 + if (dma->rx_running) 141 130 return 0; 142 131 143 132 desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr, ··· 146 135 if (!desc) 147 136 return -EBUSY; 148 137 138 + dma->rx_running = 1; 149 139 desc->callback = __dma_rx_complete; 150 140 desc->callback_param = p; 151 141 ··· 159 147 160 148 return 0; 161 149 } 162 - EXPORT_SYMBOL_GPL(serial8250_rx_dma); 163 150 164 151 int serial8250_request_dma(struct uart_8250_port *p) 165 152 {
+55 -14
drivers/tty/serial/8250/8250_dw.c
··· 122 122 return dw8250_modify_msr(p, offset, value); 123 123 } 124 124 125 - /* Read Back (rb) version to ensure register access ording. */ 126 - static void dw8250_serial_out_rb(struct uart_port *p, int offset, int value) 125 + #ifdef CONFIG_64BIT 126 + static unsigned int dw8250_serial_inq(struct uart_port *p, int offset) 127 127 { 128 - dw8250_serial_out(p, offset, value); 129 - dw8250_serial_in(p, UART_LCR); 128 + unsigned int value; 129 + 130 + value = (u8)__raw_readq(p->membase + (offset << p->regshift)); 131 + 132 + return dw8250_modify_msr(p, offset, value); 130 133 } 134 + 135 + static void dw8250_serial_outq(struct uart_port *p, int offset, int value) 136 + { 137 + struct dw8250_data *d = p->private_data; 138 + 139 + if (offset == UART_MCR) 140 + d->last_mcr = value; 141 + 142 + value &= 0xff; 143 + __raw_writeq(value, p->membase + (offset << p->regshift)); 144 + /* Read back to ensure register write ordering. */ 145 + __raw_readq(p->membase + (UART_LCR << p->regshift)); 146 + 147 + /* Make sure LCR write wasn't ignored */ 148 + if (offset == UART_LCR) { 149 + int tries = 1000; 150 + while (tries--) { 151 + unsigned int lcr = p->serial_in(p, UART_LCR); 152 + if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR)) 153 + return; 154 + dw8250_force_idle(p); 155 + __raw_writeq(value & 0xff, 156 + p->membase + (UART_LCR << p->regshift)); 157 + } 158 + dev_err(p->dev, "Couldn't set LCR to %d\n", value); 159 + } 160 + } 161 + #endif /* CONFIG_64BIT */ 131 162 132 163 static void dw8250_serial_out32(struct uart_port *p, int offset, int value) 133 164 { ··· 289 258 struct uart_8250_port *up = up_to_u8250p(p); 290 259 u32 val; 291 260 bool has_ucv = true; 261 + int id; 292 262 263 + #ifdef CONFIG_64BIT 293 264 if (of_device_is_compatible(np, "cavium,octeon-3860-uart")) { 294 - #ifdef __BIG_ENDIAN 295 - /* 296 - * Low order bits of these 64-bit registers, when 297 - * accessed as a byte, are 7 bytes further down in the 298 - * address space in big endian mode. 299 - */ 300 - p->membase += 7; 301 - #endif 302 - p->serial_out = dw8250_serial_out_rb; 265 + p->serial_in = dw8250_serial_inq; 266 + p->serial_out = dw8250_serial_outq; 303 267 p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE; 304 268 p->type = PORT_OCTEON; 305 269 data->usr_reg = 0x27; 306 270 has_ucv = false; 307 - } else if (!of_property_read_u32(np, "reg-io-width", &val)) { 271 + } else 272 + #endif 273 + if (!of_property_read_u32(np, "reg-io-width", &val)) { 308 274 switch (val) { 309 275 case 1: 310 276 break; ··· 318 290 if (has_ucv) 319 291 dw8250_setup_port(up); 320 292 293 + /* if we have a valid fifosize, try hooking up DMA here */ 294 + if (p->fifosize) { 295 + up->dma = &data->dma; 296 + 297 + up->dma->rxconf.src_maxburst = p->fifosize / 4; 298 + up->dma->txconf.dst_maxburst = p->fifosize / 4; 299 + } 300 + 321 301 if (!of_property_read_u32(np, "reg-shift", &val)) 322 302 p->regshift = val; 303 + 304 + /* get index of serial line, if found in DT aliases */ 305 + id = of_alias_get_id(np, "serial"); 306 + if (id >= 0) 307 + p->line = id; 323 308 324 309 /* clock got configured through clk api, all done */ 325 310 if (p->uartclk)
+1 -3
drivers/tty/serial/8250/8250_em.c
··· 102 102 } 103 103 104 104 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 105 - if (!priv) { 106 - dev_err(&pdev->dev, "unable to allocate private data\n"); 105 + if (!priv) 107 106 return -ENOMEM; 108 - } 109 107 110 108 priv->sclk = devm_clk_get(&pdev->dev, "sclk"); 111 109 if (IS_ERR(priv->sclk)) {
+5 -3
drivers/tty/serial/8250/8250_fintek.c
··· 89 89 return 0; 90 90 } 91 91 92 - static int fintek_8250_rs4850_config(struct uart_8250_port *uart, 92 + static int fintek_8250_rs485_config(struct uart_port *port, 93 93 struct serial_rs485 *rs485) 94 94 { 95 95 uint8_t config = 0; 96 - int index = fintek_8250_get_index(uart->port.iobase); 96 + int index = fintek_8250_get_index(port->iobase); 97 97 98 98 if (index < 0) 99 99 return -EINVAL; ··· 134 134 outb(config, DATA_PORT); 135 135 fintek_8250_exit_key(); 136 136 137 + port->rs485 = *rs485; 138 + 137 139 return 0; 138 140 } 139 141 ··· 168 166 uart.port.irq = pnp_irq(dev, 0); 169 167 uart.port.iobase = pnp_port_start(dev, 0); 170 168 uart.port.iotype = UPIO_PORT; 171 - uart.rs485_config = fintek_8250_rs4850_config; 169 + uart.port.rs485_config = fintek_8250_rs485_config; 172 170 173 171 uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; 174 172 if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE)
-4
drivers/tty/serial/8250/8250_hp300.c
··· 88 88 /* 89 89 * Parse the bootinfo to find descriptions for headless console and 90 90 * debug serial ports and register them with the 8250 driver. 91 - * This function should be called before serial_console_init() is called 92 - * to make sure the serial console will be available for use. IA-64 kernel 93 - * calls this function from setup_arch() after the EFI and ACPI tables have 94 - * been parsed. 95 91 */ 96 92 int __init hp300_setup_serial_console(void) 97 93 {
+2 -2
drivers/tty/serial/8250/8250_mtk.c
··· 74 74 /* Set to next lower baudrate supported */ 75 75 if ((baud == 500000) || (baud == 576000)) 76 76 baud = 460800; 77 - quot = DIV_ROUND_CLOSEST(port->uartclk, 4 * baud); 77 + quot = DIV_ROUND_UP(port->uartclk, 4 * baud); 78 78 } else { 79 79 serial_port_out(port, UART_MTK_HIGHS, 0x3); 80 80 81 81 /* Set to highest baudrate supported */ 82 82 if (baud >= 1152000) 83 83 baud = 921600; 84 - quot = (port->uartclk / (256 * baud)) + 1; 84 + quot = DIV_ROUND_UP(port->uartclk, 256 * baud); 85 85 } 86 86 87 87 /*
+1281
drivers/tty/serial/8250/8250_omap.c
··· 1 + /* 2 + * 8250-core based driver for the OMAP internal UART 3 + * 4 + * based on omap-serial.c, Copyright (C) 2010 Texas Instruments. 5 + * 6 + * Copyright (C) 2014 Sebastian Andrzej Siewior 7 + * 8 + */ 9 + 10 + #include <linux/device.h> 11 + #include <linux/io.h> 12 + #include <linux/module.h> 13 + #include <linux/serial_8250.h> 14 + #include <linux/serial_core.h> 15 + #include <linux/serial_reg.h> 16 + #include <linux/tty_flip.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/slab.h> 19 + #include <linux/of.h> 20 + #include <linux/of_gpio.h> 21 + #include <linux/of_irq.h> 22 + #include <linux/delay.h> 23 + #include <linux/pm_runtime.h> 24 + #include <linux/console.h> 25 + #include <linux/pm_qos.h> 26 + #include <linux/dma-mapping.h> 27 + 28 + #include "8250.h" 29 + 30 + #define DEFAULT_CLK_SPEED 48000000 31 + 32 + #define UART_ERRATA_i202_MDR1_ACCESS (1 << 0) 33 + #define OMAP_UART_WER_HAS_TX_WAKEUP (1 << 1) 34 + #define OMAP_DMA_TX_KICK (1 << 2) 35 + 36 + #define OMAP_UART_FCR_RX_TRIG 6 37 + #define OMAP_UART_FCR_TX_TRIG 4 38 + 39 + /* SCR register bitmasks */ 40 + #define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7) 41 + #define OMAP_UART_SCR_TX_TRIG_GRANU1_MASK (1 << 6) 42 + #define OMAP_UART_SCR_TX_EMPTY (1 << 3) 43 + #define OMAP_UART_SCR_DMAMODE_MASK (3 << 1) 44 + #define OMAP_UART_SCR_DMAMODE_1 (1 << 1) 45 + #define OMAP_UART_SCR_DMAMODE_CTL (1 << 0) 46 + 47 + /* MVR register bitmasks */ 48 + #define OMAP_UART_MVR_SCHEME_SHIFT 30 49 + #define OMAP_UART_LEGACY_MVR_MAJ_MASK 0xf0 50 + #define OMAP_UART_LEGACY_MVR_MAJ_SHIFT 4 51 + #define OMAP_UART_LEGACY_MVR_MIN_MASK 0x0f 52 + #define OMAP_UART_MVR_MAJ_MASK 0x700 53 + #define OMAP_UART_MVR_MAJ_SHIFT 8 54 + #define OMAP_UART_MVR_MIN_MASK 0x3f 55 + 56 + #define UART_TI752_TLR_TX 0 57 + #define UART_TI752_TLR_RX 4 58 + 59 + #define TRIGGER_TLR_MASK(x) ((x & 0x3c) >> 2) 60 + #define TRIGGER_FCR_MASK(x) (x & 3) 61 + 62 + /* Enable XON/XOFF flow control on output */ 63 + #define OMAP_UART_SW_TX 0x08 64 + /* Enable XON/XOFF flow control on input */ 65 + #define OMAP_UART_SW_RX 0x02 66 + 67 + #define OMAP_UART_WER_MOD_WKUP 0x7f 68 + #define OMAP_UART_TX_WAKEUP_EN (1 << 7) 69 + 70 + #define TX_TRIGGER 1 71 + #define RX_TRIGGER 48 72 + 73 + #define OMAP_UART_TCR_RESTORE(x) ((x / 4) << 4) 74 + #define OMAP_UART_TCR_HALT(x) ((x / 4) << 0) 75 + 76 + #define UART_BUILD_REVISION(x, y) (((x) << 8) | (y)) 77 + 78 + #define OMAP_UART_REV_46 0x0406 79 + #define OMAP_UART_REV_52 0x0502 80 + #define OMAP_UART_REV_63 0x0603 81 + 82 + struct omap8250_priv { 83 + int line; 84 + u8 habit; 85 + u8 mdr1; 86 + u8 efr; 87 + u8 scr; 88 + u8 wer; 89 + u8 xon; 90 + u8 xoff; 91 + u8 delayed_restore; 92 + u16 quot; 93 + 94 + bool is_suspending; 95 + int wakeirq; 96 + int wakeups_enabled; 97 + u32 latency; 98 + u32 calc_latency; 99 + struct pm_qos_request pm_qos_request; 100 + struct work_struct qos_work; 101 + struct uart_8250_dma omap8250_dma; 102 + }; 103 + 104 + static u32 uart_read(struct uart_8250_port *up, u32 reg) 105 + { 106 + return readl(up->port.membase + (reg << up->port.regshift)); 107 + } 108 + 109 + /* 110 + * Work Around for Errata i202 (2430, 3430, 3630, 4430 and 4460) 111 + * The access to uart register after MDR1 Access 112 + * causes UART to corrupt data. 113 + * 114 + * Need a delay = 115 + * 5 L4 clock cycles + 5 UART functional clock cycle (@48MHz = ~0.2uS) 116 + * give 10 times as much 117 + */ 118 + static void omap_8250_mdr1_errataset(struct uart_8250_port *up, 119 + struct omap8250_priv *priv) 120 + { 121 + u8 timeout = 255; 122 + u8 old_mdr1; 123 + 124 + old_mdr1 = serial_in(up, UART_OMAP_MDR1); 125 + if (old_mdr1 == priv->mdr1) 126 + return; 127 + 128 + serial_out(up, UART_OMAP_MDR1, priv->mdr1); 129 + udelay(2); 130 + serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_XMIT | 131 + UART_FCR_CLEAR_RCVR); 132 + /* 133 + * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and 134 + * TX_FIFO_E bit is 1. 135 + */ 136 + while (UART_LSR_THRE != (serial_in(up, UART_LSR) & 137 + (UART_LSR_THRE | UART_LSR_DR))) { 138 + timeout--; 139 + if (!timeout) { 140 + /* Should *never* happen. we warn and carry on */ 141 + dev_crit(up->port.dev, "Errata i202: timedout %x\n", 142 + serial_in(up, UART_LSR)); 143 + break; 144 + } 145 + udelay(1); 146 + } 147 + } 148 + 149 + static void omap_8250_get_divisor(struct uart_port *port, unsigned int baud, 150 + struct omap8250_priv *priv) 151 + { 152 + unsigned int uartclk = port->uartclk; 153 + unsigned int div_13, div_16; 154 + unsigned int abs_d13, abs_d16; 155 + 156 + /* 157 + * Old custom speed handling. 158 + */ 159 + if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) { 160 + priv->quot = port->custom_divisor & 0xffff; 161 + /* 162 + * I assume that nobody is using this. But hey, if somebody 163 + * would like to specify the divisor _and_ the mode then the 164 + * driver is ready and waiting for it. 165 + */ 166 + if (port->custom_divisor & (1 << 16)) 167 + priv->mdr1 = UART_OMAP_MDR1_13X_MODE; 168 + else 169 + priv->mdr1 = UART_OMAP_MDR1_16X_MODE; 170 + return; 171 + } 172 + div_13 = DIV_ROUND_CLOSEST(uartclk, 13 * baud); 173 + div_16 = DIV_ROUND_CLOSEST(uartclk, 16 * baud); 174 + 175 + if (!div_13) 176 + div_13 = 1; 177 + if (!div_16) 178 + div_16 = 1; 179 + 180 + abs_d13 = abs(baud - uartclk / 13 / div_13); 181 + abs_d16 = abs(baud - uartclk / 16 / div_16); 182 + 183 + if (abs_d13 >= abs_d16) { 184 + priv->mdr1 = UART_OMAP_MDR1_16X_MODE; 185 + priv->quot = div_16; 186 + } else { 187 + priv->mdr1 = UART_OMAP_MDR1_13X_MODE; 188 + priv->quot = div_13; 189 + } 190 + } 191 + 192 + static void omap8250_update_scr(struct uart_8250_port *up, 193 + struct omap8250_priv *priv) 194 + { 195 + u8 old_scr; 196 + 197 + old_scr = serial_in(up, UART_OMAP_SCR); 198 + if (old_scr == priv->scr) 199 + return; 200 + 201 + /* 202 + * The manual recommends not to enable the DMA mode selector in the SCR 203 + * (instead of the FCR) register _and_ selecting the DMA mode as one 204 + * register write because this may lead to malfunction. 205 + */ 206 + if (priv->scr & OMAP_UART_SCR_DMAMODE_MASK) 207 + serial_out(up, UART_OMAP_SCR, 208 + priv->scr & ~OMAP_UART_SCR_DMAMODE_MASK); 209 + serial_out(up, UART_OMAP_SCR, priv->scr); 210 + } 211 + 212 + static void omap8250_restore_regs(struct uart_8250_port *up) 213 + { 214 + struct omap8250_priv *priv = up->port.private_data; 215 + struct uart_8250_dma *dma = up->dma; 216 + 217 + if (dma && dma->tx_running) { 218 + /* 219 + * TCSANOW requests the change to occur immediately however if 220 + * we have a TX-DMA operation in progress then it has been 221 + * observed that it might stall and never complete. Therefore we 222 + * delay DMA completes to prevent this hang from happen. 223 + */ 224 + priv->delayed_restore = 1; 225 + return; 226 + } 227 + 228 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 229 + serial_out(up, UART_EFR, UART_EFR_ECB); 230 + 231 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 232 + serial_out(up, UART_MCR, UART_MCR_TCRTLR); 233 + serial_out(up, UART_FCR, up->fcr); 234 + 235 + omap8250_update_scr(up, priv); 236 + 237 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 238 + 239 + serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_RESTORE(16) | 240 + OMAP_UART_TCR_HALT(52)); 241 + serial_out(up, UART_TI752_TLR, 242 + TRIGGER_TLR_MASK(TX_TRIGGER) << UART_TI752_TLR_TX | 243 + TRIGGER_TLR_MASK(RX_TRIGGER) << UART_TI752_TLR_RX); 244 + 245 + serial_out(up, UART_LCR, 0); 246 + 247 + /* drop TCR + TLR access, we setup XON/XOFF later */ 248 + serial_out(up, UART_MCR, up->mcr); 249 + serial_out(up, UART_IER, up->ier); 250 + 251 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 252 + serial_dl_write(up, priv->quot); 253 + 254 + serial_out(up, UART_EFR, priv->efr); 255 + 256 + /* Configure flow control */ 257 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 258 + serial_out(up, UART_XON1, priv->xon); 259 + serial_out(up, UART_XOFF1, priv->xoff); 260 + 261 + serial_out(up, UART_LCR, up->lcr); 262 + /* need mode A for FCR */ 263 + if (priv->habit & UART_ERRATA_i202_MDR1_ACCESS) 264 + omap_8250_mdr1_errataset(up, priv); 265 + else 266 + serial_out(up, UART_OMAP_MDR1, priv->mdr1); 267 + up->port.ops->set_mctrl(&up->port, up->port.mctrl); 268 + } 269 + 270 + /* 271 + * OMAP can use "CLK / (16 or 13) / div" for baud rate. And then we have have 272 + * some differences in how we want to handle flow control. 273 + */ 274 + static void omap_8250_set_termios(struct uart_port *port, 275 + struct ktermios *termios, 276 + struct ktermios *old) 277 + { 278 + struct uart_8250_port *up = 279 + container_of(port, struct uart_8250_port, port); 280 + struct omap8250_priv *priv = up->port.private_data; 281 + unsigned char cval = 0; 282 + unsigned int baud; 283 + 284 + switch (termios->c_cflag & CSIZE) { 285 + case CS5: 286 + cval = UART_LCR_WLEN5; 287 + break; 288 + case CS6: 289 + cval = UART_LCR_WLEN6; 290 + break; 291 + case CS7: 292 + cval = UART_LCR_WLEN7; 293 + break; 294 + default: 295 + case CS8: 296 + cval = UART_LCR_WLEN8; 297 + break; 298 + } 299 + 300 + if (termios->c_cflag & CSTOPB) 301 + cval |= UART_LCR_STOP; 302 + if (termios->c_cflag & PARENB) 303 + cval |= UART_LCR_PARITY; 304 + if (!(termios->c_cflag & PARODD)) 305 + cval |= UART_LCR_EPAR; 306 + if (termios->c_cflag & CMSPAR) 307 + cval |= UART_LCR_SPAR; 308 + 309 + /* 310 + * Ask the core to calculate the divisor for us. 311 + */ 312 + baud = uart_get_baud_rate(port, termios, old, 313 + port->uartclk / 16 / 0xffff, 314 + port->uartclk / 13); 315 + omap_8250_get_divisor(port, baud, priv); 316 + 317 + /* 318 + * Ok, we're now changing the port state. Do it with 319 + * interrupts disabled. 320 + */ 321 + pm_runtime_get_sync(port->dev); 322 + spin_lock_irq(&port->lock); 323 + 324 + /* 325 + * Update the per-port timeout. 326 + */ 327 + uart_update_timeout(port, termios->c_cflag, baud); 328 + 329 + up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; 330 + if (termios->c_iflag & INPCK) 331 + up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; 332 + if (termios->c_iflag & (IGNBRK | PARMRK)) 333 + up->port.read_status_mask |= UART_LSR_BI; 334 + 335 + /* 336 + * Characters to ignore 337 + */ 338 + up->port.ignore_status_mask = 0; 339 + if (termios->c_iflag & IGNPAR) 340 + up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 341 + if (termios->c_iflag & IGNBRK) { 342 + up->port.ignore_status_mask |= UART_LSR_BI; 343 + /* 344 + * If we're ignoring parity and break indicators, 345 + * ignore overruns too (for real raw support). 346 + */ 347 + if (termios->c_iflag & IGNPAR) 348 + up->port.ignore_status_mask |= UART_LSR_OE; 349 + } 350 + 351 + /* 352 + * ignore all characters if CREAD is not set 353 + */ 354 + if ((termios->c_cflag & CREAD) == 0) 355 + up->port.ignore_status_mask |= UART_LSR_DR; 356 + 357 + /* 358 + * Modem status interrupts 359 + */ 360 + up->ier &= ~UART_IER_MSI; 361 + if (UART_ENABLE_MS(&up->port, termios->c_cflag)) 362 + up->ier |= UART_IER_MSI; 363 + 364 + up->lcr = cval; 365 + /* Up to here it was mostly serial8250_do_set_termios() */ 366 + 367 + /* 368 + * We enable TRIG_GRANU for RX and TX and additionaly we set 369 + * SCR_TX_EMPTY bit. The result is the following: 370 + * - RX_TRIGGER amount of bytes in the FIFO will cause an interrupt. 371 + * - less than RX_TRIGGER number of bytes will also cause an interrupt 372 + * once the UART decides that there no new bytes arriving. 373 + * - Once THRE is enabled, the interrupt will be fired once the FIFO is 374 + * empty - the trigger level is ignored here. 375 + * 376 + * Once DMA is enabled: 377 + * - UART will assert the TX DMA line once there is room for TX_TRIGGER 378 + * bytes in the TX FIFO. On each assert the DMA engine will move 379 + * TX_TRIGGER bytes into the FIFO. 380 + * - UART will assert the RX DMA line once there are RX_TRIGGER bytes in 381 + * the FIFO and move RX_TRIGGER bytes. 382 + * This is because threshold and trigger values are the same. 383 + */ 384 + up->fcr = UART_FCR_ENABLE_FIFO; 385 + up->fcr |= TRIGGER_FCR_MASK(TX_TRIGGER) << OMAP_UART_FCR_TX_TRIG; 386 + up->fcr |= TRIGGER_FCR_MASK(RX_TRIGGER) << OMAP_UART_FCR_RX_TRIG; 387 + 388 + priv->scr = OMAP_UART_SCR_RX_TRIG_GRANU1_MASK | OMAP_UART_SCR_TX_EMPTY | 389 + OMAP_UART_SCR_TX_TRIG_GRANU1_MASK; 390 + 391 + if (up->dma) 392 + priv->scr |= OMAP_UART_SCR_DMAMODE_1 | 393 + OMAP_UART_SCR_DMAMODE_CTL; 394 + 395 + priv->xon = termios->c_cc[VSTART]; 396 + priv->xoff = termios->c_cc[VSTOP]; 397 + 398 + priv->efr = 0; 399 + up->mcr &= ~(UART_MCR_RTS | UART_MCR_XONANY); 400 + if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) { 401 + /* Enable AUTORTS and AUTOCTS */ 402 + priv->efr |= UART_EFR_CTS | UART_EFR_RTS; 403 + 404 + /* Ensure MCR RTS is asserted */ 405 + up->mcr |= UART_MCR_RTS; 406 + } else if (up->port.flags & UPF_SOFT_FLOW) { 407 + /* 408 + * IXON Flag: 409 + * Enable XON/XOFF flow control on input. 410 + * Receiver compares XON1, XOFF1. 411 + */ 412 + if (termios->c_iflag & IXON) 413 + priv->efr |= OMAP_UART_SW_RX; 414 + 415 + /* 416 + * IXOFF Flag: 417 + * Enable XON/XOFF flow control on output. 418 + * Transmit XON1, XOFF1 419 + */ 420 + if (termios->c_iflag & IXOFF) 421 + priv->efr |= OMAP_UART_SW_TX; 422 + 423 + /* 424 + * IXANY Flag: 425 + * Enable any character to restart output. 426 + * Operation resumes after receiving any 427 + * character after recognition of the XOFF character 428 + */ 429 + if (termios->c_iflag & IXANY) 430 + up->mcr |= UART_MCR_XONANY; 431 + } 432 + omap8250_restore_regs(up); 433 + 434 + spin_unlock_irq(&up->port.lock); 435 + pm_runtime_mark_last_busy(port->dev); 436 + pm_runtime_put_autosuspend(port->dev); 437 + 438 + /* calculate wakeup latency constraint */ 439 + priv->calc_latency = USEC_PER_SEC * 64 * 8 / baud; 440 + priv->latency = priv->calc_latency; 441 + 442 + schedule_work(&priv->qos_work); 443 + 444 + /* Don't rewrite B0 */ 445 + if (tty_termios_baud_rate(termios)) 446 + tty_termios_encode_baud_rate(termios, baud, baud); 447 + } 448 + 449 + /* same as 8250 except that we may have extra flow bits set in EFR */ 450 + static void omap_8250_pm(struct uart_port *port, unsigned int state, 451 + unsigned int oldstate) 452 + { 453 + struct uart_8250_port *up = 454 + container_of(port, struct uart_8250_port, port); 455 + struct omap8250_priv *priv = up->port.private_data; 456 + 457 + pm_runtime_get_sync(port->dev); 458 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 459 + serial_out(up, UART_EFR, priv->efr | UART_EFR_ECB); 460 + serial_out(up, UART_LCR, 0); 461 + 462 + serial_out(up, UART_IER, (state != 0) ? UART_IERX_SLEEP : 0); 463 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 464 + serial_out(up, UART_EFR, priv->efr); 465 + serial_out(up, UART_LCR, 0); 466 + 467 + pm_runtime_mark_last_busy(port->dev); 468 + pm_runtime_put_autosuspend(port->dev); 469 + } 470 + 471 + static void omap_serial_fill_features_erratas(struct uart_8250_port *up, 472 + struct omap8250_priv *priv) 473 + { 474 + u32 mvr, scheme; 475 + u16 revision, major, minor; 476 + 477 + mvr = uart_read(up, UART_OMAP_MVER); 478 + 479 + /* Check revision register scheme */ 480 + scheme = mvr >> OMAP_UART_MVR_SCHEME_SHIFT; 481 + 482 + switch (scheme) { 483 + case 0: /* Legacy Scheme: OMAP2/3 */ 484 + /* MINOR_REV[0:4], MAJOR_REV[4:7] */ 485 + major = (mvr & OMAP_UART_LEGACY_MVR_MAJ_MASK) >> 486 + OMAP_UART_LEGACY_MVR_MAJ_SHIFT; 487 + minor = (mvr & OMAP_UART_LEGACY_MVR_MIN_MASK); 488 + break; 489 + case 1: 490 + /* New Scheme: OMAP4+ */ 491 + /* MINOR_REV[0:5], MAJOR_REV[8:10] */ 492 + major = (mvr & OMAP_UART_MVR_MAJ_MASK) >> 493 + OMAP_UART_MVR_MAJ_SHIFT; 494 + minor = (mvr & OMAP_UART_MVR_MIN_MASK); 495 + break; 496 + default: 497 + dev_warn(up->port.dev, 498 + "Unknown revision, defaulting to highest\n"); 499 + /* highest possible revision */ 500 + major = 0xff; 501 + minor = 0xff; 502 + } 503 + /* normalize revision for the driver */ 504 + revision = UART_BUILD_REVISION(major, minor); 505 + 506 + switch (revision) { 507 + case OMAP_UART_REV_46: 508 + priv->habit = UART_ERRATA_i202_MDR1_ACCESS; 509 + break; 510 + case OMAP_UART_REV_52: 511 + priv->habit = UART_ERRATA_i202_MDR1_ACCESS | 512 + OMAP_UART_WER_HAS_TX_WAKEUP; 513 + break; 514 + case OMAP_UART_REV_63: 515 + priv->habit = UART_ERRATA_i202_MDR1_ACCESS | 516 + OMAP_UART_WER_HAS_TX_WAKEUP; 517 + break; 518 + default: 519 + break; 520 + } 521 + } 522 + 523 + static void omap8250_uart_qos_work(struct work_struct *work) 524 + { 525 + struct omap8250_priv *priv; 526 + 527 + priv = container_of(work, struct omap8250_priv, qos_work); 528 + pm_qos_update_request(&priv->pm_qos_request, priv->latency); 529 + } 530 + 531 + static irqreturn_t omap_wake_irq(int irq, void *dev_id) 532 + { 533 + struct uart_port *port = dev_id; 534 + int ret; 535 + 536 + ret = port->handle_irq(port); 537 + if (ret) 538 + return IRQ_HANDLED; 539 + return IRQ_NONE; 540 + } 541 + 542 + static int omap_8250_startup(struct uart_port *port) 543 + { 544 + struct uart_8250_port *up = 545 + container_of(port, struct uart_8250_port, port); 546 + struct omap8250_priv *priv = port->private_data; 547 + 548 + int ret; 549 + 550 + if (priv->wakeirq) { 551 + ret = request_irq(priv->wakeirq, omap_wake_irq, 552 + port->irqflags, "uart wakeup irq", port); 553 + if (ret) 554 + return ret; 555 + disable_irq(priv->wakeirq); 556 + } 557 + 558 + pm_runtime_get_sync(port->dev); 559 + 560 + ret = serial8250_do_startup(port); 561 + if (ret) 562 + goto err; 563 + 564 + #ifdef CONFIG_PM_RUNTIME 565 + up->capabilities |= UART_CAP_RPM; 566 + #endif 567 + 568 + /* Enable module level wake up */ 569 + priv->wer = OMAP_UART_WER_MOD_WKUP; 570 + if (priv->habit & OMAP_UART_WER_HAS_TX_WAKEUP) 571 + priv->wer |= OMAP_UART_TX_WAKEUP_EN; 572 + serial_out(up, UART_OMAP_WER, priv->wer); 573 + 574 + if (up->dma) 575 + up->dma->rx_dma(up, 0); 576 + 577 + pm_runtime_mark_last_busy(port->dev); 578 + pm_runtime_put_autosuspend(port->dev); 579 + return 0; 580 + err: 581 + pm_runtime_mark_last_busy(port->dev); 582 + pm_runtime_put_autosuspend(port->dev); 583 + if (priv->wakeirq) 584 + free_irq(priv->wakeirq, port); 585 + return ret; 586 + } 587 + 588 + static void omap_8250_shutdown(struct uart_port *port) 589 + { 590 + struct uart_8250_port *up = 591 + container_of(port, struct uart_8250_port, port); 592 + struct omap8250_priv *priv = port->private_data; 593 + 594 + flush_work(&priv->qos_work); 595 + if (up->dma) 596 + up->dma->rx_dma(up, UART_IIR_RX_TIMEOUT); 597 + 598 + pm_runtime_get_sync(port->dev); 599 + 600 + serial_out(up, UART_OMAP_WER, 0); 601 + serial8250_do_shutdown(port); 602 + 603 + pm_runtime_mark_last_busy(port->dev); 604 + pm_runtime_put_autosuspend(port->dev); 605 + 606 + if (priv->wakeirq) 607 + free_irq(priv->wakeirq, port); 608 + } 609 + 610 + static void omap_8250_throttle(struct uart_port *port) 611 + { 612 + unsigned long flags; 613 + struct uart_8250_port *up = 614 + container_of(port, struct uart_8250_port, port); 615 + 616 + pm_runtime_get_sync(port->dev); 617 + 618 + spin_lock_irqsave(&port->lock, flags); 619 + up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); 620 + serial_out(up, UART_IER, up->ier); 621 + spin_unlock_irqrestore(&port->lock, flags); 622 + 623 + pm_runtime_mark_last_busy(port->dev); 624 + pm_runtime_put_autosuspend(port->dev); 625 + } 626 + 627 + static void omap_8250_unthrottle(struct uart_port *port) 628 + { 629 + unsigned long flags; 630 + struct uart_8250_port *up = 631 + container_of(port, struct uart_8250_port, port); 632 + 633 + pm_runtime_get_sync(port->dev); 634 + 635 + spin_lock_irqsave(&port->lock, flags); 636 + up->ier |= UART_IER_RLSI | UART_IER_RDI; 637 + serial_out(up, UART_IER, up->ier); 638 + spin_unlock_irqrestore(&port->lock, flags); 639 + 640 + pm_runtime_mark_last_busy(port->dev); 641 + pm_runtime_put_autosuspend(port->dev); 642 + } 643 + 644 + #ifdef CONFIG_SERIAL_8250_DMA 645 + static int omap_8250_rx_dma(struct uart_8250_port *p, unsigned int iir); 646 + 647 + static void __dma_rx_do_complete(struct uart_8250_port *p, bool error) 648 + { 649 + struct uart_8250_dma *dma = p->dma; 650 + struct tty_port *tty_port = &p->port.state->port; 651 + struct dma_tx_state state; 652 + int count; 653 + 654 + dma_sync_single_for_cpu(dma->rxchan->device->dev, dma->rx_addr, 655 + dma->rx_size, DMA_FROM_DEVICE); 656 + 657 + dma->rx_running = 0; 658 + dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); 659 + dmaengine_terminate_all(dma->rxchan); 660 + 661 + count = dma->rx_size - state.residue; 662 + 663 + tty_insert_flip_string(tty_port, dma->rx_buf, count); 664 + p->port.icount.rx += count; 665 + if (!error) 666 + omap_8250_rx_dma(p, 0); 667 + 668 + tty_flip_buffer_push(tty_port); 669 + } 670 + 671 + static void __dma_rx_complete(void *param) 672 + { 673 + __dma_rx_do_complete(param, false); 674 + } 675 + 676 + static int omap_8250_rx_dma(struct uart_8250_port *p, unsigned int iir) 677 + { 678 + struct uart_8250_dma *dma = p->dma; 679 + struct dma_async_tx_descriptor *desc; 680 + 681 + switch (iir & 0x3f) { 682 + case UART_IIR_RLSI: 683 + /* 8250_core handles errors and break interrupts */ 684 + if (dma->rx_running) { 685 + dmaengine_pause(dma->rxchan); 686 + __dma_rx_do_complete(p, true); 687 + } 688 + return -EIO; 689 + case UART_IIR_RX_TIMEOUT: 690 + /* 691 + * If RCVR FIFO trigger level was not reached, complete the 692 + * transfer and let 8250_core copy the remaining data. 693 + */ 694 + if (dma->rx_running) { 695 + dmaengine_pause(dma->rxchan); 696 + __dma_rx_do_complete(p, true); 697 + } 698 + return -ETIMEDOUT; 699 + case UART_IIR_RDI: 700 + /* 701 + * The OMAP UART is a special BEAST. If we receive RDI we _have_ 702 + * a DMA transfer programmed but it didn't work. One reason is 703 + * that we were too slow and there were too many bytes in the 704 + * FIFO, the UART counted wrong and never kicked the DMA engine 705 + * to do anything. That means once we receive RDI on OMAP then 706 + * the DMA won't do anything soon so we have to cancel the DMA 707 + * transfer and purge the FIFO manually. 708 + */ 709 + if (dma->rx_running) { 710 + dmaengine_pause(dma->rxchan); 711 + __dma_rx_do_complete(p, true); 712 + } 713 + return -ETIMEDOUT; 714 + 715 + default: 716 + break; 717 + } 718 + 719 + if (dma->rx_running) 720 + return 0; 721 + 722 + desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr, 723 + dma->rx_size, DMA_DEV_TO_MEM, 724 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 725 + if (!desc) 726 + return -EBUSY; 727 + 728 + dma->rx_running = 1; 729 + desc->callback = __dma_rx_complete; 730 + desc->callback_param = p; 731 + 732 + dma->rx_cookie = dmaengine_submit(desc); 733 + 734 + dma_sync_single_for_device(dma->rxchan->device->dev, dma->rx_addr, 735 + dma->rx_size, DMA_FROM_DEVICE); 736 + 737 + dma_async_issue_pending(dma->rxchan); 738 + return 0; 739 + } 740 + 741 + static int omap_8250_tx_dma(struct uart_8250_port *p); 742 + 743 + static void omap_8250_dma_tx_complete(void *param) 744 + { 745 + struct uart_8250_port *p = param; 746 + struct uart_8250_dma *dma = p->dma; 747 + struct circ_buf *xmit = &p->port.state->xmit; 748 + unsigned long flags; 749 + bool en_thri = false; 750 + struct omap8250_priv *priv = p->port.private_data; 751 + 752 + dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr, 753 + UART_XMIT_SIZE, DMA_TO_DEVICE); 754 + 755 + spin_lock_irqsave(&p->port.lock, flags); 756 + 757 + dma->tx_running = 0; 758 + 759 + xmit->tail += dma->tx_size; 760 + xmit->tail &= UART_XMIT_SIZE - 1; 761 + p->port.icount.tx += dma->tx_size; 762 + 763 + if (priv->delayed_restore) { 764 + priv->delayed_restore = 0; 765 + omap8250_restore_regs(p); 766 + } 767 + 768 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 769 + uart_write_wakeup(&p->port); 770 + 771 + if (!uart_circ_empty(xmit) && !uart_tx_stopped(&p->port)) { 772 + int ret; 773 + 774 + ret = omap_8250_tx_dma(p); 775 + if (ret) 776 + en_thri = true; 777 + 778 + } else if (p->capabilities & UART_CAP_RPM) { 779 + en_thri = true; 780 + } 781 + 782 + if (en_thri) { 783 + dma->tx_err = 1; 784 + p->ier |= UART_IER_THRI; 785 + serial_port_out(&p->port, UART_IER, p->ier); 786 + } 787 + 788 + spin_unlock_irqrestore(&p->port.lock, flags); 789 + } 790 + 791 + static int omap_8250_tx_dma(struct uart_8250_port *p) 792 + { 793 + struct uart_8250_dma *dma = p->dma; 794 + struct omap8250_priv *priv = p->port.private_data; 795 + struct circ_buf *xmit = &p->port.state->xmit; 796 + struct dma_async_tx_descriptor *desc; 797 + unsigned int skip_byte = 0; 798 + int ret; 799 + 800 + if (dma->tx_running) 801 + return 0; 802 + if (uart_tx_stopped(&p->port) || uart_circ_empty(xmit)) { 803 + 804 + /* 805 + * Even if no data, we need to return an error for the two cases 806 + * below so serial8250_tx_chars() is invoked and properly clears 807 + * THRI and/or runtime suspend. 808 + */ 809 + if (dma->tx_err || p->capabilities & UART_CAP_RPM) { 810 + ret = -EBUSY; 811 + goto err; 812 + } 813 + if (p->ier & UART_IER_THRI) { 814 + p->ier &= ~UART_IER_THRI; 815 + serial_out(p, UART_IER, p->ier); 816 + } 817 + return 0; 818 + } 819 + 820 + dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); 821 + if (priv->habit & OMAP_DMA_TX_KICK) { 822 + u8 tx_lvl; 823 + 824 + /* 825 + * We need to put the first byte into the FIFO in order to start 826 + * the DMA transfer. For transfers smaller than four bytes we 827 + * don't bother doing DMA at all. It seem not matter if there 828 + * are still bytes in the FIFO from the last transfer (in case 829 + * we got here directly from omap_8250_dma_tx_complete()). Bytes 830 + * leaving the FIFO seem not to trigger the DMA transfer. It is 831 + * really the byte that we put into the FIFO. 832 + * If the FIFO is already full then we most likely got here from 833 + * omap_8250_dma_tx_complete(). And this means the DMA engine 834 + * just completed its work. We don't have to wait the complete 835 + * 86us at 115200,8n1 but around 60us (not to mention lower 836 + * baudrates). So in that case we take the interrupt and try 837 + * again with an empty FIFO. 838 + */ 839 + tx_lvl = serial_in(p, UART_OMAP_TX_LVL); 840 + if (tx_lvl == p->tx_loadsz) { 841 + ret = -EBUSY; 842 + goto err; 843 + } 844 + if (dma->tx_size < 4) { 845 + ret = -EINVAL; 846 + goto err; 847 + } 848 + skip_byte = 1; 849 + } 850 + 851 + desc = dmaengine_prep_slave_single(dma->txchan, 852 + dma->tx_addr + xmit->tail + skip_byte, 853 + dma->tx_size - skip_byte, DMA_MEM_TO_DEV, 854 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 855 + if (!desc) { 856 + ret = -EBUSY; 857 + goto err; 858 + } 859 + 860 + dma->tx_running = 1; 861 + 862 + desc->callback = omap_8250_dma_tx_complete; 863 + desc->callback_param = p; 864 + 865 + dma->tx_cookie = dmaengine_submit(desc); 866 + 867 + dma_sync_single_for_device(dma->txchan->device->dev, dma->tx_addr, 868 + UART_XMIT_SIZE, DMA_TO_DEVICE); 869 + 870 + dma_async_issue_pending(dma->txchan); 871 + if (dma->tx_err) 872 + dma->tx_err = 0; 873 + 874 + if (p->ier & UART_IER_THRI) { 875 + p->ier &= ~UART_IER_THRI; 876 + serial_out(p, UART_IER, p->ier); 877 + } 878 + if (skip_byte) 879 + serial_out(p, UART_TX, xmit->buf[xmit->tail]); 880 + return 0; 881 + err: 882 + dma->tx_err = 1; 883 + return ret; 884 + } 885 + 886 + /* 887 + * This is mostly serial8250_handle_irq(). We have a slightly different DMA 888 + * hoook for RX/TX and need different logic for them in the ISR. Therefore we 889 + * use the default routine in the non-DMA case and this one for with DMA. 890 + */ 891 + static int omap_8250_dma_handle_irq(struct uart_port *port) 892 + { 893 + struct uart_8250_port *up = up_to_u8250p(port); 894 + unsigned char status; 895 + unsigned long flags; 896 + u8 iir; 897 + int dma_err = 0; 898 + 899 + serial8250_rpm_get(up); 900 + 901 + iir = serial_port_in(port, UART_IIR); 902 + if (iir & UART_IIR_NO_INT) { 903 + serial8250_rpm_put(up); 904 + return 0; 905 + } 906 + 907 + spin_lock_irqsave(&port->lock, flags); 908 + 909 + status = serial_port_in(port, UART_LSR); 910 + 911 + if (status & (UART_LSR_DR | UART_LSR_BI)) { 912 + 913 + dma_err = omap_8250_rx_dma(up, iir); 914 + if (dma_err) { 915 + status = serial8250_rx_chars(up, status); 916 + omap_8250_rx_dma(up, 0); 917 + } 918 + } 919 + serial8250_modem_status(up); 920 + if (status & UART_LSR_THRE && up->dma->tx_err) { 921 + if (uart_tx_stopped(&up->port) || 922 + uart_circ_empty(&up->port.state->xmit)) { 923 + up->dma->tx_err = 0; 924 + serial8250_tx_chars(up); 925 + } else { 926 + /* 927 + * try again due to an earlier failer which 928 + * might have been resolved by now. 929 + */ 930 + dma_err = omap_8250_tx_dma(up); 931 + if (dma_err) 932 + serial8250_tx_chars(up); 933 + } 934 + } 935 + 936 + spin_unlock_irqrestore(&port->lock, flags); 937 + serial8250_rpm_put(up); 938 + return 1; 939 + } 940 + 941 + static bool the_no_dma_filter_fn(struct dma_chan *chan, void *param) 942 + { 943 + return false; 944 + } 945 + 946 + #else 947 + 948 + static inline int omap_8250_rx_dma(struct uart_8250_port *p, unsigned int iir) 949 + { 950 + return -EINVAL; 951 + } 952 + #endif 953 + 954 + static int omap8250_probe(struct platform_device *pdev) 955 + { 956 + struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 957 + struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 958 + struct omap8250_priv *priv; 959 + struct uart_8250_port up; 960 + int ret; 961 + void __iomem *membase; 962 + 963 + if (!regs || !irq) { 964 + dev_err(&pdev->dev, "missing registers or irq\n"); 965 + return -EINVAL; 966 + } 967 + 968 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 969 + if (!priv) 970 + return -ENOMEM; 971 + 972 + membase = devm_ioremap_nocache(&pdev->dev, regs->start, 973 + resource_size(regs)); 974 + if (!membase) 975 + return -ENODEV; 976 + 977 + memset(&up, 0, sizeof(up)); 978 + up.port.dev = &pdev->dev; 979 + up.port.mapbase = regs->start; 980 + up.port.membase = membase; 981 + up.port.irq = irq->start; 982 + /* 983 + * It claims to be 16C750 compatible however it is a little different. 984 + * It has EFR and has no FCR7_64byte bit. The AFE (which it claims to 985 + * have) is enabled via EFR instead of MCR. The type is set here 8250 986 + * just to get things going. UNKNOWN does not work for a few reasons and 987 + * we don't need our own type since we don't use 8250's set_termios() 988 + * or pm callback. 989 + */ 990 + up.port.type = PORT_8250; 991 + up.port.iotype = UPIO_MEM; 992 + up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE | UPF_SOFT_FLOW | 993 + UPF_HARD_FLOW; 994 + up.port.private_data = priv; 995 + 996 + up.port.regshift = 2; 997 + up.port.fifosize = 64; 998 + up.tx_loadsz = 64; 999 + up.capabilities = UART_CAP_FIFO; 1000 + #ifdef CONFIG_PM_RUNTIME 1001 + /* 1002 + * PM_RUNTIME is mostly transparent. However to do it right we need to a 1003 + * TX empty interrupt before we can put the device to auto idle. So if 1004 + * PM_RUNTIME is not enabled we don't add that flag and can spare that 1005 + * one extra interrupt in the TX path. 1006 + */ 1007 + up.capabilities |= UART_CAP_RPM; 1008 + #endif 1009 + up.port.set_termios = omap_8250_set_termios; 1010 + up.port.pm = omap_8250_pm; 1011 + up.port.startup = omap_8250_startup; 1012 + up.port.shutdown = omap_8250_shutdown; 1013 + up.port.throttle = omap_8250_throttle; 1014 + up.port.unthrottle = omap_8250_unthrottle; 1015 + 1016 + if (pdev->dev.of_node) { 1017 + ret = of_alias_get_id(pdev->dev.of_node, "serial"); 1018 + 1019 + of_property_read_u32(pdev->dev.of_node, "clock-frequency", 1020 + &up.port.uartclk); 1021 + priv->wakeirq = irq_of_parse_and_map(pdev->dev.of_node, 1); 1022 + } else { 1023 + ret = pdev->id; 1024 + } 1025 + if (ret < 0) { 1026 + dev_err(&pdev->dev, "failed to get alias/pdev id\n"); 1027 + return ret; 1028 + } 1029 + up.port.line = ret; 1030 + 1031 + if (!up.port.uartclk) { 1032 + up.port.uartclk = DEFAULT_CLK_SPEED; 1033 + dev_warn(&pdev->dev, 1034 + "No clock speed specified: using default: %d\n", 1035 + DEFAULT_CLK_SPEED); 1036 + } 1037 + 1038 + priv->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; 1039 + priv->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; 1040 + pm_qos_add_request(&priv->pm_qos_request, PM_QOS_CPU_DMA_LATENCY, 1041 + priv->latency); 1042 + INIT_WORK(&priv->qos_work, omap8250_uart_qos_work); 1043 + 1044 + device_init_wakeup(&pdev->dev, true); 1045 + pm_runtime_use_autosuspend(&pdev->dev); 1046 + pm_runtime_set_autosuspend_delay(&pdev->dev, -1); 1047 + 1048 + pm_runtime_irq_safe(&pdev->dev); 1049 + pm_runtime_enable(&pdev->dev); 1050 + 1051 + pm_runtime_get_sync(&pdev->dev); 1052 + 1053 + omap_serial_fill_features_erratas(&up, priv); 1054 + #ifdef CONFIG_SERIAL_8250_DMA 1055 + if (pdev->dev.of_node) { 1056 + /* 1057 + * Oh DMA support. If there are no DMA properties in the DT then 1058 + * we will fall back to a generic DMA channel which does not 1059 + * really work here. To ensure that we do not get a generic DMA 1060 + * channel assigned, we have the the_no_dma_filter_fn() here. 1061 + * To avoid "failed to request DMA" messages we check for DMA 1062 + * properties in DT. 1063 + */ 1064 + ret = of_property_count_strings(pdev->dev.of_node, "dma-names"); 1065 + if (ret == 2) { 1066 + up.dma = &priv->omap8250_dma; 1067 + up.port.handle_irq = omap_8250_dma_handle_irq; 1068 + priv->omap8250_dma.fn = the_no_dma_filter_fn; 1069 + priv->omap8250_dma.tx_dma = omap_8250_tx_dma; 1070 + priv->omap8250_dma.rx_dma = omap_8250_rx_dma; 1071 + priv->omap8250_dma.rx_size = RX_TRIGGER; 1072 + priv->omap8250_dma.rxconf.src_maxburst = RX_TRIGGER; 1073 + priv->omap8250_dma.txconf.dst_maxburst = TX_TRIGGER; 1074 + 1075 + if (of_machine_is_compatible("ti,am33xx")) 1076 + priv->habit |= OMAP_DMA_TX_KICK; 1077 + } 1078 + } 1079 + #endif 1080 + ret = serial8250_register_8250_port(&up); 1081 + if (ret < 0) { 1082 + dev_err(&pdev->dev, "unable to register 8250 port\n"); 1083 + goto err; 1084 + } 1085 + priv->line = ret; 1086 + platform_set_drvdata(pdev, priv); 1087 + pm_runtime_mark_last_busy(&pdev->dev); 1088 + pm_runtime_put_autosuspend(&pdev->dev); 1089 + return 0; 1090 + err: 1091 + pm_runtime_put(&pdev->dev); 1092 + pm_runtime_disable(&pdev->dev); 1093 + return ret; 1094 + } 1095 + 1096 + static int omap8250_remove(struct platform_device *pdev) 1097 + { 1098 + struct omap8250_priv *priv = platform_get_drvdata(pdev); 1099 + 1100 + pm_runtime_put_sync(&pdev->dev); 1101 + pm_runtime_disable(&pdev->dev); 1102 + serial8250_unregister_port(priv->line); 1103 + pm_qos_remove_request(&priv->pm_qos_request); 1104 + device_init_wakeup(&pdev->dev, false); 1105 + return 0; 1106 + } 1107 + 1108 + #if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_RUNTIME) 1109 + 1110 + static inline void omap8250_enable_wakeirq(struct omap8250_priv *priv, 1111 + bool enable) 1112 + { 1113 + if (!priv->wakeirq) 1114 + return; 1115 + 1116 + if (enable) 1117 + enable_irq(priv->wakeirq); 1118 + else 1119 + disable_irq_nosync(priv->wakeirq); 1120 + } 1121 + 1122 + static void omap8250_enable_wakeup(struct omap8250_priv *priv, 1123 + bool enable) 1124 + { 1125 + if (enable == priv->wakeups_enabled) 1126 + return; 1127 + 1128 + omap8250_enable_wakeirq(priv, enable); 1129 + priv->wakeups_enabled = enable; 1130 + } 1131 + #endif 1132 + 1133 + #ifdef CONFIG_PM_SLEEP 1134 + static int omap8250_prepare(struct device *dev) 1135 + { 1136 + struct omap8250_priv *priv = dev_get_drvdata(dev); 1137 + 1138 + if (!priv) 1139 + return 0; 1140 + priv->is_suspending = true; 1141 + return 0; 1142 + } 1143 + 1144 + static void omap8250_complete(struct device *dev) 1145 + { 1146 + struct omap8250_priv *priv = dev_get_drvdata(dev); 1147 + 1148 + if (!priv) 1149 + return; 1150 + priv->is_suspending = false; 1151 + } 1152 + 1153 + static int omap8250_suspend(struct device *dev) 1154 + { 1155 + struct omap8250_priv *priv = dev_get_drvdata(dev); 1156 + 1157 + serial8250_suspend_port(priv->line); 1158 + flush_work(&priv->qos_work); 1159 + 1160 + if (device_may_wakeup(dev)) 1161 + omap8250_enable_wakeup(priv, true); 1162 + else 1163 + omap8250_enable_wakeup(priv, false); 1164 + return 0; 1165 + } 1166 + 1167 + static int omap8250_resume(struct device *dev) 1168 + { 1169 + struct omap8250_priv *priv = dev_get_drvdata(dev); 1170 + 1171 + if (device_may_wakeup(dev)) 1172 + omap8250_enable_wakeup(priv, false); 1173 + 1174 + serial8250_resume_port(priv->line); 1175 + return 0; 1176 + } 1177 + #else 1178 + #define omap8250_prepare NULL 1179 + #define omap8250_complete NULL 1180 + #endif 1181 + 1182 + #ifdef CONFIG_PM_RUNTIME 1183 + static int omap8250_lost_context(struct uart_8250_port *up) 1184 + { 1185 + u32 val; 1186 + 1187 + val = serial_in(up, UART_OMAP_MDR1); 1188 + /* 1189 + * If we lose context, then MDR1 is set to its reset value which is 1190 + * UART_OMAP_MDR1_DISABLE. After set_termios() we set it either to 13x 1191 + * or 16x but never to disable again. 1192 + */ 1193 + if (val == UART_OMAP_MDR1_DISABLE) 1194 + return 1; 1195 + return 0; 1196 + } 1197 + 1198 + static int omap8250_runtime_suspend(struct device *dev) 1199 + { 1200 + struct omap8250_priv *priv = dev_get_drvdata(dev); 1201 + struct uart_8250_port *up; 1202 + 1203 + up = serial8250_get_port(priv->line); 1204 + /* 1205 + * When using 'no_console_suspend', the console UART must not be 1206 + * suspended. Since driver suspend is managed by runtime suspend, 1207 + * preventing runtime suspend (by returning error) will keep device 1208 + * active during suspend. 1209 + */ 1210 + if (priv->is_suspending && !console_suspend_enabled) { 1211 + if (uart_console(&up->port)) 1212 + return -EBUSY; 1213 + } 1214 + 1215 + omap8250_enable_wakeup(priv, true); 1216 + if (up->dma) 1217 + omap_8250_rx_dma(up, UART_IIR_RX_TIMEOUT); 1218 + 1219 + priv->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; 1220 + schedule_work(&priv->qos_work); 1221 + 1222 + return 0; 1223 + } 1224 + 1225 + static int omap8250_runtime_resume(struct device *dev) 1226 + { 1227 + struct omap8250_priv *priv = dev_get_drvdata(dev); 1228 + struct uart_8250_port *up; 1229 + int loss_cntx; 1230 + 1231 + /* In case runtime-pm tries this before we are setup */ 1232 + if (!priv) 1233 + return 0; 1234 + 1235 + up = serial8250_get_port(priv->line); 1236 + omap8250_enable_wakeup(priv, false); 1237 + loss_cntx = omap8250_lost_context(up); 1238 + 1239 + if (loss_cntx) 1240 + omap8250_restore_regs(up); 1241 + 1242 + if (up->dma) 1243 + omap_8250_rx_dma(up, 0); 1244 + 1245 + priv->latency = priv->calc_latency; 1246 + schedule_work(&priv->qos_work); 1247 + return 0; 1248 + } 1249 + #endif 1250 + 1251 + static const struct dev_pm_ops omap8250_dev_pm_ops = { 1252 + SET_SYSTEM_SLEEP_PM_OPS(omap8250_suspend, omap8250_resume) 1253 + SET_RUNTIME_PM_OPS(omap8250_runtime_suspend, 1254 + omap8250_runtime_resume, NULL) 1255 + .prepare = omap8250_prepare, 1256 + .complete = omap8250_complete, 1257 + }; 1258 + 1259 + static const struct of_device_id omap8250_dt_ids[] = { 1260 + { .compatible = "ti,omap2-uart" }, 1261 + { .compatible = "ti,omap3-uart" }, 1262 + { .compatible = "ti,omap4-uart" }, 1263 + {}, 1264 + }; 1265 + MODULE_DEVICE_TABLE(of, omap8250_dt_ids); 1266 + 1267 + static struct platform_driver omap8250_platform_driver = { 1268 + .driver = { 1269 + .name = "omap8250", 1270 + .pm = &omap8250_dev_pm_ops, 1271 + .of_match_table = omap8250_dt_ids, 1272 + .owner = THIS_MODULE, 1273 + }, 1274 + .probe = omap8250_probe, 1275 + .remove = omap8250_remove, 1276 + }; 1277 + module_platform_driver(omap8250_platform_driver); 1278 + 1279 + MODULE_AUTHOR("Sebastian Andrzej Siewior"); 1280 + MODULE_DESCRIPTION("OMAP 8250 Driver"); 1281 + MODULE_LICENSE("GPL v2");
+153 -45
drivers/tty/serial/8250/8250_pci.c
··· 79 79 int bar, int offset, int regshift) 80 80 { 81 81 struct pci_dev *dev = priv->dev; 82 - unsigned long base, len; 83 82 84 83 if (bar >= PCI_NUM_BAR_RESOURCES) 85 84 return -EINVAL; 86 85 87 - base = pci_resource_start(dev, bar); 88 - 89 86 if (pci_resource_flags(dev, bar) & IORESOURCE_MEM) { 90 - len = pci_resource_len(dev, bar); 91 - 92 87 if (!priv->remapped_bar[bar]) 93 - priv->remapped_bar[bar] = ioremap_nocache(base, len); 88 + priv->remapped_bar[bar] = pci_ioremap_bar(dev, bar); 94 89 if (!priv->remapped_bar[bar]) 95 90 return -ENOMEM; 96 91 97 92 port->port.iotype = UPIO_MEM; 98 93 port->port.iobase = 0; 99 - port->port.mapbase = base + offset; 94 + port->port.mapbase = pci_resource_start(dev, bar) + offset; 100 95 port->port.membase = priv->remapped_bar[bar] + offset; 101 96 port->port.regshift = regshift; 102 97 } else { 103 98 port->port.iotype = UPIO_PORT; 104 - port->port.iobase = base + offset; 99 + port->port.iobase = pci_resource_start(dev, bar) + offset; 105 100 port->port.mapbase = 0; 106 101 port->port.membase = NULL; 107 102 port->port.regshift = 0; ··· 312 317 static void pci_ni8420_exit(struct pci_dev *dev) 313 318 { 314 319 void __iomem *p; 315 - unsigned long base, len; 316 320 unsigned int bar = 0; 317 321 318 322 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) { ··· 319 325 return; 320 326 } 321 327 322 - base = pci_resource_start(dev, bar); 323 - len = pci_resource_len(dev, bar); 324 - p = ioremap_nocache(base, len); 328 + p = pci_ioremap_bar(dev, bar); 325 329 if (p == NULL) 326 330 return; 327 331 ··· 341 349 static void pci_ni8430_exit(struct pci_dev *dev) 342 350 { 343 351 void __iomem *p; 344 - unsigned long base, len; 345 352 unsigned int bar = 0; 346 353 347 354 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) { ··· 348 357 return; 349 358 } 350 359 351 - base = pci_resource_start(dev, bar); 352 - len = pci_resource_len(dev, bar); 353 - p = ioremap_nocache(base, len); 360 + p = pci_ioremap_bar(dev, bar); 354 361 if (p == NULL) 355 362 return; 356 363 ··· 671 682 static int pci_ni8420_init(struct pci_dev *dev) 672 683 { 673 684 void __iomem *p; 674 - unsigned long base, len; 675 685 unsigned int bar = 0; 676 686 677 687 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) { ··· 678 690 return 0; 679 691 } 680 692 681 - base = pci_resource_start(dev, bar); 682 - len = pci_resource_len(dev, bar); 683 - p = ioremap_nocache(base, len); 693 + p = pci_ioremap_bar(dev, bar); 684 694 if (p == NULL) 685 695 return -ENOMEM; 686 696 ··· 700 714 static int pci_ni8430_init(struct pci_dev *dev) 701 715 { 702 716 void __iomem *p; 703 - unsigned long base, len; 717 + struct pci_bus_region region; 704 718 u32 device_window; 705 719 unsigned int bar = 0; 706 720 ··· 709 723 return 0; 710 724 } 711 725 712 - base = pci_resource_start(dev, bar); 713 - len = pci_resource_len(dev, bar); 714 - p = ioremap_nocache(base, len); 726 + p = pci_ioremap_bar(dev, bar); 715 727 if (p == NULL) 716 728 return -ENOMEM; 717 729 718 - /* Set device window address and size in BAR0 */ 719 - device_window = ((base + MITE_IOWBSR1_WIN_OFFSET) & 0xffffff00) 730 + /* 731 + * Set device window address and size in BAR0, while acknowledging that 732 + * the resource structure may contain a translated address that differs 733 + * from the address the device responds to. 734 + */ 735 + pcibios_resource_to_bus(dev->bus, &region, &dev->resource[bar]); 736 + device_window = ((region.start + MITE_IOWBSR1_WIN_OFFSET) & 0xffffff00) 720 737 | MITE_IOWBSR1_WENAB | MITE_IOWBSR1_WSIZE; 721 738 writel(device_window, p + MITE_IOWBSR1); 722 739 ··· 746 757 const struct pciserial_board *board, 747 758 struct uart_8250_port *port, int idx) 748 759 { 760 + struct pci_dev *dev = priv->dev; 749 761 void __iomem *p; 750 - unsigned long base, len; 751 762 unsigned int bar, offset = board->first_offset; 752 763 753 764 if (idx >= board->num_ports) ··· 756 767 bar = FL_GET_BASE(board->flags); 757 768 offset += idx * board->uart_offset; 758 769 759 - base = pci_resource_start(priv->dev, bar); 760 - len = pci_resource_len(priv->dev, bar); 761 - p = ioremap_nocache(base, len); 770 + p = pci_ioremap_bar(dev, bar); 771 + if (!p) 772 + return -ENOMEM; 762 773 763 774 /* enable the transceiver */ 764 775 writeb(readb(p + offset + NI8430_PORTCON) | NI8430_PORTCON_TXVR_ENABLE, ··· 989 1000 pci_read_config_dword(dev, ITE_887x_POSIO0, &ioport); 990 1001 ioport &= 0xffff; 991 1002 release_region(ioport, ITE_887x_IOSIZE); 1003 + } 1004 + 1005 + /* 1006 + * EndRun Technologies. 1007 + * Determine the number of ports available on the device. 1008 + */ 1009 + #define PCI_VENDOR_ID_ENDRUN 0x7401 1010 + #define PCI_DEVICE_ID_ENDRUN_1588 0xe100 1011 + 1012 + static int pci_endrun_init(struct pci_dev *dev) 1013 + { 1014 + u8 __iomem *p; 1015 + unsigned long deviceID; 1016 + unsigned int number_uarts = 0; 1017 + 1018 + /* EndRun device is all 0xexxx */ 1019 + if (dev->vendor == PCI_VENDOR_ID_ENDRUN && 1020 + (dev->device & 0xf000) != 0xe000) 1021 + return 0; 1022 + 1023 + p = pci_iomap(dev, 0, 5); 1024 + if (p == NULL) 1025 + return -ENOMEM; 1026 + 1027 + deviceID = ioread32(p); 1028 + /* EndRun device */ 1029 + if (deviceID == 0x07000200) { 1030 + number_uarts = ioread8(p + 4); 1031 + dev_dbg(&dev->dev, 1032 + "%d ports detected on EndRun PCI Express device\n", 1033 + number_uarts); 1034 + } 1035 + pci_iounmap(dev, p); 1036 + return number_uarts; 992 1037 } 993 1038 994 1039 /* ··· 1554 1531 unsigned long iobase; 1555 1532 unsigned long ciobase = 0; 1556 1533 u8 config_base; 1534 + u32 bar_data[3]; 1557 1535 1558 1536 /* 1559 - * We are supposed to be able to read these from the PCI config space, 1560 - * but the values there don't seem to match what we need to use, so 1561 - * just use these hard-coded values for now, as they are correct. 1537 + * Find each UARTs offset in PCI configuraion space 1562 1538 */ 1563 1539 switch (idx) { 1564 - case 0: iobase = 0xe000; config_base = 0x40; break; 1565 - case 1: iobase = 0xe008; config_base = 0x48; break; 1566 - case 2: iobase = 0xe010; config_base = 0x50; break; 1567 - case 3: iobase = 0xe018; config_base = 0x58; break; 1568 - case 4: iobase = 0xe020; config_base = 0x60; break; 1569 - case 5: iobase = 0xe028; config_base = 0x68; break; 1570 - case 6: iobase = 0xe030; config_base = 0x70; break; 1571 - case 7: iobase = 0xe038; config_base = 0x78; break; 1572 - case 8: iobase = 0xe040; config_base = 0x80; break; 1573 - case 9: iobase = 0xe048; config_base = 0x88; break; 1574 - case 10: iobase = 0xe050; config_base = 0x90; break; 1575 - case 11: iobase = 0xe058; config_base = 0x98; break; 1540 + case 0: 1541 + config_base = 0x40; 1542 + break; 1543 + case 1: 1544 + config_base = 0x48; 1545 + break; 1546 + case 2: 1547 + config_base = 0x50; 1548 + break; 1549 + case 3: 1550 + config_base = 0x58; 1551 + break; 1552 + case 4: 1553 + config_base = 0x60; 1554 + break; 1555 + case 5: 1556 + config_base = 0x68; 1557 + break; 1558 + case 6: 1559 + config_base = 0x70; 1560 + break; 1561 + case 7: 1562 + config_base = 0x78; 1563 + break; 1564 + case 8: 1565 + config_base = 0x80; 1566 + break; 1567 + case 9: 1568 + config_base = 0x88; 1569 + break; 1570 + case 10: 1571 + config_base = 0x90; 1572 + break; 1573 + case 11: 1574 + config_base = 0x98; 1575 + break; 1576 1576 default: 1577 1577 /* Unknown number of ports, get out of here */ 1578 1578 return -EINVAL; ··· 1605 1559 base = pci_resource_start(priv->dev, 3); 1606 1560 ciobase = (int)(base + (0x8 * idx)); 1607 1561 } 1562 + 1563 + /* Get the io address dispatch from the BIOS */ 1564 + pci_read_config_dword(pdev, 0x24, &bar_data[0]); 1565 + pci_read_config_dword(pdev, 0x20, &bar_data[1]); 1566 + pci_read_config_dword(pdev, 0x1c, &bar_data[2]); 1567 + 1568 + /* Calculate Real IO Port */ 1569 + iobase = (bar_data[idx/4] & 0xffffffe0) + (idx % 4) * 8; 1608 1570 1609 1571 dev_dbg(&pdev->dev, "%s: idx=%d iobase=0x%lx ciobase=0x%lx config_base=0x%2x\n", 1610 1572 __func__, idx, iobase, ciobase, config_base); ··· 1814 1760 return pci_default_setup(priv, board, port, idx); 1815 1761 } 1816 1762 1763 + static int 1764 + pci_wch_ch382_setup(struct serial_private *priv, 1765 + const struct pciserial_board *board, 1766 + struct uart_8250_port *port, int idx) 1767 + { 1768 + port->port.flags |= UPF_FIXED_TYPE; 1769 + port->port.type = PORT_16850; 1770 + return pci_default_setup(priv, board, port, idx); 1771 + } 1772 + 1817 1773 #define PCI_VENDOR_ID_SBSMODULARIO 0x124B 1818 1774 #define PCI_SUBVENDOR_ID_SBSMODULARIO 0x124B 1819 1775 #define PCI_DEVICE_ID_OCTPRO 0x0001 ··· 1878 1814 #define PCI_VENDOR_ID_SUNIX 0x1fd4 1879 1815 #define PCI_DEVICE_ID_SUNIX_1999 0x1999 1880 1816 1817 + #define PCIE_VENDOR_ID_WCH 0x1c00 1818 + #define PCIE_DEVICE_ID_WCH_CH382_2S1P 0x3250 1881 1819 1882 1820 /* Unknown vendors/cards - this should not be in linux/pci_ids.h */ 1883 1821 #define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584 ··· 2412 2346 .setup = pci_netmos_9900_setup, 2413 2347 }, 2414 2348 /* 2349 + * EndRun Technologies 2350 + */ 2351 + { 2352 + .vendor = PCI_VENDOR_ID_ENDRUN, 2353 + .device = PCI_ANY_ID, 2354 + .subvendor = PCI_ANY_ID, 2355 + .subdevice = PCI_ANY_ID, 2356 + .init = pci_endrun_init, 2357 + .setup = pci_default_setup, 2358 + }, 2359 + /* 2415 2360 * For Oxford Semiconductor Tornado based devices 2416 2361 */ 2417 2362 { ··· 2570 2493 .subvendor = PCI_ANY_ID, 2571 2494 .subdevice = PCI_ANY_ID, 2572 2495 .setup = pci_wch_ch353_setup, 2496 + }, 2497 + /* WCH CH382 2S1P card (16750 clone) */ 2498 + { 2499 + .vendor = PCIE_VENDOR_ID_WCH, 2500 + .device = PCIE_DEVICE_ID_WCH_CH382_2S1P, 2501 + .subvendor = PCI_ANY_ID, 2502 + .subdevice = PCI_ANY_ID, 2503 + .setup = pci_wch_ch382_setup, 2573 2504 }, 2574 2505 /* 2575 2506 * ASIX devices with FIFO bug ··· 2839 2754 pbn_panacom2, 2840 2755 pbn_panacom4, 2841 2756 pbn_plx_romulus, 2757 + pbn_endrun_2_4000000, 2842 2758 pbn_oxsemi, 2843 2759 pbn_oxsemi_1_4000000, 2844 2760 pbn_oxsemi_2_4000000, ··· 3385 3299 }, 3386 3300 3387 3301 /* 3302 + * EndRun Technologies 3303 + * Uses the size of PCI Base region 0 to 3304 + * signal now many ports are available 3305 + * 2 port 952 Uart support 3306 + */ 3307 + [pbn_endrun_2_4000000] = { 3308 + .flags = FL_BASE0, 3309 + .num_ports = 2, 3310 + .base_baud = 4000000, 3311 + .uart_offset = 0x200, 3312 + .first_offset = 0x1000, 3313 + }, 3314 + 3315 + /* 3388 3316 * This board uses the size of PCI Base region 0 to 3389 3317 * signal now many ports are available 3390 3318 */ ··· 3686 3586 /* multi-io cards handled by parport_serial */ 3687 3587 { PCI_DEVICE(0x4348, 0x7053), }, /* WCH CH353 2S1P */ 3688 3588 { PCI_DEVICE(0x4348, 0x5053), }, /* WCH CH353 1S1P */ 3589 + { PCI_DEVICE(0x1c00, 0x3250), }, /* WCH CH382 2S1P */ 3689 3590 }; 3690 3591 3691 3592 /* ··· 4271 4170 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_ROMULUS, 4272 4171 0x10b5, 0x106a, 0, 0, 4273 4172 pbn_plx_romulus }, 4173 + /* 4174 + * EndRun Technologies. PCI express device range. 4175 + * EndRun PTP/1588 has 2 Native UARTs. 4176 + */ 4177 + { PCI_VENDOR_ID_ENDRUN, PCI_DEVICE_ID_ENDRUN_1588, 4178 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4179 + pbn_endrun_2_4000000 }, 4274 4180 /* 4275 4181 * Quatech cards. These actually have configurable clocks but for 4276 4182 * now we just use the default.
+10 -1
drivers/tty/serial/8250/Kconfig
··· 293 293 294 294 config SERIAL_8250_RT288X 295 295 bool "Ralink RT288x/RT305x/RT3662/RT3883 serial port support" 296 - depends on SERIAL_8250 && (SOC_RT288X || SOC_RT305X || SOC_RT3883) 296 + depends on SERIAL_8250 && (SOC_RT288X || SOC_RT305X || SOC_RT3883 || SOC_MT7620) 297 297 help 298 298 If you have a Ralink RT288x/RT305x SoC based board and want to use the 299 299 serial port, say Y to this option. The driver can handle up to 2 serial 300 300 ports. If unsure, say N. 301 + 302 + config SERIAL_8250_OMAP 303 + tristate "Support for OMAP internal UART (8250 based driver)" 304 + depends on SERIAL_8250 && ARCH_OMAP2PLUS 305 + help 306 + If you have a machine based on an Texas Instruments OMAP CPU you 307 + can enable its onboard serial ports by enabling this option. 308 + 309 + This driver uses ttyS instead of ttyO. 301 310 302 311 config SERIAL_8250_FINTEK 303 312 tristate "Support for Fintek F81216A LPC to 4 UART"
+1
drivers/tty/serial/8250/Makefile
··· 20 20 obj-$(CONFIG_SERIAL_8250_FSL) += 8250_fsl.o 21 21 obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o 22 22 obj-$(CONFIG_SERIAL_8250_EM) += 8250_em.o 23 + obj-$(CONFIG_SERIAL_8250_OMAP) += 8250_omap.o 23 24 obj-$(CONFIG_SERIAL_8250_FINTEK) += 8250_fintek.o 24 25 obj-$(CONFIG_SERIAL_8250_MT6577) += 8250_mtk.o
+14 -10
drivers/tty/serial/Kconfig
··· 1029 1029 a console on a serial port, say Y. Otherwise, say N. 1030 1030 1031 1031 config SERIAL_JSM 1032 - tristate "Digi International NEO PCI Support" 1032 + tristate "Digi International NEO and Classic PCI Support" 1033 1033 depends on PCI 1034 1034 select SERIAL_CORE 1035 1035 help 1036 - This is a driver for Digi International's Neo series 1036 + This is a driver for Digi International's Neo and Classic series 1037 1037 of cards which provide multiple serial ports. You would need 1038 1038 something like this to connect more than two modems to your Linux 1039 1039 box, for instance in order to become a dial-in server. This driver ··· 1281 1281 Add support for UART controller on timberdale. 1282 1282 1283 1283 config SERIAL_BCM63XX 1284 - tristate "bcm63xx serial port support" 1284 + tristate "Broadcom BCM63xx/BCM33xx UART support" 1285 1285 select SERIAL_CORE 1286 - depends on BCM63XX 1286 + depends on MIPS || ARM || COMPILE_TEST 1287 1287 help 1288 - If you have a bcm63xx CPU, you can enable its onboard 1289 - serial port by enabling this options. 1288 + This enables the driver for the onchip UART core found on 1289 + the following chipsets: 1290 1290 1291 - To compile this driver as a module, choose M here: the 1292 - module will be called bcm963xx_uart. 1291 + BCM33xx (cable modem) 1292 + BCM63xx/BCM63xxx (DSL) 1293 + BCM68xx (PON) 1294 + BCM7xxx (STB) - DOCSIS console 1293 1295 1294 1296 config SERIAL_BCM63XX_CONSOLE 1295 - bool "Console on bcm63xx serial port" 1297 + bool "Console on BCM63xx serial port" 1296 1298 depends on SERIAL_BCM63XX=y 1297 1299 select SERIAL_CORE_CONSOLE 1300 + select SERIAL_EARLYCON 1298 1301 help 1299 - If you have enabled the serial port on the bcm63xx CPU 1302 + If you have enabled the serial port on the BCM63xx CPU 1300 1303 you can make it the console by answering Y to this option. 1301 1304 1302 1305 config SERIAL_GRLIB_GAISLER_APBUART ··· 1411 1408 depends on ARCH_MXS 1412 1409 tristate "MXS AUART support" 1413 1410 select SERIAL_CORE 1411 + select SERIAL_MCTRL_GPIO if GPIOLIB 1414 1412 help 1415 1413 This driver supports the MXS Application UART (AUART) port. 1416 1414
+45 -15
drivers/tty/serial/amba-pl010.c
··· 75 75 76 76 static void pl010_stop_tx(struct uart_port *port) 77 77 { 78 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 78 + struct uart_amba_port *uap = 79 + container_of(port, struct uart_amba_port, port); 79 80 unsigned int cr; 80 81 81 82 cr = readb(uap->port.membase + UART010_CR); ··· 86 85 87 86 static void pl010_start_tx(struct uart_port *port) 88 87 { 89 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 88 + struct uart_amba_port *uap = 89 + container_of(port, struct uart_amba_port, port); 90 90 unsigned int cr; 91 91 92 92 cr = readb(uap->port.membase + UART010_CR); ··· 97 95 98 96 static void pl010_stop_rx(struct uart_port *port) 99 97 { 100 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 98 + struct uart_amba_port *uap = 99 + container_of(port, struct uart_amba_port, port); 101 100 unsigned int cr; 102 101 103 102 cr = readb(uap->port.membase + UART010_CR); ··· 106 103 writel(cr, uap->port.membase + UART010_CR); 107 104 } 108 105 109 - static void pl010_enable_ms(struct uart_port *port) 106 + static void pl010_disable_ms(struct uart_port *port) 110 107 { 111 108 struct uart_amba_port *uap = (struct uart_amba_port *)port; 109 + unsigned int cr; 110 + 111 + cr = readb(uap->port.membase + UART010_CR); 112 + cr &= ~UART010_CR_MSIE; 113 + writel(cr, uap->port.membase + UART010_CR); 114 + } 115 + 116 + static void pl010_enable_ms(struct uart_port *port) 117 + { 118 + struct uart_amba_port *uap = 119 + container_of(port, struct uart_amba_port, port); 112 120 unsigned int cr; 113 121 114 122 cr = readb(uap->port.membase + UART010_CR); ··· 273 259 274 260 static unsigned int pl010_tx_empty(struct uart_port *port) 275 261 { 276 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 262 + struct uart_amba_port *uap = 263 + container_of(port, struct uart_amba_port, port); 277 264 unsigned int status = readb(uap->port.membase + UART01x_FR); 278 265 return status & UART01x_FR_BUSY ? 0 : TIOCSER_TEMT; 279 266 } 280 267 281 268 static unsigned int pl010_get_mctrl(struct uart_port *port) 282 269 { 283 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 270 + struct uart_amba_port *uap = 271 + container_of(port, struct uart_amba_port, port); 284 272 unsigned int result = 0; 285 273 unsigned int status; 286 274 ··· 299 283 300 284 static void pl010_set_mctrl(struct uart_port *port, unsigned int mctrl) 301 285 { 302 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 286 + struct uart_amba_port *uap = 287 + container_of(port, struct uart_amba_port, port); 303 288 304 289 if (uap->data) 305 290 uap->data->set_mctrl(uap->dev, uap->port.membase, mctrl); ··· 308 291 309 292 static void pl010_break_ctl(struct uart_port *port, int break_state) 310 293 { 311 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 294 + struct uart_amba_port *uap = 295 + container_of(port, struct uart_amba_port, port); 312 296 unsigned long flags; 313 297 unsigned int lcr_h; 314 298 ··· 325 307 326 308 static int pl010_startup(struct uart_port *port) 327 309 { 328 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 310 + struct uart_amba_port *uap = 311 + container_of(port, struct uart_amba_port, port); 329 312 int retval; 330 313 331 314 /* ··· 366 347 367 348 static void pl010_shutdown(struct uart_port *port) 368 349 { 369 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 350 + struct uart_amba_port *uap = 351 + container_of(port, struct uart_amba_port, port); 370 352 371 353 /* 372 354 * Free the interrupt ··· 394 374 pl010_set_termios(struct uart_port *port, struct ktermios *termios, 395 375 struct ktermios *old) 396 376 { 397 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 377 + struct uart_amba_port *uap = 378 + container_of(port, struct uart_amba_port, port); 398 379 unsigned int lcr_h, old_cr; 399 380 unsigned long flags; 400 381 unsigned int baud, quot; ··· 489 468 spin_unlock_irqrestore(&uap->port.lock, flags); 490 469 } 491 470 492 - static void pl010_set_ldisc(struct uart_port *port, int new) 471 + static void pl010_set_ldisc(struct uart_port *port, struct ktermios *termios) 493 472 { 494 - if (new == N_PPS) { 473 + if (termios->c_line == N_PPS) { 495 474 port->flags |= UPF_HARDPPS_CD; 475 + spin_lock_irq(&port->lock); 496 476 pl010_enable_ms(port); 497 - } else 477 + spin_unlock_irq(&port->lock); 478 + } else { 498 479 port->flags &= ~UPF_HARDPPS_CD; 480 + if (!UART_ENABLE_MS(port, termios->c_cflag)) { 481 + spin_lock_irq(&port->lock); 482 + pl010_disable_ms(port); 483 + spin_unlock_irq(&port->lock); 484 + } 485 + } 499 486 } 500 487 501 488 static const char *pl010_type(struct uart_port *port) ··· 580 551 581 552 static void pl010_console_putchar(struct uart_port *port, int ch) 582 553 { 583 - struct uart_amba_port *uap = (struct uart_amba_port *)port; 554 + struct uart_amba_port *uap = 555 + container_of(port, struct uart_amba_port, port); 584 556 unsigned int status; 585 557 586 558 do {
+42 -4
drivers/tty/serial/amba-pl011.c
··· 246 246 sg_set_page(&sg->sg, phys_to_page(dma_addr), 247 247 PL011_DMA_BUFFER_SIZE, offset_in_page(dma_addr)); 248 248 sg_dma_address(&sg->sg) = dma_addr; 249 + sg_dma_len(&sg->sg) = PL011_DMA_BUFFER_SIZE; 249 250 250 251 return 0; 251 252 } ··· 322 321 .src_maxburst = uap->fifosize >> 2, 323 322 .device_fc = false, 324 323 }; 324 + struct dma_slave_caps caps; 325 325 326 + /* 327 + * Some DMA controllers provide information on their capabilities. 328 + * If the controller does, check for suitable residue processing 329 + * otherwise assime all is well. 330 + */ 331 + if (0 == dma_get_slave_caps(chan, &caps)) { 332 + if (caps.residue_granularity == 333 + DMA_RESIDUE_GRANULARITY_DESCRIPTOR) { 334 + dma_release_channel(chan); 335 + dev_info(uap->port.dev, 336 + "RX DMA disabled - no residue processing\n"); 337 + return; 338 + } 339 + } 326 340 dmaengine_slave_config(chan, &rx_conf); 327 341 uap->dmarx.chan = chan; 328 342 343 + uap->dmarx.auto_poll_rate = false; 329 344 if (plat && plat->dma_rx_poll_enable) { 330 345 /* Set poll rate if specified. */ 331 346 if (plat->dma_rx_poll_rate) { ··· 362 345 plat->dma_rx_poll_timeout; 363 346 else 364 347 uap->dmarx.poll_timeout = 3000; 365 - } else 366 - uap->dmarx.auto_poll_rate = false; 348 + } else if (!plat && dev->of_node) { 349 + uap->dmarx.auto_poll_rate = of_property_read_bool( 350 + dev->of_node, "auto-poll"); 351 + if (uap->dmarx.auto_poll_rate) { 352 + u32 x; 367 353 354 + if (0 == of_property_read_u32(dev->of_node, 355 + "poll-rate-ms", &x)) 356 + uap->dmarx.poll_rate = x; 357 + else 358 + uap->dmarx.poll_rate = 100; 359 + if (0 == of_property_read_u32(dev->of_node, 360 + "poll-timeout-ms", &x)) 361 + uap->dmarx.poll_timeout = x; 362 + else 363 + uap->dmarx.poll_timeout = 3000; 364 + } 365 + } 368 366 dev_info(uap->port.dev, "DMA channel RX %s\n", 369 367 dma_chan_name(uap->dmarx.chan)); 370 368 } ··· 533 501 memcpy(&dmatx->buf[0], &xmit->buf[xmit->tail], count); 534 502 else { 535 503 size_t first = UART_XMIT_SIZE - xmit->tail; 536 - size_t second = xmit->head; 504 + size_t second; 505 + 506 + if (first > count) 507 + first = count; 508 + second = count - first; 537 509 538 510 memcpy(&dmatx->buf[0], &xmit->buf[xmit->tail], first); 539 511 if (second) ··· 1024 988 if (!uap->dmatx.chan) 1025 989 return; 1026 990 1027 - uap->dmatx.buf = kmalloc(PL011_DMA_BUFFER_SIZE, GFP_KERNEL); 991 + uap->dmatx.buf = kmalloc(PL011_DMA_BUFFER_SIZE, GFP_KERNEL | __GFP_DMA); 1028 992 if (!uap->dmatx.buf) { 1029 993 dev_err(uap->port.dev, "no memory for DMA TX buffer\n"); 1030 994 uap->port.fifosize = uap->fifosize; ··· 1725 1689 plat->exit(); 1726 1690 } 1727 1691 1692 + if (uap->port.ops->flush_buffer) 1693 + uap->port.ops->flush_buffer(port); 1728 1694 } 1729 1695 1730 1696 static void
+20 -10
drivers/tty/serial/ar933x_uart.c
··· 119 119 120 120 static unsigned int ar933x_uart_tx_empty(struct uart_port *port) 121 121 { 122 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 122 + struct ar933x_uart_port *up = 123 + container_of(port, struct ar933x_uart_port, port); 123 124 unsigned long flags; 124 125 unsigned int rdata; 125 126 ··· 142 141 143 142 static void ar933x_uart_start_tx(struct uart_port *port) 144 143 { 145 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 144 + struct ar933x_uart_port *up = 145 + container_of(port, struct ar933x_uart_port, port); 146 146 147 147 ar933x_uart_start_tx_interrupt(up); 148 148 } 149 149 150 150 static void ar933x_uart_stop_tx(struct uart_port *port) 151 151 { 152 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 152 + struct ar933x_uart_port *up = 153 + container_of(port, struct ar933x_uart_port, port); 153 154 154 155 ar933x_uart_stop_tx_interrupt(up); 155 156 } 156 157 157 158 static void ar933x_uart_stop_rx(struct uart_port *port) 158 159 { 159 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 160 + struct ar933x_uart_port *up = 161 + container_of(port, struct ar933x_uart_port, port); 160 162 161 163 up->ier &= ~AR933X_UART_INT_RX_VALID; 162 164 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier); ··· 167 163 168 164 static void ar933x_uart_break_ctl(struct uart_port *port, int break_state) 169 165 { 170 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 166 + struct ar933x_uart_port *up = 167 + container_of(port, struct ar933x_uart_port, port); 171 168 unsigned long flags; 172 169 173 170 spin_lock_irqsave(&up->port.lock, flags); ··· 236 231 struct ktermios *new, 237 232 struct ktermios *old) 238 233 { 239 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 234 + struct ar933x_uart_port *up = 235 + container_of(port, struct ar933x_uart_port, port); 240 236 unsigned int cs; 241 237 unsigned long flags; 242 238 unsigned int baud, scale, step; ··· 410 404 411 405 static int ar933x_uart_startup(struct uart_port *port) 412 406 { 413 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 407 + struct ar933x_uart_port *up = 408 + container_of(port, struct ar933x_uart_port, port); 414 409 unsigned long flags; 415 410 int ret; 416 411 ··· 437 430 438 431 static void ar933x_uart_shutdown(struct uart_port *port) 439 432 { 440 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 433 + struct ar933x_uart_port *up = 434 + container_of(port, struct ar933x_uart_port, port); 441 435 442 436 /* Disable all interrupts */ 443 437 up->ier = 0; ··· 476 468 static int ar933x_uart_verify_port(struct uart_port *port, 477 469 struct serial_struct *ser) 478 470 { 479 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 471 + struct ar933x_uart_port *up = 472 + container_of(port, struct ar933x_uart_port, port); 480 473 481 474 if (ser->type != PORT_UNKNOWN && 482 475 ser->type != PORT_AR933X) ··· 530 521 531 522 static void ar933x_uart_console_putchar(struct uart_port *port, int ch) 532 523 { 533 - struct ar933x_uart_port *up = (struct ar933x_uart_port *) port; 524 + struct ar933x_uart_port *up = 525 + container_of(port, struct ar933x_uart_port, port); 534 526 535 527 ar933x_uart_wait_xmitr(up); 536 528 ar933x_uart_putc(up, ch);
+112 -122
drivers/tty/serial/atmel_serial.c
··· 167 167 168 168 struct circ_buf rx_ring; 169 169 170 - struct serial_rs485 rs485; /* rs485 settings */ 171 170 struct mctrl_gpios *gpios; 172 171 int gpio_irq[UART_GPIO_MAX]; 173 172 unsigned int tx_done_mask; ··· 289 290 } 290 291 291 292 /* Enable or disable the rs485 support */ 292 - void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) 293 + static int atmel_config_rs485(struct uart_port *port, 294 + struct serial_rs485 *rs485conf) 293 295 { 294 296 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 295 297 unsigned int mode; 296 - unsigned long flags; 297 - 298 - spin_lock_irqsave(&port->lock, flags); 299 298 300 299 /* Disable interrupts */ 301 300 UART_PUT_IDR(port, atmel_port->tx_done_mask); ··· 303 306 /* Resetting serial mode to RS232 (0x0) */ 304 307 mode &= ~ATMEL_US_USMODE; 305 308 306 - atmel_port->rs485 = *rs485conf; 309 + port->rs485 = *rs485conf; 307 310 308 311 if (rs485conf->flags & SER_RS485_ENABLED) { 309 312 dev_dbg(port->dev, "Setting UART to RS485\n"); ··· 324 327 /* Enable interrupts */ 325 328 UART_PUT_IER(port, atmel_port->tx_done_mask); 326 329 327 - spin_unlock_irqrestore(&port->lock, flags); 328 - 330 + return 0; 329 331 } 330 332 331 333 /* ··· 368 372 /* Resetting serial mode to RS232 (0x0) */ 369 373 mode &= ~ATMEL_US_USMODE; 370 374 371 - if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 375 + if (port->rs485.flags & SER_RS485_ENABLED) { 372 376 dev_dbg(port->dev, "Setting UART to RS485\n"); 373 - if ((atmel_port->rs485.delay_rts_after_send) > 0) 374 - UART_PUT_TTGR(port, 375 - atmel_port->rs485.delay_rts_after_send); 377 + if ((port->rs485.delay_rts_after_send) > 0) 378 + UART_PUT_TTGR(port, port->rs485.delay_rts_after_send); 376 379 mode |= ATMEL_US_USMODE_RS485; 377 380 } else { 378 381 dev_dbg(port->dev, "Setting UART to RS232\n"); ··· 418 423 /* Disable interrupts */ 419 424 UART_PUT_IDR(port, atmel_port->tx_done_mask); 420 425 421 - if ((atmel_port->rs485.flags & SER_RS485_ENABLED) && 422 - !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX)) 426 + if ((port->rs485.flags & SER_RS485_ENABLED) && 427 + !(port->rs485.flags & SER_RS485_RX_DURING_TX)) 423 428 atmel_start_rx(port); 424 429 } 425 430 ··· 436 441 really need this.*/ 437 442 return; 438 443 439 - if ((atmel_port->rs485.flags & SER_RS485_ENABLED) && 440 - !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX)) 444 + if ((port->rs485.flags & SER_RS485_ENABLED) && 445 + !(port->rs485.flags & SER_RS485_RX_DURING_TX)) 441 446 atmel_stop_rx(port); 442 447 443 448 /* re-enable PDC transmit */ ··· 802 807 atmel_port->cookie_tx = dmaengine_submit(desc); 803 808 804 809 } else { 805 - if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 810 + if (port->rs485.flags & SER_RS485_ENABLED) { 806 811 /* DMA done, stop TX, start RX for RS485 */ 807 812 atmel_start_rx(port); 808 813 } ··· 857 862 config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 858 863 config.dst_addr = port->mapbase + ATMEL_US_THR; 859 864 860 - ret = dmaengine_device_control(atmel_port->chan_tx, 861 - DMA_SLAVE_CONFIG, 862 - (unsigned long)&config); 865 + ret = dmaengine_slave_config(atmel_port->chan_tx, 866 + &config); 863 867 if (ret) { 864 868 dev_err(port->dev, "DMA tx slave configuration failed\n"); 865 869 goto chan_err; ··· 872 878 if (atmel_port->chan_tx) 873 879 atmel_release_tx_dma(port); 874 880 return -EINVAL; 875 - } 876 - 877 - static void atmel_flip_buffer_rx_dma(struct uart_port *port, 878 - char *buf, size_t count) 879 - { 880 - struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 881 - struct tty_port *tport = &port->state->port; 882 - 883 - dma_sync_sg_for_cpu(port->dev, 884 - &atmel_port->sg_rx, 885 - 1, 886 - DMA_DEV_TO_MEM); 887 - 888 - tty_insert_flip_string(tport, buf, count); 889 - 890 - dma_sync_sg_for_device(port->dev, 891 - &atmel_port->sg_rx, 892 - 1, 893 - DMA_DEV_TO_MEM); 894 - /* 895 - * Drop the lock here since it might end up calling 896 - * uart_start(), which takes the lock. 897 - */ 898 - spin_unlock(&port->lock); 899 - tty_flip_buffer_push(tport); 900 - spin_lock(&port->lock); 901 881 } 902 882 903 883 static void atmel_complete_rx_dma(void *arg) ··· 902 934 static void atmel_rx_from_dma(struct uart_port *port) 903 935 { 904 936 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 937 + struct tty_port *tport = &port->state->port; 905 938 struct circ_buf *ring = &atmel_port->rx_ring; 906 939 struct dma_chan *chan = atmel_port->chan_rx; 907 940 struct dma_tx_state state; 908 941 enum dma_status dmastat; 909 - size_t pending, count; 942 + size_t count; 910 943 911 944 912 945 /* Reset the UART timeout early so that we don't miss one */ ··· 922 953 tasklet_schedule(&atmel_port->tasklet); 923 954 return; 924 955 } 925 - /* current transfer size should no larger than dma buffer */ 926 - pending = sg_dma_len(&atmel_port->sg_rx) - state.residue; 927 - BUG_ON(pending > sg_dma_len(&atmel_port->sg_rx)); 956 + 957 + /* CPU claims ownership of RX DMA buffer */ 958 + dma_sync_sg_for_cpu(port->dev, 959 + &atmel_port->sg_rx, 960 + 1, 961 + DMA_DEV_TO_MEM); 928 962 929 963 /* 930 - * This will take the chars we have so far, 931 - * ring->head will record the transfer size, only new bytes come 932 - * will insert into the framework. 964 + * ring->head points to the end of data already written by the DMA. 965 + * ring->tail points to the beginning of data to be read by the 966 + * framework. 967 + * The current transfer size should not be larger than the dma buffer 968 + * length. 933 969 */ 934 - if (pending > ring->head) { 935 - count = pending - ring->head; 970 + ring->head = sg_dma_len(&atmel_port->sg_rx) - state.residue; 971 + BUG_ON(ring->head > sg_dma_len(&atmel_port->sg_rx)); 972 + /* 973 + * At this point ring->head may point to the first byte right after the 974 + * last byte of the dma buffer: 975 + * 0 <= ring->head <= sg_dma_len(&atmel_port->sg_rx) 976 + * 977 + * However ring->tail must always points inside the dma buffer: 978 + * 0 <= ring->tail <= sg_dma_len(&atmel_port->sg_rx) - 1 979 + * 980 + * Since we use a ring buffer, we have to handle the case 981 + * where head is lower than tail. In such a case, we first read from 982 + * tail to the end of the buffer then reset tail. 983 + */ 984 + if (ring->head < ring->tail) { 985 + count = sg_dma_len(&atmel_port->sg_rx) - ring->tail; 936 986 937 - atmel_flip_buffer_rx_dma(port, ring->buf + ring->head, count); 938 - 939 - ring->head += count; 940 - if (ring->head == sg_dma_len(&atmel_port->sg_rx)) 941 - ring->head = 0; 942 - 987 + tty_insert_flip_string(tport, ring->buf + ring->tail, count); 988 + ring->tail = 0; 943 989 port->icount.rx += count; 944 990 } 991 + 992 + /* Finally we read data from tail to head */ 993 + if (ring->tail < ring->head) { 994 + count = ring->head - ring->tail; 995 + 996 + tty_insert_flip_string(tport, ring->buf + ring->tail, count); 997 + /* Wrap ring->head if needed */ 998 + if (ring->head >= sg_dma_len(&atmel_port->sg_rx)) 999 + ring->head = 0; 1000 + ring->tail = ring->head; 1001 + port->icount.rx += count; 1002 + } 1003 + 1004 + /* USART retreives ownership of RX DMA buffer */ 1005 + dma_sync_sg_for_device(port->dev, 1006 + &atmel_port->sg_rx, 1007 + 1, 1008 + DMA_DEV_TO_MEM); 1009 + 1010 + /* 1011 + * Drop the lock here since it might end up calling 1012 + * uart_start(), which takes the lock. 1013 + */ 1014 + spin_unlock(&port->lock); 1015 + tty_flip_buffer_push(tport); 1016 + spin_lock(&port->lock); 945 1017 946 1018 UART_PUT_IER(port, ATMEL_US_TIMEOUT); 947 1019 } ··· 1036 1026 config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 1037 1027 config.src_addr = port->mapbase + ATMEL_US_RHR; 1038 1028 1039 - ret = dmaengine_device_control(atmel_port->chan_rx, 1040 - DMA_SLAVE_CONFIG, 1041 - (unsigned long)&config); 1029 + ret = dmaengine_slave_config(atmel_port->chan_rx, 1030 + &config); 1042 1031 if (ret) { 1043 1032 dev_err(port->dev, "DMA rx slave configuration failed\n"); 1044 1033 goto chan_err; ··· 1249 1240 /* Enable interrupts */ 1250 1241 UART_PUT_IER(port, atmel_port->tx_done_mask); 1251 1242 } else { 1252 - if ((atmel_port->rs485.flags & SER_RS485_ENABLED) && 1253 - !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX)) { 1243 + if ((port->rs485.flags & SER_RS485_ENABLED) && 1244 + !(port->rs485.flags & SER_RS485_RX_DURING_TX)) { 1254 1245 /* DMA done, stop TX, start RX for RS485 */ 1255 1246 atmel_start_rx(port); 1256 1247 } ··· 1561 1552 return 0; 1562 1553 } 1563 1554 1564 - static void atmel_init_rs485(struct atmel_uart_port *atmel_port, 1555 + static void atmel_init_rs485(struct uart_port *port, 1565 1556 struct platform_device *pdev) 1566 1557 { 1567 1558 struct device_node *np = pdev->dev.of_node; ··· 1572 1563 /* rs485 properties */ 1573 1564 if (of_property_read_u32_array(np, "rs485-rts-delay", 1574 1565 rs485_delay, 2) == 0) { 1575 - struct serial_rs485 *rs485conf = &atmel_port->rs485; 1566 + struct serial_rs485 *rs485conf = &port->rs485; 1576 1567 1577 1568 rs485conf->delay_rts_before_send = rs485_delay[0]; 1578 1569 rs485conf->delay_rts_after_send = rs485_delay[1]; ··· 1586 1577 rs485conf->flags |= SER_RS485_ENABLED; 1587 1578 } 1588 1579 } else { 1589 - atmel_port->rs485 = pdata->rs485; 1580 + port->rs485 = pdata->rs485; 1590 1581 } 1591 1582 1592 1583 } ··· 1811 1802 } 1812 1803 1813 1804 /* 1805 + * Flush any TX data submitted for DMA. Called when the TX circular 1806 + * buffer is reset. 1807 + */ 1808 + static void atmel_flush_buffer(struct uart_port *port) 1809 + { 1810 + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 1811 + 1812 + if (atmel_use_pdc_tx(port)) { 1813 + UART_PUT_TCR(port, 0); 1814 + atmel_port->pdc_tx.ofs = 0; 1815 + } 1816 + } 1817 + 1818 + /* 1814 1819 * Disable the port 1815 1820 */ 1816 1821 static void atmel_shutdown(struct uart_port *port) ··· 1875 1852 atmel_free_gpio_irq(port); 1876 1853 1877 1854 atmel_port->ms_irq_enabled = false; 1878 - } 1879 1855 1880 - /* 1881 - * Flush any TX data submitted for DMA. Called when the TX circular 1882 - * buffer is reset. 1883 - */ 1884 - static void atmel_flush_buffer(struct uart_port *port) 1885 - { 1886 - struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 1887 - 1888 - if (atmel_use_pdc_tx(port)) { 1889 - UART_PUT_TCR(port, 0); 1890 - atmel_port->pdc_tx.ofs = 0; 1891 - } 1856 + atmel_flush_buffer(port); 1892 1857 } 1893 1858 1894 1859 /* ··· 1922 1911 { 1923 1912 unsigned long flags; 1924 1913 unsigned int mode, imr, quot, baud; 1925 - struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 1926 1914 1927 1915 /* Get current mode register */ 1928 1916 mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL ··· 2023 2013 /* Resetting serial mode to RS232 (0x0) */ 2024 2014 mode &= ~ATMEL_US_USMODE; 2025 2015 2026 - if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 2027 - if ((atmel_port->rs485.delay_rts_after_send) > 0) 2028 - UART_PUT_TTGR(port, 2029 - atmel_port->rs485.delay_rts_after_send); 2016 + if (port->rs485.flags & SER_RS485_ENABLED) { 2017 + if ((port->rs485.delay_rts_after_send) > 0) 2018 + UART_PUT_TTGR(port, port->rs485.delay_rts_after_send); 2030 2019 mode |= ATMEL_US_USMODE_RS485; 2031 2020 } 2032 2021 ··· 2049 2040 spin_unlock_irqrestore(&port->lock, flags); 2050 2041 } 2051 2042 2052 - static void atmel_set_ldisc(struct uart_port *port, int new) 2043 + static void atmel_set_ldisc(struct uart_port *port, struct ktermios *termios) 2053 2044 { 2054 - if (new == N_PPS) { 2045 + if (termios->c_line == N_PPS) { 2055 2046 port->flags |= UPF_HARDPPS_CD; 2047 + spin_lock_irq(&port->lock); 2056 2048 atmel_enable_ms(port); 2049 + spin_unlock_irq(&port->lock); 2057 2050 } else { 2058 2051 port->flags &= ~UPF_HARDPPS_CD; 2052 + if (!UART_ENABLE_MS(port, termios->c_cflag)) { 2053 + spin_lock_irq(&port->lock); 2054 + atmel_disable_ms(port); 2055 + spin_unlock_irq(&port->lock); 2056 + } 2059 2057 } 2060 2058 } 2061 2059 ··· 2164 2148 } 2165 2149 #endif 2166 2150 2167 - static int 2168 - atmel_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg) 2169 - { 2170 - struct serial_rs485 rs485conf; 2171 - 2172 - switch (cmd) { 2173 - case TIOCSRS485: 2174 - if (copy_from_user(&rs485conf, (struct serial_rs485 *) arg, 2175 - sizeof(rs485conf))) 2176 - return -EFAULT; 2177 - 2178 - atmel_config_rs485(port, &rs485conf); 2179 - break; 2180 - 2181 - case TIOCGRS485: 2182 - if (copy_to_user((struct serial_rs485 *) arg, 2183 - &(to_atmel_uart_port(port)->rs485), 2184 - sizeof(rs485conf))) 2185 - return -EFAULT; 2186 - break; 2187 - 2188 - default: 2189 - return -ENOIOCTLCMD; 2190 - } 2191 - return 0; 2192 - } 2193 - 2194 - 2195 - 2196 2151 static struct uart_ops atmel_pops = { 2197 2152 .tx_empty = atmel_tx_empty, 2198 2153 .set_mctrl = atmel_set_mctrl, ··· 2184 2197 .config_port = atmel_config_port, 2185 2198 .verify_port = atmel_verify_port, 2186 2199 .pm = atmel_serial_pm, 2187 - .ioctl = atmel_ioctl, 2188 2200 #ifdef CONFIG_CONSOLE_POLL 2189 2201 .poll_get_char = atmel_poll_get_char, 2190 2202 .poll_put_char = atmel_poll_put_char, ··· 2203 2217 if (!atmel_init_property(atmel_port, pdev)) 2204 2218 atmel_set_ops(port); 2205 2219 2206 - atmel_init_rs485(atmel_port, pdev); 2220 + atmel_init_rs485(port, pdev); 2207 2221 2208 2222 port->iotype = UPIO_MEM; 2209 2223 port->flags = UPF_BOOT_AUTOCONF; ··· 2212 2226 port->dev = &pdev->dev; 2213 2227 port->mapbase = pdev->resource[0].start; 2214 2228 port->irq = pdev->resource[1].start; 2229 + port->rs485_config = atmel_config_rs485; 2215 2230 2216 2231 tasklet_init(&atmel_port->tasklet, atmel_tasklet_func, 2217 2232 (unsigned long)port); ··· 2247 2260 } 2248 2261 2249 2262 /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */ 2250 - if (atmel_port->rs485.flags & SER_RS485_ENABLED) 2263 + if (port->rs485.flags & SER_RS485_ENABLED) 2251 2264 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; 2252 2265 else if (atmel_use_pdc_tx(port)) { 2253 2266 port->fifosize = PDC_BUFFER_SIZE; ··· 2528 2541 struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev); 2529 2542 void *data; 2530 2543 int ret = -ENODEV; 2544 + bool rs485_enabled; 2531 2545 2532 2546 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1)); 2533 2547 ··· 2576 2588 port->rx_ring.buf = data; 2577 2589 } 2578 2590 2591 + rs485_enabled = port->uart.rs485.flags & SER_RS485_ENABLED; 2592 + 2579 2593 ret = uart_add_one_port(&atmel_uart, &port->uart); 2580 2594 if (ret) 2581 2595 goto err_add_port; ··· 2596 2606 device_init_wakeup(&pdev->dev, 1); 2597 2607 platform_set_drvdata(pdev, port); 2598 2608 2599 - if (port->rs485.flags & SER_RS485_ENABLED) { 2609 + if (rs485_enabled) { 2600 2610 UART_PUT_MR(&port->uart, ATMEL_US_USMODE_NORMAL); 2601 2611 UART_PUT_CR(&port->uart, ATMEL_US_RTSEN); 2602 2612 }
+33 -22
drivers/tty/serial/bcm63xx_uart.c
··· 588 588 */ 589 589 static int bcm_uart_request_port(struct uart_port *port) 590 590 { 591 - unsigned int size; 592 - 593 - size = UART_REG_SIZE; 594 - if (!request_mem_region(port->mapbase, size, "bcm63xx")) { 595 - dev_err(port->dev, "Memory region busy\n"); 596 - return -EBUSY; 597 - } 598 - 599 - port->membase = ioremap(port->mapbase, size); 600 - if (!port->membase) { 601 - dev_err(port->dev, "Unable to map registers\n"); 602 - release_mem_region(port->mapbase, size); 603 - return -EBUSY; 604 - } 591 + /* UARTs always present */ 605 592 return 0; 606 593 } 607 594 ··· 597 610 */ 598 611 static void bcm_uart_release_port(struct uart_port *port) 599 612 { 600 - release_mem_region(port->mapbase, UART_REG_SIZE); 601 - iounmap(port->membase); 613 + /* Nothing to release ... */ 602 614 } 603 615 604 616 /* ··· 768 782 769 783 console_initcall(bcm63xx_console_init); 770 784 785 + static void bcm_early_write(struct console *con, const char *s, unsigned n) 786 + { 787 + struct earlycon_device *dev = con->data; 788 + 789 + uart_console_write(&dev->port, s, n, bcm_console_putchar); 790 + wait_for_xmitr(&dev->port); 791 + } 792 + 793 + static int __init bcm_early_console_setup(struct earlycon_device *device, 794 + const char *opt) 795 + { 796 + if (!device->port.membase) 797 + return -ENODEV; 798 + 799 + device->con->write = bcm_early_write; 800 + return 0; 801 + } 802 + 803 + OF_EARLYCON_DECLARE(bcm63xx_uart, "brcm,bcm6345-uart", bcm_early_console_setup); 804 + 771 805 #define BCM63XX_CONSOLE (&bcm63xx_console) 772 806 #else 773 807 #define BCM63XX_CONSOLE NULL ··· 819 813 if (pdev->id < 0 || pdev->id >= BCM63XX_NR_UARTS) 820 814 return -EINVAL; 821 815 822 - if (ports[pdev->id].membase) 816 + port = &ports[pdev->id]; 817 + if (port->membase) 823 818 return -EBUSY; 819 + memset(port, 0, sizeof(*port)); 824 820 825 821 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 826 822 if (!res_mem) 827 823 return -ENODEV; 828 824 825 + port->mapbase = res_mem->start; 826 + port->membase = devm_ioremap_resource(&pdev->dev, res_mem); 827 + if (IS_ERR(port->membase)) 828 + return PTR_ERR(port->membase); 829 + 829 830 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 830 831 if (!res_irq) 831 832 return -ENODEV; 832 833 833 - clk = clk_get(&pdev->dev, "periph"); 834 + clk = pdev->dev.of_node ? of_clk_get(pdev->dev.of_node, 0) : 835 + clk_get(&pdev->dev, "periph"); 834 836 if (IS_ERR(clk)) 835 837 return -ENODEV; 836 838 837 - port = &ports[pdev->id]; 838 - memset(port, 0, sizeof(*port)); 839 839 port->iotype = UPIO_MEM; 840 - port->mapbase = res_mem->start; 841 840 port->irq = res_irq->start; 842 841 port->ops = &bcm_uart_ops; 843 842 port->flags = UPF_BOOT_AUTOCONF; ··· 916 905 module_exit(bcm_uart_exit); 917 906 918 907 MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>"); 919 - MODULE_DESCRIPTION("Broadcom 63<xx integrated uart driver"); 908 + MODULE_DESCRIPTION("Broadcom 63xx integrated uart driver"); 920 909 MODULE_LICENSE("GPL");
+3 -2
drivers/tty/serial/bfin_sport_uart.c
··· 517 517 up->csize = 5; 518 518 break; 519 519 default: 520 - pr_warning("requested word length not supported\n"); 520 + pr_warn("requested word length not supported\n"); 521 + break; 521 522 } 522 523 523 524 if (termios->c_cflag & CSTOPB) { 524 525 up->stopb = 1; 525 526 } 526 527 if (termios->c_cflag & PARENB) { 527 - pr_warning("PAREN bits is not supported yet\n"); 528 + pr_warn("PAREN bit is not supported yet\n"); 528 529 /* up->parib = 1; */ 529 530 } 530 531
+3 -2
drivers/tty/serial/bfin_uart.c
··· 944 944 * Enable the IrDA function if tty->ldisc.num is N_IRDA. 945 945 * In other cases, disable IrDA function. 946 946 */ 947 - static void bfin_serial_set_ldisc(struct uart_port *port, int ld) 947 + static void bfin_serial_set_ldisc(struct uart_port *port, 948 + struct ktermios *termios) 948 949 { 949 950 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 950 951 unsigned int val; 951 952 952 - switch (ld) { 953 + switch (termios->c_line) { 953 954 case N_IRDA: 954 955 val = UART_GET_GCTL(uart); 955 956 val |= (UMOD_IRDA | RPOLC);
+3 -2
drivers/tty/serial/clps711x.c
··· 225 225 writel(ubrlcr, port->membase + UBRLCR_OFFSET); 226 226 } 227 227 228 - static void uart_clps711x_set_ldisc(struct uart_port *port, int ld) 228 + static void uart_clps711x_set_ldisc(struct uart_port *port, 229 + struct ktermios *termios) 229 230 { 230 231 if (!port->line) { 231 232 struct clps711x_port *s = dev_get_drvdata(port->dev); 232 233 233 234 regmap_update_bits(s->syscon, SYSCON_OFFSET, SYSCON1_SIREN, 234 - (ld == N_IRDA) ? SYSCON1_SIREN : 0); 235 + (termios->c_line == N_IRDA) ? SYSCON1_SIREN : 0); 235 236 } 236 237 } 237 238
+32 -16
drivers/tty/serial/cpm_uart/cpm_uart_core.c
··· 80 80 */ 81 81 static unsigned int cpm_uart_tx_empty(struct uart_port *port) 82 82 { 83 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 83 + struct uart_cpm_port *pinfo = 84 + container_of(port, struct uart_cpm_port, port); 84 85 cbd_t __iomem *bdp = pinfo->tx_bd_base; 85 86 int ret = 0; 86 87 ··· 103 102 104 103 static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) 105 104 { 106 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 105 + struct uart_cpm_port *pinfo = 106 + container_of(port, struct uart_cpm_port, port); 107 107 108 108 if (pinfo->gpios[GPIO_RTS] >= 0) 109 109 gpio_set_value(pinfo->gpios[GPIO_RTS], !(mctrl & TIOCM_RTS)); ··· 115 113 116 114 static unsigned int cpm_uart_get_mctrl(struct uart_port *port) 117 115 { 118 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 116 + struct uart_cpm_port *pinfo = 117 + container_of(port, struct uart_cpm_port, port); 119 118 unsigned int mctrl = TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; 120 119 121 120 if (pinfo->gpios[GPIO_CTS] >= 0) { ··· 147 144 */ 148 145 static void cpm_uart_stop_tx(struct uart_port *port) 149 146 { 150 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 147 + struct uart_cpm_port *pinfo = 148 + container_of(port, struct uart_cpm_port, port); 151 149 smc_t __iomem *smcp = pinfo->smcp; 152 150 scc_t __iomem *sccp = pinfo->sccp; 153 151 ··· 165 161 */ 166 162 static void cpm_uart_start_tx(struct uart_port *port) 167 163 { 168 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 164 + struct uart_cpm_port *pinfo = 165 + container_of(port, struct uart_cpm_port, port); 169 166 smc_t __iomem *smcp = pinfo->smcp; 170 167 scc_t __iomem *sccp = pinfo->sccp; 171 168 ··· 194 189 */ 195 190 static void cpm_uart_stop_rx(struct uart_port *port) 196 191 { 197 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 192 + struct uart_cpm_port *pinfo = 193 + container_of(port, struct uart_cpm_port, port); 198 194 smc_t __iomem *smcp = pinfo->smcp; 199 195 scc_t __iomem *sccp = pinfo->sccp; 200 196 ··· 212 206 */ 213 207 static void cpm_uart_break_ctl(struct uart_port *port, int break_state) 214 208 { 215 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 209 + struct uart_cpm_port *pinfo = 210 + container_of(port, struct uart_cpm_port, port); 216 211 217 212 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port->line, 218 213 break_state); ··· 247 240 unsigned char ch; 248 241 u8 *cp; 249 242 struct tty_port *tport = &port->state->port; 250 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 243 + struct uart_cpm_port *pinfo = 244 + container_of(port, struct uart_cpm_port, port); 251 245 cbd_t __iomem *bdp; 252 246 u16 status; 253 247 unsigned int flg; ··· 405 397 static int cpm_uart_startup(struct uart_port *port) 406 398 { 407 399 int retval; 408 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 400 + struct uart_cpm_port *pinfo = 401 + container_of(port, struct uart_cpm_port, port); 409 402 410 403 pr_debug("CPM uart[%d]:startup\n", port->line); 411 404 ··· 451 442 */ 452 443 static void cpm_uart_shutdown(struct uart_port *port) 453 444 { 454 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 445 + struct uart_cpm_port *pinfo = 446 + container_of(port, struct uart_cpm_port, port); 455 447 456 448 pr_debug("CPM uart[%d]:shutdown\n", port->line); 457 449 ··· 502 492 unsigned long flags; 503 493 u16 cval, scval, prev_mode; 504 494 int bits, sbits; 505 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 495 + struct uart_cpm_port *pinfo = 496 + container_of(port, struct uart_cpm_port, port); 506 497 smc_t __iomem *smcp = pinfo->smcp; 507 498 scc_t __iomem *sccp = pinfo->sccp; 508 499 int maxidl; ··· 686 675 cbd_t __iomem *bdp; 687 676 u8 *p; 688 677 int count; 689 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 678 + struct uart_cpm_port *pinfo = 679 + container_of(port, struct uart_cpm_port, port); 690 680 struct circ_buf *xmit = &port->state->xmit; 691 681 692 682 /* Handle xon/xoff */ ··· 918 906 */ 919 907 static int cpm_uart_request_port(struct uart_port *port) 920 908 { 921 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 909 + struct uart_cpm_port *pinfo = 910 + container_of(port, struct uart_cpm_port, port); 922 911 int ret; 923 912 924 913 pr_debug("CPM uart[%d]:request port\n", port->line); ··· 951 938 952 939 static void cpm_uart_release_port(struct uart_port *port) 953 940 { 954 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 941 + struct uart_cpm_port *pinfo = 942 + container_of(port, struct uart_cpm_port, port); 955 943 956 944 if (!(pinfo->flags & FLAG_CONSOLE)) 957 945 cpm_uart_freebuf(pinfo); ··· 1096 1082 1097 1083 static int cpm_get_poll_char(struct uart_port *port) 1098 1084 { 1099 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 1085 + struct uart_cpm_port *pinfo = 1086 + container_of(port, struct uart_cpm_port, port); 1100 1087 1101 1088 if (!serial_polled) { 1102 1089 serial_polled = 1; ··· 1114 1099 static void cpm_put_poll_char(struct uart_port *port, 1115 1100 unsigned char c) 1116 1101 { 1117 - struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 1102 + struct uart_cpm_port *pinfo = 1103 + container_of(port, struct uart_cpm_port, port); 1118 1104 static char ch[2]; 1119 1105 1120 1106 ch[0] = (char)c;
-12
drivers/tty/serial/crisv10.c
··· 3676 3676 } 3677 3677 info->port.flags |= ASYNC_CLOSING; 3678 3678 /* 3679 - * Save the termios structure, since this port may have 3680 - * separate termios for callout and dialin. 3681 - */ 3682 - if (info->port.flags & ASYNC_NORMAL_ACTIVE) 3683 - info->normal_termios = tty->termios; 3684 - /* 3685 3679 * Now we wait for the transmit buffer to clear; and we notify 3686 3680 * the line discipline to only process XON/XOFF characters. 3687 3681 */ ··· 4070 4076 return retval; 4071 4077 } 4072 4078 4073 - if ((info->port.count == 1) && (info->port.flags & ASYNC_SPLIT_TERMIOS)) { 4074 - tty->termios = info->normal_termios; 4075 - change_speed(info); 4076 - } 4077 - 4078 4079 #ifdef SERIAL_DEBUG_OPEN 4079 4080 printk("rs_open ttyS%d successful...\n", info->line); 4080 4081 #endif ··· 4316 4327 info->custom_divisor = 0; 4317 4328 info->x_char = 0; 4318 4329 info->event = 0; 4319 - info->normal_termios = driver->init_termios; 4320 4330 info->xmit.buf = NULL; 4321 4331 info->xmit.tail = info->xmit.head = 0; 4322 4332 info->first_recv_buffer = info->last_recv_buffer = NULL;
-1
drivers/tty/serial/crisv10.h
··· 98 98 99 99 struct work_struct work; 100 100 struct async_icount icount; /* error-statistics etc.*/ 101 - struct ktermios normal_termios; 102 101 103 102 unsigned long char_time_usec; /* The time for 1 char, in usecs */ 104 103 unsigned long flush_time_usec; /* How often we should flush */
+1 -1
drivers/tty/serial/earlycon.c
··· 98 98 strlcpy(device->options, options, length); 99 99 } 100 100 101 - if (mmio || mmio32) 101 + if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM32) 102 102 pr_info("Early serial console at MMIO%s 0x%llx (options '%s')\n", 103 103 mmio32 ? "32" : "", 104 104 (unsigned long long)port->mapbase,
+17 -8
drivers/tty/serial/fsl_lpuart.c
··· 1786 1786 } 1787 1787 sport->port.line = ret; 1788 1788 sport->lpuart32 = of_device_is_compatible(np, "fsl,ls1021a-lpuart"); 1789 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1790 - if (!res) 1791 - return -ENODEV; 1792 1789 1793 - sport->port.mapbase = res->start; 1790 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1794 1791 sport->port.membase = devm_ioremap_resource(&pdev->dev, res); 1795 1792 if (IS_ERR(sport->port.membase)) 1796 1793 return PTR_ERR(sport->port.membase); 1797 1794 1795 + sport->port.mapbase = res->start; 1798 1796 sport->port.dev = &pdev->dev; 1799 1797 sport->port.type = PORT_LPUART; 1800 1798 sport->port.iotype = UPIO_MEM; ··· 1860 1862 static int lpuart_resume(struct device *dev) 1861 1863 { 1862 1864 struct lpuart_port *sport = dev_get_drvdata(dev); 1865 + unsigned long temp; 1866 + 1867 + if (sport->lpuart32) { 1868 + lpuart32_setup_watermark(sport); 1869 + temp = lpuart32_read(sport->port.membase + UARTCTRL); 1870 + temp |= (UARTCTRL_RIE | UARTCTRL_TIE | UARTCTRL_RE | 1871 + UARTCTRL_TE | UARTCTRL_ILIE); 1872 + lpuart32_write(temp, sport->port.membase + UARTCTRL); 1873 + } else { 1874 + lpuart_setup_watermark(sport); 1875 + temp = readb(sport->port.membase + UARTCR2); 1876 + temp |= (UARTCR2_RIE | UARTCR2_TIE | UARTCR2_RE | UARTCR2_TE); 1877 + writeb(temp, sport->port.membase + UARTCR2); 1878 + } 1863 1879 1864 1880 uart_resume_port(&lpuart_reg, &sport->port); 1865 1881 ··· 1896 1884 1897 1885 static int __init lpuart_serial_init(void) 1898 1886 { 1899 - int ret; 1887 + int ret = uart_register_driver(&lpuart_reg); 1900 1888 1901 - pr_info("serial: Freescale lpuart driver\n"); 1902 - 1903 - ret = uart_register_driver(&lpuart_reg); 1904 1889 if (ret) 1905 1890 return ret; 1906 1891
+3 -1
drivers/tty/serial/icom.c
··· 1550 1550 1551 1551 icom_adapter->base_addr = pci_ioremap_bar(dev, 0); 1552 1552 1553 - if (!icom_adapter->base_addr) 1553 + if (!icom_adapter->base_addr) { 1554 + retval = -ENOMEM; 1554 1555 goto probe_exit1; 1556 + } 1555 1557 1556 1558 /* save off irq and request irq line */ 1557 1559 if ( (retval = request_irq(dev->irq, icom_interrupt,
+75 -78
drivers/tty/serial/imx.c
··· 302 302 /* 303 303 * Save and restore functions for UCR1, UCR2 and UCR3 registers 304 304 */ 305 - #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_IMX_CONSOLE) 305 + #if defined(CONFIG_SERIAL_IMX_CONSOLE) 306 306 static void imx_port_ucrs_save(struct uart_port *port, 307 307 struct imx_port_ucrs *ucr) 308 308 { ··· 991 991 992 992 sport->rx_buf = kzalloc(PAGE_SIZE, GFP_KERNEL); 993 993 if (!sport->rx_buf) { 994 - dev_err(dev, "cannot alloc DMA buffer.\n"); 995 994 ret = -ENOMEM; 996 995 goto err; 997 996 } ··· 1075 1076 1076 1077 retval = clk_prepare_enable(sport->clk_per); 1077 1078 if (retval) 1078 - goto error_out1; 1079 + return retval; 1079 1080 retval = clk_prepare_enable(sport->clk_ipg); 1080 1081 if (retval) { 1081 1082 clk_disable_unprepare(sport->clk_per); 1082 - goto error_out1; 1083 + return retval; 1083 1084 } 1084 1085 1085 1086 imx_setup_ufcr(sport, 0); ··· 1107 1108 1108 1109 while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) && (--i > 0)) 1109 1110 udelay(1); 1110 - 1111 - /* 1112 - * Allocate the IRQ(s) i.MX1 has three interrupts whereas later 1113 - * chips only have one interrupt. 1114 - */ 1115 - if (sport->txirq > 0) { 1116 - retval = request_irq(sport->rxirq, imx_rxint, 0, 1117 - dev_name(port->dev), sport); 1118 - if (retval) 1119 - goto error_out1; 1120 - 1121 - retval = request_irq(sport->txirq, imx_txint, 0, 1122 - dev_name(port->dev), sport); 1123 - if (retval) 1124 - goto error_out2; 1125 - 1126 - /* do not use RTS IRQ on IrDA */ 1127 - if (!USE_IRDA(sport)) { 1128 - retval = request_irq(sport->rtsirq, imx_rtsint, 0, 1129 - dev_name(port->dev), sport); 1130 - if (retval) 1131 - goto error_out3; 1132 - } 1133 - } else { 1134 - retval = request_irq(sport->port.irq, imx_int, 0, 1135 - dev_name(port->dev), sport); 1136 - if (retval) { 1137 - free_irq(sport->port.irq, sport); 1138 - goto error_out1; 1139 - } 1140 - } 1141 1111 1142 1112 spin_lock_irqsave(&sport->port.lock, flags); 1143 1113 /* ··· 1169 1201 } 1170 1202 1171 1203 return 0; 1172 - 1173 - error_out3: 1174 - if (sport->txirq) 1175 - free_irq(sport->txirq, sport); 1176 - error_out2: 1177 - if (sport->rxirq) 1178 - free_irq(sport->rxirq, sport); 1179 - error_out1: 1180 - return retval; 1181 1204 } 1182 1205 1183 1206 static void imx_shutdown(struct uart_port *port) ··· 1212 1253 * Stop our timer. 1213 1254 */ 1214 1255 del_timer_sync(&sport->timer); 1215 - 1216 - /* 1217 - * Free the interrupts 1218 - */ 1219 - if (sport->txirq > 0) { 1220 - if (!USE_IRDA(sport)) 1221 - free_irq(sport->rtsirq, sport); 1222 - free_irq(sport->txirq, sport); 1223 - free_irq(sport->rxirq, sport); 1224 - } else 1225 - free_irq(sport->port.irq, sport); 1226 1256 1227 1257 /* 1228 1258 * Disable all interrupts, port and break condition. ··· 1455 1507 } 1456 1508 1457 1509 #if defined(CONFIG_CONSOLE_POLL) 1510 + 1511 + static int imx_poll_init(struct uart_port *port) 1512 + { 1513 + struct imx_port *sport = (struct imx_port *)port; 1514 + unsigned long flags; 1515 + unsigned long temp; 1516 + int retval; 1517 + 1518 + retval = clk_prepare_enable(sport->clk_ipg); 1519 + if (retval) 1520 + return retval; 1521 + retval = clk_prepare_enable(sport->clk_per); 1522 + if (retval) 1523 + clk_disable_unprepare(sport->clk_ipg); 1524 + 1525 + imx_setup_ufcr(sport, 0); 1526 + 1527 + spin_lock_irqsave(&sport->port.lock, flags); 1528 + 1529 + temp = readl(sport->port.membase + UCR1); 1530 + if (is_imx1_uart(sport)) 1531 + temp |= IMX1_UCR1_UARTCLKEN; 1532 + temp |= UCR1_UARTEN | UCR1_RRDYEN; 1533 + temp &= ~(UCR1_TXMPTYEN | UCR1_RTSDEN); 1534 + writel(temp, sport->port.membase + UCR1); 1535 + 1536 + temp = readl(sport->port.membase + UCR2); 1537 + temp |= UCR2_RXEN; 1538 + writel(temp, sport->port.membase + UCR2); 1539 + 1540 + spin_unlock_irqrestore(&sport->port.lock, flags); 1541 + 1542 + return 0; 1543 + } 1544 + 1458 1545 static int imx_poll_get_char(struct uart_port *port) 1459 1546 { 1460 - if (!(readl(port->membase + USR2) & USR2_RDR)) 1547 + if (!(readl_relaxed(port->membase + USR2) & USR2_RDR)) 1461 1548 return NO_POLL_CHAR; 1462 1549 1463 - return readl(port->membase + URXD0) & URXD_RX_DATA; 1550 + return readl_relaxed(port->membase + URXD0) & URXD_RX_DATA; 1464 1551 } 1465 1552 1466 1553 static void imx_poll_put_char(struct uart_port *port, unsigned char c) 1467 1554 { 1468 - struct imx_port_ucrs old_ucr; 1469 1555 unsigned int status; 1470 - 1471 - /* save control registers */ 1472 - imx_port_ucrs_save(port, &old_ucr); 1473 - 1474 - /* disable interrupts */ 1475 - writel(UCR1_UARTEN, port->membase + UCR1); 1476 - writel(old_ucr.ucr2 & ~(UCR2_ATEN | UCR2_RTSEN | UCR2_ESCI), 1477 - port->membase + UCR2); 1478 - writel(old_ucr.ucr3 & ~(UCR3_DCD | UCR3_RI | UCR3_DTREN), 1479 - port->membase + UCR3); 1480 1556 1481 1557 /* drain */ 1482 1558 do { 1483 - status = readl(port->membase + USR1); 1559 + status = readl_relaxed(port->membase + USR1); 1484 1560 } while (~status & USR1_TRDY); 1485 1561 1486 1562 /* write */ 1487 - writel(c, port->membase + URTX0); 1563 + writel_relaxed(c, port->membase + URTX0); 1488 1564 1489 1565 /* flush */ 1490 1566 do { 1491 - status = readl(port->membase + USR2); 1567 + status = readl_relaxed(port->membase + USR2); 1492 1568 } while (~status & USR2_TXDC); 1493 - 1494 - /* restore control registers */ 1495 - imx_port_ucrs_restore(port, &old_ucr); 1496 1569 } 1497 1570 #endif 1498 1571 ··· 1534 1565 .config_port = imx_config_port, 1535 1566 .verify_port = imx_verify_port, 1536 1567 #if defined(CONFIG_CONSOLE_POLL) 1568 + .poll_init = imx_poll_init, 1537 1569 .poll_get_char = imx_poll_get_char, 1538 1570 .poll_put_char = imx_poll_put_char, 1539 1571 #endif ··· 1899 1929 1900 1930 sport->port.uartclk = clk_get_rate(sport->clk_per); 1901 1931 1932 + /* 1933 + * Allocate the IRQ(s) i.MX1 has three interrupts whereas later 1934 + * chips only have one interrupt. 1935 + */ 1936 + if (sport->txirq > 0) { 1937 + ret = devm_request_irq(&pdev->dev, sport->rxirq, imx_rxint, 0, 1938 + dev_name(&pdev->dev), sport); 1939 + if (ret) 1940 + return ret; 1941 + 1942 + ret = devm_request_irq(&pdev->dev, sport->txirq, imx_txint, 0, 1943 + dev_name(&pdev->dev), sport); 1944 + if (ret) 1945 + return ret; 1946 + 1947 + /* do not use RTS IRQ on IrDA */ 1948 + if (!USE_IRDA(sport)) { 1949 + ret = devm_request_irq(&pdev->dev, sport->rtsirq, 1950 + imx_rtsint, 0, 1951 + dev_name(&pdev->dev), sport); 1952 + if (ret) 1953 + return ret; 1954 + } 1955 + } else { 1956 + ret = devm_request_irq(&pdev->dev, sport->port.irq, imx_int, 0, 1957 + dev_name(&pdev->dev), sport); 1958 + if (ret) 1959 + return ret; 1960 + } 1961 + 1902 1962 imx_ports[sport->port.line] = sport; 1903 1963 1904 1964 platform_set_drvdata(pdev, sport); ··· 1959 1959 1960 1960 static int __init imx_serial_init(void) 1961 1961 { 1962 - int ret; 1962 + int ret = uart_register_driver(&imx_reg); 1963 1963 1964 - pr_info("Serial: IMX driver\n"); 1965 - 1966 - ret = uart_register_driver(&imx_reg); 1967 1964 if (ret) 1968 1965 return ret; 1969 1966
+12 -6
drivers/tty/serial/ip22zilog.c
··· 544 544 /* The port lock is held and interrupts are disabled. */ 545 545 static void ip22zilog_set_mctrl(struct uart_port *port, unsigned int mctrl) 546 546 { 547 - struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port; 547 + struct uart_ip22zilog_port *up = 548 + container_of(port, struct uart_ip22zilog_port, port); 548 549 struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port); 549 550 unsigned char set_bits, clear_bits; 550 551 ··· 569 568 /* The port lock is held and interrupts are disabled. */ 570 569 static void ip22zilog_stop_tx(struct uart_port *port) 571 570 { 572 - struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port; 571 + struct uart_ip22zilog_port *up = 572 + container_of(port, struct uart_ip22zilog_port, port); 573 573 574 574 up->flags |= IP22ZILOG_FLAG_TX_STOPPED; 575 575 } ··· 578 576 /* The port lock is held and interrupts are disabled. */ 579 577 static void ip22zilog_start_tx(struct uart_port *port) 580 578 { 581 - struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port; 579 + struct uart_ip22zilog_port *up = 580 + container_of(port, struct uart_ip22zilog_port, port); 582 581 struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port); 583 582 unsigned char status; 584 583 ··· 639 636 /* The port lock is held. */ 640 637 static void ip22zilog_enable_ms(struct uart_port *port) 641 638 { 642 - struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port; 639 + struct uart_ip22zilog_port *up = 640 + container_of(port, struct uart_ip22zilog_port, port); 643 641 struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port); 644 642 unsigned char new_reg; 645 643 ··· 656 652 /* The port lock is not held. */ 657 653 static void ip22zilog_break_ctl(struct uart_port *port, int break_state) 658 654 { 659 - struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port; 655 + struct uart_ip22zilog_port *up = 656 + container_of(port, struct uart_ip22zilog_port, port); 660 657 struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port); 661 658 unsigned char set_bits, clear_bits, new_reg; 662 659 unsigned long flags; ··· 878 873 ip22zilog_set_termios(struct uart_port *port, struct ktermios *termios, 879 874 struct ktermios *old) 880 875 { 881 - struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port; 876 + struct uart_ip22zilog_port *up = 877 + container_of(port, struct uart_ip22zilog_port, port); 882 878 unsigned long flags; 883 879 int baud, brg; 884 880
+1 -1
drivers/tty/serial/jsm/Makefile
··· 4 4 5 5 obj-$(CONFIG_SERIAL_JSM) += jsm.o 6 6 7 - jsm-objs := jsm_driver.o jsm_neo.o jsm_tty.o 7 + jsm-objs := jsm_driver.o jsm_neo.o jsm_tty.o jsm_cls.o 8 8
+79 -22
drivers/tty/serial/jsm/jsm.h
··· 13 13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 14 * PURPOSE. See the GNU General Public License for more details. 15 15 * 16 - * You should have received a copy of the GNU General Public License 17 - * along with this program; if not, write to the Free Software 18 - * Foundation, Inc., 59 * Temple Place - Suite 330, Boston, 19 - * MA 02111-1307, USA. 20 - * 21 16 * Contact Information: 22 17 * Scott H Kilau <Scott_Kilau@digi.com> 23 18 * Wendy Xiong <wendyx@us.ibm.com> ··· 63 68 #define MAX_STOPS_SENT 5 64 69 65 70 /* Board ids */ 71 + #define PCI_DEVICE_ID_CLASSIC_4 0x0028 72 + #define PCI_DEVICE_ID_CLASSIC_8 0x0029 73 + #define PCI_DEVICE_ID_CLASSIC_4_422 0x00D0 74 + #define PCI_DEVICE_ID_CLASSIC_8_422 0x00D1 66 75 #define PCI_DEVICE_ID_NEO_4 0x00B0 67 76 #define PCI_DEVICE_ID_NEO_1_422 0x00CC 68 77 #define PCI_DEVICE_ID_NEO_1_422_485 0x00CD ··· 111 112 ************************************************************************/ 112 113 struct board_ops { 113 114 irq_handler_t intr; 114 - void (*uart_init) (struct jsm_channel *ch); 115 - void (*uart_off) (struct jsm_channel *ch); 116 - void (*param) (struct jsm_channel *ch); 117 - void (*assert_modem_signals) (struct jsm_channel *ch); 118 - void (*flush_uart_write) (struct jsm_channel *ch); 119 - void (*flush_uart_read) (struct jsm_channel *ch); 120 - void (*disable_receiver) (struct jsm_channel *ch); 121 - void (*enable_receiver) (struct jsm_channel *ch); 122 - void (*send_break) (struct jsm_channel *ch); 123 - void (*clear_break) (struct jsm_channel *ch, int); 124 - void (*send_start_character) (struct jsm_channel *ch); 125 - void (*send_stop_character) (struct jsm_channel *ch); 126 - void (*copy_data_from_queue_to_uart) (struct jsm_channel *ch); 127 - u32 (*get_uart_bytes_left) (struct jsm_channel *ch); 128 - void (*send_immediate_char) (struct jsm_channel *ch, unsigned char); 115 + void (*uart_init)(struct jsm_channel *ch); 116 + void (*uart_off)(struct jsm_channel *ch); 117 + void (*param)(struct jsm_channel *ch); 118 + void (*assert_modem_signals)(struct jsm_channel *ch); 119 + void (*flush_uart_write)(struct jsm_channel *ch); 120 + void (*flush_uart_read)(struct jsm_channel *ch); 121 + void (*disable_receiver)(struct jsm_channel *ch); 122 + void (*enable_receiver)(struct jsm_channel *ch); 123 + void (*send_break)(struct jsm_channel *ch); 124 + void (*clear_break)(struct jsm_channel *ch); 125 + void (*send_start_character)(struct jsm_channel *ch); 126 + void (*send_stop_character)(struct jsm_channel *ch); 127 + void (*copy_data_from_queue_to_uart)(struct jsm_channel *ch); 128 + u32 (*get_uart_bytes_left)(struct jsm_channel *ch); 129 + void (*send_immediate_char)(struct jsm_channel *ch, unsigned char); 129 130 }; 130 131 131 132 ··· 188 189 #define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */ 189 190 #define CH_BAUD0 0x08000 /* Used for checking B0 transitions */ 190 191 191 - /* Our Read/Error/Write queue sizes */ 192 + /* Our Read/Error queue sizes */ 192 193 #define RQUEUEMASK 0x1FFF /* 8 K - 1 */ 193 194 #define EQUEUEMASK 0x1FFF /* 8 K - 1 */ 194 195 #define RQUEUESIZE (RQUEUEMASK + 1) ··· 221 222 u8 ch_mostat; /* FEP output modem status */ 222 223 u8 ch_mistat; /* FEP input modem status */ 223 224 224 - struct neo_uart_struct __iomem *ch_neo_uart; /* Pointer to the "mapped" UART struct */ 225 + /* Pointers to the "mapped" UART structs */ 226 + struct neo_uart_struct __iomem *ch_neo_uart; /* NEO card */ 227 + struct cls_uart_struct __iomem *ch_cls_uart; /* Classic card */ 228 + 225 229 u8 ch_cached_lsr; /* Cached value of the LSR register */ 226 230 227 231 u8 *ch_rqueue; /* Our read queue buffer - malloc'ed */ ··· 256 254 u64 ch_xoff_sends; /* Count of xoffs transmitted */ 257 255 }; 258 256 257 + /************************************************************************ 258 + * Per channel/port Classic UART structures * 259 + ************************************************************************ 260 + * Base Structure Entries Usage Meanings to Host * 261 + * * 262 + * W = read write R = read only * 263 + * U = Unused. * 264 + ************************************************************************/ 265 + 266 + struct cls_uart_struct { 267 + u8 txrx; /* WR RHR/THR - Holding Reg */ 268 + u8 ier; /* WR IER - Interrupt Enable Reg */ 269 + u8 isr_fcr; /* WR ISR/FCR - Interrupt Status Reg/Fifo Control Reg*/ 270 + u8 lcr; /* WR LCR - Line Control Reg */ 271 + u8 mcr; /* WR MCR - Modem Control Reg */ 272 + u8 lsr; /* WR LSR - Line Status Reg */ 273 + u8 msr; /* WR MSR - Modem Status Reg */ 274 + u8 spr; /* WR SPR - Scratch Pad Reg */ 275 + }; 276 + 277 + /* Where to read the interrupt register (8bits) */ 278 + #define UART_CLASSIC_POLL_ADDR_OFFSET 0x40 279 + 280 + #define UART_EXAR654_ENHANCED_REGISTER_SET 0xBF 281 + 282 + #define UART_16654_FCR_TXTRIGGER_8 0x0 283 + #define UART_16654_FCR_TXTRIGGER_16 0x10 284 + #define UART_16654_FCR_TXTRIGGER_32 0x20 285 + #define UART_16654_FCR_TXTRIGGER_56 0x30 286 + 287 + #define UART_16654_FCR_RXTRIGGER_8 0x0 288 + #define UART_16654_FCR_RXTRIGGER_16 0x40 289 + #define UART_16654_FCR_RXTRIGGER_56 0x80 290 + #define UART_16654_FCR_RXTRIGGER_60 0xC0 291 + 292 + #define UART_IIR_CTSRTS 0x20 /* Received CTS/RTS change of state */ 293 + #define UART_IIR_RDI_TIMEOUT 0x0C /* Receiver data TIMEOUT */ 294 + 295 + /* 296 + * These are the EXTENDED definitions for the Exar 654's Interrupt 297 + * Enable Register. 298 + */ 299 + #define UART_EXAR654_EFR_ECB 0x10 /* Enhanced control bit */ 300 + #define UART_EXAR654_EFR_IXON 0x2 /* Receiver compares Xon1/Xoff1 */ 301 + #define UART_EXAR654_EFR_IXOFF 0x8 /* Transmit Xon1/Xoff1 */ 302 + #define UART_EXAR654_EFR_RTSDTR 0x40 /* Auto RTS/DTR Flow Control Enable */ 303 + #define UART_EXAR654_EFR_CTSDSR 0x80 /* Auto CTS/DSR Flow COntrol Enable */ 304 + 305 + #define UART_EXAR654_XOFF_DETECT 0x1 /* Indicates whether chip saw an incoming XOFF char */ 306 + #define UART_EXAR654_XON_DETECT 0x2 /* Indicates whether chip saw an incoming XON char */ 307 + 308 + #define UART_EXAR654_IER_XOFF 0x20 /* Xoff Interrupt Enable */ 309 + #define UART_EXAR654_IER_RTSDTR 0x40 /* Output Interrupt Enable */ 310 + #define UART_EXAR654_IER_CTSDSR 0x80 /* Input Interrupt Enable */ 259 311 260 312 /************************************************************************ 261 313 * Per channel/port NEO UART structure * ··· 430 374 */ 431 375 extern struct uart_driver jsm_uart_driver; 432 376 extern struct board_ops jsm_neo_ops; 377 + extern struct board_ops jsm_cls_ops; 433 378 extern int jsm_debug; 434 379 435 380 /*************************************************************************
+982
drivers/tty/serial/jsm/jsm_cls.c
··· 1 + /* 2 + * Copyright 2003 Digi International (www.digi.com) 3 + * Scott H Kilau <Scott_Kilau at digi dot com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2, or (at your option) 8 + * any later version. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 12 + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 + * PURPOSE. See the GNU General Public License for more details. 14 + * 15 + * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE! 16 + * 17 + * This is shared code between Digi's CVS archive and the 18 + * Linux Kernel sources. 19 + * Changing the source just for reformatting needlessly breaks 20 + * our CVS diff history. 21 + * 22 + * Send any bug fixes/changes to: Eng.Linux at digi dot com. 23 + * Thank you. 24 + * 25 + */ 26 + 27 + #include <linux/delay.h> /* For udelay */ 28 + #include <linux/io.h> /* For read[bwl]/write[bwl] */ 29 + #include <linux/serial.h> /* For struct async_serial */ 30 + #include <linux/serial_reg.h> /* For the various UART offsets */ 31 + #include <linux/pci.h> 32 + #include <linux/tty.h> 33 + 34 + #include "jsm.h" /* Driver main header file */ 35 + 36 + static struct { 37 + unsigned int rate; 38 + unsigned int cflag; 39 + } baud_rates[] = { 40 + { 921600, B921600 }, 41 + { 460800, B460800 }, 42 + { 230400, B230400 }, 43 + { 115200, B115200 }, 44 + { 57600, B57600 }, 45 + { 38400, B38400 }, 46 + { 19200, B19200 }, 47 + { 9600, B9600 }, 48 + { 4800, B4800 }, 49 + { 2400, B2400 }, 50 + { 1200, B1200 }, 51 + { 600, B600 }, 52 + { 300, B300 }, 53 + { 200, B200 }, 54 + { 150, B150 }, 55 + { 134, B134 }, 56 + { 110, B110 }, 57 + { 75, B75 }, 58 + { 50, B50 }, 59 + }; 60 + 61 + static void cls_set_cts_flow_control(struct jsm_channel *ch) 62 + { 63 + u8 lcrb = readb(&ch->ch_cls_uart->lcr); 64 + u8 ier = readb(&ch->ch_cls_uart->ier); 65 + u8 isr_fcr = 0; 66 + 67 + /* 68 + * The Enhanced Register Set may only be accessed when 69 + * the Line Control Register is set to 0xBFh. 70 + */ 71 + writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr); 72 + 73 + isr_fcr = readb(&ch->ch_cls_uart->isr_fcr); 74 + 75 + /* Turn on CTS flow control, turn off IXON flow control */ 76 + isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_CTSDSR); 77 + isr_fcr &= ~(UART_EXAR654_EFR_IXON); 78 + 79 + writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr); 80 + 81 + /* Write old LCR value back out, which turns enhanced access off */ 82 + writeb(lcrb, &ch->ch_cls_uart->lcr); 83 + 84 + /* 85 + * Enable interrupts for CTS flow, turn off interrupts for 86 + * received XOFF chars 87 + */ 88 + ier |= (UART_EXAR654_IER_CTSDSR); 89 + ier &= ~(UART_EXAR654_IER_XOFF); 90 + writeb(ier, &ch->ch_cls_uart->ier); 91 + 92 + /* Set the usual FIFO values */ 93 + writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr); 94 + 95 + writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 | 96 + UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR), 97 + &ch->ch_cls_uart->isr_fcr); 98 + 99 + ch->ch_t_tlevel = 16; 100 + } 101 + 102 + static void cls_set_ixon_flow_control(struct jsm_channel *ch) 103 + { 104 + u8 lcrb = readb(&ch->ch_cls_uart->lcr); 105 + u8 ier = readb(&ch->ch_cls_uart->ier); 106 + u8 isr_fcr = 0; 107 + 108 + /* 109 + * The Enhanced Register Set may only be accessed when 110 + * the Line Control Register is set to 0xBFh. 111 + */ 112 + writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr); 113 + 114 + isr_fcr = readb(&ch->ch_cls_uart->isr_fcr); 115 + 116 + /* Turn on IXON flow control, turn off CTS flow control */ 117 + isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXON); 118 + isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR); 119 + 120 + writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr); 121 + 122 + /* Now set our current start/stop chars while in enhanced mode */ 123 + writeb(ch->ch_startc, &ch->ch_cls_uart->mcr); 124 + writeb(0, &ch->ch_cls_uart->lsr); 125 + writeb(ch->ch_stopc, &ch->ch_cls_uart->msr); 126 + writeb(0, &ch->ch_cls_uart->spr); 127 + 128 + /* Write old LCR value back out, which turns enhanced access off */ 129 + writeb(lcrb, &ch->ch_cls_uart->lcr); 130 + 131 + /* 132 + * Disable interrupts for CTS flow, turn on interrupts for 133 + * received XOFF chars 134 + */ 135 + ier &= ~(UART_EXAR654_IER_CTSDSR); 136 + ier |= (UART_EXAR654_IER_XOFF); 137 + writeb(ier, &ch->ch_cls_uart->ier); 138 + 139 + /* Set the usual FIFO values */ 140 + writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr); 141 + 142 + writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 | 143 + UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR), 144 + &ch->ch_cls_uart->isr_fcr); 145 + } 146 + 147 + static void cls_set_no_output_flow_control(struct jsm_channel *ch) 148 + { 149 + u8 lcrb = readb(&ch->ch_cls_uart->lcr); 150 + u8 ier = readb(&ch->ch_cls_uart->ier); 151 + u8 isr_fcr = 0; 152 + 153 + /* 154 + * The Enhanced Register Set may only be accessed when 155 + * the Line Control Register is set to 0xBFh. 156 + */ 157 + writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr); 158 + 159 + isr_fcr = readb(&ch->ch_cls_uart->isr_fcr); 160 + 161 + /* Turn off IXON flow control, turn off CTS flow control */ 162 + isr_fcr |= (UART_EXAR654_EFR_ECB); 163 + isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR | UART_EXAR654_EFR_IXON); 164 + 165 + writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr); 166 + 167 + /* Write old LCR value back out, which turns enhanced access off */ 168 + writeb(lcrb, &ch->ch_cls_uart->lcr); 169 + 170 + /* 171 + * Disable interrupts for CTS flow, turn off interrupts for 172 + * received XOFF chars 173 + */ 174 + ier &= ~(UART_EXAR654_IER_CTSDSR); 175 + ier &= ~(UART_EXAR654_IER_XOFF); 176 + writeb(ier, &ch->ch_cls_uart->ier); 177 + 178 + /* Set the usual FIFO values */ 179 + writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr); 180 + 181 + writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 | 182 + UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR), 183 + &ch->ch_cls_uart->isr_fcr); 184 + 185 + ch->ch_r_watermark = 0; 186 + ch->ch_t_tlevel = 16; 187 + ch->ch_r_tlevel = 16; 188 + } 189 + 190 + static void cls_set_rts_flow_control(struct jsm_channel *ch) 191 + { 192 + u8 lcrb = readb(&ch->ch_cls_uart->lcr); 193 + u8 ier = readb(&ch->ch_cls_uart->ier); 194 + u8 isr_fcr = 0; 195 + 196 + /* 197 + * The Enhanced Register Set may only be accessed when 198 + * the Line Control Register is set to 0xBFh. 199 + */ 200 + writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr); 201 + 202 + isr_fcr = readb(&ch->ch_cls_uart->isr_fcr); 203 + 204 + /* Turn on RTS flow control, turn off IXOFF flow control */ 205 + isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_RTSDTR); 206 + isr_fcr &= ~(UART_EXAR654_EFR_IXOFF); 207 + 208 + writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr); 209 + 210 + /* Write old LCR value back out, which turns enhanced access off */ 211 + writeb(lcrb, &ch->ch_cls_uart->lcr); 212 + 213 + /* Enable interrupts for RTS flow */ 214 + ier |= (UART_EXAR654_IER_RTSDTR); 215 + writeb(ier, &ch->ch_cls_uart->ier); 216 + 217 + /* Set the usual FIFO values */ 218 + writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr); 219 + 220 + writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 | 221 + UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR), 222 + &ch->ch_cls_uart->isr_fcr); 223 + 224 + ch->ch_r_watermark = 4; 225 + ch->ch_r_tlevel = 8; 226 + } 227 + 228 + static void cls_set_ixoff_flow_control(struct jsm_channel *ch) 229 + { 230 + u8 lcrb = readb(&ch->ch_cls_uart->lcr); 231 + u8 ier = readb(&ch->ch_cls_uart->ier); 232 + u8 isr_fcr = 0; 233 + 234 + /* 235 + * The Enhanced Register Set may only be accessed when 236 + * the Line Control Register is set to 0xBFh. 237 + */ 238 + writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr); 239 + 240 + isr_fcr = readb(&ch->ch_cls_uart->isr_fcr); 241 + 242 + /* Turn on IXOFF flow control, turn off RTS flow control */ 243 + isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXOFF); 244 + isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR); 245 + 246 + writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr); 247 + 248 + /* Now set our current start/stop chars while in enhanced mode */ 249 + writeb(ch->ch_startc, &ch->ch_cls_uart->mcr); 250 + writeb(0, &ch->ch_cls_uart->lsr); 251 + writeb(ch->ch_stopc, &ch->ch_cls_uart->msr); 252 + writeb(0, &ch->ch_cls_uart->spr); 253 + 254 + /* Write old LCR value back out, which turns enhanced access off */ 255 + writeb(lcrb, &ch->ch_cls_uart->lcr); 256 + 257 + /* Disable interrupts for RTS flow */ 258 + ier &= ~(UART_EXAR654_IER_RTSDTR); 259 + writeb(ier, &ch->ch_cls_uart->ier); 260 + 261 + /* Set the usual FIFO values */ 262 + writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr); 263 + 264 + writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 | 265 + UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR), 266 + &ch->ch_cls_uart->isr_fcr); 267 + } 268 + 269 + static void cls_set_no_input_flow_control(struct jsm_channel *ch) 270 + { 271 + u8 lcrb = readb(&ch->ch_cls_uart->lcr); 272 + u8 ier = readb(&ch->ch_cls_uart->ier); 273 + u8 isr_fcr = 0; 274 + 275 + /* 276 + * The Enhanced Register Set may only be accessed when 277 + * the Line Control Register is set to 0xBFh. 278 + */ 279 + writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr); 280 + 281 + isr_fcr = readb(&ch->ch_cls_uart->isr_fcr); 282 + 283 + /* Turn off IXOFF flow control, turn off RTS flow control */ 284 + isr_fcr |= (UART_EXAR654_EFR_ECB); 285 + isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR | UART_EXAR654_EFR_IXOFF); 286 + 287 + writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr); 288 + 289 + /* Write old LCR value back out, which turns enhanced access off */ 290 + writeb(lcrb, &ch->ch_cls_uart->lcr); 291 + 292 + /* Disable interrupts for RTS flow */ 293 + ier &= ~(UART_EXAR654_IER_RTSDTR); 294 + writeb(ier, &ch->ch_cls_uart->ier); 295 + 296 + /* Set the usual FIFO values */ 297 + writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr); 298 + 299 + writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 | 300 + UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR), 301 + &ch->ch_cls_uart->isr_fcr); 302 + 303 + ch->ch_t_tlevel = 16; 304 + ch->ch_r_tlevel = 16; 305 + } 306 + 307 + /* 308 + * cls_clear_break. 309 + * Determines whether its time to shut off break condition. 310 + * 311 + * No locks are assumed to be held when calling this function. 312 + * channel lock is held and released in this function. 313 + */ 314 + static void cls_clear_break(struct jsm_channel *ch) 315 + { 316 + unsigned long lock_flags; 317 + 318 + spin_lock_irqsave(&ch->ch_lock, lock_flags); 319 + 320 + /* Turn break off, and unset some variables */ 321 + if (ch->ch_flags & CH_BREAK_SENDING) { 322 + u8 temp = readb(&ch->ch_cls_uart->lcr); 323 + 324 + writeb((temp & ~UART_LCR_SBC), &ch->ch_cls_uart->lcr); 325 + 326 + ch->ch_flags &= ~(CH_BREAK_SENDING); 327 + jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, 328 + "clear break Finishing UART_LCR_SBC! finished: %lx\n", 329 + jiffies); 330 + } 331 + spin_unlock_irqrestore(&ch->ch_lock, lock_flags); 332 + } 333 + 334 + static void cls_disable_receiver(struct jsm_channel *ch) 335 + { 336 + u8 tmp = readb(&ch->ch_cls_uart->ier); 337 + 338 + tmp &= ~(UART_IER_RDI); 339 + writeb(tmp, &ch->ch_cls_uart->ier); 340 + } 341 + 342 + static void cls_enable_receiver(struct jsm_channel *ch) 343 + { 344 + u8 tmp = readb(&ch->ch_cls_uart->ier); 345 + 346 + tmp |= (UART_IER_RDI); 347 + writeb(tmp, &ch->ch_cls_uart->ier); 348 + } 349 + 350 + /* Make the UART raise any of the output signals we want up */ 351 + static void cls_assert_modem_signals(struct jsm_channel *ch) 352 + { 353 + if (!ch) 354 + return; 355 + 356 + writeb(ch->ch_mostat, &ch->ch_cls_uart->mcr); 357 + } 358 + 359 + static void cls_copy_data_from_uart_to_queue(struct jsm_channel *ch) 360 + { 361 + int qleft = 0; 362 + u8 linestatus = 0; 363 + u8 error_mask = 0; 364 + u16 head; 365 + u16 tail; 366 + unsigned long flags; 367 + 368 + if (!ch) 369 + return; 370 + 371 + spin_lock_irqsave(&ch->ch_lock, flags); 372 + 373 + /* cache head and tail of queue */ 374 + head = ch->ch_r_head & RQUEUEMASK; 375 + tail = ch->ch_r_tail & RQUEUEMASK; 376 + 377 + /* Get our cached LSR */ 378 + linestatus = ch->ch_cached_lsr; 379 + ch->ch_cached_lsr = 0; 380 + 381 + /* Store how much space we have left in the queue */ 382 + qleft = tail - head - 1; 383 + if (qleft < 0) 384 + qleft += RQUEUEMASK + 1; 385 + 386 + /* 387 + * Create a mask to determine whether we should 388 + * insert the character (if any) into our queue. 389 + */ 390 + if (ch->ch_c_iflag & IGNBRK) 391 + error_mask |= UART_LSR_BI; 392 + 393 + while (1) { 394 + /* 395 + * Grab the linestatus register, we need to 396 + * check to see if there is any data to read 397 + */ 398 + linestatus = readb(&ch->ch_cls_uart->lsr); 399 + 400 + /* Break out if there is no data to fetch */ 401 + if (!(linestatus & UART_LSR_DR)) 402 + break; 403 + 404 + /* 405 + * Discard character if we are ignoring the error mask 406 + * which in this case is the break signal. 407 + */ 408 + if (linestatus & error_mask) { 409 + u8 discard; 410 + 411 + linestatus = 0; 412 + discard = readb(&ch->ch_cls_uart->txrx); 413 + continue; 414 + } 415 + 416 + /* 417 + * If our queue is full, we have no choice but to drop some 418 + * data. The assumption is that HWFLOW or SWFLOW should have 419 + * stopped things way way before we got to this point. 420 + * 421 + * I decided that I wanted to ditch the oldest data first, 422 + * I hope thats okay with everyone? Yes? Good. 423 + */ 424 + while (qleft < 1) { 425 + tail = (tail + 1) & RQUEUEMASK; 426 + ch->ch_r_tail = tail; 427 + ch->ch_err_overrun++; 428 + qleft++; 429 + } 430 + 431 + ch->ch_equeue[head] = linestatus & (UART_LSR_BI | UART_LSR_PE 432 + | UART_LSR_FE); 433 + ch->ch_rqueue[head] = readb(&ch->ch_cls_uart->txrx); 434 + 435 + qleft--; 436 + 437 + if (ch->ch_equeue[head] & UART_LSR_PE) 438 + ch->ch_err_parity++; 439 + if (ch->ch_equeue[head] & UART_LSR_BI) 440 + ch->ch_err_break++; 441 + if (ch->ch_equeue[head] & UART_LSR_FE) 442 + ch->ch_err_frame++; 443 + 444 + /* Add to, and flip head if needed */ 445 + head = (head + 1) & RQUEUEMASK; 446 + ch->ch_rxcount++; 447 + } 448 + 449 + /* 450 + * Write new final heads to channel structure. 451 + */ 452 + ch->ch_r_head = head & RQUEUEMASK; 453 + ch->ch_e_head = head & EQUEUEMASK; 454 + 455 + spin_unlock_irqrestore(&ch->ch_lock, flags); 456 + } 457 + 458 + static void cls_copy_data_from_queue_to_uart(struct jsm_channel *ch) 459 + { 460 + u16 tail; 461 + int n; 462 + int qlen; 463 + u32 len_written = 0; 464 + struct circ_buf *circ; 465 + 466 + if (!ch) 467 + return; 468 + 469 + circ = &ch->uart_port.state->xmit; 470 + 471 + /* No data to write to the UART */ 472 + if (uart_circ_empty(circ)) 473 + return; 474 + 475 + /* If port is "stopped", don't send any data to the UART */ 476 + if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_BREAK_SENDING)) 477 + return; 478 + 479 + /* We have to do it this way, because of the EXAR TXFIFO count bug. */ 480 + if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM))) 481 + return; 482 + 483 + n = 32; 484 + 485 + /* cache tail of queue */ 486 + tail = circ->tail & (UART_XMIT_SIZE - 1); 487 + qlen = uart_circ_chars_pending(circ); 488 + 489 + /* Find minimum of the FIFO space, versus queue length */ 490 + n = min(n, qlen); 491 + 492 + while (n > 0) { 493 + writeb(circ->buf[tail], &ch->ch_cls_uart->txrx); 494 + tail = (tail + 1) & (UART_XMIT_SIZE - 1); 495 + n--; 496 + ch->ch_txcount++; 497 + len_written++; 498 + } 499 + 500 + /* Update the final tail */ 501 + circ->tail = tail & (UART_XMIT_SIZE - 1); 502 + 503 + if (len_written > ch->ch_t_tlevel) 504 + ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 505 + 506 + if (uart_circ_empty(circ)) 507 + uart_write_wakeup(&ch->uart_port); 508 + } 509 + 510 + static void cls_parse_modem(struct jsm_channel *ch, u8 signals) 511 + { 512 + u8 msignals = signals; 513 + 514 + jsm_dbg(MSIGS, &ch->ch_bd->pci_dev, 515 + "neo_parse_modem: port: %d msignals: %x\n", 516 + ch->ch_portnum, msignals); 517 + 518 + /* 519 + * Scrub off lower bits. 520 + * They signify delta's, which I don't care about 521 + * Keep DDCD and DDSR though 522 + */ 523 + msignals &= 0xf8; 524 + 525 + if (msignals & UART_MSR_DDCD) 526 + uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_DCD); 527 + if (msignals & UART_MSR_DDSR) 528 + uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_CTS); 529 + 530 + if (msignals & UART_MSR_DCD) 531 + ch->ch_mistat |= UART_MSR_DCD; 532 + else 533 + ch->ch_mistat &= ~UART_MSR_DCD; 534 + 535 + if (msignals & UART_MSR_DSR) 536 + ch->ch_mistat |= UART_MSR_DSR; 537 + else 538 + ch->ch_mistat &= ~UART_MSR_DSR; 539 + 540 + if (msignals & UART_MSR_RI) 541 + ch->ch_mistat |= UART_MSR_RI; 542 + else 543 + ch->ch_mistat &= ~UART_MSR_RI; 544 + 545 + if (msignals & UART_MSR_CTS) 546 + ch->ch_mistat |= UART_MSR_CTS; 547 + else 548 + ch->ch_mistat &= ~UART_MSR_CTS; 549 + 550 + jsm_dbg(MSIGS, &ch->ch_bd->pci_dev, 551 + "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n", 552 + ch->ch_portnum, 553 + !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_DTR), 554 + !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_RTS), 555 + !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_CTS), 556 + !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DSR), 557 + !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_RI), 558 + !!((ch->ch_mistat | ch->ch_mostat) & UART_MSR_DCD)); 559 + } 560 + 561 + /* Parse the ISR register for the specific port */ 562 + static inline void cls_parse_isr(struct jsm_board *brd, uint port) 563 + { 564 + struct jsm_channel *ch; 565 + u8 isr = 0; 566 + unsigned long flags; 567 + 568 + /* 569 + * No need to verify board pointer, it was already 570 + * verified in the interrupt routine. 571 + */ 572 + 573 + if (port > brd->nasync) 574 + return; 575 + 576 + ch = brd->channels[port]; 577 + if (!ch) 578 + return; 579 + 580 + /* Here we try to figure out what caused the interrupt to happen */ 581 + while (1) { 582 + isr = readb(&ch->ch_cls_uart->isr_fcr); 583 + 584 + /* Bail if no pending interrupt on port */ 585 + if (isr & UART_IIR_NO_INT) 586 + break; 587 + 588 + /* Receive Interrupt pending */ 589 + if (isr & (UART_IIR_RDI | UART_IIR_RDI_TIMEOUT)) { 590 + /* Read data from uart -> queue */ 591 + cls_copy_data_from_uart_to_queue(ch); 592 + jsm_check_queue_flow_control(ch); 593 + } 594 + 595 + /* Transmit Hold register empty pending */ 596 + if (isr & UART_IIR_THRI) { 597 + /* Transfer data (if any) from Write Queue -> UART. */ 598 + spin_lock_irqsave(&ch->ch_lock, flags); 599 + ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 600 + spin_unlock_irqrestore(&ch->ch_lock, flags); 601 + cls_copy_data_from_queue_to_uart(ch); 602 + } 603 + 604 + /* 605 + * CTS/RTS change of state: 606 + * Don't need to do anything, the cls_parse_modem 607 + * below will grab the updated modem signals. 608 + */ 609 + 610 + /* Parse any modem signal changes */ 611 + cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr)); 612 + } 613 + } 614 + 615 + /* Channel lock MUST be held before calling this function! */ 616 + static void cls_flush_uart_write(struct jsm_channel *ch) 617 + { 618 + u8 tmp = 0; 619 + u8 i = 0; 620 + 621 + if (!ch) 622 + return; 623 + 624 + writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), 625 + &ch->ch_cls_uart->isr_fcr); 626 + 627 + for (i = 0; i < 10; i++) { 628 + /* Check to see if the UART feels it completely flushed FIFO */ 629 + tmp = readb(&ch->ch_cls_uart->isr_fcr); 630 + if (tmp & UART_FCR_CLEAR_XMIT) { 631 + jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, 632 + "Still flushing TX UART... i: %d\n", i); 633 + udelay(10); 634 + } else 635 + break; 636 + } 637 + 638 + ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 639 + } 640 + 641 + /* Channel lock MUST be held before calling this function! */ 642 + static void cls_flush_uart_read(struct jsm_channel *ch) 643 + { 644 + if (!ch) 645 + return; 646 + 647 + /* 648 + * For complete POSIX compatibility, we should be purging the 649 + * read FIFO in the UART here. 650 + * 651 + * However, clearing the read FIFO (UART_FCR_CLEAR_RCVR) also 652 + * incorrectly flushes write data as well as just basically trashing the 653 + * FIFO. 654 + * 655 + * Presumably, this is a bug in this UART. 656 + */ 657 + 658 + udelay(10); 659 + } 660 + 661 + static void cls_send_start_character(struct jsm_channel *ch) 662 + { 663 + if (!ch) 664 + return; 665 + 666 + if (ch->ch_startc != __DISABLED_CHAR) { 667 + ch->ch_xon_sends++; 668 + writeb(ch->ch_startc, &ch->ch_cls_uart->txrx); 669 + } 670 + } 671 + 672 + static void cls_send_stop_character(struct jsm_channel *ch) 673 + { 674 + if (!ch) 675 + return; 676 + 677 + if (ch->ch_stopc != __DISABLED_CHAR) { 678 + ch->ch_xoff_sends++; 679 + writeb(ch->ch_stopc, &ch->ch_cls_uart->txrx); 680 + } 681 + } 682 + 683 + /* 684 + * cls_param() 685 + * Send any/all changes to the line to the UART. 686 + */ 687 + static void cls_param(struct jsm_channel *ch) 688 + { 689 + u8 lcr = 0; 690 + u8 uart_lcr = 0; 691 + u8 ier = 0; 692 + u32 baud = 9600; 693 + int quot = 0; 694 + struct jsm_board *bd; 695 + int i; 696 + unsigned int cflag; 697 + 698 + bd = ch->ch_bd; 699 + if (!bd) 700 + return; 701 + 702 + /* 703 + * If baud rate is zero, flush queues, and set mval to drop DTR. 704 + */ 705 + if ((ch->ch_c_cflag & (CBAUD)) == 0) { 706 + ch->ch_r_head = 0; 707 + ch->ch_r_tail = 0; 708 + ch->ch_e_head = 0; 709 + ch->ch_e_tail = 0; 710 + 711 + cls_flush_uart_write(ch); 712 + cls_flush_uart_read(ch); 713 + 714 + /* The baudrate is B0 so all modem lines are to be dropped. */ 715 + ch->ch_flags |= (CH_BAUD0); 716 + ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR); 717 + cls_assert_modem_signals(ch); 718 + return; 719 + } 720 + 721 + cflag = C_BAUD(ch->uart_port.state->port.tty); 722 + baud = 9600; 723 + for (i = 0; i < ARRAY_SIZE(baud_rates); i++) { 724 + if (baud_rates[i].cflag == cflag) { 725 + baud = baud_rates[i].rate; 726 + break; 727 + } 728 + } 729 + 730 + if (ch->ch_flags & CH_BAUD0) 731 + ch->ch_flags &= ~(CH_BAUD0); 732 + 733 + if (ch->ch_c_cflag & PARENB) 734 + lcr |= UART_LCR_PARITY; 735 + 736 + if (!(ch->ch_c_cflag & PARODD)) 737 + lcr |= UART_LCR_EPAR; 738 + 739 + /* 740 + * Not all platforms support mark/space parity, 741 + * so this will hide behind an ifdef. 742 + */ 743 + #ifdef CMSPAR 744 + if (ch->ch_c_cflag & CMSPAR) 745 + lcr |= UART_LCR_SPAR; 746 + #endif 747 + 748 + if (ch->ch_c_cflag & CSTOPB) 749 + lcr |= UART_LCR_STOP; 750 + 751 + switch (ch->ch_c_cflag & CSIZE) { 752 + case CS5: 753 + lcr |= UART_LCR_WLEN5; 754 + break; 755 + case CS6: 756 + lcr |= UART_LCR_WLEN6; 757 + break; 758 + case CS7: 759 + lcr |= UART_LCR_WLEN7; 760 + break; 761 + case CS8: 762 + default: 763 + lcr |= UART_LCR_WLEN8; 764 + break; 765 + } 766 + 767 + ier = readb(&ch->ch_cls_uart->ier); 768 + uart_lcr = readb(&ch->ch_cls_uart->lcr); 769 + 770 + quot = ch->ch_bd->bd_dividend / baud; 771 + 772 + if (quot != 0) { 773 + writeb(UART_LCR_DLAB, &ch->ch_cls_uart->lcr); 774 + writeb((quot & 0xff), &ch->ch_cls_uart->txrx); 775 + writeb((quot >> 8), &ch->ch_cls_uart->ier); 776 + writeb(lcr, &ch->ch_cls_uart->lcr); 777 + } 778 + 779 + if (uart_lcr != lcr) 780 + writeb(lcr, &ch->ch_cls_uart->lcr); 781 + 782 + if (ch->ch_c_cflag & CREAD) 783 + ier |= (UART_IER_RDI | UART_IER_RLSI); 784 + 785 + ier |= (UART_IER_THRI | UART_IER_MSI); 786 + 787 + writeb(ier, &ch->ch_cls_uart->ier); 788 + 789 + if (ch->ch_c_cflag & CRTSCTS) 790 + cls_set_cts_flow_control(ch); 791 + else if (ch->ch_c_iflag & IXON) { 792 + /* 793 + * If start/stop is set to disable, 794 + * then we should disable flow control. 795 + */ 796 + if ((ch->ch_startc == __DISABLED_CHAR) || 797 + (ch->ch_stopc == __DISABLED_CHAR)) 798 + cls_set_no_output_flow_control(ch); 799 + else 800 + cls_set_ixon_flow_control(ch); 801 + } else 802 + cls_set_no_output_flow_control(ch); 803 + 804 + if (ch->ch_c_cflag & CRTSCTS) 805 + cls_set_rts_flow_control(ch); 806 + else if (ch->ch_c_iflag & IXOFF) { 807 + /* 808 + * If start/stop is set to disable, 809 + * then we should disable flow control. 810 + */ 811 + if ((ch->ch_startc == __DISABLED_CHAR) || 812 + (ch->ch_stopc == __DISABLED_CHAR)) 813 + cls_set_no_input_flow_control(ch); 814 + else 815 + cls_set_ixoff_flow_control(ch); 816 + } else 817 + cls_set_no_input_flow_control(ch); 818 + 819 + cls_assert_modem_signals(ch); 820 + 821 + /* get current status of the modem signals now */ 822 + cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr)); 823 + } 824 + 825 + /* 826 + * cls_intr() 827 + * 828 + * Classic specific interrupt handler. 829 + */ 830 + static irqreturn_t cls_intr(int irq, void *voidbrd) 831 + { 832 + struct jsm_board *brd = voidbrd; 833 + unsigned long lock_flags; 834 + unsigned char uart_poll; 835 + uint i = 0; 836 + 837 + /* Lock out the slow poller from running on this board. */ 838 + spin_lock_irqsave(&brd->bd_intr_lock, lock_flags); 839 + 840 + /* 841 + * Check the board's global interrupt offset to see if we 842 + * acctually do have an interrupt pending on us. 843 + */ 844 + uart_poll = readb(brd->re_map_membase + UART_CLASSIC_POLL_ADDR_OFFSET); 845 + 846 + jsm_dbg(INTR, &brd->pci_dev, "%s:%d uart_poll: %x\n", 847 + __FILE__, __LINE__, uart_poll); 848 + 849 + if (!uart_poll) { 850 + jsm_dbg(INTR, &brd->pci_dev, 851 + "Kernel interrupted to me, but no pending interrupts...\n"); 852 + spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags); 853 + return IRQ_NONE; 854 + } 855 + 856 + /* At this point, we have at least SOMETHING to service, dig further. */ 857 + 858 + /* Parse each port to find out what caused the interrupt */ 859 + for (i = 0; i < brd->nasync; i++) 860 + cls_parse_isr(brd, i); 861 + 862 + spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags); 863 + 864 + return IRQ_HANDLED; 865 + } 866 + 867 + /* Inits UART */ 868 + static void cls_uart_init(struct jsm_channel *ch) 869 + { 870 + unsigned char lcrb = readb(&ch->ch_cls_uart->lcr); 871 + unsigned char isr_fcr = 0; 872 + 873 + writeb(0, &ch->ch_cls_uart->ier); 874 + 875 + /* 876 + * The Enhanced Register Set may only be accessed when 877 + * the Line Control Register is set to 0xBFh. 878 + */ 879 + writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr); 880 + 881 + isr_fcr = readb(&ch->ch_cls_uart->isr_fcr); 882 + 883 + /* Turn on Enhanced/Extended controls */ 884 + isr_fcr |= (UART_EXAR654_EFR_ECB); 885 + 886 + writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr); 887 + 888 + /* Write old LCR value back out, which turns enhanced access off */ 889 + writeb(lcrb, &ch->ch_cls_uart->lcr); 890 + 891 + /* Clear out UART and FIFO */ 892 + readb(&ch->ch_cls_uart->txrx); 893 + 894 + writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), 895 + &ch->ch_cls_uart->isr_fcr); 896 + udelay(10); 897 + 898 + ch->ch_flags |= (CH_FIFO_ENABLED | CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 899 + 900 + readb(&ch->ch_cls_uart->lsr); 901 + readb(&ch->ch_cls_uart->msr); 902 + } 903 + 904 + /* 905 + * Turns off UART. 906 + */ 907 + static void cls_uart_off(struct jsm_channel *ch) 908 + { 909 + /* Stop all interrupts from accurring. */ 910 + writeb(0, &ch->ch_cls_uart->ier); 911 + } 912 + 913 + /* 914 + * cls_get_uarts_bytes_left. 915 + * Returns 0 is nothing left in the FIFO, returns 1 otherwise. 916 + * 917 + * The channel lock MUST be held by the calling function. 918 + */ 919 + static u32 cls_get_uart_bytes_left(struct jsm_channel *ch) 920 + { 921 + u8 left = 0; 922 + u8 lsr = readb(&ch->ch_cls_uart->lsr); 923 + 924 + /* Determine whether the Transmitter is empty or not */ 925 + if (!(lsr & UART_LSR_TEMT)) 926 + left = 1; 927 + else { 928 + ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 929 + left = 0; 930 + } 931 + 932 + return left; 933 + } 934 + 935 + /* 936 + * cls_send_break. 937 + * Starts sending a break thru the UART. 938 + * 939 + * The channel lock MUST be held by the calling function. 940 + */ 941 + static void cls_send_break(struct jsm_channel *ch) 942 + { 943 + /* Tell the UART to start sending the break */ 944 + if (!(ch->ch_flags & CH_BREAK_SENDING)) { 945 + u8 temp = readb(&ch->ch_cls_uart->lcr); 946 + 947 + writeb((temp | UART_LCR_SBC), &ch->ch_cls_uart->lcr); 948 + ch->ch_flags |= (CH_BREAK_SENDING); 949 + } 950 + } 951 + 952 + /* 953 + * cls_send_immediate_char. 954 + * Sends a specific character as soon as possible to the UART, 955 + * jumping over any bytes that might be in the write queue. 956 + * 957 + * The channel lock MUST be held by the calling function. 958 + */ 959 + static void cls_send_immediate_char(struct jsm_channel *ch, unsigned char c) 960 + { 961 + writeb(c, &ch->ch_cls_uart->txrx); 962 + } 963 + 964 + struct board_ops jsm_cls_ops = { 965 + .intr = cls_intr, 966 + .uart_init = cls_uart_init, 967 + .uart_off = cls_uart_off, 968 + .param = cls_param, 969 + .assert_modem_signals = cls_assert_modem_signals, 970 + .flush_uart_write = cls_flush_uart_write, 971 + .flush_uart_read = cls_flush_uart_read, 972 + .disable_receiver = cls_disable_receiver, 973 + .enable_receiver = cls_enable_receiver, 974 + .send_break = cls_send_break, 975 + .clear_break = cls_clear_break, 976 + .send_start_character = cls_send_start_character, 977 + .send_stop_character = cls_send_stop_character, 978 + .copy_data_from_queue_to_uart = cls_copy_data_from_queue_to_uart, 979 + .get_uart_bytes_left = cls_get_uart_bytes_left, 980 + .send_immediate_char = cls_send_immediate_char 981 + }; 982 +
+120 -36
drivers/tty/serial/jsm/jsm_driver.c
··· 13 13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 14 * PURPOSE. See the GNU General Public License for more details. 15 15 * 16 - * You should have received a copy of the GNU General Public License 17 - * along with this program; if not, write to the Free Software 18 - * Foundation, Inc., 59 * Temple Place - Suite 330, Boston, 19 - * MA 02111-1307, USA. 20 - * 21 16 * Contact Information: 22 17 * Scott H Kilau <Scott_Kilau@digi.com> 23 18 * Wendy Xiong <wendyx@us.ibm.com> ··· 26 31 #include "jsm.h" 27 32 28 33 MODULE_AUTHOR("Digi International, http://www.digi.com"); 29 - MODULE_DESCRIPTION("Driver for the Digi International " 30 - "Neo PCI based product line"); 34 + MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line"); 31 35 MODULE_LICENSE("GPL"); 32 36 MODULE_SUPPORTED_DEVICE("jsm"); 33 37 ··· 44 50 }; 45 51 46 52 static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev, 47 - pci_channel_state_t state); 53 + pci_channel_state_t state); 48 54 static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev); 49 55 static void jsm_io_resume(struct pci_dev *pdev); 50 56 ··· 62 68 { 63 69 int rc = 0; 64 70 struct jsm_board *brd; 65 - static int adapter_count = 0; 71 + static int adapter_count; 66 72 67 73 rc = pci_enable_device(pdev); 68 74 if (rc) { ··· 76 82 goto out_disable_device; 77 83 } 78 84 79 - brd = kzalloc(sizeof(struct jsm_board), GFP_KERNEL); 85 + brd = kzalloc(sizeof(*brd), GFP_KERNEL); 80 86 if (!brd) { 81 - dev_err(&pdev->dev, 82 - "memory allocation for board structure failed\n"); 83 87 rc = -ENOMEM; 84 88 goto out_release_regions; 85 89 } ··· 87 95 brd->pci_dev = pdev; 88 96 89 97 switch (pdev->device) { 90 - 91 98 case PCI_DEVICE_ID_NEO_2DB9: 92 99 case PCI_DEVICE_ID_NEO_2DB9PRI: 93 100 case PCI_DEVICE_ID_NEO_2RJ45: ··· 95 104 brd->maxports = 2; 96 105 break; 97 106 107 + case PCI_DEVICE_ID_CLASSIC_4: 108 + case PCI_DEVICE_ID_CLASSIC_4_422: 98 109 case PCI_DEVICE_ID_NEO_4: 99 110 case PCIE_DEVICE_ID_NEO_4: 100 111 case PCIE_DEVICE_ID_NEO_4RJ45: ··· 104 111 brd->maxports = 4; 105 112 break; 106 113 114 + case PCI_DEVICE_ID_CLASSIC_8: 115 + case PCI_DEVICE_ID_CLASSIC_8_422: 107 116 case PCI_DEVICE_ID_DIGI_NEO_8: 108 117 case PCIE_DEVICE_ID_NEO_8: 109 118 case PCIE_DEVICE_ID_NEO_8RJ45: ··· 124 129 125 130 brd->irq = pdev->irq; 126 131 127 - jsm_dbg(INIT, &brd->pci_dev, "jsm_found_board - NEO adapter\n"); 132 + switch (pdev->device) { 133 + case PCI_DEVICE_ID_CLASSIC_4: 134 + case PCI_DEVICE_ID_CLASSIC_4_422: 135 + case PCI_DEVICE_ID_CLASSIC_8: 136 + case PCI_DEVICE_ID_CLASSIC_8_422: 128 137 129 - /* get the PCI Base Address Registers */ 130 - brd->membase = pci_resource_start(pdev, 0); 131 - brd->membase_end = pci_resource_end(pdev, 0); 138 + jsm_dbg(INIT, &brd->pci_dev, 139 + "jsm_found_board - Classic adapter\n"); 132 140 133 - if (brd->membase & 1) 134 - brd->membase &= ~3; 135 - else 136 - brd->membase &= ~15; 141 + /* 142 + * For PCI ClassicBoards 143 + * PCI Local Address (.i.e. "resource" number) space 144 + * 0 PLX Memory Mapped Config 145 + * 1 PLX I/O Mapped Config 146 + * 2 I/O Mapped UARTs and Status 147 + * 3 Memory Mapped VPD 148 + * 4 Memory Mapped UARTs and Status 149 + */ 137 150 138 - /* Assign the board_ops struct */ 139 - brd->bd_ops = &jsm_neo_ops; 151 + /* Get the PCI Base Address Registers */ 152 + brd->membase = pci_resource_start(pdev, 4); 153 + brd->membase_end = pci_resource_end(pdev, 4); 140 154 141 - brd->bd_uart_offset = 0x200; 142 - brd->bd_dividend = 921600; 155 + if (brd->membase & 0x1) 156 + brd->membase &= ~0x3; 157 + else 158 + brd->membase &= ~0xF; 143 159 144 - brd->re_map_membase = ioremap(brd->membase, pci_resource_len(pdev, 0)); 145 - if (!brd->re_map_membase) { 146 - dev_err(&pdev->dev, 147 - "card has no PCI Memory resources, " 148 - "failing board.\n"); 149 - rc = -ENOMEM; 150 - goto out_kfree_brd; 160 + brd->iobase = pci_resource_start(pdev, 1); 161 + brd->iobase_end = pci_resource_end(pdev, 1); 162 + brd->iobase = ((unsigned int)(brd->iobase)) & 0xFFFE; 163 + 164 + /* Assign the board_ops struct */ 165 + brd->bd_ops = &jsm_cls_ops; 166 + 167 + brd->bd_uart_offset = 0x8; 168 + brd->bd_dividend = 921600; 169 + 170 + brd->re_map_membase = ioremap(brd->membase, 171 + pci_resource_len(pdev, 4)); 172 + if (!brd->re_map_membase) { 173 + dev_err(&pdev->dev, 174 + "Card has no PCI Memory resources, failing board.\n"); 175 + rc = -ENOMEM; 176 + goto out_kfree_brd; 177 + } 178 + 179 + /* 180 + * Enable Local Interrupt 1 (0x1), 181 + * Local Interrupt 1 Polarity Active high (0x2), 182 + * Enable PCI interrupt (0x43) 183 + */ 184 + outb(0x43, brd->iobase + 0x4c); 185 + 186 + break; 187 + 188 + case PCI_DEVICE_ID_NEO_2DB9: 189 + case PCI_DEVICE_ID_NEO_2DB9PRI: 190 + case PCI_DEVICE_ID_NEO_2RJ45: 191 + case PCI_DEVICE_ID_NEO_2RJ45PRI: 192 + case PCI_DEVICE_ID_NEO_2_422_485: 193 + case PCI_DEVICE_ID_NEO_4: 194 + case PCIE_DEVICE_ID_NEO_4: 195 + case PCIE_DEVICE_ID_NEO_4RJ45: 196 + case PCIE_DEVICE_ID_NEO_4_IBM: 197 + case PCI_DEVICE_ID_DIGI_NEO_8: 198 + case PCIE_DEVICE_ID_NEO_8: 199 + case PCIE_DEVICE_ID_NEO_8RJ45: 200 + 201 + jsm_dbg(INIT, &brd->pci_dev, "jsm_found_board - NEO adapter\n"); 202 + 203 + /* get the PCI Base Address Registers */ 204 + brd->membase = pci_resource_start(pdev, 0); 205 + brd->membase_end = pci_resource_end(pdev, 0); 206 + 207 + if (brd->membase & 1) 208 + brd->membase &= ~0x3; 209 + else 210 + brd->membase &= ~0xF; 211 + 212 + /* Assign the board_ops struct */ 213 + brd->bd_ops = &jsm_neo_ops; 214 + 215 + brd->bd_uart_offset = 0x200; 216 + brd->bd_dividend = 921600; 217 + 218 + brd->re_map_membase = ioremap(brd->membase, 219 + pci_resource_len(pdev, 0)); 220 + if (!brd->re_map_membase) { 221 + dev_err(&pdev->dev, 222 + "Card has no PCI Memory resources, failing board.\n"); 223 + rc = -ENOMEM; 224 + goto out_kfree_brd; 225 + } 226 + 227 + break; 228 + default: 229 + return -ENXIO; 151 230 } 152 231 153 - rc = request_irq(brd->irq, brd->bd_ops->intr, 154 - IRQF_SHARED, "JSM", brd); 232 + rc = request_irq(brd->irq, brd->bd_ops->intr, IRQF_SHARED, "JSM", brd); 155 233 if (rc) { 156 - printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq); 234 + dev_warn(&pdev->dev, "Failed to hook IRQ %d\n", brd->irq); 157 235 goto out_iounmap; 158 236 } 159 237 ··· 246 178 } 247 179 248 180 /* Log the information about the board */ 249 - dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n", 181 + dev_info(&pdev->dev, "board %d: Digi Classic/Neo (rev %d), irq %d\n", 250 182 adapter_count, brd->rev, brd->irq); 251 183 252 184 pci_set_drvdata(pdev, brd); ··· 272 204 { 273 205 struct jsm_board *brd = pci_get_drvdata(pdev); 274 206 int i = 0; 207 + 208 + switch (pdev->device) { 209 + case PCI_DEVICE_ID_CLASSIC_4: 210 + case PCI_DEVICE_ID_CLASSIC_4_422: 211 + case PCI_DEVICE_ID_CLASSIC_8: 212 + case PCI_DEVICE_ID_CLASSIC_8_422: 213 + /* Tell card not to interrupt anymore. */ 214 + outb(0x0, brd->iobase + 0x4c); 215 + break; 216 + default: 217 + break; 218 + } 275 219 276 220 jsm_remove_uart_port(brd); 277 221 ··· 319 239 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4), 0, 0, 11 }, 320 240 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4RJ45), 0, 0, 12 }, 321 241 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_8RJ45), 0, 0, 13 }, 242 + { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_CLASSIC_4), 0, 0, 14 }, 243 + { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_CLASSIC_4_422), 0, 0, 15 }, 244 + { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_CLASSIC_8), 0, 0, 16 }, 245 + { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_CLASSIC_8_422), 0, 0, 17 }, 322 246 { 0, } 323 247 }; 324 248 MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
+14 -22
drivers/tty/serial/jsm/jsm_neo.c
··· 13 13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 14 * PURPOSE. See the GNU General Public License for more details. 15 15 * 16 - * You should have received a copy of the GNU General Public License 17 - * along with this program; if not, write to the Free Software 18 - * Foundation, Inc., 59 * Temple Place - Suite 330, Boston, 19 - * MA 02111-1307, USA. 20 - * 21 16 * Contact Information: 22 17 * Scott H Kilau <Scott_Kilau@digi.com> 23 18 * Wendy Xiong <wendyx@us.ibm.com> ··· 644 649 645 650 /* Check to see if the UART feels it completely flushed the FIFO. */ 646 651 tmp = readb(&ch->ch_neo_uart->isr_fcr); 647 - if (tmp & 4) { 652 + if (tmp & UART_FCR_CLEAR_XMIT) { 648 653 jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, 649 654 "Still flushing TX UART... i: %d\n", i); 650 655 udelay(10); ··· 689 694 /* 690 695 * No locks are assumed to be held when calling this function. 691 696 */ 692 - static void neo_clear_break(struct jsm_channel *ch, int force) 697 + static void neo_clear_break(struct jsm_channel *ch) 693 698 { 694 699 unsigned long lock_flags; 695 700 ··· 1019 1024 lcr |= UART_LCR_STOP; 1020 1025 1021 1026 switch (ch->ch_c_cflag & CSIZE) { 1022 - case CS5: 1023 - lcr |= UART_LCR_WLEN5; 1024 - break; 1025 - case CS6: 1026 - lcr |= UART_LCR_WLEN6; 1027 - break; 1028 - case CS7: 1029 - lcr |= UART_LCR_WLEN7; 1030 - break; 1031 - case CS8: 1032 - default: 1033 - lcr |= UART_LCR_WLEN8; 1027 + case CS5: 1028 + lcr |= UART_LCR_WLEN5; 1034 1029 break; 1030 + case CS6: 1031 + lcr |= UART_LCR_WLEN6; 1032 + break; 1033 + case CS7: 1034 + lcr |= UART_LCR_WLEN7; 1035 + break; 1036 + case CS8: 1037 + default: 1038 + lcr |= UART_LCR_WLEN8; 1039 + break; 1035 1040 } 1036 1041 1037 1042 ier = readb(&ch->ch_neo_uart->ier); 1038 1043 uart_lcr = readb(&ch->ch_neo_uart->lcr); 1039 - 1040 - if (baud == 0) 1041 - baud = 9600; 1042 1044 1043 1045 quot = ch->ch_bd->bd_dividend / baud; 1044 1046
+23 -16
drivers/tty/serial/jsm/jsm_tty.c
··· 13 13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 14 * PURPOSE. See the GNU General Public License for more details. 15 15 * 16 - * You should have received a copy of the GNU General Public License 17 - * along with this program; if not, write to the Free Software 18 - * Foundation, Inc., 59 * Temple Place - Suite 330, Boston, 19 - * MA 02111-1307, USA. 20 - * 21 16 * Contact Information: 22 17 * Scott H Kilau <Scott_Kilau@digi.com> 23 18 * Ananda Venkatarman <mansarov@us.ibm.com> ··· 72 77 static unsigned int jsm_tty_get_mctrl(struct uart_port *port) 73 78 { 74 79 int result; 75 - struct jsm_channel *channel = (struct jsm_channel *)port; 80 + struct jsm_channel *channel = 81 + container_of(port, struct jsm_channel, uart_port); 76 82 77 83 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n"); 78 84 ··· 94 98 */ 95 99 static void jsm_tty_set_mctrl(struct uart_port *port, unsigned int mctrl) 96 100 { 97 - struct jsm_channel *channel = (struct jsm_channel *)port; 101 + struct jsm_channel *channel = 102 + container_of(port, struct jsm_channel, uart_port); 98 103 99 104 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n"); 100 105 ··· 130 133 131 134 static void jsm_tty_start_tx(struct uart_port *port) 132 135 { 133 - struct jsm_channel *channel = (struct jsm_channel *)port; 136 + struct jsm_channel *channel = 137 + container_of(port, struct jsm_channel, uart_port); 134 138 135 139 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n"); 136 140 ··· 143 145 144 146 static void jsm_tty_stop_tx(struct uart_port *port) 145 147 { 146 - struct jsm_channel *channel = (struct jsm_channel *)port; 148 + struct jsm_channel *channel = 149 + container_of(port, struct jsm_channel, uart_port); 147 150 148 151 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n"); 149 152 ··· 156 157 static void jsm_tty_send_xchar(struct uart_port *port, char ch) 157 158 { 158 159 unsigned long lock_flags; 159 - struct jsm_channel *channel = (struct jsm_channel *)port; 160 + struct jsm_channel *channel = 161 + container_of(port, struct jsm_channel, uart_port); 160 162 struct ktermios *termios; 161 163 162 164 spin_lock_irqsave(&port->lock, lock_flags); ··· 172 172 173 173 static void jsm_tty_stop_rx(struct uart_port *port) 174 174 { 175 - struct jsm_channel *channel = (struct jsm_channel *)port; 175 + struct jsm_channel *channel = 176 + container_of(port, struct jsm_channel, uart_port); 176 177 177 178 channel->ch_bd->bd_ops->disable_receiver(channel); 178 179 } ··· 181 180 static void jsm_tty_break(struct uart_port *port, int break_state) 182 181 { 183 182 unsigned long lock_flags; 184 - struct jsm_channel *channel = (struct jsm_channel *)port; 183 + struct jsm_channel *channel = 184 + container_of(port, struct jsm_channel, uart_port); 185 185 186 186 spin_lock_irqsave(&port->lock, lock_flags); 187 187 if (break_state == -1) 188 188 channel->ch_bd->bd_ops->send_break(channel); 189 189 else 190 - channel->ch_bd->bd_ops->clear_break(channel, 0); 190 + channel->ch_bd->bd_ops->clear_break(channel); 191 191 192 192 spin_unlock_irqrestore(&port->lock, lock_flags); 193 193 } ··· 196 194 static int jsm_tty_open(struct uart_port *port) 197 195 { 198 196 struct jsm_board *brd; 199 - struct jsm_channel *channel = (struct jsm_channel *)port; 197 + struct jsm_channel *channel = 198 + container_of(port, struct jsm_channel, uart_port); 200 199 struct ktermios *termios; 201 200 202 201 /* Get board pointer from our array of majors we have allocated */ ··· 276 273 { 277 274 struct jsm_board *bd; 278 275 struct ktermios *ts; 279 - struct jsm_channel *channel = (struct jsm_channel *)port; 276 + struct jsm_channel *channel = 277 + container_of(port, struct jsm_channel, uart_port); 280 278 281 279 jsm_dbg(CLOSE, &channel->ch_bd->pci_dev, "start\n"); 282 280 ··· 311 307 struct ktermios *old_termios) 312 308 { 313 309 unsigned long lock_flags; 314 - struct jsm_channel *channel = (struct jsm_channel *)port; 310 + struct jsm_channel *channel = 311 + container_of(port, struct jsm_channel, uart_port); 315 312 316 313 spin_lock_irqsave(&port->lock, lock_flags); 317 314 channel->ch_c_cflag = termios->c_cflag; ··· 420 415 421 416 if (brd->bd_uart_offset == 0x200) 422 417 ch->ch_neo_uart = vaddr + (brd->bd_uart_offset * i); 418 + else 419 + ch->ch_cls_uart = vaddr + (brd->bd_uart_offset * i); 423 420 424 421 ch->ch_bd = brd; 425 422 ch->ch_portnum = i;
+3 -1
drivers/tty/serial/lantiq.c
··· 497 497 static void 498 498 lqasc_release_port(struct uart_port *port) 499 499 { 500 + struct platform_device *pdev = to_platform_device(port->dev); 501 + 500 502 if (port->flags & UPF_IOREMAP) { 501 - iounmap(port->membase); 503 + devm_iounmap(&pdev->dev, port->membase); 502 504 port->membase = NULL; 503 505 } 504 506 }
+28 -14
drivers/tty/serial/m32r_sio.c
··· 249 249 250 250 static void m32r_sio_stop_tx(struct uart_port *port) 251 251 { 252 - struct uart_sio_port *up = (struct uart_sio_port *)port; 252 + struct uart_sio_port *up = 253 + container_of(port, struct uart_sio_port, port); 253 254 254 255 if (up->ier & UART_IER_THRI) { 255 256 up->ier &= ~UART_IER_THRI; ··· 261 260 static void m32r_sio_start_tx(struct uart_port *port) 262 261 { 263 262 #ifdef CONFIG_SERIAL_M32R_PLDSIO 264 - struct uart_sio_port *up = (struct uart_sio_port *)port; 263 + struct uart_sio_port *up = 264 + container_of(port, struct uart_sio_port, port); 265 265 struct circ_buf *xmit = &up->port.state->xmit; 266 266 267 267 if (!(up->ier & UART_IER_THRI)) { ··· 276 274 } 277 275 while((serial_in(up, UART_LSR) & UART_EMPTY) != UART_EMPTY); 278 276 #else 279 - struct uart_sio_port *up = (struct uart_sio_port *)port; 277 + struct uart_sio_port *up = 278 + container_of(port, struct uart_sio_port, port); 280 279 281 280 if (!(up->ier & UART_IER_THRI)) { 282 281 up->ier |= UART_IER_THRI; ··· 288 285 289 286 static void m32r_sio_stop_rx(struct uart_port *port) 290 287 { 291 - struct uart_sio_port *up = (struct uart_sio_port *)port; 288 + struct uart_sio_port *up = 289 + container_of(port, struct uart_sio_port, port); 292 290 293 291 up->ier &= ~UART_IER_RLSI; 294 292 up->port.read_status_mask &= ~UART_LSR_DR; ··· 298 294 299 295 static void m32r_sio_enable_ms(struct uart_port *port) 300 296 { 301 - struct uart_sio_port *up = (struct uart_sio_port *)port; 297 + struct uart_sio_port *up = 298 + container_of(port, struct uart_sio_port, port); 302 299 303 300 up->ier |= UART_IER_MSI; 304 301 serial_out(up, UART_IER, up->ier); ··· 586 581 587 582 static unsigned int m32r_sio_tx_empty(struct uart_port *port) 588 583 { 589 - struct uart_sio_port *up = (struct uart_sio_port *)port; 584 + struct uart_sio_port *up = 585 + container_of(port, struct uart_sio_port, port); 590 586 unsigned long flags; 591 587 unsigned int ret; 592 588 ··· 615 609 616 610 static int m32r_sio_startup(struct uart_port *port) 617 611 { 618 - struct uart_sio_port *up = (struct uart_sio_port *)port; 612 + struct uart_sio_port *up = 613 + container_of(port, struct uart_sio_port, port); 619 614 int retval; 620 615 621 616 sio_init(); ··· 659 652 660 653 static void m32r_sio_shutdown(struct uart_port *port) 661 654 { 662 - struct uart_sio_port *up = (struct uart_sio_port *)port; 655 + struct uart_sio_port *up = 656 + container_of(port, struct uart_sio_port, port); 663 657 664 658 /* 665 659 * Disable interrupts from this port ··· 689 681 static void m32r_sio_set_termios(struct uart_port *port, 690 682 struct ktermios *termios, struct ktermios *old) 691 683 { 692 - struct uart_sio_port *up = (struct uart_sio_port *)port; 684 + struct uart_sio_port *up = 685 + container_of(port, struct uart_sio_port, port); 693 686 unsigned char cval = 0; 694 687 unsigned long flags; 695 688 unsigned int baud, quot; ··· 789 780 static void m32r_sio_pm(struct uart_port *port, unsigned int state, 790 781 unsigned int oldstate) 791 782 { 792 - struct uart_sio_port *up = (struct uart_sio_port *)port; 783 + struct uart_sio_port *up = 784 + container_of(port, struct uart_sio_port, port); 793 785 794 786 if (up->pm) 795 787 up->pm(port, state, oldstate); ··· 835 825 836 826 static void m32r_sio_release_port(struct uart_port *port) 837 827 { 838 - struct uart_sio_port *up = (struct uart_sio_port *)port; 828 + struct uart_sio_port *up = 829 + container_of(port, struct uart_sio_port, port); 839 830 unsigned long start, offset = 0, size = 0; 840 831 841 832 size <<= up->port.regshift; ··· 873 862 874 863 static int m32r_sio_request_port(struct uart_port *port) 875 864 { 876 - struct uart_sio_port *up = (struct uart_sio_port *)port; 865 + struct uart_sio_port *up = 866 + container_of(port, struct uart_sio_port, port); 877 867 struct resource *res = NULL; 878 868 int ret = 0; 879 869 ··· 901 889 902 890 static void m32r_sio_config_port(struct uart_port *port, int unused) 903 891 { 904 - struct uart_sio_port *up = (struct uart_sio_port *)port; 892 + struct uart_sio_port *up = 893 + container_of(port, struct uart_sio_port, port); 905 894 unsigned long flags; 906 895 907 896 spin_lock_irqsave(&up->port.lock, flags); ··· 1013 1000 1014 1001 static void m32r_sio_console_putchar(struct uart_port *port, int ch) 1015 1002 { 1016 - struct uart_sio_port *up = (struct uart_sio_port *)port; 1003 + struct uart_sio_port *up = 1004 + container_of(port, struct uart_sio_port, port); 1017 1005 1018 1006 wait_for_xmitr(up); 1019 1007 sio_out(up, SIOTXB, ch);
+32 -47
drivers/tty/serial/max310x.c
··· 346 346 unsigned int val = 0; 347 347 int ret; 348 348 349 - ret = regmap_read(s->regmap, MAX310X_REVID_REG, &val); 349 + ret = regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, 350 + MAX310X_EXTREG_ENBL); 350 351 if (ret) 351 352 return ret; 352 353 354 + regmap_read(s->regmap, MAX310X_REVID_EXTREG, &val); 355 + regmap_write(s->regmap, MAX310X_GLOBALCMD_REG, MAX310X_EXTREG_DSBL); 353 356 if (((val & MAX310x_REV_MASK) != MAX3109_REV_ID)) { 354 357 dev_err(dev, 355 358 "%s ID 0x%02x does not match\n", s->devtype->name, val); ··· 877 874 uart_update_timeout(port, termios->c_cflag, baud); 878 875 } 879 876 880 - static int max310x_ioctl(struct uart_port *port, unsigned int cmd, 881 - unsigned long arg) 877 + static int max310x_rs485_config(struct uart_port *port, 878 + struct serial_rs485 *rs485) 882 879 { 883 - #if defined(TIOCSRS485) && defined(TIOCGRS485) 884 - struct serial_rs485 rs485; 885 880 unsigned int val; 886 881 887 - switch (cmd) { 888 - case TIOCSRS485: 889 - if (copy_from_user(&rs485, (void __user *)arg, sizeof(rs485))) 890 - return -EFAULT; 891 - if (rs485.delay_rts_before_send > 0x0f || 892 - rs485.delay_rts_after_send > 0x0f) 893 - return -ERANGE; 894 - val = (rs485.delay_rts_before_send << 4) | 895 - rs485.delay_rts_after_send; 896 - max310x_port_write(port, MAX310X_HDPIXDELAY_REG, val); 897 - if (rs485.flags & SER_RS485_ENABLED) { 898 - max310x_port_update(port, MAX310X_MODE1_REG, 899 - MAX310X_MODE1_TRNSCVCTRL_BIT, 900 - MAX310X_MODE1_TRNSCVCTRL_BIT); 901 - max310x_port_update(port, MAX310X_MODE2_REG, 902 - MAX310X_MODE2_ECHOSUPR_BIT, 903 - MAX310X_MODE2_ECHOSUPR_BIT); 904 - } else { 905 - max310x_port_update(port, MAX310X_MODE1_REG, 906 - MAX310X_MODE1_TRNSCVCTRL_BIT, 0); 907 - max310x_port_update(port, MAX310X_MODE2_REG, 908 - MAX310X_MODE2_ECHOSUPR_BIT, 0); 909 - } 910 - return 0; 911 - case TIOCGRS485: 912 - memset(&rs485, 0, sizeof(rs485)); 913 - val = max310x_port_read(port, MAX310X_MODE1_REG); 914 - rs485.flags = (val & MAX310X_MODE1_TRNSCVCTRL_BIT) ? 915 - SER_RS485_ENABLED : 0; 916 - rs485.flags |= SER_RS485_RTS_ON_SEND; 917 - val = max310x_port_read(port, MAX310X_HDPIXDELAY_REG); 918 - rs485.delay_rts_before_send = val >> 4; 919 - rs485.delay_rts_after_send = val & 0x0f; 920 - if (copy_to_user((void __user *)arg, &rs485, sizeof(rs485))) 921 - return -EFAULT; 922 - return 0; 923 - default: 924 - break; 925 - } 926 - #endif 882 + if (rs485->delay_rts_before_send > 0x0f || 883 + rs485->delay_rts_after_send > 0x0f) 884 + return -ERANGE; 927 885 928 - return -ENOIOCTLCMD; 886 + val = (rs485->delay_rts_before_send << 4) | 887 + rs485->delay_rts_after_send; 888 + max310x_port_write(port, MAX310X_HDPIXDELAY_REG, val); 889 + if (rs485->flags & SER_RS485_ENABLED) { 890 + max310x_port_update(port, MAX310X_MODE1_REG, 891 + MAX310X_MODE1_TRNSCVCTRL_BIT, 892 + MAX310X_MODE1_TRNSCVCTRL_BIT); 893 + max310x_port_update(port, MAX310X_MODE2_REG, 894 + MAX310X_MODE2_ECHOSUPR_BIT, 895 + MAX310X_MODE2_ECHOSUPR_BIT); 896 + } else { 897 + max310x_port_update(port, MAX310X_MODE1_REG, 898 + MAX310X_MODE1_TRNSCVCTRL_BIT, 0); 899 + max310x_port_update(port, MAX310X_MODE2_REG, 900 + MAX310X_MODE2_ECHOSUPR_BIT, 0); 901 + } 902 + 903 + rs485->flags &= SER_RS485_RTS_ON_SEND | SER_RS485_ENABLED; 904 + memset(rs485->padding, 0, sizeof(rs485->padding)); 905 + port->rs485 = *rs485; 906 + 907 + return 0; 929 908 } 930 909 931 910 static int max310x_startup(struct uart_port *port) ··· 1002 1017 .release_port = max310x_null_void, 1003 1018 .config_port = max310x_config_port, 1004 1019 .verify_port = max310x_verify_port, 1005 - .ioctl = max310x_ioctl, 1006 1020 }; 1007 1021 1008 1022 static int __maybe_unused max310x_suspend(struct device *dev) ··· 1202 1218 s->p[i].port.iobase = i * 0x20; 1203 1219 s->p[i].port.membase = (void __iomem *)~0; 1204 1220 s->p[i].port.uartclk = uartclk; 1221 + s->p[i].port.rs485_config = max310x_rs485_config; 1205 1222 s->p[i].port.ops = &max310x_ops; 1206 1223 /* Disable all interrupts */ 1207 1224 max310x_port_write(&s->p[i].port, MAX310X_IRQEN_REG, 0);
+8 -34
drivers/tty/serial/mcf.c
··· 57 57 struct uart_port port; 58 58 unsigned int sigs; /* Local copy of line sigs */ 59 59 unsigned char imr; /* Local IMR mirror */ 60 - struct serial_rs485 rs485; /* RS485 settings */ 61 60 }; 62 61 63 62 /****************************************************************************/ ··· 103 104 { 104 105 struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 105 106 106 - if (pp->rs485.flags & SER_RS485_ENABLED) { 107 + if (port->rs485.flags & SER_RS485_ENABLED) { 107 108 /* Enable Transmitter */ 108 109 writeb(MCFUART_UCR_TXENABLE, port->membase + MCFUART_UCR); 109 110 /* Manually assert RTS */ ··· 257 258 mr2 |= MCFUART_MR2_TXCTS; 258 259 } 259 260 260 - if (pp->rs485.flags & SER_RS485_ENABLED) { 261 + spin_lock_irqsave(&port->lock, flags); 262 + if (port->rs485.flags & SER_RS485_ENABLED) { 261 263 dev_dbg(port->dev, "Setting UART to RS485\n"); 262 264 mr2 |= MCFUART_MR2_TXRTS; 263 265 } 264 266 265 - spin_lock_irqsave(&port->lock, flags); 266 267 uart_update_timeout(port, termios->c_cflag, baud); 267 268 writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR); 268 269 writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR); ··· 359 360 pp->imr &= ~MCFUART_UIR_TXREADY; 360 361 writeb(pp->imr, port->membase + MCFUART_UIMR); 361 362 /* Disable TX to negate RTS automatically */ 362 - if (pp->rs485.flags & SER_RS485_ENABLED) 363 + if (port->rs485.flags & SER_RS485_ENABLED) 363 364 writeb(MCFUART_UCR_TXDISABLE, 364 365 port->membase + MCFUART_UCR); 365 366 } ··· 439 440 /****************************************************************************/ 440 441 441 442 /* Enable or disable the RS485 support */ 442 - static void mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485) 443 + static int mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485) 443 444 { 444 445 struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 445 - unsigned long flags; 446 446 unsigned char mr1, mr2; 447 447 448 - spin_lock_irqsave(&port->lock, flags); 449 448 /* Get mode registers */ 450 449 mr1 = readb(port->membase + MCFUART_UMR); 451 450 mr2 = readb(port->membase + MCFUART_UMR); ··· 457 460 } 458 461 writeb(mr1, port->membase + MCFUART_UMR); 459 462 writeb(mr2, port->membase + MCFUART_UMR); 460 - pp->rs485 = *rs485; 461 - spin_unlock_irqrestore(&port->lock, flags); 462 - } 463 + port->rs485 = *rs485; 463 464 464 - static int mcf_ioctl(struct uart_port *port, unsigned int cmd, 465 - unsigned long arg) 466 - { 467 - switch (cmd) { 468 - case TIOCSRS485: { 469 - struct serial_rs485 rs485; 470 - if (copy_from_user(&rs485, (struct serial_rs485 *)arg, 471 - sizeof(struct serial_rs485))) 472 - return -EFAULT; 473 - mcf_config_rs485(port, &rs485); 474 - break; 475 - } 476 - case TIOCGRS485: { 477 - struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 478 - if (copy_to_user((struct serial_rs485 *)arg, &pp->rs485, 479 - sizeof(struct serial_rs485))) 480 - return -EFAULT; 481 - break; 482 - } 483 - default: 484 - return -ENOIOCTLCMD; 485 - } 486 465 return 0; 487 466 } 488 467 ··· 483 510 .release_port = mcf_release_port, 484 511 .config_port = mcf_config_port, 485 512 .verify_port = mcf_verify_port, 486 - .ioctl = mcf_ioctl, 487 513 }; 488 514 489 515 static struct mcf_uart mcf_ports[4]; ··· 510 538 port->irq = platp[i].irq; 511 539 port->uartclk = MCF_BUSCLK; 512 540 port->flags = UPF_BOOT_AUTOCONF; 541 + port->rs485_config = mcf_config_rs485; 513 542 port->ops = &mcf_uart_ops; 514 543 } 515 544 ··· 636 663 port->uartclk = MCF_BUSCLK; 637 664 port->ops = &mcf_uart_ops; 638 665 port->flags = UPF_BOOT_AUTOCONF; 666 + port->rs485_config = mcf_config_rs485; 639 667 640 668 uart_add_one_port(&mcf_driver, port); 641 669 }
+1
drivers/tty/serial/men_z135_uart.c
··· 809 809 810 810 static const struct mcb_device_id men_z135_ids[] = { 811 811 { .device = 0x87 }, 812 + { } 812 813 }; 813 814 MODULE_DEVICE_TABLE(mcb, men_z135_ids); 814 815
+1 -1
drivers/tty/serial/mfd.c
··· 1371 1371 hsu->iolen = 0x1000; 1372 1372 1373 1373 if (!(request_mem_region(hsu->paddr, hsu->iolen, "HSU global"))) 1374 - pr_warning("HSU: error in request mem region\n"); 1374 + pr_warn("HSU: error in request mem region\n"); 1375 1375 1376 1376 hsu->reg = ioremap_nocache((unsigned long)hsu->paddr, hsu->iolen); 1377 1377 if (!hsu->reg) {
+26 -13
drivers/tty/serial/mpsc.c
··· 1246 1246 */ 1247 1247 static uint mpsc_tx_empty(struct uart_port *port) 1248 1248 { 1249 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1249 + struct mpsc_port_info *pi = 1250 + container_of(port, struct mpsc_port_info, port); 1250 1251 ulong iflags; 1251 1252 uint rc; 1252 1253 ··· 1265 1264 1266 1265 static uint mpsc_get_mctrl(struct uart_port *port) 1267 1266 { 1268 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1267 + struct mpsc_port_info *pi = 1268 + container_of(port, struct mpsc_port_info, port); 1269 1269 u32 mflags, status; 1270 1270 1271 1271 status = (pi->mirror_regs) ? pi->MPSC_CHR_10_m ··· 1283 1281 1284 1282 static void mpsc_stop_tx(struct uart_port *port) 1285 1283 { 1286 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1284 + struct mpsc_port_info *pi = 1285 + container_of(port, struct mpsc_port_info, port); 1287 1286 1288 1287 pr_debug("mpsc_stop_tx[%d]\n", port->line); 1289 1288 ··· 1293 1290 1294 1291 static void mpsc_start_tx(struct uart_port *port) 1295 1292 { 1296 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1293 + struct mpsc_port_info *pi = 1294 + container_of(port, struct mpsc_port_info, port); 1297 1295 unsigned long iflags; 1298 1296 1299 1297 spin_lock_irqsave(&pi->tx_lock, iflags); ··· 1320 1316 1321 1317 static void mpsc_stop_rx(struct uart_port *port) 1322 1318 { 1323 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1319 + struct mpsc_port_info *pi = 1320 + container_of(port, struct mpsc_port_info, port); 1324 1321 1325 1322 pr_debug("mpsc_stop_rx[%d]: Stopping...\n", port->line); 1326 1323 ··· 1343 1338 1344 1339 static void mpsc_break_ctl(struct uart_port *port, int ctl) 1345 1340 { 1346 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1341 + struct mpsc_port_info *pi = 1342 + container_of(port, struct mpsc_port_info, port); 1347 1343 ulong flags; 1348 1344 u32 v; 1349 1345 ··· 1359 1353 1360 1354 static int mpsc_startup(struct uart_port *port) 1361 1355 { 1362 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1356 + struct mpsc_port_info *pi = 1357 + container_of(port, struct mpsc_port_info, port); 1363 1358 u32 flag = 0; 1364 1359 int rc; 1365 1360 ··· 1390 1383 1391 1384 static void mpsc_shutdown(struct uart_port *port) 1392 1385 { 1393 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1386 + struct mpsc_port_info *pi = 1387 + container_of(port, struct mpsc_port_info, port); 1394 1388 1395 1389 pr_debug("mpsc_shutdown[%d]: Shutting down MPSC\n", port->line); 1396 1390 ··· 1402 1394 static void mpsc_set_termios(struct uart_port *port, struct ktermios *termios, 1403 1395 struct ktermios *old) 1404 1396 { 1405 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1397 + struct mpsc_port_info *pi = 1398 + container_of(port, struct mpsc_port_info, port); 1406 1399 u32 baud; 1407 1400 ulong flags; 1408 1401 u32 chr_bits, stop_bits, par; ··· 1507 1498 1508 1499 static void mpsc_release_port(struct uart_port *port) 1509 1500 { 1510 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1501 + struct mpsc_port_info *pi = 1502 + container_of(port, struct mpsc_port_info, port); 1511 1503 1512 1504 if (pi->ready) { 1513 1505 mpsc_uninit_rings(pi); ··· 1523 1513 1524 1514 static int mpsc_verify_port(struct uart_port *port, struct serial_struct *ser) 1525 1515 { 1526 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1516 + struct mpsc_port_info *pi = 1517 + container_of(port, struct mpsc_port_info, port); 1527 1518 int rc = 0; 1528 1519 1529 1520 pr_debug("mpsc_verify_port[%d]: Verifying port data\n", pi->port.line); ··· 1559 1548 1560 1549 static int mpsc_get_poll_char(struct uart_port *port) 1561 1550 { 1562 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1551 + struct mpsc_port_info *pi = 1552 + container_of(port, struct mpsc_port_info, port); 1563 1553 struct mpsc_rx_desc *rxre; 1564 1554 u32 cmdstat, bytes_in, i; 1565 1555 u8 *bp; ··· 1660 1648 static void mpsc_put_poll_char(struct uart_port *port, 1661 1649 unsigned char c) 1662 1650 { 1663 - struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1651 + struct mpsc_port_info *pi = 1652 + container_of(port, struct mpsc_port_info, port); 1664 1653 u32 data; 1665 1654 1666 1655 data = readl(pi->mpsc_base + MPSC_MPCR);
+12 -15
drivers/tty/serial/mrst_max3110.c
··· 27 27 * interrupt for a low speed UART device 28 28 */ 29 29 30 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 31 + 30 32 #ifdef CONFIG_MAGIC_SYSRQ 31 33 #define SUPPORT_SYSRQ 32 34 #endif ··· 48 46 #include <linux/pm.h> 49 47 50 48 #include "mrst_max3110.h" 51 - 52 - #define PR_FMT "mrst_max3110: " 53 49 54 50 #define UART_TX_NEEDED 1 55 51 #define CON_TX_NEEDED 2 ··· 127 127 *obuf = out; 128 128 ret = max3110_write_then_read(max, obuf, ibuf, 2, 1); 129 129 if (ret) { 130 - pr_warning(PR_FMT "%s(): get err msg %d when sending 0x%x\n", 131 - __func__, ret, out); 130 + pr_warn("%s: get err msg %d when sending 0x%x\n", 131 + __func__, ret, out); 132 132 goto exit; 133 133 } 134 134 ··· 153 153 154 154 blen = M3110_RX_FIFO_DEPTH * sizeof(u16); 155 155 buf = kzalloc(blen * 2, GFP_KERNEL | GFP_DMA); 156 - if (!buf) { 157 - pr_warning(PR_FMT "%s(): fail to alloc dma buffer\n", __func__); 156 + if (!buf) 158 157 return 0; 159 - } 160 158 161 159 /* tx/rx always have the same length */ 162 160 obuf = buf; ··· 210 212 int parity = 'n'; 211 213 int flow = 'n'; 212 214 213 - pr_info(PR_FMT "setting up console\n"); 215 + pr_info("setting up console\n"); 214 216 215 217 if (co->index == -1) 216 218 co->index = 0; 217 219 218 220 if (!max) { 219 - pr_err(PR_FMT "pmax is NULL, return"); 221 + pr_err("pmax is NULL, return\n"); 220 222 return -ENODEV; 221 223 } 222 224 ··· 294 296 295 297 ret = max3110_write_then_read(max, obuf, ibuf, blen, 0); 296 298 if (ret) 297 - pr_warning(PR_FMT "%s(): get err msg %d\n", 298 - __func__, ret); 299 + pr_warn("%s: get err msg %d\n", __func__, ret); 299 300 300 301 receive_chars(max, ibuf, len); 301 302 ··· 408 411 int ret = 0; 409 412 struct circ_buf *xmit = &max->con_xmit; 410 413 411 - pr_info(PR_FMT "start main thread\n"); 414 + pr_info("start main thread\n"); 412 415 413 416 do { 414 417 wait_event_interruptible(*wq, ··· 452 455 { 453 456 struct uart_max3110 *max = _max; 454 457 455 - pr_info(PR_FMT "start read thread\n"); 458 + pr_info("start read thread\n"); 456 459 do { 457 460 /* 458 461 * If can't acquire the mutex, it means the main thread ··· 478 481 int ret = 0; 479 482 480 483 if (port->line != 0) { 481 - pr_err(PR_FMT "uart port startup failed\n"); 484 + pr_err("uart port startup failed\n"); 482 485 return -1; 483 486 } 484 487 ··· 501 504 if (IS_ERR(max->read_thread)) { 502 505 ret = PTR_ERR(max->read_thread); 503 506 max->read_thread = NULL; 504 - pr_err(PR_FMT "Can't create read thread!\n"); 507 + pr_err("Can't create read thread!\n"); 505 508 return ret; 506 509 } 507 510 }
+59 -54
drivers/tty/serial/msm_serial.c
··· 54 54 unsigned int imr; 55 55 int is_uartdm; 56 56 unsigned int old_snap_state; 57 + bool break_detected; 57 58 }; 58 59 59 60 static inline void wait_for_xmitr(struct uart_port *port) ··· 127 126 128 127 while (count > 0) { 129 128 unsigned char buf[4]; 129 + int sysrq, r_count, i; 130 130 131 131 sr = msm_read(port, UART_SR); 132 132 if ((sr & UART_SR_RX_READY) == 0) { 133 133 msm_port->old_snap_state -= count; 134 134 break; 135 135 } 136 - ioread32_rep(port->membase + UARTDM_RF, buf, 1); 137 - if (sr & UART_SR_RX_BREAK) { 138 - port->icount.brk++; 139 - if (uart_handle_break(port)) 140 - continue; 141 - } else if (sr & UART_SR_PAR_FRAME_ERR) 142 - port->icount.frame++; 143 136 144 - /* TODO: handle sysrq */ 145 - tty_insert_flip_string(tport, buf, min(count, 4)); 146 - count -= 4; 137 + ioread32_rep(port->membase + UARTDM_RF, buf, 1); 138 + r_count = min_t(int, count, sizeof(buf)); 139 + 140 + for (i = 0; i < r_count; i++) { 141 + char flag = TTY_NORMAL; 142 + 143 + if (msm_port->break_detected && buf[i] == 0) { 144 + port->icount.brk++; 145 + flag = TTY_BREAK; 146 + msm_port->break_detected = false; 147 + if (uart_handle_break(port)) 148 + continue; 149 + } 150 + 151 + if (!(port->read_status_mask & UART_SR_RX_BREAK)) 152 + flag = TTY_NORMAL; 153 + 154 + spin_unlock(&port->lock); 155 + sysrq = uart_handle_sysrq_char(port, buf[i]); 156 + spin_lock(&port->lock); 157 + if (!sysrq) 158 + tty_insert_flip_char(tport, buf[i], flag); 159 + } 160 + count -= r_count; 147 161 } 148 162 149 163 spin_unlock(&port->lock); ··· 190 174 while ((sr = msm_read(port, UART_SR)) & UART_SR_RX_READY) { 191 175 unsigned int c; 192 176 char flag = TTY_NORMAL; 177 + int sysrq; 193 178 194 179 c = msm_read(port, UART_RF); 195 180 ··· 212 195 else if (sr & UART_SR_PAR_FRAME_ERR) 213 196 flag = TTY_FRAME; 214 197 215 - if (!uart_handle_sysrq_char(port, c)) 198 + spin_unlock(&port->lock); 199 + sysrq = uart_handle_sysrq_char(port, c); 200 + spin_lock(&port->lock); 201 + if (!sysrq) 216 202 tty_insert_flip_char(tport, c, flag); 217 203 } 218 204 ··· 306 286 spin_lock(&port->lock); 307 287 misr = msm_read(port, UART_MISR); 308 288 msm_write(port, 0, UART_IMR); /* disable interrupt */ 289 + 290 + if (misr & UART_IMR_RXBREAK_START) { 291 + msm_port->break_detected = true; 292 + msm_write(port, UART_CR_CMD_RESET_RXBREAK_START, UART_CR); 293 + } 309 294 310 295 if (misr & (UART_IMR_RXLEV | UART_IMR_RXSTALE)) { 311 296 if (msm_port->is_uartdm) ··· 427 402 428 403 entry = msm_find_best_baud(port, baud); 429 404 430 - if (msm_port->is_uartdm) 431 - msm_write(port, UART_CR_CMD_RESET_RX, UART_CR); 432 - 433 405 msm_write(port, entry->code, UART_CSR); 434 406 435 407 /* RX stale watermark */ ··· 442 420 443 421 /* set TX watermark */ 444 422 msm_write(port, 10, UART_TFWR); 423 + 424 + msm_write(port, UART_CR_CMD_PROTECTION_EN, UART_CR); 425 + msm_reset(port); 426 + 427 + /* Enable RX and TX */ 428 + msm_write(port, UART_CR_TX_ENABLE | UART_CR_RX_ENABLE, UART_CR); 429 + 430 + /* turn on RX and CTS interrupts */ 431 + msm_port->imr = UART_IMR_RXLEV | UART_IMR_RXSTALE | 432 + UART_IMR_CURRENT_CTS | UART_IMR_RXBREAK_START; 433 + 434 + msm_write(port, msm_port->imr, UART_IMR); 445 435 446 436 if (msm_port->is_uartdm) { 447 437 msm_write(port, UART_CR_CMD_RESET_STALE_INT, UART_CR); ··· 501 467 data |= UART_MR1_AUTO_RFR_LEVEL1 & (rfr_level << 2); 502 468 data |= UART_MR1_AUTO_RFR_LEVEL0 & rfr_level; 503 469 msm_write(port, data, UART_MR1); 504 - 505 - /* make sure that RXSTALE count is non-zero */ 506 - data = msm_read(port, UART_IPR); 507 - if (unlikely(!data)) { 508 - data |= UART_IPR_RXSTALE_LAST; 509 - data |= UART_IPR_STALE_LSB; 510 - msm_write(port, data, UART_IPR); 511 - } 512 - 513 - data = 0; 514 - if (!port->cons || (port->cons && !(port->cons->flags & CON_ENABLED))) { 515 - msm_write(port, UART_CR_CMD_PROTECTION_EN, UART_CR); 516 - msm_reset(port); 517 - data = UART_CR_TX_ENABLE; 518 - } 519 - 520 - data |= UART_CR_RX_ENABLE; 521 - msm_write(port, data, UART_CR); /* enable TX & RX */ 522 - 523 - /* Make sure IPR is not 0 to start with*/ 524 - if (msm_port->is_uartdm) 525 - msm_write(port, UART_IPR_STALE_LSB, UART_IPR); 526 - 527 - /* turn on RX and CTS interrupts */ 528 - msm_port->imr = UART_IMR_RXLEV | UART_IMR_RXSTALE | 529 - UART_IMR_CURRENT_CTS; 530 - 531 - if (msm_port->is_uartdm) { 532 - msm_write(port, 0xFFFFFF, UARTDM_DMRX); 533 - msm_write(port, UART_CR_CMD_RESET_STALE_INT, UART_CR); 534 - msm_write(port, UART_CR_CMD_STALE_EVENT_ENABLE, UART_CR); 535 - } 536 - 537 - msm_write(port, msm_port->imr, UART_IMR); 538 470 return 0; 539 471 } 540 472 ··· 1044 1044 struct resource *resource; 1045 1045 struct uart_port *port; 1046 1046 const struct of_device_id *id; 1047 - int irq; 1047 + int irq, line; 1048 1048 1049 - if (pdev->id == -1) 1050 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1; 1049 + if (pdev->dev.of_node) 1050 + line = of_alias_get_id(pdev->dev.of_node, "serial"); 1051 + else 1052 + line = pdev->id; 1051 1053 1052 - if (unlikely(pdev->id < 0 || pdev->id >= UART_NR)) 1054 + if (line < 0) 1055 + line = atomic_inc_return(&msm_uart_next_id) - 1; 1056 + 1057 + if (unlikely(line < 0 || line >= UART_NR)) 1053 1058 return -ENXIO; 1054 1059 1055 - dev_info(&pdev->dev, "msm_serial: detected port #%d\n", pdev->id); 1060 + dev_info(&pdev->dev, "msm_serial: detected port #%d\n", line); 1056 1061 1057 - port = get_port_from_line(pdev->id); 1062 + port = get_port_from_line(line); 1058 1063 port->dev = &pdev->dev; 1059 1064 msm_port = UART_TO_MSM(port); 1060 1065
+2
drivers/tty/serial/msm_serial.h
··· 65 65 #define UART_CR_TX_ENABLE (1 << 2) 66 66 #define UART_CR_RX_DISABLE (1 << 1) 67 67 #define UART_CR_RX_ENABLE (1 << 0) 68 + #define UART_CR_CMD_RESET_RXBREAK_START ((1 << 11) | (2 << 4)) 68 69 69 70 #define UART_IMR 0x0014 70 71 #define UART_IMR_TXLEV (1 << 0) ··· 73 72 #define UART_IMR_RXLEV (1 << 4) 74 73 #define UART_IMR_DELTA_CTS (1 << 5) 75 74 #define UART_IMR_CURRENT_CTS (1 << 6) 75 + #define UART_IMR_RXBREAK_START (1 << 10) 76 76 77 77 #define UART_IPR_RXSTALE_LAST 0x20 78 78 #define UART_IPR_STALE_LSB 0x1F
+233 -17
drivers/tty/serial/mxs-auart.c
··· 14 14 * http://www.gnu.org/copyleft/gpl.html 15 15 */ 16 16 17 + #if defined(CONFIG_SERIAL_MXS_AUART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 18 + #define SUPPORT_SYSRQ 19 + #endif 20 + 17 21 #include <linux/kernel.h> 18 22 #include <linux/errno.h> 19 23 #include <linux/init.h> ··· 41 37 #include <linux/dmaengine.h> 42 38 43 39 #include <asm/cacheflush.h> 40 + 41 + #include <linux/gpio.h> 42 + #include <linux/gpio/consumer.h> 43 + #include <linux/err.h> 44 + #include <linux/irq.h> 45 + #include "serial_mctrl_gpio.h" 44 46 45 47 #define MXS_AUART_PORTS 5 46 48 #define MXS_AUART_FIFO_SIZE 16 ··· 149 139 #define MXS_AUART_DMA_RX_READY 3 /* bit 3 */ 150 140 #define MXS_AUART_RTSCTS 4 /* bit 4 */ 151 141 unsigned long flags; 152 - unsigned int ctrl; 142 + unsigned int mctrl_prev; 153 143 enum mxs_auart_type devtype; 154 144 155 145 unsigned int irq; ··· 165 155 struct scatterlist rx_sgl; 166 156 struct dma_chan *rx_dma_chan; 167 157 void *rx_dma_buf; 158 + 159 + struct mctrl_gpios *gpios; 160 + int gpio_irq[UART_GPIO_MAX]; 161 + bool ms_irq_enabled; 168 162 }; 169 163 170 164 static struct platform_device_id mxs_auart_devtype[] = { ··· 428 414 ctrl |= AUART_CTRL2_RTS; 429 415 } 430 416 431 - s->ctrl = mctrl; 432 417 writel(ctrl, u->membase + AUART_CTRL2); 418 + 419 + mctrl_gpio_set(s->gpios, mctrl); 420 + } 421 + 422 + #define MCTRL_ANY_DELTA (TIOCM_RI | TIOCM_DSR | TIOCM_CD | TIOCM_CTS) 423 + static u32 mxs_auart_modem_status(struct mxs_auart_port *s, u32 mctrl) 424 + { 425 + u32 mctrl_diff; 426 + 427 + mctrl_diff = mctrl ^ s->mctrl_prev; 428 + s->mctrl_prev = mctrl; 429 + if (mctrl_diff & MCTRL_ANY_DELTA && s->ms_irq_enabled && 430 + s->port.state != NULL) { 431 + if (mctrl_diff & TIOCM_RI) 432 + s->port.icount.rng++; 433 + if (mctrl_diff & TIOCM_DSR) 434 + s->port.icount.dsr++; 435 + if (mctrl_diff & TIOCM_CD) 436 + uart_handle_dcd_change(&s->port, mctrl & TIOCM_CD); 437 + if (mctrl_diff & TIOCM_CTS) 438 + uart_handle_cts_change(&s->port, mctrl & TIOCM_CTS); 439 + 440 + wake_up_interruptible(&s->port.state->port.delta_msr_wait); 441 + } 442 + return mctrl; 433 443 } 434 444 435 445 static u32 mxs_auart_get_mctrl(struct uart_port *u) 436 446 { 437 447 struct mxs_auart_port *s = to_auart_port(u); 438 448 u32 stat = readl(u->membase + AUART_STAT); 439 - int ctrl2 = readl(u->membase + AUART_CTRL2); 440 - u32 mctrl = s->ctrl; 449 + u32 mctrl = 0; 441 450 442 - mctrl &= ~TIOCM_CTS; 443 451 if (stat & AUART_STAT_CTS) 444 452 mctrl |= TIOCM_CTS; 445 453 446 - if (ctrl2 & AUART_CTRL2_RTS) 447 - mctrl |= TIOCM_RTS; 454 + return mctrl_gpio_get(s->gpios, &mctrl); 455 + } 448 456 449 - return mctrl; 457 + /* 458 + * Enable modem status interrupts 459 + */ 460 + static void mxs_auart_enable_ms(struct uart_port *port) 461 + { 462 + struct mxs_auart_port *s = to_auart_port(port); 463 + 464 + /* 465 + * Interrupt should not be enabled twice 466 + */ 467 + if (s->ms_irq_enabled) 468 + return; 469 + 470 + s->ms_irq_enabled = true; 471 + 472 + if (s->gpio_irq[UART_GPIO_CTS] >= 0) 473 + enable_irq(s->gpio_irq[UART_GPIO_CTS]); 474 + /* TODO: enable AUART_INTR_CTSMIEN otherwise */ 475 + 476 + if (s->gpio_irq[UART_GPIO_DSR] >= 0) 477 + enable_irq(s->gpio_irq[UART_GPIO_DSR]); 478 + 479 + if (s->gpio_irq[UART_GPIO_RI] >= 0) 480 + enable_irq(s->gpio_irq[UART_GPIO_RI]); 481 + 482 + if (s->gpio_irq[UART_GPIO_DCD] >= 0) 483 + enable_irq(s->gpio_irq[UART_GPIO_DCD]); 484 + } 485 + 486 + /* 487 + * Disable modem status interrupts 488 + */ 489 + static void mxs_auart_disable_ms(struct uart_port *port) 490 + { 491 + struct mxs_auart_port *s = to_auart_port(port); 492 + 493 + /* 494 + * Interrupt should not be disabled twice 495 + */ 496 + if (!s->ms_irq_enabled) 497 + return; 498 + 499 + s->ms_irq_enabled = false; 500 + 501 + if (s->gpio_irq[UART_GPIO_CTS] >= 0) 502 + disable_irq(s->gpio_irq[UART_GPIO_CTS]); 503 + /* TODO: disable AUART_INTR_CTSMIEN otherwise */ 504 + 505 + if (s->gpio_irq[UART_GPIO_DSR] >= 0) 506 + disable_irq(s->gpio_irq[UART_GPIO_DSR]); 507 + 508 + if (s->gpio_irq[UART_GPIO_RI] >= 0) 509 + disable_irq(s->gpio_irq[UART_GPIO_RI]); 510 + 511 + if (s->gpio_irq[UART_GPIO_DCD] >= 0) 512 + disable_irq(s->gpio_irq[UART_GPIO_DCD]); 450 513 } 451 514 452 515 static int mxs_auart_dma_prep_rx(struct mxs_auart_port *s); ··· 651 560 652 561 } 653 562 563 + #define RTS_AT_AUART() IS_ERR_OR_NULL(mctrl_gpio_to_gpiod(s->gpios, \ 564 + UART_GPIO_RTS)) 565 + #define CTS_AT_AUART() IS_ERR_OR_NULL(mctrl_gpio_to_gpiod(s->gpios, \ 566 + UART_GPIO_CTS)) 654 567 static void mxs_auart_settermios(struct uart_port *u, 655 568 struct ktermios *termios, 656 569 struct ktermios *old) ··· 731 636 ctrl |= AUART_LINECTRL_STP2; 732 637 733 638 /* figure out the hardware flow control settings */ 639 + ctrl2 &= ~(AUART_CTRL2_CTSEN | AUART_CTRL2_RTSEN); 734 640 if (cflag & CRTSCTS) { 735 641 /* 736 642 * The DMA has a bug(see errata:2836) in mx23. ··· 746 650 ctrl2 |= AUART_CTRL2_TXDMAE | AUART_CTRL2_RXDMAE 747 651 | AUART_CTRL2_DMAONERR; 748 652 } 749 - ctrl2 |= AUART_CTRL2_CTSEN | AUART_CTRL2_RTSEN; 750 - } else { 751 - ctrl2 &= ~(AUART_CTRL2_CTSEN | AUART_CTRL2_RTSEN); 653 + /* Even if RTS is GPIO line RTSEN can be enabled because 654 + * the pinctrl configuration decides about RTS pin function */ 655 + ctrl2 |= AUART_CTRL2_RTSEN; 656 + if (CTS_AT_AUART()) 657 + ctrl2 |= AUART_CTRL2_CTSEN; 752 658 } 753 659 754 660 /* set baud rate */ ··· 776 678 dev_err(s->dev, "We can not start up the DMA.\n"); 777 679 } 778 680 } 681 + 682 + /* CTS flow-control and modem-status interrupts */ 683 + if (UART_ENABLE_MS(u, termios->c_cflag)) 684 + mxs_auart_enable_ms(u); 685 + else 686 + mxs_auart_disable_ms(u); 687 + } 688 + 689 + static void mxs_auart_set_ldisc(struct uart_port *port, 690 + struct ktermios *termios) 691 + { 692 + if (termios->c_line == N_PPS) { 693 + port->flags |= UPF_HARDPPS_CD; 694 + mxs_auart_enable_ms(port); 695 + } else { 696 + port->flags &= ~UPF_HARDPPS_CD; 697 + } 779 698 } 780 699 781 700 static irqreturn_t mxs_auart_irq_handle(int irq, void *context) 782 701 { 783 702 u32 istat; 784 703 struct mxs_auart_port *s = context; 704 + u32 mctrl_temp = s->mctrl_prev; 785 705 u32 stat = readl(s->port.membase + AUART_STAT); 786 706 787 707 istat = readl(s->port.membase + AUART_INTR); ··· 811 695 | AUART_INTR_CTSMIS), 812 696 s->port.membase + AUART_INTR_CLR); 813 697 698 + /* 699 + * Dealing with GPIO interrupt 700 + */ 701 + if (irq == s->gpio_irq[UART_GPIO_CTS] || 702 + irq == s->gpio_irq[UART_GPIO_DCD] || 703 + irq == s->gpio_irq[UART_GPIO_DSR] || 704 + irq == s->gpio_irq[UART_GPIO_RI]) 705 + mxs_auart_modem_status(s, 706 + mctrl_gpio_get(s->gpios, &mctrl_temp)); 707 + 814 708 if (istat & AUART_INTR_CTSMIS) { 815 - uart_handle_cts_change(&s->port, stat & AUART_STAT_CTS); 709 + if (CTS_AT_AUART() && s->ms_irq_enabled) 710 + uart_handle_cts_change(&s->port, 711 + stat & AUART_STAT_CTS); 816 712 writel(AUART_INTR_CTSMIS, 817 713 s->port.membase + AUART_INTR_CLR); 818 714 istat &= ~AUART_INTR_CTSMIS; ··· 885 757 */ 886 758 writel(AUART_LINECTRL_FEN, u->membase + AUART_LINECTRL_SET); 887 759 760 + /* get initial status of modem lines */ 761 + mctrl_gpio_get(s->gpios, &s->mctrl_prev); 762 + 763 + s->ms_irq_enabled = false; 888 764 return 0; 889 765 } 890 766 891 767 static void mxs_auart_shutdown(struct uart_port *u) 892 768 { 893 769 struct mxs_auart_port *s = to_auart_port(u); 770 + 771 + mxs_auart_disable_ms(u); 894 772 895 773 if (auart_dma_enabled(s)) 896 774 mxs_auart_dma_exit(s); ··· 913 779 914 780 static unsigned int mxs_auart_tx_empty(struct uart_port *u) 915 781 { 916 - if (readl(u->membase + AUART_STAT) & AUART_STAT_TXFE) 782 + if ((readl(u->membase + AUART_STAT) & 783 + (AUART_STAT_TXFE | AUART_STAT_BUSY)) == AUART_STAT_TXFE) 917 784 return TIOCSER_TEMT; 918 - else 919 - return 0; 785 + 786 + return 0; 920 787 } 921 788 922 789 static void mxs_auart_start_tx(struct uart_port *u) ··· 955 820 .start_tx = mxs_auart_start_tx, 956 821 .stop_tx = mxs_auart_stop_tx, 957 822 .stop_rx = mxs_auart_stop_rx, 823 + .enable_ms = mxs_auart_enable_ms, 958 824 .break_ctl = mxs_auart_break_ctl, 959 825 .set_mctrl = mxs_auart_set_mctrl, 960 826 .get_mctrl = mxs_auart_get_mctrl, 961 827 .startup = mxs_auart_startup, 962 828 .shutdown = mxs_auart_shutdown, 963 829 .set_termios = mxs_auart_settermios, 830 + .set_ldisc = mxs_auart_set_ldisc, 964 831 .type = mxs_auart_type, 965 832 .release_port = mxs_auart_release_port, 966 833 .request_port = mxs_auart_request_port, ··· 1157 1020 return 0; 1158 1021 } 1159 1022 1023 + static bool mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev) 1024 + { 1025 + enum mctrl_gpio_idx i; 1026 + struct gpio_desc *gpiod; 1027 + 1028 + s->gpios = mctrl_gpio_init(dev, 0); 1029 + if (IS_ERR_OR_NULL(s->gpios)) 1030 + return false; 1031 + 1032 + /* Block (enabled before) DMA option if RTS or CTS is GPIO line */ 1033 + if (!RTS_AT_AUART() || !CTS_AT_AUART()) { 1034 + if (test_bit(MXS_AUART_RTSCTS, &s->flags)) 1035 + dev_warn(dev, 1036 + "DMA and flow control via gpio may cause some problems. DMA disabled!\n"); 1037 + clear_bit(MXS_AUART_RTSCTS, &s->flags); 1038 + } 1039 + 1040 + for (i = 0; i < UART_GPIO_MAX; i++) { 1041 + gpiod = mctrl_gpio_to_gpiod(s->gpios, i); 1042 + if (gpiod && (gpiod_get_direction(gpiod) == GPIOF_DIR_IN)) 1043 + s->gpio_irq[i] = gpiod_to_irq(gpiod); 1044 + else 1045 + s->gpio_irq[i] = -EINVAL; 1046 + } 1047 + 1048 + return true; 1049 + } 1050 + 1051 + static void mxs_auart_free_gpio_irq(struct mxs_auart_port *s) 1052 + { 1053 + enum mctrl_gpio_idx i; 1054 + 1055 + for (i = 0; i < UART_GPIO_MAX; i++) 1056 + if (s->gpio_irq[i] >= 0) 1057 + free_irq(s->gpio_irq[i], s); 1058 + } 1059 + 1060 + static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s) 1061 + { 1062 + int *irq = s->gpio_irq; 1063 + enum mctrl_gpio_idx i; 1064 + int err = 0; 1065 + 1066 + for (i = 0; (i < UART_GPIO_MAX) && !err; i++) { 1067 + if (irq[i] < 0) 1068 + continue; 1069 + 1070 + irq_set_status_flags(irq[i], IRQ_NOAUTOEN); 1071 + err = request_irq(irq[i], mxs_auart_irq_handle, 1072 + IRQ_TYPE_EDGE_BOTH, dev_name(s->dev), s); 1073 + if (err) 1074 + dev_err(s->dev, "%s - Can't get %d irq\n", 1075 + __func__, irq[i]); 1076 + } 1077 + 1078 + /* 1079 + * If something went wrong, rollback. 1080 + */ 1081 + while (err && (--i >= 0)) 1082 + if (irq[i] >= 0) 1083 + free_irq(irq[i], s); 1084 + 1085 + return err; 1086 + } 1087 + 1160 1088 static int mxs_auart_probe(struct platform_device *pdev) 1161 1089 { 1162 1090 const struct of_device_id *of_id = ··· 1269 1067 s->port.type = PORT_IMX; 1270 1068 s->port.dev = s->dev = &pdev->dev; 1271 1069 1272 - s->ctrl = 0; 1070 + s->mctrl_prev = 0; 1273 1071 1274 1072 s->irq = platform_get_irq(pdev, 0); 1275 1073 s->port.irq = s->irq; ··· 1279 1077 1280 1078 platform_set_drvdata(pdev, s); 1281 1079 1080 + if (!mxs_auart_init_gpios(s, &pdev->dev)) 1081 + dev_err(&pdev->dev, 1082 + "Failed to initialize GPIOs. The serial port may not work as expected\n"); 1083 + 1084 + /* 1085 + * Get the GPIO lines IRQ 1086 + */ 1087 + ret = mxs_auart_request_gpio_irq(s); 1088 + if (ret) 1089 + goto out_free_irq; 1090 + 1282 1091 auart_port[s->port.line] = s; 1283 1092 1284 1093 mxs_auart_reset(&s->port); 1285 1094 1286 1095 ret = uart_add_one_port(&auart_driver, &s->port); 1287 1096 if (ret) 1288 - goto out_free_irq; 1097 + goto out_free_gpio_irq; 1289 1098 1290 1099 version = readl(s->port.membase + AUART_VERSION); 1291 1100 dev_info(&pdev->dev, "Found APPUART %d.%d.%d\n", ··· 1305 1092 1306 1093 return 0; 1307 1094 1095 + out_free_gpio_irq: 1096 + mxs_auart_free_gpio_irq(s); 1308 1097 out_free_irq: 1309 1098 auart_port[pdev->id] = NULL; 1310 1099 free_irq(s->irq, s); ··· 1326 1111 1327 1112 auart_port[pdev->id] = NULL; 1328 1113 1114 + mxs_auart_free_gpio_irq(s); 1329 1115 clk_put(s->clk); 1330 1116 free_irq(s->irq, s); 1331 1117 kfree(s);
+74 -1
drivers/tty/serial/of_serial.c
··· 9 9 * 2 of the License, or (at your option) any later version. 10 10 * 11 11 */ 12 + #include <linux/console.h> 12 13 #include <linux/module.h> 13 14 #include <linux/slab.h> 14 15 #include <linux/delay.h> ··· 130 129 131 130 port->dev = &ofdev->dev; 132 131 133 - if (type == PORT_TEGRA) 132 + switch (type) { 133 + case PORT_TEGRA: 134 134 port->handle_break = tegra_serial_handle_break; 135 + break; 136 + 137 + case PORT_RT2880: 138 + port->iotype = UPIO_AU; 139 + break; 140 + } 135 141 136 142 return 0; 137 143 out: ··· 248 240 return 0; 249 241 } 250 242 243 + #ifdef CONFIG_PM_SLEEP 244 + #ifdef CONFIG_SERIAL_8250 245 + static void of_serial_suspend_8250(struct of_serial_info *info) 246 + { 247 + struct uart_8250_port *port8250 = serial8250_get_port(info->line); 248 + struct uart_port *port = &port8250->port; 249 + 250 + serial8250_suspend_port(info->line); 251 + if (info->clk && (!uart_console(port) || console_suspend_enabled)) 252 + clk_disable_unprepare(info->clk); 253 + } 254 + 255 + static void of_serial_resume_8250(struct of_serial_info *info) 256 + { 257 + struct uart_8250_port *port8250 = serial8250_get_port(info->line); 258 + struct uart_port *port = &port8250->port; 259 + 260 + if (info->clk && (!uart_console(port) || console_suspend_enabled)) 261 + clk_prepare_enable(info->clk); 262 + 263 + serial8250_resume_port(info->line); 264 + } 265 + #else 266 + static inline void of_serial_suspend_8250(struct of_serial_info *info) 267 + { 268 + } 269 + 270 + static inline void of_serial_resume_8250(struct of_serial_info *info) 271 + { 272 + } 273 + #endif 274 + 275 + static int of_serial_suspend(struct device *dev) 276 + { 277 + struct of_serial_info *info = dev_get_drvdata(dev); 278 + 279 + switch (info->type) { 280 + case PORT_8250 ... PORT_MAX_8250: 281 + of_serial_suspend_8250(info); 282 + break; 283 + default: 284 + break; 285 + } 286 + 287 + return 0; 288 + } 289 + 290 + static int of_serial_resume(struct device *dev) 291 + { 292 + struct of_serial_info *info = dev_get_drvdata(dev); 293 + 294 + switch (info->type) { 295 + case PORT_8250 ... PORT_MAX_8250: 296 + of_serial_resume_8250(info); 297 + break; 298 + default: 299 + break; 300 + } 301 + 302 + return 0; 303 + } 304 + #endif 305 + static SIMPLE_DEV_PM_OPS(of_serial_pm_ops, of_serial_suspend, of_serial_resume); 306 + 251 307 /* 252 308 * A few common types, add more as needed. 253 309 */ ··· 324 252 { .compatible = "ns16850", .data = (void *)PORT_16850, }, 325 253 { .compatible = "nvidia,tegra20-uart", .data = (void *)PORT_TEGRA, }, 326 254 { .compatible = "nxp,lpc3220-uart", .data = (void *)PORT_LPC3220, }, 255 + { .compatible = "ralink,rt2880-uart", .data = (void *)PORT_RT2880, }, 327 256 { .compatible = "altr,16550-FIFO32", 328 257 .data = (void *)PORT_ALTR_16550_F32, }, 329 258 { .compatible = "altr,16550-FIFO64",
+35 -58
drivers/tty/serial/omap-serial.c
··· 46 46 47 47 #include <dt-bindings/gpio/gpio.h> 48 48 49 - #define OMAP_MAX_HSUART_PORTS 6 49 + #define OMAP_MAX_HSUART_PORTS 10 50 50 51 51 #define UART_BUILD_REVISION(x, y) (((x) << 8) | (y)) 52 52 ··· 163 163 u8 wakeups_enabled; 164 164 u32 features; 165 165 166 - struct serial_rs485 rs485; 167 166 int rts_gpio; 168 167 169 168 struct pm_qos_request pm_qos_request; ··· 315 316 pm_runtime_get_sync(up->dev); 316 317 317 318 /* Handle RS-485 */ 318 - if (up->rs485.flags & SER_RS485_ENABLED) { 319 + if (port->rs485.flags & SER_RS485_ENABLED) { 319 320 if (up->scr & OMAP_UART_SCR_TX_EMPTY) { 320 321 /* THR interrupt is fired when both TX FIFO and TX 321 322 * shift register are empty. This means there's nothing ··· 326 327 */ 327 328 up->scr &= ~OMAP_UART_SCR_TX_EMPTY; 328 329 serial_out(up, UART_OMAP_SCR, up->scr); 329 - res = (up->rs485.flags & SER_RS485_RTS_AFTER_SEND) ? 1 : 0; 330 + res = (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) ? 331 + 1 : 0; 330 332 if (gpio_get_value(up->rts_gpio) != res) { 331 - if (up->rs485.delay_rts_after_send > 0) 332 - mdelay(up->rs485.delay_rts_after_send); 333 + if (port->rs485.delay_rts_after_send > 0) 334 + mdelay( 335 + port->rs485.delay_rts_after_send); 333 336 gpio_set_value(up->rts_gpio, res); 334 337 } 335 338 } else { ··· 354 353 serial_out(up, UART_IER, up->ier); 355 354 } 356 355 357 - if ((up->rs485.flags & SER_RS485_ENABLED) && 358 - !(up->rs485.flags & SER_RS485_RX_DURING_TX)) { 356 + if ((port->rs485.flags & SER_RS485_ENABLED) && 357 + !(port->rs485.flags & SER_RS485_RX_DURING_TX)) { 359 358 /* 360 359 * Empty the RX FIFO, we are not interested in anything 361 360 * received during the half-duplex transmission. ··· 430 429 pm_runtime_get_sync(up->dev); 431 430 432 431 /* Handle RS-485 */ 433 - if (up->rs485.flags & SER_RS485_ENABLED) { 432 + if (port->rs485.flags & SER_RS485_ENABLED) { 434 433 /* Fire THR interrupts when FIFO is below trigger level */ 435 434 up->scr &= ~OMAP_UART_SCR_TX_EMPTY; 436 435 serial_out(up, UART_OMAP_SCR, up->scr); 437 436 438 437 /* if rts not already enabled */ 439 - res = (up->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0; 438 + res = (port->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0; 440 439 if (gpio_get_value(up->rts_gpio) != res) { 441 440 gpio_set_value(up->rts_gpio, res); 442 - if (up->rs485.delay_rts_before_send > 0) 443 - mdelay(up->rs485.delay_rts_before_send); 441 + if (port->rs485.delay_rts_before_send > 0) 442 + mdelay(port->rs485.delay_rts_before_send); 444 443 } 445 444 } 446 445 447 - if ((up->rs485.flags & SER_RS485_ENABLED) && 448 - !(up->rs485.flags & SER_RS485_RX_DURING_TX)) 446 + if ((port->rs485.flags & SER_RS485_ENABLED) && 447 + !(port->rs485.flags & SER_RS485_RX_DURING_TX)) 449 448 serial_omap_stop_rx(port); 450 449 451 450 serial_omap_enable_ier_thri(up); ··· 1356 1355 #endif 1357 1356 1358 1357 /* Enable or disable the rs485 support */ 1359 - static void 1358 + static int 1360 1359 serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) 1361 1360 { 1362 1361 struct uart_omap_port *up = to_uart_omap_port(port); 1363 - unsigned long flags; 1364 1362 unsigned int mode; 1365 1363 int val; 1366 1364 1367 1365 pm_runtime_get_sync(up->dev); 1368 - spin_lock_irqsave(&up->port.lock, flags); 1369 1366 1370 1367 /* Disable interrupts from this port */ 1371 1368 mode = up->ier; ··· 1371 1372 serial_out(up, UART_IER, 0); 1372 1373 1373 1374 /* store new config */ 1374 - up->rs485 = *rs485conf; 1375 + port->rs485 = *rs485conf; 1375 1376 1376 1377 /* 1377 1378 * Just as a precaution, only allow rs485 ··· 1379 1380 */ 1380 1381 if (gpio_is_valid(up->rts_gpio)) { 1381 1382 /* enable / disable rts */ 1382 - val = (up->rs485.flags & SER_RS485_ENABLED) ? 1383 + val = (port->rs485.flags & SER_RS485_ENABLED) ? 1383 1384 SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND; 1384 - val = (up->rs485.flags & val) ? 1 : 0; 1385 + val = (port->rs485.flags & val) ? 1 : 0; 1385 1386 gpio_set_value(up->rts_gpio, val); 1386 1387 } else 1387 - up->rs485.flags &= ~SER_RS485_ENABLED; 1388 + port->rs485.flags &= ~SER_RS485_ENABLED; 1388 1389 1389 1390 /* Enable interrupts */ 1390 1391 up->ier = mode; ··· 1393 1394 /* If RS-485 is disabled, make sure the THR interrupt is fired when 1394 1395 * TX FIFO is below the trigger level. 1395 1396 */ 1396 - if (!(up->rs485.flags & SER_RS485_ENABLED) && 1397 + if (!(port->rs485.flags & SER_RS485_ENABLED) && 1397 1398 (up->scr & OMAP_UART_SCR_TX_EMPTY)) { 1398 1399 up->scr &= ~OMAP_UART_SCR_TX_EMPTY; 1399 1400 serial_out(up, UART_OMAP_SCR, up->scr); 1400 1401 } 1401 1402 1402 - spin_unlock_irqrestore(&up->port.lock, flags); 1403 1403 pm_runtime_mark_last_busy(up->dev); 1404 1404 pm_runtime_put_autosuspend(up->dev); 1405 - } 1406 1405 1407 - static int 1408 - serial_omap_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg) 1409 - { 1410 - struct serial_rs485 rs485conf; 1411 - 1412 - switch (cmd) { 1413 - case TIOCSRS485: 1414 - if (copy_from_user(&rs485conf, (void __user *) arg, 1415 - sizeof(rs485conf))) 1416 - return -EFAULT; 1417 - 1418 - serial_omap_config_rs485(port, &rs485conf); 1419 - break; 1420 - 1421 - case TIOCGRS485: 1422 - if (copy_to_user((void __user *) arg, 1423 - &(to_uart_omap_port(port)->rs485), 1424 - sizeof(rs485conf))) 1425 - return -EFAULT; 1426 - break; 1427 - 1428 - default: 1429 - return -ENOIOCTLCMD; 1430 - } 1431 1406 return 0; 1432 1407 } 1433 - 1434 1408 1435 1409 static struct uart_ops serial_omap_pops = { 1436 1410 .tx_empty = serial_omap_tx_empty, ··· 1425 1453 .request_port = serial_omap_request_port, 1426 1454 .config_port = serial_omap_config_port, 1427 1455 .verify_port = serial_omap_verify_port, 1428 - .ioctl = serial_omap_ioctl, 1429 1456 #ifdef CONFIG_CONSOLE_POLL 1430 1457 .poll_put_char = serial_omap_poll_put_char, 1431 1458 .poll_get_char = serial_omap_poll_get_char, ··· 1558 1587 static int serial_omap_probe_rs485(struct uart_omap_port *up, 1559 1588 struct device_node *np) 1560 1589 { 1561 - struct serial_rs485 *rs485conf = &up->rs485; 1590 + struct serial_rs485 *rs485conf = &up->port.rs485; 1562 1591 u32 rs485_delay[2]; 1563 1592 enum of_gpio_flags flags; 1564 1593 int ret; ··· 1653 1682 up->port.ops = &serial_omap_pops; 1654 1683 1655 1684 if (pdev->dev.of_node) 1656 - up->port.line = of_alias_get_id(pdev->dev.of_node, "serial"); 1685 + ret = of_alias_get_id(pdev->dev.of_node, "serial"); 1657 1686 else 1658 - up->port.line = pdev->id; 1687 + ret = pdev->id; 1659 1688 1660 - if (up->port.line < 0) { 1689 + if (ret < 0) { 1661 1690 dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", 1662 - up->port.line); 1663 - ret = -ENODEV; 1691 + ret); 1692 + goto err_port_line; 1693 + } 1694 + up->port.line = ret; 1695 + 1696 + if (up->port.line >= OMAP_MAX_HSUART_PORTS) { 1697 + dev_err(&pdev->dev, "uart ID %d > MAX %d.\n", up->port.line, 1698 + OMAP_MAX_HSUART_PORTS); 1699 + ret = -ENXIO; 1664 1700 goto err_port_line; 1665 1701 } 1666 1702 ··· 1680 1702 up->port.membase = base; 1681 1703 up->port.flags = omap_up_info->flags; 1682 1704 up->port.uartclk = omap_up_info->uartclk; 1705 + up->port.rs485_config = serial_omap_config_rs485; 1683 1706 if (!up->port.uartclk) { 1684 1707 up->port.uartclk = DEFAULT_CLK_SPEED; 1685 1708 dev_warn(&pdev->dev, ··· 1726 1747 pm_runtime_disable(&pdev->dev); 1727 1748 err_rs485: 1728 1749 err_port_line: 1729 - dev_err(&pdev->dev, "[UART%d]: failure [%s]: %d\n", 1730 - pdev->id, __func__, ret); 1731 1750 return ret; 1732 1751 } 1733 1752
+6 -3
drivers/tty/serial/pmac_zilog.c
··· 1352 1352 1353 1353 static int pmz_poll_get_char(struct uart_port *port) 1354 1354 { 1355 - struct uart_pmac_port *uap = (struct uart_pmac_port *)port; 1355 + struct uart_pmac_port *uap = 1356 + container_of(port, struct uart_pmac_port, port); 1356 1357 int tries = 2; 1357 1358 1358 1359 while (tries) { ··· 1368 1367 1369 1368 static void pmz_poll_put_char(struct uart_port *port, unsigned char c) 1370 1369 { 1371 - struct uart_pmac_port *uap = (struct uart_pmac_port *)port; 1370 + struct uart_pmac_port *uap = 1371 + container_of(port, struct uart_pmac_port, port); 1372 1372 1373 1373 /* Wait for the transmit buffer to empty. */ 1374 1374 while ((read_zsreg(uap, R0) & Tx_BUF_EMP) == 0) ··· 1956 1954 1957 1955 static void pmz_console_putchar(struct uart_port *port, int ch) 1958 1956 { 1959 - struct uart_pmac_port *uap = (struct uart_pmac_port *)port; 1957 + struct uart_pmac_port *uap = 1958 + container_of(port, struct uart_pmac_port, port); 1960 1959 1961 1960 /* Wait for the transmit buffer to empty. */ 1962 1961 while ((read_zsreg(uap, R0) & Tx_BUF_EMP) == 0)
+32 -16
drivers/tty/serial/pnx8xxx_uart.c
··· 126 126 */ 127 127 static void pnx8xxx_stop_tx(struct uart_port *port) 128 128 { 129 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 129 + struct pnx8xxx_port *sport = 130 + container_of(port, struct pnx8xxx_port, port); 130 131 u32 ien; 131 132 132 133 /* Disable TX intr */ ··· 143 142 */ 144 143 static void pnx8xxx_start_tx(struct uart_port *port) 145 144 { 146 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 145 + struct pnx8xxx_port *sport = 146 + container_of(port, struct pnx8xxx_port, port); 147 147 u32 ien; 148 148 149 149 /* Clear all pending TX intr */ ··· 160 158 */ 161 159 static void pnx8xxx_stop_rx(struct uart_port *port) 162 160 { 163 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 161 + struct pnx8xxx_port *sport = 162 + container_of(port, struct pnx8xxx_port, port); 164 163 u32 ien; 165 164 166 165 /* Disable RX intr */ ··· 177 174 */ 178 175 static void pnx8xxx_enable_ms(struct uart_port *port) 179 176 { 180 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 177 + struct pnx8xxx_port *sport = 178 + container_of(port, struct pnx8xxx_port, port); 181 179 182 180 mod_timer(&sport->timer, jiffies); 183 181 } ··· 317 313 */ 318 314 static unsigned int pnx8xxx_tx_empty(struct uart_port *port) 319 315 { 320 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 316 + struct pnx8xxx_port *sport = 317 + container_of(port, struct pnx8xxx_port, port); 321 318 322 319 return serial_in(sport, PNX8XXX_FIFO) & PNX8XXX_UART_FIFO_TXFIFO_STA ? 0 : TIOCSER_TEMT; 323 320 } 324 321 325 322 static unsigned int pnx8xxx_get_mctrl(struct uart_port *port) 326 323 { 327 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 324 + struct pnx8xxx_port *sport = 325 + container_of(port, struct pnx8xxx_port, port); 328 326 unsigned int mctrl = TIOCM_DSR; 329 327 unsigned int msr; 330 328 ··· 353 347 */ 354 348 static void pnx8xxx_break_ctl(struct uart_port *port, int break_state) 355 349 { 356 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 350 + struct pnx8xxx_port *sport = 351 + container_of(port, struct pnx8xxx_port, port); 357 352 unsigned long flags; 358 353 unsigned int lcr; 359 354 ··· 370 363 371 364 static int pnx8xxx_startup(struct uart_port *port) 372 365 { 373 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 366 + struct pnx8xxx_port *sport = 367 + container_of(port, struct pnx8xxx_port, port); 374 368 int retval; 375 369 376 370 /* ··· 405 397 406 398 static void pnx8xxx_shutdown(struct uart_port *port) 407 399 { 408 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 400 + struct pnx8xxx_port *sport = 401 + container_of(port, struct pnx8xxx_port, port); 409 402 int lcr; 410 403 411 404 /* ··· 443 434 pnx8xxx_set_termios(struct uart_port *port, struct ktermios *termios, 444 435 struct ktermios *old) 445 436 { 446 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 437 + struct pnx8xxx_port *sport = 438 + container_of(port, struct pnx8xxx_port, port); 447 439 unsigned long flags; 448 440 unsigned int lcr_fcr, old_ien, baud, quot; 449 441 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; ··· 561 551 562 552 static const char *pnx8xxx_type(struct uart_port *port) 563 553 { 564 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 554 + struct pnx8xxx_port *sport = 555 + container_of(port, struct pnx8xxx_port, port); 565 556 566 557 return sport->port.type == PORT_PNX8XXX ? "PNX8XXX" : NULL; 567 558 } ··· 572 561 */ 573 562 static void pnx8xxx_release_port(struct uart_port *port) 574 563 { 575 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 564 + struct pnx8xxx_port *sport = 565 + container_of(port, struct pnx8xxx_port, port); 576 566 577 567 release_mem_region(sport->port.mapbase, UART_PORT_SIZE); 578 568 } ··· 583 571 */ 584 572 static int pnx8xxx_request_port(struct uart_port *port) 585 573 { 586 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 574 + struct pnx8xxx_port *sport = 575 + container_of(port, struct pnx8xxx_port, port); 587 576 return request_mem_region(sport->port.mapbase, UART_PORT_SIZE, 588 577 "pnx8xxx-uart") != NULL ? 0 : -EBUSY; 589 578 } ··· 594 581 */ 595 582 static void pnx8xxx_config_port(struct uart_port *port, int flags) 596 583 { 597 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 584 + struct pnx8xxx_port *sport = 585 + container_of(port, struct pnx8xxx_port, port); 598 586 599 587 if (flags & UART_CONFIG_TYPE && 600 588 pnx8xxx_request_port(&sport->port) == 0) ··· 610 596 static int 611 597 pnx8xxx_verify_port(struct uart_port *port, struct serial_struct *ser) 612 598 { 613 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 599 + struct pnx8xxx_port *sport = 600 + container_of(port, struct pnx8xxx_port, port); 614 601 int ret = 0; 615 602 616 603 if (ser->type != PORT_UNKNOWN && ser->type != PORT_PNX8XXX) ··· 677 662 678 663 static void pnx8xxx_console_putchar(struct uart_port *port, int ch) 679 664 { 680 - struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; 665 + struct pnx8xxx_port *sport = 666 + container_of(port, struct pnx8xxx_port, port); 681 667 int status; 682 668 683 669 do {
+3
drivers/tty/serial/pxa.c
··· 223 223 } 224 224 } 225 225 226 + /* should hold up->port.lock */ 226 227 static inline void check_modem_status(struct uart_pxa_port *up) 227 228 { 228 229 int status; ··· 256 255 iir = serial_in(up, UART_IIR); 257 256 if (iir & UART_IIR_NO_INT) 258 257 return IRQ_NONE; 258 + spin_lock(&up->port.lock); 259 259 lsr = serial_in(up, UART_LSR); 260 260 if (lsr & UART_LSR_DR) 261 261 receive_chars(up, &lsr); 262 262 check_modem_status(up); 263 263 if (lsr & UART_LSR_THRE) 264 264 transmit_chars(up); 265 + spin_unlock(&up->port.lock); 265 266 return IRQ_HANDLED; 266 267 } 267 268
+30 -15
drivers/tty/serial/sa1100.c
··· 142 142 */ 143 143 static void sa1100_stop_tx(struct uart_port *port) 144 144 { 145 - struct sa1100_port *sport = (struct sa1100_port *)port; 145 + struct sa1100_port *sport = 146 + container_of(port, struct sa1100_port, port); 146 147 u32 utcr3; 147 148 148 149 utcr3 = UART_GET_UTCR3(sport); ··· 156 155 */ 157 156 static void sa1100_start_tx(struct uart_port *port) 158 157 { 159 - struct sa1100_port *sport = (struct sa1100_port *)port; 158 + struct sa1100_port *sport = 159 + container_of(port, struct sa1100_port, port); 160 160 u32 utcr3; 161 161 162 162 utcr3 = UART_GET_UTCR3(sport); ··· 170 168 */ 171 169 static void sa1100_stop_rx(struct uart_port *port) 172 170 { 173 - struct sa1100_port *sport = (struct sa1100_port *)port; 171 + struct sa1100_port *sport = 172 + container_of(port, struct sa1100_port, port); 174 173 u32 utcr3; 175 174 176 175 utcr3 = UART_GET_UTCR3(sport); ··· 183 180 */ 184 181 static void sa1100_enable_ms(struct uart_port *port) 185 182 { 186 - struct sa1100_port *sport = (struct sa1100_port *)port; 183 + struct sa1100_port *sport = 184 + container_of(port, struct sa1100_port, port); 187 185 188 186 mod_timer(&sport->timer, jiffies); 189 187 } ··· 327 323 */ 328 324 static unsigned int sa1100_tx_empty(struct uart_port *port) 329 325 { 330 - struct sa1100_port *sport = (struct sa1100_port *)port; 326 + struct sa1100_port *sport = 327 + container_of(port, struct sa1100_port, port); 331 328 332 329 return UART_GET_UTSR1(sport) & UTSR1_TBY ? 0 : TIOCSER_TEMT; 333 330 } ··· 347 342 */ 348 343 static void sa1100_break_ctl(struct uart_port *port, int break_state) 349 344 { 350 - struct sa1100_port *sport = (struct sa1100_port *)port; 345 + struct sa1100_port *sport = 346 + container_of(port, struct sa1100_port, port); 351 347 unsigned long flags; 352 348 unsigned int utcr3; 353 349 ··· 364 358 365 359 static int sa1100_startup(struct uart_port *port) 366 360 { 367 - struct sa1100_port *sport = (struct sa1100_port *)port; 361 + struct sa1100_port *sport = 362 + container_of(port, struct sa1100_port, port); 368 363 int retval; 369 364 370 365 /* ··· 394 387 395 388 static void sa1100_shutdown(struct uart_port *port) 396 389 { 397 - struct sa1100_port *sport = (struct sa1100_port *)port; 390 + struct sa1100_port *sport = 391 + container_of(port, struct sa1100_port, port); 398 392 399 393 /* 400 394 * Stop our timer. ··· 417 409 sa1100_set_termios(struct uart_port *port, struct ktermios *termios, 418 410 struct ktermios *old) 419 411 { 420 - struct sa1100_port *sport = (struct sa1100_port *)port; 412 + struct sa1100_port *sport = 413 + container_of(port, struct sa1100_port, port); 421 414 unsigned long flags; 422 415 unsigned int utcr0, old_utcr3, baud, quot; 423 416 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; ··· 521 512 522 513 static const char *sa1100_type(struct uart_port *port) 523 514 { 524 - struct sa1100_port *sport = (struct sa1100_port *)port; 515 + struct sa1100_port *sport = 516 + container_of(port, struct sa1100_port, port); 525 517 526 518 return sport->port.type == PORT_SA1100 ? "SA1100" : NULL; 527 519 } ··· 532 522 */ 533 523 static void sa1100_release_port(struct uart_port *port) 534 524 { 535 - struct sa1100_port *sport = (struct sa1100_port *)port; 525 + struct sa1100_port *sport = 526 + container_of(port, struct sa1100_port, port); 536 527 537 528 release_mem_region(sport->port.mapbase, UART_PORT_SIZE); 538 529 } ··· 543 532 */ 544 533 static int sa1100_request_port(struct uart_port *port) 545 534 { 546 - struct sa1100_port *sport = (struct sa1100_port *)port; 535 + struct sa1100_port *sport = 536 + container_of(port, struct sa1100_port, port); 547 537 548 538 return request_mem_region(sport->port.mapbase, UART_PORT_SIZE, 549 539 "sa11x0-uart") != NULL ? 0 : -EBUSY; ··· 555 543 */ 556 544 static void sa1100_config_port(struct uart_port *port, int flags) 557 545 { 558 - struct sa1100_port *sport = (struct sa1100_port *)port; 546 + struct sa1100_port *sport = 547 + container_of(port, struct sa1100_port, port); 559 548 560 549 if (flags & UART_CONFIG_TYPE && 561 550 sa1100_request_port(&sport->port) == 0) ··· 571 558 static int 572 559 sa1100_verify_port(struct uart_port *port, struct serial_struct *ser) 573 560 { 574 - struct sa1100_port *sport = (struct sa1100_port *)port; 561 + struct sa1100_port *sport = 562 + container_of(port, struct sa1100_port, port); 575 563 int ret = 0; 576 564 577 565 if (ser->type != PORT_UNKNOWN && ser->type != PORT_SA1100) ··· 705 691 #ifdef CONFIG_SERIAL_SA1100_CONSOLE 706 692 static void sa1100_console_putchar(struct uart_port *port, int ch) 707 693 { 708 - struct sa1100_port *sport = (struct sa1100_port *)port; 694 + struct sa1100_port *sport = 695 + container_of(port, struct sa1100_port, port); 709 696 710 697 while (!(UART_GET_UTSR1(sport) & UTSR1_TNF)) 711 698 barrier();
+38 -52
drivers/tty/serial/samsung.c
··· 199 199 } 200 200 } 201 201 202 - static inline struct s3c24xx_uart_info *s3c24xx_port_to_info(struct uart_port *port) 202 + static inline struct s3c24xx_uart_info 203 + *s3c24xx_port_to_info(struct uart_port *port) 203 204 { 204 205 return to_ourport(port)->info; 205 206 } 206 207 207 - static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port) 208 + static inline struct s3c2410_uartcfg 209 + *s3c24xx_port_to_cfg(struct uart_port *port) 208 210 { 209 211 struct s3c24xx_uart_port *ourport; 210 212 ··· 239 237 struct uart_port *port = &ourport->port; 240 238 unsigned int ufcon, ch, flag, ufstat, uerstat; 241 239 unsigned long flags; 242 - int max_count = 64; 240 + int max_count = port->fifosize; 243 241 244 242 spin_lock_irqsave(&port->lock, flags); 245 243 ··· 313 311 uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN, 314 312 ch, flag); 315 313 316 - ignore_char: 314 + ignore_char: 317 315 continue; 318 316 } 319 317 320 318 spin_unlock_irqrestore(&port->lock, flags); 321 319 tty_flip_buffer_push(&port->state->port); 322 320 323 - out: 321 + out: 324 322 return IRQ_HANDLED; 325 323 } 326 324 ··· 330 328 struct uart_port *port = &ourport->port; 331 329 struct circ_buf *xmit = &port->state->xmit; 332 330 unsigned long flags; 333 - int count = 256; 331 + int count = port->fifosize; 334 332 335 333 spin_lock_irqsave(&port->lock, flags); 336 334 ··· 370 368 if (uart_circ_empty(xmit)) 371 369 s3c24xx_serial_stop_tx(port); 372 370 373 - out: 371 + out: 374 372 spin_unlock_irqrestore(&port->lock, flags); 375 373 return IRQ_HANDLED; 376 374 } ··· 521 519 522 520 return ret; 523 521 524 - err: 522 + err: 525 523 s3c24xx_serial_shutdown(port); 526 524 return ret; 527 525 } ··· 561 559 unsigned int old) 562 560 { 563 561 struct s3c24xx_uart_port *ourport = to_ourport(port); 562 + int timeout = 10000; 564 563 565 564 ourport->pm_level = level; 566 565 567 566 switch (level) { 568 567 case 3: 568 + while (--timeout && !s3c24xx_serial_txempty_nofifo(port)) 569 + udelay(100); 570 + 569 571 if (!IS_ERR(ourport->baudclk)) 570 572 clk_disable_unprepare(ourport->baudclk); 571 573 ··· 847 841 */ 848 842 port->read_status_mask = S3C2410_UERSTAT_OVERRUN; 849 843 if (termios->c_iflag & INPCK) 850 - port->read_status_mask |= S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_PARITY; 851 - 844 + port->read_status_mask |= S3C2410_UERSTAT_FRAME | 845 + S3C2410_UERSTAT_PARITY; 852 846 /* 853 847 * Which character status flags should we ignore? 854 848 */ ··· 975 969 .minor = S3C24XX_SERIAL_MINOR, 976 970 }; 977 971 978 - static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = { 972 + #define __PORT_LOCK_UNLOCKED(i) \ 973 + __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[i].port.lock) 974 + static struct s3c24xx_uart_port 975 + s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = { 979 976 [0] = { 980 977 .port = { 981 - .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock), 978 + .lock = __PORT_LOCK_UNLOCKED(0), 982 979 .iotype = UPIO_MEM, 983 980 .uartclk = 0, 984 981 .fifosize = 16, ··· 992 983 }, 993 984 [1] = { 994 985 .port = { 995 - .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock), 986 + .lock = __PORT_LOCK_UNLOCKED(1), 996 987 .iotype = UPIO_MEM, 997 988 .uartclk = 0, 998 989 .fifosize = 16, ··· 1005 996 1006 997 [2] = { 1007 998 .port = { 1008 - .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock), 999 + .lock = __PORT_LOCK_UNLOCKED(2), 1009 1000 .iotype = UPIO_MEM, 1010 1001 .uartclk = 0, 1011 1002 .fifosize = 16, ··· 1018 1009 #if CONFIG_SERIAL_SAMSUNG_UARTS > 3 1019 1010 [3] = { 1020 1011 .port = { 1021 - .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[3].port.lock), 1012 + .lock = __PORT_LOCK_UNLOCKED(3), 1022 1013 .iotype = UPIO_MEM, 1023 1014 .uartclk = 0, 1024 1015 .fifosize = 16, ··· 1029 1020 } 1030 1021 #endif 1031 1022 }; 1023 + #undef __PORT_LOCK_UNLOCKED 1032 1024 1033 1025 /* s3c24xx_serial_resetport 1034 1026 * ··· 1112 1102 s3c24xx_serial_set_termios(uport, termios, NULL); 1113 1103 } 1114 1104 1115 - exit: 1105 + exit: 1116 1106 return 0; 1117 1107 } 1118 1108 1119 - static inline int s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port) 1109 + static inline int 1110 + s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port) 1120 1111 { 1121 1112 port->freq_transition.notifier_call = s3c24xx_serial_cpufreq_transition; 1122 1113 ··· 1125 1114 CPUFREQ_TRANSITION_NOTIFIER); 1126 1115 } 1127 1116 1128 - static inline void s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port) 1117 + static inline void 1118 + s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port) 1129 1119 { 1130 1120 cpufreq_unregister_notifier(&port->freq_transition, 1131 1121 CPUFREQ_TRANSITION_NOTIFIER); 1132 1122 } 1133 1123 1134 1124 #else 1135 - static inline int s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port) 1125 + static inline int 1126 + s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port) 1136 1127 { 1137 1128 return 0; 1138 1129 } 1139 1130 1140 - static inline void s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port) 1131 + static inline void 1132 + s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port) 1141 1133 { 1142 1134 } 1143 1135 #endif ··· 1240 1226 return 0; 1241 1227 } 1242 1228 1243 - #ifdef CONFIG_SAMSUNG_CLOCK 1244 - static ssize_t s3c24xx_serial_show_clksrc(struct device *dev, 1245 - struct device_attribute *attr, 1246 - char *buf) 1247 - { 1248 - struct uart_port *port = s3c24xx_dev_to_port(dev); 1249 - struct s3c24xx_uart_port *ourport = to_ourport(port); 1250 - 1251 - if (IS_ERR(ourport->baudclk)) 1252 - return -EINVAL; 1253 - 1254 - return snprintf(buf, PAGE_SIZE, "* %s\n", 1255 - ourport->baudclk->name ?: "(null)"); 1256 - } 1257 - 1258 - static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL); 1259 - #endif 1260 - 1261 1229 /* Device driver serial port probe */ 1262 1230 1263 1231 static const struct of_device_id s3c24xx_uart_dt_match[]; ··· 1292 1296 of_property_read_u32(np, 1293 1297 "samsung,uart-fifosize", &ourport->port.fifosize); 1294 1298 1295 - if (!ourport->port.fifosize) { 1296 - ourport->port.fifosize = (ourport->info->fifosize) ? 1297 - ourport->info->fifosize : 1298 - ourport->drv_data->fifosize[index]; 1299 - } 1299 + if (ourport->drv_data->fifosize[index]) 1300 + ourport->port.fifosize = ourport->drv_data->fifosize[index]; 1301 + else if (ourport->info->fifosize) 1302 + ourport->port.fifosize = ourport->info->fifosize; 1300 1303 1301 1304 probe_index++; 1302 1305 ··· 1324 1329 */ 1325 1330 clk_disable_unprepare(ourport->clk); 1326 1331 1327 - #ifdef CONFIG_SAMSUNG_CLOCK 1328 - ret = device_create_file(&pdev->dev, &dev_attr_clock_source); 1329 - if (ret < 0) 1330 - dev_err(&pdev->dev, "failed to add clock source attr.\n"); 1331 - #endif 1332 - 1333 1332 ret = s3c24xx_serial_cpufreq_register(ourport); 1334 1333 if (ret < 0) 1335 1334 dev_err(&pdev->dev, "failed to add cpufreq notifier\n"); ··· 1337 1348 1338 1349 if (port) { 1339 1350 s3c24xx_serial_cpufreq_deregister(to_ourport(port)); 1340 - #ifdef CONFIG_SAMSUNG_CLOCK 1341 - device_remove_file(&dev->dev, &dev_attr_clock_source); 1342 - #endif 1343 1351 uart_remove_one_port(&s3c24xx_uart_drv, port); 1344 1352 } 1345 1353
+12 -45
drivers/tty/serial/sc16is7xx.c
··· 304 304 struct uart_port port; 305 305 struct work_struct tx_work; 306 306 struct work_struct md_work; 307 - 308 - struct serial_rs485 rs485; 309 307 }; 310 308 311 309 struct sc16is7xx_port { ··· 655 657 struct circ_buf *xmit = &one->port.state->xmit; 656 658 657 659 /* handle rs485 */ 658 - if (one->rs485.flags & SER_RS485_ENABLED) { 660 + if (port->rs485.flags & SER_RS485_ENABLED) { 659 661 /* do nothing if current tx not yet completed */ 660 662 int lsr = sc16is7xx_port_read(port, SC16IS7XX_LSR_REG); 661 663 if (!(lsr & SC16IS7XX_LSR_TEMT_BIT)) 662 664 return; 663 665 664 666 if (uart_circ_empty(xmit) && 665 - (one->rs485.delay_rts_after_send > 0)) 666 - mdelay(one->rs485.delay_rts_after_send); 667 + (port->rs485.delay_rts_after_send > 0)) 668 + mdelay(port->rs485.delay_rts_after_send); 667 669 } 668 670 669 671 sc16is7xx_port_update(port, SC16IS7XX_IER_REG, ··· 686 688 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 687 689 688 690 /* handle rs485 */ 689 - if ((one->rs485.flags & SER_RS485_ENABLED) && 690 - (one->rs485.delay_rts_before_send > 0)) { 691 - mdelay(one->rs485.delay_rts_before_send); 691 + if ((port->rs485.flags & SER_RS485_ENABLED) && 692 + (port->rs485.delay_rts_before_send > 0)) { 693 + mdelay(port->rs485.delay_rts_before_send); 692 694 } 693 695 694 696 if (!work_pending(&one->tx_work)) ··· 828 830 uart_update_timeout(port, termios->c_cflag, baud); 829 831 } 830 832 831 - #if defined(TIOCSRS485) && defined(TIOCGRS485) 832 - static void sc16is7xx_config_rs485(struct uart_port *port, 833 + static int sc16is7xx_config_rs485(struct uart_port *port, 833 834 struct serial_rs485 *rs485) 834 835 { 835 - struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 836 - 837 - one->rs485 = *rs485; 838 - 839 - if (one->rs485.flags & SER_RS485_ENABLED) { 836 + if (port->rs485.flags & SER_RS485_ENABLED) 840 837 sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, 841 838 SC16IS7XX_EFCR_AUTO_RS485_BIT, 842 839 SC16IS7XX_EFCR_AUTO_RS485_BIT); 843 - } else { 840 + else 844 841 sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, 845 842 SC16IS7XX_EFCR_AUTO_RS485_BIT, 846 843 0); 847 - } 848 - } 849 - #endif 844 + port->rs485 = *rs485; 850 845 851 - static int sc16is7xx_ioctl(struct uart_port *port, unsigned int cmd, 852 - unsigned long arg) 853 - { 854 - #if defined(TIOCSRS485) && defined(TIOCGRS485) 855 - struct serial_rs485 rs485; 856 - 857 - switch (cmd) { 858 - case TIOCSRS485: 859 - if (copy_from_user(&rs485, (void __user *)arg, sizeof(rs485))) 860 - return -EFAULT; 861 - 862 - sc16is7xx_config_rs485(port, &rs485); 863 - return 0; 864 - case TIOCGRS485: 865 - if (copy_to_user((void __user *)arg, 866 - &(to_sc16is7xx_one(port, port)->rs485), 867 - sizeof(rs485))) 868 - return -EFAULT; 869 - return 0; 870 - default: 871 - break; 872 - } 873 - #endif 874 - 875 - return -ENOIOCTLCMD; 846 + return 0; 876 847 } 877 848 878 849 static int sc16is7xx_startup(struct uart_port *port) ··· 967 1000 .release_port = sc16is7xx_null_void, 968 1001 .config_port = sc16is7xx_config_port, 969 1002 .verify_port = sc16is7xx_verify_port, 970 - .ioctl = sc16is7xx_ioctl, 971 1003 .pm = sc16is7xx_pm, 972 1004 }; 973 1005 ··· 1096 1130 s->p[i].port.flags = UPF_FIXED_TYPE | UPF_LOW_LATENCY; 1097 1131 s->p[i].port.iotype = UPIO_PORT; 1098 1132 s->p[i].port.uartclk = freq; 1133 + s->p[i].port.rs485_config = sc16is7xx_config_rs485; 1099 1134 s->p[i].port.ops = &sc16is7xx_ops; 1100 1135 /* Disable all interrupts */ 1101 1136 sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_IER_REG, 0);
+19 -17
drivers/tty/serial/serial-tegra.c
··· 319 319 if (unlikely(lsr & TEGRA_UART_LSR_ANY)) { 320 320 if (lsr & UART_LSR_OE) { 321 321 /* Overrrun error */ 322 - flag |= TTY_OVERRUN; 322 + flag = TTY_OVERRUN; 323 323 tup->uport.icount.overrun++; 324 324 dev_err(tup->uport.dev, "Got overrun errors\n"); 325 325 } else if (lsr & UART_LSR_PE) { 326 326 /* Parity error */ 327 - flag |= TTY_PARITY; 327 + flag = TTY_PARITY; 328 328 tup->uport.icount.parity++; 329 329 dev_err(tup->uport.dev, "Got Parity errors\n"); 330 330 } else if (lsr & UART_LSR_FE) { 331 - flag |= TTY_FRAME; 331 + flag = TTY_FRAME; 332 332 tup->uport.icount.frame++; 333 333 dev_err(tup->uport.dev, "Got frame errors\n"); 334 334 } else if (lsr & UART_LSR_BI) { ··· 1034 1034 return ret; 1035 1035 } 1036 1036 1037 + /* 1038 + * Flush any TX data submitted for DMA and PIO. Called when the 1039 + * TX circular buffer is reset. 1040 + */ 1041 + static void tegra_uart_flush_buffer(struct uart_port *u) 1042 + { 1043 + struct tegra_uart_port *tup = to_tegra_uport(u); 1044 + 1045 + tup->tx_bytes = 0; 1046 + if (tup->tx_dma_chan) 1047 + dmaengine_terminate_all(tup->tx_dma_chan); 1048 + return; 1049 + } 1050 + 1037 1051 static void tegra_uart_shutdown(struct uart_port *u) 1038 1052 { 1039 1053 struct tegra_uart_port *tup = to_tegra_uport(u); ··· 1060 1046 tegra_uart_dma_channel_free(tup, true); 1061 1047 tegra_uart_dma_channel_free(tup, false); 1062 1048 free_irq(u->irq, tup); 1049 + 1050 + tegra_uart_flush_buffer(u); 1063 1051 } 1064 1052 1065 1053 static void tegra_uart_enable_ms(struct uart_port *u) ··· 1187 1171 tegra_uart_read(tup, UART_IER); 1188 1172 1189 1173 spin_unlock_irqrestore(&u->lock, flags); 1190 - return; 1191 - } 1192 - 1193 - /* 1194 - * Flush any TX data submitted for DMA and PIO. Called when the 1195 - * TX circular buffer is reset. 1196 - */ 1197 - static void tegra_uart_flush_buffer(struct uart_port *u) 1198 - { 1199 - struct tegra_uart_port *tup = to_tegra_uport(u); 1200 - 1201 - tup->tx_bytes = 0; 1202 - if (tup->tx_dma_chan) 1203 - dmaengine_terminate_all(tup->tx_dma_chan); 1204 1174 return; 1205 1175 } 1206 1176
+90 -28
drivers/tty/serial/serial_core.c
··· 61 61 62 62 static int uart_dcd_enabled(struct uart_port *uport) 63 63 { 64 - return uport->status & UPSTAT_DCD_ENABLE; 64 + return !!(uport->status & UPSTAT_DCD_ENABLE); 65 65 } 66 66 67 67 /* ··· 436 436 437 437 EXPORT_SYMBOL(uart_get_divisor); 438 438 439 - /* FIXME: Consistent locking policy */ 439 + /* Caller holds port mutex */ 440 440 static void uart_change_speed(struct tty_struct *tty, struct uart_state *state, 441 441 struct ktermios *old_termios) 442 442 { ··· 537 537 count -= c; 538 538 ret += c; 539 539 } 540 + 541 + __uart_start(tty); 540 542 spin_unlock_irqrestore(&port->lock, flags); 541 543 542 - uart_start(tty); 543 544 return ret; 544 545 } 545 546 ··· 619 618 { 620 619 struct uart_state *state = tty->driver_data; 621 620 struct uart_port *port = state->uart_port; 622 - uint32_t mask = 0; 621 + upf_t mask = 0; 623 622 624 623 if (I_IXOFF(tty)) 625 624 mask |= UPF_SOFT_FLOW; ··· 642 641 { 643 642 struct uart_state *state = tty->driver_data; 644 643 struct uart_port *port = state->uart_port; 645 - uint32_t mask = 0; 644 + upf_t mask = 0; 646 645 647 646 if (I_IXOFF(tty)) 648 647 mask |= UPF_SOFT_FLOW; ··· 1152 1151 return 0; 1153 1152 } 1154 1153 1154 + static int uart_get_rs485_config(struct uart_port *port, 1155 + struct serial_rs485 __user *rs485) 1156 + { 1157 + unsigned long flags; 1158 + struct serial_rs485 aux; 1159 + 1160 + spin_lock_irqsave(&port->lock, flags); 1161 + aux = port->rs485; 1162 + spin_unlock_irqrestore(&port->lock, flags); 1163 + 1164 + if (copy_to_user(rs485, &aux, sizeof(aux))) 1165 + return -EFAULT; 1166 + 1167 + return 0; 1168 + } 1169 + 1170 + static int uart_set_rs485_config(struct uart_port *port, 1171 + struct serial_rs485 __user *rs485_user) 1172 + { 1173 + struct serial_rs485 rs485; 1174 + int ret; 1175 + unsigned long flags; 1176 + 1177 + if (!port->rs485_config) 1178 + return -ENOIOCTLCMD; 1179 + 1180 + if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user))) 1181 + return -EFAULT; 1182 + 1183 + spin_lock_irqsave(&port->lock, flags); 1184 + ret = port->rs485_config(port, &rs485); 1185 + spin_unlock_irqrestore(&port->lock, flags); 1186 + if (ret) 1187 + return ret; 1188 + 1189 + if (copy_to_user(rs485_user, &port->rs485, sizeof(port->rs485))) 1190 + return -EFAULT; 1191 + 1192 + return 0; 1193 + } 1194 + 1155 1195 /* 1156 1196 * Called via sys_ioctl. We can use spin_lock_irq() here. 1157 1197 */ ··· 1215 1173 break; 1216 1174 1217 1175 case TIOCSSERIAL: 1176 + down_write(&tty->termios_rwsem); 1218 1177 ret = uart_set_info_user(tty, state, uarg); 1178 + up_write(&tty->termios_rwsem); 1219 1179 break; 1220 1180 1221 1181 case TIOCSERCONFIG: 1182 + down_write(&tty->termios_rwsem); 1222 1183 ret = uart_do_autoconfig(tty, state); 1184 + up_write(&tty->termios_rwsem); 1223 1185 break; 1224 1186 1225 1187 case TIOCSERGWILD: /* obsolete */ ··· 1263 1217 * All these rely on hardware being present and need to be 1264 1218 * protected against the tty being hung up. 1265 1219 */ 1220 + 1266 1221 switch (cmd) { 1267 1222 case TIOCSERGETLSR: /* Get line status register */ 1268 1223 ret = uart_get_lsr_info(tty, state, uarg); 1269 1224 break; 1270 1225 1226 + case TIOCGRS485: 1227 + ret = uart_get_rs485_config(state->uart_port, uarg); 1228 + break; 1229 + 1230 + case TIOCSRS485: 1231 + ret = uart_set_rs485_config(state->uart_port, uarg); 1232 + break; 1271 1233 default: { 1272 1234 struct uart_port *uport = state->uart_port; 1273 1235 if (uport->ops->ioctl) ··· 1294 1240 struct uart_state *state = tty->driver_data; 1295 1241 struct uart_port *uport = state->uart_port; 1296 1242 1297 - if (uport->ops->set_ldisc) 1298 - uport->ops->set_ldisc(uport, tty->termios.c_line); 1243 + if (uport->ops->set_ldisc) { 1244 + mutex_lock(&state->port.mutex); 1245 + uport->ops->set_ldisc(uport, &tty->termios); 1246 + mutex_unlock(&state->port.mutex); 1247 + } 1299 1248 } 1300 1249 1301 1250 static void uart_set_termios(struct tty_struct *tty, ··· 1335 1278 return; 1336 1279 } 1337 1280 1281 + mutex_lock(&state->port.mutex); 1338 1282 uart_change_speed(tty, state, old_termios); 1283 + mutex_unlock(&state->port.mutex); 1339 1284 /* reload cflag from termios; port driver may have overriden flags */ 1340 1285 cflag = tty->termios.c_cflag; 1341 1286 ··· 1390 1331 struct uart_port *uport; 1391 1332 unsigned long flags; 1392 1333 1393 - if (!state) 1334 + if (!state) { 1335 + struct uart_driver *drv = tty->driver->driver_state; 1336 + 1337 + state = drv->state + tty->index; 1338 + port = &state->port; 1339 + spin_lock_irq(&port->lock); 1340 + --port->count; 1341 + spin_unlock_irq(&port->lock); 1394 1342 return; 1343 + } 1395 1344 1396 1345 uport = state->uart_port; 1397 1346 port = &state->port; ··· 1428 1361 1429 1362 mutex_lock(&port->mutex); 1430 1363 uart_shutdown(tty, state); 1431 - uart_flush_buffer(tty); 1432 - 1433 - tty_ldisc_flush(tty); 1434 - 1435 1364 tty_port_tty_set(port, NULL); 1436 1365 tty->closing = 0; 1437 1366 spin_lock_irqsave(&port->lock, flags); ··· 1435 1372 if (port->blocked_open) { 1436 1373 spin_unlock_irqrestore(&port->lock, flags); 1437 1374 if (port->close_delay) 1438 - msleep_interruptible( 1439 - jiffies_to_msecs(port->close_delay)); 1375 + msleep_interruptible(jiffies_to_msecs(port->close_delay)); 1440 1376 spin_lock_irqsave(&port->lock, flags); 1441 1377 } else if (!uart_console(uport)) { 1442 1378 spin_unlock_irqrestore(&port->lock, flags); ··· 1453 1391 wake_up_interruptible(&port->close_wait); 1454 1392 1455 1393 mutex_unlock(&port->mutex); 1394 + 1395 + tty_ldisc_flush(tty); 1456 1396 } 1457 1397 1458 1398 static void uart_wait_until_sent(struct tty_struct *tty, int timeout) ··· 1616 1552 1617 1553 pr_debug("uart_open(%d) called\n", line); 1618 1554 1555 + spin_lock_irq(&port->lock); 1556 + ++port->count; 1557 + spin_unlock_irq(&port->lock); 1558 + 1619 1559 /* 1620 1560 * We take the semaphore here to guarantee that we won't be re-entered 1621 1561 * while allocating the state structure, or while we request any IRQs ··· 1632 1564 goto end; 1633 1565 } 1634 1566 1635 - port->count++; 1636 1567 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) { 1637 1568 retval = -ENXIO; 1638 - goto err_dec_count; 1569 + goto err_unlock; 1639 1570 } 1640 1571 1641 - /* 1642 - * Once we set tty->driver_data here, we are guaranteed that 1643 - * uart_close() will decrement the driver module use count. 1644 - * Any failures from here onwards should not touch the count. 1645 - */ 1646 1572 tty->driver_data = state; 1647 1573 state->uart_port->state = state; 1648 1574 state->port.low_latency = ··· 1657 1595 1658 1596 end: 1659 1597 return retval; 1660 - err_dec_count: 1661 - port->count--; 1598 + err_unlock: 1662 1599 mutex_unlock(&port->mutex); 1663 1600 goto end; 1664 1601 } ··· 2153 2092 break; 2154 2093 case UPIO_MEM: 2155 2094 case UPIO_MEM32: 2095 + case UPIO_MEM32BE: 2156 2096 case UPIO_AU: 2157 2097 case UPIO_TSI: 2158 2098 snprintf(address, sizeof(address), ··· 2401 2339 2402 2340 tty_port_init(port); 2403 2341 port->ops = &uart_port_ops; 2404 - port->close_delay = HZ / 2; /* .5 seconds */ 2405 - port->closing_wait = 30 * HZ;/* 30 seconds */ 2406 2342 } 2407 2343 2408 2344 retval = tty_register_driver(normal); ··· 2649 2589 goto out; 2650 2590 } 2651 2591 2592 + /* Link the port to the driver state table and vice versa */ 2652 2593 state->uart_port = uport; 2653 - state->pm_state = UART_PM_STATE_UNDEFINED; 2654 - 2655 - uport->cons = drv->cons; 2656 2594 uport->state = state; 2595 + 2596 + state->pm_state = UART_PM_STATE_UNDEFINED; 2597 + uport->cons = drv->cons; 2657 2598 2658 2599 /* 2659 2600 * If this port is a console, then the spinlock is already ··· 2797 2736 (port1->hub6 == port2->hub6); 2798 2737 case UPIO_MEM: 2799 2738 case UPIO_MEM32: 2739 + case UPIO_MEM32BE: 2800 2740 case UPIO_AU: 2801 2741 case UPIO_TSI: 2802 2742 return (port1->mapbase == port2->mapbase);
+1 -4
drivers/tty/serial/sh-sci.c
··· 1812 1812 err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr * 1813 1813 (1 << (2 * c + 1)) / 1000)) - 1814 1814 1000; 1815 - if (err < 0) 1816 - continue; 1817 - 1818 1815 /* Calc recv margin 1819 1816 * M: Receive margin (%) 1820 1817 * N: Ratio of bit rate to clock (N = sampling rate) ··· 1826 1829 */ 1827 1830 recv_margin = abs((500 - 1828 1831 DIV_ROUND_CLOSEST(1000, sr << 1)) / 10); 1829 - if (min_err > err) { 1832 + if (abs(min_err) > abs(err)) { 1830 1833 min_err = err; 1831 1834 recv_max_margin = recv_margin; 1832 1835 } else if ((min_err == err) &&
+27 -7
drivers/tty/serial/sirfsoc_uart.c
··· 1032 1032 unsigned int oldstate) 1033 1033 { 1034 1034 struct sirfsoc_uart_port *sirfport = to_sirfport(port); 1035 - if (!state) 1035 + if (!state) { 1036 + if (sirfport->is_bt_uart) { 1037 + clk_prepare_enable(sirfport->clk_noc); 1038 + clk_prepare_enable(sirfport->clk_general); 1039 + } 1036 1040 clk_prepare_enable(sirfport->clk); 1037 - else 1041 + } else { 1038 1042 clk_disable_unprepare(sirfport->clk); 1043 + if (sirfport->is_bt_uart) { 1044 + clk_disable_unprepare(sirfport->clk_general); 1045 + clk_disable_unprepare(sirfport->clk_noc); 1046 + } 1047 + } 1039 1048 } 1040 1049 1041 1050 static int sirfsoc_uart_startup(struct uart_port *port) ··· 1387 1378 } 1388 1379 port->irq = res->start; 1389 1380 1390 - sirfport->clk = clk_get(&pdev->dev, NULL); 1381 + sirfport->clk = devm_clk_get(&pdev->dev, NULL); 1391 1382 if (IS_ERR(sirfport->clk)) { 1392 1383 ret = PTR_ERR(sirfport->clk); 1393 1384 goto err; 1394 1385 } 1395 1386 port->uartclk = clk_get_rate(sirfport->clk); 1387 + if (of_device_is_compatible(pdev->dev.of_node, "sirf,marco-bt-uart")) { 1388 + sirfport->clk_general = devm_clk_get(&pdev->dev, "general"); 1389 + if (IS_ERR(sirfport->clk_general)) { 1390 + ret = PTR_ERR(sirfport->clk_general); 1391 + goto err; 1392 + } 1393 + sirfport->clk_noc = devm_clk_get(&pdev->dev, "noc"); 1394 + if (IS_ERR(sirfport->clk_noc)) { 1395 + ret = PTR_ERR(sirfport->clk_noc); 1396 + goto err; 1397 + } 1398 + sirfport->is_bt_uart = true; 1399 + } else 1400 + sirfport->is_bt_uart = false; 1396 1401 1397 1402 port->ops = &sirfsoc_uart_ops; 1398 1403 spin_lock_init(&port->lock); ··· 1415 1392 ret = uart_add_one_port(&sirfsoc_uart_drv, port); 1416 1393 if (ret != 0) { 1417 1394 dev_err(&pdev->dev, "Cannot add UART port(%d).\n", pdev->id); 1418 - goto port_err; 1395 + goto err; 1419 1396 } 1420 1397 1421 1398 sirfport->rx_dma_chan = dma_request_slave_channel(port->dev, "rx"); ··· 1444 1421 sirfport->rx_dma_items[j].xmit.buf, 1445 1422 sirfport->rx_dma_items[j].dma_addr); 1446 1423 dma_release_channel(sirfport->rx_dma_chan); 1447 - port_err: 1448 - clk_put(sirfport->clk); 1449 1424 err: 1450 1425 return ret; 1451 1426 } ··· 1452 1431 { 1453 1432 struct sirfsoc_uart_port *sirfport = platform_get_drvdata(pdev); 1454 1433 struct uart_port *port = &sirfport->port; 1455 - clk_put(sirfport->clk); 1456 1434 uart_remove_one_port(&sirfsoc_uart_drv, port); 1457 1435 if (sirfport->rx_dma_chan) { 1458 1436 int i;
+4
drivers/tty/serial/sirfsoc_uart.h
··· 417 417 418 418 struct uart_port port; 419 419 struct clk *clk; 420 + /* UART6 for BT usage in A7DA platform need multi-clock source */ 421 + bool is_bt_uart; 422 + struct clk *clk_general; 423 + struct clk *clk_noc; 420 424 /* for SiRFmarco, there are SET/CLR for UART_INT_EN */ 421 425 bool is_marco; 422 426 struct sirfsoc_uart_register *uart_reg;
+24 -12
drivers/tty/serial/sunsab.c
··· 345 345 /* port->lock is not held. */ 346 346 static unsigned int sunsab_tx_empty(struct uart_port *port) 347 347 { 348 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 348 + struct uart_sunsab_port *up = 349 + container_of(port, struct uart_sunsab_port, port); 349 350 int ret; 350 351 351 352 /* Do not need a lock for a state test like this. */ ··· 361 360 /* port->lock held by caller. */ 362 361 static void sunsab_set_mctrl(struct uart_port *port, unsigned int mctrl) 363 362 { 364 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 363 + struct uart_sunsab_port *up = 364 + container_of(port, struct uart_sunsab_port, port); 365 365 366 366 if (mctrl & TIOCM_RTS) { 367 367 up->cached_mode &= ~SAB82532_MODE_FRTS; ··· 385 383 /* port->lock is held by caller and interrupts are disabled. */ 386 384 static unsigned int sunsab_get_mctrl(struct uart_port *port) 387 385 { 388 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 386 + struct uart_sunsab_port *up = 387 + container_of(port, struct uart_sunsab_port, port); 389 388 unsigned char val; 390 389 unsigned int result; 391 390 ··· 407 404 /* port->lock held by caller. */ 408 405 static void sunsab_stop_tx(struct uart_port *port) 409 406 { 410 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 407 + struct uart_sunsab_port *up = 408 + container_of(port, struct uart_sunsab_port, port); 411 409 412 410 up->interrupt_mask1 |= SAB82532_IMR1_XPR; 413 411 writeb(up->interrupt_mask1, &up->regs->w.imr1); ··· 436 432 /* port->lock held by caller. */ 437 433 static void sunsab_start_tx(struct uart_port *port) 438 434 { 439 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 435 + struct uart_sunsab_port *up = 436 + container_of(port, struct uart_sunsab_port, port); 440 437 struct circ_buf *xmit = &up->port.state->xmit; 441 438 int i; 442 439 ··· 470 465 /* port->lock is not held. */ 471 466 static void sunsab_send_xchar(struct uart_port *port, char ch) 472 467 { 473 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 468 + struct uart_sunsab_port *up = 469 + container_of(port, struct uart_sunsab_port, port); 474 470 unsigned long flags; 475 471 476 472 if (ch == __DISABLED_CHAR) ··· 488 482 /* port->lock held by caller. */ 489 483 static void sunsab_stop_rx(struct uart_port *port) 490 484 { 491 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 485 + struct uart_sunsab_port *up = 486 + container_of(port, struct uart_sunsab_port, port); 492 487 493 488 up->interrupt_mask0 |= SAB82532_IMR0_TCD; 494 489 writeb(up->interrupt_mask1, &up->regs->w.imr0); ··· 498 491 /* port->lock is not held. */ 499 492 static void sunsab_break_ctl(struct uart_port *port, int break_state) 500 493 { 501 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 494 + struct uart_sunsab_port *up = 495 + container_of(port, struct uart_sunsab_port, port); 502 496 unsigned long flags; 503 497 unsigned char val; 504 498 ··· 522 514 /* port->lock is not held. */ 523 515 static int sunsab_startup(struct uart_port *port) 524 516 { 525 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 517 + struct uart_sunsab_port *up = 518 + container_of(port, struct uart_sunsab_port, port); 526 519 unsigned long flags; 527 520 unsigned char tmp; 528 521 int err = request_irq(up->port.irq, sunsab_interrupt, ··· 594 585 /* port->lock is not held. */ 595 586 static void sunsab_shutdown(struct uart_port *port) 596 587 { 597 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 588 + struct uart_sunsab_port *up = 589 + container_of(port, struct uart_sunsab_port, port); 598 590 unsigned long flags; 599 591 600 592 spin_lock_irqsave(&up->port.lock, flags); ··· 781 771 static void sunsab_set_termios(struct uart_port *port, struct ktermios *termios, 782 772 struct ktermios *old) 783 773 { 784 - struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 774 + struct uart_sunsab_port *up = 775 + container_of(port, struct uart_sunsab_port, port); 785 776 unsigned long flags; 786 777 unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000); 787 778 unsigned int quot = uart_get_divisor(port, baud); ··· 851 840 852 841 static void sunsab_console_putchar(struct uart_port *port, int c) 853 842 { 854 - struct uart_sunsab_port *up = (struct uart_sunsab_port *)port; 843 + struct uart_sunsab_port *up = 844 + container_of(port, struct uart_sunsab_port, port); 855 845 856 846 sunsab_tec_wait(up); 857 847 writeb(c, &up->regs->w.tic);
+26 -13
drivers/tty/serial/sunsu.c
··· 264 264 265 265 static void sunsu_stop_tx(struct uart_port *port) 266 266 { 267 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 267 + struct uart_sunsu_port *up = 268 + container_of(port, struct uart_sunsu_port, port); 268 269 269 270 __stop_tx(up); 270 271 ··· 280 279 281 280 static void sunsu_start_tx(struct uart_port *port) 282 281 { 283 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 282 + struct uart_sunsu_port *up = 283 + container_of(port, struct uart_sunsu_port, port); 284 284 285 285 if (!(up->ier & UART_IER_THRI)) { 286 286 up->ier |= UART_IER_THRI; ··· 299 297 300 298 static void sunsu_stop_rx(struct uart_port *port) 301 299 { 302 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 300 + struct uart_sunsu_port *up = 301 + container_of(port, struct uart_sunsu_port, port); 303 302 304 303 up->ier &= ~UART_IER_RLSI; 305 304 up->port.read_status_mask &= ~UART_LSR_DR; ··· 309 306 310 307 static void sunsu_enable_ms(struct uart_port *port) 311 308 { 312 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 309 + struct uart_sunsu_port *up = 310 + container_of(port, struct uart_sunsu_port, port); 313 311 unsigned long flags; 314 312 315 313 spin_lock_irqsave(&up->port.lock, flags); ··· 547 543 548 544 static unsigned int sunsu_tx_empty(struct uart_port *port) 549 545 { 550 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 546 + struct uart_sunsu_port *up = 547 + container_of(port, struct uart_sunsu_port, port); 551 548 unsigned long flags; 552 549 unsigned int ret; 553 550 ··· 561 556 562 557 static unsigned int sunsu_get_mctrl(struct uart_port *port) 563 558 { 564 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 559 + struct uart_sunsu_port *up = 560 + container_of(port, struct uart_sunsu_port, port); 565 561 unsigned char status; 566 562 unsigned int ret; 567 563 ··· 582 576 583 577 static void sunsu_set_mctrl(struct uart_port *port, unsigned int mctrl) 584 578 { 585 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 579 + struct uart_sunsu_port *up = 580 + container_of(port, struct uart_sunsu_port, port); 586 581 unsigned char mcr = 0; 587 582 588 583 if (mctrl & TIOCM_RTS) ··· 602 595 603 596 static void sunsu_break_ctl(struct uart_port *port, int break_state) 604 597 { 605 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 598 + struct uart_sunsu_port *up = 599 + container_of(port, struct uart_sunsu_port, port); 606 600 unsigned long flags; 607 601 608 602 spin_lock_irqsave(&up->port.lock, flags); ··· 617 609 618 610 static int sunsu_startup(struct uart_port *port) 619 611 { 620 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 612 + struct uart_sunsu_port *up = 613 + container_of(port, struct uart_sunsu_port, port); 621 614 unsigned long flags; 622 615 int retval; 623 616 ··· 728 719 729 720 static void sunsu_shutdown(struct uart_port *port) 730 721 { 731 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 722 + struct uart_sunsu_port *up = 723 + container_of(port, struct uart_sunsu_port, port); 732 724 unsigned long flags; 733 725 734 726 /* ··· 777 767 sunsu_change_speed(struct uart_port *port, unsigned int cflag, 778 768 unsigned int iflag, unsigned int quot) 779 769 { 780 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 770 + struct uart_sunsu_port *up = 771 + container_of(port, struct uart_sunsu_port, port); 781 772 unsigned char cval, fcr = 0; 782 773 unsigned long flags; 783 774 ··· 929 918 930 919 static void sunsu_config_port(struct uart_port *port, int flags) 931 920 { 932 - struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 921 + struct uart_sunsu_port *up = 922 + container_of(port, struct uart_sunsu_port, port); 933 923 934 924 if (flags & UART_CONFIG_TYPE) { 935 925 /* ··· 1289 1277 1290 1278 static void sunsu_console_putchar(struct uart_port *port, int ch) 1291 1279 { 1292 - struct uart_sunsu_port *up = (struct uart_sunsu_port *)port; 1280 + struct uart_sunsu_port *up = 1281 + container_of(port, struct uart_sunsu_port, port); 1293 1282 1294 1283 wait_for_xmitr(up); 1295 1284 serial_out(up, UART_TX, ch);
+16 -8
drivers/tty/serial/sunzilog.c
··· 644 644 /* The port lock is held and interrupts are disabled. */ 645 645 static void sunzilog_set_mctrl(struct uart_port *port, unsigned int mctrl) 646 646 { 647 - struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port; 647 + struct uart_sunzilog_port *up = 648 + container_of(port, struct uart_sunzilog_port, port); 648 649 struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port); 649 650 unsigned char set_bits, clear_bits; 650 651 ··· 669 668 /* The port lock is held and interrupts are disabled. */ 670 669 static void sunzilog_stop_tx(struct uart_port *port) 671 670 { 672 - struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port; 671 + struct uart_sunzilog_port *up = 672 + container_of(port, struct uart_sunzilog_port, port); 673 673 674 674 up->flags |= SUNZILOG_FLAG_TX_STOPPED; 675 675 } ··· 678 676 /* The port lock is held and interrupts are disabled. */ 679 677 static void sunzilog_start_tx(struct uart_port *port) 680 678 { 681 - struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port; 679 + struct uart_sunzilog_port *up = 680 + container_of(port, struct uart_sunzilog_port, port); 682 681 struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port); 683 682 unsigned char status; 684 683 ··· 739 736 /* The port lock is held. */ 740 737 static void sunzilog_enable_ms(struct uart_port *port) 741 738 { 742 - struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port; 739 + struct uart_sunzilog_port *up = 740 + container_of(port, struct uart_sunzilog_port, port); 743 741 struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port); 744 742 unsigned char new_reg; 745 743 ··· 756 752 /* The port lock is not held. */ 757 753 static void sunzilog_break_ctl(struct uart_port *port, int break_state) 758 754 { 759 - struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port; 755 + struct uart_sunzilog_port *up = 756 + container_of(port, struct uart_sunzilog_port, port); 760 757 struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(port); 761 758 unsigned char set_bits, clear_bits, new_reg; 762 759 unsigned long flags; ··· 943 938 sunzilog_set_termios(struct uart_port *port, struct ktermios *termios, 944 939 struct ktermios *old) 945 940 { 946 - struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port; 941 + struct uart_sunzilog_port *up = 942 + container_of(port, struct uart_sunzilog_port, port); 947 943 unsigned long flags; 948 944 int baud, brg; 949 945 ··· 1004 998 static int sunzilog_get_poll_char(struct uart_port *port) 1005 999 { 1006 1000 unsigned char ch, r1; 1007 - struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port; 1001 + struct uart_sunzilog_port *up = 1002 + container_of(port, struct uart_sunzilog_port, port); 1008 1003 struct zilog_channel __iomem *channel 1009 1004 = ZILOG_CHANNEL_FROM_PORT(&up->port); 1010 1005 ··· 1039 1032 static void sunzilog_put_poll_char(struct uart_port *port, 1040 1033 unsigned char ch) 1041 1034 { 1042 - struct uart_sunzilog_port *up = (struct uart_sunzilog_port *)port; 1035 + struct uart_sunzilog_port *up = 1036 + container_of(port, struct uart_sunzilog_port, port); 1043 1037 1044 1038 sunzilog_putchar(&up->port, ch); 1045 1039 }
+2
drivers/tty/serial/timbuart.c
··· 273 273 dev_dbg(port->dev, "%s\n", __func__); 274 274 free_irq(port->irq, uart); 275 275 iowrite32(0, port->membase + TIMBUART_IER); 276 + 277 + timbuart_flush_buffer(port); 276 278 } 277 279 278 280 static int get_bindex(int baud)
+21 -1
drivers/tty/serial/xilinx_uartps.c
··· 133 133 #define CDNS_UART_IXR_BRK 0x80000000 134 134 135 135 /* 136 + * Modem Control register: 137 + * The read/write Modem Control register controls the interface with the modem 138 + * or data set, or a peripheral device emulating a modem. 139 + */ 140 + #define CDNS_UART_MODEMCR_FCM 0x00000020 /* Automatic flow control mode */ 141 + #define CDNS_UART_MODEMCR_RTS 0x00000002 /* Request to send output control */ 142 + #define CDNS_UART_MODEMCR_DTR 0x00000001 /* Data Terminal Ready */ 143 + 144 + /* 136 145 * Channel Status Register: 137 146 * The channel status register (CSR) is provided to enable the control logic 138 147 * to monitor the status of bits in the channel interrupt status register, ··· 924 915 925 916 static void cdns_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) 926 917 { 927 - /* N/A */ 918 + u32 val; 919 + 920 + val = cdns_uart_readl(CDNS_UART_MODEMCR_OFFSET); 921 + 922 + val &= ~(CDNS_UART_MODEMCR_RTS | CDNS_UART_MODEMCR_DTR); 923 + 924 + if (mctrl & TIOCM_RTS) 925 + val |= CDNS_UART_MODEMCR_RTS; 926 + if (mctrl & TIOCM_DTR) 927 + val |= CDNS_UART_MODEMCR_DTR; 928 + 929 + cdns_uart_writel(val, CDNS_UART_MODEMCR_OFFSET); 928 930 } 929 931 930 932 #ifdef CONFIG_CONSOLE_POLL
+8 -2
drivers/tty/tty_buffer.c
··· 202 202 /** 203 203 * tty_buffer_flush - flush full tty buffers 204 204 * @tty: tty to flush 205 + * @ld: optional ldisc ptr (must be referenced) 205 206 * 206 - * flush all the buffers containing receive data. 207 + * flush all the buffers containing receive data. If ld != NULL, 208 + * flush the ldisc input buffer. 207 209 * 208 210 * Locking: takes buffer lock to ensure single-threaded flip buffer 209 211 * 'consumer' 210 212 */ 211 213 212 - void tty_buffer_flush(struct tty_struct *tty) 214 + void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld) 213 215 { 214 216 struct tty_port *port = tty->port; 215 217 struct tty_bufhead *buf = &port->buf; ··· 225 223 buf->head = next; 226 224 } 227 225 buf->head->read = buf->head->commit; 226 + 227 + if (ld && ld->ops->flush_buffer) 228 + ld->ops->flush_buffer(tty); 229 + 228 230 atomic_dec(&buf->priority); 229 231 mutex_unlock(&buf->lock); 230 232 }
+228 -222
drivers/tty/tty_io.c
··· 153 153 static int __tty_fasync(int fd, struct file *filp, int on); 154 154 static int tty_fasync(int fd, struct file *filp, int on); 155 155 static void release_tty(struct tty_struct *tty, int idx); 156 - static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); 157 - static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); 158 156 159 157 /** 160 158 * free_tty_struct - free a disused tty ··· 167 169 { 168 170 if (!tty) 169 171 return; 170 - if (tty->dev) 171 - put_device(tty->dev); 172 + put_device(tty->dev); 172 173 kfree(tty->write_buf); 173 174 tty->magic = 0xDEADDEAD; 174 175 kfree(tty); ··· 274 277 return 0; 275 278 } 276 279 280 + /* Caller must hold tty_lock */ 277 281 static int check_tty_count(struct tty_struct *tty, const char *routine) 278 282 { 279 283 #ifdef CHECK_TTY_COUNT ··· 490 492 static DEFINE_SPINLOCK(redirect_lock); 491 493 static struct file *redirect; 492 494 495 + 496 + void proc_clear_tty(struct task_struct *p) 497 + { 498 + unsigned long flags; 499 + struct tty_struct *tty; 500 + spin_lock_irqsave(&p->sighand->siglock, flags); 501 + tty = p->signal->tty; 502 + p->signal->tty = NULL; 503 + spin_unlock_irqrestore(&p->sighand->siglock, flags); 504 + tty_kref_put(tty); 505 + } 506 + 507 + /** 508 + * proc_set_tty - set the controlling terminal 509 + * 510 + * Only callable by the session leader and only if it does not already have 511 + * a controlling terminal. 512 + * 513 + * Caller must hold: tty_lock() 514 + * a readlock on tasklist_lock 515 + * sighand lock 516 + */ 517 + static void __proc_set_tty(struct tty_struct *tty) 518 + { 519 + unsigned long flags; 520 + 521 + spin_lock_irqsave(&tty->ctrl_lock, flags); 522 + /* 523 + * The session and fg pgrp references will be non-NULL if 524 + * tiocsctty() is stealing the controlling tty 525 + */ 526 + put_pid(tty->session); 527 + put_pid(tty->pgrp); 528 + tty->pgrp = get_pid(task_pgrp(current)); 529 + spin_unlock_irqrestore(&tty->ctrl_lock, flags); 530 + tty->session = get_pid(task_session(current)); 531 + if (current->signal->tty) { 532 + printk(KERN_DEBUG "tty not NULL!!\n"); 533 + tty_kref_put(current->signal->tty); 534 + } 535 + put_pid(current->signal->tty_old_pgrp); 536 + current->signal->tty = tty_kref_get(tty); 537 + current->signal->tty_old_pgrp = NULL; 538 + } 539 + 540 + static void proc_set_tty(struct tty_struct *tty) 541 + { 542 + spin_lock_irq(&current->sighand->siglock); 543 + __proc_set_tty(tty); 544 + spin_unlock_irq(&current->sighand->siglock); 545 + } 546 + 547 + struct tty_struct *get_current_tty(void) 548 + { 549 + struct tty_struct *tty; 550 + unsigned long flags; 551 + 552 + spin_lock_irqsave(&current->sighand->siglock, flags); 553 + tty = tty_kref_get(current->signal->tty); 554 + spin_unlock_irqrestore(&current->sighand->siglock, flags); 555 + return tty; 556 + } 557 + EXPORT_SYMBOL_GPL(get_current_tty); 558 + 559 + static void session_clear_tty(struct pid *session) 560 + { 561 + struct task_struct *p; 562 + do_each_pid_task(session, PIDTYPE_SID, p) { 563 + proc_clear_tty(p); 564 + } while_each_pid_task(session, PIDTYPE_SID, p); 565 + } 566 + 493 567 /** 494 568 * tty_wakeup - request more data 495 569 * @tty: terminal ··· 690 620 return; 691 621 } 692 622 693 - /* some functions below drop BTM, so we need this bit */ 694 - set_bit(TTY_HUPPING, &tty->flags); 695 - 696 623 /* inuse_filps is protected by the single tty lock, 697 624 this really needs to change if we want to flush the 698 625 workqueue with the lock held */ ··· 714 647 while (refs--) 715 648 tty_kref_put(tty); 716 649 717 - /* 718 - * it drops BTM and thus races with reopen 719 - * we protect the race by TTY_HUPPING 720 - */ 721 650 tty_ldisc_hangup(tty); 722 651 723 652 spin_lock_irq(&tty->ctrl_lock); ··· 745 682 * can't yet guarantee all that. 746 683 */ 747 684 set_bit(TTY_HUPPED, &tty->flags); 748 - clear_bit(TTY_HUPPING, &tty->flags); 749 - 750 685 tty_unlock(tty); 751 686 752 687 if (f) ··· 852 791 } 853 792 854 793 EXPORT_SYMBOL(tty_hung_up_p); 855 - 856 - static void session_clear_tty(struct pid *session) 857 - { 858 - struct task_struct *p; 859 - do_each_pid_task(session, PIDTYPE_SID, p) { 860 - proc_clear_tty(p); 861 - } while_each_pid_task(session, PIDTYPE_SID, p); 862 - } 863 794 864 795 /** 865 796 * disassociate_ctty - disconnect controlling tty ··· 980 927 return; 981 928 tty->stopped = 1; 982 929 if (tty->ops->stop) 983 - (tty->ops->stop)(tty); 930 + tty->ops->stop(tty); 984 931 } 985 932 986 933 void stop_tty(struct tty_struct *tty) ··· 1011 958 return; 1012 959 tty->stopped = 0; 1013 960 if (tty->ops->start) 1014 - (tty->ops->start)(tty); 961 + tty->ops->start(tty); 1015 962 tty_wakeup(tty); 1016 963 } 1017 964 ··· 1065 1012 situation */ 1066 1013 ld = tty_ldisc_ref_wait(tty); 1067 1014 if (ld->ops->read) 1068 - i = (ld->ops->read)(tty, file, buf, count); 1015 + i = ld->ops->read(tty, file, buf, count); 1069 1016 else 1070 1017 i = -EIO; 1071 1018 tty_ldisc_deref(ld); ··· 1077 1024 } 1078 1025 1079 1026 static void tty_write_unlock(struct tty_struct *tty) 1080 - __releases(&tty->atomic_write_lock) 1081 1027 { 1082 1028 mutex_unlock(&tty->atomic_write_lock); 1083 1029 wake_up_interruptible_poll(&tty->write_wait, POLLOUT); 1084 1030 } 1085 1031 1086 1032 static int tty_write_lock(struct tty_struct *tty, int ndelay) 1087 - __acquires(&tty->atomic_write_lock) 1088 1033 { 1089 1034 if (!mutex_trylock(&tty->atomic_write_lock)) { 1090 1035 if (ndelay) ··· 1197 1146 if (tty) { 1198 1147 mutex_lock(&tty->atomic_write_lock); 1199 1148 tty_lock(tty); 1200 - if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { 1149 + if (tty->ops->write && tty->count > 0) { 1201 1150 tty_unlock(tty); 1202 1151 tty->ops->write(tty, msg, strlen(msg)); 1203 1152 } else ··· 1344 1293 * @driver: the driver for the tty 1345 1294 * @idx: the minor number 1346 1295 * 1347 - * Return the tty, if found or ERR_PTR() otherwise. 1296 + * Return the tty, if found. If not found, return NULL or ERR_PTR() if the 1297 + * driver lookup() method returns an error. 1348 1298 * 1349 - * Locking: tty_mutex must be held. If tty is found, the mutex must 1350 - * be held until the 'fast-open' is also done. Will change once we 1351 - * have refcounting in the driver and per driver locking 1299 + * Locking: tty_mutex must be held. If the tty is found, bump the tty kref. 1352 1300 */ 1353 1301 static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, 1354 1302 struct inode *inode, int idx) 1355 1303 { 1356 - if (driver->ops->lookup) 1357 - return driver->ops->lookup(driver, inode, idx); 1304 + struct tty_struct *tty; 1358 1305 1359 - return driver->ttys[idx]; 1306 + if (driver->ops->lookup) 1307 + tty = driver->ops->lookup(driver, inode, idx); 1308 + else 1309 + tty = driver->ttys[idx]; 1310 + 1311 + if (!IS_ERR(tty)) 1312 + tty_kref_get(tty); 1313 + return tty; 1360 1314 } 1361 1315 1362 1316 /** ··· 1449 1393 * @tty - the tty to open 1450 1394 * 1451 1395 * Return 0 on success, -errno on error. 1396 + * Re-opens on master ptys are not allowed and return -EIO. 1452 1397 * 1453 - * Locking: tty_mutex must be held from the time the tty was found 1454 - * till this open completes. 1398 + * Locking: Caller must hold tty_lock 1455 1399 */ 1456 1400 static int tty_reopen(struct tty_struct *tty) 1457 1401 { 1458 1402 struct tty_driver *driver = tty->driver; 1459 1403 1460 - if (test_bit(TTY_CLOSING, &tty->flags) || 1461 - test_bit(TTY_HUPPING, &tty->flags)) 1404 + if (!tty->count) 1462 1405 return -EIO; 1463 1406 1464 1407 if (driver->type == TTY_DRIVER_TYPE_PTY && 1465 - driver->subtype == PTY_TYPE_MASTER) { 1466 - /* 1467 - * special case for PTY masters: only one open permitted, 1468 - * and the slave side open count is incremented as well. 1469 - */ 1470 - if (tty->count) 1471 - return -EIO; 1408 + driver->subtype == PTY_TYPE_MASTER) 1409 + return -EIO; 1472 1410 1473 - tty->link->count++; 1474 - } 1475 1411 tty->count++; 1476 1412 1477 1413 WARN_ON(!tty->ldisc); ··· 1583 1535 EXPORT_SYMBOL(tty_free_termios); 1584 1536 1585 1537 /** 1586 - * tty_flush_works - flush all works of a tty 1587 - * @tty: tty device to flush works for 1538 + * tty_flush_works - flush all works of a tty/pty pair 1539 + * @tty: tty device to flush works for (or either end of a pty pair) 1588 1540 * 1589 - * Sync flush all works belonging to @tty. 1541 + * Sync flush all works belonging to @tty (and the 'other' tty). 1590 1542 */ 1591 1543 static void tty_flush_works(struct tty_struct *tty) 1592 1544 { 1593 1545 flush_work(&tty->SAK_work); 1594 1546 flush_work(&tty->hangup_work); 1547 + if (tty->link) { 1548 + flush_work(&tty->link->SAK_work); 1549 + flush_work(&tty->link->hangup_work); 1550 + } 1595 1551 } 1596 1552 1597 1553 /** ··· 1687 1635 tty->link->port->itty = NULL; 1688 1636 cancel_work_sync(&tty->port->buf.work); 1689 1637 1690 - if (tty->link) 1691 - tty_kref_put(tty->link); 1638 + tty_kref_put(tty->link); 1692 1639 tty_kref_put(tty); 1693 1640 } 1694 1641 ··· 1700 1649 * Performs some paranoid checking before true release of the @tty. 1701 1650 * This is a no-op unless TTY_PARANOIA_CHECK is defined. 1702 1651 */ 1703 - static int tty_release_checks(struct tty_struct *tty, struct tty_struct *o_tty, 1704 - int idx) 1652 + static int tty_release_checks(struct tty_struct *tty, int idx) 1705 1653 { 1706 1654 #ifdef TTY_PARANOIA_CHECK 1707 1655 if (idx < 0 || idx >= tty->driver->num) { ··· 1719 1669 return -1; 1720 1670 } 1721 1671 if (tty->driver->other) { 1672 + struct tty_struct *o_tty = tty->link; 1673 + 1722 1674 if (o_tty != tty->driver->other->ttys[idx]) { 1723 1675 printk(KERN_DEBUG "%s: other->table[%d] not o_tty for (%s)\n", 1724 1676 __func__, idx, tty->name); ··· 1757 1705 int tty_release(struct inode *inode, struct file *filp) 1758 1706 { 1759 1707 struct tty_struct *tty = file_tty(filp); 1760 - struct tty_struct *o_tty; 1761 - int pty_master, tty_closing, o_tty_closing, do_sleep; 1708 + struct tty_struct *o_tty = NULL; 1709 + int do_sleep, final; 1762 1710 int idx; 1763 1711 char buf[64]; 1764 1712 long timeout = 0; ··· 1773 1721 __tty_fasync(-1, filp, 0); 1774 1722 1775 1723 idx = tty->index; 1776 - pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1777 - tty->driver->subtype == PTY_TYPE_MASTER); 1778 - /* Review: parallel close */ 1779 - o_tty = tty->link; 1724 + if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1725 + tty->driver->subtype == PTY_TYPE_MASTER) 1726 + o_tty = tty->link; 1780 1727 1781 - if (tty_release_checks(tty, o_tty, idx)) { 1728 + if (tty_release_checks(tty, idx)) { 1782 1729 tty_unlock(tty); 1783 1730 return 0; 1784 1731 } ··· 1790 1739 if (tty->ops->close) 1791 1740 tty->ops->close(tty, filp); 1792 1741 1793 - tty_unlock(tty); 1742 + /* If tty is pty master, lock the slave pty (stable lock order) */ 1743 + tty_lock_slave(o_tty); 1744 + 1794 1745 /* 1795 1746 * Sanity check: if tty->count is going to zero, there shouldn't be 1796 1747 * any waiters on tty->read_wait or tty->write_wait. We test the ··· 1803 1750 * The test for the o_tty closing is necessary, since the master and 1804 1751 * slave sides may close in any order. If the slave side closes out 1805 1752 * first, its count will be one, since the master side holds an open. 1806 - * Thus this test wouldn't be triggered at the time the slave closes, 1753 + * Thus this test wouldn't be triggered at the time the slave closed, 1807 1754 * so we do it now. 1808 - * 1809 - * Note that it's possible for the tty to be opened again while we're 1810 - * flushing out waiters. By recalculating the closing flags before 1811 - * each iteration we avoid any problems. 1812 1755 */ 1813 1756 while (1) { 1814 - /* Guard against races with tty->count changes elsewhere and 1815 - opens on /dev/tty */ 1816 - 1817 - mutex_lock(&tty_mutex); 1818 - tty_lock_pair(tty, o_tty); 1819 - tty_closing = tty->count <= 1; 1820 - o_tty_closing = o_tty && 1821 - (o_tty->count <= (pty_master ? 1 : 0)); 1822 1757 do_sleep = 0; 1823 1758 1824 - if (tty_closing) { 1759 + if (tty->count <= 1) { 1825 1760 if (waitqueue_active(&tty->read_wait)) { 1826 1761 wake_up_poll(&tty->read_wait, POLLIN); 1827 1762 do_sleep++; ··· 1819 1778 do_sleep++; 1820 1779 } 1821 1780 } 1822 - if (o_tty_closing) { 1781 + if (o_tty && o_tty->count <= 1) { 1823 1782 if (waitqueue_active(&o_tty->read_wait)) { 1824 1783 wake_up_poll(&o_tty->read_wait, POLLIN); 1825 1784 do_sleep++; ··· 1837 1796 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", 1838 1797 __func__, tty_name(tty, buf)); 1839 1798 } 1840 - tty_unlock_pair(tty, o_tty); 1841 - mutex_unlock(&tty_mutex); 1842 1799 schedule_timeout_killable(timeout); 1843 1800 if (timeout < 120 * HZ) 1844 1801 timeout = 2 * timeout + 1; ··· 1844 1805 timeout = MAX_SCHEDULE_TIMEOUT; 1845 1806 } 1846 1807 1847 - /* 1848 - * The closing flags are now consistent with the open counts on 1849 - * both sides, and we've completed the last operation that could 1850 - * block, so it's safe to proceed with closing. 1851 - * 1852 - * We must *not* drop the tty_mutex until we ensure that a further 1853 - * entry into tty_open can not pick up this tty. 1854 - */ 1855 - if (pty_master) { 1808 + if (o_tty) { 1856 1809 if (--o_tty->count < 0) { 1857 1810 printk(KERN_WARNING "%s: bad pty slave count (%d) for %s\n", 1858 1811 __func__, o_tty->count, tty_name(o_tty, buf)); ··· 1871 1840 /* 1872 1841 * Perform some housekeeping before deciding whether to return. 1873 1842 * 1874 - * Set the TTY_CLOSING flag if this was the last open. In the 1875 - * case of a pty we may have to wait around for the other side 1876 - * to close, and TTY_CLOSING makes sure we can't be reopened. 1877 - */ 1878 - if (tty_closing) 1879 - set_bit(TTY_CLOSING, &tty->flags); 1880 - if (o_tty_closing) 1881 - set_bit(TTY_CLOSING, &o_tty->flags); 1882 - 1883 - /* 1884 1843 * If _either_ side is closing, make sure there aren't any 1885 1844 * processes that still think tty or o_tty is their controlling 1886 1845 * tty. 1887 1846 */ 1888 - if (tty_closing || o_tty_closing) { 1847 + if (!tty->count) { 1889 1848 read_lock(&tasklist_lock); 1890 1849 session_clear_tty(tty->session); 1891 1850 if (o_tty) ··· 1883 1862 read_unlock(&tasklist_lock); 1884 1863 } 1885 1864 1886 - mutex_unlock(&tty_mutex); 1887 - tty_unlock_pair(tty, o_tty); 1888 - /* At this point the TTY_CLOSING flag should ensure a dead tty 1865 + /* check whether both sides are closing ... */ 1866 + final = !tty->count && !(o_tty && o_tty->count); 1867 + 1868 + tty_unlock_slave(o_tty); 1869 + tty_unlock(tty); 1870 + 1871 + /* At this point, the tty->count == 0 should ensure a dead tty 1889 1872 cannot be re-opened by a racing opener */ 1890 1873 1891 - /* check whether both sides are closing ... */ 1892 - if (!tty_closing || (o_tty && !o_tty_closing)) 1874 + if (!final) 1893 1875 return 0; 1894 1876 1895 1877 #ifdef TTY_DEBUG_HANGUP ··· 1901 1877 /* 1902 1878 * Ask the line discipline code to release its structures 1903 1879 */ 1904 - tty_ldisc_release(tty, o_tty); 1880 + tty_ldisc_release(tty); 1905 1881 1906 1882 /* Wait for pending work before tty destruction commmences */ 1907 1883 tty_flush_works(tty); 1908 - if (o_tty) 1909 - tty_flush_works(o_tty); 1910 1884 1911 1885 #ifdef TTY_DEBUG_HANGUP 1912 1886 printk(KERN_DEBUG "%s: %s: freeing structure...\n", __func__, tty_name(tty, buf)); ··· 1923 1901 } 1924 1902 1925 1903 /** 1926 - * tty_open_current_tty - get tty of current task for open 1904 + * tty_open_current_tty - get locked tty of current task 1927 1905 * @device: device number 1928 1906 * @filp: file pointer to tty 1929 - * @return: tty of the current task iff @device is /dev/tty 1907 + * @return: locked tty of the current task iff @device is /dev/tty 1908 + * 1909 + * Performs a re-open of the current task's controlling tty. 1930 1910 * 1931 1911 * We cannot return driver and index like for the other nodes because 1932 1912 * devpts will not work then. It expects inodes to be from devpts FS. 1933 - * 1934 - * We need to move to returning a refcounted object from all the lookup 1935 - * paths including this one. 1936 1913 */ 1937 1914 static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp) 1938 1915 { 1939 1916 struct tty_struct *tty; 1917 + int retval; 1940 1918 1941 1919 if (device != MKDEV(TTYAUX_MAJOR, 0)) 1942 1920 return NULL; ··· 1947 1925 1948 1926 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */ 1949 1927 /* noctty = 1; */ 1950 - tty_kref_put(tty); 1951 - /* FIXME: we put a reference and return a TTY! */ 1952 - /* This is only safe because the caller holds tty_mutex */ 1928 + tty_lock(tty); 1929 + tty_kref_put(tty); /* safe to drop the kref now */ 1930 + 1931 + retval = tty_reopen(tty); 1932 + if (retval < 0) { 1933 + tty_unlock(tty); 1934 + tty = ERR_PTR(retval); 1935 + } 1953 1936 return tty; 1954 1937 } 1955 1938 ··· 2052 2025 index = -1; 2053 2026 retval = 0; 2054 2027 2055 - mutex_lock(&tty_mutex); 2056 - /* This is protected by the tty_mutex */ 2057 2028 tty = tty_open_current_tty(device, filp); 2058 - if (IS_ERR(tty)) { 2059 - retval = PTR_ERR(tty); 2060 - goto err_unlock; 2061 - } else if (!tty) { 2029 + if (!tty) { 2030 + mutex_lock(&tty_mutex); 2062 2031 driver = tty_lookup_driver(device, filp, &noctty, &index); 2063 2032 if (IS_ERR(driver)) { 2064 2033 retval = PTR_ERR(driver); ··· 2067 2044 retval = PTR_ERR(tty); 2068 2045 goto err_unlock; 2069 2046 } 2047 + 2048 + if (tty) { 2049 + mutex_unlock(&tty_mutex); 2050 + tty_lock(tty); 2051 + /* safe to drop the kref from tty_driver_lookup_tty() */ 2052 + tty_kref_put(tty); 2053 + retval = tty_reopen(tty); 2054 + if (retval < 0) { 2055 + tty_unlock(tty); 2056 + tty = ERR_PTR(retval); 2057 + } 2058 + } else { /* Returns with the tty_lock held for now */ 2059 + tty = tty_init_dev(driver, index); 2060 + mutex_unlock(&tty_mutex); 2061 + } 2062 + 2063 + tty_driver_kref_put(driver); 2070 2064 } 2071 2065 2072 - if (tty) { 2073 - tty_lock(tty); 2074 - retval = tty_reopen(tty); 2075 - if (retval < 0) { 2076 - tty_unlock(tty); 2077 - tty = ERR_PTR(retval); 2078 - } 2079 - } else /* Returns with the tty_lock held for now */ 2080 - tty = tty_init_dev(driver, index); 2081 - 2082 - mutex_unlock(&tty_mutex); 2083 - if (driver) 2084 - tty_driver_kref_put(driver); 2085 2066 if (IS_ERR(tty)) { 2086 2067 retval = PTR_ERR(tty); 2087 2068 goto err_file; ··· 2127 2100 /* 2128 2101 * Need to reset f_op in case a hangup happened. 2129 2102 */ 2130 - if (filp->f_op == &hung_up_tty_fops) 2103 + if (tty_hung_up_p(filp)) 2131 2104 filp->f_op = &tty_fops; 2132 2105 goto retry_open; 2133 2106 } 2134 2107 clear_bit(TTY_HUPPED, &tty->flags); 2135 - tty_unlock(tty); 2136 2108 2137 2109 2138 - mutex_lock(&tty_mutex); 2139 - tty_lock(tty); 2110 + read_lock(&tasklist_lock); 2140 2111 spin_lock_irq(&current->sighand->siglock); 2141 2112 if (!noctty && 2142 2113 current->signal->leader && 2143 2114 !current->signal->tty && 2144 2115 tty->session == NULL) 2145 - __proc_set_tty(current, tty); 2116 + __proc_set_tty(tty); 2146 2117 spin_unlock_irq(&current->sighand->siglock); 2118 + read_unlock(&tasklist_lock); 2147 2119 tty_unlock(tty); 2148 - mutex_unlock(&tty_mutex); 2149 2120 return 0; 2150 2121 err_unlock: 2151 2122 mutex_unlock(&tty_mutex); ··· 2180 2155 2181 2156 ld = tty_ldisc_ref_wait(tty); 2182 2157 if (ld->ops->poll) 2183 - ret = (ld->ops->poll)(tty, filp, wait); 2158 + ret = ld->ops->poll(tty, filp, wait); 2184 2159 tty_ldisc_deref(ld); 2185 2160 return ret; 2186 2161 } ··· 2308 2283 int tty_do_resize(struct tty_struct *tty, struct winsize *ws) 2309 2284 { 2310 2285 struct pid *pgrp; 2311 - unsigned long flags; 2312 2286 2313 2287 /* Lock the tty */ 2314 2288 mutex_lock(&tty->winsize_mutex); 2315 2289 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) 2316 2290 goto done; 2317 - /* Get the PID values and reference them so we can 2318 - avoid holding the tty ctrl lock while sending signals */ 2319 - spin_lock_irqsave(&tty->ctrl_lock, flags); 2320 - pgrp = get_pid(tty->pgrp); 2321 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 2322 2291 2292 + /* Signal the foreground process group */ 2293 + pgrp = tty_get_pgrp(tty); 2323 2294 if (pgrp) 2324 2295 kill_pgrp(pgrp, SIGWINCH, 1); 2325 2296 put_pid(pgrp); ··· 2424 2403 * leader to set this tty as the controlling tty for the session. 2425 2404 * 2426 2405 * Locking: 2427 - * Takes tty_mutex() to protect tty instance 2406 + * Takes tty_lock() to serialize proc_set_tty() for this tty 2428 2407 * Takes tasklist_lock internally to walk sessions 2429 2408 * Takes ->siglock() when updating signal->tty 2430 2409 */ ··· 2432 2411 static int tiocsctty(struct tty_struct *tty, int arg) 2433 2412 { 2434 2413 int ret = 0; 2435 - if (current->signal->leader && (task_session(current) == tty->session)) 2436 - return ret; 2437 2414 2438 - mutex_lock(&tty_mutex); 2415 + tty_lock(tty); 2416 + read_lock(&tasklist_lock); 2417 + 2418 + if (current->signal->leader && (task_session(current) == tty->session)) 2419 + goto unlock; 2420 + 2439 2421 /* 2440 2422 * The process must be a session leader and 2441 2423 * not have a controlling tty already. ··· 2457 2433 /* 2458 2434 * Steal it away 2459 2435 */ 2460 - read_lock(&tasklist_lock); 2461 2436 session_clear_tty(tty->session); 2462 - read_unlock(&tasklist_lock); 2463 2437 } else { 2464 2438 ret = -EPERM; 2465 2439 goto unlock; 2466 2440 } 2467 2441 } 2468 - proc_set_tty(current, tty); 2442 + proc_set_tty(tty); 2469 2443 unlock: 2470 - mutex_unlock(&tty_mutex); 2444 + read_unlock(&tasklist_lock); 2445 + tty_unlock(tty); 2471 2446 return ret; 2472 2447 } 2473 2448 ··· 2490 2467 return pgrp; 2491 2468 } 2492 2469 EXPORT_SYMBOL_GPL(tty_get_pgrp); 2470 + 2471 + /* 2472 + * This checks not only the pgrp, but falls back on the pid if no 2473 + * satisfactory pgrp is found. I dunno - gdb doesn't work correctly 2474 + * without this... 2475 + * 2476 + * The caller must hold rcu lock or the tasklist lock. 2477 + */ 2478 + static struct pid *session_of_pgrp(struct pid *pgrp) 2479 + { 2480 + struct task_struct *p; 2481 + struct pid *sid = NULL; 2482 + 2483 + p = pid_task(pgrp, PIDTYPE_PGID); 2484 + if (p == NULL) 2485 + p = pid_task(pgrp, PIDTYPE_PID); 2486 + if (p != NULL) 2487 + sid = task_session(p); 2488 + 2489 + return sid; 2490 + } 2493 2491 2494 2492 /** 2495 2493 * tiocgpgrp - get process group ··· 2758 2714 return 0; 2759 2715 } 2760 2716 2761 - struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) 2717 + static void tty_warn_deprecated_flags(struct serial_struct __user *ss) 2718 + { 2719 + static DEFINE_RATELIMIT_STATE(depr_flags, 2720 + DEFAULT_RATELIMIT_INTERVAL, 2721 + DEFAULT_RATELIMIT_BURST); 2722 + char comm[TASK_COMM_LEN]; 2723 + int flags; 2724 + 2725 + if (get_user(flags, &ss->flags)) 2726 + return; 2727 + 2728 + flags &= ASYNC_DEPRECATED; 2729 + 2730 + if (flags && __ratelimit(&depr_flags)) 2731 + pr_warning("%s: '%s' is using deprecated serial flags (with no effect): %.8x\n", 2732 + __func__, get_task_comm(comm, current), flags); 2733 + } 2734 + 2735 + /* 2736 + * if pty, return the slave side (real_tty) 2737 + * otherwise, return self 2738 + */ 2739 + static struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) 2762 2740 { 2763 2741 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 2764 2742 tty->driver->subtype == PTY_TYPE_MASTER) 2765 2743 tty = tty->link; 2766 2744 return tty; 2767 2745 } 2768 - EXPORT_SYMBOL(tty_pair_get_tty); 2769 - 2770 - struct tty_struct *tty_pair_get_pty(struct tty_struct *tty) 2771 - { 2772 - if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 2773 - tty->driver->subtype == PTY_TYPE_MASTER) 2774 - return tty; 2775 - return tty->link; 2776 - } 2777 - EXPORT_SYMBOL(tty_pair_get_pty); 2778 2746 2779 2747 /* 2780 2748 * Split this up, as gcc can choke on it otherwise.. ··· 2915 2859 case TCIFLUSH: 2916 2860 case TCIOFLUSH: 2917 2861 /* flush tty buffer and allow ldisc to process ioctl */ 2918 - tty_buffer_flush(tty); 2862 + tty_buffer_flush(tty, NULL); 2919 2863 break; 2920 2864 } 2921 2865 break; 2866 + case TIOCSSERIAL: 2867 + tty_warn_deprecated_flags(p); 2868 + break; 2922 2869 } 2923 2870 if (tty->ops->ioctl) { 2924 - retval = (tty->ops->ioctl)(tty, cmd, arg); 2871 + retval = tty->ops->ioctl(tty, cmd, arg); 2925 2872 if (retval != -ENOIOCTLCMD) 2926 2873 return retval; 2927 2874 } ··· 2951 2892 return -EINVAL; 2952 2893 2953 2894 if (tty->ops->compat_ioctl) { 2954 - retval = (tty->ops->compat_ioctl)(tty, cmd, arg); 2895 + retval = tty->ops->compat_ioctl(tty, cmd, arg); 2955 2896 if (retval != -ENOIOCTLCMD) 2956 2897 return retval; 2957 2898 } ··· 3501 3442 return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index; 3502 3443 } 3503 3444 EXPORT_SYMBOL(tty_devnum); 3504 - 3505 - void proc_clear_tty(struct task_struct *p) 3506 - { 3507 - unsigned long flags; 3508 - struct tty_struct *tty; 3509 - spin_lock_irqsave(&p->sighand->siglock, flags); 3510 - tty = p->signal->tty; 3511 - p->signal->tty = NULL; 3512 - spin_unlock_irqrestore(&p->sighand->siglock, flags); 3513 - tty_kref_put(tty); 3514 - } 3515 - 3516 - /* Called under the sighand lock */ 3517 - 3518 - static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 3519 - { 3520 - if (tty) { 3521 - unsigned long flags; 3522 - /* We should not have a session or pgrp to put here but.... */ 3523 - spin_lock_irqsave(&tty->ctrl_lock, flags); 3524 - put_pid(tty->session); 3525 - put_pid(tty->pgrp); 3526 - tty->pgrp = get_pid(task_pgrp(tsk)); 3527 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 3528 - tty->session = get_pid(task_session(tsk)); 3529 - if (tsk->signal->tty) { 3530 - printk(KERN_DEBUG "tty not NULL!!\n"); 3531 - tty_kref_put(tsk->signal->tty); 3532 - } 3533 - } 3534 - put_pid(tsk->signal->tty_old_pgrp); 3535 - tsk->signal->tty = tty_kref_get(tty); 3536 - tsk->signal->tty_old_pgrp = NULL; 3537 - } 3538 - 3539 - static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 3540 - { 3541 - spin_lock_irq(&tsk->sighand->siglock); 3542 - __proc_set_tty(tsk, tty); 3543 - spin_unlock_irq(&tsk->sighand->siglock); 3544 - } 3545 - 3546 - struct tty_struct *get_current_tty(void) 3547 - { 3548 - struct tty_struct *tty; 3549 - unsigned long flags; 3550 - 3551 - spin_lock_irqsave(&current->sighand->siglock, flags); 3552 - tty = tty_kref_get(current->signal->tty); 3553 - spin_unlock_irqrestore(&current->sighand->siglock, flags); 3554 - return tty; 3555 - } 3556 - EXPORT_SYMBOL_GPL(get_current_tty); 3557 3445 3558 3446 void tty_default_fops(struct file_operations *fops) 3559 3447 {
+6 -32
drivers/tty/tty_ioctl.c
··· 524 524 * @tty: tty to update 525 525 * @new_termios: desired new value 526 526 * 527 - * Perform updates to the termios values set on this terminal. There 528 - * is a bit of layering violation here with n_tty in terms of the 529 - * internal knowledge of this function. 527 + * Perform updates to the termios values set on this terminal. 528 + * A master pty's termios should never be set. 530 529 * 531 530 * Locking: termios_rwsem 532 531 */ ··· 534 535 { 535 536 struct ktermios old_termios; 536 537 struct tty_ldisc *ld; 537 - unsigned long flags; 538 538 539 + WARN_ON(tty->driver->type == TTY_DRIVER_TYPE_PTY && 540 + tty->driver->subtype == PTY_TYPE_MASTER); 539 541 /* 540 542 * Perform the actual termios internal changes under lock. 541 543 */ ··· 549 549 tty->termios = *new_termios; 550 550 unset_locked_termios(&tty->termios, &old_termios, &tty->termios_locked); 551 551 552 - /* See if packet mode change of state. */ 553 - if (tty->link && tty->link->packet) { 554 - int extproc = (old_termios.c_lflag & EXTPROC) | 555 - (tty->termios.c_lflag & EXTPROC); 556 - int old_flow = ((old_termios.c_iflag & IXON) && 557 - (old_termios.c_cc[VSTOP] == '\023') && 558 - (old_termios.c_cc[VSTART] == '\021')); 559 - int new_flow = (I_IXON(tty) && 560 - STOP_CHAR(tty) == '\023' && 561 - START_CHAR(tty) == '\021'); 562 - if ((old_flow != new_flow) || extproc) { 563 - spin_lock_irqsave(&tty->ctrl_lock, flags); 564 - if (old_flow != new_flow) { 565 - tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP); 566 - if (new_flow) 567 - tty->ctrl_status |= TIOCPKT_DOSTOP; 568 - else 569 - tty->ctrl_status |= TIOCPKT_NOSTOP; 570 - } 571 - if (extproc) 572 - tty->ctrl_status |= TIOCPKT_IOCTL; 573 - spin_unlock_irqrestore(&tty->ctrl_lock, flags); 574 - wake_up_interruptible(&tty->link->read_wait); 575 - } 576 - } 577 - 578 552 if (tty->ops->set_termios) 579 - (*tty->ops->set_termios)(tty, &old_termios); 553 + tty->ops->set_termios(tty, &old_termios); 580 554 else 581 555 tty_termios_copy_hw(&tty->termios, &old_termios); 582 556 583 557 ld = tty_ldisc_ref(tty); 584 558 if (ld != NULL) { 585 559 if (ld->ops->set_termios) 586 - (ld->ops->set_termios)(tty, &old_termios); 560 + ld->ops->set_termios(tty, &old_termios); 587 561 tty_ldisc_deref(ld); 588 562 } 589 563 up_write(&tty->termios_rwsem);
+56 -55
drivers/tty/tty_ldisc.c
··· 308 308 309 309 310 310 static inline int __lockfunc 311 - tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout) 311 + __tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout) 312 312 { 313 313 return ldsem_down_write(&tty->ldisc_sem, timeout); 314 314 } 315 315 316 316 static inline int __lockfunc 317 - tty_ldisc_lock_nested(struct tty_struct *tty, unsigned long timeout) 317 + __tty_ldisc_lock_nested(struct tty_struct *tty, unsigned long timeout) 318 318 { 319 319 return ldsem_down_write_nested(&tty->ldisc_sem, 320 320 LDISC_SEM_OTHER, timeout); 321 321 } 322 322 323 - static inline void tty_ldisc_unlock(struct tty_struct *tty) 323 + static inline void __tty_ldisc_unlock(struct tty_struct *tty) 324 324 { 325 325 return ldsem_up_write(&tty->ldisc_sem); 326 + } 327 + 328 + static int __lockfunc 329 + tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout) 330 + { 331 + int ret; 332 + 333 + ret = __tty_ldisc_lock(tty, timeout); 334 + if (!ret) 335 + return -EBUSY; 336 + set_bit(TTY_LDISC_HALTED, &tty->flags); 337 + return 0; 338 + } 339 + 340 + static void tty_ldisc_unlock(struct tty_struct *tty) 341 + { 342 + clear_bit(TTY_LDISC_HALTED, &tty->flags); 343 + __tty_ldisc_unlock(tty); 326 344 } 327 345 328 346 static int __lockfunc ··· 350 332 int ret; 351 333 352 334 if (tty < tty2) { 353 - ret = tty_ldisc_lock(tty, timeout); 335 + ret = __tty_ldisc_lock(tty, timeout); 354 336 if (ret) { 355 - ret = tty_ldisc_lock_nested(tty2, timeout); 337 + ret = __tty_ldisc_lock_nested(tty2, timeout); 356 338 if (!ret) 357 - tty_ldisc_unlock(tty); 339 + __tty_ldisc_unlock(tty); 358 340 } 359 341 } else { 360 342 /* if this is possible, it has lots of implications */ 361 343 WARN_ON_ONCE(tty == tty2); 362 344 if (tty2 && tty != tty2) { 363 - ret = tty_ldisc_lock(tty2, timeout); 345 + ret = __tty_ldisc_lock(tty2, timeout); 364 346 if (ret) { 365 - ret = tty_ldisc_lock_nested(tty, timeout); 347 + ret = __tty_ldisc_lock_nested(tty, timeout); 366 348 if (!ret) 367 - tty_ldisc_unlock(tty2); 349 + __tty_ldisc_unlock(tty2); 368 350 } 369 351 } else 370 - ret = tty_ldisc_lock(tty, timeout); 352 + ret = __tty_ldisc_lock(tty, timeout); 371 353 } 372 354 373 355 if (!ret) ··· 388 370 static void __lockfunc tty_ldisc_unlock_pair(struct tty_struct *tty, 389 371 struct tty_struct *tty2) 390 372 { 391 - tty_ldisc_unlock(tty); 373 + __tty_ldisc_unlock(tty); 392 374 if (tty2) 393 - tty_ldisc_unlock(tty2); 394 - } 395 - 396 - static void __lockfunc tty_ldisc_enable_pair(struct tty_struct *tty, 397 - struct tty_struct *tty2) 398 - { 399 - clear_bit(TTY_LDISC_HALTED, &tty->flags); 400 - if (tty2) 401 - clear_bit(TTY_LDISC_HALTED, &tty2->flags); 402 - 403 - tty_ldisc_unlock_pair(tty, tty2); 375 + __tty_ldisc_unlock(tty2); 404 376 } 405 377 406 378 /** 407 379 * tty_ldisc_flush - flush line discipline queue 408 380 * @tty: tty 409 381 * 410 - * Flush the line discipline queue (if any) for this tty. If there 411 - * is no line discipline active this is a no-op. 382 + * Flush the line discipline queue (if any) and the tty flip buffers 383 + * for this tty. 412 384 */ 413 385 414 386 void tty_ldisc_flush(struct tty_struct *tty) 415 387 { 416 388 struct tty_ldisc *ld = tty_ldisc_ref(tty); 417 - if (ld) { 418 - if (ld->ops->flush_buffer) 419 - ld->ops->flush_buffer(tty); 389 + 390 + tty_buffer_flush(tty, ld); 391 + if (ld) 420 392 tty_ldisc_deref(ld); 421 - } 422 - tty_buffer_flush(tty); 423 393 } 424 394 EXPORT_SYMBOL_GPL(tty_ldisc_flush); 425 395 ··· 523 517 { 524 518 int retval; 525 519 struct tty_ldisc *old_ldisc, *new_ldisc; 526 - struct tty_struct *o_tty = tty->link; 527 520 528 521 new_ldisc = tty_ldisc_get(tty, ldisc); 529 522 if (IS_ERR(new_ldisc)) 530 523 return PTR_ERR(new_ldisc); 531 524 532 - retval = tty_ldisc_lock_pair_timeout(tty, o_tty, 5 * HZ); 525 + tty_lock(tty); 526 + retval = tty_ldisc_lock(tty, 5 * HZ); 533 527 if (retval) { 534 528 tty_ldisc_put(new_ldisc); 529 + tty_unlock(tty); 535 530 return retval; 536 531 } 537 532 ··· 541 534 */ 542 535 543 536 if (tty->ldisc->ops->num == ldisc) { 544 - tty_ldisc_enable_pair(tty, o_tty); 537 + tty_ldisc_unlock(tty); 545 538 tty_ldisc_put(new_ldisc); 539 + tty_unlock(tty); 546 540 return 0; 547 541 } 548 542 549 543 old_ldisc = tty->ldisc; 550 - tty_lock(tty); 551 544 552 - if (test_bit(TTY_HUPPING, &tty->flags) || 553 - test_bit(TTY_HUPPED, &tty->flags)) { 545 + if (test_bit(TTY_HUPPED, &tty->flags)) { 554 546 /* We were raced by the hangup method. It will have stomped 555 547 the ldisc data and closed the ldisc down */ 556 - tty_ldisc_enable_pair(tty, o_tty); 548 + tty_ldisc_unlock(tty); 557 549 tty_ldisc_put(new_ldisc); 558 550 tty_unlock(tty); 559 551 return -EIO; ··· 572 566 tty_ldisc_restore(tty, old_ldisc); 573 567 } 574 568 575 - if (tty->ldisc->ops->num != old_ldisc->ops->num && tty->ops->set_ldisc) 569 + if (tty->ldisc->ops->num != old_ldisc->ops->num && tty->ops->set_ldisc) { 570 + down_read(&tty->termios_rwsem); 576 571 tty->ops->set_ldisc(tty); 572 + up_read(&tty->termios_rwsem); 573 + } 577 574 578 575 /* At this point we hold a reference to the new ldisc and a 579 576 reference to the old ldisc, or we hold two references to ··· 589 580 /* 590 581 * Allow ldisc referencing to occur again 591 582 */ 592 - tty_ldisc_enable_pair(tty, o_tty); 583 + tty_ldisc_unlock(tty); 593 584 594 585 /* Restart the work queue in case no characters kick it off. Safe if 595 586 already running */ 596 587 schedule_work(&tty->port->buf.work); 597 - if (o_tty) 598 - schedule_work(&o_tty->port->buf.work); 599 588 600 589 tty_unlock(tty); 601 590 return retval; ··· 682 675 wake_up_interruptible_poll(&tty->write_wait, POLLOUT); 683 676 wake_up_interruptible_poll(&tty->read_wait, POLLIN); 684 677 685 - tty_unlock(tty); 686 - 687 678 /* 688 679 * Shutdown the current line discipline, and reset it to 689 680 * N_TTY if need be. 690 681 * 691 682 * Avoid racing set_ldisc or tty_ldisc_release 692 683 */ 693 - tty_ldisc_lock_pair(tty, tty->link); 694 - tty_lock(tty); 684 + tty_ldisc_lock(tty, MAX_SCHEDULE_TIMEOUT); 695 685 696 686 if (tty->ldisc) { 697 687 ··· 710 706 WARN_ON(tty_ldisc_open(tty, tty->ldisc)); 711 707 } 712 708 } 713 - tty_ldisc_enable_pair(tty, tty->link); 709 + tty_ldisc_unlock(tty); 714 710 if (reset) 715 711 tty_reset_termios(tty); 716 712 ··· 762 758 763 759 /** 764 760 * tty_ldisc_release - release line discipline 765 - * @tty: tty being shut down 766 - * @o_tty: pair tty for pty/tty pairs 761 + * @tty: tty being shut down (or one end of pty pair) 767 762 * 768 - * Called during the final close of a tty/pty pair in order to shut down 769 - * the line discpline layer. On exit the ldisc assigned is N_TTY and the 770 - * ldisc has not been opened. 763 + * Called during the final close of a tty or a pty pair in order to shut 764 + * down the line discpline layer. On exit, each ldisc assigned is N_TTY and 765 + * each ldisc has not been opened. 771 766 */ 772 767 773 - void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) 768 + void tty_ldisc_release(struct tty_struct *tty) 774 769 { 770 + struct tty_struct *o_tty = tty->link; 771 + 775 772 /* 776 773 * Shutdown this line discipline. As this is the final close, 777 774 * it does not race with the set_ldisc code path. ··· 781 776 tty_ldisc_debug(tty, "closing ldisc: %p\n", tty->ldisc); 782 777 783 778 tty_ldisc_lock_pair(tty, o_tty); 784 - tty_lock_pair(tty, o_tty); 785 - 786 779 tty_ldisc_kill(tty); 787 780 if (o_tty) 788 781 tty_ldisc_kill(o_tty); 789 - 790 - tty_unlock_pair(tty, o_tty); 791 782 tty_ldisc_unlock_pair(tty, o_tty); 792 783 793 784 /* And the memory resources remaining (buffers, termios) will be
+21 -28
drivers/tty/tty_mutex.c
··· 4 4 #include <linux/semaphore.h> 5 5 #include <linux/sched.h> 6 6 7 + /* 8 + * Nested tty locks are necessary for releasing pty pairs. 9 + * The stable lock order is master pty first, then slave pty. 10 + */ 11 + 7 12 /* Legacy tty mutex glue */ 8 13 9 14 enum { 10 15 TTY_MUTEX_NORMAL, 11 - TTY_MUTEX_NESTED, 16 + TTY_MUTEX_SLAVE, 12 17 }; 13 18 14 19 /* 15 20 * Getting the big tty mutex. 16 21 */ 17 22 18 - static void __lockfunc tty_lock_nested(struct tty_struct *tty, 19 - unsigned int subclass) 23 + void __lockfunc tty_lock(struct tty_struct *tty) 20 24 { 21 25 if (tty->magic != TTY_MAGIC) { 22 26 pr_err("L Bad %p\n", tty); ··· 28 24 return; 29 25 } 30 26 tty_kref_get(tty); 31 - mutex_lock_nested(&tty->legacy_mutex, subclass); 32 - } 33 - 34 - void __lockfunc tty_lock(struct tty_struct *tty) 35 - { 36 - return tty_lock_nested(tty, TTY_MUTEX_NORMAL); 27 + mutex_lock(&tty->legacy_mutex); 37 28 } 38 29 EXPORT_SYMBOL(tty_lock); 39 30 ··· 44 45 } 45 46 EXPORT_SYMBOL(tty_unlock); 46 47 47 - /* 48 - * Getting the big tty mutex for a pair of ttys with lock ordering 49 - * On a non pty/tty pair tty2 can be NULL which is just fine. 50 - */ 51 - void __lockfunc tty_lock_pair(struct tty_struct *tty, 52 - struct tty_struct *tty2) 48 + void __lockfunc tty_lock_slave(struct tty_struct *tty) 53 49 { 54 - if (tty < tty2) { 50 + if (tty && tty != tty->link) { 51 + WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) || 52 + !tty->driver->type == TTY_DRIVER_TYPE_PTY || 53 + !tty->driver->type == PTY_TYPE_SLAVE); 55 54 tty_lock(tty); 56 - tty_lock_nested(tty2, TTY_MUTEX_NESTED); 57 - } else { 58 - if (tty2 && tty2 != tty) 59 - tty_lock(tty2); 60 - tty_lock_nested(tty, TTY_MUTEX_NESTED); 61 55 } 62 56 } 63 - EXPORT_SYMBOL(tty_lock_pair); 64 57 65 - void __lockfunc tty_unlock_pair(struct tty_struct *tty, 66 - struct tty_struct *tty2) 58 + void __lockfunc tty_unlock_slave(struct tty_struct *tty) 67 59 { 68 - tty_unlock(tty); 69 - if (tty2 && tty2 != tty) 70 - tty_unlock(tty2); 60 + if (tty && tty != tty->link) 61 + tty_unlock(tty); 71 62 } 72 - EXPORT_SYMBOL(tty_unlock_pair); 63 + 64 + void tty_set_lock_subclass(struct tty_struct *tty) 65 + { 66 + lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE); 67 + }
+4 -6
drivers/tty/tty_port.c
··· 193 193 unsigned long flags; 194 194 195 195 spin_lock_irqsave(&port->lock, flags); 196 - if (port->tty) 197 - tty_kref_put(port->tty); 196 + tty_kref_put(port->tty); 198 197 port->tty = tty_kref_get(tty); 199 198 spin_unlock_irqrestore(&port->lock, flags); 200 199 } ··· 472 473 { 473 474 unsigned long flags; 474 475 475 - spin_lock_irqsave(&port->lock, flags); 476 - if (tty_hung_up_p(filp)) { 477 - spin_unlock_irqrestore(&port->lock, flags); 476 + if (tty_hung_up_p(filp)) 478 477 return 0; 479 - } 480 478 479 + spin_lock_irqsave(&port->lock, flags); 481 480 if (tty->count == 1 && port->count != 1) { 482 481 printk(KERN_WARNING 483 482 "tty_port_close_start: tty->count = 1 port count = %d.\n", ··· 519 522 { 520 523 unsigned long flags; 521 524 525 + tty_ldisc_flush(tty); 522 526 tty->closing = 0; 523 527 524 528 spin_lock_irqsave(&port->lock, flags);
+3 -3
drivers/tty/vt/keyboard.c
··· 924 924 925 925 if (kbd->kbdmode != VC_UNICODE) { 926 926 if (!up_flag) 927 - pr_warning("keyboard mode must be unicode for braille patterns\n"); 927 + pr_warn("keyboard mode must be unicode for braille patterns\n"); 928 928 return; 929 929 } 930 930 ··· 1253 1253 if (raw_mode && !hw_raw) 1254 1254 if (emulate_raw(vc, keycode, !down << 7)) 1255 1255 if (keycode < BTN_MISC && printk_ratelimit()) 1256 - pr_warning("can't emulate rawmode for keycode %d\n", 1257 - keycode); 1256 + pr_warn("can't emulate rawmode for keycode %d\n", 1257 + keycode); 1258 1258 1259 1259 #ifdef CONFIG_SPARC 1260 1260 if (keycode == KEY_A && sparc_l1_a_state) {
+14 -8
drivers/tty/vt/vt.c
··· 156 156 static void blank_screen_t(unsigned long dummy); 157 157 static void set_palette(struct vc_data *vc); 158 158 159 + #define vt_get_kmsg_redirect() vt_kmsg_redirect(-1) 160 + 159 161 static int printable; /* Is console ready for printing? */ 160 162 int default_utf8 = true; 161 163 module_param(default_utf8, int, S_IRUGO | S_IWUSR); ··· 1369 1367 rgb_from_256(vc->vc_par[i])); 1370 1368 } else if (vc->vc_par[i] == 2 && /* 24 bit */ 1371 1369 i <= vc->vc_npar + 3) {/* extremely rare */ 1372 - struct rgb c = {r:vc->vc_par[i+1], 1373 - g:vc->vc_par[i+2], 1374 - b:vc->vc_par[i+3]}; 1370 + struct rgb c = { 1371 + .r = vc->vc_par[i + 1], 1372 + .g = vc->vc_par[i + 2], 1373 + .b = vc->vc_par[i + 3], 1374 + }; 1375 1375 rgb_foreground(vc, c); 1376 1376 i += 3; 1377 1377 } ··· 1392 1388 rgb_from_256(vc->vc_par[i])); 1393 1389 } else if (vc->vc_par[i] == 2 && /* 24 bit */ 1394 1390 i <= vc->vc_npar + 3) { 1395 - struct rgb c = {r:vc->vc_par[i+1], 1396 - g:vc->vc_par[i+2], 1397 - b:vc->vc_par[i+3]}; 1391 + struct rgb c = { 1392 + .r = vc->vc_par[i + 1], 1393 + .g = vc->vc_par[i + 2], 1394 + .b = vc->vc_par[i + 3], 1395 + }; 1398 1396 rgb_background(vc, c); 1399 1397 i += 3; 1400 1398 } ··· 3855 3849 return; 3856 3850 if (!vc_cons_allocated(fg_console)) { 3857 3851 /* impossible */ 3858 - pr_warning("unblank_screen: tty %d not allocated ??\n", 3859 - fg_console+1); 3852 + pr_warn("unblank_screen: tty %d not allocated ??\n", 3853 + fg_console + 1); 3860 3854 return; 3861 3855 } 3862 3856 vc = vc_cons[fg_console].d;
-3
include/linux/kernel.h
··· 416 416 extern int kernel_text_address(unsigned long addr); 417 417 extern int func_ptr_is_kernel_text(void *ptr); 418 418 419 - struct pid; 420 - extern struct pid *session_of_pgrp(struct pid *pgrp); 421 - 422 419 unsigned long int_sqrt(unsigned long); 423 420 424 421 extern void bust_spinlocks(int yes);
-3
include/linux/serial_8250.h
··· 97 97 unsigned char msr_saved_flags; 98 98 99 99 struct uart_8250_dma *dma; 100 - struct serial_rs485 rs485; 101 100 102 101 /* 8250 specific callbacks */ 103 102 int (*dl_read)(struct uart_8250_port *); 104 103 void (*dl_write)(struct uart_8250_port *, int); 105 - int (*rs485_config)(struct uart_8250_port *, 106 - struct serial_rs485 *rs485); 107 104 }; 108 105 109 106 static inline struct uart_8250_port *up_to_u8250p(struct uart_port *up)
-2
include/linux/serial_bcm63xx.h
··· 116 116 UART_FIFO_PARERR_MASK | \ 117 117 UART_FIFO_BRKDET_MASK) 118 118 119 - #define UART_REG_SIZE 24 120 - 121 119 #endif /* _LINUX_SERIAL_BCM63XX_H */
+44 -23
include/linux/serial_core.h
··· 63 63 void (*flush_buffer)(struct uart_port *); 64 64 void (*set_termios)(struct uart_port *, struct ktermios *new, 65 65 struct ktermios *old); 66 - void (*set_ldisc)(struct uart_port *, int new); 66 + void (*set_ldisc)(struct uart_port *, struct ktermios *); 67 67 void (*pm)(struct uart_port *, unsigned int state, 68 68 unsigned int oldstate); 69 69 ··· 131 131 void (*pm)(struct uart_port *, unsigned int state, 132 132 unsigned int old); 133 133 void (*handle_break)(struct uart_port *); 134 + int (*rs485_config)(struct uart_port *, 135 + struct serial_rs485 *rs485); 134 136 unsigned int irq; /* irq number */ 135 137 unsigned long irqflags; /* irq flags */ 136 138 unsigned int uartclk; /* base uart clock */ ··· 142 140 unsigned char iotype; /* io access style */ 143 141 unsigned char unused1; 144 142 145 - #define UPIO_PORT (0) 146 - #define UPIO_HUB6 (1) 147 - #define UPIO_MEM (2) 148 - #define UPIO_MEM32 (3) 149 - #define UPIO_AU (4) /* Au1x00 and RT288x type IO */ 150 - #define UPIO_TSI (5) /* Tsi108/109 type IO */ 143 + #define UPIO_PORT (0) /* 8b I/O port access */ 144 + #define UPIO_HUB6 (1) /* Hub6 ISA card */ 145 + #define UPIO_MEM (2) /* 8b MMIO access */ 146 + #define UPIO_MEM32 (3) /* 32b little endian */ 147 + #define UPIO_MEM32BE (4) /* 32b big endian */ 148 + #define UPIO_AU (5) /* Au1x00 and RT288x type IO */ 149 + #define UPIO_TSI (6) /* Tsi108/109 type IO */ 151 150 152 151 unsigned int read_status_mask; /* driver specific */ 153 152 unsigned int ignore_status_mask; /* driver specific */ ··· 163 160 /* flags must be updated while holding port mutex */ 164 161 upf_t flags; 165 162 166 - #define UPF_FOURPORT ((__force upf_t) (1 << 1)) 167 - #define UPF_SAK ((__force upf_t) (1 << 2)) 168 - #define UPF_SPD_MASK ((__force upf_t) (0x1030)) 169 - #define UPF_SPD_HI ((__force upf_t) (0x0010)) 170 - #define UPF_SPD_VHI ((__force upf_t) (0x0020)) 171 - #define UPF_SPD_CUST ((__force upf_t) (0x0030)) 172 - #define UPF_SPD_SHI ((__force upf_t) (0x1000)) 173 - #define UPF_SPD_WARP ((__force upf_t) (0x1010)) 174 - #define UPF_SKIP_TEST ((__force upf_t) (1 << 6)) 175 - #define UPF_AUTO_IRQ ((__force upf_t) (1 << 7)) 176 - #define UPF_HARDPPS_CD ((__force upf_t) (1 << 11)) 177 - #define UPF_LOW_LATENCY ((__force upf_t) (1 << 13)) 178 - #define UPF_BUGGY_UART ((__force upf_t) (1 << 14)) 163 + /* 164 + * These flags must be equivalent to the flags defined in 165 + * include/uapi/linux/tty_flags.h which are the userspace definitions 166 + * assigned from the serial_struct flags in uart_set_info() 167 + * [for bit definitions in the UPF_CHANGE_MASK] 168 + * 169 + * Bits [0..UPF_LAST_USER] are userspace defined/visible/changeable 170 + * except bit 15 (UPF_NO_TXEN_TEST) which is masked off. 171 + * The remaining bits are serial-core specific and not modifiable by 172 + * userspace. 173 + */ 174 + #define UPF_FOURPORT ((__force upf_t) ASYNC_FOURPORT /* 1 */ ) 175 + #define UPF_SAK ((__force upf_t) ASYNC_SAK /* 2 */ ) 176 + #define UPF_SPD_HI ((__force upf_t) ASYNC_SPD_HI /* 4 */ ) 177 + #define UPF_SPD_VHI ((__force upf_t) ASYNC_SPD_VHI /* 5 */ ) 178 + #define UPF_SPD_CUST ((__force upf_t) ASYNC_SPD_CUST /* 0x0030 */ ) 179 + #define UPF_SPD_WARP ((__force upf_t) ASYNC_SPD_WARP /* 0x1010 */ ) 180 + #define UPF_SPD_MASK ((__force upf_t) ASYNC_SPD_MASK /* 0x1030 */ ) 181 + #define UPF_SKIP_TEST ((__force upf_t) ASYNC_SKIP_TEST /* 6 */ ) 182 + #define UPF_AUTO_IRQ ((__force upf_t) ASYNC_AUTO_IRQ /* 7 */ ) 183 + #define UPF_HARDPPS_CD ((__force upf_t) ASYNC_HARDPPS_CD /* 11 */ ) 184 + #define UPF_SPD_SHI ((__force upf_t) ASYNC_SPD_SHI /* 12 */ ) 185 + #define UPF_LOW_LATENCY ((__force upf_t) ASYNC_LOW_LATENCY /* 13 */ ) 186 + #define UPF_BUGGY_UART ((__force upf_t) ASYNC_BUGGY_UART /* 14 */ ) 179 187 #define UPF_NO_TXEN_TEST ((__force upf_t) (1 << 15)) 180 - #define UPF_MAGIC_MULTIPLIER ((__force upf_t) (1 << 16)) 188 + #define UPF_MAGIC_MULTIPLIER ((__force upf_t) ASYNC_MAGIC_MULTIPLIER /* 16 */ ) 189 + 181 190 /* Port has hardware-assisted h/w flow control (iow, auto-RTS *not* auto-CTS) */ 182 191 #define UPF_HARD_FLOW ((__force upf_t) (1 << 21)) 183 192 /* Port has hardware-assisted s/w flow control */ ··· 205 190 #define UPF_DEAD ((__force upf_t) (1 << 30)) 206 191 #define UPF_IOREMAP ((__force upf_t) (1 << 31)) 207 192 208 - #define UPF_CHANGE_MASK ((__force upf_t) (0x17fff)) 193 + #define __UPF_CHANGE_MASK 0x17fff 194 + #define UPF_CHANGE_MASK ((__force upf_t) __UPF_CHANGE_MASK) 209 195 #define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY)) 196 + 197 + #if __UPF_CHANGE_MASK > ASYNC_FLAGS 198 + #error Change mask not equivalent to userspace-visible bit defines 199 + #endif 210 200 211 201 /* status must be updated while holding port lock */ 212 202 upstat_t status; ··· 234 214 unsigned char unused[2]; 235 215 struct attribute_group *attr_group; /* port specific attributes */ 236 216 const struct attribute_group **tty_groups; /* all attributes (serial core use only) */ 217 + struct serial_rs485 rs485; 237 218 void *private_data; /* generic platform data pointer */ 238 219 }; 239 220 ··· 388 367 389 368 static inline bool uart_cts_enabled(struct uart_port *uport) 390 369 { 391 - return uport->status & UPSTAT_CTS_ENABLE; 370 + return !!(uport->status & UPSTAT_CTS_ENABLE); 392 371 } 393 372 394 373 /*
+6 -22
include/linux/tty.h
··· 284 284 285 285 #define N_TTY_BUF_SIZE 4096 286 286 287 - unsigned char closing:1; 287 + int closing; 288 288 unsigned char *write_buf; 289 289 int write_cnt; 290 290 /* If the tty has a pending do_SAK, queue it here - akpm */ ··· 316 316 #define TTY_EXCLUSIVE 3 /* Exclusive open mode */ 317 317 #define TTY_DEBUG 4 /* Debugging */ 318 318 #define TTY_DO_WRITE_WAKEUP 5 /* Call write_wakeup after queuing new */ 319 - #define TTY_CLOSING 7 /* ->close() in progress */ 320 319 #define TTY_LDISC_OPEN 11 /* Line discipline is open */ 321 320 #define TTY_PTY_LOCK 16 /* pty private */ 322 321 #define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */ 323 322 #define TTY_HUPPED 18 /* Post driver->hangup() */ 324 - #define TTY_HUPPING 21 /* ->hangup() in progress */ 325 323 #define TTY_LDISC_HALTED 22 /* Line discipline is halted */ 326 324 327 325 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty)) ··· 435 437 extern int tty_signal(int sig, struct tty_struct *tty); 436 438 extern void tty_hangup(struct tty_struct *tty); 437 439 extern void tty_vhangup(struct tty_struct *tty); 438 - extern void tty_unhangup(struct file *filp); 439 440 extern int tty_hung_up_p(struct file *filp); 440 441 extern void do_SAK(struct tty_struct *tty); 441 442 extern void __do_SAK(struct tty_struct *tty); 442 443 extern void no_tty(void); 443 444 extern void tty_flush_to_ldisc(struct tty_struct *tty); 444 445 extern void tty_buffer_free_all(struct tty_port *port); 445 - extern void tty_buffer_flush(struct tty_struct *tty); 446 + extern void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld); 446 447 extern void tty_buffer_init(struct tty_port *port); 447 448 extern speed_t tty_termios_baud_rate(struct ktermios *termios); 448 449 extern speed_t tty_termios_input_baud_rate(struct ktermios *termios); ··· 494 497 extern int tty_init_termios(struct tty_struct *tty); 495 498 extern int tty_standard_install(struct tty_driver *driver, 496 499 struct tty_struct *tty); 497 - 498 - extern struct tty_struct *tty_pair_get_tty(struct tty_struct *tty); 499 - extern struct tty_struct *tty_pair_get_pty(struct tty_struct *tty); 500 500 501 501 extern struct mutex tty_mutex; 502 502 extern spinlock_t tty_files_lock; ··· 556 562 extern int tty_unregister_ldisc(int disc); 557 563 extern int tty_set_ldisc(struct tty_struct *tty, int ldisc); 558 564 extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty); 559 - extern void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty); 565 + extern void tty_ldisc_release(struct tty_struct *tty); 560 566 extern void tty_ldisc_init(struct tty_struct *tty); 561 567 extern void tty_ldisc_deinit(struct tty_struct *tty); 562 568 extern void tty_ldisc_begin(void); ··· 617 623 extern long n_tty_compat_ioctl_helper(struct tty_struct *tty, struct file *file, 618 624 unsigned int cmd, unsigned long arg); 619 625 620 - /* serial.c */ 621 - 622 - extern void serial_console_init(void); 623 - 624 - /* pcxx.c */ 625 - 626 - extern int pcxe_open(struct tty_struct *tty, struct file *filp); 627 - 628 626 /* vt.c */ 629 627 630 628 extern int vt_ioctl(struct tty_struct *tty, ··· 629 643 /* functions for preparation of BKL removal */ 630 644 extern void __lockfunc tty_lock(struct tty_struct *tty); 631 645 extern void __lockfunc tty_unlock(struct tty_struct *tty); 632 - extern void __lockfunc tty_lock_pair(struct tty_struct *tty, 633 - struct tty_struct *tty2); 634 - extern void __lockfunc tty_unlock_pair(struct tty_struct *tty, 635 - struct tty_struct *tty2); 636 - 646 + extern void __lockfunc tty_lock_slave(struct tty_struct *tty); 647 + extern void __lockfunc tty_unlock_slave(struct tty_struct *tty); 648 + extern void tty_set_lock_subclass(struct tty_struct *tty); 637 649 /* 638 650 * this shall be called only from where BTM is held (like close) 639 651 *
+2 -1
include/uapi/linux/serial_core.h
··· 54 54 #define PORT_ALTR_16550_F32 26 /* Altera 16550 UART with 32 FIFOs */ 55 55 #define PORT_ALTR_16550_F64 27 /* Altera 16550 UART with 64 FIFOs */ 56 56 #define PORT_ALTR_16550_F128 28 /* Altera 16550 UART with 128 FIFOs */ 57 - #define PORT_MAX_8250 28 /* max port ID */ 57 + #define PORT_RT2880 29 /* Ralink RT2880 internal UART */ 58 + #define PORT_MAX_8250 29 /* max port ID */ 58 59 59 60 /* 60 61 * ARM specific type numbers. These are not currently guaranteed
+1
include/uapi/linux/serial_reg.h
··· 359 359 #define UART_OMAP_SYSC 0x15 /* System configuration register */ 360 360 #define UART_OMAP_SYSS 0x16 /* System status register */ 361 361 #define UART_OMAP_WER 0x17 /* Wake-up enable register */ 362 + #define UART_OMAP_TX_LVL 0x1a /* TX FIFO level register */ 362 363 363 364 /* 364 365 * These are the definitions for the MDR1 register
+13 -6
include/uapi/linux/tty_flags.h
··· 6 6 * shared by the tty_port flags structures. 7 7 * 8 8 * Define ASYNCB_* for convenient use with {test,set,clear}_bit. 9 + * 10 + * Bits [0..ASYNCB_LAST_USER] are userspace defined/visible/changeable 11 + * [x] in the bit comments indicates the flag is defunct and no longer used. 9 12 */ 10 13 #define ASYNCB_HUP_NOTIFY 0 /* Notify getty on hangups and closes 11 14 * on the callout port */ 12 15 #define ASYNCB_FOURPORT 1 /* Set OU1, OUT2 per AST Fourport settings */ 13 16 #define ASYNCB_SAK 2 /* Secure Attention Key (Orange book) */ 14 - #define ASYNCB_SPLIT_TERMIOS 3 /* Separate termios for dialin/callout */ 17 + #define ASYNCB_SPLIT_TERMIOS 3 /* [x] Separate termios for dialin/callout */ 15 18 #define ASYNCB_SPD_HI 4 /* Use 56000 instead of 38400 bps */ 16 19 #define ASYNCB_SPD_VHI 5 /* Use 115200 instead of 38400 bps */ 17 20 #define ASYNCB_SKIP_TEST 6 /* Skip UART test during autoconfiguration */ 18 21 #define ASYNCB_AUTO_IRQ 7 /* Do automatic IRQ during 19 22 * autoconfiguration */ 20 - #define ASYNCB_SESSION_LOCKOUT 8 /* Lock out cua opens based on session */ 21 - #define ASYNCB_PGRP_LOCKOUT 9 /* Lock out cua opens based on pgrp */ 22 - #define ASYNCB_CALLOUT_NOHUP 10 /* Don't do hangups for cua device */ 23 + #define ASYNCB_SESSION_LOCKOUT 8 /* [x] Lock out cua opens based on session */ 24 + #define ASYNCB_PGRP_LOCKOUT 9 /* [x] Lock out cua opens based on pgrp */ 25 + #define ASYNCB_CALLOUT_NOHUP 10 /* [x] Don't do hangups for cua device */ 23 26 #define ASYNCB_HARDPPS_CD 11 /* Call hardpps when CD goes high */ 24 27 #define ASYNCB_SPD_SHI 12 /* Use 230400 instead of 38400 bps */ 25 28 #define ASYNCB_LOW_LATENCY 13 /* Request low latency behaviour */ 26 29 #define ASYNCB_BUGGY_UART 14 /* This is a buggy UART, skip some safety 27 30 * checks. Note: can be dangerous! */ 28 - #define ASYNCB_AUTOPROBE 15 /* Port was autoprobed by PCI or PNP code */ 29 - #define ASYNCB_LAST_USER 15 31 + #define ASYNCB_AUTOPROBE 15 /* [x] Port was autoprobed by PCI/PNP code */ 32 + #define ASYNCB_MAGIC_MULTIPLIER 16 /* Use special CLK or divisor */ 33 + #define ASYNCB_LAST_USER 16 30 34 31 35 /* Internal flags used only by kernel */ 32 36 #define ASYNCB_INITIALIZED 31 /* Serial port was initialized */ ··· 61 57 #define ASYNC_LOW_LATENCY (1U << ASYNCB_LOW_LATENCY) 62 58 #define ASYNC_BUGGY_UART (1U << ASYNCB_BUGGY_UART) 63 59 #define ASYNC_AUTOPROBE (1U << ASYNCB_AUTOPROBE) 60 + #define ASYNC_MAGIC_MULTIPLIER (1U << ASYNCB_MAGIC_MULTIPLIER) 64 61 65 62 #define ASYNC_FLAGS ((1U << (ASYNCB_LAST_USER + 1)) - 1) 63 + #define ASYNC_DEPRECATED (ASYNC_SESSION_LOCKOUT | ASYNC_PGRP_LOCKOUT | \ 64 + ASYNC_CALLOUT_NOHUP | ASYNC_AUTOPROBE) 66 65 #define ASYNC_USR_MASK (ASYNC_SPD_MASK|ASYNC_CALLOUT_NOHUP| \ 67 66 ASYNC_LOW_LATENCY) 68 67 #define ASYNC_SPD_CUST (ASYNC_SPD_HI|ASYNC_SPD_VHI)
-3
include/uapi/linux/vt.h
··· 84 84 85 85 #define VT_SETACTIVATE 0x560F /* Activate and set the mode of a console */ 86 86 87 - 88 - #define vt_get_kmsg_redirect() vt_kmsg_redirect(-1) 89 - 90 87 #endif /* _UAPI_LINUX_VT_H */
-21
kernel/exit.c
··· 212 212 } 213 213 214 214 /* 215 - * This checks not only the pgrp, but falls back on the pid if no 216 - * satisfactory pgrp is found. I dunno - gdb doesn't work correctly 217 - * without this... 218 - * 219 - * The caller must hold rcu lock or the tasklist lock. 220 - */ 221 - struct pid *session_of_pgrp(struct pid *pgrp) 222 - { 223 - struct task_struct *p; 224 - struct pid *sid = NULL; 225 - 226 - p = pid_task(pgrp, PIDTYPE_PGID); 227 - if (p == NULL) 228 - p = pid_task(pgrp, PIDTYPE_PID); 229 - if (p != NULL) 230 - sid = task_session(p); 231 - 232 - return sid; 233 - } 234 - 235 - /* 236 215 * Determine if a process group is "orphaned", according to the POSIX 237 216 * definition in 2.2.2.52. Orphaned process groups are not to be affected 238 217 * by terminal-generated stop signals. Newly orphaned process groups are