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

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

Pull tty and serial updates from Greg KH:
"Here is the big tty and serial patch set for 4.9-rc1.

It also includes some drivers/dma/ changes, as those were needed by
some serial drivers, and they were all acked by the DMA maintainer.

Also in here is the long-suffering ACPI SPCR patchset, which was
passed around from maintainer to maintainer like a hot-potato. Seems I
was the sucker^Wlucky one. All of those patches have been acked by the
various subsystem maintainers as well.

All of this has been in linux-next with no reported issues"

* tag 'tty-4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (111 commits)
Revert "serial: pl011: add console matching function"
MAINTAINERS: update entry for atmel_serial driver
serial: pl011: add console matching function
ARM64: ACPI: enable ACPI_SPCR_TABLE
ACPI: parse SPCR and enable matching console
of/serial: move earlycon early_param handling to serial
Revert "drivers/tty: Explicitly pass current to show_stack"
tty: amba-pl011: Don't complain on -EPROBE_DEFER when no irq
nios2: dts: 10m50: Add tx-threshold parameter
serial: 8250: Set Altera 16550 TX FIFO Threshold
serial: 8250: of: Load TX FIFO Threshold from DT
Documentation: dt: serial: Add TX FIFO threshold parameter
drivers/tty: Explicitly pass current to show_stack
serial: imx: Fix DCD reading
serial: stm32: mark symbols static where possible
serial: xuartps: Add some register initialisation to cdns_early_console_setup()
serial: xuartps: Removed unwanted checks while reading the error conditions
serial: xuartps: Rewrite the interrupt handling logic
serial: stm32: use mapbase instead of membase for DMA
tty/serial: atmel: fix fractional baud rate computation
...

+2624 -1283
+2
Documentation/devicetree/bindings/serial/8250.txt
··· 42 42 - auto-flow-control: one way to enable automatic flow control support. The 43 43 driver is allowed to detect support for the capability even without this 44 44 property. 45 + - tx-threshold: Specify the TX FIFO low water indication for parts with 46 + programmable TX FIFO thresholds. 45 47 46 48 Note: 47 49 * fsl,ns16550:
+46
Documentation/devicetree/bindings/serial/st,stm32-usart.txt
··· 1 + * STMicroelectronics STM32 USART 2 + 3 + Required properties: 4 + - compatible: Can be either "st,stm32-usart", "st,stm32-uart", 5 + "st,stm32f7-usart" or "st,stm32f7-uart" depending on whether 6 + the device supports synchronous mode and is compatible with 7 + stm32(f4) or stm32f7. 8 + - reg: The address and length of the peripheral registers space 9 + - interrupts: The interrupt line of the USART instance 10 + - clocks: The input clock of the USART instance 11 + 12 + Optional properties: 13 + - pinctrl: The reference on the pins configuration 14 + - st,hw-flow-ctrl: bool flag to enable hardware flow control. 15 + - dmas: phandle(s) to DMA controller node(s). Refer to stm32-dma.txt 16 + - dma-names: "rx" and/or "tx" 17 + 18 + Examples: 19 + usart4: serial@40004c00 { 20 + compatible = "st,stm32-uart"; 21 + reg = <0x40004c00 0x400>; 22 + interrupts = <52>; 23 + clocks = <&clk_pclk1>; 24 + pinctrl-names = "default"; 25 + pinctrl-0 = <&pinctrl_usart4>; 26 + }; 27 + 28 + usart2: serial@40004400 { 29 + compatible = "st,stm32-usart", "st,stm32-uart"; 30 + reg = <0x40004400 0x400>; 31 + interrupts = <38>; 32 + clocks = <&clk_pclk1>; 33 + st,hw-flow-ctrl; 34 + pinctrl-names = "default"; 35 + pinctrl-0 = <&pinctrl_usart2 &pinctrl_usart2_rtscts>; 36 + }; 37 + 38 + usart1: serial@40011000 { 39 + compatible = "st,stm32-usart", "st,stm32-uart"; 40 + reg = <0x40011000 0x400>; 41 + interrupts = <37>; 42 + clocks = <&rcc 0 164>; 43 + dmas = <&dma2 2 4 0x414 0x0>, 44 + <&dma2 7 4 0x414 0x0>; 45 + dma-names = "rx", "tx"; 46 + };
+6 -5
Documentation/kernel-parameters.txt
··· 1054 1054 determined by the stdout-path property in device 1055 1055 tree's chosen node. 1056 1056 1057 - cdns,<addr> 1058 - Start an early, polled-mode console on a cadence serial 1059 - port at the specified address. The cadence serial port 1060 - must already be setup and configured. Options are not 1061 - yet supported. 1057 + cdns,<addr>[,options] 1058 + Start an early, polled-mode console on a Cadence 1059 + (xuartps) serial port at the specified address. Only 1060 + supported option is baud rate. If baud rate is not 1061 + specified, the serial port must already be setup and 1062 + configured. 1062 1063 1063 1064 uart[8250],io,<addr>[,options] 1064 1065 uart[8250],mmio,<addr>[,options]
+6 -5
MAINTAINERS
··· 2121 2121 S: Maintained 2122 2122 F: drivers/mmc/host/atmel-mci.c 2123 2123 2124 - ATMEL AT91 / AT32 SERIAL DRIVER 2125 - M: Nicolas Ferre <nicolas.ferre@atmel.com> 2126 - S: Supported 2127 - F: drivers/tty/serial/atmel_serial.c 2128 - 2129 2124 ATMEL AT91 SAMA5D2-Compatible Shutdown Controller 2130 2125 M: Nicolas Ferre <nicolas.ferre@atmel.com> 2131 2126 S: Supported ··· 7768 7773 T: git git://git.monstr.eu/linux-2.6-microblaze.git 7769 7774 S: Supported 7770 7775 F: arch/microblaze/ 7776 + 7777 + MICROCHIP / ATMEL AT91 / AT32 SERIAL DRIVER 7778 + M: Richard Genoud <richard.genoud@gmail.com> 7779 + S: Maintained 7780 + F: drivers/tty/serial/atmel_serial.c 7781 + F: include/linux/atmel_serial.h 7771 7782 7772 7783 MICROSOFT SURFACE PRO 3 BUTTON DRIVER 7773 7784 M: Chen Yu <yu.c.chen@intel.com>
+1
arch/arm64/Kconfig
··· 4 4 select ACPI_GENERIC_GSI if ACPI 5 5 select ACPI_REDUCED_HARDWARE_ONLY if ACPI 6 6 select ACPI_MCFG if ACPI 7 + select ACPI_SPCR_TABLE if ACPI 7 8 select ARCH_CLOCKSOURCE_DATA 8 9 select ARCH_HAS_DEVMEM_IS_ALLOWED 9 10 select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
+10 -1
arch/arm64/kernel/acpi.c
··· 24 24 #include <linux/memblock.h> 25 25 #include <linux/of_fdt.h> 26 26 #include <linux/smp.h> 27 + #include <linux/serial_core.h> 27 28 28 29 #include <asm/cputype.h> 29 30 #include <asm/cpu_ops.h> ··· 207 206 if (param_acpi_off || 208 207 (!param_acpi_on && !param_acpi_force && 209 208 of_scan_flat_dt(dt_scan_depth1_nodes, NULL))) 210 - return; 209 + goto done; 211 210 212 211 /* 213 212 * ACPI is disabled at this point. Enable it in order to parse ··· 226 225 pr_err("Failed to init ACPI tables\n"); 227 226 if (!param_acpi_force) 228 227 disable_acpi(); 228 + } 229 + 230 + done: 231 + if (acpi_disabled) { 232 + if (earlycon_init_is_deferred) 233 + early_init_dt_scan_chosen_stdout(); 234 + } else { 235 + parse_spcr(earlycon_init_is_deferred); 229 236 } 230 237 } 231 238
+1
arch/nios2/boot/dts/10m50_devboard.dts
··· 83 83 fifo-size = <32>; 84 84 reg-io-width = <4>; 85 85 reg-shift = <2>; 86 + tx-threshold = <16>; 86 87 }; 87 88 88 89 sysid: sysid@18001528 {
+3
drivers/acpi/Kconfig
··· 77 77 78 78 endif 79 79 80 + config ACPI_SPCR_TABLE 81 + bool 82 + 80 83 config ACPI_SLEEP 81 84 bool 82 85 depends on SUSPEND || HIBERNATION
+1
drivers/acpi/Makefile
··· 82 82 obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o 83 83 obj-$(CONFIG_ACPI_BGRT) += bgrt.o 84 84 obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o 85 + obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o 85 86 obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o 86 87 87 88 # processor has its own "processor." module_param namespace
+111
drivers/acpi/spcr.c
··· 1 + /* 2 + * Copyright (c) 2012, Intel Corporation 3 + * Copyright (c) 2015, Red Hat, Inc. 4 + * Copyright (c) 2015, 2016 Linaro Ltd. 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + * 10 + */ 11 + 12 + #define pr_fmt(fmt) "ACPI: SPCR: " fmt 13 + 14 + #include <linux/acpi.h> 15 + #include <linux/console.h> 16 + #include <linux/kernel.h> 17 + #include <linux/serial_core.h> 18 + 19 + /** 20 + * parse_spcr() - parse ACPI SPCR table and add preferred console 21 + * 22 + * @earlycon: set up earlycon for the console specified by the table 23 + * 24 + * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be 25 + * defined to parse ACPI SPCR table. As a result of the parsing preferred 26 + * console is registered and if @earlycon is true, earlycon is set up. 27 + * 28 + * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called 29 + * from arch inintialization code as soon as the DT/ACPI decision is made. 30 + * 31 + */ 32 + int __init parse_spcr(bool earlycon) 33 + { 34 + static char opts[64]; 35 + struct acpi_table_spcr *table; 36 + acpi_size table_size; 37 + acpi_status status; 38 + char *uart; 39 + char *iotype; 40 + int baud_rate; 41 + int err; 42 + 43 + if (acpi_disabled) 44 + return -ENODEV; 45 + 46 + status = acpi_get_table_with_size(ACPI_SIG_SPCR, 0, 47 + (struct acpi_table_header **)&table, 48 + &table_size); 49 + 50 + if (ACPI_FAILURE(status)) 51 + return -ENOENT; 52 + 53 + if (table->header.revision < 2) { 54 + err = -ENOENT; 55 + pr_err("wrong table version\n"); 56 + goto done; 57 + } 58 + 59 + iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ? 60 + "mmio" : "io"; 61 + 62 + switch (table->interface_type) { 63 + case ACPI_DBG2_ARM_SBSA_32BIT: 64 + iotype = "mmio32"; 65 + /* fall through */ 66 + case ACPI_DBG2_ARM_PL011: 67 + case ACPI_DBG2_ARM_SBSA_GENERIC: 68 + case ACPI_DBG2_BCM2835: 69 + uart = "pl011"; 70 + break; 71 + case ACPI_DBG2_16550_COMPATIBLE: 72 + case ACPI_DBG2_16550_SUBSET: 73 + uart = "uart"; 74 + break; 75 + default: 76 + err = -ENOENT; 77 + goto done; 78 + } 79 + 80 + switch (table->baud_rate) { 81 + case 3: 82 + baud_rate = 9600; 83 + break; 84 + case 4: 85 + baud_rate = 19200; 86 + break; 87 + case 6: 88 + baud_rate = 57600; 89 + break; 90 + case 7: 91 + baud_rate = 115200; 92 + break; 93 + default: 94 + err = -ENOENT; 95 + goto done; 96 + } 97 + 98 + snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype, 99 + table->serial_port.address, baud_rate); 100 + 101 + pr_info("console: %s\n", opts); 102 + 103 + if (earlycon) 104 + setup_earlycon(opts); 105 + 106 + err = add_preferred_console(uart, 0, opts + strlen(uart) + 1); 107 + 108 + done: 109 + early_acpi_os_unmap_memory((void __iomem *)table, table_size); 110 + return err; 111 + }
+15 -24
drivers/dma/dw/core.c
··· 46 46 u8 _dmsize = _is_slave ? _sconfig->dst_maxburst : \ 47 47 DW_DMA_MSIZE_16; \ 48 48 u8 _dms = (_dwc->direction == DMA_MEM_TO_DEV) ? \ 49 - _dwc->p_master : _dwc->m_master; \ 49 + _dwc->dws.p_master : _dwc->dws.m_master; \ 50 50 u8 _sms = (_dwc->direction == DMA_DEV_TO_MEM) ? \ 51 - _dwc->p_master : _dwc->m_master; \ 51 + _dwc->dws.p_master : _dwc->dws.m_master; \ 52 52 \ 53 53 (DWC_CTLL_DST_MSIZE(_dmsize) \ 54 54 | DWC_CTLL_SRC_MSIZE(_smsize) \ ··· 143 143 struct dw_dma *dw = to_dw_dma(dwc->chan.device); 144 144 u32 cfghi = DWC_CFGH_FIFO_MODE; 145 145 u32 cfglo = DWC_CFGL_CH_PRIOR(dwc->priority); 146 + bool hs_polarity = dwc->dws.hs_polarity; 146 147 147 148 if (test_bit(DW_DMA_IS_INITIALIZED, &dwc->flags)) 148 149 return; 149 150 150 - cfghi |= DWC_CFGH_DST_PER(dwc->dst_id); 151 - cfghi |= DWC_CFGH_SRC_PER(dwc->src_id); 151 + cfghi |= DWC_CFGH_DST_PER(dwc->dws.dst_id); 152 + cfghi |= DWC_CFGH_SRC_PER(dwc->dws.src_id); 153 + 154 + /* Set polarity of handshake interface */ 155 + cfglo |= hs_polarity ? DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL : 0; 152 156 153 157 channel_writel(dwc, CFG_LO, cfglo); 154 158 channel_writel(dwc, CFG_HI, cfghi); ··· 213 209 static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first) 214 210 { 215 211 struct dw_dma *dw = to_dw_dma(dwc->chan.device); 216 - u8 lms = DWC_LLP_LMS(dwc->m_master); 212 + u8 lms = DWC_LLP_LMS(dwc->dws.m_master); 217 213 unsigned long was_soft_llp; 218 214 219 215 /* ASSERT: channel is idle */ ··· 666 662 struct dw_desc *prev; 667 663 size_t xfer_count; 668 664 size_t offset; 669 - u8 m_master = dwc->m_master; 665 + u8 m_master = dwc->dws.m_master; 670 666 unsigned int src_width; 671 667 unsigned int dst_width; 672 668 unsigned int data_width = dw->pdata->data_width[m_master]; ··· 744 740 struct dw_desc *prev; 745 741 struct dw_desc *first; 746 742 u32 ctllo; 747 - u8 m_master = dwc->m_master; 743 + u8 m_master = dwc->dws.m_master; 748 744 u8 lms = DWC_LLP_LMS(m_master); 749 745 dma_addr_t reg; 750 746 unsigned int reg_width; ··· 899 895 return false; 900 896 901 897 /* We have to copy data since dws can be temporary storage */ 902 - 903 - dwc->src_id = dws->src_id; 904 - dwc->dst_id = dws->dst_id; 905 - 906 - dwc->m_master = dws->m_master; 907 - dwc->p_master = dws->p_master; 898 + memcpy(&dwc->dws, dws, sizeof(struct dw_dma_slave)); 908 899 909 900 return true; 910 901 } ··· 1166 1167 spin_lock_irqsave(&dwc->lock, flags); 1167 1168 1168 1169 /* Clear custom channel configuration */ 1169 - dwc->src_id = 0; 1170 - dwc->dst_id = 0; 1171 - 1172 - dwc->m_master = 0; 1173 - dwc->p_master = 0; 1170 + memset(&dwc->dws, 0, sizeof(struct dw_dma_slave)); 1174 1171 1175 1172 clear_bit(DW_DMA_IS_INITIALIZED, &dwc->flags); 1176 1173 ··· 1259 1264 struct dw_cyclic_desc *retval = NULL; 1260 1265 struct dw_desc *desc; 1261 1266 struct dw_desc *last = NULL; 1262 - u8 lms = DWC_LLP_LMS(dwc->m_master); 1267 + u8 lms = DWC_LLP_LMS(dwc->dws.m_master); 1263 1268 unsigned long was_cyclic; 1264 1269 unsigned int reg_width; 1265 1270 unsigned int periods; ··· 1571 1576 (dwc_params >> DWC_PARAMS_MBLK_EN & 0x1) == 0; 1572 1577 } else { 1573 1578 dwc->block_size = pdata->block_size; 1574 - 1575 - /* Check if channel supports multi block transfer */ 1576 - channel_writel(dwc, LLP, DWC_LLP_LOC(0xffffffff)); 1577 - dwc->nollp = DWC_LLP_LOC(channel_readl(dwc, LLP)) == 0; 1578 - channel_writel(dwc, LLP, 0); 1579 + dwc->nollp = pdata->is_nollp; 1579 1580 } 1580 1581 } 1581 1582
+1 -4
drivers/dma/dw/regs.h
··· 245 245 bool nollp; 246 246 247 247 /* custom slave configuration */ 248 - u8 src_id; 249 - u8 dst_id; 250 - u8 m_master; 251 - u8 p_master; 248 + struct dw_dma_slave dws; 252 249 253 250 /* configuration passed via .device_config */ 254 251 struct dma_slave_config dma_sconfig;
+4 -5
drivers/dma/hsu/hsu.c
··· 200 200 * is not a normal timeout interrupt, ie. hsu_dma_get_status() returned 0. 201 201 * 202 202 * Return: 203 - * IRQ_NONE for invalid channel number, IRQ_HANDLED otherwise. 203 + * 0 for invalid channel number, 1 otherwise. 204 204 */ 205 - irqreturn_t hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr, 206 - u32 status) 205 + int hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr, u32 status) 207 206 { 208 207 struct hsu_dma_chan *hsuc; 209 208 struct hsu_dma_desc *desc; ··· 210 211 211 212 /* Sanity check */ 212 213 if (nr >= chip->hsu->nr_channels) 213 - return IRQ_NONE; 214 + return 0; 214 215 215 216 hsuc = &chip->hsu->chan[nr]; 216 217 ··· 229 230 } 230 231 spin_unlock_irqrestore(&hsuc->vchan.lock, flags); 231 232 232 - return IRQ_HANDLED; 233 + return 1; 233 234 } 234 235 EXPORT_SYMBOL_GPL(hsu_dma_do_irq); 235 236
+3 -3
drivers/dma/hsu/pci.c
··· 29 29 u32 dmaisr; 30 30 u32 status; 31 31 unsigned short i; 32 - irqreturn_t ret = IRQ_NONE; 32 + int ret = 0; 33 33 int err; 34 34 35 35 dmaisr = readl(chip->regs + HSU_PCI_DMAISR); ··· 37 37 if (dmaisr & 0x1) { 38 38 err = hsu_dma_get_status(chip, i, &status); 39 39 if (err > 0) 40 - ret |= IRQ_HANDLED; 40 + ret |= 1; 41 41 else if (err == 0) 42 42 ret |= hsu_dma_do_irq(chip, i, status); 43 43 } 44 44 dmaisr >>= 1; 45 45 } 46 46 47 - return ret; 47 + return IRQ_RETVAL(ret); 48 48 } 49 49 50 50 static int hsu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+34 -22
drivers/dma/imx-sdma.c
··· 648 648 writel_relaxed(val, sdma->regs + chnenbl); 649 649 } 650 650 651 - static void sdma_handle_channel_loop(struct sdma_channel *sdmac) 652 - { 653 - if (sdmac->desc.callback) 654 - sdmac->desc.callback(sdmac->desc.callback_param); 655 - } 656 - 657 651 static void sdma_update_channel_loop(struct sdma_channel *sdmac) 658 652 { 659 653 struct sdma_buffer_descriptor *bd; 654 + int error = 0; 655 + enum dma_status old_status = sdmac->status; 660 656 661 657 /* 662 658 * loop mode. Iterate over descriptors, re-setup them and ··· 664 668 if (bd->mode.status & BD_DONE) 665 669 break; 666 670 667 - if (bd->mode.status & BD_RROR) 671 + if (bd->mode.status & BD_RROR) { 672 + bd->mode.status &= ~BD_RROR; 668 673 sdmac->status = DMA_ERROR; 674 + error = -EIO; 675 + } 669 676 677 + /* 678 + * We use bd->mode.count to calculate the residue, since contains 679 + * the number of bytes present in the current buffer descriptor. 680 + */ 681 + 682 + sdmac->chn_real_count = bd->mode.count; 670 683 bd->mode.status |= BD_DONE; 684 + bd->mode.count = sdmac->period_len; 685 + 686 + /* 687 + * The callback is called from the interrupt context in order 688 + * to reduce latency and to avoid the risk of altering the 689 + * SDMA transaction status by the time the client tasklet is 690 + * executed. 691 + */ 692 + 693 + if (sdmac->desc.callback) 694 + sdmac->desc.callback(sdmac->desc.callback_param); 695 + 671 696 sdmac->buf_tail++; 672 697 sdmac->buf_tail %= sdmac->num_bd; 698 + 699 + if (error) 700 + sdmac->status = old_status; 673 701 } 674 702 } 675 703 676 - static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac) 704 + static void mxc_sdma_handle_channel_normal(unsigned long data) 677 705 { 706 + struct sdma_channel *sdmac = (struct sdma_channel *) data; 678 707 struct sdma_buffer_descriptor *bd; 679 708 int i, error = 0; 680 709 ··· 726 705 sdmac->desc.callback(sdmac->desc.callback_param); 727 706 } 728 707 729 - static void sdma_tasklet(unsigned long data) 730 - { 731 - struct sdma_channel *sdmac = (struct sdma_channel *) data; 732 - 733 - if (sdmac->flags & IMX_DMA_SG_LOOP) 734 - sdma_handle_channel_loop(sdmac); 735 - else 736 - mxc_sdma_handle_channel_normal(sdmac); 737 - } 738 - 739 708 static irqreturn_t sdma_int_handler(int irq, void *dev_id) 740 709 { 741 710 struct sdma_engine *sdma = dev_id; ··· 742 731 743 732 if (sdmac->flags & IMX_DMA_SG_LOOP) 744 733 sdma_update_channel_loop(sdmac); 745 - 746 - tasklet_schedule(&sdmac->tasklet); 734 + else 735 + tasklet_schedule(&sdmac->tasklet); 747 736 748 737 __clear_bit(channel, &stat); 749 738 } ··· 1364 1353 u32 residue; 1365 1354 1366 1355 if (sdmac->flags & IMX_DMA_SG_LOOP) 1367 - residue = (sdmac->num_bd - sdmac->buf_tail) * sdmac->period_len; 1356 + residue = (sdmac->num_bd - sdmac->buf_tail) * 1357 + sdmac->period_len - sdmac->chn_real_count; 1368 1358 else 1369 1359 residue = sdmac->chn_count - sdmac->chn_real_count; 1370 1360 ··· 1744 1732 dma_cookie_init(&sdmac->chan); 1745 1733 sdmac->channel = i; 1746 1734 1747 - tasklet_init(&sdmac->tasklet, sdma_tasklet, 1735 + tasklet_init(&sdmac->tasklet, mxc_sdma_handle_channel_normal, 1748 1736 (unsigned long) sdmac); 1749 1737 /* 1750 1738 * Add the channel to the DMAC list. Do not add channel 0 though
+1 -10
drivers/of/fdt.c
··· 924 924 925 925 #ifdef CONFIG_SERIAL_EARLYCON 926 926 927 - static int __init early_init_dt_scan_chosen_serial(void) 927 + int __init early_init_dt_scan_chosen_stdout(void) 928 928 { 929 929 int offset; 930 930 const char *p, *q, *options = NULL; ··· 968 968 } 969 969 return -ENODEV; 970 970 } 971 - 972 - static int __init setup_of_earlycon(char *buf) 973 - { 974 - if (buf) 975 - return 0; 976 - 977 - return early_init_dt_scan_chosen_serial(); 978 - } 979 - early_param("earlycon", setup_of_earlycon); 980 971 #endif 981 972 982 973 /**
+1 -1
drivers/tty/pty.c
··· 800 800 return retval; 801 801 } 802 802 803 - static struct file_operations ptmx_fops; 803 + static struct file_operations ptmx_fops __ro_after_init; 804 804 805 805 static void __init unix98_pty_init(void) 806 806 {
+5
drivers/tty/serial/8250/8250.h
··· 31 31 struct dma_chan *rxchan; 32 32 struct dma_chan *txchan; 33 33 34 + /* Device address base for DMA operations */ 35 + phys_addr_t rx_dma_addr; 36 + phys_addr_t tx_dma_addr; 37 + 38 + /* DMA address of the buffer in memory */ 34 39 dma_addr_t rx_addr; 35 40 dma_addr_t tx_addr; 36 41
+1 -1
drivers/tty/serial/8250/8250_core.c
··· 639 639 { 640 640 char match[] = "uart"; /* 8250-specific earlycon name */ 641 641 unsigned char iotype; 642 - unsigned long addr; 642 + resource_size_t addr; 643 643 int i; 644 644 645 645 if (strncmp(name, match, 4) != 0)
+9 -5
drivers/tty/serial/8250/8250_dma.c
··· 142 142 if (dma->rx_running) { 143 143 dmaengine_pause(dma->rxchan); 144 144 __dma_rx_complete(p); 145 - dmaengine_terminate_all(dma->rxchan); 145 + dmaengine_terminate_async(dma->rxchan); 146 146 } 147 147 } 148 148 EXPORT_SYMBOL_GPL(serial8250_rx_dma_flush); ··· 150 150 int serial8250_request_dma(struct uart_8250_port *p) 151 151 { 152 152 struct uart_8250_dma *dma = p->dma; 153 + phys_addr_t rx_dma_addr = dma->rx_dma_addr ? 154 + dma->rx_dma_addr : p->port.mapbase; 155 + phys_addr_t tx_dma_addr = dma->tx_dma_addr ? 156 + dma->tx_dma_addr : p->port.mapbase; 153 157 dma_cap_mask_t mask; 154 158 struct dma_slave_caps caps; 155 159 int ret; ··· 161 157 /* Default slave configuration parameters */ 162 158 dma->rxconf.direction = DMA_DEV_TO_MEM; 163 159 dma->rxconf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 164 - dma->rxconf.src_addr = p->port.mapbase + UART_RX; 160 + dma->rxconf.src_addr = rx_dma_addr + UART_RX; 165 161 166 162 dma->txconf.direction = DMA_MEM_TO_DEV; 167 163 dma->txconf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 168 - dma->txconf.dst_addr = p->port.mapbase + UART_TX; 164 + dma->txconf.dst_addr = tx_dma_addr + UART_TX; 169 165 170 166 dma_cap_zero(mask); 171 167 dma_cap_set(DMA_SLAVE, mask); ··· 251 247 return; 252 248 253 249 /* Release RX resources */ 254 - dmaengine_terminate_all(dma->rxchan); 250 + dmaengine_terminate_sync(dma->rxchan); 255 251 dma_free_coherent(dma->rxchan->device->dev, dma->rx_size, dma->rx_buf, 256 252 dma->rx_addr); 257 253 dma_release_channel(dma->rxchan); 258 254 dma->rxchan = NULL; 259 255 260 256 /* Release TX resources */ 261 - dmaengine_terminate_all(dma->txchan); 257 + dmaengine_terminate_sync(dma->txchan); 262 258 dma_unmap_single(dma->txchan->device->dev, dma->tx_addr, 263 259 UART_XMIT_SIZE, DMA_TO_DEVICE); 264 260 dma_release_channel(dma->txchan);
+25 -23
drivers/tty/serial/8250/8250_dw.c
··· 365 365 struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 366 366 int irq = platform_get_irq(pdev, 0); 367 367 struct uart_port *p = &uart.port; 368 + struct device *dev = &pdev->dev; 368 369 struct dw8250_data *data; 369 370 int err; 370 371 u32 val; 371 372 372 373 if (!regs) { 373 - dev_err(&pdev->dev, "no registers defined\n"); 374 + dev_err(dev, "no registers defined\n"); 374 375 return -EINVAL; 375 376 } 376 377 377 378 if (irq < 0) { 378 379 if (irq != -EPROBE_DEFER) 379 - dev_err(&pdev->dev, "cannot get irq\n"); 380 + dev_err(dev, "cannot get irq\n"); 380 381 return irq; 381 382 } 382 383 ··· 388 387 p->pm = dw8250_do_pm; 389 388 p->type = PORT_8250; 390 389 p->flags = UPF_SHARE_IRQ | UPF_FIXED_PORT; 391 - p->dev = &pdev->dev; 390 + p->dev = dev; 392 391 p->iotype = UPIO_MEM; 393 392 p->serial_in = dw8250_serial_in; 394 393 p->serial_out = dw8250_serial_out; 395 394 396 - p->membase = devm_ioremap(&pdev->dev, regs->start, resource_size(regs)); 395 + p->membase = devm_ioremap(dev, regs->start, resource_size(regs)); 397 396 if (!p->membase) 398 397 return -ENOMEM; 399 398 400 - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 399 + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 401 400 if (!data) 402 401 return -ENOMEM; 403 402 ··· 405 404 data->usr_reg = DW_UART_USR; 406 405 p->private_data = data; 407 406 408 - data->uart_16550_compatible = device_property_read_bool(p->dev, 407 + data->uart_16550_compatible = device_property_read_bool(dev, 409 408 "snps,uart-16550-compatible"); 410 409 411 - err = device_property_read_u32(p->dev, "reg-shift", &val); 410 + err = device_property_read_u32(dev, "reg-shift", &val); 412 411 if (!err) 413 412 p->regshift = val; 414 413 415 - err = device_property_read_u32(p->dev, "reg-io-width", &val); 414 + err = device_property_read_u32(dev, "reg-io-width", &val); 416 415 if (!err && val == 4) { 417 416 p->iotype = UPIO_MEM32; 418 417 p->serial_in = dw8250_serial_in32; 419 418 p->serial_out = dw8250_serial_out32; 420 419 } 421 420 422 - if (device_property_read_bool(p->dev, "dcd-override")) { 421 + if (device_property_read_bool(dev, "dcd-override")) { 423 422 /* Always report DCD as active */ 424 423 data->msr_mask_on |= UART_MSR_DCD; 425 424 data->msr_mask_off |= UART_MSR_DDCD; 426 425 } 427 426 428 - if (device_property_read_bool(p->dev, "dsr-override")) { 427 + if (device_property_read_bool(dev, "dsr-override")) { 429 428 /* Always report DSR as active */ 430 429 data->msr_mask_on |= UART_MSR_DSR; 431 430 data->msr_mask_off |= UART_MSR_DDSR; 432 431 } 433 432 434 - if (device_property_read_bool(p->dev, "cts-override")) { 433 + if (device_property_read_bool(dev, "cts-override")) { 435 434 /* Always report CTS as active */ 436 435 data->msr_mask_on |= UART_MSR_CTS; 437 436 data->msr_mask_off |= UART_MSR_DCTS; 438 437 } 439 438 440 - if (device_property_read_bool(p->dev, "ri-override")) { 439 + if (device_property_read_bool(dev, "ri-override")) { 441 440 /* Always report Ring indicator as inactive */ 442 441 data->msr_mask_off |= UART_MSR_RI; 443 442 data->msr_mask_off |= UART_MSR_TERI; 444 443 } 445 444 446 445 /* Always ask for fixed clock rate from a property. */ 447 - device_property_read_u32(p->dev, "clock-frequency", &p->uartclk); 446 + device_property_read_u32(dev, "clock-frequency", &p->uartclk); 448 447 449 448 /* If there is separate baudclk, get the rate from it. */ 450 - data->clk = devm_clk_get(&pdev->dev, "baudclk"); 449 + data->clk = devm_clk_get(dev, "baudclk"); 451 450 if (IS_ERR(data->clk) && PTR_ERR(data->clk) != -EPROBE_DEFER) 452 - data->clk = devm_clk_get(&pdev->dev, NULL); 451 + data->clk = devm_clk_get(dev, NULL); 453 452 if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) 454 453 return -EPROBE_DEFER; 455 454 if (!IS_ERR_OR_NULL(data->clk)) { 456 455 err = clk_prepare_enable(data->clk); 457 456 if (err) 458 - dev_warn(&pdev->dev, "could not enable optional baudclk: %d\n", 457 + dev_warn(dev, "could not enable optional baudclk: %d\n", 459 458 err); 460 459 else 461 460 p->uartclk = clk_get_rate(data->clk); ··· 463 462 464 463 /* If no clock rate is defined, fail. */ 465 464 if (!p->uartclk) { 466 - dev_err(&pdev->dev, "clock rate not defined\n"); 465 + dev_err(dev, "clock rate not defined\n"); 467 466 return -EINVAL; 468 467 } 469 468 470 - data->pclk = devm_clk_get(&pdev->dev, "apb_pclk"); 471 - if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) { 469 + data->pclk = devm_clk_get(dev, "apb_pclk"); 470 + if (IS_ERR(data->pclk) && PTR_ERR(data->pclk) == -EPROBE_DEFER) { 472 471 err = -EPROBE_DEFER; 473 472 goto err_clk; 474 473 } 475 474 if (!IS_ERR(data->pclk)) { 476 475 err = clk_prepare_enable(data->pclk); 477 476 if (err) { 478 - dev_err(&pdev->dev, "could not enable apb_pclk\n"); 477 + dev_err(dev, "could not enable apb_pclk\n"); 479 478 goto err_clk; 480 479 } 481 480 } 482 481 483 - data->rst = devm_reset_control_get_optional(&pdev->dev, NULL); 482 + data->rst = devm_reset_control_get_optional(dev, NULL); 484 483 if (IS_ERR(data->rst) && PTR_ERR(data->rst) == -EPROBE_DEFER) { 485 484 err = -EPROBE_DEFER; 486 485 goto err_pclk; ··· 512 511 513 512 platform_set_drvdata(pdev, data); 514 513 515 - pm_runtime_set_active(&pdev->dev); 516 - pm_runtime_enable(&pdev->dev); 514 + pm_runtime_set_active(dev); 515 + pm_runtime_enable(dev); 517 516 518 517 return 0; 519 518 ··· 625 624 { "APMC0D08", 0}, 626 625 { "AMD0020", 0 }, 627 626 { "AMDI0020", 0 }, 627 + { "HISI0031", 0 }, 628 628 { }, 629 629 }; 630 630 MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match);
+378
drivers/tty/serial/8250/8250_lpss.c
··· 1 + /* 2 + * 8250_lpss.c - Driver for UART on Intel Braswell and various other Intel SoCs 3 + * 4 + * Copyright (C) 2016 Intel Corporation 5 + * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/bitops.h> 13 + #include <linux/module.h> 14 + #include <linux/pci.h> 15 + #include <linux/rational.h> 16 + 17 + #include <linux/dmaengine.h> 18 + #include <linux/dma/dw.h> 19 + 20 + #include "8250.h" 21 + 22 + #define PCI_DEVICE_ID_INTEL_QRK_UARTx 0x0936 23 + 24 + #define PCI_DEVICE_ID_INTEL_BYT_UART1 0x0f0a 25 + #define PCI_DEVICE_ID_INTEL_BYT_UART2 0x0f0c 26 + 27 + #define PCI_DEVICE_ID_INTEL_BSW_UART1 0x228a 28 + #define PCI_DEVICE_ID_INTEL_BSW_UART2 0x228c 29 + 30 + #define PCI_DEVICE_ID_INTEL_BDW_UART1 0x9ce3 31 + #define PCI_DEVICE_ID_INTEL_BDW_UART2 0x9ce4 32 + 33 + /* Intel LPSS specific registers */ 34 + 35 + #define BYT_PRV_CLK 0x800 36 + #define BYT_PRV_CLK_EN BIT(0) 37 + #define BYT_PRV_CLK_M_VAL_SHIFT 1 38 + #define BYT_PRV_CLK_N_VAL_SHIFT 16 39 + #define BYT_PRV_CLK_UPDATE BIT(31) 40 + 41 + #define BYT_TX_OVF_INT 0x820 42 + #define BYT_TX_OVF_INT_MASK BIT(1) 43 + 44 + struct lpss8250; 45 + 46 + struct lpss8250_board { 47 + unsigned long freq; 48 + unsigned int base_baud; 49 + int (*setup)(struct lpss8250 *, struct uart_port *p); 50 + void (*exit)(struct lpss8250 *); 51 + }; 52 + 53 + struct lpss8250 { 54 + int line; 55 + struct lpss8250_board *board; 56 + 57 + /* DMA parameters */ 58 + struct uart_8250_dma dma; 59 + struct dw_dma_chip dma_chip; 60 + struct dw_dma_slave dma_param; 61 + u8 dma_maxburst; 62 + }; 63 + 64 + static void byt_set_termios(struct uart_port *p, struct ktermios *termios, 65 + struct ktermios *old) 66 + { 67 + unsigned int baud = tty_termios_baud_rate(termios); 68 + struct lpss8250 *lpss = p->private_data; 69 + unsigned long fref = lpss->board->freq, fuart = baud * 16; 70 + unsigned long w = BIT(15) - 1; 71 + unsigned long m, n; 72 + u32 reg; 73 + 74 + /* Gracefully handle the B0 case: fall back to B9600 */ 75 + fuart = fuart ? fuart : 9600 * 16; 76 + 77 + /* Get Fuart closer to Fref */ 78 + fuart *= rounddown_pow_of_two(fref / fuart); 79 + 80 + /* 81 + * For baud rates 0.5M, 1M, 1.5M, 2M, 2.5M, 3M, 3.5M and 4M the 82 + * dividers must be adjusted. 83 + * 84 + * uartclk = (m / n) * 100 MHz, where m <= n 85 + */ 86 + rational_best_approximation(fuart, fref, w, w, &m, &n); 87 + p->uartclk = fuart; 88 + 89 + /* Reset the clock */ 90 + reg = (m << BYT_PRV_CLK_M_VAL_SHIFT) | (n << BYT_PRV_CLK_N_VAL_SHIFT); 91 + writel(reg, p->membase + BYT_PRV_CLK); 92 + reg |= BYT_PRV_CLK_EN | BYT_PRV_CLK_UPDATE; 93 + writel(reg, p->membase + BYT_PRV_CLK); 94 + 95 + p->status &= ~UPSTAT_AUTOCTS; 96 + if (termios->c_cflag & CRTSCTS) 97 + p->status |= UPSTAT_AUTOCTS; 98 + 99 + serial8250_do_set_termios(p, termios, old); 100 + } 101 + 102 + static unsigned int byt_get_mctrl(struct uart_port *port) 103 + { 104 + unsigned int ret = serial8250_do_get_mctrl(port); 105 + 106 + /* Force DCD and DSR signals to permanently be reported as active */ 107 + ret |= TIOCM_CAR | TIOCM_DSR; 108 + 109 + return ret; 110 + } 111 + 112 + static int byt_serial_setup(struct lpss8250 *lpss, struct uart_port *port) 113 + { 114 + struct dw_dma_slave *param = &lpss->dma_param; 115 + struct uart_8250_port *up = up_to_u8250p(port); 116 + struct pci_dev *pdev = to_pci_dev(port->dev); 117 + unsigned int dma_devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0); 118 + struct pci_dev *dma_dev = pci_get_slot(pdev->bus, dma_devfn); 119 + 120 + switch (pdev->device) { 121 + case PCI_DEVICE_ID_INTEL_BYT_UART1: 122 + case PCI_DEVICE_ID_INTEL_BSW_UART1: 123 + case PCI_DEVICE_ID_INTEL_BDW_UART1: 124 + param->src_id = 3; 125 + param->dst_id = 2; 126 + break; 127 + case PCI_DEVICE_ID_INTEL_BYT_UART2: 128 + case PCI_DEVICE_ID_INTEL_BSW_UART2: 129 + case PCI_DEVICE_ID_INTEL_BDW_UART2: 130 + param->src_id = 5; 131 + param->dst_id = 4; 132 + break; 133 + default: 134 + return -EINVAL; 135 + } 136 + 137 + param->dma_dev = &dma_dev->dev; 138 + param->m_master = 0; 139 + param->p_master = 1; 140 + 141 + /* TODO: Detect FIFO size automaticaly for DesignWare 8250 */ 142 + port->fifosize = 64; 143 + up->tx_loadsz = 64; 144 + 145 + lpss->dma_maxburst = 16; 146 + 147 + port->set_termios = byt_set_termios; 148 + port->get_mctrl = byt_get_mctrl; 149 + 150 + /* Disable TX counter interrupts */ 151 + writel(BYT_TX_OVF_INT_MASK, port->membase + BYT_TX_OVF_INT); 152 + 153 + return 0; 154 + } 155 + 156 + #ifdef CONFIG_SERIAL_8250_DMA 157 + static const struct dw_dma_platform_data qrk_serial_dma_pdata = { 158 + .nr_channels = 2, 159 + .is_private = true, 160 + .is_nollp = true, 161 + .chan_allocation_order = CHAN_ALLOCATION_ASCENDING, 162 + .chan_priority = CHAN_PRIORITY_ASCENDING, 163 + .block_size = 4095, 164 + .nr_masters = 1, 165 + .data_width = {4}, 166 + }; 167 + 168 + static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) 169 + { 170 + struct uart_8250_dma *dma = &lpss->dma; 171 + struct dw_dma_chip *chip = &lpss->dma_chip; 172 + struct dw_dma_slave *param = &lpss->dma_param; 173 + struct pci_dev *pdev = to_pci_dev(port->dev); 174 + int ret; 175 + 176 + chip->dev = &pdev->dev; 177 + chip->irq = pdev->irq; 178 + chip->regs = pci_ioremap_bar(pdev, 1); 179 + chip->pdata = &qrk_serial_dma_pdata; 180 + 181 + /* Falling back to PIO mode if DMA probing fails */ 182 + ret = dw_dma_probe(chip); 183 + if (ret) 184 + return; 185 + 186 + /* Special DMA address for UART */ 187 + dma->rx_dma_addr = 0xfffff000; 188 + dma->tx_dma_addr = 0xfffff000; 189 + 190 + param->dma_dev = &pdev->dev; 191 + param->src_id = 0; 192 + param->dst_id = 1; 193 + param->hs_polarity = true; 194 + 195 + lpss->dma_maxburst = 8; 196 + } 197 + 198 + static void qrk_serial_exit_dma(struct lpss8250 *lpss) 199 + { 200 + struct dw_dma_slave *param = &lpss->dma_param; 201 + 202 + if (!param->dma_dev) 203 + return; 204 + dw_dma_remove(&lpss->dma_chip); 205 + } 206 + #else /* CONFIG_SERIAL_8250_DMA */ 207 + static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) {} 208 + static void qrk_serial_exit_dma(struct lpss8250 *lpss) {} 209 + #endif /* !CONFIG_SERIAL_8250_DMA */ 210 + 211 + static int qrk_serial_setup(struct lpss8250 *lpss, struct uart_port *port) 212 + { 213 + struct pci_dev *pdev = to_pci_dev(port->dev); 214 + int ret; 215 + 216 + ret = pci_alloc_irq_vectors(pdev, 1, 1, 0); 217 + if (ret < 0) 218 + return ret; 219 + 220 + port->irq = pci_irq_vector(pdev, 0); 221 + 222 + qrk_serial_setup_dma(lpss, port); 223 + return 0; 224 + } 225 + 226 + static void qrk_serial_exit(struct lpss8250 *lpss) 227 + { 228 + qrk_serial_exit_dma(lpss); 229 + } 230 + 231 + static bool lpss8250_dma_filter(struct dma_chan *chan, void *param) 232 + { 233 + struct dw_dma_slave *dws = param; 234 + 235 + if (dws->dma_dev != chan->device->dev) 236 + return false; 237 + 238 + chan->private = dws; 239 + return true; 240 + } 241 + 242 + static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port) 243 + { 244 + struct uart_8250_dma *dma = &lpss->dma; 245 + struct dw_dma_slave *rx_param, *tx_param; 246 + struct device *dev = port->port.dev; 247 + 248 + if (!lpss->dma_param.dma_dev) 249 + return 0; 250 + 251 + rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL); 252 + if (!rx_param) 253 + return -ENOMEM; 254 + 255 + tx_param = devm_kzalloc(dev, sizeof(*tx_param), GFP_KERNEL); 256 + if (!tx_param) 257 + return -ENOMEM; 258 + 259 + *rx_param = lpss->dma_param; 260 + dma->rxconf.src_maxburst = lpss->dma_maxburst; 261 + 262 + *tx_param = lpss->dma_param; 263 + dma->txconf.dst_maxburst = lpss->dma_maxburst; 264 + 265 + dma->fn = lpss8250_dma_filter; 266 + dma->rx_param = rx_param; 267 + dma->tx_param = tx_param; 268 + 269 + port->dma = dma; 270 + return 0; 271 + } 272 + 273 + static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id) 274 + { 275 + struct uart_8250_port uart; 276 + struct lpss8250 *lpss; 277 + int ret; 278 + 279 + ret = pcim_enable_device(pdev); 280 + if (ret) 281 + return ret; 282 + 283 + pci_set_master(pdev); 284 + 285 + lpss = devm_kzalloc(&pdev->dev, sizeof(*lpss), GFP_KERNEL); 286 + if (!lpss) 287 + return -ENOMEM; 288 + 289 + lpss->board = (struct lpss8250_board *)id->driver_data; 290 + 291 + memset(&uart, 0, sizeof(struct uart_8250_port)); 292 + 293 + uart.port.dev = &pdev->dev; 294 + uart.port.irq = pdev->irq; 295 + uart.port.private_data = lpss; 296 + uart.port.type = PORT_16550A; 297 + uart.port.iotype = UPIO_MEM; 298 + uart.port.regshift = 2; 299 + uart.port.uartclk = lpss->board->base_baud * 16; 300 + uart.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT | UPF_FIXED_TYPE; 301 + uart.capabilities = UART_CAP_FIFO | UART_CAP_AFE; 302 + uart.port.mapbase = pci_resource_start(pdev, 0); 303 + uart.port.membase = pcim_iomap(pdev, 0, 0); 304 + if (!uart.port.membase) 305 + return -ENOMEM; 306 + 307 + ret = lpss->board->setup(lpss, &uart.port); 308 + if (ret) 309 + return ret; 310 + 311 + ret = lpss8250_dma_setup(lpss, &uart); 312 + if (ret) 313 + goto err_exit; 314 + 315 + ret = serial8250_register_8250_port(&uart); 316 + if (ret < 0) 317 + goto err_exit; 318 + 319 + lpss->line = ret; 320 + 321 + pci_set_drvdata(pdev, lpss); 322 + return 0; 323 + 324 + err_exit: 325 + if (lpss->board->exit) 326 + lpss->board->exit(lpss); 327 + return ret; 328 + } 329 + 330 + static void lpss8250_remove(struct pci_dev *pdev) 331 + { 332 + struct lpss8250 *lpss = pci_get_drvdata(pdev); 333 + 334 + if (lpss->board->exit) 335 + lpss->board->exit(lpss); 336 + 337 + serial8250_unregister_port(lpss->line); 338 + } 339 + 340 + static const struct lpss8250_board byt_board = { 341 + .freq = 100000000, 342 + .base_baud = 2764800, 343 + .setup = byt_serial_setup, 344 + }; 345 + 346 + static const struct lpss8250_board qrk_board = { 347 + .freq = 44236800, 348 + .base_baud = 2764800, 349 + .setup = qrk_serial_setup, 350 + .exit = qrk_serial_exit, 351 + }; 352 + 353 + #define LPSS_DEVICE(id, board) { PCI_VDEVICE(INTEL, id), (kernel_ulong_t)&board } 354 + 355 + static const struct pci_device_id pci_ids[] = { 356 + LPSS_DEVICE(PCI_DEVICE_ID_INTEL_QRK_UARTx, qrk_board), 357 + LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BYT_UART1, byt_board), 358 + LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BYT_UART2, byt_board), 359 + LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BSW_UART1, byt_board), 360 + LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BSW_UART2, byt_board), 361 + LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BDW_UART1, byt_board), 362 + LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BDW_UART2, byt_board), 363 + { }, 364 + }; 365 + MODULE_DEVICE_TABLE(pci, pci_ids); 366 + 367 + static struct pci_driver lpss8250_pci_driver = { 368 + .name = "8250_lpss", 369 + .id_table = pci_ids, 370 + .probe = lpss8250_probe, 371 + .remove = lpss8250_remove, 372 + }; 373 + 374 + module_pci_driver(lpss8250_pci_driver); 375 + 376 + MODULE_AUTHOR("Intel Corporation"); 377 + MODULE_LICENSE("GPL v2"); 378 + MODULE_DESCRIPTION("Intel LPSS UART driver");
+4 -4
drivers/tty/serial/8250/8250_mid.c
··· 99 99 struct uart_8250_port *up = up_to_u8250p(p); 100 100 unsigned int fisr = serial_port_in(p, INTEL_MID_UART_DNV_FISR); 101 101 u32 status; 102 - int ret = IRQ_NONE; 102 + int ret = 0; 103 103 int err; 104 104 105 105 if (fisr & BIT(2)) { 106 106 err = hsu_dma_get_status(&mid->dma_chip, 1, &status); 107 107 if (err > 0) { 108 108 serial8250_rx_dma_flush(up); 109 - ret |= IRQ_HANDLED; 109 + ret |= 1; 110 110 } else if (err == 0) 111 111 ret |= hsu_dma_do_irq(&mid->dma_chip, 1, status); 112 112 } 113 113 if (fisr & BIT(1)) { 114 114 err = hsu_dma_get_status(&mid->dma_chip, 0, &status); 115 115 if (err > 0) 116 - ret |= IRQ_HANDLED; 116 + ret |= 1; 117 117 else if (err == 0) 118 118 ret |= hsu_dma_do_irq(&mid->dma_chip, 0, status); 119 119 } 120 120 if (fisr & BIT(0)) 121 121 ret |= serial8250_handle_irq(p, serial_port_in(p, UART_IIR)); 122 - return ret; 122 + return IRQ_RETVAL(ret); 123 123 } 124 124 125 125 #define DNV_DMA_CHAN_OFFSET 0x80
+1 -5
drivers/tty/serial/8250/8250_mtk.c
··· 62 62 */ 63 63 baud = uart_get_baud_rate(port, termios, old, 64 64 port->uartclk / 16 / 0xffff, 65 - port->uartclk / 16); 65 + port->uartclk); 66 66 67 67 if (baud <= 115200) { 68 68 serial_port_out(port, UART_MTK_HIGHS, 0x0); ··· 76 76 quot = DIV_ROUND_UP(port->uartclk, 4 * baud); 77 77 } else { 78 78 serial_port_out(port, UART_MTK_HIGHS, 0x3); 79 - 80 - /* Set to highest baudrate supported */ 81 - if (baud >= 1152000) 82 - baud = 921600; 83 79 quot = DIV_ROUND_UP(port->uartclk, 256 * baud); 84 80 } 85 81
+7
drivers/tty/serial/8250/8250_of.c
··· 195 195 switch (port_type) { 196 196 case PORT_8250 ... PORT_MAX_8250: 197 197 { 198 + u32 tx_threshold; 198 199 struct uart_8250_port port8250; 199 200 memset(&port8250, 0, sizeof(port8250)); 200 201 port8250.port = port; 201 202 202 203 if (port.fifosize) 203 204 port8250.capabilities = UART_CAP_FIFO; 205 + 206 + /* Check for TX FIFO threshold & set tx_loadsz */ 207 + if ((of_property_read_u32(ofdev->dev.of_node, "tx-threshold", 208 + &tx_threshold) == 0) && 209 + (tx_threshold < port.fifosize)) 210 + port8250.tx_loadsz = port.fifosize - tx_threshold; 204 211 205 212 if (of_property_read_bool(ofdev->dev.of_node, 206 213 "auto-flow-control"))
+43 -269
drivers/tty/serial/8250/8250_pci.c
··· 21 21 #include <linux/serial_core.h> 22 22 #include <linux/8250_pci.h> 23 23 #include <linux/bitops.h> 24 - #include <linux/rational.h> 25 24 26 25 #include <asm/byteorder.h> 27 26 #include <asm/io.h> 28 - 29 - #include <linux/dmaengine.h> 30 - #include <linux/platform_data/dma-dw.h> 31 27 32 28 #include "8250.h" 33 29 ··· 1345 1349 return ret; 1346 1350 } 1347 1351 1348 - #define PCI_DEVICE_ID_INTEL_BYT_UART1 0x0f0a 1349 - #define PCI_DEVICE_ID_INTEL_BYT_UART2 0x0f0c 1350 - 1351 - #define PCI_DEVICE_ID_INTEL_BSW_UART1 0x228a 1352 - #define PCI_DEVICE_ID_INTEL_BSW_UART2 0x228c 1353 - 1354 - #define PCI_DEVICE_ID_INTEL_BDW_UART1 0x9ce3 1355 - #define PCI_DEVICE_ID_INTEL_BDW_UART2 0x9ce4 1356 - 1357 - #define BYT_PRV_CLK 0x800 1358 - #define BYT_PRV_CLK_EN (1 << 0) 1359 - #define BYT_PRV_CLK_M_VAL_SHIFT 1 1360 - #define BYT_PRV_CLK_N_VAL_SHIFT 16 1361 - #define BYT_PRV_CLK_UPDATE (1 << 31) 1362 - 1363 - #define BYT_TX_OVF_INT 0x820 1364 - #define BYT_TX_OVF_INT_MASK (1 << 1) 1365 - 1366 - static void 1367 - byt_set_termios(struct uart_port *p, struct ktermios *termios, 1368 - struct ktermios *old) 1369 - { 1370 - unsigned int baud = tty_termios_baud_rate(termios); 1371 - unsigned long fref = 100000000, fuart = baud * 16; 1372 - unsigned long w = BIT(15) - 1; 1373 - unsigned long m, n; 1374 - u32 reg; 1375 - 1376 - /* Gracefully handle the B0 case: fall back to B9600 */ 1377 - fuart = fuart ? fuart : 9600 * 16; 1378 - 1379 - /* Get Fuart closer to Fref */ 1380 - fuart *= rounddown_pow_of_two(fref / fuart); 1381 - 1382 - /* 1383 - * For baud rates 0.5M, 1M, 1.5M, 2M, 2.5M, 3M, 3.5M and 4M the 1384 - * dividers must be adjusted. 1385 - * 1386 - * uartclk = (m / n) * 100 MHz, where m <= n 1387 - */ 1388 - rational_best_approximation(fuart, fref, w, w, &m, &n); 1389 - p->uartclk = fuart; 1390 - 1391 - /* Reset the clock */ 1392 - reg = (m << BYT_PRV_CLK_M_VAL_SHIFT) | (n << BYT_PRV_CLK_N_VAL_SHIFT); 1393 - writel(reg, p->membase + BYT_PRV_CLK); 1394 - reg |= BYT_PRV_CLK_EN | BYT_PRV_CLK_UPDATE; 1395 - writel(reg, p->membase + BYT_PRV_CLK); 1396 - 1397 - p->status &= ~UPSTAT_AUTOCTS; 1398 - if (termios->c_cflag & CRTSCTS) 1399 - p->status |= UPSTAT_AUTOCTS; 1400 - 1401 - serial8250_do_set_termios(p, termios, old); 1402 - } 1403 - 1404 - static bool byt_dma_filter(struct dma_chan *chan, void *param) 1405 - { 1406 - struct dw_dma_slave *dws = param; 1407 - 1408 - if (dws->dma_dev != chan->device->dev) 1409 - return false; 1410 - 1411 - chan->private = dws; 1412 - return true; 1413 - } 1414 - 1415 - static unsigned int 1416 - byt_get_mctrl(struct uart_port *port) 1417 - { 1418 - unsigned int ret = serial8250_do_get_mctrl(port); 1419 - 1420 - /* Force DCD and DSR signals to permanently be reported as active. */ 1421 - ret |= TIOCM_CAR | TIOCM_DSR; 1422 - 1423 - return ret; 1424 - } 1425 - 1426 - static int 1427 - byt_serial_setup(struct serial_private *priv, 1428 - const struct pciserial_board *board, 1429 - struct uart_8250_port *port, int idx) 1430 - { 1431 - struct pci_dev *pdev = priv->dev; 1432 - struct device *dev = port->port.dev; 1433 - struct uart_8250_dma *dma; 1434 - struct dw_dma_slave *tx_param, *rx_param; 1435 - struct pci_dev *dma_dev; 1436 - int ret; 1437 - 1438 - dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); 1439 - if (!dma) 1440 - return -ENOMEM; 1441 - 1442 - tx_param = devm_kzalloc(dev, sizeof(*tx_param), GFP_KERNEL); 1443 - if (!tx_param) 1444 - return -ENOMEM; 1445 - 1446 - rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL); 1447 - if (!rx_param) 1448 - return -ENOMEM; 1449 - 1450 - switch (pdev->device) { 1451 - case PCI_DEVICE_ID_INTEL_BYT_UART1: 1452 - case PCI_DEVICE_ID_INTEL_BSW_UART1: 1453 - case PCI_DEVICE_ID_INTEL_BDW_UART1: 1454 - rx_param->src_id = 3; 1455 - tx_param->dst_id = 2; 1456 - break; 1457 - case PCI_DEVICE_ID_INTEL_BYT_UART2: 1458 - case PCI_DEVICE_ID_INTEL_BSW_UART2: 1459 - case PCI_DEVICE_ID_INTEL_BDW_UART2: 1460 - rx_param->src_id = 5; 1461 - tx_param->dst_id = 4; 1462 - break; 1463 - default: 1464 - return -EINVAL; 1465 - } 1466 - 1467 - rx_param->m_master = 0; 1468 - rx_param->p_master = 1; 1469 - 1470 - dma->rxconf.src_maxburst = 16; 1471 - 1472 - tx_param->m_master = 0; 1473 - tx_param->p_master = 1; 1474 - 1475 - dma->txconf.dst_maxburst = 16; 1476 - 1477 - dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0)); 1478 - rx_param->dma_dev = &dma_dev->dev; 1479 - tx_param->dma_dev = &dma_dev->dev; 1480 - 1481 - dma->fn = byt_dma_filter; 1482 - dma->rx_param = rx_param; 1483 - dma->tx_param = tx_param; 1484 - 1485 - ret = pci_default_setup(priv, board, port, idx); 1486 - port->port.iotype = UPIO_MEM; 1487 - port->port.type = PORT_16550A; 1488 - port->port.flags = (port->port.flags | UPF_FIXED_PORT | UPF_FIXED_TYPE); 1489 - port->port.set_termios = byt_set_termios; 1490 - port->port.get_mctrl = byt_get_mctrl; 1491 - port->port.fifosize = 64; 1492 - port->tx_loadsz = 64; 1493 - port->dma = dma; 1494 - port->capabilities = UART_CAP_FIFO | UART_CAP_AFE; 1495 - 1496 - /* Disable Tx counter interrupts */ 1497 - writel(BYT_TX_OVF_INT_MASK, port->port.membase + BYT_TX_OVF_INT); 1498 - 1499 - return ret; 1500 - } 1501 - 1502 1352 static int 1503 1353 pci_omegapci_setup(struct serial_private *priv, 1504 1354 const struct pciserial_board *board, ··· 1583 1741 #define PCI_DEVICE_ID_EXAR_XR17V4358 0x4358 1584 1742 #define PCI_DEVICE_ID_EXAR_XR17V8358 0x8358 1585 1743 1744 + #define UART_EXAR_MPIOINT_7_0 0x8f /* MPIOINT[7:0] */ 1745 + #define UART_EXAR_MPIOLVL_7_0 0x90 /* MPIOLVL[7:0] */ 1746 + #define UART_EXAR_MPIO3T_7_0 0x91 /* MPIO3T[7:0] */ 1747 + #define UART_EXAR_MPIOINV_7_0 0x92 /* MPIOINV[7:0] */ 1748 + #define UART_EXAR_MPIOSEL_7_0 0x93 /* MPIOSEL[7:0] */ 1749 + #define UART_EXAR_MPIOOD_7_0 0x94 /* MPIOOD[7:0] */ 1750 + #define UART_EXAR_MPIOINT_15_8 0x95 /* MPIOINT[15:8] */ 1751 + #define UART_EXAR_MPIOLVL_15_8 0x96 /* MPIOLVL[15:8] */ 1752 + #define UART_EXAR_MPIO3T_15_8 0x97 /* MPIO3T[15:8] */ 1753 + #define UART_EXAR_MPIOINV_15_8 0x98 /* MPIOINV[15:8] */ 1754 + #define UART_EXAR_MPIOSEL_15_8 0x99 /* MPIOSEL[15:8] */ 1755 + #define UART_EXAR_MPIOOD_15_8 0x9a /* MPIOOD[15:8] */ 1756 + 1586 1757 static int 1587 1758 pci_xr17c154_setup(struct serial_private *priv, 1588 1759 const struct pciserial_board *board, ··· 1638 1783 * Setup Multipurpose Input/Output pins. 1639 1784 */ 1640 1785 if (idx == 0) { 1641 - writeb(0x00, p + 0x8f); /*MPIOINT[7:0]*/ 1642 - writeb(0x00, p + 0x90); /*MPIOLVL[7:0]*/ 1643 - writeb(0x00, p + 0x91); /*MPIO3T[7:0]*/ 1644 - writeb(0x00, p + 0x92); /*MPIOINV[7:0]*/ 1645 - writeb(0x00, p + 0x93); /*MPIOSEL[7:0]*/ 1646 - writeb(0x00, p + 0x94); /*MPIOOD[7:0]*/ 1647 - writeb(0x00, p + 0x95); /*MPIOINT[15:8]*/ 1648 - writeb(0x00, p + 0x96); /*MPIOLVL[15:8]*/ 1649 - writeb(0x00, p + 0x97); /*MPIO3T[15:8]*/ 1650 - writeb(0x00, p + 0x98); /*MPIOINV[15:8]*/ 1651 - writeb(0x00, p + 0x99); /*MPIOSEL[15:8]*/ 1652 - writeb(0x00, p + 0x9a); /*MPIOOD[15:8]*/ 1786 + writeb(0x00, p + UART_EXAR_MPIOINT_7_0); 1787 + writeb(0x00, p + UART_EXAR_MPIOLVL_7_0); 1788 + writeb(0x00, p + UART_EXAR_MPIO3T_7_0); 1789 + writeb(0x00, p + UART_EXAR_MPIOINV_7_0); 1790 + writeb(0x00, p + UART_EXAR_MPIOSEL_7_0); 1791 + writeb(0x00, p + UART_EXAR_MPIOOD_7_0); 1792 + writeb(0x00, p + UART_EXAR_MPIOINT_15_8); 1793 + writeb(0x00, p + UART_EXAR_MPIOLVL_15_8); 1794 + writeb(0x00, p + UART_EXAR_MPIO3T_15_8); 1795 + writeb(0x00, p + UART_EXAR_MPIOINV_15_8); 1796 + writeb(0x00, p + UART_EXAR_MPIOSEL_15_8); 1797 + writeb(0x00, p + UART_EXAR_MPIOOD_15_8); 1653 1798 } 1654 1799 writeb(0x00, p + UART_EXAR_8XMODE); 1655 1800 writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR); ··· 1685 1830 switch (priv->dev->device) { 1686 1831 case PCI_DEVICE_ID_COMMTECH_4222PCI335: 1687 1832 case PCI_DEVICE_ID_COMMTECH_4224PCI335: 1688 - writeb(0x78, p + 0x90); /* MPIOLVL[7:0] */ 1689 - writeb(0x00, p + 0x92); /* MPIOINV[7:0] */ 1690 - writeb(0x00, p + 0x93); /* MPIOSEL[7:0] */ 1833 + writeb(0x78, p + UART_EXAR_MPIOLVL_7_0); 1834 + writeb(0x00, p + UART_EXAR_MPIOINV_7_0); 1835 + writeb(0x00, p + UART_EXAR_MPIOSEL_7_0); 1691 1836 break; 1692 1837 case PCI_DEVICE_ID_COMMTECH_2324PCI335: 1693 1838 case PCI_DEVICE_ID_COMMTECH_2328PCI335: 1694 - writeb(0x00, p + 0x90); /* MPIOLVL[7:0] */ 1695 - writeb(0xc0, p + 0x92); /* MPIOINV[7:0] */ 1696 - writeb(0xc0, p + 0x93); /* MPIOSEL[7:0] */ 1839 + writeb(0x00, p + UART_EXAR_MPIOLVL_7_0); 1840 + writeb(0xc0, p + UART_EXAR_MPIOINV_7_0); 1841 + writeb(0xc0, p + UART_EXAR_MPIOSEL_7_0); 1697 1842 break; 1698 1843 } 1699 - writeb(0x00, p + 0x8f); /* MPIOINT[7:0] */ 1700 - writeb(0x00, p + 0x91); /* MPIO3T[7:0] */ 1701 - writeb(0x00, p + 0x94); /* MPIOOD[7:0] */ 1844 + writeb(0x00, p + UART_EXAR_MPIOINT_7_0); 1845 + writeb(0x00, p + UART_EXAR_MPIO3T_7_0); 1846 + writeb(0x00, p + UART_EXAR_MPIOOD_7_0); 1702 1847 } 1703 1848 writeb(0x00, p + UART_EXAR_8XMODE); 1704 1849 writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR); ··· 1789 1934 #define PCI_DEVICE_ID_COMMTECH_4222PCIE 0x0022 1790 1935 #define PCI_DEVICE_ID_BROADCOM_TRUMANAGE 0x160a 1791 1936 #define PCI_DEVICE_ID_AMCC_ADDIDATA_APCI7800 0x818e 1792 - #define PCI_DEVICE_ID_INTEL_QRK_UART 0x0936 1793 1937 1794 1938 #define PCI_VENDOR_ID_SUNIX 0x1fd4 1795 1939 #define PCI_DEVICE_ID_SUNIX_1999 0x1999 ··· 1931 2077 .subvendor = PCI_ANY_ID, 1932 2078 .subdevice = PCI_ANY_ID, 1933 2079 .setup = kt_serial_setup, 1934 - }, 1935 - { 1936 - .vendor = PCI_VENDOR_ID_INTEL, 1937 - .device = PCI_DEVICE_ID_INTEL_BYT_UART1, 1938 - .subvendor = PCI_ANY_ID, 1939 - .subdevice = PCI_ANY_ID, 1940 - .setup = byt_serial_setup, 1941 - }, 1942 - { 1943 - .vendor = PCI_VENDOR_ID_INTEL, 1944 - .device = PCI_DEVICE_ID_INTEL_BYT_UART2, 1945 - .subvendor = PCI_ANY_ID, 1946 - .subdevice = PCI_ANY_ID, 1947 - .setup = byt_serial_setup, 1948 - }, 1949 - { 1950 - .vendor = PCI_VENDOR_ID_INTEL, 1951 - .device = PCI_DEVICE_ID_INTEL_BSW_UART1, 1952 - .subvendor = PCI_ANY_ID, 1953 - .subdevice = PCI_ANY_ID, 1954 - .setup = byt_serial_setup, 1955 - }, 1956 - { 1957 - .vendor = PCI_VENDOR_ID_INTEL, 1958 - .device = PCI_DEVICE_ID_INTEL_BSW_UART2, 1959 - .subvendor = PCI_ANY_ID, 1960 - .subdevice = PCI_ANY_ID, 1961 - .setup = byt_serial_setup, 1962 - }, 1963 - { 1964 - .vendor = PCI_VENDOR_ID_INTEL, 1965 - .device = PCI_DEVICE_ID_INTEL_BDW_UART1, 1966 - .subvendor = PCI_ANY_ID, 1967 - .subdevice = PCI_ANY_ID, 1968 - .setup = byt_serial_setup, 1969 - }, 1970 - { 1971 - .vendor = PCI_VENDOR_ID_INTEL, 1972 - .device = PCI_DEVICE_ID_INTEL_BDW_UART2, 1973 - .subvendor = PCI_ANY_ID, 1974 - .subdevice = PCI_ANY_ID, 1975 - .setup = byt_serial_setup, 1976 2080 }, 1977 2081 /* 1978 2082 * ITE ··· 2804 2992 pbn_ADDIDATA_PCIe_4_3906250, 2805 2993 pbn_ADDIDATA_PCIe_8_3906250, 2806 2994 pbn_ce4100_1_115200, 2807 - pbn_byt, 2808 - pbn_qrk, 2809 2995 pbn_omegapci, 2810 2996 pbn_NETMOS9900_2s_115200, 2811 2997 pbn_brcm_trumanage, ··· 3579 3769 .base_baud = 921600, 3580 3770 .reg_shift = 2, 3581 3771 }, 3582 - [pbn_byt] = { 3583 - .flags = FL_BASE0, 3584 - .num_ports = 1, 3585 - .base_baud = 2764800, 3586 - .reg_shift = 2, 3587 - }, 3588 - [pbn_qrk] = { 3589 - .flags = FL_BASE0, 3590 - .num_ports = 1, 3591 - .base_baud = 2764800, 3592 - .reg_shift = 2, 3593 - }, 3594 3772 [pbn_omegapci] = { 3595 3773 .flags = FL_BASE0, 3596 3774 .num_ports = 8, ··· 3690 3892 { PCI_VDEVICE(INTEL, 0x081d), }, 3691 3893 { PCI_VDEVICE(INTEL, 0x1191), }, 3692 3894 { PCI_VDEVICE(INTEL, 0x19d8), }, 3895 + 3896 + /* Intel platforms with DesignWare UART */ 3897 + { PCI_VDEVICE(INTEL, 0x0936), }, 3898 + { PCI_VDEVICE(INTEL, 0x0f0a), }, 3899 + { PCI_VDEVICE(INTEL, 0x0f0c), }, 3900 + { PCI_VDEVICE(INTEL, 0x228a), }, 3901 + { PCI_VDEVICE(INTEL, 0x228c), }, 3902 + { PCI_VDEVICE(INTEL, 0x9ce3), }, 3903 + { PCI_VDEVICE(INTEL, 0x9ce4), }, 3693 3904 }; 3694 3905 3695 3906 /* ··· 5466 5659 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CE4100_UART, 5467 5660 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5468 5661 pbn_ce4100_1_115200 }, 5469 - /* Intel BayTrail */ 5470 - { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT_UART1, 5471 - PCI_ANY_ID, PCI_ANY_ID, 5472 - PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000, 5473 - pbn_byt }, 5474 - { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT_UART2, 5475 - PCI_ANY_ID, PCI_ANY_ID, 5476 - PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000, 5477 - pbn_byt }, 5478 - { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW_UART1, 5479 - PCI_ANY_ID, PCI_ANY_ID, 5480 - PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000, 5481 - pbn_byt }, 5482 - { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW_UART2, 5483 - PCI_ANY_ID, PCI_ANY_ID, 5484 - PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000, 5485 - pbn_byt }, 5486 5662 5487 - /* Intel Broadwell */ 5488 - { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BDW_UART1, 5489 - PCI_ANY_ID, PCI_ANY_ID, 5490 - PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000, 5491 - pbn_byt }, 5492 - { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BDW_UART2, 5493 - PCI_ANY_ID, PCI_ANY_ID, 5494 - PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000, 5495 - pbn_byt }, 5496 - 5497 - /* 5498 - * Intel Quark x1000 5499 - */ 5500 - { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_UART, 5501 - PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5502 - pbn_qrk }, 5503 5663 /* 5504 5664 * Cronyx Omega PCI 5505 5665 */
+57 -24
drivers/tty/serial/8250/8250_port.c
··· 178 178 .fifo_size = 16, 179 179 .tx_loadsz = 16, 180 180 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00, 181 - .flags = UART_CAP_FIFO | UART_CAP_AFE, 181 + .flags = UART_CAP_FIFO /* | UART_CAP_AFE */, 182 182 }, 183 183 [PORT_U6_16550A] = { 184 184 .name = "U6_16550A", ··· 585 585 */ 586 586 int serial8250_em485_init(struct uart_8250_port *p) 587 587 { 588 - if (p->em485 != NULL) 588 + if (p->em485) 589 589 return 0; 590 590 591 591 p->em485 = kmalloc(sizeof(struct uart_8250_em485), GFP_ATOMIC); 592 - if (p->em485 == NULL) 592 + if (!p->em485) 593 593 return -ENOMEM; 594 594 595 595 setup_timer(&p->em485->stop_tx_timer, ··· 619 619 */ 620 620 void serial8250_em485_destroy(struct uart_8250_port *p) 621 621 { 622 - if (p->em485 == NULL) 622 + if (!p->em485) 623 623 return; 624 624 625 625 del_timer(&p->em485->start_tx_timer); ··· 1402 1402 1403 1403 static void __do_stop_tx_rs485(struct uart_8250_port *p) 1404 1404 { 1405 - if (!p->em485) 1406 - return; 1407 - 1408 1405 serial8250_em485_rts_after_send(p); 1406 + 1409 1407 /* 1410 1408 * Empty the RX FIFO, we are not interested in anything 1411 1409 * received during the half-duplex transmission. ··· 1412 1414 if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX)) { 1413 1415 serial8250_clear_fifos(p); 1414 1416 1415 - serial8250_rpm_get(p); 1416 - 1417 1417 p->ier |= UART_IER_RLSI | UART_IER_RDI; 1418 1418 serial_port_out(&p->port, UART_IER, p->ier); 1419 - 1420 - serial8250_rpm_put(p); 1421 1419 } 1422 1420 } 1423 1421 ··· 1423 1429 struct uart_8250_em485 *em485 = p->em485; 1424 1430 unsigned long flags; 1425 1431 1432 + serial8250_rpm_get(p); 1426 1433 spin_lock_irqsave(&p->port.lock, flags); 1427 1434 if (em485 && 1428 1435 em485->active_timer == &em485->stop_tx_timer) { ··· 1431 1436 em485->active_timer = NULL; 1432 1437 } 1433 1438 spin_unlock_irqrestore(&p->port.lock, flags); 1439 + serial8250_rpm_put(p); 1434 1440 } 1435 1441 1436 1442 static void __stop_tx_rs485(struct uart_8250_port *p) 1437 1443 { 1438 1444 struct uart_8250_em485 *em485 = p->em485; 1439 - 1440 - if (!em485) 1441 - return; 1442 1445 1443 1446 /* 1444 1447 * __do_stop_tx_rs485 is going to set RTS according to config ··· 1468 1475 unsigned char lsr = serial_in(p, UART_LSR); 1469 1476 /* 1470 1477 * To provide required timeing and allow FIFO transfer, 1471 - * __stop_tx_rs485 must be called only when both FIFO and 1478 + * __stop_tx_rs485() must be called only when both FIFO and 1472 1479 * shift register are empty. It is for device driver to enable 1473 1480 * interrupt on TEMT. 1474 1481 */ ··· 1477 1484 1478 1485 del_timer(&em485->start_tx_timer); 1479 1486 em485->active_timer = NULL; 1487 + 1488 + __stop_tx_rs485(p); 1480 1489 } 1481 1490 __do_stop_tx(p); 1482 - __stop_tx_rs485(p); 1483 1491 } 1484 1492 1485 1493 static void serial8250_stop_tx(struct uart_port *port) ··· 1870 1876 return ret; 1871 1877 } 1872 1878 1879 + /* 1880 + * Newer 16550 compatible parts such as the SC16C650 & Altera 16550 Soft IP 1881 + * have a programmable TX threshold that triggers the THRE interrupt in 1882 + * the IIR register. In this case, the THRE interrupt indicates the FIFO 1883 + * has space available. Load it up with tx_loadsz bytes. 1884 + */ 1885 + static int serial8250_tx_threshold_handle_irq(struct uart_port *port) 1886 + { 1887 + unsigned long flags; 1888 + unsigned int iir = serial_port_in(port, UART_IIR); 1889 + 1890 + /* TX Threshold IRQ triggered so load up FIFO */ 1891 + if ((iir & UART_IIR_ID) == UART_IIR_THRI) { 1892 + struct uart_8250_port *up = up_to_u8250p(port); 1893 + 1894 + spin_lock_irqsave(&port->lock, flags); 1895 + serial8250_tx_chars(up); 1896 + spin_unlock_irqrestore(&port->lock, flags); 1897 + } 1898 + 1899 + iir = serial_port_in(port, UART_IIR); 1900 + return serial8250_handle_irq(port, iir); 1901 + } 1902 + 1873 1903 static unsigned int serial8250_tx_empty(struct uart_port *port) 1874 1904 { 1875 1905 struct uart_8250_port *up = up_to_u8250p(port); ··· 2006 1988 if (--tmout == 0) 2007 1989 break; 2008 1990 udelay(1); 1991 + touch_nmi_watchdog(); 2009 1992 } 2010 1993 2011 1994 /* Wait up to 1s for flow control if necessary */ ··· 2181 2162 serial_port_out(port, UART_TRG, UART_TRG_96); 2182 2163 2183 2164 serial_port_out(port, UART_LCR, 0); 2165 + } 2166 + 2167 + /* 2168 + * For the Altera 16550 variants, set TX threshold trigger level. 2169 + */ 2170 + if (((port->type == PORT_ALTR_16550_F32) || 2171 + (port->type == PORT_ALTR_16550_F64) || 2172 + (port->type == PORT_ALTR_16550_F128)) && (port->fifosize > 1)) { 2173 + /* Bounds checking of TX threshold (valid 0 to fifosize-2) */ 2174 + if ((up->tx_loadsz < 2) || (up->tx_loadsz > port->fifosize)) { 2175 + pr_err("ttyS%d TX FIFO Threshold errors, skipping\n", 2176 + serial_index(port)); 2177 + } else { 2178 + serial_port_out(port, UART_ALTR_AFR, 2179 + UART_ALTR_EN_TXFIFO_LW); 2180 + serial_port_out(port, UART_ALTR_TX_LOW, 2181 + port->fifosize - up->tx_loadsz); 2182 + port->handle_irq = serial8250_tx_threshold_handle_irq; 2183 + } 2184 2184 } 2185 2185 2186 2186 if (port->irq) { ··· 2537 2499 struct ktermios *termios, 2538 2500 struct ktermios *old) 2539 2501 { 2540 - unsigned int tolerance = port->uartclk / 100; 2541 - 2542 2502 /* 2543 2503 * Ask the core to calculate the divisor for us. 2544 2504 * Allow 1% tolerance at the upper limit so uart clks marginally ··· 2545 2509 */ 2546 2510 return uart_get_baud_rate(port, termios, old, 2547 2511 port->uartclk / 16 / 0xffff, 2548 - (port->uartclk + tolerance) / 16); 2512 + port->uartclk); 2549 2513 } 2550 2514 2551 2515 void ··· 2582 2546 /* 2583 2547 * MCR-based auto flow control. When AFE is enabled, RTS will be 2584 2548 * deasserted when the receive FIFO contains more characters than 2585 - * the trigger, or the MCR RTS bit is cleared. In the case where 2586 - * the remote UART is not using CTS auto flow control, we must 2587 - * have sufficient FIFO entries for the latency of the remote 2588 - * UART to respond. IOW, at least 32 bytes of FIFO. 2549 + * the trigger, or the MCR RTS bit is cleared. 2589 2550 */ 2590 - if (up->capabilities & UART_CAP_AFE && port->fifosize >= 32) { 2551 + if (up->capabilities & UART_CAP_AFE) { 2591 2552 up->mcr &= ~UART_MCR_AFE; 2592 2553 if (termios->c_cflag & CRTSCTS) 2593 2554 up->mcr |= UART_MCR_AFE;
+15 -1
drivers/tty/serial/8250/Kconfig
··· 120 120 tristate "8250/16550 PCI device support" if EXPERT 121 121 depends on SERIAL_8250 && PCI 122 122 default SERIAL_8250 123 - select RATIONAL 124 123 help 125 124 This builds standard PCI serial support. You may be able to 126 125 disable this feature if you only need legacy serial support. ··· 400 401 help 401 402 If you have a system using an Ingenic SoC and wish to make use of 402 403 its UARTs, say Y to this option. If unsure, say N. 404 + 405 + config SERIAL_8250_LPSS 406 + tristate "Support for serial ports on Intel LPSS platforms" if EXPERT 407 + default SERIAL_8250 408 + depends on SERIAL_8250 && PCI 409 + depends on X86 || COMPILE_TEST 410 + select DW_DMAC_CORE if SERIAL_8250_DMA 411 + select DW_DMAC_PCI if (SERIAL_8250_DMA && X86_INTEL_LPSS) 412 + select RATIONAL 413 + help 414 + Selecting this option will enable handling of the extra features 415 + present on the UART found on various Intel platforms such as: 416 + - Intel Baytrail SoC 417 + - Intel Braswell SoC 418 + - Intel Quark X1000 SoC 403 419 404 420 config SERIAL_8250_MID 405 421 tristate "Support for serial ports on Intel MID platforms" if EXPERT
+1
drivers/tty/serial/8250/Makefile
··· 28 28 obj-$(CONFIG_SERIAL_8250_MT6577) += 8250_mtk.o 29 29 obj-$(CONFIG_SERIAL_8250_UNIPHIER) += 8250_uniphier.o 30 30 obj-$(CONFIG_SERIAL_8250_INGENIC) += 8250_ingenic.o 31 + obj-$(CONFIG_SERIAL_8250_LPSS) += 8250_lpss.o 31 32 obj-$(CONFIG_SERIAL_8250_MID) += 8250_mid.o 32 33 obj-$(CONFIG_SERIAL_8250_MOXA) += 8250_moxa.o 33 34 obj-$(CONFIG_SERIAL_OF_PLATFORM) += 8250_of.o
+1 -1
drivers/tty/serial/altera_jtaguart.c
··· 280 280 /* 281 281 * Define the basic serial functions we support. 282 282 */ 283 - static struct uart_ops altera_jtaguart_ops = { 283 + static const struct uart_ops altera_jtaguart_ops = { 284 284 .tx_empty = altera_jtaguart_tx_empty, 285 285 .get_mctrl = altera_jtaguart_get_mctrl, 286 286 .set_mctrl = altera_jtaguart_set_mctrl,
+1 -1
drivers/tty/serial/altera_uart.c
··· 404 404 /* 405 405 * Define the basic serial functions we support. 406 406 */ 407 - static struct uart_ops altera_uart_ops = { 407 + static const struct uart_ops altera_uart_ops = { 408 408 .tx_empty = altera_uart_tx_empty, 409 409 .get_mctrl = altera_uart_get_mctrl, 410 410 .set_mctrl = altera_uart_set_mctrl,
+45 -12
drivers/tty/serial/amba-pl011.c
··· 93 93 struct vendor_data { 94 94 const u16 *reg_offset; 95 95 unsigned int ifls; 96 + unsigned int fr_busy; 97 + unsigned int fr_dsr; 98 + unsigned int fr_cts; 99 + unsigned int fr_ri; 96 100 bool access_32b; 97 101 bool oversampling; 98 102 bool dma_threshold; ··· 115 111 static struct vendor_data vendor_arm = { 116 112 .reg_offset = pl011_std_offsets, 117 113 .ifls = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8, 114 + .fr_busy = UART01x_FR_BUSY, 115 + .fr_dsr = UART01x_FR_DSR, 116 + .fr_cts = UART01x_FR_CTS, 117 + .fr_ri = UART011_FR_RI, 118 118 .oversampling = false, 119 119 .dma_threshold = false, 120 120 .cts_event_workaround = false, ··· 129 121 130 122 static struct vendor_data vendor_sbsa = { 131 123 .reg_offset = pl011_std_offsets, 124 + .fr_busy = UART01x_FR_BUSY, 125 + .fr_dsr = UART01x_FR_DSR, 126 + .fr_cts = UART01x_FR_CTS, 127 + .fr_ri = UART011_FR_RI, 132 128 .access_32b = true, 133 129 .oversampling = false, 134 130 .dma_threshold = false, ··· 176 164 static struct vendor_data vendor_st = { 177 165 .reg_offset = pl011_st_offsets, 178 166 .ifls = UART011_IFLS_RX_HALF|UART011_IFLS_TX_HALF, 167 + .fr_busy = UART01x_FR_BUSY, 168 + .fr_dsr = UART01x_FR_DSR, 169 + .fr_cts = UART01x_FR_CTS, 170 + .fr_ri = UART011_FR_RI, 179 171 .oversampling = true, 180 172 .dma_threshold = true, 181 173 .cts_event_workaround = true, ··· 204 188 [REG_DMACR] = ZX_UART011_DMACR, 205 189 }; 206 190 207 - static struct vendor_data vendor_zte __maybe_unused = { 191 + static unsigned int get_fifosize_zte(struct amba_device *dev) 192 + { 193 + return 16; 194 + } 195 + 196 + static struct vendor_data vendor_zte = { 208 197 .reg_offset = pl011_zte_offsets, 209 198 .access_32b = true, 210 199 .ifls = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8, 211 - .get_fifosize = get_fifosize_arm, 200 + .fr_busy = ZX_UART01x_FR_BUSY, 201 + .fr_dsr = ZX_UART01x_FR_DSR, 202 + .fr_cts = ZX_UART01x_FR_CTS, 203 + .fr_ri = ZX_UART011_FR_RI, 204 + .get_fifosize = get_fifosize_zte, 212 205 }; 213 206 214 207 /* Deals with DMA transactions */ ··· 1192 1167 return; 1193 1168 1194 1169 /* Disable RX and TX DMA */ 1195 - while (pl011_read(uap, REG_FR) & UART01x_FR_BUSY) 1170 + while (pl011_read(uap, REG_FR) & uap->vendor->fr_busy) 1196 1171 cpu_relax(); 1197 1172 1198 1173 spin_lock_irq(&uap->port.lock); ··· 1441 1416 if (delta & UART01x_FR_DCD) 1442 1417 uart_handle_dcd_change(&uap->port, status & UART01x_FR_DCD); 1443 1418 1444 - if (delta & UART01x_FR_DSR) 1419 + if (delta & uap->vendor->fr_dsr) 1445 1420 uap->port.icount.dsr++; 1446 1421 1447 - if (delta & UART01x_FR_CTS) 1448 - uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS); 1422 + if (delta & uap->vendor->fr_cts) 1423 + uart_handle_cts_change(&uap->port, 1424 + status & uap->vendor->fr_cts); 1449 1425 1450 1426 wake_up_interruptible(&uap->port.state->port.delta_msr_wait); 1451 1427 } ··· 1519 1493 struct uart_amba_port *uap = 1520 1494 container_of(port, struct uart_amba_port, port); 1521 1495 unsigned int status = pl011_read(uap, REG_FR); 1522 - return status & (UART01x_FR_BUSY|UART01x_FR_TXFF) ? 0 : TIOCSER_TEMT; 1496 + return status & (uap->vendor->fr_busy | UART01x_FR_TXFF) ? 1497 + 0 : TIOCSER_TEMT; 1523 1498 } 1524 1499 1525 1500 static unsigned int pl011_get_mctrl(struct uart_port *port) ··· 1535 1508 result |= tiocmbit 1536 1509 1537 1510 TIOCMBIT(UART01x_FR_DCD, TIOCM_CAR); 1538 - TIOCMBIT(UART01x_FR_DSR, TIOCM_DSR); 1539 - TIOCMBIT(UART01x_FR_CTS, TIOCM_CTS); 1540 - TIOCMBIT(UART011_FR_RI, TIOCM_RNG); 1511 + TIOCMBIT(uap->vendor->fr_dsr, TIOCM_DSR); 1512 + TIOCMBIT(uap->vendor->fr_cts, TIOCM_CTS); 1513 + TIOCMBIT(uap->vendor->fr_ri, TIOCM_RNG); 1541 1514 #undef TIOCMBIT 1542 1515 return result; 1543 1516 } ··· 2218 2191 * Finally, wait for transmitter to become empty 2219 2192 * and restore the TCR 2220 2193 */ 2221 - while (pl011_read(uap, REG_FR) & UART01x_FR_BUSY) 2194 + while (pl011_read(uap, REG_FR) & uap->vendor->fr_busy) 2222 2195 cpu_relax(); 2223 2196 if (!uap->vendor->always_enabled) 2224 2197 pl011_write(old_cr, uap, REG_CR); ··· 2582 2555 2583 2556 ret = platform_get_irq(pdev, 0); 2584 2557 if (ret < 0) { 2585 - dev_err(&pdev->dev, "cannot obtain irq\n"); 2558 + if (ret != -EPROBE_DEFER) 2559 + dev_err(&pdev->dev, "cannot obtain irq\n"); 2586 2560 return ret; 2587 2561 } 2588 2562 uap->port.irq = ret; ··· 2649 2621 .id = 0x00380802, 2650 2622 .mask = 0x00ffffff, 2651 2623 .data = &vendor_st, 2624 + }, 2625 + { 2626 + .id = AMBA_LINUX_ID(0x00, 0x1, 0xffe), 2627 + .mask = 0x00ffffff, 2628 + .data = &vendor_zte, 2652 2629 }, 2653 2630 { 0, 0 }, 2654 2631 };
+1 -1
drivers/tty/serial/arc_uart.c
··· 464 464 } 465 465 #endif 466 466 467 - static struct uart_ops arc_serial_pops = { 467 + static const struct uart_ops arc_serial_pops = { 468 468 .tx_empty = arc_serial_tx_empty, 469 469 .set_mctrl = arc_serial_set_mctrl, 470 470 .get_mctrl = arc_serial_get_mctrl,
+43 -15
drivers/tty/serial/atmel_serial.c
··· 166 166 u32 rts_low; 167 167 bool ms_irq_enabled; 168 168 u32 rtor; /* address of receiver timeout register if it exists */ 169 + bool has_frac_baudrate; 169 170 bool has_hw_timer; 170 171 struct timer_list uart_timer; 171 172 ··· 1635 1634 1636 1635 if (np) { 1637 1636 /* DMA/PDC usage specification */ 1638 - if (of_get_property(np, "atmel,use-dma-rx", NULL)) { 1639 - if (of_get_property(np, "dmas", NULL)) { 1637 + if (of_property_read_bool(np, "atmel,use-dma-rx")) { 1638 + if (of_property_read_bool(np, "dmas")) { 1640 1639 atmel_port->use_dma_rx = true; 1641 1640 atmel_port->use_pdc_rx = false; 1642 1641 } else { ··· 1648 1647 atmel_port->use_pdc_rx = false; 1649 1648 } 1650 1649 1651 - if (of_get_property(np, "atmel,use-dma-tx", NULL)) { 1652 - if (of_get_property(np, "dmas", NULL)) { 1650 + if (of_property_read_bool(np, "atmel,use-dma-tx")) { 1651 + if (of_property_read_bool(np, "dmas")) { 1653 1652 atmel_port->use_dma_tx = true; 1654 1653 atmel_port->use_pdc_tx = false; 1655 1654 } else { ··· 1746 1745 dbgu_uart = 0x44424755; /* DBGU */ 1747 1746 new_uart = 0x55415254; /* UART */ 1748 1747 1748 + /* 1749 + * Only USART devices from at91sam9260 SOC implement fractional 1750 + * baudrate. 1751 + */ 1752 + atmel_port->has_frac_baudrate = false; 1749 1753 atmel_port->has_hw_timer = false; 1750 1754 1751 1755 if (name == new_uart) { ··· 1759 1753 atmel_port->rtor = ATMEL_UA_RTOR; 1760 1754 } else if (name == usart) { 1761 1755 dev_dbg(port->dev, "Usart\n"); 1756 + atmel_port->has_frac_baudrate = true; 1762 1757 atmel_port->has_hw_timer = true; 1763 1758 atmel_port->rtor = ATMEL_US_RTOR; 1764 1759 } else if (name == dbgu_uart) { ··· 1771 1764 case 0x302: 1772 1765 case 0x10213: 1773 1766 dev_dbg(port->dev, "This version is usart\n"); 1767 + atmel_port->has_frac_baudrate = true; 1774 1768 atmel_port->has_hw_timer = true; 1775 1769 atmel_port->rtor = ATMEL_US_RTOR; 1776 1770 break; ··· 1937 1929 { 1938 1930 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 1939 1931 1932 + /* Disable modem control lines interrupts */ 1933 + atmel_disable_ms(port); 1934 + 1940 1935 /* Disable interrupts at device level */ 1941 1936 atmel_uart_writel(port, ATMEL_US_IDR, -1); 1942 1937 ··· 1990 1979 */ 1991 1980 free_irq(port->irq, port); 1992 1981 1993 - atmel_port->ms_irq_enabled = false; 1994 - 1995 1982 atmel_flush_buffer(port); 1996 1983 } 1997 1984 ··· 2034 2025 static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, 2035 2026 struct ktermios *old) 2036 2027 { 2028 + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 2037 2029 unsigned long flags; 2038 - unsigned int old_mode, mode, imr, quot, baud; 2030 + unsigned int old_mode, mode, imr, quot, baud, div, cd, fp = 0; 2039 2031 2040 2032 /* save the current mode register */ 2041 2033 mode = old_mode = atmel_uart_readl(port, ATMEL_US_MR); ··· 2046 2036 ATMEL_US_PAR | ATMEL_US_USMODE); 2047 2037 2048 2038 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); 2049 - quot = uart_get_divisor(port, baud); 2050 - 2051 - if (quot > 65535) { /* BRGR is 16-bit, so switch to slower clock */ 2052 - quot /= 8; 2053 - mode |= ATMEL_US_USCLKS_MCK_DIV8; 2054 - } 2055 2039 2056 2040 /* byte size */ 2057 2041 switch (termios->c_cflag & CSIZE) { ··· 2164 2160 atmel_uart_writel(port, ATMEL_US_CR, rts_state); 2165 2161 } 2166 2162 2167 - /* set the baud rate */ 2163 + /* 2164 + * Set the baud rate: 2165 + * Fractional baudrate allows to setup output frequency more 2166 + * accurately. This feature is enabled only when using normal mode. 2167 + * baudrate = selected clock / (8 * (2 - OVER) * (CD + FP / 8)) 2168 + * Currently, OVER is always set to 0 so we get 2169 + * baudrate = selected clock / (16 * (CD + FP / 8)) 2170 + * then 2171 + * 8 CD + FP = selected clock / (2 * baudrate) 2172 + */ 2173 + if (atmel_port->has_frac_baudrate && 2174 + (mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_NORMAL) { 2175 + div = DIV_ROUND_CLOSEST(port->uartclk, baud * 2); 2176 + cd = div >> 3; 2177 + fp = div & ATMEL_US_FP_MASK; 2178 + } else { 2179 + cd = uart_get_divisor(port, baud); 2180 + } 2181 + 2182 + if (cd > 65535) { /* BRGR is 16-bit, so switch to slower clock */ 2183 + cd /= 8; 2184 + mode |= ATMEL_US_USCLKS_MCK_DIV8; 2185 + } 2186 + quot = cd | fp << ATMEL_US_FP_OFFSET; 2187 + 2168 2188 atmel_uart_writel(port, ATMEL_US_BRGR, quot); 2169 2189 atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_RSTSTA | ATMEL_US_RSTRX); 2170 2190 atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN | ATMEL_US_RXEN); ··· 2320 2292 } 2321 2293 #endif 2322 2294 2323 - static struct uart_ops atmel_pops = { 2295 + static const struct uart_ops atmel_pops = { 2324 2296 .tx_empty = atmel_tx_empty, 2325 2297 .set_mctrl = atmel_set_mctrl, 2326 2298 .get_mctrl = atmel_get_mctrl,
+1 -1
drivers/tty/serial/bcm63xx_uart.c
··· 631 631 } 632 632 633 633 /* serial core callbacks */ 634 - static struct uart_ops bcm_uart_ops = { 634 + static const struct uart_ops bcm_uart_ops = { 635 635 .tx_empty = bcm_uart_tx_empty, 636 636 .get_mctrl = bcm_uart_get_mctrl, 637 637 .set_mctrl = bcm_uart_set_mctrl,
+2 -1
drivers/tty/serial/earlycon-arm-semihost.c
··· 53 53 uart_console_write(&dev->port, s, n, smh_putc); 54 54 } 55 55 56 - int __init early_smh_setup(struct earlycon_device *device, const char *opt) 56 + static int 57 + __init early_smh_setup(struct earlycon_device *device, const char *opt) 57 58 { 58 59 device->con->write = smh_write; 59 60 return 0;
+20 -6
drivers/tty/serial/earlycon.c
··· 21 21 #include <linux/sizes.h> 22 22 #include <linux/of.h> 23 23 #include <linux/of_fdt.h> 24 + #include <linux/acpi.h> 24 25 25 26 #ifdef CONFIG_FIX_EARLYCON_MEM 26 27 #include <asm/fixmap.h> ··· 39 38 .con = &early_con, 40 39 }; 41 40 42 - static void __iomem * __init earlycon_map(unsigned long paddr, size_t size) 41 + static void __iomem * __init earlycon_map(resource_size_t paddr, size_t size) 43 42 { 44 43 void __iomem *base; 45 44 #ifdef CONFIG_FIX_EARLYCON_MEM ··· 50 49 base = ioremap(paddr, size); 51 50 #endif 52 51 if (!base) 53 - pr_err("%s: Couldn't map 0x%llx\n", __func__, 54 - (unsigned long long)paddr); 52 + pr_err("%s: Couldn't map %pa\n", __func__, &paddr); 55 53 56 54 return base; 57 55 } ··· 92 92 { 93 93 struct uart_port *port = &device->port; 94 94 int length; 95 - unsigned long addr; 95 + resource_size_t addr; 96 96 97 97 if (uart_parse_earlycon(options, &port->iotype, &addr, &options)) 98 98 return -EINVAL; ··· 199 199 return -ENOENT; 200 200 } 201 201 202 + /* 203 + * When CONFIG_ACPI_SPCR_TABLE is defined, "earlycon" without parameters in 204 + * command line does not start DT earlycon immediately, instead it defers 205 + * starting it until DT/ACPI decision is made. At that time if ACPI is enabled 206 + * call parse_spcr(), else call early_init_dt_scan_chosen_stdout() 207 + */ 208 + bool earlycon_init_is_deferred __initdata; 209 + 202 210 /* early_param wrapper for setup_earlycon() */ 203 211 static int __init param_setup_earlycon(char *buf) 204 212 { ··· 216 208 * Just 'earlycon' is a valid param for devicetree earlycons; 217 209 * don't generate a warning from parse_early_params() in that case 218 210 */ 219 - if (!buf || !buf[0]) 220 - return 0; 211 + if (!buf || !buf[0]) { 212 + if (IS_ENABLED(CONFIG_ACPI_SPCR_TABLE)) { 213 + earlycon_init_is_deferred = true; 214 + return 0; 215 + } else { 216 + return early_init_dt_scan_chosen_stdout(); 217 + } 218 + } 221 219 222 220 err = setup_earlycon(buf); 223 221 if (err == -ENOENT || err == -EALREADY)
+481 -339
drivers/tty/serial/fsl_lpuart.c
··· 224 224 #define UARTWATER_TXWATER_OFF 0 225 225 #define UARTWATER_RXWATER_OFF 16 226 226 227 - #define FSL_UART_RX_DMA_BUFFER_SIZE 64 227 + /* Rx DMA timeout in ms, which is used to calculate Rx ring buffer size */ 228 + #define DMA_RX_TIMEOUT (10) 228 229 229 230 #define DRIVER_NAME "fsl-lpuart" 230 231 #define DEV_NAME "ttyLP" ··· 244 243 struct dma_chan *dma_rx_chan; 245 244 struct dma_async_tx_descriptor *dma_tx_desc; 246 245 struct dma_async_tx_descriptor *dma_rx_desc; 247 - dma_addr_t dma_tx_buf_bus; 248 - dma_addr_t dma_rx_buf_bus; 249 246 dma_cookie_t dma_tx_cookie; 250 247 dma_cookie_t dma_rx_cookie; 251 - unsigned char *dma_tx_buf_virt; 252 - unsigned char *dma_rx_buf_virt; 253 248 unsigned int dma_tx_bytes; 254 249 unsigned int dma_rx_bytes; 255 - int dma_tx_in_progress; 256 - int dma_rx_in_progress; 250 + bool dma_tx_in_progress; 257 251 unsigned int dma_rx_timeout; 258 252 struct timer_list lpuart_timer; 253 + struct scatterlist rx_sgl, tx_sgl[2]; 254 + struct circ_buf rx_ring; 255 + int rx_dma_rng_buf_len; 256 + unsigned int dma_tx_nents; 257 + wait_queue_head_t dma_wait; 259 258 }; 260 259 261 260 static const struct of_device_id lpuart_dt_ids[] = { ··· 271 270 272 271 /* Forward declare this for the dma callbacks*/ 273 272 static void lpuart_dma_tx_complete(void *arg); 274 - static void lpuart_dma_rx_complete(void *arg); 275 273 276 274 static u32 lpuart32_read(void __iomem *addr) 277 275 { ··· 316 316 lpuart32_write(temp & ~UARTCTRL_RE, port->membase + UARTCTRL); 317 317 } 318 318 319 - static void lpuart_copy_rx_to_tty(struct lpuart_port *sport, 320 - struct tty_port *tty, int count) 319 + static void lpuart_dma_tx(struct lpuart_port *sport) 321 320 { 322 - int copied; 321 + struct circ_buf *xmit = &sport->port.state->xmit; 322 + struct scatterlist *sgl = sport->tx_sgl; 323 + struct device *dev = sport->port.dev; 324 + int ret; 323 325 324 - sport->port.icount.rx += count; 326 + if (sport->dma_tx_in_progress) 327 + return; 325 328 326 - if (!tty) { 327 - dev_err(sport->port.dev, "No tty port\n"); 329 + sport->dma_tx_bytes = uart_circ_chars_pending(xmit); 330 + 331 + if (xmit->tail < xmit->head) { 332 + sport->dma_tx_nents = 1; 333 + sg_init_one(sgl, xmit->buf + xmit->tail, sport->dma_tx_bytes); 334 + } else { 335 + sport->dma_tx_nents = 2; 336 + sg_init_table(sgl, 2); 337 + sg_set_buf(sgl, xmit->buf + xmit->tail, 338 + UART_XMIT_SIZE - xmit->tail); 339 + sg_set_buf(sgl + 1, xmit->buf, xmit->head); 340 + } 341 + 342 + ret = dma_map_sg(dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE); 343 + if (!ret) { 344 + dev_err(dev, "DMA mapping error for TX.\n"); 328 345 return; 329 346 } 330 347 331 - dma_sync_single_for_cpu(sport->port.dev, sport->dma_rx_buf_bus, 332 - FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE); 333 - copied = tty_insert_flip_string(tty, 334 - ((unsigned char *)(sport->dma_rx_buf_virt)), count); 335 - 336 - if (copied != count) { 337 - WARN_ON(1); 338 - dev_err(sport->port.dev, "RxData copy to tty layer failed\n"); 339 - } 340 - 341 - dma_sync_single_for_device(sport->port.dev, sport->dma_rx_buf_bus, 342 - FSL_UART_RX_DMA_BUFFER_SIZE, DMA_TO_DEVICE); 343 - } 344 - 345 - static void lpuart_pio_tx(struct lpuart_port *sport) 346 - { 347 - struct circ_buf *xmit = &sport->port.state->xmit; 348 - unsigned long flags; 349 - 350 - spin_lock_irqsave(&sport->port.lock, flags); 351 - 352 - while (!uart_circ_empty(xmit) && 353 - readb(sport->port.membase + UARTTCFIFO) < sport->txfifo_size) { 354 - writeb(xmit->buf[xmit->tail], sport->port.membase + UARTDR); 355 - xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 356 - sport->port.icount.tx++; 357 - } 358 - 359 - if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 360 - uart_write_wakeup(&sport->port); 361 - 362 - if (uart_circ_empty(xmit)) 363 - writeb(readb(sport->port.membase + UARTCR5) | UARTCR5_TDMAS, 364 - sport->port.membase + UARTCR5); 365 - 366 - spin_unlock_irqrestore(&sport->port.lock, flags); 367 - } 368 - 369 - static int lpuart_dma_tx(struct lpuart_port *sport, unsigned long count) 370 - { 371 - struct circ_buf *xmit = &sport->port.state->xmit; 372 - dma_addr_t tx_bus_addr; 373 - 374 - dma_sync_single_for_device(sport->port.dev, sport->dma_tx_buf_bus, 375 - UART_XMIT_SIZE, DMA_TO_DEVICE); 376 - sport->dma_tx_bytes = count & ~(sport->txfifo_size - 1); 377 - tx_bus_addr = sport->dma_tx_buf_bus + xmit->tail; 378 - sport->dma_tx_desc = dmaengine_prep_slave_single(sport->dma_tx_chan, 379 - tx_bus_addr, sport->dma_tx_bytes, 348 + sport->dma_tx_desc = dmaengine_prep_slave_sg(sport->dma_tx_chan, sgl, 349 + sport->dma_tx_nents, 380 350 DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT); 381 - 382 351 if (!sport->dma_tx_desc) { 383 - dev_err(sport->port.dev, "Not able to get desc for tx\n"); 384 - return -EIO; 352 + dma_unmap_sg(dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE); 353 + dev_err(dev, "Cannot prepare TX slave DMA!\n"); 354 + return; 385 355 } 386 356 387 357 sport->dma_tx_desc->callback = lpuart_dma_tx_complete; 388 358 sport->dma_tx_desc->callback_param = sport; 389 - sport->dma_tx_in_progress = 1; 359 + sport->dma_tx_in_progress = true; 390 360 sport->dma_tx_cookie = dmaengine_submit(sport->dma_tx_desc); 391 361 dma_async_issue_pending(sport->dma_tx_chan); 392 362 393 - return 0; 394 - } 395 - 396 - static void lpuart_prepare_tx(struct lpuart_port *sport) 397 - { 398 - struct circ_buf *xmit = &sport->port.state->xmit; 399 - unsigned long count = CIRC_CNT_TO_END(xmit->head, 400 - xmit->tail, UART_XMIT_SIZE); 401 - 402 - if (!count) 403 - return; 404 - 405 - if (count < sport->txfifo_size) 406 - writeb(readb(sport->port.membase + UARTCR5) & ~UARTCR5_TDMAS, 407 - sport->port.membase + UARTCR5); 408 - else { 409 - writeb(readb(sport->port.membase + UARTCR5) | UARTCR5_TDMAS, 410 - sport->port.membase + UARTCR5); 411 - lpuart_dma_tx(sport, count); 412 - } 413 363 } 414 364 415 365 static void lpuart_dma_tx_complete(void *arg) 416 366 { 417 367 struct lpuart_port *sport = arg; 368 + struct scatterlist *sgl = &sport->tx_sgl[0]; 418 369 struct circ_buf *xmit = &sport->port.state->xmit; 419 370 unsigned long flags; 420 371 421 - async_tx_ack(sport->dma_tx_desc); 422 - 423 372 spin_lock_irqsave(&sport->port.lock, flags); 424 373 374 + dma_unmap_sg(sport->port.dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE); 375 + 425 376 xmit->tail = (xmit->tail + sport->dma_tx_bytes) & (UART_XMIT_SIZE - 1); 426 - sport->dma_tx_in_progress = 0; 377 + 378 + sport->port.icount.tx += sport->dma_tx_bytes; 379 + sport->dma_tx_in_progress = false; 380 + spin_unlock_irqrestore(&sport->port.lock, flags); 427 381 428 382 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 429 383 uart_write_wakeup(&sport->port); 430 384 431 - lpuart_prepare_tx(sport); 385 + if (waitqueue_active(&sport->dma_wait)) { 386 + wake_up(&sport->dma_wait); 387 + return; 388 + } 389 + 390 + spin_lock_irqsave(&sport->port.lock, flags); 391 + 392 + if (!uart_circ_empty(xmit) && !uart_tx_stopped(&sport->port)) 393 + lpuart_dma_tx(sport); 432 394 433 395 spin_unlock_irqrestore(&sport->port.lock, flags); 434 396 } 435 397 436 - static int lpuart_dma_rx(struct lpuart_port *sport) 398 + static int lpuart_dma_tx_request(struct uart_port *port) 437 399 { 438 - dma_sync_single_for_device(sport->port.dev, sport->dma_rx_buf_bus, 439 - FSL_UART_RX_DMA_BUFFER_SIZE, DMA_TO_DEVICE); 440 - sport->dma_rx_desc = dmaengine_prep_slave_single(sport->dma_rx_chan, 441 - sport->dma_rx_buf_bus, FSL_UART_RX_DMA_BUFFER_SIZE, 442 - DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT); 400 + struct lpuart_port *sport = container_of(port, 401 + struct lpuart_port, port); 402 + struct dma_slave_config dma_tx_sconfig = {}; 403 + int ret; 443 404 444 - if (!sport->dma_rx_desc) { 445 - dev_err(sport->port.dev, "Not able to get desc for rx\n"); 446 - return -EIO; 405 + dma_tx_sconfig.dst_addr = sport->port.mapbase + UARTDR; 406 + dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 407 + dma_tx_sconfig.dst_maxburst = 1; 408 + dma_tx_sconfig.direction = DMA_MEM_TO_DEV; 409 + ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig); 410 + 411 + if (ret) { 412 + dev_err(sport->port.dev, 413 + "DMA slave config failed, err = %d\n", ret); 414 + return ret; 447 415 } 448 - 449 - sport->dma_rx_desc->callback = lpuart_dma_rx_complete; 450 - sport->dma_rx_desc->callback_param = sport; 451 - sport->dma_rx_in_progress = 1; 452 - sport->dma_rx_cookie = dmaengine_submit(sport->dma_rx_desc); 453 - dma_async_issue_pending(sport->dma_rx_chan); 454 416 455 417 return 0; 456 418 } ··· 420 458 static void lpuart_flush_buffer(struct uart_port *port) 421 459 { 422 460 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 461 + 423 462 if (sport->lpuart_dma_tx_use) { 463 + if (sport->dma_tx_in_progress) { 464 + dma_unmap_sg(sport->port.dev, &sport->tx_sgl[0], 465 + sport->dma_tx_nents, DMA_TO_DEVICE); 466 + sport->dma_tx_in_progress = false; 467 + } 424 468 dmaengine_terminate_all(sport->dma_tx_chan); 425 - sport->dma_tx_in_progress = 0; 426 469 } 427 - } 428 - 429 - static void lpuart_dma_rx_complete(void *arg) 430 - { 431 - struct lpuart_port *sport = arg; 432 - struct tty_port *port = &sport->port.state->port; 433 - unsigned long flags; 434 - 435 - async_tx_ack(sport->dma_rx_desc); 436 - mod_timer(&sport->lpuart_timer, jiffies + sport->dma_rx_timeout); 437 - 438 - spin_lock_irqsave(&sport->port.lock, flags); 439 - 440 - sport->dma_rx_in_progress = 0; 441 - lpuart_copy_rx_to_tty(sport, port, FSL_UART_RX_DMA_BUFFER_SIZE); 442 - tty_flip_buffer_push(port); 443 - lpuart_dma_rx(sport); 444 - 445 - spin_unlock_irqrestore(&sport->port.lock, flags); 446 - } 447 - 448 - static void lpuart_timer_func(unsigned long data) 449 - { 450 - struct lpuart_port *sport = (struct lpuart_port *)data; 451 - struct tty_port *port = &sport->port.state->port; 452 - struct dma_tx_state state; 453 - unsigned long flags; 454 - unsigned char temp; 455 - int count; 456 - 457 - del_timer(&sport->lpuart_timer); 458 - dmaengine_pause(sport->dma_rx_chan); 459 - dmaengine_tx_status(sport->dma_rx_chan, sport->dma_rx_cookie, &state); 460 - dmaengine_terminate_all(sport->dma_rx_chan); 461 - count = FSL_UART_RX_DMA_BUFFER_SIZE - state.residue; 462 - async_tx_ack(sport->dma_rx_desc); 463 - 464 - spin_lock_irqsave(&sport->port.lock, flags); 465 - 466 - sport->dma_rx_in_progress = 0; 467 - lpuart_copy_rx_to_tty(sport, port, count); 468 - tty_flip_buffer_push(port); 469 - temp = readb(sport->port.membase + UARTCR5); 470 - writeb(temp & ~UARTCR5_RDMAS, sport->port.membase + UARTCR5); 471 - 472 - spin_unlock_irqrestore(&sport->port.lock, flags); 473 - } 474 - 475 - static inline void lpuart_prepare_rx(struct lpuart_port *sport) 476 - { 477 - unsigned long flags; 478 - unsigned char temp; 479 - 480 - spin_lock_irqsave(&sport->port.lock, flags); 481 - 482 - sport->lpuart_timer.expires = jiffies + sport->dma_rx_timeout; 483 - add_timer(&sport->lpuart_timer); 484 - 485 - lpuart_dma_rx(sport); 486 - temp = readb(sport->port.membase + UARTCR5); 487 - writeb(temp | UARTCR5_RDMAS, sport->port.membase + UARTCR5); 488 - 489 - spin_unlock_irqrestore(&sport->port.lock, flags); 490 470 } 491 471 492 472 static inline void lpuart_transmit_buffer(struct lpuart_port *sport) ··· 484 580 writeb(temp | UARTCR2_TIE, port->membase + UARTCR2); 485 581 486 582 if (sport->lpuart_dma_tx_use) { 487 - if (!uart_circ_empty(xmit) && !sport->dma_tx_in_progress) 488 - lpuart_prepare_tx(sport); 583 + if (!uart_circ_empty(xmit) && !uart_tx_stopped(port)) 584 + lpuart_dma_tx(sport); 489 585 } else { 490 586 if (readb(port->membase + UARTSR1) & UARTSR1_TDRE) 491 587 lpuart_transmit_buffer(sport); ··· 502 598 503 599 if (lpuart32_read(port->membase + UARTSTAT) & UARTSTAT_TDRE) 504 600 lpuart32_transmit_buffer(sport); 601 + } 602 + 603 + /* return TIOCSER_TEMT when transmitter is not busy */ 604 + static unsigned int lpuart_tx_empty(struct uart_port *port) 605 + { 606 + struct lpuart_port *sport = container_of(port, 607 + struct lpuart_port, port); 608 + unsigned char sr1 = readb(port->membase + UARTSR1); 609 + unsigned char sfifo = readb(port->membase + UARTSFIFO); 610 + 611 + if (sport->dma_tx_in_progress) 612 + return 0; 613 + 614 + if (sr1 & UARTSR1_TC && sfifo & UARTSFIFO_TXEMPT) 615 + return TIOCSER_TEMT; 616 + 617 + return 0; 618 + } 619 + 620 + static unsigned int lpuart32_tx_empty(struct uart_port *port) 621 + { 622 + return (lpuart32_read(port->membase + UARTSTAT) & UARTSTAT_TC) ? 623 + TIOCSER_TEMT : 0; 505 624 } 506 625 507 626 static irqreturn_t lpuart_txint(int irq, void *dev_id) ··· 693 766 static irqreturn_t lpuart_int(int irq, void *dev_id) 694 767 { 695 768 struct lpuart_port *sport = dev_id; 696 - unsigned char sts, crdma; 769 + unsigned char sts; 697 770 698 771 sts = readb(sport->port.membase + UARTSR1); 699 - crdma = readb(sport->port.membase + UARTCR5); 700 772 701 - if (sts & UARTSR1_RDRF && !(crdma & UARTCR5_RDMAS)) { 702 - if (sport->lpuart_dma_rx_use) 703 - lpuart_prepare_rx(sport); 704 - else 705 - lpuart_rxint(irq, dev_id); 706 - } 707 - if (sts & UARTSR1_TDRE && !(crdma & UARTCR5_TDMAS)) { 708 - if (sport->lpuart_dma_tx_use) 709 - lpuart_pio_tx(sport); 710 - else 711 - lpuart_txint(irq, dev_id); 712 - } 773 + if (sts & UARTSR1_RDRF) 774 + lpuart_rxint(irq, dev_id); 775 + 776 + if (sts & UARTSR1_TDRE) 777 + lpuart_txint(irq, dev_id); 713 778 714 779 return IRQ_HANDLED; 715 780 } ··· 726 807 return IRQ_HANDLED; 727 808 } 728 809 729 - /* return TIOCSER_TEMT when transmitter is not busy */ 730 - static unsigned int lpuart_tx_empty(struct uart_port *port) 810 + static void lpuart_copy_rx_to_tty(struct lpuart_port *sport) 731 811 { 732 - return (readb(port->membase + UARTSR1) & UARTSR1_TC) ? 733 - TIOCSER_TEMT : 0; 812 + struct tty_port *port = &sport->port.state->port; 813 + struct dma_tx_state state; 814 + enum dma_status dmastat; 815 + struct circ_buf *ring = &sport->rx_ring; 816 + unsigned long flags; 817 + int count = 0; 818 + unsigned char sr; 819 + 820 + sr = readb(sport->port.membase + UARTSR1); 821 + 822 + if (sr & (UARTSR1_PE | UARTSR1_FE)) { 823 + /* Read DR to clear the error flags */ 824 + readb(sport->port.membase + UARTDR); 825 + 826 + if (sr & UARTSR1_PE) 827 + sport->port.icount.parity++; 828 + else if (sr & UARTSR1_FE) 829 + sport->port.icount.frame++; 830 + } 831 + 832 + async_tx_ack(sport->dma_rx_desc); 833 + 834 + spin_lock_irqsave(&sport->port.lock, flags); 835 + 836 + dmastat = dmaengine_tx_status(sport->dma_rx_chan, 837 + sport->dma_rx_cookie, 838 + &state); 839 + 840 + if (dmastat == DMA_ERROR) { 841 + dev_err(sport->port.dev, "Rx DMA transfer failed!\n"); 842 + spin_unlock_irqrestore(&sport->port.lock, flags); 843 + return; 844 + } 845 + 846 + /* CPU claims ownership of RX DMA buffer */ 847 + dma_sync_sg_for_cpu(sport->port.dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE); 848 + 849 + /* 850 + * ring->head points to the end of data already written by the DMA. 851 + * ring->tail points to the beginning of data to be read by the 852 + * framework. 853 + * The current transfer size should not be larger than the dma buffer 854 + * length. 855 + */ 856 + ring->head = sport->rx_sgl.length - state.residue; 857 + BUG_ON(ring->head > sport->rx_sgl.length); 858 + /* 859 + * At this point ring->head may point to the first byte right after the 860 + * last byte of the dma buffer: 861 + * 0 <= ring->head <= sport->rx_sgl.length 862 + * 863 + * However ring->tail must always points inside the dma buffer: 864 + * 0 <= ring->tail <= sport->rx_sgl.length - 1 865 + * 866 + * Since we use a ring buffer, we have to handle the case 867 + * where head is lower than tail. In such a case, we first read from 868 + * tail to the end of the buffer then reset tail. 869 + */ 870 + if (ring->head < ring->tail) { 871 + count = sport->rx_sgl.length - ring->tail; 872 + 873 + tty_insert_flip_string(port, ring->buf + ring->tail, count); 874 + ring->tail = 0; 875 + sport->port.icount.rx += count; 876 + } 877 + 878 + /* Finally we read data from tail to head */ 879 + if (ring->tail < ring->head) { 880 + count = ring->head - ring->tail; 881 + tty_insert_flip_string(port, ring->buf + ring->tail, count); 882 + /* Wrap ring->head if needed */ 883 + if (ring->head >= sport->rx_sgl.length) 884 + ring->head = 0; 885 + ring->tail = ring->head; 886 + sport->port.icount.rx += count; 887 + } 888 + 889 + dma_sync_sg_for_device(sport->port.dev, &sport->rx_sgl, 1, 890 + DMA_FROM_DEVICE); 891 + 892 + spin_unlock_irqrestore(&sport->port.lock, flags); 893 + 894 + tty_flip_buffer_push(port); 895 + mod_timer(&sport->lpuart_timer, jiffies + sport->dma_rx_timeout); 734 896 } 735 897 736 - static unsigned int lpuart32_tx_empty(struct uart_port *port) 898 + static void lpuart_dma_rx_complete(void *arg) 737 899 { 738 - return (lpuart32_read(port->membase + UARTSTAT) & UARTSTAT_TC) ? 739 - TIOCSER_TEMT : 0; 900 + struct lpuart_port *sport = arg; 901 + 902 + lpuart_copy_rx_to_tty(sport); 903 + } 904 + 905 + static void lpuart_timer_func(unsigned long data) 906 + { 907 + struct lpuart_port *sport = (struct lpuart_port *)data; 908 + 909 + lpuart_copy_rx_to_tty(sport); 910 + } 911 + 912 + static inline int lpuart_start_rx_dma(struct lpuart_port *sport) 913 + { 914 + struct dma_slave_config dma_rx_sconfig = {}; 915 + struct circ_buf *ring = &sport->rx_ring; 916 + int ret, nent; 917 + int bits, baud; 918 + struct tty_struct *tty = tty_port_tty_get(&sport->port.state->port); 919 + struct ktermios *termios = &tty->termios; 920 + 921 + baud = tty_get_baud_rate(tty); 922 + 923 + bits = (termios->c_cflag & CSIZE) == CS7 ? 9 : 10; 924 + if (termios->c_cflag & PARENB) 925 + bits++; 926 + 927 + /* 928 + * Calculate length of one DMA buffer size to keep latency below 929 + * 10ms at any baud rate. 930 + */ 931 + sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / bits / 1000) * 2; 932 + sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len) - 1)); 933 + if (sport->rx_dma_rng_buf_len < 16) 934 + sport->rx_dma_rng_buf_len = 16; 935 + 936 + ring->buf = kmalloc(sport->rx_dma_rng_buf_len, GFP_ATOMIC); 937 + if (!ring->buf) { 938 + dev_err(sport->port.dev, "Ring buf alloc failed\n"); 939 + return -ENOMEM; 940 + } 941 + 942 + sg_init_one(&sport->rx_sgl, ring->buf, sport->rx_dma_rng_buf_len); 943 + sg_set_buf(&sport->rx_sgl, ring->buf, sport->rx_dma_rng_buf_len); 944 + nent = dma_map_sg(sport->port.dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE); 945 + 946 + if (!nent) { 947 + dev_err(sport->port.dev, "DMA Rx mapping error\n"); 948 + return -EINVAL; 949 + } 950 + 951 + dma_rx_sconfig.src_addr = sport->port.mapbase + UARTDR; 952 + dma_rx_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 953 + dma_rx_sconfig.src_maxburst = 1; 954 + dma_rx_sconfig.direction = DMA_DEV_TO_MEM; 955 + ret = dmaengine_slave_config(sport->dma_rx_chan, &dma_rx_sconfig); 956 + 957 + if (ret < 0) { 958 + dev_err(sport->port.dev, 959 + "DMA Rx slave config failed, err = %d\n", ret); 960 + return ret; 961 + } 962 + 963 + sport->dma_rx_desc = dmaengine_prep_dma_cyclic(sport->dma_rx_chan, 964 + sg_dma_address(&sport->rx_sgl), 965 + sport->rx_sgl.length, 966 + sport->rx_sgl.length / 2, 967 + DMA_DEV_TO_MEM, 968 + DMA_PREP_INTERRUPT); 969 + if (!sport->dma_rx_desc) { 970 + dev_err(sport->port.dev, "Cannot prepare cyclic DMA\n"); 971 + return -EFAULT; 972 + } 973 + 974 + sport->dma_rx_desc->callback = lpuart_dma_rx_complete; 975 + sport->dma_rx_desc->callback_param = sport; 976 + sport->dma_rx_cookie = dmaengine_submit(sport->dma_rx_desc); 977 + dma_async_issue_pending(sport->dma_rx_chan); 978 + 979 + writeb(readb(sport->port.membase + UARTCR5) | UARTCR5_RDMAS, 980 + sport->port.membase + UARTCR5); 981 + 982 + return 0; 983 + } 984 + 985 + static void lpuart_dma_rx_free(struct uart_port *port) 986 + { 987 + struct lpuart_port *sport = container_of(port, 988 + struct lpuart_port, port); 989 + 990 + if (sport->dma_rx_chan) 991 + dmaengine_terminate_all(sport->dma_rx_chan); 992 + 993 + dma_unmap_sg(sport->port.dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE); 994 + kfree(sport->rx_ring.buf); 995 + sport->rx_ring.tail = 0; 996 + sport->rx_ring.head = 0; 997 + sport->dma_rx_desc = NULL; 998 + sport->dma_rx_cookie = -EINVAL; 999 + } 1000 + 1001 + static int lpuart_config_rs485(struct uart_port *port, 1002 + struct serial_rs485 *rs485) 1003 + { 1004 + struct lpuart_port *sport = container_of(port, 1005 + struct lpuart_port, port); 1006 + 1007 + u8 modem = readb(sport->port.membase + UARTMODEM) & 1008 + ~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE); 1009 + writeb(modem, sport->port.membase + UARTMODEM); 1010 + 1011 + if (rs485->flags & SER_RS485_ENABLED) { 1012 + /* Enable auto RS-485 RTS mode */ 1013 + modem |= UARTMODEM_TXRTSE; 1014 + 1015 + /* 1016 + * RTS needs to be logic HIGH either during transer _or_ after 1017 + * transfer, other variants are not supported by the hardware. 1018 + */ 1019 + 1020 + if (!(rs485->flags & (SER_RS485_RTS_ON_SEND | 1021 + SER_RS485_RTS_AFTER_SEND))) 1022 + rs485->flags |= SER_RS485_RTS_ON_SEND; 1023 + 1024 + if (rs485->flags & SER_RS485_RTS_ON_SEND && 1025 + rs485->flags & SER_RS485_RTS_AFTER_SEND) 1026 + rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; 1027 + 1028 + /* 1029 + * The hardware defaults to RTS logic HIGH while transfer. 1030 + * Switch polarity in case RTS shall be logic HIGH 1031 + * after transfer. 1032 + * Note: UART is assumed to be active high. 1033 + */ 1034 + if (rs485->flags & SER_RS485_RTS_ON_SEND) 1035 + modem &= ~UARTMODEM_TXRTSPOL; 1036 + else if (rs485->flags & SER_RS485_RTS_AFTER_SEND) 1037 + modem |= UARTMODEM_TXRTSPOL; 1038 + } 1039 + 1040 + /* Store the new configuration */ 1041 + sport->port.rs485 = *rs485; 1042 + 1043 + writeb(modem, sport->port.membase + UARTMODEM); 1044 + return 0; 740 1045 } 741 1046 742 1047 static unsigned int lpuart_get_mctrl(struct uart_port *port) ··· 996 853 static void lpuart_set_mctrl(struct uart_port *port, unsigned int mctrl) 997 854 { 998 855 unsigned char temp; 856 + struct lpuart_port *sport = container_of(port, 857 + struct lpuart_port, port); 999 858 1000 - temp = readb(port->membase + UARTMODEM) & 859 + /* Make sure RXRTSE bit is not set when RS485 is enabled */ 860 + if (!(sport->port.rs485.flags & SER_RS485_ENABLED)) { 861 + temp = readb(sport->port.membase + UARTMODEM) & 1001 862 ~(UARTMODEM_RXRTSE | UARTMODEM_TXCTSE); 1002 863 1003 - if (mctrl & TIOCM_RTS) 1004 - temp |= UARTMODEM_RXRTSE; 864 + if (mctrl & TIOCM_RTS) 865 + temp |= UARTMODEM_RXRTSE; 1005 866 1006 - if (mctrl & TIOCM_CTS) 1007 - temp |= UARTMODEM_TXCTSE; 867 + if (mctrl & TIOCM_CTS) 868 + temp |= UARTMODEM_TXCTSE; 1008 869 1009 - writeb(temp, port->membase + UARTMODEM); 870 + writeb(temp, port->membase + UARTMODEM); 871 + } 1010 872 } 1011 873 1012 874 static void lpuart32_set_mctrl(struct uart_port *port, unsigned int mctrl) ··· 1069 921 writeb(val | UARTPFIFO_TXFE | UARTPFIFO_RXFE, 1070 922 sport->port.membase + UARTPFIFO); 1071 923 1072 - /* explicitly clear RDRF */ 1073 - readb(sport->port.membase + UARTSR1); 1074 - 1075 924 /* flush Tx and Rx FIFO */ 1076 925 writeb(UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH, 1077 926 sport->port.membase + UARTCFIFO); 927 + 928 + /* explicitly clear RDRF */ 929 + if (readb(sport->port.membase + UARTSR1) & UARTSR1_RDRF) { 930 + readb(sport->port.membase + UARTDR); 931 + writeb(UARTSFIFO_RXUF, sport->port.membase + UARTSFIFO); 932 + } 1078 933 1079 934 writeb(0, sport->port.membase + UARTTWFIFO); 1080 935 writeb(1, sport->port.membase + UARTRWFIFO); ··· 1111 960 lpuart32_write(ctrl_saved, sport->port.membase + UARTCTRL); 1112 961 } 1113 962 1114 - static int lpuart_dma_tx_request(struct uart_port *port) 963 + static void rx_dma_timer_init(struct lpuart_port *sport) 1115 964 { 1116 - struct lpuart_port *sport = container_of(port, 1117 - struct lpuart_port, port); 1118 - struct dma_slave_config dma_tx_sconfig; 1119 - dma_addr_t dma_bus; 1120 - unsigned char *dma_buf; 1121 - int ret; 1122 - 1123 - dma_bus = dma_map_single(sport->dma_tx_chan->device->dev, 1124 - sport->port.state->xmit.buf, 1125 - UART_XMIT_SIZE, DMA_TO_DEVICE); 1126 - 1127 - if (dma_mapping_error(sport->dma_tx_chan->device->dev, dma_bus)) { 1128 - dev_err(sport->port.dev, "dma_map_single tx failed\n"); 1129 - return -ENOMEM; 1130 - } 1131 - 1132 - dma_buf = sport->port.state->xmit.buf; 1133 - dma_tx_sconfig.dst_addr = sport->port.mapbase + UARTDR; 1134 - dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 1135 - dma_tx_sconfig.dst_maxburst = sport->txfifo_size; 1136 - dma_tx_sconfig.direction = DMA_MEM_TO_DEV; 1137 - ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig); 1138 - 1139 - if (ret < 0) { 1140 - dev_err(sport->port.dev, 1141 - "Dma slave config failed, err = %d\n", ret); 1142 - return ret; 1143 - } 1144 - 1145 - sport->dma_tx_buf_virt = dma_buf; 1146 - sport->dma_tx_buf_bus = dma_bus; 1147 - sport->dma_tx_in_progress = 0; 1148 - 1149 - return 0; 1150 - } 1151 - 1152 - static int lpuart_dma_rx_request(struct uart_port *port) 1153 - { 1154 - struct lpuart_port *sport = container_of(port, 1155 - struct lpuart_port, port); 1156 - struct dma_slave_config dma_rx_sconfig; 1157 - dma_addr_t dma_bus; 1158 - unsigned char *dma_buf; 1159 - int ret; 1160 - 1161 - dma_buf = devm_kzalloc(sport->port.dev, 1162 - FSL_UART_RX_DMA_BUFFER_SIZE, GFP_KERNEL); 1163 - 1164 - if (!dma_buf) { 1165 - dev_err(sport->port.dev, "Dma rx alloc failed\n"); 1166 - return -ENOMEM; 1167 - } 1168 - 1169 - dma_bus = dma_map_single(sport->dma_rx_chan->device->dev, dma_buf, 1170 - FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE); 1171 - 1172 - if (dma_mapping_error(sport->dma_rx_chan->device->dev, dma_bus)) { 1173 - dev_err(sport->port.dev, "dma_map_single rx failed\n"); 1174 - return -ENOMEM; 1175 - } 1176 - 1177 - dma_rx_sconfig.src_addr = sport->port.mapbase + UARTDR; 1178 - dma_rx_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 1179 - dma_rx_sconfig.src_maxburst = 1; 1180 - dma_rx_sconfig.direction = DMA_DEV_TO_MEM; 1181 - ret = dmaengine_slave_config(sport->dma_rx_chan, &dma_rx_sconfig); 1182 - 1183 - if (ret < 0) { 1184 - dev_err(sport->port.dev, 1185 - "Dma slave config failed, err = %d\n", ret); 1186 - return ret; 1187 - } 1188 - 1189 - sport->dma_rx_buf_virt = dma_buf; 1190 - sport->dma_rx_buf_bus = dma_bus; 1191 - sport->dma_rx_in_progress = 0; 1192 - 1193 - return 0; 1194 - } 1195 - 1196 - static void lpuart_dma_tx_free(struct uart_port *port) 1197 - { 1198 - struct lpuart_port *sport = container_of(port, 1199 - struct lpuart_port, port); 1200 - 1201 - dma_unmap_single(sport->port.dev, sport->dma_tx_buf_bus, 1202 - UART_XMIT_SIZE, DMA_TO_DEVICE); 1203 - 1204 - sport->dma_tx_buf_bus = 0; 1205 - sport->dma_tx_buf_virt = NULL; 1206 - } 1207 - 1208 - static void lpuart_dma_rx_free(struct uart_port *port) 1209 - { 1210 - struct lpuart_port *sport = container_of(port, 1211 - struct lpuart_port, port); 1212 - 1213 - dma_unmap_single(sport->port.dev, sport->dma_rx_buf_bus, 1214 - FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE); 1215 - 1216 - sport->dma_rx_buf_bus = 0; 1217 - sport->dma_rx_buf_virt = NULL; 965 + setup_timer(&sport->lpuart_timer, lpuart_timer_func, 966 + (unsigned long)sport); 967 + sport->lpuart_timer.expires = jiffies + sport->dma_rx_timeout; 968 + add_timer(&sport->lpuart_timer); 1218 969 } 1219 970 1220 971 static int lpuart_startup(struct uart_port *port) ··· 1137 1084 sport->rxfifo_size = 0x1 << (((temp >> UARTPFIFO_RXSIZE_OFF) & 1138 1085 UARTPFIFO_FIFOSIZE_MASK) + 1); 1139 1086 1140 - if (sport->dma_rx_chan && !lpuart_dma_rx_request(port)) { 1141 - sport->lpuart_dma_rx_use = true; 1142 - setup_timer(&sport->lpuart_timer, lpuart_timer_func, 1143 - (unsigned long)sport); 1144 - } else 1145 - sport->lpuart_dma_rx_use = false; 1146 - 1147 - 1148 - if (sport->dma_tx_chan && !lpuart_dma_tx_request(port)) { 1149 - sport->lpuart_dma_tx_use = true; 1150 - temp = readb(port->membase + UARTCR5); 1151 - temp &= ~UARTCR5_RDMAS; 1152 - writeb(temp | UARTCR5_TDMAS, port->membase + UARTCR5); 1153 - } else 1154 - sport->lpuart_dma_tx_use = false; 1155 - 1156 1087 ret = devm_request_irq(port->dev, port->irq, lpuart_int, 0, 1157 1088 DRIVER_NAME, sport); 1158 1089 if (ret) ··· 1150 1113 temp |= (UARTCR2_RIE | UARTCR2_TIE | UARTCR2_RE | UARTCR2_TE); 1151 1114 writeb(temp, sport->port.membase + UARTCR2); 1152 1115 1116 + if (sport->dma_rx_chan && !lpuart_start_rx_dma(sport)) { 1117 + /* set Rx DMA timeout */ 1118 + sport->dma_rx_timeout = msecs_to_jiffies(DMA_RX_TIMEOUT); 1119 + if (!sport->dma_rx_timeout) 1120 + sport->dma_rx_timeout = 1; 1121 + 1122 + sport->lpuart_dma_rx_use = true; 1123 + rx_dma_timer_init(sport); 1124 + } else { 1125 + sport->lpuart_dma_rx_use = false; 1126 + } 1127 + 1128 + if (sport->dma_tx_chan && !lpuart_dma_tx_request(port)) { 1129 + init_waitqueue_head(&sport->dma_wait); 1130 + sport->lpuart_dma_tx_use = true; 1131 + temp = readb(port->membase + UARTCR5); 1132 + writeb(temp | UARTCR5_TDMAS, port->membase + UARTCR5); 1133 + } else { 1134 + sport->lpuart_dma_tx_use = false; 1135 + } 1136 + 1153 1137 spin_unlock_irqrestore(&sport->port.lock, flags); 1138 + 1154 1139 return 0; 1155 1140 } 1156 1141 ··· 1229 1170 devm_free_irq(port->dev, port->irq, sport); 1230 1171 1231 1172 if (sport->lpuart_dma_rx_use) { 1232 - lpuart_dma_rx_free(&sport->port); 1233 1173 del_timer_sync(&sport->lpuart_timer); 1174 + lpuart_dma_rx_free(&sport->port); 1234 1175 } 1235 1176 1236 - if (sport->lpuart_dma_tx_use) 1237 - lpuart_dma_tx_free(&sport->port); 1177 + if (sport->lpuart_dma_tx_use) { 1178 + if (wait_event_interruptible(sport->dma_wait, 1179 + !sport->dma_tx_in_progress) != false) { 1180 + sport->dma_tx_in_progress = false; 1181 + dmaengine_terminate_all(sport->dma_tx_chan); 1182 + } 1183 + 1184 + lpuart_stop_tx(port); 1185 + } 1238 1186 } 1239 1187 1240 1188 static void lpuart32_shutdown(struct uart_port *port) ··· 1269 1203 { 1270 1204 struct lpuart_port *sport = container_of(port, struct lpuart_port, port); 1271 1205 unsigned long flags; 1272 - unsigned char cr1, old_cr1, old_cr2, cr4, bdh, modem; 1206 + unsigned char cr1, old_cr1, old_cr2, cr3, cr4, bdh, modem; 1273 1207 unsigned int baud; 1274 1208 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; 1275 1209 unsigned int sbr, brfa; 1276 1210 1277 1211 cr1 = old_cr1 = readb(sport->port.membase + UARTCR1); 1278 1212 old_cr2 = readb(sport->port.membase + UARTCR2); 1213 + cr3 = readb(sport->port.membase + UARTCR3); 1279 1214 cr4 = readb(sport->port.membase + UARTCR4); 1280 1215 bdh = readb(sport->port.membase + UARTBDH); 1281 1216 modem = readb(sport->port.membase + UARTMODEM); ··· 1307 1240 cr1 |= UARTCR1_M; 1308 1241 } 1309 1242 1243 + /* 1244 + * When auto RS-485 RTS mode is enabled, 1245 + * hardware flow control need to be disabled. 1246 + */ 1247 + if (sport->port.rs485.flags & SER_RS485_ENABLED) 1248 + termios->c_cflag &= ~CRTSCTS; 1249 + 1310 1250 if (termios->c_cflag & CRTSCTS) { 1311 1251 modem |= (UARTMODEM_RXRTSE | UARTMODEM_TXCTSE); 1312 1252 } else { ··· 1331 1257 if ((termios->c_cflag & PARENB)) { 1332 1258 if (termios->c_cflag & CMSPAR) { 1333 1259 cr1 &= ~UARTCR1_PE; 1334 - cr1 |= UARTCR1_M; 1260 + if (termios->c_cflag & PARODD) 1261 + cr3 |= UARTCR3_T8; 1262 + else 1263 + cr3 &= ~UARTCR3_T8; 1335 1264 } else { 1336 1265 cr1 |= UARTCR1_PE; 1337 1266 if ((termios->c_cflag & CSIZE) == CS8) ··· 1374 1297 /* update the per-port timeout */ 1375 1298 uart_update_timeout(port, termios->c_cflag, baud); 1376 1299 1377 - if (sport->lpuart_dma_rx_use) { 1378 - /* Calculate delay for 1.5 DMA buffers */ 1379 - sport->dma_rx_timeout = (sport->port.timeout - HZ / 50) * 1380 - FSL_UART_RX_DMA_BUFFER_SIZE * 3 / 1381 - sport->rxfifo_size / 2; 1382 - dev_dbg(port->dev, "DMA Rx t-out %ums, tty t-out %u jiffies\n", 1383 - sport->dma_rx_timeout * 1000 / HZ, sport->port.timeout); 1384 - if (sport->dma_rx_timeout < msecs_to_jiffies(20)) 1385 - sport->dma_rx_timeout = msecs_to_jiffies(20); 1386 - } 1387 - 1388 1300 /* wait transmit engin complete */ 1389 1301 while (!(readb(sport->port.membase + UARTSR1) & UARTSR1_TC)) 1390 1302 barrier(); ··· 1391 1325 writeb(cr4 | brfa, sport->port.membase + UARTCR4); 1392 1326 writeb(bdh, sport->port.membase + UARTBDH); 1393 1327 writeb(sbr & 0xFF, sport->port.membase + UARTBDL); 1328 + writeb(cr3, sport->port.membase + UARTCR3); 1394 1329 writeb(cr1, sport->port.membase + UARTCR1); 1395 1330 writeb(modem, sport->port.membase + UARTMODEM); 1396 1331 1397 1332 /* restore control register */ 1398 1333 writeb(old_cr2, sport->port.membase + UARTCR2); 1334 + 1335 + /* 1336 + * If new baud rate is set, we will also need to update the Ring buffer 1337 + * length according to the selected baud rate and restart Rx DMA path. 1338 + */ 1339 + if (old) { 1340 + if (sport->lpuart_dma_rx_use) { 1341 + del_timer_sync(&sport->lpuart_timer); 1342 + lpuart_dma_rx_free(&sport->port); 1343 + } 1344 + 1345 + if (sport->dma_rx_chan && !lpuart_start_rx_dma(sport)) { 1346 + sport->lpuart_dma_rx_use = true; 1347 + rx_dma_timer_init(sport); 1348 + } else { 1349 + sport->lpuart_dma_rx_use = false; 1350 + } 1351 + } 1399 1352 1400 1353 spin_unlock_irqrestore(&sport->port.lock, flags); 1401 1354 } ··· 1579 1494 return ret; 1580 1495 } 1581 1496 1582 - static struct uart_ops lpuart_pops = { 1497 + static const struct uart_ops lpuart_pops = { 1583 1498 .tx_empty = lpuart_tx_empty, 1584 1499 .set_mctrl = lpuart_set_mctrl, 1585 1500 .get_mctrl = lpuart_get_mctrl, ··· 1598 1513 .flush_buffer = lpuart_flush_buffer, 1599 1514 }; 1600 1515 1601 - static struct uart_ops lpuart32_pops = { 1516 + static const struct uart_ops lpuart32_pops = { 1602 1517 .tx_empty = lpuart32_tx_empty, 1603 1518 .set_mctrl = lpuart32_set_mctrl, 1604 1519 .get_mctrl = lpuart32_get_mctrl, ··· 1928 1843 sport->port.ops = &lpuart_pops; 1929 1844 sport->port.flags = UPF_BOOT_AUTOCONF; 1930 1845 1846 + sport->port.rs485_config = lpuart_config_rs485; 1847 + 1931 1848 sport->clk = devm_clk_get(&pdev->dev, "ipg"); 1932 1849 if (IS_ERR(sport->clk)) { 1933 1850 ret = PTR_ERR(sport->clk); ··· 1969 1882 if (!sport->dma_rx_chan) 1970 1883 dev_info(sport->port.dev, "DMA rx channel request failed, " 1971 1884 "operating without rx DMA\n"); 1885 + 1886 + if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time")) { 1887 + sport->port.rs485.flags |= SER_RS485_ENABLED; 1888 + sport->port.rs485.flags |= SER_RS485_RTS_ON_SEND; 1889 + writeb(UARTMODEM_TXRTSE, sport->port.membase + UARTMODEM); 1890 + } 1972 1891 1973 1892 return 0; 1974 1893 } ··· 2016 1923 2017 1924 uart_suspend_port(&lpuart_reg, &sport->port); 2018 1925 1926 + if (sport->lpuart_dma_rx_use) { 1927 + /* 1928 + * EDMA driver during suspend will forcefully release any 1929 + * non-idle DMA channels. If port wakeup is enabled or if port 1930 + * is console port or 'no_console_suspend' is set the Rx DMA 1931 + * cannot resume as as expected, hence gracefully release the 1932 + * Rx DMA path before suspend and start Rx DMA path on resume. 1933 + */ 1934 + if (sport->port.irq_wake) { 1935 + del_timer_sync(&sport->lpuart_timer); 1936 + lpuart_dma_rx_free(&sport->port); 1937 + } 1938 + 1939 + /* Disable Rx DMA to use UART port as wakeup source */ 1940 + writeb(readb(sport->port.membase + UARTCR5) & ~UARTCR5_RDMAS, 1941 + sport->port.membase + UARTCR5); 1942 + } 1943 + 1944 + if (sport->lpuart_dma_tx_use) { 1945 + sport->dma_tx_in_progress = false; 1946 + dmaengine_terminate_all(sport->dma_tx_chan); 1947 + } 1948 + 1949 + if (sport->port.suspended && !sport->port.irq_wake) 1950 + clk_disable_unprepare(sport->clk); 1951 + 2019 1952 return 0; 2020 1953 } 2021 1954 ··· 2049 1930 { 2050 1931 struct lpuart_port *sport = dev_get_drvdata(dev); 2051 1932 unsigned long temp; 1933 + 1934 + if (sport->port.suspended && !sport->port.irq_wake) 1935 + clk_prepare_enable(sport->clk); 2052 1936 2053 1937 if (sport->lpuart32) { 2054 1938 lpuart32_setup_watermark(sport); ··· 2064 1942 temp = readb(sport->port.membase + UARTCR2); 2065 1943 temp |= (UARTCR2_RIE | UARTCR2_TIE | UARTCR2_RE | UARTCR2_TE); 2066 1944 writeb(temp, sport->port.membase + UARTCR2); 1945 + } 1946 + 1947 + if (sport->lpuart_dma_rx_use) { 1948 + if (sport->port.irq_wake) { 1949 + if (!lpuart_start_rx_dma(sport)) { 1950 + sport->lpuart_dma_rx_use = true; 1951 + rx_dma_timer_init(sport); 1952 + } else { 1953 + sport->lpuart_dma_rx_use = false; 1954 + } 1955 + } 1956 + } 1957 + 1958 + if (sport->dma_tx_chan && !lpuart_dma_tx_request(&sport->port)) { 1959 + init_waitqueue_head(&sport->dma_wait); 1960 + sport->lpuart_dma_tx_use = true; 1961 + writeb(readb(sport->port.membase + UARTCR5) | 1962 + UARTCR5_TDMAS, sport->port.membase + UARTCR5); 1963 + } else { 1964 + sport->lpuart_dma_tx_use = false; 2067 1965 } 2068 1966 2069 1967 uart_resume_port(&lpuart_reg, &sport->port);
+146 -75
drivers/tty/serial/imx.c
··· 190 190 enum imx_uart_type { 191 191 IMX1_UART, 192 192 IMX21_UART, 193 + IMX53_UART, 193 194 IMX6Q_UART, 194 195 }; 195 196 ··· 223 222 struct dma_chan *dma_chan_rx, *dma_chan_tx; 224 223 struct scatterlist rx_sgl, tx_sgl[2]; 225 224 void *rx_buf; 225 + struct circ_buf rx_ring; 226 + unsigned int rx_periods; 227 + dma_cookie_t rx_cookie; 226 228 unsigned int tx_bytes; 227 229 unsigned int dma_tx_nents; 228 230 wait_queue_head_t dma_wait; ··· 248 244 .uts_reg = IMX21_UTS, 249 245 .devtype = IMX21_UART, 250 246 }, 247 + [IMX53_UART] = { 248 + .uts_reg = IMX21_UTS, 249 + .devtype = IMX53_UART, 250 + }, 251 251 [IMX6Q_UART] = { 252 252 .uts_reg = IMX21_UTS, 253 253 .devtype = IMX6Q_UART, ··· 266 258 .name = "imx21-uart", 267 259 .driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX21_UART], 268 260 }, { 261 + .name = "imx53-uart", 262 + .driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX53_UART], 263 + }, { 269 264 .name = "imx6q-uart", 270 265 .driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX6Q_UART], 271 266 }, { ··· 279 268 280 269 static const struct of_device_id imx_uart_dt_ids[] = { 281 270 { .compatible = "fsl,imx6q-uart", .data = &imx_uart_devdata[IMX6Q_UART], }, 271 + { .compatible = "fsl,imx53-uart", .data = &imx_uart_devdata[IMX53_UART], }, 282 272 { .compatible = "fsl,imx1-uart", .data = &imx_uart_devdata[IMX1_UART], }, 283 273 { .compatible = "fsl,imx21-uart", .data = &imx_uart_devdata[IMX21_UART], }, 284 274 { /* sentinel */ } ··· 299 287 static inline int is_imx21_uart(struct imx_port *sport) 300 288 { 301 289 return sport->devdata->devtype == IMX21_UART; 290 + } 291 + 292 + static inline int is_imx53_uart(struct imx_port *sport) 293 + { 294 + return sport->devdata->devtype == IMX53_UART; 302 295 } 303 296 304 297 static inline int is_imx6q_uart(struct imx_port *sport) ··· 718 701 return IRQ_HANDLED; 719 702 } 720 703 704 + static void clear_rx_errors(struct imx_port *sport); 721 705 static int start_rx_dma(struct imx_port *sport); 722 706 /* 723 707 * If the RXFIFO is filled with some data, and then we ··· 744 726 temp &= ~(UCR2_ATEN); 745 727 writel(temp, sport->port.membase + UCR2); 746 728 729 + /* disable the rx errors interrupts */ 730 + temp = readl(sport->port.membase + UCR4); 731 + temp &= ~UCR4_OREN; 732 + writel(temp, sport->port.membase + UCR4); 733 + 747 734 /* tell the DMA to receive the data. */ 748 735 start_rx_dma(sport); 749 736 } ··· 763 740 { 764 741 unsigned int tmp = TIOCM_DSR; 765 742 unsigned usr1 = readl(sport->port.membase + USR1); 743 + unsigned usr2 = readl(sport->port.membase + USR2); 766 744 767 745 if (usr1 & USR1_RTSS) 768 746 tmp |= TIOCM_CTS; 769 747 770 748 /* in DCE mode DCDIN is always 0 */ 771 - if (!(usr1 & USR2_DCDIN)) 749 + if (!(usr2 & USR2_DCDIN)) 772 750 tmp |= TIOCM_CAR; 773 751 774 752 if (sport->dte_mode) ··· 956 932 } 957 933 958 934 #define RX_BUF_SIZE (PAGE_SIZE) 959 - static void imx_rx_dma_done(struct imx_port *sport) 960 - { 961 - unsigned long temp; 962 - unsigned long flags; 963 - 964 - spin_lock_irqsave(&sport->port.lock, flags); 965 - 966 - /* re-enable interrupts to get notified when new symbols are incoming */ 967 - temp = readl(sport->port.membase + UCR1); 968 - temp |= UCR1_RRDYEN; 969 - writel(temp, sport->port.membase + UCR1); 970 - 971 - temp = readl(sport->port.membase + UCR2); 972 - temp |= UCR2_ATEN; 973 - writel(temp, sport->port.membase + UCR2); 974 - 975 - sport->dma_is_rxing = 0; 976 - 977 - /* Is the shutdown waiting for us? */ 978 - if (waitqueue_active(&sport->dma_wait)) 979 - wake_up(&sport->dma_wait); 980 - 981 - spin_unlock_irqrestore(&sport->port.lock, flags); 982 - } 983 935 984 936 /* 985 937 * There are two kinds of RX DMA interrupts(such as in the MX6Q): ··· 972 972 struct scatterlist *sgl = &sport->rx_sgl; 973 973 struct tty_port *port = &sport->port.state->port; 974 974 struct dma_tx_state state; 975 + struct circ_buf *rx_ring = &sport->rx_ring; 975 976 enum dma_status status; 976 - unsigned int count; 977 - 978 - /* unmap it first */ 979 - dma_unmap_sg(sport->port.dev, sgl, 1, DMA_FROM_DEVICE); 977 + unsigned int w_bytes = 0; 978 + unsigned int r_bytes; 979 + unsigned int bd_size; 980 980 981 981 status = dmaengine_tx_status(chan, (dma_cookie_t)0, &state); 982 - count = RX_BUF_SIZE - state.residue; 983 982 984 - dev_dbg(sport->port.dev, "We get %d bytes.\n", count); 985 - 986 - if (count) { 987 - if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) { 988 - int bytes = tty_insert_flip_string(port, sport->rx_buf, 989 - count); 990 - 991 - if (bytes != count) 992 - sport->port.icount.buf_overrun++; 993 - } 994 - tty_flip_buffer_push(port); 995 - sport->port.icount.rx += count; 983 + if (status == DMA_ERROR) { 984 + dev_err(sport->port.dev, "DMA transaction error.\n"); 985 + clear_rx_errors(sport); 986 + return; 996 987 } 997 988 998 - /* 999 - * Restart RX DMA directly if more data is available in order to skip 1000 - * the roundtrip through the IRQ handler. If there is some data already 1001 - * in the FIFO, DMA needs to be restarted soon anyways. 1002 - * 1003 - * Otherwise stop the DMA and reactivate FIFO IRQs to restart DMA once 1004 - * data starts to arrive again. 1005 - */ 1006 - if (readl(sport->port.membase + USR2) & USR2_RDR) 1007 - start_rx_dma(sport); 1008 - else 1009 - imx_rx_dma_done(sport); 989 + if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) { 990 + 991 + /* 992 + * The state-residue variable represents the empty space 993 + * relative to the entire buffer. Taking this in consideration 994 + * the head is always calculated base on the buffer total 995 + * length - DMA transaction residue. The UART script from the 996 + * SDMA firmware will jump to the next buffer descriptor, 997 + * once a DMA transaction if finalized (IMX53 RM - A.4.1.2.4). 998 + * Taking this in consideration the tail is always at the 999 + * beginning of the buffer descriptor that contains the head. 1000 + */ 1001 + 1002 + /* Calculate the head */ 1003 + rx_ring->head = sg_dma_len(sgl) - state.residue; 1004 + 1005 + /* Calculate the tail. */ 1006 + bd_size = sg_dma_len(sgl) / sport->rx_periods; 1007 + rx_ring->tail = ((rx_ring->head-1) / bd_size) * bd_size; 1008 + 1009 + if (rx_ring->head <= sg_dma_len(sgl) && 1010 + rx_ring->head > rx_ring->tail) { 1011 + 1012 + /* Move data from tail to head */ 1013 + r_bytes = rx_ring->head - rx_ring->tail; 1014 + 1015 + /* CPU claims ownership of RX DMA buffer */ 1016 + dma_sync_sg_for_cpu(sport->port.dev, sgl, 1, 1017 + DMA_FROM_DEVICE); 1018 + 1019 + w_bytes = tty_insert_flip_string(port, 1020 + sport->rx_buf + rx_ring->tail, r_bytes); 1021 + 1022 + /* UART retrieves ownership of RX DMA buffer */ 1023 + dma_sync_sg_for_device(sport->port.dev, sgl, 1, 1024 + DMA_FROM_DEVICE); 1025 + 1026 + if (w_bytes != r_bytes) 1027 + sport->port.icount.buf_overrun++; 1028 + 1029 + sport->port.icount.rx += w_bytes; 1030 + } else { 1031 + WARN_ON(rx_ring->head > sg_dma_len(sgl)); 1032 + WARN_ON(rx_ring->head <= rx_ring->tail); 1033 + } 1034 + } 1035 + 1036 + if (w_bytes) { 1037 + tty_flip_buffer_push(port); 1038 + dev_dbg(sport->port.dev, "We get %d bytes.\n", w_bytes); 1039 + } 1010 1040 } 1041 + 1042 + /* RX DMA buffer periods */ 1043 + #define RX_DMA_PERIODS 4 1011 1044 1012 1045 static int start_rx_dma(struct imx_port *sport) 1013 1046 { ··· 1050 1017 struct dma_async_tx_descriptor *desc; 1051 1018 int ret; 1052 1019 1020 + sport->rx_ring.head = 0; 1021 + sport->rx_ring.tail = 0; 1022 + sport->rx_periods = RX_DMA_PERIODS; 1023 + 1053 1024 sg_init_one(sgl, sport->rx_buf, RX_BUF_SIZE); 1054 1025 ret = dma_map_sg(dev, sgl, 1, DMA_FROM_DEVICE); 1055 1026 if (ret == 0) { 1056 1027 dev_err(dev, "DMA mapping error for RX.\n"); 1057 1028 return -EINVAL; 1058 1029 } 1059 - desc = dmaengine_prep_slave_sg(chan, sgl, 1, DMA_DEV_TO_MEM, 1060 - DMA_PREP_INTERRUPT); 1030 + 1031 + desc = dmaengine_prep_dma_cyclic(chan, sg_dma_address(sgl), 1032 + sg_dma_len(sgl), sg_dma_len(sgl) / sport->rx_periods, 1033 + DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT); 1034 + 1061 1035 if (!desc) { 1062 1036 dma_unmap_sg(dev, sgl, 1, DMA_FROM_DEVICE); 1063 1037 dev_err(dev, "We cannot prepare for the RX slave dma!\n"); ··· 1074 1034 desc->callback_param = sport; 1075 1035 1076 1036 dev_dbg(dev, "RX: prepare for the DMA.\n"); 1077 - dmaengine_submit(desc); 1037 + sport->rx_cookie = dmaengine_submit(desc); 1078 1038 dma_async_issue_pending(chan); 1079 1039 return 0; 1040 + } 1041 + 1042 + static void clear_rx_errors(struct imx_port *sport) 1043 + { 1044 + unsigned int status_usr1, status_usr2; 1045 + 1046 + status_usr1 = readl(sport->port.membase + USR1); 1047 + status_usr2 = readl(sport->port.membase + USR2); 1048 + 1049 + if (status_usr2 & USR2_BRCD) { 1050 + sport->port.icount.brk++; 1051 + writel(USR2_BRCD, sport->port.membase + USR2); 1052 + } else if (status_usr1 & USR1_FRAMERR) { 1053 + sport->port.icount.frame++; 1054 + writel(USR1_FRAMERR, sport->port.membase + USR1); 1055 + } else if (status_usr1 & USR1_PARITYERR) { 1056 + sport->port.icount.parity++; 1057 + writel(USR1_PARITYERR, sport->port.membase + USR1); 1058 + } 1059 + 1060 + if (status_usr2 & USR2_ORE) { 1061 + sport->port.icount.overrun++; 1062 + writel(USR2_ORE, sport->port.membase + USR2); 1063 + } 1064 + 1080 1065 } 1081 1066 1082 1067 #define TXTL_DEFAULT 2 /* reset default */ ··· 1123 1058 static void imx_uart_dma_exit(struct imx_port *sport) 1124 1059 { 1125 1060 if (sport->dma_chan_rx) { 1061 + dmaengine_terminate_sync(sport->dma_chan_rx); 1126 1062 dma_release_channel(sport->dma_chan_rx); 1127 1063 sport->dma_chan_rx = NULL; 1128 - 1064 + sport->rx_cookie = -EINVAL; 1129 1065 kfree(sport->rx_buf); 1130 1066 sport->rx_buf = NULL; 1131 1067 } 1132 1068 1133 1069 if (sport->dma_chan_tx) { 1070 + dmaengine_terminate_sync(sport->dma_chan_tx); 1134 1071 dma_release_channel(sport->dma_chan_tx); 1135 1072 sport->dma_chan_tx = NULL; 1136 1073 } ··· 1170 1103 ret = -ENOMEM; 1171 1104 goto err; 1172 1105 } 1106 + sport->rx_ring.buf = sport->rx_buf; 1173 1107 1174 1108 /* Prepare for TX : */ 1175 1109 sport->dma_chan_tx = dma_request_slave_channel(dev, "tx"); ··· 1269 1201 writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); 1270 1202 1271 1203 /* Can we enable the DMA support? */ 1272 - if (is_imx6q_uart(sport) && !uart_console(port) && 1273 - !sport->dma_is_inited) 1204 + if (!uart_console(port) && !sport->dma_is_inited) 1274 1205 imx_uart_dma_init(sport); 1275 1206 1276 1207 spin_lock_irqsave(&sport->port.lock, flags); ··· 1350 1283 unsigned long flags; 1351 1284 1352 1285 if (sport->dma_is_enabled) { 1353 - int ret; 1286 + sport->dma_is_rxing = 0; 1287 + sport->dma_is_txing = 0; 1288 + dmaengine_terminate_sync(sport->dma_chan_tx); 1289 + dmaengine_terminate_sync(sport->dma_chan_rx); 1354 1290 1355 - /* We have to wait for the DMA to finish. */ 1356 - ret = wait_event_interruptible(sport->dma_wait, 1357 - !sport->dma_is_rxing && !sport->dma_is_txing); 1358 - if (ret != 0) { 1359 - sport->dma_is_rxing = 0; 1360 - sport->dma_is_txing = 0; 1361 - dmaengine_terminate_all(sport->dma_chan_tx); 1362 - dmaengine_terminate_all(sport->dma_chan_rx); 1363 - } 1364 1291 spin_lock_irqsave(&sport->port.lock, flags); 1365 1292 imx_stop_tx(port); 1366 1293 imx_stop_rx(port); ··· 1751 1690 return 0; 1752 1691 } 1753 1692 1754 - static struct uart_ops imx_pops = { 1693 + static const struct uart_ops imx_pops = { 1755 1694 .tx_empty = imx_tx_empty, 1756 1695 .set_mctrl = imx_set_mctrl, 1757 1696 .get_mctrl = imx_get_mctrl, ··· 2138 2077 2139 2078 /* For register access, we only need to enable the ipg clock. */ 2140 2079 ret = clk_prepare_enable(sport->clk_ipg); 2141 - if (ret) 2080 + if (ret) { 2081 + dev_err(&pdev->dev, "failed to enable per clk: %d\n", ret); 2142 2082 return ret; 2083 + } 2143 2084 2144 2085 /* Disable interrupts before requesting them */ 2145 2086 reg = readl_relaxed(sport->port.membase + UCR1); ··· 2158 2095 if (txirq > 0) { 2159 2096 ret = devm_request_irq(&pdev->dev, rxirq, imx_rxint, 0, 2160 2097 dev_name(&pdev->dev), sport); 2161 - if (ret) 2098 + if (ret) { 2099 + dev_err(&pdev->dev, "failed to request rx irq: %d\n", 2100 + ret); 2162 2101 return ret; 2102 + } 2163 2103 2164 2104 ret = devm_request_irq(&pdev->dev, txirq, imx_txint, 0, 2165 2105 dev_name(&pdev->dev), sport); 2166 - if (ret) 2106 + if (ret) { 2107 + dev_err(&pdev->dev, "failed to request tx irq: %d\n", 2108 + ret); 2167 2109 return ret; 2110 + } 2168 2111 } else { 2169 2112 ret = devm_request_irq(&pdev->dev, rxirq, imx_int, 0, 2170 2113 dev_name(&pdev->dev), sport); 2171 - if (ret) 2114 + if (ret) { 2115 + dev_err(&pdev->dev, "failed to request irq: %d\n", ret); 2172 2116 return ret; 2117 + } 2173 2118 } 2174 2119 2175 2120 imx_ports[sport->port.line] = sport;
+1 -1
drivers/tty/serial/jsm/jsm_tty.c
··· 346 346 port->type = PORT_JSM; 347 347 } 348 348 349 - static struct uart_ops jsm_ops = { 349 + static const struct uart_ops jsm_ops = { 350 350 .tx_empty = jsm_tty_tx_empty, 351 351 .set_mctrl = jsm_tty_set_mctrl, 352 352 .get_mctrl = jsm_tty_get_mctrl,
+1 -1
drivers/tty/serial/max3100.c
··· 712 712 dev_dbg(&s->spi->dev, "%s\n", __func__); 713 713 } 714 714 715 - static struct uart_ops max3100_ops = { 715 + static const struct uart_ops max3100_ops = { 716 716 .tx_empty = max3100_tx_empty, 717 717 .set_mctrl = max3100_set_mctrl, 718 718 .get_mctrl = max3100_get_mctrl,
+1 -1
drivers/tty/serial/max310x.c
··· 1329 1329 const struct spi_device_id *id_entry = spi_get_device_id(spi); 1330 1330 1331 1331 devtype = (struct max310x_devtype *)id_entry->driver_data; 1332 - flags = IRQF_TRIGGER_FALLING; 1333 1332 } 1334 1333 1334 + flags = IRQF_TRIGGER_FALLING; 1335 1335 regcfg.max_register = devtype->nr * 0x20 - 1; 1336 1336 regmap = devm_regmap_init_spi(spi, &regcfg); 1337 1337
+1 -1
drivers/tty/serial/men_z135_uart.c
··· 775 775 return -EINVAL; 776 776 } 777 777 778 - static struct uart_ops men_z135_ops = { 778 + static const struct uart_ops men_z135_ops = { 779 779 .tx_empty = men_z135_tx_empty, 780 780 .set_mctrl = men_z135_set_mctrl, 781 781 .get_mctrl = men_z135_get_mctrl,
+8 -7
drivers/tty/serial/mxs-auart.c
··· 1317 1317 mxs_clr(AUART_LINECTRL_BRK, s, REG_LINECTRL); 1318 1318 } 1319 1319 1320 - static struct uart_ops mxs_auart_ops = { 1320 + static const struct uart_ops mxs_auart_ops = { 1321 1321 .tx_empty = mxs_auart_tx_empty, 1322 1322 .start_tx = mxs_auart_start_tx, 1323 1323 .stop_tx = mxs_auart_stop_tx, ··· 1510 1510 1511 1511 if (!is_asm9260_auart(s)) { 1512 1512 s->clk = devm_clk_get(&pdev->dev, NULL); 1513 - if (IS_ERR(s->clk)) 1514 - return PTR_ERR(s->clk); 1515 - 1516 - return 0; 1513 + return PTR_ERR_OR_ZERO(s->clk); 1517 1514 } 1518 1515 1519 1516 s->clk = devm_clk_get(s->dev, "mod"); ··· 1534 1537 err = clk_set_rate(s->clk, clk_get_rate(s->clk_ahb)); 1535 1538 if (err) { 1536 1539 dev_err(s->dev, "Failed to set rate!\n"); 1537 - return err; 1540 + goto disable_clk_ahb; 1538 1541 } 1539 1542 1540 1543 err = clk_prepare_enable(s->clk); 1541 1544 if (err) { 1542 1545 dev_err(s->dev, "Failed to enable clk!\n"); 1543 - return err; 1546 + goto disable_clk_ahb; 1544 1547 } 1545 1548 1546 1549 return 0; 1550 + 1551 + disable_clk_ahb: 1552 + clk_disable_unprepare(s->clk_ahb); 1553 + return err; 1547 1554 } 1548 1555 1549 1556 /*
+1 -1
drivers/tty/serial/pch_uart.c
··· 1604 1604 } 1605 1605 #endif /* CONFIG_CONSOLE_POLL */ 1606 1606 1607 - static struct uart_ops pch_uart_ops = { 1607 + static const struct uart_ops pch_uart_ops = { 1608 1608 .tx_empty = pch_uart_tx_empty, 1609 1609 .set_mctrl = pch_uart_set_mctrl, 1610 1610 .get_mctrl = pch_uart_get_mctrl,
+1 -1
drivers/tty/serial/samsung.c
··· 1577 1577 } 1578 1578 1579 1579 1580 - #ifdef CONFIG_CPU_FREQ 1580 + #ifdef CONFIG_ARM_S3C24XX_CPUFREQ 1581 1581 1582 1582 static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb, 1583 1583 unsigned long val, void *data)
+1 -1
drivers/tty/serial/samsung.h
··· 102 102 103 103 struct s3c24xx_uart_dma *dma; 104 104 105 - #ifdef CONFIG_CPU_FREQ 105 + #ifdef CONFIG_ARM_S3C24XX_CPUFREQ 106 106 struct notifier_block freq_transition; 107 107 #endif 108 108 };
+20
drivers/tty/serial/sc16is7xx.c
··· 1205 1205 } 1206 1206 #endif 1207 1207 1208 + /* reset device, purging any pending irq / data */ 1209 + regmap_write(s->regmap, SC16IS7XX_IOCONTROL_REG << SC16IS7XX_REG_SHIFT, 1210 + SC16IS7XX_IOCONTROL_SRESET_BIT); 1211 + 1208 1212 for (i = 0; i < devtype->nr_uart; ++i) { 1209 1213 s->p[i].line = i; 1210 1214 /* Initialize port data */ ··· 1238 1234 init_kthread_work(&s->p[i].reg_work, sc16is7xx_reg_proc); 1239 1235 /* Register port */ 1240 1236 uart_add_one_port(&sc16is7xx_uart, &s->p[i].port); 1237 + 1238 + /* Enable EFR */ 1239 + sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_LCR_REG, 1240 + SC16IS7XX_LCR_CONF_MODE_B); 1241 + 1242 + regcache_cache_bypass(s->regmap, true); 1243 + 1244 + /* Enable write access to enhanced features */ 1245 + sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_EFR_REG, 1246 + SC16IS7XX_EFR_ENABLE_BIT); 1247 + 1248 + regcache_cache_bypass(s->regmap, false); 1249 + 1250 + /* Restore access to general registers */ 1251 + sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_LCR_REG, 0x00); 1252 + 1241 1253 /* Go to suspend mode */ 1242 1254 sc16is7xx_power(&s->p[i].port, 0); 1243 1255 }
+53 -91
drivers/tty/serial/serial_core.c
··· 235 235 if (tty_port_initialized(port)) 236 236 return 0; 237 237 238 - /* 239 - * Set the TTY IO error marker - we will only clear this 240 - * once we have successfully opened the port. 241 - */ 242 - set_bit(TTY_IO_ERROR, &tty->flags); 243 - 244 238 retval = uart_port_startup(tty, state, init_hw); 245 - if (!retval) { 246 - tty_port_set_initialized(port, 1); 247 - clear_bit(TTY_IO_ERROR, &tty->flags); 248 - } else if (retval > 0) 249 - retval = 0; 239 + if (retval) 240 + set_bit(TTY_IO_ERROR, &tty->flags); 250 241 251 242 return retval; 252 243 } ··· 963 972 } 964 973 uart_change_speed(tty, state, NULL); 965 974 } 966 - } else 975 + } else { 967 976 retval = uart_startup(tty, state, 1); 977 + if (retval > 0) 978 + retval = 0; 979 + } 968 980 exit: 969 981 return retval; 970 982 } ··· 1133 1139 uport->ops->config_port(uport, flags); 1134 1140 1135 1141 ret = uart_startup(tty, state, 1); 1142 + if (ret > 0) 1143 + ret = 0; 1136 1144 } 1137 1145 out: 1138 1146 mutex_unlock(&port->mutex); ··· 1461 1465 { 1462 1466 struct uart_state *state = tty->driver_data; 1463 1467 struct tty_port *port; 1464 - struct uart_port *uport; 1465 1468 1466 1469 if (!state) { 1467 1470 struct uart_driver *drv = tty->driver->driver_state; ··· 1476 1481 port = &state->port; 1477 1482 pr_debug("uart_close(%d) called\n", tty->index); 1478 1483 1479 - if (tty_port_close_start(port, tty, filp) == 0) 1480 - return; 1484 + tty_port_close(tty->port, tty, filp); 1485 + } 1481 1486 1482 - mutex_lock(&port->mutex); 1483 - uport = uart_port_check(state); 1487 + static void uart_tty_port_shutdown(struct tty_port *port) 1488 + { 1489 + struct uart_state *state = container_of(port, struct uart_state, port); 1490 + struct uart_port *uport = uart_port_check(state); 1484 1491 1485 1492 /* 1486 1493 * At this point, we stop accepting input. To do this, we 1487 1494 * disable the receive line status interrupts. 1488 1495 */ 1489 - if (tty_port_initialized(port) && 1490 - !WARN(!uport, "detached port still initialized!\n")) { 1491 - spin_lock_irq(&uport->lock); 1492 - uport->ops->stop_rx(uport); 1493 - spin_unlock_irq(&uport->lock); 1494 - /* 1495 - * Before we drop DTR, make sure the UART transmitter 1496 - * has completely drained; this is especially 1497 - * important if there is a transmit FIFO! 1498 - */ 1499 - uart_wait_until_sent(tty, uport->timeout); 1500 - } 1496 + if (WARN(!uport, "detached port still initialized!\n")) 1497 + return; 1501 1498 1502 - uart_shutdown(tty, state); 1503 - tty_port_tty_set(port, NULL); 1499 + spin_lock_irq(&uport->lock); 1500 + uport->ops->stop_rx(uport); 1501 + spin_unlock_irq(&uport->lock); 1504 1502 1505 - spin_lock_irq(&port->lock); 1506 - 1507 - if (port->blocked_open) { 1508 - spin_unlock_irq(&port->lock); 1509 - if (port->close_delay) 1510 - msleep_interruptible(jiffies_to_msecs(port->close_delay)); 1511 - spin_lock_irq(&port->lock); 1512 - } else if (uport && !uart_console(uport)) { 1513 - spin_unlock_irq(&port->lock); 1514 - uart_change_pm(state, UART_PM_STATE_OFF); 1515 - spin_lock_irq(&port->lock); 1516 - } 1517 - spin_unlock_irq(&port->lock); 1518 - tty_port_set_active(port, 0); 1503 + uart_port_shutdown(port); 1519 1504 1520 1505 /* 1521 - * Wake up anyone trying to open this port. 1506 + * It's possible for shutdown to be called after suspend if we get 1507 + * a DCD drop (hangup) at just the right time. Clear suspended bit so 1508 + * we don't try to resume a port that has been shutdown. 1522 1509 */ 1523 - wake_up_interruptible(&port->open_wait); 1510 + tty_port_set_suspended(port, 0); 1524 1511 1525 - mutex_unlock(&port->mutex); 1512 + uart_change_pm(state, UART_PM_STATE_OFF); 1526 1513 1527 - tty_ldisc_flush(tty); 1528 - tty->closing = 0; 1529 1514 } 1530 1515 1531 1516 static void uart_wait_until_sent(struct tty_struct *tty, int timeout) ··· 1686 1711 struct uart_driver *drv = tty->driver->driver_state; 1687 1712 int retval, line = tty->index; 1688 1713 struct uart_state *state = drv->state + line; 1689 - struct tty_port *port = &state->port; 1690 - struct uart_port *uport; 1691 - 1692 - pr_debug("uart_open(%d) called\n", line); 1693 - 1694 - spin_lock_irq(&port->lock); 1695 - ++port->count; 1696 - spin_unlock_irq(&port->lock); 1697 - 1698 - /* 1699 - * We take the semaphore here to guarantee that we won't be re-entered 1700 - * while allocating the state structure, or while we request any IRQs 1701 - * that the driver may need. This also has the nice side-effect that 1702 - * it delays the action of uart_hangup, so we can guarantee that 1703 - * state->port.tty will always contain something reasonable. 1704 - */ 1705 - if (mutex_lock_interruptible(&port->mutex)) { 1706 - retval = -ERESTARTSYS; 1707 - goto end; 1708 - } 1709 - 1710 - uport = uart_port_check(state); 1711 - if (!uport || uport->flags & UPF_DEAD) { 1712 - retval = -ENXIO; 1713 - goto err_unlock; 1714 - } 1715 1714 1716 1715 tty->driver_data = state; 1717 - uport->state = state; 1716 + 1717 + retval = tty_port_open(&state->port, tty, filp); 1718 + if (retval > 0) 1719 + retval = 0; 1720 + 1721 + return retval; 1722 + } 1723 + 1724 + static int uart_port_activate(struct tty_port *port, struct tty_struct *tty) 1725 + { 1726 + struct uart_state *state = container_of(port, struct uart_state, port); 1727 + struct uart_port *uport; 1728 + 1729 + uport = uart_port_check(state); 1730 + if (!uport || uport->flags & UPF_DEAD) 1731 + return -ENXIO; 1732 + 1718 1733 port->low_latency = (uport->flags & UPF_LOW_LATENCY) ? 1 : 0; 1719 - tty_port_tty_set(port, tty); 1720 1734 1721 1735 /* 1722 1736 * Start up the serial port. 1723 1737 */ 1724 - retval = uart_startup(tty, state, 0); 1725 - 1726 - /* 1727 - * If we succeeded, wait until the port is ready. 1728 - */ 1729 - err_unlock: 1730 - mutex_unlock(&port->mutex); 1731 - if (retval == 0) 1732 - retval = tty_port_block_til_ready(port, tty, filp); 1733 - end: 1734 - return retval; 1738 + return uart_startup(tty, state, 0); 1735 1739 } 1736 1740 1737 1741 static const char *uart_type(struct uart_port *port) ··· 1894 1940 * 1895 1941 * Returns 0 on success or -EINVAL on failure 1896 1942 */ 1897 - int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr, 1943 + int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr, 1898 1944 char **options) 1899 1945 { 1900 1946 if (strncmp(p, "mmio,", 5) == 0) { ··· 1922 1968 return -EINVAL; 1923 1969 } 1924 1970 1925 - *addr = simple_strtoul(p, NULL, 0); 1971 + /* 1972 + * Before you replace it with kstrtoull(), think about options separator 1973 + * (',') it will not tolerate 1974 + */ 1975 + *addr = simple_strtoull(p, NULL, 0); 1926 1976 p = strchr(p, ','); 1927 1977 if (p) 1928 1978 p++; ··· 2428 2470 static const struct tty_port_operations uart_port_ops = { 2429 2471 .carrier_raised = uart_carrier_raised, 2430 2472 .dtr_rts = uart_dtr_rts, 2473 + .activate = uart_port_activate, 2474 + .shutdown = uart_tty_port_shutdown, 2431 2475 }; 2432 2476 2433 2477 /** ··· 2745 2785 state->pm_state = UART_PM_STATE_UNDEFINED; 2746 2786 uport->cons = drv->cons; 2747 2787 uport->minor = drv->tty_driver->minor_start + uport->line; 2788 + 2789 + port->console = uart_console(uport); 2748 2790 2749 2791 /* 2750 2792 * If this port is a console, then the spinlock is already
+1 -1
drivers/tty/serial/sh-sci.c
··· 2533 2533 return 0; 2534 2534 } 2535 2535 2536 - static struct uart_ops sci_uart_ops = { 2536 + static const struct uart_ops sci_uart_ops = { 2537 2537 .tx_empty = sci_tx_empty, 2538 2538 .set_mctrl = sci_set_mctrl, 2539 2539 .get_mctrl = sci_get_mctrl,
+1 -1
drivers/tty/serial/st-asc.c
··· 639 639 640 640 /*---------------------------------------------------------------------*/ 641 641 642 - static struct uart_ops asc_uart_ops = { 642 + static const struct uart_ops asc_uart_ops = { 643 643 .tx_empty = asc_tx_empty, 644 644 .set_mctrl = asc_set_mctrl, 645 645 .get_mctrl = asc_get_mctrl,
+463 -152
drivers/tty/serial/stm32-usart.c
··· 1 1 /* 2 2 * Copyright (C) Maxime Coquelin 2015 3 - * Author: Maxime Coquelin <mcoquelin.stm32@gmail.com> 3 + * Authors: Maxime Coquelin <mcoquelin.stm32@gmail.com> 4 + * Gerald Baeza <gerald.baeza@st.com> 4 5 * License terms: GNU General Public License (GPL), version 2 5 6 * 6 7 * Inspired by st-asc.c from STMicroelectronics (c) ··· 11 10 #define SUPPORT_SYSRQ 12 11 #endif 13 12 14 - #include <linux/module.h> 15 - #include <linux/serial.h> 13 + #include <linux/clk.h> 16 14 #include <linux/console.h> 17 - #include <linux/sysrq.h> 18 - #include <linux/platform_device.h> 19 - #include <linux/io.h> 20 - #include <linux/irq.h> 21 - #include <linux/tty.h> 22 - #include <linux/tty_flip.h> 23 15 #include <linux/delay.h> 24 - #include <linux/spinlock.h> 25 - #include <linux/pm_runtime.h> 16 + #include <linux/dma-direction.h> 17 + #include <linux/dmaengine.h> 18 + #include <linux/dma-mapping.h> 19 + #include <linux/io.h> 20 + #include <linux/iopoll.h> 21 + #include <linux/irq.h> 22 + #include <linux/module.h> 26 23 #include <linux/of.h> 27 24 #include <linux/of_platform.h> 25 + #include <linux/platform_device.h> 26 + #include <linux/pm_runtime.h> 28 27 #include <linux/serial_core.h> 29 - #include <linux/clk.h> 28 + #include <linux/serial.h> 29 + #include <linux/spinlock.h> 30 + #include <linux/sysrq.h> 31 + #include <linux/tty_flip.h> 32 + #include <linux/tty.h> 30 33 31 - #define DRIVER_NAME "stm32-usart" 32 - 33 - /* Register offsets */ 34 - #define USART_SR 0x00 35 - #define USART_DR 0x04 36 - #define USART_BRR 0x08 37 - #define USART_CR1 0x0c 38 - #define USART_CR2 0x10 39 - #define USART_CR3 0x14 40 - #define USART_GTPR 0x18 41 - 42 - /* USART_SR */ 43 - #define USART_SR_PE BIT(0) 44 - #define USART_SR_FE BIT(1) 45 - #define USART_SR_NF BIT(2) 46 - #define USART_SR_ORE BIT(3) 47 - #define USART_SR_IDLE BIT(4) 48 - #define USART_SR_RXNE BIT(5) 49 - #define USART_SR_TC BIT(6) 50 - #define USART_SR_TXE BIT(7) 51 - #define USART_SR_LBD BIT(8) 52 - #define USART_SR_CTS BIT(9) 53 - #define USART_SR_ERR_MASK (USART_SR_LBD | USART_SR_ORE | \ 54 - USART_SR_FE | USART_SR_PE) 55 - /* Dummy bits */ 56 - #define USART_SR_DUMMY_RX BIT(16) 57 - 58 - /* USART_DR */ 59 - #define USART_DR_MASK GENMASK(8, 0) 60 - 61 - /* USART_BRR */ 62 - #define USART_BRR_DIV_F_MASK GENMASK(3, 0) 63 - #define USART_BRR_DIV_M_MASK GENMASK(15, 4) 64 - #define USART_BRR_DIV_M_SHIFT 4 65 - 66 - /* USART_CR1 */ 67 - #define USART_CR1_SBK BIT(0) 68 - #define USART_CR1_RWU BIT(1) 69 - #define USART_CR1_RE BIT(2) 70 - #define USART_CR1_TE BIT(3) 71 - #define USART_CR1_IDLEIE BIT(4) 72 - #define USART_CR1_RXNEIE BIT(5) 73 - #define USART_CR1_TCIE BIT(6) 74 - #define USART_CR1_TXEIE BIT(7) 75 - #define USART_CR1_PEIE BIT(8) 76 - #define USART_CR1_PS BIT(9) 77 - #define USART_CR1_PCE BIT(10) 78 - #define USART_CR1_WAKE BIT(11) 79 - #define USART_CR1_M BIT(12) 80 - #define USART_CR1_UE BIT(13) 81 - #define USART_CR1_OVER8 BIT(15) 82 - #define USART_CR1_IE_MASK GENMASK(8, 4) 83 - 84 - /* USART_CR2 */ 85 - #define USART_CR2_ADD_MASK GENMASK(3, 0) 86 - #define USART_CR2_LBDL BIT(5) 87 - #define USART_CR2_LBDIE BIT(6) 88 - #define USART_CR2_LBCL BIT(8) 89 - #define USART_CR2_CPHA BIT(9) 90 - #define USART_CR2_CPOL BIT(10) 91 - #define USART_CR2_CLKEN BIT(11) 92 - #define USART_CR2_STOP_2B BIT(13) 93 - #define USART_CR2_STOP_MASK GENMASK(13, 12) 94 - #define USART_CR2_LINEN BIT(14) 95 - 96 - /* USART_CR3 */ 97 - #define USART_CR3_EIE BIT(0) 98 - #define USART_CR3_IREN BIT(1) 99 - #define USART_CR3_IRLP BIT(2) 100 - #define USART_CR3_HDSEL BIT(3) 101 - #define USART_CR3_NACK BIT(4) 102 - #define USART_CR3_SCEN BIT(5) 103 - #define USART_CR3_DMAR BIT(6) 104 - #define USART_CR3_DMAT BIT(7) 105 - #define USART_CR3_RTSE BIT(8) 106 - #define USART_CR3_CTSE BIT(9) 107 - #define USART_CR3_CTSIE BIT(10) 108 - #define USART_CR3_ONEBIT BIT(11) 109 - 110 - /* USART_GTPR */ 111 - #define USART_GTPR_PSC_MASK GENMASK(7, 0) 112 - #define USART_GTPR_GT_MASK GENMASK(15, 8) 113 - 114 - #define DRIVER_NAME "stm32-usart" 115 - #define STM32_SERIAL_NAME "ttyS" 116 - #define STM32_MAX_PORTS 6 117 - 118 - struct stm32_port { 119 - struct uart_port port; 120 - struct clk *clk; 121 - bool hw_flow_control; 122 - }; 123 - 124 - static struct stm32_port stm32_ports[STM32_MAX_PORTS]; 125 - static struct uart_driver stm32_usart_driver; 34 + #include "stm32-usart.h" 126 35 127 36 static void stm32_stop_tx(struct uart_port *port); 37 + static void stm32_transmit_chars(struct uart_port *port); 128 38 129 39 static inline struct stm32_port *to_stm32_port(struct uart_port *port) 130 40 { ··· 60 148 writel_relaxed(val, port->membase + reg); 61 149 } 62 150 63 - static void stm32_receive_chars(struct uart_port *port) 151 + static int stm32_pending_rx(struct uart_port *port, u32 *sr, int *last_res, 152 + bool threaded) 153 + { 154 + struct stm32_port *stm32_port = to_stm32_port(port); 155 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 156 + enum dma_status status; 157 + struct dma_tx_state state; 158 + 159 + *sr = readl_relaxed(port->membase + ofs->isr); 160 + 161 + if (threaded && stm32_port->rx_ch) { 162 + status = dmaengine_tx_status(stm32_port->rx_ch, 163 + stm32_port->rx_ch->cookie, 164 + &state); 165 + if ((status == DMA_IN_PROGRESS) && 166 + (*last_res != state.residue)) 167 + return 1; 168 + else 169 + return 0; 170 + } else if (*sr & USART_SR_RXNE) { 171 + return 1; 172 + } 173 + return 0; 174 + } 175 + 176 + static unsigned long 177 + stm32_get_char(struct uart_port *port, u32 *sr, int *last_res) 178 + { 179 + struct stm32_port *stm32_port = to_stm32_port(port); 180 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 181 + unsigned long c; 182 + 183 + if (stm32_port->rx_ch) { 184 + c = stm32_port->rx_buf[RX_BUF_L - (*last_res)--]; 185 + if ((*last_res) == 0) 186 + *last_res = RX_BUF_L; 187 + return c; 188 + } else { 189 + return readl_relaxed(port->membase + ofs->rdr); 190 + } 191 + } 192 + 193 + static void stm32_receive_chars(struct uart_port *port, bool threaded) 64 194 { 65 195 struct tty_port *tport = &port->state->port; 196 + struct stm32_port *stm32_port = to_stm32_port(port); 197 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 66 198 unsigned long c; 67 199 u32 sr; 68 200 char flag; 201 + static int last_res = RX_BUF_L; 69 202 70 203 if (port->irq_wake) 71 204 pm_wakeup_event(tport->tty->dev, 0); 72 205 73 - while ((sr = readl_relaxed(port->membase + USART_SR)) & USART_SR_RXNE) { 206 + while (stm32_pending_rx(port, &sr, &last_res, threaded)) { 74 207 sr |= USART_SR_DUMMY_RX; 75 - c = readl_relaxed(port->membase + USART_DR); 208 + c = stm32_get_char(port, &sr, &last_res); 76 209 flag = TTY_NORMAL; 77 210 port->icount.rx++; 78 211 ··· 127 170 if (uart_handle_break(port)) 128 171 continue; 129 172 } else if (sr & USART_SR_ORE) { 173 + if (ofs->icr != UNDEF_REG) 174 + writel_relaxed(USART_ICR_ORECF, 175 + port->membase + 176 + ofs->icr); 130 177 port->icount.overrun++; 131 178 } else if (sr & USART_SR_PE) { 132 179 port->icount.parity++; ··· 158 197 spin_lock(&port->lock); 159 198 } 160 199 200 + static void stm32_tx_dma_complete(void *arg) 201 + { 202 + struct uart_port *port = arg; 203 + struct stm32_port *stm32port = to_stm32_port(port); 204 + struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 205 + unsigned int isr; 206 + int ret; 207 + 208 + ret = readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, 209 + isr, 210 + (isr & USART_SR_TC), 211 + 10, 100000); 212 + 213 + if (ret) 214 + dev_err(port->dev, "terminal count not set\n"); 215 + 216 + if (ofs->icr == UNDEF_REG) 217 + stm32_clr_bits(port, ofs->isr, USART_SR_TC); 218 + else 219 + stm32_set_bits(port, ofs->icr, USART_CR_TC); 220 + 221 + stm32_clr_bits(port, ofs->cr3, USART_CR3_DMAT); 222 + stm32port->tx_dma_busy = false; 223 + 224 + /* Let's see if we have pending data to send */ 225 + stm32_transmit_chars(port); 226 + } 227 + 228 + static void stm32_transmit_chars_pio(struct uart_port *port) 229 + { 230 + struct stm32_port *stm32_port = to_stm32_port(port); 231 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 232 + struct circ_buf *xmit = &port->state->xmit; 233 + unsigned int isr; 234 + int ret; 235 + 236 + if (stm32_port->tx_dma_busy) { 237 + stm32_clr_bits(port, ofs->cr3, USART_CR3_DMAT); 238 + stm32_port->tx_dma_busy = false; 239 + } 240 + 241 + ret = readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, 242 + isr, 243 + (isr & USART_SR_TXE), 244 + 10, 100); 245 + 246 + if (ret) 247 + dev_err(port->dev, "tx empty not set\n"); 248 + 249 + stm32_set_bits(port, ofs->cr1, USART_CR1_TXEIE); 250 + 251 + writel_relaxed(xmit->buf[xmit->tail], port->membase + ofs->tdr); 252 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 253 + port->icount.tx++; 254 + } 255 + 256 + static void stm32_transmit_chars_dma(struct uart_port *port) 257 + { 258 + struct stm32_port *stm32port = to_stm32_port(port); 259 + struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 260 + struct circ_buf *xmit = &port->state->xmit; 261 + struct dma_async_tx_descriptor *desc = NULL; 262 + dma_cookie_t cookie; 263 + unsigned int count, i; 264 + 265 + if (stm32port->tx_dma_busy) 266 + return; 267 + 268 + stm32port->tx_dma_busy = true; 269 + 270 + count = uart_circ_chars_pending(xmit); 271 + 272 + if (count > TX_BUF_L) 273 + count = TX_BUF_L; 274 + 275 + if (xmit->tail < xmit->head) { 276 + memcpy(&stm32port->tx_buf[0], &xmit->buf[xmit->tail], count); 277 + } else { 278 + size_t one = UART_XMIT_SIZE - xmit->tail; 279 + size_t two; 280 + 281 + if (one > count) 282 + one = count; 283 + two = count - one; 284 + 285 + memcpy(&stm32port->tx_buf[0], &xmit->buf[xmit->tail], one); 286 + if (two) 287 + memcpy(&stm32port->tx_buf[one], &xmit->buf[0], two); 288 + } 289 + 290 + desc = dmaengine_prep_slave_single(stm32port->tx_ch, 291 + stm32port->tx_dma_buf, 292 + count, 293 + DMA_MEM_TO_DEV, 294 + DMA_PREP_INTERRUPT); 295 + 296 + if (!desc) { 297 + for (i = count; i > 0; i--) 298 + stm32_transmit_chars_pio(port); 299 + return; 300 + } 301 + 302 + desc->callback = stm32_tx_dma_complete; 303 + desc->callback_param = port; 304 + 305 + /* Push current DMA TX transaction in the pending queue */ 306 + cookie = dmaengine_submit(desc); 307 + 308 + /* Issue pending DMA TX requests */ 309 + dma_async_issue_pending(stm32port->tx_ch); 310 + 311 + stm32_clr_bits(port, ofs->isr, USART_SR_TC); 312 + stm32_set_bits(port, ofs->cr3, USART_CR3_DMAT); 313 + 314 + xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); 315 + port->icount.tx += count; 316 + } 317 + 161 318 static void stm32_transmit_chars(struct uart_port *port) 162 319 { 320 + struct stm32_port *stm32_port = to_stm32_port(port); 321 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 163 322 struct circ_buf *xmit = &port->state->xmit; 164 323 165 324 if (port->x_char) { 166 - writel_relaxed(port->x_char, port->membase + USART_DR); 325 + if (stm32_port->tx_dma_busy) 326 + stm32_clr_bits(port, ofs->cr3, USART_CR3_DMAT); 327 + writel_relaxed(port->x_char, port->membase + ofs->tdr); 167 328 port->x_char = 0; 168 329 port->icount.tx++; 330 + if (stm32_port->tx_dma_busy) 331 + stm32_set_bits(port, ofs->cr3, USART_CR3_DMAT); 169 332 return; 170 333 } 171 334 ··· 303 218 return; 304 219 } 305 220 306 - writel_relaxed(xmit->buf[xmit->tail], port->membase + USART_DR); 307 - xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 308 - port->icount.tx++; 221 + if (stm32_port->tx_ch) 222 + stm32_transmit_chars_dma(port); 223 + else 224 + stm32_transmit_chars_pio(port); 309 225 310 226 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 311 227 uart_write_wakeup(port); ··· 318 232 static irqreturn_t stm32_interrupt(int irq, void *ptr) 319 233 { 320 234 struct uart_port *port = ptr; 235 + struct stm32_port *stm32_port = to_stm32_port(port); 236 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 321 237 u32 sr; 322 238 323 239 spin_lock(&port->lock); 324 240 325 - sr = readl_relaxed(port->membase + USART_SR); 241 + sr = readl_relaxed(port->membase + ofs->isr); 326 242 327 - if (sr & USART_SR_RXNE) 328 - stm32_receive_chars(port); 243 + if ((sr & USART_SR_RXNE) && !(stm32_port->rx_ch)) 244 + stm32_receive_chars(port, false); 329 245 330 - if (sr & USART_SR_TXE) 246 + if ((sr & USART_SR_TXE) && !(stm32_port->tx_ch)) 331 247 stm32_transmit_chars(port); 248 + 249 + spin_unlock(&port->lock); 250 + 251 + if (stm32_port->rx_ch) 252 + return IRQ_WAKE_THREAD; 253 + else 254 + return IRQ_HANDLED; 255 + } 256 + 257 + static irqreturn_t stm32_threaded_interrupt(int irq, void *ptr) 258 + { 259 + struct uart_port *port = ptr; 260 + struct stm32_port *stm32_port = to_stm32_port(port); 261 + 262 + spin_lock(&port->lock); 263 + 264 + if (stm32_port->rx_ch) 265 + stm32_receive_chars(port, true); 332 266 333 267 spin_unlock(&port->lock); 334 268 ··· 357 251 358 252 static unsigned int stm32_tx_empty(struct uart_port *port) 359 253 { 360 - return readl_relaxed(port->membase + USART_SR) & USART_SR_TXE; 254 + struct stm32_port *stm32_port = to_stm32_port(port); 255 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 256 + 257 + return readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE; 361 258 } 362 259 363 260 static void stm32_set_mctrl(struct uart_port *port, unsigned int mctrl) 364 261 { 262 + struct stm32_port *stm32_port = to_stm32_port(port); 263 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 264 + 365 265 if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS)) 366 - stm32_set_bits(port, USART_CR3, USART_CR3_RTSE); 266 + stm32_set_bits(port, ofs->cr3, USART_CR3_RTSE); 367 267 else 368 - stm32_clr_bits(port, USART_CR3, USART_CR3_RTSE); 268 + stm32_clr_bits(port, ofs->cr3, USART_CR3_RTSE); 369 269 } 370 270 371 271 static unsigned int stm32_get_mctrl(struct uart_port *port) ··· 383 271 /* Transmit stop */ 384 272 static void stm32_stop_tx(struct uart_port *port) 385 273 { 386 - stm32_clr_bits(port, USART_CR1, USART_CR1_TXEIE); 274 + struct stm32_port *stm32_port = to_stm32_port(port); 275 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 276 + 277 + stm32_clr_bits(port, ofs->cr1, USART_CR1_TXEIE); 387 278 } 388 279 389 280 /* There are probably characters waiting to be transmitted. */ ··· 397 282 if (uart_circ_empty(xmit)) 398 283 return; 399 284 400 - stm32_set_bits(port, USART_CR1, USART_CR1_TXEIE | USART_CR1_TE); 285 + stm32_transmit_chars(port); 401 286 } 402 287 403 288 /* Throttle the remote when input buffer is about to overflow. */ 404 289 static void stm32_throttle(struct uart_port *port) 405 290 { 291 + struct stm32_port *stm32_port = to_stm32_port(port); 292 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 406 293 unsigned long flags; 407 294 408 295 spin_lock_irqsave(&port->lock, flags); 409 - stm32_clr_bits(port, USART_CR1, USART_CR1_RXNEIE); 296 + stm32_clr_bits(port, ofs->cr1, USART_CR1_RXNEIE); 410 297 spin_unlock_irqrestore(&port->lock, flags); 411 298 } 412 299 413 300 /* Unthrottle the remote, the input buffer can now accept data. */ 414 301 static void stm32_unthrottle(struct uart_port *port) 415 302 { 303 + struct stm32_port *stm32_port = to_stm32_port(port); 304 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 416 305 unsigned long flags; 417 306 418 307 spin_lock_irqsave(&port->lock, flags); 419 - stm32_set_bits(port, USART_CR1, USART_CR1_RXNEIE); 308 + stm32_set_bits(port, ofs->cr1, USART_CR1_RXNEIE); 420 309 spin_unlock_irqrestore(&port->lock, flags); 421 310 } 422 311 423 312 /* Receive stop */ 424 313 static void stm32_stop_rx(struct uart_port *port) 425 314 { 426 - stm32_clr_bits(port, USART_CR1, USART_CR1_RXNEIE); 315 + struct stm32_port *stm32_port = to_stm32_port(port); 316 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 317 + 318 + stm32_clr_bits(port, ofs->cr1, USART_CR1_RXNEIE); 427 319 } 428 320 429 321 /* Handle breaks - ignored by us */ ··· 440 318 441 319 static int stm32_startup(struct uart_port *port) 442 320 { 321 + struct stm32_port *stm32_port = to_stm32_port(port); 322 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 443 323 const char *name = to_platform_device(port->dev)->name; 444 324 u32 val; 445 325 int ret; 446 326 447 - ret = request_irq(port->irq, stm32_interrupt, 0, name, port); 327 + ret = request_threaded_irq(port->irq, stm32_interrupt, 328 + stm32_threaded_interrupt, 329 + IRQF_NO_SUSPEND, name, port); 448 330 if (ret) 449 331 return ret; 450 332 451 333 val = USART_CR1_RXNEIE | USART_CR1_TE | USART_CR1_RE; 452 - stm32_set_bits(port, USART_CR1, val); 334 + stm32_set_bits(port, ofs->cr1, val); 453 335 454 336 return 0; 455 337 } 456 338 457 339 static void stm32_shutdown(struct uart_port *port) 458 340 { 341 + struct stm32_port *stm32_port = to_stm32_port(port); 342 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 343 + struct stm32_usart_config *cfg = &stm32_port->info->cfg; 459 344 u32 val; 460 345 461 346 val = USART_CR1_TXEIE | USART_CR1_RXNEIE | USART_CR1_TE | USART_CR1_RE; 462 - stm32_set_bits(port, USART_CR1, val); 347 + val |= BIT(cfg->uart_enable_bit); 348 + stm32_clr_bits(port, ofs->cr1, val); 463 349 464 350 free_irq(port->irq, port); 465 351 } ··· 476 346 struct ktermios *old) 477 347 { 478 348 struct stm32_port *stm32_port = to_stm32_port(port); 349 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 350 + struct stm32_usart_config *cfg = &stm32_port->info->cfg; 479 351 unsigned int baud; 480 352 u32 usartdiv, mantissa, fraction, oversampling; 481 353 tcflag_t cflag = termios->c_cflag; ··· 492 360 spin_lock_irqsave(&port->lock, flags); 493 361 494 362 /* Stop serial port and reset value */ 495 - writel_relaxed(0, port->membase + USART_CR1); 363 + writel_relaxed(0, port->membase + ofs->cr1); 496 364 497 - cr1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE | USART_CR1_RXNEIE; 365 + cr1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE; 366 + cr1 |= BIT(cfg->uart_enable_bit); 498 367 cr2 = 0; 499 368 cr3 = 0; 500 369 ··· 504 371 505 372 if (cflag & PARENB) { 506 373 cr1 |= USART_CR1_PCE; 507 - if ((cflag & CSIZE) == CS8) 508 - cr1 |= USART_CR1_M; 374 + if ((cflag & CSIZE) == CS8) { 375 + if (cfg->has_7bits_data) 376 + cr1 |= USART_CR1_M0; 377 + else 378 + cr1 |= USART_CR1_M; 379 + } 509 380 } 510 381 511 382 if (cflag & PARODD) ··· 531 394 */ 532 395 if (usartdiv < 16) { 533 396 oversampling = 8; 534 - stm32_set_bits(port, USART_CR1, USART_CR1_OVER8); 397 + stm32_set_bits(port, ofs->cr1, USART_CR1_OVER8); 535 398 } else { 536 399 oversampling = 16; 537 - stm32_clr_bits(port, USART_CR1, USART_CR1_OVER8); 400 + stm32_clr_bits(port, ofs->cr1, USART_CR1_OVER8); 538 401 } 539 402 540 403 mantissa = (usartdiv / oversampling) << USART_BRR_DIV_M_SHIFT; 541 404 fraction = usartdiv % oversampling; 542 - writel_relaxed(mantissa | fraction, port->membase + USART_BRR); 405 + writel_relaxed(mantissa | fraction, port->membase + ofs->brr); 543 406 544 407 uart_update_timeout(port, cflag, baud); 545 408 ··· 567 430 if ((termios->c_cflag & CREAD) == 0) 568 431 port->ignore_status_mask |= USART_SR_DUMMY_RX; 569 432 570 - writel_relaxed(cr3, port->membase + USART_CR3); 571 - writel_relaxed(cr2, port->membase + USART_CR2); 572 - writel_relaxed(cr1, port->membase + USART_CR1); 433 + if (stm32_port->rx_ch) 434 + cr3 |= USART_CR3_DMAR; 435 + 436 + writel_relaxed(cr3, port->membase + ofs->cr3); 437 + writel_relaxed(cr2, port->membase + ofs->cr2); 438 + writel_relaxed(cr1, port->membase + ofs->cr1); 573 439 574 440 spin_unlock_irqrestore(&port->lock, flags); 575 441 } ··· 609 469 { 610 470 struct stm32_port *stm32port = container_of(port, 611 471 struct stm32_port, port); 472 + struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 473 + struct stm32_usart_config *cfg = &stm32port->info->cfg; 612 474 unsigned long flags = 0; 613 475 614 476 switch (state) { ··· 619 477 break; 620 478 case UART_PM_STATE_OFF: 621 479 spin_lock_irqsave(&port->lock, flags); 622 - stm32_clr_bits(port, USART_CR1, USART_CR1_UE); 480 + stm32_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); 623 481 spin_unlock_irqrestore(&port->lock, flags); 624 482 clk_disable_unprepare(stm32port->clk); 625 483 break; ··· 681 539 if (!stm32port->port.uartclk) 682 540 ret = -EINVAL; 683 541 684 - clk_disable_unprepare(stm32port->clk); 685 - 686 542 return ret; 687 543 } 688 544 ··· 700 560 return NULL; 701 561 702 562 stm32_ports[id].hw_flow_control = of_property_read_bool(np, 703 - "auto-flow-control"); 563 + "st,hw-flow-ctrl"); 704 564 stm32_ports[id].port.line = id; 705 565 return &stm32_ports[id]; 706 566 } 707 567 708 568 #ifdef CONFIG_OF 709 569 static const struct of_device_id stm32_match[] = { 710 - { .compatible = "st,stm32-usart", }, 711 - { .compatible = "st,stm32-uart", }, 570 + { .compatible = "st,stm32-usart", .data = &stm32f4_info}, 571 + { .compatible = "st,stm32-uart", .data = &stm32f4_info}, 572 + { .compatible = "st,stm32f7-usart", .data = &stm32f7_info}, 573 + { .compatible = "st,stm32f7-uart", .data = &stm32f7_info}, 712 574 {}, 713 575 }; 714 576 715 577 MODULE_DEVICE_TABLE(of, stm32_match); 716 578 #endif 717 579 580 + static int stm32_of_dma_rx_probe(struct stm32_port *stm32port, 581 + struct platform_device *pdev) 582 + { 583 + struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 584 + struct uart_port *port = &stm32port->port; 585 + struct device *dev = &pdev->dev; 586 + struct dma_slave_config config; 587 + struct dma_async_tx_descriptor *desc = NULL; 588 + dma_cookie_t cookie; 589 + int ret; 590 + 591 + /* Request DMA RX channel */ 592 + stm32port->rx_ch = dma_request_slave_channel(dev, "rx"); 593 + if (!stm32port->rx_ch) { 594 + dev_info(dev, "rx dma alloc failed\n"); 595 + return -ENODEV; 596 + } 597 + stm32port->rx_buf = dma_alloc_coherent(&pdev->dev, RX_BUF_L, 598 + &stm32port->rx_dma_buf, 599 + GFP_KERNEL); 600 + if (!stm32port->rx_buf) { 601 + ret = -ENOMEM; 602 + goto alloc_err; 603 + } 604 + 605 + /* Configure DMA channel */ 606 + memset(&config, 0, sizeof(config)); 607 + config.src_addr = port->mapbase + ofs->rdr; 608 + config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 609 + 610 + ret = dmaengine_slave_config(stm32port->rx_ch, &config); 611 + if (ret < 0) { 612 + dev_err(dev, "rx dma channel config failed\n"); 613 + ret = -ENODEV; 614 + goto config_err; 615 + } 616 + 617 + /* Prepare a DMA cyclic transaction */ 618 + desc = dmaengine_prep_dma_cyclic(stm32port->rx_ch, 619 + stm32port->rx_dma_buf, 620 + RX_BUF_L, RX_BUF_P, DMA_DEV_TO_MEM, 621 + DMA_PREP_INTERRUPT); 622 + if (!desc) { 623 + dev_err(dev, "rx dma prep cyclic failed\n"); 624 + ret = -ENODEV; 625 + goto config_err; 626 + } 627 + 628 + /* No callback as dma buffer is drained on usart interrupt */ 629 + desc->callback = NULL; 630 + desc->callback_param = NULL; 631 + 632 + /* Push current DMA transaction in the pending queue */ 633 + cookie = dmaengine_submit(desc); 634 + 635 + /* Issue pending DMA requests */ 636 + dma_async_issue_pending(stm32port->rx_ch); 637 + 638 + return 0; 639 + 640 + config_err: 641 + dma_free_coherent(&pdev->dev, 642 + RX_BUF_L, stm32port->rx_buf, 643 + stm32port->rx_dma_buf); 644 + 645 + alloc_err: 646 + dma_release_channel(stm32port->rx_ch); 647 + stm32port->rx_ch = NULL; 648 + 649 + return ret; 650 + } 651 + 652 + static int stm32_of_dma_tx_probe(struct stm32_port *stm32port, 653 + struct platform_device *pdev) 654 + { 655 + struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 656 + struct uart_port *port = &stm32port->port; 657 + struct device *dev = &pdev->dev; 658 + struct dma_slave_config config; 659 + int ret; 660 + 661 + stm32port->tx_dma_busy = false; 662 + 663 + /* Request DMA TX channel */ 664 + stm32port->tx_ch = dma_request_slave_channel(dev, "tx"); 665 + if (!stm32port->tx_ch) { 666 + dev_info(dev, "tx dma alloc failed\n"); 667 + return -ENODEV; 668 + } 669 + stm32port->tx_buf = dma_alloc_coherent(&pdev->dev, TX_BUF_L, 670 + &stm32port->tx_dma_buf, 671 + GFP_KERNEL); 672 + if (!stm32port->tx_buf) { 673 + ret = -ENOMEM; 674 + goto alloc_err; 675 + } 676 + 677 + /* Configure DMA channel */ 678 + memset(&config, 0, sizeof(config)); 679 + config.dst_addr = port->mapbase + ofs->tdr; 680 + config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 681 + 682 + ret = dmaengine_slave_config(stm32port->tx_ch, &config); 683 + if (ret < 0) { 684 + dev_err(dev, "tx dma channel config failed\n"); 685 + ret = -ENODEV; 686 + goto config_err; 687 + } 688 + 689 + return 0; 690 + 691 + config_err: 692 + dma_free_coherent(&pdev->dev, 693 + TX_BUF_L, stm32port->tx_buf, 694 + stm32port->tx_dma_buf); 695 + 696 + alloc_err: 697 + dma_release_channel(stm32port->tx_ch); 698 + stm32port->tx_ch = NULL; 699 + 700 + return ret; 701 + } 702 + 718 703 static int stm32_serial_probe(struct platform_device *pdev) 719 704 { 720 - int ret; 705 + const struct of_device_id *match; 721 706 struct stm32_port *stm32port; 707 + int ret; 722 708 723 709 stm32port = stm32_of_get_stm32_port(pdev); 724 710 if (!stm32port) 725 711 return -ENODEV; 712 + 713 + match = of_match_device(stm32_match, &pdev->dev); 714 + if (match && match->data) 715 + stm32port->info = (struct stm32_usart_info *)match->data; 716 + else 717 + return -EINVAL; 726 718 727 719 ret = stm32_init_port(stm32port, pdev); 728 720 if (ret) ··· 864 592 if (ret) 865 593 return ret; 866 594 595 + ret = stm32_of_dma_rx_probe(stm32port, pdev); 596 + if (ret) 597 + dev_info(&pdev->dev, "interrupt mode used for rx (no dma)\n"); 598 + 599 + ret = stm32_of_dma_tx_probe(stm32port, pdev); 600 + if (ret) 601 + dev_info(&pdev->dev, "interrupt mode used for tx (no dma)\n"); 602 + 867 603 platform_set_drvdata(pdev, &stm32port->port); 868 604 869 605 return 0; ··· 880 600 static int stm32_serial_remove(struct platform_device *pdev) 881 601 { 882 602 struct uart_port *port = platform_get_drvdata(pdev); 603 + struct stm32_port *stm32_port = to_stm32_port(port); 604 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 605 + 606 + stm32_clr_bits(port, ofs->cr3, USART_CR3_DMAR); 607 + 608 + if (stm32_port->rx_ch) 609 + dma_release_channel(stm32_port->rx_ch); 610 + 611 + if (stm32_port->rx_dma_buf) 612 + dma_free_coherent(&pdev->dev, 613 + RX_BUF_L, stm32_port->rx_buf, 614 + stm32_port->rx_dma_buf); 615 + 616 + stm32_clr_bits(port, ofs->cr3, USART_CR3_DMAT); 617 + 618 + if (stm32_port->tx_ch) 619 + dma_release_channel(stm32_port->tx_ch); 620 + 621 + if (stm32_port->tx_dma_buf) 622 + dma_free_coherent(&pdev->dev, 623 + TX_BUF_L, stm32_port->tx_buf, 624 + stm32_port->tx_dma_buf); 625 + 626 + clk_disable_unprepare(stm32_port->clk); 883 627 884 628 return uart_remove_one_port(&stm32_usart_driver, port); 885 629 } ··· 912 608 #ifdef CONFIG_SERIAL_STM32_CONSOLE 913 609 static void stm32_console_putchar(struct uart_port *port, int ch) 914 610 { 915 - while (!(readl_relaxed(port->membase + USART_SR) & USART_SR_TXE)) 611 + struct stm32_port *stm32_port = to_stm32_port(port); 612 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 613 + 614 + while (!(readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE)) 916 615 cpu_relax(); 917 616 918 - writel_relaxed(ch, port->membase + USART_DR); 617 + writel_relaxed(ch, port->membase + ofs->tdr); 919 618 } 920 619 921 620 static void stm32_console_write(struct console *co, const char *s, unsigned cnt) 922 621 { 923 622 struct uart_port *port = &stm32_ports[co->index].port; 623 + struct stm32_port *stm32_port = to_stm32_port(port); 624 + struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 625 + struct stm32_usart_config *cfg = &stm32_port->info->cfg; 924 626 unsigned long flags; 925 627 u32 old_cr1, new_cr1; 926 628 int locked = 1; ··· 939 629 else 940 630 spin_lock(&port->lock); 941 631 942 - /* Save and disable interrupts */ 943 - old_cr1 = readl_relaxed(port->membase + USART_CR1); 632 + /* Save and disable interrupts, enable the transmitter */ 633 + old_cr1 = readl_relaxed(port->membase + ofs->cr1); 944 634 new_cr1 = old_cr1 & ~USART_CR1_IE_MASK; 945 - writel_relaxed(new_cr1, port->membase + USART_CR1); 635 + new_cr1 |= USART_CR1_TE | BIT(cfg->uart_enable_bit); 636 + writel_relaxed(new_cr1, port->membase + ofs->cr1); 946 637 947 638 uart_console_write(port, s, cnt, stm32_console_putchar); 948 639 949 640 /* Restore interrupt state */ 950 - writel_relaxed(old_cr1, port->membase + USART_CR1); 641 + writel_relaxed(old_cr1, port->membase + ofs->cr1); 951 642 952 643 if (locked) 953 644 spin_unlock(&port->lock);
+229
drivers/tty/serial/stm32-usart.h
··· 1 + /* 2 + * Copyright (C) Maxime Coquelin 2015 3 + * Authors: Maxime Coquelin <mcoquelin.stm32@gmail.com> 4 + * Gerald Baeza <gerald_baeza@yahoo.fr> 5 + * License terms: GNU General Public License (GPL), version 2 6 + */ 7 + 8 + #define DRIVER_NAME "stm32-usart" 9 + 10 + struct stm32_usart_offsets { 11 + u8 cr1; 12 + u8 cr2; 13 + u8 cr3; 14 + u8 brr; 15 + u8 gtpr; 16 + u8 rtor; 17 + u8 rqr; 18 + u8 isr; 19 + u8 icr; 20 + u8 rdr; 21 + u8 tdr; 22 + }; 23 + 24 + struct stm32_usart_config { 25 + u8 uart_enable_bit; /* USART_CR1_UE */ 26 + bool has_7bits_data; 27 + }; 28 + 29 + struct stm32_usart_info { 30 + struct stm32_usart_offsets ofs; 31 + struct stm32_usart_config cfg; 32 + }; 33 + 34 + #define UNDEF_REG ~0 35 + 36 + /* Register offsets */ 37 + struct stm32_usart_info stm32f4_info = { 38 + .ofs = { 39 + .isr = 0x00, 40 + .rdr = 0x04, 41 + .tdr = 0x04, 42 + .brr = 0x08, 43 + .cr1 = 0x0c, 44 + .cr2 = 0x10, 45 + .cr3 = 0x14, 46 + .gtpr = 0x18, 47 + .rtor = UNDEF_REG, 48 + .rqr = UNDEF_REG, 49 + .icr = UNDEF_REG, 50 + }, 51 + .cfg = { 52 + .uart_enable_bit = 13, 53 + .has_7bits_data = false, 54 + } 55 + }; 56 + 57 + struct stm32_usart_info stm32f7_info = { 58 + .ofs = { 59 + .cr1 = 0x00, 60 + .cr2 = 0x04, 61 + .cr3 = 0x08, 62 + .brr = 0x0c, 63 + .gtpr = 0x10, 64 + .rtor = 0x14, 65 + .rqr = 0x18, 66 + .isr = 0x1c, 67 + .icr = 0x20, 68 + .rdr = 0x24, 69 + .tdr = 0x28, 70 + }, 71 + .cfg = { 72 + .uart_enable_bit = 0, 73 + .has_7bits_data = true, 74 + } 75 + }; 76 + 77 + /* USART_SR (F4) / USART_ISR (F7) */ 78 + #define USART_SR_PE BIT(0) 79 + #define USART_SR_FE BIT(1) 80 + #define USART_SR_NF BIT(2) 81 + #define USART_SR_ORE BIT(3) 82 + #define USART_SR_IDLE BIT(4) 83 + #define USART_SR_RXNE BIT(5) 84 + #define USART_SR_TC BIT(6) 85 + #define USART_SR_TXE BIT(7) 86 + #define USART_SR_LBD BIT(8) 87 + #define USART_SR_CTSIF BIT(9) 88 + #define USART_SR_CTS BIT(10) /* F7 */ 89 + #define USART_SR_RTOF BIT(11) /* F7 */ 90 + #define USART_SR_EOBF BIT(12) /* F7 */ 91 + #define USART_SR_ABRE BIT(14) /* F7 */ 92 + #define USART_SR_ABRF BIT(15) /* F7 */ 93 + #define USART_SR_BUSY BIT(16) /* F7 */ 94 + #define USART_SR_CMF BIT(17) /* F7 */ 95 + #define USART_SR_SBKF BIT(18) /* F7 */ 96 + #define USART_SR_TEACK BIT(21) /* F7 */ 97 + #define USART_SR_ERR_MASK (USART_SR_LBD | USART_SR_ORE | \ 98 + USART_SR_FE | USART_SR_PE) 99 + /* Dummy bits */ 100 + #define USART_SR_DUMMY_RX BIT(16) 101 + 102 + /* USART_ICR (F7) */ 103 + #define USART_CR_TC BIT(6) 104 + 105 + /* USART_DR */ 106 + #define USART_DR_MASK GENMASK(8, 0) 107 + 108 + /* USART_BRR */ 109 + #define USART_BRR_DIV_F_MASK GENMASK(3, 0) 110 + #define USART_BRR_DIV_M_MASK GENMASK(15, 4) 111 + #define USART_BRR_DIV_M_SHIFT 4 112 + 113 + /* USART_CR1 */ 114 + #define USART_CR1_SBK BIT(0) 115 + #define USART_CR1_RWU BIT(1) /* F4 */ 116 + #define USART_CR1_RE BIT(2) 117 + #define USART_CR1_TE BIT(3) 118 + #define USART_CR1_IDLEIE BIT(4) 119 + #define USART_CR1_RXNEIE BIT(5) 120 + #define USART_CR1_TCIE BIT(6) 121 + #define USART_CR1_TXEIE BIT(7) 122 + #define USART_CR1_PEIE BIT(8) 123 + #define USART_CR1_PS BIT(9) 124 + #define USART_CR1_PCE BIT(10) 125 + #define USART_CR1_WAKE BIT(11) 126 + #define USART_CR1_M BIT(12) 127 + #define USART_CR1_M0 BIT(12) /* F7 */ 128 + #define USART_CR1_MME BIT(13) /* F7 */ 129 + #define USART_CR1_CMIE BIT(14) /* F7 */ 130 + #define USART_CR1_OVER8 BIT(15) 131 + #define USART_CR1_DEDT_MASK GENMASK(20, 16) /* F7 */ 132 + #define USART_CR1_DEAT_MASK GENMASK(25, 21) /* F7 */ 133 + #define USART_CR1_RTOIE BIT(26) /* F7 */ 134 + #define USART_CR1_EOBIE BIT(27) /* F7 */ 135 + #define USART_CR1_M1 BIT(28) /* F7 */ 136 + #define USART_CR1_IE_MASK (GENMASK(8, 4) | BIT(14) | BIT(26) | BIT(27)) 137 + 138 + /* USART_CR2 */ 139 + #define USART_CR2_ADD_MASK GENMASK(3, 0) /* F4 */ 140 + #define USART_CR2_ADDM7 BIT(4) /* F7 */ 141 + #define USART_CR2_LBDL BIT(5) 142 + #define USART_CR2_LBDIE BIT(6) 143 + #define USART_CR2_LBCL BIT(8) 144 + #define USART_CR2_CPHA BIT(9) 145 + #define USART_CR2_CPOL BIT(10) 146 + #define USART_CR2_CLKEN BIT(11) 147 + #define USART_CR2_STOP_2B BIT(13) 148 + #define USART_CR2_STOP_MASK GENMASK(13, 12) 149 + #define USART_CR2_LINEN BIT(14) 150 + #define USART_CR2_SWAP BIT(15) /* F7 */ 151 + #define USART_CR2_RXINV BIT(16) /* F7 */ 152 + #define USART_CR2_TXINV BIT(17) /* F7 */ 153 + #define USART_CR2_DATAINV BIT(18) /* F7 */ 154 + #define USART_CR2_MSBFIRST BIT(19) /* F7 */ 155 + #define USART_CR2_ABREN BIT(20) /* F7 */ 156 + #define USART_CR2_ABRMOD_MASK GENMASK(22, 21) /* F7 */ 157 + #define USART_CR2_RTOEN BIT(23) /* F7 */ 158 + #define USART_CR2_ADD_F7_MASK GENMASK(31, 24) /* F7 */ 159 + 160 + /* USART_CR3 */ 161 + #define USART_CR3_EIE BIT(0) 162 + #define USART_CR3_IREN BIT(1) 163 + #define USART_CR3_IRLP BIT(2) 164 + #define USART_CR3_HDSEL BIT(3) 165 + #define USART_CR3_NACK BIT(4) 166 + #define USART_CR3_SCEN BIT(5) 167 + #define USART_CR3_DMAR BIT(6) 168 + #define USART_CR3_DMAT BIT(7) 169 + #define USART_CR3_RTSE BIT(8) 170 + #define USART_CR3_CTSE BIT(9) 171 + #define USART_CR3_CTSIE BIT(10) 172 + #define USART_CR3_ONEBIT BIT(11) 173 + #define USART_CR3_OVRDIS BIT(12) /* F7 */ 174 + #define USART_CR3_DDRE BIT(13) /* F7 */ 175 + #define USART_CR3_DEM BIT(14) /* F7 */ 176 + #define USART_CR3_DEP BIT(15) /* F7 */ 177 + #define USART_CR3_SCARCNT_MASK GENMASK(19, 17) /* F7 */ 178 + 179 + /* USART_GTPR */ 180 + #define USART_GTPR_PSC_MASK GENMASK(7, 0) 181 + #define USART_GTPR_GT_MASK GENMASK(15, 8) 182 + 183 + /* USART_RTOR */ 184 + #define USART_RTOR_RTO_MASK GENMASK(23, 0) /* F7 */ 185 + #define USART_RTOR_BLEN_MASK GENMASK(31, 24) /* F7 */ 186 + 187 + /* USART_RQR */ 188 + #define USART_RQR_ABRRQ BIT(0) /* F7 */ 189 + #define USART_RQR_SBKRQ BIT(1) /* F7 */ 190 + #define USART_RQR_MMRQ BIT(2) /* F7 */ 191 + #define USART_RQR_RXFRQ BIT(3) /* F7 */ 192 + #define USART_RQR_TXFRQ BIT(4) /* F7 */ 193 + 194 + /* USART_ICR */ 195 + #define USART_ICR_PECF BIT(0) /* F7 */ 196 + #define USART_ICR_FFECF BIT(1) /* F7 */ 197 + #define USART_ICR_NCF BIT(2) /* F7 */ 198 + #define USART_ICR_ORECF BIT(3) /* F7 */ 199 + #define USART_ICR_IDLECF BIT(4) /* F7 */ 200 + #define USART_ICR_TCCF BIT(6) /* F7 */ 201 + #define USART_ICR_LBDCF BIT(8) /* F7 */ 202 + #define USART_ICR_CTSCF BIT(9) /* F7 */ 203 + #define USART_ICR_RTOCF BIT(11) /* F7 */ 204 + #define USART_ICR_EOBCF BIT(12) /* F7 */ 205 + #define USART_ICR_CMCF BIT(17) /* F7 */ 206 + 207 + #define STM32_SERIAL_NAME "ttyS" 208 + #define STM32_MAX_PORTS 6 209 + 210 + #define RX_BUF_L 200 /* dma rx buffer length */ 211 + #define RX_BUF_P RX_BUF_L /* dma rx buffer period */ 212 + #define TX_BUF_L 200 /* dma tx buffer length */ 213 + 214 + struct stm32_port { 215 + struct uart_port port; 216 + struct clk *clk; 217 + struct stm32_usart_info *info; 218 + struct dma_chan *rx_ch; /* dma rx channel */ 219 + dma_addr_t rx_dma_buf; /* dma rx buffer bus address */ 220 + unsigned char *rx_buf; /* dma rx buffer cpu address */ 221 + struct dma_chan *tx_ch; /* dma tx channel */ 222 + dma_addr_t tx_dma_buf; /* dma tx buffer bus address */ 223 + unsigned char *tx_buf; /* dma tx buffer cpu address */ 224 + bool tx_dma_busy; /* dma tx busy */ 225 + bool hw_flow_control; 226 + }; 227 + 228 + static struct stm32_port stm32_ports[STM32_MAX_PORTS]; 229 + static struct uart_driver stm32_usart_driver;
+1 -1
drivers/tty/serial/timbuart.c
··· 394 394 return -EINVAL; 395 395 } 396 396 397 - static struct uart_ops timbuart_ops = { 397 + static const struct uart_ops timbuart_ops = { 398 398 .tx_empty = timbuart_tx_empty, 399 399 .set_mctrl = timbuart_set_mctrl, 400 400 .get_mctrl = timbuart_get_mctrl,
+1 -1
drivers/tty/serial/uartlite.c
··· 387 387 } 388 388 #endif 389 389 390 - static struct uart_ops ulite_ops = { 390 + static const struct uart_ops ulite_ops = { 391 391 .tx_empty = ulite_tx_empty, 392 392 .set_mctrl = ulite_set_mctrl, 393 393 .get_mctrl = ulite_get_mctrl,
+4 -4
drivers/tty/serial/vt8500_serial.c
··· 118 118 * have been allocated as we can't use pdev->id in 119 119 * devicetree 120 120 */ 121 - static unsigned long vt8500_ports_in_use; 121 + static DECLARE_BITMAP(vt8500_ports_in_use, VT8500_MAX_PORTS); 122 122 123 123 static inline void vt8500_write(struct uart_port *port, unsigned int val, 124 124 unsigned int off) ··· 663 663 664 664 if (port < 0) { 665 665 /* calculate the port id */ 666 - port = find_first_zero_bit(&vt8500_ports_in_use, 667 - sizeof(vt8500_ports_in_use)); 666 + port = find_first_zero_bit(vt8500_ports_in_use, 667 + VT8500_MAX_PORTS); 668 668 } 669 669 670 670 if (port >= VT8500_MAX_PORTS) 671 671 return -ENODEV; 672 672 673 673 /* reserve the port id */ 674 - if (test_and_set_bit(port, &vt8500_ports_in_use)) { 674 + if (test_and_set_bit(port, vt8500_ports_in_use)) { 675 675 /* port already in use - shouldn't really happen */ 676 676 return -EBUSY; 677 677 }
+211 -97
drivers/tty/serial/xilinx_uartps.c
··· 57 57 #define CDNS_UART_IMR 0x10 /* Interrupt Mask */ 58 58 #define CDNS_UART_ISR 0x14 /* Interrupt Status */ 59 59 #define CDNS_UART_BAUDGEN 0x18 /* Baud Rate Generator */ 60 - #define CDNS_UART_RXTOUT 0x1C /* RX Timeout */ 60 + #define CDNS_UART_RXTOUT 0x1C /* RX Timeout */ 61 61 #define CDNS_UART_RXWM 0x20 /* RX FIFO Trigger Level */ 62 62 #define CDNS_UART_MODEMCR 0x24 /* Modem Control */ 63 63 #define CDNS_UART_MODEMSR 0x28 /* Modem Status */ ··· 68 68 #define CDNS_UART_IRRX_PWIDTH 0x3C /* IR Min Received Pulse Width */ 69 69 #define CDNS_UART_IRTX_PWIDTH 0x40 /* IR Transmitted pulse Width */ 70 70 #define CDNS_UART_TXWM 0x44 /* TX FIFO Trigger Level */ 71 + #define CDNS_UART_RXBS 0x48 /* RX FIFO byte status register */ 71 72 72 73 /* Control Register Bit Definitions */ 73 74 #define CDNS_UART_CR_STOPBRK 0x00000100 /* Stop TX break */ ··· 80 79 #define CDNS_UART_CR_TXRST 0x00000002 /* TX logic reset */ 81 80 #define CDNS_UART_CR_RXRST 0x00000001 /* RX logic reset */ 82 81 #define CDNS_UART_CR_RST_TO 0x00000040 /* Restart Timeout Counter */ 82 + #define CDNS_UART_RXBS_PARITY 0x00000001 /* Parity error status */ 83 + #define CDNS_UART_RXBS_FRAMING 0x00000002 /* Framing error status */ 84 + #define CDNS_UART_RXBS_BRK 0x00000004 /* Overrun error status */ 83 85 84 86 /* 85 87 * Mode Register: ··· 130 126 #define CDNS_UART_IXR_RXEMPTY 0x00000002 /* RX FIFO empty interrupt. */ 131 127 #define CDNS_UART_IXR_MASK 0x00001FFF /* Valid bit mask */ 132 128 133 - #define CDNS_UART_RX_IRQS (CDNS_UART_IXR_PARITY | CDNS_UART_IXR_FRAMING | \ 134 - CDNS_UART_IXR_OVERRUN | CDNS_UART_IXR_RXTRIG | \ 129 + /* 130 + * Do not enable parity error interrupt for the following 131 + * reason: When parity error interrupt is enabled, each Rx 132 + * parity error always results in 2 events. The first one 133 + * being parity error interrupt and the second one with a 134 + * proper Rx interrupt with the incoming data. Disabling 135 + * parity error interrupt ensures better handling of parity 136 + * error events. With this change, for a parity error case, we 137 + * get a Rx interrupt with parity error set in ISR register 138 + * and we still handle parity errors in the desired way. 139 + */ 140 + 141 + #define CDNS_UART_RX_IRQS (CDNS_UART_IXR_FRAMING | \ 142 + CDNS_UART_IXR_OVERRUN | \ 143 + CDNS_UART_IXR_RXTRIG | \ 135 144 CDNS_UART_IXR_TOUT) 136 145 137 146 /* Goes in read_status_mask for break detection as the HW doesn't do it*/ 138 - #define CDNS_UART_IXR_BRK 0x80000000 147 + #define CDNS_UART_IXR_BRK 0x00002000 139 148 149 + #define CDNS_UART_RXBS_SUPPORT BIT(1) 140 150 /* 141 151 * Modem Control register: 142 152 * The read/write Modem Control register controls the interface with the modem ··· 190 172 struct clk *pclk; 191 173 unsigned int baud; 192 174 struct notifier_block clk_rate_change_nb; 175 + u32 quirks; 176 + }; 177 + struct cdns_platform_data { 178 + u32 quirks; 193 179 }; 194 180 #define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \ 195 181 clk_rate_change_nb); 196 182 197 - static void cdns_uart_handle_rx(struct uart_port *port, unsigned int isrstatus) 183 + /** 184 + * cdns_uart_handle_rx - Handle the received bytes along with Rx errors. 185 + * @dev_id: Id of the UART port 186 + * @isrstatus: The interrupt status register value as read 187 + * Return: None 188 + */ 189 + static void cdns_uart_handle_rx(void *dev_id, unsigned int isrstatus) 198 190 { 199 - /* 200 - * There is no hardware break detection, so we interpret framing 201 - * error with all-zeros data as a break sequence. Most of the time, 202 - * there's another non-zero byte at the end of the sequence. 203 - */ 204 - if (isrstatus & CDNS_UART_IXR_FRAMING) { 205 - while (!(readl(port->membase + CDNS_UART_SR) & 206 - CDNS_UART_SR_RXEMPTY)) { 207 - if (!readl(port->membase + CDNS_UART_FIFO)) { 191 + struct uart_port *port = (struct uart_port *)dev_id; 192 + struct cdns_uart *cdns_uart = port->private_data; 193 + unsigned int data; 194 + unsigned int rxbs_status = 0; 195 + unsigned int status_mask; 196 + unsigned int framerrprocessed = 0; 197 + char status = TTY_NORMAL; 198 + bool is_rxbs_support; 199 + 200 + is_rxbs_support = cdns_uart->quirks & CDNS_UART_RXBS_SUPPORT; 201 + 202 + while ((readl(port->membase + CDNS_UART_SR) & 203 + CDNS_UART_SR_RXEMPTY) != CDNS_UART_SR_RXEMPTY) { 204 + if (is_rxbs_support) 205 + rxbs_status = readl(port->membase + CDNS_UART_RXBS); 206 + data = readl(port->membase + CDNS_UART_FIFO); 207 + port->icount.rx++; 208 + /* 209 + * There is no hardware break detection in Zynq, so we interpret 210 + * framing error with all-zeros data as a break sequence. 211 + * Most of the time, there's another non-zero byte at the 212 + * end of the sequence. 213 + */ 214 + if (!is_rxbs_support && (isrstatus & CDNS_UART_IXR_FRAMING)) { 215 + if (!data) { 208 216 port->read_status_mask |= CDNS_UART_IXR_BRK; 209 - isrstatus &= ~CDNS_UART_IXR_FRAMING; 217 + framerrprocessed = 1; 218 + continue; 210 219 } 211 220 } 212 - writel(CDNS_UART_IXR_FRAMING, port->membase + CDNS_UART_ISR); 213 - } 221 + if (is_rxbs_support && (rxbs_status & CDNS_UART_RXBS_BRK)) { 222 + port->icount.brk++; 223 + status = TTY_BREAK; 224 + if (uart_handle_break(port)) 225 + continue; 226 + } 214 227 215 - /* drop byte with parity error if IGNPAR specified */ 216 - if (isrstatus & port->ignore_status_mask & CDNS_UART_IXR_PARITY) 217 - isrstatus &= ~(CDNS_UART_IXR_RXTRIG | CDNS_UART_IXR_TOUT); 228 + isrstatus &= port->read_status_mask; 229 + isrstatus &= ~port->ignore_status_mask; 230 + status_mask = port->read_status_mask; 231 + status_mask &= ~port->ignore_status_mask; 218 232 219 - isrstatus &= port->read_status_mask; 220 - isrstatus &= ~port->ignore_status_mask; 221 - 222 - if (!(isrstatus & (CDNS_UART_IXR_TOUT | CDNS_UART_IXR_RXTRIG))) 223 - return; 224 - 225 - while (!(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_RXEMPTY)) { 226 - u32 data; 227 - char status = TTY_NORMAL; 228 - 229 - data = readl(port->membase + CDNS_UART_FIFO); 230 - 231 - /* Non-NULL byte after BREAK is garbage (99%) */ 232 - if (data && (port->read_status_mask & CDNS_UART_IXR_BRK)) { 233 + if (data && 234 + (port->read_status_mask & CDNS_UART_IXR_BRK)) { 233 235 port->read_status_mask &= ~CDNS_UART_IXR_BRK; 234 236 port->icount.brk++; 235 237 if (uart_handle_break(port)) ··· 259 221 if (uart_handle_sysrq_char(port, data)) 260 222 continue; 261 223 262 - port->icount.rx++; 263 - 264 - if (isrstatus & CDNS_UART_IXR_PARITY) { 265 - port->icount.parity++; 266 - status = TTY_PARITY; 267 - } else if (isrstatus & CDNS_UART_IXR_FRAMING) { 268 - port->icount.frame++; 269 - status = TTY_FRAME; 270 - } else if (isrstatus & CDNS_UART_IXR_OVERRUN) { 271 - port->icount.overrun++; 224 + if (is_rxbs_support) { 225 + if ((rxbs_status & CDNS_UART_RXBS_PARITY) 226 + && (status_mask & CDNS_UART_IXR_PARITY)) { 227 + port->icount.parity++; 228 + status = TTY_PARITY; 229 + } 230 + if ((rxbs_status & CDNS_UART_RXBS_FRAMING) 231 + && (status_mask & CDNS_UART_IXR_PARITY)) { 232 + port->icount.frame++; 233 + status = TTY_FRAME; 234 + } 235 + } else { 236 + if (isrstatus & CDNS_UART_IXR_PARITY) { 237 + port->icount.parity++; 238 + status = TTY_PARITY; 239 + } 240 + if ((isrstatus & CDNS_UART_IXR_FRAMING) && 241 + !framerrprocessed) { 242 + port->icount.frame++; 243 + status = TTY_FRAME; 244 + } 272 245 } 273 - 274 - uart_insert_char(port, isrstatus, CDNS_UART_IXR_OVERRUN, 275 - data, status); 246 + if (isrstatus & CDNS_UART_IXR_OVERRUN) { 247 + port->icount.overrun++; 248 + tty_insert_flip_char(&port->state->port, 0, 249 + TTY_OVERRUN); 250 + } 251 + tty_insert_flip_char(&port->state->port, data, status); 252 + isrstatus = 0; 276 253 } 254 + spin_unlock(&port->lock); 277 255 tty_flip_buffer_push(&port->state->port); 256 + spin_lock(&port->lock); 278 257 } 279 258 280 - static void cdns_uart_handle_tx(struct uart_port *port) 259 + /** 260 + * cdns_uart_handle_tx - Handle the bytes to be Txed. 261 + * @dev_id: Id of the UART port 262 + * Return: None 263 + */ 264 + static void cdns_uart_handle_tx(void *dev_id) 281 265 { 266 + struct uart_port *port = (struct uart_port *)dev_id; 282 267 unsigned int numbytes; 283 268 284 269 if (uart_circ_empty(&port->state->xmit)) { 285 270 writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_IDR); 286 - return; 271 + } else { 272 + numbytes = port->fifosize; 273 + while (numbytes && !uart_circ_empty(&port->state->xmit) && 274 + !(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXFULL)) { 275 + /* 276 + * Get the data from the UART circular buffer 277 + * and write it to the cdns_uart's TX_FIFO 278 + * register. 279 + */ 280 + writel( 281 + port->state->xmit.buf[port->state->xmit. 282 + tail], port->membase + CDNS_UART_FIFO); 283 + 284 + port->icount.tx++; 285 + 286 + /* 287 + * Adjust the tail of the UART buffer and wrap 288 + * the buffer if it reaches limit. 289 + */ 290 + port->state->xmit.tail = 291 + (port->state->xmit.tail + 1) & 292 + (UART_XMIT_SIZE - 1); 293 + 294 + numbytes--; 295 + } 296 + 297 + if (uart_circ_chars_pending( 298 + &port->state->xmit) < WAKEUP_CHARS) 299 + uart_write_wakeup(port); 287 300 } 288 - 289 - numbytes = port->fifosize; 290 - while (numbytes && !uart_circ_empty(&port->state->xmit) && 291 - !(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXFULL)) { 292 - /* 293 - * Get the data from the UART circular buffer 294 - * and write it to the cdns_uart's TX_FIFO 295 - * register. 296 - */ 297 - writel(port->state->xmit.buf[port->state->xmit.tail], 298 - port->membase + CDNS_UART_FIFO); 299 - port->icount.tx++; 300 - 301 - /* 302 - * Adjust the tail of the UART buffer and wrap 303 - * the buffer if it reaches limit. 304 - */ 305 - port->state->xmit.tail = 306 - (port->state->xmit.tail + 1) & (UART_XMIT_SIZE - 1); 307 - 308 - numbytes--; 309 - } 310 - 311 - if (uart_circ_chars_pending(&port->state->xmit) < WAKEUP_CHARS) 312 - uart_write_wakeup(port); 313 301 } 314 302 315 303 /** ··· 348 284 static irqreturn_t cdns_uart_isr(int irq, void *dev_id) 349 285 { 350 286 struct uart_port *port = (struct uart_port *)dev_id; 351 - unsigned long flags; 352 287 unsigned int isrstatus; 353 288 354 - spin_lock_irqsave(&port->lock, flags); 289 + spin_lock(&port->lock); 355 290 356 291 /* Read the interrupt status register to determine which 357 - * interrupt(s) is/are active. 292 + * interrupt(s) is/are active and clear them. 358 293 */ 359 294 isrstatus = readl(port->membase + CDNS_UART_ISR); 360 - 361 - if (isrstatus & CDNS_UART_RX_IRQS) 362 - cdns_uart_handle_rx(port, isrstatus); 363 - 364 - if ((isrstatus & CDNS_UART_IXR_TXEMPTY) == CDNS_UART_IXR_TXEMPTY) 365 - cdns_uart_handle_tx(port); 366 - 367 295 writel(isrstatus, port->membase + CDNS_UART_ISR); 368 296 369 - /* be sure to release the lock and tty before leaving */ 370 - spin_unlock_irqrestore(&port->lock, flags); 297 + if (isrstatus & CDNS_UART_IXR_TXEMPTY) { 298 + cdns_uart_handle_tx(dev_id); 299 + isrstatus &= ~CDNS_UART_IXR_TXEMPTY; 300 + } 301 + if (isrstatus & CDNS_UART_IXR_MASK) 302 + cdns_uart_handle_rx(dev_id, isrstatus); 371 303 304 + spin_unlock(&port->lock); 372 305 return IRQ_HANDLED; 373 306 } 374 307 ··· 714 653 ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST; 715 654 writel(ctrl_reg, port->membase + CDNS_UART_CR); 716 655 656 + while (readl(port->membase + CDNS_UART_CR) & 657 + (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST)) 658 + cpu_relax(); 659 + 717 660 /* 718 661 * Clear the RX disable and TX disable bits and then set the TX enable 719 662 * bit and RX enable bit to enable the transmitter and receiver. ··· 801 736 */ 802 737 static int cdns_uart_startup(struct uart_port *port) 803 738 { 739 + struct cdns_uart *cdns_uart = port->private_data; 740 + bool is_brk_support; 804 741 int ret; 805 742 unsigned long flags; 806 743 unsigned int status = 0; 744 + 745 + is_brk_support = cdns_uart->quirks & CDNS_UART_RXBS_SUPPORT; 807 746 808 747 spin_lock_irqsave(&port->lock, flags); 809 748 ··· 820 751 */ 821 752 writel(CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST, 822 753 port->membase + CDNS_UART_CR); 754 + 755 + while (readl(port->membase + CDNS_UART_CR) & 756 + (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST)) 757 + cpu_relax(); 823 758 824 759 /* 825 760 * Clear the RX disable bit and then set the RX enable bit to enable ··· 867 794 } 868 795 869 796 /* Set the Interrupt Registers with desired interrupts */ 870 - writel(CDNS_UART_RX_IRQS, port->membase + CDNS_UART_IER); 797 + if (is_brk_support) 798 + writel(CDNS_UART_RX_IRQS | CDNS_UART_IXR_BRK, 799 + port->membase + CDNS_UART_IER); 800 + else 801 + writel(CDNS_UART_RX_IRQS, port->membase + CDNS_UART_IER); 871 802 872 803 return 0; 873 804 } ··· 1070 993 } 1071 994 } 1072 995 1073 - static struct uart_ops cdns_uart_ops = { 996 + static const struct uart_ops cdns_uart_ops = { 1074 997 .set_mctrl = cdns_uart_set_mctrl, 1075 998 .get_mctrl = cdns_uart_get_mctrl, 1076 999 .start_tx = cdns_uart_start_tx, ··· 1165 1088 static int __init cdns_early_console_setup(struct earlycon_device *device, 1166 1089 const char *opt) 1167 1090 { 1168 - if (!device->port.membase) 1091 + struct uart_port *port = &device->port; 1092 + 1093 + if (!port->membase) 1169 1094 return -ENODEV; 1095 + 1096 + /* initialise control register */ 1097 + writel(CDNS_UART_CR_TX_EN|CDNS_UART_CR_TXRST|CDNS_UART_CR_RXRST, 1098 + port->membase + CDNS_UART_CR); 1099 + 1100 + /* only set baud if specified on command line - otherwise 1101 + * assume it has been initialized by a boot loader. 1102 + */ 1103 + if (device->baud) { 1104 + u32 cd = 0, bdiv = 0; 1105 + u32 mr; 1106 + int div8; 1107 + 1108 + cdns_uart_calc_baud_divs(port->uartclk, device->baud, 1109 + &bdiv, &cd, &div8); 1110 + mr = CDNS_UART_MR_PARITY_NONE; 1111 + if (div8) 1112 + mr |= CDNS_UART_MR_CLKSEL; 1113 + 1114 + writel(mr, port->membase + CDNS_UART_MR); 1115 + writel(cd, port->membase + CDNS_UART_BAUDGEN); 1116 + writel(bdiv, port->membase + CDNS_UART_BAUDDIV); 1117 + } 1170 1118 1171 1119 device->con->write = cdns_early_write; 1172 1120 ··· 1430 1328 static SIMPLE_DEV_PM_OPS(cdns_uart_dev_pm_ops, cdns_uart_suspend, 1431 1329 cdns_uart_resume); 1432 1330 1331 + static const struct cdns_platform_data zynqmp_uart_def = { 1332 + .quirks = CDNS_UART_RXBS_SUPPORT, }; 1333 + 1334 + /* Match table for of_platform binding */ 1335 + static const struct of_device_id cdns_uart_of_match[] = { 1336 + { .compatible = "xlnx,xuartps", }, 1337 + { .compatible = "cdns,uart-r1p8", }, 1338 + { .compatible = "cdns,uart-r1p12", .data = &zynqmp_uart_def }, 1339 + {} 1340 + }; 1341 + MODULE_DEVICE_TABLE(of, cdns_uart_of_match); 1342 + 1433 1343 /** 1434 1344 * cdns_uart_probe - Platform driver probe 1435 1345 * @pdev: Pointer to the platform device structure ··· 1454 1340 struct uart_port *port; 1455 1341 struct resource *res; 1456 1342 struct cdns_uart *cdns_uart_data; 1343 + const struct of_device_id *match; 1457 1344 1458 1345 cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data), 1459 1346 GFP_KERNEL); 1460 1347 if (!cdns_uart_data) 1461 1348 return -ENOMEM; 1349 + 1350 + match = of_match_node(cdns_uart_of_match, pdev->dev.of_node); 1351 + if (match && match->data) { 1352 + const struct cdns_platform_data *data = match->data; 1353 + 1354 + cdns_uart_data->quirks = data->quirks; 1355 + } 1462 1356 1463 1357 cdns_uart_data->pclk = devm_clk_get(&pdev->dev, "pclk"); 1464 1358 if (IS_ERR(cdns_uart_data->pclk)) { ··· 1592 1470 clk_unprepare(cdns_uart_data->pclk); 1593 1471 return rc; 1594 1472 } 1595 - 1596 - /* Match table for of_platform binding */ 1597 - static const struct of_device_id cdns_uart_of_match[] = { 1598 - { .compatible = "xlnx,xuartps", }, 1599 - { .compatible = "cdns,uart-r1p8", }, 1600 - {} 1601 - }; 1602 - MODULE_DEVICE_TABLE(of, cdns_uart_of_match); 1603 1473 1604 1474 static struct platform_driver cdns_uart_platform_driver = { 1605 1475 .probe = cdns_uart_probe,
+9 -4
drivers/tty/vt/vt.c
··· 1312 1312 if (i > vc->vc_npar) 1313 1313 return i; 1314 1314 1315 - if (vc->vc_par[i] == 5 && i < vc->vc_npar) { 1316 - /* 256 colours -- ubiquitous */ 1315 + if (vc->vc_par[i] == 5 && i + 1 <= vc->vc_npar) { 1316 + /* 256 colours */ 1317 1317 i++; 1318 1318 rgb_from_256(vc->vc_par[i], &c); 1319 - } else if (vc->vc_par[i] == 2 && i <= vc->vc_npar + 3) { 1320 - /* 24 bit -- extremely rare */ 1319 + } else if (vc->vc_par[i] == 2 && i + 3 <= vc->vc_npar) { 1320 + /* 24 bit */ 1321 1321 c.r = vc->vc_par[i + 1]; 1322 1322 c.g = vc->vc_par[i + 2]; 1323 1323 c.b = vc->vc_par[i + 3]; ··· 1415 1415 (vc->vc_color & 0x0f); 1416 1416 break; 1417 1417 default: 1418 + if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) { 1419 + if (vc->vc_par[i] < 100) 1420 + vc->vc_intensity = 2; 1421 + vc->vc_par[i] -= 60; 1422 + } 1418 1423 if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37) 1419 1424 vc->vc_color = color_table[vc->vc_par[i] - 30] 1420 1425 | (vc->vc_color & 0xf0);
+26 -45
fs/devpts/inode.c
··· 272 272 struct dentry *root = sb->s_root; 273 273 struct pts_fs_info *fsi = DEVPTS_SB(sb); 274 274 struct pts_mount_opts *opts = &fsi->mount_opts; 275 - kuid_t root_uid; 276 - kgid_t root_gid; 277 - 278 - root_uid = make_kuid(current_user_ns(), 0); 279 - root_gid = make_kgid(current_user_ns(), 0); 280 - if (!uid_valid(root_uid) || !gid_valid(root_gid)) 281 - return -EINVAL; 275 + kuid_t ptmx_uid = current_fsuid(); 276 + kgid_t ptmx_gid = current_fsgid(); 282 277 283 278 inode_lock(d_inode(root)); 284 279 ··· 304 309 305 310 mode = S_IFCHR|opts->ptmxmode; 306 311 init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2)); 307 - inode->i_uid = root_uid; 308 - inode->i_gid = root_gid; 312 + inode->i_uid = ptmx_uid; 313 + inode->i_gid = ptmx_gid; 309 314 310 315 d_add(dentry, inode); 311 316 ··· 331 336 struct pts_fs_info *fsi = DEVPTS_SB(sb); 332 337 struct pts_mount_opts *opts = &fsi->mount_opts; 333 338 334 - sync_filesystem(sb); 335 339 err = parse_mount_options(data, PARSE_REMOUNT, opts); 336 340 337 341 /* ··· 389 395 devpts_fill_super(struct super_block *s, void *data, int silent) 390 396 { 391 397 struct inode *inode; 398 + int error; 392 399 393 400 s->s_iflags &= ~SB_I_NODEV; 394 401 s->s_blocksize = 1024; ··· 398 403 s->s_op = &devpts_sops; 399 404 s->s_time_gran = 1; 400 405 406 + error = -ENOMEM; 401 407 s->s_fs_info = new_pts_fs_info(s); 402 408 if (!s->s_fs_info) 403 409 goto fail; 404 410 411 + error = parse_mount_options(data, PARSE_MOUNT, &DEVPTS_SB(s)->mount_opts); 412 + if (error) 413 + goto fail; 414 + 415 + error = -ENOMEM; 405 416 inode = new_inode(s); 406 417 if (!inode) 407 418 goto fail; ··· 419 418 set_nlink(inode, 2); 420 419 421 420 s->s_root = d_make_root(inode); 422 - if (s->s_root) 423 - return 0; 421 + if (!s->s_root) { 422 + pr_err("get root dentry failed\n"); 423 + goto fail; 424 + } 424 425 425 - pr_err("get root dentry failed\n"); 426 + error = mknod_ptmx(s); 427 + if (error) 428 + goto fail_dput; 426 429 430 + return 0; 431 + fail_dput: 432 + dput(s->s_root); 433 + s->s_root = NULL; 427 434 fail: 428 - return -ENOMEM; 435 + return error; 429 436 } 430 437 431 438 /* ··· 445 436 static struct dentry *devpts_mount(struct file_system_type *fs_type, 446 437 int flags, const char *dev_name, void *data) 447 438 { 448 - int error; 449 - struct pts_mount_opts opts; 450 - struct super_block *s; 451 - 452 - error = parse_mount_options(data, PARSE_MOUNT, &opts); 453 - if (error) 454 - return ERR_PTR(error); 455 - 456 - s = sget(fs_type, NULL, set_anon_super, flags, NULL); 457 - if (IS_ERR(s)) 458 - return ERR_CAST(s); 459 - 460 - if (!s->s_root) { 461 - error = devpts_fill_super(s, data, flags & MS_SILENT ? 1 : 0); 462 - if (error) 463 - goto out_undo_sget; 464 - s->s_flags |= MS_ACTIVE; 465 - } 466 - 467 - memcpy(&(DEVPTS_SB(s))->mount_opts, &opts, sizeof(opts)); 468 - 469 - error = mknod_ptmx(s); 470 - if (error) 471 - goto out_undo_sget; 472 - 473 - return dget(s->s_root); 474 - 475 - out_undo_sget: 476 - deactivate_locked_super(s); 477 - return ERR_PTR(error); 439 + return mount_nodev(fs_type, flags, data, devpts_fill_super); 478 440 } 479 441 480 442 static void devpts_kill_sb(struct super_block *sb) 481 443 { 482 444 struct pts_fs_info *fsi = DEVPTS_SB(sb); 483 445 484 - ida_destroy(&fsi->allocated_ptys); 446 + if (fsi) 447 + ida_destroy(&fsi->allocated_ptys); 485 448 kfree(fsi); 486 449 kill_litter_super(sb); 487 450 }
+6
include/linux/acpi.h
··· 1099 1099 static inline bool acpi_has_watchdog(void) { return false; } 1100 1100 #endif 1101 1101 1102 + #ifdef CONFIG_ACPI_SPCR_TABLE 1103 + int parse_spcr(bool earlycon); 1104 + #else 1105 + static inline int parse_spcr(bool earlycon) { return 0; } 1106 + #endif 1107 + 1102 1108 #endif /*_LINUX_ACPI_H*/
+6
include/linux/amba/bus.h
··· 53 53 AMBA_VENDOR_ST = 0x80, 54 54 AMBA_VENDOR_QCOM = 0x51, 55 55 AMBA_VENDOR_LSI = 0xb6, 56 + AMBA_VENDOR_LINUX = 0xfe, /* This value is not official */ 56 57 }; 58 + 59 + /* This is used to generate pseudo-ID for AMBA device */ 60 + #define AMBA_LINUX_ID(conf, rev, part) \ 61 + (((conf) & 0xff) << 24 | ((rev) & 0xf) << 20 | \ 62 + AMBA_VENDOR_LINUX << 12 | ((part) & 0xfff)) 57 63 58 64 extern struct bus_type amba_bustype; 59 65
+9
include/linux/amba/serial.h
··· 104 104 #define UART01x_FR_CTS 0x001 105 105 #define UART01x_FR_TMSK (UART01x_FR_TXFF + UART01x_FR_BUSY) 106 106 107 + /* 108 + * Some bits of Flag Register on ZTE device have different position from 109 + * standard ones. 110 + */ 111 + #define ZX_UART01x_FR_BUSY 0x100 112 + #define ZX_UART01x_FR_DSR 0x008 113 + #define ZX_UART01x_FR_CTS 0x002 114 + #define ZX_UART011_FR_RI 0x001 115 + 107 116 #define UART011_CR_CTSEN 0x8000 /* CTS hardware flow control */ 108 117 #define UART011_CR_RTSEN 0x4000 /* RTS hardware flow control */ 109 118 #define UART011_CR_OUT2 0x2000 /* OUT2 */
+2
include/linux/atmel_serial.h
··· 118 118 119 119 #define ATMEL_US_BRGR 0x20 /* Baud Rate Generator Register */ 120 120 #define ATMEL_US_CD GENMASK(15, 0) /* Clock Divider */ 121 + #define ATMEL_US_FP_OFFSET 16 /* Fractional Part */ 122 + #define ATMEL_US_FP_MASK 0x7 121 123 122 124 #define ATMEL_US_RTOR 0x24 /* Receiver Time-out Register for USART */ 123 125 #define ATMEL_UA_RTOR 0x28 /* Receiver Time-out Register for UART */
+5
include/linux/dma/dw.h
··· 40 40 }; 41 41 42 42 /* Export to the platform drivers */ 43 + #if IS_ENABLED(CONFIG_DW_DMAC_CORE) 43 44 int dw_dma_probe(struct dw_dma_chip *chip); 44 45 int dw_dma_remove(struct dw_dma_chip *chip); 46 + #else 47 + static inline int dw_dma_probe(struct dw_dma_chip *chip) { return -ENODEV; } 48 + static inline int dw_dma_remove(struct dw_dma_chip *chip) { return 0; } 49 + #endif /* CONFIG_DW_DMAC_CORE */ 45 50 46 51 /* DMA API extensions */ 47 52 struct dw_desc;
+4 -5
include/linux/dma/hsu.h
··· 41 41 /* Export to the internal users */ 42 42 int hsu_dma_get_status(struct hsu_dma_chip *chip, unsigned short nr, 43 43 u32 *status); 44 - irqreturn_t hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr, 45 - u32 status); 44 + int hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr, u32 status); 46 45 47 46 /* Export to the platform drivers */ 48 47 int hsu_dma_probe(struct hsu_dma_chip *chip); ··· 52 53 { 53 54 return 0; 54 55 } 55 - static inline irqreturn_t hsu_dma_do_irq(struct hsu_dma_chip *chip, 56 - unsigned short nr, u32 status) 56 + static inline int hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr, 57 + u32 status) 57 58 { 58 - return IRQ_NONE; 59 + return 0; 59 60 } 60 61 static inline int hsu_dma_probe(struct hsu_dma_chip *chip) { return -ENODEV; } 61 62 static inline int hsu_dma_remove(struct hsu_dma_chip *chip) { return 0; }
+3
include/linux/of_fdt.h
··· 14 14 15 15 #include <linux/types.h> 16 16 #include <linux/init.h> 17 + #include <linux/errno.h> 17 18 18 19 /* Definitions used by the flattened device tree */ 19 20 #define OF_DT_HEADER 0xd00dfeed /* marker */ ··· 67 66 int depth, void *data); 68 67 extern int early_init_dt_scan_memory(unsigned long node, const char *uname, 69 68 int depth, void *data); 69 + extern int early_init_dt_scan_chosen_stdout(void); 70 70 extern void early_init_fdt_scan_reserved_mem(void); 71 71 extern void early_init_fdt_reserve_self(void); 72 72 extern void early_init_dt_add_memory_arch(u64 base, u64 size); ··· 96 94 extern u64 of_flat_dt_translate_address(unsigned long node); 97 95 extern void of_fdt_limit_memory(int limit); 98 96 #else /* CONFIG_OF_FLATTREE */ 97 + static inline int early_init_dt_scan_chosen_stdout(void) { return -ENODEV; } 99 98 static inline void early_init_fdt_scan_reserved_mem(void) {} 100 99 static inline void early_init_fdt_reserve_self(void) {} 101 100 static inline const char *of_flat_dt_get_machine_name(void) { return NULL; }
+4
include/linux/platform_data/dma-dw.h
··· 23 23 * @dst_id: dst request line 24 24 * @m_master: memory master for transfers on allocated channel 25 25 * @p_master: peripheral master for transfers on allocated channel 26 + * @hs_polarity:set active low polarity of handshake interface 26 27 */ 27 28 struct dw_dma_slave { 28 29 struct device *dma_dev; ··· 31 30 u8 dst_id; 32 31 u8 m_master; 33 32 u8 p_master; 33 + bool hs_polarity; 34 34 }; 35 35 36 36 /** ··· 40 38 * @is_private: The device channels should be marked as private and not for 41 39 * by the general purpose DMA channel allocator. 42 40 * @is_memcpy: The device channels do support memory-to-memory transfers. 41 + * @is_nollp: The device channels does not support multi block transfers. 43 42 * @chan_allocation_order: Allocate channels starting from 0 or 7 44 43 * @chan_priority: Set channel priority increasing from 0 to 7 or 7 to 0. 45 44 * @block_size: Maximum block size supported by the controller ··· 52 49 unsigned int nr_channels; 53 50 bool is_private; 54 51 bool is_memcpy; 52 + bool is_nollp; 55 53 #define CHAN_ALLOCATION_ASCENDING 0 /* zero to seven */ 56 54 #define CHAN_ALLOCATION_DESCENDING 1 /* seven to zero */ 57 55 unsigned char chan_allocation_order;
+10 -3
include/linux/serial_core.h
··· 367 367 368 368 #define EARLYCON_DECLARE(_name, fn) OF_EARLYCON_DECLARE(_name, "", fn) 369 369 370 - extern int setup_earlycon(char *buf); 371 370 extern int of_setup_earlycon(const struct earlycon_id *match, 372 371 unsigned long node, 373 372 const char *options); 374 373 374 + #ifdef CONFIG_SERIAL_EARLYCON 375 + extern bool earlycon_init_is_deferred __initdata; 376 + int setup_earlycon(char *buf); 377 + #else 378 + static const bool earlycon_init_is_deferred; 379 + static inline int setup_earlycon(char *buf) { return 0; } 380 + #endif 381 + 375 382 struct uart_port *uart_get_console(struct uart_port *ports, int nr, 376 383 struct console *c); 377 - int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr, 384 + int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr, 378 385 char **options); 379 386 void uart_parse_options(char *options, int *baud, int *parity, int *bits, 380 387 int *flow); ··· 419 412 static inline int uart_tx_stopped(struct uart_port *port) 420 413 { 421 414 struct tty_struct *tty = port->state->port.tty; 422 - if (tty->stopped || port->hw_stopped) 415 + if ((tty && tty->stopped) || port->hw_stopped) 423 416 return 1; 424 417 return 0; 425 418 }
+8
include/uapi/linux/serial_reg.h
··· 376 376 #define UART_EXAR_TXTRG 0x0a /* Tx FIFO trigger level write-only */ 377 377 #define UART_EXAR_RXTRG 0x0b /* Rx FIFO trigger level write-only */ 378 378 379 + /* 380 + * These are definitions for the Altera ALTR_16550_F32/F64/F128 381 + * Normalized from 0x100 to 0x40 because of shift by 2 (32 bit regs). 382 + */ 383 + #define UART_ALTR_AFR 0x40 /* Additional Features Register */ 384 + #define UART_ALTR_EN_TXFIFO_LW 0x01 /* Enable the TX FIFO Low Watermark */ 385 + #define UART_ALTR_TX_LOW 0x41 /* Tx FIFO Low Watermark */ 386 + 379 387 #endif /* _LINUX_SERIAL_REG_H */ 380 388