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

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

Pull tty/serial driver updates from Greg KH:
"Here is the big tty and serial driver pull request for 4.19-rc1.

It's not all that big, just a number of small serial driver updates
and fixes, along with some better vt handling for unicode characters
for those using braille terminals.

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

* tag 'tty-4.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (73 commits)
tty: serial: 8250: Revert NXP SC16C2552 workaround
serial: 8250_exar: Read INT0 from slave device, too
tty: rocket: Fix possible buffer overwrite on register_PCI
serial: 8250_dw: Add ACPI support for uart on Broadcom SoC
serial: 8250_dw: always set baud rate in dw8250_set_termios
dt-bindings: serial: Add binding for uartlite
tty: serial: uartlite: Add support for suspend and resume
tty: serial: uartlite: Add clock adaptation
tty: serial: uartlite: Add structure for private data
serial: sh-sci: Improve support for separate TEI and DRI interrupts
serial: sh-sci: Remove SCIx_RZ_SCIFA_REGTYPE
serial: sh-sci: Allow for compressed SCIF address
serial: sh-sci: Improve interrupts description
serial: 8250: Use cached port name directly in messages
serial: 8250_exar: Drop unused variable in pci_xr17v35x_setup()
vt: drop unused struct vt_struct
vt: avoid a VLA in the unicode screen scroll function
vt: add /dev/vcsu* to devices.txt
vt: coherence validation code for the unicode screen buffer
vt: selection: take screen contents from uniscr if available
...

+1382 -339
+10 -6
Documentation/admin-guide/devices.txt
··· 173 173 they are redirected through the parport multiplex layer. 174 174 175 175 7 char Virtual console capture devices 176 - 0 = /dev/vcs Current vc text contents 177 - 1 = /dev/vcs1 tty1 text contents 176 + 0 = /dev/vcs Current vc text (glyph) contents 177 + 1 = /dev/vcs1 tty1 text (glyph) contents 178 178 ... 179 - 63 = /dev/vcs63 tty63 text contents 180 - 128 = /dev/vcsa Current vc text/attribute contents 181 - 129 = /dev/vcsa1 tty1 text/attribute contents 179 + 63 = /dev/vcs63 tty63 text (glyph) contents 180 + 64 = /dev/vcsu Current vc text (unicode) contents 181 + 65 = /dev/vcsu1 tty1 text (unicode) contents 182 182 ... 183 - 191 = /dev/vcsa63 tty63 text/attribute contents 183 + 127 = /dev/vcsu63 tty63 text (unicode) contents 184 + 128 = /dev/vcsa Current vc text/attribute (glyph) contents 185 + 129 = /dev/vcsa1 tty1 text/attribute (glyph) contents 186 + ... 187 + 191 = /dev/vcsa63 tty63 text/attribute (glyph) contents 184 188 185 189 NOTE: These devices permit both read and write access. 186 190
+4
Documentation/devicetree/bindings/arm/mediatek.txt
··· 11 11 "mediatek,mt6589" 12 12 "mediatek,mt6592" 13 13 "mediatek,mt6755" 14 + "mediatek,mt6765" 14 15 "mediatek,mt6795" 15 16 "mediatek,mt6797" 16 17 "mediatek,mt7622" ··· 42 41 - Evaluation phone for MT6755(Helio P10): 43 42 Required root node properties: 44 43 - compatible = "mediatek,mt6755-evb", "mediatek,mt6755"; 44 + - Evaluation board for MT6765(Helio P22): 45 + Required root node properties: 46 + - compatible = "mediatek,mt6765-evb", "mediatek,mt6765"; 45 47 - Evaluation board for MT6795(Helio X10): 46 48 Required root node properties: 47 49 - compatible = "mediatek,mt6795-evb", "mediatek,mt6795";
+1
Documentation/devicetree/bindings/interrupt-controller/mediatek,sysirq.txt
··· 11 11 "mediatek,mt7622-sysirq", "mediatek,mt6577-sysirq": for MT7622 12 12 "mediatek,mt6795-sysirq", "mediatek,mt6577-sysirq": for MT6795 13 13 "mediatek,mt6797-sysirq", "mediatek,mt6577-sysirq": for MT6797 14 + "mediatek,mt6765-sysirq", "mediatek,mt6577-sysirq": for MT6765 14 15 "mediatek,mt6755-sysirq", "mediatek,mt6577-sysirq": for MT6755 15 16 "mediatek,mt6592-sysirq", "mediatek,mt6577-sysirq": for MT6592 16 17 "mediatek,mt6589-sysirq", "mediatek,mt6577-sysirq": for MT6589
+5 -1
Documentation/devicetree/bindings/serial/fsl-imx-uart.txt
··· 9 9 - fsl,dte-mode : Indicate the uart works in DTE mode. The uart works 10 10 in DCE mode by default. 11 11 - rs485-rts-delay, rs485-rts-active-low, rs485-rx-during-tx, 12 - linux,rs485-enabled-at-boot-time: see rs485.txt 12 + linux,rs485-enabled-at-boot-time: see rs485.txt. Note that for RS485 13 + you must enable either the "uart-has-rtscts" or the "rts-gpios" 14 + properties. In case you use "uart-has-rtscts" the signal that controls 15 + the transceiver is actually CTS_B, not RTS_B. CTS_B is always output, 16 + and RTS_B is input, regardless of dte-mode. 13 17 14 18 Please check Documentation/devicetree/bindings/serial/serial.txt 15 19 for the complete list of generic properties.
+1
Documentation/devicetree/bindings/serial/mtk-uart.txt
··· 8 8 * "mediatek,mt6582-uart" for MT6582 compatible UARTS 9 9 * "mediatek,mt6589-uart" for MT6589 compatible UARTS 10 10 * "mediatek,mt6755-uart" for MT6755 compatible UARTS 11 + * "mediatek,mt6765-uart" for MT6765 compatible UARTS 11 12 * "mediatek,mt6795-uart" for MT6795 compatible UARTS 12 13 * "mediatek,mt6797-uart" for MT6797 compatible UARTS 13 14 * "mediatek,mt7622-uart" for MT7622 compatible UARTS
+1
Documentation/devicetree/bindings/serial/omap_serial.txt
··· 1 1 OMAP UART controller 2 2 3 3 Required properties: 4 + - compatible : should be "ti,am654-uart" for AM654 controllers 4 5 - compatible : should be "ti,omap2-uart" for OMAP2 controllers 5 6 - compatible : should be "ti,omap3-uart" for OMAP3 controllers 6 7 - compatible : should be "ti,omap4-uart" for OMAP4 controllers
+10
Documentation/devicetree/bindings/serial/renesas,rzn1-uart.txt
··· 1 + Renesas RZ/N1 UART 2 + 3 + This controller is based on the Synopsys DesignWare ABP UART and inherits all 4 + properties defined in snps-dw-apb-uart.txt except for the compatible property. 5 + 6 + Required properties: 7 + - compatible : The device specific string followed by the generic RZ/N1 string. 8 + Therefore it must be one of: 9 + "renesas,r9a06g032-uart", "renesas,rzn1-uart" 10 + "renesas,r9a06g033-uart", "renesas,rzn1-uart"
+17 -2
Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
··· 5 5 - compatible: Must contain one or more of the following: 6 6 7 7 - "renesas,scif-r7s72100" for R7S72100 (RZ/A1H) SCIF compatible UART. 8 + - "renesas,scif-r7s9210" for R7S9210 (RZ/A2) SCIF compatible UART. 8 9 - "renesas,scifa-r8a73a4" for R8A73A4 (R-Mobile APE6) SCIFA compatible UART. 9 10 - "renesas,scifb-r8a73a4" for R8A73A4 (R-Mobile APE6) SCIFB compatible UART. 10 11 - "renesas,scifa-r8a7740" for R8A7740 (R-Mobile A1) SCIFA compatible UART. ··· 73 72 family-specific and/or generic versions. 74 73 75 74 - reg: Base address and length of the I/O registers used by the UART. 76 - - interrupts: Must contain an interrupt-specifier for the SCIx interrupt. 75 + - interrupts: Must contain one or more interrupt-specifiers for the SCIx. 76 + If a single interrupt is expressed, then all events are 77 + multiplexed into this single interrupt. 78 + 79 + If multiple interrupts are provided by the hardware, the order 80 + in which the interrupts are listed must match order below. Note 81 + that some HW interrupt events may be muxed together resulting 82 + in duplicate entries. 83 + The interrupt order is as follows: 84 + 1. Error (ERI) 85 + 2. Receive buffer full (RXI) 86 + 3. Transmit buffer empty (TXI) 87 + 4. Break (BRI) 88 + 5. Data Ready (DRI) 89 + 6. Transmit End (TEI) 77 90 78 91 - clocks: Must contain a phandle and clock-specifier pair for each entry 79 92 in clock-names. ··· 104 89 - "scif_clk" for the optional external clock source for the frequency 105 90 divider (SCIF_CLK). 106 91 107 - Note: Each enabled SCIx UART should have an alias correctly numbered in the 92 + Note: Each enabled SCIx UART may have an optional "serialN" alias in the 108 93 "aliases" node. 109 94 110 95 Optional properties:
+23
Documentation/devicetree/bindings/serial/xlnx,opb-uartlite.txt
··· 1 + Xilinx Axi Uartlite controller Device Tree Bindings 2 + --------------------------------------------------------- 3 + 4 + Required properties: 5 + - compatible : Can be either of 6 + "xlnx,xps-uartlite-1.00.a" 7 + "xlnx,opb-uartlite-1.00.b" 8 + - reg : Physical base address and size of the Axi Uartlite 9 + registers map. 10 + - interrupts : Should contain the UART controller interrupt. 11 + 12 + Optional properties: 13 + - port-number : Set Uart port number 14 + - clock-names : Should be "s_axi_aclk" 15 + - clocks : Input clock specifier. Refer to common clock bindings. 16 + 17 + Example: 18 + serial@800c0000 { 19 + compatible = "xlnx,xps-uartlite-1.00.a"; 20 + reg = <0x0 0x800c0000 0x10000>; 21 + interrupts = <0x0 0x6e 0x1>; 22 + port-number = <0>; 23 + };
+1 -1
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt
··· 46 46 Qualcomm Technologies Inc. GENI Serial Engine based UART Controller 47 47 48 48 Required properties: 49 - - compatible: Must be "qcom,geni-debug-uart". 49 + - compatible: Must be "qcom,geni-debug-uart" or "qcom,geni-uart". 50 50 - reg: Must contain UART register location and length. 51 51 - interrupts: Must contain UART core interrupts. 52 52 - clock-names: Must contain "se".
+9
drivers/parport/parport_serial.c
··· 58 58 timedia_9079c, 59 59 wch_ch353_1s1p, 60 60 wch_ch353_2s1p, 61 + wch_ch382_0s1p, 61 62 wch_ch382_2s1p, 62 63 brainboxes_5s1p, 63 64 sunix_2s1p, ··· 148 147 /* timedia_9079c */ { 1, { { 2, 3 }, } }, 149 148 /* wch_ch353_1s1p*/ { 1, { { 1, -1}, } }, 150 149 /* wch_ch353_2s1p*/ { 1, { { 2, -1}, } }, 150 + /* wch_ch382_0s1p*/ { 1, { { 2, -1}, } }, 151 151 /* wch_ch382_2s1p*/ { 1, { { 2, -1}, } }, 152 152 /* brainboxes_5s1p */ { 1, { { 3, -1 }, } }, 153 153 /* sunix_2s1p */ { 1, { { 3, -1 }, } }, ··· 254 252 /* WCH CARDS */ 255 253 { 0x4348, 0x5053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, wch_ch353_1s1p}, 256 254 { 0x4348, 0x7053, 0x4348, 0x3253, 0, 0, wch_ch353_2s1p}, 255 + { 0x1c00, 0x3050, 0x1c00, 0x3050, 0, 0, wch_ch382_0s1p}, 257 256 { 0x1c00, 0x3250, 0x1c00, 0x3250, 0, 0, wch_ch382_2s1p}, 258 257 259 258 /* BrainBoxes PX272/PX306 MIO card */ ··· 494 491 [wch_ch353_2s1p] = { 495 492 .flags = FL_BASE0|FL_BASE_BARS, 496 493 .num_ports = 2, 494 + .base_baud = 115200, 495 + .uart_offset = 8, 496 + }, 497 + [wch_ch382_0s1p] = { 498 + .flags = FL_BASE0, 499 + .num_ports = 0, 497 500 .base_baud = 115200, 498 501 .uart_offset = 8, 499 502 },
+28 -2
drivers/s390/char/keyboard.c
··· 39 39 }; 40 40 static const int KBD_NR_TYPES = ARRAY_SIZE(kbd_max_vals); 41 41 42 - static unsigned char ret_diacr[NR_DEAD] = { 43 - '`', '\'', '^', '~', '"', ',' 42 + static const unsigned char ret_diacr[NR_DEAD] = { 43 + '`', /* dead_grave */ 44 + '\'', /* dead_acute */ 45 + '^', /* dead_circumflex */ 46 + '~', /* dead_tilda */ 47 + '"', /* dead_diaeresis */ 48 + ',', /* dead_cedilla */ 49 + '_', /* dead_macron */ 50 + 'U', /* dead_breve */ 51 + '.', /* dead_abovedot */ 52 + '*', /* dead_abovering */ 53 + '=', /* dead_doubleacute */ 54 + 'c', /* dead_caron */ 55 + 'k', /* dead_ogonek */ 56 + 'i', /* dead_iota */ 57 + '#', /* dead_voiced_sound */ 58 + 'o', /* dead_semivoiced_sound */ 59 + '!', /* dead_belowdot */ 60 + '?', /* dead_hook */ 61 + '+', /* dead_horn */ 62 + '-', /* dead_stroke */ 63 + ')', /* dead_abovecomma */ 64 + '(', /* dead_abovereversedcomma */ 65 + ':', /* dead_doublegrave */ 66 + 'n', /* dead_invertedbreve */ 67 + ';', /* dead_belowcomma */ 68 + '$', /* dead_currency */ 69 + '@', /* dead_greek */ 44 70 }; 45 71 46 72 /*
+1 -1
drivers/tty/pty.c
··· 625 625 if (tty->driver != ptm_driver) 626 626 return -EIO; 627 627 628 - fd = get_unused_fd_flags(0); 628 + fd = get_unused_fd_flags(flags); 629 629 if (fd < 0) { 630 630 retval = fd; 631 631 goto err;
+1 -1
drivers/tty/rocket.c
··· 1881 1881 ByteIO_t UPCIRingInd = 0; 1882 1882 1883 1883 if (!dev || !pci_match_id(rocket_pci_ids, dev) || 1884 - pci_enable_device(dev)) 1884 + pci_enable_device(dev) || i >= NUM_BOARDS) 1885 1885 return 0; 1886 1886 1887 1887 rcktpt_io_addr[i] = pci_resource_start(dev, 0);
+44 -4
drivers/tty/serdev/core.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/of.h> 15 15 #include <linux/of_device.h> 16 + #include <linux/pm_domain.h> 17 + #include <linux/pm_runtime.h> 16 18 #include <linux/serdev.h> 17 19 #include <linux/slab.h> 18 20 ··· 145 143 int serdev_device_open(struct serdev_device *serdev) 146 144 { 147 145 struct serdev_controller *ctrl = serdev->ctrl; 146 + int ret; 148 147 149 148 if (!ctrl || !ctrl->ops->open) 150 149 return -EINVAL; 151 150 152 - return ctrl->ops->open(ctrl); 151 + ret = ctrl->ops->open(ctrl); 152 + if (ret) 153 + return ret; 154 + 155 + ret = pm_runtime_get_sync(&ctrl->dev); 156 + if (ret < 0) { 157 + pm_runtime_put_noidle(&ctrl->dev); 158 + goto err_close; 159 + } 160 + 161 + return 0; 162 + 163 + err_close: 164 + if (ctrl->ops->close) 165 + ctrl->ops->close(ctrl); 166 + 167 + return ret; 153 168 } 154 169 EXPORT_SYMBOL_GPL(serdev_device_open); 155 170 ··· 176 157 177 158 if (!ctrl || !ctrl->ops->close) 178 159 return; 160 + 161 + pm_runtime_put(&ctrl->dev); 179 162 180 163 ctrl->ops->close(ctrl); 181 164 } ··· 351 330 static int serdev_drv_probe(struct device *dev) 352 331 { 353 332 const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); 333 + int ret; 354 334 355 - return sdrv->probe(to_serdev_device(dev)); 335 + ret = dev_pm_domain_attach(dev, true); 336 + if (ret) 337 + return ret; 338 + 339 + ret = sdrv->probe(to_serdev_device(dev)); 340 + if (ret) 341 + dev_pm_domain_detach(dev, true); 342 + 343 + return ret; 356 344 } 357 345 358 346 static int serdev_drv_remove(struct device *dev) ··· 369 339 const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); 370 340 if (sdrv->remove) 371 341 sdrv->remove(to_serdev_device(dev)); 342 + 343 + dev_pm_domain_detach(dev, true); 344 + 372 345 return 0; 373 346 } 374 347 ··· 448 415 serdev_controller_set_drvdata(ctrl, &ctrl[1]); 449 416 450 417 dev_set_name(&ctrl->dev, "serial%d", id); 418 + 419 + pm_runtime_no_callbacks(&ctrl->dev); 420 + pm_suspend_ignore_children(&ctrl->dev, true); 451 421 452 422 dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); 453 423 return ctrl; ··· 583 547 if (ret) 584 548 return ret; 585 549 550 + pm_runtime_enable(&ctrl->dev); 551 + 586 552 ret_of = of_serdev_register_devices(ctrl); 587 553 ret_acpi = acpi_serdev_register_devices(ctrl); 588 554 if (ret_of && ret_acpi) { 589 555 dev_dbg(&ctrl->dev, "no devices registered: of:%d acpi:%d\n", 590 556 ret_of, ret_acpi); 591 557 ret = -ENODEV; 592 - goto out_dev_del; 558 + goto err_rpm_disable; 593 559 } 594 560 595 561 dev_dbg(&ctrl->dev, "serdev%d registered: dev:%p\n", 596 562 ctrl->nr, &ctrl->dev); 597 563 return 0; 598 564 599 - out_dev_del: 565 + err_rpm_disable: 566 + pm_runtime_disable(&ctrl->dev); 600 567 device_del(&ctrl->dev); 601 568 return ret; 602 569 }; ··· 630 591 631 592 dummy = device_for_each_child(&ctrl->dev, NULL, 632 593 serdev_remove_device); 594 + pm_runtime_disable(&ctrl->dev); 633 595 device_del(&ctrl->dev); 634 596 } 635 597 EXPORT_SYMBOL_GPL(serdev_controller_remove);
+5 -1
drivers/tty/serial/8250/8250_core.c
··· 323 323 * the port is opened so this value needs to be preserved. 324 324 */ 325 325 if (up->bugs & UART_BUG_THRE) { 326 - pr_debug("ttyS%d - using backup timer\n", serial_index(port)); 326 + pr_debug("%s - using backup timer\n", port->name); 327 327 328 328 up->timer.function = serial8250_backup_timeout; 329 329 mod_timer(&up->timer, jiffies + ··· 1023 1023 uart->port.get_mctrl = up->port.get_mctrl; 1024 1024 if (up->port.set_mctrl) 1025 1025 uart->port.set_mctrl = up->port.set_mctrl; 1026 + if (up->port.get_divisor) 1027 + uart->port.get_divisor = up->port.get_divisor; 1028 + if (up->port.set_divisor) 1029 + uart->port.set_divisor = up->port.set_divisor; 1026 1030 if (up->port.startup) 1027 1031 uart->port.startup = up->port.startup; 1028 1032 if (up->port.shutdown)
+65 -9
drivers/tty/serial/8250/8250_dw.c
··· 31 31 32 32 /* Offsets for the DesignWare specific registers */ 33 33 #define DW_UART_USR 0x1f /* UART Status Register */ 34 + #define DW_UART_DLF 0xc0 /* Divisor Latch Fraction Register */ 34 35 #define DW_UART_CPR 0xf4 /* Component Parameter Register */ 35 36 #define DW_UART_UCV 0xf8 /* UART Component Version */ 36 37 ··· 56 55 57 56 struct dw8250_data { 58 57 u8 usr_reg; 58 + u8 dlf_size; 59 59 int line; 60 60 int msr_mask_on; 61 61 int msr_mask_off; ··· 68 66 unsigned int skip_autocfg:1; 69 67 unsigned int uart_16550_compatible:1; 70 68 }; 69 + 70 + static inline u32 dw8250_readl_ext(struct uart_port *p, int offset) 71 + { 72 + if (p->iotype == UPIO_MEM32BE) 73 + return ioread32be(p->membase + offset); 74 + return readl(p->membase + offset); 75 + } 76 + 77 + static inline void dw8250_writel_ext(struct uart_port *p, int offset, u32 reg) 78 + { 79 + if (p->iotype == UPIO_MEM32BE) 80 + iowrite32be(reg, p->membase + offset); 81 + else 82 + writel(reg, p->membase + offset); 83 + } 71 84 72 85 static inline int dw8250_modify_msr(struct uart_port *p, int offset, int value) 73 86 { ··· 310 293 long rate; 311 294 int ret; 312 295 313 - if (IS_ERR(d->clk) || !old) 296 + if (IS_ERR(d->clk)) 314 297 goto out; 315 298 316 299 clk_disable_unprepare(d->clk); ··· 368 351 return param == chan->device->dev->parent; 369 352 } 370 353 354 + /* 355 + * divisor = div(I) + div(F) 356 + * "I" means integer, "F" means fractional 357 + * quot = div(I) = clk / (16 * baud) 358 + * frac = div(F) * 2^dlf_size 359 + * 360 + * let rem = clk % (16 * baud) 361 + * we have: div(F) * (16 * baud) = rem 362 + * so frac = 2^dlf_size * rem / (16 * baud) = (rem << dlf_size) / (16 * baud) 363 + */ 364 + static unsigned int dw8250_get_divisor(struct uart_port *p, 365 + unsigned int baud, 366 + unsigned int *frac) 367 + { 368 + unsigned int quot, rem, base_baud = baud * 16; 369 + struct dw8250_data *d = p->private_data; 370 + 371 + quot = p->uartclk / base_baud; 372 + rem = p->uartclk % base_baud; 373 + *frac = DIV_ROUND_CLOSEST(rem << d->dlf_size, base_baud); 374 + 375 + return quot; 376 + } 377 + 378 + static void dw8250_set_divisor(struct uart_port *p, unsigned int baud, 379 + unsigned int quot, unsigned int quot_frac) 380 + { 381 + dw8250_writel_ext(p, DW_UART_DLF, quot_frac); 382 + serial8250_do_set_divisor(p, baud, quot, quot_frac); 383 + } 384 + 371 385 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data) 372 386 { 373 387 if (p->dev->of_node) { ··· 452 404 * If the Component Version Register returns zero, we know that 453 405 * ADDITIONAL_FEATURES are not enabled. No need to go any further. 454 406 */ 455 - if (p->iotype == UPIO_MEM32BE) 456 - reg = ioread32be(p->membase + DW_UART_UCV); 457 - else 458 - reg = readl(p->membase + DW_UART_UCV); 407 + reg = dw8250_readl_ext(p, DW_UART_UCV); 459 408 if (!reg) 460 409 return; 461 410 462 411 dev_dbg(p->dev, "Designware UART version %c.%c%c\n", 463 412 (reg >> 24) & 0xff, (reg >> 16) & 0xff, (reg >> 8) & 0xff); 464 413 465 - if (p->iotype == UPIO_MEM32BE) 466 - reg = ioread32be(p->membase + DW_UART_CPR); 467 - else 468 - reg = readl(p->membase + DW_UART_CPR); 414 + dw8250_writel_ext(p, DW_UART_DLF, ~0U); 415 + reg = dw8250_readl_ext(p, DW_UART_DLF); 416 + dw8250_writel_ext(p, DW_UART_DLF, 0); 417 + 418 + if (reg) { 419 + struct dw8250_data *d = p->private_data; 420 + 421 + d->dlf_size = fls(reg); 422 + p->get_divisor = dw8250_get_divisor; 423 + p->set_divisor = dw8250_set_divisor; 424 + } 425 + 426 + reg = dw8250_readl_ext(p, DW_UART_CPR); 469 427 if (!reg) 470 428 return; 471 429 ··· 747 693 { .compatible = "snps,dw-apb-uart" }, 748 694 { .compatible = "cavium,octeon-3860-uart" }, 749 695 { .compatible = "marvell,armada-38x-uart" }, 696 + { .compatible = "renesas,rzn1-uart" }, 750 697 { /* Sentinel */ } 751 698 }; 752 699 MODULE_DEVICE_TABLE(of, dw8250_of_match); ··· 762 707 { "APMC0D08", 0}, 763 708 { "AMD0020", 0 }, 764 709 { "AMDI0020", 0 }, 710 + { "BRCM2032", 0 }, 765 711 { "HISI0031", 0 }, 766 712 { }, 767 713 };
+34 -20
drivers/tty/serial/8250/8250_exar.c
··· 109 109 * struct exar8250_board - board information 110 110 * @num_ports: number of serial ports 111 111 * @reg_shift: describes UART register mapping in PCI memory 112 + * @setup: quirk run at ->probe() stage 113 + * @exit: quirk run at ->remove() stage 112 114 */ 113 115 struct exar8250_board { 114 116 unsigned int num_ports; 115 117 unsigned int reg_shift; 116 - bool has_slave; 117 118 int (*setup)(struct exar8250 *, struct pci_dev *, 118 119 struct uart_8250_port *, int); 119 120 void (*exit)(struct pci_dev *pcidev); ··· 273 272 return 0; 274 273 } 275 274 275 + static int generic_rs485_config(struct uart_port *port, 276 + struct serial_rs485 *rs485) 277 + { 278 + bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED); 279 + u8 __iomem *p = port->membase; 280 + u8 value; 281 + 282 + value = readb(p + UART_EXAR_FCTR); 283 + if (is_rs485) 284 + value |= UART_FCTR_EXAR_485; 285 + else 286 + value &= ~UART_FCTR_EXAR_485; 287 + 288 + writeb(value, p + UART_EXAR_FCTR); 289 + 290 + if (is_rs485) 291 + writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR); 292 + 293 + port->rs485 = *rs485; 294 + 295 + return 0; 296 + } 297 + 276 298 static const struct exar8250_platform exar8250_default_platform = { 277 299 .register_gpio = xr17v35x_register_gpio, 300 + .rs485_config = generic_rs485_config, 278 301 }; 279 302 280 303 static int iot2040_rs485_config(struct uart_port *port, ··· 331 306 value |= mode; 332 307 writeb(value, p + UART_EXAR_MPIOLVL_7_0); 333 308 334 - value = readb(p + UART_EXAR_FCTR); 335 - if (is_rs485) 336 - value |= UART_FCTR_EXAR_485; 337 - else 338 - value &= ~UART_FCTR_EXAR_485; 339 - writeb(value, p + UART_EXAR_FCTR); 340 - 341 - if (is_rs485) 342 - writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR); 343 - 344 - port->rs485 = *rs485; 345 - 346 - return 0; 309 + return generic_rs485_config(port, rs485); 347 310 } 348 311 349 312 static const struct property_entry iot2040_gpio_properties[] = { ··· 377 364 pci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev, 378 365 struct uart_8250_port *port, int idx) 379 366 { 380 - const struct exar8250_board *board = priv->board; 381 367 const struct exar8250_platform *platform; 382 368 const struct dmi_system_id *dmi_match; 383 369 unsigned int offset = idx * 0x400; ··· 394 382 port->port.rs485_config = platform->rs485_config; 395 383 396 384 /* 397 - * Setup the uart clock for the devices on expansion slot to 385 + * Setup the UART clock for the devices on expansion slot to 398 386 * half the clock speed of the main chip (which is 125MHz) 399 387 */ 400 - if (board->has_slave && idx >= 8) 388 + if (idx >= 8) 401 389 port->port.uartclk /= 2; 402 390 403 391 ret = default_setup(priv, pcidev, idx, offset, port); ··· 445 433 struct exar8250 *priv = data; 446 434 447 435 /* Clear all PCI interrupts by reading INT0. No effect on IIR */ 448 - ioread8(priv->virt + UART_EXAR_INT0); 436 + readb(priv->virt + UART_EXAR_INT0); 437 + 438 + /* Clear INT0 for Expansion Interface slave ports, too */ 439 + if (priv->board->num_ports > 8) 440 + readb(priv->virt + 0x2000 + UART_EXAR_INT0); 449 441 450 442 return IRQ_HANDLED; 451 443 } ··· 606 590 607 591 static const struct exar8250_board pbn_exar_XR17V4358 = { 608 592 .num_ports = 12, 609 - .has_slave = true, 610 593 .setup = pci_xr17v35x_setup, 611 594 .exit = pci_xr17v35x_exit, 612 595 }; 613 596 614 597 static const struct exar8250_board pbn_exar_XR17V8358 = { 615 598 .num_ports = 16, 616 - .has_slave = true, 617 599 .setup = pci_xr17v35x_setup, 618 600 .exit = pci_xr17v35x_exit, 619 601 };
+5 -1
drivers/tty/serial/8250/8250_of.c
··· 124 124 dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n", 125 125 prop); 126 126 ret = -EINVAL; 127 - goto err_dispose; 127 + goto err_unprepare; 128 128 } 129 129 } 130 130 port->flags |= UPF_IOREMAP; ··· 144 144 port->line = ret; 145 145 146 146 port->irq = irq_of_parse_and_map(np, 0); 147 + if (!port->irq) { 148 + ret = -EPROBE_DEFER; 149 + goto err_unprepare; 150 + } 147 151 148 152 info->rst = devm_reset_control_get_optional_shared(&ofdev->dev, NULL); 149 153 if (IS_ERR(info->rst)) {
+1
drivers/tty/serial/8250/8250_omap.c
··· 1115 1115 static const u8 dra742_habit = UART_ERRATA_CLOCK_DISABLE; 1116 1116 1117 1117 static const struct of_device_id omap8250_dt_ids[] = { 1118 + { .compatible = "ti,am654-uart" }, 1118 1119 { .compatible = "ti,omap2-uart" }, 1119 1120 { .compatible = "ti,omap3-uart" }, 1120 1121 { .compatible = "ti,omap4-uart", .data = &omap4_habit, },
+40 -23
drivers/tty/serial/8250/8250_port.c
··· 90 90 .name = "16550A", 91 91 .fifo_size = 16, 92 92 .tx_loadsz = 16, 93 - .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | 94 - UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT, 93 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 95 94 .rxtrig_bytes = {1, 4, 8, 14}, 96 95 .flags = UART_CAP_FIFO, 97 96 }, ··· 1210 1211 if (!port->iobase && !port->mapbase && !port->membase) 1211 1212 return; 1212 1213 1213 - DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04lx, 0x%p): ", 1214 - serial_index(port), port->iobase, port->membase); 1214 + DEBUG_AUTOCONF("%s: autoconf (0x%04lx, 0x%p): ", 1215 + port->name, port->iobase, port->membase); 1215 1216 1216 1217 /* 1217 1218 * We really do need global IRQs disabled here - we're going to ··· 1362 1363 fintek_8250_probe(up); 1363 1364 1364 1365 if (up->capabilities != old_capabilities) { 1365 - pr_warn("ttyS%d: detected caps %08x should be %08x\n", 1366 - serial_index(port), old_capabilities, 1367 - up->capabilities); 1366 + pr_warn("%s: detected caps %08x should be %08x\n", 1367 + port->name, old_capabilities, up->capabilities); 1368 1368 } 1369 1369 out: 1370 1370 DEBUG_AUTOCONF("iir=%d ", scratch); ··· 2210 2212 */ 2211 2213 if (!(port->flags & UPF_BUGGY_UART) && 2212 2214 (serial_port_in(port, UART_LSR) == 0xff)) { 2213 - printk_ratelimited(KERN_INFO "ttyS%d: LSR safety check engaged!\n", 2214 - serial_index(port)); 2215 + pr_info_ratelimited("%s: LSR safety check engaged!\n", port->name); 2215 2216 retval = -ENODEV; 2216 2217 goto out; 2217 2218 } ··· 2242 2245 (port->type == PORT_ALTR_16550_F128)) && (port->fifosize > 1)) { 2243 2246 /* Bounds checking of TX threshold (valid 0 to fifosize-2) */ 2244 2247 if ((up->tx_loadsz < 2) || (up->tx_loadsz > port->fifosize)) { 2245 - pr_err("ttyS%d TX FIFO Threshold errors, skipping\n", 2246 - serial_index(port)); 2248 + pr_err("%s TX FIFO Threshold errors, skipping\n", 2249 + port->name); 2247 2250 } else { 2248 2251 serial_port_out(port, UART_ALTR_AFR, 2249 2252 UART_ALTR_EN_TXFIFO_LW); ··· 2340 2343 if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { 2341 2344 if (!(up->bugs & UART_BUG_TXEN)) { 2342 2345 up->bugs |= UART_BUG_TXEN; 2343 - pr_debug("ttyS%d - enabling bad tx status workarounds\n", 2344 - serial_index(port)); 2346 + pr_debug("%s - enabling bad tx status workarounds\n", 2347 + port->name); 2345 2348 } 2346 2349 } else { 2347 2350 up->bugs &= ~UART_BUG_TXEN; ··· 2370 2373 if (up->dma) { 2371 2374 retval = serial8250_request_dma(up); 2372 2375 if (retval) { 2373 - pr_warn_ratelimited("ttyS%d - failed to request DMA\n", 2374 - serial_index(port)); 2376 + pr_warn_ratelimited("%s - failed to request DMA\n", 2377 + port->name); 2375 2378 up->dma = NULL; 2376 2379 } 2377 2380 } ··· 2495 2498 return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2; 2496 2499 } 2497 2500 2498 - static unsigned int serial8250_get_divisor(struct uart_8250_port *up, 2499 - unsigned int baud, 2500 - unsigned int *frac) 2501 + static unsigned int serial8250_do_get_divisor(struct uart_port *port, 2502 + unsigned int baud, 2503 + unsigned int *frac) 2501 2504 { 2502 - struct uart_port *port = &up->port; 2505 + struct uart_8250_port *up = up_to_u8250p(port); 2503 2506 unsigned int quot; 2504 2507 2505 2508 /* ··· 2527 2530 quot++; 2528 2531 2529 2532 return quot; 2533 + } 2534 + 2535 + static unsigned int serial8250_get_divisor(struct uart_port *port, 2536 + unsigned int baud, 2537 + unsigned int *frac) 2538 + { 2539 + if (port->get_divisor) 2540 + return port->get_divisor(port, baud, frac); 2541 + 2542 + return serial8250_do_get_divisor(port, baud, frac); 2530 2543 } 2531 2544 2532 2545 static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, ··· 2577 2570 return cval; 2578 2571 } 2579 2572 2580 - static void serial8250_set_divisor(struct uart_port *port, unsigned int baud, 2581 - unsigned int quot, unsigned int quot_frac) 2573 + void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud, 2574 + unsigned int quot, unsigned int quot_frac) 2582 2575 { 2583 2576 struct uart_8250_port *up = up_to_u8250p(port); 2584 2577 ··· 2608 2601 quot_frac |= serial_port_in(port, 0x2) & 0xf0; 2609 2602 serial_port_out(port, 0x2, quot_frac); 2610 2603 } 2604 + } 2605 + EXPORT_SYMBOL_GPL(serial8250_do_set_divisor); 2606 + 2607 + static void serial8250_set_divisor(struct uart_port *port, unsigned int baud, 2608 + unsigned int quot, unsigned int quot_frac) 2609 + { 2610 + if (port->set_divisor) 2611 + port->set_divisor(port, baud, quot, quot_frac); 2612 + else 2613 + serial8250_do_set_divisor(port, baud, quot, quot_frac); 2611 2614 } 2612 2615 2613 2616 static unsigned int serial8250_get_baud_rate(struct uart_port *port, ··· 2653 2636 cval = serial8250_compute_lcr(up, termios->c_cflag); 2654 2637 2655 2638 baud = serial8250_get_baud_rate(port, termios, old); 2656 - quot = serial8250_get_divisor(up, baud, &frac); 2639 + quot = serial8250_get_divisor(port, baud, &frac); 2657 2640 2658 2641 /* 2659 2642 * Ok, we're now changing the port state. Do it with ··· 3214 3197 termios.c_cflag = port->state->port.tty->termios.c_cflag; 3215 3198 3216 3199 baud = serial8250_get_baud_rate(port, &termios, NULL); 3217 - quot = serial8250_get_divisor(up, baud, &frac); 3200 + quot = serial8250_get_divisor(port, baud, &frac); 3218 3201 3219 3202 serial8250_set_divisor(port, baud, quot, frac); 3220 3203 serial_port_out(port, UART_LCR, up->lcr);
+4 -2
drivers/tty/serial/8250/serial_cs.c
··· 638 638 (link->has_func_id) && 639 639 (link->socket->pcmcia_pfc == 0) && 640 640 ((link->func_id == CISTPL_FUNCID_MULTI) || 641 - (link->func_id == CISTPL_FUNCID_SERIAL))) 642 - pcmcia_loop_config(link, serial_check_for_multi, info); 641 + (link->func_id == CISTPL_FUNCID_SERIAL))) { 642 + if (pcmcia_loop_config(link, serial_check_for_multi, info)) 643 + goto failed; 644 + } 643 645 644 646 /* 645 647 * Apply any multi-port quirk.
+3 -2
drivers/tty/serial/imx.c
··· 314 314 /* 315 315 * UCR2_SRST is the only bit in the cached registers that might 316 316 * differ from the value that was last written. As it only 317 - * clears after being set, reread conditionally. 317 + * automatically becomes one after being cleared, reread 318 + * conditionally. 318 319 */ 319 320 if (!(sport->ucr2 & UCR2_SRST)) 320 321 sport->ucr2 = readl(sport->port.membase + offset); ··· 1052 1051 unsigned int r_bytes; 1053 1052 unsigned int bd_size; 1054 1053 1055 - status = dmaengine_tx_status(chan, (dma_cookie_t)0, &state); 1054 + status = dmaengine_tx_status(chan, sport->rx_cookie, &state); 1056 1055 1057 1056 if (status == DMA_ERROR) { 1058 1057 imx_uart_clear_rx_errors(sport);
+1 -2
drivers/tty/serial/jsm/jsm_tty.c
··· 430 430 { 431 431 int i, rc; 432 432 unsigned int line; 433 - struct jsm_channel *ch; 434 433 435 434 if (!brd) 436 435 return -ENXIO; ··· 443 444 brd->nasync = brd->maxports; 444 445 445 446 /* Set up channel variables */ 446 - for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) { 447 + for (i = 0; i < brd->nasync; i++) { 447 448 448 449 if (!brd->channels[i]) 449 450 continue;
+10 -4
drivers/tty/serial/max310x.c
··· 531 531 return 1; 532 532 } 533 533 534 - static int max310x_set_ref_clk(struct max310x_port *s, unsigned long freq, 535 - bool xtal) 534 + static int max310x_set_ref_clk(struct device *dev, struct max310x_port *s, 535 + unsigned long freq, bool xtal) 536 536 { 537 537 unsigned int div, clksrc, pllcfg = 0; 538 538 long besterr = -1; ··· 588 588 regmap_write(s->regmap, MAX310X_CLKSRC_REG, clksrc); 589 589 590 590 /* Wait for crystal */ 591 - if (pllcfg && xtal) 591 + if (xtal) { 592 + unsigned int val; 592 593 msleep(10); 594 + regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val); 595 + if (!(val & MAX310X_STS_CLKREADY_BIT)) { 596 + dev_warn(dev, "clock is not stable yet\n"); 597 + } 598 + } 593 599 594 600 return (int)bestfreq; 595 601 } ··· 1266 1260 MAX310X_MODE1_AUTOSLEEP_BIT); 1267 1261 } 1268 1262 1269 - uartclk = max310x_set_ref_clk(s, freq, xtal); 1263 + uartclk = max310x_set_ref_clk(dev, s, freq, xtal); 1270 1264 dev_dbg(dev, "Reference clock set to %i Hz\n", uartclk); 1271 1265 1272 1266 mutex_init(&s->mutex);
+2 -1
drivers/tty/serial/pxa.c
··· 887 887 goto err_clk; 888 888 if (sport->port.line >= ARRAY_SIZE(serial_pxa_ports)) { 889 889 dev_err(&dev->dev, "serial%d out of range\n", sport->port.line); 890 - return -EINVAL; 890 + ret = -EINVAL; 891 + goto err_clk; 891 892 } 892 893 snprintf(sport->name, PXA_NAME_LEN - 1, "UART%d", sport->port.line + 1); 893 894
+231 -32
drivers/tty/serial/qcom_geni_serial.c
··· 17 17 #include <linux/tty_flip.h> 18 18 19 19 /* UART specific GENI registers */ 20 + #define SE_UART_LOOPBACK_CFG 0x22c 20 21 #define SE_UART_TX_TRANS_CFG 0x25c 21 22 #define SE_UART_TX_WORD_LEN 0x268 22 23 #define SE_UART_TX_STOP_BIT_LEN 0x26c ··· 27 26 #define SE_UART_RX_STALE_CNT 0x294 28 27 #define SE_UART_TX_PARITY_CFG 0x2a4 29 28 #define SE_UART_RX_PARITY_CFG 0x2a8 29 + #define SE_UART_MANUAL_RFR 0x2ac 30 30 31 31 /* SE_UART_TRANS_CFG */ 32 32 #define UART_TX_PAR_EN BIT(0) ··· 64 62 #define PAR_SPACE 0x10 65 63 #define PAR_MARK 0x11 66 64 65 + /* SE_UART_MANUAL_RFR register fields */ 66 + #define UART_MANUAL_RFR_EN BIT(31) 67 + #define UART_RFR_NOT_READY BIT(1) 68 + #define UART_RFR_READY BIT(0) 69 + 67 70 /* UART M_CMD OP codes */ 68 71 #define UART_START_TX 0x1 69 72 #define UART_START_BREAK 0x4 ··· 81 74 #define STALE_TIMEOUT 16 82 75 #define DEFAULT_BITS_PER_CHAR 10 83 76 #define GENI_UART_CONS_PORTS 1 77 + #define GENI_UART_PORTS 3 84 78 #define DEF_FIFO_DEPTH_WORDS 16 85 79 #define DEF_TX_WM 2 86 80 #define DEF_FIFO_WIDTH_BITS 32 87 81 #define UART_CONSOLE_RX_WM 2 82 + #define MAX_LOOPBACK_CFG 3 88 83 89 84 #ifdef CONFIG_CONSOLE_POLL 90 85 #define RX_BYTES_PW 1 ··· 110 101 unsigned int baud; 111 102 unsigned int tx_bytes_pw; 112 103 unsigned int rx_bytes_pw; 104 + u32 *rx_fifo; 105 + u32 loopback; 113 106 bool brk; 114 107 }; 115 108 116 109 static const struct uart_ops qcom_geni_console_pops; 110 + static const struct uart_ops qcom_geni_uart_pops; 117 111 static struct uart_driver qcom_geni_console_driver; 112 + static struct uart_driver qcom_geni_uart_driver; 118 113 static int handle_rx_console(struct uart_port *uport, u32 bytes, bool drop); 114 + static int handle_rx_uart(struct uart_port *uport, u32 bytes, bool drop); 119 115 static unsigned int qcom_geni_serial_tx_empty(struct uart_port *port); 120 116 static void qcom_geni_serial_stop_rx(struct uart_port *uport); 121 117 122 118 static const unsigned long root_freq[] = {7372800, 14745600, 19200000, 29491200, 123 119 32000000, 48000000, 64000000, 80000000, 124 - 96000000, 100000000}; 120 + 96000000, 100000000, 102400000, 121 + 112000000, 120000000, 128000000}; 125 122 126 123 #define to_dev_port(ptr, member) \ 127 124 container_of(ptr, struct qcom_geni_serial_port, member) 125 + 126 + static struct qcom_geni_serial_port qcom_geni_uart_ports[GENI_UART_PORTS] = { 127 + [0] = { 128 + .uport = { 129 + .iotype = UPIO_MEM, 130 + .ops = &qcom_geni_uart_pops, 131 + .flags = UPF_BOOT_AUTOCONF, 132 + .line = 0, 133 + }, 134 + }, 135 + [1] = { 136 + .uport = { 137 + .iotype = UPIO_MEM, 138 + .ops = &qcom_geni_uart_pops, 139 + .flags = UPF_BOOT_AUTOCONF, 140 + .line = 1, 141 + }, 142 + }, 143 + [2] = { 144 + .uport = { 145 + .iotype = UPIO_MEM, 146 + .ops = &qcom_geni_uart_pops, 147 + .flags = UPF_BOOT_AUTOCONF, 148 + .line = 2, 149 + }, 150 + }, 151 + }; 152 + 153 + static ssize_t loopback_show(struct device *dev, 154 + struct device_attribute *attr, char *buf) 155 + { 156 + struct platform_device *pdev = to_platform_device(dev); 157 + struct qcom_geni_serial_port *port = platform_get_drvdata(pdev); 158 + 159 + return snprintf(buf, sizeof(u32), "%d\n", port->loopback); 160 + } 161 + 162 + static ssize_t loopback_store(struct device *dev, 163 + struct device_attribute *attr, const char *buf, 164 + size_t size) 165 + { 166 + struct platform_device *pdev = to_platform_device(dev); 167 + struct qcom_geni_serial_port *port = platform_get_drvdata(pdev); 168 + u32 loopback; 169 + 170 + if (kstrtoint(buf, 0, &loopback) || loopback > MAX_LOOPBACK_CFG) { 171 + dev_err(dev, "Invalid input\n"); 172 + return -EINVAL; 173 + } 174 + port->loopback = loopback; 175 + return size; 176 + } 177 + static DEVICE_ATTR_RW(loopback); 128 178 129 179 static struct qcom_geni_serial_port qcom_geni_console_port = { 130 180 .uport = { ··· 216 148 } 217 149 } 218 150 219 - static unsigned int qcom_geni_cons_get_mctrl(struct uart_port *uport) 151 + static unsigned int qcom_geni_serial_get_mctrl(struct uart_port *uport) 220 152 { 221 - return TIOCM_DSR | TIOCM_CAR | TIOCM_CTS; 153 + unsigned int mctrl = TIOCM_DSR | TIOCM_CAR; 154 + u32 geni_ios; 155 + 156 + if (uart_console(uport) || !uart_cts_enabled(uport)) { 157 + mctrl |= TIOCM_CTS; 158 + } else { 159 + geni_ios = readl_relaxed(uport->membase + SE_GENI_IOS); 160 + if (!(geni_ios & IO2_DATA_IN)) 161 + mctrl |= TIOCM_CTS; 162 + } 163 + 164 + return mctrl; 222 165 } 223 166 224 - static void qcom_geni_cons_set_mctrl(struct uart_port *uport, 167 + static void qcom_geni_serial_set_mctrl(struct uart_port *uport, 225 168 unsigned int mctrl) 226 169 { 170 + u32 uart_manual_rfr = 0; 171 + 172 + if (uart_console(uport) || !uart_cts_enabled(uport)) 173 + return; 174 + 175 + if (!(mctrl & TIOCM_RTS)) 176 + uart_manual_rfr = UART_MANUAL_RFR_EN | UART_RFR_NOT_READY; 177 + writel_relaxed(uart_manual_rfr, uport->membase + SE_UART_MANUAL_RFR); 227 178 } 228 179 229 180 static const char *qcom_geni_serial_get_type(struct uart_port *uport) ··· 250 163 return "MSM"; 251 164 } 252 165 253 - static struct qcom_geni_serial_port *get_port_from_line(int line) 166 + static struct qcom_geni_serial_port *get_port_from_line(int line, bool console) 254 167 { 255 - if (line < 0 || line >= GENI_UART_CONS_PORTS) 168 + struct qcom_geni_serial_port *port; 169 + int nr_ports = console ? GENI_UART_CONS_PORTS : GENI_UART_PORTS; 170 + 171 + if (line < 0 || line >= nr_ports) 256 172 return ERR_PTR(-ENXIO); 257 - return &qcom_geni_console_port; 173 + 174 + port = console ? &qcom_geni_console_port : &qcom_geni_uart_ports[line]; 175 + return port; 258 176 } 259 177 260 178 static bool qcom_geni_serial_poll_bit(struct uart_port *uport, ··· 438 346 439 347 WARN_ON(co->index < 0 || co->index >= GENI_UART_CONS_PORTS); 440 348 441 - port = get_port_from_line(co->index); 349 + port = get_port_from_line(co->index, true); 442 350 if (IS_ERR(port)) 443 351 return; 444 352 ··· 511 419 } 512 420 513 421 #endif /* CONFIG_SERIAL_QCOM_GENI_CONSOLE */ 422 + 423 + static int handle_rx_uart(struct uart_port *uport, u32 bytes, bool drop) 424 + { 425 + unsigned char *buf; 426 + struct tty_port *tport; 427 + struct qcom_geni_serial_port *port = to_dev_port(uport, uport); 428 + u32 num_bytes_pw = port->tx_fifo_width / BITS_PER_BYTE; 429 + u32 words = ALIGN(bytes, num_bytes_pw) / num_bytes_pw; 430 + int ret; 431 + 432 + tport = &uport->state->port; 433 + ioread32_rep(uport->membase + SE_GENI_RX_FIFOn, port->rx_fifo, words); 434 + if (drop) 435 + return 0; 436 + 437 + buf = (unsigned char *)port->rx_fifo; 438 + ret = tty_insert_flip_string(tport, buf, bytes); 439 + if (ret != bytes) { 440 + dev_err(uport->dev, "%s:Unable to push data ret %d_bytes %d\n", 441 + __func__, ret, bytes); 442 + WARN_ON_ONCE(1); 443 + } 444 + uport->icount.rx += ret; 445 + tty_flip_buffer_push(tport); 446 + return ret; 447 + } 514 448 515 449 static void qcom_geni_serial_start_tx(struct uart_port *uport) 516 450 { ··· 704 586 u32 status; 705 587 unsigned int chunk; 706 588 int tail; 589 + u32 irq_en; 707 590 708 591 chunk = uart_circ_chars_pending(xmit); 709 592 status = readl_relaxed(uport->membase + SE_GENI_TX_FIFO_STATUS); ··· 712 593 if (!chunk && !status) { 713 594 qcom_geni_serial_stop_tx(uport); 714 595 goto out_write_wakeup; 596 + } 597 + 598 + if (!uart_console(uport)) { 599 + irq_en = readl_relaxed(uport->membase + SE_GENI_M_IRQ_EN); 600 + irq_en &= ~(M_TX_FIFO_WATERMARK_EN); 601 + writel_relaxed(0, uport->membase + SE_GENI_TX_WATERMARK_REG); 602 + writel_relaxed(irq_en, uport->membase + SE_GENI_M_IRQ_EN); 715 603 } 716 604 717 605 avail = (port->tx_fifo_depth - port->tx_wm) * port->tx_bytes_pw; ··· 749 623 } 750 624 751 625 xmit->tail = tail & (UART_XMIT_SIZE - 1); 752 - qcom_geni_serial_poll_tx_done(uport); 626 + if (uart_console(uport)) 627 + qcom_geni_serial_poll_tx_done(uport); 753 628 out_write_wakeup: 754 629 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 755 630 uart_write_wakeup(uport); ··· 837 710 unsigned long flags; 838 711 839 712 /* Stop the console before stopping the current tx */ 840 - console_stop(uport->cons); 713 + if (uart_console(uport)) 714 + console_stop(uport->cons); 841 715 842 716 free_irq(uport->irq, uport); 843 717 spin_lock_irqsave(&uport->lock, flags); ··· 859 731 * it else we could end up in data loss scenarios. 860 732 */ 861 733 port->xfer_mode = GENI_SE_FIFO; 862 - qcom_geni_serial_poll_tx_done(uport); 734 + if (uart_console(uport)) 735 + qcom_geni_serial_poll_tx_done(uport); 863 736 geni_se_config_packing(&port->se, BITS_PER_BYTE, port->tx_bytes_pw, 864 737 false, true, false); 865 738 geni_se_config_packing(&port->se, BITS_PER_BYTE, port->rx_bytes_pw, 866 739 false, false, true); 867 740 geni_se_init(&port->se, port->rx_wm, port->rx_rfr); 868 741 geni_se_select_mode(&port->se, port->xfer_mode); 742 + if (!uart_console(uport)) { 743 + port->rx_fifo = devm_kzalloc(uport->dev, 744 + port->rx_fifo_depth * sizeof(u32), GFP_KERNEL); 745 + if (!port->rx_fifo) 746 + return -ENOMEM; 747 + } 869 748 port->setup = true; 870 749 return 0; 871 750 } ··· 884 749 struct qcom_geni_serial_port *port = to_dev_port(uport, uport); 885 750 886 751 scnprintf(port->name, sizeof(port->name), 887 - "qcom_serial_geni%d", uport->line); 752 + "qcom_serial_%s%d", 753 + (uart_console(uport) ? "console" : "uart"), uport->line); 888 754 755 + if (!uart_console(uport)) { 756 + port->tx_bytes_pw = 4; 757 + port->rx_bytes_pw = RX_BYTES_PW; 758 + } 889 759 proto = geni_se_read_proto(&port->se); 890 760 if (proto != GENI_SE_UART) { 891 761 dev_err(uport->dev, "Invalid FW loaded, proto: %d\n", proto); ··· 1026 886 if (baud) 1027 887 uart_update_timeout(uport, termios->c_cflag, baud); 1028 888 889 + if (!uart_console(uport)) 890 + writel_relaxed(port->loopback, 891 + uport->membase + SE_UART_LOOPBACK_CFG); 1029 892 writel_relaxed(tx_trans_cfg, uport->membase + SE_UART_TX_TRANS_CFG); 1030 893 writel_relaxed(tx_parity_cfg, uport->membase + SE_UART_TX_PARITY_CFG); 1031 894 writel_relaxed(rx_trans_cfg, uport->membase + SE_UART_RX_TRANS_CFG); ··· 1060 917 if (co->index >= GENI_UART_CONS_PORTS || co->index < 0) 1061 918 return -ENXIO; 1062 919 1063 - port = get_port_from_line(co->index); 920 + port = get_port_from_line(co->index, true); 1064 921 if (IS_ERR(port)) { 1065 922 pr_err("Invalid line %d\n", co->index); 1066 923 return PTR_ERR(port); ··· 1191 1048 } 1192 1049 #endif /* CONFIG_SERIAL_QCOM_GENI_CONSOLE */ 1193 1050 1194 - static void qcom_geni_serial_cons_pm(struct uart_port *uport, 1051 + static struct uart_driver qcom_geni_uart_driver = { 1052 + .owner = THIS_MODULE, 1053 + .driver_name = "qcom_geni_uart", 1054 + .dev_name = "ttyHS", 1055 + .nr = GENI_UART_PORTS, 1056 + }; 1057 + 1058 + static void qcom_geni_serial_pm(struct uart_port *uport, 1195 1059 unsigned int new_state, unsigned int old_state) 1196 1060 { 1197 1061 struct qcom_geni_serial_port *port = to_dev_port(uport, uport); 1198 1062 1199 - if (unlikely(!uart_console(uport))) 1200 - return; 1201 - 1202 1063 if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF) 1064 + geni_se_resources_on(&port->se); 1065 + else if (!uart_console(uport) && (new_state == UART_PM_STATE_ON && 1066 + old_state == UART_PM_STATE_UNDEFINED)) 1203 1067 geni_se_resources_on(&port->se); 1204 1068 else if (new_state == UART_PM_STATE_OFF && 1205 1069 old_state == UART_PM_STATE_ON) ··· 1224 1074 .config_port = qcom_geni_serial_config_port, 1225 1075 .shutdown = qcom_geni_serial_shutdown, 1226 1076 .type = qcom_geni_serial_get_type, 1227 - .set_mctrl = qcom_geni_cons_set_mctrl, 1228 - .get_mctrl = qcom_geni_cons_get_mctrl, 1077 + .set_mctrl = qcom_geni_serial_set_mctrl, 1078 + .get_mctrl = qcom_geni_serial_get_mctrl, 1229 1079 #ifdef CONFIG_CONSOLE_POLL 1230 1080 .poll_get_char = qcom_geni_serial_get_char, 1231 1081 .poll_put_char = qcom_geni_serial_poll_put_char, 1232 1082 #endif 1233 - .pm = qcom_geni_serial_cons_pm, 1083 + .pm = qcom_geni_serial_pm, 1084 + }; 1085 + 1086 + static const struct uart_ops qcom_geni_uart_pops = { 1087 + .tx_empty = qcom_geni_serial_tx_empty, 1088 + .stop_tx = qcom_geni_serial_stop_tx, 1089 + .start_tx = qcom_geni_serial_start_tx, 1090 + .stop_rx = qcom_geni_serial_stop_rx, 1091 + .set_termios = qcom_geni_serial_set_termios, 1092 + .startup = qcom_geni_serial_startup, 1093 + .request_port = qcom_geni_serial_request_port, 1094 + .config_port = qcom_geni_serial_config_port, 1095 + .shutdown = qcom_geni_serial_shutdown, 1096 + .type = qcom_geni_serial_get_type, 1097 + .set_mctrl = qcom_geni_serial_set_mctrl, 1098 + .get_mctrl = qcom_geni_serial_get_mctrl, 1099 + .pm = qcom_geni_serial_pm, 1234 1100 }; 1235 1101 1236 1102 static int qcom_geni_serial_probe(struct platform_device *pdev) ··· 1257 1091 struct uart_port *uport; 1258 1092 struct resource *res; 1259 1093 int irq; 1094 + bool console = false; 1095 + struct uart_driver *drv; 1260 1096 1261 - if (pdev->dev.of_node) 1262 - line = of_alias_get_id(pdev->dev.of_node, "serial"); 1097 + if (of_device_is_compatible(pdev->dev.of_node, "qcom,geni-debug-uart")) 1098 + console = true; 1263 1099 1264 - if (line < 0 || line >= GENI_UART_CONS_PORTS) 1265 - return -ENXIO; 1266 - port = get_port_from_line(line); 1100 + if (pdev->dev.of_node) { 1101 + if (console) { 1102 + drv = &qcom_geni_console_driver; 1103 + line = of_alias_get_id(pdev->dev.of_node, "serial"); 1104 + } else { 1105 + drv = &qcom_geni_uart_driver; 1106 + line = of_alias_get_id(pdev->dev.of_node, "hsuart"); 1107 + } 1108 + } 1109 + 1110 + port = get_port_from_line(line, console); 1267 1111 if (IS_ERR(port)) { 1268 1112 dev_err(&pdev->dev, "Invalid line %d\n", line); 1269 1113 return PTR_ERR(port); ··· 1310 1134 } 1311 1135 uport->irq = irq; 1312 1136 1313 - uport->private_data = &qcom_geni_console_driver; 1137 + uport->private_data = drv; 1314 1138 platform_set_drvdata(pdev, port); 1315 - port->handle_rx = handle_rx_console; 1316 - return uart_add_one_port(&qcom_geni_console_driver, uport); 1139 + port->handle_rx = console ? handle_rx_console : handle_rx_uart; 1140 + if (!console) 1141 + device_create_file(uport->dev, &dev_attr_loopback); 1142 + return uart_add_one_port(drv, uport); 1317 1143 } 1318 1144 1319 1145 static int qcom_geni_serial_remove(struct platform_device *pdev) ··· 1332 1154 struct qcom_geni_serial_port *port = dev_get_drvdata(dev); 1333 1155 struct uart_port *uport = &port->uport; 1334 1156 1335 - uart_suspend_port(uport->private_data, uport); 1157 + if (uart_console(uport)) { 1158 + uart_suspend_port(uport->private_data, uport); 1159 + } else { 1160 + struct uart_state *state = uport->state; 1161 + /* 1162 + * If the port is open, deny system suspend. 1163 + */ 1164 + if (state->pm_state == UART_PM_STATE_ON) 1165 + return -EBUSY; 1166 + } 1167 + 1336 1168 return 0; 1337 1169 } 1338 1170 ··· 1351 1163 struct qcom_geni_serial_port *port = dev_get_drvdata(dev); 1352 1164 struct uart_port *uport = &port->uport; 1353 1165 1354 - if (console_suspend_enabled && uport->suspended) { 1166 + if (uart_console(uport) && 1167 + console_suspend_enabled && uport->suspended) { 1355 1168 uart_resume_port(uport->private_data, uport); 1356 1169 /* 1357 1170 * uart_suspend_port() invokes port shutdown which in turn ··· 1374 1185 1375 1186 static const struct of_device_id qcom_geni_serial_match_table[] = { 1376 1187 { .compatible = "qcom,geni-debug-uart", }, 1188 + { .compatible = "qcom,geni-uart", }, 1377 1189 {} 1378 1190 }; 1379 1191 MODULE_DEVICE_TABLE(of, qcom_geni_serial_match_table); ··· 1397 1207 if (ret) 1398 1208 return ret; 1399 1209 1400 - ret = platform_driver_register(&qcom_geni_serial_platform_driver); 1401 - if (ret) 1210 + ret = uart_register_driver(&qcom_geni_uart_driver); 1211 + if (ret) { 1402 1212 console_unregister(&qcom_geni_console_driver); 1213 + return ret; 1214 + } 1215 + 1216 + ret = platform_driver_register(&qcom_geni_serial_platform_driver); 1217 + if (ret) { 1218 + console_unregister(&qcom_geni_console_driver); 1219 + uart_unregister_driver(&qcom_geni_uart_driver); 1220 + } 1403 1221 return ret; 1404 1222 } 1405 1223 module_init(qcom_geni_serial_init); ··· 1416 1218 { 1417 1219 platform_driver_unregister(&qcom_geni_serial_platform_driver); 1418 1220 console_unregister(&qcom_geni_console_driver); 1221 + uart_unregister_driver(&qcom_geni_uart_driver); 1419 1222 } 1420 1223 module_exit(qcom_geni_serial_exit); 1421 1224
+12 -5
drivers/tty/serial/serial_core.c
··· 182 182 { 183 183 struct uart_port *uport = uart_port_check(state); 184 184 unsigned long page; 185 + unsigned long flags = 0; 185 186 int retval = 0; 186 187 187 188 if (uport->type == PORT_UNKNOWN) ··· 197 196 * Initialise and allocate the transmit and temporary 198 197 * buffer. 199 198 */ 200 - if (!state->xmit.buf) { 201 - /* This is protected by the per port mutex */ 202 - page = get_zeroed_page(GFP_KERNEL); 203 - if (!page) 204 - return -ENOMEM; 199 + page = get_zeroed_page(GFP_KERNEL); 200 + if (!page) 201 + return -ENOMEM; 205 202 203 + uart_port_lock(state, flags); 204 + if (!state->xmit.buf) { 206 205 state->xmit.buf = (unsigned char *) page; 207 206 uart_circ_clear(&state->xmit); 207 + } else { 208 + free_page(page); 208 209 } 210 + uart_port_unlock(uport, flags); 209 211 210 212 retval = uport->ops->startup(uport); 211 213 if (retval == 0) { ··· 267 263 { 268 264 struct uart_port *uport = uart_port_check(state); 269 265 struct tty_port *port = &state->port; 266 + unsigned long flags = 0; 270 267 271 268 /* 272 269 * Set the TTY IO error marker ··· 300 295 /* 301 296 * Free the transmit buffer page. 302 297 */ 298 + uart_port_lock(state, flags); 303 299 if (state->xmit.buf) { 304 300 free_page((unsigned long)state->xmit.buf); 305 301 state->xmit.buf = NULL; 306 302 } 303 + uart_port_unlock(uport, flags); 307 304 } 308 305 309 306 /**
+114 -77
drivers/tty/serial/sh-sci.c
··· 65 65 SCIx_RXI_IRQ, 66 66 SCIx_TXI_IRQ, 67 67 SCIx_BRI_IRQ, 68 + SCIx_DRI_IRQ, 69 + SCIx_TEI_IRQ, 68 70 SCIx_NR_IRQS, 69 71 70 72 SCIx_MUX_IRQ = SCIx_NR_IRQS, /* special case */ ··· 137 135 struct dma_chan *chan_rx; 138 136 139 137 #ifdef CONFIG_SERIAL_SH_SCI_DMA 138 + struct dma_chan *chan_tx_saved; 139 + struct dma_chan *chan_rx_saved; 140 140 dma_cookie_t cookie_tx; 141 141 dma_cookie_t cookie_rx[2]; 142 142 dma_cookie_t active_rx; ··· 319 315 [SCIx_SH4_SCIF_REGTYPE] = { 320 316 .regs = { 321 317 [SCSMR] = { 0x00, 16 }, 322 - [SCBRR] = { 0x04, 8 }, 323 - [SCSCR] = { 0x08, 16 }, 324 - [SCxTDR] = { 0x0c, 8 }, 325 - [SCxSR] = { 0x10, 16 }, 326 - [SCxRDR] = { 0x14, 8 }, 327 - [SCFCR] = { 0x18, 16 }, 328 - [SCFDR] = { 0x1c, 16 }, 329 - [SCSPTR] = { 0x20, 16 }, 330 - [SCLSR] = { 0x24, 16 }, 318 + [SCBRR] = { 0x02, 8 }, 319 + [SCSCR] = { 0x04, 16 }, 320 + [SCxTDR] = { 0x06, 8 }, 321 + [SCxSR] = { 0x08, 16 }, 322 + [SCxRDR] = { 0x0a, 8 }, 323 + [SCFCR] = { 0x0c, 16 }, 324 + [SCFDR] = { 0x0e, 16 }, 325 + [SCSPTR] = { 0x10, 16 }, 326 + [SCLSR] = { 0x12, 16 }, 331 327 }, 332 328 .fifosize = 16, 333 329 .overrun_reg = SCLSR, ··· 1216 1212 return -1; 1217 1213 } 1218 1214 1219 - static void sci_rx_dma_release(struct sci_port *s, bool enable_pio) 1215 + static void sci_rx_dma_release(struct sci_port *s) 1220 1216 { 1221 - struct dma_chan *chan = s->chan_rx; 1222 - struct uart_port *port = &s->port; 1223 - unsigned long flags; 1217 + struct dma_chan *chan = s->chan_rx_saved; 1224 1218 1225 - spin_lock_irqsave(&port->lock, flags); 1226 - s->chan_rx = NULL; 1219 + s->chan_rx_saved = s->chan_rx = NULL; 1227 1220 s->cookie_rx[0] = s->cookie_rx[1] = -EINVAL; 1228 - spin_unlock_irqrestore(&port->lock, flags); 1229 - dmaengine_terminate_all(chan); 1221 + dmaengine_terminate_sync(chan); 1230 1222 dma_free_coherent(chan->device->dev, s->buf_len_rx * 2, s->rx_buf[0], 1231 1223 sg_dma_address(&s->sg_rx[0])); 1232 1224 dma_release_channel(chan); 1233 - if (enable_pio) { 1234 - spin_lock_irqsave(&port->lock, flags); 1235 - sci_start_rx(port); 1236 - spin_unlock_irqrestore(&port->lock, flags); 1237 - } 1238 1225 } 1239 1226 1240 1227 static void start_hrtimer_us(struct hrtimer *hrt, unsigned long usec) ··· 1284 1289 fail: 1285 1290 spin_unlock_irqrestore(&port->lock, flags); 1286 1291 dev_warn(port->dev, "Failed submitting Rx DMA descriptor\n"); 1287 - sci_rx_dma_release(s, true); 1292 + /* Switch to PIO */ 1293 + spin_lock_irqsave(&port->lock, flags); 1294 + s->chan_rx = NULL; 1295 + sci_start_rx(port); 1296 + spin_unlock_irqrestore(&port->lock, flags); 1288 1297 } 1289 1298 1290 - static void sci_tx_dma_release(struct sci_port *s, bool enable_pio) 1299 + static void sci_tx_dma_release(struct sci_port *s) 1291 1300 { 1292 - struct dma_chan *chan = s->chan_tx; 1293 - struct uart_port *port = &s->port; 1294 - unsigned long flags; 1301 + struct dma_chan *chan = s->chan_tx_saved; 1295 1302 1296 - spin_lock_irqsave(&port->lock, flags); 1297 - s->chan_tx = NULL; 1303 + cancel_work_sync(&s->work_tx); 1304 + s->chan_tx_saved = s->chan_tx = NULL; 1298 1305 s->cookie_tx = -EINVAL; 1299 - spin_unlock_irqrestore(&port->lock, flags); 1300 - dmaengine_terminate_all(chan); 1306 + dmaengine_terminate_sync(chan); 1301 1307 dma_unmap_single(chan->device->dev, s->tx_dma_addr, UART_XMIT_SIZE, 1302 1308 DMA_TO_DEVICE); 1303 1309 dma_release_channel(chan); 1304 - if (enable_pio) { 1305 - spin_lock_irqsave(&port->lock, flags); 1306 - sci_start_tx(port); 1307 - spin_unlock_irqrestore(&port->lock, flags); 1308 - } 1309 1310 } 1310 1311 1311 1312 static void sci_submit_rx(struct sci_port *s) 1312 1313 { 1313 1314 struct dma_chan *chan = s->chan_rx; 1315 + struct uart_port *port = &s->port; 1316 + unsigned long flags; 1314 1317 int i; 1315 1318 1316 1319 for (i = 0; i < 2; i++) { ··· 1336 1343 1337 1344 fail: 1338 1345 if (i) 1339 - dmaengine_terminate_all(chan); 1346 + dmaengine_terminate_async(chan); 1340 1347 for (i = 0; i < 2; i++) 1341 1348 s->cookie_rx[i] = -EINVAL; 1342 1349 s->active_rx = -EINVAL; 1343 - sci_rx_dma_release(s, true); 1350 + /* Switch to PIO */ 1351 + spin_lock_irqsave(&port->lock, flags); 1352 + s->chan_rx = NULL; 1353 + sci_start_rx(port); 1354 + spin_unlock_irqrestore(&port->lock, flags); 1344 1355 } 1345 1356 1346 1357 static void work_fn_tx(struct work_struct *work) ··· 1354 1357 struct dma_chan *chan = s->chan_tx; 1355 1358 struct uart_port *port = &s->port; 1356 1359 struct circ_buf *xmit = &port->state->xmit; 1360 + unsigned long flags; 1357 1361 dma_addr_t buf; 1358 1362 1359 1363 /* ··· 1376 1378 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1377 1379 if (!desc) { 1378 1380 dev_warn(port->dev, "Failed preparing Tx DMA descriptor\n"); 1379 - /* switch to PIO */ 1380 - sci_tx_dma_release(s, true); 1381 - return; 1381 + goto switch_to_pio; 1382 1382 } 1383 1383 1384 1384 dma_sync_single_for_device(chan->device->dev, buf, s->tx_dma_len, ··· 1389 1393 s->cookie_tx = dmaengine_submit(desc); 1390 1394 if (dma_submit_error(s->cookie_tx)) { 1391 1395 dev_warn(port->dev, "Failed submitting Tx DMA descriptor\n"); 1392 - /* switch to PIO */ 1393 - sci_tx_dma_release(s, true); 1394 - return; 1396 + goto switch_to_pio; 1395 1397 } 1396 1398 1397 1399 dev_dbg(port->dev, "%s: %p: %d...%d, cookie %d\n", 1398 1400 __func__, xmit->buf, xmit->tail, xmit->head, s->cookie_tx); 1399 1401 1400 1402 dma_async_issue_pending(chan); 1403 + return; 1404 + 1405 + switch_to_pio: 1406 + spin_lock_irqsave(&port->lock, flags); 1407 + s->chan_tx = NULL; 1408 + sci_start_tx(port); 1409 + spin_unlock_irqrestore(&port->lock, flags); 1410 + return; 1401 1411 } 1402 1412 1403 1413 static enum hrtimer_restart rx_timer_fn(struct hrtimer *t) ··· 1454 1452 } 1455 1453 1456 1454 /* Handle incomplete DMA receive */ 1457 - dmaengine_terminate_all(s->chan_rx); 1455 + dmaengine_terminate_async(s->chan_rx); 1458 1456 read = sg_dma_len(&s->sg_rx[active]) - state.residue; 1459 1457 1460 1458 if (read) { ··· 1537 1535 chan = sci_request_dma_chan(port, DMA_MEM_TO_DEV); 1538 1536 dev_dbg(port->dev, "%s: TX: got channel %p\n", __func__, chan); 1539 1537 if (chan) { 1540 - s->chan_tx = chan; 1541 1538 /* UART circular tx buffer is an aligned page. */ 1542 1539 s->tx_dma_addr = dma_map_single(chan->device->dev, 1543 1540 port->state->xmit.buf, ··· 1545 1544 if (dma_mapping_error(chan->device->dev, s->tx_dma_addr)) { 1546 1545 dev_warn(port->dev, "Failed mapping Tx DMA descriptor\n"); 1547 1546 dma_release_channel(chan); 1548 - s->chan_tx = NULL; 1549 1547 } else { 1550 1548 dev_dbg(port->dev, "%s: mapped %lu@%p to %pad\n", 1551 1549 __func__, UART_XMIT_SIZE, 1552 1550 port->state->xmit.buf, &s->tx_dma_addr); 1553 - } 1554 1551 1555 - INIT_WORK(&s->work_tx, work_fn_tx); 1552 + INIT_WORK(&s->work_tx, work_fn_tx); 1553 + s->chan_tx_saved = s->chan_tx = chan; 1554 + } 1556 1555 } 1557 1556 1558 1557 chan = sci_request_dma_chan(port, DMA_DEV_TO_MEM); ··· 1562 1561 dma_addr_t dma; 1563 1562 void *buf; 1564 1563 1565 - s->chan_rx = chan; 1566 - 1567 1564 s->buf_len_rx = 2 * max_t(size_t, 16, port->fifosize); 1568 1565 buf = dma_alloc_coherent(chan->device->dev, s->buf_len_rx * 2, 1569 1566 &dma, GFP_KERNEL); ··· 1569 1570 dev_warn(port->dev, 1570 1571 "Failed to allocate Rx dma buffer, using PIO\n"); 1571 1572 dma_release_channel(chan); 1572 - s->chan_rx = NULL; 1573 1573 return; 1574 1574 } 1575 1575 ··· 1589 1591 1590 1592 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 1591 1593 sci_submit_rx(s); 1594 + 1595 + s->chan_rx_saved = s->chan_rx = chan; 1592 1596 } 1593 1597 } 1594 1598 ··· 1598 1598 { 1599 1599 struct sci_port *s = to_sci_port(port); 1600 1600 1601 - if (s->chan_tx) 1602 - sci_tx_dma_release(s, false); 1603 - if (s->chan_rx) 1604 - sci_rx_dma_release(s, false); 1601 + if (s->chan_tx_saved) 1602 + sci_tx_dma_release(s); 1603 + if (s->chan_rx_saved) 1604 + sci_rx_dma_release(s); 1605 1605 } 1606 1606 1607 1607 static void sci_flush_buffer(struct uart_port *port) ··· 1683 1683 return IRQ_HANDLED; 1684 1684 } 1685 1685 1686 + static irqreturn_t sci_br_interrupt(int irq, void *ptr) 1687 + { 1688 + struct uart_port *port = ptr; 1689 + 1690 + /* Handle BREAKs */ 1691 + sci_handle_breaks(port); 1692 + sci_clear_SCxSR(port, SCxSR_BREAK_CLEAR(port)); 1693 + 1694 + return IRQ_HANDLED; 1695 + } 1696 + 1686 1697 static irqreturn_t sci_er_interrupt(int irq, void *ptr) 1687 1698 { 1688 1699 struct uart_port *port = ptr; 1689 1700 struct sci_port *s = to_sci_port(port); 1701 + 1702 + if (s->irqs[SCIx_ERI_IRQ] == s->irqs[SCIx_BRI_IRQ]) { 1703 + /* Break and Error interrupts are muxed */ 1704 + unsigned short ssr_status = serial_port_in(port, SCxSR); 1705 + 1706 + /* Break Interrupt */ 1707 + if (ssr_status & SCxSR_BRK(port)) 1708 + sci_br_interrupt(irq, ptr); 1709 + 1710 + /* Break only? */ 1711 + if (!(ssr_status & SCxSR_ERRORS(port))) 1712 + return IRQ_HANDLED; 1713 + } 1690 1714 1691 1715 /* Handle errors */ 1692 1716 if (port->type == PORT_SCI) { ··· 1730 1706 /* Kick the transmission */ 1731 1707 if (!s->chan_tx) 1732 1708 sci_tx_interrupt(irq, ptr); 1733 - 1734 - return IRQ_HANDLED; 1735 - } 1736 - 1737 - static irqreturn_t sci_br_interrupt(int irq, void *ptr) 1738 - { 1739 - struct uart_port *port = ptr; 1740 - 1741 - /* Handle BREAKs */ 1742 - sci_handle_breaks(port); 1743 - sci_clear_SCxSR(port, SCxSR_BREAK_CLEAR(port)); 1744 1709 1745 1710 return IRQ_HANDLED; 1746 1711 } ··· 1807 1794 .handler = sci_br_interrupt, 1808 1795 }, 1809 1796 1797 + [SCIx_DRI_IRQ] = { 1798 + .desc = "rx ready", 1799 + .handler = sci_rx_interrupt, 1800 + }, 1801 + 1802 + [SCIx_TEI_IRQ] = { 1803 + .desc = "tx end", 1804 + .handler = sci_tx_interrupt, 1805 + }, 1806 + 1810 1807 /* 1811 1808 * Special muxed handler. 1812 1809 */ ··· 1829 1806 static int sci_request_irq(struct sci_port *port) 1830 1807 { 1831 1808 struct uart_port *up = &port->port; 1832 - int i, j, ret = 0; 1809 + int i, j, w, ret = 0; 1833 1810 1834 1811 for (i = j = 0; i < SCIx_NR_IRQS; i++, j++) { 1835 1812 const struct sci_irq_desc *desc; 1836 1813 int irq; 1814 + 1815 + /* Check if already registered (muxed) */ 1816 + for (w = 0; w < i; w++) 1817 + if (port->irqs[w] == port->irqs[i]) 1818 + w = i + 1; 1819 + if (w > i) 1820 + continue; 1837 1821 1838 1822 if (SCIx_IRQ_IS_MUXED(port)) { 1839 1823 i = SCIx_MUX_IRQ; ··· 2122 2092 spin_unlock_irqrestore(&port->lock, flags); 2123 2093 2124 2094 #ifdef CONFIG_SERIAL_SH_SCI_DMA 2125 - if (s->chan_rx) { 2095 + if (s->chan_rx_saved) { 2126 2096 dev_dbg(port->dev, "%s(%d) deleting rx_timer\n", __func__, 2127 2097 port->line); 2128 2098 hrtimer_cancel(&s->rx_timer); 2129 2099 } 2130 2100 #endif 2131 2101 2102 + if (s->rx_trigger > 1 && s->rx_fifo_timeout > 0) 2103 + del_timer_sync(&s->rx_fifo_timer); 2132 2104 sci_free_irq(s); 2133 2105 sci_free_dma(port); 2134 2106 } ··· 2810 2778 { 2811 2779 struct uart_port *port = &sci_port->port; 2812 2780 const struct resource *res; 2813 - unsigned int i; 2781 + unsigned int i, regtype; 2814 2782 int ret; 2815 2783 2816 2784 sci_port->cfg = p; ··· 2831 2799 2832 2800 /* The SCI generates several interrupts. They can be muxed together or 2833 2801 * connected to different interrupt lines. In the muxed case only one 2834 - * interrupt resource is specified. In the non-muxed case three or four 2835 - * interrupt resources are specified, as the BRI interrupt is optional. 2802 + * interrupt resource is specified as there is only one interrupt ID. 2803 + * In the non-muxed case, up to 6 interrupt signals might be generated 2804 + * from the SCI, however those signals might have their own individual 2805 + * interrupt ID numbers, or muxed together with another interrupt. 2836 2806 */ 2837 2807 if (sci_port->irqs[0] < 0) 2838 2808 return -ENXIO; 2839 2809 2840 - if (sci_port->irqs[1] < 0) { 2841 - sci_port->irqs[1] = sci_port->irqs[0]; 2842 - sci_port->irqs[2] = sci_port->irqs[0]; 2843 - sci_port->irqs[3] = sci_port->irqs[0]; 2844 - } 2810 + if (sci_port->irqs[1] < 0) 2811 + for (i = 1; i < ARRAY_SIZE(sci_port->irqs); i++) 2812 + sci_port->irqs[i] = sci_port->irqs[0]; 2845 2813 2846 2814 sci_port->params = sci_probe_regmap(p); 2847 2815 if (unlikely(sci_port->params == NULL)) 2848 2816 return -EINVAL; 2849 2817 2818 + regtype = sci_port->params - sci_port_params; 2850 2819 switch (p->type) { 2851 2820 case PORT_SCIFB: 2852 2821 sci_port->rx_trigger = 48; ··· 2901 2868 else 2902 2869 port->regshift = 1; 2903 2870 } 2871 + 2872 + if (regtype == SCIx_SH4_SCIF_REGTYPE) 2873 + if (sci_port->reg_size >= 0x20) 2874 + port->regshift = 1; 2904 2875 2905 2876 /* 2906 2877 * The UART port needs an IRQ value, so we peg this to the RX IRQ
+103 -9
drivers/tty/serial/uartlite.c
··· 21 21 #include <linux/of_address.h> 22 22 #include <linux/of_device.h> 23 23 #include <linux/of_platform.h> 24 + #include <linux/clk.h> 24 25 25 26 #define ULITE_NAME "ttyUL" 26 27 #define ULITE_MAJOR 204 ··· 54 53 #define ULITE_CONTROL_RST_TX 0x01 55 54 #define ULITE_CONTROL_RST_RX 0x02 56 55 #define ULITE_CONTROL_IE 0x10 56 + 57 + struct uartlite_data { 58 + const struct uartlite_reg_ops *reg_ops; 59 + struct clk *clk; 60 + }; 57 61 58 62 struct uartlite_reg_ops { 59 63 u32 (*in)(void __iomem *addr); ··· 97 91 98 92 static inline u32 uart_in32(u32 offset, struct uart_port *port) 99 93 { 100 - const struct uartlite_reg_ops *reg_ops = port->private_data; 94 + struct uartlite_data *pdata = port->private_data; 101 95 102 - return reg_ops->in(port->membase + offset); 96 + return pdata->reg_ops->in(port->membase + offset); 103 97 } 104 98 105 99 static inline void uart_out32(u32 val, u32 offset, struct uart_port *port) 106 100 { 107 - const struct uartlite_reg_ops *reg_ops = port->private_data; 101 + struct uartlite_data *pdata = port->private_data; 108 102 109 - reg_ops->out(val, port->membase + offset); 103 + pdata->reg_ops->out(val, port->membase + offset); 110 104 } 111 105 112 106 static struct uart_port ulite_ports[ULITE_NR_UARTS]; ··· 263 257 264 258 static int ulite_startup(struct uart_port *port) 265 259 { 260 + struct uartlite_data *pdata = port->private_data; 266 261 int ret; 262 + 263 + ret = clk_enable(pdata->clk); 264 + if (ret) { 265 + dev_err(port->dev, "Failed to enable clock\n"); 266 + return ret; 267 + } 267 268 268 269 ret = request_irq(port->irq, ulite_isr, IRQF_SHARED | IRQF_TRIGGER_RISING, 269 270 "uartlite", port); ··· 286 273 287 274 static void ulite_shutdown(struct uart_port *port) 288 275 { 276 + struct uartlite_data *pdata = port->private_data; 277 + 289 278 uart_out32(0, ULITE_CONTROL, port); 290 279 uart_in32(ULITE_CONTROL, port); /* dummy */ 291 280 free_irq(port->irq, port); 281 + clk_disable(pdata->clk); 292 282 } 293 283 294 284 static void ulite_set_termios(struct uart_port *port, struct ktermios *termios, ··· 341 325 342 326 static int ulite_request_port(struct uart_port *port) 343 327 { 328 + struct uartlite_data *pdata = port->private_data; 344 329 int ret; 345 330 346 331 pr_debug("ulite console: port=%p; port->mapbase=%llx\n", ··· 359 342 return -EBUSY; 360 343 } 361 344 362 - port->private_data = (void *)&uartlite_be; 345 + pdata->reg_ops = &uartlite_be; 363 346 ret = uart_in32(ULITE_CONTROL, port); 364 347 uart_out32(ULITE_CONTROL_RST_TX, ULITE_CONTROL, port); 365 348 ret = uart_in32(ULITE_STATUS, port); 366 349 /* Endianess detection */ 367 350 if ((ret & ULITE_STATUS_TXEMPTY) != ULITE_STATUS_TXEMPTY) 368 - port->private_data = (void *)&uartlite_le; 351 + pdata->reg_ops = &uartlite_le; 369 352 370 353 return 0; 371 354 } ··· 380 363 { 381 364 /* we don't want the core code to modify any port params */ 382 365 return -EINVAL; 366 + } 367 + 368 + static void ulite_pm(struct uart_port *port, unsigned int state, 369 + unsigned int oldstate) 370 + { 371 + struct uartlite_data *pdata = port->private_data; 372 + 373 + if (!state) 374 + clk_enable(pdata->clk); 375 + else 376 + clk_disable(pdata->clk); 383 377 } 384 378 385 379 #ifdef CONFIG_CONSOLE_POLL ··· 428 400 .request_port = ulite_request_port, 429 401 .config_port = ulite_config_port, 430 402 .verify_port = ulite_verify_port, 403 + .pm = ulite_pm, 431 404 #ifdef CONFIG_CONSOLE_POLL 432 405 .poll_get_char = ulite_get_poll_char, 433 406 .poll_put_char = ulite_put_poll_char, ··· 614 585 * @id: requested id number. Pass -1 for automatic port assignment 615 586 * @base: base address of uartlite registers 616 587 * @irq: irq number for uartlite 588 + * @pdata: private data for uartlite 617 589 * 618 590 * Returns: 0 on success, <0 otherwise 619 591 */ 620 - static int ulite_assign(struct device *dev, int id, u32 base, int irq) 592 + static int ulite_assign(struct device *dev, int id, u32 base, int irq, 593 + struct uartlite_data *pdata) 621 594 { 622 595 struct uart_port *port; 623 596 int rc; ··· 656 625 port->dev = dev; 657 626 port->type = PORT_UNKNOWN; 658 627 port->line = id; 628 + port->private_data = pdata; 659 629 660 630 dev_set_drvdata(dev, port); 661 631 ··· 690 658 return rc; 691 659 } 692 660 661 + /** 662 + * ulite_suspend - Stop the device. 663 + * 664 + * @dev: handle to the device structure. 665 + * Return: 0 always. 666 + */ 667 + static int __maybe_unused ulite_suspend(struct device *dev) 668 + { 669 + struct uart_port *port = dev_get_drvdata(dev); 670 + 671 + if (port) 672 + uart_suspend_port(&ulite_uart_driver, port); 673 + 674 + return 0; 675 + } 676 + 677 + /** 678 + * ulite_resume - Resume the device. 679 + * 680 + * @dev: handle to the device structure. 681 + * Return: 0 on success, errno otherwise. 682 + */ 683 + static int __maybe_unused ulite_resume(struct device *dev) 684 + { 685 + struct uart_port *port = dev_get_drvdata(dev); 686 + 687 + if (port) 688 + uart_resume_port(&ulite_uart_driver, port); 689 + 690 + return 0; 691 + } 692 + 693 693 /* --------------------------------------------------------------------- 694 694 * Platform bus binding 695 695 */ 696 + 697 + static SIMPLE_DEV_PM_OPS(ulite_pm_ops, ulite_suspend, ulite_resume); 696 698 697 699 #if defined(CONFIG_OF) 698 700 /* Match table for of_platform binding */ ··· 741 675 static int ulite_probe(struct platform_device *pdev) 742 676 { 743 677 struct resource *res; 744 - int irq; 678 + struct uartlite_data *pdata; 679 + int irq, ret; 745 680 int id = pdev->id; 746 681 #ifdef CONFIG_OF 747 682 const __be32 *prop; ··· 751 684 if (prop) 752 685 id = be32_to_cpup(prop); 753 686 #endif 687 + pdata = devm_kzalloc(&pdev->dev, sizeof(struct uartlite_data), 688 + GFP_KERNEL); 689 + if (!pdata) 690 + return -ENOMEM; 754 691 755 692 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 756 693 if (!res) ··· 764 693 if (irq <= 0) 765 694 return -ENXIO; 766 695 767 - return ulite_assign(&pdev->dev, id, res->start, irq); 696 + pdata->clk = devm_clk_get(&pdev->dev, "s_axi_aclk"); 697 + if (IS_ERR(pdata->clk)) { 698 + if (PTR_ERR(pdata->clk) != -ENOENT) 699 + return PTR_ERR(pdata->clk); 700 + 701 + /* 702 + * Clock framework support is optional, continue on 703 + * anyways if we don't find a matching clock. 704 + */ 705 + pdata->clk = NULL; 706 + } 707 + 708 + ret = clk_prepare(pdata->clk); 709 + if (ret) { 710 + dev_err(&pdev->dev, "Failed to prepare clock\n"); 711 + return ret; 712 + } 713 + 714 + return ulite_assign(&pdev->dev, id, res->start, irq, pdata); 768 715 } 769 716 770 717 static int ulite_remove(struct platform_device *pdev) 771 718 { 719 + struct uart_port *port = dev_get_drvdata(&pdev->dev); 720 + struct uartlite_data *pdata = port->private_data; 721 + 722 + clk_disable_unprepare(pdata->clk); 772 723 return ulite_release(&pdev->dev); 773 724 } 774 725 ··· 803 710 .driver = { 804 711 .name = "uartlite", 805 712 .of_match_table = of_match_ptr(ulite_of_match), 713 + .pm = &ulite_pm_ops, 806 714 }, 807 715 }; 808 716
+8 -15
drivers/tty/serial/xilinx_uartps.c
··· 167 167 #define CDNS_UART_SR_TXEMPTY 0x00000008 /* TX FIFO empty */ 168 168 #define CDNS_UART_SR_TXFULL 0x00000010 /* TX FIFO full */ 169 169 #define CDNS_UART_SR_RXTRIG 0x00000001 /* Rx Trigger */ 170 + #define CDNS_UART_SR_TACTIVE 0x00000800 /* TX state machine active */ 170 171 171 172 /* baud dividers min/max values */ 172 173 #define CDNS_UART_BDIV_MIN 4 ··· 830 829 * the receiver. 831 830 */ 832 831 status = readl(port->membase + CDNS_UART_CR); 833 - status &= CDNS_UART_CR_RX_DIS; 832 + status &= ~CDNS_UART_CR_RX_DIS; 834 833 status |= CDNS_UART_CR_RX_EN; 835 834 writel(status, port->membase + CDNS_UART_CR); 836 835 ··· 1100 1099 1101 1100 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE 1102 1101 /** 1103 - * cdns_uart_console_wait_tx - Wait for the TX to be full 1104 - * @port: Handle to the uart port structure 1105 - */ 1106 - static void cdns_uart_console_wait_tx(struct uart_port *port) 1107 - { 1108 - while (!(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXEMPTY)) 1109 - barrier(); 1110 - } 1111 - 1112 - /** 1113 1102 * cdns_uart_console_putchar - write the character to the FIFO buffer 1114 1103 * @port: Handle to the uart port structure 1115 1104 * @ch: Character to be written 1116 1105 */ 1117 1106 static void cdns_uart_console_putchar(struct uart_port *port, int ch) 1118 1107 { 1119 - cdns_uart_console_wait_tx(port); 1108 + while (readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXFULL) 1109 + cpu_relax(); 1120 1110 writel(ch, port->membase + CDNS_UART_FIFO); 1121 1111 } 1122 1112 ··· 1198 1206 writel(ctrl, port->membase + CDNS_UART_CR); 1199 1207 1200 1208 uart_console_write(port, s, count, cdns_uart_console_putchar); 1201 - cdns_uart_console_wait_tx(port); 1202 - 1203 - writel(ctrl, port->membase + CDNS_UART_CR); 1209 + while ((readl(port->membase + CDNS_UART_SR) & 1210 + (CDNS_UART_SR_TXEMPTY | CDNS_UART_SR_TACTIVE)) != 1211 + CDNS_UART_SR_TXEMPTY) 1212 + cpu_relax(); 1204 1213 1205 1214 /* restore interrupt state */ 1206 1215 writel(imr, port->membase + CDNS_UART_IER);
+15 -7
drivers/tty/tty_baudrate.c
··· 100 100 101 101 if (cbaud == B0) 102 102 return tty_termios_baud_rate(termios); 103 - 103 + #ifdef BOTHER 104 104 /* Magic token for arbitrary speed via c_ispeed*/ 105 105 if (cbaud == BOTHER) 106 106 return termios->c_ispeed; 107 - 107 + #endif 108 108 if (cbaud & CBAUDEX) { 109 109 cbaud &= ~CBAUDEX; 110 110 ··· 114 114 cbaud += 15; 115 115 } 116 116 return baud_table[cbaud]; 117 - #else 117 + #else /* IBSHIFT */ 118 118 return tty_termios_baud_rate(termios); 119 - #endif 119 + #endif /* IBSHIFT */ 120 120 } 121 121 EXPORT_SYMBOL(tty_termios_input_baud_rate); 122 122 ··· 156 156 termios->c_ispeed = ibaud; 157 157 termios->c_ospeed = obaud; 158 158 159 + #ifdef IBSHIFT 160 + if ((termios->c_cflag >> IBSHIFT) & CBAUD) 161 + ibinput = 1; /* An input speed was specified */ 162 + #endif 159 163 #ifdef BOTHER 160 164 /* If the user asked for a precise weird speed give a precise weird 161 165 answer. If they asked for a Bfoo speed they may have problems 162 166 digesting non-exact replies so fuzz a bit */ 163 167 164 - if ((termios->c_cflag & CBAUD) == BOTHER) 168 + if ((termios->c_cflag & CBAUD) == BOTHER) { 165 169 oclose = 0; 170 + if (!ibinput) 171 + iclose = 0; 172 + } 166 173 if (((termios->c_cflag >> IBSHIFT) & CBAUD) == BOTHER) 167 174 iclose = 0; 168 - if ((termios->c_cflag >> IBSHIFT) & CBAUD) 169 - ibinput = 1; /* An input speed was specified */ 170 175 #endif 171 176 termios->c_cflag &= ~CBAUD; 177 + #ifdef IBSHIFT 178 + termios->c_cflag &= ~(CBAUD << IBSHIFT); 179 + #endif 172 180 173 181 /* 174 182 * Our goal is to find a close match to the standard baud rate
+5 -14
drivers/tty/tty_io.c
··· 814 814 } 815 815 EXPORT_SYMBOL(start_tty); 816 816 817 - static void tty_update_time(struct timespec *time) 817 + static void tty_update_time(struct timespec64 *time) 818 818 { 819 - unsigned long sec = get_seconds(); 819 + time64_t sec = ktime_get_real_seconds(); 820 820 821 821 /* 822 822 * We only care if the two values differ in anything other than the ··· 867 867 i = -EIO; 868 868 tty_ldisc_deref(ld); 869 869 870 - if (i > 0) { 871 - struct timespec ts; 872 - 873 - ts = timespec64_to_timespec(inode->i_atime); 874 - tty_update_time(&ts); 875 - inode->i_atime = timespec_to_timespec64(ts); 876 - } 870 + if (i > 0) 871 + tty_update_time(&inode->i_atime); 877 872 878 873 return i; 879 874 } ··· 969 974 cond_resched(); 970 975 } 971 976 if (written) { 972 - struct timespec ts; 973 - 974 - ts = timespec64_to_timespec(file_inode(file)->i_mtime); 975 - tty_update_time(&ts); 976 - file_inode(file)->i_mtime = timespec_to_timespec64(ts); 977 + tty_update_time(&file_inode(file)->i_mtime); 977 978 ret = written; 978 979 } 979 980 out:
+35 -47
drivers/tty/tty_ldsem.c
··· 74 74 struct task_struct *task; 75 75 }; 76 76 77 - static inline long ldsem_atomic_update(long delta, struct ld_semaphore *sem) 78 - { 79 - return atomic_long_add_return(delta, (atomic_long_t *)&sem->count); 80 - } 81 - 82 - /* 83 - * ldsem_cmpxchg() updates @*old with the last-known sem->count value. 84 - * Returns 1 if count was successfully changed; @*old will have @new value. 85 - * Returns 0 if count was not changed; @*old will have most recent sem->count 86 - */ 87 - static inline int ldsem_cmpxchg(long *old, long new, struct ld_semaphore *sem) 88 - { 89 - long tmp = atomic_long_cmpxchg(&sem->count, *old, new); 90 - if (tmp == *old) { 91 - *old = new; 92 - return 1; 93 - } else { 94 - *old = tmp; 95 - return 0; 96 - } 97 - } 98 - 99 77 /* 100 78 * Initialize an ldsem: 101 79 */ ··· 87 109 debug_check_no_locks_freed((void *)sem, sizeof(*sem)); 88 110 lockdep_init_map(&sem->dep_map, name, key, 0); 89 111 #endif 90 - sem->count = LDSEM_UNLOCKED; 112 + atomic_long_set(&sem->count, LDSEM_UNLOCKED); 91 113 sem->wait_readers = 0; 92 114 raw_spin_lock_init(&sem->wait_lock); 93 115 INIT_LIST_HEAD(&sem->read_wait); ··· 100 122 struct task_struct *tsk; 101 123 long adjust, count; 102 124 103 - /* Try to grant read locks to all readers on the read wait list. 125 + /* 126 + * Try to grant read locks to all readers on the read wait list. 104 127 * Note the 'active part' of the count is incremented by 105 128 * the number of readers before waking any processes up. 106 129 */ 107 130 adjust = sem->wait_readers * (LDSEM_ACTIVE_BIAS - LDSEM_WAIT_BIAS); 108 - count = ldsem_atomic_update(adjust, sem); 131 + count = atomic_long_add_return(adjust, &sem->count); 109 132 do { 110 133 if (count > 0) 111 134 break; 112 - if (ldsem_cmpxchg(&count, count - adjust, sem)) 135 + if (atomic_long_try_cmpxchg(&sem->count, &count, count - adjust)) 113 136 return; 114 137 } while (1); 115 138 ··· 127 148 128 149 static inline int writer_trylock(struct ld_semaphore *sem) 129 150 { 130 - /* only wake this writer if the active part of the count can be 151 + /* 152 + * Only wake this writer if the active part of the count can be 131 153 * transitioned from 0 -> 1 132 154 */ 133 - long count = ldsem_atomic_update(LDSEM_ACTIVE_BIAS, sem); 155 + long count = atomic_long_add_return(LDSEM_ACTIVE_BIAS, &sem->count); 134 156 do { 135 157 if ((count & LDSEM_ACTIVE_MASK) == LDSEM_ACTIVE_BIAS) 136 158 return 1; 137 - if (ldsem_cmpxchg(&count, count - LDSEM_ACTIVE_BIAS, sem)) 159 + if (atomic_long_try_cmpxchg(&sem->count, &count, count - LDSEM_ACTIVE_BIAS)) 138 160 return 0; 139 161 } while (1); 140 162 } ··· 185 205 /* set up my own style of waitqueue */ 186 206 raw_spin_lock_irq(&sem->wait_lock); 187 207 188 - /* Try to reverse the lock attempt but if the count has changed 208 + /* 209 + * Try to reverse the lock attempt but if the count has changed 189 210 * so that reversing fails, check if there are are no waiters, 190 - * and early-out if not */ 211 + * and early-out if not 212 + */ 191 213 do { 192 - if (ldsem_cmpxchg(&count, count + adjust, sem)) 214 + if (atomic_long_try_cmpxchg(&sem->count, &count, count + adjust)) { 215 + count += adjust; 193 216 break; 217 + } 194 218 if (count > 0) { 195 219 raw_spin_unlock_irq(&sem->wait_lock); 196 220 return sem; ··· 227 243 __set_current_state(TASK_RUNNING); 228 244 229 245 if (!timeout) { 230 - /* lock timed out but check if this task was just 246 + /* 247 + * Lock timed out but check if this task was just 231 248 * granted lock ownership - if so, pretend there 232 - * was no timeout; otherwise, cleanup lock wait */ 249 + * was no timeout; otherwise, cleanup lock wait. 250 + */ 233 251 raw_spin_lock_irq(&sem->wait_lock); 234 252 if (waiter.task) { 235 - ldsem_atomic_update(-LDSEM_WAIT_BIAS, sem); 253 + atomic_long_add_return(-LDSEM_WAIT_BIAS, &sem->count); 236 254 list_del(&waiter.list); 237 255 raw_spin_unlock_irq(&sem->wait_lock); 238 256 put_task_struct(waiter.task); ··· 259 273 /* set up my own style of waitqueue */ 260 274 raw_spin_lock_irq(&sem->wait_lock); 261 275 262 - /* Try to reverse the lock attempt but if the count has changed 276 + /* 277 + * Try to reverse the lock attempt but if the count has changed 263 278 * so that reversing fails, check if the lock is now owned, 264 - * and early-out if so */ 279 + * and early-out if so. 280 + */ 265 281 do { 266 - if (ldsem_cmpxchg(&count, count + adjust, sem)) 282 + if (atomic_long_try_cmpxchg(&sem->count, &count, count + adjust)) 267 283 break; 268 284 if ((count & LDSEM_ACTIVE_MASK) == LDSEM_ACTIVE_BIAS) { 269 285 raw_spin_unlock_irq(&sem->wait_lock); ··· 291 303 } 292 304 293 305 if (!locked) 294 - ldsem_atomic_update(-LDSEM_WAIT_BIAS, sem); 306 + atomic_long_add_return(-LDSEM_WAIT_BIAS, &sem->count); 295 307 list_del(&waiter.list); 296 308 raw_spin_unlock_irq(&sem->wait_lock); 297 309 ··· 312 324 313 325 lockdep_acquire_read(sem, subclass, 0, _RET_IP_); 314 326 315 - count = ldsem_atomic_update(LDSEM_READ_BIAS, sem); 327 + count = atomic_long_add_return(LDSEM_READ_BIAS, &sem->count); 316 328 if (count <= 0) { 317 329 lock_stat(sem, contended); 318 330 if (!down_read_failed(sem, count, timeout)) { ··· 331 343 332 344 lockdep_acquire(sem, subclass, 0, _RET_IP_); 333 345 334 - count = ldsem_atomic_update(LDSEM_WRITE_BIAS, sem); 346 + count = atomic_long_add_return(LDSEM_WRITE_BIAS, &sem->count); 335 347 if ((count & LDSEM_ACTIVE_MASK) != LDSEM_ACTIVE_BIAS) { 336 348 lock_stat(sem, contended); 337 349 if (!down_write_failed(sem, count, timeout)) { ··· 358 370 */ 359 371 int ldsem_down_read_trylock(struct ld_semaphore *sem) 360 372 { 361 - long count = sem->count; 373 + long count = atomic_long_read(&sem->count); 362 374 363 375 while (count >= 0) { 364 - if (ldsem_cmpxchg(&count, count + LDSEM_READ_BIAS, sem)) { 376 + if (atomic_long_try_cmpxchg(&sem->count, &count, count + LDSEM_READ_BIAS)) { 365 377 lockdep_acquire_read(sem, 0, 1, _RET_IP_); 366 378 lock_stat(sem, acquired); 367 379 return 1; ··· 384 396 */ 385 397 int ldsem_down_write_trylock(struct ld_semaphore *sem) 386 398 { 387 - long count = sem->count; 399 + long count = atomic_long_read(&sem->count); 388 400 389 401 while ((count & LDSEM_ACTIVE_MASK) == 0) { 390 - if (ldsem_cmpxchg(&count, count + LDSEM_WRITE_BIAS, sem)) { 402 + if (atomic_long_try_cmpxchg(&sem->count, &count, count + LDSEM_WRITE_BIAS)) { 391 403 lockdep_acquire(sem, 0, 1, _RET_IP_); 392 404 lock_stat(sem, acquired); 393 405 return 1; ··· 405 417 406 418 lockdep_release(sem, 1, _RET_IP_); 407 419 408 - count = ldsem_atomic_update(-LDSEM_READ_BIAS, sem); 420 + count = atomic_long_add_return(-LDSEM_READ_BIAS, &sem->count); 409 421 if (count < 0 && (count & LDSEM_ACTIVE_MASK) == 0) 410 422 ldsem_wake(sem); 411 423 } ··· 419 431 420 432 lockdep_release(sem, 1, _RET_IP_); 421 433 422 - count = ldsem_atomic_update(-LDSEM_WRITE_BIAS, sem); 434 + count = atomic_long_add_return(-LDSEM_WRITE_BIAS, &sem->count); 423 435 if (count < 0) 424 436 ldsem_wake(sem); 425 437 }
+29 -1
drivers/tty/vt/keyboard.c
··· 690 690 */ 691 691 static void k_dead(struct vc_data *vc, unsigned char value, char up_flag) 692 692 { 693 - static const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' }; 693 + static const unsigned char ret_diacr[NR_DEAD] = { 694 + '`', /* dead_grave */ 695 + '\'', /* dead_acute */ 696 + '^', /* dead_circumflex */ 697 + '~', /* dead_tilda */ 698 + '"', /* dead_diaeresis */ 699 + ',', /* dead_cedilla */ 700 + '_', /* dead_macron */ 701 + 'U', /* dead_breve */ 702 + '.', /* dead_abovedot */ 703 + '*', /* dead_abovering */ 704 + '=', /* dead_doubleacute */ 705 + 'c', /* dead_caron */ 706 + 'k', /* dead_ogonek */ 707 + 'i', /* dead_iota */ 708 + '#', /* dead_voiced_sound */ 709 + 'o', /* dead_semivoiced_sound */ 710 + '!', /* dead_belowdot */ 711 + '?', /* dead_hook */ 712 + '+', /* dead_horn */ 713 + '-', /* dead_stroke */ 714 + ')', /* dead_abovecomma */ 715 + '(', /* dead_abovereversedcomma */ 716 + ':', /* dead_doublegrave */ 717 + 'n', /* dead_invertedbreve */ 718 + ';', /* dead_belowcomma */ 719 + '$', /* dead_currency */ 720 + '@', /* dead_greek */ 721 + }; 694 722 695 723 k_deadunicode(vc, ret_diacr[value], up_flag); 696 724 }
+29 -19
drivers/tty/vt/selection.c
··· 57 57 complement_pos(sel_cons, where); 58 58 } 59 59 60 - static u16 60 + static u32 61 61 sel_pos(int n) 62 62 { 63 + if (use_unicode) 64 + return screen_glyph_unicode(sel_cons, n / 2); 63 65 return inverse_translate(sel_cons, screen_glyph(sel_cons, n), 64 - use_unicode); 66 + 0); 65 67 } 66 68 67 69 /** ··· 92 90 0x07FFFFFE, /* lowercase */ 93 91 }; 94 92 95 - static inline int inword(const u16 c) { 93 + static inline int inword(const u32 c) 94 + { 96 95 return c > 0x7f || (( inwordLut[c>>5] >> (c & 0x1F) ) & 1); 97 96 } 98 97 ··· 119 116 return (!(p % size_row) || !((p + 2) % size_row)); 120 117 } 121 118 122 - /* constrain v such that v <= u */ 123 - static inline unsigned short limit(const unsigned short v, const unsigned short u) 124 - { 125 - return (v > u) ? u : v; 126 - } 127 - 128 - /* stores the char in UTF8 and returns the number of bytes used (1-3) */ 129 - static int store_utf8(u16 c, char *p) 119 + /* stores the char in UTF8 and returns the number of bytes used (1-4) */ 120 + static int store_utf8(u32 c, char *p) 130 121 { 131 122 if (c < 0x80) { 132 123 /* 0******* */ ··· 131 134 p[0] = 0xc0 | (c >> 6); 132 135 p[1] = 0x80 | (c & 0x3f); 133 136 return 2; 134 - } else { 137 + } else if (c < 0x10000) { 135 138 /* 1110**** 10****** 10****** */ 136 139 p[0] = 0xe0 | (c >> 12); 137 140 p[1] = 0x80 | ((c >> 6) & 0x3f); 138 141 p[2] = 0x80 | (c & 0x3f); 139 142 return 3; 140 - } 143 + } else if (c < 0x110000) { 144 + /* 11110*** 10****** 10****** 10****** */ 145 + p[0] = 0xf0 | (c >> 18); 146 + p[1] = 0x80 | ((c >> 12) & 0x3f); 147 + p[2] = 0x80 | ((c >> 6) & 0x3f); 148 + p[3] = 0x80 | (c & 0x3f); 149 + return 4; 150 + } else { 151 + /* outside Unicode, replace with U+FFFD */ 152 + p[0] = 0xef; 153 + p[1] = 0xbf; 154 + p[2] = 0xbd; 155 + return 3; 156 + } 141 157 } 142 158 143 159 /** ··· 170 160 struct tiocl_selection v; 171 161 char *bp, *obp; 172 162 int i, ps, pe, multiplier; 173 - u16 c; 163 + u32 c; 174 164 int mode; 175 165 176 166 poke_blanked_console(); 177 167 if (copy_from_user(&v, sel, sizeof(*sel))) 178 168 return -EFAULT; 179 169 180 - v.xs = limit(v.xs - 1, vc->vc_cols - 1); 181 - v.ys = limit(v.ys - 1, vc->vc_rows - 1); 182 - v.xe = limit(v.xe - 1, vc->vc_cols - 1); 183 - v.ye = limit(v.ye - 1, vc->vc_rows - 1); 170 + v.xs = min_t(u16, v.xs - 1, vc->vc_cols - 1); 171 + v.ys = min_t(u16, v.ys - 1, vc->vc_rows - 1); 172 + v.xe = min_t(u16, v.xe - 1, vc->vc_cols - 1); 173 + v.ye = min_t(u16, v.ye - 1, vc->vc_rows - 1); 184 174 ps = v.ys * vc->vc_size_row + (v.xs << 1); 185 175 pe = v.ye * vc->vc_size_row + (v.xe << 1); 186 176 ··· 289 279 sel_end = new_sel_end; 290 280 291 281 /* Allocate a new buffer before freeing the old one ... */ 292 - multiplier = use_unicode ? 3 : 1; /* chars can take up to 3 bytes */ 282 + multiplier = use_unicode ? 4 : 1; /* chars can take up to 4 bytes */ 293 283 bp = kmalloc_array((sel_end - sel_start) / 2 + 1, multiplier, 294 284 GFP_KERNEL); 295 285 if (!bp) {
+76 -14
drivers/tty/vt/vc_screen.c
··· 10 10 * Attribute/character pair is in native endianity. 11 11 * [minor: N+128] 12 12 * 13 + * /dev/vcsuN: similar to /dev/vcsaN but using 4-byte unicode values 14 + * instead of 1-byte screen glyph values. 15 + * [minor: N+64] 16 + * 17 + * /dev/vcsuaN: same idea as /dev/vcsaN for unicode (not yet implemented). 18 + * 13 19 * This replaces screendump and part of selection, so that the system 14 20 * administrator can control access using file system permissions. 15 21 * ··· 56 50 #define HEADER_SIZE 4 57 51 58 52 #define CON_BUF_SIZE (CONFIG_BASE_SMALL ? 256 : PAGE_SIZE) 53 + 54 + /* 55 + * Our minor space: 56 + * 57 + * 0 ... 63 glyph mode without attributes 58 + * 64 ... 127 unicode mode without attributes 59 + * 128 ... 191 glyph mode with attributes 60 + * 192 ... 255 unused (reserved for unicode with attributes) 61 + * 62 + * This relies on MAX_NR_CONSOLES being <= 63, meaning 63 actual consoles 63 + * with minors 0, 64, 128 and 192 being proxies for the foreground console. 64 + */ 65 + #if MAX_NR_CONSOLES > 63 66 + #warning "/dev/vcs* devices may not accommodate more than 63 consoles" 67 + #endif 68 + 69 + #define console(inode) (iminor(inode) & 63) 70 + #define use_unicode(inode) (iminor(inode) & 64) 71 + #define use_attributes(inode) (iminor(inode) & 128) 72 + 59 73 60 74 struct vcs_poll_data { 61 75 struct notifier_block notifier; ··· 128 102 poll = kzalloc(sizeof(*poll), GFP_KERNEL); 129 103 if (!poll) 130 104 return NULL; 131 - poll->cons_num = iminor(file_inode(file)) & 127; 105 + poll->cons_num = console(file_inode(file)); 132 106 init_waitqueue_head(&poll->waitq); 133 107 poll->notifier.notifier_call = vcs_notifier; 134 108 if (register_vt_notifier(&poll->notifier) != 0) { ··· 166 140 static struct vc_data* 167 141 vcs_vc(struct inode *inode, int *viewed) 168 142 { 169 - unsigned int currcons = iminor(inode) & 127; 143 + unsigned int currcons = console(inode); 170 144 171 145 WARN_CONSOLE_UNLOCKED(); 172 146 ··· 190 164 vcs_size(struct inode *inode) 191 165 { 192 166 int size; 193 - int minor = iminor(inode); 194 167 struct vc_data *vc; 195 168 196 169 WARN_CONSOLE_UNLOCKED(); ··· 200 175 201 176 size = vc->vc_rows * vc->vc_cols; 202 177 203 - if (minor & 128) 178 + if (use_attributes(inode)) { 179 + if (use_unicode(inode)) 180 + return -EOPNOTSUPP; 204 181 size = 2*size + HEADER_SIZE; 182 + } else if (use_unicode(inode)) 183 + size *= 4; 205 184 return size; 206 185 } 207 186 ··· 226 197 vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 227 198 { 228 199 struct inode *inode = file_inode(file); 229 - unsigned int currcons = iminor(inode); 230 200 struct vc_data *vc; 231 201 struct vcs_poll_data *poll; 232 - long pos; 233 - long attr, read; 234 - int col, maxcol, viewed; 202 + long pos, read; 203 + int attr, uni_mode, row, col, maxcol, viewed; 235 204 unsigned short *org = NULL; 236 205 ssize_t ret; 237 206 char *con_buf; ··· 245 218 */ 246 219 console_lock(); 247 220 248 - attr = (currcons & 128); 221 + uni_mode = use_unicode(inode); 222 + attr = use_attributes(inode); 249 223 ret = -ENXIO; 250 224 vc = vcs_vc(inode, &viewed); 251 225 if (!vc) ··· 255 227 ret = -EINVAL; 256 228 if (pos < 0) 257 229 goto unlock_out; 230 + /* we enforce 32-bit alignment for pos and count in unicode mode */ 231 + if (uni_mode && (pos | count) & 3) 232 + goto unlock_out; 233 + 258 234 poll = file->private_data; 259 235 if (count && poll) 260 236 poll->seen_last_update = true; ··· 298 266 con_buf_start = con_buf0 = con_buf; 299 267 orig_count = this_round; 300 268 maxcol = vc->vc_cols; 301 - if (!attr) { 269 + if (uni_mode) { 270 + unsigned int nr; 271 + 272 + ret = vc_uniscr_check(vc); 273 + if (ret) 274 + break; 275 + p /= 4; 276 + row = p / vc->vc_cols; 277 + col = p % maxcol; 278 + nr = maxcol - col; 279 + do { 280 + if (nr > this_round/4) 281 + nr = this_round/4; 282 + vc_uniscr_copy_line(vc, con_buf0, viewed, 283 + row, col, nr); 284 + con_buf0 += nr * 4; 285 + this_round -= nr * 4; 286 + row++; 287 + col = 0; 288 + nr = maxcol; 289 + } while (this_round); 290 + } else if (!attr) { 302 291 org = screen_pos(vc, p, viewed); 303 292 col = p % maxcol; 304 293 p += maxcol - col; ··· 428 375 vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 429 376 { 430 377 struct inode *inode = file_inode(file); 431 - unsigned int currcons = iminor(inode); 432 378 struct vc_data *vc; 433 379 long pos; 434 380 long attr, size, written; ··· 448 396 */ 449 397 console_lock(); 450 398 451 - attr = (currcons & 128); 399 + attr = use_attributes(inode); 452 400 ret = -ENXIO; 453 401 vc = vcs_vc(inode, &viewed); 454 402 if (!vc) ··· 645 593 static int 646 594 vcs_open(struct inode *inode, struct file *filp) 647 595 { 648 - unsigned int currcons = iminor(inode) & 127; 596 + unsigned int currcons = console(inode); 597 + bool attr = use_attributes(inode); 598 + bool uni_mode = use_unicode(inode); 649 599 int ret = 0; 650 - 600 + 601 + /* we currently don't support attributes in unicode mode */ 602 + if (attr && uni_mode) 603 + return -EOPNOTSUPP; 604 + 651 605 console_lock(); 652 606 if(currcons && !vc_cons_allocated(currcons-1)) 653 607 ret = -ENXIO; ··· 686 628 { 687 629 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 1), NULL, 688 630 "vcs%u", index + 1); 631 + device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 65), NULL, 632 + "vcsu%u", index + 1); 689 633 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 129), NULL, 690 634 "vcsa%u", index + 1); 691 635 } ··· 695 635 void vcs_remove_sysfs(int index) 696 636 { 697 637 device_destroy(vc_class, MKDEV(VCS_MAJOR, index + 1)); 638 + device_destroy(vc_class, MKDEV(VCS_MAJOR, index + 65)); 698 639 device_destroy(vc_class, MKDEV(VCS_MAJOR, index + 129)); 699 640 } 700 641 ··· 708 647 vc_class = class_create(THIS_MODULE, "vc"); 709 648 710 649 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 0), NULL, "vcs"); 650 + device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 64), NULL, "vcsu"); 711 651 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 128), NULL, "vcsa"); 712 652 for (i = 0; i < MIN_NR_CONSOLES; i++) 713 653 vcs_make_sysfs(i);
+356 -11
drivers/tty/vt/vt.c
··· 104 104 #include <linux/kdb.h> 105 105 #include <linux/ctype.h> 106 106 #include <linux/bsearch.h> 107 + #include <linux/gcd.h> 107 108 108 109 #define MAX_NR_CON_DRIVER 16 109 110 ··· 318 317 schedule_work(&console_work); 319 318 } 320 319 320 + /* 321 + * Code to manage unicode-based screen buffers 322 + */ 323 + 324 + #ifdef NO_VC_UNI_SCREEN 325 + /* this disables and optimizes related code away at compile time */ 326 + #define get_vc_uniscr(vc) NULL 327 + #else 328 + #define get_vc_uniscr(vc) vc->vc_uni_screen 329 + #endif 330 + 331 + #define VC_UNI_SCREEN_DEBUG 0 332 + 333 + typedef uint32_t char32_t; 334 + 335 + /* 336 + * Our screen buffer is preceded by an array of line pointers so that 337 + * scrolling only implies some pointer shuffling. 338 + */ 339 + struct uni_screen { 340 + char32_t *lines[0]; 341 + }; 342 + 343 + static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows) 344 + { 345 + struct uni_screen *uniscr; 346 + void *p; 347 + unsigned int memsize, i; 348 + 349 + /* allocate everything in one go */ 350 + memsize = cols * rows * sizeof(char32_t); 351 + memsize += rows * sizeof(char32_t *); 352 + p = kmalloc(memsize, GFP_KERNEL); 353 + if (!p) 354 + return NULL; 355 + 356 + /* initial line pointers */ 357 + uniscr = p; 358 + p = uniscr->lines + rows; 359 + for (i = 0; i < rows; i++) { 360 + uniscr->lines[i] = p; 361 + p += cols * sizeof(char32_t); 362 + } 363 + return uniscr; 364 + } 365 + 366 + static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr) 367 + { 368 + kfree(vc->vc_uni_screen); 369 + vc->vc_uni_screen = new_uniscr; 370 + } 371 + 372 + static void vc_uniscr_putc(struct vc_data *vc, char32_t uc) 373 + { 374 + struct uni_screen *uniscr = get_vc_uniscr(vc); 375 + 376 + if (uniscr) 377 + uniscr->lines[vc->vc_y][vc->vc_x] = uc; 378 + } 379 + 380 + static void vc_uniscr_insert(struct vc_data *vc, unsigned int nr) 381 + { 382 + struct uni_screen *uniscr = get_vc_uniscr(vc); 383 + 384 + if (uniscr) { 385 + char32_t *ln = uniscr->lines[vc->vc_y]; 386 + unsigned int x = vc->vc_x, cols = vc->vc_cols; 387 + 388 + memmove(&ln[x + nr], &ln[x], (cols - x - nr) * sizeof(*ln)); 389 + memset32(&ln[x], ' ', nr); 390 + } 391 + } 392 + 393 + static void vc_uniscr_delete(struct vc_data *vc, unsigned int nr) 394 + { 395 + struct uni_screen *uniscr = get_vc_uniscr(vc); 396 + 397 + if (uniscr) { 398 + char32_t *ln = uniscr->lines[vc->vc_y]; 399 + unsigned int x = vc->vc_x, cols = vc->vc_cols; 400 + 401 + memcpy(&ln[x], &ln[x + nr], (cols - x - nr) * sizeof(*ln)); 402 + memset32(&ln[cols - nr], ' ', nr); 403 + } 404 + } 405 + 406 + static void vc_uniscr_clear_line(struct vc_data *vc, unsigned int x, 407 + unsigned int nr) 408 + { 409 + struct uni_screen *uniscr = get_vc_uniscr(vc); 410 + 411 + if (uniscr) { 412 + char32_t *ln = uniscr->lines[vc->vc_y]; 413 + 414 + memset32(&ln[x], ' ', nr); 415 + } 416 + } 417 + 418 + static void vc_uniscr_clear_lines(struct vc_data *vc, unsigned int y, 419 + unsigned int nr) 420 + { 421 + struct uni_screen *uniscr = get_vc_uniscr(vc); 422 + 423 + if (uniscr) { 424 + unsigned int cols = vc->vc_cols; 425 + 426 + while (nr--) 427 + memset32(uniscr->lines[y++], ' ', cols); 428 + } 429 + } 430 + 431 + static void vc_uniscr_scroll(struct vc_data *vc, unsigned int t, unsigned int b, 432 + enum con_scroll dir, unsigned int nr) 433 + { 434 + struct uni_screen *uniscr = get_vc_uniscr(vc); 435 + 436 + if (uniscr) { 437 + unsigned int i, j, k, sz, d, clear; 438 + 439 + sz = b - t; 440 + clear = b - nr; 441 + d = nr; 442 + if (dir == SM_DOWN) { 443 + clear = t; 444 + d = sz - nr; 445 + } 446 + for (i = 0; i < gcd(d, sz); i++) { 447 + char32_t *tmp = uniscr->lines[t + i]; 448 + j = i; 449 + while (1) { 450 + k = j + d; 451 + if (k >= sz) 452 + k -= sz; 453 + if (k == i) 454 + break; 455 + uniscr->lines[t + j] = uniscr->lines[t + k]; 456 + j = k; 457 + } 458 + uniscr->lines[t + j] = tmp; 459 + } 460 + vc_uniscr_clear_lines(vc, clear, nr); 461 + } 462 + } 463 + 464 + static void vc_uniscr_copy_area(struct uni_screen *dst, 465 + unsigned int dst_cols, 466 + unsigned int dst_rows, 467 + struct uni_screen *src, 468 + unsigned int src_cols, 469 + unsigned int src_top_row, 470 + unsigned int src_bot_row) 471 + { 472 + unsigned int dst_row = 0; 473 + 474 + if (!dst) 475 + return; 476 + 477 + while (src_top_row < src_bot_row) { 478 + char32_t *src_line = src->lines[src_top_row]; 479 + char32_t *dst_line = dst->lines[dst_row]; 480 + 481 + memcpy(dst_line, src_line, src_cols * sizeof(char32_t)); 482 + if (dst_cols - src_cols) 483 + memset32(dst_line + src_cols, ' ', dst_cols - src_cols); 484 + src_top_row++; 485 + dst_row++; 486 + } 487 + while (dst_row < dst_rows) { 488 + char32_t *dst_line = dst->lines[dst_row]; 489 + 490 + memset32(dst_line, ' ', dst_cols); 491 + dst_row++; 492 + } 493 + } 494 + 495 + /* 496 + * Called from vcs_read() to make sure unicode screen retrieval is possible. 497 + * This will initialize the unicode screen buffer if not already done. 498 + * This returns 0 if OK, or a negative error code otherwise. 499 + * In particular, -ENODATA is returned if the console is not in UTF-8 mode. 500 + */ 501 + int vc_uniscr_check(struct vc_data *vc) 502 + { 503 + struct uni_screen *uniscr; 504 + unsigned short *p; 505 + int x, y, mask; 506 + 507 + if (__is_defined(NO_VC_UNI_SCREEN)) 508 + return -EOPNOTSUPP; 509 + 510 + WARN_CONSOLE_UNLOCKED(); 511 + 512 + if (!vc->vc_utf) 513 + return -ENODATA; 514 + 515 + if (vc->vc_uni_screen) 516 + return 0; 517 + 518 + uniscr = vc_uniscr_alloc(vc->vc_cols, vc->vc_rows); 519 + if (!uniscr) 520 + return -ENOMEM; 521 + 522 + /* 523 + * Let's populate it initially with (imperfect) reverse translation. 524 + * This is the next best thing we can do short of having it enabled 525 + * from the start even when no users rely on this functionality. True 526 + * unicode content will be available after a complete screen refresh. 527 + */ 528 + p = (unsigned short *)vc->vc_origin; 529 + mask = vc->vc_hi_font_mask | 0xff; 530 + for (y = 0; y < vc->vc_rows; y++) { 531 + char32_t *line = uniscr->lines[y]; 532 + for (x = 0; x < vc->vc_cols; x++) { 533 + u16 glyph = scr_readw(p++) & mask; 534 + line[x] = inverse_translate(vc, glyph, true); 535 + } 536 + } 537 + 538 + vc->vc_uni_screen = uniscr; 539 + return 0; 540 + } 541 + 542 + /* 543 + * Called from vcs_read() to get the unicode data from the screen. 544 + * This must be preceded by a successful call to vc_uniscr_check() once 545 + * the console lock has been taken. 546 + */ 547 + void vc_uniscr_copy_line(struct vc_data *vc, void *dest, int viewed, 548 + unsigned int row, unsigned int col, unsigned int nr) 549 + { 550 + struct uni_screen *uniscr = get_vc_uniscr(vc); 551 + int offset = row * vc->vc_size_row + col * 2; 552 + unsigned long pos; 553 + 554 + BUG_ON(!uniscr); 555 + 556 + pos = (unsigned long)screenpos(vc, offset, viewed); 557 + if (pos >= vc->vc_origin && pos < vc->vc_scr_end) { 558 + /* 559 + * Desired position falls in the main screen buffer. 560 + * However the actual row/col might be different if 561 + * scrollback is active. 562 + */ 563 + row = (pos - vc->vc_origin) / vc->vc_size_row; 564 + col = ((pos - vc->vc_origin) % vc->vc_size_row) / 2; 565 + memcpy(dest, &uniscr->lines[row][col], nr * sizeof(char32_t)); 566 + } else { 567 + /* 568 + * Scrollback is active. For now let's simply backtranslate 569 + * the screen glyphs until the unicode screen buffer does 570 + * synchronize with console display drivers for a scrollback 571 + * buffer of its own. 572 + */ 573 + u16 *p = (u16 *)pos; 574 + int mask = vc->vc_hi_font_mask | 0xff; 575 + char32_t *uni_buf = dest; 576 + while (nr--) { 577 + u16 glyph = scr_readw(p++) & mask; 578 + *uni_buf++ = inverse_translate(vc, glyph, true); 579 + } 580 + } 581 + } 582 + 583 + /* this is for validation and debugging only */ 584 + static void vc_uniscr_debug_check(struct vc_data *vc) 585 + { 586 + struct uni_screen *uniscr = get_vc_uniscr(vc); 587 + unsigned short *p; 588 + int x, y, mask; 589 + 590 + if (!VC_UNI_SCREEN_DEBUG || !uniscr) 591 + return; 592 + 593 + WARN_CONSOLE_UNLOCKED(); 594 + 595 + /* 596 + * Make sure our unicode screen translates into the same glyphs 597 + * as the actual screen. This is brutal indeed. 598 + */ 599 + p = (unsigned short *)vc->vc_origin; 600 + mask = vc->vc_hi_font_mask | 0xff; 601 + for (y = 0; y < vc->vc_rows; y++) { 602 + char32_t *line = uniscr->lines[y]; 603 + for (x = 0; x < vc->vc_cols; x++) { 604 + u16 glyph = scr_readw(p++) & mask; 605 + char32_t uc = line[x]; 606 + int tc = conv_uni_to_pc(vc, uc); 607 + if (tc == -4) 608 + tc = conv_uni_to_pc(vc, 0xfffd); 609 + if (tc == -4) 610 + tc = conv_uni_to_pc(vc, '?'); 611 + if (tc != glyph) 612 + pr_err_ratelimited( 613 + "%s: mismatch at %d,%d: glyph=%#x tc=%#x\n", 614 + __func__, x, y, glyph, tc); 615 + } 616 + } 617 + } 618 + 619 + 321 620 static void con_scroll(struct vc_data *vc, unsigned int t, unsigned int b, 322 621 enum con_scroll dir, unsigned int nr) 323 622 { ··· 627 326 nr = b - t - 1; 628 327 if (b > vc->vc_rows || t >= b || nr < 1) 629 328 return; 329 + vc_uniscr_scroll(vc, t, b, dir, nr); 630 330 if (con_is_visible(vc) && vc->vc_sw->con_scroll(vc, t, b, dir, nr)) 631 331 return; 632 332 ··· 835 533 { 836 534 unsigned short *p = (unsigned short *) vc->vc_pos; 837 535 536 + vc_uniscr_insert(vc, nr); 838 537 scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x - nr) * 2); 839 538 scr_memsetw(p, vc->vc_video_erase_char, nr * 2); 840 539 vc->vc_need_wrap = 0; ··· 848 545 { 849 546 unsigned short *p = (unsigned short *) vc->vc_pos; 850 547 548 + vc_uniscr_delete(vc, nr); 851 549 scr_memcpyw(p, p + nr, (vc->vc_cols - vc->vc_x - nr) * 2); 852 550 scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char, 853 551 nr * 2); ··· 1149 845 { 1150 846 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0; 1151 847 unsigned long end; 1152 - unsigned int old_rows, old_row_size; 848 + unsigned int old_rows, old_row_size, first_copied_row; 1153 849 unsigned int new_cols, new_rows, new_row_size, new_screen_size; 1154 850 unsigned int user; 1155 851 unsigned short *newscreen; 852 + struct uni_screen *new_uniscr = NULL; 1156 853 1157 854 WARN_CONSOLE_UNLOCKED(); 1158 855 ··· 1180 875 if (!newscreen) 1181 876 return -ENOMEM; 1182 877 878 + if (get_vc_uniscr(vc)) { 879 + new_uniscr = vc_uniscr_alloc(new_cols, new_rows); 880 + if (!new_uniscr) { 881 + kfree(newscreen); 882 + return -ENOMEM; 883 + } 884 + } 885 + 1183 886 if (vc == sel_cons) 1184 887 clear_selection(); 1185 888 ··· 1197 884 err = resize_screen(vc, new_cols, new_rows, user); 1198 885 if (err) { 1199 886 kfree(newscreen); 887 + kfree(new_uniscr); 1200 888 return err; 1201 889 } 1202 890 ··· 1218 904 * Cursor near the bottom, copy contents from the 1219 905 * bottom of buffer 1220 906 */ 1221 - old_origin += (old_rows - new_rows) * old_row_size; 907 + first_copied_row = (old_rows - new_rows); 1222 908 } else { 1223 909 /* 1224 910 * Cursor is in no man's land, copy 1/2 screenful 1225 911 * from the top and bottom of cursor position 1226 912 */ 1227 - old_origin += (vc->vc_y - new_rows/2) * old_row_size; 913 + first_copied_row = (vc->vc_y - new_rows/2); 1228 914 } 1229 - } 1230 - 915 + old_origin += first_copied_row * old_row_size; 916 + } else 917 + first_copied_row = 0; 1231 918 end = old_origin + old_row_size * min(old_rows, new_rows); 919 + 920 + vc_uniscr_copy_area(new_uniscr, new_cols, new_rows, 921 + get_vc_uniscr(vc), rlth/2, first_copied_row, 922 + min(old_rows, new_rows)); 923 + vc_uniscr_set(vc, new_uniscr); 1232 924 1233 925 update_attr(vc); 1234 926 ··· 1333 1013 vc->vc_sw->con_deinit(vc); 1334 1014 put_pid(vc->vt_pid); 1335 1015 module_put(vc->vc_sw->owner); 1016 + vc_uniscr_set(vc, NULL); 1336 1017 kfree(vc->vc_screenbuf); 1337 1018 vc_cons[currcons].d = NULL; 1338 1019 } ··· 1492 1171 1493 1172 switch (vpar) { 1494 1173 case 0: /* erase from cursor to end of display */ 1174 + vc_uniscr_clear_line(vc, vc->vc_x, 1175 + vc->vc_cols - vc->vc_x); 1176 + vc_uniscr_clear_lines(vc, vc->vc_y + 1, 1177 + vc->vc_rows - vc->vc_y - 1); 1495 1178 count = (vc->vc_scr_end - vc->vc_pos) >> 1; 1496 1179 start = (unsigned short *)vc->vc_pos; 1497 1180 break; 1498 1181 case 1: /* erase from start to cursor */ 1182 + vc_uniscr_clear_line(vc, 0, vc->vc_x + 1); 1183 + vc_uniscr_clear_lines(vc, 0, vc->vc_y); 1499 1184 count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1; 1500 1185 start = (unsigned short *)vc->vc_origin; 1501 1186 break; 1502 1187 case 2: /* erase whole display */ 1503 1188 case 3: /* (and scrollback buffer later) */ 1189 + vc_uniscr_clear_lines(vc, 0, vc->vc_rows); 1504 1190 count = vc->vc_cols * vc->vc_rows; 1505 1191 start = (unsigned short *)vc->vc_origin; 1506 1192 break; ··· 1528 1200 static void csi_K(struct vc_data *vc, int vpar) 1529 1201 { 1530 1202 unsigned int count; 1531 - unsigned short * start; 1203 + unsigned short *start = (unsigned short *)vc->vc_pos; 1204 + int offset; 1532 1205 1533 1206 switch (vpar) { 1534 1207 case 0: /* erase from cursor to end of line */ 1208 + offset = 0; 1535 1209 count = vc->vc_cols - vc->vc_x; 1536 - start = (unsigned short *)vc->vc_pos; 1537 1210 break; 1538 1211 case 1: /* erase from start of line to cursor */ 1539 - start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1)); 1212 + offset = -vc->vc_x; 1540 1213 count = vc->vc_x + 1; 1541 1214 break; 1542 1215 case 2: /* erase whole line */ 1543 - start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1)); 1216 + offset = -vc->vc_x; 1544 1217 count = vc->vc_cols; 1545 1218 break; 1546 1219 default: 1547 1220 return; 1548 1221 } 1549 - scr_memsetw(start, vc->vc_video_erase_char, 2 * count); 1222 + vc_uniscr_clear_line(vc, vc->vc_x + offset, count); 1223 + scr_memsetw(start + offset, vc->vc_video_erase_char, 2 * count); 1550 1224 vc->vc_need_wrap = 0; 1551 1225 if (con_should_update(vc)) 1552 1226 do_update_region(vc, (unsigned long) start, count); ··· 1562 1232 vpar++; 1563 1233 count = (vpar > vc->vc_cols - vc->vc_x) ? (vc->vc_cols - vc->vc_x) : vpar; 1564 1234 1235 + vc_uniscr_clear_line(vc, vc->vc_x, count); 1565 1236 scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count); 1566 1237 if (con_should_update(vc)) 1567 1238 vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1, count); ··· 2519 2188 /* acquires console_lock */ 2520 2189 static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count) 2521 2190 { 2522 - int c, tc, ok, n = 0, draw_x = -1; 2191 + int c, next_c, tc, ok, n = 0, draw_x = -1; 2523 2192 unsigned int currcons; 2524 2193 unsigned long draw_from = 0, draw_to = 0; 2525 2194 struct vc_data *vc; ··· 2713 2382 con_flush(vc, draw_from, draw_to, &draw_x); 2714 2383 } 2715 2384 2385 + next_c = c; 2716 2386 while (1) { 2717 2387 if (vc->vc_need_wrap || vc->vc_decim) 2718 2388 con_flush(vc, draw_from, draw_to, ··· 2724 2392 } 2725 2393 if (vc->vc_decim) 2726 2394 insert_char(vc, 1); 2395 + vc_uniscr_putc(vc, next_c); 2727 2396 scr_writew(himask ? 2728 2397 ((vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) : 2729 2398 (vc_attr << 8) + tc, ··· 2745 2412 2746 2413 tc = conv_uni_to_pc(vc, ' '); /* A space is printed in the second column */ 2747 2414 if (tc < 0) tc = ' '; 2415 + next_c = ' '; 2748 2416 } 2749 2417 notify_write(vc, c); 2750 2418 ··· 2765 2431 do_con_trol(tty, vc, orig); 2766 2432 } 2767 2433 con_flush(vc, draw_from, draw_to, &draw_x); 2434 + vc_uniscr_debug_check(vc); 2768 2435 console_conditional_schedule(); 2769 2436 console_unlock(); 2770 2437 notify_update(vc); ··· 4591 4256 return c; 4592 4257 } 4593 4258 EXPORT_SYMBOL_GPL(screen_glyph); 4259 + 4260 + u32 screen_glyph_unicode(struct vc_data *vc, int n) 4261 + { 4262 + struct uni_screen *uniscr = get_vc_uniscr(vc); 4263 + 4264 + if (uniscr) 4265 + return uniscr->lines[n / vc->vc_cols][n % vc->vc_cols]; 4266 + return inverse_translate(vc, screen_glyph(vc, n * 2), 1); 4267 + } 4268 + EXPORT_SYMBOL_GPL(screen_glyph_unicode); 4594 4269 4595 4270 /* used by vcs - note the word offset */ 4596 4271 unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed)
+3 -2
include/linux/console_struct.h
··· 17 17 #include <linux/vt.h> 18 18 #include <linux/workqueue.h> 19 19 20 - struct vt_struct; 21 20 struct uni_pagedir; 21 + struct uni_screen; 22 22 23 23 #define NPAR 16 24 24 ··· 140 140 struct vc_data **vc_display_fg; /* [!] Ptr to var holding fg console for this display */ 141 141 struct uni_pagedir *vc_uni_pagedir; 142 142 struct uni_pagedir **vc_uni_pagedir_loc; /* [!] Location of uni_pagedir variable for this console */ 143 + struct uni_screen *vc_uni_screen; /* unicode screen content */ 143 144 bool vc_panic_force_write; /* when oops/panic this VC can accept forced output/blanking */ 144 145 /* additional information is in vt_kern.h */ 145 146 }; ··· 149 148 struct vc_data *d; 150 149 struct work_struct SAK_work; 151 150 152 - /* might add scrmem, vt_struct, kbd at some time, 151 + /* might add scrmem, kbd at some time, 153 152 to have everything in one place - the disadvantage 154 153 would be that vc_cons etc can no longer be static */ 155 154 };
+6
include/linux/selection.h
··· 32 32 33 33 extern unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed); 34 34 extern u16 screen_glyph(struct vc_data *vc, int offset); 35 + extern u32 screen_glyph_unicode(struct vc_data *vc, int offset); 35 36 extern void complement_pos(struct vc_data *vc, int offset); 36 37 extern void invert_screen(struct vc_data *vc, int offset, int count, int shift); 37 38 ··· 42 41 extern u16 vcs_scr_readw(struct vc_data *vc, const u16 *org); 43 42 extern void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org); 44 43 extern void vcs_scr_updated(struct vc_data *vc); 44 + 45 + extern int vc_uniscr_check(struct vc_data *vc); 46 + extern void vc_uniscr_copy_line(struct vc_data *vc, void *dest, int viewed, 47 + unsigned int row, unsigned int col, 48 + unsigned int nr); 45 49 46 50 #endif
+3
include/linux/serial_8250.h
··· 160 160 extern void serial8250_do_pm(struct uart_port *port, unsigned int state, 161 161 unsigned int oldstate); 162 162 extern void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl); 163 + extern void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud, 164 + unsigned int quot, 165 + unsigned int quot_frac); 163 166 extern int fsl8250_handle_irq(struct uart_port *port); 164 167 int serial8250_handle_irq(struct uart_port *port, unsigned int iir); 165 168 unsigned char serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr);
+7
include/linux/serial_core.h
··· 127 127 struct ktermios *); 128 128 unsigned int (*get_mctrl)(struct uart_port *); 129 129 void (*set_mctrl)(struct uart_port *, unsigned int); 130 + unsigned int (*get_divisor)(struct uart_port *, 131 + unsigned int baud, 132 + unsigned int *frac); 133 + void (*set_divisor)(struct uart_port *, 134 + unsigned int baud, 135 + unsigned int quot, 136 + unsigned int quot_frac); 130 137 int (*startup)(struct uart_port *port); 131 138 void (*shutdown)(struct uart_port *port); 132 139 void (*throttle)(struct uart_port *port);
+2 -2
include/linux/tty_ldisc.h
··· 119 119 120 120 #include <linux/fs.h> 121 121 #include <linux/wait.h> 122 - 122 + #include <linux/atomic.h> 123 123 124 124 /* 125 125 * the semaphore definition 126 126 */ 127 127 struct ld_semaphore { 128 - long count; 128 + atomic_long_t count; 129 129 raw_spinlock_t wait_lock; 130 130 unsigned int wait_readers; 131 131 struct list_head read_wait;
+22 -1
include/uapi/linux/keyboard.h
··· 357 357 #define K_DTILDE K(KT_DEAD,3) 358 358 #define K_DDIERE K(KT_DEAD,4) 359 359 #define K_DCEDIL K(KT_DEAD,5) 360 + #define K_DMACRON K(KT_DEAD,6) 361 + #define K_DBREVE K(KT_DEAD,7) 362 + #define K_DABDOT K(KT_DEAD,8) 363 + #define K_DABRING K(KT_DEAD,9) 364 + #define K_DDBACUTE K(KT_DEAD,10) 365 + #define K_DCARON K(KT_DEAD,11) 366 + #define K_DOGONEK K(KT_DEAD,12) 367 + #define K_DIOTA K(KT_DEAD,13) 368 + #define K_DVOICED K(KT_DEAD,14) 369 + #define K_DSEMVOICED K(KT_DEAD,15) 370 + #define K_DBEDOT K(KT_DEAD,16) 371 + #define K_DHOOK K(KT_DEAD,17) 372 + #define K_DHORN K(KT_DEAD,18) 373 + #define K_DSTROKE K(KT_DEAD,19) 374 + #define K_DABCOMMA K(KT_DEAD,20) 375 + #define K_DABREVCOMMA K(KT_DEAD,21) 376 + #define K_DDBGRAVE K(KT_DEAD,22) 377 + #define K_DINVBREVE K(KT_DEAD,23) 378 + #define K_DBECOMMA K(KT_DEAD,24) 379 + #define K_DCURRENCY K(KT_DEAD,25) 380 + #define K_DGREEK K(KT_DEAD,26) 360 381 361 - #define NR_DEAD 6 382 + #define NR_DEAD 27 362 383 363 384 #define K_DOWN K(KT_CUR,0) 364 385 #define K_LEFT K(KT_CUR,1)