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

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

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

It was delayed for a bit due to some questions surrounding some of the
console command line parsing changes that are in here. There's still
one tiny regression for people who were previously putting multiple
console command lines and expecting them all to be ignored for some
odd reason, but Peter is working on fixing that. If not, I'll send a
revert for the offending patch, but I have faith that Peter can
address it.

Other than the console work here, there's the usual serial driver
updates and changes, and a buch of 8250 reworks to try to make that
driver easier to maintain over time, and have it support more devices
in the future.

All of these have been in linux-next for a while"

* tag 'tty-4.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (119 commits)
n_gsm: Drop unneeded cast on netdev_priv
sc16is7xx: expose RTS inversion in RS-485 mode
serial: 8250_pci: port failed after wakeup from S3
earlycon: 8250: Document kernel command line options
earlycon: 8250: Fix command line regression
earlycon: Fix __earlycon_table stride
tty: clean up the tty time logic a bit
serial: 8250_dw: only get the clock rate in one place
serial: 8250_dw: remove useless ACPI ID check
dmaengine: hsu: move memory allocation to GFP_NOWAIT
dmaengine: hsu: remove redundant pieces of code
serial: 8250_pci: add Intel Tangier support
dmaengine: hsu: add Intel Tangier PCI ID
serial: 8250_pci: replace switch-case by formula for Intel MID
serial: 8250_pci: replace switch-case by formula
tty: cpm_uart: replace CONFIG_8xx by CONFIG_CPM1
serial: jsm: some off by one bugs
serial: xuartps: Fix check in console_setup().
serial: xuartps: Get rid of register access macros.
serial: xuartps: Fix iobase use.
...

+2368 -4754
+15 -3
Documentation/kernel-parameters.txt
··· 713 713 714 714 uart[8250],io,<addr>[,options] 715 715 uart[8250],mmio,<addr>[,options] 716 + uart[8250],mmio32,<addr>[,options] 717 + uart[8250],0x<addr>[,options] 716 718 Start an early, polled-mode console on the 8250/16550 717 719 UART at the specified I/O port or MMIO address, 718 - switching to the matching ttyS device later. The 719 - options are the same as for ttyS, above. 720 + switching to the matching ttyS device later. 721 + MMIO inter-register address stride is either 8-bit 722 + (mmio) or 32-bit (mmio32). 723 + If none of [io|mmio|mmio32], <addr> is assumed to be 724 + equivalent to 'mmio'. 'options' are specified in the 725 + same format described for ttyS above; if unspecified, 726 + the h/w is not re-initialized. 727 + 720 728 hvc<n> Use the hypervisor console device <n>. This is for 721 729 both Xen and PowerPC hypervisors. 722 730 ··· 958 950 uart[8250],io,<addr>[,options] 959 951 uart[8250],mmio,<addr>[,options] 960 952 uart[8250],mmio32,<addr>[,options] 953 + uart[8250],0x<addr>[,options] 961 954 Start an early, polled-mode console on the 8250/16550 962 955 UART at the specified I/O port or MMIO address. 963 956 MMIO inter-register address stride is either 8-bit 964 957 (mmio) or 32-bit (mmio32). 965 - The options are the same as for ttyS, above. 958 + If none of [io|mmio|mmio32], <addr> is assumed to be 959 + equivalent to 'mmio'. 'options' are specified in the 960 + same format described for "console=ttyS<n>"; if 961 + unspecified, the h/w is not initialized. 966 962 967 963 pl011,<addr> 968 964 Start an early, polled-mode console on a pl011 serial
+2 -2
arch/mips/mti-malta/malta-init.c
··· 14 14 #include <linux/init.h> 15 15 #include <linux/string.h> 16 16 #include <linux/kernel.h> 17 - #include <linux/serial_8250.h> 17 + #include <linux/serial_core.h> 18 18 19 19 #include <asm/cacheflush.h> 20 20 #include <asm/smp-ops.h> ··· 75 75 if ((strstr(fw_getcmdline(), "earlycon=")) == NULL) { 76 76 sprintf(console_string, "uart8250,io,0x3f8,%d%c%c", baud, 77 77 parity, bits); 78 - setup_early_serial8250_console(console_string); 78 + setup_earlycon(console_string); 79 79 } 80 80 81 81 if ((strstr(fw_getcmdline(), "console=")) == NULL) {
-4
arch/x86/Kconfig.debug
··· 43 43 with klogd/syslogd or the X server. You should normally N here, 44 44 unless you want to debug such a crash. 45 45 46 - config EARLY_PRINTK_INTEL_MID 47 - bool "Early printk for Intel MID platform support" 48 - depends on EARLY_PRINTK && X86_INTEL_MID 49 - 50 46 config EARLY_PRINTK_DBGP 51 47 bool "Early printk via EHCI debug port" 52 48 depends on EARLY_PRINTK && PCI
-3
arch/x86/include/asm/intel-mid.h
··· 136 136 #define SFI_MTMR_MAX_NUM 8 137 137 #define SFI_MRTC_MAX 8 138 138 139 - extern struct console early_hsu_console; 140 - extern void hsu_early_console_init(const char *); 141 - 142 139 extern void intel_scu_devices_create(void); 143 140 extern void intel_scu_devices_destroy(void); 144 141
+4 -4
arch/x86/include/asm/serial.h
··· 12 12 13 13 /* Standard COM flags (except for COM4, because of the 8514 problem) */ 14 14 #ifdef CONFIG_SERIAL_DETECT_IRQ 15 - # define STD_COMX_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ) 16 - # define STD_COM4_FLAGS (ASYNC_BOOT_AUTOCONF | 0 | ASYNC_AUTO_IRQ) 15 + # define STD_COMX_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_AUTO_IRQ) 16 + # define STD_COM4_FLAGS (UPF_BOOT_AUTOCONF | 0 | UPF_AUTO_IRQ) 17 17 #else 18 - # define STD_COMX_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST | 0 ) 19 - # define STD_COM4_FLAGS (ASYNC_BOOT_AUTOCONF | 0 | 0 ) 18 + # define STD_COMX_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | 0 ) 19 + # define STD_COM4_FLAGS (UPF_BOOT_AUTOCONF | 0 | 0 ) 20 20 #endif 21 21 22 22 #define SERIAL_PORT_DFNS \
-6
arch/x86/kernel/early_printk.c
··· 375 375 if (!strncmp(buf, "xen", 3)) 376 376 early_console_register(&xenboot_console, keep); 377 377 #endif 378 - #ifdef CONFIG_EARLY_PRINTK_INTEL_MID 379 - if (!strncmp(buf, "hsu", 3)) { 380 - hsu_early_console_init(buf + 3); 381 - early_console_register(&early_hsu_console, keep); 382 - } 383 - #endif 384 378 #ifdef CONFIG_EARLY_PRINTK_EFI 385 379 if (!strncmp(buf, "efi", 3)) 386 380 early_console_register(&early_efi_console, keep);
-1
arch/x86/platform/intel-mid/Makefile
··· 1 1 obj-$(CONFIG_X86_INTEL_MID) += intel-mid.o intel_mid_vrtc.o mfld.o mrfl.o 2 - obj-$(CONFIG_EARLY_PRINTK_INTEL_MID) += early_printk_intel_mid.o 3 2 4 3 # SFI specific code 5 4 ifdef CONFIG_X86_INTEL_MID
-112
arch/x86/platform/intel-mid/early_printk_intel_mid.c
··· 1 - /* 2 - * early_printk_intel_mid.c - early consoles for Intel MID platforms 3 - * 4 - * Copyright (c) 2008-2010, Intel Corporation 5 - * 6 - * This program is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU General Public License 8 - * as published by the Free Software Foundation; version 2 9 - * of the License. 10 - */ 11 - 12 - /* 13 - * This file implements early console named hsu. 14 - * hsu is based on a High Speed UART device which only exists in the Medfield 15 - * platform 16 - */ 17 - 18 - #include <linux/serial_reg.h> 19 - #include <linux/serial_mfd.h> 20 - #include <linux/console.h> 21 - #include <linux/kernel.h> 22 - #include <linux/delay.h> 23 - #include <linux/io.h> 24 - 25 - #include <asm/fixmap.h> 26 - #include <asm/pgtable.h> 27 - #include <asm/intel-mid.h> 28 - 29 - /* 30 - * Following is the early console based on Medfield HSU (High 31 - * Speed UART) device. 32 - */ 33 - #define HSU_PORT_BASE 0xffa28080 34 - 35 - static void __iomem *phsu; 36 - 37 - void hsu_early_console_init(const char *s) 38 - { 39 - unsigned long paddr, port = 0; 40 - u8 lcr; 41 - 42 - /* 43 - * Select the early HSU console port if specified by user in the 44 - * kernel command line. 45 - */ 46 - if (*s && !kstrtoul(s, 10, &port)) 47 - port = clamp_val(port, 0, 2); 48 - 49 - paddr = HSU_PORT_BASE + port * 0x80; 50 - phsu = (void __iomem *)set_fixmap_offset_nocache(FIX_EARLYCON_MEM_BASE, paddr); 51 - 52 - /* Disable FIFO */ 53 - writeb(0x0, phsu + UART_FCR); 54 - 55 - /* Set to default 115200 bps, 8n1 */ 56 - lcr = readb(phsu + UART_LCR); 57 - writeb((0x80 | lcr), phsu + UART_LCR); 58 - writeb(0x18, phsu + UART_DLL); 59 - writeb(lcr, phsu + UART_LCR); 60 - writel(0x3600, phsu + UART_MUL*4); 61 - 62 - writeb(0x8, phsu + UART_MCR); 63 - writeb(0x7, phsu + UART_FCR); 64 - writeb(0x3, phsu + UART_LCR); 65 - 66 - /* Clear IRQ status */ 67 - readb(phsu + UART_LSR); 68 - readb(phsu + UART_RX); 69 - readb(phsu + UART_IIR); 70 - readb(phsu + UART_MSR); 71 - 72 - /* Enable FIFO */ 73 - writeb(0x7, phsu + UART_FCR); 74 - } 75 - 76 - #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 77 - 78 - static void early_hsu_putc(char ch) 79 - { 80 - unsigned int timeout = 10000; /* 10ms */ 81 - u8 status; 82 - 83 - while (--timeout) { 84 - status = readb(phsu + UART_LSR); 85 - if (status & BOTH_EMPTY) 86 - break; 87 - udelay(1); 88 - } 89 - 90 - /* Only write the char when there was no timeout */ 91 - if (timeout) 92 - writeb(ch, phsu + UART_TX); 93 - } 94 - 95 - static void early_hsu_write(struct console *con, const char *str, unsigned n) 96 - { 97 - int i; 98 - 99 - for (i = 0; i < n && *str; i++) { 100 - if (*str == '\n') 101 - early_hsu_putc('\r'); 102 - early_hsu_putc(*str); 103 - str++; 104 - } 105 - } 106 - 107 - struct console early_hsu_console = { 108 - .name = "earlyhsu", 109 - .write = early_hsu_write, 110 - .flags = CON_PRINTBUFFER, 111 - .index = -1, 112 - };
+2
drivers/dma/Kconfig
··· 112 112 EloPlus is on mpc85xx and mpc86xx and Pxxx parts, and the Elo3 is on 113 113 some Txxx and Bxxx parts. 114 114 115 + source "drivers/dma/hsu/Kconfig" 116 + 115 117 config MPC512X_DMA 116 118 tristate "Freescale MPC512x built-in DMA engine support" 117 119 depends on PPC_MPC512x || PPC_MPC831x
+1
drivers/dma/Makefile
··· 10 10 obj-$(CONFIG_INTEL_IOATDMA) += ioat/ 11 11 obj-$(CONFIG_INTEL_IOP_ADMA) += iop-adma.o 12 12 obj-$(CONFIG_FSL_DMA) += fsldma.o 13 + obj-$(CONFIG_HSU_DMA) += hsu/ 13 14 obj-$(CONFIG_MPC512X_DMA) += mpc512x_dma.o 14 15 obj-$(CONFIG_PPC_BESTCOMM) += bestcomm/ 15 16 obj-$(CONFIG_MV_XOR) += mv_xor.o
+14
drivers/dma/hsu/Kconfig
··· 1 + # DMA engine configuration for hsu 2 + config HSU_DMA 3 + tristate "High Speed UART DMA support" 4 + select DMA_ENGINE 5 + select DMA_VIRTUAL_CHANNELS 6 + 7 + config HSU_DMA_PCI 8 + tristate "High Speed UART DMA PCI driver" 9 + depends on PCI 10 + select HSU_DMA 11 + help 12 + Support the High Speed UART DMA on the platfroms that 13 + enumerate it as a PCI device. For example, Intel Medfield 14 + has integrated this HSU DMA controller.
+5
drivers/dma/hsu/Makefile
··· 1 + obj-$(CONFIG_HSU_DMA) += hsu_dma.o 2 + hsu_dma-objs := hsu.o 3 + 4 + obj-$(CONFIG_HSU_DMA_PCI) += hsu_dma_pci.o 5 + hsu_dma_pci-objs := pci.o
+495
drivers/dma/hsu/hsu.c
··· 1 + /* 2 + * Core driver for the High Speed UART DMA 3 + * 4 + * Copyright (C) 2015 Intel Corporation 5 + * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 6 + * 7 + * Partially based on the bits found in drivers/tty/serial/mfd.c. 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License version 2 as 11 + * published by the Free Software Foundation. 12 + */ 13 + 14 + /* 15 + * DMA channel allocation: 16 + * 1. Even number chans are used for DMA Read (UART TX), odd chans for DMA 17 + * Write (UART RX). 18 + * 2. 0/1 channel are assigned to port 0, 2/3 chan to port 1, 4/5 chan to 19 + * port 3, and so on. 20 + */ 21 + 22 + #include <linux/delay.h> 23 + #include <linux/dmaengine.h> 24 + #include <linux/dma-mapping.h> 25 + #include <linux/init.h> 26 + #include <linux/module.h> 27 + #include <linux/slab.h> 28 + 29 + #include "hsu.h" 30 + 31 + #define HSU_DMA_BUSWIDTHS \ 32 + BIT(DMA_SLAVE_BUSWIDTH_UNDEFINED) | \ 33 + BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \ 34 + BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \ 35 + BIT(DMA_SLAVE_BUSWIDTH_3_BYTES) | \ 36 + BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | \ 37 + BIT(DMA_SLAVE_BUSWIDTH_8_BYTES) | \ 38 + BIT(DMA_SLAVE_BUSWIDTH_16_BYTES) 39 + 40 + static inline void hsu_chan_disable(struct hsu_dma_chan *hsuc) 41 + { 42 + hsu_chan_writel(hsuc, HSU_CH_CR, 0); 43 + } 44 + 45 + static inline void hsu_chan_enable(struct hsu_dma_chan *hsuc) 46 + { 47 + u32 cr = HSU_CH_CR_CHA; 48 + 49 + if (hsuc->direction == DMA_MEM_TO_DEV) 50 + cr &= ~HSU_CH_CR_CHD; 51 + else if (hsuc->direction == DMA_DEV_TO_MEM) 52 + cr |= HSU_CH_CR_CHD; 53 + 54 + hsu_chan_writel(hsuc, HSU_CH_CR, cr); 55 + } 56 + 57 + static void hsu_dma_chan_start(struct hsu_dma_chan *hsuc) 58 + { 59 + struct dma_slave_config *config = &hsuc->config; 60 + struct hsu_dma_desc *desc = hsuc->desc; 61 + u32 bsr = 0, mtsr = 0; /* to shut the compiler up */ 62 + u32 dcr = HSU_CH_DCR_CHSOE | HSU_CH_DCR_CHEI; 63 + unsigned int i, count; 64 + 65 + if (hsuc->direction == DMA_MEM_TO_DEV) { 66 + bsr = config->dst_maxburst; 67 + mtsr = config->dst_addr_width; 68 + } else if (hsuc->direction == DMA_DEV_TO_MEM) { 69 + bsr = config->src_maxburst; 70 + mtsr = config->src_addr_width; 71 + } 72 + 73 + hsu_chan_disable(hsuc); 74 + 75 + hsu_chan_writel(hsuc, HSU_CH_DCR, 0); 76 + hsu_chan_writel(hsuc, HSU_CH_BSR, bsr); 77 + hsu_chan_writel(hsuc, HSU_CH_MTSR, mtsr); 78 + 79 + /* Set descriptors */ 80 + count = (desc->nents - desc->active) % HSU_DMA_CHAN_NR_DESC; 81 + for (i = 0; i < count; i++) { 82 + hsu_chan_writel(hsuc, HSU_CH_DxSAR(i), desc->sg[i].addr); 83 + hsu_chan_writel(hsuc, HSU_CH_DxTSR(i), desc->sg[i].len); 84 + 85 + /* Prepare value for DCR */ 86 + dcr |= HSU_CH_DCR_DESCA(i); 87 + dcr |= HSU_CH_DCR_CHTOI(i); /* timeout bit, see HSU Errata 1 */ 88 + 89 + desc->active++; 90 + } 91 + /* Only for the last descriptor in the chain */ 92 + dcr |= HSU_CH_DCR_CHSOD(count - 1); 93 + dcr |= HSU_CH_DCR_CHDI(count - 1); 94 + 95 + hsu_chan_writel(hsuc, HSU_CH_DCR, dcr); 96 + 97 + hsu_chan_enable(hsuc); 98 + } 99 + 100 + static void hsu_dma_stop_channel(struct hsu_dma_chan *hsuc) 101 + { 102 + unsigned long flags; 103 + 104 + spin_lock_irqsave(&hsuc->lock, flags); 105 + hsu_chan_disable(hsuc); 106 + hsu_chan_writel(hsuc, HSU_CH_DCR, 0); 107 + spin_unlock_irqrestore(&hsuc->lock, flags); 108 + } 109 + 110 + static void hsu_dma_start_channel(struct hsu_dma_chan *hsuc) 111 + { 112 + unsigned long flags; 113 + 114 + spin_lock_irqsave(&hsuc->lock, flags); 115 + hsu_dma_chan_start(hsuc); 116 + spin_unlock_irqrestore(&hsuc->lock, flags); 117 + } 118 + 119 + static void hsu_dma_start_transfer(struct hsu_dma_chan *hsuc) 120 + { 121 + struct virt_dma_desc *vdesc; 122 + 123 + /* Get the next descriptor */ 124 + vdesc = vchan_next_desc(&hsuc->vchan); 125 + if (!vdesc) { 126 + hsuc->desc = NULL; 127 + return; 128 + } 129 + 130 + list_del(&vdesc->node); 131 + hsuc->desc = to_hsu_dma_desc(vdesc); 132 + 133 + /* Start the channel with a new descriptor */ 134 + hsu_dma_start_channel(hsuc); 135 + } 136 + 137 + static u32 hsu_dma_chan_get_sr(struct hsu_dma_chan *hsuc) 138 + { 139 + unsigned long flags; 140 + u32 sr; 141 + 142 + spin_lock_irqsave(&hsuc->lock, flags); 143 + sr = hsu_chan_readl(hsuc, HSU_CH_SR); 144 + spin_unlock_irqrestore(&hsuc->lock, flags); 145 + 146 + return sr; 147 + } 148 + 149 + irqreturn_t hsu_dma_irq(struct hsu_dma_chip *chip, unsigned short nr) 150 + { 151 + struct hsu_dma_chan *hsuc; 152 + struct hsu_dma_desc *desc; 153 + unsigned long flags; 154 + u32 sr; 155 + 156 + /* Sanity check */ 157 + if (nr >= chip->pdata->nr_channels) 158 + return IRQ_NONE; 159 + 160 + hsuc = &chip->hsu->chan[nr]; 161 + 162 + /* 163 + * No matter what situation, need read clear the IRQ status 164 + * There is a bug, see Errata 5, HSD 2900918 165 + */ 166 + sr = hsu_dma_chan_get_sr(hsuc); 167 + if (!sr) 168 + return IRQ_NONE; 169 + 170 + /* Timeout IRQ, need wait some time, see Errata 2 */ 171 + if (hsuc->direction == DMA_DEV_TO_MEM && (sr & HSU_CH_SR_DESCTO_ANY)) 172 + udelay(2); 173 + 174 + sr &= ~HSU_CH_SR_DESCTO_ANY; 175 + if (!sr) 176 + return IRQ_HANDLED; 177 + 178 + spin_lock_irqsave(&hsuc->vchan.lock, flags); 179 + desc = hsuc->desc; 180 + if (desc) { 181 + if (sr & HSU_CH_SR_CHE) { 182 + desc->status = DMA_ERROR; 183 + } else if (desc->active < desc->nents) { 184 + hsu_dma_start_channel(hsuc); 185 + } else { 186 + vchan_cookie_complete(&desc->vdesc); 187 + desc->status = DMA_COMPLETE; 188 + hsu_dma_start_transfer(hsuc); 189 + } 190 + } 191 + spin_unlock_irqrestore(&hsuc->vchan.lock, flags); 192 + 193 + return IRQ_HANDLED; 194 + } 195 + EXPORT_SYMBOL_GPL(hsu_dma_irq); 196 + 197 + static struct hsu_dma_desc *hsu_dma_alloc_desc(unsigned int nents) 198 + { 199 + struct hsu_dma_desc *desc; 200 + 201 + desc = kzalloc(sizeof(*desc), GFP_NOWAIT); 202 + if (!desc) 203 + return NULL; 204 + 205 + desc->sg = kcalloc(nents, sizeof(*desc->sg), GFP_NOWAIT); 206 + if (!desc->sg) { 207 + kfree(desc); 208 + return NULL; 209 + } 210 + 211 + return desc; 212 + } 213 + 214 + static void hsu_dma_desc_free(struct virt_dma_desc *vdesc) 215 + { 216 + struct hsu_dma_desc *desc = to_hsu_dma_desc(vdesc); 217 + 218 + kfree(desc->sg); 219 + kfree(desc); 220 + } 221 + 222 + static struct dma_async_tx_descriptor *hsu_dma_prep_slave_sg( 223 + struct dma_chan *chan, struct scatterlist *sgl, 224 + unsigned int sg_len, enum dma_transfer_direction direction, 225 + unsigned long flags, void *context) 226 + { 227 + struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan); 228 + struct hsu_dma_desc *desc; 229 + struct scatterlist *sg; 230 + unsigned int i; 231 + 232 + desc = hsu_dma_alloc_desc(sg_len); 233 + if (!desc) 234 + return NULL; 235 + 236 + for_each_sg(sgl, sg, sg_len, i) { 237 + desc->sg[i].addr = sg_dma_address(sg); 238 + desc->sg[i].len = sg_dma_len(sg); 239 + } 240 + 241 + desc->nents = sg_len; 242 + desc->direction = direction; 243 + /* desc->active = 0 by kzalloc */ 244 + desc->status = DMA_IN_PROGRESS; 245 + 246 + return vchan_tx_prep(&hsuc->vchan, &desc->vdesc, flags); 247 + } 248 + 249 + static void hsu_dma_issue_pending(struct dma_chan *chan) 250 + { 251 + struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan); 252 + unsigned long flags; 253 + 254 + spin_lock_irqsave(&hsuc->vchan.lock, flags); 255 + if (vchan_issue_pending(&hsuc->vchan) && !hsuc->desc) 256 + hsu_dma_start_transfer(hsuc); 257 + spin_unlock_irqrestore(&hsuc->vchan.lock, flags); 258 + } 259 + 260 + static size_t hsu_dma_desc_size(struct hsu_dma_desc *desc) 261 + { 262 + size_t bytes = 0; 263 + unsigned int i; 264 + 265 + for (i = desc->active; i < desc->nents; i++) 266 + bytes += desc->sg[i].len; 267 + 268 + return bytes; 269 + } 270 + 271 + static size_t hsu_dma_active_desc_size(struct hsu_dma_chan *hsuc) 272 + { 273 + struct hsu_dma_desc *desc = hsuc->desc; 274 + size_t bytes = hsu_dma_desc_size(desc); 275 + int i; 276 + unsigned long flags; 277 + 278 + spin_lock_irqsave(&hsuc->lock, flags); 279 + i = desc->active % HSU_DMA_CHAN_NR_DESC; 280 + do { 281 + bytes += hsu_chan_readl(hsuc, HSU_CH_DxTSR(i)); 282 + } while (--i >= 0); 283 + spin_unlock_irqrestore(&hsuc->lock, flags); 284 + 285 + return bytes; 286 + } 287 + 288 + static enum dma_status hsu_dma_tx_status(struct dma_chan *chan, 289 + dma_cookie_t cookie, struct dma_tx_state *state) 290 + { 291 + struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan); 292 + struct virt_dma_desc *vdesc; 293 + enum dma_status status; 294 + size_t bytes; 295 + unsigned long flags; 296 + 297 + status = dma_cookie_status(chan, cookie, state); 298 + if (status == DMA_COMPLETE) 299 + return status; 300 + 301 + spin_lock_irqsave(&hsuc->vchan.lock, flags); 302 + vdesc = vchan_find_desc(&hsuc->vchan, cookie); 303 + if (hsuc->desc && cookie == hsuc->desc->vdesc.tx.cookie) { 304 + bytes = hsu_dma_active_desc_size(hsuc); 305 + dma_set_residue(state, bytes); 306 + status = hsuc->desc->status; 307 + } else if (vdesc) { 308 + bytes = hsu_dma_desc_size(to_hsu_dma_desc(vdesc)); 309 + dma_set_residue(state, bytes); 310 + } 311 + spin_unlock_irqrestore(&hsuc->vchan.lock, flags); 312 + 313 + return status; 314 + } 315 + 316 + static int hsu_dma_slave_config(struct dma_chan *chan, 317 + struct dma_slave_config *config) 318 + { 319 + struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan); 320 + 321 + /* Check if chan will be configured for slave transfers */ 322 + if (!is_slave_direction(config->direction)) 323 + return -EINVAL; 324 + 325 + memcpy(&hsuc->config, config, sizeof(hsuc->config)); 326 + 327 + return 0; 328 + } 329 + 330 + static void hsu_dma_chan_deactivate(struct hsu_dma_chan *hsuc) 331 + { 332 + unsigned long flags; 333 + 334 + spin_lock_irqsave(&hsuc->lock, flags); 335 + hsu_chan_disable(hsuc); 336 + spin_unlock_irqrestore(&hsuc->lock, flags); 337 + } 338 + 339 + static void hsu_dma_chan_activate(struct hsu_dma_chan *hsuc) 340 + { 341 + unsigned long flags; 342 + 343 + spin_lock_irqsave(&hsuc->lock, flags); 344 + hsu_chan_enable(hsuc); 345 + spin_unlock_irqrestore(&hsuc->lock, flags); 346 + } 347 + 348 + static int hsu_dma_pause(struct dma_chan *chan) 349 + { 350 + struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan); 351 + unsigned long flags; 352 + 353 + spin_lock_irqsave(&hsuc->vchan.lock, flags); 354 + if (hsuc->desc && hsuc->desc->status == DMA_IN_PROGRESS) { 355 + hsu_dma_chan_deactivate(hsuc); 356 + hsuc->desc->status = DMA_PAUSED; 357 + } 358 + spin_unlock_irqrestore(&hsuc->vchan.lock, flags); 359 + 360 + return 0; 361 + } 362 + 363 + static int hsu_dma_resume(struct dma_chan *chan) 364 + { 365 + struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan); 366 + unsigned long flags; 367 + 368 + spin_lock_irqsave(&hsuc->vchan.lock, flags); 369 + if (hsuc->desc && hsuc->desc->status == DMA_PAUSED) { 370 + hsuc->desc->status = DMA_IN_PROGRESS; 371 + hsu_dma_chan_activate(hsuc); 372 + } 373 + spin_unlock_irqrestore(&hsuc->vchan.lock, flags); 374 + 375 + return 0; 376 + } 377 + 378 + static int hsu_dma_terminate_all(struct dma_chan *chan) 379 + { 380 + struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan); 381 + unsigned long flags; 382 + LIST_HEAD(head); 383 + 384 + spin_lock_irqsave(&hsuc->vchan.lock, flags); 385 + 386 + hsu_dma_stop_channel(hsuc); 387 + hsuc->desc = NULL; 388 + 389 + vchan_get_all_descriptors(&hsuc->vchan, &head); 390 + spin_unlock_irqrestore(&hsuc->vchan.lock, flags); 391 + vchan_dma_desc_free_list(&hsuc->vchan, &head); 392 + 393 + return 0; 394 + } 395 + 396 + static void hsu_dma_free_chan_resources(struct dma_chan *chan) 397 + { 398 + vchan_free_chan_resources(to_virt_chan(chan)); 399 + } 400 + 401 + int hsu_dma_probe(struct hsu_dma_chip *chip) 402 + { 403 + struct hsu_dma *hsu; 404 + struct hsu_dma_platform_data *pdata = chip->pdata; 405 + void __iomem *addr = chip->regs + chip->offset; 406 + unsigned short i; 407 + int ret; 408 + 409 + hsu = devm_kzalloc(chip->dev, sizeof(*hsu), GFP_KERNEL); 410 + if (!hsu) 411 + return -ENOMEM; 412 + 413 + chip->hsu = hsu; 414 + 415 + if (!pdata) { 416 + pdata = devm_kzalloc(chip->dev, sizeof(*pdata), GFP_KERNEL); 417 + if (!pdata) 418 + return -ENOMEM; 419 + 420 + chip->pdata = pdata; 421 + 422 + /* Guess nr_channels from the IO space length */ 423 + pdata->nr_channels = (chip->length - chip->offset) / 424 + HSU_DMA_CHAN_LENGTH; 425 + } 426 + 427 + hsu->chan = devm_kcalloc(chip->dev, pdata->nr_channels, 428 + sizeof(*hsu->chan), GFP_KERNEL); 429 + if (!hsu->chan) 430 + return -ENOMEM; 431 + 432 + INIT_LIST_HEAD(&hsu->dma.channels); 433 + for (i = 0; i < pdata->nr_channels; i++) { 434 + struct hsu_dma_chan *hsuc = &hsu->chan[i]; 435 + 436 + hsuc->vchan.desc_free = hsu_dma_desc_free; 437 + vchan_init(&hsuc->vchan, &hsu->dma); 438 + 439 + hsuc->direction = (i & 0x1) ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV; 440 + hsuc->reg = addr + i * HSU_DMA_CHAN_LENGTH; 441 + 442 + spin_lock_init(&hsuc->lock); 443 + } 444 + 445 + dma_cap_set(DMA_SLAVE, hsu->dma.cap_mask); 446 + dma_cap_set(DMA_PRIVATE, hsu->dma.cap_mask); 447 + 448 + hsu->dma.device_free_chan_resources = hsu_dma_free_chan_resources; 449 + 450 + hsu->dma.device_prep_slave_sg = hsu_dma_prep_slave_sg; 451 + 452 + hsu->dma.device_issue_pending = hsu_dma_issue_pending; 453 + hsu->dma.device_tx_status = hsu_dma_tx_status; 454 + 455 + hsu->dma.device_config = hsu_dma_slave_config; 456 + hsu->dma.device_pause = hsu_dma_pause; 457 + hsu->dma.device_resume = hsu_dma_resume; 458 + hsu->dma.device_terminate_all = hsu_dma_terminate_all; 459 + 460 + hsu->dma.src_addr_widths = HSU_DMA_BUSWIDTHS; 461 + hsu->dma.dst_addr_widths = HSU_DMA_BUSWIDTHS; 462 + hsu->dma.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); 463 + hsu->dma.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; 464 + 465 + hsu->dma.dev = chip->dev; 466 + 467 + ret = dma_async_device_register(&hsu->dma); 468 + if (ret) 469 + return ret; 470 + 471 + dev_info(chip->dev, "Found HSU DMA, %d channels\n", pdata->nr_channels); 472 + return 0; 473 + } 474 + EXPORT_SYMBOL_GPL(hsu_dma_probe); 475 + 476 + int hsu_dma_remove(struct hsu_dma_chip *chip) 477 + { 478 + struct hsu_dma *hsu = chip->hsu; 479 + unsigned short i; 480 + 481 + dma_async_device_unregister(&hsu->dma); 482 + 483 + for (i = 0; i < chip->pdata->nr_channels; i++) { 484 + struct hsu_dma_chan *hsuc = &hsu->chan[i]; 485 + 486 + tasklet_kill(&hsuc->vchan.task); 487 + } 488 + 489 + return 0; 490 + } 491 + EXPORT_SYMBOL_GPL(hsu_dma_remove); 492 + 493 + MODULE_LICENSE("GPL v2"); 494 + MODULE_DESCRIPTION("High Speed UART DMA core driver"); 495 + MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
+118
drivers/dma/hsu/hsu.h
··· 1 + /* 2 + * Driver for the High Speed UART DMA 3 + * 4 + * Copyright (C) 2015 Intel Corporation 5 + * 6 + * Partially based on the bits found in drivers/tty/serial/mfd.c. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 as 10 + * published by the Free Software Foundation. 11 + */ 12 + 13 + #ifndef __DMA_HSU_H__ 14 + #define __DMA_HSU_H__ 15 + 16 + #include <linux/spinlock.h> 17 + #include <linux/dma/hsu.h> 18 + 19 + #include "../virt-dma.h" 20 + 21 + #define HSU_CH_SR 0x00 /* channel status */ 22 + #define HSU_CH_CR 0x04 /* channel control */ 23 + #define HSU_CH_DCR 0x08 /* descriptor control */ 24 + #define HSU_CH_BSR 0x10 /* FIFO buffer size */ 25 + #define HSU_CH_MTSR 0x14 /* minimum transfer size */ 26 + #define HSU_CH_DxSAR(x) (0x20 + 8 * (x)) /* desc start addr */ 27 + #define HSU_CH_DxTSR(x) (0x24 + 8 * (x)) /* desc transfer size */ 28 + #define HSU_CH_D0SAR 0x20 /* desc 0 start addr */ 29 + #define HSU_CH_D0TSR 0x24 /* desc 0 transfer size */ 30 + #define HSU_CH_D1SAR 0x28 31 + #define HSU_CH_D1TSR 0x2c 32 + #define HSU_CH_D2SAR 0x30 33 + #define HSU_CH_D2TSR 0x34 34 + #define HSU_CH_D3SAR 0x38 35 + #define HSU_CH_D3TSR 0x3c 36 + 37 + #define HSU_DMA_CHAN_NR_DESC 4 38 + #define HSU_DMA_CHAN_LENGTH 0x40 39 + 40 + /* Bits in HSU_CH_SR */ 41 + #define HSU_CH_SR_DESCTO(x) BIT(8 + (x)) 42 + #define HSU_CH_SR_DESCTO_ANY (BIT(11) | BIT(10) | BIT(9) | BIT(8)) 43 + #define HSU_CH_SR_CHE BIT(15) 44 + 45 + /* Bits in HSU_CH_CR */ 46 + #define HSU_CH_CR_CHA BIT(0) 47 + #define HSU_CH_CR_CHD BIT(1) 48 + 49 + /* Bits in HSU_CH_DCR */ 50 + #define HSU_CH_DCR_DESCA(x) BIT(0 + (x)) 51 + #define HSU_CH_DCR_CHSOD(x) BIT(8 + (x)) 52 + #define HSU_CH_DCR_CHSOTO BIT(14) 53 + #define HSU_CH_DCR_CHSOE BIT(15) 54 + #define HSU_CH_DCR_CHDI(x) BIT(16 + (x)) 55 + #define HSU_CH_DCR_CHEI BIT(23) 56 + #define HSU_CH_DCR_CHTOI(x) BIT(24 + (x)) 57 + 58 + struct hsu_dma_sg { 59 + dma_addr_t addr; 60 + unsigned int len; 61 + }; 62 + 63 + struct hsu_dma_desc { 64 + struct virt_dma_desc vdesc; 65 + enum dma_transfer_direction direction; 66 + struct hsu_dma_sg *sg; 67 + unsigned int nents; 68 + unsigned int active; 69 + enum dma_status status; 70 + }; 71 + 72 + static inline struct hsu_dma_desc *to_hsu_dma_desc(struct virt_dma_desc *vdesc) 73 + { 74 + return container_of(vdesc, struct hsu_dma_desc, vdesc); 75 + } 76 + 77 + struct hsu_dma_chan { 78 + struct virt_dma_chan vchan; 79 + 80 + void __iomem *reg; 81 + spinlock_t lock; 82 + 83 + /* hardware configuration */ 84 + enum dma_transfer_direction direction; 85 + struct dma_slave_config config; 86 + 87 + struct hsu_dma_desc *desc; 88 + }; 89 + 90 + static inline struct hsu_dma_chan *to_hsu_dma_chan(struct dma_chan *chan) 91 + { 92 + return container_of(chan, struct hsu_dma_chan, vchan.chan); 93 + } 94 + 95 + static inline u32 hsu_chan_readl(struct hsu_dma_chan *hsuc, int offset) 96 + { 97 + return readl(hsuc->reg + offset); 98 + } 99 + 100 + static inline void hsu_chan_writel(struct hsu_dma_chan *hsuc, int offset, 101 + u32 value) 102 + { 103 + writel(value, hsuc->reg + offset); 104 + } 105 + 106 + struct hsu_dma { 107 + struct dma_device dma; 108 + 109 + /* channels */ 110 + struct hsu_dma_chan *chan; 111 + }; 112 + 113 + static inline struct hsu_dma *to_hsu_dma(struct dma_device *ddev) 114 + { 115 + return container_of(ddev, struct hsu_dma, dma); 116 + } 117 + 118 + #endif /* __DMA_HSU_H__ */
+124
drivers/dma/hsu/pci.c
··· 1 + /* 2 + * PCI driver for the High Speed UART DMA 3 + * 4 + * Copyright (C) 2015 Intel Corporation 5 + * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 6 + * 7 + * Partially based on the bits found in drivers/tty/serial/mfd.c. 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License version 2 as 11 + * published by the Free Software Foundation. 12 + */ 13 + 14 + #include <linux/bitops.h> 15 + #include <linux/device.h> 16 + #include <linux/module.h> 17 + #include <linux/pci.h> 18 + 19 + #include "hsu.h" 20 + 21 + #define HSU_PCI_DMASR 0x00 22 + #define HSU_PCI_DMAISR 0x04 23 + 24 + #define HSU_PCI_CHAN_OFFSET 0x100 25 + 26 + static irqreturn_t hsu_pci_irq(int irq, void *dev) 27 + { 28 + struct hsu_dma_chip *chip = dev; 29 + u32 dmaisr; 30 + unsigned short i; 31 + irqreturn_t ret = IRQ_NONE; 32 + 33 + dmaisr = readl(chip->regs + HSU_PCI_DMAISR); 34 + for (i = 0; i < chip->pdata->nr_channels; i++) { 35 + if (dmaisr & 0x1) 36 + ret |= hsu_dma_irq(chip, i); 37 + dmaisr >>= 1; 38 + } 39 + 40 + return ret; 41 + } 42 + 43 + static int hsu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 44 + { 45 + struct hsu_dma_chip *chip; 46 + int ret; 47 + 48 + ret = pcim_enable_device(pdev); 49 + if (ret) 50 + return ret; 51 + 52 + ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev)); 53 + if (ret) { 54 + dev_err(&pdev->dev, "I/O memory remapping failed\n"); 55 + return ret; 56 + } 57 + 58 + pci_set_master(pdev); 59 + pci_try_set_mwi(pdev); 60 + 61 + ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 62 + if (ret) 63 + return ret; 64 + 65 + ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 66 + if (ret) 67 + return ret; 68 + 69 + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 70 + if (!chip) 71 + return -ENOMEM; 72 + 73 + chip->dev = &pdev->dev; 74 + chip->regs = pcim_iomap_table(pdev)[0]; 75 + chip->length = pci_resource_len(pdev, 0); 76 + chip->offset = HSU_PCI_CHAN_OFFSET; 77 + chip->irq = pdev->irq; 78 + 79 + pci_enable_msi(pdev); 80 + 81 + ret = hsu_dma_probe(chip); 82 + if (ret) 83 + return ret; 84 + 85 + ret = request_irq(chip->irq, hsu_pci_irq, 0, "hsu_dma_pci", chip); 86 + if (ret) 87 + goto err_register_irq; 88 + 89 + pci_set_drvdata(pdev, chip); 90 + 91 + return 0; 92 + 93 + err_register_irq: 94 + hsu_dma_remove(chip); 95 + return ret; 96 + } 97 + 98 + static void hsu_pci_remove(struct pci_dev *pdev) 99 + { 100 + struct hsu_dma_chip *chip = pci_get_drvdata(pdev); 101 + 102 + free_irq(chip->irq, chip); 103 + hsu_dma_remove(chip); 104 + } 105 + 106 + static const struct pci_device_id hsu_pci_id_table[] = { 107 + { PCI_VDEVICE(INTEL, 0x081e), 0 }, 108 + { PCI_VDEVICE(INTEL, 0x1192), 0 }, 109 + { } 110 + }; 111 + MODULE_DEVICE_TABLE(pci, hsu_pci_id_table); 112 + 113 + static struct pci_driver hsu_pci_driver = { 114 + .name = "hsu_dma_pci", 115 + .id_table = hsu_pci_id_table, 116 + .probe = hsu_pci_probe, 117 + .remove = hsu_pci_remove, 118 + }; 119 + 120 + module_pci_driver(hsu_pci_driver); 121 + 122 + MODULE_LICENSE("GPL v2"); 123 + MODULE_DESCRIPTION("High Speed UART DMA PCI driver"); 124 + MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
+2 -2
drivers/firmware/pcdp.c
··· 15 15 #include <linux/console.h> 16 16 #include <linux/efi.h> 17 17 #include <linux/serial.h> 18 - #include <linux/serial_8250.h> 18 + #include <linux/serial_core.h> 19 19 #include <asm/vga.h> 20 20 #include "pcdp.h" 21 21 ··· 43 43 } 44 44 45 45 add_preferred_console("uart", 8250, &options[9]); 46 - return setup_early_serial8250_console(options); 46 + return setup_earlycon(options); 47 47 #else 48 48 return -ENODEV; 49 49 #endif
+1 -1
drivers/tty/hvc/hvc_opal.c
··· 41 41 42 42 static const char hvc_opal_name[] = "hvc_opal"; 43 43 44 - static struct of_device_id hvc_opal_match[] = { 44 + static const struct of_device_id hvc_opal_match[] = { 45 45 { .name = "serial", .compatible = "ibm,opal-console-raw" }, 46 46 { .name = "serial", .compatible = "ibm,opal-console-hvsi" }, 47 47 { },
+6 -6
drivers/tty/n_gsm.c
··· 2669 2669 static int gsm_mux_net_start_xmit(struct sk_buff *skb, 2670 2670 struct net_device *net) 2671 2671 { 2672 - struct gsm_mux_net *mux_net = (struct gsm_mux_net *)netdev_priv(net); 2672 + struct gsm_mux_net *mux_net = netdev_priv(net); 2673 2673 struct gsm_dlci *dlci = mux_net->dlci; 2674 2674 muxnet_get(mux_net); 2675 2675 ··· 2698 2698 { 2699 2699 struct net_device *net = dlci->net; 2700 2700 struct sk_buff *skb; 2701 - struct gsm_mux_net *mux_net = (struct gsm_mux_net *)netdev_priv(net); 2701 + struct gsm_mux_net *mux_net = netdev_priv(net); 2702 2702 muxnet_get(mux_net); 2703 2703 2704 2704 /* Allocate an sk_buff */ ··· 2727 2727 2728 2728 static int gsm_change_mtu(struct net_device *net, int new_mtu) 2729 2729 { 2730 - struct gsm_mux_net *mux_net = (struct gsm_mux_net *)netdev_priv(net); 2730 + struct gsm_mux_net *mux_net = netdev_priv(net); 2731 2731 if ((new_mtu < 8) || (new_mtu > mux_net->dlci->gsm->mtu)) 2732 2732 return -EINVAL; 2733 2733 net->mtu = new_mtu; ··· 2763 2763 pr_debug("destroy network interface"); 2764 2764 if (!dlci->net) 2765 2765 return; 2766 - mux_net = (struct gsm_mux_net *)netdev_priv(dlci->net); 2766 + mux_net = netdev_priv(dlci->net); 2767 2767 muxnet_put(mux_net); 2768 2768 } 2769 2769 ··· 2801 2801 return -ENOMEM; 2802 2802 } 2803 2803 net->mtu = dlci->gsm->mtu; 2804 - mux_net = (struct gsm_mux_net *)netdev_priv(net); 2804 + mux_net = netdev_priv(net); 2805 2805 mux_net->dlci = dlci; 2806 2806 kref_init(&mux_net->ref); 2807 2807 strncpy(nc->if_name, net->name, IFNAMSIZ); /* return net name */ ··· 2824 2824 } 2825 2825 2826 2826 /* Line discipline for real tty */ 2827 - struct tty_ldisc_ops tty_ldisc_packet = { 2827 + static struct tty_ldisc_ops tty_ldisc_packet = { 2828 2828 .owner = THIS_MODULE, 2829 2829 .magic = TTY_LDISC_MAGIC, 2830 2830 .name = "n_gsm",
+18 -5
drivers/tty/serial/8250/8250.h
··· 21 21 22 22 /* Filter function */ 23 23 dma_filter_fn fn; 24 - 25 24 /* Parameter to the filter function */ 26 25 void *rx_param; 27 26 void *tx_param; ··· 52 53 unsigned int baud_base; 53 54 unsigned int port; 54 55 unsigned int irq; 55 - unsigned int flags; 56 + upf_t flags; 56 57 unsigned char hub6; 57 58 unsigned char io_type; 58 59 unsigned char __iomem *iomem_base; ··· 83 84 #define UART_BUG_NOMSR (1 << 2) /* UART has buggy MSR status bits (Au1x00) */ 84 85 #define UART_BUG_THRE (1 << 3) /* UART has buggy THRE reassertion */ 85 86 #define UART_BUG_PARITY (1 << 4) /* UART mishandles parity if FIFO enabled */ 86 - 87 - #define PROBE_RSA (1 << 0) 88 - #define PROBE_ANY (~0) 89 87 90 88 #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8) 91 89 ··· 194 198 } 195 199 static inline void serial8250_release_dma(struct uart_8250_port *p) { } 196 200 #endif 201 + 202 + static inline int ns16550a_goto_highspeed(struct uart_8250_port *up) 203 + { 204 + unsigned char status; 205 + 206 + status = serial_in(up, 0x04); /* EXCR2 */ 207 + #define PRESL(x) ((x) & 0x30) 208 + if (PRESL(status) == 0x10) { 209 + /* already in high speed mode */ 210 + return 0; 211 + } else { 212 + status &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ 213 + status |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ 214 + serial_out(up, 0x04, status); 215 + } 216 + return 1; 217 + }
+330 -167
drivers/tty/serial/8250/8250_core.c
··· 31 31 #include <linux/tty.h> 32 32 #include <linux/ratelimit.h> 33 33 #include <linux/tty_flip.h> 34 - #include <linux/serial_core.h> 35 34 #include <linux/serial.h> 36 35 #include <linux/serial_8250.h> 37 36 #include <linux/nmi.h> ··· 60 61 61 62 static int serial_index(struct uart_port *port) 62 63 { 63 - return (serial8250_reg.minor - 64) + port->line; 64 + return port->minor - 64; 64 65 } 65 66 66 67 static unsigned int skip_txen_test; /* force skip of txen test at init time */ ··· 357 358 #if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X) 358 359 359 360 /* Au1x00/RT288x UART hardware has a weird register layout */ 360 - static const u8 au_io_in_map[] = { 361 - [UART_RX] = 0, 362 - [UART_IER] = 2, 363 - [UART_IIR] = 3, 364 - [UART_LCR] = 5, 365 - [UART_MCR] = 6, 366 - [UART_LSR] = 7, 367 - [UART_MSR] = 8, 361 + static const s8 au_io_in_map[8] = { 362 + 0, /* UART_RX */ 363 + 2, /* UART_IER */ 364 + 3, /* UART_IIR */ 365 + 5, /* UART_LCR */ 366 + 6, /* UART_MCR */ 367 + 7, /* UART_LSR */ 368 + 8, /* UART_MSR */ 369 + -1, /* UART_SCR (unmapped) */ 368 370 }; 369 371 370 - static const u8 au_io_out_map[] = { 371 - [UART_TX] = 1, 372 - [UART_IER] = 2, 373 - [UART_FCR] = 4, 374 - [UART_LCR] = 5, 375 - [UART_MCR] = 6, 372 + static const s8 au_io_out_map[8] = { 373 + 1, /* UART_TX */ 374 + 2, /* UART_IER */ 375 + 4, /* UART_FCR */ 376 + 5, /* UART_LCR */ 377 + 6, /* UART_MCR */ 378 + -1, /* UART_LSR (unmapped) */ 379 + -1, /* UART_MSR (unmapped) */ 380 + -1, /* UART_SCR (unmapped) */ 376 381 }; 377 382 378 383 static unsigned int au_serial_in(struct uart_port *p, int offset) 379 384 { 380 - offset = au_io_in_map[offset] << p->regshift; 381 - return __raw_readl(p->membase + offset); 385 + if (offset >= ARRAY_SIZE(au_io_in_map)) 386 + return UINT_MAX; 387 + offset = au_io_in_map[offset]; 388 + if (offset < 0) 389 + return UINT_MAX; 390 + return __raw_readl(p->membase + (offset << p->regshift)); 382 391 } 383 392 384 393 static void au_serial_out(struct uart_port *p, int offset, int value) 385 394 { 386 - offset = au_io_out_map[offset] << p->regshift; 387 - __raw_writel(value, p->membase + offset); 395 + if (offset >= ARRAY_SIZE(au_io_out_map)) 396 + return; 397 + offset = au_io_out_map[offset]; 398 + if (offset < 0) 399 + return; 400 + __raw_writel(value, p->membase + (offset << p->regshift)); 388 401 } 389 402 390 403 /* Au1x00 haven't got a standard divisor latch */ ··· 906 895 /* 907 896 * Exar ST16C2550 "A2" devices incorrectly detect as 908 897 * having an EFR, and report an ID of 0x0201. See 909 - * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html 898 + * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html 910 899 */ 911 900 if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16) 912 901 return 1; 913 902 914 903 return 0; 915 - } 916 - 917 - static inline int ns16550a_goto_highspeed(struct uart_8250_port *up) 918 - { 919 - unsigned char status; 920 - 921 - status = serial_in(up, 0x04); /* EXCR2 */ 922 - #define PRESL(x) ((x) & 0x30) 923 - if (PRESL(status) == 0x10) { 924 - /* already in high speed mode */ 925 - return 0; 926 - } else { 927 - status &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ 928 - status |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ 929 - serial_out(up, 0x04, status); 930 - } 931 - return 1; 932 904 } 933 905 934 906 /* ··· 1116 1122 * whether or not this UART is a 16550A or not, since this will 1117 1123 * determine whether or not we can use its FIFO features or not. 1118 1124 */ 1119 - static void autoconfig(struct uart_8250_port *up, unsigned int probeflags) 1125 + static void autoconfig(struct uart_8250_port *up) 1120 1126 { 1121 1127 unsigned char status1, scratch, scratch2, scratch3; 1122 1128 unsigned char save_lcr, save_mcr; ··· 1239 1245 /* 1240 1246 * Only probe for RSA ports if we got the region. 1241 1247 */ 1242 - if (port->type == PORT_16550A && probeflags & PROBE_RSA) { 1243 - int i; 1244 - 1245 - for (i = 0 ; i < probe_rsa_count; ++i) { 1246 - if (probe_rsa[i] == port->iobase && __enable_rsa(up)) { 1247 - port->type = PORT_RSA; 1248 - break; 1249 - } 1250 - } 1251 - } 1248 + if (port->type == PORT_16550A && up->probe & UART_PROBE_RSA && 1249 + __enable_rsa(up)) 1250 + port->type = PORT_RSA; 1252 1251 #endif 1253 1252 1254 1253 serial_out(up, UART_LCR, save_lcr); 1255 1254 1256 1255 port->fifosize = uart_config[up->port.type].fifo_size; 1257 - old_capabilities = up->capabilities; 1256 + old_capabilities = up->capabilities; 1258 1257 up->capabilities = uart_config[port->type].flags; 1259 1258 up->tx_loadsz = uart_config[port->type].tx_loadsz; 1260 1259 ··· 1894 1907 jiffies + uart_poll_timeout(&up->port) + HZ / 5); 1895 1908 } 1896 1909 1910 + static int univ8250_setup_irq(struct uart_8250_port *up) 1911 + { 1912 + struct uart_port *port = &up->port; 1913 + int retval = 0; 1914 + 1915 + /* 1916 + * The above check will only give an accurate result the first time 1917 + * the port is opened so this value needs to be preserved. 1918 + */ 1919 + if (up->bugs & UART_BUG_THRE) { 1920 + pr_debug("ttyS%d - using backup timer\n", serial_index(port)); 1921 + 1922 + up->timer.function = serial8250_backup_timeout; 1923 + up->timer.data = (unsigned long)up; 1924 + mod_timer(&up->timer, jiffies + 1925 + uart_poll_timeout(port) + HZ / 5); 1926 + } 1927 + 1928 + /* 1929 + * If the "interrupt" for this port doesn't correspond with any 1930 + * hardware interrupt, we use a timer-based system. The original 1931 + * driver used to do this with IRQ0. 1932 + */ 1933 + if (!port->irq) { 1934 + up->timer.data = (unsigned long)up; 1935 + mod_timer(&up->timer, jiffies + uart_poll_timeout(port)); 1936 + } else 1937 + retval = serial_link_irq_chain(up); 1938 + 1939 + return retval; 1940 + } 1941 + 1942 + static void univ8250_release_irq(struct uart_8250_port *up) 1943 + { 1944 + struct uart_port *port = &up->port; 1945 + 1946 + del_timer_sync(&up->timer); 1947 + up->timer.function = serial8250_timeout; 1948 + if (port->irq) 1949 + serial_unlink_irq_chain(up); 1950 + } 1951 + 1897 1952 static unsigned int serial8250_tx_empty(struct uart_port *port) 1898 1953 { 1899 1954 struct uart_8250_port *up = up_to_u8250p(port); ··· 2240 2211 if ((!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) || 2241 2212 up->port.flags & UPF_BUG_THRE) { 2242 2213 up->bugs |= UART_BUG_THRE; 2243 - pr_debug("ttyS%d - using backup timer\n", 2244 - serial_index(port)); 2245 2214 } 2246 2215 } 2247 2216 2248 - /* 2249 - * The above check will only give an accurate result the first time 2250 - * the port is opened so this value needs to be preserved. 2251 - */ 2252 - if (up->bugs & UART_BUG_THRE) { 2253 - up->timer.function = serial8250_backup_timeout; 2254 - up->timer.data = (unsigned long)up; 2255 - mod_timer(&up->timer, jiffies + 2256 - uart_poll_timeout(port) + HZ / 5); 2257 - } 2258 - 2259 - /* 2260 - * If the "interrupt" for this port doesn't correspond with any 2261 - * hardware interrupt, we use a timer-based system. The original 2262 - * driver used to do this with IRQ0. 2263 - */ 2264 - if (!port->irq) { 2265 - up->timer.data = (unsigned long)up; 2266 - mod_timer(&up->timer, jiffies + uart_poll_timeout(port)); 2267 - } else { 2268 - retval = serial_link_irq_chain(up); 2269 - if (retval) 2270 - goto out; 2271 - } 2217 + retval = up->ops->setup_irq(up); 2218 + if (retval) 2219 + goto out; 2272 2220 2273 2221 /* 2274 2222 * Now, initialize the UART ··· 2276 2270 is variable. So, let's just don't test if we receive 2277 2271 TX irq. This way, we'll never enable UART_BUG_TXEN. 2278 2272 */ 2279 - if (skip_txen_test || up->port.flags & UPF_NO_TXEN_TEST) 2273 + if (up->port.flags & UPF_NO_TXEN_TEST) 2280 2274 goto dont_test_tx_en; 2281 2275 2282 2276 /* ··· 2403 2397 serial_port_in(port, UART_RX); 2404 2398 serial8250_rpm_put(up); 2405 2399 2406 - del_timer_sync(&up->timer); 2407 - up->timer.function = serial8250_timeout; 2408 - if (port->irq) 2409 - serial_unlink_irq_chain(up); 2400 + up->ops->release_irq(up); 2410 2401 } 2411 2402 EXPORT_SYMBOL_GPL(serial8250_do_shutdown); 2412 2403 ··· 2722 2719 2723 2720 static unsigned int serial8250_port_size(struct uart_8250_port *pt) 2724 2721 { 2722 + if (pt->port.mapsize) 2723 + return pt->port.mapsize; 2725 2724 if (pt->port.iotype == UPIO_AU) { 2726 2725 if (pt->port.type == PORT_RT2880) 2727 2726 return 0x100; ··· 2803 2798 } 2804 2799 } 2805 2800 2801 + #ifdef CONFIG_SERIAL_8250_RSA 2806 2802 static int serial8250_request_rsa_resource(struct uart_8250_port *up) 2807 2803 { 2808 2804 unsigned long start = UART_RSA_BASE << up->port.regshift; ··· 2838 2832 break; 2839 2833 } 2840 2834 } 2835 + #endif 2841 2836 2842 2837 static void serial8250_release_port(struct uart_port *port) 2843 2838 { 2844 2839 struct uart_8250_port *up = up_to_u8250p(port); 2845 2840 2846 2841 serial8250_release_std_resource(up); 2847 - if (port->type == PORT_RSA) 2848 - serial8250_release_rsa_resource(up); 2849 2842 } 2850 2843 2851 2844 static int serial8250_request_port(struct uart_port *port) ··· 2856 2851 return -ENODEV; 2857 2852 2858 2853 ret = serial8250_request_std_resource(up); 2859 - if (ret == 0 && port->type == PORT_RSA) { 2860 - ret = serial8250_request_rsa_resource(up); 2861 - if (ret < 0) 2862 - serial8250_release_std_resource(up); 2863 - } 2864 2854 2865 2855 return ret; 2866 2856 } ··· 3003 3003 static void serial8250_config_port(struct uart_port *port, int flags) 3004 3004 { 3005 3005 struct uart_8250_port *up = up_to_u8250p(port); 3006 - int probeflags = PROBE_ANY; 3007 3006 int ret; 3008 3007 3009 3008 if (port->type == PORT_8250_CIR) ··· 3016 3017 if (ret < 0) 3017 3018 return; 3018 3019 3019 - ret = serial8250_request_rsa_resource(up); 3020 - if (ret < 0) 3021 - probeflags &= ~PROBE_RSA; 3022 - 3023 3020 if (port->iotype != up->cur_iotype) 3024 3021 set_io_from_upio(port); 3025 3022 3026 3023 if (flags & UART_CONFIG_TYPE) 3027 - autoconfig(up, probeflags); 3024 + autoconfig(up); 3028 3025 3029 3026 /* if access method is AU, it is a 16550 with a quirk */ 3030 3027 if (port->type == PORT_16550A && port->iotype == UPIO_AU) ··· 3033 3038 if (port->type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) 3034 3039 autoconfig_irq(up); 3035 3040 3036 - if (port->type != PORT_RSA && probeflags & PROBE_RSA) 3037 - serial8250_release_rsa_resource(up); 3038 3041 if (port->type == PORT_UNKNOWN) 3039 3042 serial8250_release_std_resource(up); 3040 3043 ··· 3066 3073 return uart_config[type].name; 3067 3074 } 3068 3075 3069 - static struct uart_ops serial8250_pops = { 3076 + static const struct uart_ops serial8250_pops = { 3070 3077 .tx_empty = serial8250_tx_empty, 3071 3078 .set_mctrl = serial8250_set_mctrl, 3072 3079 .get_mctrl = serial8250_get_mctrl, ··· 3091 3098 .poll_get_char = serial8250_get_poll_char, 3092 3099 .poll_put_char = serial8250_put_poll_char, 3093 3100 #endif 3101 + }; 3102 + 3103 + static const struct uart_ops *base_ops; 3104 + static struct uart_ops univ8250_port_ops; 3105 + 3106 + static const struct uart_8250_ops univ8250_driver_ops = { 3107 + .setup_irq = univ8250_setup_irq, 3108 + .release_irq = univ8250_release_irq, 3094 3109 }; 3095 3110 3096 3111 static struct uart_8250_port serial8250_ports[UART_NR]; ··· 3131 3130 } 3132 3131 EXPORT_SYMBOL(serial8250_set_isa_configurator); 3133 3132 3133 + static void serial8250_init_port(struct uart_8250_port *up) 3134 + { 3135 + struct uart_port *port = &up->port; 3136 + 3137 + spin_lock_init(&port->lock); 3138 + port->ops = &serial8250_pops; 3139 + 3140 + up->cur_iotype = 0xFF; 3141 + } 3142 + 3143 + static void serial8250_set_defaults(struct uart_8250_port *up) 3144 + { 3145 + struct uart_port *port = &up->port; 3146 + 3147 + if (up->port.flags & UPF_FIXED_TYPE) { 3148 + unsigned int type = up->port.type; 3149 + 3150 + if (!up->port.fifosize) 3151 + up->port.fifosize = uart_config[type].fifo_size; 3152 + if (!up->tx_loadsz) 3153 + up->tx_loadsz = uart_config[type].tx_loadsz; 3154 + if (!up->capabilities) 3155 + up->capabilities = uart_config[type].flags; 3156 + } 3157 + 3158 + set_io_from_upio(port); 3159 + 3160 + /* default dma handlers */ 3161 + if (up->dma) { 3162 + if (!up->dma->tx_dma) 3163 + up->dma->tx_dma = serial8250_tx_dma; 3164 + if (!up->dma->rx_dma) 3165 + up->dma->rx_dma = serial8250_rx_dma; 3166 + } 3167 + } 3168 + 3169 + #ifdef CONFIG_SERIAL_8250_RSA 3170 + 3171 + static void univ8250_config_port(struct uart_port *port, int flags) 3172 + { 3173 + struct uart_8250_port *up = up_to_u8250p(port); 3174 + 3175 + up->probe &= ~UART_PROBE_RSA; 3176 + if (port->type == PORT_RSA) { 3177 + if (serial8250_request_rsa_resource(up) == 0) 3178 + up->probe |= UART_PROBE_RSA; 3179 + } else if (flags & UART_CONFIG_TYPE) { 3180 + int i; 3181 + 3182 + for (i = 0; i < probe_rsa_count; i++) { 3183 + if (probe_rsa[i] == up->port.iobase) { 3184 + if (serial8250_request_rsa_resource(up) == 0) 3185 + up->probe |= UART_PROBE_RSA; 3186 + break; 3187 + } 3188 + } 3189 + } 3190 + 3191 + base_ops->config_port(port, flags); 3192 + 3193 + if (port->type != PORT_RSA && up->probe & UART_PROBE_RSA) 3194 + serial8250_release_rsa_resource(up); 3195 + } 3196 + 3197 + static int univ8250_request_port(struct uart_port *port) 3198 + { 3199 + struct uart_8250_port *up = up_to_u8250p(port); 3200 + int ret; 3201 + 3202 + ret = base_ops->request_port(port); 3203 + if (ret == 0 && port->type == PORT_RSA) { 3204 + ret = serial8250_request_rsa_resource(up); 3205 + if (ret < 0) 3206 + base_ops->release_port(port); 3207 + } 3208 + 3209 + return ret; 3210 + } 3211 + 3212 + static void univ8250_release_port(struct uart_port *port) 3213 + { 3214 + struct uart_8250_port *up = up_to_u8250p(port); 3215 + 3216 + if (port->type == PORT_RSA) 3217 + serial8250_release_rsa_resource(up); 3218 + base_ops->release_port(port); 3219 + } 3220 + 3221 + static void univ8250_rsa_support(struct uart_ops *ops) 3222 + { 3223 + ops->config_port = univ8250_config_port; 3224 + ops->request_port = univ8250_request_port; 3225 + ops->release_port = univ8250_release_port; 3226 + } 3227 + 3228 + #else 3229 + #define univ8250_rsa_support(x) do { } while (0) 3230 + #endif /* CONFIG_SERIAL_8250_RSA */ 3231 + 3134 3232 static void __init serial8250_isa_init_ports(void) 3135 3233 { 3136 3234 struct uart_8250_port *up; ··· 3248 3148 struct uart_port *port = &up->port; 3249 3149 3250 3150 port->line = i; 3251 - spin_lock_init(&port->lock); 3151 + serial8250_init_port(up); 3152 + if (!base_ops) 3153 + base_ops = port->ops; 3154 + port->ops = &univ8250_port_ops; 3252 3155 3253 3156 init_timer(&up->timer); 3254 3157 up->timer.function = serial8250_timeout; 3255 - up->cur_iotype = 0xFF; 3158 + 3159 + up->ops = &univ8250_driver_ops; 3256 3160 3257 3161 /* 3258 3162 * ALPHA_KLUDGE_MCR needs to be killed. 3259 3163 */ 3260 3164 up->mcr_mask = ~ALPHA_KLUDGE_MCR; 3261 3165 up->mcr_force = ALPHA_KLUDGE_MCR; 3262 - 3263 - port->ops = &serial8250_pops; 3264 3166 } 3167 + 3168 + /* chain base port ops to support Remote Supervisor Adapter */ 3169 + univ8250_port_ops = *base_ops; 3170 + univ8250_rsa_support(&univ8250_port_ops); 3265 3171 3266 3172 if (share_irqs) 3267 3173 irqflag = IRQF_SHARED; ··· 3286 3180 port->membase = old_serial_port[i].iomem_base; 3287 3181 port->iotype = old_serial_port[i].io_type; 3288 3182 port->regshift = old_serial_port[i].iomem_reg_shift; 3289 - set_io_from_upio(port); 3183 + serial8250_set_defaults(up); 3184 + 3290 3185 port->irqflags |= irqflag; 3291 3186 if (serial8250_isa_config != NULL) 3292 3187 serial8250_isa_config(i, &up->port, &up->capabilities); 3293 - 3294 3188 } 3295 - } 3296 - 3297 - static void 3298 - serial8250_init_fixed_type_port(struct uart_8250_port *up, unsigned int type) 3299 - { 3300 - up->port.type = type; 3301 - if (!up->port.fifosize) 3302 - up->port.fifosize = uart_config[type].fifo_size; 3303 - if (!up->tx_loadsz) 3304 - up->tx_loadsz = uart_config[type].tx_loadsz; 3305 - if (!up->capabilities) 3306 - up->capabilities = uart_config[type].flags; 3307 3189 } 3308 3190 3309 3191 static void __init ··· 3307 3213 3308 3214 up->port.dev = dev; 3309 3215 3310 - if (up->port.flags & UPF_FIXED_TYPE) 3311 - serial8250_init_fixed_type_port(up, up->port.type); 3216 + if (skip_txen_test) 3217 + up->port.flags |= UPF_NO_TXEN_TEST; 3312 3218 3313 3219 uart_add_one_port(drv, &up->port); 3314 3220 } ··· 3330 3236 * 3331 3237 * The console_lock must be held when we get here. 3332 3238 */ 3333 - static void 3334 - serial8250_console_write(struct console *co, const char *s, unsigned int count) 3239 + static void serial8250_console_write(struct uart_8250_port *up, const char *s, 3240 + unsigned int count) 3335 3241 { 3336 - struct uart_8250_port *up = &serial8250_ports[co->index]; 3337 3242 struct uart_port *port = &up->port; 3338 3243 unsigned long flags; 3339 3244 unsigned int ier; ··· 3404 3311 serial8250_rpm_put(up); 3405 3312 } 3406 3313 3407 - static int serial8250_console_setup(struct console *co, char *options) 3314 + static void univ8250_console_write(struct console *co, const char *s, 3315 + unsigned int count) 3408 3316 { 3409 - struct uart_port *port; 3317 + struct uart_8250_port *up = &serial8250_ports[co->index]; 3318 + 3319 + serial8250_console_write(up, s, count); 3320 + } 3321 + 3322 + static unsigned int probe_baud(struct uart_port *port) 3323 + { 3324 + unsigned char lcr, dll, dlm; 3325 + unsigned int quot; 3326 + 3327 + lcr = serial_port_in(port, UART_LCR); 3328 + serial_port_out(port, UART_LCR, lcr | UART_LCR_DLAB); 3329 + dll = serial_port_in(port, UART_DLL); 3330 + dlm = serial_port_in(port, UART_DLM); 3331 + serial_port_out(port, UART_LCR, lcr); 3332 + 3333 + quot = (dlm << 8) | dll; 3334 + return (port->uartclk / 16) / quot; 3335 + } 3336 + 3337 + static int serial8250_console_setup(struct uart_port *port, char *options, bool probe) 3338 + { 3410 3339 int baud = 9600; 3411 3340 int bits = 8; 3412 3341 int parity = 'n'; 3413 3342 int flow = 'n'; 3343 + 3344 + if (!port->iobase && !port->membase) 3345 + return -ENODEV; 3346 + 3347 + if (options) 3348 + uart_parse_options(options, &baud, &parity, &bits, &flow); 3349 + else if (probe) 3350 + baud = probe_baud(port); 3351 + 3352 + return uart_set_options(port, port->cons, baud, parity, bits, flow); 3353 + } 3354 + 3355 + static int univ8250_console_setup(struct console *co, char *options) 3356 + { 3357 + struct uart_port *port; 3414 3358 3415 3359 /* 3416 3360 * Check whether an invalid uart number has been specified, and ··· 3457 3327 if (co->index >= nr_uarts) 3458 3328 co->index = 0; 3459 3329 port = &serial8250_ports[co->index].port; 3460 - if (!port->iobase && !port->membase) 3330 + /* link port to console */ 3331 + port->cons = co; 3332 + 3333 + return serial8250_console_setup(port, options, false); 3334 + } 3335 + 3336 + /** 3337 + * univ8250_console_match - non-standard console matching 3338 + * @co: registering console 3339 + * @name: name from console command line 3340 + * @idx: index from console command line 3341 + * @options: ptr to option string from console command line 3342 + * 3343 + * Only attempts to match console command lines of the form: 3344 + * console=uart[8250],io|mmio|mmio32,<addr>[,<options>] 3345 + * console=uart[8250],0x<addr>[,<options>] 3346 + * This form is used to register an initial earlycon boot console and 3347 + * replace it with the serial8250_console at 8250 driver init. 3348 + * 3349 + * Performs console setup for a match (as required by interface) 3350 + * If no <options> are specified, then assume the h/w is already setup. 3351 + * 3352 + * Returns 0 if console matches; otherwise non-zero to use default matching 3353 + */ 3354 + static int univ8250_console_match(struct console *co, char *name, int idx, 3355 + char *options) 3356 + { 3357 + char match[] = "uart"; /* 8250-specific earlycon name */ 3358 + unsigned char iotype; 3359 + unsigned long addr; 3360 + int i; 3361 + 3362 + if (strncmp(name, match, 4) != 0) 3461 3363 return -ENODEV; 3462 3364 3463 - if (options) 3464 - uart_parse_options(options, &baud, &parity, &bits, &flow); 3365 + if (uart_parse_earlycon(options, &iotype, &addr, &options)) 3366 + return -ENODEV; 3465 3367 3466 - return uart_set_options(port, co, baud, parity, bits, flow); 3368 + /* try to match the port specified on the command line */ 3369 + for (i = 0; i < nr_uarts; i++) { 3370 + struct uart_port *port = &serial8250_ports[i].port; 3371 + 3372 + if (port->iotype != iotype) 3373 + continue; 3374 + if ((iotype == UPIO_MEM || iotype == UPIO_MEM32) && 3375 + (port->mapbase != addr)) 3376 + continue; 3377 + if (iotype == UPIO_PORT && port->iobase != addr) 3378 + continue; 3379 + 3380 + co->index = i; 3381 + port->cons = co; 3382 + return serial8250_console_setup(port, options, true); 3383 + } 3384 + 3385 + return -ENODEV; 3467 3386 } 3468 3387 3469 - static int serial8250_console_early_setup(void) 3470 - { 3471 - return serial8250_find_port_for_earlycon(); 3472 - } 3473 - 3474 - static struct console serial8250_console = { 3388 + static struct console univ8250_console = { 3475 3389 .name = "ttyS", 3476 - .write = serial8250_console_write, 3390 + .write = univ8250_console_write, 3477 3391 .device = uart_console_device, 3478 - .setup = serial8250_console_setup, 3479 - .early_setup = serial8250_console_early_setup, 3392 + .setup = univ8250_console_setup, 3393 + .match = univ8250_console_match, 3480 3394 .flags = CON_PRINTBUFFER | CON_ANYTIME, 3481 3395 .index = -1, 3482 3396 .data = &serial8250_reg, 3483 3397 }; 3484 3398 3485 - static int __init serial8250_console_init(void) 3399 + static int __init univ8250_console_init(void) 3486 3400 { 3487 3401 serial8250_isa_init_ports(); 3488 - register_console(&serial8250_console); 3402 + register_console(&univ8250_console); 3489 3403 return 0; 3490 3404 } 3491 - console_initcall(serial8250_console_init); 3405 + console_initcall(univ8250_console_init); 3492 3406 3493 - int serial8250_find_port(struct uart_port *p) 3494 - { 3495 - int line; 3496 - struct uart_port *port; 3497 - 3498 - for (line = 0; line < nr_uarts; line++) { 3499 - port = &serial8250_ports[line].port; 3500 - if (uart_match_port(p, port)) 3501 - return line; 3502 - } 3503 - return -ENODEV; 3504 - } 3505 - 3506 - #define SERIAL8250_CONSOLE &serial8250_console 3407 + #define SERIAL8250_CONSOLE &univ8250_console 3507 3408 #else 3508 3409 #define SERIAL8250_CONSOLE NULL 3509 3410 #endif ··· 3573 3412 p->iotype = port->iotype; 3574 3413 p->flags = port->flags; 3575 3414 p->mapbase = port->mapbase; 3415 + p->mapsize = port->mapsize; 3576 3416 p->private_data = port->private_data; 3577 3417 p->type = port->type; 3578 3418 p->line = port->line; 3579 3419 3580 - set_io_from_upio(p); 3420 + serial8250_set_defaults(up_to_u8250p(p)); 3421 + 3581 3422 if (port->serial_in) 3582 3423 p->serial_in = port->serial_in; 3583 3424 if (port->serial_out) 3584 3425 p->serial_out = port->serial_out; 3585 3426 if (port->handle_irq) 3586 3427 p->handle_irq = port->handle_irq; 3587 - else 3588 - p->handle_irq = serial8250_default_handle_irq; 3589 3428 3590 3429 return 0; 3591 3430 } ··· 3605 3444 port->type != PORT_8250) { 3606 3445 unsigned char canary = 0xa5; 3607 3446 serial_out(up, UART_SCR, canary); 3608 - up->canary = canary; 3447 + if (serial_in(up, UART_SCR) == canary) 3448 + up->canary = canary; 3609 3449 } 3610 3450 3611 3451 uart_suspend_port(&serial8250_reg, port); ··· 3828 3666 uart->port.flags = up->port.flags | UPF_BOOT_AUTOCONF; 3829 3667 uart->bugs = up->bugs; 3830 3668 uart->port.mapbase = up->port.mapbase; 3669 + uart->port.mapsize = up->port.mapsize; 3831 3670 uart->port.private_data = up->port.private_data; 3832 3671 uart->port.fifosize = up->port.fifosize; 3833 3672 uart->tx_loadsz = up->tx_loadsz; ··· 3837 3674 uart->port.unthrottle = up->port.unthrottle; 3838 3675 uart->port.rs485_config = up->port.rs485_config; 3839 3676 uart->port.rs485 = up->port.rs485; 3677 + uart->dma = up->dma; 3840 3678 3841 3679 /* Take tx_loadsz from fifosize if it wasn't set separately */ 3842 3680 if (uart->port.fifosize && !uart->tx_loadsz) ··· 3846 3682 if (up->port.dev) 3847 3683 uart->port.dev = up->port.dev; 3848 3684 3849 - if (up->port.flags & UPF_FIXED_TYPE) 3850 - serial8250_init_fixed_type_port(uart, up->port.type); 3685 + if (skip_txen_test) 3686 + uart->port.flags |= UPF_NO_TXEN_TEST; 3851 3687 3852 - set_io_from_upio(&uart->port); 3688 + if (up->port.flags & UPF_FIXED_TYPE) 3689 + uart->port.type = up->port.type; 3690 + 3691 + serial8250_set_defaults(uart); 3692 + 3853 3693 /* Possibly override default I/O functions. */ 3854 3694 if (up->port.serial_in) 3855 3695 uart->port.serial_in = up->port.serial_in; ··· 3878 3710 uart->dl_read = up->dl_read; 3879 3711 if (up->dl_write) 3880 3712 uart->dl_write = up->dl_write; 3881 - if (up->dma) { 3882 - uart->dma = up->dma; 3883 - if (!uart->dma->tx_dma) 3884 - uart->dma->tx_dma = serial8250_tx_dma; 3885 - if (!uart->dma->rx_dma) 3886 - uart->dma->rx_dma = serial8250_rx_dma; 3887 - } 3888 3713 3889 3714 if (serial8250_isa_config != NULL) 3890 3715 serial8250_isa_config(0, &uart->port, ··· 3908 3747 uart_remove_one_port(&serial8250_reg, &uart->port); 3909 3748 if (serial8250_isa_devs) { 3910 3749 uart->port.flags &= ~UPF_BOOT_AUTOCONF; 3750 + if (skip_txen_test) 3751 + uart->port.flags |= UPF_NO_TXEN_TEST; 3911 3752 uart->port.type = PORT_UNKNOWN; 3912 3753 uart->port.dev = &serial8250_isa_devs->dev; 3913 - uart->capabilities = uart_config[uart->port.type].flags; 3754 + uart->capabilities = 0; 3914 3755 uart_add_one_port(&serial8250_reg, &uart->port); 3915 3756 } else { 3916 3757 uart->port.dev = NULL;
+28 -30
drivers/tty/serial/8250/8250_dw.c
··· 17 17 #include <linux/io.h> 18 18 #include <linux/module.h> 19 19 #include <linux/serial_8250.h> 20 - #include <linux/serial_core.h> 21 20 #include <linux/serial_reg.h> 22 21 #include <linux/of.h> 23 22 #include <linux/of_irq.h> ··· 363 364 } 364 365 365 366 if (of_property_read_bool(np, "cts-override")) { 366 - /* Always report DSR as active */ 367 - data->msr_mask_on |= UART_MSR_DSR; 368 - data->msr_mask_off |= UART_MSR_DDSR; 367 + /* Always report CTS as active */ 368 + data->msr_mask_on |= UART_MSR_CTS; 369 + data->msr_mask_off |= UART_MSR_DCTS; 369 370 } 370 371 371 372 if (of_property_read_bool(np, "ri-override")) { ··· 374 375 data->msr_mask_off |= UART_MSR_TERI; 375 376 } 376 377 377 - /* clock got configured through clk api, all done */ 378 - if (p->uartclk) 379 - return 0; 380 - 381 - /* try to find out clock frequency from DT as fallback */ 382 - if (of_property_read_u32(np, "clock-frequency", &val)) { 383 - dev_err(p->dev, "clk or clock-frequency not defined\n"); 384 - return -EINVAL; 385 - } 386 - p->uartclk = val; 387 - 388 378 return 0; 389 379 } 390 380 391 381 static int dw8250_probe_acpi(struct uart_8250_port *up, 392 382 struct dw8250_data *data) 393 383 { 394 - const struct acpi_device_id *id; 395 384 struct uart_port *p = &up->port; 396 385 397 386 dw8250_setup_port(up); 398 - 399 - id = acpi_match_device(p->dev->driver->acpi_match_table, p->dev); 400 - if (!id) 401 - return -ENODEV; 402 - 403 - if (!p->uartclk) 404 - if (device_property_read_u32(p->dev, "clock-frequency", 405 - &p->uartclk)) 406 - return -EINVAL; 407 387 408 388 p->iotype = UPIO_MEM32; 409 389 p->serial_in = dw8250_serial_in32; ··· 403 425 { 404 426 struct uart_8250_port uart = {}; 405 427 struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 406 - struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 428 + int irq = platform_get_irq(pdev, 0); 407 429 struct dw8250_data *data; 408 430 int err; 409 431 410 - if (!regs || !irq) { 411 - dev_err(&pdev->dev, "no registers/irq defined\n"); 432 + if (!regs) { 433 + dev_err(&pdev->dev, "no registers defined\n"); 412 434 return -EINVAL; 435 + } 436 + 437 + if (irq < 0) { 438 + if (irq != -EPROBE_DEFER) 439 + dev_err(&pdev->dev, "cannot get irq\n"); 440 + return irq; 413 441 } 414 442 415 443 spin_lock_init(&uart.port.lock); 416 444 uart.port.mapbase = regs->start; 417 - uart.port.irq = irq->start; 445 + uart.port.irq = irq; 418 446 uart.port.handle_irq = dw8250_handle_irq; 419 447 uart.port.pm = dw8250_do_pm; 420 448 uart.port.type = PORT_8250; ··· 437 453 return -ENOMEM; 438 454 439 455 data->usr_reg = DW_UART_USR; 456 + 457 + /* Always ask for fixed clock rate from a property. */ 458 + device_property_read_u32(&pdev->dev, "clock-frequency", 459 + &uart.port.uartclk); 460 + 461 + /* If there is separate baudclk, get the rate from it. */ 440 462 data->clk = devm_clk_get(&pdev->dev, "baudclk"); 441 463 if (IS_ERR(data->clk) && PTR_ERR(data->clk) != -EPROBE_DEFER) 442 464 data->clk = devm_clk_get(&pdev->dev, NULL); 443 465 if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) 444 466 return -EPROBE_DEFER; 445 - if (!IS_ERR(data->clk)) { 467 + if (!IS_ERR_OR_NULL(data->clk)) { 446 468 err = clk_prepare_enable(data->clk); 447 469 if (err) 448 470 dev_warn(&pdev->dev, "could not enable optional baudclk: %d\n", 449 471 err); 450 472 else 451 473 uart.port.uartclk = clk_get_rate(data->clk); 474 + } 475 + 476 + /* If no clock rate is defined, fail. */ 477 + if (!uart.port.uartclk) { 478 + dev_err(&pdev->dev, "clock rate not defined\n"); 479 + return -EINVAL; 452 480 } 453 481 454 482 data->pclk = devm_clk_get(&pdev->dev, "apb_pclk"); ··· 625 629 { "80860F0A", 0 }, 626 630 { "8086228A", 0 }, 627 631 { "APMC0D08", 0}, 632 + { "AMD0020", 0 }, 628 633 { }, 629 634 }; 630 635 MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match); ··· 646 649 MODULE_AUTHOR("Jamie Iles"); 647 650 MODULE_LICENSE("GPL"); 648 651 MODULE_DESCRIPTION("Synopsys DesignWare 8250 serial port driver"); 652 + MODULE_ALIAS("platform:dw-apb-uart");
+10 -59
drivers/tty/serial/8250/8250_early.c
··· 29 29 #include <linux/tty.h> 30 30 #include <linux/init.h> 31 31 #include <linux/console.h> 32 - #include <linux/serial_core.h> 33 32 #include <linux/serial_reg.h> 34 33 #include <linux/serial.h> 35 34 #include <linux/serial_8250.h> 36 35 #include <asm/io.h> 37 36 #include <asm/serial.h> 38 - 39 - static struct earlycon_device *early_device; 40 37 41 38 unsigned int __weak __init serial8250_early_in(struct uart_port *port, int offset) 42 39 { ··· 87 90 static void __init early_serial8250_write(struct console *console, 88 91 const char *s, unsigned int count) 89 92 { 90 - struct uart_port *port = &early_device->port; 93 + struct earlycon_device *device = console->data; 94 + struct uart_port *port = &device->port; 91 95 unsigned int ier; 92 96 93 97 /* Save the IER and disable interrupts preserving the UUE bit */ ··· 103 105 104 106 if (ier) 105 107 serial8250_early_out(port, UART_IER, ier); 106 - } 107 - 108 - static unsigned int __init probe_baud(struct uart_port *port) 109 - { 110 - unsigned char lcr, dll, dlm; 111 - unsigned int quot; 112 - 113 - lcr = serial8250_early_in(port, UART_LCR); 114 - serial8250_early_out(port, UART_LCR, lcr | UART_LCR_DLAB); 115 - dll = serial8250_early_in(port, UART_DLL); 116 - dlm = serial8250_early_in(port, UART_DLM); 117 - serial8250_early_out(port, UART_LCR, lcr); 118 - 119 - quot = (dlm << 8) | dll; 120 - return (port->uartclk / 16) / quot; 121 108 } 122 109 123 110 static void __init init_port(struct earlycon_device *device) ··· 130 147 const char *options) 131 148 { 132 149 if (!(device->port.membase || device->port.iobase)) 133 - return 0; 150 + return -ENODEV; 134 151 135 152 if (!device->baud) { 136 - device->baud = probe_baud(&device->port); 137 - snprintf(device->options, sizeof(device->options), "%u", 138 - device->baud); 139 - } 153 + struct uart_port *port = &device->port; 154 + unsigned int ier; 140 155 141 - init_port(device); 156 + /* assume the device was initialized, only mask interrupts */ 157 + ier = serial8250_early_in(port, UART_IER); 158 + serial8250_early_out(port, UART_IER, ier & UART_IER_UUE); 159 + } else 160 + init_port(device); 142 161 143 - early_device = device; 144 162 device->con->write = early_serial8250_write; 145 163 return 0; 146 164 } 147 165 EARLYCON_DECLARE(uart8250, early_serial8250_setup); 148 166 EARLYCON_DECLARE(uart, early_serial8250_setup); 149 - 150 - int __init setup_early_serial8250_console(char *cmdline) 151 - { 152 - char match[] = "uart8250"; 153 - 154 - if (cmdline && cmdline[4] == ',') 155 - match[4] = '\0'; 156 - 157 - return setup_earlycon(cmdline, match, early_serial8250_setup); 158 - } 159 - 160 - int serial8250_find_port_for_earlycon(void) 161 - { 162 - struct earlycon_device *device = early_device; 163 - struct uart_port *port = device ? &device->port : NULL; 164 - int line; 165 - int ret; 166 - 167 - if (!port || (!port->membase && !port->iobase)) 168 - return -ENODEV; 169 - 170 - line = serial8250_find_port(port); 171 - if (line < 0) 172 - return -ENODEV; 173 - 174 - ret = update_console_cmdline("uart", 8250, 175 - "ttyS", line, device->options); 176 - if (ret < 0) 177 - ret = update_console_cmdline("uart", 0, 178 - "ttyS", line, device->options); 179 - 180 - return ret; 181 - }
-1
drivers/tty/serial/8250/8250_em.c
··· 21 21 #include <linux/io.h> 22 22 #include <linux/module.h> 23 23 #include <linux/serial_8250.h> 24 - #include <linux/serial_core.h> 25 24 #include <linux/serial_reg.h> 26 25 #include <linux/platform_device.h> 27 26 #include <linux/clk.h>
-1
drivers/tty/serial/8250/8250_hp300.c
··· 10 10 #include <linux/string.h> 11 11 #include <linux/kernel.h> 12 12 #include <linux/serial.h> 13 - #include <linux/serial_core.h> 14 13 #include <linux/serial_8250.h> 15 14 #include <linux/delay.h> 16 15 #include <linux/dio.h>
-1
drivers/tty/serial/8250/8250_omap.c
··· 11 11 #include <linux/io.h> 12 12 #include <linux/module.h> 13 13 #include <linux/serial_8250.h> 14 - #include <linux/serial_core.h> 15 14 #include <linux/serial_reg.h> 16 15 #include <linux/tty_flip.h> 17 16 #include <linux/platform_device.h>
+305 -127
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> 24 25 25 26 #include <asm/byteorder.h> 26 27 #include <asm/io.h> 27 28 28 29 #include <linux/dmaengine.h> 29 30 #include <linux/platform_data/dma-dw.h> 31 + #include <linux/platform_data/dma-hsu.h> 30 32 31 33 #include "8250.h" 32 34 ··· 1394 1392 struct ktermios *old) 1395 1393 { 1396 1394 unsigned int baud = tty_termios_baud_rate(termios); 1397 - unsigned int m, n; 1395 + unsigned long fref = 100000000, fuart = baud * 16; 1396 + unsigned long w = BIT(15) - 1; 1397 + unsigned long m, n; 1398 1398 u32 reg; 1399 + 1400 + /* Get Fuart closer to Fref */ 1401 + fuart *= rounddown_pow_of_two(fref / fuart); 1399 1402 1400 1403 /* 1401 1404 * For baud rates 0.5M, 1M, 1.5M, 2M, 2.5M, 3M, 3.5M and 4M the ··· 1408 1401 * 1409 1402 * uartclk = (m / n) * 100 MHz, where m <= n 1410 1403 */ 1411 - switch (baud) { 1412 - case 500000: 1413 - case 1000000: 1414 - case 2000000: 1415 - case 4000000: 1416 - m = 64; 1417 - n = 100; 1418 - p->uartclk = 64000000; 1419 - break; 1420 - case 3500000: 1421 - m = 56; 1422 - n = 100; 1423 - p->uartclk = 56000000; 1424 - break; 1425 - case 1500000: 1426 - case 3000000: 1427 - m = 48; 1428 - n = 100; 1429 - p->uartclk = 48000000; 1430 - break; 1431 - case 2500000: 1432 - m = 40; 1433 - n = 100; 1434 - p->uartclk = 40000000; 1435 - break; 1436 - default: 1437 - m = 2304; 1438 - n = 3125; 1439 - p->uartclk = 73728000; 1440 - } 1404 + rational_best_approximation(fuart, fref, w, w, &m, &n); 1405 + p->uartclk = fuart; 1441 1406 1442 1407 /* Reset the clock */ 1443 1408 reg = (m << BYT_PRV_CLK_M_VAL_SHIFT) | (n << BYT_PRV_CLK_N_VAL_SHIFT); ··· 1504 1525 return ret; 1505 1526 } 1506 1527 1528 + #define INTEL_MID_UART_PS 0x30 1529 + #define INTEL_MID_UART_MUL 0x34 1530 + #define INTEL_MID_UART_DIV 0x38 1531 + 1532 + static void intel_mid_set_termios(struct uart_port *p, 1533 + struct ktermios *termios, 1534 + struct ktermios *old, 1535 + unsigned long fref) 1536 + { 1537 + unsigned int baud = tty_termios_baud_rate(termios); 1538 + unsigned short ps = 16; 1539 + unsigned long fuart = baud * ps; 1540 + unsigned long w = BIT(24) - 1; 1541 + unsigned long mul, div; 1542 + 1543 + if (fref < fuart) { 1544 + /* Find prescaler value that satisfies Fuart < Fref */ 1545 + if (fref > baud) 1546 + ps = fref / baud; /* baud rate too high */ 1547 + else 1548 + ps = 1; /* PLL case */ 1549 + fuart = baud * ps; 1550 + } else { 1551 + /* Get Fuart closer to Fref */ 1552 + fuart *= rounddown_pow_of_two(fref / fuart); 1553 + } 1554 + 1555 + rational_best_approximation(fuart, fref, w, w, &mul, &div); 1556 + p->uartclk = fuart * 16 / ps; /* core uses ps = 16 always */ 1557 + 1558 + writel(ps, p->membase + INTEL_MID_UART_PS); /* set PS */ 1559 + writel(mul, p->membase + INTEL_MID_UART_MUL); /* set MUL */ 1560 + writel(div, p->membase + INTEL_MID_UART_DIV); 1561 + 1562 + serial8250_do_set_termios(p, termios, old); 1563 + } 1564 + 1565 + static void intel_mid_set_termios_38_4M(struct uart_port *p, 1566 + struct ktermios *termios, 1567 + struct ktermios *old) 1568 + { 1569 + intel_mid_set_termios(p, termios, old, 38400000); 1570 + } 1571 + 1572 + static void intel_mid_set_termios_50M(struct uart_port *p, 1573 + struct ktermios *termios, 1574 + struct ktermios *old) 1575 + { 1576 + /* 1577 + * The uart clk is 50Mhz, and the baud rate come from: 1578 + * baud = 50M * MUL / (DIV * PS * DLAB) 1579 + */ 1580 + intel_mid_set_termios(p, termios, old, 50000000); 1581 + } 1582 + 1583 + static bool intel_mid_dma_filter(struct dma_chan *chan, void *param) 1584 + { 1585 + struct hsu_dma_slave *s = param; 1586 + 1587 + if (s->dma_dev != chan->device->dev || s->chan_id != chan->chan_id) 1588 + return false; 1589 + 1590 + chan->private = s; 1591 + return true; 1592 + } 1593 + 1594 + static int intel_mid_serial_setup(struct serial_private *priv, 1595 + const struct pciserial_board *board, 1596 + struct uart_8250_port *port, int idx, 1597 + int index, struct pci_dev *dma_dev) 1598 + { 1599 + struct device *dev = port->port.dev; 1600 + struct uart_8250_dma *dma; 1601 + struct hsu_dma_slave *tx_param, *rx_param; 1602 + 1603 + dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); 1604 + if (!dma) 1605 + return -ENOMEM; 1606 + 1607 + tx_param = devm_kzalloc(dev, sizeof(*tx_param), GFP_KERNEL); 1608 + if (!tx_param) 1609 + return -ENOMEM; 1610 + 1611 + rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL); 1612 + if (!rx_param) 1613 + return -ENOMEM; 1614 + 1615 + rx_param->chan_id = index * 2 + 1; 1616 + tx_param->chan_id = index * 2; 1617 + 1618 + dma->rxconf.src_maxburst = 64; 1619 + dma->txconf.dst_maxburst = 64; 1620 + 1621 + rx_param->dma_dev = &dma_dev->dev; 1622 + tx_param->dma_dev = &dma_dev->dev; 1623 + 1624 + dma->fn = intel_mid_dma_filter; 1625 + dma->rx_param = rx_param; 1626 + dma->tx_param = tx_param; 1627 + 1628 + port->port.type = PORT_16750; 1629 + port->port.flags |= UPF_FIXED_PORT | UPF_FIXED_TYPE; 1630 + port->dma = dma; 1631 + 1632 + return pci_default_setup(priv, board, port, idx); 1633 + } 1634 + 1635 + #define PCI_DEVICE_ID_INTEL_PNW_UART1 0x081b 1636 + #define PCI_DEVICE_ID_INTEL_PNW_UART2 0x081c 1637 + #define PCI_DEVICE_ID_INTEL_PNW_UART3 0x081d 1638 + 1639 + static int pnw_serial_setup(struct serial_private *priv, 1640 + const struct pciserial_board *board, 1641 + struct uart_8250_port *port, int idx) 1642 + { 1643 + struct pci_dev *pdev = priv->dev; 1644 + struct pci_dev *dma_dev; 1645 + int index; 1646 + 1647 + switch (pdev->device) { 1648 + case PCI_DEVICE_ID_INTEL_PNW_UART1: 1649 + index = 0; 1650 + break; 1651 + case PCI_DEVICE_ID_INTEL_PNW_UART2: 1652 + index = 1; 1653 + break; 1654 + case PCI_DEVICE_ID_INTEL_PNW_UART3: 1655 + index = 2; 1656 + break; 1657 + default: 1658 + return -EINVAL; 1659 + } 1660 + 1661 + dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 3)); 1662 + 1663 + port->port.set_termios = intel_mid_set_termios_50M; 1664 + 1665 + return intel_mid_serial_setup(priv, board, port, idx, index, dma_dev); 1666 + } 1667 + 1668 + #define PCI_DEVICE_ID_INTEL_TNG_UART 0x1191 1669 + 1670 + static int tng_serial_setup(struct serial_private *priv, 1671 + const struct pciserial_board *board, 1672 + struct uart_8250_port *port, int idx) 1673 + { 1674 + struct pci_dev *pdev = priv->dev; 1675 + struct pci_dev *dma_dev; 1676 + int index = PCI_FUNC(pdev->devfn); 1677 + 1678 + /* Currently no support for HSU port0 */ 1679 + if (index-- == 0) 1680 + return -ENODEV; 1681 + 1682 + dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(5, 0)); 1683 + 1684 + port->port.set_termios = intel_mid_set_termios_38_4M; 1685 + 1686 + return intel_mid_serial_setup(priv, board, port, idx, index, dma_dev); 1687 + } 1688 + 1507 1689 static int 1508 1690 pci_omegapci_setup(struct serial_private *priv, 1509 1691 const struct pciserial_board *board, ··· 1690 1550 struct uart_8250_port *port, int idx) 1691 1551 { 1692 1552 struct pci_dev *pdev = priv->dev; 1693 - unsigned long base; 1694 - unsigned long iobase; 1695 - unsigned long ciobase = 0; 1696 1553 u8 config_base; 1697 - u32 bar_data[3]; 1554 + u16 iobase; 1698 1555 1699 - /* 1700 - * Find each UARTs offset in PCI configuraion space 1701 - */ 1702 - switch (idx) { 1703 - case 0: 1704 - config_base = 0x40; 1705 - break; 1706 - case 1: 1707 - config_base = 0x48; 1708 - break; 1709 - case 2: 1710 - config_base = 0x50; 1711 - break; 1712 - case 3: 1713 - config_base = 0x58; 1714 - break; 1715 - case 4: 1716 - config_base = 0x60; 1717 - break; 1718 - case 5: 1719 - config_base = 0x68; 1720 - break; 1721 - case 6: 1722 - config_base = 0x70; 1723 - break; 1724 - case 7: 1725 - config_base = 0x78; 1726 - break; 1727 - case 8: 1728 - config_base = 0x80; 1729 - break; 1730 - case 9: 1731 - config_base = 0x88; 1732 - break; 1733 - case 10: 1734 - config_base = 0x90; 1735 - break; 1736 - case 11: 1737 - config_base = 0x98; 1738 - break; 1739 - default: 1740 - /* Unknown number of ports, get out of here */ 1741 - return -EINVAL; 1742 - } 1556 + config_base = 0x40 + 0x08 * idx; 1743 1557 1744 - if (idx < 4) { 1745 - base = pci_resource_start(priv->dev, 3); 1746 - ciobase = (int)(base + (0x8 * idx)); 1747 - } 1558 + /* Get the io address from configuration space */ 1559 + pci_read_config_word(pdev, config_base + 4, &iobase); 1748 1560 1749 - /* Get the io address dispatch from the BIOS */ 1750 - pci_read_config_dword(pdev, 0x24, &bar_data[0]); 1751 - pci_read_config_dword(pdev, 0x20, &bar_data[1]); 1752 - pci_read_config_dword(pdev, 0x1c, &bar_data[2]); 1753 - 1754 - /* Calculate Real IO Port */ 1755 - iobase = (bar_data[idx/4] & 0xffffffe0) + (idx % 4) * 8; 1756 - 1757 - dev_dbg(&pdev->dev, "%s: idx=%d iobase=0x%lx ciobase=0x%lx config_base=0x%2x\n", 1758 - __func__, idx, iobase, ciobase, config_base); 1759 - 1760 - /* Enable UART I/O port */ 1761 - pci_write_config_byte(pdev, config_base + 0x00, 0x01); 1762 - 1763 - /* Select 128-byte FIFO and 8x FIFO threshold */ 1764 - pci_write_config_byte(pdev, config_base + 0x01, 0x33); 1765 - 1766 - /* LSB UART */ 1767 - pci_write_config_byte(pdev, config_base + 0x04, (u8)(iobase & 0xff)); 1768 - 1769 - /* MSB UART */ 1770 - pci_write_config_byte(pdev, config_base + 0x05, (u8)((iobase & 0xff00) >> 8)); 1771 - 1772 - /* irq number, this usually fails, but the spec says to do it anyway. */ 1773 - pci_write_config_byte(pdev, config_base + 0x06, pdev->irq); 1561 + dev_dbg(&pdev->dev, "%s: idx=%d iobase=0x%x", __func__, idx, iobase); 1774 1562 1775 1563 port->port.iotype = UPIO_PORT; 1776 1564 port->port.iobase = iobase; 1777 - port->port.mapbase = 0; 1778 - port->port.membase = NULL; 1779 - port->port.regshift = 0; 1780 1565 1781 1566 return 0; 1567 + } 1568 + 1569 + static int pci_fintek_init(struct pci_dev *dev) 1570 + { 1571 + unsigned long iobase; 1572 + u32 max_port, i; 1573 + u32 bar_data[3]; 1574 + u8 config_base; 1575 + 1576 + switch (dev->device) { 1577 + case 0x1104: /* 4 ports */ 1578 + case 0x1108: /* 8 ports */ 1579 + max_port = dev->device & 0xff; 1580 + break; 1581 + case 0x1112: /* 12 ports */ 1582 + max_port = 12; 1583 + break; 1584 + default: 1585 + return -EINVAL; 1586 + } 1587 + 1588 + /* Get the io address dispatch from the BIOS */ 1589 + pci_read_config_dword(dev, 0x24, &bar_data[0]); 1590 + pci_read_config_dword(dev, 0x20, &bar_data[1]); 1591 + pci_read_config_dword(dev, 0x1c, &bar_data[2]); 1592 + 1593 + for (i = 0; i < max_port; ++i) { 1594 + /* UART0 configuration offset start from 0x40 */ 1595 + config_base = 0x40 + 0x08 * i; 1596 + 1597 + /* Calculate Real IO Port */ 1598 + iobase = (bar_data[i / 4] & 0xffffffe0) + (i % 4) * 8; 1599 + 1600 + /* Enable UART I/O port */ 1601 + pci_write_config_byte(dev, config_base + 0x00, 0x01); 1602 + 1603 + /* Select 128-byte FIFO and 8x FIFO threshold */ 1604 + pci_write_config_byte(dev, config_base + 0x01, 0x33); 1605 + 1606 + /* LSB UART */ 1607 + pci_write_config_byte(dev, config_base + 0x04, 1608 + (u8)(iobase & 0xff)); 1609 + 1610 + /* MSB UART */ 1611 + pci_write_config_byte(dev, config_base + 0x05, 1612 + (u8)((iobase & 0xff00) >> 8)); 1613 + 1614 + pci_write_config_byte(dev, config_base + 0x06, dev->irq); 1615 + } 1616 + 1617 + return max_port; 1782 1618 } 1783 1619 1784 1620 static int skip_tx_en_setup(struct serial_private *priv, ··· 2102 1986 .subvendor = PCI_ANY_ID, 2103 1987 .subdevice = PCI_ANY_ID, 2104 1988 .setup = byt_serial_setup, 1989 + }, 1990 + { 1991 + .vendor = PCI_VENDOR_ID_INTEL, 1992 + .device = PCI_DEVICE_ID_INTEL_PNW_UART1, 1993 + .subvendor = PCI_ANY_ID, 1994 + .subdevice = PCI_ANY_ID, 1995 + .setup = pnw_serial_setup, 1996 + }, 1997 + { 1998 + .vendor = PCI_VENDOR_ID_INTEL, 1999 + .device = PCI_DEVICE_ID_INTEL_PNW_UART2, 2000 + .subvendor = PCI_ANY_ID, 2001 + .subdevice = PCI_ANY_ID, 2002 + .setup = pnw_serial_setup, 2003 + }, 2004 + { 2005 + .vendor = PCI_VENDOR_ID_INTEL, 2006 + .device = PCI_DEVICE_ID_INTEL_PNW_UART3, 2007 + .subvendor = PCI_ANY_ID, 2008 + .subdevice = PCI_ANY_ID, 2009 + .setup = pnw_serial_setup, 2010 + }, 2011 + { 2012 + .vendor = PCI_VENDOR_ID_INTEL, 2013 + .device = PCI_DEVICE_ID_INTEL_TNG_UART, 2014 + .subvendor = PCI_ANY_ID, 2015 + .subdevice = PCI_ANY_ID, 2016 + .setup = tng_serial_setup, 2105 2017 }, 2106 2018 { 2107 2019 .vendor = PCI_VENDOR_ID_INTEL, ··· 2797 2653 .subvendor = PCI_ANY_ID, 2798 2654 .subdevice = PCI_ANY_ID, 2799 2655 .setup = pci_fintek_setup, 2656 + .init = pci_fintek_init, 2800 2657 }, 2801 2658 { 2802 2659 .vendor = 0x1c29, ··· 2805 2660 .subvendor = PCI_ANY_ID, 2806 2661 .subdevice = PCI_ANY_ID, 2807 2662 .setup = pci_fintek_setup, 2663 + .init = pci_fintek_init, 2808 2664 }, 2809 2665 { 2810 2666 .vendor = 0x1c29, ··· 2813 2667 .subvendor = PCI_ANY_ID, 2814 2668 .subdevice = PCI_ANY_ID, 2815 2669 .setup = pci_fintek_setup, 2670 + .init = pci_fintek_init, 2816 2671 }, 2817 2672 2818 2673 /* ··· 3011 2864 pbn_ADDIDATA_PCIe_8_3906250, 3012 2865 pbn_ce4100_1_115200, 3013 2866 pbn_byt, 2867 + pbn_pnw, 2868 + pbn_tng, 3014 2869 pbn_qrk, 3015 2870 pbn_omegapci, 3016 2871 pbn_NETMOS9900_2s_115200, ··· 3779 3630 .uart_offset = 0x80, 3780 3631 .reg_shift = 2, 3781 3632 }, 3633 + [pbn_pnw] = { 3634 + .flags = FL_BASE0, 3635 + .num_ports = 1, 3636 + .base_baud = 115200, 3637 + }, 3638 + [pbn_tng] = { 3639 + .flags = FL_BASE0, 3640 + .num_ports = 1, 3641 + .base_baud = 1843200, 3642 + }, 3782 3643 [pbn_qrk] = { 3783 3644 .flags = FL_BASE0, 3784 3645 .num_ports = 1, ··· 4165 4006 pci_disable_device(dev); 4166 4007 } 4167 4008 4168 - #ifdef CONFIG_PM 4169 - static int pciserial_suspend_one(struct pci_dev *dev, pm_message_t state) 4009 + #ifdef CONFIG_PM_SLEEP 4010 + static int pciserial_suspend_one(struct device *dev) 4170 4011 { 4171 - struct serial_private *priv = pci_get_drvdata(dev); 4012 + struct pci_dev *pdev = to_pci_dev(dev); 4013 + struct serial_private *priv = pci_get_drvdata(pdev); 4172 4014 4173 4015 if (priv) 4174 4016 pciserial_suspend_ports(priv); 4175 4017 4176 - pci_save_state(dev); 4177 - pci_set_power_state(dev, pci_choose_state(dev, state)); 4178 4018 return 0; 4179 4019 } 4180 4020 4181 - static int pciserial_resume_one(struct pci_dev *dev) 4021 + static int pciserial_resume_one(struct device *dev) 4182 4022 { 4023 + struct pci_dev *pdev = to_pci_dev(dev); 4024 + struct serial_private *priv = pci_get_drvdata(pdev); 4183 4025 int err; 4184 - struct serial_private *priv = pci_get_drvdata(dev); 4185 - 4186 - pci_set_power_state(dev, PCI_D0); 4187 - pci_restore_state(dev); 4188 4026 4189 4027 if (priv) { 4190 4028 /* 4191 4029 * The device may have been disabled. Re-enable it. 4192 4030 */ 4193 - err = pci_enable_device(dev); 4031 + err = pci_enable_device(pdev); 4194 4032 /* FIXME: We cannot simply error out here */ 4195 4033 if (err) 4196 - dev_err(&dev->dev, "Unable to re-enable ports, trying to continue.\n"); 4034 + dev_err(dev, "Unable to re-enable ports, trying to continue.\n"); 4197 4035 pciserial_resume_ports(priv); 4198 4036 } 4199 4037 return 0; 4200 4038 } 4201 4039 #endif 4040 + 4041 + static SIMPLE_DEV_PM_OPS(pciserial_pm_ops, pciserial_suspend_one, 4042 + pciserial_resume_one); 4202 4043 4203 4044 static struct pci_device_id serial_pci_tbl[] = { 4204 4045 /* Advantech use PCI_DEVICE_ID_ADVANTECH_PCI3620 (0x3620) as 'PCI_SUBVENDOR_ID' */ ··· 5522 5363 pbn_byt }, 5523 5364 5524 5365 /* 5366 + * Intel Penwell 5367 + */ 5368 + { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PNW_UART1, 5369 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5370 + pbn_pnw}, 5371 + { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PNW_UART2, 5372 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5373 + pbn_pnw}, 5374 + { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PNW_UART3, 5375 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5376 + pbn_pnw}, 5377 + 5378 + /* 5379 + * Intel Tangier 5380 + */ 5381 + { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TNG_UART, 5382 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5383 + pbn_tng}, 5384 + 5385 + /* 5525 5386 * Intel Quark x1000 5526 5387 */ 5527 5388 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_UART, ··· 5689 5510 .name = "serial", 5690 5511 .probe = pciserial_init_one, 5691 5512 .remove = pciserial_remove_one, 5692 - #ifdef CONFIG_PM 5693 - .suspend = pciserial_suspend_one, 5694 - .resume = pciserial_resume_one, 5695 - #endif 5513 + .driver = { 5514 + .pm = &pciserial_pm_ops, 5515 + }, 5696 5516 .id_table = serial_pci_tbl, 5697 5517 .err_handler = &serial8250_err_handler, 5698 5518 };
+1
drivers/tty/serial/8250/Kconfig
··· 108 108 tristate "8250/16550 PCI device support" if EXPERT 109 109 depends on SERIAL_8250 && PCI 110 110 default SERIAL_8250 111 + select RATIONAL 111 112 help 112 113 This builds standard PCI serial support. You may be able to 113 114 disable this feature if you only need legacy serial support.
+5 -27
drivers/tty/serial/Kconfig
··· 20 20 21 21 config SERIAL_AMBA_PL010 22 22 tristate "ARM AMBA PL010 serial port support" 23 - depends on ARM_AMBA && (BROKEN || !ARCH_VERSATILE) 23 + depends on ARM_AMBA 24 24 select SERIAL_CORE 25 25 help 26 26 This selects the ARM(R) AMBA(R) PrimeCell PL010 UART. If you have ··· 483 483 your boot loader (lilo or loadlin) about how to pass options to the 484 484 kernel at boot time.) 485 485 486 - config SERIAL_MFD_HSU 487 - tristate "Medfield High Speed UART support" 488 - depends on PCI 489 - select SERIAL_CORE 490 - 491 - config SERIAL_MFD_HSU_CONSOLE 492 - bool "Medfile HSU serial console support" 493 - depends on SERIAL_MFD_HSU=y 494 - select SERIAL_CORE_CONSOLE 495 - 496 486 config SERIAL_BFIN 497 487 tristate "Blackfin serial port support" 498 488 depends on BLACKFIN ··· 825 835 826 836 config SERIAL_PMACZILOG 827 837 tristate "Mac or PowerMac z85c30 ESCC support" 828 - depends on (M68K && MAC) || (PPC_OF && PPC_PMAC) 838 + depends on (M68K && MAC) || PPC_PMAC 829 839 select SERIAL_CORE 830 840 help 831 841 This driver supports the Zilog z85C30 serial ports found on ··· 868 878 869 879 config SERIAL_CPM 870 880 tristate "CPM SCC/SMC serial port support" 871 - depends on CPM2 || 8xx 881 + depends on CPM2 || CPM1 872 882 select SERIAL_CORE 873 883 help 874 884 This driver supports the SCC and SMC serial ports on Motorola ··· 1044 1054 1045 1055 config SERIAL_MSM 1046 1056 bool "MSM on-chip serial port support" 1047 - depends on ARCH_MSM || ARCH_QCOM 1057 + depends on ARCH_QCOM 1048 1058 select SERIAL_CORE 1049 1059 1050 1060 config SERIAL_MSM_CONSOLE ··· 1052 1062 depends on SERIAL_MSM=y 1053 1063 select SERIAL_CORE_CONSOLE 1054 1064 select SERIAL_EARLYCON 1055 - 1056 - config SERIAL_MSM_HS 1057 - tristate "MSM UART High Speed: Serial Driver" 1058 - depends on ARCH_MSM7X00A || ARCH_MSM7X30 || ARCH_QSD8X50 1059 - select SERIAL_CORE 1060 - help 1061 - If you have a machine based on MSM family of SoCs, you 1062 - can enable its onboard high speed serial port by enabling 1063 - this option. 1064 - 1065 - Choose M here to compile it as a module. The module will be 1066 - called msm_serial_hs. 1067 1065 1068 1066 config SERIAL_VT8500 1069 1067 bool "VIA VT8500 on-chip serial port support" ··· 1131 1153 1132 1154 config SERIAL_OF_PLATFORM_NWPSERIAL 1133 1155 tristate "NWP serial port driver" 1134 - depends on PPC_OF && PPC_DCR 1156 + depends on PPC_DCR 1135 1157 select SERIAL_OF_PLATFORM 1136 1158 select SERIAL_CORE_CONSOLE 1137 1159 select SERIAL_CORE
-2
drivers/tty/serial/Makefile
··· 62 62 obj-$(CONFIG_SERIAL_ATMEL) += atmel_serial.o 63 63 obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o 64 64 obj-$(CONFIG_SERIAL_MSM) += msm_serial.o 65 - obj-$(CONFIG_SERIAL_MSM_HS) += msm_serial_hs.o 66 65 obj-$(CONFIG_SERIAL_NETX) += netx-serial.o 67 66 obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o 68 67 obj-$(CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL) += nwpserial.o ··· 77 78 obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o 78 79 obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o 79 80 obj-$(CONFIG_SERIAL_VT8500) += vt8500_serial.o 80 - obj-$(CONFIG_SERIAL_MFD_HSU) += mfd.o 81 81 obj-$(CONFIG_SERIAL_IFX6X60) += ifx6x60.o 82 82 obj-$(CONFIG_SERIAL_PCH_UART) += pch_uart.o 83 83 obj-$(CONFIG_SERIAL_MSM_SMD) += msm_smd_tty.o
+129 -105
drivers/tty/serial/amba-pl011.c
··· 58 58 #include <linux/pinctrl/consumer.h> 59 59 #include <linux/sizes.h> 60 60 #include <linux/io.h> 61 + #include <linux/workqueue.h> 61 62 62 63 #define UART_NR 14 63 64 ··· 157 156 unsigned int lcrh_tx; /* vendor-specific */ 158 157 unsigned int lcrh_rx; /* vendor-specific */ 159 158 unsigned int old_cr; /* state during shutdown */ 159 + struct delayed_work tx_softirq_work; 160 160 bool autorts; 161 + unsigned int tx_irq_seen; /* 0=none, 1=1, 2=2 or more */ 161 162 char type[12]; 162 163 #ifdef CONFIG_DMA_ENGINE 163 164 /* DMA stuff */ ··· 167 164 bool using_rx_dma; 168 165 struct pl011_dmarx_data dmarx; 169 166 struct pl011_dmatx_data dmatx; 167 + bool dma_probed; 170 168 #endif 171 169 }; 172 170 ··· 265 261 } 266 262 } 267 263 268 - static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port *uap) 264 + static void pl011_dma_probe(struct uart_amba_port *uap) 269 265 { 270 266 /* DMA is the sole user of the platform data right now */ 271 267 struct amba_pl011_data *plat = dev_get_platdata(uap->port.dev); 268 + struct device *dev = uap->port.dev; 272 269 struct dma_slave_config tx_conf = { 273 270 .dst_addr = uap->port.mapbase + UART01x_DR, 274 271 .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, ··· 280 275 struct dma_chan *chan; 281 276 dma_cap_mask_t mask; 282 277 283 - chan = dma_request_slave_channel(dev, "tx"); 278 + uap->dma_probed = true; 279 + chan = dma_request_slave_channel_reason(dev, "tx"); 280 + if (IS_ERR(chan)) { 281 + if (PTR_ERR(chan) == -EPROBE_DEFER) { 282 + uap->dma_probed = false; 283 + return; 284 + } 284 285 285 - if (!chan) { 286 286 /* We need platform data */ 287 287 if (!plat || !plat->dma_filter) { 288 288 dev_info(uap->port.dev, "no DMA platform data\n"); ··· 395 385 } 396 386 } 397 387 398 - #ifndef MODULE 399 - /* 400 - * Stack up the UARTs and let the above initcall be done at device 401 - * initcall time, because the serial driver is called as an arch 402 - * initcall, and at this time the DMA subsystem is not yet registered. 403 - * At this point the driver will switch over to using DMA where desired. 404 - */ 405 - struct dma_uap { 406 - struct list_head node; 407 - struct uart_amba_port *uap; 408 - struct device *dev; 409 - }; 410 - 411 - static LIST_HEAD(pl011_dma_uarts); 412 - 413 - static int __init pl011_dma_initcall(void) 414 - { 415 - struct list_head *node, *tmp; 416 - 417 - list_for_each_safe(node, tmp, &pl011_dma_uarts) { 418 - struct dma_uap *dmau = list_entry(node, struct dma_uap, node); 419 - pl011_dma_probe_initcall(dmau->dev, dmau->uap); 420 - list_del(node); 421 - kfree(dmau); 422 - } 423 - return 0; 424 - } 425 - 426 - device_initcall(pl011_dma_initcall); 427 - 428 - static void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap) 429 - { 430 - struct dma_uap *dmau = kzalloc(sizeof(struct dma_uap), GFP_KERNEL); 431 - if (dmau) { 432 - dmau->uap = uap; 433 - dmau->dev = dev; 434 - list_add_tail(&dmau->node, &pl011_dma_uarts); 435 - } 436 - } 437 - #else 438 - static void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap) 439 - { 440 - pl011_dma_probe_initcall(dev, uap); 441 - } 442 - #endif 443 - 444 388 static void pl011_dma_remove(struct uart_amba_port *uap) 445 389 { 446 - /* TODO: remove the initcall if it has not yet executed */ 447 390 if (uap->dmatx.chan) 448 391 dma_release_channel(uap->dmatx.chan); 449 392 if (uap->dmarx.chan) 450 393 dma_release_channel(uap->dmarx.chan); 451 394 } 452 395 453 - /* Forward declare this for the refill routine */ 396 + /* Forward declare these for the refill routine */ 454 397 static int pl011_dma_tx_refill(struct uart_amba_port *uap); 398 + static void pl011_start_tx_pio(struct uart_amba_port *uap); 455 399 456 400 /* 457 401 * The current DMA TX buffer has been sent. ··· 443 479 return; 444 480 } 445 481 446 - if (pl011_dma_tx_refill(uap) <= 0) { 482 + if (pl011_dma_tx_refill(uap) <= 0) 447 483 /* 448 484 * We didn't queue a DMA buffer for some reason, but we 449 485 * have data pending to be sent. Re-enable the TX IRQ. 450 486 */ 451 - uap->im |= UART011_TXIM; 452 - writew(uap->im, uap->port.membase + UART011_IMSC); 453 - } 487 + pl011_start_tx_pio(uap); 488 + 454 489 spin_unlock_irqrestore(&uap->port.lock, flags); 455 490 } 456 491 ··· 627 664 if (!uap->dmatx.queued) { 628 665 if (pl011_dma_tx_refill(uap) > 0) { 629 666 uap->im &= ~UART011_TXIM; 630 - ret = true; 631 - } else { 632 - uap->im |= UART011_TXIM; 667 + writew(uap->im, uap->port.membase + 668 + UART011_IMSC); 669 + } else 633 670 ret = false; 634 - } 635 - writew(uap->im, uap->port.membase + UART011_IMSC); 636 671 } else if (!(uap->dmacr & UART011_TXDMAE)) { 637 672 uap->dmacr |= UART011_TXDMAE; 638 673 writew(uap->dmacr, ··· 982 1021 { 983 1022 int ret; 984 1023 1024 + if (!uap->dma_probed) 1025 + pl011_dma_probe(uap); 1026 + 985 1027 if (!uap->dmatx.chan) 986 1028 return; 987 1029 ··· 1106 1142 1107 1143 #else 1108 1144 /* Blank functions if the DMA engine is not available */ 1109 - static inline void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap) 1145 + static inline void pl011_dma_probe(struct uart_amba_port *uap) 1110 1146 { 1111 1147 } 1112 1148 ··· 1172 1208 pl011_dma_tx_stop(uap); 1173 1209 } 1174 1210 1211 + static bool pl011_tx_chars(struct uart_amba_port *uap); 1212 + 1213 + /* Start TX with programmed I/O only (no DMA) */ 1214 + static void pl011_start_tx_pio(struct uart_amba_port *uap) 1215 + { 1216 + uap->im |= UART011_TXIM; 1217 + writew(uap->im, uap->port.membase + UART011_IMSC); 1218 + if (!uap->tx_irq_seen) 1219 + pl011_tx_chars(uap); 1220 + } 1221 + 1175 1222 static void pl011_start_tx(struct uart_port *port) 1176 1223 { 1177 1224 struct uart_amba_port *uap = 1178 1225 container_of(port, struct uart_amba_port, port); 1179 1226 1180 - if (!pl011_dma_tx_start(uap)) { 1181 - uap->im |= UART011_TXIM; 1182 - writew(uap->im, uap->port.membase + UART011_IMSC); 1183 - } 1227 + if (!pl011_dma_tx_start(uap)) 1228 + pl011_start_tx_pio(uap); 1184 1229 } 1185 1230 1186 1231 static void pl011_stop_rx(struct uart_port *port) ··· 1247 1274 spin_lock(&uap->port.lock); 1248 1275 } 1249 1276 1250 - static void pl011_tx_chars(struct uart_amba_port *uap) 1277 + /* 1278 + * Transmit a character 1279 + * There must be at least one free entry in the TX FIFO to accept the char. 1280 + * 1281 + * Returns true if the FIFO might have space in it afterwards; 1282 + * returns false if the FIFO definitely became full. 1283 + */ 1284 + static bool pl011_tx_char(struct uart_amba_port *uap, unsigned char c) 1285 + { 1286 + writew(c, uap->port.membase + UART01x_DR); 1287 + uap->port.icount.tx++; 1288 + 1289 + if (likely(uap->tx_irq_seen > 1)) 1290 + return true; 1291 + 1292 + return !(readw(uap->port.membase + UART01x_FR) & UART01x_FR_TXFF); 1293 + } 1294 + 1295 + static bool pl011_tx_chars(struct uart_amba_port *uap) 1251 1296 { 1252 1297 struct circ_buf *xmit = &uap->port.state->xmit; 1253 1298 int count; 1254 1299 1300 + if (unlikely(uap->tx_irq_seen < 2)) 1301 + /* 1302 + * Initial FIFO fill level unknown: we must check TXFF 1303 + * after each write, so just try to fill up the FIFO. 1304 + */ 1305 + count = uap->fifosize; 1306 + else /* tx_irq_seen >= 2 */ 1307 + /* 1308 + * FIFO initially at least half-empty, so we can simply 1309 + * write half the FIFO without polling TXFF. 1310 + 1311 + * Note: the *first* TX IRQ can still race with 1312 + * pl011_start_tx_pio(), which can result in the FIFO 1313 + * being fuller than expected in that case. 1314 + */ 1315 + count = uap->fifosize >> 1; 1316 + 1317 + /* 1318 + * If the FIFO is full we're guaranteed a TX IRQ at some later point, 1319 + * and can't transmit immediately in any case: 1320 + */ 1321 + if (unlikely(uap->tx_irq_seen < 2 && 1322 + readw(uap->port.membase + UART01x_FR) & UART01x_FR_TXFF)) 1323 + return false; 1324 + 1255 1325 if (uap->port.x_char) { 1256 - writew(uap->port.x_char, uap->port.membase + UART01x_DR); 1257 - uap->port.icount.tx++; 1326 + pl011_tx_char(uap, uap->port.x_char); 1258 1327 uap->port.x_char = 0; 1259 - return; 1328 + --count; 1260 1329 } 1261 1330 if (uart_circ_empty(xmit) || uart_tx_stopped(&uap->port)) { 1262 1331 pl011_stop_tx(&uap->port); 1263 - return; 1332 + goto done; 1264 1333 } 1265 1334 1266 1335 /* If we are using DMA mode, try to send some characters. */ 1267 1336 if (pl011_dma_tx_irq(uap)) 1268 - return; 1337 + goto done; 1269 1338 1270 - count = uap->fifosize >> 1; 1271 - do { 1272 - writew(xmit->buf[xmit->tail], uap->port.membase + UART01x_DR); 1339 + while (count-- > 0 && pl011_tx_char(uap, xmit->buf[xmit->tail])) { 1273 1340 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 1274 - uap->port.icount.tx++; 1275 1341 if (uart_circ_empty(xmit)) 1276 1342 break; 1277 - } while (--count > 0); 1343 + } 1278 1344 1279 1345 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 1280 1346 uart_write_wakeup(&uap->port); 1281 1347 1282 - if (uart_circ_empty(xmit)) 1348 + if (uart_circ_empty(xmit)) { 1283 1349 pl011_stop_tx(&uap->port); 1350 + goto done; 1351 + } 1352 + 1353 + if (unlikely(!uap->tx_irq_seen)) 1354 + schedule_delayed_work(&uap->tx_softirq_work, uap->port.timeout); 1355 + 1356 + done: 1357 + return false; 1284 1358 } 1285 1359 1286 1360 static void pl011_modem_status(struct uart_amba_port *uap) ··· 1352 1332 uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS); 1353 1333 1354 1334 wake_up_interruptible(&uap->port.state->port.delta_msr_wait); 1335 + } 1336 + 1337 + static void pl011_tx_softirq(struct work_struct *work) 1338 + { 1339 + struct delayed_work *dwork = to_delayed_work(work); 1340 + struct uart_amba_port *uap = 1341 + container_of(dwork, struct uart_amba_port, tx_softirq_work); 1342 + 1343 + spin_lock(&uap->port.lock); 1344 + while (pl011_tx_chars(uap)) ; 1345 + spin_unlock(&uap->port.lock); 1346 + } 1347 + 1348 + static void pl011_tx_irq_seen(struct uart_amba_port *uap) 1349 + { 1350 + if (likely(uap->tx_irq_seen > 1)) 1351 + return; 1352 + 1353 + uap->tx_irq_seen++; 1354 + if (uap->tx_irq_seen < 2) 1355 + /* first TX IRQ */ 1356 + cancel_delayed_work(&uap->tx_softirq_work); 1355 1357 } 1356 1358 1357 1359 static irqreturn_t pl011_int(int irq, void *dev_id) ··· 1414 1372 if (status & (UART011_DSRMIS|UART011_DCDMIS| 1415 1373 UART011_CTSMIS|UART011_RIMIS)) 1416 1374 pl011_modem_status(uap); 1417 - if (status & UART011_TXIS) 1375 + if (status & UART011_TXIS) { 1376 + pl011_tx_irq_seen(uap); 1418 1377 pl011_tx_chars(uap); 1378 + } 1419 1379 1420 1380 if (pass_counter-- == 0) 1421 1381 break; ··· 1621 1577 { 1622 1578 struct uart_amba_port *uap = 1623 1579 container_of(port, struct uart_amba_port, port); 1624 - unsigned int cr, lcr_h, fbrd, ibrd; 1580 + unsigned int cr; 1625 1581 int retval; 1626 1582 1627 1583 retval = pl011_hwinit(port); ··· 1639 1595 1640 1596 writew(uap->vendor->ifls, uap->port.membase + UART011_IFLS); 1641 1597 1642 - /* 1643 - * Provoke TX FIFO interrupt into asserting. Taking care to preserve 1644 - * baud rate and data format specified by FBRD, IBRD and LCRH as the 1645 - * UART may already be in use as a console. 1646 - */ 1647 1598 spin_lock_irq(&uap->port.lock); 1648 - 1649 - fbrd = readw(uap->port.membase + UART011_FBRD); 1650 - ibrd = readw(uap->port.membase + UART011_IBRD); 1651 - lcr_h = readw(uap->port.membase + uap->lcrh_rx); 1652 - 1653 - cr = UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_LBE; 1654 - writew(cr, uap->port.membase + UART011_CR); 1655 - writew(0, uap->port.membase + UART011_FBRD); 1656 - writew(1, uap->port.membase + UART011_IBRD); 1657 - pl011_write_lcr_h(uap, 0); 1658 - writew(0, uap->port.membase + UART01x_DR); 1659 - while (readw(uap->port.membase + UART01x_FR) & UART01x_FR_BUSY) 1660 - barrier(); 1661 - 1662 - writew(fbrd, uap->port.membase + UART011_FBRD); 1663 - writew(ibrd, uap->port.membase + UART011_IBRD); 1664 - pl011_write_lcr_h(uap, lcr_h); 1665 1599 1666 1600 /* restore RTS and DTR */ 1667 1601 cr = uap->old_cr & (UART011_CR_RTS | UART011_CR_DTR); ··· 1694 1672 container_of(port, struct uart_amba_port, port); 1695 1673 unsigned int cr; 1696 1674 1675 + cancel_delayed_work_sync(&uap->tx_softirq_work); 1676 + 1697 1677 /* 1698 1678 * disable all interrupts 1699 1679 */ 1700 1680 spin_lock_irq(&uap->port.lock); 1701 1681 uap->im = 0; 1702 1682 writew(uap->im, uap->port.membase + UART011_IMSC); 1703 - writew(0xffff, uap->port.membase + UART011_ICR); 1683 + writew(0xffff & ~UART011_TXIS, uap->port.membase + UART011_ICR); 1704 1684 spin_unlock_irq(&uap->port.lock); 1705 1685 1706 1686 pl011_dma_shutdown(uap); ··· 2242 2218 uap->port.ops = &amba_pl011_pops; 2243 2219 uap->port.flags = UPF_BOOT_AUTOCONF; 2244 2220 uap->port.line = i; 2245 - pl011_dma_probe(&dev->dev, uap); 2221 + INIT_DELAYED_WORK(&uap->tx_softirq_work, pl011_tx_softirq); 2246 2222 2247 2223 /* Ensure interrupts from this UART are masked and cleared */ 2248 2224 writew(0, uap->port.membase + UART011_IMSC); ··· 2257 2233 if (!amba_reg.state) { 2258 2234 ret = uart_register_driver(&amba_reg); 2259 2235 if (ret < 0) { 2260 - pr_err("Failed to register AMBA-PL011 driver\n"); 2236 + dev_err(&dev->dev, 2237 + "Failed to register AMBA-PL011 driver\n"); 2261 2238 return ret; 2262 2239 } 2263 2240 } ··· 2267 2242 if (ret) { 2268 2243 amba_ports[i] = NULL; 2269 2244 uart_unregister_driver(&amba_reg); 2270 - pl011_dma_remove(uap); 2271 2245 } 2272 2246 2273 2247 return ret;
+1 -1
drivers/tty/serial/apbuart.c
··· 572 572 return 0; 573 573 } 574 574 575 - static struct of_device_id apbuart_match[] = { 575 + static const struct of_device_id apbuart_match[] = { 576 576 { 577 577 .name = "GAISLER_APBUART", 578 578 },
+1 -1
drivers/tty/serial/ar933x_uart.c
··· 649 649 id = 0; 650 650 } 651 651 652 - if (id > CONFIG_SERIAL_AR933X_NR_UARTS) 652 + if (id >= CONFIG_SERIAL_AR933X_NR_UARTS) 653 653 return -EINVAL; 654 654 655 655 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+17 -12
drivers/tty/serial/atmel_serial.c
··· 855 855 spin_lock_init(&atmel_port->lock_tx); 856 856 sg_init_table(&atmel_port->sg_tx, 1); 857 857 /* UART circular tx buffer is an aligned page. */ 858 - BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK); 858 + BUG_ON(!PAGE_ALIGNED(port->state->xmit.buf)); 859 859 sg_set_page(&atmel_port->sg_tx, 860 860 virt_to_page(port->state->xmit.buf), 861 861 UART_XMIT_SIZE, ··· 1034 1034 spin_lock_init(&atmel_port->lock_rx); 1035 1035 sg_init_table(&atmel_port->sg_rx, 1); 1036 1036 /* UART circular rx buffer is an aligned page. */ 1037 - BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK); 1037 + BUG_ON(!PAGE_ALIGNED(ring->buf)); 1038 1038 sg_set_page(&atmel_port->sg_rx, 1039 1039 virt_to_page(ring->buf), 1040 - ATMEL_SERIAL_RINGSIZE, 1040 + sizeof(struct atmel_uart_char) * ATMEL_SERIAL_RINGSIZE, 1041 1041 (int)ring->buf & ~PAGE_MASK); 1042 1042 nent = dma_map_sg(port->dev, 1043 1043 &atmel_port->sg_rx, ··· 1554 1554 spin_unlock(&port->lock); 1555 1555 } 1556 1556 1557 - static int atmel_init_property(struct atmel_uart_port *atmel_port, 1557 + static void atmel_init_property(struct atmel_uart_port *atmel_port, 1558 1558 struct platform_device *pdev) 1559 1559 { 1560 1560 struct device_node *np = pdev->dev.of_node; ··· 1595 1595 atmel_port->use_dma_tx = false; 1596 1596 } 1597 1597 1598 - return 0; 1599 1598 } 1600 1599 1601 1600 static void atmel_init_rs485(struct uart_port *port, ··· 1776 1777 if (retval) 1777 1778 goto free_irq; 1778 1779 1780 + tasklet_enable(&atmel_port->tasklet); 1781 + 1779 1782 /* 1780 1783 * Initialize DMA (if necessary) 1781 1784 */ 1782 1785 atmel_init_property(atmel_port, pdev); 1786 + atmel_set_ops(port); 1783 1787 1784 1788 if (atmel_port->prepare_rx) { 1785 1789 retval = atmel_port->prepare_rx(port); ··· 1881 1879 * Clear out any scheduled tasklets before 1882 1880 * we destroy the buffers 1883 1881 */ 1882 + tasklet_disable(&atmel_port->tasklet); 1884 1883 tasklet_kill(&atmel_port->tasklet); 1885 1884 1886 1885 /* ··· 2259 2256 struct uart_port *port = &atmel_port->uart; 2260 2257 struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev); 2261 2258 2262 - if (!atmel_init_property(atmel_port, pdev)) 2263 - atmel_set_ops(port); 2259 + atmel_init_property(atmel_port, pdev); 2260 + atmel_set_ops(port); 2264 2261 2265 2262 atmel_init_rs485(port, pdev); 2266 2263 ··· 2275 2272 2276 2273 tasklet_init(&atmel_port->tasklet, atmel_tasklet_func, 2277 2274 (unsigned long)port); 2275 + tasklet_disable(&atmel_port->tasklet); 2278 2276 2279 2277 memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring)); 2280 2278 ··· 2585 2581 struct gpio_desc *gpiod; 2586 2582 2587 2583 p->gpios = mctrl_gpio_init(dev, 0); 2588 - if (IS_ERR_OR_NULL(p->gpios)) 2589 - return -1; 2584 + if (IS_ERR(p->gpios)) 2585 + return PTR_ERR(p->gpios); 2590 2586 2591 2587 for (i = 0; i < UART_GPIO_MAX; i++) { 2592 2588 gpiod = mctrl_gpio_to_gpiod(p->gpios, i); ··· 2639 2635 spin_lock_init(&port->lock_suspended); 2640 2636 2641 2637 ret = atmel_init_gpios(port, &pdev->dev); 2642 - if (ret < 0) 2643 - dev_err(&pdev->dev, "%s", 2644 - "Failed to initialize GPIOs. The serial port may not work as expected"); 2638 + if (ret < 0) { 2639 + dev_err(&pdev->dev, "Failed to initialize GPIOs."); 2640 + goto err; 2641 + } 2645 2642 2646 2643 ret = atmel_init_port(port, pdev); 2647 2644 if (ret)
+2 -2
drivers/tty/serial/bcm63xx_uart.c
··· 854 854 855 855 ret = uart_add_one_port(&bcm_uart_driver, port); 856 856 if (ret) { 857 - ports[pdev->id].membase = 0; 857 + ports[pdev->id].membase = NULL; 858 858 return ret; 859 859 } 860 860 platform_set_drvdata(pdev, port); ··· 868 868 port = platform_get_drvdata(pdev); 869 869 uart_remove_one_port(&bcm_uart_driver, port); 870 870 /* mark port as free */ 871 - ports[pdev->id].membase = 0; 871 + ports[pdev->id].membase = NULL; 872 872 return 0; 873 873 } 874 874
+2
drivers/tty/serial/bfin_uart.c
··· 464 464 int x_pos, pos; 465 465 unsigned long flags; 466 466 467 + dma_disable_irq_nosync(uart->rx_dma_channel); 467 468 spin_lock_irqsave(&uart->rx_lock, flags); 468 469 469 470 /* 2D DMA RX buffer ring is used. Because curr_y_count and ··· 497 496 } 498 497 499 498 spin_unlock_irqrestore(&uart->rx_lock, flags); 499 + dma_enable_irq(uart->rx_dma_channel); 500 500 501 501 mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES); 502 502 }
+2
drivers/tty/serial/clps711x.c
··· 501 501 platform_set_drvdata(pdev, s); 502 502 503 503 s->gpios = mctrl_gpio_init(&pdev->dev, 0); 504 + if (IS_ERR(s->gpios)) 505 + return PTR_ERR(s->gpios); 504 506 505 507 ret = uart_add_one_port(&clps711x_uart, &s->port); 506 508 if (ret)
+1 -1
drivers/tty/serial/cpm_uart/Makefile
··· 6 6 7 7 # Select the correct platform objects. 8 8 cpm_uart-objs-$(CONFIG_CPM2) += cpm_uart_cpm2.o 9 - cpm_uart-objs-$(CONFIG_8xx) += cpm_uart_cpm1.o 9 + cpm_uart-objs-$(CONFIG_CPM1) += cpm_uart_cpm1.o 10 10 11 11 cpm_uart-objs := cpm_uart_core.o $(cpm_uart-objs-y)
+1 -1
drivers/tty/serial/cpm_uart/cpm_uart.h
··· 19 19 20 20 #if defined(CONFIG_CPM2) 21 21 #include "cpm_uart_cpm2.h" 22 - #elif defined(CONFIG_8xx) 22 + #elif defined(CONFIG_CPM1) 23 23 #include "cpm_uart_cpm1.h" 24 24 #endif 25 25
+1 -1
drivers/tty/serial/cpm_uart/cpm_uart_core.c
··· 1435 1435 return uart_remove_one_port(&cpm_reg, &pinfo->port); 1436 1436 } 1437 1437 1438 - static struct of_device_id cpm_uart_match[] = { 1438 + static const struct of_device_id cpm_uart_match[] = { 1439 1439 { 1440 1440 .compatible = "fsl,cpm1-smc-uart", 1441 1441 },
+95 -45
drivers/tty/serial/earlycon.c
··· 10 10 * it under the terms of the GNU General Public License version 2 as 11 11 * published by the Free Software Foundation. 12 12 */ 13 + 14 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 15 + 13 16 #include <linux/console.h> 14 17 #include <linux/kernel.h> 15 18 #include <linux/init.h> ··· 37 34 .con = &early_con, 38 35 }; 39 36 37 + extern struct earlycon_id __earlycon_table[]; 38 + static const struct earlycon_id __earlycon_table_sentinel 39 + __used __section(__earlycon_table_end); 40 + 40 41 static const struct of_device_id __earlycon_of_table_sentinel 41 42 __used __section(__earlycon_of_table_end); 42 43 ··· 61 54 return base; 62 55 } 63 56 64 - static int __init parse_options(struct earlycon_device *device, 65 - char *options) 57 + static int __init parse_options(struct earlycon_device *device, char *options) 66 58 { 67 59 struct uart_port *port = &device->port; 68 - int mmio, mmio32, length; 60 + int length; 69 61 unsigned long addr; 70 62 71 - if (!options) 72 - return -ENODEV; 63 + if (uart_parse_earlycon(options, &port->iotype, &addr, &options)) 64 + return -EINVAL; 73 65 74 - mmio = !strncmp(options, "mmio,", 5); 75 - mmio32 = !strncmp(options, "mmio32,", 7); 76 - if (mmio || mmio32) { 77 - port->iotype = (mmio ? UPIO_MEM : UPIO_MEM32); 78 - options += mmio ? 5 : 7; 79 - addr = simple_strtoul(options, NULL, 0); 66 + switch (port->iotype) { 67 + case UPIO_MEM32: 68 + port->regshift = 2; /* fall-through */ 69 + case UPIO_MEM: 80 70 port->mapbase = addr; 81 - if (mmio32) 82 - port->regshift = 2; 83 - } else if (!strncmp(options, "io,", 3)) { 84 - port->iotype = UPIO_PORT; 85 - options += 3; 86 - addr = simple_strtoul(options, NULL, 0); 71 + break; 72 + case UPIO_PORT: 87 73 port->iobase = addr; 88 - mmio = 0; 89 - } else if (!strncmp(options, "0x", 2)) { 90 - port->iotype = UPIO_MEM; 91 - addr = simple_strtoul(options, NULL, 0); 92 - port->mapbase = addr; 93 - } else { 74 + break; 75 + default: 94 76 return -EINVAL; 95 77 } 96 78 97 - port->uartclk = BASE_BAUD * 16; 98 - 99 - options = strchr(options, ','); 100 79 if (options) { 101 - options++; 102 80 device->baud = simple_strtoul(options, NULL, 0); 103 81 length = min(strcspn(options, " ") + 1, 104 82 (size_t)(sizeof(device->options))); ··· 92 100 93 101 if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM32) 94 102 pr_info("Early serial console at MMIO%s 0x%llx (options '%s')\n", 95 - mmio32 ? "32" : "", 103 + (port->iotype == UPIO_MEM32) ? "32" : "", 96 104 (unsigned long long)port->mapbase, 97 105 device->options); 98 106 else ··· 103 111 return 0; 104 112 } 105 113 106 - int __init setup_earlycon(char *buf, const char *match, 107 - int (*setup)(struct earlycon_device *, const char *)) 114 + static int __init register_earlycon(char *buf, const struct earlycon_id *match) 108 115 { 109 116 int err; 110 - size_t len; 111 117 struct uart_port *port = &early_console_dev.port; 112 118 113 - if (!buf || !match || !setup) 114 - return 0; 115 - 116 - len = strlen(match); 117 - if (strncmp(buf, match, len)) 118 - return 0; 119 - if (buf[len] && (buf[len] != ',')) 120 - return 0; 121 - 122 - buf += len + 1; 123 - 124 - err = parse_options(&early_console_dev, buf); 125 119 /* On parsing error, pass the options buf to the setup function */ 126 - if (!err) 120 + if (buf && !parse_options(&early_console_dev, buf)) 127 121 buf = NULL; 128 122 123 + port->uartclk = BASE_BAUD * 16; 129 124 if (port->mapbase) 130 125 port->membase = earlycon_map(port->mapbase, 64); 131 126 132 127 early_console_dev.con->data = &early_console_dev; 133 - err = setup(&early_console_dev, buf); 128 + err = match->setup(&early_console_dev, buf); 134 129 if (err < 0) 135 130 return err; 136 131 if (!early_console_dev.con->write) ··· 126 147 register_console(early_console_dev.con); 127 148 return 0; 128 149 } 150 + 151 + /** 152 + * setup_earlycon - match and register earlycon console 153 + * @buf: earlycon param string 154 + * 155 + * Registers the earlycon console matching the earlycon specified 156 + * in the param string @buf. Acceptable param strings are of the form 157 + * <name>,io|mmio|mmio32,<addr>,<options> 158 + * <name>,0x<addr>,<options> 159 + * <name>,<options> 160 + * <name> 161 + * 162 + * Only for the third form does the earlycon setup() method receive the 163 + * <options> string in the 'options' parameter; all other forms set 164 + * the parameter to NULL. 165 + * 166 + * Returns 0 if an attempt to register the earlycon was made, 167 + * otherwise negative error code 168 + */ 169 + int __init setup_earlycon(char *buf) 170 + { 171 + const struct earlycon_id *match; 172 + 173 + if (!buf || !buf[0]) 174 + return -EINVAL; 175 + 176 + if (early_con.flags & CON_ENABLED) 177 + return -EALREADY; 178 + 179 + for (match = __earlycon_table; match->name[0]; match++) { 180 + size_t len = strlen(match->name); 181 + 182 + if (strncmp(buf, match->name, len)) 183 + continue; 184 + 185 + if (buf[len]) { 186 + if (buf[len] != ',') 187 + continue; 188 + buf += len + 1; 189 + } else 190 + buf = NULL; 191 + 192 + return register_earlycon(buf, match); 193 + } 194 + 195 + return -ENOENT; 196 + } 197 + 198 + /* early_param wrapper for setup_earlycon() */ 199 + static int __init param_setup_earlycon(char *buf) 200 + { 201 + int err; 202 + 203 + /* 204 + * Just 'earlycon' is a valid param for devicetree earlycons; 205 + * don't generate a warning from parse_early_params() in that case 206 + */ 207 + if (!buf || !buf[0]) 208 + return 0; 209 + 210 + err = setup_earlycon(buf); 211 + if (err == -ENOENT) { 212 + pr_warn("no match for %s\n", buf); 213 + err = 0; 214 + } else if (err == -EALREADY) { 215 + pr_warn("already registered\n"); 216 + err = 0; 217 + } 218 + return err; 219 + } 220 + early_param("earlycon", param_setup_earlycon); 129 221 130 222 int __init of_setup_earlycon(unsigned long addr, 131 223 int (*setup)(struct earlycon_device *, const char *))
+1 -1
drivers/tty/serial/fsl_lpuart.c
··· 257 257 struct timer_list lpuart_timer; 258 258 }; 259 259 260 - static struct of_device_id lpuart_dt_ids[] = { 260 + static const struct of_device_id lpuart_dt_ids[] = { 261 261 { 262 262 .compatible = "fsl,vf610-lpuart", 263 263 },
+121 -196
drivers/tty/serial/imx.c
··· 1 1 /* 2 - * Driver for Motorola IMX serial ports 2 + * Driver for Motorola/Freescale IMX serial ports 3 3 * 4 - * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. 4 + * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. 5 5 * 6 - * Author: Sascha Hauer <sascha@saschahauer.de> 7 - * Copyright (C) 2004 Pengutronix 8 - * 9 - * Copyright (C) 2009 emlix GmbH 10 - * Author: Fabian Godehardt (added IrDA support for iMX) 6 + * Author: Sascha Hauer <sascha@saschahauer.de> 7 + * Copyright (C) 2004 Pengutronix 11 8 * 12 9 * This program is free software; you can redistribute it and/or modify 13 10 * it under the terms of the GNU General Public License as published by ··· 15 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 20 * GNU General Public License for more details. 18 - * 19 - * You should have received a copy of the GNU General Public License 20 - * along with this program; if not, write to the Free Software 21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 - * 23 - * [29-Mar-2005] Mike Lee 24 - * Added hardware handshake 25 21 */ 26 22 27 23 #if defined(CONFIG_SERIAL_IMX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) ··· 179 189 180 190 #define UART_NR 8 181 191 182 - /* i.mx21 type uart runs on all i.mx except i.mx1 */ 192 + /* i.MX21 type uart runs on all i.mx except i.MX1 and i.MX6q */ 183 193 enum imx_uart_type { 184 194 IMX1_UART, 185 195 IMX21_UART, ··· 196 206 struct uart_port port; 197 207 struct timer_list timer; 198 208 unsigned int old_status; 199 - int txirq, rxirq, rtsirq; 200 209 unsigned int have_rtscts:1; 201 210 unsigned int dte_mode:1; 202 - unsigned int use_irda:1; 203 211 unsigned int irda_inv_rx:1; 204 212 unsigned int irda_inv_tx:1; 205 213 unsigned short trcv_delay; /* transceiver delay */ ··· 223 235 unsigned int ucr2; 224 236 unsigned int ucr3; 225 237 }; 226 - 227 - #ifdef CONFIG_IRDA 228 - #define USE_IRDA(sport) ((sport)->use_irda) 229 - #else 230 - #define USE_IRDA(sport) (0) 231 - #endif 232 238 233 239 static struct imx_uart_data imx_uart_devdata[] = { 234 240 [IMX1_UART] = { ··· 255 273 }; 256 274 MODULE_DEVICE_TABLE(platform, imx_uart_devtype); 257 275 258 - static struct of_device_id imx_uart_dt_ids[] = { 276 + static const struct of_device_id imx_uart_dt_ids[] = { 259 277 { .compatible = "fsl,imx6q-uart", .data = &imx_uart_devdata[IMX6Q_UART], }, 260 278 { .compatible = "fsl,imx1-uart", .data = &imx_uart_devdata[IMX1_UART], }, 261 279 { .compatible = "fsl,imx21-uart", .data = &imx_uart_devdata[IMX21_UART], }, ··· 358 376 struct imx_port *sport = (struct imx_port *)port; 359 377 unsigned long temp; 360 378 361 - if (USE_IRDA(sport)) { 362 - /* half duplex - wait for end of transmission */ 363 - int n = 256; 364 - while ((--n > 0) && 365 - !(readl(sport->port.membase + USR2) & USR2_TXDC)) { 366 - udelay(5); 367 - barrier(); 368 - } 369 - /* 370 - * irda transceiver - wait a bit more to avoid 371 - * cutoff, hardware dependent 372 - */ 373 - udelay(sport->trcv_delay); 374 - 375 - /* 376 - * half duplex - reactivate receive mode, 377 - * flush receive pipe echo crap 378 - */ 379 - if (readl(sport->port.membase + USR2) & USR2_TXDC) { 380 - temp = readl(sport->port.membase + UCR1); 381 - temp &= ~(UCR1_TXMPTYEN | UCR1_TRDYEN); 382 - writel(temp, sport->port.membase + UCR1); 383 - 384 - temp = readl(sport->port.membase + UCR4); 385 - temp &= ~(UCR4_TCEN); 386 - writel(temp, sport->port.membase + UCR4); 387 - 388 - while (readl(sport->port.membase + URXD0) & 389 - URXD_CHARRDY) 390 - barrier(); 391 - 392 - temp = readl(sport->port.membase + UCR1); 393 - temp |= UCR1_RRDYEN; 394 - writel(temp, sport->port.membase + UCR1); 395 - 396 - temp = readl(sport->port.membase + UCR4); 397 - temp |= UCR4_DREN; 398 - writel(temp, sport->port.membase + UCR4); 399 - } 400 - return; 401 - } 402 - 403 379 /* 404 380 * We are maybe in the SMP context, so if the DMA TX thread is running 405 381 * on other cpu, we have to wait for it to finish. ··· 365 425 if (sport->dma_is_enabled && sport->dma_is_txing) 366 426 return; 367 427 368 - temp = readl(sport->port.membase + UCR1); 369 - writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1); 428 + temp = readl(port->membase + UCR1); 429 + writel(temp & ~UCR1_TXMPTYEN, port->membase + UCR1); 430 + 431 + /* in rs485 mode disable transmitter if shifter is empty */ 432 + if (port->rs485.flags & SER_RS485_ENABLED && 433 + readl(port->membase + USR2) & USR2_TXDC) { 434 + temp = readl(port->membase + UCR2); 435 + if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) 436 + temp &= ~UCR2_CTS; 437 + else 438 + temp |= UCR2_CTS; 439 + writel(temp, port->membase + UCR2); 440 + 441 + temp = readl(port->membase + UCR4); 442 + temp &= ~UCR4_TCEN; 443 + writel(temp, port->membase + UCR4); 444 + } 370 445 } 371 446 372 447 /* ··· 575 620 struct imx_port *sport = (struct imx_port *)port; 576 621 unsigned long temp; 577 622 578 - if (USE_IRDA(sport)) { 579 - /* half duplex in IrDA mode; have to disable receive mode */ 580 - temp = readl(sport->port.membase + UCR4); 581 - temp &= ~(UCR4_DREN); 582 - writel(temp, sport->port.membase + UCR4); 623 + if (port->rs485.flags & SER_RS485_ENABLED) { 624 + /* enable transmitter and shifter empty irq */ 625 + temp = readl(port->membase + UCR2); 626 + if (port->rs485.flags & SER_RS485_RTS_ON_SEND) 627 + temp &= ~UCR2_CTS; 628 + else 629 + temp |= UCR2_CTS; 630 + writel(temp, port->membase + UCR2); 583 631 584 - temp = readl(sport->port.membase + UCR1); 585 - temp &= ~(UCR1_RRDYEN); 586 - writel(temp, sport->port.membase + UCR1); 632 + temp = readl(port->membase + UCR4); 633 + temp |= UCR4_TCEN; 634 + writel(temp, port->membase + UCR4); 587 635 } 588 636 589 637 if (!sport->dma_is_enabled) { 590 638 temp = readl(sport->port.membase + UCR1); 591 639 writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1); 592 - } 593 - 594 - if (USE_IRDA(sport)) { 595 - temp = readl(sport->port.membase + UCR1); 596 - temp |= UCR1_TRDYEN; 597 - writel(temp, sport->port.membase + UCR1); 598 - 599 - temp = readl(sport->port.membase + UCR4); 600 - temp |= UCR4_TCEN; 601 - writel(temp, sport->port.membase + UCR4); 602 640 } 603 641 604 642 if (sport->dma_is_enabled) { ··· 744 796 unsigned int sts2; 745 797 746 798 sts = readl(sport->port.membase + USR1); 799 + sts2 = readl(sport->port.membase + USR2); 747 800 748 801 if (sts & USR1_RRDY) { 749 802 if (sport->dma_is_enabled) ··· 753 804 imx_rxint(irq, dev_id); 754 805 } 755 806 756 - if (sts & USR1_TRDY && 757 - readl(sport->port.membase + UCR1) & UCR1_TXMPTYEN) 807 + if ((sts & USR1_TRDY && 808 + readl(sport->port.membase + UCR1) & UCR1_TXMPTYEN) || 809 + (sts2 & USR2_TXDC && 810 + readl(sport->port.membase + UCR4) & UCR4_TCEN)) 758 811 imx_txint(irq, dev_id); 759 812 760 813 if (sts & USR1_RTSD) ··· 765 814 if (sts & USR1_AWAKE) 766 815 writel(USR1_AWAKE, sport->port.membase + USR1); 767 816 768 - sts2 = readl(sport->port.membase + USR2); 769 817 if (sts2 & USR2_ORE) { 770 818 dev_err(sport->port.dev, "Rx FIFO overrun\n"); 771 819 sport->port.icount.overrun++; 772 - writel(sts2 | USR2_ORE, sport->port.membase + USR2); 820 + writel(USR2_ORE, sport->port.membase + USR2); 773 821 } 774 822 775 823 return IRQ_HANDLED; ··· 816 866 struct imx_port *sport = (struct imx_port *)port; 817 867 unsigned long temp; 818 868 819 - temp = readl(sport->port.membase + UCR2) & ~(UCR2_CTS | UCR2_CTSC); 820 - if (mctrl & TIOCM_RTS) 821 - temp |= UCR2_CTS | UCR2_CTSC; 822 - 823 - writel(temp, sport->port.membase + UCR2); 869 + if (!(port->rs485.flags & SER_RS485_ENABLED)) { 870 + temp = readl(sport->port.membase + UCR2); 871 + temp &= ~(UCR2_CTS | UCR2_CTSC); 872 + if (mctrl & TIOCM_RTS) 873 + temp |= UCR2_CTS | UCR2_CTSC; 874 + writel(temp, sport->port.membase + UCR2); 875 + } 824 876 825 877 temp = readl(sport->port.membase + uts_reg(sport)) & ~UTS_LOOP; 826 878 if (mctrl & TIOCM_LOOP) ··· 1108 1156 */ 1109 1157 temp = readl(sport->port.membase + UCR4); 1110 1158 1111 - if (USE_IRDA(sport)) 1112 - temp |= UCR4_IRSC; 1113 - 1114 1159 /* set the trigger level for CTS */ 1115 1160 temp &= ~(UCR4_CTSTL_MASK << UCR4_CTSTL_SHF); 1116 1161 temp |= CTSTL << UCR4_CTSTL_SHF; ··· 1130 1181 imx_uart_dma_init(sport); 1131 1182 1132 1183 spin_lock_irqsave(&sport->port.lock, flags); 1184 + 1133 1185 /* 1134 1186 * Finally, clear and enable interrupts 1135 1187 */ 1136 1188 writel(USR1_RTSD, sport->port.membase + USR1); 1189 + writel(USR2_ORE, sport->port.membase + USR2); 1137 1190 1138 1191 if (sport->dma_is_inited && !sport->dma_is_enabled) 1139 1192 imx_enable_dma(sport); ··· 1143 1192 temp = readl(sport->port.membase + UCR1); 1144 1193 temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN; 1145 1194 1146 - if (USE_IRDA(sport)) { 1147 - temp |= UCR1_IREN; 1148 - temp &= ~(UCR1_RTSDEN); 1149 - } 1150 - 1151 1195 writel(temp, sport->port.membase + UCR1); 1152 - 1153 - /* Clear any pending ORE flag before enabling interrupt */ 1154 - temp = readl(sport->port.membase + USR2); 1155 - writel(temp | USR2_ORE, sport->port.membase + USR2); 1156 1196 1157 1197 temp = readl(sport->port.membase + UCR4); 1158 1198 temp |= UCR4_OREN; ··· 1161 1219 writel(temp, sport->port.membase + UCR3); 1162 1220 } 1163 1221 1164 - if (USE_IRDA(sport)) { 1165 - temp = readl(sport->port.membase + UCR4); 1166 - if (sport->irda_inv_rx) 1167 - temp |= UCR4_INVR; 1168 - else 1169 - temp &= ~(UCR4_INVR); 1170 - writel(temp | UCR4_DREN, sport->port.membase + UCR4); 1171 - 1172 - temp = readl(sport->port.membase + UCR3); 1173 - if (sport->irda_inv_tx) 1174 - temp |= UCR3_INVT; 1175 - else 1176 - temp &= ~(UCR3_INVT); 1177 - writel(temp, sport->port.membase + UCR3); 1178 - } 1179 - 1180 1222 /* 1181 1223 * Enable modem status interrupts 1182 1224 */ 1183 1225 imx_enable_ms(&sport->port); 1184 1226 spin_unlock_irqrestore(&sport->port.lock, flags); 1185 - 1186 - if (USE_IRDA(sport)) { 1187 - struct imxuart_platform_data *pdata; 1188 - pdata = dev_get_platdata(sport->port.dev); 1189 - sport->irda_inv_rx = pdata->irda_inv_rx; 1190 - sport->irda_inv_tx = pdata->irda_inv_tx; 1191 - sport->trcv_delay = pdata->transceiver_delay; 1192 - if (pdata->irda_enable) 1193 - pdata->irda_enable(1); 1194 - } 1195 1227 1196 1228 return 0; 1197 1229 } ··· 1202 1286 writel(temp, sport->port.membase + UCR2); 1203 1287 spin_unlock_irqrestore(&sport->port.lock, flags); 1204 1288 1205 - if (USE_IRDA(sport)) { 1206 - struct imxuart_platform_data *pdata; 1207 - pdata = dev_get_platdata(sport->port.dev); 1208 - if (pdata->irda_enable) 1209 - pdata->irda_enable(0); 1210 - } 1211 - 1212 1289 /* 1213 1290 * Stop our timer. 1214 1291 */ ··· 1214 1305 spin_lock_irqsave(&sport->port.lock, flags); 1215 1306 temp = readl(sport->port.membase + UCR1); 1216 1307 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); 1217 - if (USE_IRDA(sport)) 1218 - temp &= ~(UCR1_IREN); 1219 1308 1220 1309 writel(temp, sport->port.membase + UCR1); 1221 1310 spin_unlock_irqrestore(&sport->port.lock, flags); ··· 1227 1320 struct imx_port *sport = (struct imx_port *)port; 1228 1321 struct scatterlist *sgl = &sport->tx_sgl[0]; 1229 1322 unsigned long temp; 1230 - int i = 100, ubir, ubmr, ubrc, uts; 1323 + int i = 100, ubir, ubmr, uts; 1231 1324 1232 1325 if (!sport->dma_chan_tx) 1233 1326 return; ··· 1252 1345 */ 1253 1346 ubir = readl(sport->port.membase + UBIR); 1254 1347 ubmr = readl(sport->port.membase + UBMR); 1255 - ubrc = readl(sport->port.membase + UBRC); 1256 1348 uts = readl(sport->port.membase + IMX21_UTS); 1257 1349 1258 1350 temp = readl(sport->port.membase + UCR2); ··· 1264 1358 /* Restore the registers */ 1265 1359 writel(ubir, sport->port.membase + UBIR); 1266 1360 writel(ubmr, sport->port.membase + UBMR); 1267 - writel(ubrc, sport->port.membase + UBRC); 1268 1361 writel(uts, sport->port.membase + IMX21_UTS); 1269 1362 } 1270 1363 ··· 1278 1373 unsigned int div, ufcr; 1279 1374 unsigned long num, denom; 1280 1375 uint64_t tdiv64; 1281 - 1282 - /* 1283 - * If we don't support modem control lines, don't allow 1284 - * these to be set. 1285 - */ 1286 - if (0) { 1287 - termios->c_cflag &= ~(HUPCL | CRTSCTS | CMSPAR); 1288 - termios->c_cflag |= CLOCAL; 1289 - } 1290 1376 1291 1377 /* 1292 1378 * We only support CS7 and CS8. ··· 1297 1401 if (termios->c_cflag & CRTSCTS) { 1298 1402 if (sport->have_rtscts) { 1299 1403 ucr2 &= ~UCR2_IRTS; 1300 - ucr2 |= UCR2_CTSC; 1404 + 1405 + if (port->rs485.flags & SER_RS485_ENABLED) { 1406 + /* 1407 + * RTS is mandatory for rs485 operation, so keep 1408 + * it under manual control and keep transmitter 1409 + * disabled. 1410 + */ 1411 + if (!(port->rs485.flags & 1412 + SER_RS485_RTS_AFTER_SEND)) 1413 + ucr2 |= UCR2_CTS; 1414 + } else { 1415 + ucr2 |= UCR2_CTSC; 1416 + } 1301 1417 } else { 1302 1418 termios->c_cflag &= ~CRTSCTS; 1303 1419 } 1304 - } 1420 + } else if (port->rs485.flags & SER_RS485_ENABLED) 1421 + /* disable transmitter */ 1422 + if (!(port->rs485.flags & SER_RS485_RTS_AFTER_SEND)) 1423 + ucr2 |= UCR2_CTS; 1305 1424 1306 1425 if (termios->c_cflag & CSTOPB) 1307 1426 ucr2 |= UCR2_STPB; ··· 1382 1471 sport->port.membase + UCR2); 1383 1472 old_txrxen &= (UCR2_TXEN | UCR2_RXEN); 1384 1473 1385 - if (USE_IRDA(sport)) { 1386 - /* 1387 - * use maximum available submodule frequency to 1388 - * avoid missing short pulses due to low sampling rate 1389 - */ 1390 - div = 1; 1391 - } else { 1392 - /* custom-baudrate handling */ 1393 - div = sport->port.uartclk / (baud * 16); 1394 - if (baud == 38400 && quot != div) 1395 - baud = sport->port.uartclk / (quot * 16); 1474 + /* custom-baudrate handling */ 1475 + div = sport->port.uartclk / (baud * 16); 1476 + if (baud == 38400 && quot != div) 1477 + baud = sport->port.uartclk / (quot * 16); 1396 1478 1397 - div = sport->port.uartclk / (baud * 16); 1398 - if (div > 7) 1399 - div = 7; 1400 - if (!div) 1401 - div = 1; 1402 - } 1479 + div = sport->port.uartclk / (baud * 16); 1480 + if (div > 7) 1481 + div = 7; 1482 + if (!div) 1483 + div = 1; 1403 1484 1404 1485 rational_best_approximation(16 * div * baud, sport->port.uartclk, 1405 1486 1 << 16, 1 << 16, &num, &denom); ··· 1537 1634 } while (~status & USR2_TXDC); 1538 1635 } 1539 1636 #endif 1637 + 1638 + static int imx_rs485_config(struct uart_port *port, 1639 + struct serial_rs485 *rs485conf) 1640 + { 1641 + struct imx_port *sport = (struct imx_port *)port; 1642 + 1643 + /* unimplemented */ 1644 + rs485conf->delay_rts_before_send = 0; 1645 + rs485conf->delay_rts_after_send = 0; 1646 + rs485conf->flags |= SER_RS485_RX_DURING_TX; 1647 + 1648 + /* RTS is required to control the transmitter */ 1649 + if (!sport->have_rtscts) 1650 + rs485conf->flags &= ~SER_RS485_ENABLED; 1651 + 1652 + if (rs485conf->flags & SER_RS485_ENABLED) { 1653 + unsigned long temp; 1654 + 1655 + /* disable transmitter */ 1656 + temp = readl(sport->port.membase + UCR2); 1657 + temp &= ~UCR2_CTSC; 1658 + if (rs485conf->flags & SER_RS485_RTS_AFTER_SEND) 1659 + temp &= ~UCR2_CTS; 1660 + else 1661 + temp |= UCR2_CTS; 1662 + writel(temp, sport->port.membase + UCR2); 1663 + } 1664 + 1665 + port->rs485 = *rs485conf; 1666 + 1667 + return 0; 1668 + } 1540 1669 1541 1670 static struct uart_ops imx_pops = { 1542 1671 .tx_empty = imx_tx_empty, ··· 1862 1927 if (of_get_property(np, "fsl,uart-has-rtscts", NULL)) 1863 1928 sport->have_rtscts = 1; 1864 1929 1865 - if (of_get_property(np, "fsl,irda-mode", NULL)) 1866 - sport->use_irda = 1; 1867 - 1868 1930 if (of_get_property(np, "fsl,dte-mode", NULL)) 1869 1931 sport->dte_mode = 1; 1870 1932 ··· 1890 1958 1891 1959 if (pdata->flags & IMXUART_HAVE_RTSCTS) 1892 1960 sport->have_rtscts = 1; 1893 - 1894 - if (pdata->flags & IMXUART_IRDA) 1895 - sport->use_irda = 1; 1896 1961 } 1897 1962 1898 1963 static int serial_imx_probe(struct platform_device *pdev) ··· 1898 1969 void __iomem *base; 1899 1970 int ret = 0; 1900 1971 struct resource *res; 1972 + int txirq, rxirq, rtsirq; 1901 1973 1902 1974 sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); 1903 1975 if (!sport) ··· 1915 1985 if (IS_ERR(base)) 1916 1986 return PTR_ERR(base); 1917 1987 1988 + rxirq = platform_get_irq(pdev, 0); 1989 + txirq = platform_get_irq(pdev, 1); 1990 + rtsirq = platform_get_irq(pdev, 2); 1991 + 1918 1992 sport->port.dev = &pdev->dev; 1919 1993 sport->port.mapbase = res->start; 1920 1994 sport->port.membase = base; 1921 1995 sport->port.type = PORT_IMX, 1922 1996 sport->port.iotype = UPIO_MEM; 1923 - sport->port.irq = platform_get_irq(pdev, 0); 1924 - sport->rxirq = platform_get_irq(pdev, 0); 1925 - sport->txirq = platform_get_irq(pdev, 1); 1926 - sport->rtsirq = platform_get_irq(pdev, 2); 1997 + sport->port.irq = rxirq; 1927 1998 sport->port.fifosize = 32; 1928 1999 sport->port.ops = &imx_pops; 2000 + sport->port.rs485_config = imx_rs485_config; 2001 + sport->port.rs485.flags = 2002 + SER_RS485_RTS_ON_SEND | SER_RS485_RX_DURING_TX; 1929 2003 sport->port.flags = UPF_BOOT_AUTOCONF; 1930 2004 init_timer(&sport->timer); 1931 2005 sport->timer.function = imx_timeout; ··· 1955 2021 * Allocate the IRQ(s) i.MX1 has three interrupts whereas later 1956 2022 * chips only have one interrupt. 1957 2023 */ 1958 - if (sport->txirq > 0) { 1959 - ret = devm_request_irq(&pdev->dev, sport->rxirq, imx_rxint, 0, 2024 + if (txirq > 0) { 2025 + ret = devm_request_irq(&pdev->dev, rxirq, imx_rxint, 0, 1960 2026 dev_name(&pdev->dev), sport); 1961 2027 if (ret) 1962 2028 return ret; 1963 2029 1964 - ret = devm_request_irq(&pdev->dev, sport->txirq, imx_txint, 0, 2030 + ret = devm_request_irq(&pdev->dev, txirq, imx_txint, 0, 1965 2031 dev_name(&pdev->dev), sport); 1966 2032 if (ret) 1967 2033 return ret; 1968 - 1969 - /* do not use RTS IRQ on IrDA */ 1970 - if (!USE_IRDA(sport)) { 1971 - ret = devm_request_irq(&pdev->dev, sport->rtsirq, 1972 - imx_rtsint, 0, 1973 - dev_name(&pdev->dev), sport); 1974 - if (ret) 1975 - return ret; 1976 - } 1977 2034 } else { 1978 - ret = devm_request_irq(&pdev->dev, sport->port.irq, imx_int, 0, 2035 + ret = devm_request_irq(&pdev->dev, rxirq, imx_int, 0, 1979 2036 dev_name(&pdev->dev), sport); 1980 2037 if (ret) 1981 2038 return ret;
+1 -1
drivers/tty/serial/jsm/jsm_cls.c
··· 570 570 * verified in the interrupt routine. 571 571 */ 572 572 573 - if (port > brd->nasync) 573 + if (port >= brd->nasync) 574 574 return; 575 575 576 576 ch = brd->channels[port];
+3 -3
drivers/tty/serial/jsm/jsm_neo.c
··· 724 724 if (!brd) 725 725 return; 726 726 727 - if (port > brd->maxports) 727 + if (port >= brd->maxports) 728 728 return; 729 729 730 730 ch = brd->channels[port]; ··· 840 840 if (!brd) 841 841 return; 842 842 843 - if (port > brd->maxports) 843 + if (port >= brd->maxports) 844 844 return; 845 845 846 846 ch = brd->channels[port]; ··· 1180 1180 */ 1181 1181 1182 1182 /* Verify the port is in range. */ 1183 - if (port > brd->nasync) 1183 + if (port >= brd->nasync) 1184 1184 continue; 1185 1185 1186 1186 ch = brd->channels[port];
+1 -1
drivers/tty/serial/max3100.c
··· 782 782 pdata = dev_get_platdata(&spi->dev); 783 783 max3100s[i]->crystal = pdata->crystal; 784 784 max3100s[i]->loopback = pdata->loopback; 785 - max3100s[i]->poll_time = pdata->poll_time * HZ / 1000; 785 + max3100s[i]->poll_time = msecs_to_jiffies(pdata->poll_time); 786 786 if (pdata->poll_time > 0 && max3100s[i]->poll_time == 0) 787 787 max3100s[i]->poll_time = 1; 788 788 max3100s[i]->max3100_hw_suspend = pdata->max3100_hw_suspend;
-1505
drivers/tty/serial/mfd.c
··· 1 - /* 2 - * mfd.c: driver for High Speed UART device of Intel Medfield platform 3 - * 4 - * Refer pxa.c, 8250.c and some other drivers in drivers/serial/ 5 - * 6 - * (C) Copyright 2010 Intel Corporation 7 - * 8 - * This program is free software; you can redistribute it and/or 9 - * modify it under the terms of the GNU General Public License 10 - * as published by the Free Software Foundation; version 2 11 - * of the License. 12 - */ 13 - 14 - /* Notes: 15 - * 1. DMA channel allocation: 0/1 channel are assigned to port 0, 16 - * 2/3 chan to port 1, 4/5 chan to port 3. Even number chans 17 - * are used for RX, odd chans for TX 18 - * 19 - * 2. The RI/DSR/DCD/DTR are not pinned out, DCD & DSR are always 20 - * asserted, only when the HW is reset the DDCD and DDSR will 21 - * be triggered 22 - */ 23 - 24 - #if defined(CONFIG_SERIAL_MFD_HSU_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 25 - #define SUPPORT_SYSRQ 26 - #endif 27 - 28 - #include <linux/module.h> 29 - #include <linux/init.h> 30 - #include <linux/console.h> 31 - #include <linux/sysrq.h> 32 - #include <linux/slab.h> 33 - #include <linux/serial_reg.h> 34 - #include <linux/circ_buf.h> 35 - #include <linux/delay.h> 36 - #include <linux/interrupt.h> 37 - #include <linux/tty.h> 38 - #include <linux/tty_flip.h> 39 - #include <linux/serial_core.h> 40 - #include <linux/serial_mfd.h> 41 - #include <linux/dma-mapping.h> 42 - #include <linux/pci.h> 43 - #include <linux/nmi.h> 44 - #include <linux/io.h> 45 - #include <linux/debugfs.h> 46 - #include <linux/pm_runtime.h> 47 - 48 - #define HSU_DMA_BUF_SIZE 2048 49 - 50 - #define chan_readl(chan, offset) readl(chan->reg + offset) 51 - #define chan_writel(chan, offset, val) writel(val, chan->reg + offset) 52 - 53 - #define mfd_readl(obj, offset) readl(obj->reg + offset) 54 - #define mfd_writel(obj, offset, val) writel(val, obj->reg + offset) 55 - 56 - static int hsu_dma_enable; 57 - module_param(hsu_dma_enable, int, 0); 58 - MODULE_PARM_DESC(hsu_dma_enable, 59 - "It is a bitmap to set working mode, if bit[x] is 1, then port[x] will work in DMA mode, otherwise in PIO mode."); 60 - 61 - struct hsu_dma_buffer { 62 - u8 *buf; 63 - dma_addr_t dma_addr; 64 - u32 dma_size; 65 - u32 ofs; 66 - }; 67 - 68 - struct hsu_dma_chan { 69 - u32 id; 70 - enum dma_data_direction dirt; 71 - struct uart_hsu_port *uport; 72 - void __iomem *reg; 73 - }; 74 - 75 - struct uart_hsu_port { 76 - struct uart_port port; 77 - unsigned char ier; 78 - unsigned char lcr; 79 - unsigned char mcr; 80 - unsigned int lsr_break_flag; 81 - char name[12]; 82 - int index; 83 - struct device *dev; 84 - 85 - struct hsu_dma_chan *txc; 86 - struct hsu_dma_chan *rxc; 87 - struct hsu_dma_buffer txbuf; 88 - struct hsu_dma_buffer rxbuf; 89 - int use_dma; /* flag for DMA/PIO */ 90 - int running; 91 - int dma_tx_on; 92 - }; 93 - 94 - /* Top level data structure of HSU */ 95 - struct hsu_port { 96 - void __iomem *reg; 97 - unsigned long paddr; 98 - unsigned long iolen; 99 - u32 irq; 100 - 101 - struct uart_hsu_port port[3]; 102 - struct hsu_dma_chan chans[10]; 103 - 104 - struct dentry *debugfs; 105 - }; 106 - 107 - static inline unsigned int serial_in(struct uart_hsu_port *up, int offset) 108 - { 109 - unsigned int val; 110 - 111 - if (offset > UART_MSR) { 112 - offset <<= 2; 113 - val = readl(up->port.membase + offset); 114 - } else 115 - val = (unsigned int)readb(up->port.membase + offset); 116 - 117 - return val; 118 - } 119 - 120 - static inline void serial_out(struct uart_hsu_port *up, int offset, int value) 121 - { 122 - if (offset > UART_MSR) { 123 - offset <<= 2; 124 - writel(value, up->port.membase + offset); 125 - } else { 126 - unsigned char val = value & 0xff; 127 - writeb(val, up->port.membase + offset); 128 - } 129 - } 130 - 131 - #ifdef CONFIG_DEBUG_FS 132 - 133 - #define HSU_REGS_BUFSIZE 1024 134 - 135 - 136 - static ssize_t port_show_regs(struct file *file, char __user *user_buf, 137 - size_t count, loff_t *ppos) 138 - { 139 - struct uart_hsu_port *up = file->private_data; 140 - char *buf; 141 - u32 len = 0; 142 - ssize_t ret; 143 - 144 - buf = kzalloc(HSU_REGS_BUFSIZE, GFP_KERNEL); 145 - if (!buf) 146 - return 0; 147 - 148 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 149 - "MFD HSU port[%d] regs:\n", up->index); 150 - 151 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 152 - "=================================\n"); 153 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 154 - "IER: \t\t0x%08x\n", serial_in(up, UART_IER)); 155 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 156 - "IIR: \t\t0x%08x\n", serial_in(up, UART_IIR)); 157 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 158 - "LCR: \t\t0x%08x\n", serial_in(up, UART_LCR)); 159 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 160 - "MCR: \t\t0x%08x\n", serial_in(up, UART_MCR)); 161 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 162 - "LSR: \t\t0x%08x\n", serial_in(up, UART_LSR)); 163 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 164 - "MSR: \t\t0x%08x\n", serial_in(up, UART_MSR)); 165 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 166 - "FOR: \t\t0x%08x\n", serial_in(up, UART_FOR)); 167 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 168 - "PS: \t\t0x%08x\n", serial_in(up, UART_PS)); 169 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 170 - "MUL: \t\t0x%08x\n", serial_in(up, UART_MUL)); 171 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 172 - "DIV: \t\t0x%08x\n", serial_in(up, UART_DIV)); 173 - 174 - if (len > HSU_REGS_BUFSIZE) 175 - len = HSU_REGS_BUFSIZE; 176 - 177 - ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); 178 - kfree(buf); 179 - return ret; 180 - } 181 - 182 - static ssize_t dma_show_regs(struct file *file, char __user *user_buf, 183 - size_t count, loff_t *ppos) 184 - { 185 - struct hsu_dma_chan *chan = file->private_data; 186 - char *buf; 187 - u32 len = 0; 188 - ssize_t ret; 189 - 190 - buf = kzalloc(HSU_REGS_BUFSIZE, GFP_KERNEL); 191 - if (!buf) 192 - return 0; 193 - 194 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 195 - "MFD HSU DMA channel [%d] regs:\n", chan->id); 196 - 197 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 198 - "=================================\n"); 199 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 200 - "CR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_CR)); 201 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 202 - "DCR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_DCR)); 203 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 204 - "BSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_BSR)); 205 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 206 - "MOTSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_MOTSR)); 207 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 208 - "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D0SAR)); 209 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 210 - "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D0TSR)); 211 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 212 - "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D1SAR)); 213 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 214 - "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D1TSR)); 215 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 216 - "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D2SAR)); 217 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 218 - "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D2TSR)); 219 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 220 - "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3SAR)); 221 - len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 222 - "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3TSR)); 223 - 224 - if (len > HSU_REGS_BUFSIZE) 225 - len = HSU_REGS_BUFSIZE; 226 - 227 - ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); 228 - kfree(buf); 229 - return ret; 230 - } 231 - 232 - static const struct file_operations port_regs_ops = { 233 - .owner = THIS_MODULE, 234 - .open = simple_open, 235 - .read = port_show_regs, 236 - .llseek = default_llseek, 237 - }; 238 - 239 - static const struct file_operations dma_regs_ops = { 240 - .owner = THIS_MODULE, 241 - .open = simple_open, 242 - .read = dma_show_regs, 243 - .llseek = default_llseek, 244 - }; 245 - 246 - static int hsu_debugfs_init(struct hsu_port *hsu) 247 - { 248 - int i; 249 - char name[32]; 250 - 251 - hsu->debugfs = debugfs_create_dir("hsu", NULL); 252 - if (!hsu->debugfs) 253 - return -ENOMEM; 254 - 255 - for (i = 0; i < 3; i++) { 256 - snprintf(name, sizeof(name), "port_%d_regs", i); 257 - debugfs_create_file(name, S_IFREG | S_IRUGO, 258 - hsu->debugfs, (void *)(&hsu->port[i]), &port_regs_ops); 259 - } 260 - 261 - for (i = 0; i < 6; i++) { 262 - snprintf(name, sizeof(name), "dma_chan_%d_regs", i); 263 - debugfs_create_file(name, S_IFREG | S_IRUGO, 264 - hsu->debugfs, (void *)&hsu->chans[i], &dma_regs_ops); 265 - } 266 - 267 - return 0; 268 - } 269 - 270 - static void hsu_debugfs_remove(struct hsu_port *hsu) 271 - { 272 - if (hsu->debugfs) 273 - debugfs_remove_recursive(hsu->debugfs); 274 - } 275 - 276 - #else 277 - static inline int hsu_debugfs_init(struct hsu_port *hsu) 278 - { 279 - return 0; 280 - } 281 - 282 - static inline void hsu_debugfs_remove(struct hsu_port *hsu) 283 - { 284 - } 285 - #endif /* CONFIG_DEBUG_FS */ 286 - 287 - static void serial_hsu_enable_ms(struct uart_port *port) 288 - { 289 - struct uart_hsu_port *up = 290 - container_of(port, struct uart_hsu_port, port); 291 - 292 - up->ier |= UART_IER_MSI; 293 - serial_out(up, UART_IER, up->ier); 294 - } 295 - 296 - static void hsu_dma_tx(struct uart_hsu_port *up) 297 - { 298 - struct circ_buf *xmit = &up->port.state->xmit; 299 - struct hsu_dma_buffer *dbuf = &up->txbuf; 300 - int count; 301 - 302 - /* test_and_set_bit may be better, but anyway it's in lock protected mode */ 303 - if (up->dma_tx_on) 304 - return; 305 - 306 - /* Update the circ buf info */ 307 - xmit->tail += dbuf->ofs; 308 - xmit->tail &= UART_XMIT_SIZE - 1; 309 - 310 - up->port.icount.tx += dbuf->ofs; 311 - dbuf->ofs = 0; 312 - 313 - /* Disable the channel */ 314 - chan_writel(up->txc, HSU_CH_CR, 0x0); 315 - 316 - if (!uart_circ_empty(xmit) && !uart_tx_stopped(&up->port)) { 317 - dma_sync_single_for_device(up->port.dev, 318 - dbuf->dma_addr, 319 - dbuf->dma_size, 320 - DMA_TO_DEVICE); 321 - 322 - count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); 323 - dbuf->ofs = count; 324 - 325 - /* Reprogram the channel */ 326 - chan_writel(up->txc, HSU_CH_D0SAR, dbuf->dma_addr + xmit->tail); 327 - chan_writel(up->txc, HSU_CH_D0TSR, count); 328 - 329 - /* Reenable the channel */ 330 - chan_writel(up->txc, HSU_CH_DCR, 0x1 331 - | (0x1 << 8) 332 - | (0x1 << 16) 333 - | (0x1 << 24)); 334 - up->dma_tx_on = 1; 335 - chan_writel(up->txc, HSU_CH_CR, 0x1); 336 - } 337 - 338 - if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 339 - uart_write_wakeup(&up->port); 340 - } 341 - 342 - /* The buffer is already cache coherent */ 343 - static void hsu_dma_start_rx_chan(struct hsu_dma_chan *rxc, 344 - struct hsu_dma_buffer *dbuf) 345 - { 346 - dbuf->ofs = 0; 347 - 348 - chan_writel(rxc, HSU_CH_BSR, 32); 349 - chan_writel(rxc, HSU_CH_MOTSR, 4); 350 - 351 - chan_writel(rxc, HSU_CH_D0SAR, dbuf->dma_addr); 352 - chan_writel(rxc, HSU_CH_D0TSR, dbuf->dma_size); 353 - chan_writel(rxc, HSU_CH_DCR, 0x1 | (0x1 << 8) 354 - | (0x1 << 16) 355 - | (0x1 << 24) /* timeout bit, see HSU Errata 1 */ 356 - ); 357 - chan_writel(rxc, HSU_CH_CR, 0x3); 358 - } 359 - 360 - /* Protected by spin_lock_irqsave(port->lock) */ 361 - static void serial_hsu_start_tx(struct uart_port *port) 362 - { 363 - struct uart_hsu_port *up = 364 - container_of(port, struct uart_hsu_port, port); 365 - 366 - if (up->use_dma) { 367 - hsu_dma_tx(up); 368 - } else if (!(up->ier & UART_IER_THRI)) { 369 - up->ier |= UART_IER_THRI; 370 - serial_out(up, UART_IER, up->ier); 371 - } 372 - } 373 - 374 - static void serial_hsu_stop_tx(struct uart_port *port) 375 - { 376 - struct uart_hsu_port *up = 377 - container_of(port, struct uart_hsu_port, port); 378 - struct hsu_dma_chan *txc = up->txc; 379 - 380 - if (up->use_dma) 381 - chan_writel(txc, HSU_CH_CR, 0x0); 382 - else if (up->ier & UART_IER_THRI) { 383 - up->ier &= ~UART_IER_THRI; 384 - serial_out(up, UART_IER, up->ier); 385 - } 386 - } 387 - 388 - /* This is always called in spinlock protected mode, so 389 - * modify timeout timer is safe here */ 390 - static void hsu_dma_rx(struct uart_hsu_port *up, u32 int_sts, 391 - unsigned long *flags) 392 - { 393 - struct hsu_dma_buffer *dbuf = &up->rxbuf; 394 - struct hsu_dma_chan *chan = up->rxc; 395 - struct uart_port *port = &up->port; 396 - struct tty_port *tport = &port->state->port; 397 - int count; 398 - 399 - /* 400 - * First need to know how many is already transferred, 401 - * then check if its a timeout DMA irq, and return 402 - * the trail bytes out, push them up and reenable the 403 - * channel 404 - */ 405 - 406 - /* Timeout IRQ, need wait some time, see Errata 2 */ 407 - if (int_sts & 0xf00) 408 - udelay(2); 409 - 410 - /* Stop the channel */ 411 - chan_writel(chan, HSU_CH_CR, 0x0); 412 - 413 - count = chan_readl(chan, HSU_CH_D0SAR) - dbuf->dma_addr; 414 - if (!count) { 415 - /* Restart the channel before we leave */ 416 - chan_writel(chan, HSU_CH_CR, 0x3); 417 - return; 418 - } 419 - 420 - dma_sync_single_for_cpu(port->dev, dbuf->dma_addr, 421 - dbuf->dma_size, DMA_FROM_DEVICE); 422 - 423 - /* 424 - * Head will only wrap around when we recycle 425 - * the DMA buffer, and when that happens, we 426 - * explicitly set tail to 0. So head will 427 - * always be greater than tail. 428 - */ 429 - tty_insert_flip_string(tport, dbuf->buf, count); 430 - port->icount.rx += count; 431 - 432 - dma_sync_single_for_device(up->port.dev, dbuf->dma_addr, 433 - dbuf->dma_size, DMA_FROM_DEVICE); 434 - 435 - /* Reprogram the channel */ 436 - chan_writel(chan, HSU_CH_D0SAR, dbuf->dma_addr); 437 - chan_writel(chan, HSU_CH_D0TSR, dbuf->dma_size); 438 - chan_writel(chan, HSU_CH_DCR, 0x1 439 - | (0x1 << 8) 440 - | (0x1 << 16) 441 - | (0x1 << 24) /* timeout bit, see HSU Errata 1 */ 442 - ); 443 - spin_unlock_irqrestore(&up->port.lock, *flags); 444 - tty_flip_buffer_push(tport); 445 - spin_lock_irqsave(&up->port.lock, *flags); 446 - 447 - chan_writel(chan, HSU_CH_CR, 0x3); 448 - 449 - } 450 - 451 - static void serial_hsu_stop_rx(struct uart_port *port) 452 - { 453 - struct uart_hsu_port *up = 454 - container_of(port, struct uart_hsu_port, port); 455 - struct hsu_dma_chan *chan = up->rxc; 456 - 457 - if (up->use_dma) 458 - chan_writel(chan, HSU_CH_CR, 0x2); 459 - else { 460 - up->ier &= ~UART_IER_RLSI; 461 - up->port.read_status_mask &= ~UART_LSR_DR; 462 - serial_out(up, UART_IER, up->ier); 463 - } 464 - } 465 - 466 - static inline void receive_chars(struct uart_hsu_port *up, int *status, 467 - unsigned long *flags) 468 - { 469 - unsigned int ch, flag; 470 - unsigned int max_count = 256; 471 - 472 - do { 473 - ch = serial_in(up, UART_RX); 474 - flag = TTY_NORMAL; 475 - up->port.icount.rx++; 476 - 477 - if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE | 478 - UART_LSR_FE | UART_LSR_OE))) { 479 - 480 - dev_warn(up->dev, "We really rush into ERR/BI case" 481 - "status = 0x%02x", *status); 482 - /* For statistics only */ 483 - if (*status & UART_LSR_BI) { 484 - *status &= ~(UART_LSR_FE | UART_LSR_PE); 485 - up->port.icount.brk++; 486 - /* 487 - * We do the SysRQ and SAK checking 488 - * here because otherwise the break 489 - * may get masked by ignore_status_mask 490 - * or read_status_mask. 491 - */ 492 - if (uart_handle_break(&up->port)) 493 - goto ignore_char; 494 - } else if (*status & UART_LSR_PE) 495 - up->port.icount.parity++; 496 - else if (*status & UART_LSR_FE) 497 - up->port.icount.frame++; 498 - if (*status & UART_LSR_OE) 499 - up->port.icount.overrun++; 500 - 501 - /* Mask off conditions which should be ignored. */ 502 - *status &= up->port.read_status_mask; 503 - 504 - #ifdef CONFIG_SERIAL_MFD_HSU_CONSOLE 505 - if (up->port.cons && 506 - up->port.cons->index == up->port.line) { 507 - /* Recover the break flag from console xmit */ 508 - *status |= up->lsr_break_flag; 509 - up->lsr_break_flag = 0; 510 - } 511 - #endif 512 - if (*status & UART_LSR_BI) { 513 - flag = TTY_BREAK; 514 - } else if (*status & UART_LSR_PE) 515 - flag = TTY_PARITY; 516 - else if (*status & UART_LSR_FE) 517 - flag = TTY_FRAME; 518 - } 519 - 520 - if (uart_handle_sysrq_char(&up->port, ch)) 521 - goto ignore_char; 522 - 523 - uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag); 524 - ignore_char: 525 - *status = serial_in(up, UART_LSR); 526 - } while ((*status & UART_LSR_DR) && max_count--); 527 - 528 - spin_unlock_irqrestore(&up->port.lock, *flags); 529 - tty_flip_buffer_push(&up->port.state->port); 530 - spin_lock_irqsave(&up->port.lock, *flags); 531 - } 532 - 533 - static void transmit_chars(struct uart_hsu_port *up) 534 - { 535 - struct circ_buf *xmit = &up->port.state->xmit; 536 - int count; 537 - 538 - if (up->port.x_char) { 539 - serial_out(up, UART_TX, up->port.x_char); 540 - up->port.icount.tx++; 541 - up->port.x_char = 0; 542 - return; 543 - } 544 - if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { 545 - serial_hsu_stop_tx(&up->port); 546 - return; 547 - } 548 - 549 - /* The IRQ is for TX FIFO half-empty */ 550 - count = up->port.fifosize / 2; 551 - 552 - do { 553 - serial_out(up, UART_TX, xmit->buf[xmit->tail]); 554 - xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 555 - 556 - up->port.icount.tx++; 557 - if (uart_circ_empty(xmit)) 558 - break; 559 - } while (--count > 0); 560 - 561 - if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 562 - uart_write_wakeup(&up->port); 563 - 564 - if (uart_circ_empty(xmit)) 565 - serial_hsu_stop_tx(&up->port); 566 - } 567 - 568 - static inline void check_modem_status(struct uart_hsu_port *up) 569 - { 570 - int status; 571 - 572 - status = serial_in(up, UART_MSR); 573 - 574 - if ((status & UART_MSR_ANY_DELTA) == 0) 575 - return; 576 - 577 - if (status & UART_MSR_TERI) 578 - up->port.icount.rng++; 579 - if (status & UART_MSR_DDSR) 580 - up->port.icount.dsr++; 581 - /* We may only get DDCD when HW init and reset */ 582 - if (status & UART_MSR_DDCD) 583 - uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); 584 - /* Will start/stop_tx accordingly */ 585 - if (status & UART_MSR_DCTS) 586 - uart_handle_cts_change(&up->port, status & UART_MSR_CTS); 587 - 588 - wake_up_interruptible(&up->port.state->port.delta_msr_wait); 589 - } 590 - 591 - /* 592 - * This handles the interrupt from one port. 593 - */ 594 - static irqreturn_t port_irq(int irq, void *dev_id) 595 - { 596 - struct uart_hsu_port *up = dev_id; 597 - unsigned int iir, lsr; 598 - unsigned long flags; 599 - 600 - if (unlikely(!up->running)) 601 - return IRQ_NONE; 602 - 603 - spin_lock_irqsave(&up->port.lock, flags); 604 - if (up->use_dma) { 605 - lsr = serial_in(up, UART_LSR); 606 - if (unlikely(lsr & (UART_LSR_BI | UART_LSR_PE | 607 - UART_LSR_FE | UART_LSR_OE))) 608 - dev_warn(up->dev, 609 - "Got lsr irq while using DMA, lsr = 0x%2x\n", 610 - lsr); 611 - check_modem_status(up); 612 - spin_unlock_irqrestore(&up->port.lock, flags); 613 - return IRQ_HANDLED; 614 - } 615 - 616 - iir = serial_in(up, UART_IIR); 617 - if (iir & UART_IIR_NO_INT) { 618 - spin_unlock_irqrestore(&up->port.lock, flags); 619 - return IRQ_NONE; 620 - } 621 - 622 - lsr = serial_in(up, UART_LSR); 623 - if (lsr & UART_LSR_DR) 624 - receive_chars(up, &lsr, &flags); 625 - check_modem_status(up); 626 - 627 - /* lsr will be renewed during the receive_chars */ 628 - if (lsr & UART_LSR_THRE) 629 - transmit_chars(up); 630 - 631 - spin_unlock_irqrestore(&up->port.lock, flags); 632 - return IRQ_HANDLED; 633 - } 634 - 635 - static inline void dma_chan_irq(struct hsu_dma_chan *chan) 636 - { 637 - struct uart_hsu_port *up = chan->uport; 638 - unsigned long flags; 639 - u32 int_sts; 640 - 641 - spin_lock_irqsave(&up->port.lock, flags); 642 - 643 - if (!up->use_dma || !up->running) 644 - goto exit; 645 - 646 - /* 647 - * No matter what situation, need read clear the IRQ status 648 - * There is a bug, see Errata 5, HSD 2900918 649 - */ 650 - int_sts = chan_readl(chan, HSU_CH_SR); 651 - 652 - /* Rx channel */ 653 - if (chan->dirt == DMA_FROM_DEVICE) 654 - hsu_dma_rx(up, int_sts, &flags); 655 - 656 - /* Tx channel */ 657 - if (chan->dirt == DMA_TO_DEVICE) { 658 - chan_writel(chan, HSU_CH_CR, 0x0); 659 - up->dma_tx_on = 0; 660 - hsu_dma_tx(up); 661 - } 662 - 663 - exit: 664 - spin_unlock_irqrestore(&up->port.lock, flags); 665 - return; 666 - } 667 - 668 - static irqreturn_t dma_irq(int irq, void *dev_id) 669 - { 670 - struct hsu_port *hsu = dev_id; 671 - u32 int_sts, i; 672 - 673 - int_sts = mfd_readl(hsu, HSU_GBL_DMAISR); 674 - 675 - /* Currently we only have 6 channels may be used */ 676 - for (i = 0; i < 6; i++) { 677 - if (int_sts & 0x1) 678 - dma_chan_irq(&hsu->chans[i]); 679 - int_sts >>= 1; 680 - } 681 - 682 - return IRQ_HANDLED; 683 - } 684 - 685 - static unsigned int serial_hsu_tx_empty(struct uart_port *port) 686 - { 687 - struct uart_hsu_port *up = 688 - container_of(port, struct uart_hsu_port, port); 689 - unsigned long flags; 690 - unsigned int ret; 691 - 692 - spin_lock_irqsave(&up->port.lock, flags); 693 - ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; 694 - spin_unlock_irqrestore(&up->port.lock, flags); 695 - 696 - return ret; 697 - } 698 - 699 - static unsigned int serial_hsu_get_mctrl(struct uart_port *port) 700 - { 701 - struct uart_hsu_port *up = 702 - container_of(port, struct uart_hsu_port, port); 703 - unsigned char status; 704 - unsigned int ret; 705 - 706 - status = serial_in(up, UART_MSR); 707 - 708 - ret = 0; 709 - if (status & UART_MSR_DCD) 710 - ret |= TIOCM_CAR; 711 - if (status & UART_MSR_RI) 712 - ret |= TIOCM_RNG; 713 - if (status & UART_MSR_DSR) 714 - ret |= TIOCM_DSR; 715 - if (status & UART_MSR_CTS) 716 - ret |= TIOCM_CTS; 717 - return ret; 718 - } 719 - 720 - static void serial_hsu_set_mctrl(struct uart_port *port, unsigned int mctrl) 721 - { 722 - struct uart_hsu_port *up = 723 - container_of(port, struct uart_hsu_port, port); 724 - unsigned char mcr = 0; 725 - 726 - if (mctrl & TIOCM_RTS) 727 - mcr |= UART_MCR_RTS; 728 - if (mctrl & TIOCM_DTR) 729 - mcr |= UART_MCR_DTR; 730 - if (mctrl & TIOCM_OUT1) 731 - mcr |= UART_MCR_OUT1; 732 - if (mctrl & TIOCM_OUT2) 733 - mcr |= UART_MCR_OUT2; 734 - if (mctrl & TIOCM_LOOP) 735 - mcr |= UART_MCR_LOOP; 736 - 737 - mcr |= up->mcr; 738 - 739 - serial_out(up, UART_MCR, mcr); 740 - } 741 - 742 - static void serial_hsu_break_ctl(struct uart_port *port, int break_state) 743 - { 744 - struct uart_hsu_port *up = 745 - container_of(port, struct uart_hsu_port, port); 746 - unsigned long flags; 747 - 748 - spin_lock_irqsave(&up->port.lock, flags); 749 - if (break_state == -1) 750 - up->lcr |= UART_LCR_SBC; 751 - else 752 - up->lcr &= ~UART_LCR_SBC; 753 - serial_out(up, UART_LCR, up->lcr); 754 - spin_unlock_irqrestore(&up->port.lock, flags); 755 - } 756 - 757 - /* 758 - * What special to do: 759 - * 1. chose the 64B fifo mode 760 - * 2. start dma or pio depends on configuration 761 - * 3. we only allocate dma memory when needed 762 - */ 763 - static int serial_hsu_startup(struct uart_port *port) 764 - { 765 - struct uart_hsu_port *up = 766 - container_of(port, struct uart_hsu_port, port); 767 - unsigned long flags; 768 - 769 - pm_runtime_get_sync(up->dev); 770 - 771 - /* 772 - * Clear the FIFO buffers and disable them. 773 - * (they will be reenabled in set_termios()) 774 - */ 775 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 776 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 777 - UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 778 - serial_out(up, UART_FCR, 0); 779 - 780 - /* Clear the interrupt registers. */ 781 - (void) serial_in(up, UART_LSR); 782 - (void) serial_in(up, UART_RX); 783 - (void) serial_in(up, UART_IIR); 784 - (void) serial_in(up, UART_MSR); 785 - 786 - /* Now, initialize the UART, default is 8n1 */ 787 - serial_out(up, UART_LCR, UART_LCR_WLEN8); 788 - 789 - spin_lock_irqsave(&up->port.lock, flags); 790 - 791 - up->port.mctrl |= TIOCM_OUT2; 792 - serial_hsu_set_mctrl(&up->port, up->port.mctrl); 793 - 794 - /* 795 - * Finally, enable interrupts. Note: Modem status interrupts 796 - * are set via set_termios(), which will be occurring imminently 797 - * anyway, so we don't enable them here. 798 - */ 799 - if (!up->use_dma) 800 - up->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE; 801 - else 802 - up->ier = 0; 803 - serial_out(up, UART_IER, up->ier); 804 - 805 - spin_unlock_irqrestore(&up->port.lock, flags); 806 - 807 - /* DMA init */ 808 - if (up->use_dma) { 809 - struct hsu_dma_buffer *dbuf; 810 - struct circ_buf *xmit = &port->state->xmit; 811 - 812 - up->dma_tx_on = 0; 813 - 814 - /* First allocate the RX buffer */ 815 - dbuf = &up->rxbuf; 816 - dbuf->buf = kzalloc(HSU_DMA_BUF_SIZE, GFP_KERNEL); 817 - if (!dbuf->buf) { 818 - up->use_dma = 0; 819 - goto exit; 820 - } 821 - dbuf->dma_addr = dma_map_single(port->dev, 822 - dbuf->buf, 823 - HSU_DMA_BUF_SIZE, 824 - DMA_FROM_DEVICE); 825 - dbuf->dma_size = HSU_DMA_BUF_SIZE; 826 - 827 - /* Start the RX channel right now */ 828 - hsu_dma_start_rx_chan(up->rxc, dbuf); 829 - 830 - /* Next init the TX DMA */ 831 - dbuf = &up->txbuf; 832 - dbuf->buf = xmit->buf; 833 - dbuf->dma_addr = dma_map_single(port->dev, 834 - dbuf->buf, 835 - UART_XMIT_SIZE, 836 - DMA_TO_DEVICE); 837 - dbuf->dma_size = UART_XMIT_SIZE; 838 - 839 - /* This should not be changed all around */ 840 - chan_writel(up->txc, HSU_CH_BSR, 32); 841 - chan_writel(up->txc, HSU_CH_MOTSR, 4); 842 - dbuf->ofs = 0; 843 - } 844 - 845 - exit: 846 - /* And clear the interrupt registers again for luck. */ 847 - (void) serial_in(up, UART_LSR); 848 - (void) serial_in(up, UART_RX); 849 - (void) serial_in(up, UART_IIR); 850 - (void) serial_in(up, UART_MSR); 851 - 852 - up->running = 1; 853 - return 0; 854 - } 855 - 856 - static void serial_hsu_shutdown(struct uart_port *port) 857 - { 858 - struct uart_hsu_port *up = 859 - container_of(port, struct uart_hsu_port, port); 860 - unsigned long flags; 861 - 862 - /* Disable interrupts from this port */ 863 - up->ier = 0; 864 - serial_out(up, UART_IER, 0); 865 - up->running = 0; 866 - 867 - spin_lock_irqsave(&up->port.lock, flags); 868 - up->port.mctrl &= ~TIOCM_OUT2; 869 - serial_hsu_set_mctrl(&up->port, up->port.mctrl); 870 - spin_unlock_irqrestore(&up->port.lock, flags); 871 - 872 - /* Disable break condition and FIFOs */ 873 - serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC); 874 - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 875 - UART_FCR_CLEAR_RCVR | 876 - UART_FCR_CLEAR_XMIT); 877 - serial_out(up, UART_FCR, 0); 878 - 879 - pm_runtime_put(up->dev); 880 - } 881 - 882 - static void 883 - serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios, 884 - struct ktermios *old) 885 - { 886 - struct uart_hsu_port *up = 887 - container_of(port, struct uart_hsu_port, port); 888 - unsigned char cval, fcr = 0; 889 - unsigned long flags; 890 - unsigned int baud, quot; 891 - u32 ps, mul; 892 - 893 - switch (termios->c_cflag & CSIZE) { 894 - case CS5: 895 - cval = UART_LCR_WLEN5; 896 - break; 897 - case CS6: 898 - cval = UART_LCR_WLEN6; 899 - break; 900 - case CS7: 901 - cval = UART_LCR_WLEN7; 902 - break; 903 - default: 904 - case CS8: 905 - cval = UART_LCR_WLEN8; 906 - break; 907 - } 908 - 909 - /* CMSPAR isn't supported by this driver */ 910 - termios->c_cflag &= ~CMSPAR; 911 - 912 - if (termios->c_cflag & CSTOPB) 913 - cval |= UART_LCR_STOP; 914 - if (termios->c_cflag & PARENB) 915 - cval |= UART_LCR_PARITY; 916 - if (!(termios->c_cflag & PARODD)) 917 - cval |= UART_LCR_EPAR; 918 - 919 - /* 920 - * The base clk is 50Mhz, and the baud rate come from: 921 - * baud = 50M * MUL / (DIV * PS * DLAB) 922 - * 923 - * For those basic low baud rate we can get the direct 924 - * scalar from 2746800, like 115200 = 2746800/24. For those 925 - * higher baud rate, we handle them case by case, mainly by 926 - * adjusting the MUL/PS registers, and DIV register is kept 927 - * as default value 0x3d09 to make things simple 928 - */ 929 - baud = uart_get_baud_rate(port, termios, old, 0, 4000000); 930 - 931 - quot = 1; 932 - ps = 0x10; 933 - mul = 0x3600; 934 - switch (baud) { 935 - case 3500000: 936 - mul = 0x3345; 937 - ps = 0xC; 938 - break; 939 - case 1843200: 940 - mul = 0x2400; 941 - break; 942 - case 3000000: 943 - case 2500000: 944 - case 2000000: 945 - case 1500000: 946 - case 1000000: 947 - case 500000: 948 - /* mul/ps/quot = 0x9C4/0x10/0x1 will make a 500000 bps */ 949 - mul = baud / 500000 * 0x9C4; 950 - break; 951 - default: 952 - /* Use uart_get_divisor to get quot for other baud rates */ 953 - quot = 0; 954 - } 955 - 956 - if (!quot) 957 - quot = uart_get_divisor(port, baud); 958 - 959 - if ((up->port.uartclk / quot) < (2400 * 16)) 960 - fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_1B; 961 - else if ((up->port.uartclk / quot) < (230400 * 16)) 962 - fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_16B; 963 - else 964 - fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_32B; 965 - 966 - fcr |= UART_FCR_HSU_64B_FIFO; 967 - 968 - /* 969 - * Ok, we're now changing the port state. Do it with 970 - * interrupts disabled. 971 - */ 972 - spin_lock_irqsave(&up->port.lock, flags); 973 - 974 - /* Update the per-port timeout */ 975 - uart_update_timeout(port, termios->c_cflag, baud); 976 - 977 - up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; 978 - if (termios->c_iflag & INPCK) 979 - up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; 980 - if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) 981 - up->port.read_status_mask |= UART_LSR_BI; 982 - 983 - /* Characters to ignore */ 984 - up->port.ignore_status_mask = 0; 985 - if (termios->c_iflag & IGNPAR) 986 - up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 987 - if (termios->c_iflag & IGNBRK) { 988 - up->port.ignore_status_mask |= UART_LSR_BI; 989 - /* 990 - * If we're ignoring parity and break indicators, 991 - * ignore overruns too (for real raw support). 992 - */ 993 - if (termios->c_iflag & IGNPAR) 994 - up->port.ignore_status_mask |= UART_LSR_OE; 995 - } 996 - 997 - /* Ignore all characters if CREAD is not set */ 998 - if ((termios->c_cflag & CREAD) == 0) 999 - up->port.ignore_status_mask |= UART_LSR_DR; 1000 - 1001 - /* 1002 - * CTS flow control flag and modem status interrupts, disable 1003 - * MSI by default 1004 - */ 1005 - up->ier &= ~UART_IER_MSI; 1006 - if (UART_ENABLE_MS(&up->port, termios->c_cflag)) 1007 - up->ier |= UART_IER_MSI; 1008 - 1009 - serial_out(up, UART_IER, up->ier); 1010 - 1011 - if (termios->c_cflag & CRTSCTS) 1012 - up->mcr |= UART_MCR_AFE | UART_MCR_RTS; 1013 - else 1014 - up->mcr &= ~UART_MCR_AFE; 1015 - 1016 - serial_out(up, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */ 1017 - serial_out(up, UART_DLL, quot & 0xff); /* LS of divisor */ 1018 - serial_out(up, UART_DLM, quot >> 8); /* MS of divisor */ 1019 - serial_out(up, UART_LCR, cval); /* reset DLAB */ 1020 - serial_out(up, UART_MUL, mul); /* set MUL */ 1021 - serial_out(up, UART_PS, ps); /* set PS */ 1022 - up->lcr = cval; /* Save LCR */ 1023 - serial_hsu_set_mctrl(&up->port, up->port.mctrl); 1024 - serial_out(up, UART_FCR, fcr); 1025 - spin_unlock_irqrestore(&up->port.lock, flags); 1026 - } 1027 - 1028 - static void 1029 - serial_hsu_pm(struct uart_port *port, unsigned int state, 1030 - unsigned int oldstate) 1031 - { 1032 - } 1033 - 1034 - static void serial_hsu_release_port(struct uart_port *port) 1035 - { 1036 - } 1037 - 1038 - static int serial_hsu_request_port(struct uart_port *port) 1039 - { 1040 - return 0; 1041 - } 1042 - 1043 - static void serial_hsu_config_port(struct uart_port *port, int flags) 1044 - { 1045 - struct uart_hsu_port *up = 1046 - container_of(port, struct uart_hsu_port, port); 1047 - up->port.type = PORT_MFD; 1048 - } 1049 - 1050 - static int 1051 - serial_hsu_verify_port(struct uart_port *port, struct serial_struct *ser) 1052 - { 1053 - /* We don't want the core code to modify any port params */ 1054 - return -EINVAL; 1055 - } 1056 - 1057 - static const char * 1058 - serial_hsu_type(struct uart_port *port) 1059 - { 1060 - struct uart_hsu_port *up = 1061 - container_of(port, struct uart_hsu_port, port); 1062 - return up->name; 1063 - } 1064 - 1065 - /* Mainly for uart console use */ 1066 - static struct uart_hsu_port *serial_hsu_ports[3]; 1067 - static struct uart_driver serial_hsu_reg; 1068 - 1069 - #ifdef CONFIG_SERIAL_MFD_HSU_CONSOLE 1070 - 1071 - #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 1072 - 1073 - /* Wait for transmitter & holding register to empty */ 1074 - static inline void wait_for_xmitr(struct uart_hsu_port *up) 1075 - { 1076 - unsigned int status, tmout = 1000; 1077 - 1078 - /* Wait up to 1ms for the character to be sent. */ 1079 - do { 1080 - status = serial_in(up, UART_LSR); 1081 - 1082 - if (status & UART_LSR_BI) 1083 - up->lsr_break_flag = UART_LSR_BI; 1084 - 1085 - if (--tmout == 0) 1086 - break; 1087 - udelay(1); 1088 - } while (!(status & BOTH_EMPTY)); 1089 - 1090 - /* Wait up to 1s for flow control if necessary */ 1091 - if (up->port.flags & UPF_CONS_FLOW) { 1092 - tmout = 1000000; 1093 - while (--tmout && 1094 - ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0)) 1095 - udelay(1); 1096 - } 1097 - } 1098 - 1099 - static void serial_hsu_console_putchar(struct uart_port *port, int ch) 1100 - { 1101 - struct uart_hsu_port *up = 1102 - container_of(port, struct uart_hsu_port, port); 1103 - 1104 - wait_for_xmitr(up); 1105 - serial_out(up, UART_TX, ch); 1106 - } 1107 - 1108 - /* 1109 - * Print a string to the serial port trying not to disturb 1110 - * any possible real use of the port... 1111 - * 1112 - * The console_lock must be held when we get here. 1113 - */ 1114 - static void 1115 - serial_hsu_console_write(struct console *co, const char *s, unsigned int count) 1116 - { 1117 - struct uart_hsu_port *up = serial_hsu_ports[co->index]; 1118 - unsigned long flags; 1119 - unsigned int ier; 1120 - int locked = 1; 1121 - 1122 - touch_nmi_watchdog(); 1123 - 1124 - local_irq_save(flags); 1125 - if (up->port.sysrq) 1126 - locked = 0; 1127 - else if (oops_in_progress) { 1128 - locked = spin_trylock(&up->port.lock); 1129 - } else 1130 - spin_lock(&up->port.lock); 1131 - 1132 - /* First save the IER then disable the interrupts */ 1133 - ier = serial_in(up, UART_IER); 1134 - serial_out(up, UART_IER, 0); 1135 - 1136 - uart_console_write(&up->port, s, count, serial_hsu_console_putchar); 1137 - 1138 - /* 1139 - * Finally, wait for transmitter to become empty 1140 - * and restore the IER 1141 - */ 1142 - wait_for_xmitr(up); 1143 - serial_out(up, UART_IER, ier); 1144 - 1145 - if (locked) 1146 - spin_unlock(&up->port.lock); 1147 - local_irq_restore(flags); 1148 - } 1149 - 1150 - static struct console serial_hsu_console; 1151 - 1152 - static int __init 1153 - serial_hsu_console_setup(struct console *co, char *options) 1154 - { 1155 - struct uart_hsu_port *up; 1156 - int baud = 115200; 1157 - int bits = 8; 1158 - int parity = 'n'; 1159 - int flow = 'n'; 1160 - 1161 - if (co->index == -1 || co->index >= serial_hsu_reg.nr) 1162 - co->index = 0; 1163 - up = serial_hsu_ports[co->index]; 1164 - if (!up) 1165 - return -ENODEV; 1166 - 1167 - if (options) 1168 - uart_parse_options(options, &baud, &parity, &bits, &flow); 1169 - 1170 - return uart_set_options(&up->port, co, baud, parity, bits, flow); 1171 - } 1172 - 1173 - static struct console serial_hsu_console = { 1174 - .name = "ttyMFD", 1175 - .write = serial_hsu_console_write, 1176 - .device = uart_console_device, 1177 - .setup = serial_hsu_console_setup, 1178 - .flags = CON_PRINTBUFFER, 1179 - .index = -1, 1180 - .data = &serial_hsu_reg, 1181 - }; 1182 - 1183 - #define SERIAL_HSU_CONSOLE (&serial_hsu_console) 1184 - #else 1185 - #define SERIAL_HSU_CONSOLE NULL 1186 - #endif 1187 - 1188 - static struct uart_ops serial_hsu_pops = { 1189 - .tx_empty = serial_hsu_tx_empty, 1190 - .set_mctrl = serial_hsu_set_mctrl, 1191 - .get_mctrl = serial_hsu_get_mctrl, 1192 - .stop_tx = serial_hsu_stop_tx, 1193 - .start_tx = serial_hsu_start_tx, 1194 - .stop_rx = serial_hsu_stop_rx, 1195 - .enable_ms = serial_hsu_enable_ms, 1196 - .break_ctl = serial_hsu_break_ctl, 1197 - .startup = serial_hsu_startup, 1198 - .shutdown = serial_hsu_shutdown, 1199 - .set_termios = serial_hsu_set_termios, 1200 - .pm = serial_hsu_pm, 1201 - .type = serial_hsu_type, 1202 - .release_port = serial_hsu_release_port, 1203 - .request_port = serial_hsu_request_port, 1204 - .config_port = serial_hsu_config_port, 1205 - .verify_port = serial_hsu_verify_port, 1206 - }; 1207 - 1208 - static struct uart_driver serial_hsu_reg = { 1209 - .owner = THIS_MODULE, 1210 - .driver_name = "MFD serial", 1211 - .dev_name = "ttyMFD", 1212 - .major = TTY_MAJOR, 1213 - .minor = 128, 1214 - .nr = 3, 1215 - .cons = SERIAL_HSU_CONSOLE, 1216 - }; 1217 - 1218 - #ifdef CONFIG_PM 1219 - static int serial_hsu_suspend(struct pci_dev *pdev, pm_message_t state) 1220 - { 1221 - void *priv = pci_get_drvdata(pdev); 1222 - struct uart_hsu_port *up; 1223 - 1224 - /* Make sure this is not the internal dma controller */ 1225 - if (priv && (pdev->device != 0x081E)) { 1226 - up = priv; 1227 - uart_suspend_port(&serial_hsu_reg, &up->port); 1228 - } 1229 - 1230 - pci_save_state(pdev); 1231 - pci_set_power_state(pdev, pci_choose_state(pdev, state)); 1232 - return 0; 1233 - } 1234 - 1235 - static int serial_hsu_resume(struct pci_dev *pdev) 1236 - { 1237 - void *priv = pci_get_drvdata(pdev); 1238 - struct uart_hsu_port *up; 1239 - int ret; 1240 - 1241 - pci_set_power_state(pdev, PCI_D0); 1242 - pci_restore_state(pdev); 1243 - 1244 - ret = pci_enable_device(pdev); 1245 - if (ret) 1246 - dev_warn(&pdev->dev, 1247 - "HSU: can't re-enable device, try to continue\n"); 1248 - 1249 - if (priv && (pdev->device != 0x081E)) { 1250 - up = priv; 1251 - uart_resume_port(&serial_hsu_reg, &up->port); 1252 - } 1253 - return 0; 1254 - } 1255 - 1256 - static int serial_hsu_runtime_idle(struct device *dev) 1257 - { 1258 - pm_schedule_suspend(dev, 500); 1259 - return -EBUSY; 1260 - } 1261 - 1262 - static int serial_hsu_runtime_suspend(struct device *dev) 1263 - { 1264 - return 0; 1265 - } 1266 - 1267 - static int serial_hsu_runtime_resume(struct device *dev) 1268 - { 1269 - return 0; 1270 - } 1271 - #else 1272 - #define serial_hsu_suspend NULL 1273 - #define serial_hsu_resume NULL 1274 - #define serial_hsu_runtime_idle NULL 1275 - #define serial_hsu_runtime_suspend NULL 1276 - #define serial_hsu_runtime_resume NULL 1277 - #endif 1278 - 1279 - static const struct dev_pm_ops serial_hsu_pm_ops = { 1280 - .runtime_suspend = serial_hsu_runtime_suspend, 1281 - .runtime_resume = serial_hsu_runtime_resume, 1282 - .runtime_idle = serial_hsu_runtime_idle, 1283 - }; 1284 - 1285 - /* temp global pointer before we settle down on using one or four PCI dev */ 1286 - static struct hsu_port *phsu; 1287 - 1288 - static int serial_hsu_probe(struct pci_dev *pdev, 1289 - const struct pci_device_id *ent) 1290 - { 1291 - struct uart_hsu_port *uport; 1292 - int index, ret; 1293 - 1294 - printk(KERN_INFO "HSU: found PCI Serial controller(ID: %04x:%04x)\n", 1295 - pdev->vendor, pdev->device); 1296 - 1297 - switch (pdev->device) { 1298 - case 0x081B: 1299 - index = 0; 1300 - break; 1301 - case 0x081C: 1302 - index = 1; 1303 - break; 1304 - case 0x081D: 1305 - index = 2; 1306 - break; 1307 - case 0x081E: 1308 - /* internal DMA controller */ 1309 - index = 3; 1310 - break; 1311 - default: 1312 - dev_err(&pdev->dev, "HSU: out of index!"); 1313 - return -ENODEV; 1314 - } 1315 - 1316 - ret = pci_enable_device(pdev); 1317 - if (ret) 1318 - return ret; 1319 - 1320 - if (index == 3) { 1321 - /* DMA controller */ 1322 - ret = request_irq(pdev->irq, dma_irq, 0, "hsu_dma", phsu); 1323 - if (ret) { 1324 - dev_err(&pdev->dev, "can not get IRQ\n"); 1325 - goto err_disable; 1326 - } 1327 - pci_set_drvdata(pdev, phsu); 1328 - } else { 1329 - /* UART port 0~2 */ 1330 - uport = &phsu->port[index]; 1331 - uport->port.irq = pdev->irq; 1332 - uport->port.dev = &pdev->dev; 1333 - uport->dev = &pdev->dev; 1334 - 1335 - ret = request_irq(pdev->irq, port_irq, 0, uport->name, uport); 1336 - if (ret) { 1337 - dev_err(&pdev->dev, "can not get IRQ\n"); 1338 - goto err_disable; 1339 - } 1340 - uart_add_one_port(&serial_hsu_reg, &uport->port); 1341 - 1342 - pci_set_drvdata(pdev, uport); 1343 - } 1344 - 1345 - pm_runtime_put_noidle(&pdev->dev); 1346 - pm_runtime_allow(&pdev->dev); 1347 - 1348 - return 0; 1349 - 1350 - err_disable: 1351 - pci_disable_device(pdev); 1352 - return ret; 1353 - } 1354 - 1355 - static void hsu_global_init(void) 1356 - { 1357 - struct hsu_port *hsu; 1358 - struct uart_hsu_port *uport; 1359 - struct hsu_dma_chan *dchan; 1360 - int i, ret; 1361 - 1362 - hsu = kzalloc(sizeof(struct hsu_port), GFP_KERNEL); 1363 - if (!hsu) 1364 - return; 1365 - 1366 - /* Get basic io resource and map it */ 1367 - hsu->paddr = 0xffa28000; 1368 - hsu->iolen = 0x1000; 1369 - 1370 - if (!(request_mem_region(hsu->paddr, hsu->iolen, "HSU global"))) 1371 - pr_warn("HSU: error in request mem region\n"); 1372 - 1373 - hsu->reg = ioremap_nocache((unsigned long)hsu->paddr, hsu->iolen); 1374 - if (!hsu->reg) { 1375 - pr_err("HSU: error in ioremap\n"); 1376 - ret = -ENOMEM; 1377 - goto err_free_region; 1378 - } 1379 - 1380 - /* Initialise the 3 UART ports */ 1381 - uport = hsu->port; 1382 - for (i = 0; i < 3; i++) { 1383 - uport->port.type = PORT_MFD; 1384 - uport->port.iotype = UPIO_MEM; 1385 - uport->port.mapbase = (resource_size_t)hsu->paddr 1386 - + HSU_PORT_REG_OFFSET 1387 - + i * HSU_PORT_REG_LENGTH; 1388 - uport->port.membase = hsu->reg + HSU_PORT_REG_OFFSET 1389 - + i * HSU_PORT_REG_LENGTH; 1390 - 1391 - sprintf(uport->name, "hsu_port%d", i); 1392 - uport->port.fifosize = 64; 1393 - uport->port.ops = &serial_hsu_pops; 1394 - uport->port.line = i; 1395 - uport->port.flags = UPF_IOREMAP; 1396 - /* set the scalable maxim support rate to 2746800 bps */ 1397 - uport->port.uartclk = 115200 * 24 * 16; 1398 - 1399 - uport->running = 0; 1400 - uport->txc = &hsu->chans[i * 2]; 1401 - uport->rxc = &hsu->chans[i * 2 + 1]; 1402 - 1403 - serial_hsu_ports[i] = uport; 1404 - uport->index = i; 1405 - 1406 - if (hsu_dma_enable & (1<<i)) 1407 - uport->use_dma = 1; 1408 - else 1409 - uport->use_dma = 0; 1410 - 1411 - uport++; 1412 - } 1413 - 1414 - /* Initialise 6 dma channels */ 1415 - dchan = hsu->chans; 1416 - for (i = 0; i < 6; i++) { 1417 - dchan->id = i; 1418 - dchan->dirt = (i & 0x1) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 1419 - dchan->uport = &hsu->port[i/2]; 1420 - dchan->reg = hsu->reg + HSU_DMA_CHANS_REG_OFFSET + 1421 - i * HSU_DMA_CHANS_REG_LENGTH; 1422 - 1423 - dchan++; 1424 - } 1425 - 1426 - phsu = hsu; 1427 - hsu_debugfs_init(hsu); 1428 - return; 1429 - 1430 - err_free_region: 1431 - release_mem_region(hsu->paddr, hsu->iolen); 1432 - kfree(hsu); 1433 - return; 1434 - } 1435 - 1436 - static void serial_hsu_remove(struct pci_dev *pdev) 1437 - { 1438 - void *priv = pci_get_drvdata(pdev); 1439 - struct uart_hsu_port *up; 1440 - 1441 - if (!priv) 1442 - return; 1443 - 1444 - pm_runtime_forbid(&pdev->dev); 1445 - pm_runtime_get_noresume(&pdev->dev); 1446 - 1447 - /* For port 0/1/2, priv is the address of uart_hsu_port */ 1448 - if (pdev->device != 0x081E) { 1449 - up = priv; 1450 - uart_remove_one_port(&serial_hsu_reg, &up->port); 1451 - } 1452 - 1453 - free_irq(pdev->irq, priv); 1454 - pci_disable_device(pdev); 1455 - } 1456 - 1457 - /* First 3 are UART ports, and the 4th is the DMA */ 1458 - static const struct pci_device_id pci_ids[] = { 1459 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081B) }, 1460 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081C) }, 1461 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081D) }, 1462 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081E) }, 1463 - {}, 1464 - }; 1465 - 1466 - static struct pci_driver hsu_pci_driver = { 1467 - .name = "HSU serial", 1468 - .id_table = pci_ids, 1469 - .probe = serial_hsu_probe, 1470 - .remove = serial_hsu_remove, 1471 - .suspend = serial_hsu_suspend, 1472 - .resume = serial_hsu_resume, 1473 - .driver = { 1474 - .pm = &serial_hsu_pm_ops, 1475 - }, 1476 - }; 1477 - 1478 - static int __init hsu_pci_init(void) 1479 - { 1480 - int ret; 1481 - 1482 - hsu_global_init(); 1483 - 1484 - ret = uart_register_driver(&serial_hsu_reg); 1485 - if (ret) 1486 - return ret; 1487 - 1488 - return pci_register_driver(&hsu_pci_driver); 1489 - } 1490 - 1491 - static void __exit hsu_pci_exit(void) 1492 - { 1493 - pci_unregister_driver(&hsu_pci_driver); 1494 - uart_unregister_driver(&serial_hsu_reg); 1495 - 1496 - hsu_debugfs_remove(phsu); 1497 - 1498 - kfree(phsu); 1499 - } 1500 - 1501 - module_init(hsu_pci_init); 1502 - module_exit(hsu_pci_exit); 1503 - 1504 - MODULE_LICENSE("GPL v2"); 1505 - MODULE_DEVICE_TABLE(pci, pci_ids);
+1 -1
drivers/tty/serial/mpc52xx_uart.c
··· 1717 1717 /* OF Platform Driver */ 1718 1718 /* ======================================================================== */ 1719 1719 1720 - static struct of_device_id mpc52xx_uart_of_match[] = { 1720 + static const struct of_device_id mpc52xx_uart_of_match[] = { 1721 1721 #ifdef CONFIG_PPC_MPC52xx 1722 1722 { .compatible = "fsl,mpc5200b-psc-uart", .data = &mpc5200b_psc_ops, }, 1723 1723 { .compatible = "fsl,mpc5200-psc-uart", .data = &mpc52xx_psc_ops, },
-9
drivers/tty/serial/msm_serial.h
··· 170 170 msm_serial_set_mnd_regs_tcxoby4(port); 171 171 } 172 172 173 - /* 174 - * TROUT has a specific defect that makes it report it's uartclk 175 - * as 19.2Mhz (TCXO) when it's actually 4.8Mhz (TCXO/4). This special 176 - * cases TROUT to use the right clock. 177 - */ 178 - #ifdef CONFIG_MACH_TROUT 179 - #define msm_serial_set_mnd_regs msm_serial_set_mnd_regs_tcxoby4 180 - #else 181 173 #define msm_serial_set_mnd_regs msm_serial_set_mnd_regs_from_uartclk 182 - #endif 183 174 184 175 #endif /* __DRIVERS_SERIAL_MSM_SERIAL_H */
-1874
drivers/tty/serial/msm_serial_hs.c
··· 1 - /* 2 - * MSM 7k/8k High speed uart driver 3 - * 4 - * Copyright (c) 2007-2011, Code Aurora Forum. All rights reserved. 5 - * Copyright (c) 2008 Google Inc. 6 - * Modified: Nick Pelly <npelly@google.com> 7 - * 8 - * This program is free software; you can redistribute it and/or 9 - * modify it under the terms of the GNU General Public License 10 - * version 2 as published by the Free Software Foundation. 11 - * 12 - * This program is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 - * See the GNU General Public License for more details. 16 - * 17 - * Has optional support for uart power management independent of linux 18 - * suspend/resume: 19 - * 20 - * RX wakeup. 21 - * UART wakeup can be triggered by RX activity (using a wakeup GPIO on the 22 - * UART RX pin). This should only be used if there is not a wakeup 23 - * GPIO on the UART CTS, and the first RX byte is known (for example, with the 24 - * Bluetooth Texas Instruments HCILL protocol), since the first RX byte will 25 - * always be lost. RTS will be asserted even while the UART is off in this mode 26 - * of operation. See msm_serial_hs_platform_data.rx_wakeup_irq. 27 - */ 28 - 29 - #include <linux/module.h> 30 - 31 - #include <linux/serial.h> 32 - #include <linux/serial_core.h> 33 - #include <linux/tty.h> 34 - #include <linux/tty_flip.h> 35 - #include <linux/slab.h> 36 - #include <linux/init.h> 37 - #include <linux/interrupt.h> 38 - #include <linux/irq.h> 39 - #include <linux/io.h> 40 - #include <linux/ioport.h> 41 - #include <linux/kernel.h> 42 - #include <linux/timer.h> 43 - #include <linux/clk.h> 44 - #include <linux/platform_device.h> 45 - #include <linux/pm_runtime.h> 46 - #include <linux/dma-mapping.h> 47 - #include <linux/dmapool.h> 48 - #include <linux/wait.h> 49 - #include <linux/workqueue.h> 50 - 51 - #include <linux/atomic.h> 52 - #include <asm/irq.h> 53 - 54 - #include <mach/hardware.h> 55 - #include <mach/dma.h> 56 - #include <linux/platform_data/msm_serial_hs.h> 57 - 58 - /* HSUART Registers */ 59 - #define UARTDM_MR1_ADDR 0x0 60 - #define UARTDM_MR2_ADDR 0x4 61 - 62 - /* Data Mover result codes */ 63 - #define RSLT_FIFO_CNTR_BMSK (0xE << 28) 64 - #define RSLT_VLD BIT(1) 65 - 66 - /* write only register */ 67 - #define UARTDM_CSR_ADDR 0x8 68 - #define UARTDM_CSR_115200 0xFF 69 - #define UARTDM_CSR_57600 0xEE 70 - #define UARTDM_CSR_38400 0xDD 71 - #define UARTDM_CSR_28800 0xCC 72 - #define UARTDM_CSR_19200 0xBB 73 - #define UARTDM_CSR_14400 0xAA 74 - #define UARTDM_CSR_9600 0x99 75 - #define UARTDM_CSR_7200 0x88 76 - #define UARTDM_CSR_4800 0x77 77 - #define UARTDM_CSR_3600 0x66 78 - #define UARTDM_CSR_2400 0x55 79 - #define UARTDM_CSR_1200 0x44 80 - #define UARTDM_CSR_600 0x33 81 - #define UARTDM_CSR_300 0x22 82 - #define UARTDM_CSR_150 0x11 83 - #define UARTDM_CSR_75 0x00 84 - 85 - /* write only register */ 86 - #define UARTDM_TF_ADDR 0x70 87 - #define UARTDM_TF2_ADDR 0x74 88 - #define UARTDM_TF3_ADDR 0x78 89 - #define UARTDM_TF4_ADDR 0x7C 90 - 91 - /* write only register */ 92 - #define UARTDM_CR_ADDR 0x10 93 - #define UARTDM_IMR_ADDR 0x14 94 - 95 - #define UARTDM_IPR_ADDR 0x18 96 - #define UARTDM_TFWR_ADDR 0x1c 97 - #define UARTDM_RFWR_ADDR 0x20 98 - #define UARTDM_HCR_ADDR 0x24 99 - #define UARTDM_DMRX_ADDR 0x34 100 - #define UARTDM_IRDA_ADDR 0x38 101 - #define UARTDM_DMEN_ADDR 0x3c 102 - 103 - /* UART_DM_NO_CHARS_FOR_TX */ 104 - #define UARTDM_NCF_TX_ADDR 0x40 105 - 106 - #define UARTDM_BADR_ADDR 0x44 107 - 108 - #define UARTDM_SIM_CFG_ADDR 0x80 109 - /* Read Only register */ 110 - #define UARTDM_SR_ADDR 0x8 111 - 112 - /* Read Only register */ 113 - #define UARTDM_RF_ADDR 0x70 114 - #define UARTDM_RF2_ADDR 0x74 115 - #define UARTDM_RF3_ADDR 0x78 116 - #define UARTDM_RF4_ADDR 0x7C 117 - 118 - /* Read Only register */ 119 - #define UARTDM_MISR_ADDR 0x10 120 - 121 - /* Read Only register */ 122 - #define UARTDM_ISR_ADDR 0x14 123 - #define UARTDM_RX_TOTAL_SNAP_ADDR 0x38 124 - 125 - #define UARTDM_RXFS_ADDR 0x50 126 - 127 - /* Register field Mask Mapping */ 128 - #define UARTDM_SR_PAR_FRAME_BMSK BIT(5) 129 - #define UARTDM_SR_OVERRUN_BMSK BIT(4) 130 - #define UARTDM_SR_TXEMT_BMSK BIT(3) 131 - #define UARTDM_SR_TXRDY_BMSK BIT(2) 132 - #define UARTDM_SR_RXRDY_BMSK BIT(0) 133 - 134 - #define UARTDM_CR_TX_DISABLE_BMSK BIT(3) 135 - #define UARTDM_CR_RX_DISABLE_BMSK BIT(1) 136 - #define UARTDM_CR_TX_EN_BMSK BIT(2) 137 - #define UARTDM_CR_RX_EN_BMSK BIT(0) 138 - 139 - /* UARTDM_CR channel_comman bit value (register field is bits 8:4) */ 140 - #define RESET_RX 0x10 141 - #define RESET_TX 0x20 142 - #define RESET_ERROR_STATUS 0x30 143 - #define RESET_BREAK_INT 0x40 144 - #define START_BREAK 0x50 145 - #define STOP_BREAK 0x60 146 - #define RESET_CTS 0x70 147 - #define RESET_STALE_INT 0x80 148 - #define RFR_LOW 0xD0 149 - #define RFR_HIGH 0xE0 150 - #define CR_PROTECTION_EN 0x100 151 - #define STALE_EVENT_ENABLE 0x500 152 - #define STALE_EVENT_DISABLE 0x600 153 - #define FORCE_STALE_EVENT 0x400 154 - #define CLEAR_TX_READY 0x300 155 - #define RESET_TX_ERROR 0x800 156 - #define RESET_TX_DONE 0x810 157 - 158 - #define UARTDM_MR1_AUTO_RFR_LEVEL1_BMSK 0xffffff00 159 - #define UARTDM_MR1_AUTO_RFR_LEVEL0_BMSK 0x3f 160 - #define UARTDM_MR1_CTS_CTL_BMSK 0x40 161 - #define UARTDM_MR1_RX_RDY_CTL_BMSK 0x80 162 - 163 - #define UARTDM_MR2_ERROR_MODE_BMSK 0x40 164 - #define UARTDM_MR2_BITS_PER_CHAR_BMSK 0x30 165 - 166 - /* bits per character configuration */ 167 - #define FIVE_BPC (0 << 4) 168 - #define SIX_BPC (1 << 4) 169 - #define SEVEN_BPC (2 << 4) 170 - #define EIGHT_BPC (3 << 4) 171 - 172 - #define UARTDM_MR2_STOP_BIT_LEN_BMSK 0xc 173 - #define STOP_BIT_ONE (1 << 2) 174 - #define STOP_BIT_TWO (3 << 2) 175 - 176 - #define UARTDM_MR2_PARITY_MODE_BMSK 0x3 177 - 178 - /* Parity configuration */ 179 - #define NO_PARITY 0x0 180 - #define EVEN_PARITY 0x1 181 - #define ODD_PARITY 0x2 182 - #define SPACE_PARITY 0x3 183 - 184 - #define UARTDM_IPR_STALE_TIMEOUT_MSB_BMSK 0xffffff80 185 - #define UARTDM_IPR_STALE_LSB_BMSK 0x1f 186 - 187 - /* These can be used for both ISR and IMR register */ 188 - #define UARTDM_ISR_TX_READY_BMSK BIT(7) 189 - #define UARTDM_ISR_CURRENT_CTS_BMSK BIT(6) 190 - #define UARTDM_ISR_DELTA_CTS_BMSK BIT(5) 191 - #define UARTDM_ISR_RXLEV_BMSK BIT(4) 192 - #define UARTDM_ISR_RXSTALE_BMSK BIT(3) 193 - #define UARTDM_ISR_RXBREAK_BMSK BIT(2) 194 - #define UARTDM_ISR_RXHUNT_BMSK BIT(1) 195 - #define UARTDM_ISR_TXLEV_BMSK BIT(0) 196 - 197 - /* Field definitions for UART_DM_DMEN*/ 198 - #define UARTDM_TX_DM_EN_BMSK 0x1 199 - #define UARTDM_RX_DM_EN_BMSK 0x2 200 - 201 - #define UART_FIFOSIZE 64 202 - #define UARTCLK 7372800 203 - 204 - /* Rx DMA request states */ 205 - enum flush_reason { 206 - FLUSH_NONE, 207 - FLUSH_DATA_READY, 208 - FLUSH_DATA_INVALID, /* values after this indicate invalid data */ 209 - FLUSH_IGNORE = FLUSH_DATA_INVALID, 210 - FLUSH_STOP, 211 - FLUSH_SHUTDOWN, 212 - }; 213 - 214 - /* UART clock states */ 215 - enum msm_hs_clk_states_e { 216 - MSM_HS_CLK_PORT_OFF, /* port not in use */ 217 - MSM_HS_CLK_OFF, /* clock disabled */ 218 - MSM_HS_CLK_REQUEST_OFF, /* disable after TX and RX flushed */ 219 - MSM_HS_CLK_ON, /* clock enabled */ 220 - }; 221 - 222 - /* Track the forced RXSTALE flush during clock off sequence. 223 - * These states are only valid during MSM_HS_CLK_REQUEST_OFF */ 224 - enum msm_hs_clk_req_off_state_e { 225 - CLK_REQ_OFF_START, 226 - CLK_REQ_OFF_RXSTALE_ISSUED, 227 - CLK_REQ_OFF_FLUSH_ISSUED, 228 - CLK_REQ_OFF_RXSTALE_FLUSHED, 229 - }; 230 - 231 - /** 232 - * struct msm_hs_tx 233 - * @tx_ready_int_en: ok to dma more tx? 234 - * @dma_in_flight: tx dma in progress 235 - * @xfer: top level DMA command pointer structure 236 - * @command_ptr: third level command struct pointer 237 - * @command_ptr_ptr: second level command list struct pointer 238 - * @mapped_cmd_ptr: DMA view of third level command struct 239 - * @mapped_cmd_ptr_ptr: DMA view of second level command list struct 240 - * @tx_count: number of bytes to transfer in DMA transfer 241 - * @dma_base: DMA view of UART xmit buffer 242 - * 243 - * This structure describes a single Tx DMA transaction. MSM DMA 244 - * commands have two levels of indirection. The top level command 245 - * ptr points to a list of command ptr which in turn points to a 246 - * single DMA 'command'. In our case each Tx transaction consists 247 - * of a single second level pointer pointing to a 'box type' command. 248 - */ 249 - struct msm_hs_tx { 250 - unsigned int tx_ready_int_en; 251 - unsigned int dma_in_flight; 252 - struct msm_dmov_cmd xfer; 253 - dmov_box *command_ptr; 254 - u32 *command_ptr_ptr; 255 - dma_addr_t mapped_cmd_ptr; 256 - dma_addr_t mapped_cmd_ptr_ptr; 257 - int tx_count; 258 - dma_addr_t dma_base; 259 - }; 260 - 261 - /** 262 - * struct msm_hs_rx 263 - * @flush: Rx DMA request state 264 - * @xfer: top level DMA command pointer structure 265 - * @cmdptr_dmaaddr: DMA view of second level command structure 266 - * @command_ptr: third level DMA command pointer structure 267 - * @command_ptr_ptr: second level DMA command list pointer 268 - * @mapped_cmd_ptr: DMA view of the third level command structure 269 - * @wait: wait for DMA completion before shutdown 270 - * @buffer: destination buffer for RX DMA 271 - * @rbuffer: DMA view of buffer 272 - * @pool: dma pool out of which coherent rx buffer is allocated 273 - * @tty_work: private work-queue for tty flip buffer push task 274 - * 275 - * This structure describes a single Rx DMA transaction. Rx DMA 276 - * transactions use box mode DMA commands. 277 - */ 278 - struct msm_hs_rx { 279 - enum flush_reason flush; 280 - struct msm_dmov_cmd xfer; 281 - dma_addr_t cmdptr_dmaaddr; 282 - dmov_box *command_ptr; 283 - u32 *command_ptr_ptr; 284 - dma_addr_t mapped_cmd_ptr; 285 - wait_queue_head_t wait; 286 - dma_addr_t rbuffer; 287 - unsigned char *buffer; 288 - struct dma_pool *pool; 289 - struct work_struct tty_work; 290 - }; 291 - 292 - /** 293 - * struct msm_hs_rx_wakeup 294 - * @irq: IRQ line to be configured as interrupt source on Rx activity 295 - * @ignore: boolean value. 1 = ignore the wakeup interrupt 296 - * @rx_to_inject: extra character to be inserted to Rx tty on wakeup 297 - * @inject_rx: 1 = insert rx_to_inject. 0 = do not insert extra character 298 - * 299 - * This is an optional structure required for UART Rx GPIO IRQ based 300 - * wakeup from low power state. UART wakeup can be triggered by RX activity 301 - * (using a wakeup GPIO on the UART RX pin). This should only be used if 302 - * there is not a wakeup GPIO on the UART CTS, and the first RX byte is 303 - * known (eg., with the Bluetooth Texas Instruments HCILL protocol), 304 - * since the first RX byte will always be lost. RTS will be asserted even 305 - * while the UART is clocked off in this mode of operation. 306 - */ 307 - struct msm_hs_rx_wakeup { 308 - int irq; /* < 0 indicates low power wakeup disabled */ 309 - unsigned char ignore; 310 - unsigned char inject_rx; 311 - char rx_to_inject; 312 - }; 313 - 314 - /** 315 - * struct msm_hs_port 316 - * @uport: embedded uart port structure 317 - * @imr_reg: shadow value of UARTDM_IMR 318 - * @clk: uart input clock handle 319 - * @tx: Tx transaction related data structure 320 - * @rx: Rx transaction related data structure 321 - * @dma_tx_channel: Tx DMA command channel 322 - * @dma_rx_channel Rx DMA command channel 323 - * @dma_tx_crci: Tx channel rate control interface number 324 - * @dma_rx_crci: Rx channel rate control interface number 325 - * @clk_off_timer: Timer to poll DMA event completion before clock off 326 - * @clk_off_delay: clk_off_timer poll interval 327 - * @clk_state: overall clock state 328 - * @clk_req_off_state: post flush clock states 329 - * @rx_wakeup: optional rx_wakeup feature related data 330 - * @exit_lpm_cb: optional callback to exit low power mode 331 - * 332 - * Low level serial port structure. 333 - */ 334 - struct msm_hs_port { 335 - struct uart_port uport; 336 - unsigned long imr_reg; 337 - struct clk *clk; 338 - struct msm_hs_tx tx; 339 - struct msm_hs_rx rx; 340 - 341 - int dma_tx_channel; 342 - int dma_rx_channel; 343 - int dma_tx_crci; 344 - int dma_rx_crci; 345 - 346 - struct hrtimer clk_off_timer; 347 - ktime_t clk_off_delay; 348 - enum msm_hs_clk_states_e clk_state; 349 - enum msm_hs_clk_req_off_state_e clk_req_off_state; 350 - 351 - struct msm_hs_rx_wakeup rx_wakeup; 352 - void (*exit_lpm_cb)(struct uart_port *); 353 - }; 354 - 355 - #define MSM_UARTDM_BURST_SIZE 16 /* DM burst size (in bytes) */ 356 - #define UARTDM_TX_BUF_SIZE UART_XMIT_SIZE 357 - #define UARTDM_RX_BUF_SIZE 512 358 - 359 - #define UARTDM_NR 2 360 - 361 - static struct msm_hs_port q_uart_port[UARTDM_NR]; 362 - static struct platform_driver msm_serial_hs_platform_driver; 363 - static struct uart_driver msm_hs_driver; 364 - static struct uart_ops msm_hs_ops; 365 - static struct workqueue_struct *msm_hs_workqueue; 366 - 367 - #define UARTDM_TO_MSM(uart_port) \ 368 - container_of((uart_port), struct msm_hs_port, uport) 369 - 370 - static unsigned int use_low_power_rx_wakeup(struct msm_hs_port 371 - *msm_uport) 372 - { 373 - return (msm_uport->rx_wakeup.irq >= 0); 374 - } 375 - 376 - static unsigned int msm_hs_read(struct uart_port *uport, 377 - unsigned int offset) 378 - { 379 - return ioread32(uport->membase + offset); 380 - } 381 - 382 - static void msm_hs_write(struct uart_port *uport, unsigned int offset, 383 - unsigned int value) 384 - { 385 - iowrite32(value, uport->membase + offset); 386 - } 387 - 388 - static void msm_hs_release_port(struct uart_port *port) 389 - { 390 - iounmap(port->membase); 391 - } 392 - 393 - static int msm_hs_request_port(struct uart_port *port) 394 - { 395 - port->membase = ioremap(port->mapbase, PAGE_SIZE); 396 - if (unlikely(!port->membase)) 397 - return -ENOMEM; 398 - 399 - /* configure the CR Protection to Enable */ 400 - msm_hs_write(port, UARTDM_CR_ADDR, CR_PROTECTION_EN); 401 - return 0; 402 - } 403 - 404 - static int msm_hs_remove(struct platform_device *pdev) 405 - { 406 - 407 - struct msm_hs_port *msm_uport; 408 - struct device *dev; 409 - 410 - if (pdev->id < 0 || pdev->id >= UARTDM_NR) { 411 - printk(KERN_ERR "Invalid plaform device ID = %d\n", pdev->id); 412 - return -EINVAL; 413 - } 414 - 415 - msm_uport = &q_uart_port[pdev->id]; 416 - dev = msm_uport->uport.dev; 417 - 418 - dma_unmap_single(dev, msm_uport->rx.mapped_cmd_ptr, sizeof(dmov_box), 419 - DMA_TO_DEVICE); 420 - dma_pool_free(msm_uport->rx.pool, msm_uport->rx.buffer, 421 - msm_uport->rx.rbuffer); 422 - dma_pool_destroy(msm_uport->rx.pool); 423 - 424 - dma_unmap_single(dev, msm_uport->rx.cmdptr_dmaaddr, sizeof(u32), 425 - DMA_TO_DEVICE); 426 - dma_unmap_single(dev, msm_uport->tx.mapped_cmd_ptr_ptr, sizeof(u32), 427 - DMA_TO_DEVICE); 428 - dma_unmap_single(dev, msm_uport->tx.mapped_cmd_ptr, sizeof(dmov_box), 429 - DMA_TO_DEVICE); 430 - 431 - uart_remove_one_port(&msm_hs_driver, &msm_uport->uport); 432 - clk_put(msm_uport->clk); 433 - 434 - /* Free the tx resources */ 435 - kfree(msm_uport->tx.command_ptr); 436 - kfree(msm_uport->tx.command_ptr_ptr); 437 - 438 - /* Free the rx resources */ 439 - kfree(msm_uport->rx.command_ptr); 440 - kfree(msm_uport->rx.command_ptr_ptr); 441 - 442 - iounmap(msm_uport->uport.membase); 443 - 444 - return 0; 445 - } 446 - 447 - static int msm_hs_init_clk_locked(struct uart_port *uport) 448 - { 449 - int ret; 450 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 451 - 452 - ret = clk_enable(msm_uport->clk); 453 - if (ret) { 454 - printk(KERN_ERR "Error could not turn on UART clk\n"); 455 - return ret; 456 - } 457 - 458 - /* Set up the MREG/NREG/DREG/MNDREG */ 459 - ret = clk_set_rate(msm_uport->clk, uport->uartclk); 460 - if (ret) { 461 - printk(KERN_WARNING "Error setting clock rate on UART\n"); 462 - clk_disable(msm_uport->clk); 463 - return ret; 464 - } 465 - 466 - msm_uport->clk_state = MSM_HS_CLK_ON; 467 - return 0; 468 - } 469 - 470 - /* Enable and Disable clocks (Used for power management) */ 471 - static void msm_hs_pm(struct uart_port *uport, unsigned int state, 472 - unsigned int oldstate) 473 - { 474 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 475 - 476 - if (use_low_power_rx_wakeup(msm_uport) || 477 - msm_uport->exit_lpm_cb) 478 - return; /* ignore linux PM states, 479 - use msm_hs_request_clock API */ 480 - 481 - switch (state) { 482 - case 0: 483 - clk_enable(msm_uport->clk); 484 - break; 485 - case 3: 486 - clk_disable(msm_uport->clk); 487 - break; 488 - default: 489 - dev_err(uport->dev, "msm_serial: Unknown PM state %d\n", 490 - state); 491 - } 492 - } 493 - 494 - /* 495 - * programs the UARTDM_CSR register with correct bit rates 496 - * 497 - * Interrupts should be disabled before we are called, as 498 - * we modify Set Baud rate 499 - * Set receive stale interrupt level, dependent on Bit Rate 500 - * Goal is to have around 8 ms before indicate stale. 501 - * roundup (((Bit Rate * .008) / 10) + 1 502 - */ 503 - static void msm_hs_set_bps_locked(struct uart_port *uport, 504 - unsigned int bps) 505 - { 506 - unsigned long rxstale; 507 - unsigned long data; 508 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 509 - 510 - switch (bps) { 511 - case 300: 512 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_75); 513 - rxstale = 1; 514 - break; 515 - case 600: 516 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_150); 517 - rxstale = 1; 518 - break; 519 - case 1200: 520 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_300); 521 - rxstale = 1; 522 - break; 523 - case 2400: 524 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_600); 525 - rxstale = 1; 526 - break; 527 - case 4800: 528 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_1200); 529 - rxstale = 1; 530 - break; 531 - case 9600: 532 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_2400); 533 - rxstale = 2; 534 - break; 535 - case 14400: 536 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_3600); 537 - rxstale = 3; 538 - break; 539 - case 19200: 540 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_4800); 541 - rxstale = 4; 542 - break; 543 - case 28800: 544 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_7200); 545 - rxstale = 6; 546 - break; 547 - case 38400: 548 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_9600); 549 - rxstale = 8; 550 - break; 551 - case 57600: 552 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_14400); 553 - rxstale = 16; 554 - break; 555 - case 76800: 556 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_19200); 557 - rxstale = 16; 558 - break; 559 - case 115200: 560 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_28800); 561 - rxstale = 31; 562 - break; 563 - case 230400: 564 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_57600); 565 - rxstale = 31; 566 - break; 567 - case 460800: 568 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_115200); 569 - rxstale = 31; 570 - break; 571 - case 4000000: 572 - case 3686400: 573 - case 3200000: 574 - case 3500000: 575 - case 3000000: 576 - case 2500000: 577 - case 1500000: 578 - case 1152000: 579 - case 1000000: 580 - case 921600: 581 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_115200); 582 - rxstale = 31; 583 - break; 584 - default: 585 - msm_hs_write(uport, UARTDM_CSR_ADDR, UARTDM_CSR_2400); 586 - /* default to 9600 */ 587 - bps = 9600; 588 - rxstale = 2; 589 - break; 590 - } 591 - if (bps > 460800) 592 - uport->uartclk = bps * 16; 593 - else 594 - uport->uartclk = UARTCLK; 595 - 596 - if (clk_set_rate(msm_uport->clk, uport->uartclk)) { 597 - printk(KERN_WARNING "Error setting clock rate on UART\n"); 598 - return; 599 - } 600 - 601 - data = rxstale & UARTDM_IPR_STALE_LSB_BMSK; 602 - data |= UARTDM_IPR_STALE_TIMEOUT_MSB_BMSK & (rxstale << 2); 603 - 604 - msm_hs_write(uport, UARTDM_IPR_ADDR, data); 605 - } 606 - 607 - /* 608 - * termios : new ktermios 609 - * oldtermios: old ktermios previous setting 610 - * 611 - * Configure the serial port 612 - */ 613 - static void msm_hs_set_termios(struct uart_port *uport, 614 - struct ktermios *termios, 615 - struct ktermios *oldtermios) 616 - { 617 - unsigned int bps; 618 - unsigned long data; 619 - unsigned long flags; 620 - unsigned int c_cflag = termios->c_cflag; 621 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 622 - 623 - spin_lock_irqsave(&uport->lock, flags); 624 - clk_enable(msm_uport->clk); 625 - 626 - /* 300 is the minimum baud support by the driver */ 627 - bps = uart_get_baud_rate(uport, termios, oldtermios, 200, 4000000); 628 - 629 - /* Temporary remapping 200 BAUD to 3.2 mbps */ 630 - if (bps == 200) 631 - bps = 3200000; 632 - 633 - msm_hs_set_bps_locked(uport, bps); 634 - 635 - data = msm_hs_read(uport, UARTDM_MR2_ADDR); 636 - data &= ~UARTDM_MR2_PARITY_MODE_BMSK; 637 - /* set parity */ 638 - if (PARENB == (c_cflag & PARENB)) { 639 - if (PARODD == (c_cflag & PARODD)) 640 - data |= ODD_PARITY; 641 - else if (CMSPAR == (c_cflag & CMSPAR)) 642 - data |= SPACE_PARITY; 643 - else 644 - data |= EVEN_PARITY; 645 - } 646 - 647 - /* Set bits per char */ 648 - data &= ~UARTDM_MR2_BITS_PER_CHAR_BMSK; 649 - 650 - switch (c_cflag & CSIZE) { 651 - case CS5: 652 - data |= FIVE_BPC; 653 - break; 654 - case CS6: 655 - data |= SIX_BPC; 656 - break; 657 - case CS7: 658 - data |= SEVEN_BPC; 659 - break; 660 - default: 661 - data |= EIGHT_BPC; 662 - break; 663 - } 664 - /* stop bits */ 665 - if (c_cflag & CSTOPB) { 666 - data |= STOP_BIT_TWO; 667 - } else { 668 - /* otherwise 1 stop bit */ 669 - data |= STOP_BIT_ONE; 670 - } 671 - data |= UARTDM_MR2_ERROR_MODE_BMSK; 672 - /* write parity/bits per char/stop bit configuration */ 673 - msm_hs_write(uport, UARTDM_MR2_ADDR, data); 674 - 675 - /* Configure HW flow control */ 676 - data = msm_hs_read(uport, UARTDM_MR1_ADDR); 677 - 678 - data &= ~(UARTDM_MR1_CTS_CTL_BMSK | UARTDM_MR1_RX_RDY_CTL_BMSK); 679 - 680 - if (c_cflag & CRTSCTS) { 681 - data |= UARTDM_MR1_CTS_CTL_BMSK; 682 - data |= UARTDM_MR1_RX_RDY_CTL_BMSK; 683 - } 684 - 685 - msm_hs_write(uport, UARTDM_MR1_ADDR, data); 686 - 687 - uport->ignore_status_mask = termios->c_iflag & INPCK; 688 - uport->ignore_status_mask |= termios->c_iflag & IGNPAR; 689 - uport->read_status_mask = (termios->c_cflag & CREAD); 690 - 691 - msm_hs_write(uport, UARTDM_IMR_ADDR, 0); 692 - 693 - /* Set Transmit software time out */ 694 - uart_update_timeout(uport, c_cflag, bps); 695 - 696 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_RX); 697 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_TX); 698 - 699 - if (msm_uport->rx.flush == FLUSH_NONE) { 700 - msm_uport->rx.flush = FLUSH_IGNORE; 701 - msm_dmov_stop_cmd(msm_uport->dma_rx_channel, NULL, 1); 702 - } 703 - 704 - msm_hs_write(uport, UARTDM_IMR_ADDR, msm_uport->imr_reg); 705 - 706 - clk_disable(msm_uport->clk); 707 - spin_unlock_irqrestore(&uport->lock, flags); 708 - } 709 - 710 - /* 711 - * Standard API, Transmitter 712 - * Any character in the transmit shift register is sent 713 - */ 714 - static unsigned int msm_hs_tx_empty(struct uart_port *uport) 715 - { 716 - unsigned int data; 717 - unsigned int ret = 0; 718 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 719 - 720 - clk_enable(msm_uport->clk); 721 - 722 - data = msm_hs_read(uport, UARTDM_SR_ADDR); 723 - if (data & UARTDM_SR_TXEMT_BMSK) 724 - ret = TIOCSER_TEMT; 725 - 726 - clk_disable(msm_uport->clk); 727 - 728 - return ret; 729 - } 730 - 731 - /* 732 - * Standard API, Stop transmitter. 733 - * Any character in the transmit shift register is sent as 734 - * well as the current data mover transfer . 735 - */ 736 - static void msm_hs_stop_tx_locked(struct uart_port *uport) 737 - { 738 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 739 - 740 - msm_uport->tx.tx_ready_int_en = 0; 741 - } 742 - 743 - /* 744 - * Standard API, Stop receiver as soon as possible. 745 - * 746 - * Function immediately terminates the operation of the 747 - * channel receiver and any incoming characters are lost. None 748 - * of the receiver status bits are affected by this command and 749 - * characters that are already in the receive FIFO there. 750 - */ 751 - static void msm_hs_stop_rx_locked(struct uart_port *uport) 752 - { 753 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 754 - unsigned int data; 755 - 756 - clk_enable(msm_uport->clk); 757 - 758 - /* disable dlink */ 759 - data = msm_hs_read(uport, UARTDM_DMEN_ADDR); 760 - data &= ~UARTDM_RX_DM_EN_BMSK; 761 - msm_hs_write(uport, UARTDM_DMEN_ADDR, data); 762 - 763 - /* Disable the receiver */ 764 - if (msm_uport->rx.flush == FLUSH_NONE) 765 - msm_dmov_stop_cmd(msm_uport->dma_rx_channel, NULL, 1); 766 - 767 - if (msm_uport->rx.flush != FLUSH_SHUTDOWN) 768 - msm_uport->rx.flush = FLUSH_STOP; 769 - 770 - clk_disable(msm_uport->clk); 771 - } 772 - 773 - /* Transmit the next chunk of data */ 774 - static void msm_hs_submit_tx_locked(struct uart_port *uport) 775 - { 776 - int left; 777 - int tx_count; 778 - dma_addr_t src_addr; 779 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 780 - struct msm_hs_tx *tx = &msm_uport->tx; 781 - struct circ_buf *tx_buf = &msm_uport->uport.state->xmit; 782 - 783 - if (uart_circ_empty(tx_buf) || uport->state->port.tty->stopped) { 784 - msm_hs_stop_tx_locked(uport); 785 - return; 786 - } 787 - 788 - tx->dma_in_flight = 1; 789 - 790 - tx_count = uart_circ_chars_pending(tx_buf); 791 - 792 - if (UARTDM_TX_BUF_SIZE < tx_count) 793 - tx_count = UARTDM_TX_BUF_SIZE; 794 - 795 - left = UART_XMIT_SIZE - tx_buf->tail; 796 - 797 - if (tx_count > left) 798 - tx_count = left; 799 - 800 - src_addr = tx->dma_base + tx_buf->tail; 801 - dma_sync_single_for_device(uport->dev, src_addr, tx_count, 802 - DMA_TO_DEVICE); 803 - 804 - tx->command_ptr->num_rows = (((tx_count + 15) >> 4) << 16) | 805 - ((tx_count + 15) >> 4); 806 - tx->command_ptr->src_row_addr = src_addr; 807 - 808 - dma_sync_single_for_device(uport->dev, tx->mapped_cmd_ptr, 809 - sizeof(dmov_box), DMA_TO_DEVICE); 810 - 811 - *tx->command_ptr_ptr = CMD_PTR_LP | DMOV_CMD_ADDR(tx->mapped_cmd_ptr); 812 - 813 - dma_sync_single_for_device(uport->dev, tx->mapped_cmd_ptr_ptr, 814 - sizeof(u32), DMA_TO_DEVICE); 815 - 816 - /* Save tx_count to use in Callback */ 817 - tx->tx_count = tx_count; 818 - msm_hs_write(uport, UARTDM_NCF_TX_ADDR, tx_count); 819 - 820 - /* Disable the tx_ready interrupt */ 821 - msm_uport->imr_reg &= ~UARTDM_ISR_TX_READY_BMSK; 822 - msm_hs_write(uport, UARTDM_IMR_ADDR, msm_uport->imr_reg); 823 - msm_dmov_enqueue_cmd(msm_uport->dma_tx_channel, &tx->xfer); 824 - } 825 - 826 - /* Start to receive the next chunk of data */ 827 - static void msm_hs_start_rx_locked(struct uart_port *uport) 828 - { 829 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 830 - 831 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_STALE_INT); 832 - msm_hs_write(uport, UARTDM_DMRX_ADDR, UARTDM_RX_BUF_SIZE); 833 - msm_hs_write(uport, UARTDM_CR_ADDR, STALE_EVENT_ENABLE); 834 - msm_uport->imr_reg |= UARTDM_ISR_RXLEV_BMSK; 835 - msm_hs_write(uport, UARTDM_IMR_ADDR, msm_uport->imr_reg); 836 - 837 - msm_uport->rx.flush = FLUSH_NONE; 838 - msm_dmov_enqueue_cmd(msm_uport->dma_rx_channel, &msm_uport->rx.xfer); 839 - 840 - /* might have finished RX and be ready to clock off */ 841 - hrtimer_start(&msm_uport->clk_off_timer, msm_uport->clk_off_delay, 842 - HRTIMER_MODE_REL); 843 - } 844 - 845 - /* Enable the transmitter Interrupt */ 846 - static void msm_hs_start_tx_locked(struct uart_port *uport) 847 - { 848 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 849 - 850 - clk_enable(msm_uport->clk); 851 - 852 - if (msm_uport->exit_lpm_cb) 853 - msm_uport->exit_lpm_cb(uport); 854 - 855 - if (msm_uport->tx.tx_ready_int_en == 0) { 856 - msm_uport->tx.tx_ready_int_en = 1; 857 - msm_hs_submit_tx_locked(uport); 858 - } 859 - 860 - clk_disable(msm_uport->clk); 861 - } 862 - 863 - /* 864 - * This routine is called when we are done with a DMA transfer 865 - * 866 - * This routine is registered with Data mover when we set 867 - * up a Data Mover transfer. It is called from Data mover ISR 868 - * when the DMA transfer is done. 869 - */ 870 - static void msm_hs_dmov_tx_callback(struct msm_dmov_cmd *cmd_ptr, 871 - unsigned int result, 872 - struct msm_dmov_errdata *err) 873 - { 874 - unsigned long flags; 875 - struct msm_hs_port *msm_uport; 876 - 877 - /* DMA did not finish properly */ 878 - WARN_ON((((result & RSLT_FIFO_CNTR_BMSK) >> 28) == 1) && 879 - !(result & RSLT_VLD)); 880 - 881 - msm_uport = container_of(cmd_ptr, struct msm_hs_port, tx.xfer); 882 - 883 - spin_lock_irqsave(&msm_uport->uport.lock, flags); 884 - clk_enable(msm_uport->clk); 885 - 886 - msm_uport->imr_reg |= UARTDM_ISR_TX_READY_BMSK; 887 - msm_hs_write(&msm_uport->uport, UARTDM_IMR_ADDR, msm_uport->imr_reg); 888 - 889 - clk_disable(msm_uport->clk); 890 - spin_unlock_irqrestore(&msm_uport->uport.lock, flags); 891 - } 892 - 893 - /* 894 - * This routine is called when we are done with a DMA transfer or the 895 - * a flush has been sent to the data mover driver. 896 - * 897 - * This routine is registered with Data mover when we set up a Data Mover 898 - * transfer. It is called from Data mover ISR when the DMA transfer is done. 899 - */ 900 - static void msm_hs_dmov_rx_callback(struct msm_dmov_cmd *cmd_ptr, 901 - unsigned int result, 902 - struct msm_dmov_errdata *err) 903 - { 904 - int retval; 905 - int rx_count; 906 - unsigned long status; 907 - unsigned int error_f = 0; 908 - unsigned long flags; 909 - unsigned int flush; 910 - struct tty_port *port; 911 - struct uart_port *uport; 912 - struct msm_hs_port *msm_uport; 913 - 914 - msm_uport = container_of(cmd_ptr, struct msm_hs_port, rx.xfer); 915 - uport = &msm_uport->uport; 916 - 917 - spin_lock_irqsave(&uport->lock, flags); 918 - clk_enable(msm_uport->clk); 919 - 920 - port = &uport->state->port; 921 - 922 - msm_hs_write(uport, UARTDM_CR_ADDR, STALE_EVENT_DISABLE); 923 - 924 - status = msm_hs_read(uport, UARTDM_SR_ADDR); 925 - 926 - /* overflow is not connect to data in a FIFO */ 927 - if (unlikely((status & UARTDM_SR_OVERRUN_BMSK) && 928 - (uport->read_status_mask & CREAD))) { 929 - tty_insert_flip_char(port, 0, TTY_OVERRUN); 930 - uport->icount.buf_overrun++; 931 - error_f = 1; 932 - } 933 - 934 - if (!(uport->ignore_status_mask & INPCK)) 935 - status = status & ~(UARTDM_SR_PAR_FRAME_BMSK); 936 - 937 - if (unlikely(status & UARTDM_SR_PAR_FRAME_BMSK)) { 938 - /* Can not tell difference between parity & frame error */ 939 - uport->icount.parity++; 940 - error_f = 1; 941 - if (uport->ignore_status_mask & IGNPAR) 942 - tty_insert_flip_char(port, 0, TTY_PARITY); 943 - } 944 - 945 - if (error_f) 946 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_ERROR_STATUS); 947 - 948 - if (msm_uport->clk_req_off_state == CLK_REQ_OFF_FLUSH_ISSUED) 949 - msm_uport->clk_req_off_state = CLK_REQ_OFF_RXSTALE_FLUSHED; 950 - 951 - flush = msm_uport->rx.flush; 952 - if (flush == FLUSH_IGNORE) 953 - msm_hs_start_rx_locked(uport); 954 - if (flush == FLUSH_STOP) 955 - msm_uport->rx.flush = FLUSH_SHUTDOWN; 956 - if (flush >= FLUSH_DATA_INVALID) 957 - goto out; 958 - 959 - rx_count = msm_hs_read(uport, UARTDM_RX_TOTAL_SNAP_ADDR); 960 - 961 - if (0 != (uport->read_status_mask & CREAD)) { 962 - retval = tty_insert_flip_string(port, msm_uport->rx.buffer, 963 - rx_count); 964 - BUG_ON(retval != rx_count); 965 - } 966 - 967 - msm_hs_start_rx_locked(uport); 968 - 969 - out: 970 - clk_disable(msm_uport->clk); 971 - 972 - spin_unlock_irqrestore(&uport->lock, flags); 973 - 974 - if (flush < FLUSH_DATA_INVALID) 975 - queue_work(msm_hs_workqueue, &msm_uport->rx.tty_work); 976 - } 977 - 978 - static void msm_hs_tty_flip_buffer_work(struct work_struct *work) 979 - { 980 - struct msm_hs_port *msm_uport = 981 - container_of(work, struct msm_hs_port, rx.tty_work); 982 - 983 - tty_flip_buffer_push(&msm_uport->uport.state->port); 984 - } 985 - 986 - /* 987 - * Standard API, Current states of modem control inputs 988 - * 989 - * Since CTS can be handled entirely by HARDWARE we always 990 - * indicate clear to send and count on the TX FIFO to block when 991 - * it fills up. 992 - * 993 - * - TIOCM_DCD 994 - * - TIOCM_CTS 995 - * - TIOCM_DSR 996 - * - TIOCM_RI 997 - * (Unsupported) DCD and DSR will return them high. RI will return low. 998 - */ 999 - static unsigned int msm_hs_get_mctrl_locked(struct uart_port *uport) 1000 - { 1001 - return TIOCM_DSR | TIOCM_CAR | TIOCM_CTS; 1002 - } 1003 - 1004 - /* 1005 - * True enables UART auto RFR, which indicates we are ready for data if the RX 1006 - * buffer is not full. False disables auto RFR, and deasserts RFR to indicate 1007 - * we are not ready for data. Must be called with UART clock on. 1008 - */ 1009 - static void set_rfr_locked(struct uart_port *uport, int auto_rfr) 1010 - { 1011 - unsigned int data; 1012 - 1013 - data = msm_hs_read(uport, UARTDM_MR1_ADDR); 1014 - 1015 - if (auto_rfr) { 1016 - /* enable auto ready-for-receiving */ 1017 - data |= UARTDM_MR1_RX_RDY_CTL_BMSK; 1018 - msm_hs_write(uport, UARTDM_MR1_ADDR, data); 1019 - } else { 1020 - /* disable auto ready-for-receiving */ 1021 - data &= ~UARTDM_MR1_RX_RDY_CTL_BMSK; 1022 - msm_hs_write(uport, UARTDM_MR1_ADDR, data); 1023 - /* RFR is active low, set high */ 1024 - msm_hs_write(uport, UARTDM_CR_ADDR, RFR_HIGH); 1025 - } 1026 - } 1027 - 1028 - /* 1029 - * Standard API, used to set or clear RFR 1030 - */ 1031 - static void msm_hs_set_mctrl_locked(struct uart_port *uport, 1032 - unsigned int mctrl) 1033 - { 1034 - unsigned int auto_rfr; 1035 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1036 - 1037 - clk_enable(msm_uport->clk); 1038 - 1039 - auto_rfr = TIOCM_RTS & mctrl ? 1 : 0; 1040 - set_rfr_locked(uport, auto_rfr); 1041 - 1042 - clk_disable(msm_uport->clk); 1043 - } 1044 - 1045 - /* Standard API, Enable modem status (CTS) interrupt */ 1046 - static void msm_hs_enable_ms_locked(struct uart_port *uport) 1047 - { 1048 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1049 - 1050 - clk_enable(msm_uport->clk); 1051 - 1052 - /* Enable DELTA_CTS Interrupt */ 1053 - msm_uport->imr_reg |= UARTDM_ISR_DELTA_CTS_BMSK; 1054 - msm_hs_write(uport, UARTDM_IMR_ADDR, msm_uport->imr_reg); 1055 - 1056 - clk_disable(msm_uport->clk); 1057 - 1058 - } 1059 - 1060 - /* 1061 - * Standard API, Break Signal 1062 - * 1063 - * Control the transmission of a break signal. ctl eq 0 => break 1064 - * signal terminate ctl ne 0 => start break signal 1065 - */ 1066 - static void msm_hs_break_ctl(struct uart_port *uport, int ctl) 1067 - { 1068 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1069 - 1070 - clk_enable(msm_uport->clk); 1071 - msm_hs_write(uport, UARTDM_CR_ADDR, ctl ? START_BREAK : STOP_BREAK); 1072 - clk_disable(msm_uport->clk); 1073 - } 1074 - 1075 - static void msm_hs_config_port(struct uart_port *uport, int cfg_flags) 1076 - { 1077 - unsigned long flags; 1078 - 1079 - spin_lock_irqsave(&uport->lock, flags); 1080 - if (cfg_flags & UART_CONFIG_TYPE) { 1081 - uport->type = PORT_MSM; 1082 - msm_hs_request_port(uport); 1083 - } 1084 - spin_unlock_irqrestore(&uport->lock, flags); 1085 - } 1086 - 1087 - /* Handle CTS changes (Called from interrupt handler) */ 1088 - static void msm_hs_handle_delta_cts_locked(struct uart_port *uport) 1089 - { 1090 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1091 - 1092 - clk_enable(msm_uport->clk); 1093 - 1094 - /* clear interrupt */ 1095 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_CTS); 1096 - uport->icount.cts++; 1097 - 1098 - clk_disable(msm_uport->clk); 1099 - 1100 - /* clear the IOCTL TIOCMIWAIT if called */ 1101 - wake_up_interruptible(&uport->state->port.delta_msr_wait); 1102 - } 1103 - 1104 - /* check if the TX path is flushed, and if so clock off 1105 - * returns 0 did not clock off, need to retry (still sending final byte) 1106 - * -1 did not clock off, do not retry 1107 - * 1 if we clocked off 1108 - */ 1109 - static int msm_hs_check_clock_off_locked(struct uart_port *uport) 1110 - { 1111 - unsigned long sr_status; 1112 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1113 - struct circ_buf *tx_buf = &uport->state->xmit; 1114 - 1115 - /* Cancel if tx tty buffer is not empty, dma is in flight, 1116 - * or tx fifo is not empty, or rx fifo is not empty */ 1117 - if (msm_uport->clk_state != MSM_HS_CLK_REQUEST_OFF || 1118 - !uart_circ_empty(tx_buf) || msm_uport->tx.dma_in_flight || 1119 - (msm_uport->imr_reg & UARTDM_ISR_TXLEV_BMSK) || 1120 - !(msm_uport->imr_reg & UARTDM_ISR_RXLEV_BMSK)) { 1121 - return -1; 1122 - } 1123 - 1124 - /* Make sure the uart is finished with the last byte */ 1125 - sr_status = msm_hs_read(uport, UARTDM_SR_ADDR); 1126 - if (!(sr_status & UARTDM_SR_TXEMT_BMSK)) 1127 - return 0; /* retry */ 1128 - 1129 - /* Make sure forced RXSTALE flush complete */ 1130 - switch (msm_uport->clk_req_off_state) { 1131 - case CLK_REQ_OFF_START: 1132 - msm_uport->clk_req_off_state = CLK_REQ_OFF_RXSTALE_ISSUED; 1133 - msm_hs_write(uport, UARTDM_CR_ADDR, FORCE_STALE_EVENT); 1134 - return 0; /* RXSTALE flush not complete - retry */ 1135 - case CLK_REQ_OFF_RXSTALE_ISSUED: 1136 - case CLK_REQ_OFF_FLUSH_ISSUED: 1137 - return 0; /* RXSTALE flush not complete - retry */ 1138 - case CLK_REQ_OFF_RXSTALE_FLUSHED: 1139 - break; /* continue */ 1140 - } 1141 - 1142 - if (msm_uport->rx.flush != FLUSH_SHUTDOWN) { 1143 - if (msm_uport->rx.flush == FLUSH_NONE) 1144 - msm_hs_stop_rx_locked(uport); 1145 - return 0; /* come back later to really clock off */ 1146 - } 1147 - 1148 - /* we really want to clock off */ 1149 - clk_disable(msm_uport->clk); 1150 - msm_uport->clk_state = MSM_HS_CLK_OFF; 1151 - 1152 - if (use_low_power_rx_wakeup(msm_uport)) { 1153 - msm_uport->rx_wakeup.ignore = 1; 1154 - enable_irq(msm_uport->rx_wakeup.irq); 1155 - } 1156 - return 1; 1157 - } 1158 - 1159 - static enum hrtimer_restart msm_hs_clk_off_retry(struct hrtimer *timer) 1160 - { 1161 - unsigned long flags; 1162 - int ret = HRTIMER_NORESTART; 1163 - struct msm_hs_port *msm_uport = container_of(timer, struct msm_hs_port, 1164 - clk_off_timer); 1165 - struct uart_port *uport = &msm_uport->uport; 1166 - 1167 - spin_lock_irqsave(&uport->lock, flags); 1168 - 1169 - if (!msm_hs_check_clock_off_locked(uport)) { 1170 - hrtimer_forward_now(timer, msm_uport->clk_off_delay); 1171 - ret = HRTIMER_RESTART; 1172 - } 1173 - 1174 - spin_unlock_irqrestore(&uport->lock, flags); 1175 - 1176 - return ret; 1177 - } 1178 - 1179 - static irqreturn_t msm_hs_isr(int irq, void *dev) 1180 - { 1181 - unsigned long flags; 1182 - unsigned long isr_status; 1183 - struct msm_hs_port *msm_uport = dev; 1184 - struct uart_port *uport = &msm_uport->uport; 1185 - struct circ_buf *tx_buf = &uport->state->xmit; 1186 - struct msm_hs_tx *tx = &msm_uport->tx; 1187 - struct msm_hs_rx *rx = &msm_uport->rx; 1188 - 1189 - spin_lock_irqsave(&uport->lock, flags); 1190 - 1191 - isr_status = msm_hs_read(uport, UARTDM_MISR_ADDR); 1192 - 1193 - /* Uart RX starting */ 1194 - if (isr_status & UARTDM_ISR_RXLEV_BMSK) { 1195 - msm_uport->imr_reg &= ~UARTDM_ISR_RXLEV_BMSK; 1196 - msm_hs_write(uport, UARTDM_IMR_ADDR, msm_uport->imr_reg); 1197 - } 1198 - /* Stale rx interrupt */ 1199 - if (isr_status & UARTDM_ISR_RXSTALE_BMSK) { 1200 - msm_hs_write(uport, UARTDM_CR_ADDR, STALE_EVENT_DISABLE); 1201 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_STALE_INT); 1202 - 1203 - if (msm_uport->clk_req_off_state == CLK_REQ_OFF_RXSTALE_ISSUED) 1204 - msm_uport->clk_req_off_state = 1205 - CLK_REQ_OFF_FLUSH_ISSUED; 1206 - if (rx->flush == FLUSH_NONE) { 1207 - rx->flush = FLUSH_DATA_READY; 1208 - msm_dmov_stop_cmd(msm_uport->dma_rx_channel, NULL, 1); 1209 - } 1210 - } 1211 - /* tx ready interrupt */ 1212 - if (isr_status & UARTDM_ISR_TX_READY_BMSK) { 1213 - /* Clear TX Ready */ 1214 - msm_hs_write(uport, UARTDM_CR_ADDR, CLEAR_TX_READY); 1215 - 1216 - if (msm_uport->clk_state == MSM_HS_CLK_REQUEST_OFF) { 1217 - msm_uport->imr_reg |= UARTDM_ISR_TXLEV_BMSK; 1218 - msm_hs_write(uport, UARTDM_IMR_ADDR, 1219 - msm_uport->imr_reg); 1220 - } 1221 - 1222 - /* Complete DMA TX transactions and submit new transactions */ 1223 - tx_buf->tail = (tx_buf->tail + tx->tx_count) & ~UART_XMIT_SIZE; 1224 - 1225 - tx->dma_in_flight = 0; 1226 - 1227 - uport->icount.tx += tx->tx_count; 1228 - if (tx->tx_ready_int_en) 1229 - msm_hs_submit_tx_locked(uport); 1230 - 1231 - if (uart_circ_chars_pending(tx_buf) < WAKEUP_CHARS) 1232 - uart_write_wakeup(uport); 1233 - } 1234 - if (isr_status & UARTDM_ISR_TXLEV_BMSK) { 1235 - /* TX FIFO is empty */ 1236 - msm_uport->imr_reg &= ~UARTDM_ISR_TXLEV_BMSK; 1237 - msm_hs_write(uport, UARTDM_IMR_ADDR, msm_uport->imr_reg); 1238 - if (!msm_hs_check_clock_off_locked(uport)) 1239 - hrtimer_start(&msm_uport->clk_off_timer, 1240 - msm_uport->clk_off_delay, 1241 - HRTIMER_MODE_REL); 1242 - } 1243 - 1244 - /* Change in CTS interrupt */ 1245 - if (isr_status & UARTDM_ISR_DELTA_CTS_BMSK) 1246 - msm_hs_handle_delta_cts_locked(uport); 1247 - 1248 - spin_unlock_irqrestore(&uport->lock, flags); 1249 - 1250 - return IRQ_HANDLED; 1251 - } 1252 - 1253 - void msm_hs_request_clock_off_locked(struct uart_port *uport) 1254 - { 1255 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1256 - 1257 - if (msm_uport->clk_state == MSM_HS_CLK_ON) { 1258 - msm_uport->clk_state = MSM_HS_CLK_REQUEST_OFF; 1259 - msm_uport->clk_req_off_state = CLK_REQ_OFF_START; 1260 - if (!use_low_power_rx_wakeup(msm_uport)) 1261 - set_rfr_locked(uport, 0); 1262 - msm_uport->imr_reg |= UARTDM_ISR_TXLEV_BMSK; 1263 - msm_hs_write(uport, UARTDM_IMR_ADDR, msm_uport->imr_reg); 1264 - } 1265 - } 1266 - 1267 - /** 1268 - * msm_hs_request_clock_off - request to (i.e. asynchronously) turn off uart 1269 - * clock once pending TX is flushed and Rx DMA command is terminated. 1270 - * @uport: uart_port structure for the device instance. 1271 - * 1272 - * This functions puts the device into a partially active low power mode. It 1273 - * waits to complete all pending tx transactions, flushes ongoing Rx DMA 1274 - * command and terminates UART side Rx transaction, puts UART HW in non DMA 1275 - * mode and then clocks off the device. A client calls this when no UART 1276 - * data is expected. msm_request_clock_on() must be called before any further 1277 - * UART can be sent or received. 1278 - */ 1279 - void msm_hs_request_clock_off(struct uart_port *uport) 1280 - { 1281 - unsigned long flags; 1282 - 1283 - spin_lock_irqsave(&uport->lock, flags); 1284 - msm_hs_request_clock_off_locked(uport); 1285 - spin_unlock_irqrestore(&uport->lock, flags); 1286 - } 1287 - 1288 - void msm_hs_request_clock_on_locked(struct uart_port *uport) 1289 - { 1290 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1291 - unsigned int data; 1292 - 1293 - switch (msm_uport->clk_state) { 1294 - case MSM_HS_CLK_OFF: 1295 - clk_enable(msm_uport->clk); 1296 - disable_irq_nosync(msm_uport->rx_wakeup.irq); 1297 - /* fall-through */ 1298 - case MSM_HS_CLK_REQUEST_OFF: 1299 - if (msm_uport->rx.flush == FLUSH_STOP || 1300 - msm_uport->rx.flush == FLUSH_SHUTDOWN) { 1301 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_RX); 1302 - data = msm_hs_read(uport, UARTDM_DMEN_ADDR); 1303 - data |= UARTDM_RX_DM_EN_BMSK; 1304 - msm_hs_write(uport, UARTDM_DMEN_ADDR, data); 1305 - } 1306 - hrtimer_try_to_cancel(&msm_uport->clk_off_timer); 1307 - if (msm_uport->rx.flush == FLUSH_SHUTDOWN) 1308 - msm_hs_start_rx_locked(uport); 1309 - if (!use_low_power_rx_wakeup(msm_uport)) 1310 - set_rfr_locked(uport, 1); 1311 - if (msm_uport->rx.flush == FLUSH_STOP) 1312 - msm_uport->rx.flush = FLUSH_IGNORE; 1313 - msm_uport->clk_state = MSM_HS_CLK_ON; 1314 - break; 1315 - case MSM_HS_CLK_ON: 1316 - break; 1317 - case MSM_HS_CLK_PORT_OFF: 1318 - break; 1319 - } 1320 - } 1321 - 1322 - /** 1323 - * msm_hs_request_clock_on - Switch the device from partially active low 1324 - * power mode to fully active (i.e. clock on) mode. 1325 - * @uport: uart_port structure for the device. 1326 - * 1327 - * This function switches on the input clock, puts UART HW into DMA mode 1328 - * and enqueues an Rx DMA command if the device was in partially active 1329 - * mode. It has no effect if called with the device in inactive state. 1330 - */ 1331 - void msm_hs_request_clock_on(struct uart_port *uport) 1332 - { 1333 - unsigned long flags; 1334 - 1335 - spin_lock_irqsave(&uport->lock, flags); 1336 - msm_hs_request_clock_on_locked(uport); 1337 - spin_unlock_irqrestore(&uport->lock, flags); 1338 - } 1339 - 1340 - static irqreturn_t msm_hs_rx_wakeup_isr(int irq, void *dev) 1341 - { 1342 - unsigned int wakeup = 0; 1343 - unsigned long flags; 1344 - struct msm_hs_port *msm_uport = dev; 1345 - struct uart_port *uport = &msm_uport->uport; 1346 - 1347 - spin_lock_irqsave(&uport->lock, flags); 1348 - if (msm_uport->clk_state == MSM_HS_CLK_OFF) { 1349 - /* ignore the first irq - it is a pending irq that occurred 1350 - * before enable_irq() */ 1351 - if (msm_uport->rx_wakeup.ignore) 1352 - msm_uport->rx_wakeup.ignore = 0; 1353 - else 1354 - wakeup = 1; 1355 - } 1356 - 1357 - if (wakeup) { 1358 - /* the uart was clocked off during an rx, wake up and 1359 - * optionally inject char into tty rx */ 1360 - msm_hs_request_clock_on_locked(uport); 1361 - if (msm_uport->rx_wakeup.inject_rx) { 1362 - tty_insert_flip_char(&uport->state->port, 1363 - msm_uport->rx_wakeup.rx_to_inject, 1364 - TTY_NORMAL); 1365 - queue_work(msm_hs_workqueue, &msm_uport->rx.tty_work); 1366 - } 1367 - } 1368 - 1369 - spin_unlock_irqrestore(&uport->lock, flags); 1370 - 1371 - return IRQ_HANDLED; 1372 - } 1373 - 1374 - static const char *msm_hs_type(struct uart_port *port) 1375 - { 1376 - return (port->type == PORT_MSM) ? "MSM_HS_UART" : NULL; 1377 - } 1378 - 1379 - /* Called when port is opened */ 1380 - static int msm_hs_startup(struct uart_port *uport) 1381 - { 1382 - int ret; 1383 - int rfr_level; 1384 - unsigned long flags; 1385 - unsigned int data; 1386 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1387 - struct circ_buf *tx_buf = &uport->state->xmit; 1388 - struct msm_hs_tx *tx = &msm_uport->tx; 1389 - struct msm_hs_rx *rx = &msm_uport->rx; 1390 - 1391 - rfr_level = uport->fifosize; 1392 - if (rfr_level > 16) 1393 - rfr_level -= 16; 1394 - 1395 - tx->dma_base = dma_map_single(uport->dev, tx_buf->buf, UART_XMIT_SIZE, 1396 - DMA_TO_DEVICE); 1397 - 1398 - /* do not let tty layer execute RX in global workqueue, use a 1399 - * dedicated workqueue managed by this driver */ 1400 - uport->state->port.low_latency = 1; 1401 - 1402 - /* turn on uart clk */ 1403 - ret = msm_hs_init_clk_locked(uport); 1404 - if (unlikely(ret)) { 1405 - printk(KERN_ERR "Turning uartclk failed!\n"); 1406 - goto err_msm_hs_init_clk; 1407 - } 1408 - 1409 - /* Set auto RFR Level */ 1410 - data = msm_hs_read(uport, UARTDM_MR1_ADDR); 1411 - data &= ~UARTDM_MR1_AUTO_RFR_LEVEL1_BMSK; 1412 - data &= ~UARTDM_MR1_AUTO_RFR_LEVEL0_BMSK; 1413 - data |= (UARTDM_MR1_AUTO_RFR_LEVEL1_BMSK & (rfr_level << 2)); 1414 - data |= (UARTDM_MR1_AUTO_RFR_LEVEL0_BMSK & rfr_level); 1415 - msm_hs_write(uport, UARTDM_MR1_ADDR, data); 1416 - 1417 - /* Make sure RXSTALE count is non-zero */ 1418 - data = msm_hs_read(uport, UARTDM_IPR_ADDR); 1419 - if (!data) { 1420 - data |= 0x1f & UARTDM_IPR_STALE_LSB_BMSK; 1421 - msm_hs_write(uport, UARTDM_IPR_ADDR, data); 1422 - } 1423 - 1424 - /* Enable Data Mover Mode */ 1425 - data = UARTDM_TX_DM_EN_BMSK | UARTDM_RX_DM_EN_BMSK; 1426 - msm_hs_write(uport, UARTDM_DMEN_ADDR, data); 1427 - 1428 - /* Reset TX */ 1429 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_TX); 1430 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_RX); 1431 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_ERROR_STATUS); 1432 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_BREAK_INT); 1433 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_STALE_INT); 1434 - msm_hs_write(uport, UARTDM_CR_ADDR, RESET_CTS); 1435 - msm_hs_write(uport, UARTDM_CR_ADDR, RFR_LOW); 1436 - /* Turn on Uart Receiver */ 1437 - msm_hs_write(uport, UARTDM_CR_ADDR, UARTDM_CR_RX_EN_BMSK); 1438 - 1439 - /* Turn on Uart Transmitter */ 1440 - msm_hs_write(uport, UARTDM_CR_ADDR, UARTDM_CR_TX_EN_BMSK); 1441 - 1442 - /* Initialize the tx */ 1443 - tx->tx_ready_int_en = 0; 1444 - tx->dma_in_flight = 0; 1445 - 1446 - tx->xfer.complete_func = msm_hs_dmov_tx_callback; 1447 - tx->xfer.execute_func = NULL; 1448 - 1449 - tx->command_ptr->cmd = CMD_LC | 1450 - CMD_DST_CRCI(msm_uport->dma_tx_crci) | CMD_MODE_BOX; 1451 - 1452 - tx->command_ptr->src_dst_len = (MSM_UARTDM_BURST_SIZE << 16) 1453 - | (MSM_UARTDM_BURST_SIZE); 1454 - 1455 - tx->command_ptr->row_offset = (MSM_UARTDM_BURST_SIZE << 16); 1456 - 1457 - tx->command_ptr->dst_row_addr = 1458 - msm_uport->uport.mapbase + UARTDM_TF_ADDR; 1459 - 1460 - 1461 - /* Turn on Uart Receive */ 1462 - rx->xfer.complete_func = msm_hs_dmov_rx_callback; 1463 - rx->xfer.execute_func = NULL; 1464 - 1465 - rx->command_ptr->cmd = CMD_LC | 1466 - CMD_SRC_CRCI(msm_uport->dma_rx_crci) | CMD_MODE_BOX; 1467 - 1468 - rx->command_ptr->src_dst_len = (MSM_UARTDM_BURST_SIZE << 16) 1469 - | (MSM_UARTDM_BURST_SIZE); 1470 - rx->command_ptr->row_offset = MSM_UARTDM_BURST_SIZE; 1471 - rx->command_ptr->src_row_addr = uport->mapbase + UARTDM_RF_ADDR; 1472 - 1473 - 1474 - msm_uport->imr_reg |= UARTDM_ISR_RXSTALE_BMSK; 1475 - /* Enable reading the current CTS, no harm even if CTS is ignored */ 1476 - msm_uport->imr_reg |= UARTDM_ISR_CURRENT_CTS_BMSK; 1477 - 1478 - msm_hs_write(uport, UARTDM_TFWR_ADDR, 0); /* TXLEV on empty TX fifo */ 1479 - 1480 - 1481 - ret = request_irq(uport->irq, msm_hs_isr, IRQF_TRIGGER_HIGH, 1482 - "msm_hs_uart", msm_uport); 1483 - if (unlikely(ret)) { 1484 - printk(KERN_ERR "Request msm_hs_uart IRQ failed!\n"); 1485 - goto err_request_irq; 1486 - } 1487 - if (use_low_power_rx_wakeup(msm_uport)) { 1488 - ret = request_irq(msm_uport->rx_wakeup.irq, 1489 - msm_hs_rx_wakeup_isr, 1490 - IRQF_TRIGGER_FALLING, 1491 - "msm_hs_rx_wakeup", msm_uport); 1492 - if (unlikely(ret)) { 1493 - printk(KERN_ERR "Request msm_hs_rx_wakeup IRQ failed!\n"); 1494 - free_irq(uport->irq, msm_uport); 1495 - goto err_request_irq; 1496 - } 1497 - disable_irq(msm_uport->rx_wakeup.irq); 1498 - } 1499 - 1500 - spin_lock_irqsave(&uport->lock, flags); 1501 - 1502 - msm_hs_write(uport, UARTDM_RFWR_ADDR, 0); 1503 - msm_hs_start_rx_locked(uport); 1504 - 1505 - spin_unlock_irqrestore(&uport->lock, flags); 1506 - ret = pm_runtime_set_active(uport->dev); 1507 - if (ret) 1508 - dev_err(uport->dev, "set active error:%d\n", ret); 1509 - pm_runtime_enable(uport->dev); 1510 - 1511 - return 0; 1512 - 1513 - err_request_irq: 1514 - err_msm_hs_init_clk: 1515 - dma_unmap_single(uport->dev, tx->dma_base, 1516 - UART_XMIT_SIZE, DMA_TO_DEVICE); 1517 - return ret; 1518 - } 1519 - 1520 - /* Initialize tx and rx data structures */ 1521 - static int uartdm_init_port(struct uart_port *uport) 1522 - { 1523 - int ret = 0; 1524 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1525 - struct msm_hs_tx *tx = &msm_uport->tx; 1526 - struct msm_hs_rx *rx = &msm_uport->rx; 1527 - 1528 - /* Allocate the command pointer. Needs to be 64 bit aligned */ 1529 - tx->command_ptr = kmalloc(sizeof(dmov_box), GFP_KERNEL | __GFP_DMA); 1530 - if (!tx->command_ptr) 1531 - return -ENOMEM; 1532 - 1533 - tx->command_ptr_ptr = kmalloc(sizeof(u32), GFP_KERNEL | __GFP_DMA); 1534 - if (!tx->command_ptr_ptr) { 1535 - ret = -ENOMEM; 1536 - goto err_tx_command_ptr_ptr; 1537 - } 1538 - 1539 - tx->mapped_cmd_ptr = dma_map_single(uport->dev, tx->command_ptr, 1540 - sizeof(dmov_box), DMA_TO_DEVICE); 1541 - tx->mapped_cmd_ptr_ptr = dma_map_single(uport->dev, 1542 - tx->command_ptr_ptr, 1543 - sizeof(u32), DMA_TO_DEVICE); 1544 - tx->xfer.cmdptr = DMOV_CMD_ADDR(tx->mapped_cmd_ptr_ptr); 1545 - 1546 - init_waitqueue_head(&rx->wait); 1547 - 1548 - rx->pool = dma_pool_create("rx_buffer_pool", uport->dev, 1549 - UARTDM_RX_BUF_SIZE, 16, 0); 1550 - if (!rx->pool) { 1551 - pr_err("%s(): cannot allocate rx_buffer_pool", __func__); 1552 - ret = -ENOMEM; 1553 - goto err_dma_pool_create; 1554 - } 1555 - 1556 - rx->buffer = dma_pool_alloc(rx->pool, GFP_KERNEL, &rx->rbuffer); 1557 - if (!rx->buffer) { 1558 - pr_err("%s(): cannot allocate rx->buffer", __func__); 1559 - ret = -ENOMEM; 1560 - goto err_dma_pool_alloc; 1561 - } 1562 - 1563 - /* Allocate the command pointer. Needs to be 64 bit aligned */ 1564 - rx->command_ptr = kmalloc(sizeof(dmov_box), GFP_KERNEL | __GFP_DMA); 1565 - if (!rx->command_ptr) { 1566 - pr_err("%s(): cannot allocate rx->command_ptr", __func__); 1567 - ret = -ENOMEM; 1568 - goto err_rx_command_ptr; 1569 - } 1570 - 1571 - rx->command_ptr_ptr = kmalloc(sizeof(u32), GFP_KERNEL | __GFP_DMA); 1572 - if (!rx->command_ptr_ptr) { 1573 - pr_err("%s(): cannot allocate rx->command_ptr_ptr", __func__); 1574 - ret = -ENOMEM; 1575 - goto err_rx_command_ptr_ptr; 1576 - } 1577 - 1578 - rx->command_ptr->num_rows = ((UARTDM_RX_BUF_SIZE >> 4) << 16) | 1579 - (UARTDM_RX_BUF_SIZE >> 4); 1580 - 1581 - rx->command_ptr->dst_row_addr = rx->rbuffer; 1582 - 1583 - rx->mapped_cmd_ptr = dma_map_single(uport->dev, rx->command_ptr, 1584 - sizeof(dmov_box), DMA_TO_DEVICE); 1585 - 1586 - *rx->command_ptr_ptr = CMD_PTR_LP | DMOV_CMD_ADDR(rx->mapped_cmd_ptr); 1587 - 1588 - rx->cmdptr_dmaaddr = dma_map_single(uport->dev, rx->command_ptr_ptr, 1589 - sizeof(u32), DMA_TO_DEVICE); 1590 - rx->xfer.cmdptr = DMOV_CMD_ADDR(rx->cmdptr_dmaaddr); 1591 - 1592 - INIT_WORK(&rx->tty_work, msm_hs_tty_flip_buffer_work); 1593 - 1594 - return ret; 1595 - 1596 - err_rx_command_ptr_ptr: 1597 - kfree(rx->command_ptr); 1598 - err_rx_command_ptr: 1599 - dma_pool_free(msm_uport->rx.pool, msm_uport->rx.buffer, 1600 - msm_uport->rx.rbuffer); 1601 - err_dma_pool_alloc: 1602 - dma_pool_destroy(msm_uport->rx.pool); 1603 - err_dma_pool_create: 1604 - dma_unmap_single(uport->dev, msm_uport->tx.mapped_cmd_ptr_ptr, 1605 - sizeof(u32), DMA_TO_DEVICE); 1606 - dma_unmap_single(uport->dev, msm_uport->tx.mapped_cmd_ptr, 1607 - sizeof(dmov_box), DMA_TO_DEVICE); 1608 - kfree(msm_uport->tx.command_ptr_ptr); 1609 - err_tx_command_ptr_ptr: 1610 - kfree(msm_uport->tx.command_ptr); 1611 - return ret; 1612 - } 1613 - 1614 - static int msm_hs_probe(struct platform_device *pdev) 1615 - { 1616 - int ret; 1617 - struct uart_port *uport; 1618 - struct msm_hs_port *msm_uport; 1619 - struct resource *resource; 1620 - const struct msm_serial_hs_platform_data *pdata = 1621 - dev_get_platdata(&pdev->dev); 1622 - 1623 - if (pdev->id < 0 || pdev->id >= UARTDM_NR) { 1624 - printk(KERN_ERR "Invalid plaform device ID = %d\n", pdev->id); 1625 - return -EINVAL; 1626 - } 1627 - 1628 - msm_uport = &q_uart_port[pdev->id]; 1629 - uport = &msm_uport->uport; 1630 - 1631 - uport->dev = &pdev->dev; 1632 - 1633 - resource = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1634 - if (unlikely(!resource)) 1635 - return -ENXIO; 1636 - 1637 - uport->mapbase = resource->start; 1638 - uport->irq = platform_get_irq(pdev, 0); 1639 - if (unlikely(uport->irq < 0)) 1640 - return -ENXIO; 1641 - 1642 - if (unlikely(irq_set_irq_wake(uport->irq, 1))) 1643 - return -ENXIO; 1644 - 1645 - if (pdata == NULL || pdata->rx_wakeup_irq < 0) 1646 - msm_uport->rx_wakeup.irq = -1; 1647 - else { 1648 - msm_uport->rx_wakeup.irq = pdata->rx_wakeup_irq; 1649 - msm_uport->rx_wakeup.ignore = 1; 1650 - msm_uport->rx_wakeup.inject_rx = pdata->inject_rx_on_wakeup; 1651 - msm_uport->rx_wakeup.rx_to_inject = pdata->rx_to_inject; 1652 - 1653 - if (unlikely(msm_uport->rx_wakeup.irq < 0)) 1654 - return -ENXIO; 1655 - 1656 - if (unlikely(irq_set_irq_wake(msm_uport->rx_wakeup.irq, 1))) 1657 - return -ENXIO; 1658 - } 1659 - 1660 - if (pdata == NULL) 1661 - msm_uport->exit_lpm_cb = NULL; 1662 - else 1663 - msm_uport->exit_lpm_cb = pdata->exit_lpm_cb; 1664 - 1665 - resource = platform_get_resource_byname(pdev, IORESOURCE_DMA, 1666 - "uartdm_channels"); 1667 - if (unlikely(!resource)) 1668 - return -ENXIO; 1669 - 1670 - msm_uport->dma_tx_channel = resource->start; 1671 - msm_uport->dma_rx_channel = resource->end; 1672 - 1673 - resource = platform_get_resource_byname(pdev, IORESOURCE_DMA, 1674 - "uartdm_crci"); 1675 - if (unlikely(!resource)) 1676 - return -ENXIO; 1677 - 1678 - msm_uport->dma_tx_crci = resource->start; 1679 - msm_uport->dma_rx_crci = resource->end; 1680 - 1681 - uport->iotype = UPIO_MEM; 1682 - uport->fifosize = UART_FIFOSIZE; 1683 - uport->ops = &msm_hs_ops; 1684 - uport->flags = UPF_BOOT_AUTOCONF; 1685 - uport->uartclk = UARTCLK; 1686 - msm_uport->imr_reg = 0x0; 1687 - msm_uport->clk = clk_get(&pdev->dev, "uartdm_clk"); 1688 - if (IS_ERR(msm_uport->clk)) 1689 - return PTR_ERR(msm_uport->clk); 1690 - 1691 - ret = uartdm_init_port(uport); 1692 - if (unlikely(ret)) 1693 - return ret; 1694 - 1695 - msm_uport->clk_state = MSM_HS_CLK_PORT_OFF; 1696 - hrtimer_init(&msm_uport->clk_off_timer, CLOCK_MONOTONIC, 1697 - HRTIMER_MODE_REL); 1698 - msm_uport->clk_off_timer.function = msm_hs_clk_off_retry; 1699 - msm_uport->clk_off_delay = ktime_set(0, 1000000); /* 1ms */ 1700 - 1701 - uport->line = pdev->id; 1702 - return uart_add_one_port(&msm_hs_driver, uport); 1703 - } 1704 - 1705 - static int __init msm_serial_hs_init(void) 1706 - { 1707 - int ret, i; 1708 - 1709 - /* Init all UARTS as non-configured */ 1710 - for (i = 0; i < UARTDM_NR; i++) 1711 - q_uart_port[i].uport.type = PORT_UNKNOWN; 1712 - 1713 - msm_hs_workqueue = create_singlethread_workqueue("msm_serial_hs"); 1714 - if (unlikely(!msm_hs_workqueue)) 1715 - return -ENOMEM; 1716 - 1717 - ret = uart_register_driver(&msm_hs_driver); 1718 - if (unlikely(ret)) { 1719 - printk(KERN_ERR "%s failed to load\n", __func__); 1720 - goto err_uart_register_driver; 1721 - } 1722 - 1723 - ret = platform_driver_register(&msm_serial_hs_platform_driver); 1724 - if (ret) { 1725 - printk(KERN_ERR "%s failed to load\n", __func__); 1726 - goto err_platform_driver_register; 1727 - } 1728 - 1729 - return ret; 1730 - 1731 - err_platform_driver_register: 1732 - uart_unregister_driver(&msm_hs_driver); 1733 - err_uart_register_driver: 1734 - destroy_workqueue(msm_hs_workqueue); 1735 - return ret; 1736 - } 1737 - module_init(msm_serial_hs_init); 1738 - 1739 - /* 1740 - * Called by the upper layer when port is closed. 1741 - * - Disables the port 1742 - * - Unhook the ISR 1743 - */ 1744 - static void msm_hs_shutdown(struct uart_port *uport) 1745 - { 1746 - unsigned long flags; 1747 - struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1748 - 1749 - BUG_ON(msm_uport->rx.flush < FLUSH_STOP); 1750 - 1751 - spin_lock_irqsave(&uport->lock, flags); 1752 - clk_enable(msm_uport->clk); 1753 - 1754 - /* Disable the transmitter */ 1755 - msm_hs_write(uport, UARTDM_CR_ADDR, UARTDM_CR_TX_DISABLE_BMSK); 1756 - /* Disable the receiver */ 1757 - msm_hs_write(uport, UARTDM_CR_ADDR, UARTDM_CR_RX_DISABLE_BMSK); 1758 - 1759 - pm_runtime_disable(uport->dev); 1760 - pm_runtime_set_suspended(uport->dev); 1761 - 1762 - /* Free the interrupt */ 1763 - free_irq(uport->irq, msm_uport); 1764 - if (use_low_power_rx_wakeup(msm_uport)) 1765 - free_irq(msm_uport->rx_wakeup.irq, msm_uport); 1766 - 1767 - msm_uport->imr_reg = 0; 1768 - msm_hs_write(uport, UARTDM_IMR_ADDR, msm_uport->imr_reg); 1769 - 1770 - wait_event(msm_uport->rx.wait, msm_uport->rx.flush == FLUSH_SHUTDOWN); 1771 - 1772 - clk_disable(msm_uport->clk); /* to balance local clk_enable() */ 1773 - if (msm_uport->clk_state != MSM_HS_CLK_OFF) 1774 - clk_disable(msm_uport->clk); /* to balance clk_state */ 1775 - msm_uport->clk_state = MSM_HS_CLK_PORT_OFF; 1776 - 1777 - dma_unmap_single(uport->dev, msm_uport->tx.dma_base, 1778 - UART_XMIT_SIZE, DMA_TO_DEVICE); 1779 - 1780 - spin_unlock_irqrestore(&uport->lock, flags); 1781 - 1782 - if (cancel_work_sync(&msm_uport->rx.tty_work)) 1783 - msm_hs_tty_flip_buffer_work(&msm_uport->rx.tty_work); 1784 - } 1785 - 1786 - static void __exit msm_serial_hs_exit(void) 1787 - { 1788 - flush_workqueue(msm_hs_workqueue); 1789 - destroy_workqueue(msm_hs_workqueue); 1790 - platform_driver_unregister(&msm_serial_hs_platform_driver); 1791 - uart_unregister_driver(&msm_hs_driver); 1792 - } 1793 - module_exit(msm_serial_hs_exit); 1794 - 1795 - #ifdef CONFIG_PM 1796 - static int msm_hs_runtime_idle(struct device *dev) 1797 - { 1798 - /* 1799 - * returning success from idle results in runtime suspend to be 1800 - * called 1801 - */ 1802 - return 0; 1803 - } 1804 - 1805 - static int msm_hs_runtime_resume(struct device *dev) 1806 - { 1807 - struct platform_device *pdev = container_of(dev, struct 1808 - platform_device, dev); 1809 - struct msm_hs_port *msm_uport = &q_uart_port[pdev->id]; 1810 - 1811 - msm_hs_request_clock_on(&msm_uport->uport); 1812 - return 0; 1813 - } 1814 - 1815 - static int msm_hs_runtime_suspend(struct device *dev) 1816 - { 1817 - struct platform_device *pdev = container_of(dev, struct 1818 - platform_device, dev); 1819 - struct msm_hs_port *msm_uport = &q_uart_port[pdev->id]; 1820 - 1821 - msm_hs_request_clock_off(&msm_uport->uport); 1822 - return 0; 1823 - } 1824 - #else 1825 - #define msm_hs_runtime_idle NULL 1826 - #define msm_hs_runtime_resume NULL 1827 - #define msm_hs_runtime_suspend NULL 1828 - #endif 1829 - 1830 - static const struct dev_pm_ops msm_hs_dev_pm_ops = { 1831 - .runtime_suspend = msm_hs_runtime_suspend, 1832 - .runtime_resume = msm_hs_runtime_resume, 1833 - .runtime_idle = msm_hs_runtime_idle, 1834 - }; 1835 - 1836 - static struct platform_driver msm_serial_hs_platform_driver = { 1837 - .probe = msm_hs_probe, 1838 - .remove = msm_hs_remove, 1839 - .driver = { 1840 - .name = "msm_serial_hs", 1841 - .pm = &msm_hs_dev_pm_ops, 1842 - }, 1843 - }; 1844 - 1845 - static struct uart_driver msm_hs_driver = { 1846 - .owner = THIS_MODULE, 1847 - .driver_name = "msm_serial_hs", 1848 - .dev_name = "ttyHS", 1849 - .nr = UARTDM_NR, 1850 - .cons = 0, 1851 - }; 1852 - 1853 - static struct uart_ops msm_hs_ops = { 1854 - .tx_empty = msm_hs_tx_empty, 1855 - .set_mctrl = msm_hs_set_mctrl_locked, 1856 - .get_mctrl = msm_hs_get_mctrl_locked, 1857 - .stop_tx = msm_hs_stop_tx_locked, 1858 - .start_tx = msm_hs_start_tx_locked, 1859 - .stop_rx = msm_hs_stop_rx_locked, 1860 - .enable_ms = msm_hs_enable_ms_locked, 1861 - .break_ctl = msm_hs_break_ctl, 1862 - .startup = msm_hs_startup, 1863 - .shutdown = msm_hs_shutdown, 1864 - .set_termios = msm_hs_set_termios, 1865 - .pm = msm_hs_pm, 1866 - .type = msm_hs_type, 1867 - .config_port = msm_hs_config_port, 1868 - .release_port = msm_hs_release_port, 1869 - .request_port = msm_hs_request_port, 1870 - }; 1871 - 1872 - MODULE_DESCRIPTION("High Speed UART Driver for the MSM chipset"); 1873 - MODULE_VERSION("1.2"); 1874 - MODULE_LICENSE("GPL v2");
+10 -8
drivers/tty/serial/mxs-auart.c
··· 176 176 }; 177 177 MODULE_DEVICE_TABLE(platform, mxs_auart_devtype); 178 178 179 - static struct of_device_id mxs_auart_dt_ids[] = { 179 + static const struct of_device_id mxs_auart_dt_ids[] = { 180 180 { 181 181 .compatible = "fsl,imx28-auart", 182 182 .data = &mxs_auart_devtype[IMX28_AUART] ··· 1155 1155 return 0; 1156 1156 } 1157 1157 1158 - static bool mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev) 1158 + static int mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev) 1159 1159 { 1160 1160 enum mctrl_gpio_idx i; 1161 1161 struct gpio_desc *gpiod; 1162 1162 1163 1163 s->gpios = mctrl_gpio_init(dev, 0); 1164 - if (IS_ERR_OR_NULL(s->gpios)) 1165 - return false; 1164 + if (IS_ERR(s->gpios)) 1165 + return PTR_ERR(s->gpios); 1166 1166 1167 1167 /* Block (enabled before) DMA option if RTS or CTS is GPIO line */ 1168 1168 if (!RTS_AT_AUART() || !CTS_AT_AUART()) { ··· 1180 1180 s->gpio_irq[i] = -EINVAL; 1181 1181 } 1182 1182 1183 - return true; 1183 + return 0; 1184 1184 } 1185 1185 1186 1186 static void mxs_auart_free_gpio_irq(struct mxs_auart_port *s) ··· 1276 1276 1277 1277 platform_set_drvdata(pdev, s); 1278 1278 1279 - if (!mxs_auart_init_gpios(s, &pdev->dev)) 1280 - dev_err(&pdev->dev, 1281 - "Failed to initialize GPIOs. The serial port may not work as expected\n"); 1279 + ret = mxs_auart_init_gpios(s, &pdev->dev); 1280 + if (ret) { 1281 + dev_err(&pdev->dev, "Failed to initialize GPIOs.\n"); 1282 + return ret; 1283 + } 1282 1284 1283 1285 /* 1284 1286 * Get the GPIO lines IRQ
+3 -2
drivers/tty/serial/of_serial.c
··· 89 89 90 90 spin_lock_init(&port->lock); 91 91 port->mapbase = resource.start; 92 + port->mapsize = resource_size(&resource); 92 93 93 94 /* Check for shifted address mapping */ 94 95 if (of_property_read_u32(np, "reg-offset", &prop) == 0) ··· 156 155 /* 157 156 * Try to register a serial port 158 157 */ 159 - static struct of_device_id of_platform_serial_table[]; 158 + static const struct of_device_id of_platform_serial_table[]; 160 159 static int of_platform_serial_probe(struct platform_device *ofdev) 161 160 { 162 161 const struct of_device_id *match; ··· 321 320 /* 322 321 * A few common types, add more as needed. 323 322 */ 324 - static struct of_device_id of_platform_serial_table[] = { 323 + static const struct of_device_id of_platform_serial_table[] = { 325 324 { .compatible = "ns8250", .data = (void *)PORT_8250, }, 326 325 { .compatible = "ns16450", .data = (void *)PORT_16450, }, 327 326 { .compatible = "ns16550a", .data = (void *)PORT_16550A, },
+5 -5
drivers/tty/serial/omap-serial.c
··· 1654 1654 up->port.type = PORT_OMAP; 1655 1655 up->port.iotype = UPIO_MEM; 1656 1656 up->port.irq = uartirq; 1657 - up->wakeirq = wakeirq; 1658 - if (!up->wakeirq) 1659 - dev_info(up->port.dev, "no wakeirq for uart%d\n", 1660 - up->port.line); 1661 - 1662 1657 up->port.regshift = 2; 1663 1658 up->port.fifosize = 64; 1664 1659 up->port.ops = &serial_omap_pops; ··· 1676 1681 ret = -ENXIO; 1677 1682 goto err_port_line; 1678 1683 } 1684 + 1685 + up->wakeirq = wakeirq; 1686 + if (!up->wakeirq) 1687 + dev_info(up->port.dev, "no wakeirq for uart%d\n", 1688 + up->port.line); 1679 1689 1680 1690 ret = serial_omap_probe_rs485(up, pdev->dev.of_node); 1681 1691 if (ret < 0)
+1 -1
drivers/tty/serial/pmac_zilog.c
··· 1846 1846 1847 1847 #ifdef CONFIG_PPC_PMAC 1848 1848 1849 - static struct of_device_id pmz_match[] = 1849 + static const struct of_device_id pmz_match[] = 1850 1850 { 1851 1851 { 1852 1852 .name = "ch-a",
+1 -1
drivers/tty/serial/pxa.c
··· 824 824 }; 825 825 #endif 826 826 827 - static struct of_device_id serial_pxa_dt_ids[] = { 827 + static const struct of_device_id serial_pxa_dt_ids[] = { 828 828 { .compatible = "mrvl,pxa-uart", }, 829 829 { .compatible = "mrvl,mmp-uart", }, 830 830 {}
+34 -12
drivers/tty/serial/sc16is7xx.c
··· 829 829 } 830 830 831 831 static int sc16is7xx_config_rs485(struct uart_port *port, 832 - struct serial_rs485 *rs485) 832 + struct serial_rs485 *rs485) 833 833 { 834 - if (port->rs485.flags & SER_RS485_ENABLED) 835 - sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, 836 - SC16IS7XX_EFCR_AUTO_RS485_BIT, 837 - SC16IS7XX_EFCR_AUTO_RS485_BIT); 838 - else 839 - sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, 840 - SC16IS7XX_EFCR_AUTO_RS485_BIT, 841 - 0); 834 + const u32 mask = SC16IS7XX_EFCR_AUTO_RS485_BIT | 835 + SC16IS7XX_EFCR_RTS_INVERT_BIT; 836 + u32 efcr = 0; 837 + 838 + if (rs485->flags & SER_RS485_ENABLED) { 839 + bool rts_during_rx, rts_during_tx; 840 + 841 + rts_during_rx = rs485->flags & SER_RS485_RTS_AFTER_SEND; 842 + rts_during_tx = rs485->flags & SER_RS485_RTS_ON_SEND; 843 + 844 + efcr |= SC16IS7XX_EFCR_AUTO_RS485_BIT; 845 + 846 + if (!rts_during_rx && rts_during_tx) 847 + /* default */; 848 + else if (rts_during_rx && !rts_during_tx) 849 + efcr |= SC16IS7XX_EFCR_RTS_INVERT_BIT; 850 + else 851 + dev_err(port->dev, 852 + "unsupported RTS signalling on_send:%d after_send:%d - exactly one of RS485 RTS flags should be set\n", 853 + rts_during_tx, rts_during_rx); 854 + } 855 + 856 + sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, mask, efcr); 857 + 842 858 port->rs485 = *rs485; 843 859 844 860 return 0; ··· 919 903 /* Disable all interrupts */ 920 904 sc16is7xx_port_write(port, SC16IS7XX_IER_REG, 0); 921 905 /* Disable TX/RX */ 922 - sc16is7xx_port_write(port, SC16IS7XX_EFCR_REG, 923 - SC16IS7XX_EFCR_RXDISABLE_BIT | 924 - SC16IS7XX_EFCR_TXDISABLE_BIT); 906 + sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, 907 + SC16IS7XX_EFCR_RXDISABLE_BIT | 908 + SC16IS7XX_EFCR_TXDISABLE_BIT, 909 + SC16IS7XX_EFCR_RXDISABLE_BIT | 910 + SC16IS7XX_EFCR_TXDISABLE_BIT); 925 911 926 912 sc16is7xx_power(port, 0); 927 913 } ··· 1066 1048 else 1067 1049 return PTR_ERR(s->clk); 1068 1050 } else { 1051 + clk_prepare_enable(s->clk); 1069 1052 freq = clk_get_rate(s->clk); 1070 1053 } 1071 1054 ··· 1138 1119 IRQF_ONESHOT | flags, dev_name(dev), s); 1139 1120 if (!ret) 1140 1121 return 0; 1122 + 1123 + for (i = 0; i < s->uart.nr; i++) 1124 + uart_remove_one_port(&s->uart, &s->p[i].port); 1141 1125 1142 1126 mutex_destroy(&s->mutex); 1143 1127
+1 -1
drivers/tty/serial/serial-tegra.c
··· 1251 1251 .support_clk_src_div = true, 1252 1252 }; 1253 1253 1254 - static struct of_device_id tegra_uart_of_match[] = { 1254 + static const struct of_device_id tegra_uart_of_match[] = { 1255 1255 { 1256 1256 .compatible = "nvidia,tegra30-hsuart", 1257 1257 .data = &tegra30_uart_chip_data,
+49 -3
drivers/tty/serial/serial_core.c
··· 1118 1118 1119 1119 cprev = cnow; 1120 1120 } 1121 - 1122 - current->state = TASK_RUNNING; 1121 + __set_current_state(TASK_RUNNING); 1123 1122 remove_wait_queue(&port->delta_msr_wait, &wait); 1124 1123 1125 1124 return ret; ··· 1765 1766 #endif 1766 1767 1767 1768 #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL) 1768 - /* 1769 + /** 1769 1770 * uart_console_write - write a console message to a serial port 1770 1771 * @port: the port to write the message 1771 1772 * @s: array of characters ··· 1807 1808 1808 1809 return ports + idx; 1809 1810 } 1811 + 1812 + /** 1813 + * uart_parse_earlycon - Parse earlycon options 1814 + * @p: ptr to 2nd field (ie., just beyond '<name>,') 1815 + * @iotype: ptr for decoded iotype (out) 1816 + * @addr: ptr for decoded mapbase/iobase (out) 1817 + * @options: ptr for <options> field; NULL if not present (out) 1818 + * 1819 + * Decodes earlycon kernel command line parameters of the form 1820 + * earlycon=<name>,io|mmio|mmio32,<addr>,<options> 1821 + * console=<name>,io|mmio|mmio32,<addr>,<options> 1822 + * 1823 + * The optional form 1824 + * earlycon=<name>,0x<addr>,<options> 1825 + * console=<name>,0x<addr>,<options> 1826 + * is also accepted; the returned @iotype will be UPIO_MEM. 1827 + * 1828 + * Returns 0 on success or -EINVAL on failure 1829 + */ 1830 + int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr, 1831 + char **options) 1832 + { 1833 + if (strncmp(p, "mmio,", 5) == 0) { 1834 + *iotype = UPIO_MEM; 1835 + p += 5; 1836 + } else if (strncmp(p, "mmio32,", 7) == 0) { 1837 + *iotype = UPIO_MEM32; 1838 + p += 7; 1839 + } else if (strncmp(p, "io,", 3) == 0) { 1840 + *iotype = UPIO_PORT; 1841 + p += 3; 1842 + } else if (strncmp(p, "0x", 2) == 0) { 1843 + *iotype = UPIO_MEM; 1844 + } else { 1845 + return -EINVAL; 1846 + } 1847 + 1848 + *addr = simple_strtoul(p, NULL, 0); 1849 + p = strchr(p, ','); 1850 + if (p) 1851 + p++; 1852 + 1853 + *options = p; 1854 + return 0; 1855 + } 1856 + EXPORT_SYMBOL_GPL(uart_parse_earlycon); 1810 1857 1811 1858 /** 1812 1859 * uart_parse_options - Parse serial port baud/parity/bits/flow control. ··· 2682 2637 2683 2638 state->pm_state = UART_PM_STATE_UNDEFINED; 2684 2639 uport->cons = drv->cons; 2640 + uport->minor = drv->tty_driver->minor_start + uport->line; 2685 2641 2686 2642 /* 2687 2643 * If this port is a console, then the spinlock is already
+13 -37
drivers/tty/serial/serial_mctrl_gpio.c
··· 48 48 int value_array[UART_GPIO_MAX]; 49 49 unsigned int count = 0; 50 50 51 - if (IS_ERR_OR_NULL(gpios)) 52 - return; 53 - 54 51 for (i = 0; i < UART_GPIO_MAX; i++) 55 52 if (!IS_ERR_OR_NULL(gpios->gpio[i]) && 56 53 mctrl_gpios_desc[i].dir_out) { ··· 62 65 struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios, 63 66 enum mctrl_gpio_idx gidx) 64 67 { 65 - if (!IS_ERR_OR_NULL(gpios) && !IS_ERR_OR_NULL(gpios->gpio[gidx])) 66 - return gpios->gpio[gidx]; 67 - else 68 - return NULL; 68 + return gpios->gpio[gidx]; 69 69 } 70 70 EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod); 71 71 ··· 70 76 { 71 77 enum mctrl_gpio_idx i; 72 78 73 - /* 74 - * return it unchanged if the structure is not allocated 75 - */ 76 - if (IS_ERR_OR_NULL(gpios)) 77 - return *mctrl; 78 - 79 79 for (i = 0; i < UART_GPIO_MAX; i++) { 80 - if (!IS_ERR_OR_NULL(gpios->gpio[i]) && 81 - !mctrl_gpios_desc[i].dir_out) { 80 + if (gpios->gpio[i] && !mctrl_gpios_desc[i].dir_out) { 82 81 if (gpiod_get_value(gpios->gpio[i])) 83 82 *mctrl |= mctrl_gpios_desc[i].mctrl; 84 83 else ··· 87 100 { 88 101 struct mctrl_gpios *gpios; 89 102 enum mctrl_gpio_idx i; 90 - int err; 91 103 92 104 gpios = devm_kzalloc(dev, sizeof(*gpios), GFP_KERNEL); 93 105 if (!gpios) 94 106 return ERR_PTR(-ENOMEM); 95 107 96 108 for (i = 0; i < UART_GPIO_MAX; i++) { 97 - gpios->gpio[i] = devm_gpiod_get_index(dev, 98 - mctrl_gpios_desc[i].name, 99 - idx); 100 - 101 - /* 102 - * The GPIOs are maybe not all filled, 103 - * this is not an error. 104 - */ 105 - if (IS_ERR_OR_NULL(gpios->gpio[i])) 106 - continue; 109 + enum gpiod_flags flags; 107 110 108 111 if (mctrl_gpios_desc[i].dir_out) 109 - err = gpiod_direction_output(gpios->gpio[i], 0); 112 + flags = GPIOD_OUT_LOW; 110 113 else 111 - err = gpiod_direction_input(gpios->gpio[i]); 112 - if (err) { 113 - dev_dbg(dev, "Unable to set direction for %s GPIO", 114 - mctrl_gpios_desc[i].name); 115 - devm_gpiod_put(dev, gpios->gpio[i]); 116 - gpios->gpio[i] = NULL; 117 - } 114 + flags = GPIOD_IN; 115 + 116 + gpios->gpio[i] = 117 + devm_gpiod_get_index_optional(dev, 118 + mctrl_gpios_desc[i].name, 119 + idx, flags); 120 + 121 + if (IS_ERR(gpios->gpio[i])) 122 + return ERR_CAST(gpios->gpio[i]); 118 123 } 119 124 120 125 return gpios; ··· 116 137 void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios) 117 138 { 118 139 enum mctrl_gpio_idx i; 119 - 120 - if (IS_ERR_OR_NULL(gpios)) 121 - return; 122 140 123 141 for (i = 0; i < UART_GPIO_MAX; i++) 124 142 if (!IS_ERR_OR_NULL(gpios->gpio[i]))
+67 -21
drivers/tty/serial/sh-sci.c
··· 844 844 struct tty_port *tport = &port->state->port; 845 845 struct sci_port *s = to_sci_port(port); 846 846 struct plat_sci_reg *reg; 847 - int copied = 0; 847 + int copied = 0, offset; 848 + u16 status, bit; 848 849 849 - reg = sci_getreg(port, SCLSR); 850 + switch (port->type) { 851 + case PORT_SCIF: 852 + case PORT_HSCIF: 853 + offset = SCLSR; 854 + break; 855 + case PORT_SCIFA: 856 + case PORT_SCIFB: 857 + offset = SCxSR; 858 + break; 859 + default: 860 + return 0; 861 + } 862 + 863 + reg = sci_getreg(port, offset); 850 864 if (!reg->size) 851 865 return 0; 852 866 853 - if ((serial_port_in(port, SCLSR) & (1 << s->overrun_bit))) { 854 - serial_port_out(port, SCLSR, 0); 867 + status = serial_port_in(port, offset); 868 + bit = 1 << s->overrun_bit; 869 + 870 + if (status & bit) { 871 + status &= ~bit; 872 + serial_port_out(port, offset, status); 855 873 856 874 port->icount.overrun++; 857 875 ··· 1014 996 1015 997 static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr) 1016 998 { 1017 - unsigned short ssr_status, scr_status, err_enabled; 1018 - unsigned short slr_status = 0; 999 + unsigned short ssr_status, scr_status, err_enabled, orer_status = 0; 1019 1000 struct uart_port *port = ptr; 1020 1001 struct sci_port *s = to_sci_port(port); 1021 1002 irqreturn_t ret = IRQ_NONE; 1022 1003 1023 1004 ssr_status = serial_port_in(port, SCxSR); 1024 1005 scr_status = serial_port_in(port, SCSCR); 1025 - if (port->type == PORT_SCIF || port->type == PORT_HSCIF) 1026 - slr_status = serial_port_in(port, SCLSR); 1006 + switch (port->type) { 1007 + case PORT_SCIF: 1008 + case PORT_HSCIF: 1009 + orer_status = serial_port_in(port, SCLSR); 1010 + break; 1011 + case PORT_SCIFA: 1012 + case PORT_SCIFB: 1013 + orer_status = ssr_status; 1014 + break; 1015 + } 1016 + 1027 1017 err_enabled = scr_status & port_rx_irq_mask(port); 1028 1018 1029 1019 /* Tx Interrupt */ ··· 1059 1033 ret = sci_br_interrupt(irq, ptr); 1060 1034 1061 1035 /* Overrun Interrupt */ 1062 - if (port->type == PORT_SCIF || port->type == PORT_HSCIF) { 1063 - if (slr_status & 0x01) 1064 - sci_handle_fifo_overrun(port); 1065 - } 1036 + if (orer_status & (1 << s->overrun_bit)) 1037 + sci_handle_fifo_overrun(port); 1066 1038 1067 1039 return ret; 1068 1040 } ··· 1991 1967 1992 1968 #ifdef CONFIG_SERIAL_SH_SCI_DMA 1993 1969 /* 1994 - * Calculate delay for 1.5 DMA buffers: see 1995 - * drivers/serial/serial_core.c::uart_update_timeout(). With 10 bits 1996 - * (CS8), 250Hz, 115200 baud and 64 bytes FIFO, the above function 1970 + * Calculate delay for 2 DMA buffers (4 FIFO). 1971 + * See drivers/serial/serial_core.c::uart_update_timeout(). With 10 1972 + * bits (CS8), 250Hz, 115200 baud and 64 bytes FIFO, the above function 1997 1973 * calculates 1 jiffie for the data plus 5 jiffies for the "slop(e)." 1998 - * Then below we calculate 3 jiffies (12ms) for 1.5 DMA buffers (3 FIFO 1999 - * sizes), but it has been found out experimentally, that this is not 2000 - * enough: the driver too often needlessly runs on a DMA timeout. 20ms 2001 - * as a minimum seem to work perfectly. 1974 + * Then below we calculate 5 jiffies (20ms) for 2 DMA buffers (4 FIFO 1975 + * sizes), but when performing a faster transfer, value obtained by 1976 + * this formula is may not enough. Therefore, if value is smaller than 1977 + * 20msec, this sets 20msec as timeout of DMA. 2002 1978 */ 2003 1979 if (s->chan_rx) { 2004 - s->rx_timeout = (port->timeout - HZ / 50) * s->buf_len_rx * 3 / 2005 - port->fifosize / 2; 1980 + unsigned int bits; 1981 + 1982 + /* byte size and parity */ 1983 + switch (termios->c_cflag & CSIZE) { 1984 + case CS5: 1985 + bits = 7; 1986 + break; 1987 + case CS6: 1988 + bits = 8; 1989 + break; 1990 + case CS7: 1991 + bits = 9; 1992 + break; 1993 + default: 1994 + bits = 10; 1995 + break; 1996 + } 1997 + 1998 + if (termios->c_cflag & CSTOPB) 1999 + bits++; 2000 + if (termios->c_cflag & PARENB) 2001 + bits++; 2002 + s->rx_timeout = DIV_ROUND_UP((s->buf_len_rx * 2 * bits * HZ) / 2003 + (baud / 10), 10); 2006 2004 dev_dbg(port->dev, "DMA Rx t-out %ums, tty t-out %u jiffies\n", 2007 2005 s->rx_timeout * 1000 / HZ, port->timeout); 2008 2006 if (s->rx_timeout < msecs_to_jiffies(20))
+1 -1
drivers/tty/serial/sirfsoc_uart.c
··· 1269 1269 #endif 1270 1270 }; 1271 1271 1272 - static struct of_device_id sirfsoc_uart_ids[] = { 1272 + static const struct of_device_id sirfsoc_uart_ids[] = { 1273 1273 { .compatible = "sirf,prima2-uart", .data = &sirfsoc_uart,}, 1274 1274 { .compatible = "sirf,atlas7-uart", .data = &sirfsoc_uart}, 1275 1275 { .compatible = "sirf,prima2-usp-uart", .data = &sirfsoc_usp},
+5 -1
drivers/tty/serial/sprd_serial.c
··· 493 493 return -EINVAL; 494 494 if (port->irq != ser->irq) 495 495 return -EINVAL; 496 + if (port->iotype != ser->io_type) 497 + return -EINVAL; 496 498 return 0; 497 499 } 498 500 ··· 709 707 up->dev = &pdev->dev; 710 708 up->line = index; 711 709 up->type = PORT_SPRD; 712 - up->iotype = SERIAL_IO_PORT; 710 + up->iotype = UPIO_MEM; 713 711 up->uartclk = SPRD_DEF_RATE; 714 712 up->fifosize = SPRD_FIFO_SIZE; 715 713 up->ops = &serial_sprd_ops; ··· 756 754 return ret; 757 755 } 758 756 757 + #ifdef CONFIG_PM_SLEEP 759 758 static int sprd_suspend(struct device *dev) 760 759 { 761 760 struct sprd_uart_port *sup = dev_get_drvdata(dev); ··· 774 771 775 772 return 0; 776 773 } 774 + #endif 777 775 778 776 static SIMPLE_DEV_PM_OPS(sprd_pm_ops, sprd_suspend, sprd_resume); 779 777
+1 -1
drivers/tty/serial/st-asc.c
··· 720 720 } 721 721 722 722 #ifdef CONFIG_OF 723 - static struct of_device_id asc_match[] = { 723 + static const struct of_device_id asc_match[] = { 724 724 { .compatible = "st,asc", }, 725 725 {}, 726 726 };
+1 -1
drivers/tty/serial/uartlite.c
··· 622 622 623 623 #if defined(CONFIG_OF) 624 624 /* Match table for of_platform binding */ 625 - static struct of_device_id ulite_of_match[] = { 625 + static const struct of_device_id ulite_of_match[] = { 626 626 { .compatible = "xlnx,opb-uartlite-1.00.b", }, 627 627 { .compatible = "xlnx,xps-uartlite-1.00.a", }, 628 628 {}
+1 -1
drivers/tty/serial/ucc_uart.c
··· 1473 1473 return 0; 1474 1474 } 1475 1475 1476 - static struct of_device_id ucc_uart_match[] = { 1476 + static const struct of_device_id ucc_uart_match[] = { 1477 1477 { 1478 1478 .type = "serial", 1479 1479 .compatible = "ucc_uart",
+124 -118
drivers/tty/serial/xilinx_uartps.c
··· 37 37 #define CDNS_UART_MINOR 0 /* works best with devtmpfs */ 38 38 #define CDNS_UART_NR_PORTS 2 39 39 #define CDNS_UART_FIFO_SIZE 64 /* FIFO size */ 40 - #define CDNS_UART_REGISTER_SPACE 0xFFF 41 - 42 - #define cdns_uart_readl(offset) ioread32(port->membase + offset) 43 - #define cdns_uart_writel(val, offset) iowrite32(val, port->membase + offset) 40 + #define CDNS_UART_REGISTER_SPACE 0x1000 44 41 45 42 /* Rx Trigger level */ 46 43 static int rx_trigger_level = 56; ··· 192 195 /* Read the interrupt status register to determine which 193 196 * interrupt(s) is/are active. 194 197 */ 195 - isrstatus = cdns_uart_readl(CDNS_UART_ISR_OFFSET); 198 + isrstatus = readl(port->membase + CDNS_UART_ISR_OFFSET); 196 199 197 200 /* 198 201 * There is no hardware break detection, so we interpret framing ··· 200 203 * there's another non-zero byte at the end of the sequence. 201 204 */ 202 205 if (isrstatus & CDNS_UART_IXR_FRAMING) { 203 - while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & 206 + while (!(readl(port->membase + CDNS_UART_SR_OFFSET) & 204 207 CDNS_UART_SR_RXEMPTY)) { 205 - if (!cdns_uart_readl(CDNS_UART_FIFO_OFFSET)) { 208 + if (!readl(port->membase + CDNS_UART_FIFO_OFFSET)) { 206 209 port->read_status_mask |= CDNS_UART_IXR_BRK; 207 210 isrstatus &= ~CDNS_UART_IXR_FRAMING; 208 211 } 209 212 } 210 - cdns_uart_writel(CDNS_UART_IXR_FRAMING, CDNS_UART_ISR_OFFSET); 213 + writel(CDNS_UART_IXR_FRAMING, 214 + port->membase + CDNS_UART_ISR_OFFSET); 211 215 } 212 216 213 217 /* drop byte with parity error if IGNPAR specified */ ··· 221 223 if ((isrstatus & CDNS_UART_IXR_TOUT) || 222 224 (isrstatus & CDNS_UART_IXR_RXTRIG)) { 223 225 /* Receive Timeout Interrupt */ 224 - while ((cdns_uart_readl(CDNS_UART_SR_OFFSET) & 225 - CDNS_UART_SR_RXEMPTY) != CDNS_UART_SR_RXEMPTY) { 226 - data = cdns_uart_readl(CDNS_UART_FIFO_OFFSET); 226 + while (!(readl(port->membase + CDNS_UART_SR_OFFSET) & 227 + CDNS_UART_SR_RXEMPTY)) { 228 + data = readl(port->membase + CDNS_UART_FIFO_OFFSET); 227 229 228 230 /* Non-NULL byte after BREAK is garbage (99%) */ 229 231 if (data && (port->read_status_mask & ··· 273 275 /* Dispatch an appropriate handler */ 274 276 if ((isrstatus & CDNS_UART_IXR_TXEMPTY) == CDNS_UART_IXR_TXEMPTY) { 275 277 if (uart_circ_empty(&port->state->xmit)) { 276 - cdns_uart_writel(CDNS_UART_IXR_TXEMPTY, 277 - CDNS_UART_IDR_OFFSET); 278 + writel(CDNS_UART_IXR_TXEMPTY, 279 + port->membase + CDNS_UART_IDR_OFFSET); 278 280 } else { 279 281 numbytes = port->fifosize; 280 282 /* Break if no more data available in the UART buffer */ ··· 285 287 * and write it to the cdns_uart's TX_FIFO 286 288 * register. 287 289 */ 288 - cdns_uart_writel( 289 - port->state->xmit.buf[port->state->xmit. 290 - tail], CDNS_UART_FIFO_OFFSET); 290 + writel(port->state->xmit.buf[ 291 + port->state->xmit.tail], 292 + port->membase + CDNS_UART_FIFO_OFFSET); 291 293 292 294 port->icount.tx++; 293 295 ··· 305 307 } 306 308 } 307 309 308 - cdns_uart_writel(isrstatus, CDNS_UART_ISR_OFFSET); 310 + writel(isrstatus, port->membase + CDNS_UART_ISR_OFFSET); 309 311 310 312 /* be sure to release the lock and tty before leaving */ 311 313 spin_unlock_irqrestore(&port->lock, flags); ··· 395 397 &div8); 396 398 397 399 /* Write new divisors to hardware */ 398 - mreg = cdns_uart_readl(CDNS_UART_MR_OFFSET); 400 + mreg = readl(port->membase + CDNS_UART_MR_OFFSET); 399 401 if (div8) 400 402 mreg |= CDNS_UART_MR_CLKSEL; 401 403 else 402 404 mreg &= ~CDNS_UART_MR_CLKSEL; 403 - cdns_uart_writel(mreg, CDNS_UART_MR_OFFSET); 404 - cdns_uart_writel(cd, CDNS_UART_BAUDGEN_OFFSET); 405 - cdns_uart_writel(bdiv, CDNS_UART_BAUDDIV_OFFSET); 405 + writel(mreg, port->membase + CDNS_UART_MR_OFFSET); 406 + writel(cd, port->membase + CDNS_UART_BAUDGEN_OFFSET); 407 + writel(bdiv, port->membase + CDNS_UART_BAUDDIV_OFFSET); 406 408 cdns_uart->baud = baud; 407 409 408 410 return calc_baud; ··· 449 451 spin_lock_irqsave(&cdns_uart->port->lock, flags); 450 452 451 453 /* Disable the TX and RX to set baud rate */ 452 - ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); 454 + ctrl_reg = readl(port->membase + CDNS_UART_CR_OFFSET); 453 455 ctrl_reg |= CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS; 454 - cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); 456 + writel(ctrl_reg, port->membase + CDNS_UART_CR_OFFSET); 455 457 456 458 spin_unlock_irqrestore(&cdns_uart->port->lock, flags); 457 459 ··· 476 478 spin_lock_irqsave(&cdns_uart->port->lock, flags); 477 479 478 480 /* Set TX/RX Reset */ 479 - ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); 481 + ctrl_reg = readl(port->membase + CDNS_UART_CR_OFFSET); 480 482 ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST; 481 - cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); 483 + writel(ctrl_reg, port->membase + CDNS_UART_CR_OFFSET); 482 484 483 - while (cdns_uart_readl(CDNS_UART_CR_OFFSET) & 485 + while (readl(port->membase + CDNS_UART_CR_OFFSET) & 484 486 (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST)) 485 487 cpu_relax(); 486 488 ··· 489 491 * enable bit and RX enable bit to enable the transmitter and 490 492 * receiver. 491 493 */ 492 - cdns_uart_writel(rx_timeout, CDNS_UART_RXTOUT_OFFSET); 493 - ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); 494 + writel(rx_timeout, port->membase + CDNS_UART_RXTOUT_OFFSET); 495 + ctrl_reg = readl(port->membase + CDNS_UART_CR_OFFSET); 494 496 ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS); 495 497 ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN; 496 - cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); 498 + writel(ctrl_reg, port->membase + CDNS_UART_CR_OFFSET); 497 499 498 500 spin_unlock_irqrestore(&cdns_uart->port->lock, flags); 499 501 ··· 515 517 if (uart_circ_empty(&port->state->xmit) || uart_tx_stopped(port)) 516 518 return; 517 519 518 - status = cdns_uart_readl(CDNS_UART_CR_OFFSET); 520 + status = readl(port->membase + CDNS_UART_CR_OFFSET); 519 521 /* Set the TX enable bit and clear the TX disable bit to enable the 520 522 * transmitter. 521 523 */ 522 - cdns_uart_writel((status & ~CDNS_UART_CR_TX_DIS) | CDNS_UART_CR_TX_EN, 523 - CDNS_UART_CR_OFFSET); 524 + writel((status & ~CDNS_UART_CR_TX_DIS) | CDNS_UART_CR_TX_EN, 525 + port->membase + CDNS_UART_CR_OFFSET); 524 526 525 - while (numbytes-- && ((cdns_uart_readl(CDNS_UART_SR_OFFSET) & 527 + while (numbytes-- && ((readl(port->membase + CDNS_UART_SR_OFFSET) & 526 528 CDNS_UART_SR_TXFULL)) != CDNS_UART_SR_TXFULL) { 527 529 /* Break if no more data available in the UART buffer */ 528 530 if (uart_circ_empty(&port->state->xmit)) ··· 531 533 /* Get the data from the UART circular buffer and 532 534 * write it to the cdns_uart's TX_FIFO register. 533 535 */ 534 - cdns_uart_writel( 535 - port->state->xmit.buf[port->state->xmit.tail], 536 - CDNS_UART_FIFO_OFFSET); 536 + writel(port->state->xmit.buf[port->state->xmit.tail], 537 + port->membase + CDNS_UART_FIFO_OFFSET); 537 538 port->icount.tx++; 538 539 539 540 /* Adjust the tail of the UART buffer and wrap ··· 541 544 port->state->xmit.tail = (port->state->xmit.tail + 1) & 542 545 (UART_XMIT_SIZE - 1); 543 546 } 544 - cdns_uart_writel(CDNS_UART_IXR_TXEMPTY, CDNS_UART_ISR_OFFSET); 547 + writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_ISR_OFFSET); 545 548 /* Enable the TX Empty interrupt */ 546 - cdns_uart_writel(CDNS_UART_IXR_TXEMPTY, CDNS_UART_IER_OFFSET); 549 + writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_IER_OFFSET); 547 550 548 551 if (uart_circ_chars_pending(&port->state->xmit) < WAKEUP_CHARS) 549 552 uart_write_wakeup(port); ··· 557 560 { 558 561 unsigned int regval; 559 562 560 - regval = cdns_uart_readl(CDNS_UART_CR_OFFSET); 563 + regval = readl(port->membase + CDNS_UART_CR_OFFSET); 561 564 regval |= CDNS_UART_CR_TX_DIS; 562 565 /* Disable the transmitter */ 563 - cdns_uart_writel(regval, CDNS_UART_CR_OFFSET); 566 + writel(regval, port->membase + CDNS_UART_CR_OFFSET); 564 567 } 565 568 566 569 /** ··· 571 574 { 572 575 unsigned int regval; 573 576 574 - regval = cdns_uart_readl(CDNS_UART_CR_OFFSET); 577 + regval = readl(port->membase + CDNS_UART_CR_OFFSET); 575 578 regval |= CDNS_UART_CR_RX_DIS; 576 579 /* Disable the receiver */ 577 - cdns_uart_writel(regval, CDNS_UART_CR_OFFSET); 580 + writel(regval, port->membase + CDNS_UART_CR_OFFSET); 578 581 } 579 582 580 583 /** ··· 587 590 { 588 591 unsigned int status; 589 592 590 - status = cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_TXEMPTY; 593 + status = readl(port->membase + CDNS_UART_SR_OFFSET) & 594 + CDNS_UART_SR_TXEMPTY; 591 595 return status ? TIOCSER_TEMT : 0; 592 596 } 593 597 ··· 605 607 606 608 spin_lock_irqsave(&port->lock, flags); 607 609 608 - status = cdns_uart_readl(CDNS_UART_CR_OFFSET); 610 + status = readl(port->membase + CDNS_UART_CR_OFFSET); 609 611 610 612 if (ctl == -1) 611 - cdns_uart_writel(CDNS_UART_CR_STARTBRK | status, 612 - CDNS_UART_CR_OFFSET); 613 + writel(CDNS_UART_CR_STARTBRK | status, 614 + port->membase + CDNS_UART_CR_OFFSET); 613 615 else { 614 616 if ((status & CDNS_UART_CR_STOPBRK) == 0) 615 - cdns_uart_writel(CDNS_UART_CR_STOPBRK | status, 616 - CDNS_UART_CR_OFFSET); 617 + writel(CDNS_UART_CR_STOPBRK | status, 618 + port->membase + CDNS_UART_CR_OFFSET); 617 619 } 618 620 spin_unlock_irqrestore(&port->lock, flags); 619 621 } ··· 636 638 spin_lock_irqsave(&port->lock, flags); 637 639 638 640 /* Wait for the transmit FIFO to empty before making changes */ 639 - if (!(cdns_uart_readl(CDNS_UART_CR_OFFSET) & CDNS_UART_CR_TX_DIS)) { 640 - while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & 641 + if (!(readl(port->membase + CDNS_UART_CR_OFFSET) & 642 + CDNS_UART_CR_TX_DIS)) { 643 + while (!(readl(port->membase + CDNS_UART_SR_OFFSET) & 641 644 CDNS_UART_SR_TXEMPTY)) { 642 645 cpu_relax(); 643 646 } 644 647 } 645 648 646 649 /* Disable the TX and RX to set baud rate */ 647 - ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); 650 + ctrl_reg = readl(port->membase + CDNS_UART_CR_OFFSET); 648 651 ctrl_reg |= CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS; 649 - cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); 652 + writel(ctrl_reg, port->membase + CDNS_UART_CR_OFFSET); 650 653 651 654 /* 652 655 * Min baud rate = 6bps and Max Baud Rate is 10Mbps for 100Mhz clk ··· 666 667 uart_update_timeout(port, termios->c_cflag, baud); 667 668 668 669 /* Set TX/RX Reset */ 669 - ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); 670 + ctrl_reg = readl(port->membase + CDNS_UART_CR_OFFSET); 670 671 ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST; 671 - cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); 672 + writel(ctrl_reg, port->membase + CDNS_UART_CR_OFFSET); 672 673 673 674 /* 674 675 * Clear the RX disable and TX disable bits and then set the TX enable 675 676 * bit and RX enable bit to enable the transmitter and receiver. 676 677 */ 677 - ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); 678 + ctrl_reg = readl(port->membase + CDNS_UART_CR_OFFSET); 678 679 ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS); 679 680 ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN; 680 - cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); 681 + writel(ctrl_reg, port->membase + CDNS_UART_CR_OFFSET); 681 682 682 - cdns_uart_writel(rx_timeout, CDNS_UART_RXTOUT_OFFSET); 683 + writel(rx_timeout, port->membase + CDNS_UART_RXTOUT_OFFSET); 683 684 684 685 port->read_status_mask = CDNS_UART_IXR_TXEMPTY | CDNS_UART_IXR_RXTRIG | 685 686 CDNS_UART_IXR_OVERRUN | CDNS_UART_IXR_TOUT; ··· 699 700 CDNS_UART_IXR_TOUT | CDNS_UART_IXR_PARITY | 700 701 CDNS_UART_IXR_FRAMING | CDNS_UART_IXR_OVERRUN; 701 702 702 - mode_reg = cdns_uart_readl(CDNS_UART_MR_OFFSET); 703 + mode_reg = readl(port->membase + CDNS_UART_MR_OFFSET); 703 704 704 705 /* Handling Data Size */ 705 706 switch (termios->c_cflag & CSIZE) { ··· 740 741 cval |= CDNS_UART_MR_PARITY_NONE; 741 742 } 742 743 cval |= mode_reg & 1; 743 - cdns_uart_writel(cval, CDNS_UART_MR_OFFSET); 744 + writel(cval, port->membase + CDNS_UART_MR_OFFSET); 744 745 745 746 spin_unlock_irqrestore(&port->lock, flags); 746 747 } ··· 761 762 return retval; 762 763 763 764 /* Disable the TX and RX */ 764 - cdns_uart_writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS, 765 - CDNS_UART_CR_OFFSET); 765 + writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS, 766 + port->membase + CDNS_UART_CR_OFFSET); 766 767 767 768 /* Set the Control Register with TX/RX Enable, TX/RX Reset, 768 769 * no break chars. 769 770 */ 770 - cdns_uart_writel(CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST, 771 - CDNS_UART_CR_OFFSET); 771 + writel(CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST, 772 + port->membase + CDNS_UART_CR_OFFSET); 772 773 773 - status = cdns_uart_readl(CDNS_UART_CR_OFFSET); 774 + status = readl(port->membase + CDNS_UART_CR_OFFSET); 774 775 775 776 /* Clear the RX disable and TX disable bits and then set the TX enable 776 777 * bit and RX enable bit to enable the transmitter and receiver. 777 778 */ 778 - cdns_uart_writel((status & ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS)) 779 + writel((status & ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS)) 779 780 | (CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN | 780 - CDNS_UART_CR_STOPBRK), CDNS_UART_CR_OFFSET); 781 + CDNS_UART_CR_STOPBRK), 782 + port->membase + CDNS_UART_CR_OFFSET); 781 783 782 784 /* Set the Mode Register with normal mode,8 data bits,1 stop bit, 783 785 * no parity. 784 786 */ 785 - cdns_uart_writel(CDNS_UART_MR_CHMODE_NORM | CDNS_UART_MR_STOPMODE_1_BIT 787 + writel(CDNS_UART_MR_CHMODE_NORM | CDNS_UART_MR_STOPMODE_1_BIT 786 788 | CDNS_UART_MR_PARITY_NONE | CDNS_UART_MR_CHARLEN_8_BIT, 787 - CDNS_UART_MR_OFFSET); 789 + port->membase + CDNS_UART_MR_OFFSET); 788 790 789 791 /* 790 792 * Set the RX FIFO Trigger level to use most of the FIFO, but it 791 793 * can be tuned with a module parameter 792 794 */ 793 - cdns_uart_writel(rx_trigger_level, CDNS_UART_RXWM_OFFSET); 795 + writel(rx_trigger_level, port->membase + CDNS_UART_RXWM_OFFSET); 794 796 795 797 /* 796 798 * Receive Timeout register is enabled but it 797 799 * can be tuned with a module parameter 798 800 */ 799 - cdns_uart_writel(rx_timeout, CDNS_UART_RXTOUT_OFFSET); 801 + writel(rx_timeout, port->membase + CDNS_UART_RXTOUT_OFFSET); 800 802 801 803 /* Clear out any pending interrupts before enabling them */ 802 - cdns_uart_writel(cdns_uart_readl(CDNS_UART_ISR_OFFSET), 803 - CDNS_UART_ISR_OFFSET); 804 + writel(readl(port->membase + CDNS_UART_ISR_OFFSET), 805 + port->membase + CDNS_UART_ISR_OFFSET); 804 806 805 807 /* Set the Interrupt Registers with desired interrupts */ 806 - cdns_uart_writel(CDNS_UART_IXR_TXEMPTY | CDNS_UART_IXR_PARITY | 808 + writel(CDNS_UART_IXR_TXEMPTY | CDNS_UART_IXR_PARITY | 807 809 CDNS_UART_IXR_FRAMING | CDNS_UART_IXR_OVERRUN | 808 810 CDNS_UART_IXR_RXTRIG | CDNS_UART_IXR_TOUT, 809 - CDNS_UART_IER_OFFSET); 811 + port->membase + CDNS_UART_IER_OFFSET); 810 812 811 813 return retval; 812 814 } ··· 821 821 int status; 822 822 823 823 /* Disable interrupts */ 824 - status = cdns_uart_readl(CDNS_UART_IMR_OFFSET); 825 - cdns_uart_writel(status, CDNS_UART_IDR_OFFSET); 824 + status = readl(port->membase + CDNS_UART_IMR_OFFSET); 825 + writel(status, port->membase + CDNS_UART_IDR_OFFSET); 826 826 827 827 /* Disable the TX and RX */ 828 - cdns_uart_writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS, 829 - CDNS_UART_CR_OFFSET); 828 + writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS, 829 + port->membase + CDNS_UART_CR_OFFSET); 830 830 free_irq(port->irq, port); 831 831 } 832 832 ··· 928 928 { 929 929 u32 val; 930 930 931 - val = cdns_uart_readl(CDNS_UART_MODEMCR_OFFSET); 931 + val = readl(port->membase + CDNS_UART_MODEMCR_OFFSET); 932 932 933 933 val &= ~(CDNS_UART_MODEMCR_RTS | CDNS_UART_MODEMCR_DTR); 934 934 ··· 937 937 if (mctrl & TIOCM_DTR) 938 938 val |= CDNS_UART_MODEMCR_DTR; 939 939 940 - cdns_uart_writel(val, CDNS_UART_MODEMCR_OFFSET); 940 + writel(val, port->membase + CDNS_UART_MODEMCR_OFFSET); 941 941 } 942 942 943 943 #ifdef CONFIG_CONSOLE_POLL ··· 947 947 int c; 948 948 949 949 /* Disable all interrupts */ 950 - imr = cdns_uart_readl(CDNS_UART_IMR_OFFSET); 951 - cdns_uart_writel(imr, CDNS_UART_IDR_OFFSET); 950 + imr = readl(port->membase + CDNS_UART_IMR_OFFSET); 951 + writel(imr, port->membase + CDNS_UART_IDR_OFFSET); 952 952 953 953 /* Check if FIFO is empty */ 954 - if (cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_RXEMPTY) 954 + if (readl(port->membase + CDNS_UART_SR_OFFSET) & CDNS_UART_SR_RXEMPTY) 955 955 c = NO_POLL_CHAR; 956 956 else /* Read a character */ 957 - c = (unsigned char) cdns_uart_readl(CDNS_UART_FIFO_OFFSET); 957 + c = (unsigned char) readl( 958 + port->membase + CDNS_UART_FIFO_OFFSET); 958 959 959 960 /* Enable interrupts */ 960 - cdns_uart_writel(imr, CDNS_UART_IER_OFFSET); 961 + writel(imr, port->membase + CDNS_UART_IER_OFFSET); 961 962 962 963 return c; 963 964 } ··· 968 967 u32 imr; 969 968 970 969 /* Disable all interrupts */ 971 - imr = cdns_uart_readl(CDNS_UART_IMR_OFFSET); 972 - cdns_uart_writel(imr, CDNS_UART_IDR_OFFSET); 970 + imr = readl(port->membase + CDNS_UART_IMR_OFFSET); 971 + writel(imr, port->membase + CDNS_UART_IDR_OFFSET); 973 972 974 973 /* Wait until FIFO is empty */ 975 - while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_TXEMPTY)) 974 + while (!(readl(port->membase + CDNS_UART_SR_OFFSET) & 975 + CDNS_UART_SR_TXEMPTY)) 976 976 cpu_relax(); 977 977 978 978 /* Write a character */ 979 - cdns_uart_writel(c, CDNS_UART_FIFO_OFFSET); 979 + writel(c, port->membase + CDNS_UART_FIFO_OFFSET); 980 980 981 981 /* Wait until FIFO is empty */ 982 - while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_TXEMPTY)) 982 + while (!(readl(port->membase + CDNS_UART_SR_OFFSET) & 983 + CDNS_UART_SR_TXEMPTY)) 983 984 cpu_relax(); 984 985 985 986 /* Enable interrupts */ 986 - cdns_uart_writel(imr, CDNS_UART_IER_OFFSET); 987 + writel(imr, port->membase + CDNS_UART_IER_OFFSET); 987 988 988 989 return; 989 990 } ··· 1013 1010 #endif 1014 1011 }; 1015 1012 1016 - static struct uart_port cdns_uart_port[2]; 1013 + static struct uart_port cdns_uart_port[CDNS_UART_NR_PORTS]; 1017 1014 1018 1015 /** 1019 1016 * cdns_uart_get_port - Configure the port from platform device resource info ··· 1041 1038 /* At this point, we've got an empty uart_port struct, initialize it */ 1042 1039 spin_lock_init(&port->lock); 1043 1040 port->membase = NULL; 1044 - port->iobase = 1; /* mark port in use */ 1045 1041 port->irq = 0; 1046 1042 port->type = PORT_UNKNOWN; 1047 1043 port->iotype = UPIO_MEM32; ··· 1059 1057 */ 1060 1058 static void cdns_uart_console_wait_tx(struct uart_port *port) 1061 1059 { 1062 - while ((cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_TXEMPTY) 1063 - != CDNS_UART_SR_TXEMPTY) 1060 + while (!(readl(port->membase + CDNS_UART_SR_OFFSET) & 1061 + CDNS_UART_SR_TXEMPTY)) 1064 1062 barrier(); 1065 1063 } 1066 1064 ··· 1072 1070 static void cdns_uart_console_putchar(struct uart_port *port, int ch) 1073 1071 { 1074 1072 cdns_uart_console_wait_tx(port); 1075 - cdns_uart_writel(ch, CDNS_UART_FIFO_OFFSET); 1073 + writel(ch, port->membase + CDNS_UART_FIFO_OFFSET); 1076 1074 } 1077 1075 1078 1076 static void cdns_early_write(struct console *con, const char *s, unsigned n) ··· 1114 1112 spin_lock_irqsave(&port->lock, flags); 1115 1113 1116 1114 /* save and disable interrupt */ 1117 - imr = cdns_uart_readl(CDNS_UART_IMR_OFFSET); 1118 - cdns_uart_writel(imr, CDNS_UART_IDR_OFFSET); 1115 + imr = readl(port->membase + CDNS_UART_IMR_OFFSET); 1116 + writel(imr, port->membase + CDNS_UART_IDR_OFFSET); 1119 1117 1120 1118 /* 1121 1119 * Make sure that the tx part is enabled. Set the TX enable bit and 1122 1120 * clear the TX disable bit to enable the transmitter. 1123 1121 */ 1124 - ctrl = cdns_uart_readl(CDNS_UART_CR_OFFSET); 1125 - cdns_uart_writel((ctrl & ~CDNS_UART_CR_TX_DIS) | CDNS_UART_CR_TX_EN, 1126 - CDNS_UART_CR_OFFSET); 1122 + ctrl = readl(port->membase + CDNS_UART_CR_OFFSET); 1123 + writel((ctrl & ~CDNS_UART_CR_TX_DIS) | CDNS_UART_CR_TX_EN, 1124 + port->membase + CDNS_UART_CR_OFFSET); 1127 1125 1128 1126 uart_console_write(port, s, count, cdns_uart_console_putchar); 1129 1127 cdns_uart_console_wait_tx(port); 1130 1128 1131 - cdns_uart_writel(ctrl, CDNS_UART_CR_OFFSET); 1129 + writel(ctrl, port->membase + CDNS_UART_CR_OFFSET); 1132 1130 1133 1131 /* restore interrupt state */ 1134 - cdns_uart_writel(imr, CDNS_UART_IER_OFFSET); 1132 + writel(imr, port->membase + CDNS_UART_IER_OFFSET); 1135 1133 1136 1134 if (locked) 1137 1135 spin_unlock_irqrestore(&port->lock, flags); ··· 1155 1153 if (co->index < 0 || co->index >= CDNS_UART_NR_PORTS) 1156 1154 return -EINVAL; 1157 1155 1158 - if (!port->mapbase) { 1159 - pr_debug("console on ttyPS%i not present\n", co->index); 1156 + if (!port->membase) { 1157 + pr_debug("console on " CDNS_UART_TTY_NAME "%i not present\n", 1158 + co->index); 1160 1159 return -ENODEV; 1161 1160 } 1162 1161 ··· 1243 1240 1244 1241 spin_lock_irqsave(&port->lock, flags); 1245 1242 /* Empty the receive FIFO 1st before making changes */ 1246 - while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & 1243 + while (!(readl(port->membase + CDNS_UART_SR_OFFSET) & 1247 1244 CDNS_UART_SR_RXEMPTY)) 1248 - cdns_uart_readl(CDNS_UART_FIFO_OFFSET); 1245 + readl(port->membase + CDNS_UART_FIFO_OFFSET); 1249 1246 /* set RX trigger level to 1 */ 1250 - cdns_uart_writel(1, CDNS_UART_RXWM_OFFSET); 1247 + writel(1, port->membase + CDNS_UART_RXWM_OFFSET); 1251 1248 /* disable RX timeout interrups */ 1252 - cdns_uart_writel(CDNS_UART_IXR_TOUT, CDNS_UART_IDR_OFFSET); 1249 + writel(CDNS_UART_IXR_TOUT, 1250 + port->membase + CDNS_UART_IDR_OFFSET); 1253 1251 spin_unlock_irqrestore(&port->lock, flags); 1254 1252 } 1255 1253 ··· 1289 1285 spin_lock_irqsave(&port->lock, flags); 1290 1286 1291 1287 /* Set TX/RX Reset */ 1292 - ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); 1288 + ctrl_reg = readl(port->membase + CDNS_UART_CR_OFFSET); 1293 1289 ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST; 1294 - cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); 1295 - while (cdns_uart_readl(CDNS_UART_CR_OFFSET) & 1290 + writel(ctrl_reg, port->membase + CDNS_UART_CR_OFFSET); 1291 + while (readl(port->membase + CDNS_UART_CR_OFFSET) & 1296 1292 (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST)) 1297 1293 cpu_relax(); 1298 1294 1299 1295 /* restore rx timeout value */ 1300 - cdns_uart_writel(rx_timeout, CDNS_UART_RXTOUT_OFFSET); 1296 + writel(rx_timeout, port->membase + CDNS_UART_RXTOUT_OFFSET); 1301 1297 /* Enable Tx/Rx */ 1302 - ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); 1298 + ctrl_reg = readl(port->membase + CDNS_UART_CR_OFFSET); 1303 1299 ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS); 1304 1300 ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN; 1305 - cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); 1301 + writel(ctrl_reg, port->membase + CDNS_UART_CR_OFFSET); 1306 1302 1307 1303 spin_unlock_irqrestore(&port->lock, flags); 1308 1304 } else { 1309 1305 spin_lock_irqsave(&port->lock, flags); 1310 1306 /* restore original rx trigger level */ 1311 - cdns_uart_writel(rx_trigger_level, CDNS_UART_RXWM_OFFSET); 1307 + writel(rx_trigger_level, 1308 + port->membase + CDNS_UART_RXWM_OFFSET); 1312 1309 /* enable RX timeout interrupt */ 1313 - cdns_uart_writel(CDNS_UART_IXR_TOUT, CDNS_UART_IER_OFFSET); 1310 + writel(CDNS_UART_IXR_TOUT, 1311 + port->membase + CDNS_UART_IER_OFFSET); 1314 1312 spin_unlock_irqrestore(&port->lock, flags); 1315 1313 } 1316 1314 ··· 1464 1458 } 1465 1459 1466 1460 /* Match table for of_platform binding */ 1467 - static struct of_device_id cdns_uart_of_match[] = { 1461 + static const struct of_device_id cdns_uart_of_match[] = { 1468 1462 { .compatible = "xlnx,xuartps", }, 1469 1463 { .compatible = "cdns,uart-r1p8", }, 1470 1464 {}
+18 -6
drivers/tty/tty_io.c
··· 1025 1025 } 1026 1026 EXPORT_SYMBOL(start_tty); 1027 1027 1028 - /* We limit tty time update visibility to every 8 seconds or so. */ 1029 1028 static void tty_update_time(struct timespec *time) 1030 1029 { 1031 1030 unsigned long sec = get_seconds(); 1032 - if (abs(sec - time->tv_sec) & ~7) 1031 + 1032 + /* 1033 + * We only care if the two values differ in anything other than the 1034 + * lower three bits (i.e every 8 seconds). If so, then we can update 1035 + * the time of the tty device, otherwise it could be construded as a 1036 + * security leak to let userspace know the exact timing of the tty. 1037 + */ 1038 + if ((sec ^ time->tv_sec) & ~7) 1033 1039 time->tv_sec = sec; 1034 1040 } 1035 1041 ··· 3599 3593 } 3600 3594 static DEVICE_ATTR(active, S_IRUGO, show_cons_active, NULL); 3601 3595 3596 + static struct attribute *cons_dev_attrs[] = { 3597 + &dev_attr_active.attr, 3598 + NULL 3599 + }; 3600 + 3601 + ATTRIBUTE_GROUPS(cons_dev); 3602 + 3602 3603 static struct device *consdev; 3603 3604 3604 3605 void console_sysfs_notify(void) ··· 3630 3617 if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) || 3631 3618 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0) 3632 3619 panic("Couldn't register /dev/console driver\n"); 3633 - consdev = device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL, 3634 - "console"); 3620 + consdev = device_create_with_groups(tty_class, NULL, 3621 + MKDEV(TTYAUX_MAJOR, 1), NULL, 3622 + cons_dev_groups, "console"); 3635 3623 if (IS_ERR(consdev)) 3636 3624 consdev = NULL; 3637 - else 3638 - WARN_ON(device_create_file(consdev, &dev_attr_active) < 0); 3639 3625 3640 3626 #ifdef CONFIG_VT 3641 3627 vty_init(&console_fops);
+33 -41
drivers/tty/vt/vt.c
··· 1237 1237 1238 1238 struct rgb { u8 r; u8 g; u8 b; }; 1239 1239 1240 - struct rgb rgb_from_256(int i) 1240 + static struct rgb rgb_from_256(int i) 1241 1241 { 1242 1242 struct rgb c; 1243 1243 if (i < 8) { /* Standard colours. */ ··· 1573 1573 case 11: /* set bell duration in msec */ 1574 1574 if (vc->vc_npar >= 1) 1575 1575 vc->vc_bell_duration = (vc->vc_par[1] < 2000) ? 1576 - vc->vc_par[1] * HZ / 1000 : 0; 1576 + msecs_to_jiffies(vc->vc_par[1]) : 0; 1577 1577 else 1578 1578 vc->vc_bell_duration = DEFAULT_BELL_DURATION; 1579 1579 break; ··· 3041 3041 } 3042 3042 static DEVICE_ATTR(active, S_IRUGO, show_tty_active, NULL); 3043 3043 3044 + static struct attribute *vt_dev_attrs[] = { 3045 + &dev_attr_active.attr, 3046 + NULL 3047 + }; 3048 + 3049 + ATTRIBUTE_GROUPS(vt_dev); 3050 + 3044 3051 int __init vty_init(const struct file_operations *console_fops) 3045 3052 { 3046 3053 cdev_init(&vc0_cdev, console_fops); 3047 3054 if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || 3048 3055 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) 3049 3056 panic("Couldn't register /dev/tty0 driver\n"); 3050 - tty0dev = device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0"); 3057 + tty0dev = device_create_with_groups(tty_class, NULL, 3058 + MKDEV(TTY_MAJOR, 0), NULL, 3059 + vt_dev_groups, "tty0"); 3051 3060 if (IS_ERR(tty0dev)) 3052 3061 tty0dev = NULL; 3053 - else 3054 - WARN_ON(device_create_file(tty0dev, &dev_attr_active) < 0); 3055 3062 3056 3063 vcs_init(); 3057 3064 ··· 3430 3423 3431 3424 } 3432 3425 3433 - static struct device_attribute device_attrs[] = { 3434 - __ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind), 3435 - __ATTR(name, S_IRUGO, show_name, NULL), 3426 + static DEVICE_ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind); 3427 + static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 3428 + 3429 + static struct attribute *con_dev_attrs[] = { 3430 + &dev_attr_bind.attr, 3431 + &dev_attr_name.attr, 3432 + NULL 3436 3433 }; 3434 + 3435 + ATTRIBUTE_GROUPS(con_dev); 3437 3436 3438 3437 static int vtconsole_init_device(struct con_driver *con) 3439 3438 { 3440 - int i; 3441 - int error = 0; 3442 - 3443 3439 con->flag |= CON_DRIVER_FLAG_ATTR; 3444 - dev_set_drvdata(con->dev, con); 3445 - for (i = 0; i < ARRAY_SIZE(device_attrs); i++) { 3446 - error = device_create_file(con->dev, &device_attrs[i]); 3447 - if (error) 3448 - break; 3449 - } 3450 - 3451 - if (error) { 3452 - while (--i >= 0) 3453 - device_remove_file(con->dev, &device_attrs[i]); 3454 - con->flag &= ~CON_DRIVER_FLAG_ATTR; 3455 - } 3456 - 3457 - return error; 3440 + return 0; 3458 3441 } 3459 3442 3460 3443 static void vtconsole_deinit_device(struct con_driver *con) 3461 3444 { 3462 - int i; 3463 - 3464 - if (con->flag & CON_DRIVER_FLAG_ATTR) { 3465 - for (i = 0; i < ARRAY_SIZE(device_attrs); i++) 3466 - device_remove_file(con->dev, &device_attrs[i]); 3467 - con->flag &= ~CON_DRIVER_FLAG_ATTR; 3468 - } 3445 + con->flag &= ~CON_DRIVER_FLAG_ATTR; 3469 3446 } 3470 3447 3471 3448 /** ··· 3612 3621 if (retval) 3613 3622 goto err; 3614 3623 3615 - con_driver->dev = device_create(vtconsole_class, NULL, 3616 - MKDEV(0, con_driver->node), 3617 - NULL, "vtcon%i", 3618 - con_driver->node); 3619 - 3624 + con_driver->dev = 3625 + device_create_with_groups(vtconsole_class, NULL, 3626 + MKDEV(0, con_driver->node), 3627 + con_driver, con_dev_groups, 3628 + "vtcon%i", con_driver->node); 3620 3629 if (IS_ERR(con_driver->dev)) { 3621 3630 printk(KERN_WARNING "Unable to create device for %s; " 3622 3631 "errno = %ld\n", con_driver->desc, ··· 3730 3739 struct con_driver *con = &registered_con_driver[i]; 3731 3740 3732 3741 if (con->con && !con->dev) { 3733 - con->dev = device_create(vtconsole_class, NULL, 3734 - MKDEV(0, con->node), 3735 - NULL, "vtcon%i", 3736 - con->node); 3742 + con->dev = 3743 + device_create_with_groups(vtconsole_class, NULL, 3744 + MKDEV(0, con->node), 3745 + con, con_dev_groups, 3746 + "vtcon%i", con->node); 3737 3747 3738 3748 if (IS_ERR(con->dev)) { 3739 3749 printk(KERN_WARNING "Unable to create "
+1 -1
drivers/tty/vt/vt_ioctl.c
··· 388 388 * Generate the tone for the appropriate number of ticks. 389 389 * If the time is zero, turn off sound ourselves. 390 390 */ 391 - ticks = HZ * ((arg >> 16) & 0xffff) / 1000; 391 + ticks = msecs_to_jiffies((arg >> 16) & 0xffff); 392 392 count = ticks ? (arg & 0xffff) : 0; 393 393 if (count) 394 394 count = PIT_TICK_RATE / count;
+9
include/asm-generic/vmlinux.lds.h
··· 153 153 #define TRACE_SYSCALLS() 154 154 #endif 155 155 156 + #ifdef CONFIG_SERIAL_EARLYCON 157 + #define EARLYCON_TABLE() STRUCT_ALIGN(); \ 158 + VMLINUX_SYMBOL(__earlycon_table) = .; \ 159 + *(__earlycon_table) \ 160 + *(__earlycon_table_end) 161 + #else 162 + #define EARLYCON_TABLE() 163 + #endif 156 164 157 165 #define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name) 158 166 #define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name) ··· 516 508 CPUIDLE_METHOD_OF_TABLES() \ 517 509 KERNEL_DTB() \ 518 510 IRQCHIP_OF_MATCH_TABLE() \ 511 + EARLYCON_TABLE() \ 519 512 EARLYCON_OF_TABLES() 520 513 521 514 #define INIT_TEXT \
+1 -2
include/linux/console.h
··· 123 123 struct tty_driver *(*device)(struct console *, int *); 124 124 void (*unblank)(void); 125 125 int (*setup)(struct console *, char *); 126 - int (*early_setup)(void); 126 + int (*match)(struct console *, char *name, int idx, char *options); 127 127 short flags; 128 128 short index; 129 129 int cflag; ··· 141 141 extern struct console *early_console; 142 142 143 143 extern int add_preferred_console(char *name, int idx, char *options); 144 - extern int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options); 145 144 extern void register_console(struct console *); 146 145 extern int unregister_console(struct console *); 147 146 extern struct console *console_drivers;
+48
include/linux/dma/hsu.h
··· 1 + /* 2 + * Driver for the High Speed UART DMA 3 + * 4 + * Copyright (C) 2015 Intel Corporation 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 + #ifndef _DMA_HSU_H 12 + #define _DMA_HSU_H 13 + 14 + #include <linux/device.h> 15 + #include <linux/interrupt.h> 16 + 17 + #include <linux/platform_data/dma-hsu.h> 18 + 19 + struct hsu_dma; 20 + 21 + /** 22 + * struct hsu_dma_chip - representation of HSU DMA hardware 23 + * @dev: struct device of the DMA controller 24 + * @irq: irq line 25 + * @regs: memory mapped I/O space 26 + * @length: I/O space length 27 + * @offset: offset of the I/O space where registers are located 28 + * @hsu: struct hsu_dma that is filed by ->probe() 29 + * @pdata: platform data for the DMA controller if provided 30 + */ 31 + struct hsu_dma_chip { 32 + struct device *dev; 33 + int irq; 34 + void __iomem *regs; 35 + unsigned int length; 36 + unsigned int offset; 37 + struct hsu_dma *hsu; 38 + struct hsu_dma_platform_data *pdata; 39 + }; 40 + 41 + /* Export to the internal users */ 42 + irqreturn_t hsu_dma_irq(struct hsu_dma_chip *chip, unsigned short nr); 43 + 44 + /* Export to the platform drivers */ 45 + int hsu_dma_probe(struct hsu_dma_chip *chip); 46 + int hsu_dma_remove(struct hsu_dma_chip *chip); 47 + 48 + #endif /* _DMA_HSU_H */
+25
include/linux/platform_data/dma-hsu.h
··· 1 + /* 2 + * Driver for the High Speed UART DMA 3 + * 4 + * Copyright (C) 2015 Intel Corporation 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 + #ifndef _PLATFORM_DATA_DMA_HSU_H 12 + #define _PLATFORM_DATA_DMA_HSU_H 13 + 14 + #include <linux/device.h> 15 + 16 + struct hsu_dma_slave { 17 + struct device *dma_dev; 18 + int chan_id; 19 + }; 20 + 21 + struct hsu_dma_platform_data { 22 + unsigned short nr_channels; 23 + }; 24 + 25 + #endif /* _PLATFORM_DATA_DMA_HSU_H */
-49
include/linux/platform_data/msm_serial_hs.h
··· 1 - /* 2 - * Copyright (C) 2008 Google, Inc. 3 - * Author: Nick Pelly <npelly@google.com> 4 - * 5 - * This software is licensed under the terms of the GNU General Public 6 - * License version 2, as published by the Free Software Foundation, and 7 - * may be copied, distributed, and modified under those terms. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 - * GNU General Public License for more details. 13 - */ 14 - 15 - #ifndef __ASM_ARCH_MSM_SERIAL_HS_H 16 - #define __ASM_ARCH_MSM_SERIAL_HS_H 17 - 18 - #include <linux/serial_core.h> 19 - 20 - /* API to request the uart clock off or on for low power management 21 - * Clients should call request_clock_off() when no uart data is expected, 22 - * and must call request_clock_on() before any further uart data can be 23 - * received. */ 24 - extern void msm_hs_request_clock_off(struct uart_port *uport); 25 - extern void msm_hs_request_clock_on(struct uart_port *uport); 26 - 27 - /** 28 - * struct msm_serial_hs_platform_data 29 - * @rx_wakeup_irq: Rx activity irq 30 - * @rx_to_inject: extra character to be inserted to Rx tty on wakeup 31 - * @inject_rx: 1 = insert rx_to_inject. 0 = do not insert extra character 32 - * @exit_lpm_cb: function called before every Tx transaction 33 - * 34 - * This is an optional structure required for UART Rx GPIO IRQ based 35 - * wakeup from low power state. UART wakeup can be triggered by RX activity 36 - * (using a wakeup GPIO on the UART RX pin). This should only be used if 37 - * there is not a wakeup GPIO on the UART CTS, and the first RX byte is 38 - * known (eg., with the Bluetooth Texas Instruments HCILL protocol), 39 - * since the first RX byte will always be lost. RTS will be asserted even 40 - * while the UART is clocked off in this mode of operation. 41 - */ 42 - struct msm_serial_hs_platform_data { 43 - int rx_wakeup_irq; 44 - unsigned char inject_rx_on_wakeup; 45 - char rx_to_inject; 46 - void (*exit_lpm_cb)(struct uart_port *); 47 - }; 48 - 49 - #endif
-5
include/linux/platform_data/serial-imx.h
··· 20 20 #define ASMARM_ARCH_UART_H 21 21 22 22 #define IMXUART_HAVE_RTSCTS (1<<0) 23 - #define IMXUART_IRDA (1<<1) 24 23 25 24 struct imxuart_platform_data { 26 25 unsigned int flags; 27 - void (*irda_enable)(int enable); 28 - unsigned int irda_inv_rx:1; 29 - unsigned int irda_inv_tx:1; 30 - unsigned short transceiver_delay; 31 26 }; 32 27 33 28 #endif
+17 -3
include/linux/serial_8250.h
··· 60 60 }; 61 61 62 62 struct uart_8250_dma; 63 + struct uart_8250_port; 64 + 65 + /** 66 + * 8250 core driver operations 67 + * 68 + * @setup_irq() Setup irq handling. The universal 8250 driver links this 69 + * port to the irq chain. Other drivers may @request_irq(). 70 + * @release_irq() Undo irq handling. The universal 8250 driver unlinks 71 + * the port from the irq chain. 72 + */ 73 + struct uart_8250_ops { 74 + int (*setup_irq)(struct uart_8250_port *); 75 + void (*release_irq)(struct uart_8250_port *); 76 + }; 63 77 64 78 /* 65 79 * This should be used by drivers which want to register ··· 102 88 unsigned char canary; /* non-zero during system sleep 103 89 * if no_console_suspend 104 90 */ 91 + unsigned char probe; 92 + #define UART_PROBE_RSA (1 << 0) 105 93 106 94 /* 107 95 * Some bits in registers are cleared on a read, so they must ··· 116 100 unsigned char msr_saved_flags; 117 101 118 102 struct uart_8250_dma *dma; 103 + const struct uart_8250_ops *ops; 119 104 120 105 /* 8250 specific callbacks */ 121 106 int (*dl_read)(struct uart_8250_port *); ··· 135 118 136 119 extern int early_serial_setup(struct uart_port *port); 137 120 138 - extern int serial8250_find_port(struct uart_port *p); 139 - extern int serial8250_find_port_for_earlycon(void); 140 121 extern unsigned int serial8250_early_in(struct uart_port *port, int offset); 141 122 extern void serial8250_early_out(struct uart_port *port, int offset, int value); 142 - extern int setup_early_serial8250_console(char *cmdline); 143 123 extern void serial8250_do_set_termios(struct uart_port *port, 144 124 struct ktermios *termios, struct ktermios *old); 145 125 extern int serial8250_do_startup(struct uart_port *port);
+15 -8
include/linux/serial_core.h
··· 235 235 const struct uart_ops *ops; 236 236 unsigned int custom_divisor; 237 237 unsigned int line; /* port index */ 238 + unsigned int minor; 238 239 resource_size_t mapbase; /* for ioremap */ 240 + resource_size_t mapsize; 239 241 struct device *dev; /* parent device */ 240 242 unsigned char hub6; /* this should be in the 8250 driver */ 241 243 unsigned char suspended; ··· 338 336 char options[16]; /* e.g., 115200n8 */ 339 337 unsigned int baud; 340 338 }; 341 - int setup_earlycon(char *buf, const char *match, 342 - int (*setup)(struct earlycon_device *, const char *)); 343 339 340 + struct earlycon_id { 341 + char name[16]; 342 + int (*setup)(struct earlycon_device *, const char *options); 343 + } __aligned(32); 344 + 345 + extern int setup_earlycon(char *buf); 344 346 extern int of_setup_earlycon(unsigned long addr, 345 347 int (*setup)(struct earlycon_device *, const char *)); 346 348 347 - #define EARLYCON_DECLARE(name, func) \ 348 - static int __init name ## _setup_earlycon(char *buf) \ 349 - { \ 350 - return setup_earlycon(buf, __stringify(name), func); \ 351 - } \ 352 - early_param("earlycon", name ## _setup_earlycon); 349 + #define EARLYCON_DECLARE(_name, func) \ 350 + static const struct earlycon_id __earlycon_##_name \ 351 + __used __section(__earlycon_table) \ 352 + = { .name = __stringify(_name), \ 353 + .setup = func } 353 354 354 355 #define OF_EARLYCON_DECLARE(name, compat, fn) \ 355 356 _OF_DECLARE(earlycon, name, compat, fn, void *) 356 357 357 358 struct uart_port *uart_get_console(struct uart_port *ports, int nr, 358 359 struct console *c); 360 + int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr, 361 + char **options); 359 362 void uart_parse_options(char *options, int *baud, int *parity, int *bits, 360 363 int *flow); 361 364 int uart_set_options(struct uart_port *port, struct console *co, int baud,
-47
include/linux/serial_mfd.h
··· 1 - #ifndef _SERIAL_MFD_H_ 2 - #define _SERIAL_MFD_H_ 3 - 4 - /* HW register offset definition */ 5 - #define UART_FOR 0x08 6 - #define UART_PS 0x0C 7 - #define UART_MUL 0x0D 8 - #define UART_DIV 0x0E 9 - 10 - #define HSU_GBL_IEN 0x0 11 - #define HSU_GBL_IST 0x4 12 - 13 - #define HSU_GBL_INT_BIT_PORT0 0x0 14 - #define HSU_GBL_INT_BIT_PORT1 0x1 15 - #define HSU_GBL_INT_BIT_PORT2 0x2 16 - #define HSU_GBL_INT_BIT_IRI 0x3 17 - #define HSU_GBL_INT_BIT_HDLC 0x4 18 - #define HSU_GBL_INT_BIT_DMA 0x5 19 - 20 - #define HSU_GBL_ISR 0x8 21 - #define HSU_GBL_DMASR 0x400 22 - #define HSU_GBL_DMAISR 0x404 23 - 24 - #define HSU_PORT_REG_OFFSET 0x80 25 - #define HSU_PORT0_REG_OFFSET 0x80 26 - #define HSU_PORT1_REG_OFFSET 0x100 27 - #define HSU_PORT2_REG_OFFSET 0x180 28 - #define HSU_PORT_REG_LENGTH 0x80 29 - 30 - #define HSU_DMA_CHANS_REG_OFFSET 0x500 31 - #define HSU_DMA_CHANS_REG_LENGTH 0x40 32 - 33 - #define HSU_CH_SR 0x0 /* channel status reg */ 34 - #define HSU_CH_CR 0x4 /* control reg */ 35 - #define HSU_CH_DCR 0x8 /* descriptor control reg */ 36 - #define HSU_CH_BSR 0x10 /* max fifo buffer size reg */ 37 - #define HSU_CH_MOTSR 0x14 /* minimum ocp transfer size */ 38 - #define HSU_CH_D0SAR 0x20 /* desc 0 start addr */ 39 - #define HSU_CH_D0TSR 0x24 /* desc 0 transfer size */ 40 - #define HSU_CH_D1SAR 0x28 41 - #define HSU_CH_D1TSR 0x2C 42 - #define HSU_CH_D2SAR 0x30 43 - #define HSU_CH_D2TSR 0x34 44 - #define HSU_CH_D3SAR 0x38 45 - #define HSU_CH_D3TSR 0x3C 46 - 47 - #endif
-19
include/uapi/linux/serial_reg.h
··· 242 242 #define UART_FCR_PXAR32 0xc0 /* receive FIFO threshold = 32 */ 243 243 244 244 /* 245 - * Intel MID on-chip HSU (High Speed UART) defined bits 246 - */ 247 - #define UART_FCR_HSU_64_1B 0x00 /* receive FIFO treshold = 1 */ 248 - #define UART_FCR_HSU_64_16B 0x40 /* receive FIFO treshold = 16 */ 249 - #define UART_FCR_HSU_64_32B 0x80 /* receive FIFO treshold = 32 */ 250 - #define UART_FCR_HSU_64_56B 0xc0 /* receive FIFO treshold = 56 */ 251 - 252 - #define UART_FCR_HSU_16_1B 0x00 /* receive FIFO treshold = 1 */ 253 - #define UART_FCR_HSU_16_4B 0x40 /* receive FIFO treshold = 4 */ 254 - #define UART_FCR_HSU_16_8B 0x80 /* receive FIFO treshold = 8 */ 255 - #define UART_FCR_HSU_16_14B 0xc0 /* receive FIFO treshold = 14 */ 256 - 257 - #define UART_FCR_HSU_64B_FIFO 0x20 /* chose 64 bytes FIFO */ 258 - #define UART_FCR_HSU_16B_FIFO 0x00 /* chose 16 bytes FIFO */ 259 - 260 - #define UART_FCR_HALF_EMPT_TXI 0x00 /* trigger TX_EMPT IRQ for half empty */ 261 - #define UART_FCR_FULL_EMPT_TXI 0x08 /* trigger TX_EMPT IRQ for full empty */ 262 - 263 - /* 264 245 * These register definitions are for the 16C950 265 246 */ 266 247 #define UART_ASR 0x01 /* Additional Status Register */
+18 -35
kernel/printk/printk.c
··· 2017 2017 return __add_preferred_console(name, idx, options, NULL); 2018 2018 } 2019 2019 2020 - int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options) 2021 - { 2022 - struct console_cmdline *c; 2023 - int i; 2024 - 2025 - for (i = 0, c = console_cmdline; 2026 - i < MAX_CMDLINECONSOLES && c->name[0]; 2027 - i++, c++) 2028 - if (strcmp(c->name, name) == 0 && c->index == idx) { 2029 - strlcpy(c->name, name_new, sizeof(c->name)); 2030 - c->options = options; 2031 - c->index = idx_new; 2032 - return i; 2033 - } 2034 - /* not found */ 2035 - return -1; 2036 - } 2037 - 2038 2020 bool console_suspend_enabled = true; 2039 2021 EXPORT_SYMBOL(console_suspend_enabled); 2040 2022 ··· 2418 2436 if (preferred_console < 0 || bcon || !console_drivers) 2419 2437 preferred_console = selected_console; 2420 2438 2421 - if (newcon->early_setup) 2422 - newcon->early_setup(); 2423 - 2424 2439 /* 2425 2440 * See if we want to use this console driver. If we 2426 2441 * didn't select a console we take the first one ··· 2443 2464 for (i = 0, c = console_cmdline; 2444 2465 i < MAX_CMDLINECONSOLES && c->name[0]; 2445 2466 i++, c++) { 2446 - BUILD_BUG_ON(sizeof(c->name) != sizeof(newcon->name)); 2447 - if (strcmp(c->name, newcon->name) != 0) 2448 - continue; 2449 - if (newcon->index >= 0 && 2450 - newcon->index != c->index) 2451 - continue; 2452 - if (newcon->index < 0) 2453 - newcon->index = c->index; 2467 + if (!newcon->match || 2468 + newcon->match(newcon, c->name, c->index, c->options) != 0) { 2469 + /* default matching */ 2470 + BUILD_BUG_ON(sizeof(c->name) != sizeof(newcon->name)); 2471 + if (strcmp(c->name, newcon->name) != 0) 2472 + continue; 2473 + if (newcon->index >= 0 && 2474 + newcon->index != c->index) 2475 + continue; 2476 + if (newcon->index < 0) 2477 + newcon->index = c->index; 2454 2478 2455 - if (_braille_register_console(newcon, c)) 2456 - return; 2479 + if (_braille_register_console(newcon, c)) 2480 + return; 2457 2481 2458 - if (newcon->setup && 2459 - newcon->setup(newcon, console_cmdline[i].options) != 0) 2460 - break; 2482 + if (newcon->setup && 2483 + newcon->setup(newcon, c->options) != 0) 2484 + break; 2485 + } 2486 + 2461 2487 newcon->flags |= CON_ENABLED; 2462 - newcon->index = c->index; 2463 2488 if (i == selected_console) { 2464 2489 newcon->flags |= CON_CONSDEV; 2465 2490 preferred_console = selected_console;