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

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

Pull tty/serial driver patches from Greg KH:
"Here's the big tty/serial driver update for 3.20-rc1. Nothing huge
here, just lots of driver updates and some core tty layer fixes as
well. All have been in linux-next with no reported issues"

* tag 'tty-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (119 commits)
serial: 8250: Fix UART_BUG_TXEN workaround
serial: driver for ETRAX FS UART
tty: remove unused variable sprop
serial: of-serial: fetch line number from DT
serial: samsung: earlycon support depends on CONFIG_SERIAL_SAMSUNG_CONSOLE
tty/serial: serial8250_set_divisor() can be static
tty/serial: Add Spreadtrum sc9836-uart driver support
Documentation: DT: Add bindings for Spreadtrum SoC Platform
serial: samsung: remove redundant interrupt enabling
tty: Remove external interface for tty_set_termios()
serial: omap: Fix RTS handling
serial: 8250_omap: Use UPSTAT_AUTORTS for RTS handling
serial: core: Rework hw-assisted flow control support
tty/serial: 8250_early: Add support for PXA UARTs
tty/serial: of_serial: add support for PXA/MMP uarts
tty/serial: of_serial: add DT alias ID handling
serial: 8250: Prevent concurrent updates to shadow registers
serial: 8250: Use canary to restart console after suspend
serial: 8250: Refactor XR17V35X divisor calculation
serial: 8250: Refactor divisor programming
...

+4523 -1910
+11
Documentation/devicetree/bindings/arm/sprd.txt
··· 1 + Spreadtrum SoC Platforms Device Tree Bindings 2 + ---------------------------------------------------- 3 + 4 + Sharkl64 is a Spreadtrum's SoC Platform which is based 5 + on ARM 64-bit processor. 6 + 7 + SC9836 openphone board with SC9836 SoC based on the 8 + Sharkl64 Platform shall have the following properties. 9 + 10 + Required root node properties: 11 + - compatible = "sprd,sc9836-openphone", "sprd,sc9836";
+27
Documentation/devicetree/bindings/serial/digicolor-usart.txt
··· 1 + Binding for Conexant Digicolor USART 2 + 3 + Note: this binding is only applicable for using the USART peripheral as 4 + UART. USART also support synchronous serial protocols like SPI and I2S. Use 5 + the binding that matches the wiring of your system. 6 + 7 + Required properties: 8 + - compatible : should be "cnxt,cx92755-usart". 9 + - reg: Should contain USART controller registers location and length. 10 + - interrupts: Should contain a single USART controller interrupt. 11 + - clocks: Must contain phandles to the USART clock 12 + See ../clocks/clock-bindings.txt for details. 13 + 14 + Note: Each UART port should have an alias correctly numbered 15 + in "aliases" node. 16 + 17 + Example: 18 + aliases { 19 + serial0 = &uart0; 20 + }; 21 + 22 + uart0: uart@f0000740 { 23 + compatible = "cnxt,cx92755-usart"; 24 + reg = <0xf0000740 0x20>; 25 + clocks = <&main_clk>; 26 + interrupts = <44>; 27 + };
+2 -2
Documentation/devicetree/bindings/serial/sirf-uart.txt
··· 2 2 3 3 Required properties: 4 4 - compatible : Should be "sirf,prima2-uart", "sirf, prima2-usp-uart", 5 - "sirf,marco-uart" or "sirf,marco-bt-uart" which means 5 + "sirf,atlas7-uart" or "sirf,atlas7-bt-uart" which means 6 6 uart located in BT module and used for BT. 7 7 - reg : Offset and length of the register set for the device 8 8 - interrupts : Should contain uart interrupt ··· 37 37 for uart use in BT module, 38 38 uart6: uart@11000000 { 39 39 cell-index = <6>; 40 - compatible = "sirf,marco-bt-uart", "sirf,marco-uart"; 40 + compatible = "sirf,atlas7-bt-uart", "sirf,atlas7-uart"; 41 41 reg = <0x11000000 0x1000>; 42 42 interrupts = <0 100 0>; 43 43 clocks = <&clks 138>, <&clks 140>, <&clks 141>;
+7
Documentation/devicetree/bindings/serial/sprd-uart.txt
··· 1 + * Spreadtrum serial UART 2 + 3 + Required properties: 4 + - compatible: must be "sprd,sc9836-uart" 5 + - reg: offset and length of the register set for the device 6 + - interrupts: exactly one interrupt specifier 7 + - clocks: phandles to input clocks.
+2
Documentation/devicetree/bindings/vendor-prefixes.txt
··· 37 37 chunghwa Chunghwa Picture Tubes Ltd. 38 38 cirrus Cirrus Logic, Inc. 39 39 cnm Chips&Media, Inc. 40 + cnxt Conexant Systems, Inc. 40 41 cortina Cortina Systems, Inc. 41 42 cosmic Cosmic Circuits 42 43 crystalfontz Crystalfontz America, Inc. ··· 163 162 solidrun SolidRun 164 163 sony Sony Corporation 165 164 spansion Spansion Inc. 165 + sprd Spreadtrum Communications Inc. 166 166 st STMicroelectronics 167 167 ste ST-Ericsson 168 168 stericsson ST-Ericsson
+12
Documentation/kernel-parameters.txt
··· 970 970 971 971 smh Use ARM semihosting calls for early console. 972 972 973 + s3c2410,<addr> 974 + s3c2412,<addr> 975 + s3c2440,<addr> 976 + s3c6400,<addr> 977 + s5pv210,<addr> 978 + exynos4210,<addr> 979 + Use early console provided by serial driver available 980 + on Samsung SoCs, requires selecting proper type and 981 + a correct base address of the selected UART port. The 982 + serial port must already be setup and configured. 983 + Options are not yet supported. 984 + 973 985 earlyprintk= [X86,SH,BLACKFIN,ARM,M68k] 974 986 earlyprintk=vga 975 987 earlyprintk=efi
+1
arch/arm/boot/dts/exynos4210-origen.dts
··· 31 31 32 32 chosen { 33 33 bootargs ="root=/dev/ram0 rw ramdisk=8192 initrd=0x41000000,8M console=ttySAC2,115200 init=/linuxrc"; 34 + stdout-path = &serial_2; 34 35 }; 35 36 36 37 regulators {
+1
arch/arm/boot/dts/exynos4210-smdkv310.dts
··· 27 27 28 28 chosen { 29 29 bootargs = "root=/dev/ram0 rw ramdisk=8192 initrd=0x41000000,8M console=ttySAC1,115200 init=/linuxrc"; 30 + stdout-path = &serial_1; 30 31 }; 31 32 32 33 sdhci@12530000 {
+1
arch/arm/boot/dts/exynos4210-trats.dts
··· 28 28 29 29 chosen { 30 30 bootargs = "console=ttySAC2,115200N8 root=/dev/mmcblk0p5 rootwait earlyprintk panic=5"; 31 + stdout-path = &serial_2; 31 32 }; 32 33 33 34 regulators {
+1
arch/arm/boot/dts/exynos4210-universal_c210.dts
··· 26 26 27 27 chosen { 28 28 bootargs = "console=ttySAC2,115200N8 root=/dev/mmcblk0p5 rw rootwait earlyprintk panic=5 maxcpus=1"; 29 + stdout-path = &serial_2; 29 30 }; 30 31 31 32 sysram@02020000 {
+4
arch/arm/boot/dts/exynos4412-odroid-common.dtsi
··· 12 12 #include "exynos4412.dtsi" 13 13 14 14 / { 15 + chosen { 16 + stdout-path = &serial_1; 17 + }; 18 + 15 19 firmware@0204F000 { 16 20 compatible = "samsung,secure-firmware"; 17 21 reg = <0x0204F000 0x1000>;
+1
arch/arm/boot/dts/exynos4412-origen.dts
··· 26 26 27 27 chosen { 28 28 bootargs ="console=ttySAC2,115200"; 29 + stdout-path = &serial_2; 29 30 }; 30 31 31 32 firmware@0203F000 {
+1
arch/arm/boot/dts/exynos4412-smdk4412.dts
··· 25 25 26 26 chosen { 27 27 bootargs ="root=/dev/ram0 rw ramdisk=8192 initrd=0x41000000,8M console=ttySAC1,115200 init=/linuxrc"; 28 + stdout-path = &serial_1; 28 29 }; 29 30 30 31 g2d@10800000 {
+4
arch/arm/boot/dts/exynos4412-tiny4412.dts
··· 18 18 model = "FriendlyARM TINY4412 board based on Exynos4412"; 19 19 compatible = "friendlyarm,tiny4412", "samsung,exynos4412", "samsung,exynos4"; 20 20 21 + chosen { 22 + stdout-path = &serial_0; 23 + }; 24 + 21 25 memory { 22 26 reg = <0x40000000 0x40000000>; 23 27 };
+1
arch/arm/boot/dts/exynos4412-trats2.dts
··· 32 32 33 33 chosen { 34 34 bootargs = "console=ttySAC2,115200N8 root=/dev/mmcblk0p5 rootwait earlyprintk panic=5"; 35 + stdout-path = &serial_2; 35 36 }; 36 37 37 38 firmware@0204F000 {
-3
arch/x86/include/asm/intel-mid.h
··· 136 136 #define SFI_MTMR_MAX_NUM 8 137 137 #define SFI_MRTC_MAX 8 138 138 139 - extern struct console early_mrst_console; 140 - extern void mrst_early_console_init(void); 141 - 142 139 extern struct console early_hsu_console; 143 140 extern void hsu_early_console_init(const char *); 144 141
+167 -22
arch/x86/kernel/early_printk.c
··· 19 19 #include <linux/usb/ehci_def.h> 20 20 #include <linux/efi.h> 21 21 #include <asm/efi.h> 22 + #include <asm/pci_x86.h> 22 23 23 24 /* Simple VGA output */ 24 25 #define VGABASE (__ISA_IO_base + 0xb8000) ··· 77 76 78 77 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */ 79 78 80 - static int early_serial_base = 0x3f8; /* ttyS0 */ 79 + static unsigned long early_serial_base = 0x3f8; /* ttyS0 */ 81 80 82 81 #define XMTRDY 0x20 83 82 ··· 95 94 #define DLL 0 /* Divisor Latch Low */ 96 95 #define DLH 1 /* Divisor latch High */ 97 96 97 + static void mem32_serial_out(unsigned long addr, int offset, int value) 98 + { 99 + uint32_t *vaddr = (uint32_t *)addr; 100 + /* shift implied by pointer type */ 101 + writel(value, vaddr + offset); 102 + } 103 + 104 + static unsigned int mem32_serial_in(unsigned long addr, int offset) 105 + { 106 + uint32_t *vaddr = (uint32_t *)addr; 107 + /* shift implied by pointer type */ 108 + return readl(vaddr + offset); 109 + } 110 + 111 + static unsigned int io_serial_in(unsigned long addr, int offset) 112 + { 113 + return inb(addr + offset); 114 + } 115 + 116 + static void io_serial_out(unsigned long addr, int offset, int value) 117 + { 118 + outb(value, addr + offset); 119 + } 120 + 121 + static unsigned int (*serial_in)(unsigned long addr, int offset) = io_serial_in; 122 + static void (*serial_out)(unsigned long addr, int offset, int value) = io_serial_out; 123 + 98 124 static int early_serial_putc(unsigned char ch) 99 125 { 100 126 unsigned timeout = 0xffff; 101 127 102 - while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout) 128 + while ((serial_in(early_serial_base, LSR) & XMTRDY) == 0 && --timeout) 103 129 cpu_relax(); 104 - outb(ch, early_serial_base + TXR); 130 + serial_out(early_serial_base, TXR, ch); 105 131 return timeout ? 0 : -1; 106 132 } 107 133 ··· 142 114 } 143 115 } 144 116 117 + static __init void early_serial_hw_init(unsigned divisor) 118 + { 119 + unsigned char c; 120 + 121 + serial_out(early_serial_base, LCR, 0x3); /* 8n1 */ 122 + serial_out(early_serial_base, IER, 0); /* no interrupt */ 123 + serial_out(early_serial_base, FCR, 0); /* no fifo */ 124 + serial_out(early_serial_base, MCR, 0x3); /* DTR + RTS */ 125 + 126 + c = serial_in(early_serial_base, LCR); 127 + serial_out(early_serial_base, LCR, c | DLAB); 128 + serial_out(early_serial_base, DLL, divisor & 0xff); 129 + serial_out(early_serial_base, DLH, (divisor >> 8) & 0xff); 130 + serial_out(early_serial_base, LCR, c & ~DLAB); 131 + } 132 + 145 133 #define DEFAULT_BAUD 9600 146 134 147 135 static __init void early_serial_init(char *s) 148 136 { 149 - unsigned char c; 150 137 unsigned divisor; 151 - unsigned baud = DEFAULT_BAUD; 138 + unsigned long baud = DEFAULT_BAUD; 152 139 char *e; 153 140 154 141 if (*s == ',') ··· 188 145 s++; 189 146 } 190 147 191 - outb(0x3, early_serial_base + LCR); /* 8n1 */ 192 - outb(0, early_serial_base + IER); /* no interrupt */ 193 - outb(0, early_serial_base + FCR); /* no fifo */ 194 - outb(0x3, early_serial_base + MCR); /* DTR + RTS */ 195 - 196 148 if (*s) { 197 - baud = simple_strtoul(s, &e, 0); 198 - if (baud == 0 || s == e) 149 + if (kstrtoul(s, 0, &baud) < 0 || baud == 0) 199 150 baud = DEFAULT_BAUD; 200 151 } 201 152 153 + /* Convert from baud to divisor value */ 202 154 divisor = 115200 / baud; 203 - c = inb(early_serial_base + LCR); 204 - outb(c | DLAB, early_serial_base + LCR); 205 - outb(divisor & 0xff, early_serial_base + DLL); 206 - outb((divisor >> 8) & 0xff, early_serial_base + DLH); 207 - outb(c & ~DLAB, early_serial_base + LCR); 155 + 156 + /* These will always be IO based ports */ 157 + serial_in = io_serial_in; 158 + serial_out = io_serial_out; 159 + 160 + /* Set up the HW */ 161 + early_serial_hw_init(divisor); 208 162 } 163 + 164 + #ifdef CONFIG_PCI 165 + /* 166 + * early_pci_serial_init() 167 + * 168 + * This function is invoked when the early_printk param starts with "pciserial" 169 + * The rest of the param should be ",B:D.F,baud" where B, D & F describe the 170 + * location of a PCI device that must be a UART device. 171 + */ 172 + static __init void early_pci_serial_init(char *s) 173 + { 174 + unsigned divisor; 175 + unsigned long baud = DEFAULT_BAUD; 176 + u8 bus, slot, func; 177 + uint32_t classcode, bar0; 178 + uint16_t cmdreg; 179 + char *e; 180 + 181 + 182 + /* 183 + * First, part the param to get the BDF values 184 + */ 185 + if (*s == ',') 186 + ++s; 187 + 188 + if (*s == 0) 189 + return; 190 + 191 + bus = (u8)simple_strtoul(s, &e, 16); 192 + s = e; 193 + if (*s != ':') 194 + return; 195 + ++s; 196 + slot = (u8)simple_strtoul(s, &e, 16); 197 + s = e; 198 + if (*s != '.') 199 + return; 200 + ++s; 201 + func = (u8)simple_strtoul(s, &e, 16); 202 + s = e; 203 + 204 + /* A baud might be following */ 205 + if (*s == ',') 206 + s++; 207 + 208 + /* 209 + * Second, find the device from the BDF 210 + */ 211 + cmdreg = read_pci_config(bus, slot, func, PCI_COMMAND); 212 + classcode = read_pci_config(bus, slot, func, PCI_CLASS_REVISION); 213 + bar0 = read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_0); 214 + 215 + /* 216 + * Verify it is a UART type device 217 + */ 218 + if (((classcode >> 16 != PCI_CLASS_COMMUNICATION_MODEM) && 219 + (classcode >> 16 != PCI_CLASS_COMMUNICATION_SERIAL)) || 220 + (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */ 221 + return; 222 + 223 + /* 224 + * Determine if it is IO or memory mapped 225 + */ 226 + if (bar0 & 0x01) { 227 + /* it is IO mapped */ 228 + serial_in = io_serial_in; 229 + serial_out = io_serial_out; 230 + early_serial_base = bar0&0xfffffffc; 231 + write_pci_config(bus, slot, func, PCI_COMMAND, 232 + cmdreg|PCI_COMMAND_IO); 233 + } else { 234 + /* It is memory mapped - assume 32-bit alignment */ 235 + serial_in = mem32_serial_in; 236 + serial_out = mem32_serial_out; 237 + /* WARNING! assuming the address is always in the first 4G */ 238 + early_serial_base = 239 + (unsigned long)early_ioremap(bar0 & 0xfffffff0, 0x10); 240 + write_pci_config(bus, slot, func, PCI_COMMAND, 241 + cmdreg|PCI_COMMAND_MEMORY); 242 + } 243 + 244 + /* 245 + * Lastly, initalize the hardware 246 + */ 247 + if (*s) { 248 + if (strcmp(s, "nocfg") == 0) 249 + /* Sometimes, we want to leave the UART alone 250 + * and assume the BIOS has set it up correctly. 251 + * "nocfg" tells us this is the case, and we 252 + * should do no more setup. 253 + */ 254 + return; 255 + if (kstrtoul(s, 0, &baud) < 0 || baud == 0) 256 + baud = DEFAULT_BAUD; 257 + } 258 + 259 + /* Convert from baud to divisor value */ 260 + divisor = 115200 / baud; 261 + 262 + /* Set up the HW */ 263 + early_serial_hw_init(divisor); 264 + } 265 + #endif 209 266 210 267 static struct console early_serial_console = { 211 268 .name = "earlyser", ··· 353 210 early_serial_init(buf + 4); 354 211 early_console_register(&early_serial_console, keep); 355 212 } 213 + #ifdef CONFIG_PCI 214 + if (!strncmp(buf, "pciserial", 9)) { 215 + early_pci_serial_init(buf + 9); 216 + early_console_register(&early_serial_console, keep); 217 + buf += 9; /* Keep from match the above "serial" */ 218 + } 219 + #endif 356 220 if (!strncmp(buf, "vga", 3) && 357 221 boot_params.screen_info.orig_video_isVGA == 1) { 358 222 max_xpos = boot_params.screen_info.orig_video_cols; ··· 376 226 early_console_register(&xenboot_console, keep); 377 227 #endif 378 228 #ifdef CONFIG_EARLY_PRINTK_INTEL_MID 379 - if (!strncmp(buf, "mrst", 4)) { 380 - mrst_early_console_init(); 381 - early_console_register(&early_mrst_console, keep); 382 - } 383 - 384 229 if (!strncmp(buf, "hsu", 3)) { 385 230 hsu_early_console_init(buf + 3); 386 231 early_console_register(&early_hsu_console, keep);
-2
arch/x86/platform/intel-mid/device_libs/Makefile
··· 16 16 obj-$(subst m,y,$(CONFIG_INPUT_BMA150)) += platform_bma023.o 17 17 obj-$(subst m,y,$(CONFIG_GPIO_PCA953X)) += platform_tca6416.o 18 18 obj-$(subst m,y,$(CONFIG_DRM_MEDFIELD)) += platform_tc35876x.o 19 - # SPI Devices 20 - obj-$(subst m,y,$(CONFIG_SERIAL_MRST_MAX3110)) += platform_max3111.o 21 19 # MISC Devices 22 20 obj-$(subst m,y,$(CONFIG_KEYBOARD_GPIO)) += platform_gpio_keys.o 23 21 obj-$(subst m,y,$(CONFIG_INTEL_MID_WATCHDOG)) += platform_wdt.o
-35
arch/x86/platform/intel-mid/device_libs/platform_max3111.c
··· 1 - /* 2 - * platform_max3111.c: max3111 platform data initilization file 3 - * 4 - * (C) Copyright 2013 Intel Corporation 5 - * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com> 6 - * 7 - * This program is free software; you can redistribute it and/or 8 - * modify it under the terms of the GNU General Public License 9 - * as published by the Free Software Foundation; version 2 10 - * of the License. 11 - */ 12 - 13 - #include <linux/gpio.h> 14 - #include <linux/spi/spi.h> 15 - #include <asm/intel-mid.h> 16 - 17 - static void __init *max3111_platform_data(void *info) 18 - { 19 - struct spi_board_info *spi_info = info; 20 - int intr = get_gpio_by_name("max3111_int"); 21 - 22 - spi_info->mode = SPI_MODE_0; 23 - if (intr == -1) 24 - return NULL; 25 - spi_info->irq = intr + INTEL_MID_IRQ_OFFSET; 26 - return NULL; 27 - } 28 - 29 - static const struct devs_id max3111_dev_id __initconst = { 30 - .name = "spi_max3111", 31 - .type = SFI_DEV_TYPE_SPI, 32 - .get_platform_data = &max3111_platform_data, 33 - }; 34 - 35 - sfi_device(max3111_dev_id);
+4 -216
arch/x86/platform/intel-mid/early_printk_intel_mid.c
··· 10 10 */ 11 11 12 12 /* 13 - * This file implements two early consoles named mrst and hsu. 14 - * mrst is based on Maxim3110 spi-uart device, it exists in both 15 - * Moorestown and Medfield platforms, while hsu is based on a High 16 - * Speed UART device which only exists in the Medfield platform 13 + * This file implements early console named hsu. 14 + * hsu is based on a High Speed UART device which only exists in the Medfield 15 + * platform 17 16 */ 18 17 19 18 #include <linux/serial_reg.h> 20 19 #include <linux/serial_mfd.h> 21 - #include <linux/kmsg_dump.h> 22 20 #include <linux/console.h> 23 21 #include <linux/kernel.h> 24 22 #include <linux/delay.h> ··· 25 27 #include <asm/fixmap.h> 26 28 #include <asm/pgtable.h> 27 29 #include <asm/intel-mid.h> 28 - 29 - #define MRST_SPI_TIMEOUT 0x200000 30 - #define MRST_REGBASE_SPI0 0xff128000 31 - #define MRST_REGBASE_SPI1 0xff128400 32 - #define MRST_CLK_SPI0_REG 0xff11d86c 33 - 34 - /* Bit fields in CTRLR0 */ 35 - #define SPI_DFS_OFFSET 0 36 - 37 - #define SPI_FRF_OFFSET 4 38 - #define SPI_FRF_SPI 0x0 39 - #define SPI_FRF_SSP 0x1 40 - #define SPI_FRF_MICROWIRE 0x2 41 - #define SPI_FRF_RESV 0x3 42 - 43 - #define SPI_MODE_OFFSET 6 44 - #define SPI_SCPH_OFFSET 6 45 - #define SPI_SCOL_OFFSET 7 46 - #define SPI_TMOD_OFFSET 8 47 - #define SPI_TMOD_TR 0x0 /* xmit & recv */ 48 - #define SPI_TMOD_TO 0x1 /* xmit only */ 49 - #define SPI_TMOD_RO 0x2 /* recv only */ 50 - #define SPI_TMOD_EPROMREAD 0x3 /* eeprom read mode */ 51 - 52 - #define SPI_SLVOE_OFFSET 10 53 - #define SPI_SRL_OFFSET 11 54 - #define SPI_CFS_OFFSET 12 55 - 56 - /* Bit fields in SR, 7 bits */ 57 - #define SR_MASK 0x7f /* cover 7 bits */ 58 - #define SR_BUSY (1 << 0) 59 - #define SR_TF_NOT_FULL (1 << 1) 60 - #define SR_TF_EMPT (1 << 2) 61 - #define SR_RF_NOT_EMPT (1 << 3) 62 - #define SR_RF_FULL (1 << 4) 63 - #define SR_TX_ERR (1 << 5) 64 - #define SR_DCOL (1 << 6) 65 - 66 - struct dw_spi_reg { 67 - u32 ctrl0; 68 - u32 ctrl1; 69 - u32 ssienr; 70 - u32 mwcr; 71 - u32 ser; 72 - u32 baudr; 73 - u32 txfltr; 74 - u32 rxfltr; 75 - u32 txflr; 76 - u32 rxflr; 77 - u32 sr; 78 - u32 imr; 79 - u32 isr; 80 - u32 risr; 81 - u32 txoicr; 82 - u32 rxoicr; 83 - u32 rxuicr; 84 - u32 msticr; 85 - u32 icr; 86 - u32 dmacr; 87 - u32 dmatdlr; 88 - u32 dmardlr; 89 - u32 idr; 90 - u32 version; 91 - 92 - /* Currently operates as 32 bits, though only the low 16 bits matter */ 93 - u32 dr; 94 - } __packed; 95 - 96 - #define dw_readl(dw, name) __raw_readl(&(dw)->name) 97 - #define dw_writel(dw, name, val) __raw_writel((val), &(dw)->name) 98 - 99 - /* Default use SPI0 register for mrst, we will detect Penwell and use SPI1 */ 100 - static unsigned long mrst_spi_paddr = MRST_REGBASE_SPI0; 101 - 102 - static u32 *pclk_spi0; 103 - /* Always contains an accessible address, start with 0 */ 104 - static struct dw_spi_reg *pspi; 105 - 106 - static struct kmsg_dumper dw_dumper; 107 - static int dumper_registered; 108 - 109 - static void dw_kmsg_dump(struct kmsg_dumper *dumper, 110 - enum kmsg_dump_reason reason) 111 - { 112 - static char line[1024]; 113 - size_t len; 114 - 115 - /* When run to this, we'd better re-init the HW */ 116 - mrst_early_console_init(); 117 - 118 - while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) 119 - early_mrst_console.write(&early_mrst_console, line, len); 120 - } 121 - 122 - /* Set the ratio rate to 115200, 8n1, IRQ disabled */ 123 - static void max3110_write_config(void) 124 - { 125 - u16 config; 126 - 127 - config = 0xc001; 128 - dw_writel(pspi, dr, config); 129 - } 130 - 131 - /* Translate char to a eligible word and send to max3110 */ 132 - static void max3110_write_data(char c) 133 - { 134 - u16 data; 135 - 136 - data = 0x8000 | c; 137 - dw_writel(pspi, dr, data); 138 - } 139 - 140 - void mrst_early_console_init(void) 141 - { 142 - u32 ctrlr0 = 0; 143 - u32 spi0_cdiv; 144 - u32 freq; /* Freqency info only need be searched once */ 145 - 146 - /* Base clk is 100 MHz, the actual clk = 100M / (clk_divider + 1) */ 147 - pclk_spi0 = (void *)set_fixmap_offset_nocache(FIX_EARLYCON_MEM_BASE, 148 - MRST_CLK_SPI0_REG); 149 - spi0_cdiv = ((*pclk_spi0) & 0xe00) >> 9; 150 - freq = 100000000 / (spi0_cdiv + 1); 151 - 152 - if (intel_mid_identify_cpu() == INTEL_MID_CPU_CHIP_PENWELL) 153 - mrst_spi_paddr = MRST_REGBASE_SPI1; 154 - 155 - pspi = (void *)set_fixmap_offset_nocache(FIX_EARLYCON_MEM_BASE, 156 - mrst_spi_paddr); 157 - 158 - /* Disable SPI controller */ 159 - dw_writel(pspi, ssienr, 0); 160 - 161 - /* Set control param, 8 bits, transmit only mode */ 162 - ctrlr0 = dw_readl(pspi, ctrl0); 163 - 164 - ctrlr0 &= 0xfcc0; 165 - ctrlr0 |= 0xf | (SPI_FRF_SPI << SPI_FRF_OFFSET) 166 - | (SPI_TMOD_TO << SPI_TMOD_OFFSET); 167 - dw_writel(pspi, ctrl0, ctrlr0); 168 - 169 - /* 170 - * Change the spi0 clk to comply with 115200 bps, use 100000 to 171 - * calculate the clk dividor to make the clock a little slower 172 - * than real baud rate. 173 - */ 174 - dw_writel(pspi, baudr, freq/100000); 175 - 176 - /* Disable all INT for early phase */ 177 - dw_writel(pspi, imr, 0x0); 178 - 179 - /* Set the cs to spi-uart */ 180 - dw_writel(pspi, ser, 0x2); 181 - 182 - /* Enable the HW, the last step for HW init */ 183 - dw_writel(pspi, ssienr, 0x1); 184 - 185 - /* Set the default configuration */ 186 - max3110_write_config(); 187 - 188 - /* Register the kmsg dumper */ 189 - if (!dumper_registered) { 190 - dw_dumper.dump = dw_kmsg_dump; 191 - kmsg_dump_register(&dw_dumper); 192 - dumper_registered = 1; 193 - } 194 - } 195 - 196 - /* Slave select should be called in the read/write function */ 197 - static void early_mrst_spi_putc(char c) 198 - { 199 - unsigned int timeout; 200 - u32 sr; 201 - 202 - timeout = MRST_SPI_TIMEOUT; 203 - /* Early putc needs to make sure the TX FIFO is not full */ 204 - while (--timeout) { 205 - sr = dw_readl(pspi, sr); 206 - if (!(sr & SR_TF_NOT_FULL)) 207 - cpu_relax(); 208 - else 209 - break; 210 - } 211 - 212 - if (!timeout) 213 - pr_warn("MRST earlycon: timed out\n"); 214 - else 215 - max3110_write_data(c); 216 - } 217 - 218 - /* Early SPI only uses polling mode */ 219 - static void early_mrst_spi_write(struct console *con, const char *str, 220 - unsigned n) 221 - { 222 - int i; 223 - 224 - for (i = 0; i < n && *str; i++) { 225 - if (*str == '\n') 226 - early_mrst_spi_putc('\r'); 227 - early_mrst_spi_putc(*str); 228 - str++; 229 - } 230 - } 231 - 232 - struct console early_mrst_console = { 233 - .name = "earlymrst", 234 - .write = early_mrst_spi_write, 235 - .flags = CON_PRINTBUFFER, 236 - .index = -1, 237 - }; 238 30 239 31 /* 240 32 * Following is the early console based on Medfield HSU (High ··· 47 259 port = clamp_val(port, 0, 2); 48 260 49 261 paddr = HSU_PORT_BASE + port * 0x80; 50 - phsu = (void *)set_fixmap_offset_nocache(FIX_EARLYCON_MEM_BASE, paddr); 262 + phsu = (void __iomem *)set_fixmap_offset_nocache(FIX_EARLYCON_MEM_BASE, paddr); 51 263 52 264 /* Disable FIFO */ 53 265 writeb(0x0, phsu + UART_FCR);
+2 -13
drivers/bluetooth/hci_ath.c
··· 51 51 52 52 static int ath_wakeup_ar3k(struct tty_struct *tty) 53 53 { 54 - struct ktermios ktermios; 55 54 int status = tty->driver->ops->tiocmget(tty); 56 55 57 56 if (status & TIOCM_CTS) 58 57 return status; 59 58 60 - /* Disable Automatic RTSCTS */ 61 - ktermios = tty->termios; 62 - ktermios.c_cflag &= ~CRTSCTS; 63 - tty_set_termios(tty, &ktermios); 64 - 65 59 /* Clear RTS first */ 66 - status = tty->driver->ops->tiocmget(tty); 60 + tty->driver->ops->tiocmget(tty); 67 61 tty->driver->ops->tiocmset(tty, 0x00, TIOCM_RTS); 68 62 mdelay(20); 69 63 70 64 /* Set RTS, wake up board */ 71 - status = tty->driver->ops->tiocmget(tty); 65 + tty->driver->ops->tiocmget(tty); 72 66 tty->driver->ops->tiocmset(tty, TIOCM_RTS, 0x00); 73 67 mdelay(20); 74 68 75 69 status = tty->driver->ops->tiocmget(tty); 76 - 77 - /* Enable Automatic RTSCTS */ 78 - ktermios.c_cflag |= CRTSCTS; 79 - status = tty_set_termios(tty, &ktermios); 80 - 81 70 return status; 82 71 } 83 72
+1 -1
drivers/pnp/driver.c
··· 182 182 return error; 183 183 } 184 184 185 - if (pnp_dev->protocol->suspend) 185 + if (pnp_can_suspend(pnp_dev)) 186 186 pnp_dev->protocol->suspend(pnp_dev, state); 187 187 return 0; 188 188 }
+1 -1
drivers/tty/amiserial.c
··· 931 931 struct serial_state *info = tty->driver_data; 932 932 unsigned long flags; 933 933 934 - if (serial_paranoia_check(info, tty->name, "rs_send_char")) 934 + if (serial_paranoia_check(info, tty->name, "rs_send_xchar")) 935 935 return; 936 936 937 937 info->x_char = ch;
-1
drivers/tty/ehv_bytechan.c
··· 112 112 static int find_console_handle(void) 113 113 { 114 114 struct device_node *np = of_stdout; 115 - const char *sprop = NULL; 116 115 const uint32_t *iprop; 117 116 118 117 /* We don't care what the aliased node is actually called. We only
+1 -1
drivers/tty/isicom.c
··· 1055 1055 1056 1056 outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base); 1057 1057 outw((length & 0xff) << 8 | 0x00, base); 1058 - outw((length & 0xff00), base); 1058 + outw((length & 0xff00u), base); 1059 1059 InterruptTheCard(base); 1060 1060 1061 1061 unlock_card(card);
+149 -105
drivers/tty/n_tty.c
··· 90 90 struct n_tty_data { 91 91 /* producer-published */ 92 92 size_t read_head; 93 + size_t commit_head; 93 94 size_t canon_head; 94 95 size_t echo_head; 95 96 size_t echo_commit; ··· 162 161 return put_user(x, ptr); 163 162 } 164 163 165 - static int receive_room(struct tty_struct *tty) 166 - { 167 - struct n_tty_data *ldata = tty->disc_data; 168 - int left; 169 - 170 - if (I_PARMRK(tty)) { 171 - /* Multiply read_cnt by 3, since each byte might take up to 172 - * three times as many spaces when PARMRK is set (depending on 173 - * its flags, e.g. parity error). */ 174 - left = N_TTY_BUF_SIZE - read_cnt(ldata) * 3 - 1; 175 - } else 176 - left = N_TTY_BUF_SIZE - read_cnt(ldata) - 1; 177 - 178 - /* 179 - * If we are doing input canonicalization, and there are no 180 - * pending newlines, let characters through without limit, so 181 - * that erase characters will be handled. Other excess 182 - * characters will be beeped. 183 - */ 184 - if (left <= 0) 185 - left = ldata->icanon && ldata->canon_head == ldata->read_tail; 186 - 187 - return left; 188 - } 189 - 190 164 /** 191 - * n_tty_set_room - receive space 165 + * n_tty_kick_worker - start input worker (if required) 192 166 * @tty: terminal 193 167 * 194 - * Re-schedules the flip buffer work if space just became available. 168 + * Re-schedules the flip buffer work if it may have stopped 195 169 * 196 170 * Caller holds exclusive termios_rwsem 197 171 * or ··· 174 198 * holds non-exclusive termios_rwsem 175 199 */ 176 200 177 - static void n_tty_set_room(struct tty_struct *tty) 201 + static void n_tty_kick_worker(struct tty_struct *tty) 178 202 { 179 203 struct n_tty_data *ldata = tty->disc_data; 180 204 181 - /* Did this open up the receive buffer? We may need to flip */ 182 - if (unlikely(ldata->no_room) && receive_room(tty)) { 205 + /* Did the input worker stop? Restart it */ 206 + if (unlikely(ldata->no_room)) { 183 207 ldata->no_room = 0; 184 208 185 209 WARN_RATELIMIT(tty->port->itty == NULL, ··· 200 224 ssize_t n = 0; 201 225 202 226 if (!ldata->icanon) 203 - n = read_cnt(ldata); 227 + n = ldata->commit_head - ldata->read_tail; 204 228 else 205 229 n = ldata->canon_head - ldata->read_tail; 206 230 return n; ··· 223 247 224 248 static void n_tty_check_throttle(struct tty_struct *tty) 225 249 { 226 - if (tty->driver->type == TTY_DRIVER_TYPE_PTY) 227 - return; 250 + struct n_tty_data *ldata = tty->disc_data; 251 + 228 252 /* 229 253 * Check the remaining room for the input canonicalization 230 254 * mode. We don't want to throttle the driver if we're in 231 255 * canonical mode and don't have a newline yet! 232 256 */ 257 + if (ldata->icanon && ldata->canon_head == ldata->read_tail) 258 + return; 259 + 233 260 while (1) { 234 261 int throttled; 235 262 tty_set_flow_change(tty, TTY_THROTTLE_SAFE); 236 - if (receive_room(tty) >= TTY_THRESHOLD_THROTTLE) 263 + if (N_TTY_BUF_SIZE - read_cnt(ldata) >= TTY_THRESHOLD_THROTTLE) 237 264 break; 238 265 throttled = tty_throttle_safe(tty); 239 266 if (!throttled) ··· 253 274 return; 254 275 if (!tty->count) 255 276 return; 256 - n_tty_set_room(tty); 277 + n_tty_kick_worker(tty); 257 278 n_tty_write_wakeup(tty->link); 258 279 if (waitqueue_active(&tty->link->write_wait)) 259 280 wake_up_interruptible_poll(&tty->link->write_wait, POLLOUT); ··· 275 296 break; 276 297 if (!tty->count) 277 298 break; 278 - n_tty_set_room(tty); 299 + n_tty_kick_worker(tty); 279 300 unthrottled = tty_unthrottle_safe(tty); 280 301 if (!unthrottled) 281 302 break; ··· 292 313 * 293 314 * n_tty_receive_buf()/producer path: 294 315 * caller holds non-exclusive termios_rwsem 295 - * modifies read_head 296 - * 297 - * read_head is only considered 'published' if canonical mode is 298 - * not active. 299 316 */ 300 317 301 318 static inline void put_tty_queue(unsigned char c, struct n_tty_data *ldata) ··· 315 340 { 316 341 ldata->read_head = ldata->canon_head = ldata->read_tail = 0; 317 342 ldata->echo_head = ldata->echo_tail = ldata->echo_commit = 0; 343 + ldata->commit_head = 0; 318 344 ldata->echo_mark = 0; 319 345 ldata->line_start = 0; 320 346 ··· 355 379 { 356 380 down_write(&tty->termios_rwsem); 357 381 reset_buffer_flags(tty->disc_data); 358 - n_tty_set_room(tty); 382 + n_tty_kick_worker(tty); 359 383 360 384 if (tty->link) 361 385 n_tty_packet_mode_flush(tty); ··· 963 987 * 964 988 * n_tty_receive_buf()/producer path: 965 989 * caller holds non-exclusive termios_rwsem 966 - * modifies read_head 967 - * 968 - * Modifying the read_head is not considered a publish in this context 969 - * because canonical mode is active -- only canon_head publishes 970 990 */ 971 991 972 992 static void eraser(unsigned char c, struct tty_struct *tty) ··· 1090 1118 * Called when a signal is being sent due to terminal input. 1091 1119 * Called from the driver receive_buf path so serialized. 1092 1120 * 1121 + * Performs input and output flush if !NOFLSH. In this context, the echo 1122 + * buffer is 'output'. The signal is processed first to alert any current 1123 + * readers or writers to discontinue and exit their i/o loops. 1124 + * 1093 1125 * Locking: ctrl_lock 1094 1126 */ 1095 1127 1096 1128 static void isig(int sig, struct tty_struct *tty) 1097 1129 { 1130 + struct n_tty_data *ldata = tty->disc_data; 1098 1131 struct pid *tty_pgrp = tty_get_pgrp(tty); 1099 1132 if (tty_pgrp) { 1100 1133 kill_pgrp(tty_pgrp, sig, 1); 1101 1134 put_pid(tty_pgrp); 1135 + } 1136 + 1137 + if (!L_NOFLSH(tty)) { 1138 + up_read(&tty->termios_rwsem); 1139 + down_write(&tty->termios_rwsem); 1140 + 1141 + /* clear echo buffer */ 1142 + mutex_lock(&ldata->output_lock); 1143 + ldata->echo_head = ldata->echo_tail = 0; 1144 + ldata->echo_mark = ldata->echo_commit = 0; 1145 + mutex_unlock(&ldata->output_lock); 1146 + 1147 + /* clear output buffer */ 1148 + tty_driver_flush_buffer(tty); 1149 + 1150 + /* clear input buffer */ 1151 + reset_buffer_flags(tty->disc_data); 1152 + 1153 + /* notify pty master of flush */ 1154 + if (tty->link) 1155 + n_tty_packet_mode_flush(tty); 1156 + 1157 + up_write(&tty->termios_rwsem); 1158 + down_read(&tty->termios_rwsem); 1102 1159 } 1103 1160 } 1104 1161 ··· 1140 1139 * 1141 1140 * n_tty_receive_buf()/producer path: 1142 1141 * caller holds non-exclusive termios_rwsem 1143 - * publishes read_head via put_tty_queue() 1144 1142 * 1145 1143 * Note: may get exclusive termios_rwsem if flushing input buffer 1146 1144 */ ··· 1152 1152 return; 1153 1153 if (I_BRKINT(tty)) { 1154 1154 isig(SIGINT, tty); 1155 - if (!L_NOFLSH(tty)) { 1156 - /* flushing needs exclusive termios_rwsem */ 1157 - up_read(&tty->termios_rwsem); 1158 - n_tty_flush_buffer(tty); 1159 - tty_driver_flush_buffer(tty); 1160 - down_read(&tty->termios_rwsem); 1161 - } 1162 1155 return; 1163 1156 } 1164 1157 if (I_PARMRK(tty)) { ··· 1202 1209 * 1203 1210 * n_tty_receive_buf()/producer path: 1204 1211 * caller holds non-exclusive termios_rwsem 1205 - * publishes read_head via put_tty_queue() 1206 1212 */ 1207 1213 static void n_tty_receive_parity_error(struct tty_struct *tty, unsigned char c) 1208 1214 { ··· 1225 1233 static void 1226 1234 n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c) 1227 1235 { 1228 - if (!L_NOFLSH(tty)) { 1229 - /* flushing needs exclusive termios_rwsem */ 1230 - up_read(&tty->termios_rwsem); 1231 - n_tty_flush_buffer(tty); 1232 - tty_driver_flush_buffer(tty); 1233 - down_read(&tty->termios_rwsem); 1234 - } 1236 + isig(signal, tty); 1235 1237 if (I_IXON(tty)) 1236 1238 start_tty(tty); 1237 1239 if (L_ECHO(tty)) { ··· 1233 1247 commit_echoes(tty); 1234 1248 } else 1235 1249 process_echoes(tty); 1236 - isig(signal, tty); 1237 1250 return; 1238 1251 } 1239 1252 ··· 1248 1263 * n_tty_receive_buf()/producer path: 1249 1264 * caller holds non-exclusive termios_rwsem 1250 1265 * publishes canon_head if canonical mode is active 1251 - * otherwise, publishes read_head via put_tty_queue() 1252 1266 * 1253 1267 * Returns 1 if LNEXT was received, else returns 0 1254 1268 */ ··· 1360 1376 handle_newline: 1361 1377 set_bit(ldata->read_head & (N_TTY_BUF_SIZE - 1), ldata->read_flags); 1362 1378 put_tty_queue(c, ldata); 1363 - ldata->canon_head = ldata->read_head; 1379 + smp_store_release(&ldata->canon_head, ldata->read_head); 1364 1380 kill_fasync(&tty->fasync, SIGIO, POLL_IN); 1365 1381 if (waitqueue_active(&tty->read_wait)) 1366 1382 wake_up_interruptible_poll(&tty->read_wait, POLLIN); ··· 1496 1512 n_tty_receive_char_flagged(tty, c, flag); 1497 1513 } 1498 1514 1499 - /** 1500 - * n_tty_receive_buf - data receive 1501 - * @tty: terminal device 1502 - * @cp: buffer 1503 - * @fp: flag buffer 1504 - * @count: characters 1505 - * 1506 - * Called by the terminal driver when a block of characters has 1507 - * been received. This function must be called from soft contexts 1508 - * not from interrupt context. The driver is responsible for making 1509 - * calls one at a time and in order (or using flush_to_ldisc) 1510 - * 1511 - * n_tty_receive_buf()/producer path: 1512 - * claims non-exclusive termios_rwsem 1513 - * publishes read_head and canon_head 1514 - */ 1515 - 1516 1515 static void 1517 1516 n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp, 1518 1517 char *fp, int count) ··· 1504 1537 size_t n, head; 1505 1538 1506 1539 head = ldata->read_head & (N_TTY_BUF_SIZE - 1); 1507 - n = N_TTY_BUF_SIZE - max(read_cnt(ldata), head); 1508 - n = min_t(size_t, count, n); 1540 + n = min_t(size_t, count, N_TTY_BUF_SIZE - head); 1509 1541 memcpy(read_buf_addr(ldata, head), cp, n); 1510 1542 ldata->read_head += n; 1511 1543 cp += n; 1512 1544 count -= n; 1513 1545 1514 1546 head = ldata->read_head & (N_TTY_BUF_SIZE - 1); 1515 - n = N_TTY_BUF_SIZE - max(read_cnt(ldata), head); 1516 - n = min_t(size_t, count, n); 1547 + n = min_t(size_t, count, N_TTY_BUF_SIZE - head); 1517 1548 memcpy(read_buf_addr(ldata, head), cp, n); 1518 1549 ldata->read_head += n; 1519 1550 } ··· 1641 1676 tty->ops->flush_chars(tty); 1642 1677 } 1643 1678 1644 - if ((!ldata->icanon && (read_cnt(ldata) >= ldata->minimum_to_wake)) || 1645 - L_EXTPROC(tty)) { 1679 + if (ldata->icanon && !L_EXTPROC(tty)) 1680 + return; 1681 + 1682 + /* publish read_head to consumer */ 1683 + smp_store_release(&ldata->commit_head, ldata->read_head); 1684 + 1685 + if ((read_cnt(ldata) >= ldata->minimum_to_wake) || L_EXTPROC(tty)) { 1646 1686 kill_fasync(&tty->fasync, SIGIO, POLL_IN); 1647 1687 if (waitqueue_active(&tty->read_wait)) 1648 1688 wake_up_interruptible_poll(&tty->read_wait, POLLIN); 1649 1689 } 1650 1690 } 1651 1691 1692 + /** 1693 + * n_tty_receive_buf_common - process input 1694 + * @tty: device to receive input 1695 + * @cp: input chars 1696 + * @fp: flags for each char (if NULL, all chars are TTY_NORMAL) 1697 + * @count: number of input chars in @cp 1698 + * 1699 + * Called by the terminal driver when a block of characters has 1700 + * been received. This function must be called from soft contexts 1701 + * not from interrupt context. The driver is responsible for making 1702 + * calls one at a time and in order (or using flush_to_ldisc) 1703 + * 1704 + * Returns the # of input chars from @cp which were processed. 1705 + * 1706 + * In canonical mode, the maximum line length is 4096 chars (including 1707 + * the line termination char); lines longer than 4096 chars are 1708 + * truncated. After 4095 chars, input data is still processed but 1709 + * not stored. Overflow processing ensures the tty can always 1710 + * receive more input until at least one line can be read. 1711 + * 1712 + * In non-canonical mode, the read buffer will only accept 4095 chars; 1713 + * this provides the necessary space for a newline char if the input 1714 + * mode is switched to canonical. 1715 + * 1716 + * Note it is possible for the read buffer to _contain_ 4096 chars 1717 + * in non-canonical mode: the read buffer could already contain the 1718 + * maximum canon line of 4096 chars when the mode is switched to 1719 + * non-canonical. 1720 + * 1721 + * n_tty_receive_buf()/producer path: 1722 + * claims non-exclusive termios_rwsem 1723 + * publishes commit_head or canon_head 1724 + */ 1652 1725 static int 1653 1726 n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp, 1654 1727 char *fp, int count, int flow) 1655 1728 { 1656 1729 struct n_tty_data *ldata = tty->disc_data; 1657 - int room, n, rcvd = 0; 1730 + int room, n, rcvd = 0, overflow; 1658 1731 1659 1732 down_read(&tty->termios_rwsem); 1660 1733 1661 1734 while (1) { 1662 - room = receive_room(tty); 1735 + /* 1736 + * When PARMRK is set, each input char may take up to 3 chars 1737 + * in the read buf; reduce the buffer space avail by 3x 1738 + * 1739 + * If we are doing input canonicalization, and there are no 1740 + * pending newlines, let characters through without limit, so 1741 + * that erase characters will be handled. Other excess 1742 + * characters will be beeped. 1743 + * 1744 + * paired with store in *_copy_from_read_buf() -- guarantees 1745 + * the consumer has loaded the data in read_buf up to the new 1746 + * read_tail (so this producer will not overwrite unread data) 1747 + */ 1748 + size_t tail = smp_load_acquire(&ldata->read_tail); 1749 + 1750 + room = N_TTY_BUF_SIZE - (ldata->read_head - tail); 1751 + if (I_PARMRK(tty)) 1752 + room = (room + 2) / 3; 1753 + room--; 1754 + if (room <= 0) { 1755 + overflow = ldata->icanon && ldata->canon_head == tail; 1756 + if (overflow && room < 0) 1757 + ldata->read_head--; 1758 + room = overflow; 1759 + ldata->no_room = flow && !room; 1760 + } else 1761 + overflow = 0; 1762 + 1663 1763 n = min(count, room); 1664 - if (!n) { 1665 - if (flow && !room) 1666 - ldata->no_room = 1; 1764 + if (!n) 1667 1765 break; 1668 - } 1669 - __receive_buf(tty, cp, fp, n); 1766 + 1767 + /* ignore parity errors if handling overflow */ 1768 + if (!overflow || !fp || *fp != TTY_PARITY) 1769 + __receive_buf(tty, cp, fp, n); 1770 + 1670 1771 cp += n; 1671 1772 if (fp) 1672 1773 fp += n; ··· 1741 1710 } 1742 1711 1743 1712 tty->receive_room = room; 1744 - n_tty_check_throttle(tty); 1713 + 1714 + /* Unthrottle if handling overflow on pty */ 1715 + if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { 1716 + if (overflow) { 1717 + tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); 1718 + tty_unthrottle_safe(tty); 1719 + __tty_set_flow_change(tty, 0); 1720 + } 1721 + } else 1722 + n_tty_check_throttle(tty); 1723 + 1745 1724 up_read(&tty->termios_rwsem); 1746 1725 1747 1726 return rcvd; ··· 1805 1764 ldata->canon_head = ldata->read_head; 1806 1765 ldata->push = 1; 1807 1766 } 1767 + ldata->commit_head = ldata->read_head; 1808 1768 ldata->erasing = 0; 1809 1769 ldata->lnext = 0; 1810 1770 } ··· 1859 1817 else 1860 1818 ldata->real_raw = 0; 1861 1819 } 1862 - n_tty_set_room(tty); 1863 1820 /* 1864 1821 * Fix tty hang when I_IXON(tty) is cleared, but the tty 1865 1822 * been stopped by STOP_CHAR(tty) before it. ··· 1946 1905 if (ldata->icanon && !L_EXTPROC(tty)) 1947 1906 return ldata->canon_head != ldata->read_tail; 1948 1907 else 1949 - return read_cnt(ldata) >= amt; 1908 + return ldata->commit_head - ldata->read_tail >= amt; 1950 1909 } 1951 1910 1952 1911 /** ··· 1978 1937 int retval; 1979 1938 size_t n; 1980 1939 bool is_eof; 1940 + size_t head = smp_load_acquire(&ldata->commit_head); 1981 1941 size_t tail = ldata->read_tail & (N_TTY_BUF_SIZE - 1); 1982 1942 1983 1943 retval = 0; 1984 - n = min(read_cnt(ldata), N_TTY_BUF_SIZE - tail); 1944 + n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail); 1985 1945 n = min(*nr, n); 1986 1946 if (n) { 1987 1947 retval = copy_to_user(*b, read_buf_addr(ldata, tail), n); ··· 1990 1948 is_eof = n == 1 && read_buf(ldata, tail) == EOF_CHAR(tty); 1991 1949 tty_audit_add_data(tty, read_buf_addr(ldata, tail), n, 1992 1950 ldata->icanon); 1993 - ldata->read_tail += n; 1951 + smp_store_release(&ldata->read_tail, ldata->read_tail + n); 1994 1952 /* Turn single EOF into zero-length read */ 1995 - if (L_EXTPROC(tty) && ldata->icanon && is_eof && !read_cnt(ldata)) 1953 + if (L_EXTPROC(tty) && ldata->icanon && is_eof && 1954 + (head == ldata->read_tail)) 1996 1955 n = 0; 1997 1956 *b += n; 1998 1957 *nr -= n; ··· 2036 1993 bool eof_push = 0; 2037 1994 2038 1995 /* N.B. avoid overrun if nr == 0 */ 2039 - n = min(*nr, read_cnt(ldata)); 1996 + n = min(*nr, smp_load_acquire(&ldata->canon_head) - ldata->read_tail); 2040 1997 if (!n) 2041 1998 return 0; 2042 1999 ··· 2086 2043 2087 2044 if (found) 2088 2045 clear_bit(eol, ldata->read_flags); 2089 - smp_mb__after_atomic(); 2090 - ldata->read_tail += c; 2046 + smp_store_release(&ldata->read_tail, ldata->read_tail + c); 2091 2047 2092 2048 if (found) { 2093 2049 if (!ldata->push) ··· 2172 2130 ssize_t retval = 0; 2173 2131 long timeout; 2174 2132 int packet; 2133 + size_t tail; 2175 2134 2176 2135 c = job_control(tty, file); 2177 2136 if (c < 0) ··· 2209 2166 } 2210 2167 2211 2168 packet = tty->packet; 2169 + tail = ldata->read_tail; 2212 2170 2213 2171 add_wait_queue(&tty->read_wait, &wait); 2214 2172 while (nr) { ··· 2252 2208 retval = -ERESTARTSYS; 2253 2209 break; 2254 2210 } 2255 - n_tty_set_room(tty); 2256 2211 up_read(&tty->termios_rwsem); 2257 2212 2258 2213 timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, ··· 2296 2253 if (time) 2297 2254 timeout = time; 2298 2255 } 2299 - n_tty_set_room(tty); 2256 + if (tail != ldata->read_tail) 2257 + n_tty_kick_worker(tty); 2300 2258 up_read(&tty->termios_rwsem); 2301 2259 2302 2260 remove_wait_queue(&tty->read_wait, &wait);
+16 -15
drivers/tty/pty.c
··· 88 88 } 89 89 90 90 /** 91 - * pty_space - report space left for writing 92 - * @to: tty we are writing into 93 - * 94 - * Limit the buffer space used by ptys to 8k. 95 - */ 96 - 97 - static int pty_space(struct tty_struct *to) 98 - { 99 - int n = tty_buffer_space_avail(to->port); 100 - return min(n, 8192); 101 - } 102 - 103 - /** 104 91 * pty_write - write to a pty 105 92 * @tty: the tty we write from 106 93 * @buf: kernel buffer of data ··· 128 141 { 129 142 if (tty->stopped) 130 143 return 0; 131 - return pty_space(tty->link); 144 + return tty_buffer_space_avail(tty->link->port); 132 145 } 133 146 134 147 /** ··· 197 210 { 198 211 struct pid *pgrp; 199 212 213 + if (sig != SIGINT && sig != SIGQUIT && sig != SIGTSTP) 214 + return -EINVAL; 215 + 200 216 if (tty->link) { 201 217 pgrp = tty_get_pgrp(tty->link); 202 218 if (pgrp) ··· 212 222 static void pty_flush_buffer(struct tty_struct *tty) 213 223 { 214 224 struct tty_struct *to = tty->link; 225 + struct tty_ldisc *ld; 215 226 216 227 if (!to) 217 228 return; 218 - /* tty_buffer_flush(to); FIXME */ 229 + 230 + ld = tty_ldisc_ref(to); 231 + tty_buffer_flush(to, ld); 232 + if (ld) 233 + tty_ldisc_deref(ld); 234 + 219 235 if (to->packet) { 220 236 spin_lock_irq(&tty->ctrl_lock); 221 237 tty->ctrl_status |= TIOCPKT_FLUSHWRITE; ··· 395 399 goto err_put_module; 396 400 397 401 tty_set_lock_subclass(o_tty); 402 + lockdep_set_subclass(&o_tty->termios_rwsem, TTY_LOCK_SLAVE); 398 403 399 404 if (legacy) { 400 405 /* We always use new tty termios data so we can do this ··· 426 429 o_tty->link = tty; 427 430 tty_port_init(ports[0]); 428 431 tty_port_init(ports[1]); 432 + tty_buffer_set_limit(ports[0], 8192); 433 + tty_buffer_set_limit(ports[1], 8192); 429 434 o_tty->port = ports[0]; 430 435 tty->port = ports[1]; 431 436 o_tty->port->itty = o_tty; 437 + 438 + tty_buffer_set_lock_subclass(o_tty->port); 432 439 433 440 tty_driver_kref_get(driver); 434 441 tty->count++;
+2 -2
drivers/tty/rocket.c
··· 1390 1390 tty->ldisc.chars_in_buffer(tty)); 1391 1391 #endif 1392 1392 1393 - if (rocket_paranoia_check(info, "rp_throttle")) 1393 + if (rocket_paranoia_check(info, "rp_unthrottle")) 1394 1394 return; 1395 1395 1396 1396 if (I_IXOFF(tty)) ··· 1458 1458 1459 1459 orig_jiffies = jiffies; 1460 1460 #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT 1461 - printk(KERN_INFO "In RP_wait_until_sent(%d) (jiff=%lu)...\n", timeout, 1461 + printk(KERN_INFO "In %s(%d) (jiff=%lu)...\n", __func__, timeout, 1462 1462 jiffies); 1463 1463 printk(KERN_INFO "cps=%d...\n", info->cps); 1464 1464 #endif
+162 -68
drivers/tty/serial/8250/8250_core.c
··· 329 329 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 330 330 .flags = UART_CAP_FIFO | UART_CAP_AFE, 331 331 }, 332 + /* tx_loadsz is set to 63-bytes instead of 64-bytes to implement 333 + workaround of errata A-008006 which states that tx_loadsz should be 334 + configured less than Maximum supported fifo bytes */ 335 + [PORT_16550A_FSL64] = { 336 + .name = "16550A_FSL64", 337 + .fifo_size = 64, 338 + .tx_loadsz = 63, 339 + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | 340 + UART_FCR7_64BYTE, 341 + .flags = UART_CAP_FIFO, 342 + }, 332 343 }; 333 344 334 345 /* Uart divisor latch read */ ··· 967 956 up->port.type = PORT_16650; 968 957 up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; 969 958 } else { 970 - DEBUG_AUTOCONF("Motorola 8xxx DUART "); 959 + serial_out(up, UART_LCR, 0); 960 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 961 + UART_FCR7_64BYTE); 962 + status1 = serial_in(up, UART_IIR) >> 5; 963 + serial_out(up, UART_FCR, 0); 964 + serial_out(up, UART_LCR, 0); 965 + 966 + if (status1 == 7) 967 + up->port.type = PORT_16550A_FSL64; 968 + else 969 + DEBUG_AUTOCONF("Motorola 8xxx DUART "); 971 970 } 972 971 serial_out(up, UART_EFR, 0); 973 972 return; ··· 1376 1355 struct uart_8250_port *up = up_to_u8250p(port); 1377 1356 1378 1357 serial8250_rpm_get_tx(up); 1379 - if (up->dma && !up->dma->tx_dma(up)) { 1358 + 1359 + if (up->dma && !up->dma->tx_dma(up)) 1380 1360 return; 1381 - } else if (!(up->ier & UART_IER_THRI)) { 1361 + 1362 + if (!(up->ier & UART_IER_THRI)) { 1382 1363 up->ier |= UART_IER_THRI; 1383 1364 serial_port_out(port, UART_IER, up->ier); 1384 1365 ··· 1388 1365 unsigned char lsr; 1389 1366 lsr = serial_in(up, UART_LSR); 1390 1367 up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; 1391 - if (lsr & UART_LSR_TEMT) 1368 + if (lsr & UART_LSR_THRE) 1392 1369 serial8250_tx_chars(up); 1393 1370 } 1394 1371 } ··· 1947 1924 return ret; 1948 1925 } 1949 1926 1950 - static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) 1927 + void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl) 1951 1928 { 1952 1929 struct uart_8250_port *up = up_to_u8250p(port); 1953 1930 unsigned char mcr = 0; ··· 1966 1943 mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; 1967 1944 1968 1945 serial_port_out(port, UART_MCR, mcr); 1946 + } 1947 + EXPORT_SYMBOL_GPL(serial8250_do_set_mctrl); 1948 + 1949 + static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) 1950 + { 1951 + if (port->set_mctrl) 1952 + return port->set_mctrl(port, mctrl); 1953 + return serial8250_do_set_mctrl(port, mctrl); 1969 1954 } 1970 1955 1971 1956 static void serial8250_break_ctl(struct uart_port *port, int break_state) ··· 2413 2382 serial8250_do_shutdown(port); 2414 2383 } 2415 2384 2416 - static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud) 2385 + /* 2386 + * XR17V35x UARTs have an extra fractional divisor register (DLD) 2387 + * Calculate divisor with extra 4-bit fractional portion 2388 + */ 2389 + static unsigned int xr17v35x_get_divisor(struct uart_8250_port *up, 2390 + unsigned int baud, 2391 + unsigned int *frac) 2417 2392 { 2393 + struct uart_port *port = &up->port; 2394 + unsigned int quot_16; 2395 + 2396 + quot_16 = DIV_ROUND_CLOSEST(port->uartclk, baud); 2397 + *frac = quot_16 & 0x0f; 2398 + 2399 + return quot_16 >> 4; 2400 + } 2401 + 2402 + static unsigned int serial8250_get_divisor(struct uart_8250_port *up, 2403 + unsigned int baud, 2404 + unsigned int *frac) 2405 + { 2406 + struct uart_port *port = &up->port; 2418 2407 unsigned int quot; 2419 2408 2420 2409 /* 2421 2410 * Handle magic divisors for baud rates above baud_base on 2422 2411 * SMSC SuperIO chips. 2412 + * 2423 2413 */ 2424 2414 if ((port->flags & UPF_MAGIC_MULTIPLIER) && 2425 2415 baud == (port->uartclk/4)) ··· 2448 2396 else if ((port->flags & UPF_MAGIC_MULTIPLIER) && 2449 2397 baud == (port->uartclk/8)) 2450 2398 quot = 0x8002; 2399 + else if (up->port.type == PORT_XR17V35X) 2400 + quot = xr17v35x_get_divisor(up, baud, frac); 2451 2401 else 2452 2402 quot = uart_get_divisor(port, baud); 2403 + 2404 + /* 2405 + * Oxford Semi 952 rev B workaround 2406 + */ 2407 + if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0) 2408 + quot++; 2453 2409 2454 2410 return quot; 2455 2411 } 2456 2412 2457 - void 2458 - serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, 2459 - struct ktermios *old) 2413 + static unsigned char serial8250_compute_lcr(struct uart_8250_port *up, 2414 + tcflag_t c_cflag) 2460 2415 { 2461 - struct uart_8250_port *up = up_to_u8250p(port); 2462 2416 unsigned char cval; 2463 - unsigned long flags; 2464 - unsigned int baud, quot; 2465 2417 2466 - switch (termios->c_cflag & CSIZE) { 2418 + switch (c_cflag & CSIZE) { 2467 2419 case CS5: 2468 2420 cval = UART_LCR_WLEN5; 2469 2421 break; ··· 2483 2427 break; 2484 2428 } 2485 2429 2486 - if (termios->c_cflag & CSTOPB) 2430 + if (c_cflag & CSTOPB) 2487 2431 cval |= UART_LCR_STOP; 2488 - if (termios->c_cflag & PARENB) { 2432 + if (c_cflag & PARENB) { 2489 2433 cval |= UART_LCR_PARITY; 2490 2434 if (up->bugs & UART_BUG_PARITY) 2491 2435 up->fifo_bug = true; 2492 2436 } 2493 - if (!(termios->c_cflag & PARODD)) 2437 + if (!(c_cflag & PARODD)) 2494 2438 cval |= UART_LCR_EPAR; 2495 2439 #ifdef CMSPAR 2496 - if (termios->c_cflag & CMSPAR) 2440 + if (c_cflag & CMSPAR) 2497 2441 cval |= UART_LCR_SPAR; 2498 2442 #endif 2443 + 2444 + return cval; 2445 + } 2446 + 2447 + static void serial8250_set_divisor(struct uart_port *port, unsigned int baud, 2448 + unsigned int quot, unsigned int quot_frac) 2449 + { 2450 + struct uart_8250_port *up = up_to_u8250p(port); 2451 + 2452 + /* Workaround to enable 115200 baud on OMAP1510 internal ports */ 2453 + if (is_omap1510_8250(up)) { 2454 + if (baud == 115200) { 2455 + quot = 1; 2456 + serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1); 2457 + } else 2458 + serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0); 2459 + } 2460 + 2461 + /* 2462 + * For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2, 2463 + * otherwise just set DLAB 2464 + */ 2465 + if (up->capabilities & UART_NATSEMI) 2466 + serial_port_out(port, UART_LCR, 0xe0); 2467 + else 2468 + serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB); 2469 + 2470 + serial_dl_write(up, quot); 2471 + 2472 + /* XR17V35x UARTs have an extra fractional divisor register (DLD) */ 2473 + if (up->port.type == PORT_XR17V35X) 2474 + serial_port_out(port, 0x2, quot_frac); 2475 + } 2476 + 2477 + void 2478 + serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, 2479 + struct ktermios *old) 2480 + { 2481 + struct uart_8250_port *up = up_to_u8250p(port); 2482 + unsigned char cval; 2483 + unsigned long flags; 2484 + unsigned int baud, quot, frac = 0; 2485 + 2486 + cval = serial8250_compute_lcr(up, termios->c_cflag); 2499 2487 2500 2488 /* 2501 2489 * Ask the core to calculate the divisor for us. ··· 2547 2447 baud = uart_get_baud_rate(port, termios, old, 2548 2448 port->uartclk / 16 / 0xffff, 2549 2449 port->uartclk / 16); 2550 - quot = serial8250_get_divisor(port, baud); 2450 + quot = serial8250_get_divisor(up, baud, &frac); 2551 2451 2552 2452 /* 2553 - * Oxford Semi 952 rev B workaround 2453 + * Ok, we're now changing the port state. Do it with 2454 + * interrupts disabled. 2554 2455 */ 2555 - if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0) 2556 - quot++; 2456 + serial8250_rpm_get(up); 2457 + spin_lock_irqsave(&port->lock, flags); 2458 + 2459 + up->lcr = cval; /* Save computed LCR */ 2557 2460 2558 2461 if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) { 2559 2462 /* NOTE: If fifo_bug is not set, a user can set RX_trigger. */ ··· 2579 2476 if (termios->c_cflag & CRTSCTS) 2580 2477 up->mcr |= UART_MCR_AFE; 2581 2478 } 2582 - 2583 - /* 2584 - * Ok, we're now changing the port state. Do it with 2585 - * interrupts disabled. 2586 - */ 2587 - serial8250_rpm_get(up); 2588 - spin_lock_irqsave(&port->lock, flags); 2589 2479 2590 2480 /* 2591 2481 * Update the per-port timeout. ··· 2644 2548 serial_port_out(port, UART_EFR, efr); 2645 2549 } 2646 2550 2647 - /* Workaround to enable 115200 baud on OMAP1510 internal ports */ 2648 - if (is_omap1510_8250(up)) { 2649 - if (baud == 115200) { 2650 - quot = 1; 2651 - serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1); 2652 - } else 2653 - serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0); 2654 - } 2655 - 2656 - /* 2657 - * For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2, 2658 - * otherwise just set DLAB 2659 - */ 2660 - if (up->capabilities & UART_NATSEMI) 2661 - serial_port_out(port, UART_LCR, 0xe0); 2662 - else 2663 - serial_port_out(port, UART_LCR, cval | UART_LCR_DLAB); 2664 - 2665 - serial_dl_write(up, quot); 2666 - 2667 - /* 2668 - * XR17V35x UARTs have an extra fractional divisor register (DLD) 2669 - * 2670 - * We need to recalculate all of the registers, because DLM and DLL 2671 - * are already rounded to a whole integer. 2672 - * 2673 - * When recalculating we use a 32x clock instead of a 16x clock to 2674 - * allow 1-bit for rounding in the fractional part. 2675 - */ 2676 - if (up->port.type == PORT_XR17V35X) { 2677 - unsigned int baud_x32 = (port->uartclk * 2) / baud; 2678 - u16 quot = baud_x32 / 32; 2679 - u8 quot_frac = DIV_ROUND_CLOSEST(baud_x32 % 32, 2); 2680 - 2681 - serial_dl_write(up, quot); 2682 - serial_port_out(port, 0x2, quot_frac & 0xf); 2683 - } 2551 + serial8250_set_divisor(port, baud, quot, frac); 2684 2552 2685 2553 /* 2686 2554 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR ··· 2653 2593 if (port->type == PORT_16750) 2654 2594 serial_port_out(port, UART_FCR, up->fcr); 2655 2595 2656 - serial_port_out(port, UART_LCR, cval); /* reset DLAB */ 2657 - up->lcr = cval; /* Save LCR */ 2596 + serial_port_out(port, UART_LCR, up->lcr); /* reset DLAB */ 2658 2597 if (port->type != PORT_16750) { 2659 2598 /* emulated UARTs (Lucent Venus 167x) need two steps */ 2660 2599 if (up->fcr & UART_FCR_ENABLE_FIFO) ··· 3267 3208 else 3268 3209 serial_port_out(port, UART_IER, 0); 3269 3210 3211 + /* check scratch reg to see if port powered off during system sleep */ 3212 + if (up->canary && (up->canary != serial_port_in(port, UART_SCR))) { 3213 + struct ktermios termios; 3214 + unsigned int baud, quot, frac = 0; 3215 + 3216 + termios.c_cflag = port->cons->cflag; 3217 + if (port->state->port.tty && termios.c_cflag == 0) 3218 + termios.c_cflag = port->state->port.tty->termios.c_cflag; 3219 + 3220 + baud = uart_get_baud_rate(port, &termios, NULL, 3221 + port->uartclk / 16 / 0xffff, 3222 + port->uartclk / 16); 3223 + quot = serial8250_get_divisor(up, baud, &frac); 3224 + 3225 + serial8250_set_divisor(port, baud, quot, frac); 3226 + serial_port_out(port, UART_LCR, up->lcr); 3227 + serial_port_out(port, UART_MCR, UART_MCR_DTR | UART_MCR_RTS); 3228 + 3229 + up->canary = 0; 3230 + } 3231 + 3270 3232 uart_console_write(port, s, count, serial8250_console_putchar); 3271 3233 3272 3234 /* ··· 3438 3358 */ 3439 3359 void serial8250_suspend_port(int line) 3440 3360 { 3441 - uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port); 3361 + struct uart_8250_port *up = &serial8250_ports[line]; 3362 + struct uart_port *port = &up->port; 3363 + 3364 + if (!console_suspend_enabled && uart_console(port) && 3365 + port->type != PORT_8250) { 3366 + unsigned char canary = 0xa5; 3367 + serial_out(up, UART_SCR, canary); 3368 + up->canary = canary; 3369 + } 3370 + 3371 + uart_suspend_port(&serial8250_reg, port); 3442 3372 } 3443 3373 3444 3374 /** ··· 3461 3371 { 3462 3372 struct uart_8250_port *up = &serial8250_ports[line]; 3463 3373 struct uart_port *port = &up->port; 3374 + 3375 + up->canary = 0; 3464 3376 3465 3377 if (up->capabilities & UART_NATSEMI) { 3466 3378 /* Ensure it's still in high speed mode */ ··· 3697 3605 /* Possibly override set_termios call */ 3698 3606 if (up->port.set_termios) 3699 3607 uart->port.set_termios = up->port.set_termios; 3608 + if (up->port.set_mctrl) 3609 + uart->port.set_mctrl = up->port.set_mctrl; 3700 3610 if (up->port.startup) 3701 3611 uart->port.startup = up->port.startup; 3702 3612 if (up->port.shutdown)
+5 -1
drivers/tty/serial/8250/8250_dma.c
··· 59 59 60 60 dma->rx_running = 0; 61 61 dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); 62 - dmaengine_terminate_all(dma->rxchan); 63 62 64 63 count = dma->rx_size - state.residue; 65 64 ··· 80 81 return 0; 81 82 82 83 dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); 84 + if (dma->tx_size < p->port.fifosize) { 85 + ret = -EINVAL; 86 + goto err; 87 + } 83 88 84 89 desc = dmaengine_prep_slave_single(dma->txchan, 85 90 dma->tx_addr + xmit->tail, ··· 134 131 if (dma->rx_running) { 135 132 dmaengine_pause(dma->rxchan); 136 133 __dma_rx_complete(p); 134 + dmaengine_terminate_all(dma->rxchan); 137 135 } 138 136 return -ETIMEDOUT; 139 137 default:
+11
drivers/tty/serial/8250/8250_dw.c
··· 351 351 static int dw8250_probe_acpi(struct uart_8250_port *up, 352 352 struct dw8250_data *data) 353 353 { 354 + const struct acpi_device_id *id; 354 355 struct uart_port *p = &up->port; 355 356 356 357 dw8250_setup_port(up); 358 + 359 + id = acpi_match_device(p->dev->driver->acpi_match_table, p->dev); 360 + if (!id) 361 + return -ENODEV; 362 + 363 + if (!p->uartclk) 364 + if (device_property_read_u32(p->dev, "clock-frequency", 365 + &p->uartclk)) 366 + return -EINVAL; 357 367 358 368 p->iotype = UPIO_MEM32; 359 369 p->serial_in = dw8250_serial_in32; ··· 587 577 { "INT3435", 0 }, 588 578 { "80860F0A", 0 }, 589 579 { "8086228A", 0 }, 580 + { "APMC0D08", 0}, 590 581 { }, 591 582 }; 592 583 MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match);
+9 -4
drivers/tty/serial/8250/8250_early.c
··· 93 93 struct uart_port *port = &early_device->port; 94 94 unsigned int ier; 95 95 96 - /* Save the IER and disable interrupts */ 96 + /* Save the IER and disable interrupts preserving the UUE bit */ 97 97 ier = serial8250_early_in(port, UART_IER); 98 - serial8250_early_out(port, UART_IER, 0); 98 + if (ier) 99 + serial8250_early_out(port, UART_IER, ier & UART_IER_UUE); 99 100 100 101 uart_console_write(port, s, count, serial_putc); 101 102 102 103 /* Wait for transmitter to become empty and restore the IER */ 103 104 wait_for_xmitr(port); 104 - serial8250_early_out(port, UART_IER, ier); 105 + 106 + if (ier) 107 + serial8250_early_out(port, UART_IER, ier); 105 108 } 106 109 107 110 static unsigned int __init probe_baud(struct uart_port *port) ··· 127 124 struct uart_port *port = &device->port; 128 125 unsigned int divisor; 129 126 unsigned char c; 127 + unsigned int ier; 130 128 131 129 serial8250_early_out(port, UART_LCR, 0x3); /* 8n1 */ 132 - serial8250_early_out(port, UART_IER, 0); /* no interrupt */ 130 + ier = serial8250_early_in(port, UART_IER); 131 + serial8250_early_out(port, UART_IER, ier & UART_IER_UUE); /* no interrupt */ 133 132 serial8250_early_out(port, UART_FCR, 0); /* no fifo */ 134 133 serial8250_early_out(port, UART_MCR, 0x3); /* DTR + RTS */ 135 134
+76 -12
drivers/tty/serial/8250/8250_omap.c
··· 106 106 return readl(up->port.membase + (reg << up->port.regshift)); 107 107 } 108 108 109 + static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl) 110 + { 111 + struct uart_8250_port *up = up_to_u8250p(port); 112 + struct omap8250_priv *priv = up->port.private_data; 113 + u8 lcr; 114 + 115 + serial8250_do_set_mctrl(port, mctrl); 116 + 117 + /* 118 + * Turn off autoRTS if RTS is lowered and restore autoRTS setting 119 + * if RTS is raised 120 + */ 121 + lcr = serial_in(up, UART_LCR); 122 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 123 + if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS)) 124 + priv->efr |= UART_EFR_RTS; 125 + else 126 + priv->efr &= ~UART_EFR_RTS; 127 + serial_out(up, UART_EFR, priv->efr); 128 + serial_out(up, UART_LCR, lcr); 129 + } 130 + 109 131 /* 110 132 * Work Around for Errata i202 (2430, 3430, 3630, 4430 and 4460) 111 133 * The access to uart register after MDR1 Access ··· 419 397 420 398 priv->efr = 0; 421 399 up->mcr &= ~(UART_MCR_RTS | UART_MCR_XONANY); 422 - if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) { 423 - /* Enable AUTORTS and AUTOCTS */ 424 - priv->efr |= UART_EFR_CTS | UART_EFR_RTS; 400 + up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF); 425 401 426 - /* Ensure MCR RTS is asserted */ 427 - up->mcr |= UART_MCR_RTS; 402 + if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) { 403 + /* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ 404 + up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; 405 + priv->efr |= UART_EFR_CTS; 428 406 } else if (up->port.flags & UPF_SOFT_FLOW) { 429 407 /* 430 408 * IXON Flag: ··· 439 417 * Enable XON/XOFF flow control on output. 440 418 * Transmit XON1, XOFF1 441 419 */ 442 - if (termios->c_iflag & IXOFF) 420 + if (termios->c_iflag & IXOFF) { 421 + up->port.status |= UPSTAT_AUTOXOFF; 443 422 priv->efr |= OMAP_UART_SW_TX; 423 + } 444 424 445 425 /* 446 426 * IXANY Flag: ··· 474 450 static void omap_8250_pm(struct uart_port *port, unsigned int state, 475 451 unsigned int oldstate) 476 452 { 477 - struct uart_8250_port *up = 478 - container_of(port, struct uart_8250_port, port); 479 - struct omap8250_priv *priv = up->port.private_data; 453 + struct uart_8250_port *up = up_to_u8250p(port); 454 + u8 efr; 480 455 481 456 pm_runtime_get_sync(port->dev); 482 457 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 483 - serial_out(up, UART_EFR, priv->efr | UART_EFR_ECB); 458 + efr = serial_in(up, UART_EFR); 459 + serial_out(up, UART_EFR, efr | UART_EFR_ECB); 484 460 serial_out(up, UART_LCR, 0); 485 461 486 462 serial_out(up, UART_IER, (state != 0) ? UART_IERX_SLEEP : 0); 487 463 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 488 - serial_out(up, UART_EFR, priv->efr); 464 + serial_out(up, UART_EFR, efr); 489 465 serial_out(up, UART_LCR, 0); 490 466 491 467 pm_runtime_mark_last_busy(port->dev); ··· 1031 1007 up.capabilities |= UART_CAP_RPM; 1032 1008 #endif 1033 1009 up.port.set_termios = omap_8250_set_termios; 1010 + up.port.set_mctrl = omap8250_set_mctrl; 1034 1011 up.port.pm = omap_8250_pm; 1035 1012 up.port.startup = omap_8250_startup; 1036 1013 up.port.shutdown = omap_8250_shutdown; ··· 1273 1248 } 1274 1249 #endif 1275 1250 1251 + #ifdef CONFIG_SERIAL_8250_OMAP_TTYO_FIXUP 1252 + static int __init omap8250_console_fixup(void) 1253 + { 1254 + char *omap_str; 1255 + char *options; 1256 + u8 idx; 1257 + 1258 + if (strstr(boot_command_line, "console=ttyS")) 1259 + /* user set a ttyS based name for the console */ 1260 + return 0; 1261 + 1262 + omap_str = strstr(boot_command_line, "console=ttyO"); 1263 + if (!omap_str) 1264 + /* user did not set ttyO based console, so we don't care */ 1265 + return 0; 1266 + 1267 + omap_str += 12; 1268 + if ('0' <= *omap_str && *omap_str <= '9') 1269 + idx = *omap_str - '0'; 1270 + else 1271 + return 0; 1272 + 1273 + omap_str++; 1274 + if (omap_str[0] == ',') { 1275 + omap_str++; 1276 + options = omap_str; 1277 + } else { 1278 + options = NULL; 1279 + } 1280 + 1281 + add_preferred_console("ttyS", idx, options); 1282 + pr_err("WARNING: Your 'console=ttyO%d' has been replaced by 'ttyS%d'\n", 1283 + idx, idx); 1284 + pr_err("This ensures that you still see kernel messages. Please\n"); 1285 + pr_err("update your kernel commandline.\n"); 1286 + return 0; 1287 + } 1288 + console_initcall(omap8250_console_fixup); 1289 + #endif 1290 + 1276 1291 static const struct dev_pm_ops omap8250_dev_pm_ops = { 1277 1292 SET_SYSTEM_SLEEP_PM_OPS(omap8250_suspend, omap8250_resume) 1278 1293 SET_RUNTIME_PM_OPS(omap8250_runtime_suspend, ··· 1334 1269 .name = "omap8250", 1335 1270 .pm = &omap8250_dev_pm_ops, 1336 1271 .of_match_table = omap8250_dt_ids, 1337 - .owner = THIS_MODULE, 1338 1272 }, 1339 1273 .probe = omap8250_probe, 1340 1274 .remove = omap8250_remove,
+2 -2
drivers/tty/serial/8250/8250_pci.c
··· 221 221 */ 222 222 static int pci_inteli960ni_init(struct pci_dev *dev) 223 223 { 224 - unsigned long oldval; 224 + u32 oldval; 225 225 226 226 if (!(dev->subsystem_device & 0x1000)) 227 227 return -ENODEV; 228 228 229 229 /* is firmware started? */ 230 - pci_read_config_dword(dev, 0x44, (void *)&oldval); 230 + pci_read_config_dword(dev, 0x44, &oldval); 231 231 if (oldval == 0x00001000L) { /* RESET value */ 232 232 dev_dbg(&dev->dev, "Local i960 firmware missing\n"); 233 233 return -ENODEV;
+7 -1
drivers/tty/serial/8250/8250_pnp.c
··· 426 426 static int 427 427 serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) 428 428 { 429 - struct uart_8250_port uart; 429 + struct uart_8250_port uart, *port; 430 430 int ret, line, flags = dev_id->driver_data; 431 431 432 432 if (flags & UNKNOWN_DEV) { ··· 471 471 if (line < 0 || (flags & CIR_PORT)) 472 472 return -ENODEV; 473 473 474 + port = serial8250_get_port(line); 475 + if (uart_console(&port->port)) 476 + dev->capabilities |= PNP_CONSOLE; 477 + 474 478 pnp_set_drvdata(dev, (void *)((long)line + 1)); 475 479 return 0; 476 480 } ··· 482 478 static void serial_pnp_remove(struct pnp_dev *dev) 483 479 { 484 480 long line = (long)pnp_get_drvdata(dev); 481 + 482 + dev->capabilities &= ~PNP_CONSOLE; 485 483 if (line) 486 484 serial8250_unregister_port(line - 1); 487 485 }
+19
drivers/tty/serial/8250/Kconfig
··· 308 308 309 309 This driver uses ttyS instead of ttyO. 310 310 311 + config SERIAL_8250_OMAP_TTYO_FIXUP 312 + bool "Replace ttyO with ttyS" 313 + depends on SERIAL_8250_OMAP=y && SERIAL_8250_CONSOLE 314 + default y 315 + help 316 + This option replaces the "console=ttyO" argument with the matching 317 + ttyS argument if the user did not specified it on the command line. 318 + This ensures that the user can see the kernel output during boot 319 + which he wouldn't see otherwise. The getty has still to be configured 320 + for ttyS instead of ttyO regardless of this option. 321 + This option is intended for people who "automatically" enable this 322 + driver without knowing that this driver requires a different console= 323 + argument. If you read this, please keep this option disabled and 324 + instead update your kernel command line. If you prepare a kernel for a 325 + distribution or other kind of larger user base then you probably want 326 + to keep this option enabled. Otherwise people might complain about a 327 + not booting kernel because the serial console remains silent in case 328 + they forgot to update the command line. 329 + 311 330 config SERIAL_8250_FINTEK 312 331 tristate "Support for Fintek F81216A LPC to 4 UART" 313 332 depends on SERIAL_8250 && PNP
+44 -10
drivers/tty/serial/Kconfig
··· 241 241 tristate "Samsung SoC serial support" 242 242 depends on PLAT_SAMSUNG || ARCH_EXYNOS 243 243 select SERIAL_CORE 244 + select SERIAL_EARLYCON 244 245 help 245 246 Support for the on-chip UARTs on the Samsung S3C24XX series CPUs, 246 247 providing /dev/ttySAC0, 1 and 2 (note, some machines may not ··· 482 481 "console=ttySA0". (Try "man bootparam" or see the documentation of 483 482 your boot loader (lilo or loadlin) about how to pass options to the 484 483 kernel at boot time.) 485 - 486 - config SERIAL_MRST_MAX3110 487 - tristate "SPI UART driver for Max3110" 488 - depends on SPI_DW_PCI 489 - select SERIAL_CORE 490 - select SERIAL_CORE_CONSOLE 491 - help 492 - This is the UART protocol driver for the MAX3110 device on 493 - the Intel Moorestown platform. On other systems use the max3100 494 - driver. 495 484 496 485 config SERIAL_MFD_HSU 497 486 tristate "Medfield High Speed UART support" ··· 1085 1094 depends on SERIAL_VT8500=y 1086 1095 select SERIAL_CORE_CONSOLE 1087 1096 1097 + config SERIAL_ETRAXFS 1098 + bool "ETRAX FS serial port support" 1099 + depends on ETRAX_ARCH_V32 && OF 1100 + select SERIAL_CORE 1101 + 1102 + config SERIAL_ETRAXFS_CONSOLE 1103 + bool "ETRAX FS serial console support" 1104 + depends on SERIAL_ETRAXFS 1105 + select SERIAL_CORE_CONSOLE 1106 + 1088 1107 config SERIAL_NETX 1089 1108 tristate "NetX serial port support" 1090 1109 depends on ARCH_NETX ··· 1550 1549 If you have enabled the lpuart serial port on the Freescale SoCs, 1551 1550 you can make it the console by answering Y to this option. 1552 1551 1552 + config SERIAL_CONEXANT_DIGICOLOR 1553 + tristate "Conexant Digicolor CX92xxx USART serial port support" 1554 + depends on OF 1555 + select SERIAL_CORE 1556 + help 1557 + Support for the on-chip USART on Conexant Digicolor SoCs. 1558 + 1559 + config SERIAL_CONEXANT_DIGICOLOR_CONSOLE 1560 + bool "Console on Conexant Digicolor serial port" 1561 + depends on SERIAL_CONEXANT_DIGICOLOR=y 1562 + select SERIAL_CORE_CONSOLE 1563 + help 1564 + If you have enabled the USART serial port on Conexant Digicolor 1565 + SoCs, you can make it the console by answering Y to this option. 1566 + 1553 1567 config SERIAL_ST_ASC 1554 1568 tristate "ST ASC serial port support" 1555 1569 select SERIAL_CORE ··· 1592 1576 1593 1577 This driver can also be build as a module. If so, the module will be called 1594 1578 men_z135_uart.ko 1579 + 1580 + config SERIAL_SPRD 1581 + tristate "Support for Spreadtrum serial" 1582 + depends on ARCH_SPRD 1583 + select SERIAL_CORE 1584 + help 1585 + This enables the driver for the Spreadtrum's serial. 1586 + 1587 + config SERIAL_SPRD_CONSOLE 1588 + bool "Spreadtrum UART console support" 1589 + depends on SERIAL_SPRD=y 1590 + select SERIAL_CORE_CONSOLE 1591 + select SERIAL_EARLYCON 1592 + help 1593 + Support for early debug console using Spreadtrum's serial. This enables 1594 + the console before standard serial driver is probed. This is enabled 1595 + with "earlycon" on the kernel command line. The console is 1596 + enabled when early_param is processed. 1595 1597 1596 1598 endmenu 1597 1599
+3 -1
drivers/tty/serial/Makefile
··· 51 51 obj-$(CONFIG_SERIAL_MESON) += meson_uart.o 52 52 obj-$(CONFIG_SERIAL_SB1250_DUART) += sb1250-duart.o 53 53 obj-$(CONFIG_ETRAX_SERIAL) += crisv10.o 54 + obj-$(CONFIG_SERIAL_ETRAXFS) += etraxfs-uart.o 54 55 obj-$(CONFIG_SERIAL_SCCNXP) += sccnxp.o 55 56 obj-$(CONFIG_SERIAL_SC16IS7XX) += sc16is7xx.o 56 57 obj-$(CONFIG_SERIAL_JSM) += jsm/ ··· 78 77 obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o 79 78 obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o 80 79 obj-$(CONFIG_SERIAL_VT8500) += vt8500_serial.o 81 - obj-$(CONFIG_SERIAL_MRST_MAX3110) += mrst_max3110.o 82 80 obj-$(CONFIG_SERIAL_MFD_HSU) += mfd.o 83 81 obj-$(CONFIG_SERIAL_IFX6X60) += ifx6x60.o 84 82 obj-$(CONFIG_SERIAL_PCH_UART) += pch_uart.o ··· 92 92 obj-$(CONFIG_SERIAL_ARC) += arc_uart.o 93 93 obj-$(CONFIG_SERIAL_RP2) += rp2.o 94 94 obj-$(CONFIG_SERIAL_FSL_LPUART) += fsl_lpuart.o 95 + obj-$(CONFIG_SERIAL_CONEXANT_DIGICOLOR) += digicolor-usart.o 95 96 obj-$(CONFIG_SERIAL_MEN_Z135) += men_z135_uart.o 97 + obj-$(CONFIG_SERIAL_SPRD) += sprd_serial.o 96 98 97 99 # GPIOLIB helpers for modem control lines 98 100 obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
+1
drivers/tty/serial/altera_jtaguart.c
··· 441 441 port->iotype = SERIAL_IO_MEM; 442 442 port->ops = &altera_jtaguart_ops; 443 443 port->flags = UPF_BOOT_AUTOCONF; 444 + port->dev = &pdev->dev; 444 445 445 446 uart_add_one_port(&altera_jtaguart_driver, port); 446 447
+1
drivers/tty/serial/altera_uart.c
··· 589 589 port->iotype = SERIAL_IO_MEM; 590 590 port->ops = &altera_uart_ops; 591 591 port->flags = UPF_BOOT_AUTOCONF; 592 + port->dev = &pdev->dev; 592 593 593 594 platform_set_drvdata(pdev, port); 594 595
+101 -52
drivers/tty/serial/atmel_serial.c
··· 341 341 static void atmel_set_mctrl(struct uart_port *port, u_int mctrl) 342 342 { 343 343 unsigned int control = 0; 344 - unsigned int mode; 344 + unsigned int mode = UART_GET_MR(port); 345 + unsigned int rts_paused, rts_ready; 345 346 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 346 347 348 + /* override mode to RS485 if needed, otherwise keep the current mode */ 349 + if (port->rs485.flags & SER_RS485_ENABLED) { 350 + if ((port->rs485.delay_rts_after_send) > 0) 351 + UART_PUT_TTGR(port, port->rs485.delay_rts_after_send); 352 + mode &= ~ATMEL_US_USMODE; 353 + mode |= ATMEL_US_USMODE_RS485; 354 + } 355 + 356 + /* set the RTS line state according to the mode */ 357 + if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) { 358 + /* force RTS line to high level */ 359 + rts_paused = ATMEL_US_RTSEN; 360 + 361 + /* give the control of the RTS line back to the hardware */ 362 + rts_ready = ATMEL_US_RTSDIS; 363 + } else { 364 + /* force RTS line to high level */ 365 + rts_paused = ATMEL_US_RTSDIS; 366 + 367 + /* force RTS line to low level */ 368 + rts_ready = ATMEL_US_RTSEN; 369 + } 370 + 347 371 if (mctrl & TIOCM_RTS) 348 - control |= ATMEL_US_RTSEN; 372 + control |= rts_ready; 349 373 else 350 - control |= ATMEL_US_RTSDIS; 374 + control |= rts_paused; 351 375 352 376 if (mctrl & TIOCM_DTR) 353 377 control |= ATMEL_US_DTREN; ··· 383 359 mctrl_gpio_set(atmel_port->gpios, mctrl); 384 360 385 361 /* Local loopback mode? */ 386 - mode = UART_GET_MR(port) & ~ATMEL_US_CHMODE; 362 + mode &= ~ATMEL_US_CHMODE; 387 363 if (mctrl & TIOCM_LOOP) 388 364 mode |= ATMEL_US_CHMODE_LOC_LOOP; 389 365 else 390 366 mode |= ATMEL_US_CHMODE_NORMAL; 391 367 392 - /* Resetting serial mode to RS232 (0x0) */ 393 - mode &= ~ATMEL_US_USMODE; 394 - 395 - if (port->rs485.flags & SER_RS485_ENABLED) { 396 - dev_dbg(port->dev, "Setting UART to RS485\n"); 397 - if ((port->rs485.delay_rts_after_send) > 0) 398 - UART_PUT_TTGR(port, port->rs485.delay_rts_after_send); 399 - mode |= ATMEL_US_USMODE_RS485; 400 - } else { 401 - dev_dbg(port->dev, "Setting UART to RS232\n"); 402 - } 403 368 UART_PUT_MR(port, mode); 404 369 } 405 370 ··· 738 725 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 739 726 uart_write_wakeup(port); 740 727 741 - /* Do we really need this? */ 728 + /* 729 + * xmit is a circular buffer so, if we have just send data from 730 + * xmit->tail to the end of xmit->buf, now we have to transmit the 731 + * remaining data from the beginning of xmit->buf to xmit->head. 732 + */ 742 733 if (!uart_circ_empty(xmit)) 743 734 tasklet_schedule(&atmel_port->tasklet); 744 735 ··· 801 784 BUG_ON(!sg_dma_len(sg)); 802 785 803 786 desc = dmaengine_prep_slave_sg(chan, 804 - sg, 805 - 1, 806 - DMA_MEM_TO_DEV, 807 - DMA_PREP_INTERRUPT | 808 - DMA_CTRL_ACK); 787 + sg, 788 + 1, 789 + DMA_MEM_TO_DEV, 790 + DMA_PREP_INTERRUPT | 791 + DMA_CTRL_ACK); 809 792 if (!desc) { 810 793 dev_err(port->dev, "Failed to send via dma!\n"); 811 794 return; 812 795 } 813 796 814 - dma_sync_sg_for_device(port->dev, sg, 1, DMA_MEM_TO_DEV); 797 + dma_sync_sg_for_device(port->dev, sg, 1, DMA_TO_DEVICE); 815 798 816 799 atmel_port->desc_tx = desc; 817 800 desc->callback = atmel_complete_tx_dma; ··· 944 927 dma_sync_sg_for_cpu(port->dev, 945 928 &atmel_port->sg_rx, 946 929 1, 947 - DMA_DEV_TO_MEM); 930 + DMA_FROM_DEVICE); 948 931 949 932 /* 950 933 * ring->head points to the end of data already written by the DMA. ··· 991 974 dma_sync_sg_for_device(port->dev, 992 975 &atmel_port->sg_rx, 993 976 1, 994 - DMA_DEV_TO_MEM); 977 + DMA_FROM_DEVICE); 995 978 996 979 /* 997 980 * Drop the lock here since it might end up calling ··· 1029 1012 /* UART circular rx buffer is an aligned page. */ 1030 1013 BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK); 1031 1014 sg_set_page(&atmel_port->sg_rx, 1032 - virt_to_page(ring->buf), 1033 - ATMEL_SERIAL_RINGSIZE, 1034 - (int)ring->buf & ~PAGE_MASK); 1035 - nent = dma_map_sg(port->dev, 1036 - &atmel_port->sg_rx, 1037 - 1, 1038 - DMA_FROM_DEVICE); 1015 + virt_to_page(ring->buf), 1016 + ATMEL_SERIAL_RINGSIZE, 1017 + (int)ring->buf & ~PAGE_MASK); 1018 + nent = dma_map_sg(port->dev, 1019 + &atmel_port->sg_rx, 1020 + 1, 1021 + DMA_FROM_DEVICE); 1039 1022 1040 1023 if (!nent) { 1041 1024 dev_dbg(port->dev, "need to release resource of dma\n"); ··· 1064 1047 * each one is half ring buffer size 1065 1048 */ 1066 1049 desc = dmaengine_prep_dma_cyclic(atmel_port->chan_rx, 1067 - sg_dma_address(&atmel_port->sg_rx), 1068 - sg_dma_len(&atmel_port->sg_rx), 1069 - sg_dma_len(&atmel_port->sg_rx)/2, 1070 - DMA_DEV_TO_MEM, 1071 - DMA_PREP_INTERRUPT); 1050 + sg_dma_address(&atmel_port->sg_rx), 1051 + sg_dma_len(&atmel_port->sg_rx), 1052 + sg_dma_len(&atmel_port->sg_rx)/2, 1053 + DMA_DEV_TO_MEM, 1054 + DMA_PREP_INTERRUPT); 1072 1055 desc->callback = atmel_complete_rx_dma; 1073 1056 desc->callback_param = port; 1074 1057 atmel_port->desc_rx = desc; ··· 1938 1921 struct ktermios *old) 1939 1922 { 1940 1923 unsigned long flags; 1941 - unsigned int mode, imr, quot, baud; 1924 + unsigned int old_mode, mode, imr, quot, baud; 1942 1925 1943 - /* Get current mode register */ 1944 - mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL 1945 - | ATMEL_US_NBSTOP | ATMEL_US_PAR 1946 - | ATMEL_US_USMODE); 1926 + /* save the current mode register */ 1927 + mode = old_mode = UART_GET_MR(port); 1928 + 1929 + /* reset the mode, clock divisor, parity, stop bits and data size */ 1930 + mode &= ~(ATMEL_US_USCLKS | ATMEL_US_CHRL | ATMEL_US_NBSTOP | 1931 + ATMEL_US_PAR | ATMEL_US_USMODE); 1947 1932 1948 1933 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); 1949 1934 quot = uart_get_divisor(port, baud); ··· 1990 1971 } else 1991 1972 mode |= ATMEL_US_PAR_NONE; 1992 1973 1993 - /* hardware handshake (RTS/CTS) */ 1994 - if (termios->c_cflag & CRTSCTS) 1995 - mode |= ATMEL_US_USMODE_HWHS; 1996 - else 1997 - mode |= ATMEL_US_USMODE_NORMAL; 1998 - 1999 1974 spin_lock_irqsave(&port->lock, flags); 2000 1975 2001 1976 port->read_status_mask = ATMEL_US_OVRE; ··· 2033 2020 /* disable receiver and transmitter */ 2034 2021 UART_PUT_CR(port, ATMEL_US_TXDIS | ATMEL_US_RXDIS); 2035 2022 2036 - /* Resetting serial mode to RS232 (0x0) */ 2037 - mode &= ~ATMEL_US_USMODE; 2038 - 2023 + /* mode */ 2039 2024 if (port->rs485.flags & SER_RS485_ENABLED) { 2040 2025 if ((port->rs485.delay_rts_after_send) > 0) 2041 2026 UART_PUT_TTGR(port, port->rs485.delay_rts_after_send); 2042 2027 mode |= ATMEL_US_USMODE_RS485; 2028 + } else if (termios->c_cflag & CRTSCTS) { 2029 + /* RS232 with hardware handshake (RTS/CTS) */ 2030 + mode |= ATMEL_US_USMODE_HWHS; 2031 + } else { 2032 + /* RS232 without hadware handshake */ 2033 + mode |= ATMEL_US_USMODE_NORMAL; 2043 2034 } 2044 2035 2045 - /* set the parity, stop bits and data size */ 2036 + /* set the mode, clock divisor, parity, stop bits and data size */ 2046 2037 UART_PUT_MR(port, mode); 2038 + 2039 + /* 2040 + * when switching the mode, set the RTS line state according to the 2041 + * new mode, otherwise keep the former state 2042 + */ 2043 + if ((old_mode & ATMEL_US_USMODE) != (mode & ATMEL_US_USMODE)) { 2044 + unsigned int rts_state; 2045 + 2046 + if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) { 2047 + /* let the hardware control the RTS line */ 2048 + rts_state = ATMEL_US_RTSDIS; 2049 + } else { 2050 + /* force RTS line to low level */ 2051 + rts_state = ATMEL_US_RTSEN; 2052 + } 2053 + 2054 + UART_PUT_CR(port, rts_state); 2055 + } 2047 2056 2048 2057 /* set the baud rate */ 2049 2058 UART_PUT_BRGR(port, quot); ··· 2600 2565 2601 2566 ret = atmel_init_port(port, pdev); 2602 2567 if (ret) 2603 - goto err; 2568 + goto err_clear_bit; 2604 2569 2605 2570 if (!atmel_use_pdc_rx(&port->uart)) { 2606 2571 ret = -ENOMEM; ··· 2631 2596 device_init_wakeup(&pdev->dev, 1); 2632 2597 platform_set_drvdata(pdev, port); 2633 2598 2599 + /* 2600 + * The peripheral clock has been disabled by atmel_init_port(): 2601 + * enable it before accessing I/O registers 2602 + */ 2603 + clk_prepare_enable(port->clk); 2604 + 2634 2605 if (rs485_enabled) { 2635 2606 UART_PUT_MR(&port->uart, ATMEL_US_USMODE_NORMAL); 2636 2607 UART_PUT_CR(&port->uart, ATMEL_US_RTSEN); ··· 2646 2605 * Get port name of usart or uart 2647 2606 */ 2648 2607 atmel_get_ip_name(&port->uart); 2608 + 2609 + /* 2610 + * The peripheral clock can now safely be disabled till the port 2611 + * is used 2612 + */ 2613 + clk_disable_unprepare(port->clk); 2649 2614 2650 2615 return 0; 2651 2616 ··· 2663 2616 clk_put(port->clk); 2664 2617 port->clk = NULL; 2665 2618 } 2619 + err_clear_bit: 2620 + clear_bit(port->uart.line, atmel_ports_in_use); 2666 2621 err: 2667 2622 return ret; 2668 2623 }
+560
drivers/tty/serial/digicolor-usart.c
··· 1 + /* 2 + * Driver for Conexant Digicolor serial ports (USART) 3 + * 4 + * Author: Baruch Siach <baruch@tkos.co.il> 5 + * 6 + * Copyright (C) 2014 Paradox Innovation Ltd. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + */ 13 + 14 + #include <linux/module.h> 15 + #include <linux/console.h> 16 + #include <linux/serial_core.h> 17 + #include <linux/serial.h> 18 + #include <linux/clk.h> 19 + #include <linux/io.h> 20 + #include <linux/tty.h> 21 + #include <linux/tty_flip.h> 22 + #include <linux/of.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/workqueue.h> 25 + 26 + #define UA_ENABLE 0x00 27 + #define UA_ENABLE_ENABLE BIT(0) 28 + 29 + #define UA_CONTROL 0x01 30 + #define UA_CONTROL_RX_ENABLE BIT(0) 31 + #define UA_CONTROL_TX_ENABLE BIT(1) 32 + #define UA_CONTROL_SOFT_RESET BIT(2) 33 + 34 + #define UA_STATUS 0x02 35 + #define UA_STATUS_PARITY_ERR BIT(0) 36 + #define UA_STATUS_FRAME_ERR BIT(1) 37 + #define UA_STATUS_OVERRUN_ERR BIT(2) 38 + #define UA_STATUS_TX_READY BIT(6) 39 + 40 + #define UA_CONFIG 0x03 41 + #define UA_CONFIG_CHAR_LEN BIT(0) 42 + #define UA_CONFIG_STOP_BITS BIT(1) 43 + #define UA_CONFIG_PARITY BIT(2) 44 + #define UA_CONFIG_ODD_PARITY BIT(4) 45 + 46 + #define UA_EMI_REC 0x04 47 + 48 + #define UA_HBAUD_LO 0x08 49 + #define UA_HBAUD_HI 0x09 50 + 51 + #define UA_STATUS_FIFO 0x0a 52 + #define UA_STATUS_FIFO_RX_EMPTY BIT(2) 53 + #define UA_STATUS_FIFO_RX_INT_ALMOST BIT(3) 54 + #define UA_STATUS_FIFO_TX_FULL BIT(4) 55 + #define UA_STATUS_FIFO_TX_INT_ALMOST BIT(7) 56 + 57 + #define UA_CONFIG_FIFO 0x0b 58 + #define UA_CONFIG_FIFO_RX_THRESH 7 59 + #define UA_CONFIG_FIFO_RX_FIFO_MODE BIT(3) 60 + #define UA_CONFIG_FIFO_TX_FIFO_MODE BIT(7) 61 + 62 + #define UA_INTFLAG_CLEAR 0x1c 63 + #define UA_INTFLAG_SET 0x1d 64 + #define UA_INT_ENABLE 0x1e 65 + #define UA_INT_STATUS 0x1f 66 + 67 + #define UA_INT_TX BIT(0) 68 + #define UA_INT_RX BIT(1) 69 + 70 + #define DIGICOLOR_USART_NR 3 71 + 72 + /* 73 + * We use the 16 bytes hardware FIFO to buffer Rx traffic. Rx interrupt is 74 + * only produced when the FIFO is filled more than a certain configurable 75 + * threshold. Unfortunately, there is no way to set this threshold below half 76 + * FIFO. This means that we must periodically poll the FIFO status register to 77 + * see whether there are waiting Rx bytes. 78 + */ 79 + 80 + struct digicolor_port { 81 + struct uart_port port; 82 + struct delayed_work rx_poll_work; 83 + }; 84 + 85 + static struct uart_port *digicolor_ports[DIGICOLOR_USART_NR]; 86 + 87 + static bool digicolor_uart_tx_full(struct uart_port *port) 88 + { 89 + return !!(readb_relaxed(port->membase + UA_STATUS_FIFO) & 90 + UA_STATUS_FIFO_TX_FULL); 91 + } 92 + 93 + static bool digicolor_uart_rx_empty(struct uart_port *port) 94 + { 95 + return !!(readb_relaxed(port->membase + UA_STATUS_FIFO) & 96 + UA_STATUS_FIFO_RX_EMPTY); 97 + } 98 + 99 + static void digicolor_uart_stop_tx(struct uart_port *port) 100 + { 101 + u8 int_enable = readb_relaxed(port->membase + UA_INT_ENABLE); 102 + 103 + int_enable &= ~UA_INT_TX; 104 + writeb_relaxed(int_enable, port->membase + UA_INT_ENABLE); 105 + } 106 + 107 + static void digicolor_uart_start_tx(struct uart_port *port) 108 + { 109 + u8 int_enable = readb_relaxed(port->membase + UA_INT_ENABLE); 110 + 111 + int_enable |= UA_INT_TX; 112 + writeb_relaxed(int_enable, port->membase + UA_INT_ENABLE); 113 + } 114 + 115 + static void digicolor_uart_stop_rx(struct uart_port *port) 116 + { 117 + u8 int_enable = readb_relaxed(port->membase + UA_INT_ENABLE); 118 + 119 + int_enable &= ~UA_INT_RX; 120 + writeb_relaxed(int_enable, port->membase + UA_INT_ENABLE); 121 + } 122 + 123 + static void digicolor_rx_poll(struct work_struct *work) 124 + { 125 + struct digicolor_port *dp = 126 + container_of(to_delayed_work(work), 127 + struct digicolor_port, rx_poll_work); 128 + 129 + if (!digicolor_uart_rx_empty(&dp->port)) 130 + /* force RX interrupt */ 131 + writeb_relaxed(UA_INT_RX, dp->port.membase + UA_INTFLAG_SET); 132 + 133 + schedule_delayed_work(&dp->rx_poll_work, msecs_to_jiffies(100)); 134 + } 135 + 136 + static void digicolor_uart_rx(struct uart_port *port) 137 + { 138 + unsigned long flags; 139 + 140 + spin_lock_irqsave(&port->lock, flags); 141 + 142 + while (1) { 143 + u8 status, ch; 144 + unsigned int ch_flag; 145 + 146 + if (digicolor_uart_rx_empty(port)) 147 + break; 148 + 149 + ch = readb_relaxed(port->membase + UA_EMI_REC); 150 + status = readb_relaxed(port->membase + UA_STATUS); 151 + 152 + port->icount.rx++; 153 + ch_flag = TTY_NORMAL; 154 + 155 + if (status) { 156 + if (status & UA_STATUS_PARITY_ERR) 157 + port->icount.parity++; 158 + else if (status & UA_STATUS_FRAME_ERR) 159 + port->icount.frame++; 160 + else if (status & UA_STATUS_OVERRUN_ERR) 161 + port->icount.overrun++; 162 + 163 + status &= port->read_status_mask; 164 + 165 + if (status & UA_STATUS_PARITY_ERR) 166 + ch_flag = TTY_PARITY; 167 + else if (status & UA_STATUS_FRAME_ERR) 168 + ch_flag = TTY_FRAME; 169 + else if (status & UA_STATUS_OVERRUN_ERR) 170 + ch_flag = TTY_OVERRUN; 171 + } 172 + 173 + if (status & port->ignore_status_mask) 174 + continue; 175 + 176 + uart_insert_char(port, status, UA_STATUS_OVERRUN_ERR, ch, 177 + ch_flag); 178 + } 179 + 180 + spin_unlock_irqrestore(&port->lock, flags); 181 + 182 + tty_flip_buffer_push(&port->state->port); 183 + } 184 + 185 + static void digicolor_uart_tx(struct uart_port *port) 186 + { 187 + struct circ_buf *xmit = &port->state->xmit; 188 + unsigned long flags; 189 + 190 + if (digicolor_uart_tx_full(port)) 191 + return; 192 + 193 + spin_lock_irqsave(&port->lock, flags); 194 + 195 + if (port->x_char) { 196 + writeb_relaxed(port->x_char, port->membase + UA_EMI_REC); 197 + port->icount.tx++; 198 + port->x_char = 0; 199 + goto out; 200 + } 201 + 202 + if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 203 + digicolor_uart_stop_tx(port); 204 + goto out; 205 + } 206 + 207 + while (!uart_circ_empty(xmit)) { 208 + writeb(xmit->buf[xmit->tail], port->membase + UA_EMI_REC); 209 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 210 + port->icount.tx++; 211 + 212 + if (digicolor_uart_tx_full(port)) 213 + break; 214 + } 215 + 216 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 217 + uart_write_wakeup(port); 218 + 219 + out: 220 + spin_unlock_irqrestore(&port->lock, flags); 221 + } 222 + 223 + static irqreturn_t digicolor_uart_int(int irq, void *dev_id) 224 + { 225 + struct uart_port *port = dev_id; 226 + u8 int_status = readb_relaxed(port->membase + UA_INT_STATUS); 227 + 228 + writeb_relaxed(UA_INT_RX | UA_INT_TX, 229 + port->membase + UA_INTFLAG_CLEAR); 230 + 231 + if (int_status & UA_INT_RX) 232 + digicolor_uart_rx(port); 233 + if (int_status & UA_INT_TX) 234 + digicolor_uart_tx(port); 235 + 236 + return IRQ_HANDLED; 237 + } 238 + 239 + static unsigned int digicolor_uart_tx_empty(struct uart_port *port) 240 + { 241 + u8 status = readb_relaxed(port->membase + UA_STATUS); 242 + 243 + return (status & UA_STATUS_TX_READY) ? TIOCSER_TEMT : 0; 244 + } 245 + 246 + static unsigned int digicolor_uart_get_mctrl(struct uart_port *port) 247 + { 248 + return TIOCM_CTS; 249 + } 250 + 251 + static void digicolor_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) 252 + { 253 + } 254 + 255 + static void digicolor_uart_break_ctl(struct uart_port *port, int state) 256 + { 257 + } 258 + 259 + static int digicolor_uart_startup(struct uart_port *port) 260 + { 261 + struct digicolor_port *dp = 262 + container_of(port, struct digicolor_port, port); 263 + 264 + writeb_relaxed(UA_ENABLE_ENABLE, port->membase + UA_ENABLE); 265 + writeb_relaxed(UA_CONTROL_SOFT_RESET, port->membase + UA_CONTROL); 266 + writeb_relaxed(0, port->membase + UA_CONTROL); 267 + 268 + writeb_relaxed(UA_CONFIG_FIFO_RX_FIFO_MODE 269 + | UA_CONFIG_FIFO_TX_FIFO_MODE | UA_CONFIG_FIFO_RX_THRESH, 270 + port->membase + UA_CONFIG_FIFO); 271 + writeb_relaxed(UA_STATUS_FIFO_RX_INT_ALMOST, 272 + port->membase + UA_STATUS_FIFO); 273 + writeb_relaxed(UA_CONTROL_RX_ENABLE | UA_CONTROL_TX_ENABLE, 274 + port->membase + UA_CONTROL); 275 + writeb_relaxed(UA_INT_TX | UA_INT_RX, 276 + port->membase + UA_INT_ENABLE); 277 + 278 + schedule_delayed_work(&dp->rx_poll_work, msecs_to_jiffies(100)); 279 + 280 + return 0; 281 + } 282 + 283 + static void digicolor_uart_shutdown(struct uart_port *port) 284 + { 285 + struct digicolor_port *dp = 286 + container_of(port, struct digicolor_port, port); 287 + 288 + writeb_relaxed(0, port->membase + UA_ENABLE); 289 + cancel_delayed_work_sync(&dp->rx_poll_work); 290 + } 291 + 292 + static void digicolor_uart_set_termios(struct uart_port *port, 293 + struct ktermios *termios, 294 + struct ktermios *old) 295 + { 296 + unsigned int baud, divisor; 297 + u8 config = 0; 298 + unsigned long flags; 299 + 300 + /* Mask termios capabilities we don't support */ 301 + termios->c_cflag &= ~CMSPAR; 302 + termios->c_iflag &= ~(BRKINT | IGNBRK); 303 + 304 + /* Limit baud rates so that we don't need the fractional divider */ 305 + baud = uart_get_baud_rate(port, termios, old, 306 + port->uartclk / (0x10000*16), 307 + port->uartclk / 256); 308 + divisor = uart_get_divisor(port, baud) - 1; 309 + 310 + switch (termios->c_cflag & CSIZE) { 311 + case CS7: 312 + break; 313 + case CS8: 314 + default: 315 + config |= UA_CONFIG_CHAR_LEN; 316 + break; 317 + } 318 + 319 + if (termios->c_cflag & CSTOPB) 320 + config |= UA_CONFIG_STOP_BITS; 321 + 322 + if (termios->c_cflag & PARENB) { 323 + config |= UA_CONFIG_PARITY; 324 + if (termios->c_cflag & PARODD) 325 + config |= UA_CONFIG_ODD_PARITY; 326 + } 327 + 328 + /* Set read status mask */ 329 + port->read_status_mask = UA_STATUS_OVERRUN_ERR; 330 + if (termios->c_iflag & INPCK) 331 + port->read_status_mask |= UA_STATUS_PARITY_ERR 332 + | UA_STATUS_FRAME_ERR; 333 + 334 + /* Set status ignore mask */ 335 + port->ignore_status_mask = 0; 336 + if (!(termios->c_cflag & CREAD)) 337 + port->ignore_status_mask |= UA_STATUS_OVERRUN_ERR 338 + | UA_STATUS_PARITY_ERR | UA_STATUS_FRAME_ERR; 339 + 340 + spin_lock_irqsave(&port->lock, flags); 341 + 342 + uart_update_timeout(port, termios->c_cflag, baud); 343 + 344 + writeb_relaxed(config, port->membase + UA_CONFIG); 345 + writeb_relaxed(divisor & 0xff, port->membase + UA_HBAUD_LO); 346 + writeb_relaxed(divisor >> 8, port->membase + UA_HBAUD_HI); 347 + 348 + spin_unlock_irqrestore(&port->lock, flags); 349 + } 350 + 351 + static const char *digicolor_uart_type(struct uart_port *port) 352 + { 353 + return (port->type == PORT_DIGICOLOR) ? "DIGICOLOR USART" : NULL; 354 + } 355 + 356 + static void digicolor_uart_config_port(struct uart_port *port, int flags) 357 + { 358 + if (flags & UART_CONFIG_TYPE) 359 + port->type = PORT_DIGICOLOR; 360 + } 361 + 362 + static void digicolor_uart_release_port(struct uart_port *port) 363 + { 364 + } 365 + 366 + static int digicolor_uart_request_port(struct uart_port *port) 367 + { 368 + return 0; 369 + } 370 + 371 + static const struct uart_ops digicolor_uart_ops = { 372 + .tx_empty = digicolor_uart_tx_empty, 373 + .set_mctrl = digicolor_uart_set_mctrl, 374 + .get_mctrl = digicolor_uart_get_mctrl, 375 + .stop_tx = digicolor_uart_stop_tx, 376 + .start_tx = digicolor_uart_start_tx, 377 + .stop_rx = digicolor_uart_stop_rx, 378 + .break_ctl = digicolor_uart_break_ctl, 379 + .startup = digicolor_uart_startup, 380 + .shutdown = digicolor_uart_shutdown, 381 + .set_termios = digicolor_uart_set_termios, 382 + .type = digicolor_uart_type, 383 + .config_port = digicolor_uart_config_port, 384 + .release_port = digicolor_uart_release_port, 385 + .request_port = digicolor_uart_request_port, 386 + }; 387 + 388 + static void digicolor_uart_console_putchar(struct uart_port *port, int ch) 389 + { 390 + while (digicolor_uart_tx_full(port)) 391 + cpu_relax(); 392 + 393 + writeb_relaxed(ch, port->membase + UA_EMI_REC); 394 + } 395 + 396 + static void digicolor_uart_console_write(struct console *co, const char *c, 397 + unsigned n) 398 + { 399 + struct uart_port *port = digicolor_ports[co->index]; 400 + u8 status; 401 + unsigned long flags; 402 + int locked = 1; 403 + 404 + if (oops_in_progress) 405 + locked = spin_trylock_irqsave(&port->lock, flags); 406 + else 407 + spin_lock_irqsave(&port->lock, flags); 408 + 409 + uart_console_write(port, c, n, digicolor_uart_console_putchar); 410 + 411 + if (locked) 412 + spin_unlock_irqrestore(&port->lock, flags); 413 + 414 + /* Wait for transmitter to become empty */ 415 + do { 416 + status = readb_relaxed(port->membase + UA_STATUS); 417 + } while ((status & UA_STATUS_TX_READY) == 0); 418 + } 419 + 420 + static int digicolor_uart_console_setup(struct console *co, char *options) 421 + { 422 + int baud = 115200, bits = 8, parity = 'n', flow = 'n'; 423 + struct uart_port *port; 424 + 425 + if (co->index < 0 || co->index >= DIGICOLOR_USART_NR) 426 + return -EINVAL; 427 + 428 + port = digicolor_ports[co->index]; 429 + if (!port) 430 + return -ENODEV; 431 + 432 + if (options) 433 + uart_parse_options(options, &baud, &parity, &bits, &flow); 434 + 435 + return uart_set_options(port, co, baud, parity, bits, flow); 436 + } 437 + 438 + static struct console digicolor_console = { 439 + .name = "ttyS", 440 + .device = uart_console_device, 441 + .write = digicolor_uart_console_write, 442 + .setup = digicolor_uart_console_setup, 443 + .flags = CON_PRINTBUFFER, 444 + .index = -1, 445 + }; 446 + 447 + static struct uart_driver digicolor_uart = { 448 + .driver_name = "digicolor-usart", 449 + .dev_name = "ttyS", 450 + .nr = DIGICOLOR_USART_NR, 451 + }; 452 + 453 + static int digicolor_uart_probe(struct platform_device *pdev) 454 + { 455 + struct device_node *np = pdev->dev.of_node; 456 + int ret, index; 457 + struct digicolor_port *dp; 458 + struct resource *res; 459 + struct clk *uart_clk; 460 + 461 + if (!np) { 462 + dev_err(&pdev->dev, "Missing device tree node\n"); 463 + return -ENXIO; 464 + } 465 + 466 + index = of_alias_get_id(np, "serial"); 467 + if (index < 0 || index >= DIGICOLOR_USART_NR) 468 + return -EINVAL; 469 + 470 + dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL); 471 + if (!dp) 472 + return -ENOMEM; 473 + 474 + uart_clk = devm_clk_get(&pdev->dev, NULL); 475 + if (IS_ERR(uart_clk)) 476 + return PTR_ERR(uart_clk); 477 + 478 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 479 + dp->port.mapbase = res->start; 480 + dp->port.membase = devm_ioremap_resource(&pdev->dev, res); 481 + if (IS_ERR(dp->port.membase)) 482 + return PTR_ERR(dp->port.membase); 483 + 484 + dp->port.irq = platform_get_irq(pdev, 0); 485 + if (IS_ERR_VALUE(dp->port.irq)) 486 + return dp->port.irq; 487 + 488 + dp->port.iotype = UPIO_MEM; 489 + dp->port.uartclk = clk_get_rate(uart_clk); 490 + dp->port.fifosize = 16; 491 + dp->port.dev = &pdev->dev; 492 + dp->port.ops = &digicolor_uart_ops; 493 + dp->port.line = index; 494 + dp->port.type = PORT_DIGICOLOR; 495 + spin_lock_init(&dp->port.lock); 496 + 497 + digicolor_ports[index] = &dp->port; 498 + platform_set_drvdata(pdev, &dp->port); 499 + 500 + INIT_DELAYED_WORK(&dp->rx_poll_work, digicolor_rx_poll); 501 + 502 + ret = devm_request_irq(&pdev->dev, dp->port.irq, digicolor_uart_int, 0, 503 + dev_name(&pdev->dev), &dp->port); 504 + if (ret) 505 + return ret; 506 + 507 + return uart_add_one_port(&digicolor_uart, &dp->port); 508 + } 509 + 510 + static int digicolor_uart_remove(struct platform_device *pdev) 511 + { 512 + struct uart_port *port = platform_get_drvdata(pdev); 513 + 514 + uart_remove_one_port(&digicolor_uart, port); 515 + 516 + return 0; 517 + } 518 + 519 + static const struct of_device_id digicolor_uart_dt_ids[] = { 520 + { .compatible = "cnxt,cx92755-usart", }, 521 + { } 522 + }; 523 + MODULE_DEVICE_TABLE(of, digicolor_uart_dt_ids); 524 + 525 + static struct platform_driver digicolor_uart_platform = { 526 + .driver = { 527 + .name = "digicolor-usart", 528 + .of_match_table = of_match_ptr(digicolor_uart_dt_ids), 529 + }, 530 + .probe = digicolor_uart_probe, 531 + .remove = digicolor_uart_remove, 532 + }; 533 + 534 + static int __init digicolor_uart_init(void) 535 + { 536 + int ret; 537 + 538 + if (IS_ENABLED(CONFIG_SERIAL_CONEXANT_DIGICOLOR_CONSOLE)) { 539 + digicolor_uart.cons = &digicolor_console; 540 + digicolor_console.data = &digicolor_uart; 541 + } 542 + 543 + ret = uart_register_driver(&digicolor_uart); 544 + if (ret) 545 + return ret; 546 + 547 + return platform_driver_register(&digicolor_uart_platform); 548 + } 549 + module_init(digicolor_uart_init); 550 + 551 + static void __exit digicolor_uart_exit(void) 552 + { 553 + platform_driver_unregister(&digicolor_uart_platform); 554 + uart_unregister_driver(&digicolor_uart); 555 + } 556 + module_exit(digicolor_uart_exit); 557 + 558 + MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); 559 + MODULE_DESCRIPTION("Conexant Digicolor USART serial driver"); 560 + MODULE_LICENSE("GPL");
+996
drivers/tty/serial/etraxfs-uart.c
··· 1 + #include <linux/module.h> 2 + #include <linux/init.h> 3 + #include <linux/console.h> 4 + #include <linux/platform_device.h> 5 + #include <linux/serial_core.h> 6 + #include <linux/tty_flip.h> 7 + #include <linux/of.h> 8 + #include <linux/gpio.h> 9 + #include <linux/of_irq.h> 10 + #include <linux/of_address.h> 11 + #include <hwregs/ser_defs.h> 12 + 13 + #define DRV_NAME "etraxfs-uart" 14 + #define UART_NR CONFIG_ETRAX_SERIAL_PORTS 15 + 16 + #define MODIFY_REG(instance, reg, var) \ 17 + do { \ 18 + if (REG_RD_INT(ser, instance, reg) != \ 19 + REG_TYPE_CONV(int, reg_ser_##reg, var)) \ 20 + REG_WR(ser, instance, reg, var); \ 21 + } while (0) 22 + 23 + struct uart_cris_port { 24 + struct uart_port port; 25 + 26 + int initialized; 27 + int irq; 28 + 29 + void __iomem *regi_ser; 30 + 31 + struct gpio_desc *dtr_pin; 32 + struct gpio_desc *dsr_pin; 33 + struct gpio_desc *ri_pin; 34 + struct gpio_desc *cd_pin; 35 + 36 + int write_ongoing; 37 + }; 38 + 39 + static struct uart_driver etraxfs_uart_driver; 40 + static struct uart_port *console_port; 41 + static int console_baud = 115200; 42 + static struct uart_cris_port *etraxfs_uart_ports[UART_NR]; 43 + 44 + static void cris_serial_port_init(struct uart_port *port, int line); 45 + static void etraxfs_uart_stop_rx(struct uart_port *port); 46 + static inline void etraxfs_uart_start_tx_bottom(struct uart_port *port); 47 + 48 + #ifdef CONFIG_SERIAL_ETRAXFS_CONSOLE 49 + static void 50 + cris_console_write(struct console *co, const char *s, unsigned int count) 51 + { 52 + struct uart_cris_port *up; 53 + int i; 54 + reg_ser_r_stat_din stat; 55 + reg_ser_rw_tr_dma_en tr_dma_en, old; 56 + 57 + up = etraxfs_uart_ports[co->index]; 58 + 59 + if (!up) 60 + return; 61 + 62 + /* Switch to manual mode. */ 63 + tr_dma_en = old = REG_RD(ser, up->regi_ser, rw_tr_dma_en); 64 + if (tr_dma_en.en == regk_ser_yes) { 65 + tr_dma_en.en = regk_ser_no; 66 + REG_WR(ser, up->regi_ser, rw_tr_dma_en, tr_dma_en); 67 + } 68 + 69 + /* Send data. */ 70 + for (i = 0; i < count; i++) { 71 + /* LF -> CRLF */ 72 + if (s[i] == '\n') { 73 + do { 74 + stat = REG_RD(ser, up->regi_ser, r_stat_din); 75 + } while (!stat.tr_rdy); 76 + REG_WR_INT(ser, up->regi_ser, rw_dout, '\r'); 77 + } 78 + /* Wait until transmitter is ready and send. */ 79 + do { 80 + stat = REG_RD(ser, up->regi_ser, r_stat_din); 81 + } while (!stat.tr_rdy); 82 + REG_WR_INT(ser, up->regi_ser, rw_dout, s[i]); 83 + } 84 + 85 + /* Restore mode. */ 86 + if (tr_dma_en.en != old.en) 87 + REG_WR(ser, up->regi_ser, rw_tr_dma_en, old); 88 + } 89 + 90 + static int __init 91 + cris_console_setup(struct console *co, char *options) 92 + { 93 + struct uart_port *port; 94 + int baud = 115200; 95 + int bits = 8; 96 + int parity = 'n'; 97 + int flow = 'n'; 98 + 99 + if (co->index < 0 || co->index >= UART_NR) 100 + co->index = 0; 101 + port = &etraxfs_uart_ports[co->index]->port; 102 + console_port = port; 103 + 104 + co->flags |= CON_CONSDEV; 105 + 106 + if (options) 107 + uart_parse_options(options, &baud, &parity, &bits, &flow); 108 + console_baud = baud; 109 + cris_serial_port_init(port, co->index); 110 + uart_set_options(port, co, baud, parity, bits, flow); 111 + 112 + return 0; 113 + } 114 + 115 + static struct tty_driver *cris_console_device(struct console *co, int *index) 116 + { 117 + struct uart_driver *p = co->data; 118 + *index = co->index; 119 + return p->tty_driver; 120 + } 121 + 122 + static struct console cris_console = { 123 + .name = "ttyS", 124 + .write = cris_console_write, 125 + .device = cris_console_device, 126 + .setup = cris_console_setup, 127 + .flags = CON_PRINTBUFFER, 128 + .index = -1, 129 + .data = &etraxfs_uart_driver, 130 + }; 131 + #endif /* CONFIG_SERIAL_ETRAXFS_CONSOLE */ 132 + 133 + static struct uart_driver etraxfs_uart_driver = { 134 + .owner = THIS_MODULE, 135 + .driver_name = "serial", 136 + .dev_name = "ttyS", 137 + .major = TTY_MAJOR, 138 + .minor = 64, 139 + .nr = UART_NR, 140 + #ifdef CONFIG_SERIAL_ETRAXFS_CONSOLE 141 + .cons = &cris_console, 142 + #endif /* CONFIG_SERIAL_ETRAXFS_CONSOLE */ 143 + }; 144 + 145 + static inline int crisv32_serial_get_rts(struct uart_cris_port *up) 146 + { 147 + void __iomem *regi_ser = up->regi_ser; 148 + /* 149 + * Return what the user has controlled rts to or 150 + * what the pin is? (if auto_rts is used it differs during tx) 151 + */ 152 + reg_ser_r_stat_din rstat = REG_RD(ser, regi_ser, r_stat_din); 153 + 154 + return !(rstat.rts_n == regk_ser_active); 155 + } 156 + 157 + /* 158 + * A set = 0 means 3.3V on the pin, bitvalue: 0=active, 1=inactive 159 + * 0=0V , 1=3.3V 160 + */ 161 + static inline void crisv32_serial_set_rts(struct uart_cris_port *up, 162 + int set, int force) 163 + { 164 + void __iomem *regi_ser = up->regi_ser; 165 + 166 + unsigned long flags; 167 + reg_ser_rw_rec_ctrl rec_ctrl; 168 + 169 + local_irq_save(flags); 170 + rec_ctrl = REG_RD(ser, regi_ser, rw_rec_ctrl); 171 + 172 + if (set) 173 + rec_ctrl.rts_n = regk_ser_active; 174 + else 175 + rec_ctrl.rts_n = regk_ser_inactive; 176 + REG_WR(ser, regi_ser, rw_rec_ctrl, rec_ctrl); 177 + local_irq_restore(flags); 178 + } 179 + 180 + static inline int crisv32_serial_get_cts(struct uart_cris_port *up) 181 + { 182 + void __iomem *regi_ser = up->regi_ser; 183 + reg_ser_r_stat_din rstat = REG_RD(ser, regi_ser, r_stat_din); 184 + 185 + return (rstat.cts_n == regk_ser_active); 186 + } 187 + 188 + /* 189 + * Send a single character for XON/XOFF purposes. We do it in this separate 190 + * function instead of the alternative support port.x_char, in the ...start_tx 191 + * function, so we don't mix up this case with possibly enabling transmission 192 + * of queued-up data (in case that's disabled after *receiving* an XOFF or 193 + * negative CTS). This function is used for both DMA and non-DMA case; see HW 194 + * docs specifically blessing sending characters manually when DMA for 195 + * transmission is enabled and running. We may be asked to transmit despite 196 + * the transmitter being disabled by a ..._stop_tx call so we need to enable 197 + * it temporarily but restore the state afterwards. 198 + */ 199 + static void etraxfs_uart_send_xchar(struct uart_port *port, char ch) 200 + { 201 + struct uart_cris_port *up = (struct uart_cris_port *)port; 202 + reg_ser_rw_dout dout = { .data = ch }; 203 + reg_ser_rw_ack_intr ack_intr = { .tr_rdy = regk_ser_yes }; 204 + reg_ser_r_stat_din rstat; 205 + reg_ser_rw_tr_ctrl prev_tr_ctrl, tr_ctrl; 206 + void __iomem *regi_ser = up->regi_ser; 207 + unsigned long flags; 208 + 209 + /* 210 + * Wait for tr_rdy in case a character is already being output. Make 211 + * sure we have integrity between the register reads and the writes 212 + * below, but don't busy-wait with interrupts off and the port lock 213 + * taken. 214 + */ 215 + spin_lock_irqsave(&port->lock, flags); 216 + do { 217 + spin_unlock_irqrestore(&port->lock, flags); 218 + spin_lock_irqsave(&port->lock, flags); 219 + prev_tr_ctrl = tr_ctrl = REG_RD(ser, regi_ser, rw_tr_ctrl); 220 + rstat = REG_RD(ser, regi_ser, r_stat_din); 221 + } while (!rstat.tr_rdy); 222 + 223 + /* 224 + * Ack an interrupt if one was just issued for the previous character 225 + * that was output. This is required for non-DMA as the interrupt is 226 + * used as the only indicator that the transmitter is ready and it 227 + * isn't while this x_char is being transmitted. 228 + */ 229 + REG_WR(ser, regi_ser, rw_ack_intr, ack_intr); 230 + 231 + /* Enable the transmitter in case it was disabled. */ 232 + tr_ctrl.stop = 0; 233 + REG_WR(ser, regi_ser, rw_tr_ctrl, tr_ctrl); 234 + 235 + /* 236 + * Finally, send the blessed character; nothing should stop it now, 237 + * except for an xoff-detected state, which we'll handle below. 238 + */ 239 + REG_WR(ser, regi_ser, rw_dout, dout); 240 + up->port.icount.tx++; 241 + 242 + /* There might be an xoff state to clear. */ 243 + rstat = REG_RD(ser, up->regi_ser, r_stat_din); 244 + 245 + /* 246 + * Clear any xoff state that *may* have been there to 247 + * inhibit transmission of the character. 248 + */ 249 + if (rstat.xoff_detect) { 250 + reg_ser_rw_xoff_clr xoff_clr = { .clr = 1 }; 251 + reg_ser_rw_tr_dma_en tr_dma_en; 252 + 253 + REG_WR(ser, regi_ser, rw_xoff_clr, xoff_clr); 254 + tr_dma_en = REG_RD(ser, regi_ser, rw_tr_dma_en); 255 + 256 + /* 257 + * If we had an xoff state but cleared it, instead sneak in a 258 + * disabled state for the transmitter, after the character we 259 + * sent. Thus we keep the port disabled, just as if the xoff 260 + * state was still in effect (or actually, as if stop_tx had 261 + * been called, as we stop DMA too). 262 + */ 263 + prev_tr_ctrl.stop = 1; 264 + 265 + tr_dma_en.en = 0; 266 + REG_WR(ser, regi_ser, rw_tr_dma_en, tr_dma_en); 267 + } 268 + 269 + /* Restore "previous" enabled/disabled state of the transmitter. */ 270 + REG_WR(ser, regi_ser, rw_tr_ctrl, prev_tr_ctrl); 271 + 272 + spin_unlock_irqrestore(&port->lock, flags); 273 + } 274 + 275 + /* 276 + * Do not spin_lock_irqsave or disable interrupts by other means here; it's 277 + * already done by the caller. 278 + */ 279 + static void etraxfs_uart_start_tx(struct uart_port *port) 280 + { 281 + struct uart_cris_port *up = (struct uart_cris_port *)port; 282 + 283 + /* we have already done below if a write is ongoing */ 284 + if (up->write_ongoing) 285 + return; 286 + 287 + /* Signal that write is ongoing */ 288 + up->write_ongoing = 1; 289 + 290 + etraxfs_uart_start_tx_bottom(port); 291 + } 292 + 293 + static inline void etraxfs_uart_start_tx_bottom(struct uart_port *port) 294 + { 295 + struct uart_cris_port *up = (struct uart_cris_port *)port; 296 + void __iomem *regi_ser = up->regi_ser; 297 + reg_ser_rw_tr_ctrl tr_ctrl; 298 + reg_ser_rw_intr_mask intr_mask; 299 + 300 + tr_ctrl = REG_RD(ser, regi_ser, rw_tr_ctrl); 301 + tr_ctrl.stop = regk_ser_no; 302 + REG_WR(ser, regi_ser, rw_tr_ctrl, tr_ctrl); 303 + intr_mask = REG_RD(ser, regi_ser, rw_intr_mask); 304 + intr_mask.tr_rdy = regk_ser_yes; 305 + REG_WR(ser, regi_ser, rw_intr_mask, intr_mask); 306 + } 307 + 308 + /* 309 + * This function handles both the DMA and non-DMA case by ordering the 310 + * transmitter to stop of after the current character. We don't need to wait 311 + * for any such character to be completely transmitted; we do that where it 312 + * matters, like in etraxfs_uart_set_termios. Don't busy-wait here; see 313 + * Documentation/serial/driver: this function is called within 314 + * spin_lock_irq{,save} and thus separate ones would be disastrous (when SMP). 315 + * There's no documented need to set the txd pin to any particular value; 316 + * break setting is controlled solely by etraxfs_uart_break_ctl. 317 + */ 318 + static void etraxfs_uart_stop_tx(struct uart_port *port) 319 + { 320 + struct uart_cris_port *up = (struct uart_cris_port *)port; 321 + void __iomem *regi_ser = up->regi_ser; 322 + reg_ser_rw_tr_ctrl tr_ctrl; 323 + reg_ser_rw_intr_mask intr_mask; 324 + reg_ser_rw_tr_dma_en tr_dma_en = {0}; 325 + reg_ser_rw_xoff_clr xoff_clr = {0}; 326 + 327 + /* 328 + * For the non-DMA case, we'd get a tr_rdy interrupt that we're not 329 + * interested in as we're not transmitting any characters. For the 330 + * DMA case, that interrupt is already turned off, but no reason to 331 + * waste code on conditionals here. 332 + */ 333 + intr_mask = REG_RD(ser, regi_ser, rw_intr_mask); 334 + intr_mask.tr_rdy = regk_ser_no; 335 + REG_WR(ser, regi_ser, rw_intr_mask, intr_mask); 336 + 337 + tr_ctrl = REG_RD(ser, regi_ser, rw_tr_ctrl); 338 + tr_ctrl.stop = 1; 339 + REG_WR(ser, regi_ser, rw_tr_ctrl, tr_ctrl); 340 + 341 + /* 342 + * Always clear possible hardware xoff-detected state here, no need to 343 + * unnecessary consider mctrl settings and when they change. We clear 344 + * it here rather than in start_tx: both functions are called as the 345 + * effect of XOFF processing, but start_tx is also called when upper 346 + * levels tell the driver that there are more characters to send, so 347 + * avoid adding code there. 348 + */ 349 + xoff_clr.clr = 1; 350 + REG_WR(ser, regi_ser, rw_xoff_clr, xoff_clr); 351 + 352 + /* 353 + * Disable transmitter DMA, so that if we're in XON/XOFF, we can send 354 + * those single characters without also giving go-ahead for queued up 355 + * DMA data. 356 + */ 357 + tr_dma_en.en = 0; 358 + REG_WR(ser, regi_ser, rw_tr_dma_en, tr_dma_en); 359 + 360 + /* 361 + * Make sure that write_ongoing is reset when stopping tx. 362 + */ 363 + up->write_ongoing = 0; 364 + } 365 + 366 + static void etraxfs_uart_stop_rx(struct uart_port *port) 367 + { 368 + struct uart_cris_port *up = (struct uart_cris_port *)port; 369 + void __iomem *regi_ser = up->regi_ser; 370 + reg_ser_rw_rec_ctrl rec_ctrl = REG_RD(ser, regi_ser, rw_rec_ctrl); 371 + 372 + rec_ctrl.en = regk_ser_no; 373 + REG_WR(ser, regi_ser, rw_rec_ctrl, rec_ctrl); 374 + } 375 + 376 + static void etraxfs_uart_enable_ms(struct uart_port *port) 377 + { 378 + } 379 + 380 + static void check_modem_status(struct uart_cris_port *up) 381 + { 382 + } 383 + 384 + static unsigned int etraxfs_uart_tx_empty(struct uart_port *port) 385 + { 386 + struct uart_cris_port *up = (struct uart_cris_port *)port; 387 + unsigned long flags; 388 + unsigned int ret; 389 + reg_ser_r_stat_din rstat = {0}; 390 + 391 + spin_lock_irqsave(&up->port.lock, flags); 392 + 393 + rstat = REG_RD(ser, up->regi_ser, r_stat_din); 394 + ret = rstat.tr_empty ? TIOCSER_TEMT : 0; 395 + 396 + spin_unlock_irqrestore(&up->port.lock, flags); 397 + return ret; 398 + } 399 + static unsigned int etraxfs_uart_get_mctrl(struct uart_port *port) 400 + { 401 + struct uart_cris_port *up = (struct uart_cris_port *)port; 402 + unsigned int ret; 403 + 404 + ret = 0; 405 + if (crisv32_serial_get_rts(up)) 406 + ret |= TIOCM_RTS; 407 + /* DTR is active low */ 408 + if (up->dtr_pin && !gpiod_get_raw_value(up->dtr_pin)) 409 + ret |= TIOCM_DTR; 410 + /* CD is active low */ 411 + if (up->cd_pin && !gpiod_get_raw_value(up->cd_pin)) 412 + ret |= TIOCM_CD; 413 + /* RI is active low */ 414 + if (up->ri_pin && !gpiod_get_raw_value(up->ri_pin)) 415 + ret |= TIOCM_RI; 416 + /* DSR is active low */ 417 + if (up->dsr_pin && !gpiod_get_raw_value(up->dsr_pin)) 418 + ret |= TIOCM_DSR; 419 + if (crisv32_serial_get_cts(up)) 420 + ret |= TIOCM_CTS; 421 + return ret; 422 + } 423 + 424 + static void etraxfs_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) 425 + { 426 + struct uart_cris_port *up = (struct uart_cris_port *)port; 427 + 428 + crisv32_serial_set_rts(up, mctrl & TIOCM_RTS ? 1 : 0, 0); 429 + /* DTR is active low */ 430 + if (up->dtr_pin) 431 + gpiod_set_raw_value(up->dtr_pin, mctrl & TIOCM_DTR ? 0 : 1); 432 + /* RI is active low */ 433 + if (up->ri_pin) 434 + gpiod_set_raw_value(up->ri_pin, mctrl & TIOCM_RNG ? 0 : 1); 435 + /* CD is active low */ 436 + if (up->cd_pin) 437 + gpiod_set_raw_value(up->cd_pin, mctrl & TIOCM_CD ? 0 : 1); 438 + } 439 + 440 + static void etraxfs_uart_break_ctl(struct uart_port *port, int break_state) 441 + { 442 + struct uart_cris_port *up = (struct uart_cris_port *)port; 443 + unsigned long flags; 444 + reg_ser_rw_tr_ctrl tr_ctrl; 445 + reg_ser_rw_tr_dma_en tr_dma_en; 446 + reg_ser_rw_intr_mask intr_mask; 447 + 448 + spin_lock_irqsave(&up->port.lock, flags); 449 + tr_ctrl = REG_RD(ser, up->regi_ser, rw_tr_ctrl); 450 + tr_dma_en = REG_RD(ser, up->regi_ser, rw_tr_dma_en); 451 + intr_mask = REG_RD(ser, up->regi_ser, rw_intr_mask); 452 + 453 + if (break_state != 0) { /* Send break */ 454 + /* 455 + * We need to disable DMA (if used) or tr_rdy interrupts if no 456 + * DMA. No need to make this conditional on use of DMA; 457 + * disabling will be a no-op for the other mode. 458 + */ 459 + intr_mask.tr_rdy = regk_ser_no; 460 + tr_dma_en.en = 0; 461 + 462 + /* 463 + * Stop transmission and set the txd pin to 0 after the 464 + * current character. The txd setting will take effect after 465 + * any current transmission has completed. 466 + */ 467 + tr_ctrl.stop = 1; 468 + tr_ctrl.txd = 0; 469 + } else { 470 + /* Re-enable the serial interrupt. */ 471 + intr_mask.tr_rdy = regk_ser_yes; 472 + 473 + tr_ctrl.stop = 0; 474 + tr_ctrl.txd = 1; 475 + } 476 + REG_WR(ser, up->regi_ser, rw_tr_ctrl, tr_ctrl); 477 + REG_WR(ser, up->regi_ser, rw_tr_dma_en, tr_dma_en); 478 + REG_WR(ser, up->regi_ser, rw_intr_mask, intr_mask); 479 + 480 + spin_unlock_irqrestore(&up->port.lock, flags); 481 + } 482 + 483 + static void 484 + transmit_chars_no_dma(struct uart_cris_port *up) 485 + { 486 + int max_count; 487 + struct circ_buf *xmit = &up->port.state->xmit; 488 + 489 + void __iomem *regi_ser = up->regi_ser; 490 + reg_ser_r_stat_din rstat; 491 + reg_ser_rw_ack_intr ack_intr = { .tr_rdy = regk_ser_yes }; 492 + 493 + if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { 494 + /* No more to send, so disable the interrupt. */ 495 + reg_ser_rw_intr_mask intr_mask; 496 + 497 + intr_mask = REG_RD(ser, regi_ser, rw_intr_mask); 498 + intr_mask.tr_rdy = 0; 499 + intr_mask.tr_empty = 0; 500 + REG_WR(ser, regi_ser, rw_intr_mask, intr_mask); 501 + up->write_ongoing = 0; 502 + return; 503 + } 504 + 505 + /* If the serport is fast, we send up to max_count bytes before 506 + exiting the loop. */ 507 + max_count = 64; 508 + do { 509 + reg_ser_rw_dout dout = { .data = xmit->buf[xmit->tail] }; 510 + 511 + REG_WR(ser, regi_ser, rw_dout, dout); 512 + REG_WR(ser, regi_ser, rw_ack_intr, ack_intr); 513 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE-1); 514 + up->port.icount.tx++; 515 + if (xmit->head == xmit->tail) 516 + break; 517 + rstat = REG_RD(ser, regi_ser, r_stat_din); 518 + } while ((--max_count > 0) && rstat.tr_rdy); 519 + 520 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 521 + uart_write_wakeup(&up->port); 522 + } 523 + 524 + static void receive_chars_no_dma(struct uart_cris_port *up) 525 + { 526 + reg_ser_rs_stat_din stat_din; 527 + reg_ser_r_stat_din rstat; 528 + struct tty_port *port; 529 + struct uart_icount *icount; 530 + int max_count = 16; 531 + char flag; 532 + reg_ser_rw_ack_intr ack_intr = { 0 }; 533 + 534 + rstat = REG_RD(ser, up->regi_ser, r_stat_din); 535 + icount = &up->port.icount; 536 + port = &up->port.state->port; 537 + 538 + do { 539 + stat_din = REG_RD(ser, up->regi_ser, rs_stat_din); 540 + 541 + flag = TTY_NORMAL; 542 + ack_intr.dav = 1; 543 + REG_WR(ser, up->regi_ser, rw_ack_intr, ack_intr); 544 + icount->rx++; 545 + 546 + if (stat_din.framing_err | stat_din.par_err | stat_din.orun) { 547 + if (stat_din.data == 0x00 && 548 + stat_din.framing_err) { 549 + /* Most likely a break. */ 550 + flag = TTY_BREAK; 551 + icount->brk++; 552 + } else if (stat_din.par_err) { 553 + flag = TTY_PARITY; 554 + icount->parity++; 555 + } else if (stat_din.orun) { 556 + flag = TTY_OVERRUN; 557 + icount->overrun++; 558 + } else if (stat_din.framing_err) { 559 + flag = TTY_FRAME; 560 + icount->frame++; 561 + } 562 + } 563 + 564 + /* 565 + * If this becomes important, we probably *could* handle this 566 + * gracefully by keeping track of the unhandled character. 567 + */ 568 + if (!tty_insert_flip_char(port, stat_din.data, flag)) 569 + panic("%s: No tty buffer space", __func__); 570 + rstat = REG_RD(ser, up->regi_ser, r_stat_din); 571 + } while (rstat.dav && (max_count-- > 0)); 572 + spin_unlock(&up->port.lock); 573 + tty_flip_buffer_push(port); 574 + spin_lock(&up->port.lock); 575 + } 576 + 577 + static irqreturn_t 578 + ser_interrupt(int irq, void *dev_id) 579 + { 580 + struct uart_cris_port *up = (struct uart_cris_port *)dev_id; 581 + void __iomem *regi_ser; 582 + int handled = 0; 583 + 584 + spin_lock(&up->port.lock); 585 + 586 + regi_ser = up->regi_ser; 587 + 588 + if (regi_ser) { 589 + reg_ser_r_masked_intr masked_intr; 590 + 591 + masked_intr = REG_RD(ser, regi_ser, r_masked_intr); 592 + /* 593 + * Check what interrupts are active before taking 594 + * actions. If DMA is used the interrupt shouldn't 595 + * be enabled. 596 + */ 597 + if (masked_intr.dav) { 598 + receive_chars_no_dma(up); 599 + handled = 1; 600 + } 601 + check_modem_status(up); 602 + 603 + if (masked_intr.tr_rdy) { 604 + transmit_chars_no_dma(up); 605 + handled = 1; 606 + } 607 + } 608 + spin_unlock(&up->port.lock); 609 + return IRQ_RETVAL(handled); 610 + } 611 + 612 + #ifdef CONFIG_CONSOLE_POLL 613 + static int etraxfs_uart_get_poll_char(struct uart_port *port) 614 + { 615 + reg_ser_rs_stat_din stat; 616 + reg_ser_rw_ack_intr ack_intr = { 0 }; 617 + struct uart_cris_port *up = (struct uart_cris_port *)port; 618 + 619 + do { 620 + stat = REG_RD(ser, up->regi_ser, rs_stat_din); 621 + } while (!stat.dav); 622 + 623 + /* Ack the data_avail interrupt. */ 624 + ack_intr.dav = 1; 625 + REG_WR(ser, up->regi_ser, rw_ack_intr, ack_intr); 626 + 627 + return stat.data; 628 + } 629 + 630 + static void etraxfs_uart_put_poll_char(struct uart_port *port, 631 + unsigned char c) 632 + { 633 + reg_ser_r_stat_din stat; 634 + struct uart_cris_port *up = (struct uart_cris_port *)port; 635 + 636 + do { 637 + stat = REG_RD(ser, up->regi_ser, r_stat_din); 638 + } while (!stat.tr_rdy); 639 + REG_WR_INT(ser, up->regi_ser, rw_dout, c); 640 + } 641 + #endif /* CONFIG_CONSOLE_POLL */ 642 + 643 + static int etraxfs_uart_startup(struct uart_port *port) 644 + { 645 + struct uart_cris_port *up = (struct uart_cris_port *)port; 646 + unsigned long flags; 647 + reg_ser_rw_intr_mask ser_intr_mask = {0}; 648 + 649 + ser_intr_mask.dav = regk_ser_yes; 650 + 651 + if (request_irq(etraxfs_uart_ports[port->line]->irq, ser_interrupt, 652 + 0, DRV_NAME, etraxfs_uart_ports[port->line])) 653 + panic("irq ser%d", port->line); 654 + 655 + spin_lock_irqsave(&up->port.lock, flags); 656 + 657 + REG_WR(ser, up->regi_ser, rw_intr_mask, ser_intr_mask); 658 + 659 + etraxfs_uart_set_mctrl(&up->port, up->port.mctrl); 660 + 661 + spin_unlock_irqrestore(&up->port.lock, flags); 662 + 663 + return 0; 664 + } 665 + 666 + static void etraxfs_uart_shutdown(struct uart_port *port) 667 + { 668 + struct uart_cris_port *up = (struct uart_cris_port *)port; 669 + unsigned long flags; 670 + 671 + spin_lock_irqsave(&up->port.lock, flags); 672 + 673 + etraxfs_uart_stop_tx(port); 674 + etraxfs_uart_stop_rx(port); 675 + 676 + free_irq(etraxfs_uart_ports[port->line]->irq, 677 + etraxfs_uart_ports[port->line]); 678 + 679 + etraxfs_uart_set_mctrl(&up->port, up->port.mctrl); 680 + 681 + spin_unlock_irqrestore(&up->port.lock, flags); 682 + 683 + } 684 + 685 + static void 686 + etraxfs_uart_set_termios(struct uart_port *port, struct ktermios *termios, 687 + struct ktermios *old) 688 + { 689 + struct uart_cris_port *up = (struct uart_cris_port *)port; 690 + unsigned long flags; 691 + reg_ser_rw_xoff xoff; 692 + reg_ser_rw_xoff_clr xoff_clr = {0}; 693 + reg_ser_rw_tr_ctrl tx_ctrl = {0}; 694 + reg_ser_rw_tr_dma_en tx_dma_en = {0}; 695 + reg_ser_rw_rec_ctrl rx_ctrl = {0}; 696 + reg_ser_rw_tr_baud_div tx_baud_div = {0}; 697 + reg_ser_rw_rec_baud_div rx_baud_div = {0}; 698 + int baud; 699 + 700 + if (old && 701 + termios->c_cflag == old->c_cflag && 702 + termios->c_iflag == old->c_iflag) 703 + return; 704 + 705 + /* Tx: 8 bit, no/even parity, 1 stop bit, no cts. */ 706 + tx_ctrl.base_freq = regk_ser_f29_493; 707 + tx_ctrl.en = 0; 708 + tx_ctrl.stop = 0; 709 + tx_ctrl.auto_rts = regk_ser_no; 710 + tx_ctrl.txd = 1; 711 + tx_ctrl.auto_cts = 0; 712 + /* Rx: 8 bit, no/even parity. */ 713 + rx_ctrl.dma_err = regk_ser_stop; 714 + rx_ctrl.sampling = regk_ser_majority; 715 + rx_ctrl.timeout = 1; 716 + 717 + rx_ctrl.rts_n = regk_ser_inactive; 718 + 719 + /* Common for tx and rx: 8N1. */ 720 + tx_ctrl.data_bits = regk_ser_bits8; 721 + rx_ctrl.data_bits = regk_ser_bits8; 722 + tx_ctrl.par = regk_ser_even; 723 + rx_ctrl.par = regk_ser_even; 724 + tx_ctrl.par_en = regk_ser_no; 725 + rx_ctrl.par_en = regk_ser_no; 726 + 727 + tx_ctrl.stop_bits = regk_ser_bits1; 728 + 729 + /* 730 + * Change baud-rate and write it to the hardware. 731 + * 732 + * baud_clock = base_freq / (divisor*8) 733 + * divisor = base_freq / (baud_clock * 8) 734 + * base_freq is either: 735 + * off, ext, 29.493MHz, 32.000 MHz, 32.768 MHz or 100 MHz 736 + * 20.493MHz is used for standard baudrates 737 + */ 738 + 739 + /* 740 + * For the console port we keep the original baudrate here. Not very 741 + * beautiful. 742 + */ 743 + if ((port != console_port) || old) 744 + baud = uart_get_baud_rate(port, termios, old, 0, 745 + port->uartclk / 8); 746 + else 747 + baud = console_baud; 748 + 749 + tx_baud_div.div = 29493000 / (8 * baud); 750 + /* Rx uses same as tx. */ 751 + rx_baud_div.div = tx_baud_div.div; 752 + rx_ctrl.base_freq = tx_ctrl.base_freq; 753 + 754 + if ((termios->c_cflag & CSIZE) == CS7) { 755 + /* Set 7 bit mode. */ 756 + tx_ctrl.data_bits = regk_ser_bits7; 757 + rx_ctrl.data_bits = regk_ser_bits7; 758 + } 759 + 760 + if (termios->c_cflag & CSTOPB) { 761 + /* Set 2 stop bit mode. */ 762 + tx_ctrl.stop_bits = regk_ser_bits2; 763 + } 764 + 765 + if (termios->c_cflag & PARENB) { 766 + /* Enable parity. */ 767 + tx_ctrl.par_en = regk_ser_yes; 768 + rx_ctrl.par_en = regk_ser_yes; 769 + } 770 + 771 + if (termios->c_cflag & CMSPAR) { 772 + if (termios->c_cflag & PARODD) { 773 + /* Set mark parity if PARODD and CMSPAR. */ 774 + tx_ctrl.par = regk_ser_mark; 775 + rx_ctrl.par = regk_ser_mark; 776 + } else { 777 + tx_ctrl.par = regk_ser_space; 778 + rx_ctrl.par = regk_ser_space; 779 + } 780 + } else { 781 + if (termios->c_cflag & PARODD) { 782 + /* Set odd parity. */ 783 + tx_ctrl.par = regk_ser_odd; 784 + rx_ctrl.par = regk_ser_odd; 785 + } 786 + } 787 + 788 + if (termios->c_cflag & CRTSCTS) { 789 + /* Enable automatic CTS handling. */ 790 + tx_ctrl.auto_cts = regk_ser_yes; 791 + } 792 + 793 + /* Make sure the tx and rx are enabled. */ 794 + tx_ctrl.en = regk_ser_yes; 795 + rx_ctrl.en = regk_ser_yes; 796 + 797 + spin_lock_irqsave(&port->lock, flags); 798 + 799 + tx_dma_en.en = 0; 800 + REG_WR(ser, up->regi_ser, rw_tr_dma_en, tx_dma_en); 801 + 802 + /* Actually write the control regs (if modified) to the hardware. */ 803 + uart_update_timeout(port, termios->c_cflag, port->uartclk/8); 804 + MODIFY_REG(up->regi_ser, rw_rec_baud_div, rx_baud_div); 805 + MODIFY_REG(up->regi_ser, rw_rec_ctrl, rx_ctrl); 806 + 807 + MODIFY_REG(up->regi_ser, rw_tr_baud_div, tx_baud_div); 808 + MODIFY_REG(up->regi_ser, rw_tr_ctrl, tx_ctrl); 809 + 810 + tx_dma_en.en = 0; 811 + REG_WR(ser, up->regi_ser, rw_tr_dma_en, tx_dma_en); 812 + 813 + xoff = REG_RD(ser, up->regi_ser, rw_xoff); 814 + 815 + if (up->port.state && up->port.state->port.tty && 816 + (up->port.state->port.tty->termios.c_iflag & IXON)) { 817 + xoff.chr = STOP_CHAR(up->port.state->port.tty); 818 + xoff.automatic = regk_ser_yes; 819 + } else 820 + xoff.automatic = regk_ser_no; 821 + 822 + MODIFY_REG(up->regi_ser, rw_xoff, xoff); 823 + 824 + /* 825 + * Make sure we don't start in an automatically shut-off state due to 826 + * a previous early exit. 827 + */ 828 + xoff_clr.clr = 1; 829 + REG_WR(ser, up->regi_ser, rw_xoff_clr, xoff_clr); 830 + 831 + etraxfs_uart_set_mctrl(&up->port, up->port.mctrl); 832 + spin_unlock_irqrestore(&up->port.lock, flags); 833 + } 834 + 835 + static const char * 836 + etraxfs_uart_type(struct uart_port *port) 837 + { 838 + return "CRISv32"; 839 + } 840 + 841 + static void etraxfs_uart_release_port(struct uart_port *port) 842 + { 843 + } 844 + 845 + static int etraxfs_uart_request_port(struct uart_port *port) 846 + { 847 + return 0; 848 + } 849 + 850 + static void etraxfs_uart_config_port(struct uart_port *port, int flags) 851 + { 852 + struct uart_cris_port *up = (struct uart_cris_port *)port; 853 + 854 + up->port.type = PORT_CRIS; 855 + } 856 + 857 + static const struct uart_ops etraxfs_uart_pops = { 858 + .tx_empty = etraxfs_uart_tx_empty, 859 + .set_mctrl = etraxfs_uart_set_mctrl, 860 + .get_mctrl = etraxfs_uart_get_mctrl, 861 + .stop_tx = etraxfs_uart_stop_tx, 862 + .start_tx = etraxfs_uart_start_tx, 863 + .send_xchar = etraxfs_uart_send_xchar, 864 + .stop_rx = etraxfs_uart_stop_rx, 865 + .enable_ms = etraxfs_uart_enable_ms, 866 + .break_ctl = etraxfs_uart_break_ctl, 867 + .startup = etraxfs_uart_startup, 868 + .shutdown = etraxfs_uart_shutdown, 869 + .set_termios = etraxfs_uart_set_termios, 870 + .type = etraxfs_uart_type, 871 + .release_port = etraxfs_uart_release_port, 872 + .request_port = etraxfs_uart_request_port, 873 + .config_port = etraxfs_uart_config_port, 874 + #ifdef CONFIG_CONSOLE_POLL 875 + .poll_get_char = etraxfs_uart_get_poll_char, 876 + .poll_put_char = etraxfs_uart_put_poll_char, 877 + #endif 878 + }; 879 + 880 + static void cris_serial_port_init(struct uart_port *port, int line) 881 + { 882 + struct uart_cris_port *up = (struct uart_cris_port *)port; 883 + 884 + if (up->initialized) 885 + return; 886 + up->initialized = 1; 887 + port->line = line; 888 + spin_lock_init(&port->lock); 889 + port->ops = &etraxfs_uart_pops; 890 + port->irq = up->irq; 891 + port->iobase = (unsigned long) up->regi_ser; 892 + port->uartclk = 29493000; 893 + 894 + /* 895 + * We can't fit any more than 255 here (unsigned char), though 896 + * actually UART_XMIT_SIZE characters could be pending output. 897 + * At time of this writing, the definition of "fifosize" is here the 898 + * amount of characters that can be pending output after a start_tx call 899 + * until tx_empty returns 1: see serial_core.c:uart_wait_until_sent. 900 + * This matters for timeout calculations unfortunately, but keeping 901 + * larger amounts at the DMA wouldn't win much so let's just play nice. 902 + */ 903 + port->fifosize = 255; 904 + port->flags = UPF_BOOT_AUTOCONF; 905 + } 906 + 907 + static int etraxfs_uart_probe(struct platform_device *pdev) 908 + { 909 + struct device_node *np = pdev->dev.of_node; 910 + struct uart_cris_port *up; 911 + int dev_id; 912 + 913 + if (!np) 914 + return -ENODEV; 915 + 916 + dev_id = of_alias_get_id(np, "serial"); 917 + if (dev_id < 0) 918 + dev_id = 0; 919 + 920 + if (dev_id >= UART_NR) 921 + return -EINVAL; 922 + 923 + if (etraxfs_uart_ports[dev_id]) 924 + return -EBUSY; 925 + 926 + up = devm_kzalloc(&pdev->dev, sizeof(struct uart_cris_port), 927 + GFP_KERNEL); 928 + if (!up) 929 + return -ENOMEM; 930 + 931 + up->irq = irq_of_parse_and_map(np, 0); 932 + up->regi_ser = of_iomap(np, 0); 933 + up->dtr_pin = devm_gpiod_get_optional(&pdev->dev, "dtr"); 934 + up->dsr_pin = devm_gpiod_get_optional(&pdev->dev, "dsr"); 935 + up->ri_pin = devm_gpiod_get_optional(&pdev->dev, "ri"); 936 + up->cd_pin = devm_gpiod_get_optional(&pdev->dev, "cd"); 937 + up->port.dev = &pdev->dev; 938 + cris_serial_port_init(&up->port, dev_id); 939 + 940 + etraxfs_uart_ports[dev_id] = up; 941 + platform_set_drvdata(pdev, &up->port); 942 + uart_add_one_port(&etraxfs_uart_driver, &up->port); 943 + 944 + return 0; 945 + } 946 + 947 + static int etraxfs_uart_remove(struct platform_device *pdev) 948 + { 949 + struct uart_port *port; 950 + 951 + port = platform_get_drvdata(pdev); 952 + uart_remove_one_port(&etraxfs_uart_driver, port); 953 + etraxfs_uart_ports[pdev->id] = NULL; 954 + 955 + return 0; 956 + } 957 + 958 + static const struct of_device_id etraxfs_uart_dt_ids[] = { 959 + { .compatible = "axis,etraxfs-uart" }, 960 + { /* sentinel */ } 961 + }; 962 + 963 + MODULE_DEVICE_TABLE(of, etraxfs_uart_dt_ids); 964 + 965 + static struct platform_driver etraxfs_uart_platform_driver = { 966 + .driver = { 967 + .name = DRV_NAME, 968 + .of_match_table = of_match_ptr(etraxfs_uart_dt_ids), 969 + }, 970 + .probe = etraxfs_uart_probe, 971 + .remove = etraxfs_uart_remove, 972 + }; 973 + 974 + static int __init etraxfs_uart_init(void) 975 + { 976 + int ret; 977 + 978 + ret = uart_register_driver(&etraxfs_uart_driver); 979 + if (ret) 980 + return ret; 981 + 982 + ret = platform_driver_register(&etraxfs_uart_platform_driver); 983 + if (ret) 984 + uart_unregister_driver(&etraxfs_uart_driver); 985 + 986 + return ret; 987 + } 988 + 989 + static void __exit etraxfs_uart_exit(void) 990 + { 991 + platform_driver_unregister(&etraxfs_uart_platform_driver); 992 + uart_unregister_driver(&etraxfs_uart_driver); 993 + } 994 + 995 + module_init(etraxfs_uart_init); 996 + module_exit(etraxfs_uart_exit);
+77 -58
drivers/tty/serial/fsl_lpuart.c
··· 237 237 unsigned int rxfifo_size; 238 238 bool lpuart32; 239 239 240 - bool lpuart_dma_use; 240 + bool lpuart_dma_tx_use; 241 + bool lpuart_dma_rx_use; 241 242 struct dma_chan *dma_tx_chan; 242 243 struct dma_chan *dma_rx_chan; 243 244 struct dma_async_tx_descriptor *dma_tx_desc; ··· 455 454 return 0; 456 455 } 457 456 457 + static void lpuart_flush_buffer(struct uart_port *port) 458 + { 459 + struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 460 + if (sport->lpuart_dma_tx_use) { 461 + dmaengine_terminate_all(sport->dma_tx_chan); 462 + sport->dma_tx_in_progress = 0; 463 + } 464 + } 465 + 458 466 static void lpuart_dma_rx_complete(void *arg) 459 467 { 460 468 struct lpuart_port *sport = arg; ··· 471 461 unsigned long flags; 472 462 473 463 async_tx_ack(sport->dma_rx_desc); 464 + mod_timer(&sport->lpuart_timer, jiffies + sport->dma_rx_timeout); 474 465 475 466 spin_lock_irqsave(&sport->port.lock, flags); 476 467 ··· 517 506 518 507 spin_lock_irqsave(&sport->port.lock, flags); 519 508 520 - init_timer(&sport->lpuart_timer); 521 - sport->lpuart_timer.function = lpuart_timer_func; 522 - sport->lpuart_timer.data = (unsigned long)sport; 523 509 sport->lpuart_timer.expires = jiffies + sport->dma_rx_timeout; 524 510 add_timer(&sport->lpuart_timer); 525 511 ··· 579 571 temp = readb(port->membase + UARTCR2); 580 572 writeb(temp | UARTCR2_TIE, port->membase + UARTCR2); 581 573 582 - if (sport->lpuart_dma_use) { 574 + if (sport->lpuart_dma_tx_use) { 583 575 if (!uart_circ_empty(xmit) && !sport->dma_tx_in_progress) 584 576 lpuart_prepare_tx(sport); 585 577 } else { ··· 766 758 static irqreturn_t lpuart_int(int irq, void *dev_id) 767 759 { 768 760 struct lpuart_port *sport = dev_id; 769 - unsigned char sts; 761 + unsigned char sts, crdma; 770 762 771 763 sts = readb(sport->port.membase + UARTSR1); 764 + crdma = readb(sport->port.membase + UARTCR5); 772 765 773 - if (sts & UARTSR1_RDRF) { 774 - if (sport->lpuart_dma_use) 766 + if (sts & UARTSR1_RDRF && !(crdma & UARTCR5_RDMAS)) { 767 + if (sport->lpuart_dma_rx_use) 775 768 lpuart_prepare_rx(sport); 776 769 else 777 770 lpuart_rxint(irq, dev_id); 778 771 } 779 - if (sts & UARTSR1_TDRE && 780 - !(readb(sport->port.membase + UARTCR5) & UARTCR5_TDMAS)) { 781 - if (sport->lpuart_dma_use) 772 + if (sts & UARTSR1_TDRE && !(crdma & UARTCR5_TDMAS)) { 773 + if (sport->lpuart_dma_tx_use) 782 774 lpuart_pio_tx(sport); 783 775 else 784 776 lpuart_txint(irq, dev_id); ··· 961 953 { 962 954 struct lpuart_port *sport = container_of(port, 963 955 struct lpuart_port, port); 964 - struct dma_chan *tx_chan; 965 956 struct dma_slave_config dma_tx_sconfig; 966 957 dma_addr_t dma_bus; 967 958 unsigned char *dma_buf; 968 959 int ret; 969 960 970 - tx_chan = dma_request_slave_channel(sport->port.dev, "tx"); 971 - 972 - if (!tx_chan) { 973 - dev_err(sport->port.dev, "Dma tx channel request failed!\n"); 974 - return -ENODEV; 975 - } 976 - 977 - dma_bus = dma_map_single(tx_chan->device->dev, 961 + dma_bus = dma_map_single(sport->dma_tx_chan->device->dev, 978 962 sport->port.state->xmit.buf, 979 963 UART_XMIT_SIZE, DMA_TO_DEVICE); 980 964 981 - if (dma_mapping_error(tx_chan->device->dev, dma_bus)) { 965 + if (dma_mapping_error(sport->dma_tx_chan->device->dev, dma_bus)) { 982 966 dev_err(sport->port.dev, "dma_map_single tx failed\n"); 983 - dma_release_channel(tx_chan); 984 967 return -ENOMEM; 985 968 } 986 969 ··· 980 981 dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 981 982 dma_tx_sconfig.dst_maxburst = sport->txfifo_size; 982 983 dma_tx_sconfig.direction = DMA_MEM_TO_DEV; 983 - ret = dmaengine_slave_config(tx_chan, &dma_tx_sconfig); 984 + ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig); 984 985 985 986 if (ret < 0) { 986 987 dev_err(sport->port.dev, 987 988 "Dma slave config failed, err = %d\n", ret); 988 - dma_release_channel(tx_chan); 989 989 return ret; 990 990 } 991 991 992 - sport->dma_tx_chan = tx_chan; 993 992 sport->dma_tx_buf_virt = dma_buf; 994 993 sport->dma_tx_buf_bus = dma_bus; 995 994 sport->dma_tx_in_progress = 0; ··· 999 1002 { 1000 1003 struct lpuart_port *sport = container_of(port, 1001 1004 struct lpuart_port, port); 1002 - struct dma_chan *rx_chan; 1003 1005 struct dma_slave_config dma_rx_sconfig; 1004 1006 dma_addr_t dma_bus; 1005 1007 unsigned char *dma_buf; 1006 1008 int ret; 1007 - 1008 - rx_chan = dma_request_slave_channel(sport->port.dev, "rx"); 1009 - 1010 - if (!rx_chan) { 1011 - dev_err(sport->port.dev, "Dma rx channel request failed!\n"); 1012 - return -ENODEV; 1013 - } 1014 1009 1015 1010 dma_buf = devm_kzalloc(sport->port.dev, 1016 1011 FSL_UART_RX_DMA_BUFFER_SIZE, GFP_KERNEL); 1017 1012 1018 1013 if (!dma_buf) { 1019 1014 dev_err(sport->port.dev, "Dma rx alloc failed\n"); 1020 - dma_release_channel(rx_chan); 1021 1015 return -ENOMEM; 1022 1016 } 1023 1017 1024 - dma_bus = dma_map_single(rx_chan->device->dev, dma_buf, 1018 + dma_bus = dma_map_single(sport->dma_rx_chan->device->dev, dma_buf, 1025 1019 FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE); 1026 1020 1027 - if (dma_mapping_error(rx_chan->device->dev, dma_bus)) { 1021 + if (dma_mapping_error(sport->dma_rx_chan->device->dev, dma_bus)) { 1028 1022 dev_err(sport->port.dev, "dma_map_single rx failed\n"); 1029 - dma_release_channel(rx_chan); 1030 1023 return -ENOMEM; 1031 1024 } 1032 1025 ··· 1024 1037 dma_rx_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 1025 1038 dma_rx_sconfig.src_maxburst = 1; 1026 1039 dma_rx_sconfig.direction = DMA_DEV_TO_MEM; 1027 - ret = dmaengine_slave_config(rx_chan, &dma_rx_sconfig); 1040 + ret = dmaengine_slave_config(sport->dma_rx_chan, &dma_rx_sconfig); 1028 1041 1029 1042 if (ret < 0) { 1030 1043 dev_err(sport->port.dev, 1031 1044 "Dma slave config failed, err = %d\n", ret); 1032 - dma_release_channel(rx_chan); 1033 1045 return ret; 1034 1046 } 1035 1047 1036 - sport->dma_rx_chan = rx_chan; 1037 1048 sport->dma_rx_buf_virt = dma_buf; 1038 1049 sport->dma_rx_buf_bus = dma_bus; 1039 1050 sport->dma_rx_in_progress = 0; ··· 1043 1058 { 1044 1059 struct lpuart_port *sport = container_of(port, 1045 1060 struct lpuart_port, port); 1046 - struct dma_chan *dma_chan; 1047 1061 1048 1062 dma_unmap_single(sport->port.dev, sport->dma_tx_buf_bus, 1049 1063 UART_XMIT_SIZE, DMA_TO_DEVICE); 1050 - dma_chan = sport->dma_tx_chan; 1051 - sport->dma_tx_chan = NULL; 1064 + 1052 1065 sport->dma_tx_buf_bus = 0; 1053 1066 sport->dma_tx_buf_virt = NULL; 1054 - dma_release_channel(dma_chan); 1055 1067 } 1056 1068 1057 1069 static void lpuart_dma_rx_free(struct uart_port *port) 1058 1070 { 1059 1071 struct lpuart_port *sport = container_of(port, 1060 1072 struct lpuart_port, port); 1061 - struct dma_chan *dma_chan; 1062 1073 1063 1074 dma_unmap_single(sport->port.dev, sport->dma_rx_buf_bus, 1064 1075 FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE); 1065 1076 1066 - dma_chan = sport->dma_rx_chan; 1067 - sport->dma_rx_chan = NULL; 1068 1077 sport->dma_rx_buf_bus = 0; 1069 1078 sport->dma_rx_buf_virt = NULL; 1070 - dma_release_channel(dma_chan); 1071 1079 } 1072 1080 1073 1081 static int lpuart_startup(struct uart_port *port) ··· 1079 1101 sport->rxfifo_size = 0x1 << (((temp >> UARTPFIFO_RXSIZE_OFF) & 1080 1102 UARTPFIFO_FIFOSIZE_MASK) + 1); 1081 1103 1082 - /* Whether use dma support by dma request results */ 1083 - if (lpuart_dma_tx_request(port) || lpuart_dma_rx_request(port)) { 1084 - sport->lpuart_dma_use = false; 1085 - } else { 1086 - sport->lpuart_dma_use = true; 1104 + if (sport->dma_rx_chan && !lpuart_dma_rx_request(port)) { 1105 + sport->lpuart_dma_rx_use = true; 1106 + setup_timer(&sport->lpuart_timer, lpuart_timer_func, 1107 + (unsigned long)sport); 1108 + } else 1109 + sport->lpuart_dma_rx_use = false; 1110 + 1111 + 1112 + if (sport->dma_tx_chan && !lpuart_dma_tx_request(port)) { 1113 + sport->lpuart_dma_tx_use = true; 1087 1114 temp = readb(port->membase + UARTCR5); 1115 + temp &= ~UARTCR5_RDMAS; 1088 1116 writeb(temp | UARTCR5_TDMAS, port->membase + UARTCR5); 1089 - } 1117 + } else 1118 + sport->lpuart_dma_tx_use = false; 1090 1119 1091 1120 ret = devm_request_irq(port->dev, port->irq, lpuart_int, 0, 1092 1121 DRIVER_NAME, sport); ··· 1164 1179 1165 1180 devm_free_irq(port->dev, port->irq, sport); 1166 1181 1167 - if (sport->lpuart_dma_use) { 1168 - lpuart_dma_tx_free(port); 1169 - lpuart_dma_rx_free(port); 1182 + if (sport->lpuart_dma_rx_use) { 1183 + lpuart_dma_rx_free(&sport->port); 1184 + del_timer_sync(&sport->lpuart_timer); 1170 1185 } 1186 + 1187 + if (sport->lpuart_dma_tx_use) 1188 + lpuart_dma_tx_free(&sport->port); 1171 1189 } 1172 1190 1173 1191 static void lpuart32_shutdown(struct uart_port *port) ··· 1292 1304 /* update the per-port timeout */ 1293 1305 uart_update_timeout(port, termios->c_cflag, baud); 1294 1306 1295 - if (sport->lpuart_dma_use) { 1307 + if (sport->lpuart_dma_rx_use) { 1296 1308 /* Calculate delay for 1.5 DMA buffers */ 1297 1309 sport->dma_rx_timeout = (sport->port.timeout - HZ / 50) * 1298 1310 FSL_UART_RX_DMA_BUFFER_SIZE * 3 / ··· 1505 1517 .release_port = lpuart_release_port, 1506 1518 .config_port = lpuart_config_port, 1507 1519 .verify_port = lpuart_verify_port, 1520 + .flush_buffer = lpuart_flush_buffer, 1508 1521 }; 1509 1522 1510 1523 static struct uart_ops lpuart32_pops = { ··· 1524 1535 .release_port = lpuart_release_port, 1525 1536 .config_port = lpuart_config_port, 1526 1537 .verify_port = lpuart_verify_port, 1538 + .flush_buffer = lpuart_flush_buffer, 1527 1539 }; 1528 1540 1529 1541 static struct lpuart_port *lpuart_ports[UART_NR]; ··· 1823 1833 return ret; 1824 1834 } 1825 1835 1836 + sport->dma_tx_chan = dma_request_slave_channel(sport->port.dev, "tx"); 1837 + if (!sport->dma_tx_chan) 1838 + dev_info(sport->port.dev, "DMA tx channel request failed, " 1839 + "operating without tx DMA\n"); 1840 + 1841 + sport->dma_rx_chan = dma_request_slave_channel(sport->port.dev, "rx"); 1842 + if (!sport->dma_rx_chan) 1843 + dev_info(sport->port.dev, "DMA rx channel request failed, " 1844 + "operating without rx DMA\n"); 1845 + 1826 1846 return 0; 1827 1847 } 1828 1848 ··· 1844 1844 1845 1845 clk_disable_unprepare(sport->clk); 1846 1846 1847 + if (sport->dma_tx_chan) 1848 + dma_release_channel(sport->dma_tx_chan); 1849 + 1850 + if (sport->dma_rx_chan) 1851 + dma_release_channel(sport->dma_rx_chan); 1852 + 1847 1853 return 0; 1848 1854 } 1849 1855 ··· 1857 1851 static int lpuart_suspend(struct device *dev) 1858 1852 { 1859 1853 struct lpuart_port *sport = dev_get_drvdata(dev); 1854 + unsigned long temp; 1855 + 1856 + if (sport->lpuart32) { 1857 + /* disable Rx/Tx and interrupts */ 1858 + temp = lpuart32_read(sport->port.membase + UARTCTRL); 1859 + temp &= ~(UARTCTRL_TE | UARTCTRL_TIE | UARTCTRL_TCIE); 1860 + lpuart32_write(temp, sport->port.membase + UARTCTRL); 1861 + } else { 1862 + /* disable Rx/Tx and interrupts */ 1863 + temp = readb(sport->port.membase + UARTCR2); 1864 + temp &= ~(UARTCR2_TE | UARTCR2_TIE | UARTCR2_TCIE); 1865 + writeb(temp, sport->port.membase + UARTCR2); 1866 + } 1860 1867 1861 1868 uart_suspend_port(&lpuart_reg, &sport->port); 1862 1869
+154 -36
drivers/tty/serial/imx.c
··· 74 74 #define IMX21_UTS 0xb4 /* UART Test Register on all other i.mx*/ 75 75 76 76 /* UART Control Register Bit Fields.*/ 77 + #define URXD_DUMMY_READ (1<<16) 77 78 #define URXD_CHARRDY (1<<15) 78 79 #define URXD_ERR (1<<14) 79 80 #define URXD_OVRRUN (1<<13) ··· 464 463 mod_timer(&sport->timer, jiffies); 465 464 } 466 465 466 + static void imx_dma_tx(struct imx_port *sport); 467 467 static inline void imx_transmit_buffer(struct imx_port *sport) 468 468 { 469 469 struct circ_buf *xmit = &sport->port.state->xmit; 470 + unsigned long temp; 470 471 471 472 if (sport->port.x_char) { 472 473 /* Send next char */ 473 474 writel(sport->port.x_char, sport->port.membase + URTX0); 475 + sport->port.icount.tx++; 476 + sport->port.x_char = 0; 474 477 return; 475 478 } 476 479 477 480 if (uart_circ_empty(xmit) || uart_tx_stopped(&sport->port)) { 478 481 imx_stop_tx(&sport->port); 479 482 return; 483 + } 484 + 485 + if (sport->dma_is_enabled) { 486 + /* 487 + * We've just sent a X-char Ensure the TX DMA is enabled 488 + * and the TX IRQ is disabled. 489 + **/ 490 + temp = readl(sport->port.membase + UCR1); 491 + temp &= ~UCR1_TXMPTYEN; 492 + if (sport->dma_is_txing) { 493 + temp |= UCR1_TDMAEN; 494 + writel(temp, sport->port.membase + UCR1); 495 + } else { 496 + writel(temp, sport->port.membase + UCR1); 497 + imx_dma_tx(sport); 498 + } 480 499 } 481 500 482 501 while (!uart_circ_empty(xmit) && ··· 521 500 struct scatterlist *sgl = &sport->tx_sgl[0]; 522 501 struct circ_buf *xmit = &sport->port.state->xmit; 523 502 unsigned long flags; 503 + unsigned long temp; 504 + 505 + spin_lock_irqsave(&sport->port.lock, flags); 524 506 525 507 dma_unmap_sg(sport->port.dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE); 526 508 527 - sport->dma_is_txing = 0; 509 + temp = readl(sport->port.membase + UCR1); 510 + temp &= ~UCR1_TDMAEN; 511 + writel(temp, sport->port.membase + UCR1); 528 512 529 513 /* update the stat */ 530 - spin_lock_irqsave(&sport->port.lock, flags); 531 514 xmit->tail = (xmit->tail + sport->tx_bytes) & (UART_XMIT_SIZE - 1); 532 515 sport->port.icount.tx += sport->tx_bytes; 533 - spin_unlock_irqrestore(&sport->port.lock, flags); 534 516 535 517 dev_dbg(sport->port.dev, "we finish the TX DMA.\n"); 536 518 537 - uart_write_wakeup(&sport->port); 519 + sport->dma_is_txing = 0; 520 + 521 + spin_unlock_irqrestore(&sport->port.lock, flags); 522 + 523 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 524 + uart_write_wakeup(&sport->port); 538 525 539 526 if (waitqueue_active(&sport->dma_wait)) { 540 527 wake_up(&sport->dma_wait); 541 528 dev_dbg(sport->port.dev, "exit in %s.\n", __func__); 542 529 return; 543 530 } 531 + 532 + spin_lock_irqsave(&sport->port.lock, flags); 533 + if (!uart_circ_empty(xmit) && !uart_tx_stopped(&sport->port)) 534 + imx_dma_tx(sport); 535 + spin_unlock_irqrestore(&sport->port.lock, flags); 544 536 } 545 537 546 538 static void imx_dma_tx(struct imx_port *sport) ··· 563 529 struct dma_async_tx_descriptor *desc; 564 530 struct dma_chan *chan = sport->dma_chan_tx; 565 531 struct device *dev = sport->port.dev; 566 - enum dma_status status; 532 + unsigned long temp; 567 533 int ret; 568 534 569 - status = dmaengine_tx_status(chan, (dma_cookie_t)0, NULL); 570 - if (DMA_IN_PROGRESS == status) 535 + if (sport->dma_is_txing) 571 536 return; 572 537 573 538 sport->tx_bytes = uart_circ_chars_pending(xmit); 574 539 575 - if (xmit->tail > xmit->head && xmit->head > 0) { 540 + if (xmit->tail < xmit->head) { 541 + sport->dma_tx_nents = 1; 542 + sg_init_one(sgl, xmit->buf + xmit->tail, sport->tx_bytes); 543 + } else { 576 544 sport->dma_tx_nents = 2; 577 545 sg_init_table(sgl, 2); 578 546 sg_set_buf(sgl, xmit->buf + xmit->tail, 579 547 UART_XMIT_SIZE - xmit->tail); 580 548 sg_set_buf(sgl + 1, xmit->buf, xmit->head); 581 - } else { 582 - sport->dma_tx_nents = 1; 583 - sg_init_one(sgl, xmit->buf + xmit->tail, sport->tx_bytes); 584 549 } 585 550 586 551 ret = dma_map_sg(dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE); ··· 590 557 desc = dmaengine_prep_slave_sg(chan, sgl, sport->dma_tx_nents, 591 558 DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT); 592 559 if (!desc) { 560 + dma_unmap_sg(dev, sgl, sport->dma_tx_nents, 561 + DMA_TO_DEVICE); 593 562 dev_err(dev, "We cannot prepare for the TX slave dma!\n"); 594 563 return; 595 564 } ··· 600 565 601 566 dev_dbg(dev, "TX: prepare to send %lu bytes by DMA.\n", 602 567 uart_circ_chars_pending(xmit)); 568 + 569 + temp = readl(sport->port.membase + UCR1); 570 + temp |= UCR1_TDMAEN; 571 + writel(temp, sport->port.membase + UCR1); 572 + 603 573 /* fire it */ 604 574 sport->dma_is_txing = 1; 605 575 dmaengine_submit(desc); ··· 630 590 temp &= ~(UCR1_RRDYEN); 631 591 writel(temp, sport->port.membase + UCR1); 632 592 } 633 - /* Clear any pending ORE flag before enabling interrupt */ 634 - temp = readl(sport->port.membase + USR2); 635 - writel(temp | USR2_ORE, sport->port.membase + USR2); 636 - 637 - temp = readl(sport->port.membase + UCR4); 638 - temp |= UCR4_OREN; 639 - writel(temp, sport->port.membase + UCR4); 640 593 641 594 if (!sport->dma_is_enabled) { 642 595 temp = readl(sport->port.membase + UCR1); ··· 647 614 } 648 615 649 616 if (sport->dma_is_enabled) { 650 - /* FIXME: port->x_char must be transmitted if != 0 */ 617 + if (sport->port.x_char) { 618 + /* We have X-char to send, so enable TX IRQ and 619 + * disable TX DMA to let TX interrupt to send X-char */ 620 + temp = readl(sport->port.membase + UCR1); 621 + temp &= ~UCR1_TDMAEN; 622 + temp |= UCR1_TXMPTYEN; 623 + writel(temp, sport->port.membase + UCR1); 624 + return; 625 + } 626 + 651 627 if (!uart_circ_empty(&port->state->xmit) && 652 628 !uart_tx_stopped(port)) 653 629 imx_dma_tx(sport); 654 630 return; 655 631 } 656 - 657 - if (readl(sport->port.membase + uts_reg(sport)) & UTS_TXEMPTY) 658 - imx_transmit_buffer(sport); 659 632 } 660 633 661 634 static irqreturn_t imx_rtsint(int irq, void *dev_id) ··· 733 694 continue; 734 695 } 735 696 736 - rx &= sport->port.read_status_mask; 697 + rx &= (sport->port.read_status_mask | 0xFF); 737 698 738 699 if (rx & URXD_BRK) 739 700 flg = TTY_BREAK; ··· 748 709 sport->port.sysrq = 0; 749 710 #endif 750 711 } 712 + 713 + if (sport->port.ignore_status_mask & URXD_DUMMY_READ) 714 + goto out; 751 715 752 716 tty_insert_flip_char(port, rx, flg); 753 717 } ··· 769 727 static void imx_dma_rxint(struct imx_port *sport) 770 728 { 771 729 unsigned long temp; 730 + unsigned long flags; 731 + 732 + spin_lock_irqsave(&sport->port.lock, flags); 772 733 773 734 temp = readl(sport->port.membase + USR2); 774 735 if ((temp & USR2_RDR) && !sport->dma_is_rxing) { ··· 785 740 /* tell the DMA to receive the data. */ 786 741 start_rx_dma(sport); 787 742 } 743 + 744 + spin_unlock_irqrestore(&sport->port.lock, flags); 788 745 } 789 746 790 747 static irqreturn_t imx_int(int irq, void *dev_id) ··· 916 869 static void imx_rx_dma_done(struct imx_port *sport) 917 870 { 918 871 unsigned long temp; 872 + unsigned long flags; 873 + 874 + spin_lock_irqsave(&sport->port.lock, flags); 919 875 920 876 /* Enable this interrupt when the RXFIFO is empty. */ 921 877 temp = readl(sport->port.membase + UCR1); ··· 930 880 /* Is the shutdown waiting for us? */ 931 881 if (waitqueue_active(&sport->dma_wait)) 932 882 wake_up(&sport->dma_wait); 883 + 884 + spin_unlock_irqrestore(&sport->port.lock, flags); 933 885 } 934 886 935 887 /* ··· 962 910 dev_dbg(sport->port.dev, "We get %d bytes.\n", count); 963 911 964 912 if (count) { 965 - tty_insert_flip_string(port, sport->rx_buf, count); 913 + if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) 914 + tty_insert_flip_string(port, sport->rx_buf, count); 966 915 tty_flip_buffer_push(port); 967 916 968 917 start_rx_dma(sport); 969 - } else 918 + } else if (readl(sport->port.membase + USR2) & USR2_RDR) { 919 + /* 920 + * start rx_dma directly once data in RXFIFO, more efficient 921 + * than before: 922 + * 1. call imx_rx_dma_done to stop dma if no data received 923 + * 2. wait next RDR interrupt to start dma transfer. 924 + */ 925 + start_rx_dma(sport); 926 + } else { 927 + /* 928 + * stop dma to prevent too many IDLE event trigged if no data 929 + * in RXFIFO 930 + */ 970 931 imx_rx_dma_done(sport); 932 + } 971 933 } 972 934 973 935 static int start_rx_dma(struct imx_port *sport) ··· 1001 935 desc = dmaengine_prep_slave_sg(chan, sgl, 1, DMA_DEV_TO_MEM, 1002 936 DMA_PREP_INTERRUPT); 1003 937 if (!desc) { 938 + dma_unmap_sg(dev, sgl, 1, DMA_FROM_DEVICE); 1004 939 dev_err(dev, "We cannot prepare for the RX slave dma!\n"); 1005 940 return -EINVAL; 1006 941 } ··· 1175 1108 while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) && (--i > 0)) 1176 1109 udelay(1); 1177 1110 1111 + /* Can we enable the DMA support? */ 1112 + if (is_imx6q_uart(sport) && !uart_console(port) && 1113 + !sport->dma_is_inited) 1114 + imx_uart_dma_init(sport); 1115 + 1178 1116 spin_lock_irqsave(&sport->port.lock, flags); 1179 1117 /* 1180 1118 * Finally, clear and enable interrupts 1181 1119 */ 1182 1120 writel(USR1_RTSD, sport->port.membase + USR1); 1121 + 1122 + if (sport->dma_is_inited && !sport->dma_is_enabled) 1123 + imx_enable_dma(sport); 1183 1124 1184 1125 temp = readl(sport->port.membase + UCR1); 1185 1126 temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN; ··· 1198 1123 } 1199 1124 1200 1125 writel(temp, sport->port.membase + UCR1); 1126 + 1127 + /* Clear any pending ORE flag before enabling interrupt */ 1128 + temp = readl(sport->port.membase + USR2); 1129 + writel(temp | USR2_ORE, sport->port.membase + USR2); 1130 + 1131 + temp = readl(sport->port.membase + UCR4); 1132 + temp |= UCR4_OREN; 1133 + writel(temp, sport->port.membase + UCR4); 1201 1134 1202 1135 temp = readl(sport->port.membase + UCR2); 1203 1136 temp |= (UCR2_RXEN | UCR2_TXEN); ··· 1272 1189 dmaengine_terminate_all(sport->dma_chan_tx); 1273 1190 dmaengine_terminate_all(sport->dma_chan_rx); 1274 1191 } 1192 + spin_lock_irqsave(&sport->port.lock, flags); 1275 1193 imx_stop_tx(port); 1276 1194 imx_stop_rx(port); 1277 1195 imx_disable_dma(sport); 1196 + spin_unlock_irqrestore(&sport->port.lock, flags); 1278 1197 imx_uart_dma_exit(sport); 1279 1198 } 1280 1199 ··· 1318 1233 static void imx_flush_buffer(struct uart_port *port) 1319 1234 { 1320 1235 struct imx_port *sport = (struct imx_port *)port; 1236 + struct scatterlist *sgl = &sport->tx_sgl[0]; 1237 + unsigned long temp; 1238 + int i = 100, ubir, ubmr, ubrc, uts; 1321 1239 1322 - if (sport->dma_is_enabled) { 1323 - sport->tx_bytes = 0; 1324 - dmaengine_terminate_all(sport->dma_chan_tx); 1240 + if (!sport->dma_chan_tx) 1241 + return; 1242 + 1243 + sport->tx_bytes = 0; 1244 + dmaengine_terminate_all(sport->dma_chan_tx); 1245 + if (sport->dma_is_txing) { 1246 + dma_unmap_sg(sport->port.dev, sgl, sport->dma_tx_nents, 1247 + DMA_TO_DEVICE); 1248 + temp = readl(sport->port.membase + UCR1); 1249 + temp &= ~UCR1_TDMAEN; 1250 + writel(temp, sport->port.membase + UCR1); 1251 + sport->dma_is_txing = false; 1325 1252 } 1253 + 1254 + /* 1255 + * According to the Reference Manual description of the UART SRST bit: 1256 + * "Reset the transmit and receive state machines, 1257 + * all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD 1258 + * and UTS[6-3]". As we don't need to restore the old values from 1259 + * USR1, USR2, URXD, UTXD, only save/restore the other four registers 1260 + */ 1261 + ubir = readl(sport->port.membase + UBIR); 1262 + ubmr = readl(sport->port.membase + UBMR); 1263 + ubrc = readl(sport->port.membase + UBRC); 1264 + uts = readl(sport->port.membase + IMX21_UTS); 1265 + 1266 + temp = readl(sport->port.membase + UCR2); 1267 + temp &= ~UCR2_SRST; 1268 + writel(temp, sport->port.membase + UCR2); 1269 + 1270 + while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) && (--i > 0)) 1271 + udelay(1); 1272 + 1273 + /* Restore the registers */ 1274 + writel(ubir, sport->port.membase + UBIR); 1275 + writel(ubmr, sport->port.membase + UBMR); 1276 + writel(ubrc, sport->port.membase + UBRC); 1277 + writel(uts, sport->port.membase + IMX21_UTS); 1326 1278 } 1327 1279 1328 1280 static void ··· 1402 1280 if (sport->have_rtscts) { 1403 1281 ucr2 &= ~UCR2_IRTS; 1404 1282 ucr2 |= UCR2_CTSC; 1405 - 1406 - /* Can we enable the DMA support? */ 1407 - if (is_imx6q_uart(sport) && !uart_console(port) 1408 - && !sport->dma_is_inited) 1409 - imx_uart_dma_init(sport); 1410 1283 } else { 1411 1284 termios->c_cflag &= ~CRTSCTS; 1412 1285 } ··· 1436 1319 */ 1437 1320 sport->port.ignore_status_mask = 0; 1438 1321 if (termios->c_iflag & IGNPAR) 1439 - sport->port.ignore_status_mask |= URXD_PRERR; 1322 + sport->port.ignore_status_mask |= URXD_PRERR | URXD_FRMERR; 1440 1323 if (termios->c_iflag & IGNBRK) { 1441 1324 sport->port.ignore_status_mask |= URXD_BRK; 1442 1325 /* ··· 1446 1329 if (termios->c_iflag & IGNPAR) 1447 1330 sport->port.ignore_status_mask |= URXD_OVRRUN; 1448 1331 } 1332 + 1333 + if ((termios->c_cflag & CREAD) == 0) 1334 + sport->port.ignore_status_mask |= URXD_DUMMY_READ; 1449 1335 1450 1336 /* 1451 1337 * Update the per-port timeout. ··· 1523 1403 if (UART_ENABLE_MS(&sport->port, termios->c_cflag)) 1524 1404 imx_enable_ms(&sport->port); 1525 1405 1526 - if (sport->dma_is_inited && !sport->dma_is_enabled) 1527 - imx_enable_dma(sport); 1528 1406 spin_unlock_irqrestore(&sport->port.lock, flags); 1529 1407 } 1530 1408
+3 -4
drivers/tty/serial/mcf.c
··· 3 3 /* 4 4 * mcf.c -- Freescale ColdFire UART driver 5 5 * 6 - * (C) Copyright 2003-2007, Greg Ungerer <gerg@snapgear.com> 6 + * (C) Copyright 2003-2007, Greg Ungerer <gerg@uclinux.org> 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify 9 9 * it under the terms of the GNU General Public License as published by ··· 198 198 static void mcf_set_termios(struct uart_port *port, struct ktermios *termios, 199 199 struct ktermios *old) 200 200 { 201 - struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 202 201 unsigned long flags; 203 202 unsigned int baud, baudclk; 204 203 #if defined(CONFIG_M5272) ··· 440 441 /* Enable or disable the RS485 support */ 441 442 static int mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485) 442 443 { 443 - struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 444 444 unsigned char mr1, mr2; 445 445 446 446 /* Get mode registers */ ··· 629 631 port->mapbase = platp[i].mapbase; 630 632 port->membase = (platp[i].membase) ? platp[i].membase : 631 633 (unsigned char __iomem *) platp[i].mapbase; 634 + port->dev = &pdev->dev; 632 635 port->iotype = SERIAL_IO_MEM; 633 636 port->irq = platp[i].irq; 634 637 port->uartclk = MCF_BUSCLK; ··· 701 702 module_init(mcf_init); 702 703 module_exit(mcf_exit); 703 704 704 - MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>"); 705 + MODULE_AUTHOR("Greg Ungerer <gerg@uclinux.org>"); 705 706 MODULE_DESCRIPTION("Freescale ColdFire UART driver"); 706 707 MODULE_LICENSE("GPL"); 707 708 MODULE_ALIAS("platform:mcfuart");
+109 -46
drivers/tty/serial/men_z135_uart.c
··· 23 23 #define MEN_Z135_MAX_PORTS 12 24 24 #define MEN_Z135_BASECLK 29491200 25 25 #define MEN_Z135_FIFO_SIZE 1024 26 - #define MEN_Z135_NUM_MSI_VECTORS 2 27 26 #define MEN_Z135_FIFO_WATERMARK 1020 28 27 29 28 #define MEN_Z135_STAT_REG 0x0 ··· 33 34 #define MEN_Z135_CONF_REG 0x808 34 35 #define MEN_Z135_UART_FREQ 0x80c 35 36 #define MEN_Z135_BAUD_REG 0x810 36 - #define MENZ135_TIMEOUT 0x814 37 + #define MEN_Z135_TIMEOUT 0x814 37 38 38 39 #define MEN_Z135_MEM_SIZE 0x818 39 40 40 - #define IS_IRQ(x) ((x) & 1) 41 - #define IRQ_ID(x) (((x) >> 1) & 7) 41 + #define IRQ_ID(x) ((x) & 0x1f) 42 42 43 43 #define MEN_Z135_IER_RXCIEN BIT(0) /* RX Space IRQ */ 44 44 #define MEN_Z135_IER_TXCIEN BIT(1) /* TX Space IRQ */ ··· 92 94 #define MEN_Z135_LSR_TEXP BIT(6) 93 95 #define MEN_Z135_LSR_RXFIFOERR BIT(7) 94 96 95 - #define MEN_Z135_IRQ_ID_MST 0 96 - #define MEN_Z135_IRQ_ID_TSA 1 97 - #define MEN_Z135_IRQ_ID_RDA 2 98 - #define MEN_Z135_IRQ_ID_RLS 3 99 - #define MEN_Z135_IRQ_ID_CTI 6 97 + #define MEN_Z135_IRQ_ID_RLS BIT(0) 98 + #define MEN_Z135_IRQ_ID_RDA BIT(1) 99 + #define MEN_Z135_IRQ_ID_CTI BIT(2) 100 + #define MEN_Z135_IRQ_ID_TSA BIT(3) 101 + #define MEN_Z135_IRQ_ID_MST BIT(4) 100 102 101 103 #define LCR(x) (((x) >> MEN_Z135_LCR_SHIFT) & 0xff) 102 104 ··· 116 118 module_param(align, int, S_IRUGO); 117 119 MODULE_PARM_DESC(align, "Keep hardware FIFO write pointer aligned, default 0"); 118 120 121 + static uint rx_timeout; 122 + module_param(rx_timeout, uint, S_IRUGO); 123 + MODULE_PARM_DESC(rx_timeout, "RX timeout. " 124 + "Timeout in seconds = (timeout_reg * baud_reg * 4) / freq_reg"); 125 + 119 126 struct men_z135_port { 120 127 struct uart_port port; 121 128 struct mcb_device *mdev; 122 129 unsigned char *rxbuf; 123 130 u32 stat_reg; 124 131 spinlock_t lock; 132 + bool automode; 125 133 }; 126 134 #define to_men_z135(port) container_of((port), struct men_z135_port, port) 127 135 ··· 184 180 */ 185 181 static void men_z135_handle_modem_status(struct men_z135_port *uart) 186 182 { 187 - if (uart->stat_reg & MEN_Z135_MSR_DDCD) 183 + u8 msr; 184 + 185 + msr = (uart->stat_reg >> 8) & 0xff; 186 + 187 + if (msr & MEN_Z135_MSR_DDCD) 188 188 uart_handle_dcd_change(&uart->port, 189 - uart->stat_reg & ~MEN_Z135_MSR_DCD); 190 - if (uart->stat_reg & MEN_Z135_MSR_DCTS) 189 + msr & MEN_Z135_MSR_DCD); 190 + if (msr & MEN_Z135_MSR_DCTS) 191 191 uart_handle_cts_change(&uart->port, 192 - uart->stat_reg & ~MEN_Z135_MSR_CTS); 192 + msr & MEN_Z135_MSR_CTS); 193 193 } 194 194 195 195 static void men_z135_handle_lsr(struct men_z135_port *uart) ··· 330 322 331 323 txfree = MEN_Z135_FIFO_WATERMARK - txc; 332 324 if (txfree <= 0) { 333 - pr_err("Not enough room in TX FIFO have %d, need %d\n", 325 + dev_err(&uart->mdev->dev, 326 + "Not enough room in TX FIFO have %d, need %d\n", 334 327 txfree, qlen); 335 328 goto irq_en; 336 329 } ··· 382 373 * @irq: The IRQ number 383 374 * @data: Pointer to UART port 384 375 * 385 - * Check IIR register to see which tasklet to start. 376 + * Check IIR register to find the cause of the interrupt and handle it. 377 + * It is possible that multiple interrupts reason bits are set and reading 378 + * the IIR is a destructive read, so we always need to check for all possible 379 + * interrupts and handle them. 386 380 */ 387 381 static irqreturn_t men_z135_intr(int irq, void *data) 388 382 { 389 383 struct men_z135_port *uart = (struct men_z135_port *)data; 390 384 struct uart_port *port = &uart->port; 385 + bool handled = false; 386 + unsigned long flags; 391 387 int irq_id; 392 388 393 389 uart->stat_reg = ioread32(port->membase + MEN_Z135_STAT_REG); 394 - /* IRQ pending is low active */ 395 - if (IS_IRQ(uart->stat_reg)) 396 - return IRQ_NONE; 397 - 398 390 irq_id = IRQ_ID(uart->stat_reg); 399 - switch (irq_id) { 400 - case MEN_Z135_IRQ_ID_MST: 401 - men_z135_handle_modem_status(uart); 402 - break; 403 - case MEN_Z135_IRQ_ID_TSA: 404 - men_z135_handle_tx(uart); 405 - break; 406 - case MEN_Z135_IRQ_ID_CTI: 407 - dev_dbg(&uart->mdev->dev, "Character Timeout Indication\n"); 408 - /* Fallthrough */ 409 - case MEN_Z135_IRQ_ID_RDA: 410 - /* Reading data clears RX IRQ */ 411 - men_z135_handle_rx(uart); 412 - break; 413 - case MEN_Z135_IRQ_ID_RLS: 391 + 392 + if (!irq_id) 393 + goto out; 394 + 395 + spin_lock_irqsave(&port->lock, flags); 396 + /* It's save to write to IIR[7:6] RXC[9:8] */ 397 + iowrite8(irq_id, port->membase + MEN_Z135_STAT_REG); 398 + 399 + if (irq_id & MEN_Z135_IRQ_ID_RLS) { 414 400 men_z135_handle_lsr(uart); 415 - break; 416 - default: 417 - dev_warn(&uart->mdev->dev, "Unknown IRQ id %d\n", irq_id); 418 - return IRQ_NONE; 401 + handled = true; 419 402 } 420 403 421 - return IRQ_HANDLED; 404 + if (irq_id & (MEN_Z135_IRQ_ID_RDA | MEN_Z135_IRQ_ID_CTI)) { 405 + if (irq_id & MEN_Z135_IRQ_ID_CTI) 406 + dev_dbg(&uart->mdev->dev, "Character Timeout Indication\n"); 407 + men_z135_handle_rx(uart); 408 + handled = true; 409 + } 410 + 411 + if (irq_id & MEN_Z135_IRQ_ID_TSA) { 412 + men_z135_handle_tx(uart); 413 + handled = true; 414 + } 415 + 416 + if (irq_id & MEN_Z135_IRQ_ID_MST) { 417 + men_z135_handle_modem_status(uart); 418 + handled = true; 419 + } 420 + 421 + spin_unlock_irqrestore(&port->lock, flags); 422 + out: 423 + return IRQ_RETVAL(handled); 422 424 } 423 425 424 426 /** ··· 484 464 */ 485 465 static void men_z135_set_mctrl(struct uart_port *port, unsigned int mctrl) 486 466 { 487 - struct men_z135_port *uart = to_men_z135(port); 488 - u32 conf_reg = 0; 467 + u32 old; 468 + u32 conf_reg; 489 469 470 + conf_reg = old = ioread32(port->membase + MEN_Z135_CONF_REG); 490 471 if (mctrl & TIOCM_RTS) 491 472 conf_reg |= MEN_Z135_MCR_RTS; 473 + else 474 + conf_reg &= ~MEN_Z135_MCR_RTS; 475 + 492 476 if (mctrl & TIOCM_DTR) 493 477 conf_reg |= MEN_Z135_MCR_DTR; 478 + else 479 + conf_reg &= ~MEN_Z135_MCR_DTR; 480 + 494 481 if (mctrl & TIOCM_OUT1) 495 482 conf_reg |= MEN_Z135_MCR_OUT1; 483 + else 484 + conf_reg &= ~MEN_Z135_MCR_OUT1; 485 + 496 486 if (mctrl & TIOCM_OUT2) 497 487 conf_reg |= MEN_Z135_MCR_OUT2; 488 + else 489 + conf_reg &= ~MEN_Z135_MCR_OUT2; 490 + 498 491 if (mctrl & TIOCM_LOOP) 499 492 conf_reg |= MEN_Z135_MCR_LOOP; 493 + else 494 + conf_reg &= ~MEN_Z135_MCR_LOOP; 500 495 501 - men_z135_reg_set(uart, MEN_Z135_CONF_REG, conf_reg); 496 + if (conf_reg != old) 497 + iowrite32(conf_reg, port->membase + MEN_Z135_CONF_REG); 502 498 } 503 499 504 500 /** ··· 526 490 static unsigned int men_z135_get_mctrl(struct uart_port *port) 527 491 { 528 492 unsigned int mctrl = 0; 529 - u32 stat_reg; 530 493 u8 msr; 531 494 532 - stat_reg = ioread32(port->membase + MEN_Z135_STAT_REG); 533 - 534 - msr = ~((stat_reg >> 8) & 0xff); 495 + msr = ioread8(port->membase + MEN_Z135_STAT_REG + 1); 535 496 536 497 if (msr & MEN_Z135_MSR_CTS) 537 498 mctrl |= TIOCM_CTS; ··· 557 524 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_TXCIEN); 558 525 } 559 526 527 + /* 528 + * men_z135_disable_ms() - Disable Modem Status 529 + * port: The UART port 530 + * 531 + * Enable Modem Status IRQ. 532 + */ 533 + static void men_z135_disable_ms(struct uart_port *port) 534 + { 535 + struct men_z135_port *uart = to_men_z135(port); 536 + 537 + men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_MSIEN); 538 + } 539 + 560 540 /** 561 541 * men_z135_start_tx() - Start transmitting characters 562 542 * @port: The UART port ··· 580 534 static void men_z135_start_tx(struct uart_port *port) 581 535 { 582 536 struct men_z135_port *uart = to_men_z135(port); 537 + 538 + if (uart->automode) 539 + men_z135_disable_ms(port); 583 540 584 541 men_z135_handle_tx(uart); 585 542 } ··· 633 584 634 585 iowrite32(conf_reg, port->membase + MEN_Z135_CONF_REG); 635 586 587 + if (rx_timeout) 588 + iowrite32(rx_timeout, port->membase + MEN_Z135_TIMEOUT); 589 + 636 590 return 0; 637 591 } 638 592 ··· 655 603 struct ktermios *termios, 656 604 struct ktermios *old) 657 605 { 606 + struct men_z135_port *uart = to_men_z135(port); 658 607 unsigned int baud; 659 608 u32 conf_reg; 660 609 u32 bd_reg; ··· 695 642 lcr |= MEN_Z135_PTY_EVN << MEN_Z135_PTY_SHIFT; 696 643 } else 697 644 lcr |= MEN_Z135_PAR_DIS << MEN_Z135_PEN_SHIFT; 645 + 646 + conf_reg |= MEN_Z135_IER_MSIEN; 647 + if (termios->c_cflag & CRTSCTS) { 648 + conf_reg |= MEN_Z135_MCR_RCFC; 649 + uart->automode = true; 650 + termios->c_cflag &= ~CLOCAL; 651 + } else { 652 + conf_reg &= ~MEN_Z135_MCR_RCFC; 653 + uart->automode = false; 654 + } 698 655 699 656 termios->c_cflag &= ~CMSPAR; /* Mark/Space parity is not supported */ 700 657
-909
drivers/tty/serial/mrst_max3110.c
··· 1 - /* 2 - * mrst_max3110.c - spi uart protocol driver for Maxim 3110 3 - * 4 - * Copyright (c) 2008-2010, Intel Corporation. 5 - * 6 - * This program is free software; you can redistribute it and/or modify it 7 - * under the terms and conditions of the GNU General Public License, 8 - * version 2, as published by the Free Software Foundation. 9 - * 10 - * This program is distributed in the hope it will be useful, but WITHOUT 11 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 - * more details. 14 - * 15 - * You should have received a copy of the GNU General Public License along with 16 - * this program; if not, write to the Free Software Foundation, Inc., 17 - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18 - */ 19 - 20 - /* 21 - * Note: 22 - * 1. From Max3110 spec, the Rx FIFO has 8 words, while the Tx FIFO only has 23 - * 1 word. If SPI master controller doesn't support sclk frequency change, 24 - * then the char need be sent out one by one with some delay 25 - * 26 - * 2. Currently only RX available interrupt is used, no need for waiting TXE 27 - * interrupt for a low speed UART device 28 - */ 29 - 30 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 31 - 32 - #ifdef CONFIG_MAGIC_SYSRQ 33 - #define SUPPORT_SYSRQ 34 - #endif 35 - 36 - #include <linux/module.h> 37 - #include <linux/ioport.h> 38 - #include <linux/irq.h> 39 - #include <linux/init.h> 40 - #include <linux/console.h> 41 - #include <linux/tty.h> 42 - #include <linux/tty_flip.h> 43 - #include <linux/serial_core.h> 44 - #include <linux/serial_reg.h> 45 - 46 - #include <linux/kthread.h> 47 - #include <linux/spi/spi.h> 48 - #include <linux/pm.h> 49 - 50 - #include "mrst_max3110.h" 51 - 52 - #define UART_TX_NEEDED 1 53 - #define CON_TX_NEEDED 2 54 - #define BIT_IRQ_PENDING 3 55 - 56 - struct uart_max3110 { 57 - struct uart_port port; 58 - struct spi_device *spi; 59 - char name[SPI_NAME_SIZE]; 60 - 61 - wait_queue_head_t wq; 62 - struct task_struct *main_thread; 63 - struct task_struct *read_thread; 64 - struct mutex thread_mutex; 65 - struct mutex io_mutex; 66 - 67 - u32 baud; 68 - u16 cur_conf; 69 - u8 clock; 70 - u8 parity, word_7bits; 71 - u16 irq; 72 - 73 - unsigned long uart_flags; 74 - 75 - /* console related */ 76 - struct circ_buf con_xmit; 77 - }; 78 - 79 - /* global data structure, may need be removed */ 80 - static struct uart_max3110 *pmax; 81 - 82 - static int receive_chars(struct uart_max3110 *max, 83 - unsigned short *str, int len); 84 - static int max3110_read_multi(struct uart_max3110 *max); 85 - static void max3110_con_receive(struct uart_max3110 *max); 86 - 87 - static int max3110_write_then_read(struct uart_max3110 *max, 88 - const void *txbuf, void *rxbuf, unsigned len, int always_fast) 89 - { 90 - struct spi_device *spi = max->spi; 91 - struct spi_message message; 92 - struct spi_transfer x; 93 - int ret; 94 - 95 - mutex_lock(&max->io_mutex); 96 - spi_message_init(&message); 97 - memset(&x, 0, sizeof x); 98 - x.len = len; 99 - x.tx_buf = txbuf; 100 - x.rx_buf = rxbuf; 101 - spi_message_add_tail(&x, &message); 102 - 103 - if (always_fast) 104 - x.speed_hz = spi->max_speed_hz; 105 - else if (max->baud) 106 - x.speed_hz = max->baud; 107 - 108 - /* Do the i/o */ 109 - ret = spi_sync(spi, &message); 110 - mutex_unlock(&max->io_mutex); 111 - return ret; 112 - } 113 - 114 - /* Write a 16b word to the device */ 115 - static int max3110_out(struct uart_max3110 *max, const u16 out) 116 - { 117 - void *buf; 118 - u16 *obuf, *ibuf; 119 - int ret; 120 - 121 - buf = kzalloc(8, GFP_KERNEL | GFP_DMA); 122 - if (!buf) 123 - return -ENOMEM; 124 - 125 - obuf = buf; 126 - ibuf = buf + 4; 127 - *obuf = out; 128 - ret = max3110_write_then_read(max, obuf, ibuf, 2, 1); 129 - if (ret) { 130 - pr_warn("%s: get err msg %d when sending 0x%x\n", 131 - __func__, ret, out); 132 - goto exit; 133 - } 134 - 135 - receive_chars(max, ibuf, 1); 136 - 137 - exit: 138 - kfree(buf); 139 - return ret; 140 - } 141 - 142 - /* 143 - * This is usually used to read data from SPIC RX FIFO, which doesn't 144 - * need any delay like flushing character out. 145 - * 146 - * Return how many valide bytes are read back 147 - */ 148 - static int max3110_read_multi(struct uart_max3110 *max) 149 - { 150 - void *buf; 151 - u16 *obuf, *ibuf; 152 - int ret, blen; 153 - 154 - blen = M3110_RX_FIFO_DEPTH * sizeof(u16); 155 - buf = kzalloc(blen * 2, GFP_KERNEL | GFP_DMA); 156 - if (!buf) 157 - return 0; 158 - 159 - /* tx/rx always have the same length */ 160 - obuf = buf; 161 - ibuf = buf + blen; 162 - 163 - if (max3110_write_then_read(max, obuf, ibuf, blen, 1)) { 164 - kfree(buf); 165 - return 0; 166 - } 167 - 168 - ret = receive_chars(max, ibuf, M3110_RX_FIFO_DEPTH); 169 - 170 - kfree(buf); 171 - return ret; 172 - } 173 - 174 - static void serial_m3110_con_putchar(struct uart_port *port, int ch) 175 - { 176 - struct uart_max3110 *max = 177 - container_of(port, struct uart_max3110, port); 178 - struct circ_buf *xmit = &max->con_xmit; 179 - 180 - if (uart_circ_chars_free(xmit)) { 181 - xmit->buf[xmit->head] = (char)ch; 182 - xmit->head = (xmit->head + 1) & (PAGE_SIZE - 1); 183 - } 184 - } 185 - 186 - /* 187 - * Print a string to the serial port trying not to disturb 188 - * any possible real use of the port... 189 - * 190 - * The console_lock must be held when we get here. 191 - */ 192 - static void serial_m3110_con_write(struct console *co, 193 - const char *s, unsigned int count) 194 - { 195 - if (!pmax) 196 - return; 197 - 198 - uart_console_write(&pmax->port, s, count, serial_m3110_con_putchar); 199 - 200 - if (!test_and_set_bit(CON_TX_NEEDED, &pmax->uart_flags)) 201 - wake_up(&pmax->wq); 202 - } 203 - 204 - static int __init 205 - serial_m3110_con_setup(struct console *co, char *options) 206 - { 207 - struct uart_max3110 *max = pmax; 208 - int baud = 115200; 209 - int bits = 8; 210 - int parity = 'n'; 211 - int flow = 'n'; 212 - 213 - pr_info("setting up console\n"); 214 - 215 - if (co->index == -1) 216 - co->index = 0; 217 - 218 - if (!max) { 219 - pr_err("pmax is NULL, return\n"); 220 - return -ENODEV; 221 - } 222 - 223 - if (options) 224 - uart_parse_options(options, &baud, &parity, &bits, &flow); 225 - 226 - return uart_set_options(&max->port, co, baud, parity, bits, flow); 227 - } 228 - 229 - static struct tty_driver *serial_m3110_con_device(struct console *co, 230 - int *index) 231 - { 232 - struct uart_driver *p = co->data; 233 - *index = co->index; 234 - return p->tty_driver; 235 - } 236 - 237 - static struct uart_driver serial_m3110_reg; 238 - static struct console serial_m3110_console = { 239 - .name = "ttyS", 240 - .write = serial_m3110_con_write, 241 - .device = serial_m3110_con_device, 242 - .setup = serial_m3110_con_setup, 243 - .flags = CON_PRINTBUFFER, 244 - .index = -1, 245 - .data = &serial_m3110_reg, 246 - }; 247 - 248 - static unsigned int serial_m3110_tx_empty(struct uart_port *port) 249 - { 250 - return 1; 251 - } 252 - 253 - static void serial_m3110_stop_tx(struct uart_port *port) 254 - { 255 - return; 256 - } 257 - 258 - /* stop_rx will be called in spin_lock env */ 259 - static void serial_m3110_stop_rx(struct uart_port *port) 260 - { 261 - return; 262 - } 263 - 264 - #define WORDS_PER_XFER 128 265 - static void send_circ_buf(struct uart_max3110 *max, 266 - struct circ_buf *xmit) 267 - { 268 - void *buf; 269 - u16 *obuf, *ibuf; 270 - int i, len, blen, dma_size, left, ret = 0; 271 - 272 - 273 - dma_size = WORDS_PER_XFER * sizeof(u16) * 2; 274 - buf = kzalloc(dma_size, GFP_KERNEL | GFP_DMA); 275 - if (!buf) 276 - return; 277 - obuf = buf; 278 - ibuf = buf + dma_size/2; 279 - 280 - while (!uart_circ_empty(xmit)) { 281 - left = uart_circ_chars_pending(xmit); 282 - while (left) { 283 - len = min(left, WORDS_PER_XFER); 284 - blen = len * sizeof(u16); 285 - memset(ibuf, 0, blen); 286 - 287 - for (i = 0; i < len; i++) { 288 - obuf[i] = (u8)xmit->buf[xmit->tail] | WD_TAG; 289 - xmit->tail = (xmit->tail + 1) & 290 - (UART_XMIT_SIZE - 1); 291 - } 292 - 293 - /* Fail to send msg to console is not very critical */ 294 - 295 - ret = max3110_write_then_read(max, obuf, ibuf, blen, 0); 296 - if (ret) 297 - pr_warn("%s: get err msg %d\n", __func__, ret); 298 - 299 - receive_chars(max, ibuf, len); 300 - 301 - max->port.icount.tx += len; 302 - left -= len; 303 - } 304 - } 305 - 306 - kfree(buf); 307 - } 308 - 309 - static void transmit_char(struct uart_max3110 *max) 310 - { 311 - struct uart_port *port = &max->port; 312 - struct circ_buf *xmit = &port->state->xmit; 313 - 314 - if (uart_circ_empty(xmit) || uart_tx_stopped(port)) 315 - return; 316 - 317 - send_circ_buf(max, xmit); 318 - 319 - if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 320 - uart_write_wakeup(port); 321 - 322 - if (uart_circ_empty(xmit)) 323 - serial_m3110_stop_tx(port); 324 - } 325 - 326 - /* 327 - * This will be called by uart_write() and tty_write, can't 328 - * go to sleep 329 - */ 330 - static void serial_m3110_start_tx(struct uart_port *port) 331 - { 332 - struct uart_max3110 *max = 333 - container_of(port, struct uart_max3110, port); 334 - 335 - if (!test_and_set_bit(UART_TX_NEEDED, &max->uart_flags)) 336 - wake_up(&max->wq); 337 - } 338 - 339 - static int 340 - receive_chars(struct uart_max3110 *max, unsigned short *str, int len) 341 - { 342 - struct uart_port *port = &max->port; 343 - struct tty_port *tport; 344 - char buf[M3110_RX_FIFO_DEPTH]; 345 - int r, w, usable; 346 - 347 - /* If uart is not opened, just return */ 348 - if (!port->state) 349 - return 0; 350 - 351 - tport = &port->state->port; 352 - 353 - for (r = 0, w = 0; r < len; r++) { 354 - if (str[r] & MAX3110_BREAK && 355 - uart_handle_break(port)) 356 - continue; 357 - 358 - if (str[r] & MAX3110_READ_DATA_AVAILABLE) { 359 - if (uart_handle_sysrq_char(port, str[r] & 0xff)) 360 - continue; 361 - 362 - buf[w++] = str[r] & 0xff; 363 - } 364 - } 365 - 366 - if (!w) 367 - return 0; 368 - 369 - for (r = 0; w; r += usable, w -= usable) { 370 - usable = tty_buffer_request_room(tport, w); 371 - if (usable) { 372 - tty_insert_flip_string(tport, buf + r, usable); 373 - port->icount.rx += usable; 374 - } 375 - } 376 - tty_flip_buffer_push(tport); 377 - 378 - return r; 379 - } 380 - 381 - /* 382 - * This routine will be used in read_thread or RX IRQ handling, 383 - * it will first do one round buffer read(8 words), if there is some 384 - * valid RX data, will try to read 5 more rounds till all data 385 - * is read out. 386 - * 387 - * Use stack space as data buffer to save some system load, and chose 388 - * 504 Btyes as a threadhold to do a bulk push to upper tty layer when 389 - * receiving bulk data, a much bigger buffer may cause stack overflow 390 - */ 391 - static void max3110_con_receive(struct uart_max3110 *max) 392 - { 393 - int loop = 1, num; 394 - 395 - do { 396 - num = max3110_read_multi(max); 397 - 398 - if (num) { 399 - loop = 5; 400 - } 401 - } while (--loop); 402 - } 403 - 404 - static int max3110_main_thread(void *_max) 405 - { 406 - struct uart_max3110 *max = _max; 407 - wait_queue_head_t *wq = &max->wq; 408 - int ret = 0; 409 - struct circ_buf *xmit = &max->con_xmit; 410 - 411 - pr_info("start main thread\n"); 412 - 413 - do { 414 - wait_event_interruptible(*wq, 415 - max->uart_flags || kthread_should_stop()); 416 - 417 - mutex_lock(&max->thread_mutex); 418 - 419 - if (test_and_clear_bit(BIT_IRQ_PENDING, &max->uart_flags)) 420 - max3110_con_receive(max); 421 - 422 - /* first handle console output */ 423 - if (test_and_clear_bit(CON_TX_NEEDED, &max->uart_flags)) 424 - send_circ_buf(max, xmit); 425 - 426 - /* handle uart output */ 427 - if (test_and_clear_bit(UART_TX_NEEDED, &max->uart_flags)) 428 - transmit_char(max); 429 - 430 - mutex_unlock(&max->thread_mutex); 431 - 432 - } while (!kthread_should_stop()); 433 - 434 - return ret; 435 - } 436 - 437 - static irqreturn_t serial_m3110_irq(int irq, void *dev_id) 438 - { 439 - struct uart_max3110 *max = dev_id; 440 - 441 - /* max3110's irq is a falling edge, not level triggered, 442 - * so no need to disable the irq */ 443 - 444 - if (!test_and_set_bit(BIT_IRQ_PENDING, &max->uart_flags)) 445 - wake_up(&max->wq); 446 - 447 - return IRQ_HANDLED; 448 - } 449 - 450 - /* if don't use RX IRQ, then need a thread to polling read */ 451 - static int max3110_read_thread(void *_max) 452 - { 453 - struct uart_max3110 *max = _max; 454 - 455 - pr_info("start read thread\n"); 456 - do { 457 - /* 458 - * If can't acquire the mutex, it means the main thread 459 - * is running which will also perform the rx job 460 - */ 461 - if (mutex_trylock(&max->thread_mutex)) { 462 - max3110_con_receive(max); 463 - mutex_unlock(&max->thread_mutex); 464 - } 465 - 466 - set_current_state(TASK_INTERRUPTIBLE); 467 - schedule_timeout(HZ / 20); 468 - } while (!kthread_should_stop()); 469 - 470 - return 0; 471 - } 472 - 473 - static int serial_m3110_startup(struct uart_port *port) 474 - { 475 - struct uart_max3110 *max = 476 - container_of(port, struct uart_max3110, port); 477 - u16 config = 0; 478 - int ret = 0; 479 - 480 - if (port->line != 0) { 481 - pr_err("uart port startup failed\n"); 482 - return -1; 483 - } 484 - 485 - /* Disable all IRQ and config it to 115200, 8n1 */ 486 - config = WC_TAG | WC_FIFO_ENABLE 487 - | WC_1_STOPBITS 488 - | WC_8BIT_WORD 489 - | WC_BAUD_DR2; 490 - 491 - /* as we use thread to handle tx/rx, need set low latency */ 492 - port->state->port.low_latency = 1; 493 - 494 - if (max->irq) { 495 - /* Enable RX IRQ only */ 496 - config |= WC_RXA_IRQ_ENABLE; 497 - } else { 498 - /* If IRQ is disabled, start a read thread for input data */ 499 - max->read_thread = 500 - kthread_run(max3110_read_thread, max, "max3110_read"); 501 - if (IS_ERR(max->read_thread)) { 502 - ret = PTR_ERR(max->read_thread); 503 - max->read_thread = NULL; 504 - pr_err("Can't create read thread!\n"); 505 - return ret; 506 - } 507 - } 508 - 509 - ret = max3110_out(max, config); 510 - if (ret) { 511 - if (max->read_thread) 512 - kthread_stop(max->read_thread); 513 - max->read_thread = NULL; 514 - return ret; 515 - } 516 - 517 - max->cur_conf = config; 518 - return 0; 519 - } 520 - 521 - static void serial_m3110_shutdown(struct uart_port *port) 522 - { 523 - struct uart_max3110 *max = 524 - container_of(port, struct uart_max3110, port); 525 - u16 config; 526 - 527 - if (max->read_thread) { 528 - kthread_stop(max->read_thread); 529 - max->read_thread = NULL; 530 - } 531 - 532 - /* Disable interrupts from this port */ 533 - config = WC_TAG | WC_SW_SHDI; 534 - max3110_out(max, config); 535 - } 536 - 537 - static void serial_m3110_release_port(struct uart_port *port) 538 - { 539 - } 540 - 541 - static int serial_m3110_request_port(struct uart_port *port) 542 - { 543 - return 0; 544 - } 545 - 546 - static void serial_m3110_config_port(struct uart_port *port, int flags) 547 - { 548 - port->type = PORT_MAX3100; 549 - } 550 - 551 - static int 552 - serial_m3110_verify_port(struct uart_port *port, struct serial_struct *ser) 553 - { 554 - /* we don't want the core code to modify any port params */ 555 - return -EINVAL; 556 - } 557 - 558 - 559 - static const char *serial_m3110_type(struct uart_port *port) 560 - { 561 - struct uart_max3110 *max = 562 - container_of(port, struct uart_max3110, port); 563 - return max->name; 564 - } 565 - 566 - static void 567 - serial_m3110_set_termios(struct uart_port *port, struct ktermios *termios, 568 - struct ktermios *old) 569 - { 570 - struct uart_max3110 *max = 571 - container_of(port, struct uart_max3110, port); 572 - unsigned char cval; 573 - unsigned int baud, parity = 0; 574 - int clk_div = -1; 575 - u16 new_conf = max->cur_conf; 576 - 577 - switch (termios->c_cflag & CSIZE) { 578 - case CS7: 579 - cval = UART_LCR_WLEN7; 580 - new_conf |= WC_7BIT_WORD; 581 - break; 582 - default: 583 - /* We only support CS7 & CS8 */ 584 - termios->c_cflag &= ~CSIZE; 585 - termios->c_cflag |= CS8; 586 - case CS8: 587 - cval = UART_LCR_WLEN8; 588 - new_conf |= WC_8BIT_WORD; 589 - break; 590 - } 591 - 592 - baud = uart_get_baud_rate(port, termios, old, 0, 230400); 593 - 594 - /* First calc the div for 1.8MHZ clock case */ 595 - switch (baud) { 596 - case 300: 597 - clk_div = WC_BAUD_DR384; 598 - break; 599 - case 600: 600 - clk_div = WC_BAUD_DR192; 601 - break; 602 - case 1200: 603 - clk_div = WC_BAUD_DR96; 604 - break; 605 - case 2400: 606 - clk_div = WC_BAUD_DR48; 607 - break; 608 - case 4800: 609 - clk_div = WC_BAUD_DR24; 610 - break; 611 - case 9600: 612 - clk_div = WC_BAUD_DR12; 613 - break; 614 - case 19200: 615 - clk_div = WC_BAUD_DR6; 616 - break; 617 - case 38400: 618 - clk_div = WC_BAUD_DR3; 619 - break; 620 - case 57600: 621 - clk_div = WC_BAUD_DR2; 622 - break; 623 - case 115200: 624 - clk_div = WC_BAUD_DR1; 625 - break; 626 - case 230400: 627 - if (max->clock & MAX3110_HIGH_CLK) 628 - break; 629 - default: 630 - /* Pick the previous baud rate */ 631 - baud = max->baud; 632 - clk_div = max->cur_conf & WC_BAUD_DIV_MASK; 633 - tty_termios_encode_baud_rate(termios, baud, baud); 634 - } 635 - 636 - if (max->clock & MAX3110_HIGH_CLK) { 637 - clk_div += 1; 638 - /* High clk version max3110 doesn't support B300 */ 639 - if (baud == 300) { 640 - baud = 600; 641 - clk_div = WC_BAUD_DR384; 642 - } 643 - if (baud == 230400) 644 - clk_div = WC_BAUD_DR1; 645 - tty_termios_encode_baud_rate(termios, baud, baud); 646 - } 647 - 648 - new_conf = (new_conf & ~WC_BAUD_DIV_MASK) | clk_div; 649 - 650 - if (unlikely(termios->c_cflag & CMSPAR)) 651 - termios->c_cflag &= ~CMSPAR; 652 - 653 - if (termios->c_cflag & CSTOPB) 654 - new_conf |= WC_2_STOPBITS; 655 - else 656 - new_conf &= ~WC_2_STOPBITS; 657 - 658 - if (termios->c_cflag & PARENB) { 659 - new_conf |= WC_PARITY_ENABLE; 660 - parity |= UART_LCR_PARITY; 661 - } else 662 - new_conf &= ~WC_PARITY_ENABLE; 663 - 664 - if (!(termios->c_cflag & PARODD)) 665 - parity |= UART_LCR_EPAR; 666 - max->parity = parity; 667 - 668 - uart_update_timeout(port, termios->c_cflag, baud); 669 - 670 - new_conf |= WC_TAG; 671 - if (new_conf != max->cur_conf) { 672 - if (!max3110_out(max, new_conf)) { 673 - max->cur_conf = new_conf; 674 - max->baud = baud; 675 - } 676 - } 677 - } 678 - 679 - /* Don't handle hw handshaking */ 680 - static unsigned int serial_m3110_get_mctrl(struct uart_port *port) 681 - { 682 - return TIOCM_DSR | TIOCM_CAR | TIOCM_DSR; 683 - } 684 - 685 - static void serial_m3110_set_mctrl(struct uart_port *port, unsigned int mctrl) 686 - { 687 - } 688 - 689 - static void serial_m3110_break_ctl(struct uart_port *port, int break_state) 690 - { 691 - } 692 - 693 - static void serial_m3110_pm(struct uart_port *port, unsigned int state, 694 - unsigned int oldstate) 695 - { 696 - } 697 - 698 - static struct uart_ops serial_m3110_ops = { 699 - .tx_empty = serial_m3110_tx_empty, 700 - .set_mctrl = serial_m3110_set_mctrl, 701 - .get_mctrl = serial_m3110_get_mctrl, 702 - .stop_tx = serial_m3110_stop_tx, 703 - .start_tx = serial_m3110_start_tx, 704 - .stop_rx = serial_m3110_stop_rx, 705 - .break_ctl = serial_m3110_break_ctl, 706 - .startup = serial_m3110_startup, 707 - .shutdown = serial_m3110_shutdown, 708 - .set_termios = serial_m3110_set_termios, 709 - .pm = serial_m3110_pm, 710 - .type = serial_m3110_type, 711 - .release_port = serial_m3110_release_port, 712 - .request_port = serial_m3110_request_port, 713 - .config_port = serial_m3110_config_port, 714 - .verify_port = serial_m3110_verify_port, 715 - }; 716 - 717 - static struct uart_driver serial_m3110_reg = { 718 - .owner = THIS_MODULE, 719 - .driver_name = "MRST serial", 720 - .dev_name = "ttyS", 721 - .major = TTY_MAJOR, 722 - .minor = 64, 723 - .nr = 1, 724 - .cons = &serial_m3110_console, 725 - }; 726 - 727 - #ifdef CONFIG_PM_SLEEP 728 - static int serial_m3110_suspend(struct device *dev) 729 - { 730 - struct spi_device *spi = to_spi_device(dev); 731 - struct uart_max3110 *max = spi_get_drvdata(spi); 732 - 733 - if (max->irq > 0) 734 - disable_irq(max->irq); 735 - uart_suspend_port(&serial_m3110_reg, &max->port); 736 - max3110_out(max, max->cur_conf | WC_SW_SHDI); 737 - return 0; 738 - } 739 - 740 - static int serial_m3110_resume(struct device *dev) 741 - { 742 - struct spi_device *spi = to_spi_device(dev); 743 - struct uart_max3110 *max = spi_get_drvdata(spi); 744 - 745 - max3110_out(max, max->cur_conf); 746 - uart_resume_port(&serial_m3110_reg, &max->port); 747 - if (max->irq > 0) 748 - enable_irq(max->irq); 749 - return 0; 750 - } 751 - 752 - static SIMPLE_DEV_PM_OPS(serial_m3110_pm_ops, serial_m3110_suspend, 753 - serial_m3110_resume); 754 - #define SERIAL_M3110_PM_OPS (&serial_m3110_pm_ops) 755 - 756 - #else 757 - #define SERIAL_M3110_PM_OPS NULL 758 - #endif 759 - 760 - static int serial_m3110_probe(struct spi_device *spi) 761 - { 762 - struct uart_max3110 *max; 763 - void *buffer; 764 - u16 res; 765 - int ret = 0; 766 - 767 - max = kzalloc(sizeof(*max), GFP_KERNEL); 768 - if (!max) 769 - return -ENOMEM; 770 - 771 - /* Set spi info */ 772 - spi->bits_per_word = 16; 773 - max->clock = MAX3110_HIGH_CLK; 774 - 775 - spi_setup(spi); 776 - 777 - max->port.type = PORT_MAX3100; 778 - max->port.fifosize = 2; /* Only have 16b buffer */ 779 - max->port.ops = &serial_m3110_ops; 780 - max->port.line = 0; 781 - max->port.dev = &spi->dev; 782 - max->port.uartclk = 115200; 783 - 784 - max->spi = spi; 785 - strcpy(max->name, spi->modalias); 786 - max->irq = (u16)spi->irq; 787 - 788 - mutex_init(&max->thread_mutex); 789 - mutex_init(&max->io_mutex); 790 - 791 - max->word_7bits = 0; 792 - max->parity = 0; 793 - max->baud = 0; 794 - 795 - max->cur_conf = 0; 796 - max->uart_flags = 0; 797 - 798 - /* Check if reading configuration register returns something sane */ 799 - 800 - res = RC_TAG; 801 - ret = max3110_write_then_read(max, (u8 *)&res, (u8 *)&res, 2, 0); 802 - if (ret < 0 || res == 0 || res == 0xffff) { 803 - dev_dbg(&spi->dev, "MAX3111 deemed not present (conf reg %04x)", 804 - res); 805 - ret = -ENODEV; 806 - goto err_get_page; 807 - } 808 - 809 - buffer = (void *)__get_free_page(GFP_KERNEL); 810 - if (!buffer) { 811 - ret = -ENOMEM; 812 - goto err_get_page; 813 - } 814 - max->con_xmit.buf = buffer; 815 - max->con_xmit.head = 0; 816 - max->con_xmit.tail = 0; 817 - 818 - init_waitqueue_head(&max->wq); 819 - 820 - max->main_thread = kthread_run(max3110_main_thread, 821 - max, "max3110_main"); 822 - if (IS_ERR(max->main_thread)) { 823 - ret = PTR_ERR(max->main_thread); 824 - goto err_kthread; 825 - } 826 - 827 - if (max->irq) { 828 - ret = request_irq(max->irq, serial_m3110_irq, 829 - IRQ_TYPE_EDGE_FALLING, "max3110", max); 830 - if (ret) { 831 - max->irq = 0; 832 - dev_warn(&spi->dev, 833 - "unable to allocate IRQ, will use polling method\n"); 834 - } 835 - } 836 - 837 - spi_set_drvdata(spi, max); 838 - pmax = max; 839 - 840 - /* Give membase a psudo value to pass serial_core's check */ 841 - max->port.membase = (unsigned char __iomem *)0xff110000; 842 - uart_add_one_port(&serial_m3110_reg, &max->port); 843 - 844 - return 0; 845 - 846 - err_kthread: 847 - free_page((unsigned long)buffer); 848 - err_get_page: 849 - kfree(max); 850 - return ret; 851 - } 852 - 853 - static int serial_m3110_remove(struct spi_device *dev) 854 - { 855 - struct uart_max3110 *max = spi_get_drvdata(dev); 856 - 857 - if (!max) 858 - return 0; 859 - 860 - uart_remove_one_port(&serial_m3110_reg, &max->port); 861 - 862 - free_page((unsigned long)max->con_xmit.buf); 863 - 864 - if (max->irq) 865 - free_irq(max->irq, max); 866 - 867 - if (max->main_thread) 868 - kthread_stop(max->main_thread); 869 - 870 - kfree(max); 871 - return 0; 872 - } 873 - 874 - static struct spi_driver uart_max3110_driver = { 875 - .driver = { 876 - .name = "spi_max3111", 877 - .owner = THIS_MODULE, 878 - .pm = SERIAL_M3110_PM_OPS, 879 - }, 880 - .probe = serial_m3110_probe, 881 - .remove = serial_m3110_remove, 882 - }; 883 - 884 - static int __init serial_m3110_init(void) 885 - { 886 - int ret = 0; 887 - 888 - ret = uart_register_driver(&serial_m3110_reg); 889 - if (ret) 890 - return ret; 891 - 892 - ret = spi_register_driver(&uart_max3110_driver); 893 - if (ret) 894 - uart_unregister_driver(&serial_m3110_reg); 895 - 896 - return ret; 897 - } 898 - 899 - static void __exit serial_m3110_exit(void) 900 - { 901 - spi_unregister_driver(&uart_max3110_driver); 902 - uart_unregister_driver(&serial_m3110_reg); 903 - } 904 - 905 - module_init(serial_m3110_init); 906 - module_exit(serial_m3110_exit); 907 - 908 - MODULE_LICENSE("GPL v2"); 909 - MODULE_ALIAS("spi:max3110-uart");
-61
drivers/tty/serial/mrst_max3110.h
··· 1 - #ifndef _MRST_MAX3110_H 2 - #define _MRST_MAX3110_H 3 - 4 - #define MAX3110_HIGH_CLK 0x1 /* 3.6864 MHZ */ 5 - #define MAX3110_LOW_CLK 0x0 /* 1.8432 MHZ */ 6 - 7 - /* status bits for all 4 MAX3110 operate modes */ 8 - #define MAX3110_READ_DATA_AVAILABLE (1 << 15) 9 - #define MAX3110_WRITE_BUF_EMPTY (1 << 14) 10 - #define MAX3110_BREAK (1 << 10) 11 - 12 - #define WC_TAG (3 << 14) 13 - #define RC_TAG (1 << 14) 14 - #define WD_TAG (2 << 14) 15 - #define RD_TAG (0 << 14) 16 - 17 - /* bits def for write configuration */ 18 - #define WC_FIFO_ENABLE_MASK (1 << 13) 19 - #define WC_FIFO_ENABLE (0 << 13) 20 - 21 - #define WC_SW_SHDI (1 << 12) 22 - 23 - #define WC_IRQ_MASK (0xF << 8) 24 - #define WC_TXE_IRQ_ENABLE (1 << 11) /* TX empty irq */ 25 - #define WC_RXA_IRQ_ENABLE (1 << 10) /* RX available irq */ 26 - #define WC_PAR_HIGH_IRQ_ENABLE (1 << 9) 27 - #define WC_REC_ACT_IRQ_ENABLE (1 << 8) 28 - 29 - #define WC_IRDA_ENABLE (1 << 7) 30 - 31 - #define WC_STOPBITS_MASK (1 << 6) 32 - #define WC_2_STOPBITS (1 << 6) 33 - #define WC_1_STOPBITS (0 << 6) 34 - 35 - #define WC_PARITY_ENABLE_MASK (1 << 5) 36 - #define WC_PARITY_ENABLE (1 << 5) 37 - 38 - #define WC_WORDLEN_MASK (1 << 4) 39 - #define WC_7BIT_WORD (1 << 4) 40 - #define WC_8BIT_WORD (0 << 4) 41 - 42 - #define WC_BAUD_DIV_MASK (0xF) 43 - #define WC_BAUD_DR1 (0x0) 44 - #define WC_BAUD_DR2 (0x1) 45 - #define WC_BAUD_DR4 (0x2) 46 - #define WC_BAUD_DR8 (0x3) 47 - #define WC_BAUD_DR16 (0x4) 48 - #define WC_BAUD_DR32 (0x5) 49 - #define WC_BAUD_DR64 (0x6) 50 - #define WC_BAUD_DR128 (0x7) 51 - #define WC_BAUD_DR3 (0x8) 52 - #define WC_BAUD_DR6 (0x9) 53 - #define WC_BAUD_DR12 (0xA) 54 - #define WC_BAUD_DR24 (0xB) 55 - #define WC_BAUD_DR48 (0xC) 56 - #define WC_BAUD_DR96 (0xD) 57 - #define WC_BAUD_DR192 (0xE) 58 - #define WC_BAUD_DR384 (0xF) 59 - 60 - #define M3110_RX_FIFO_DEPTH 8 61 - #endif
+4 -23
drivers/tty/serial/msm_serial.c
··· 920 920 static int __init msm_console_setup(struct console *co, char *options) 921 921 { 922 922 struct uart_port *port; 923 - struct msm_port *msm_port; 924 - int baud = 0, flow, bits, parity; 923 + int baud = 115200; 924 + int bits = 8; 925 + int parity = 'n'; 926 + int flow = 'n'; 925 927 926 928 if (unlikely(co->index >= UART_NR || co->index < 0)) 927 929 return -ENXIO; 928 930 929 931 port = get_port_from_line(co->index); 930 - msm_port = UART_TO_MSM(port); 931 932 932 933 if (unlikely(!port->membase)) 933 934 return -ENXIO; ··· 937 936 938 937 if (options) 939 938 uart_parse_options(options, &baud, &parity, &bits, &flow); 940 - 941 - bits = 8; 942 - parity = 'n'; 943 - flow = 'n'; 944 - msm_write(port, UART_MR2_BITS_PER_CHAR_8 | UART_MR2_STOP_BIT_LEN_ONE, 945 - UART_MR2); /* 8N1 */ 946 - 947 - if (baud < 300 || baud > 115200) 948 - baud = 115200; 949 - msm_set_baud_rate(port, baud); 950 - 951 - msm_reset(port); 952 - 953 - if (msm_port->is_uartdm) { 954 - msm_write(port, UART_CR_CMD_PROTECTION_EN, UART_CR); 955 - msm_write(port, UART_CR_TX_ENABLE, UART_CR); 956 - } 957 939 958 940 pr_info("msm_serial: console setup on port #%d\n", port->line); 959 941 ··· 1126 1142 1127 1143 static void __exit msm_serial_exit(void) 1128 1144 { 1129 - #ifdef CONFIG_SERIAL_MSM_CONSOLE 1130 - unregister_console(&msm_console); 1131 - #endif 1132 1145 platform_driver_unregister(&msm_platform_driver); 1133 1146 uart_unregister_driver(&msm_uart_driver); 1134 1147 }
+20 -35
drivers/tty/serial/mxs-auart.c
··· 152 152 unsigned int mctrl_prev; 153 153 enum mxs_auart_type devtype; 154 154 155 - unsigned int irq; 156 - 157 155 struct clk *clk; 158 156 struct device *dev; 159 157 ··· 1226 1228 of_match_device(mxs_auart_dt_ids, &pdev->dev); 1227 1229 struct mxs_auart_port *s; 1228 1230 u32 version; 1229 - int ret = 0; 1231 + int ret, irq; 1230 1232 struct resource *r; 1231 1233 1232 - s = kzalloc(sizeof(struct mxs_auart_port), GFP_KERNEL); 1233 - if (!s) { 1234 - ret = -ENOMEM; 1235 - goto out; 1236 - } 1234 + s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); 1235 + if (!s) 1236 + return -ENOMEM; 1237 1237 1238 1238 ret = serial_mxs_probe_dt(s, pdev); 1239 1239 if (ret > 0) 1240 1240 s->port.line = pdev->id < 0 ? 0 : pdev->id; 1241 1241 else if (ret < 0) 1242 - goto out_free; 1242 + return ret; 1243 1243 1244 1244 if (of_id) { 1245 1245 pdev->id_entry = of_id->data; 1246 1246 s->devtype = pdev->id_entry->driver_data; 1247 1247 } 1248 1248 1249 - s->clk = clk_get(&pdev->dev, NULL); 1250 - if (IS_ERR(s->clk)) { 1251 - ret = PTR_ERR(s->clk); 1252 - goto out_free; 1253 - } 1249 + s->clk = devm_clk_get(&pdev->dev, NULL); 1250 + if (IS_ERR(s->clk)) 1251 + return PTR_ERR(s->clk); 1254 1252 1255 1253 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1256 - if (!r) { 1257 - ret = -ENXIO; 1258 - goto out_free_clk; 1259 - } 1254 + if (!r) 1255 + return -ENXIO; 1256 + 1260 1257 1261 1258 s->port.mapbase = r->start; 1262 1259 s->port.membase = ioremap(r->start, resource_size(r)); ··· 1264 1271 1265 1272 s->mctrl_prev = 0; 1266 1273 1267 - s->irq = platform_get_irq(pdev, 0); 1268 - s->port.irq = s->irq; 1269 - ret = request_irq(s->irq, mxs_auart_irq_handle, 0, dev_name(&pdev->dev), s); 1274 + irq = platform_get_irq(pdev, 0); 1275 + if (irq < 0) 1276 + return irq; 1277 + 1278 + s->port.irq = irq; 1279 + ret = devm_request_irq(&pdev->dev, irq, mxs_auart_irq_handle, 0, 1280 + dev_name(&pdev->dev), s); 1270 1281 if (ret) 1271 - goto out_free_clk; 1282 + return ret; 1272 1283 1273 1284 platform_set_drvdata(pdev, s); 1274 1285 ··· 1285 1288 */ 1286 1289 ret = mxs_auart_request_gpio_irq(s); 1287 1290 if (ret) 1288 - goto out_free_irq; 1291 + return ret; 1289 1292 1290 1293 auart_port[s->port.line] = s; 1291 1294 ··· 1304 1307 1305 1308 out_free_gpio_irq: 1306 1309 mxs_auart_free_gpio_irq(s); 1307 - out_free_irq: 1308 1310 auart_port[pdev->id] = NULL; 1309 - free_irq(s->irq, s); 1310 - out_free_clk: 1311 - clk_put(s->clk); 1312 - out_free: 1313 - kfree(s); 1314 - out: 1315 1311 return ret; 1316 1312 } 1317 1313 ··· 1313 1323 struct mxs_auart_port *s = platform_get_drvdata(pdev); 1314 1324 1315 1325 uart_remove_one_port(&auart_driver, &s->port); 1316 - 1317 1326 auart_port[pdev->id] = NULL; 1318 - 1319 1327 mxs_auart_free_gpio_irq(s); 1320 - clk_put(s->clk); 1321 - free_irq(s->irq, s); 1322 - kfree(s); 1323 1328 1324 1329 return 0; 1325 1330 }
+13
drivers/tty/serial/of_serial.c
··· 102 102 if (of_property_read_u32(np, "fifo-size", &prop) == 0) 103 103 port->fifosize = prop; 104 104 105 + /* Check for a fixed line number */ 106 + ret = of_alias_get_id(np, "serial"); 107 + if (ret >= 0) 108 + port->line = ret; 109 + 105 110 port->irq = irq_of_parse_and_map(np, 0); 106 111 port->iotype = UPIO_MEM; 107 112 if (of_property_read_u32(np, "reg-io-width", &prop) == 0) { ··· 132 127 133 128 if (of_find_property(np, "no-loopback-test", NULL)) 134 129 port->flags |= UPF_SKIP_TEST; 130 + 131 + ret = of_alias_get_id(np, "serial"); 132 + if (ret >= 0) 133 + port->line = ret; 135 134 136 135 port->dev = &ofdev->dev; 137 136 ··· 340 331 .data = (void *)PORT_ALTR_16550_F64, }, 341 332 { .compatible = "altr,16550-FIFO128", 342 333 .data = (void *)PORT_ALTR_16550_F128, }, 334 + { .compatible = "mrvl,mmp-uart", 335 + .data = (void *)PORT_XSCALE, }, 336 + { .compatible = "mrvl,pxa-uart", 337 + .data = (void *)PORT_XSCALE, }, 343 338 #ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL 344 339 { .compatible = "ibm,qpace-nwp-serial", 345 340 .data = (void *)PORT_NWPSERIAL, },
+24 -13
drivers/tty/serial/omap-serial.c
··· 63 63 #define UART_ERRATA_i202_MDR1_ACCESS BIT(0) 64 64 #define UART_ERRATA_i291_DMA_FORCEIDLE BIT(1) 65 65 66 - #define DEFAULT_CLK_SPEED 48000000 /* 48Mhz*/ 66 + #define DEFAULT_CLK_SPEED 48000000 /* 48Mhz */ 67 67 68 68 /* SCR register bitmasks */ 69 69 #define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7) ··· 93 93 /* WER = 0x7F 94 94 * Enable module level wakeup in WER reg 95 95 */ 96 - #define OMAP_UART_WER_MOD_WKUP 0X7F 96 + #define OMAP_UART_WER_MOD_WKUP 0x7F 97 97 98 98 /* Enable XON/XOFF flow control on output */ 99 99 #define OMAP_UART_SW_TX 0x08 ··· 114 114 dma_addr_t tx_buf_dma_phys; 115 115 unsigned int uart_base; 116 116 /* 117 - * Buffer for rx dma.It is not required for tx because the buffer 117 + * Buffer for rx dma. It is not required for tx because the buffer 118 118 * comes from port structure. 119 119 */ 120 120 unsigned char *rx_buf; ··· 151 151 int use_dma; 152 152 /* 153 153 * Some bits in registers are cleared on a read, so they must 154 - * be saved whenever the register is read but the bits will not 154 + * be saved whenever the register is read, but the bits will not 155 155 * be immediately processed. 156 156 */ 157 157 unsigned int lsr_break_flag; ··· 681 681 static void serial_omap_set_mctrl(struct uart_port *port, unsigned int mctrl) 682 682 { 683 683 struct uart_omap_port *up = to_uart_omap_port(port); 684 - unsigned char mcr = 0, old_mcr; 684 + unsigned char mcr = 0, old_mcr, lcr; 685 685 686 686 dev_dbg(up->port.dev, "serial_omap_set_mctrl+%d\n", up->port.line); 687 687 if (mctrl & TIOCM_RTS) ··· 701 701 UART_MCR_DTR | UART_MCR_RTS); 702 702 up->mcr = old_mcr | mcr; 703 703 serial_out(up, UART_MCR, up->mcr); 704 + 705 + /* Turn off autoRTS if RTS is lowered; restore autoRTS if RTS raised */ 706 + lcr = serial_in(up, UART_LCR); 707 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 708 + if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS)) 709 + up->efr |= UART_EFR_RTS; 710 + else 711 + up->efr &= UART_EFR_RTS; 712 + serial_out(up, UART_EFR, up->efr); 713 + serial_out(up, UART_LCR, lcr); 714 + 704 715 pm_runtime_mark_last_busy(up->dev); 705 716 pm_runtime_put_autosuspend(up->dev); 706 717 } ··· 767 756 * (they will be reenabled in set_termios()) 768 757 */ 769 758 serial_omap_clear_fifos(up); 770 - /* For Hardware flow control */ 771 - serial_out(up, UART_MCR, UART_MCR_RTS); 772 759 773 760 /* 774 761 * Clear the interrupt registers. ··· 1062 1053 1063 1054 serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_TRIG); 1064 1055 1065 - if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) { 1066 - /* Enable AUTORTS and AUTOCTS */ 1067 - up->efr |= UART_EFR_CTS | UART_EFR_RTS; 1056 + up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF); 1068 1057 1069 - /* Ensure MCR RTS is asserted */ 1070 - up->mcr |= UART_MCR_RTS; 1058 + if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) { 1059 + /* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ 1060 + up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; 1061 + up->efr |= UART_EFR_CTS; 1071 1062 } else { 1072 1063 /* Disable AUTORTS and AUTOCTS */ 1073 1064 up->efr &= ~(UART_EFR_CTS | UART_EFR_RTS); ··· 1090 1081 * Enable XON/XOFF flow control on output. 1091 1082 * Transmit XON1, XOFF1 1092 1083 */ 1093 - if (termios->c_iflag & IXOFF) 1084 + if (termios->c_iflag & IXOFF) { 1085 + up->port.status |= UPSTAT_AUTOXOFF; 1094 1086 up->efr |= OMAP_UART_SW_TX; 1087 + } 1095 1088 1096 1089 /* 1097 1090 * IXANY Flag:
+662 -18
drivers/tty/serial/samsung.c
··· 28 28 #define SUPPORT_SYSRQ 29 29 #endif 30 30 31 + #include <linux/dmaengine.h> 32 + #include <linux/dma-mapping.h> 33 + #include <linux/slab.h> 31 34 #include <linux/module.h> 32 35 #include <linux/ioport.h> 33 36 #include <linux/io.h> ··· 81 78 #define S3C24XX_SERIAL_MAJOR 204 82 79 #define S3C24XX_SERIAL_MINOR 64 83 80 81 + #define S3C24XX_TX_PIO 1 82 + #define S3C24XX_TX_DMA 2 83 + #define S3C24XX_RX_PIO 1 84 + #define S3C24XX_RX_DMA 2 84 85 /* macros to change one thing to another */ 85 86 86 87 #define tx_enabled(port) ((port)->unused[0]) ··· 161 154 static void s3c24xx_serial_stop_tx(struct uart_port *port) 162 155 { 163 156 struct s3c24xx_uart_port *ourport = to_ourport(port); 157 + struct s3c24xx_uart_dma *dma = ourport->dma; 158 + struct circ_buf *xmit = &port->state->xmit; 159 + struct dma_tx_state state; 160 + int count; 164 161 165 - if (tx_enabled(port)) { 166 - if (s3c24xx_serial_has_interrupt_mask(port)) 167 - __set_bit(S3C64XX_UINTM_TXD, 168 - portaddrl(port, S3C64XX_UINTM)); 169 - else 170 - disable_irq_nosync(ourport->tx_irq); 171 - tx_enabled(port) = 0; 172 - if (port->flags & UPF_CONS_FLOW) 173 - s3c24xx_serial_rx_enable(port); 162 + if (!tx_enabled(port)) 163 + return; 164 + 165 + if (s3c24xx_serial_has_interrupt_mask(port)) 166 + __set_bit(S3C64XX_UINTM_TXD, 167 + portaddrl(port, S3C64XX_UINTM)); 168 + else 169 + disable_irq_nosync(ourport->tx_irq); 170 + 171 + if (dma && dma->tx_chan && ourport->tx_in_progress == S3C24XX_TX_DMA) { 172 + dmaengine_pause(dma->tx_chan); 173 + dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state); 174 + dmaengine_terminate_all(dma->tx_chan); 175 + dma_sync_single_for_cpu(ourport->port.dev, 176 + dma->tx_transfer_addr, dma->tx_size, DMA_TO_DEVICE); 177 + async_tx_ack(dma->tx_desc); 178 + count = dma->tx_bytes_requested - state.residue; 179 + xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); 180 + port->icount.tx += count; 174 181 } 182 + 183 + tx_enabled(port) = 0; 184 + ourport->tx_in_progress = 0; 185 + 186 + if (port->flags & UPF_CONS_FLOW) 187 + s3c24xx_serial_rx_enable(port); 188 + 189 + ourport->tx_mode = 0; 175 190 } 176 191 177 - static void s3c24xx_serial_start_tx(struct uart_port *port) 192 + static void s3c24xx_serial_start_next_tx(struct s3c24xx_uart_port *ourport); 193 + 194 + static void s3c24xx_serial_tx_dma_complete(void *args) 195 + { 196 + struct s3c24xx_uart_port *ourport = args; 197 + struct uart_port *port = &ourport->port; 198 + struct circ_buf *xmit = &port->state->xmit; 199 + struct s3c24xx_uart_dma *dma = ourport->dma; 200 + struct dma_tx_state state; 201 + unsigned long flags; 202 + int count; 203 + 204 + 205 + dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state); 206 + count = dma->tx_bytes_requested - state.residue; 207 + async_tx_ack(dma->tx_desc); 208 + 209 + dma_sync_single_for_cpu(ourport->port.dev, dma->tx_transfer_addr, 210 + dma->tx_size, DMA_TO_DEVICE); 211 + 212 + spin_lock_irqsave(&port->lock, flags); 213 + 214 + xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); 215 + port->icount.tx += count; 216 + ourport->tx_in_progress = 0; 217 + 218 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 219 + uart_write_wakeup(port); 220 + 221 + s3c24xx_serial_start_next_tx(ourport); 222 + spin_unlock_irqrestore(&port->lock, flags); 223 + } 224 + 225 + static void enable_tx_dma(struct s3c24xx_uart_port *ourport) 226 + { 227 + struct uart_port *port = &ourport->port; 228 + u32 ucon; 229 + 230 + /* Mask Tx interrupt */ 231 + if (s3c24xx_serial_has_interrupt_mask(port)) 232 + __set_bit(S3C64XX_UINTM_TXD, 233 + portaddrl(port, S3C64XX_UINTM)); 234 + else 235 + disable_irq_nosync(ourport->tx_irq); 236 + 237 + /* Enable tx dma mode */ 238 + ucon = rd_regl(port, S3C2410_UCON); 239 + ucon &= ~(S3C64XX_UCON_TXBURST_MASK | S3C64XX_UCON_TXMODE_MASK); 240 + ucon |= (dma_get_cache_alignment() >= 16) ? 241 + S3C64XX_UCON_TXBURST_16 : S3C64XX_UCON_TXBURST_1; 242 + ucon |= S3C64XX_UCON_TXMODE_DMA; 243 + wr_regl(port, S3C2410_UCON, ucon); 244 + 245 + ourport->tx_mode = S3C24XX_TX_DMA; 246 + } 247 + 248 + static void enable_tx_pio(struct s3c24xx_uart_port *ourport) 249 + { 250 + struct uart_port *port = &ourport->port; 251 + u32 ucon, ufcon; 252 + 253 + /* Set ufcon txtrig */ 254 + ourport->tx_in_progress = S3C24XX_TX_PIO; 255 + ufcon = rd_regl(port, S3C2410_UFCON); 256 + wr_regl(port, S3C2410_UFCON, ufcon); 257 + 258 + /* Enable tx pio mode */ 259 + ucon = rd_regl(port, S3C2410_UCON); 260 + ucon &= ~(S3C64XX_UCON_TXMODE_MASK); 261 + ucon |= S3C64XX_UCON_TXMODE_CPU; 262 + wr_regl(port, S3C2410_UCON, ucon); 263 + 264 + /* Unmask Tx interrupt */ 265 + if (s3c24xx_serial_has_interrupt_mask(port)) 266 + __clear_bit(S3C64XX_UINTM_TXD, 267 + portaddrl(port, S3C64XX_UINTM)); 268 + else 269 + enable_irq(ourport->tx_irq); 270 + 271 + ourport->tx_mode = S3C24XX_TX_PIO; 272 + } 273 + 274 + static void s3c24xx_serial_start_tx_pio(struct s3c24xx_uart_port *ourport) 275 + { 276 + if (ourport->tx_mode != S3C24XX_TX_PIO) 277 + enable_tx_pio(ourport); 278 + } 279 + 280 + static int s3c24xx_serial_start_tx_dma(struct s3c24xx_uart_port *ourport, 281 + unsigned int count) 282 + { 283 + struct uart_port *port = &ourport->port; 284 + struct circ_buf *xmit = &port->state->xmit; 285 + struct s3c24xx_uart_dma *dma = ourport->dma; 286 + 287 + 288 + if (ourport->tx_mode != S3C24XX_TX_DMA) 289 + enable_tx_dma(ourport); 290 + 291 + while (xmit->tail & (dma_get_cache_alignment() - 1)) { 292 + if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull) 293 + return 0; 294 + wr_regb(port, S3C2410_UTXH, xmit->buf[xmit->tail]); 295 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 296 + port->icount.tx++; 297 + count--; 298 + } 299 + 300 + dma->tx_size = count & ~(dma_get_cache_alignment() - 1); 301 + dma->tx_transfer_addr = dma->tx_addr + xmit->tail; 302 + 303 + dma_sync_single_for_device(ourport->port.dev, dma->tx_transfer_addr, 304 + dma->tx_size, DMA_TO_DEVICE); 305 + 306 + dma->tx_desc = dmaengine_prep_slave_single(dma->tx_chan, 307 + dma->tx_transfer_addr, dma->tx_size, 308 + DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT); 309 + if (!dma->tx_desc) { 310 + dev_err(ourport->port.dev, "Unable to get desc for Tx\n"); 311 + return -EIO; 312 + } 313 + 314 + dma->tx_desc->callback = s3c24xx_serial_tx_dma_complete; 315 + dma->tx_desc->callback_param = ourport; 316 + dma->tx_bytes_requested = dma->tx_size; 317 + 318 + ourport->tx_in_progress = S3C24XX_TX_DMA; 319 + dma->tx_cookie = dmaengine_submit(dma->tx_desc); 320 + dma_async_issue_pending(dma->tx_chan); 321 + return 0; 322 + } 323 + 324 + static void s3c24xx_serial_start_next_tx(struct s3c24xx_uart_port *ourport) 325 + { 326 + struct uart_port *port = &ourport->port; 327 + struct circ_buf *xmit = &port->state->xmit; 328 + unsigned long count; 329 + 330 + /* Get data size up to the end of buffer */ 331 + count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); 332 + 333 + if (!count) { 334 + s3c24xx_serial_stop_tx(port); 335 + return; 336 + } 337 + 338 + if (!ourport->dma || !ourport->dma->tx_chan || count < port->fifosize) 339 + s3c24xx_serial_start_tx_pio(ourport); 340 + else 341 + s3c24xx_serial_start_tx_dma(ourport, count); 342 + } 343 + 344 + void s3c24xx_serial_start_tx(struct uart_port *port) 178 345 { 179 346 struct s3c24xx_uart_port *ourport = to_ourport(port); 347 + struct circ_buf *xmit = &port->state->xmit; 180 348 181 349 if (!tx_enabled(port)) { 182 350 if (port->flags & UPF_CONS_FLOW) 183 351 s3c24xx_serial_rx_disable(port); 184 352 185 - if (s3c24xx_serial_has_interrupt_mask(port)) 186 - __clear_bit(S3C64XX_UINTM_TXD, 187 - portaddrl(port, S3C64XX_UINTM)); 188 - else 189 - enable_irq(ourport->tx_irq); 190 353 tx_enabled(port) = 1; 354 + if (!ourport->dma || !ourport->dma->tx_chan) 355 + s3c24xx_serial_start_tx_pio(ourport); 191 356 } 357 + 358 + if (ourport->dma && ourport->dma->tx_chan) { 359 + if (!uart_circ_empty(xmit) && !ourport->tx_in_progress) 360 + s3c24xx_serial_start_next_tx(ourport); 361 + } 362 + } 363 + 364 + static void s3c24xx_uart_copy_rx_to_tty(struct s3c24xx_uart_port *ourport, 365 + struct tty_port *tty, int count) 366 + { 367 + struct s3c24xx_uart_dma *dma = ourport->dma; 368 + int copied; 369 + 370 + if (!count) 371 + return; 372 + 373 + dma_sync_single_for_cpu(ourport->port.dev, dma->rx_addr, 374 + dma->rx_size, DMA_FROM_DEVICE); 375 + 376 + ourport->port.icount.rx += count; 377 + if (!tty) { 378 + dev_err(ourport->port.dev, "No tty port\n"); 379 + return; 380 + } 381 + copied = tty_insert_flip_string(tty, 382 + ((unsigned char *)(ourport->dma->rx_buf)), count); 383 + if (copied != count) { 384 + WARN_ON(1); 385 + dev_err(ourport->port.dev, "RxData copy to tty layer failed\n"); 386 + } 387 + } 388 + 389 + static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport, 390 + unsigned long ufstat); 391 + 392 + static void uart_rx_drain_fifo(struct s3c24xx_uart_port *ourport) 393 + { 394 + struct uart_port *port = &ourport->port; 395 + struct tty_port *tty = &port->state->port; 396 + unsigned int ch, ufstat; 397 + unsigned int count; 398 + 399 + ufstat = rd_regl(port, S3C2410_UFSTAT); 400 + count = s3c24xx_serial_rx_fifocnt(ourport, ufstat); 401 + 402 + if (!count) 403 + return; 404 + 405 + while (count-- > 0) { 406 + ch = rd_regb(port, S3C2410_URXH); 407 + 408 + ourport->port.icount.rx++; 409 + tty_insert_flip_char(tty, ch, TTY_NORMAL); 410 + } 411 + 412 + tty_flip_buffer_push(tty); 192 413 } 193 414 194 415 static void s3c24xx_serial_stop_rx(struct uart_port *port) 195 416 { 196 417 struct s3c24xx_uart_port *ourport = to_ourport(port); 418 + struct s3c24xx_uart_dma *dma = ourport->dma; 419 + struct tty_port *t = &port->state->port; 420 + struct dma_tx_state state; 421 + enum dma_status dma_status; 422 + unsigned int received; 197 423 198 424 if (rx_enabled(port)) { 199 425 dbg("s3c24xx_serial_stop_rx: port=%p\n", port); ··· 436 196 else 437 197 disable_irq_nosync(ourport->rx_irq); 438 198 rx_enabled(port) = 0; 199 + } 200 + if (dma && dma->rx_chan) { 201 + dmaengine_pause(dma->tx_chan); 202 + dma_status = dmaengine_tx_status(dma->rx_chan, 203 + dma->rx_cookie, &state); 204 + if (dma_status == DMA_IN_PROGRESS || 205 + dma_status == DMA_PAUSED) { 206 + received = dma->rx_bytes_requested - state.residue; 207 + dmaengine_terminate_all(dma->rx_chan); 208 + s3c24xx_uart_copy_rx_to_tty(ourport, t, received); 209 + } 439 210 } 440 211 } 441 212 ··· 479 228 return (ufstat & info->rx_fifomask) >> info->rx_fifoshift; 480 229 } 481 230 231 + static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport); 232 + static void s3c24xx_serial_rx_dma_complete(void *args) 233 + { 234 + struct s3c24xx_uart_port *ourport = args; 235 + struct uart_port *port = &ourport->port; 236 + 237 + struct s3c24xx_uart_dma *dma = ourport->dma; 238 + struct tty_port *t = &port->state->port; 239 + struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port); 240 + 241 + struct dma_tx_state state; 242 + unsigned long flags; 243 + int received; 244 + 245 + dmaengine_tx_status(dma->rx_chan, dma->rx_cookie, &state); 246 + received = dma->rx_bytes_requested - state.residue; 247 + async_tx_ack(dma->rx_desc); 248 + 249 + spin_lock_irqsave(&port->lock, flags); 250 + 251 + if (received) 252 + s3c24xx_uart_copy_rx_to_tty(ourport, t, received); 253 + 254 + if (tty) { 255 + tty_flip_buffer_push(t); 256 + tty_kref_put(tty); 257 + } 258 + 259 + s3c64xx_start_rx_dma(ourport); 260 + 261 + spin_unlock_irqrestore(&port->lock, flags); 262 + } 263 + 264 + static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport) 265 + { 266 + struct s3c24xx_uart_dma *dma = ourport->dma; 267 + 268 + dma_sync_single_for_device(ourport->port.dev, dma->rx_addr, 269 + dma->rx_size, DMA_FROM_DEVICE); 270 + 271 + dma->rx_desc = dmaengine_prep_slave_single(dma->rx_chan, 272 + dma->rx_addr, dma->rx_size, DMA_DEV_TO_MEM, 273 + DMA_PREP_INTERRUPT); 274 + if (!dma->rx_desc) { 275 + dev_err(ourport->port.dev, "Unable to get desc for Rx\n"); 276 + return; 277 + } 278 + 279 + dma->rx_desc->callback = s3c24xx_serial_rx_dma_complete; 280 + dma->rx_desc->callback_param = ourport; 281 + dma->rx_bytes_requested = dma->rx_size; 282 + 283 + dma->rx_cookie = dmaengine_submit(dma->rx_desc); 284 + dma_async_issue_pending(dma->rx_chan); 285 + } 482 286 483 287 /* ? - where has parity gone?? */ 484 288 #define S3C2410_UERSTAT_PARITY (0x1000) 485 289 486 - static irqreturn_t 487 - s3c24xx_serial_rx_chars(int irq, void *dev_id) 290 + static void enable_rx_dma(struct s3c24xx_uart_port *ourport) 291 + { 292 + struct uart_port *port = &ourport->port; 293 + unsigned int ucon; 294 + 295 + /* set Rx mode to DMA mode */ 296 + ucon = rd_regl(port, S3C2410_UCON); 297 + ucon &= ~(S3C64XX_UCON_RXBURST_MASK | 298 + S3C64XX_UCON_TIMEOUT_MASK | 299 + S3C64XX_UCON_EMPTYINT_EN | 300 + S3C64XX_UCON_DMASUS_EN | 301 + S3C64XX_UCON_TIMEOUT_EN | 302 + S3C64XX_UCON_RXMODE_MASK); 303 + ucon |= S3C64XX_UCON_RXBURST_16 | 304 + 0xf << S3C64XX_UCON_TIMEOUT_SHIFT | 305 + S3C64XX_UCON_EMPTYINT_EN | 306 + S3C64XX_UCON_TIMEOUT_EN | 307 + S3C64XX_UCON_RXMODE_DMA; 308 + wr_regl(port, S3C2410_UCON, ucon); 309 + 310 + ourport->rx_mode = S3C24XX_RX_DMA; 311 + } 312 + 313 + static void enable_rx_pio(struct s3c24xx_uart_port *ourport) 314 + { 315 + struct uart_port *port = &ourport->port; 316 + unsigned int ucon; 317 + 318 + /* set Rx mode to DMA mode */ 319 + ucon = rd_regl(port, S3C2410_UCON); 320 + ucon &= ~(S3C64XX_UCON_TIMEOUT_MASK | 321 + S3C64XX_UCON_EMPTYINT_EN | 322 + S3C64XX_UCON_DMASUS_EN | 323 + S3C64XX_UCON_TIMEOUT_EN | 324 + S3C64XX_UCON_RXMODE_MASK); 325 + ucon |= 0xf << S3C64XX_UCON_TIMEOUT_SHIFT | 326 + S3C64XX_UCON_TIMEOUT_EN | 327 + S3C64XX_UCON_RXMODE_CPU; 328 + wr_regl(port, S3C2410_UCON, ucon); 329 + 330 + ourport->rx_mode = S3C24XX_RX_PIO; 331 + } 332 + 333 + static irqreturn_t s3c24xx_serial_rx_chars_dma(int irq, void *dev_id) 334 + { 335 + unsigned int utrstat, ufstat, received; 336 + struct s3c24xx_uart_port *ourport = dev_id; 337 + struct uart_port *port = &ourport->port; 338 + struct s3c24xx_uart_dma *dma = ourport->dma; 339 + struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port); 340 + struct tty_port *t = &port->state->port; 341 + unsigned long flags; 342 + struct dma_tx_state state; 343 + 344 + utrstat = rd_regl(port, S3C2410_UTRSTAT); 345 + ufstat = rd_regl(port, S3C2410_UFSTAT); 346 + 347 + spin_lock_irqsave(&port->lock, flags); 348 + 349 + if (!(utrstat & S3C2410_UTRSTAT_TIMEOUT)) { 350 + s3c64xx_start_rx_dma(ourport); 351 + if (ourport->rx_mode == S3C24XX_RX_PIO) 352 + enable_rx_dma(ourport); 353 + goto finish; 354 + } 355 + 356 + if (ourport->rx_mode == S3C24XX_RX_DMA) { 357 + dmaengine_pause(dma->rx_chan); 358 + dmaengine_tx_status(dma->rx_chan, dma->rx_cookie, &state); 359 + dmaengine_terminate_all(dma->rx_chan); 360 + received = dma->rx_bytes_requested - state.residue; 361 + s3c24xx_uart_copy_rx_to_tty(ourport, t, received); 362 + 363 + enable_rx_pio(ourport); 364 + } 365 + 366 + uart_rx_drain_fifo(ourport); 367 + 368 + if (tty) { 369 + tty_flip_buffer_push(t); 370 + tty_kref_put(tty); 371 + } 372 + 373 + wr_regl(port, S3C2410_UTRSTAT, S3C2410_UTRSTAT_TIMEOUT); 374 + 375 + finish: 376 + spin_unlock_irqrestore(&port->lock, flags); 377 + 378 + return IRQ_HANDLED; 379 + } 380 + 381 + static irqreturn_t s3c24xx_serial_rx_chars_pio(int irq, void *dev_id) 488 382 { 489 383 struct s3c24xx_uart_port *ourport = dev_id; 490 384 struct uart_port *port = &ourport->port; ··· 720 324 return IRQ_HANDLED; 721 325 } 722 326 327 + 328 + static irqreturn_t s3c24xx_serial_rx_chars(int irq, void *dev_id) 329 + { 330 + struct s3c24xx_uart_port *ourport = dev_id; 331 + 332 + if (ourport->dma && ourport->dma->rx_chan) 333 + return s3c24xx_serial_rx_chars_dma(irq, dev_id); 334 + return s3c24xx_serial_rx_chars_pio(irq, dev_id); 335 + } 336 + 723 337 static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id) 724 338 { 725 339 struct s3c24xx_uart_port *ourport = id; 726 340 struct uart_port *port = &ourport->port; 727 341 struct circ_buf *xmit = &port->state->xmit; 728 342 unsigned long flags; 729 - int count = port->fifosize; 343 + int count; 730 344 731 345 spin_lock_irqsave(&port->lock, flags); 346 + 347 + count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); 348 + 349 + if (ourport->dma && ourport->dma->tx_chan && count >= port->fifosize) { 350 + s3c24xx_serial_start_tx_dma(ourport, count); 351 + goto out; 352 + } 732 353 733 354 if (port->x_char) { 734 355 wr_regb(port, S3C2410_UTXH, port->x_char); ··· 765 352 766 353 /* try and drain the buffer... */ 767 354 355 + count = port->fifosize; 768 356 while (!uart_circ_empty(xmit) && count-- > 0) { 769 357 if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull) 770 358 break; ··· 867 453 spin_unlock_irqrestore(&port->lock, flags); 868 454 } 869 455 456 + static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p) 457 + { 458 + struct s3c24xx_uart_dma *dma = p->dma; 459 + dma_cap_mask_t mask; 460 + unsigned long flags; 461 + 462 + /* Default slave configuration parameters */ 463 + dma->rx_conf.direction = DMA_DEV_TO_MEM; 464 + dma->rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 465 + dma->rx_conf.src_addr = p->port.mapbase + S3C2410_URXH; 466 + dma->rx_conf.src_maxburst = 16; 467 + 468 + dma->tx_conf.direction = DMA_MEM_TO_DEV; 469 + dma->tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 470 + dma->tx_conf.dst_addr = p->port.mapbase + S3C2410_UTXH; 471 + if (dma_get_cache_alignment() >= 16) 472 + dma->tx_conf.dst_maxburst = 16; 473 + else 474 + dma->tx_conf.dst_maxburst = 1; 475 + 476 + dma_cap_zero(mask); 477 + dma_cap_set(DMA_SLAVE, mask); 478 + 479 + dma->rx_chan = dma_request_slave_channel_compat(mask, dma->fn, 480 + dma->rx_param, p->port.dev, "rx"); 481 + if (!dma->rx_chan) 482 + return -ENODEV; 483 + 484 + dmaengine_slave_config(dma->rx_chan, &dma->rx_conf); 485 + 486 + dma->tx_chan = dma_request_slave_channel_compat(mask, dma->fn, 487 + dma->tx_param, p->port.dev, "tx"); 488 + if (!dma->tx_chan) { 489 + dma_release_channel(dma->rx_chan); 490 + return -ENODEV; 491 + } 492 + 493 + dmaengine_slave_config(dma->tx_chan, &dma->tx_conf); 494 + 495 + /* RX buffer */ 496 + dma->rx_size = PAGE_SIZE; 497 + 498 + dma->rx_buf = kmalloc(dma->rx_size, GFP_KERNEL); 499 + 500 + if (!dma->rx_buf) { 501 + dma_release_channel(dma->rx_chan); 502 + dma_release_channel(dma->tx_chan); 503 + return -ENOMEM; 504 + } 505 + 506 + dma->rx_addr = dma_map_single(dma->rx_chan->device->dev, dma->rx_buf, 507 + dma->rx_size, DMA_FROM_DEVICE); 508 + 509 + spin_lock_irqsave(&p->port.lock, flags); 510 + 511 + /* TX buffer */ 512 + dma->tx_addr = dma_map_single(dma->tx_chan->device->dev, 513 + p->port.state->xmit.buf, 514 + UART_XMIT_SIZE, DMA_TO_DEVICE); 515 + 516 + spin_unlock_irqrestore(&p->port.lock, flags); 517 + 518 + return 0; 519 + } 520 + 521 + static void s3c24xx_serial_release_dma(struct s3c24xx_uart_port *p) 522 + { 523 + struct s3c24xx_uart_dma *dma = p->dma; 524 + 525 + if (dma->rx_chan) { 526 + dmaengine_terminate_all(dma->rx_chan); 527 + dma_unmap_single(dma->rx_chan->device->dev, dma->rx_addr, 528 + dma->rx_size, DMA_FROM_DEVICE); 529 + kfree(dma->rx_buf); 530 + dma_release_channel(dma->rx_chan); 531 + dma->rx_chan = NULL; 532 + } 533 + 534 + if (dma->tx_chan) { 535 + dmaengine_terminate_all(dma->tx_chan); 536 + dma_unmap_single(dma->tx_chan->device->dev, dma->tx_addr, 537 + UART_XMIT_SIZE, DMA_TO_DEVICE); 538 + dma_release_channel(dma->tx_chan); 539 + dma->tx_chan = NULL; 540 + } 541 + } 542 + 870 543 static void s3c24xx_serial_shutdown(struct uart_port *port) 871 544 { 872 545 struct s3c24xx_uart_port *ourport = to_ourport(port); ··· 979 478 wr_regl(port, S3C64XX_UINTP, 0xf); 980 479 wr_regl(port, S3C64XX_UINTM, 0xf); 981 480 } 481 + 482 + if (ourport->dma) 483 + s3c24xx_serial_release_dma(ourport); 484 + 485 + ourport->tx_in_progress = 0; 982 486 } 983 487 984 488 static int s3c24xx_serial_startup(struct uart_port *port) ··· 1035 529 static int s3c64xx_serial_startup(struct uart_port *port) 1036 530 { 1037 531 struct s3c24xx_uart_port *ourport = to_ourport(port); 532 + unsigned long flags; 533 + unsigned int ufcon; 1038 534 int ret; 1039 535 1040 536 dbg("s3c64xx_serial_startup: port=%p (%08llx,%p)\n", 1041 537 port, (unsigned long long)port->mapbase, port->membase); 1042 538 1043 539 wr_regl(port, S3C64XX_UINTM, 0xf); 540 + if (ourport->dma) { 541 + ret = s3c24xx_serial_request_dma(ourport); 542 + if (ret < 0) { 543 + dev_warn(port->dev, "DMA request failed\n"); 544 + return ret; 545 + } 546 + } 1044 547 1045 548 ret = request_irq(port->irq, s3c64xx_serial_handle_irq, IRQF_SHARED, 1046 549 s3c24xx_serial_portname(port), ourport); ··· 1064 549 tx_enabled(port) = 0; 1065 550 ourport->tx_claimed = 1; 1066 551 552 + spin_lock_irqsave(&port->lock, flags); 553 + 554 + ufcon = rd_regl(port, S3C2410_UFCON); 555 + ufcon |= S3C2410_UFCON_RESETRX | S3C2410_UFCON_RESETTX | 556 + S5PV210_UFCON_RXTRIG8; 557 + wr_regl(port, S3C2410_UFCON, ufcon); 558 + 559 + enable_rx_pio(ourport); 560 + 561 + spin_unlock_irqrestore(&port->lock, flags); 562 + 1067 563 /* Enable Rx Interrupt */ 1068 564 __clear_bit(S3C64XX_UINTM_RXD, portaddrl(port, S3C64XX_UINTM)); 565 + 1069 566 dbg("s3c64xx_serial_startup ok\n"); 1070 567 return ret; 1071 568 } ··· 1736 1209 ret = platform_get_irq(platdev, 1); 1737 1210 if (ret > 0) 1738 1211 ourport->tx_irq = ret; 1212 + /* 1213 + * DMA is currently supported only on DT platforms, if DMA properties 1214 + * are specified. 1215 + */ 1216 + if (platdev->dev.of_node && of_find_property(platdev->dev.of_node, 1217 + "dmas", NULL)) { 1218 + ourport->dma = devm_kzalloc(port->dev, 1219 + sizeof(*ourport->dma), 1220 + GFP_KERNEL); 1221 + if (!ourport->dma) 1222 + return -ENOMEM; 1223 + } 1739 1224 1740 1225 ourport->clk = clk_get(&platdev->dev, "uart"); 1741 1226 if (IS_ERR(ourport->clk)) { ··· 2395 1856 }; 2396 1857 2397 1858 module_platform_driver(samsung_serial_driver); 1859 + 1860 + #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE 1861 + /* 1862 + * Early console. 1863 + */ 1864 + 1865 + struct samsung_early_console_data { 1866 + u32 txfull_mask; 1867 + }; 1868 + 1869 + static void samsung_early_busyuart(struct uart_port *port) 1870 + { 1871 + while (!(readl(port->membase + S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXFE)) 1872 + ; 1873 + } 1874 + 1875 + static void samsung_early_busyuart_fifo(struct uart_port *port) 1876 + { 1877 + struct samsung_early_console_data *data = port->private_data; 1878 + 1879 + while (readl(port->membase + S3C2410_UFSTAT) & data->txfull_mask) 1880 + ; 1881 + } 1882 + 1883 + static void samsung_early_putc(struct uart_port *port, int c) 1884 + { 1885 + if (readl(port->membase + S3C2410_UFCON) & S3C2410_UFCON_FIFOMODE) 1886 + samsung_early_busyuart_fifo(port); 1887 + else 1888 + samsung_early_busyuart(port); 1889 + 1890 + writeb(c, port->membase + S3C2410_UTXH); 1891 + } 1892 + 1893 + static void samsung_early_write(struct console *con, const char *s, unsigned n) 1894 + { 1895 + struct earlycon_device *dev = con->data; 1896 + 1897 + uart_console_write(&dev->port, s, n, samsung_early_putc); 1898 + } 1899 + 1900 + static int __init samsung_early_console_setup(struct earlycon_device *device, 1901 + const char *opt) 1902 + { 1903 + if (!device->port.membase) 1904 + return -ENODEV; 1905 + 1906 + device->con->write = samsung_early_write; 1907 + return 0; 1908 + } 1909 + 1910 + /* S3C2410 */ 1911 + static struct samsung_early_console_data s3c2410_early_console_data = { 1912 + .txfull_mask = S3C2410_UFSTAT_TXFULL, 1913 + }; 1914 + 1915 + static int __init s3c2410_early_console_setup(struct earlycon_device *device, 1916 + const char *opt) 1917 + { 1918 + device->port.private_data = &s3c2410_early_console_data; 1919 + return samsung_early_console_setup(device, opt); 1920 + } 1921 + OF_EARLYCON_DECLARE(s3c2410, "samsung,s3c2410-uart", 1922 + s3c2410_early_console_setup); 1923 + EARLYCON_DECLARE(s3c2410, s3c2410_early_console_setup); 1924 + 1925 + /* S3C2412, S3C2440, S3C64xx */ 1926 + static struct samsung_early_console_data s3c2440_early_console_data = { 1927 + .txfull_mask = S3C2440_UFSTAT_TXFULL, 1928 + }; 1929 + 1930 + static int __init s3c2440_early_console_setup(struct earlycon_device *device, 1931 + const char *opt) 1932 + { 1933 + device->port.private_data = &s3c2440_early_console_data; 1934 + return samsung_early_console_setup(device, opt); 1935 + } 1936 + OF_EARLYCON_DECLARE(s3c2412, "samsung,s3c2412-uart", 1937 + s3c2440_early_console_setup); 1938 + OF_EARLYCON_DECLARE(s3c2440, "samsung,s3c2440-uart", 1939 + s3c2440_early_console_setup); 1940 + OF_EARLYCON_DECLARE(s3c6400, "samsung,s3c6400-uart", 1941 + s3c2440_early_console_setup); 1942 + EARLYCON_DECLARE(s3c2412, s3c2440_early_console_setup); 1943 + EARLYCON_DECLARE(s3c2440, s3c2440_early_console_setup); 1944 + EARLYCON_DECLARE(s3c6400, s3c2440_early_console_setup); 1945 + 1946 + /* S5PV210, EXYNOS */ 1947 + static struct samsung_early_console_data s5pv210_early_console_data = { 1948 + .txfull_mask = S5PV210_UFSTAT_TXFULL, 1949 + }; 1950 + 1951 + static int __init s5pv210_early_console_setup(struct earlycon_device *device, 1952 + const char *opt) 1953 + { 1954 + device->port.private_data = &s5pv210_early_console_data; 1955 + return samsung_early_console_setup(device, opt); 1956 + } 1957 + OF_EARLYCON_DECLARE(s5pv210, "samsung,s5pv210-uart", 1958 + s5pv210_early_console_setup); 1959 + OF_EARLYCON_DECLARE(exynos4210, "samsung,exynos4210-uart", 1960 + s5pv210_early_console_setup); 1961 + EARLYCON_DECLARE(s5pv210, s5pv210_early_console_setup); 1962 + EARLYCON_DECLARE(exynos4210, s5pv210_early_console_setup); 1963 + #endif 2398 1964 2399 1965 MODULE_ALIAS("platform:samsung-uart"); 2400 1966 MODULE_DESCRIPTION("Samsung SoC Serial port driver");
+42
drivers/tty/serial/samsung.h
··· 12 12 * published by the Free Software Foundation. 13 13 */ 14 14 15 + #include <linux/dmaengine.h> 16 + 15 17 struct s3c24xx_uart_info { 16 18 char *name; 17 19 unsigned int type; ··· 43 41 unsigned int fifosize[CONFIG_SERIAL_SAMSUNG_UARTS]; 44 42 }; 45 43 44 + struct s3c24xx_uart_dma { 45 + dma_filter_fn fn; 46 + void *rx_param; 47 + void *tx_param; 48 + 49 + unsigned int rx_chan_id; 50 + unsigned int tx_chan_id; 51 + 52 + struct dma_slave_config rx_conf; 53 + struct dma_slave_config tx_conf; 54 + 55 + struct dma_chan *rx_chan; 56 + struct dma_chan *tx_chan; 57 + 58 + dma_addr_t rx_addr; 59 + dma_addr_t tx_addr; 60 + 61 + dma_cookie_t rx_cookie; 62 + dma_cookie_t tx_cookie; 63 + 64 + char *rx_buf; 65 + 66 + dma_addr_t tx_transfer_addr; 67 + 68 + size_t rx_size; 69 + size_t tx_size; 70 + 71 + struct dma_async_tx_descriptor *tx_desc; 72 + struct dma_async_tx_descriptor *rx_desc; 73 + 74 + int tx_bytes_requested; 75 + int rx_bytes_requested; 76 + }; 77 + 46 78 struct s3c24xx_uart_port { 47 79 unsigned char rx_claimed; 48 80 unsigned char tx_claimed; ··· 86 50 unsigned int rx_irq; 87 51 unsigned int tx_irq; 88 52 53 + unsigned int tx_in_progress; 54 + unsigned int tx_mode; 55 + unsigned int rx_mode; 56 + 89 57 struct s3c24xx_uart_info *info; 90 58 struct clk *clk; 91 59 struct clk *baudclk; ··· 98 58 99 59 /* reference to platform data */ 100 60 struct s3c2410_uartcfg *cfg; 61 + 62 + struct s3c24xx_uart_dma *dma; 101 63 102 64 #ifdef CONFIG_CPU_FREQ 103 65 struct notifier_block freq_transition;
+45 -64
drivers/tty/serial/serial_core.c
··· 179 179 if (tty->termios.c_cflag & CBAUD) 180 180 uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR); 181 181 } 182 - 183 - spin_lock_irq(&uport->lock); 184 - if (uart_cts_enabled(uport) && 185 - !(uport->ops->get_mctrl(uport) & TIOCM_CTS)) 186 - uport->hw_stopped = 1; 187 - else 188 - uport->hw_stopped = 0; 189 - spin_unlock_irq(&uport->lock); 190 182 } 191 183 192 184 /* ··· 434 442 { 435 443 struct uart_port *uport = state->uart_port; 436 444 struct ktermios *termios; 445 + int hw_stopped; 437 446 438 447 /* 439 448 * If we have no tty, termios, or the port does not exist, ··· 459 466 uport->status &= ~UPSTAT_DCD_ENABLE; 460 467 else 461 468 uport->status |= UPSTAT_DCD_ENABLE; 469 + 470 + /* reset sw-assisted CTS flow control based on (possibly) new mode */ 471 + hw_stopped = uport->hw_stopped; 472 + uport->hw_stopped = uart_softcts_mode(uport) && 473 + !(uport->ops->get_mctrl(uport) & TIOCM_CTS); 474 + if (uport->hw_stopped) { 475 + if (!hw_stopped) 476 + uport->ops->stop_tx(uport); 477 + } else { 478 + if (hw_stopped) 479 + __uart_start(tty); 480 + } 462 481 spin_unlock_irq(&uport->lock); 463 482 } 464 483 ··· 624 619 { 625 620 struct uart_state *state = tty->driver_data; 626 621 struct uart_port *port = state->uart_port; 627 - upf_t mask = 0; 622 + upstat_t mask = 0; 628 623 629 624 if (I_IXOFF(tty)) 630 - mask |= UPF_SOFT_FLOW; 625 + mask |= UPSTAT_AUTOXOFF; 631 626 if (tty->termios.c_cflag & CRTSCTS) 632 - mask |= UPF_HARD_FLOW; 627 + mask |= UPSTAT_AUTORTS; 633 628 634 - if (port->flags & mask) { 629 + if (port->status & mask) { 635 630 port->ops->throttle(port); 636 - mask &= ~port->flags; 631 + mask &= ~port->status; 637 632 } 638 633 639 - if (mask & UPF_SOFT_FLOW) 634 + if (mask & UPSTAT_AUTOXOFF) 640 635 uart_send_xchar(tty, STOP_CHAR(tty)); 641 636 642 - if (mask & UPF_HARD_FLOW) 637 + if (mask & UPSTAT_AUTORTS) 643 638 uart_clear_mctrl(port, TIOCM_RTS); 644 639 } 645 640 ··· 647 642 { 648 643 struct uart_state *state = tty->driver_data; 649 644 struct uart_port *port = state->uart_port; 650 - upf_t mask = 0; 645 + upstat_t mask = 0; 651 646 652 647 if (I_IXOFF(tty)) 653 - mask |= UPF_SOFT_FLOW; 648 + mask |= UPSTAT_AUTOXOFF; 654 649 if (tty->termios.c_cflag & CRTSCTS) 655 - mask |= UPF_HARD_FLOW; 650 + mask |= UPSTAT_AUTORTS; 656 651 657 - if (port->flags & mask) { 652 + if (port->status & mask) { 658 653 port->ops->unthrottle(port); 659 - mask &= ~port->flags; 654 + mask &= ~port->status; 660 655 } 661 656 662 - if (mask & UPF_SOFT_FLOW) 657 + if (mask & UPSTAT_AUTOXOFF) 663 658 uart_send_xchar(tty, START_CHAR(tty)); 664 659 665 - if (mask & UPF_HARD_FLOW) 660 + if (mask & UPSTAT_AUTORTS) 666 661 uart_set_mctrl(port, TIOCM_RTS); 667 662 } 668 663 ··· 1356 1351 mask |= TIOCM_RTS; 1357 1352 uart_set_mctrl(uport, mask); 1358 1353 } 1359 - 1360 - /* 1361 - * If the port is doing h/w assisted flow control, do nothing. 1362 - * We assume that port->hw_stopped has never been set. 1363 - */ 1364 - if (uport->flags & UPF_HARD_FLOW) 1365 - return; 1366 - 1367 - /* Handle turning off CRTSCTS */ 1368 - if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) { 1369 - spin_lock_irq(&uport->lock); 1370 - uport->hw_stopped = 0; 1371 - __uart_start(tty); 1372 - spin_unlock_irq(&uport->lock); 1373 - } 1374 - /* Handle turning on CRTSCTS */ 1375 - else if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) { 1376 - spin_lock_irq(&uport->lock); 1377 - if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS)) { 1378 - uport->hw_stopped = 1; 1379 - uport->ops->stop_tx(uport); 1380 - } 1381 - spin_unlock_irq(&uport->lock); 1382 - } 1383 1354 } 1384 1355 1385 1356 /* ··· 1989 2008 } 1990 2009 put_device(tty_dev); 1991 2010 1992 - if (console_suspend_enabled || !uart_console(uport)) 1993 - uport->suspended = 1; 2011 + /* Nothing to do if the console is not suspending */ 2012 + if (!console_suspend_enabled && uart_console(uport)) 2013 + goto unlock; 2014 + 2015 + uport->suspended = 1; 1994 2016 1995 2017 if (port->flags & ASYNC_INITIALIZED) { 1996 2018 const struct uart_ops *ops = uport->ops; 1997 2019 int tries; 1998 2020 1999 - if (console_suspend_enabled || !uart_console(uport)) { 2000 - set_bit(ASYNCB_SUSPENDED, &port->flags); 2001 - clear_bit(ASYNCB_INITIALIZED, &port->flags); 2021 + set_bit(ASYNCB_SUSPENDED, &port->flags); 2022 + clear_bit(ASYNCB_INITIALIZED, &port->flags); 2002 2023 2003 - spin_lock_irq(&uport->lock); 2004 - ops->stop_tx(uport); 2005 - ops->set_mctrl(uport, 0); 2006 - ops->stop_rx(uport); 2007 - spin_unlock_irq(&uport->lock); 2008 - } 2024 + spin_lock_irq(&uport->lock); 2025 + ops->stop_tx(uport); 2026 + ops->set_mctrl(uport, 0); 2027 + ops->stop_rx(uport); 2028 + spin_unlock_irq(&uport->lock); 2009 2029 2010 2030 /* 2011 2031 * Wait for the transmitter to empty. ··· 2018 2036 drv->dev_name, 2019 2037 drv->tty_driver->name_base + uport->line); 2020 2038 2021 - if (console_suspend_enabled || !uart_console(uport)) 2022 - ops->shutdown(uport); 2039 + ops->shutdown(uport); 2023 2040 } 2024 2041 2025 2042 /* 2026 2043 * Disable the console device before suspending. 2027 2044 */ 2028 - if (console_suspend_enabled && uart_console(uport)) 2045 + if (uart_console(uport)) 2029 2046 console_stop(uport->cons); 2030 2047 2031 - if (console_suspend_enabled || !uart_console(uport)) 2032 - uart_change_pm(state, UART_PM_STATE_OFF); 2033 - 2048 + uart_change_pm(state, UART_PM_STATE_OFF); 2049 + unlock: 2034 2050 mutex_unlock(&port->mutex); 2035 2051 2036 2052 return 0; ··· 2836 2856 2837 2857 uport->icount.cts++; 2838 2858 2839 - if (uart_cts_enabled(uport)) { 2859 + if (uart_softcts_mode(uport)) { 2840 2860 if (uport->hw_stopped) { 2841 2861 if (status) { 2842 2862 uport->hw_stopped = 0; ··· 2849 2869 uport->ops->stop_tx(uport); 2850 2870 } 2851 2871 } 2872 + 2852 2873 } 2853 2874 } 2854 2875 EXPORT_SYMBOL_GPL(uart_handle_cts_change);
+17 -8
drivers/tty/serial/sh-sci.c
··· 858 858 tty_insert_flip_char(tport, 0, TTY_OVERRUN); 859 859 tty_flip_buffer_push(tport); 860 860 861 - dev_notice(port->dev, "overrun error\n"); 861 + dev_dbg(port->dev, "overrun error\n"); 862 862 copied++; 863 863 } 864 864 ··· 997 997 static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr) 998 998 { 999 999 unsigned short ssr_status, scr_status, err_enabled; 1000 + unsigned short slr_status = 0; 1000 1001 struct uart_port *port = ptr; 1001 1002 struct sci_port *s = to_sci_port(port); 1002 1003 irqreturn_t ret = IRQ_NONE; 1003 1004 1004 1005 ssr_status = serial_port_in(port, SCxSR); 1005 1006 scr_status = serial_port_in(port, SCSCR); 1007 + if (port->type == PORT_SCIF || port->type == PORT_HSCIF) 1008 + slr_status = serial_port_in(port, SCLSR); 1006 1009 err_enabled = scr_status & port_rx_irq_mask(port); 1007 1010 1008 1011 /* Tx Interrupt */ ··· 1018 1015 * DR flags 1019 1016 */ 1020 1017 if (((ssr_status & SCxSR_RDxF(port)) || s->chan_rx) && 1021 - (scr_status & SCSCR_RIE)) 1018 + (scr_status & SCSCR_RIE)) { 1019 + if (port->type == PORT_SCIF || port->type == PORT_HSCIF) 1020 + sci_handle_fifo_overrun(port); 1022 1021 ret = sci_rx_interrupt(irq, ptr); 1022 + } 1023 1023 1024 1024 /* Error Interrupt */ 1025 1025 if ((ssr_status & SCxSR_ERRORS(port)) && err_enabled) ··· 1031 1025 /* Break Interrupt */ 1032 1026 if ((ssr_status & SCxSR_BRK(port)) && err_enabled) 1033 1027 ret = sci_br_interrupt(irq, ptr); 1028 + 1029 + /* Overrun Interrupt */ 1030 + if (port->type == PORT_SCIF || port->type == PORT_HSCIF) { 1031 + if (slr_status & 0x01) 1032 + sci_handle_fifo_overrun(port); 1033 + } 1034 1034 1035 1035 return ret; 1036 1036 } ··· 2617 2605 return 0; 2618 2606 } 2619 2607 2620 - static int sci_suspend(struct device *dev) 2608 + static __maybe_unused int sci_suspend(struct device *dev) 2621 2609 { 2622 2610 struct sci_port *sport = dev_get_drvdata(dev); 2623 2611 ··· 2627 2615 return 0; 2628 2616 } 2629 2617 2630 - static int sci_resume(struct device *dev) 2618 + static __maybe_unused int sci_resume(struct device *dev) 2631 2619 { 2632 2620 struct sci_port *sport = dev_get_drvdata(dev); 2633 2621 ··· 2637 2625 return 0; 2638 2626 } 2639 2627 2640 - static const struct dev_pm_ops sci_dev_pm_ops = { 2641 - .suspend = sci_suspend, 2642 - .resume = sci_resume, 2643 - }; 2628 + static SIMPLE_DEV_PM_OPS(sci_dev_pm_ops, sci_suspend, sci_resume); 2644 2629 2645 2630 static struct platform_driver sci_driver = { 2646 2631 .probe = sci_probe,
+20 -20
drivers/tty/serial/sirfsoc_uart.c
··· 177 177 dmaengine_pause(sirfport->tx_dma_chan); 178 178 sirfport->tx_dma_state = TX_DMA_PAUSE; 179 179 } else { 180 - if (!sirfport->is_marco) 180 + if (!sirfport->is_atlas7) 181 181 wr_regl(port, ureg->sirfsoc_int_en_reg, 182 182 rd_regl(port, ureg->sirfsoc_int_en_reg) & 183 183 ~uint_en->sirfsoc_txfifo_empty_en); ··· 186 186 uint_en->sirfsoc_txfifo_empty_en); 187 187 } 188 188 } else { 189 - if (!sirfport->is_marco) 189 + if (!sirfport->is_atlas7) 190 190 wr_regl(port, ureg->sirfsoc_int_en_reg, 191 191 rd_regl(port, ureg->sirfsoc_int_en_reg) & 192 192 ~uint_en->sirfsoc_txfifo_empty_en); ··· 217 217 } 218 218 if (sirfport->tx_dma_state == TX_DMA_RUNNING) 219 219 return; 220 - if (!sirfport->is_marco) 220 + if (!sirfport->is_atlas7) 221 221 wr_regl(port, ureg->sirfsoc_int_en_reg, 222 222 rd_regl(port, ureg->sirfsoc_int_en_reg)& 223 223 ~(uint_en->sirfsoc_txfifo_empty_en)); ··· 244 244 } 245 245 if (tran_size < 4) 246 246 sirfsoc_uart_pio_tx_chars(sirfport, tran_size); 247 - if (!sirfport->is_marco) 247 + if (!sirfport->is_atlas7) 248 248 wr_regl(port, ureg->sirfsoc_int_en_reg, 249 249 rd_regl(port, ureg->sirfsoc_int_en_reg)| 250 250 uint_en->sirfsoc_txfifo_empty_en); ··· 293 293 sirfsoc_uart_pio_tx_chars(sirfport, 294 294 SIRFSOC_UART_IO_TX_REASONABLE_CNT); 295 295 wr_regl(port, ureg->sirfsoc_tx_fifo_op, SIRFUART_FIFO_START); 296 - if (!sirfport->is_marco) 296 + if (!sirfport->is_atlas7) 297 297 wr_regl(port, ureg->sirfsoc_int_en_reg, 298 298 rd_regl(port, ureg->sirfsoc_int_en_reg)| 299 299 uint_en->sirfsoc_txfifo_empty_en); ··· 311 311 312 312 wr_regl(port, ureg->sirfsoc_rx_fifo_op, 0); 313 313 if (sirfport->rx_dma_chan) { 314 - if (!sirfport->is_marco) 314 + if (!sirfport->is_atlas7) 315 315 wr_regl(port, ureg->sirfsoc_int_en_reg, 316 316 rd_regl(port, ureg->sirfsoc_int_en_reg) & 317 317 ~(SIRFUART_RX_DMA_INT_EN(port, uint_en) | ··· 322 322 uint_en->sirfsoc_rx_done_en); 323 323 dmaengine_terminate_all(sirfport->rx_dma_chan); 324 324 } else { 325 - if (!sirfport->is_marco) 325 + if (!sirfport->is_atlas7) 326 326 wr_regl(port, ureg->sirfsoc_int_en_reg, 327 327 rd_regl(port, ureg->sirfsoc_int_en_reg)& 328 328 ~(SIRFUART_RX_IO_INT_EN(port, uint_en))); ··· 344 344 if (sirfport->uart_reg->uart_type == SIRF_REAL_UART) { 345 345 wr_regl(port, ureg->sirfsoc_afc_ctrl, 346 346 rd_regl(port, ureg->sirfsoc_afc_ctrl) & ~0x3FF); 347 - if (!sirfport->is_marco) 347 + if (!sirfport->is_atlas7) 348 348 wr_regl(port, ureg->sirfsoc_int_en_reg, 349 349 rd_regl(port, ureg->sirfsoc_int_en_reg)& 350 350 ~uint_en->sirfsoc_cts_en); ··· 380 380 wr_regl(port, ureg->sirfsoc_afc_ctrl, 381 381 rd_regl(port, ureg->sirfsoc_afc_ctrl) | 382 382 SIRFUART_AFC_TX_EN | SIRFUART_AFC_RX_EN); 383 - if (!sirfport->is_marco) 383 + if (!sirfport->is_atlas7) 384 384 wr_regl(port, ureg->sirfsoc_int_en_reg, 385 385 rd_regl(port, ureg->sirfsoc_int_en_reg) 386 386 | uint_en->sirfsoc_cts_en); ··· 544 544 sirfport->rx_io_count = 0; 545 545 wr_regl(port, ureg->sirfsoc_int_st_reg, 546 546 uint_st->sirfsoc_rx_done); 547 - if (!sirfport->is_marco) 547 + if (!sirfport->is_atlas7) 548 548 wr_regl(port, ureg->sirfsoc_int_en_reg, 549 549 rd_regl(port, ureg->sirfsoc_int_en_reg) & 550 550 ~(uint_en->sirfsoc_rx_done_en)); ··· 555 555 } else { 556 556 wr_regl(port, ureg->sirfsoc_int_st_reg, 557 557 uint_st->sirfsoc_rx_done); 558 - if (!sirfport->is_marco) 558 + if (!sirfport->is_atlas7) 559 559 wr_regl(port, ureg->sirfsoc_int_en_reg, 560 560 rd_regl(port, ureg->sirfsoc_int_en_reg) | 561 561 (uint_en->sirfsoc_rx_done_en)); ··· 578 578 dmaengine_terminate_all(sirfport->rx_dma_chan); 579 579 sirfport->rx_dma_items[sirfport->rx_issued].xmit.head = 580 580 SIRFSOC_RX_DMA_BUF_SIZE - tx_state.residue; 581 - if (!sirfport->is_marco) 581 + if (!sirfport->is_atlas7) 582 582 wr_regl(port, ureg->sirfsoc_int_en_reg, 583 583 rd_regl(port, ureg->sirfsoc_int_en_reg) & 584 584 ~(uint_en->sirfsoc_rx_timeout_en)); ··· 598 598 sirfsoc_uart_pio_rx_chars(port, 4 - sirfport->rx_io_count); 599 599 if (sirfport->rx_io_count == 4) { 600 600 sirfport->rx_io_count = 0; 601 - if (!sirfport->is_marco) 601 + if (!sirfport->is_atlas7) 602 602 wr_regl(port, ureg->sirfsoc_int_en_reg, 603 603 rd_regl(port, ureg->sirfsoc_int_en_reg) & 604 604 ~(uint_en->sirfsoc_rx_done_en)); ··· 748 748 for (i = 0; i < SIRFSOC_RX_LOOP_BUF_CNT; i++) 749 749 sirfsoc_rx_submit_one_dma_desc(port, i); 750 750 sirfport->rx_completed = sirfport->rx_issued = 0; 751 - if (!sirfport->is_marco) 751 + if (!sirfport->is_atlas7) 752 752 wr_regl(port, ureg->sirfsoc_int_en_reg, 753 753 rd_regl(port, ureg->sirfsoc_int_en_reg) | 754 754 SIRFUART_RX_DMA_INT_EN(port, uint_en)); ··· 770 770 if (sirfport->rx_dma_chan) 771 771 sirfsoc_uart_start_next_rx_dma(port); 772 772 else { 773 - if (!sirfport->is_marco) 773 + if (!sirfport->is_atlas7) 774 774 wr_regl(port, ureg->sirfsoc_int_en_reg, 775 775 rd_regl(port, ureg->sirfsoc_int_en_reg) | 776 776 SIRFUART_RX_IO_INT_EN(port, uint_en)); ··· 1124 1124 { 1125 1125 struct sirfsoc_uart_port *sirfport = to_sirfport(port); 1126 1126 struct sirfsoc_register *ureg = &sirfport->uart_reg->uart_reg; 1127 - if (!sirfport->is_marco) 1127 + if (!sirfport->is_atlas7) 1128 1128 wr_regl(port, ureg->sirfsoc_int_en_reg, 0); 1129 1129 else 1130 1130 wr_regl(port, SIRFUART_INT_EN_CLR, ~0UL); ··· 1271 1271 1272 1272 static struct of_device_id sirfsoc_uart_ids[] = { 1273 1273 { .compatible = "sirf,prima2-uart", .data = &sirfsoc_uart,}, 1274 - { .compatible = "sirf,marco-uart", .data = &sirfsoc_uart}, 1274 + { .compatible = "sirf,atlas7-uart", .data = &sirfsoc_uart}, 1275 1275 { .compatible = "sirf,prima2-usp-uart", .data = &sirfsoc_usp}, 1276 1276 {} 1277 1277 }; ··· 1350 1350 gpio_direction_output(sirfport->rts_gpio, 1); 1351 1351 } 1352 1352 usp_no_flow_control: 1353 - if (of_device_is_compatible(pdev->dev.of_node, "sirf,marco-uart")) 1354 - sirfport->is_marco = true; 1353 + if (of_device_is_compatible(pdev->dev.of_node, "sirf,atlas7-uart")) 1354 + sirfport->is_atlas7 = true; 1355 1355 1356 1356 if (of_property_read_u32(pdev->dev.of_node, 1357 1357 "fifosize", ··· 1393 1393 goto err; 1394 1394 } 1395 1395 port->uartclk = clk_get_rate(sirfport->clk); 1396 - if (of_device_is_compatible(pdev->dev.of_node, "sirf,marco-bt-uart")) { 1396 + if (of_device_is_compatible(pdev->dev.of_node, "sirf,atlas7-bt-uart")) { 1397 1397 sirfport->clk_general = devm_clk_get(&pdev->dev, "general"); 1398 1398 if (IS_ERR(sirfport->clk_general)) { 1399 1399 ret = PTR_ERR(sirfport->clk_general);
+2 -2
drivers/tty/serial/sirfsoc_uart.h
··· 421 421 bool is_bt_uart; 422 422 struct clk *clk_general; 423 423 struct clk *clk_noc; 424 - /* for SiRFmarco, there are SET/CLR for UART_INT_EN */ 425 - bool is_marco; 424 + /* for SiRFatlas7, there are SET/CLR for UART_INT_EN */ 425 + bool is_atlas7; 426 426 struct sirfsoc_uart_register *uart_reg; 427 427 struct dma_chan *rx_dma_chan; 428 428 struct dma_chan *tx_dma_chan;
+793
drivers/tty/serial/sprd_serial.c
··· 1 + /* 2 + * Copyright (C) 2012-2015 Spreadtrum Communications Inc. 3 + * 4 + * This software is licensed under the terms of the GNU General Public 5 + * License version 2, as published by the Free Software Foundation, and 6 + * may be copied, distributed, and modified under those terms. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #if defined(CONFIG_SERIAL_SPRD_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 15 + #define SUPPORT_SYSRQ 16 + #endif 17 + 18 + #include <linux/clk.h> 19 + #include <linux/console.h> 20 + #include <linux/delay.h> 21 + #include <linux/io.h> 22 + #include <linux/ioport.h> 23 + #include <linux/kernel.h> 24 + #include <linux/module.h> 25 + #include <linux/of.h> 26 + #include <linux/platform_device.h> 27 + #include <linux/serial_core.h> 28 + #include <linux/serial.h> 29 + #include <linux/slab.h> 30 + #include <linux/tty.h> 31 + #include <linux/tty_flip.h> 32 + 33 + /* device name */ 34 + #define UART_NR_MAX 8 35 + #define SPRD_TTY_NAME "ttyS" 36 + #define SPRD_FIFO_SIZE 128 37 + #define SPRD_DEF_RATE 26000000 38 + #define SPRD_BAUD_IO_LIMIT 3000000 39 + #define SPRD_TIMEOUT 256 40 + 41 + /* the offset of serial registers and BITs for them */ 42 + /* data registers */ 43 + #define SPRD_TXD 0x0000 44 + #define SPRD_RXD 0x0004 45 + 46 + /* line status register and its BITs */ 47 + #define SPRD_LSR 0x0008 48 + #define SPRD_LSR_OE BIT(4) 49 + #define SPRD_LSR_FE BIT(3) 50 + #define SPRD_LSR_PE BIT(2) 51 + #define SPRD_LSR_BI BIT(7) 52 + #define SPRD_LSR_TX_OVER BIT(15) 53 + 54 + /* data number in TX and RX fifo */ 55 + #define SPRD_STS1 0x000C 56 + 57 + /* interrupt enable register and its BITs */ 58 + #define SPRD_IEN 0x0010 59 + #define SPRD_IEN_RX_FULL BIT(0) 60 + #define SPRD_IEN_TX_EMPTY BIT(1) 61 + #define SPRD_IEN_BREAK_DETECT BIT(7) 62 + #define SPRD_IEN_TIMEOUT BIT(13) 63 + 64 + /* interrupt clear register */ 65 + #define SPRD_ICLR 0x0014 66 + 67 + /* line control register */ 68 + #define SPRD_LCR 0x0018 69 + #define SPRD_LCR_STOP_1BIT 0x10 70 + #define SPRD_LCR_STOP_2BIT 0x30 71 + #define SPRD_LCR_DATA_LEN (BIT(2) | BIT(3)) 72 + #define SPRD_LCR_DATA_LEN5 0x0 73 + #define SPRD_LCR_DATA_LEN6 0x4 74 + #define SPRD_LCR_DATA_LEN7 0x8 75 + #define SPRD_LCR_DATA_LEN8 0xc 76 + #define SPRD_LCR_PARITY (BIT(0) | BIT(1)) 77 + #define SPRD_LCR_PARITY_EN 0x2 78 + #define SPRD_LCR_EVEN_PAR 0x0 79 + #define SPRD_LCR_ODD_PAR 0x1 80 + 81 + /* control register 1 */ 82 + #define SPRD_CTL1 0x001C 83 + #define RX_HW_FLOW_CTL_THLD BIT(6) 84 + #define RX_HW_FLOW_CTL_EN BIT(7) 85 + #define TX_HW_FLOW_CTL_EN BIT(8) 86 + #define RX_TOUT_THLD_DEF 0x3E00 87 + #define RX_HFC_THLD_DEF 0x40 88 + 89 + /* fifo threshold register */ 90 + #define SPRD_CTL2 0x0020 91 + #define THLD_TX_EMPTY 0x40 92 + #define THLD_RX_FULL 0x40 93 + 94 + /* config baud rate register */ 95 + #define SPRD_CLKD0 0x0024 96 + #define SPRD_CLKD1 0x0028 97 + 98 + /* interrupt mask status register */ 99 + #define SPRD_IMSR 0x002C 100 + #define SPRD_IMSR_RX_FIFO_FULL BIT(0) 101 + #define SPRD_IMSR_TX_FIFO_EMPTY BIT(1) 102 + #define SPRD_IMSR_BREAK_DETECT BIT(7) 103 + #define SPRD_IMSR_TIMEOUT BIT(13) 104 + 105 + struct reg_backup { 106 + u32 ien; 107 + u32 ctrl0; 108 + u32 ctrl1; 109 + u32 ctrl2; 110 + u32 clkd0; 111 + u32 clkd1; 112 + u32 dspwait; 113 + }; 114 + 115 + struct sprd_uart_port { 116 + struct uart_port port; 117 + struct reg_backup reg_bak; 118 + char name[16]; 119 + }; 120 + 121 + static struct sprd_uart_port *sprd_port[UART_NR_MAX]; 122 + static int sprd_ports_num; 123 + 124 + static inline unsigned int serial_in(struct uart_port *port, int offset) 125 + { 126 + return readl_relaxed(port->membase + offset); 127 + } 128 + 129 + static inline void serial_out(struct uart_port *port, int offset, int value) 130 + { 131 + writel_relaxed(value, port->membase + offset); 132 + } 133 + 134 + static unsigned int sprd_tx_empty(struct uart_port *port) 135 + { 136 + if (serial_in(port, SPRD_STS1) & 0xff00) 137 + return 0; 138 + else 139 + return TIOCSER_TEMT; 140 + } 141 + 142 + static unsigned int sprd_get_mctrl(struct uart_port *port) 143 + { 144 + return TIOCM_DSR | TIOCM_CTS; 145 + } 146 + 147 + static void sprd_set_mctrl(struct uart_port *port, unsigned int mctrl) 148 + { 149 + /* nothing to do */ 150 + } 151 + 152 + static void sprd_stop_tx(struct uart_port *port) 153 + { 154 + unsigned int ien, iclr; 155 + 156 + iclr = serial_in(port, SPRD_ICLR); 157 + ien = serial_in(port, SPRD_IEN); 158 + 159 + iclr |= SPRD_IEN_TX_EMPTY; 160 + ien &= ~SPRD_IEN_TX_EMPTY; 161 + 162 + serial_out(port, SPRD_ICLR, iclr); 163 + serial_out(port, SPRD_IEN, ien); 164 + } 165 + 166 + static void sprd_start_tx(struct uart_port *port) 167 + { 168 + unsigned int ien; 169 + 170 + ien = serial_in(port, SPRD_IEN); 171 + if (!(ien & SPRD_IEN_TX_EMPTY)) { 172 + ien |= SPRD_IEN_TX_EMPTY; 173 + serial_out(port, SPRD_IEN, ien); 174 + } 175 + } 176 + 177 + static void sprd_stop_rx(struct uart_port *port) 178 + { 179 + unsigned int ien, iclr; 180 + 181 + iclr = serial_in(port, SPRD_ICLR); 182 + ien = serial_in(port, SPRD_IEN); 183 + 184 + ien &= ~(SPRD_IEN_RX_FULL | SPRD_IEN_BREAK_DETECT); 185 + iclr |= SPRD_IEN_RX_FULL | SPRD_IEN_BREAK_DETECT; 186 + 187 + serial_out(port, SPRD_IEN, ien); 188 + serial_out(port, SPRD_ICLR, iclr); 189 + } 190 + 191 + /* The Sprd serial does not support this function. */ 192 + static void sprd_break_ctl(struct uart_port *port, int break_state) 193 + { 194 + /* nothing to do */ 195 + } 196 + 197 + static int handle_lsr_errors(struct uart_port *port, 198 + unsigned int *flag, 199 + unsigned int *lsr) 200 + { 201 + int ret = 0; 202 + 203 + /* statistics */ 204 + if (*lsr & SPRD_LSR_BI) { 205 + *lsr &= ~(SPRD_LSR_FE | SPRD_LSR_PE); 206 + port->icount.brk++; 207 + ret = uart_handle_break(port); 208 + if (ret) 209 + return ret; 210 + } else if (*lsr & SPRD_LSR_PE) 211 + port->icount.parity++; 212 + else if (*lsr & SPRD_LSR_FE) 213 + port->icount.frame++; 214 + if (*lsr & SPRD_LSR_OE) 215 + port->icount.overrun++; 216 + 217 + /* mask off conditions which should be ignored */ 218 + *lsr &= port->read_status_mask; 219 + if (*lsr & SPRD_LSR_BI) 220 + *flag = TTY_BREAK; 221 + else if (*lsr & SPRD_LSR_PE) 222 + *flag = TTY_PARITY; 223 + else if (*lsr & SPRD_LSR_FE) 224 + *flag = TTY_FRAME; 225 + 226 + return ret; 227 + } 228 + 229 + static inline void sprd_rx(struct uart_port *port) 230 + { 231 + struct tty_port *tty = &port->state->port; 232 + unsigned int ch, flag, lsr, max_count = SPRD_TIMEOUT; 233 + 234 + while ((serial_in(port, SPRD_STS1) & 0x00ff) && max_count--) { 235 + lsr = serial_in(port, SPRD_LSR); 236 + ch = serial_in(port, SPRD_RXD); 237 + flag = TTY_NORMAL; 238 + port->icount.rx++; 239 + 240 + if (lsr & (SPRD_LSR_BI | SPRD_LSR_PE | 241 + SPRD_LSR_FE | SPRD_LSR_OE)) 242 + if (handle_lsr_errors(port, &lsr, &flag)) 243 + continue; 244 + if (uart_handle_sysrq_char(port, ch)) 245 + continue; 246 + 247 + uart_insert_char(port, lsr, SPRD_LSR_OE, ch, flag); 248 + } 249 + 250 + tty_flip_buffer_push(tty); 251 + } 252 + 253 + static inline void sprd_tx(struct uart_port *port) 254 + { 255 + struct circ_buf *xmit = &port->state->xmit; 256 + int count; 257 + 258 + if (port->x_char) { 259 + serial_out(port, SPRD_TXD, port->x_char); 260 + port->icount.tx++; 261 + port->x_char = 0; 262 + return; 263 + } 264 + 265 + if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 266 + sprd_stop_tx(port); 267 + return; 268 + } 269 + 270 + count = THLD_TX_EMPTY; 271 + do { 272 + serial_out(port, SPRD_TXD, xmit->buf[xmit->tail]); 273 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 274 + port->icount.tx++; 275 + if (uart_circ_empty(xmit)) 276 + break; 277 + } while (--count > 0); 278 + 279 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 280 + uart_write_wakeup(port); 281 + 282 + if (uart_circ_empty(xmit)) 283 + sprd_stop_tx(port); 284 + } 285 + 286 + /* this handles the interrupt from one port */ 287 + static irqreturn_t sprd_handle_irq(int irq, void *dev_id) 288 + { 289 + struct uart_port *port = dev_id; 290 + unsigned int ims; 291 + 292 + spin_lock(&port->lock); 293 + 294 + ims = serial_in(port, SPRD_IMSR); 295 + 296 + if (!ims) 297 + return IRQ_NONE; 298 + 299 + serial_out(port, SPRD_ICLR, ~0); 300 + 301 + if (ims & (SPRD_IMSR_RX_FIFO_FULL | 302 + SPRD_IMSR_BREAK_DETECT | SPRD_IMSR_TIMEOUT)) 303 + sprd_rx(port); 304 + 305 + if (ims & SPRD_IMSR_TX_FIFO_EMPTY) 306 + sprd_tx(port); 307 + 308 + spin_unlock(&port->lock); 309 + 310 + return IRQ_HANDLED; 311 + } 312 + 313 + static int sprd_startup(struct uart_port *port) 314 + { 315 + int ret = 0; 316 + unsigned int ien, fc; 317 + unsigned int timeout; 318 + struct sprd_uart_port *sp; 319 + unsigned long flags; 320 + 321 + serial_out(port, SPRD_CTL2, ((THLD_TX_EMPTY << 8) | THLD_RX_FULL)); 322 + 323 + /* clear rx fifo */ 324 + timeout = SPRD_TIMEOUT; 325 + while (timeout-- && serial_in(port, SPRD_STS1) & 0x00ff) 326 + serial_in(port, SPRD_RXD); 327 + 328 + /* clear tx fifo */ 329 + timeout = SPRD_TIMEOUT; 330 + while (timeout-- && serial_in(port, SPRD_STS1) & 0xff00) 331 + cpu_relax(); 332 + 333 + /* clear interrupt */ 334 + serial_out(port, SPRD_IEN, 0); 335 + serial_out(port, SPRD_ICLR, ~0); 336 + 337 + /* allocate irq */ 338 + sp = container_of(port, struct sprd_uart_port, port); 339 + snprintf(sp->name, sizeof(sp->name), "sprd_serial%d", port->line); 340 + ret = devm_request_irq(port->dev, port->irq, sprd_handle_irq, 341 + IRQF_SHARED, sp->name, port); 342 + if (ret) { 343 + dev_err(port->dev, "fail to request serial irq %d, ret=%d\n", 344 + port->irq, ret); 345 + return ret; 346 + } 347 + fc = serial_in(port, SPRD_CTL1); 348 + fc |= RX_TOUT_THLD_DEF | RX_HFC_THLD_DEF; 349 + serial_out(port, SPRD_CTL1, fc); 350 + 351 + /* enable interrupt */ 352 + spin_lock_irqsave(&port->lock, flags); 353 + ien = serial_in(port, SPRD_IEN); 354 + ien |= SPRD_IEN_RX_FULL | SPRD_IEN_BREAK_DETECT | SPRD_IEN_TIMEOUT; 355 + serial_out(port, SPRD_IEN, ien); 356 + spin_unlock_irqrestore(&port->lock, flags); 357 + 358 + return 0; 359 + } 360 + 361 + static void sprd_shutdown(struct uart_port *port) 362 + { 363 + serial_out(port, SPRD_IEN, 0); 364 + serial_out(port, SPRD_ICLR, ~0); 365 + devm_free_irq(port->dev, port->irq, port); 366 + } 367 + 368 + static void sprd_set_termios(struct uart_port *port, 369 + struct ktermios *termios, 370 + struct ktermios *old) 371 + { 372 + unsigned int baud, quot; 373 + unsigned int lcr = 0, fc; 374 + unsigned long flags; 375 + 376 + /* ask the core to calculate the divisor for us */ 377 + baud = uart_get_baud_rate(port, termios, old, 0, SPRD_BAUD_IO_LIMIT); 378 + 379 + quot = (unsigned int)((port->uartclk + baud / 2) / baud); 380 + 381 + /* set data length */ 382 + switch (termios->c_cflag & CSIZE) { 383 + case CS5: 384 + lcr |= SPRD_LCR_DATA_LEN5; 385 + break; 386 + case CS6: 387 + lcr |= SPRD_LCR_DATA_LEN6; 388 + break; 389 + case CS7: 390 + lcr |= SPRD_LCR_DATA_LEN7; 391 + break; 392 + case CS8: 393 + default: 394 + lcr |= SPRD_LCR_DATA_LEN8; 395 + break; 396 + } 397 + 398 + /* calculate stop bits */ 399 + lcr &= ~(SPRD_LCR_STOP_1BIT | SPRD_LCR_STOP_2BIT); 400 + if (termios->c_cflag & CSTOPB) 401 + lcr |= SPRD_LCR_STOP_2BIT; 402 + else 403 + lcr |= SPRD_LCR_STOP_1BIT; 404 + 405 + /* calculate parity */ 406 + lcr &= ~SPRD_LCR_PARITY; 407 + termios->c_cflag &= ~CMSPAR; /* no support mark/space */ 408 + if (termios->c_cflag & PARENB) { 409 + lcr |= SPRD_LCR_PARITY_EN; 410 + if (termios->c_cflag & PARODD) 411 + lcr |= SPRD_LCR_ODD_PAR; 412 + else 413 + lcr |= SPRD_LCR_EVEN_PAR; 414 + } 415 + 416 + spin_lock_irqsave(&port->lock, flags); 417 + 418 + /* update the per-port timeout */ 419 + uart_update_timeout(port, termios->c_cflag, baud); 420 + 421 + port->read_status_mask = SPRD_LSR_OE; 422 + if (termios->c_iflag & INPCK) 423 + port->read_status_mask |= SPRD_LSR_FE | SPRD_LSR_PE; 424 + if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) 425 + port->read_status_mask |= SPRD_LSR_BI; 426 + 427 + /* characters to ignore */ 428 + port->ignore_status_mask = 0; 429 + if (termios->c_iflag & IGNPAR) 430 + port->ignore_status_mask |= SPRD_LSR_PE | SPRD_LSR_FE; 431 + if (termios->c_iflag & IGNBRK) { 432 + port->ignore_status_mask |= SPRD_LSR_BI; 433 + /* 434 + * If we're ignoring parity and break indicators, 435 + * ignore overruns too (for real raw support). 436 + */ 437 + if (termios->c_iflag & IGNPAR) 438 + port->ignore_status_mask |= SPRD_LSR_OE; 439 + } 440 + 441 + /* flow control */ 442 + fc = serial_in(port, SPRD_CTL1); 443 + fc &= ~(RX_HW_FLOW_CTL_THLD | RX_HW_FLOW_CTL_EN | TX_HW_FLOW_CTL_EN); 444 + if (termios->c_cflag & CRTSCTS) { 445 + fc |= RX_HW_FLOW_CTL_THLD; 446 + fc |= RX_HW_FLOW_CTL_EN; 447 + fc |= TX_HW_FLOW_CTL_EN; 448 + } 449 + 450 + /* clock divider bit0~bit15 */ 451 + serial_out(port, SPRD_CLKD0, quot & 0xffff); 452 + 453 + /* clock divider bit16~bit20 */ 454 + serial_out(port, SPRD_CLKD1, (quot & 0x1f0000) >> 16); 455 + serial_out(port, SPRD_LCR, lcr); 456 + fc |= RX_TOUT_THLD_DEF | RX_HFC_THLD_DEF; 457 + serial_out(port, SPRD_CTL1, fc); 458 + 459 + spin_unlock_irqrestore(&port->lock, flags); 460 + 461 + /* Don't rewrite B0 */ 462 + if (tty_termios_baud_rate(termios)) 463 + tty_termios_encode_baud_rate(termios, baud, baud); 464 + } 465 + 466 + static const char *sprd_type(struct uart_port *port) 467 + { 468 + return "SPX"; 469 + } 470 + 471 + static void sprd_release_port(struct uart_port *port) 472 + { 473 + /* nothing to do */ 474 + } 475 + 476 + static int sprd_request_port(struct uart_port *port) 477 + { 478 + return 0; 479 + } 480 + 481 + static void sprd_config_port(struct uart_port *port, int flags) 482 + { 483 + if (flags & UART_CONFIG_TYPE) 484 + port->type = PORT_SPRD; 485 + } 486 + 487 + static int sprd_verify_port(struct uart_port *port, 488 + struct serial_struct *ser) 489 + { 490 + if (ser->type != PORT_SPRD) 491 + return -EINVAL; 492 + if (port->irq != ser->irq) 493 + return -EINVAL; 494 + return 0; 495 + } 496 + 497 + static struct uart_ops serial_sprd_ops = { 498 + .tx_empty = sprd_tx_empty, 499 + .get_mctrl = sprd_get_mctrl, 500 + .set_mctrl = sprd_set_mctrl, 501 + .stop_tx = sprd_stop_tx, 502 + .start_tx = sprd_start_tx, 503 + .stop_rx = sprd_stop_rx, 504 + .break_ctl = sprd_break_ctl, 505 + .startup = sprd_startup, 506 + .shutdown = sprd_shutdown, 507 + .set_termios = sprd_set_termios, 508 + .type = sprd_type, 509 + .release_port = sprd_release_port, 510 + .request_port = sprd_request_port, 511 + .config_port = sprd_config_port, 512 + .verify_port = sprd_verify_port, 513 + }; 514 + 515 + #ifdef CONFIG_SERIAL_SPRD_CONSOLE 516 + static inline void wait_for_xmitr(struct uart_port *port) 517 + { 518 + unsigned int status, tmout = 10000; 519 + 520 + /* wait up to 10ms for the character(s) to be sent */ 521 + do { 522 + status = serial_in(port, SPRD_STS1); 523 + if (--tmout == 0) 524 + break; 525 + udelay(1); 526 + } while (status & 0xff00); 527 + } 528 + 529 + static void sprd_console_putchar(struct uart_port *port, int ch) 530 + { 531 + wait_for_xmitr(port); 532 + serial_out(port, SPRD_TXD, ch); 533 + } 534 + 535 + static void sprd_console_write(struct console *co, const char *s, 536 + unsigned int count) 537 + { 538 + struct uart_port *port = &sprd_port[co->index]->port; 539 + int locked = 1; 540 + unsigned long flags; 541 + 542 + if (port->sysrq) 543 + locked = 0; 544 + else if (oops_in_progress) 545 + locked = spin_trylock_irqsave(&port->lock, flags); 546 + else 547 + spin_lock_irqsave(&port->lock, flags); 548 + 549 + uart_console_write(port, s, count, sprd_console_putchar); 550 + 551 + /* wait for transmitter to become empty */ 552 + wait_for_xmitr(port); 553 + 554 + if (locked) 555 + spin_unlock_irqrestore(&port->lock, flags); 556 + } 557 + 558 + static int __init sprd_console_setup(struct console *co, char *options) 559 + { 560 + struct uart_port *port; 561 + int baud = 115200; 562 + int bits = 8; 563 + int parity = 'n'; 564 + int flow = 'n'; 565 + 566 + if (co->index >= UART_NR_MAX || co->index < 0) 567 + co->index = 0; 568 + 569 + port = &sprd_port[co->index]->port; 570 + if (port == NULL) { 571 + pr_info("serial port %d not yet initialized\n", co->index); 572 + return -ENODEV; 573 + } 574 + if (options) 575 + uart_parse_options(options, &baud, &parity, &bits, &flow); 576 + 577 + return uart_set_options(port, co, baud, parity, bits, flow); 578 + } 579 + 580 + static struct uart_driver sprd_uart_driver; 581 + static struct console sprd_console = { 582 + .name = SPRD_TTY_NAME, 583 + .write = sprd_console_write, 584 + .device = uart_console_device, 585 + .setup = sprd_console_setup, 586 + .flags = CON_PRINTBUFFER, 587 + .index = -1, 588 + .data = &sprd_uart_driver, 589 + }; 590 + 591 + #define SPRD_CONSOLE (&sprd_console) 592 + 593 + /* Support for earlycon */ 594 + static void sprd_putc(struct uart_port *port, int c) 595 + { 596 + unsigned int timeout = SPRD_TIMEOUT; 597 + 598 + while (timeout-- && 599 + !(readl(port->membase + SPRD_LSR) & SPRD_LSR_TX_OVER)) 600 + cpu_relax(); 601 + 602 + writeb(c, port->membase + SPRD_TXD); 603 + } 604 + 605 + static void sprd_early_write(struct console *con, const char *s, 606 + unsigned n) 607 + { 608 + struct earlycon_device *dev = con->data; 609 + 610 + uart_console_write(&dev->port, s, n, sprd_putc); 611 + } 612 + 613 + static int __init sprd_early_console_setup( 614 + struct earlycon_device *device, 615 + const char *opt) 616 + { 617 + if (!device->port.membase) 618 + return -ENODEV; 619 + 620 + device->con->write = sprd_early_write; 621 + return 0; 622 + } 623 + 624 + EARLYCON_DECLARE(sprd_serial, sprd_early_console_setup); 625 + OF_EARLYCON_DECLARE(sprd_serial, "sprd,sc9836-uart", 626 + sprd_early_console_setup); 627 + 628 + #else /* !CONFIG_SERIAL_SPRD_CONSOLE */ 629 + #define SPRD_CONSOLE NULL 630 + #endif 631 + 632 + static struct uart_driver sprd_uart_driver = { 633 + .owner = THIS_MODULE, 634 + .driver_name = "sprd_serial", 635 + .dev_name = SPRD_TTY_NAME, 636 + .major = 0, 637 + .minor = 0, 638 + .nr = UART_NR_MAX, 639 + .cons = SPRD_CONSOLE, 640 + }; 641 + 642 + static int sprd_probe_dt_alias(int index, struct device *dev) 643 + { 644 + struct device_node *np; 645 + int ret = index; 646 + 647 + if (!IS_ENABLED(CONFIG_OF)) 648 + return ret; 649 + 650 + np = dev->of_node; 651 + if (!np) 652 + return ret; 653 + 654 + ret = of_alias_get_id(np, "serial"); 655 + if (IS_ERR_VALUE(ret)) 656 + ret = index; 657 + else if (ret >= ARRAY_SIZE(sprd_port) || sprd_port[ret] != NULL) { 658 + dev_warn(dev, "requested serial port %d not available.\n", ret); 659 + ret = index; 660 + } 661 + 662 + return ret; 663 + } 664 + 665 + static int sprd_remove(struct platform_device *dev) 666 + { 667 + struct sprd_uart_port *sup = platform_get_drvdata(dev); 668 + 669 + if (sup) { 670 + uart_remove_one_port(&sprd_uart_driver, &sup->port); 671 + sprd_port[sup->port.line] = NULL; 672 + sprd_ports_num--; 673 + } 674 + 675 + if (!sprd_ports_num) 676 + uart_unregister_driver(&sprd_uart_driver); 677 + 678 + return 0; 679 + } 680 + 681 + static int sprd_probe(struct platform_device *pdev) 682 + { 683 + struct resource *res; 684 + struct uart_port *up; 685 + struct clk *clk; 686 + int irq; 687 + int index; 688 + int ret; 689 + 690 + for (index = 0; index < ARRAY_SIZE(sprd_port); index++) 691 + if (sprd_port[index] == NULL) 692 + break; 693 + 694 + if (index == ARRAY_SIZE(sprd_port)) 695 + return -EBUSY; 696 + 697 + index = sprd_probe_dt_alias(index, &pdev->dev); 698 + 699 + sprd_port[index] = devm_kzalloc(&pdev->dev, 700 + sizeof(*sprd_port[index]), GFP_KERNEL); 701 + if (!sprd_port[index]) 702 + return -ENOMEM; 703 + 704 + up = &sprd_port[index]->port; 705 + up->dev = &pdev->dev; 706 + up->line = index; 707 + up->type = PORT_SPRD; 708 + up->iotype = SERIAL_IO_PORT; 709 + up->uartclk = SPRD_DEF_RATE; 710 + up->fifosize = SPRD_FIFO_SIZE; 711 + up->ops = &serial_sprd_ops; 712 + up->flags = UPF_BOOT_AUTOCONF; 713 + 714 + clk = devm_clk_get(&pdev->dev, NULL); 715 + if (!IS_ERR(clk)) 716 + up->uartclk = clk_get_rate(clk); 717 + 718 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 719 + if (!res) { 720 + dev_err(&pdev->dev, "not provide mem resource\n"); 721 + return -ENODEV; 722 + } 723 + up->mapbase = res->start; 724 + up->membase = devm_ioremap_resource(&pdev->dev, res); 725 + if (IS_ERR(up->membase)) 726 + return PTR_ERR(up->membase); 727 + 728 + irq = platform_get_irq(pdev, 0); 729 + if (irq < 0) { 730 + dev_err(&pdev->dev, "not provide irq resource\n"); 731 + return -ENODEV; 732 + } 733 + up->irq = irq; 734 + 735 + if (!sprd_ports_num) { 736 + ret = uart_register_driver(&sprd_uart_driver); 737 + if (ret < 0) { 738 + pr_err("Failed to register SPRD-UART driver\n"); 739 + return ret; 740 + } 741 + } 742 + sprd_ports_num++; 743 + 744 + ret = uart_add_one_port(&sprd_uart_driver, up); 745 + if (ret) { 746 + sprd_port[index] = NULL; 747 + sprd_remove(pdev); 748 + } 749 + 750 + platform_set_drvdata(pdev, up); 751 + 752 + return ret; 753 + } 754 + 755 + static int sprd_suspend(struct device *dev) 756 + { 757 + struct sprd_uart_port *sup = dev_get_drvdata(dev); 758 + 759 + uart_suspend_port(&sprd_uart_driver, &sup->port); 760 + 761 + return 0; 762 + } 763 + 764 + static int sprd_resume(struct device *dev) 765 + { 766 + struct sprd_uart_port *sup = dev_get_drvdata(dev); 767 + 768 + uart_resume_port(&sprd_uart_driver, &sup->port); 769 + 770 + return 0; 771 + } 772 + 773 + static SIMPLE_DEV_PM_OPS(sprd_pm_ops, sprd_suspend, sprd_resume); 774 + 775 + static const struct of_device_id serial_ids[] = { 776 + {.compatible = "sprd,sc9836-uart",}, 777 + {} 778 + }; 779 + 780 + static struct platform_driver sprd_platform_driver = { 781 + .probe = sprd_probe, 782 + .remove = sprd_remove, 783 + .driver = { 784 + .name = "sprd_serial", 785 + .of_match_table = of_match_ptr(serial_ids), 786 + .pm = &sprd_pm_ops, 787 + }, 788 + }; 789 + 790 + module_platform_driver(sprd_platform_driver); 791 + 792 + MODULE_LICENSE("GPL v2"); 793 + MODULE_DESCRIPTION("Spreadtrum SoC serial driver series");
+6 -4
drivers/tty/serial/xilinx_uartps.c
··· 637 637 638 638 spin_lock_irqsave(&port->lock, flags); 639 639 640 - /* Empty the receive FIFO 1st before making changes */ 641 - while ((cdns_uart_readl(CDNS_UART_SR_OFFSET) & 642 - CDNS_UART_SR_RXEMPTY) != CDNS_UART_SR_RXEMPTY) { 643 - cdns_uart_readl(CDNS_UART_FIFO_OFFSET); 640 + /* Wait for the transmit FIFO to empty before making changes */ 641 + if (!(cdns_uart_readl(CDNS_UART_CR_OFFSET) & CDNS_UART_CR_TX_DIS)) { 642 + while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & 643 + CDNS_UART_SR_TXEMPTY)) { 644 + cpu_relax(); 645 + } 644 646 } 645 647 646 648 /* Disable the TX and RX to set baud rate */
+6
drivers/tty/tty_buffer.c
··· 557 557 return 0; 558 558 } 559 559 EXPORT_SYMBOL_GPL(tty_buffer_set_limit); 560 + 561 + /* slave ptys can claim nested buffer lock when handling BRK and INTR */ 562 + void tty_buffer_set_lock_subclass(struct tty_port *port) 563 + { 564 + lockdep_set_subclass(&port->buf.lock, TTY_LOCK_SLAVE); 565 + }
+1 -2
drivers/tty/tty_ioctl.c
··· 530 530 * Locking: termios_rwsem 531 531 */ 532 532 533 - int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) 533 + static int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) 534 534 { 535 535 struct ktermios old_termios; 536 536 struct tty_ldisc *ld; ··· 563 563 up_write(&tty->termios_rwsem); 564 564 return 0; 565 565 } 566 - EXPORT_SYMBOL_GPL(tty_set_termios); 567 566 568 567 /** 569 568 * set_termios - set termios values for a tty
+2 -16
drivers/tty/tty_mutex.c
··· 4 4 #include <linux/semaphore.h> 5 5 #include <linux/sched.h> 6 6 7 - /* 8 - * Nested tty locks are necessary for releasing pty pairs. 9 - * The stable lock order is master pty first, then slave pty. 10 - */ 11 - 12 7 /* Legacy tty mutex glue */ 13 - 14 - enum { 15 - TTY_MUTEX_NORMAL, 16 - TTY_MUTEX_SLAVE, 17 - }; 18 8 19 9 /* 20 10 * Getting the big tty mutex. ··· 36 46 37 47 void __lockfunc tty_lock_slave(struct tty_struct *tty) 38 48 { 39 - if (tty && tty != tty->link) { 40 - WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) || 41 - !tty->driver->type == TTY_DRIVER_TYPE_PTY || 42 - !tty->driver->type == PTY_TYPE_SLAVE); 49 + if (tty && tty != tty->link) 43 50 tty_lock(tty); 44 - } 45 51 } 46 52 47 53 void __lockfunc tty_unlock_slave(struct tty_struct *tty) ··· 48 62 49 63 void tty_set_lock_subclass(struct tty_struct *tty) 50 64 { 51 - lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE); 65 + lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE); 52 66 }
+9 -9
drivers/tty/vt/vt.c
··· 500 500 #endif 501 501 if (DO_UPDATE(vc)) 502 502 do_update_region(vc, (unsigned long) p, count); 503 + notify_update(vc); 503 504 } 504 505 505 506 /* used by selection: complement pointer position */ ··· 517 516 scr_writew(old, screenpos(vc, old_offset, 1)); 518 517 if (DO_UPDATE(vc)) 519 518 vc->vc_sw->con_putc(vc, old, oldy, oldx); 519 + notify_update(vc); 520 520 } 521 521 522 522 old_offset = offset; ··· 535 533 oldy = (offset >> 1) / vc->vc_cols; 536 534 vc->vc_sw->con_putc(vc, new, oldy, oldx); 537 535 } 536 + notify_update(vc); 538 537 } 539 - 540 538 } 541 539 542 540 static void insert_char(struct vc_data *vc, unsigned int nr) ··· 3320 3318 if (first == 0 && last == MAX_NR_CONSOLES -1) 3321 3319 deflt = 1; 3322 3320 3323 - if (first != -1) { 3324 - console_lock(); 3321 + if (first != -1) 3325 3322 do_bind_con_driver(csw, first, last, deflt); 3326 - console_unlock(); 3327 - } 3328 3323 3329 3324 first = -1; 3330 3325 last = -1; ··· 3361 3362 deflt = 1; 3362 3363 3363 3364 if (first != -1) { 3364 - console_lock(); 3365 3365 ret = do_unbind_con_driver(csw, first, last, deflt); 3366 - console_unlock(); 3367 3366 if (ret != 0) 3368 3367 return ret; 3369 3368 } ··· 3391 3394 struct con_driver *con = dev_get_drvdata(dev); 3392 3395 int bind = simple_strtoul(buf, NULL, 0); 3393 3396 3397 + console_lock(); 3398 + 3394 3399 if (bind) 3395 3400 vt_bind(con); 3396 3401 else 3397 3402 vt_unbind(con); 3403 + 3404 + console_unlock(); 3398 3405 3399 3406 return count; 3400 3407 } ··· 3666 3665 for (i = 0; i < MAX_NR_CON_DRIVER; i++) { 3667 3666 struct con_driver *con_driver = &registered_con_driver[i]; 3668 3667 3669 - if (con_driver->con == csw && 3670 - con_driver->flag & CON_DRIVER_FLAG_INIT) { 3668 + if (con_driver->con == csw) { 3671 3669 vtconsole_deinit_device(con_driver); 3672 3670 device_destroy(vtconsole_class, 3673 3671 MKDEV(0, con_driver->node));
+10 -2
include/linux/pnp.h
··· 12 12 #include <linux/list.h> 13 13 #include <linux/errno.h> 14 14 #include <linux/mod_devicetable.h> 15 + #include <linux/console.h> 15 16 16 17 #define PNP_NAME_LEN 50 17 18 ··· 310 309 #define PNP_DISABLE 0x0004 311 310 #define PNP_CONFIGURABLE 0x0008 312 311 #define PNP_REMOVABLE 0x0010 312 + #define PNP_CONSOLE 0x0020 313 313 314 314 #define pnp_can_read(dev) (((dev)->protocol->get) && \ 315 315 ((dev)->capabilities & PNP_READ)) 316 316 #define pnp_can_write(dev) (((dev)->protocol->set) && \ 317 317 ((dev)->capabilities & PNP_WRITE)) 318 - #define pnp_can_disable(dev) (((dev)->protocol->disable) && \ 319 - ((dev)->capabilities & PNP_DISABLE)) 318 + #define pnp_can_disable(dev) (((dev)->protocol->disable) && \ 319 + ((dev)->capabilities & PNP_DISABLE) && \ 320 + (!((dev)->capabilities & PNP_CONSOLE) || \ 321 + console_suspend_enabled)) 320 322 #define pnp_can_configure(dev) ((!(dev)->active) && \ 321 323 ((dev)->capabilities & PNP_CONFIGURABLE)) 324 + #define pnp_can_suspend(dev) (((dev)->protocol->suspend) && \ 325 + (!((dev)->capabilities & PNP_CONSOLE) || \ 326 + console_suspend_enabled)) 327 + 322 328 323 329 #ifdef CONFIG_ISAPNP 324 330 extern struct pnp_protocol isapnp_protocol;
+4
include/linux/serial_8250.h
··· 85 85 unsigned char mcr_force; /* mask of forced bits */ 86 86 unsigned char cur_iotype; /* Running I/O type */ 87 87 unsigned int rpm_tx_active; 88 + unsigned char canary; /* non-zero during system sleep 89 + * if no_console_suspend 90 + */ 88 91 89 92 /* 90 93 * Some bits in registers are cleared on a read, so they must ··· 129 126 extern void serial8250_do_shutdown(struct uart_port *port); 130 127 extern void serial8250_do_pm(struct uart_port *port, unsigned int state, 131 128 unsigned int oldstate); 129 + extern void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl); 132 130 extern int fsl8250_handle_irq(struct uart_port *port); 133 131 int serial8250_handle_irq(struct uart_port *port, unsigned int iir); 134 132 unsigned char serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr);
+19 -3
include/linux/serial_core.h
··· 123 123 void (*set_termios)(struct uart_port *, 124 124 struct ktermios *new, 125 125 struct ktermios *old); 126 + void (*set_mctrl)(struct uart_port *, unsigned int); 126 127 int (*startup)(struct uart_port *port); 127 128 void (*shutdown)(struct uart_port *port); 128 129 void (*throttle)(struct uart_port *port); ··· 191 190 #define UPF_NO_TXEN_TEST ((__force upf_t) (1 << 15)) 192 191 #define UPF_MAGIC_MULTIPLIER ((__force upf_t) ASYNC_MAGIC_MULTIPLIER /* 16 */ ) 193 192 194 - /* Port has hardware-assisted h/w flow control (iow, auto-RTS *not* auto-CTS) */ 195 - #define UPF_HARD_FLOW ((__force upf_t) (1 << 21)) 193 + /* Port has hardware-assisted h/w flow control */ 194 + #define UPF_AUTO_CTS ((__force upf_t) (1 << 20)) 195 + #define UPF_AUTO_RTS ((__force upf_t) (1 << 21)) 196 + #define UPF_HARD_FLOW ((__force upf_t) (UPF_AUTO_CTS | UPF_AUTO_RTS)) 196 197 /* Port has hardware-assisted s/w flow control */ 197 198 #define UPF_SOFT_FLOW ((__force upf_t) (1 << 22)) 198 199 #define UPF_CONS_FLOW ((__force upf_t) (1 << 23)) ··· 216 213 #error Change mask not equivalent to userspace-visible bit defines 217 214 #endif 218 215 219 - /* status must be updated while holding port lock */ 216 + /* 217 + * Must hold termios_rwsem, port mutex and port lock to change; 218 + * can hold any one lock to read. 219 + */ 220 220 upstat_t status; 221 221 222 222 #define UPSTAT_CTS_ENABLE ((__force upstat_t) (1 << 0)) 223 223 #define UPSTAT_DCD_ENABLE ((__force upstat_t) (1 << 1)) 224 + #define UPSTAT_AUTORTS ((__force upstat_t) (1 << 2)) 225 + #define UPSTAT_AUTOCTS ((__force upstat_t) (1 << 3)) 226 + #define UPSTAT_AUTOXOFF ((__force upstat_t) (1 << 4)) 224 227 225 228 int hw_stopped; /* sw-assisted CTS flow state */ 226 229 unsigned int mctrl; /* current modem ctrl settings */ ··· 398 389 static inline bool uart_cts_enabled(struct uart_port *uport) 399 390 { 400 391 return !!(uport->status & UPSTAT_CTS_ENABLE); 392 + } 393 + 394 + static inline bool uart_softcts_mode(struct uart_port *uport) 395 + { 396 + upstat_t mask = UPSTAT_CTS_ENABLE | UPSTAT_AUTOCTS; 397 + 398 + return ((uport->status & mask) == UPSTAT_CTS_ENABLE); 401 399 } 402 400 403 401 /*
+28
include/linux/serial_s3c.h
··· 104 104 S3C2410_UCON_RXIRQMODE | \ 105 105 S3C2410_UCON_RXFIFO_TOI) 106 106 107 + #define S3C64XX_UCON_TXBURST_1 (0<<20) 108 + #define S3C64XX_UCON_TXBURST_4 (1<<20) 109 + #define S3C64XX_UCON_TXBURST_8 (2<<20) 110 + #define S3C64XX_UCON_TXBURST_16 (3<<20) 111 + #define S3C64XX_UCON_TXBURST_MASK (0xf<<20) 112 + #define S3C64XX_UCON_RXBURST_1 (0<<16) 113 + #define S3C64XX_UCON_RXBURST_4 (1<<16) 114 + #define S3C64XX_UCON_RXBURST_8 (2<<16) 115 + #define S3C64XX_UCON_RXBURST_16 (3<<16) 116 + #define S3C64XX_UCON_RXBURST_MASK (0xf<<16) 117 + #define S3C64XX_UCON_TIMEOUT_SHIFT (12) 118 + #define S3C64XX_UCON_TIMEOUT_MASK (0xf<<12) 119 + #define S3C64XX_UCON_EMPTYINT_EN (1<<11) 120 + #define S3C64XX_UCON_DMASUS_EN (1<<10) 121 + #define S3C64XX_UCON_TXINT_LEVEL (1<<9) 122 + #define S3C64XX_UCON_RXINT_LEVEL (1<<8) 123 + #define S3C64XX_UCON_TIMEOUT_EN (1<<7) 124 + #define S3C64XX_UCON_ERRINT_EN (1<<6) 125 + #define S3C64XX_UCON_TXMODE_DMA (2<<2) 126 + #define S3C64XX_UCON_TXMODE_CPU (1<<2) 127 + #define S3C64XX_UCON_TXMODE_MASK (3<<2) 128 + #define S3C64XX_UCON_RXMODE_DMA (2<<0) 129 + #define S3C64XX_UCON_RXMODE_CPU (1<<0) 130 + #define S3C64XX_UCON_RXMODE_MASK (3<<0) 131 + 107 132 #define S3C2410_UFCON_FIFOMODE (1<<0) 108 133 #define S3C2410_UFCON_TXTRIG0 (0<<6) 109 134 #define S3C2410_UFCON_RXTRIG8 (1<<4) ··· 180 155 #define S3C2440_UFSTAT_TXMASK (63<<8) 181 156 #define S3C2440_UFSTAT_RXMASK (63) 182 157 158 + #define S3C2410_UTRSTAT_TIMEOUT (1<<3) 183 159 #define S3C2410_UTRSTAT_TXE (1<<2) 184 160 #define S3C2410_UTRSTAT_TXFE (1<<1) 185 161 #define S3C2410_UTRSTAT_RXDR (1<<0) ··· 205 179 #define S3C64XX_UINTM 0x38 206 180 207 181 #define S3C64XX_UINTM_RXD (0) 182 + #define S3C64XX_UINTM_ERROR (1) 208 183 #define S3C64XX_UINTM_TXD (2) 209 184 #define S3C64XX_UINTM_RXD_MSK (1 << S3C64XX_UINTM_RXD) 185 + #define S3C64XX_UINTM_ERR_MSK (1 << S3C64XX_UINTM_ERROR) 210 186 #define S3C64XX_UINTM_TXD_MSK (1 << S3C64XX_UINTM_TXD) 211 187 212 188 /* Following are specific to S5PV210 */
+24 -1
include/linux/tty.h
··· 14 14 #include <linux/llist.h> 15 15 16 16 17 + /* 18 + * Lock subclasses for tty locks 19 + * 20 + * TTY_LOCK_NORMAL is for normal ttys and master ptys. 21 + * TTY_LOCK_SLAVE is for slave ptys only. 22 + * 23 + * Lock subclasses are necessary for handling nested locking with pty pairs. 24 + * tty locks which use nested locking: 25 + * 26 + * legacy_mutex - Nested tty locks are necessary for releasing pty pairs. 27 + * The stable lock order is master pty first, then slave pty. 28 + * termios_rwsem - The stable lock order is tty_buffer lock->termios_rwsem. 29 + * Subclassing this lock enables the slave pty to hold its 30 + * termios_rwsem when claiming the master tty_buffer lock. 31 + * tty_buffer lock - slave ptys can claim nested buffer lock when handling 32 + * signal chars. The stable lock order is slave pty, then 33 + * master. 34 + */ 35 + 36 + enum { 37 + TTY_LOCK_NORMAL = 0, 38 + TTY_LOCK_SLAVE, 39 + }; 17 40 18 41 /* 19 42 * (Note: the *_driver.minor_start values 1, 64, 128, 192 are ··· 466 443 extern void tty_buffer_free_all(struct tty_port *port); 467 444 extern void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld); 468 445 extern void tty_buffer_init(struct tty_port *port); 446 + extern void tty_buffer_set_lock_subclass(struct tty_port *port); 469 447 extern speed_t tty_termios_baud_rate(struct ktermios *termios); 470 448 extern speed_t tty_termios_input_baud_rate(struct ktermios *termios); 471 449 extern void tty_termios_encode_baud_rate(struct ktermios *termios, ··· 491 467 492 468 extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old); 493 469 extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b); 494 - extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt); 495 470 496 471 extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); 497 472 extern void tty_ldisc_deref(struct tty_ldisc *);
-4
include/linux/vt_buffer.h
··· 21 21 #ifndef VT_BUF_HAVE_RW 22 22 #define scr_writew(val, addr) (*(addr) = (val)) 23 23 #define scr_readw(addr) (*(addr)) 24 - #define scr_memcpyw(d, s, c) memcpy(d, s, c) 25 - #define scr_memmovew(d, s, c) memmove(d, s, c) 26 - #define VT_BUF_HAVE_MEMCPYW 27 - #define VT_BUF_HAVE_MEMMOVEW 28 24 #endif 29 25 30 26 #ifndef VT_BUF_HAVE_MEMSETW
+11 -1
include/uapi/linux/serial_core.h
··· 55 55 #define PORT_ALTR_16550_F64 27 /* Altera 16550 UART with 64 FIFOs */ 56 56 #define PORT_ALTR_16550_F128 28 /* Altera 16550 UART with 128 FIFOs */ 57 57 #define PORT_RT2880 29 /* Ralink RT2880 internal UART */ 58 - #define PORT_MAX_8250 29 /* max port ID */ 58 + #define PORT_16550A_FSL64 30 /* Freescale 16550 UART with 64 FIFOs */ 59 + #define PORT_MAX_8250 30 /* max port ID */ 59 60 60 61 /* 61 62 * ARM specific type numbers. These are not currently guaranteed ··· 248 247 249 248 /* MESON */ 250 249 #define PORT_MESON 109 250 + 251 + /* Conexant Digicolor */ 252 + #define PORT_DIGICOLOR 110 253 + 254 + /* SPRD SERIAL */ 255 + #define PORT_SPRD 111 256 + 257 + /* Cris v10 / v32 SoC */ 258 + #define PORT_CRIS 112 251 259 252 260 #endif /* _UAPILINUX_SERIAL_CORE_H */
+2 -1
include/uapi/linux/serial_reg.h
··· 86 86 #define UART_FCR6_T_TRIGGER_8 0x10 /* Mask for transmit trigger set at 8 */ 87 87 #define UART_FCR6_T_TRIGGER_24 0x20 /* Mask for transmit trigger set at 24 */ 88 88 #define UART_FCR6_T_TRIGGER_30 0x30 /* Mask for transmit trigger set at 30 */ 89 - #define UART_FCR7_64BYTE 0x20 /* Go into 64 byte mode (TI16C750) */ 89 + #define UART_FCR7_64BYTE 0x20 /* Go into 64 byte mode (TI16C750 and 90 + some Freescale UARTs) */ 90 91 91 92 #define UART_FCR_R_TRIG_SHIFT 6 92 93 #define UART_FCR_R_TRIG_BITS(x) \