summaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-12-13 14:18:24 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-13 14:18:24 -0500
commit5266e70335dac35c35b5ca9cea4251c1389d4a68 (patch)
treec8bfdcc37b922a0978ea7aab4a43685ee9f33c3e /drivers/tty
parent03f8d4cca352fd41f26b5c88dec1e4d3f507f5de (diff)
parenta9b01b5823f73dc741b623dfc52ccd68f8139b55 (diff)
Merge tag 'tty-4.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
Pull tty/serial updates from Greg KH: "Here's the tty/serial patchset for 4.10-rc1. It's been a quiet kernel cycle for this subsystem, just a small number of changes. A few new serial drivers, and some cleanups to the old vgacon logic, and other minor serial driver changes as well. All of these have been in linux-next for a while with no reported issues" * tag 'tty-4.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (54 commits) serial: 8250_mid fix calltrace when hotplug 8250 serial controller console: Move userspace I/O out of console_lock to fix lockdep warning tty: nozomi: avoid sprintf buffer overflow serial: 8250_pci: Detach low-level driver during PCI error recovery serial: core: don't check port twice in a row mxs-auart: count FIFO overrun errors serial: 8250_dw: Add support for IrDA SIR mode serial: 8250: Expose set_ldisc function serial: 8250: Add IrDA to UART capabilities serial: 8250_dma: power off device after TX is done serial: 8250_port: export serial8250_rpm_{get|put}_tx() serial: sunsu: Free memory when probe fails serial: sunhv: Free memory when remove() is called vt: fix Scroll Lock LED trigger name tty: typo in comments in drivers/tty/vt/keyboard.c tty: amba-pl011: Add earlycon support for SBSA UART tty: nozomi: use permission-specific DEVICE_ATTR variants tty: serial: Make the STM32 serial port depend on it's arch serial: ifx6x60: Free memory when probe fails serial: ioc4_serial: Free memory when kzalloc fails during probe ...
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/amiserial.c2
-rw-r--r--drivers/tty/nozomi.c51
-rw-r--r--drivers/tty/rocket.c4
-rw-r--r--drivers/tty/serial/8250/8250.h6
-rw-r--r--drivers/tty/serial/8250/8250_core.c7
-rw-r--r--drivers/tty/serial/8250/8250_dma.c9
-rw-r--r--drivers/tty/serial/8250/8250_dw.c22
-rw-r--r--drivers/tty/serial/8250/8250_fintek.c231
-rw-r--r--drivers/tty/serial/8250/8250_lpss.c7
-rw-r--r--drivers/tty/serial/8250/8250_mid.c4
-rw-r--r--drivers/tty/serial/8250/8250_of.c2
-rw-r--r--drivers/tty/serial/8250/8250_pci.c57
-rw-r--r--drivers/tty/serial/8250/8250_port.c18
-rw-r--r--drivers/tty/serial/8250/8250_pxa.c190
-rw-r--r--drivers/tty/serial/8250/8250_uniphier.c46
-rw-r--r--drivers/tty/serial/8250/Kconfig10
-rw-r--r--drivers/tty/serial/8250/Makefile1
-rw-r--r--drivers/tty/serial/Kconfig19
-rw-r--r--drivers/tty/serial/Makefile7
-rw-r--r--drivers/tty/serial/amba-pl011.c56
-rw-r--r--drivers/tty/serial/crisv10.c2
-rw-r--r--drivers/tty/serial/fsl_lpuart.c64
-rw-r--r--drivers/tty/serial/ifx6x60.c1
-rw-r--r--drivers/tty/serial/ioc4_serial.c7
-rw-r--r--drivers/tty/serial/mxs-auart.c2
-rw-r--r--drivers/tty/serial/pxa.c2
-rw-r--r--drivers/tty/serial/sc16is7xx.c2
-rw-r--r--drivers/tty/serial/serial_core.c17
-rw-r--r--drivers/tty/serial/sh-sci.c20
-rw-r--r--drivers/tty/serial/sunhv.c3
-rw-r--r--drivers/tty/serial/sunsu.c1
-rw-r--r--drivers/tty/vt/consolemap.c115
-rw-r--r--drivers/tty/vt/keyboard.c4
-rw-r--r--drivers/tty/vt/vt.c85
34 files changed, 830 insertions, 244 deletions
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 208f573495dc..dfbb974927f2 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1012,8 +1012,6 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state,
1012{ 1012{
1013 struct serial_struct tmp; 1013 struct serial_struct tmp;
1014 1014
1015 if (!retinfo)
1016 return -EFAULT;
1017 memset(&tmp, 0, sizeof(tmp)); 1015 memset(&tmp, 0, sizeof(tmp));
1018 tty_lock(tty); 1016 tty_lock(tty);
1019 tmp.line = tty->index; 1017 tmp.line = tty->index;
diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
index d6fd0e802ef5..39b3723a32a6 100644
--- a/drivers/tty/nozomi.c
+++ b/drivers/tty/nozomi.c
@@ -63,44 +63,23 @@
63 63
64#define VERSION_STRING DRIVER_DESC " 2.1d" 64#define VERSION_STRING DRIVER_DESC " 2.1d"
65 65
66/* Macros definitions */
67
68/* Default debug printout level */ 66/* Default debug printout level */
69#define NOZOMI_DEBUG_LEVEL 0x00 67#define NOZOMI_DEBUG_LEVEL 0x00
70
71#define P_BUF_SIZE 128
72#define NFO(_err_flag_, args...) \
73do { \
74 char tmp[P_BUF_SIZE]; \
75 snprintf(tmp, sizeof(tmp), ##args); \
76 printk(_err_flag_ "[%d] %s(): %s\n", __LINE__, \
77 __func__, tmp); \
78} while (0)
79
80#define DBG1(args...) D_(0x01, ##args)
81#define DBG2(args...) D_(0x02, ##args)
82#define DBG3(args...) D_(0x04, ##args)
83#define DBG4(args...) D_(0x08, ##args)
84#define DBG5(args...) D_(0x10, ##args)
85#define DBG6(args...) D_(0x20, ##args)
86#define DBG7(args...) D_(0x40, ##args)
87#define DBG8(args...) D_(0x80, ##args)
88
89#ifdef DEBUG
90/* Do we need this settable at runtime? */
91static int debug = NOZOMI_DEBUG_LEVEL; 68static int debug = NOZOMI_DEBUG_LEVEL;
69module_param(debug, int, S_IRUGO | S_IWUSR);
92 70
93#define D(lvl, args...) do \ 71/* Macros definitions */
94 {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \ 72#define DBG_(lvl, fmt, args...) \
95 while (0) 73do { \
96#define D_(lvl, args...) D(lvl, ##args) 74 if (lvl & debug) \
97 75 pr_debug("[%d] %s(): " fmt "\n", \
98/* These printouts are always printed */ 76 __LINE__, __func__, ##args); \
77} while (0)
99 78
100#else 79#define DBG1(args...) DBG_(0x01, ##args)
101static int debug; 80#define DBG2(args...) DBG_(0x02, ##args)
102#define D_(lvl, args...) 81#define DBG3(args...) DBG_(0x04, ##args)
103#endif 82#define DBG4(args...) DBG_(0x08, ##args)
104 83
105/* TODO: rewrite to optimize macros... */ 84/* TODO: rewrite to optimize macros... */
106 85
@@ -1320,7 +1299,7 @@ static ssize_t card_type_show(struct device *dev, struct device_attribute *attr,
1320 1299
1321 return sprintf(buf, "%d\n", dc->card_type); 1300 return sprintf(buf, "%d\n", dc->card_type);
1322} 1301}
1323static DEVICE_ATTR(card_type, S_IRUGO, card_type_show, NULL); 1302static DEVICE_ATTR_RO(card_type);
1324 1303
1325static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr, 1304static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
1326 char *buf) 1305 char *buf)
@@ -1329,7 +1308,7 @@ static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
1329 1308
1330 return sprintf(buf, "%u\n", dc->open_ttys); 1309 return sprintf(buf, "%u\n", dc->open_ttys);
1331} 1310}
1332static DEVICE_ATTR(open_ttys, S_IRUGO, open_ttys_show, NULL); 1311static DEVICE_ATTR_RO(open_ttys);
1333 1312
1334static void make_sysfs_files(struct nozomi *dc) 1313static void make_sysfs_files(struct nozomi *dc)
1335{ 1314{
@@ -1943,7 +1922,5 @@ static __exit void nozomi_exit(void)
1943module_init(nozomi_init); 1922module_init(nozomi_init);
1944module_exit(nozomi_exit); 1923module_exit(nozomi_exit);
1945 1924
1946module_param(debug, int, S_IRUGO | S_IWUSR);
1947
1948MODULE_LICENSE("Dual BSD/GPL"); 1925MODULE_LICENSE("Dual BSD/GPL");
1949MODULE_DESCRIPTION(DRIVER_DESC); 1926MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
index b0cc47c77b40..d66c1edd9892 100644
--- a/drivers/tty/rocket.c
+++ b/drivers/tty/rocket.c
@@ -1189,8 +1189,6 @@ static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
1189{ 1189{
1190 struct rocket_config tmp; 1190 struct rocket_config tmp;
1191 1191
1192 if (!retinfo)
1193 return -EFAULT;
1194 memset(&tmp, 0, sizeof (tmp)); 1192 memset(&tmp, 0, sizeof (tmp));
1195 mutex_lock(&info->port.mutex); 1193 mutex_lock(&info->port.mutex);
1196 tmp.line = info->line; 1194 tmp.line = info->line;
@@ -1255,8 +1253,6 @@ static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
1255 struct rocket_ports tmp; 1253 struct rocket_ports tmp;
1256 int board; 1254 int board;
1257 1255
1258 if (!retports)
1259 return -EFAULT;
1260 memset(&tmp, 0, sizeof (tmp)); 1256 memset(&tmp, 0, sizeof (tmp));
1261 tmp.tty_major = rocket_driver->major; 1257 tmp.tty_major = rocket_driver->major;
1262 1258
diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
index a697a8585ddc..ce8d4ffcc425 100644
--- a/drivers/tty/serial/8250/8250.h
+++ b/drivers/tty/serial/8250/8250.h
@@ -80,6 +80,7 @@ struct serial8250_config {
80#define UART_CAP_RTOIE (1 << 13) /* UART needs IER bit 4 set (Xscale, Tegra) */ 80#define UART_CAP_RTOIE (1 << 13) /* UART needs IER bit 4 set (Xscale, Tegra) */
81#define UART_CAP_HFIFO (1 << 14) /* UART has a "hidden" FIFO */ 81#define UART_CAP_HFIFO (1 << 14) /* UART has a "hidden" FIFO */
82#define UART_CAP_RPM (1 << 15) /* Runtime PM is active while idle */ 82#define UART_CAP_RPM (1 << 15) /* Runtime PM is active while idle */
83#define UART_CAP_IRDA (1 << 16) /* UART supports IrDA line discipline */
83 84
84#define UART_BUG_QUOT (1 << 0) /* UART has buggy quot LSB */ 85#define UART_BUG_QUOT (1 << 0) /* UART has buggy quot LSB */
85#define UART_BUG_TXEN (1 << 1) /* UART has buggy TX IIR status */ 86#define UART_BUG_TXEN (1 << 1) /* UART has buggy TX IIR status */
@@ -129,8 +130,13 @@ static inline void serial_dl_write(struct uart_8250_port *up, int value)
129} 130}
130 131
131struct uart_8250_port *serial8250_get_port(int line); 132struct uart_8250_port *serial8250_get_port(int line);
133
132void serial8250_rpm_get(struct uart_8250_port *p); 134void serial8250_rpm_get(struct uart_8250_port *p);
133void serial8250_rpm_put(struct uart_8250_port *p); 135void serial8250_rpm_put(struct uart_8250_port *p);
136
137void serial8250_rpm_get_tx(struct uart_8250_port *p);
138void serial8250_rpm_put_tx(struct uart_8250_port *p);
139
134int serial8250_em485_init(struct uart_8250_port *p); 140int serial8250_em485_init(struct uart_8250_port *p);
135void serial8250_em485_destroy(struct uart_8250_port *p); 141void serial8250_em485_destroy(struct uart_8250_port *p);
136 142
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 240a361b674f..61569a765d9e 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -425,10 +425,10 @@ struct uart_8250_port *serial8250_get_port(int line)
425EXPORT_SYMBOL_GPL(serial8250_get_port); 425EXPORT_SYMBOL_GPL(serial8250_get_port);
426 426
427static void (*serial8250_isa_config)(int port, struct uart_port *up, 427static void (*serial8250_isa_config)(int port, struct uart_port *up,
428 unsigned short *capabilities); 428 u32 *capabilities);
429 429
430void serial8250_set_isa_configurator( 430void serial8250_set_isa_configurator(
431 void (*v)(int port, struct uart_port *up, unsigned short *capabilities)) 431 void (*v)(int port, struct uart_port *up, u32 *capabilities))
432{ 432{
433 serial8250_isa_config = v; 433 serial8250_isa_config = v;
434} 434}
@@ -830,6 +830,7 @@ static int serial8250_probe(struct platform_device *dev)
830 uart.port.handle_irq = p->handle_irq; 830 uart.port.handle_irq = p->handle_irq;
831 uart.port.handle_break = p->handle_break; 831 uart.port.handle_break = p->handle_break;
832 uart.port.set_termios = p->set_termios; 832 uart.port.set_termios = p->set_termios;
833 uart.port.set_ldisc = p->set_ldisc;
833 uart.port.get_mctrl = p->get_mctrl; 834 uart.port.get_mctrl = p->get_mctrl;
834 uart.port.pm = p->pm; 835 uart.port.pm = p->pm;
835 uart.port.dev = &dev->dev; 836 uart.port.dev = &dev->dev;
@@ -1023,6 +1024,8 @@ int serial8250_register_8250_port(struct uart_8250_port *up)
1023 /* Possibly override set_termios call */ 1024 /* Possibly override set_termios call */
1024 if (up->port.set_termios) 1025 if (up->port.set_termios)
1025 uart->port.set_termios = up->port.set_termios; 1026 uart->port.set_termios = up->port.set_termios;
1027 if (up->port.set_ldisc)
1028 uart->port.set_ldisc = up->port.set_ldisc;
1026 if (up->port.get_mctrl) 1029 if (up->port.get_mctrl)
1027 uart->port.get_mctrl = up->port.get_mctrl; 1030 uart->port.get_mctrl = up->port.get_mctrl;
1028 if (up->port.set_mctrl) 1031 if (up->port.set_mctrl)
diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c
index fdbddbc6375d..26f17456b0d7 100644
--- a/drivers/tty/serial/8250/8250_dma.c
+++ b/drivers/tty/serial/8250/8250_dma.c
@@ -72,10 +72,15 @@ int serial8250_tx_dma(struct uart_8250_port *p)
72 struct dma_async_tx_descriptor *desc; 72 struct dma_async_tx_descriptor *desc;
73 int ret; 73 int ret;
74 74
75 if (uart_tx_stopped(&p->port) || dma->tx_running || 75 if (dma->tx_running)
76 uart_circ_empty(xmit))
77 return 0; 76 return 0;
78 77
78 if (uart_tx_stopped(&p->port) || uart_circ_empty(xmit)) {
79 /* We have been called from __dma_tx_complete() */
80 serial8250_rpm_put_tx(p);
81 return 0;
82 }
83
79 dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); 84 dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
80 85
81 desc = dmaengine_prep_slave_single(dma->txchan, 86 desc = dmaengine_prep_slave_single(dma->txchan,
diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 459d726f9d59..c89fafc972b6 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -53,6 +53,8 @@
53/* Helper for fifo size calculation */ 53/* Helper for fifo size calculation */
54#define DW_UART_CPR_FIFO_SIZE(a) (((a >> 16) & 0xff) * 16) 54#define DW_UART_CPR_FIFO_SIZE(a) (((a >> 16) & 0xff) * 16)
55 55
56/* DesignWare specific register fields */
57#define DW_UART_MCR_SIRE BIT(6)
56 58
57struct dw8250_data { 59struct dw8250_data {
58 u8 usr_reg; 60 u8 usr_reg;
@@ -254,6 +256,22 @@ out:
254 serial8250_do_set_termios(p, termios, old); 256 serial8250_do_set_termios(p, termios, old);
255} 257}
256 258
259static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios)
260{
261 struct uart_8250_port *up = up_to_u8250p(p);
262 unsigned int mcr = p->serial_in(p, UART_MCR);
263
264 if (up->capabilities & UART_CAP_IRDA) {
265 if (termios->c_line == N_IRDA)
266 mcr |= DW_UART_MCR_SIRE;
267 else
268 mcr &= ~DW_UART_MCR_SIRE;
269
270 p->serial_out(p, UART_MCR, mcr);
271 }
272 serial8250_do_set_ldisc(p, termios);
273}
274
257/* 275/*
258 * dw8250_fallback_dma_filter will prevent the UART from getting just any free 276 * dw8250_fallback_dma_filter will prevent the UART from getting just any free
259 * channel on platforms that have DMA engines, but don't have any channels 277 * channel on platforms that have DMA engines, but don't have any channels
@@ -357,6 +375,9 @@ static void dw8250_setup_port(struct uart_port *p)
357 375
358 if (reg & DW_UART_CPR_AFCE_MODE) 376 if (reg & DW_UART_CPR_AFCE_MODE)
359 up->capabilities |= UART_CAP_AFE; 377 up->capabilities |= UART_CAP_AFE;
378
379 if (reg & DW_UART_CPR_SIR_MODE)
380 up->capabilities |= UART_CAP_IRDA;
360} 381}
361 382
362static int dw8250_probe(struct platform_device *pdev) 383static int dw8250_probe(struct platform_device *pdev)
@@ -392,6 +413,7 @@ static int dw8250_probe(struct platform_device *pdev)
392 p->iotype = UPIO_MEM; 413 p->iotype = UPIO_MEM;
393 p->serial_in = dw8250_serial_in; 414 p->serial_in = dw8250_serial_in;
394 p->serial_out = dw8250_serial_out; 415 p->serial_out = dw8250_serial_out;
416 p->set_ldisc = dw8250_set_ldisc;
395 417
396 p->membase = devm_ioremap(dev, regs->start, resource_size(regs)); 418 p->membase = devm_ioremap(dev, regs->start, resource_size(regs));
397 if (!p->membase) 419 if (!p->membase)
diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c
index 0facc789fe7d..b67e7a544935 100644
--- a/drivers/tty/serial/8250/8250_fintek.c
+++ b/drivers/tty/serial/8250/8250_fintek.c
@@ -21,8 +21,11 @@
21#define EXIT_KEY 0xAA 21#define EXIT_KEY 0xAA
22#define CHIP_ID1 0x20 22#define CHIP_ID1 0x20
23#define CHIP_ID2 0x21 23#define CHIP_ID2 0x21
24#define CHIP_ID_0 0x1602 24#define CHIP_ID_F81865 0x0407
25#define CHIP_ID_1 0x0501 25#define CHIP_ID_F81866 0x1010
26#define CHIP_ID_F81216AD 0x1602
27#define CHIP_ID_F81216H 0x0501
28#define CHIP_ID_F81216 0x0802
26#define VENDOR_ID1 0x23 29#define VENDOR_ID1 0x23
27#define VENDOR_ID1_VAL 0x19 30#define VENDOR_ID1_VAL 0x19
28#define VENDOR_ID2 0x24 31#define VENDOR_ID2 0x24
@@ -43,12 +46,60 @@
43#define RXW4C_IRA BIT(3) 46#define RXW4C_IRA BIT(3)
44#define TXW4C_IRA BIT(2) 47#define TXW4C_IRA BIT(2)
45 48
49#define FIFO_CTRL 0xF6
50#define FIFO_MODE_MASK (BIT(1) | BIT(0))
51#define FIFO_MODE_128 (BIT(1) | BIT(0))
52#define RXFTHR_MODE_MASK (BIT(5) | BIT(4))
53#define RXFTHR_MODE_4X BIT(5)
54
55#define F81216_LDN_LOW 0x0
56#define F81216_LDN_HIGH 0x4
57
58/*
59 * F81866 registers
60 *
61 * The IRQ setting mode of F81866 is not the same with F81216 series.
62 * Level/Low: IRQ_MODE0:0, IRQ_MODE1:0
63 * Edge/High: IRQ_MODE0:1, IRQ_MODE1:0
64 */
65#define F81866_IRQ_MODE 0xf0
66#define F81866_IRQ_SHARE BIT(0)
67#define F81866_IRQ_MODE0 BIT(1)
68
69#define F81866_FIFO_CTRL FIFO_CTRL
70#define F81866_IRQ_MODE1 BIT(3)
71
72#define F81866_LDN_LOW 0x10
73#define F81866_LDN_HIGH 0x16
74
46struct fintek_8250 { 75struct fintek_8250 {
76 u16 pid;
47 u16 base_port; 77 u16 base_port;
48 u8 index; 78 u8 index;
49 u8 key; 79 u8 key;
50}; 80};
51 81
82static u8 sio_read_reg(struct fintek_8250 *pdata, u8 reg)
83{
84 outb(reg, pdata->base_port + ADDR_PORT);
85 return inb(pdata->base_port + DATA_PORT);
86}
87
88static void sio_write_reg(struct fintek_8250 *pdata, u8 reg, u8 data)
89{
90 outb(reg, pdata->base_port + ADDR_PORT);
91 outb(data, pdata->base_port + DATA_PORT);
92}
93
94static void sio_write_mask_reg(struct fintek_8250 *pdata, u8 reg, u8 mask,
95 u8 data)
96{
97 u8 tmp;
98
99 tmp = (sio_read_reg(pdata, reg) & ~mask) | (mask & data);
100 sio_write_reg(pdata, reg, tmp);
101}
102
52static int fintek_8250_enter_key(u16 base_port, u8 key) 103static int fintek_8250_enter_key(u16 base_port, u8 key)
53{ 104{
54 if (!request_muxed_region(base_port, 2, "8250_fintek")) 105 if (!request_muxed_region(base_port, 2, "8250_fintek"))
@@ -66,29 +117,55 @@ static void fintek_8250_exit_key(u16 base_port)
66 release_region(base_port + ADDR_PORT, 2); 117 release_region(base_port + ADDR_PORT, 2);
67} 118}
68 119
69static int fintek_8250_check_id(u16 base_port) 120static int fintek_8250_check_id(struct fintek_8250 *pdata)
70{ 121{
71 u16 chip; 122 u16 chip;
72 123
73 outb(VENDOR_ID1, base_port + ADDR_PORT); 124 if (sio_read_reg(pdata, VENDOR_ID1) != VENDOR_ID1_VAL)
74 if (inb(base_port + DATA_PORT) != VENDOR_ID1_VAL)
75 return -ENODEV; 125 return -ENODEV;
76 126
77 outb(VENDOR_ID2, base_port + ADDR_PORT); 127 if (sio_read_reg(pdata, VENDOR_ID2) != VENDOR_ID2_VAL)
78 if (inb(base_port + DATA_PORT) != VENDOR_ID2_VAL)
79 return -ENODEV; 128 return -ENODEV;
80 129
81 outb(CHIP_ID1, base_port + ADDR_PORT); 130 chip = sio_read_reg(pdata, CHIP_ID1);
82 chip = inb(base_port + DATA_PORT); 131 chip |= sio_read_reg(pdata, CHIP_ID2) << 8;
83 outb(CHIP_ID2, base_port + ADDR_PORT); 132
84 chip |= inb(base_port + DATA_PORT) << 8; 133 switch (chip) {
85 134 case CHIP_ID_F81865:
86 if (chip != CHIP_ID_0 && chip != CHIP_ID_1) 135 case CHIP_ID_F81866:
136 case CHIP_ID_F81216AD:
137 case CHIP_ID_F81216H:
138 case CHIP_ID_F81216:
139 break;
140 default:
87 return -ENODEV; 141 return -ENODEV;
142 }
88 143
144 pdata->pid = chip;
89 return 0; 145 return 0;
90} 146}
91 147
148static int fintek_8250_get_ldn_range(struct fintek_8250 *pdata, int *min,
149 int *max)
150{
151 switch (pdata->pid) {
152 case CHIP_ID_F81865:
153 case CHIP_ID_F81866:
154 *min = F81866_LDN_LOW;
155 *max = F81866_LDN_HIGH;
156 return 0;
157
158 case CHIP_ID_F81216AD:
159 case CHIP_ID_F81216H:
160 case CHIP_ID_F81216:
161 *min = F81216_LDN_LOW;
162 *max = F81216_LDN_HIGH;
163 return 0;
164 }
165
166 return -ENODEV;
167}
168
92static int fintek_8250_rs485_config(struct uart_port *port, 169static int fintek_8250_rs485_config(struct uart_port *port,
93 struct serial_rs485 *rs485) 170 struct serial_rs485 *rs485)
94{ 171{
@@ -128,10 +205,8 @@ static int fintek_8250_rs485_config(struct uart_port *port,
128 if (fintek_8250_enter_key(pdata->base_port, pdata->key)) 205 if (fintek_8250_enter_key(pdata->base_port, pdata->key))
129 return -EBUSY; 206 return -EBUSY;
130 207
131 outb(LDN, pdata->base_port + ADDR_PORT); 208 sio_write_reg(pdata, LDN, pdata->index);
132 outb(pdata->index, pdata->base_port + DATA_PORT); 209 sio_write_reg(pdata, RS485, config);
133 outb(RS485, pdata->base_port + ADDR_PORT);
134 outb(config, pdata->base_port + DATA_PORT);
135 fintek_8250_exit_key(pdata->base_port); 210 fintek_8250_exit_key(pdata->base_port);
136 211
137 port->rs485 = *rs485; 212 port->rs485 = *rs485;
@@ -139,40 +214,90 @@ static int fintek_8250_rs485_config(struct uart_port *port,
139 return 0; 214 return 0;
140} 215}
141 216
142static int find_base_port(struct fintek_8250 *pdata, u16 io_address) 217static void fintek_8250_set_irq_mode(struct fintek_8250 *pdata, bool is_level)
218{
219 sio_write_reg(pdata, LDN, pdata->index);
220
221 switch (pdata->pid) {
222 case CHIP_ID_F81866:
223 sio_write_mask_reg(pdata, F81866_FIFO_CTRL, F81866_IRQ_MODE1,
224 0);
225 /* fall through */
226 case CHIP_ID_F81865:
227 sio_write_mask_reg(pdata, F81866_IRQ_MODE, F81866_IRQ_SHARE,
228 F81866_IRQ_SHARE);
229 sio_write_mask_reg(pdata, F81866_IRQ_MODE, F81866_IRQ_MODE0,
230 is_level ? 0 : F81866_IRQ_MODE0);
231 break;
232
233 case CHIP_ID_F81216AD:
234 case CHIP_ID_F81216H:
235 case CHIP_ID_F81216:
236 sio_write_mask_reg(pdata, FINTEK_IRQ_MODE, IRQ_SHARE,
237 IRQ_SHARE);
238 sio_write_mask_reg(pdata, FINTEK_IRQ_MODE, IRQ_MODE_MASK,
239 is_level ? IRQ_LEVEL_LOW : IRQ_EDGE_HIGH);
240 break;
241 }
242}
243
244static void fintek_8250_set_max_fifo(struct fintek_8250 *pdata)
245{
246 switch (pdata->pid) {
247 case CHIP_ID_F81216H: /* 128Bytes FIFO */
248 case CHIP_ID_F81866:
249 sio_write_mask_reg(pdata, FIFO_CTRL,
250 FIFO_MODE_MASK | RXFTHR_MODE_MASK,
251 FIFO_MODE_128 | RXFTHR_MODE_4X);
252 break;
253
254 default: /* Default 16Bytes FIFO */
255 break;
256 }
257}
258
259static int probe_setup_port(struct fintek_8250 *pdata, u16 io_address,
260 unsigned int irq)
143{ 261{
144 static const u16 addr[] = {0x4e, 0x2e}; 262 static const u16 addr[] = {0x4e, 0x2e};
145 static const u8 keys[] = {0x77, 0xa0, 0x87, 0x67}; 263 static const u8 keys[] = {0x77, 0xa0, 0x87, 0x67};
146 int i, j, k; 264 struct irq_data *irq_data;
265 bool level_mode = false;
266 int i, j, k, min, max;
147 267
148 for (i = 0; i < ARRAY_SIZE(addr); i++) { 268 for (i = 0; i < ARRAY_SIZE(addr); i++) {
149 for (j = 0; j < ARRAY_SIZE(keys); j++) { 269 for (j = 0; j < ARRAY_SIZE(keys); j++) {
270 pdata->base_port = addr[i];
271 pdata->key = keys[j];
150 272
151 if (fintek_8250_enter_key(addr[i], keys[j])) 273 if (fintek_8250_enter_key(addr[i], keys[j]))
152 continue; 274 continue;
153 if (fintek_8250_check_id(addr[i])) { 275 if (fintek_8250_check_id(pdata) ||
276 fintek_8250_get_ldn_range(pdata, &min, &max)) {
154 fintek_8250_exit_key(addr[i]); 277 fintek_8250_exit_key(addr[i]);
155 continue; 278 continue;
156 } 279 }
157 280
158 for (k = 0; k < 4; k++) { 281 for (k = min; k < max; k++) {
159 u16 aux; 282 u16 aux;
160 283
161 outb(LDN, addr[i] + ADDR_PORT); 284 sio_write_reg(pdata, LDN, k);
162 outb(k, addr[i] + DATA_PORT); 285 aux = sio_read_reg(pdata, IO_ADDR1);
163 286 aux |= sio_read_reg(pdata, IO_ADDR2) << 8;
164 outb(IO_ADDR1, addr[i] + ADDR_PORT);
165 aux = inb(addr[i] + DATA_PORT);
166 outb(IO_ADDR2, addr[i] + ADDR_PORT);
167 aux |= inb(addr[i] + DATA_PORT) << 8;
168 if (aux != io_address) 287 if (aux != io_address)
169 continue; 288 continue;
170 289
171 fintek_8250_exit_key(addr[i]);
172 pdata->key = keys[j];
173 pdata->base_port = addr[i];
174 pdata->index = k; 290 pdata->index = k;
175 291
292 irq_data = irq_get_irq_data(irq);
293 if (irq_data)
294 level_mode =
295 irqd_is_level_type(irq_data);
296
297 fintek_8250_set_irq_mode(pdata, level_mode);
298 fintek_8250_set_max_fifo(pdata);
299 fintek_8250_exit_key(addr[i]);
300
176 return 0; 301 return 0;
177 } 302 }
178 303
@@ -183,39 +308,29 @@ static int find_base_port(struct fintek_8250 *pdata, u16 io_address)
183 return -ENODEV; 308 return -ENODEV;
184} 309}
185 310
186static int fintek_8250_set_irq_mode(struct fintek_8250 *pdata, bool level_mode) 311static void fintek_8250_set_rs485_handler(struct uart_8250_port *uart)
187{ 312{
188 int status; 313 struct fintek_8250 *pdata = uart->port.private_data;
189 u8 tmp; 314
190 315 switch (pdata->pid) {
191 status = fintek_8250_enter_key(pdata->base_port, pdata->key); 316 case CHIP_ID_F81216AD:
192 if (status) 317 case CHIP_ID_F81216H:
193 return status; 318 case CHIP_ID_F81866:
194 319 case CHIP_ID_F81865:
195 outb(LDN, pdata->base_port + ADDR_PORT); 320 uart->port.rs485_config = fintek_8250_rs485_config;
196 outb(pdata->index, pdata->base_port + DATA_PORT); 321 break;
197 322
198 outb(FINTEK_IRQ_MODE, pdata->base_port + ADDR_PORT); 323 default: /* No RS485 Auto direction functional */
199 tmp = inb(pdata->base_port + DATA_PORT); 324 break;
200 325 }
201 tmp &= ~IRQ_MODE_MASK;
202 tmp |= IRQ_SHARE;
203 if (!level_mode)
204 tmp |= IRQ_EDGE_HIGH;
205
206 outb(tmp, pdata->base_port + DATA_PORT);
207 fintek_8250_exit_key(pdata->base_port);
208 return 0;
209} 326}
210 327
211int fintek_8250_probe(struct uart_8250_port *uart) 328int fintek_8250_probe(struct uart_8250_port *uart)
212{ 329{
213 struct fintek_8250 *pdata; 330 struct fintek_8250 *pdata;
214 struct fintek_8250 probe_data; 331 struct fintek_8250 probe_data;
215 struct irq_data *irq_data = irq_get_irq_data(uart->port.irq);
216 bool level_mode = irqd_is_level_type(irq_data);
217 332
218 if (find_base_port(&probe_data, uart->port.iobase)) 333 if (probe_setup_port(&probe_data, uart->port.iobase, uart->port.irq))
219 return -ENODEV; 334 return -ENODEV;
220 335
221 pdata = devm_kzalloc(uart->port.dev, sizeof(*pdata), GFP_KERNEL); 336 pdata = devm_kzalloc(uart->port.dev, sizeof(*pdata), GFP_KERNEL);
@@ -223,8 +338,8 @@ int fintek_8250_probe(struct uart_8250_port *uart)
223 return -ENOMEM; 338 return -ENOMEM;
224 339
225 memcpy(pdata, &probe_data, sizeof(probe_data)); 340 memcpy(pdata, &probe_data, sizeof(probe_data));
226 uart->port.rs485_config = fintek_8250_rs485_config;
227 uart->port.private_data = pdata; 341 uart->port.private_data = pdata;
342 fintek_8250_set_rs485_handler(uart);
228 343
229 return fintek_8250_set_irq_mode(pdata, level_mode); 344 return 0;
230} 345}
diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
index b9923464599f..f607946fd996 100644
--- a/drivers/tty/serial/8250/8250_lpss.c
+++ b/drivers/tty/serial/8250/8250_lpss.c
@@ -174,7 +174,7 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
174 int ret; 174 int ret;
175 175
176 chip->dev = &pdev->dev; 176 chip->dev = &pdev->dev;
177 chip->irq = pdev->irq; 177 chip->irq = pci_irq_vector(pdev, 0);
178 chip->regs = pci_ioremap_bar(pdev, 1); 178 chip->regs = pci_ioremap_bar(pdev, 1);
179 chip->pdata = &qrk_serial_dma_pdata; 179 chip->pdata = &qrk_serial_dma_pdata;
180 180
@@ -183,6 +183,9 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
183 if (ret) 183 if (ret)
184 return; 184 return;
185 185
186 pci_set_master(pdev);
187 pci_try_set_mwi(pdev);
188
186 /* Special DMA address for UART */ 189 /* Special DMA address for UART */
187 dma->rx_dma_addr = 0xfffff000; 190 dma->rx_dma_addr = 0xfffff000;
188 dma->tx_dma_addr = 0xfffff000; 191 dma->tx_dma_addr = 0xfffff000;
@@ -280,8 +283,6 @@ static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
280 if (ret) 283 if (ret)
281 return ret; 284 return ret;
282 285
283 pci_set_master(pdev);
284
285 lpss = devm_kzalloc(&pdev->dev, sizeof(*lpss), GFP_KERNEL); 286 lpss = devm_kzalloc(&pdev->dev, sizeof(*lpss), GFP_KERNEL);
286 if (!lpss) 287 if (!lpss)
287 return -ENOMEM; 288 return -ENOMEM;
diff --git a/drivers/tty/serial/8250/8250_mid.c b/drivers/tty/serial/8250/8250_mid.c
index 39c2324484dd..ac013edf4992 100644
--- a/drivers/tty/serial/8250/8250_mid.c
+++ b/drivers/tty/serial/8250/8250_mid.c
@@ -303,10 +303,10 @@ static void mid8250_remove(struct pci_dev *pdev)
303{ 303{
304 struct mid8250 *mid = pci_get_drvdata(pdev); 304 struct mid8250 *mid = pci_get_drvdata(pdev);
305 305
306 serial8250_unregister_port(mid->line);
307
306 if (mid->board->exit) 308 if (mid->board->exit)
307 mid->board->exit(mid); 309 mid->board->exit(mid);
308
309 serial8250_unregister_port(mid->line);
310} 310}
311 311
312static const struct mid8250_board pnw_board = { 312static const struct mid8250_board pnw_board = {
diff --git a/drivers/tty/serial/8250/8250_of.c b/drivers/tty/serial/8250/8250_of.c
index 7a8b5fc81a19..d25ab1cd4295 100644
--- a/drivers/tty/serial/8250/8250_of.c
+++ b/drivers/tty/serial/8250/8250_of.c
@@ -332,8 +332,6 @@ static const struct of_device_id of_platform_serial_table[] = {
332 .data = (void *)PORT_ALTR_16550_F128, }, 332 .data = (void *)PORT_ALTR_16550_F128, },
333 { .compatible = "mrvl,mmp-uart", 333 { .compatible = "mrvl,mmp-uart",
334 .data = (void *)PORT_XSCALE, }, 334 .data = (void *)PORT_XSCALE, },
335 { .compatible = "mrvl,pxa-uart",
336 .data = (void *)PORT_XSCALE, },
337 { /* end of list */ }, 335 { /* end of list */ },
338}; 336};
339MODULE_DEVICE_TABLE(of, of_platform_serial_table); 337MODULE_DEVICE_TABLE(of, of_platform_serial_table);
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index b98c1578f45a..aa0166b6d450 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -52,6 +52,7 @@ struct serial_private {
52 struct pci_dev *dev; 52 struct pci_dev *dev;
53 unsigned int nr; 53 unsigned int nr;
54 struct pci_serial_quirk *quirk; 54 struct pci_serial_quirk *quirk;
55 const struct pciserial_board *board;
55 int line[0]; 56 int line[0];
56}; 57};
57 58
@@ -1329,6 +1330,30 @@ static int pci_default_setup(struct serial_private *priv,
1329 return setup_port(priv, port, bar, offset, board->reg_shift); 1330 return setup_port(priv, port, bar, offset, board->reg_shift);
1330} 1331}
1331 1332
1333static int pci_pericom_setup(struct serial_private *priv,
1334 const struct pciserial_board *board,
1335 struct uart_8250_port *port, int idx)
1336{
1337 unsigned int bar, offset = board->first_offset, maxnr;
1338
1339 bar = FL_GET_BASE(board->flags);
1340 if (board->flags & FL_BASE_BARS)
1341 bar += idx;
1342 else
1343 offset += idx * board->uart_offset;
1344
1345 if (idx==3)
1346 offset = 0x38;
1347
1348 maxnr = (pci_resource_len(priv->dev, bar) - board->first_offset) >>
1349 (board->reg_shift + 3);
1350
1351 if (board->flags & FL_REGION_SZ_CAP && idx >= maxnr)
1352 return 1;
1353
1354 return setup_port(priv, port, bar, offset, board->reg_shift);
1355}
1356
1332static int 1357static int
1333ce4100_serial_setup(struct serial_private *priv, 1358ce4100_serial_setup(struct serial_private *priv,
1334 const struct pciserial_board *board, 1359 const struct pciserial_board *board,
@@ -2096,6 +2121,16 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
2096 .exit = pci_plx9050_exit, 2121 .exit = pci_plx9050_exit,
2097 }, 2122 },
2098 /* 2123 /*
2124 * Pericom (Only 7954 - It have a offset jump for port 4)
2125 */
2126 {
2127 .vendor = PCI_VENDOR_ID_PERICOM,
2128 .device = PCI_DEVICE_ID_PERICOM_PI7C9X7954,
2129 .subvendor = PCI_ANY_ID,
2130 .subdevice = PCI_ANY_ID,
2131 .setup = pci_pericom_setup,
2132 },
2133 /*
2099 * PLX 2134 * PLX
2100 */ 2135 */
2101 { 2136 {
@@ -3862,6 +3897,7 @@ pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board)
3862 } 3897 }
3863 } 3898 }
3864 priv->nr = i; 3899 priv->nr = i;
3900 priv->board = board;
3865 return priv; 3901 return priv;
3866 3902
3867err_deinit: 3903err_deinit:
@@ -3872,7 +3908,7 @@ err_out:
3872} 3908}
3873EXPORT_SYMBOL_GPL(pciserial_init_ports); 3909EXPORT_SYMBOL_GPL(pciserial_init_ports);
3874 3910
3875void pciserial_remove_ports(struct serial_private *priv) 3911void pciserial_detach_ports(struct serial_private *priv)
3876{ 3912{
3877 struct pci_serial_quirk *quirk; 3913 struct pci_serial_quirk *quirk;
3878 int i; 3914 int i;
@@ -3886,7 +3922,11 @@ void pciserial_remove_ports(struct serial_private *priv)
3886 quirk = find_quirk(priv->dev); 3922 quirk = find_quirk(priv->dev);
3887 if (quirk->exit) 3923 if (quirk->exit)
3888 quirk->exit(priv->dev); 3924 quirk->exit(priv->dev);
3925}
3889 3926
3927void pciserial_remove_ports(struct serial_private *priv)
3928{
3929 pciserial_detach_ports(priv);
3890 kfree(priv); 3930 kfree(priv);
3891} 3931}
3892EXPORT_SYMBOL_GPL(pciserial_remove_ports); 3932EXPORT_SYMBOL_GPL(pciserial_remove_ports);
@@ -5577,7 +5617,7 @@ static pci_ers_result_t serial8250_io_error_detected(struct pci_dev *dev,
5577 return PCI_ERS_RESULT_DISCONNECT; 5617 return PCI_ERS_RESULT_DISCONNECT;
5578 5618
5579 if (priv) 5619 if (priv)
5580 pciserial_suspend_ports(priv); 5620 pciserial_detach_ports(priv);
5581 5621
5582 pci_disable_device(dev); 5622 pci_disable_device(dev);
5583 5623
@@ -5602,9 +5642,18 @@ static pci_ers_result_t serial8250_io_slot_reset(struct pci_dev *dev)
5602static void serial8250_io_resume(struct pci_dev *dev) 5642static void serial8250_io_resume(struct pci_dev *dev)
5603{ 5643{
5604 struct serial_private *priv = pci_get_drvdata(dev); 5644 struct serial_private *priv = pci_get_drvdata(dev);
5645 const struct pciserial_board *board;
5605 5646
5606 if (priv) 5647 if (!priv)
5607 pciserial_resume_ports(priv); 5648 return;
5649
5650 board = priv->board;
5651 kfree(priv);
5652 priv = pciserial_init_ports(dev, board);
5653
5654 if (!IS_ERR(priv)) {
5655 pci_set_drvdata(dev, priv);
5656 }
5608} 5657}
5609 5658
5610static const struct pci_error_handlers serial8250_err_handler = { 5659static const struct pci_error_handlers serial8250_err_handler = {
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 1731b98d2471..fe4399b41df6 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -636,7 +636,7 @@ EXPORT_SYMBOL_GPL(serial8250_em485_destroy);
636 * once and disable_runtime_pm_tx() will still disable RPM because the fifo is 636 * once and disable_runtime_pm_tx() will still disable RPM because the fifo is
637 * empty and the HW can idle again. 637 * empty and the HW can idle again.
638 */ 638 */
639static void serial8250_rpm_get_tx(struct uart_8250_port *p) 639void serial8250_rpm_get_tx(struct uart_8250_port *p)
640{ 640{
641 unsigned char rpm_active; 641 unsigned char rpm_active;
642 642
@@ -648,8 +648,9 @@ static void serial8250_rpm_get_tx(struct uart_8250_port *p)
648 return; 648 return;
649 pm_runtime_get_sync(p->port.dev); 649 pm_runtime_get_sync(p->port.dev);
650} 650}
651EXPORT_SYMBOL_GPL(serial8250_rpm_get_tx);
651 652
652static void serial8250_rpm_put_tx(struct uart_8250_port *p) 653void serial8250_rpm_put_tx(struct uart_8250_port *p)
653{ 654{
654 unsigned char rpm_active; 655 unsigned char rpm_active;
655 656
@@ -662,6 +663,7 @@ static void serial8250_rpm_put_tx(struct uart_8250_port *p)
662 pm_runtime_mark_last_busy(p->port.dev); 663 pm_runtime_mark_last_busy(p->port.dev);
663 pm_runtime_put_autosuspend(p->port.dev); 664 pm_runtime_put_autosuspend(p->port.dev);
664} 665}
666EXPORT_SYMBOL_GPL(serial8250_rpm_put_tx);
665 667
666/* 668/*
667 * IER sleep support. UARTs which have EFRs need the "extended 669 * IER sleep support. UARTs which have EFRs need the "extended
@@ -2691,8 +2693,7 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
2691 serial8250_do_set_termios(port, termios, old); 2693 serial8250_do_set_termios(port, termios, old);
2692} 2694}
2693 2695
2694static void 2696void serial8250_do_set_ldisc(struct uart_port *port, struct ktermios *termios)
2695serial8250_set_ldisc(struct uart_port *port, struct ktermios *termios)
2696{ 2697{
2697 if (termios->c_line == N_PPS) { 2698 if (termios->c_line == N_PPS) {
2698 port->flags |= UPF_HARDPPS_CD; 2699 port->flags |= UPF_HARDPPS_CD;
@@ -2708,7 +2709,16 @@ serial8250_set_ldisc(struct uart_port *port, struct ktermios *termios)
2708 } 2709 }
2709 } 2710 }
2710} 2711}
2712EXPORT_SYMBOL_GPL(serial8250_do_set_ldisc);
2711 2713
2714static void
2715serial8250_set_ldisc(struct uart_port *port, struct ktermios *termios)
2716{
2717 if (port->set_ldisc)
2718 port->set_ldisc(port, termios);
2719 else
2720 serial8250_do_set_ldisc(port, termios);
2721}
2712 2722
2713void serial8250_do_pm(struct uart_port *port, unsigned int state, 2723void serial8250_do_pm(struct uart_port *port, unsigned int state,
2714 unsigned int oldstate) 2724 unsigned int oldstate)
diff --git a/drivers/tty/serial/8250/8250_pxa.c b/drivers/tty/serial/8250/8250_pxa.c
new file mode 100644
index 000000000000..4d68731af534
--- /dev/null
+++ b/drivers/tty/serial/8250/8250_pxa.c
@@ -0,0 +1,190 @@
1/*
2 * drivers/tty/serial/8250/8250_pxa.c -- driver for PXA on-board UARTS
3 * Copyright: (C) 2013 Sergei Ianovich <ynvich@gmail.com>
4 *
5 * replaces drivers/serial/pxa.c by Nicolas Pitre
6 * Created: Feb 20, 2003
7 * Copyright: (C) 2003 Monta Vista Software, Inc.
8 *
9 * Based on drivers/serial/8250.c by Russell King.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 */
17
18#include <linux/device.h>
19#include <linux/init.h>
20#include <linux/io.h>
21#include <linux/module.h>
22#include <linux/serial_8250.h>
23#include <linux/serial_core.h>
24#include <linux/serial_reg.h>
25#include <linux/of.h>
26#include <linux/of_irq.h>
27#include <linux/of_platform.h>
28#include <linux/platform_device.h>
29#include <linux/slab.h>
30#include <linux/clk.h>
31#include <linux/pm_runtime.h>
32
33#include "8250.h"
34
35struct pxa8250_data {
36 int line;
37 struct clk *clk;
38};
39
40static int __maybe_unused serial_pxa_suspend(struct device *dev)
41{
42 struct pxa8250_data *data = dev_get_drvdata(dev);
43
44 serial8250_suspend_port(data->line);
45
46 return 0;
47}
48
49static int __maybe_unused serial_pxa_resume(struct device *dev)
50{
51 struct pxa8250_data *data = dev_get_drvdata(dev);
52
53 serial8250_resume_port(data->line);
54
55 return 0;
56}
57
58static const struct dev_pm_ops serial_pxa_pm_ops = {
59 SET_SYSTEM_SLEEP_PM_OPS(serial_pxa_suspend, serial_pxa_resume)
60};
61
62static const struct of_device_id serial_pxa_dt_ids[] = {
63 { .compatible = "mrvl,pxa-uart", },
64 { .compatible = "mrvl,mmp-uart", },
65 {}
66};
67MODULE_DEVICE_TABLE(of, serial_pxa_dt_ids);
68
69/* Uart divisor latch write */
70static void serial_pxa_dl_write(struct uart_8250_port *up, int value)
71{
72 unsigned int dll;
73
74 serial_out(up, UART_DLL, value & 0xff);
75 /*
76 * work around Erratum #74 according to Marvel(R) PXA270M Processor
77 * Specification Update (April 19, 2010)
78 */
79 dll = serial_in(up, UART_DLL);
80 WARN_ON(dll != (value & 0xff));
81
82 serial_out(up, UART_DLM, value >> 8 & 0xff);
83}
84
85
86static void serial_pxa_pm(struct uart_port *port, unsigned int state,
87 unsigned int oldstate)
88{
89 struct pxa8250_data *data = port->private_data;
90
91 if (!state)
92 clk_prepare_enable(data->clk);
93 else
94 clk_disable_unprepare(data->clk);
95}
96
97static int serial_pxa_probe(struct platform_device *pdev)
98{
99 struct uart_8250_port uart = {};
100 struct pxa8250_data *data;
101 struct resource *mmres, *irqres;
102 int ret;
103
104 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
105 irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
106 if (!mmres || !irqres)
107 return -ENODEV;
108
109 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
110 if (!data)
111 return -ENOMEM;
112
113 data->clk = devm_clk_get(&pdev->dev, NULL);
114 if (IS_ERR(data->clk))
115 return PTR_ERR(data->clk);
116
117 ret = clk_prepare(data->clk);
118 if (ret)
119 return ret;
120
121 uart.port.type = PORT_XSCALE;
122 uart.port.iotype = UPIO_MEM32;
123 uart.port.mapbase = mmres->start;
124 uart.port.regshift = 2;
125 uart.port.irq = irqres->start;
126 uart.port.fifosize = 64;
127 uart.port.flags = UPF_IOREMAP | UPF_SKIP_TEST;
128 uart.port.dev = &pdev->dev;
129 uart.port.uartclk = clk_get_rate(data->clk);
130 uart.port.pm = serial_pxa_pm;
131 uart.port.private_data = data;
132 uart.dl_write = serial_pxa_dl_write;
133
134 ret = serial8250_register_8250_port(&uart);
135 if (ret < 0)
136 goto err_clk;
137
138 data->line = ret;
139
140 platform_set_drvdata(pdev, data);
141
142 return 0;
143
144 err_clk:
145 clk_unprepare(data->clk);
146 return ret;
147}
148
149static int serial_pxa_remove(struct platform_device *pdev)
150{
151 struct pxa8250_data *data = platform_get_drvdata(pdev);
152
153 serial8250_unregister_port(data->line);
154
155 clk_unprepare(data->clk);
156
157 return 0;
158}
159
160static struct platform_driver serial_pxa_driver = {
161 .probe = serial_pxa_probe,
162 .remove = serial_pxa_remove,
163
164 .driver = {
165 .name = "pxa2xx-uart",
166 .pm = &serial_pxa_pm_ops,
167 .of_match_table = serial_pxa_dt_ids,
168 },
169};
170
171module_platform_driver(serial_pxa_driver);
172
173#ifdef CONFIG_SERIAL_8250_CONSOLE
174static int __init early_serial_pxa_setup(struct earlycon_device *device,
175 const char *options)
176{
177 struct uart_port *port = &device->port;
178
179 if (!(device->port.membase || device->port.iobase))
180 return -ENODEV;
181
182 port->regshift = 2;
183 return early_serial8250_setup(device, NULL);
184}
185OF_EARLYCON_DECLARE(early_pxa, "mrvl,pxa-uart", early_serial_pxa_setup);
186#endif
187
188MODULE_AUTHOR("Sergei Ianovich");
189MODULE_LICENSE("GPL");
190MODULE_ALIAS("platform:pxa2xx-uart");
diff --git a/drivers/tty/serial/8250/8250_uniphier.c b/drivers/tty/serial/8250/8250_uniphier.c
index 417d9e7038e1..746680ebf90c 100644
--- a/drivers/tty/serial/8250/8250_uniphier.c
+++ b/drivers/tty/serial/8250/8250_uniphier.c
@@ -24,10 +24,22 @@
24/* Most (but not all) of UniPhier UART devices have 64-depth FIFO. */ 24/* Most (but not all) of UniPhier UART devices have 64-depth FIFO. */
25#define UNIPHIER_UART_DEFAULT_FIFO_SIZE 64 25#define UNIPHIER_UART_DEFAULT_FIFO_SIZE 64
26 26
27#define UNIPHIER_UART_CHAR_FCR 3 /* Character / FIFO Control Register */ 27/*
28#define UNIPHIER_UART_LCR_MCR 4 /* Line/Modem Control Register */ 28 * This hardware is similar to 8250, but its register map is a bit different:
29#define UNIPHIER_UART_LCR_SHIFT 8 29 * - MMIO32 (regshift = 2)
30#define UNIPHIER_UART_DLR 9 /* Divisor Latch Register */ 30 * - FCR is not at 2, but 3
31 * - LCR and MCR are not at 3 and 4, they share 4
32 * - Divisor latch at 9, no divisor latch access bit
33 */
34
35#define UNIPHIER_UART_REGSHIFT 2
36
37/* bit[15:8] = CHAR (not used), bit[7:0] = FCR */
38#define UNIPHIER_UART_CHAR_FCR (3 << (UNIPHIER_UART_REGSHIFT))
39/* bit[15:8] = LCR, bit[7:0] = MCR */
40#define UNIPHIER_UART_LCR_MCR (4 << (UNIPHIER_UART_REGSHIFT))
41/* Divisor Latch Register */
42#define UNIPHIER_UART_DLR (9 << (UNIPHIER_UART_REGSHIFT))
31 43
32struct uniphier8250_priv { 44struct uniphier8250_priv {
33 int line; 45 int line;
@@ -44,7 +56,7 @@ static int __init uniphier_early_console_setup(struct earlycon_device *device,
44 56
45 /* This hardware always expects MMIO32 register interface. */ 57 /* This hardware always expects MMIO32 register interface. */
46 device->port.iotype = UPIO_MEM32; 58 device->port.iotype = UPIO_MEM32;
47 device->port.regshift = 2; 59 device->port.regshift = UNIPHIER_UART_REGSHIFT;
48 60
49 /* 61 /*
50 * Do not touch the divisor register in early_serial8250_setup(); 62 * Do not touch the divisor register in early_serial8250_setup();
@@ -68,17 +80,16 @@ static unsigned int uniphier_serial_in(struct uart_port *p, int offset)
68 80
69 switch (offset) { 81 switch (offset) {
70 case UART_LCR: 82 case UART_LCR:
71 valshift = UNIPHIER_UART_LCR_SHIFT; 83 valshift = 8;
72 /* fall through */ 84 /* fall through */
73 case UART_MCR: 85 case UART_MCR:
74 offset = UNIPHIER_UART_LCR_MCR; 86 offset = UNIPHIER_UART_LCR_MCR;
75 break; 87 break;
76 default: 88 default:
89 offset <<= UNIPHIER_UART_REGSHIFT;
77 break; 90 break;
78 } 91 }
79 92
80 offset <<= p->regshift;
81
82 /* 93 /*
83 * The return value must be masked with 0xff because LCR and MCR reside 94 * The return value must be masked with 0xff because LCR and MCR reside
84 * in the same register that must be accessed by 32-bit write/read. 95 * in the same register that must be accessed by 32-bit write/read.
@@ -90,27 +101,26 @@ static unsigned int uniphier_serial_in(struct uart_port *p, int offset)
90static void uniphier_serial_out(struct uart_port *p, int offset, int value) 101static void uniphier_serial_out(struct uart_port *p, int offset, int value)
91{ 102{
92 unsigned int valshift = 0; 103 unsigned int valshift = 0;
93 bool normal = false; 104 bool normal = true;
94 105
95 switch (offset) { 106 switch (offset) {
96 case UART_FCR: 107 case UART_FCR:
97 offset = UNIPHIER_UART_CHAR_FCR; 108 offset = UNIPHIER_UART_CHAR_FCR;
98 break; 109 break;
99 case UART_LCR: 110 case UART_LCR:
100 valshift = UNIPHIER_UART_LCR_SHIFT; 111 valshift = 8;
101 /* Divisor latch access bit does not exist. */ 112 /* Divisor latch access bit does not exist. */
102 value &= ~UART_LCR_DLAB; 113 value &= ~UART_LCR_DLAB;
103 /* fall through */ 114 /* fall through */
104 case UART_MCR: 115 case UART_MCR:
105 offset = UNIPHIER_UART_LCR_MCR; 116 offset = UNIPHIER_UART_LCR_MCR;
117 normal = false;
106 break; 118 break;
107 default: 119 default:
108 normal = true; 120 offset <<= UNIPHIER_UART_REGSHIFT;
109 break; 121 break;
110 } 122 }
111 123
112 offset <<= p->regshift;
113
114 if (normal) { 124 if (normal) {
115 writel(value, p->membase + offset); 125 writel(value, p->membase + offset);
116 } else { 126 } else {
@@ -139,16 +149,12 @@ static void uniphier_serial_out(struct uart_port *p, int offset, int value)
139 */ 149 */
140static int uniphier_serial_dl_read(struct uart_8250_port *up) 150static int uniphier_serial_dl_read(struct uart_8250_port *up)
141{ 151{
142 int offset = UNIPHIER_UART_DLR << up->port.regshift; 152 return readl(up->port.membase + UNIPHIER_UART_DLR);
143
144 return readl(up->port.membase + offset);
145} 153}
146 154
147static void uniphier_serial_dl_write(struct uart_8250_port *up, int value) 155static void uniphier_serial_dl_write(struct uart_8250_port *up, int value)
148{ 156{
149 int offset = UNIPHIER_UART_DLR << up->port.regshift; 157 writel(value, up->port.membase + UNIPHIER_UART_DLR);
150
151 writel(value, up->port.membase + offset);
152} 158}
153 159
154static int uniphier_of_serial_setup(struct device *dev, struct uart_port *port, 160static int uniphier_of_serial_setup(struct device *dev, struct uart_port *port,
@@ -234,7 +240,7 @@ static int uniphier_uart_probe(struct platform_device *pdev)
234 240
235 up.port.type = PORT_16550A; 241 up.port.type = PORT_16550A;
236 up.port.iotype = UPIO_MEM32; 242 up.port.iotype = UPIO_MEM32;
237 up.port.regshift = 2; 243 up.port.regshift = UNIPHIER_UART_REGSHIFT;
238 up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE; 244 up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE;
239 up.capabilities = UART_CAP_FIFO; 245 up.capabilities = UART_CAP_FIFO;
240 246
diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig
index 899834776b36..0b8b6740ba43 100644
--- a/drivers/tty/serial/8250/Kconfig
+++ b/drivers/tty/serial/8250/Kconfig
@@ -439,6 +439,16 @@ config SERIAL_8250_MOXA
439 This driver can also be built as a module. The module will be called 439 This driver can also be built as a module. The module will be called
440 8250_moxa. If you want to do that, say M here. 440 8250_moxa. If you want to do that, say M here.
441 441
442config SERIAL_8250_PXA
443 tristate "PXA serial port support"
444 depends on SERIAL_8250
445 depends on ARCH_PXA || ARCH_MMP
446 help
447 If you have a machine based on an Intel XScale PXA2xx CPU you can
448 enable its onboard serial ports by enabling this option. The option is
449 applicable to both devicetree and legacy boards, and early console is
450 part of its support.
451
442config SERIAL_OF_PLATFORM 452config SERIAL_OF_PLATFORM
443 tristate "Devicetree based probing for 8250 ports" 453 tristate "Devicetree based probing for 8250 ports"
444 depends on SERIAL_8250 && OF 454 depends on SERIAL_8250 && OF
diff --git a/drivers/tty/serial/8250/Makefile b/drivers/tty/serial/8250/Makefile
index 276c6fb60337..850e721877a9 100644
--- a/drivers/tty/serial/8250/Makefile
+++ b/drivers/tty/serial/8250/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_SERIAL_8250_INGENIC) += 8250_ingenic.o
31obj-$(CONFIG_SERIAL_8250_LPSS) += 8250_lpss.o 31obj-$(CONFIG_SERIAL_8250_LPSS) += 8250_lpss.o
32obj-$(CONFIG_SERIAL_8250_MID) += 8250_mid.o 32obj-$(CONFIG_SERIAL_8250_MID) += 8250_mid.o
33obj-$(CONFIG_SERIAL_8250_MOXA) += 8250_moxa.o 33obj-$(CONFIG_SERIAL_8250_MOXA) += 8250_moxa.o
34obj-$(CONFIG_SERIAL_8250_PXA) += 8250_pxa.o
34obj-$(CONFIG_SERIAL_OF_PLATFORM) += 8250_of.o 35obj-$(CONFIG_SERIAL_OF_PLATFORM) += 8250_of.o
35 36
36CFLAGS_8250_ingenic.o += -I$(srctree)/scripts/dtc/libfdt 37CFLAGS_8250_ingenic.o += -I$(srctree)/scripts/dtc/libfdt
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 25c1d7bc0100..e9cf5b67f1b7 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -438,17 +438,27 @@ config SERIAL_MPSC_CONSOLE
438 Say Y here if you want to support a serial console on a Marvell MPSC. 438 Say Y here if you want to support a serial console on a Marvell MPSC.
439 439
440config SERIAL_PXA 440config SERIAL_PXA
441 bool "PXA serial port support" 441 bool "PXA serial port support (DEPRECATED)"
442 depends on ARCH_PXA || ARCH_MMP 442 depends on ARCH_PXA || ARCH_MMP
443 select SERIAL_CORE 443 select SERIAL_CORE
444 select SERIAL_8250_PXA if SERIAL_8250=y
445 select SERIAL_PXA_NON8250 if !SERIAL_8250=y
444 help 446 help
445 If you have a machine based on an Intel XScale PXA2xx CPU you 447 If you have a machine based on an Intel XScale PXA2xx CPU you
446 can enable its onboard serial ports by enabling this option. 448 can enable its onboard serial ports by enabling this option.
447 449
450 Unless you have a specific need, you should use SERIAL_8250_PXA
451 instead of this.
452
453config SERIAL_PXA_NON8250
454 bool
455 depends on !SERIAL_8250
456
448config SERIAL_PXA_CONSOLE 457config SERIAL_PXA_CONSOLE
449 bool "Console on PXA serial port" 458 bool "Console on PXA serial port (DEPRECATED)"
450 depends on SERIAL_PXA 459 depends on SERIAL_PXA
451 select SERIAL_CORE_CONSOLE 460 select SERIAL_CORE_CONSOLE
461 select SERIAL_8250_CONSOLE if SERIAL_8250=y
452 help 462 help
453 If you have enabled the serial port on the Intel XScale PXA 463 If you have enabled the serial port on the Intel XScale PXA
454 CPU you can make it the console by answering Y to this option. 464 CPU you can make it the console by answering Y to this option.
@@ -460,6 +470,9 @@ config SERIAL_PXA_CONSOLE
460 your boot loader (lilo or loadlin) about how to pass options to the 470 your boot loader (lilo or loadlin) about how to pass options to the
461 kernel at boot time.) 471 kernel at boot time.)
462 472
473 Unless you have a specific need, you should use SERIAL_8250_PXA
474 and SERIAL_8250_CONSOLE instead of this.
475
463config SERIAL_SA1100 476config SERIAL_SA1100
464 bool "SA1100 serial port support" 477 bool "SA1100 serial port support"
465 depends on ARCH_SA1100 478 depends on ARCH_SA1100
@@ -1626,7 +1639,7 @@ config SERIAL_STM32
1626 tristate "STMicroelectronics STM32 serial port support" 1639 tristate "STMicroelectronics STM32 serial port support"
1627 select SERIAL_CORE 1640 select SERIAL_CORE
1628 depends on HAS_DMA 1641 depends on HAS_DMA
1629 depends on ARM || COMPILE_TEST 1642 depends on ARCH_STM32 || COMPILE_TEST
1630 help 1643 help
1631 This driver is for the on-chip Serial Controller on 1644 This driver is for the on-chip Serial Controller on
1632 STMicroelectronics STM32 MCUs. 1645 STMicroelectronics STM32 MCUs.
diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
index 1278d376da50..2d6288bc4554 100644
--- a/drivers/tty/serial/Makefile
+++ b/drivers/tty/serial/Makefile
@@ -23,7 +23,7 @@ obj-$(CONFIG_SERIAL_8250) += 8250/
23obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o 23obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o
24obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o 24obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o
25obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o 25obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o
26obj-$(CONFIG_SERIAL_PXA) += pxa.o 26obj-$(CONFIG_SERIAL_PXA_NON8250) += pxa.o
27obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o 27obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
28obj-$(CONFIG_SERIAL_SA1100) += sa1100.o 28obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
29obj-$(CONFIG_SERIAL_BCM63XX) += bcm63xx_uart.o 29obj-$(CONFIG_SERIAL_BCM63XX) += bcm63xx_uart.o
@@ -62,13 +62,11 @@ obj-$(CONFIG_SERIAL_ATMEL) += atmel_serial.o
62obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o 62obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
63obj-$(CONFIG_SERIAL_MSM) += msm_serial.o 63obj-$(CONFIG_SERIAL_MSM) += msm_serial.o
64obj-$(CONFIG_SERIAL_NETX) += netx-serial.o 64obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
65obj-$(CONFIG_SERIAL_KGDB_NMI) += kgdb_nmi.o
66obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o 65obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
67obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o 66obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o
68obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o 67obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o
69obj-$(CONFIG_SERIAL_ST_ASC) += st-asc.o 68obj-$(CONFIG_SERIAL_ST_ASC) += st-asc.o
70obj-$(CONFIG_SERIAL_TILEGX) += tilegx.o 69obj-$(CONFIG_SERIAL_TILEGX) += tilegx.o
71obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
72obj-$(CONFIG_SERIAL_QE) += ucc_uart.o 70obj-$(CONFIG_SERIAL_QE) += ucc_uart.o
73obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o 71obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o
74obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o 72obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o
@@ -96,3 +94,6 @@ obj-$(CONFIG_SERIAL_MPS2_UART) += mps2-uart.o
96 94
97# GPIOLIB helpers for modem control lines 95# GPIOLIB helpers for modem control lines
98obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o 96obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
97
98obj-$(CONFIG_SERIAL_KGDB_NMI) += kgdb_nmi.o
99obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index e2c33b9528d8..d4171d71a258 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -2315,12 +2315,67 @@ static int __init pl011_console_setup(struct console *co, char *options)
2315 return uart_set_options(&uap->port, co, baud, parity, bits, flow); 2315 return uart_set_options(&uap->port, co, baud, parity, bits, flow);
2316} 2316}
2317 2317
2318/**
2319 * pl011_console_match - non-standard console matching
2320 * @co: registering console
2321 * @name: name from console command line
2322 * @idx: index from console command line
2323 * @options: ptr to option string from console command line
2324 *
2325 * Only attempts to match console command lines of the form:
2326 * console=pl011,mmio|mmio32,<addr>[,<options>]
2327 * console=pl011,0x<addr>[,<options>]
2328 * This form is used to register an initial earlycon boot console and
2329 * replace it with the amba_console at pl011 driver init.
2330 *
2331 * Performs console setup for a match (as required by interface)
2332 * If no <options> are specified, then assume the h/w is already setup.
2333 *
2334 * Returns 0 if console matches; otherwise non-zero to use default matching
2335 */
2336static int __init pl011_console_match(struct console *co, char *name, int idx,
2337 char *options)
2338{
2339 unsigned char iotype;
2340 resource_size_t addr;
2341 int i;
2342
2343 if (strcmp(name, "pl011") != 0)
2344 return -ENODEV;
2345
2346 if (uart_parse_earlycon(options, &iotype, &addr, &options))
2347 return -ENODEV;
2348
2349 if (iotype != UPIO_MEM && iotype != UPIO_MEM32)
2350 return -ENODEV;
2351
2352 /* try to match the port specified on the command line */
2353 for (i = 0; i < ARRAY_SIZE(amba_ports); i++) {
2354 struct uart_port *port;
2355
2356 if (!amba_ports[i])
2357 continue;
2358
2359 port = &amba_ports[i]->port;
2360
2361 if (port->mapbase != addr)
2362 continue;
2363
2364 co->index = i;
2365 port->cons = co;
2366 return pl011_console_setup(co, options);
2367 }
2368
2369 return -ENODEV;
2370}
2371
2318static struct uart_driver amba_reg; 2372static struct uart_driver amba_reg;
2319static struct console amba_console = { 2373static struct console amba_console = {
2320 .name = "ttyAMA", 2374 .name = "ttyAMA",
2321 .write = pl011_console_write, 2375 .write = pl011_console_write,
2322 .device = uart_console_device, 2376 .device = uart_console_device,
2323 .setup = pl011_console_setup, 2377 .setup = pl011_console_setup,
2378 .match = pl011_console_match,
2324 .flags = CON_PRINTBUFFER, 2379 .flags = CON_PRINTBUFFER,
2325 .index = -1, 2380 .index = -1,
2326 .data = &amba_reg, 2381 .data = &amba_reg,
@@ -2357,6 +2412,7 @@ static int __init pl011_early_console_setup(struct earlycon_device *device,
2357 return 0; 2412 return 0;
2358} 2413}
2359OF_EARLYCON_DECLARE(pl011, "arm,pl011", pl011_early_console_setup); 2414OF_EARLYCON_DECLARE(pl011, "arm,pl011", pl011_early_console_setup);
2415OF_EARLYCON_DECLARE(pl011, "arm,sbsa-uart", pl011_early_console_setup);
2360 2416
2361#else 2417#else
2362#define AMBA_CONSOLE NULL 2418#define AMBA_CONSOLE NULL
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c
index 6450a38cb1aa..e92c23470e51 100644
--- a/drivers/tty/serial/crisv10.c
+++ b/drivers/tty/serial/crisv10.c
@@ -3213,8 +3213,6 @@ get_serial_info(struct e100_serial * info,
3213 * should set them to something else than 0. 3213 * should set them to something else than 0.
3214 */ 3214 */
3215 3215
3216 if (!retinfo)
3217 return -EFAULT;
3218 memset(&tmp, 0, sizeof(tmp)); 3216 memset(&tmp, 0, sizeof(tmp));
3219 tmp.type = info->type; 3217 tmp.type = info->type;
3220 tmp.line = info->line; 3218 tmp.line = info->line;
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 76103f2c4a80..a1c6519837a4 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -430,6 +430,65 @@ static void lpuart_flush_buffer(struct uart_port *port)
430 } 430 }
431} 431}
432 432
433#if defined(CONFIG_CONSOLE_POLL)
434
435static int lpuart_poll_init(struct uart_port *port)
436{
437 struct lpuart_port *sport = container_of(port,
438 struct lpuart_port, port);
439 unsigned long flags;
440 unsigned char temp;
441
442 sport->port.fifosize = 0;
443
444 spin_lock_irqsave(&sport->port.lock, flags);
445 /* Disable Rx & Tx */
446 writeb(0, sport->port.membase + UARTCR2);
447
448 temp = readb(sport->port.membase + UARTPFIFO);
449 /* Enable Rx and Tx FIFO */
450 writeb(temp | UARTPFIFO_RXFE | UARTPFIFO_TXFE,
451 sport->port.membase + UARTPFIFO);
452
453 /* flush Tx and Rx FIFO */
454 writeb(UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH,
455 sport->port.membase + UARTCFIFO);
456
457 /* explicitly clear RDRF */
458 if (readb(sport->port.membase + UARTSR1) & UARTSR1_RDRF) {
459 readb(sport->port.membase + UARTDR);
460 writeb(UARTSFIFO_RXUF, sport->port.membase + UARTSFIFO);
461 }
462
463 writeb(0, sport->port.membase + UARTTWFIFO);
464 writeb(1, sport->port.membase + UARTRWFIFO);
465
466 /* Enable Rx and Tx */
467 writeb(UARTCR2_RE | UARTCR2_TE, sport->port.membase + UARTCR2);
468 spin_unlock_irqrestore(&sport->port.lock, flags);
469
470 return 0;
471}
472
473static void lpuart_poll_put_char(struct uart_port *port, unsigned char c)
474{
475 /* drain */
476 while (!(readb(port->membase + UARTSR1) & UARTSR1_TDRE))
477 barrier();
478
479 writeb(c, port->membase + UARTDR);
480}
481
482static int lpuart_poll_get_char(struct uart_port *port)
483{
484 if (!(readb(port->membase + UARTSR1) & UARTSR1_RDRF))
485 return NO_POLL_CHAR;
486
487 return readb(port->membase + UARTDR);
488}
489
490#endif
491
433static inline void lpuart_transmit_buffer(struct lpuart_port *sport) 492static inline void lpuart_transmit_buffer(struct lpuart_port *sport)
434{ 493{
435 struct circ_buf *xmit = &sport->port.state->xmit; 494 struct circ_buf *xmit = &sport->port.state->xmit;
@@ -1595,6 +1654,11 @@ static const struct uart_ops lpuart_pops = {
1595 .config_port = lpuart_config_port, 1654 .config_port = lpuart_config_port,
1596 .verify_port = lpuart_verify_port, 1655 .verify_port = lpuart_verify_port,
1597 .flush_buffer = lpuart_flush_buffer, 1656 .flush_buffer = lpuart_flush_buffer,
1657#if defined(CONFIG_CONSOLE_POLL)
1658 .poll_init = lpuart_poll_init,
1659 .poll_get_char = lpuart_poll_get_char,
1660 .poll_put_char = lpuart_poll_put_char,
1661#endif
1598}; 1662};
1599 1663
1600static const struct uart_ops lpuart32_pops = { 1664static const struct uart_ops lpuart32_pops = {
diff --git a/drivers/tty/serial/ifx6x60.c b/drivers/tty/serial/ifx6x60.c
index d386346248de..157883653256 100644
--- a/drivers/tty/serial/ifx6x60.c
+++ b/drivers/tty/serial/ifx6x60.c
@@ -1042,6 +1042,7 @@ static int ifx_spi_spi_probe(struct spi_device *spi)
1042 ret = spi_setup(spi); 1042 ret = spi_setup(spi);
1043 if (ret) { 1043 if (ret) {
1044 dev_err(&spi->dev, "SPI setup wasn't successful %d", ret); 1044 dev_err(&spi->dev, "SPI setup wasn't successful %d", ret);
1045 kfree(ifx_dev);
1045 return -ENODEV; 1046 return -ENODEV;
1046 } 1047 }
1047 1048
diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
index e5c42fef69d2..3be051abb2a2 100644
--- a/drivers/tty/serial/ioc4_serial.c
+++ b/drivers/tty/serial/ioc4_serial.c
@@ -1082,7 +1082,7 @@ static int inline ioc4_attach_local(struct ioc4_driver_data *idd)
1082 if (!port) { 1082 if (!port) {
1083 printk(KERN_WARNING 1083 printk(KERN_WARNING
1084 "IOC4 serial memory not available for port\n"); 1084 "IOC4 serial memory not available for port\n");
1085 return -ENOMEM; 1085 goto free;
1086 } 1086 }
1087 spin_lock_init(&port->ip_lock); 1087 spin_lock_init(&port->ip_lock);
1088 1088
@@ -1190,6 +1190,11 @@ static int inline ioc4_attach_local(struct ioc4_driver_data *idd)
1190 handle_dma_error_intr, port); 1190 handle_dma_error_intr, port);
1191 } 1191 }
1192 return 0; 1192 return 0;
1193
1194free:
1195 while (port_number)
1196 kfree(ports[--port_number]);
1197 return -ENOMEM;
1193} 1198}
1194 1199
1195/** 1200/**
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index 770454e0dfa3..8c1c9112b3fd 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -1016,7 +1016,7 @@ static void mxs_auart_settermios(struct uart_port *u,
1016 ctrl |= AUART_LINECTRL_EPS; 1016 ctrl |= AUART_LINECTRL_EPS;
1017 } 1017 }
1018 1018
1019 u->read_status_mask = 0; 1019 u->read_status_mask = AUART_STAT_OERR;
1020 1020
1021 if (termios->c_iflag & INPCK) 1021 if (termios->c_iflag & INPCK)
1022 u->read_status_mask |= AUART_STAT_PERR; 1022 u->read_status_mask |= AUART_STAT_PERR;
diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c
index cd9d9e878475..75952811c0da 100644
--- a/drivers/tty/serial/pxa.c
+++ b/drivers/tty/serial/pxa.c
@@ -925,6 +925,8 @@ static struct platform_driver serial_pxa_driver = {
925 }, 925 },
926}; 926};
927 927
928
929/* 8250 driver for PXA serial ports should be used */
928static int __init serial_pxa_init(void) 930static int __init serial_pxa_init(void)
929{ 931{
930 int ret; 932 int ret;
diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index fb0672554123..793395451982 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -1264,7 +1264,7 @@ static int sc16is7xx_probe(struct device *dev,
1264 1264
1265 /* Setup interrupt */ 1265 /* Setup interrupt */
1266 ret = devm_request_irq(dev, irq, sc16is7xx_irq, 1266 ret = devm_request_irq(dev, irq, sc16is7xx_irq,
1267 IRQF_ONESHOT | flags, dev_name(dev), s); 1267 flags, dev_name(dev), s);
1268 if (!ret) 1268 if (!ret)
1269 return 0; 1269 return 0;
1270 1270
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index f2303f390345..d0847375ea64 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -73,7 +73,7 @@ static inline struct uart_port *uart_port_ref(struct uart_state *state)
73 73
74static inline void uart_port_deref(struct uart_port *uport) 74static inline void uart_port_deref(struct uart_port *uport)
75{ 75{
76 if (uport && atomic_dec_and_test(&uport->state->refcount)) 76 if (atomic_dec_and_test(&uport->state->refcount))
77 wake_up(&uport->state->remove_wait); 77 wake_up(&uport->state->remove_wait);
78} 78}
79 79
@@ -88,9 +88,10 @@ static inline void uart_port_deref(struct uart_port *uport)
88#define uart_port_unlock(uport, flags) \ 88#define uart_port_unlock(uport, flags) \
89 ({ \ 89 ({ \
90 struct uart_port *__uport = uport; \ 90 struct uart_port *__uport = uport; \
91 if (__uport) \ 91 if (__uport) { \
92 spin_unlock_irqrestore(&__uport->lock, flags); \ 92 spin_unlock_irqrestore(&__uport->lock, flags); \
93 uart_port_deref(__uport); \ 93 uart_port_deref(__uport); \
94 } \
94 }) 95 })
95 96
96static inline struct uart_port *uart_port_check(struct uart_state *state) 97static inline struct uart_port *uart_port_check(struct uart_state *state)
@@ -1515,7 +1516,10 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1515 unsigned long char_time, expire; 1516 unsigned long char_time, expire;
1516 1517
1517 port = uart_port_ref(state); 1518 port = uart_port_ref(state);
1518 if (!port || port->type == PORT_UNKNOWN || port->fifosize == 0) { 1519 if (!port)
1520 return;
1521
1522 if (port->type == PORT_UNKNOWN || port->fifosize == 0) {
1519 uart_port_deref(port); 1523 uart_port_deref(port);
1520 return; 1524 return;
1521 } 1525 }
@@ -2365,9 +2369,10 @@ static int uart_poll_get_char(struct tty_driver *driver, int line)
2365 2369
2366 if (state) { 2370 if (state) {
2367 port = uart_port_ref(state); 2371 port = uart_port_ref(state);
2368 if (port) 2372 if (port) {
2369 ret = port->ops->poll_get_char(port); 2373 ret = port->ops->poll_get_char(port);
2370 uart_port_deref(port); 2374 uart_port_deref(port);
2375 }
2371 } 2376 }
2372 return ret; 2377 return ret;
2373} 2378}
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 4b26252c2885..91e7dddbf72c 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1142,11 +1142,8 @@ static int sci_dma_rx_push(struct sci_port *s, void *buf, size_t count)
1142 int copied; 1142 int copied;
1143 1143
1144 copied = tty_insert_flip_string(tport, buf, count); 1144 copied = tty_insert_flip_string(tport, buf, count);
1145 if (copied < count) { 1145 if (copied < count)
1146 dev_warn(port->dev, "Rx overrun: dropping %zu bytes\n",
1147 count - copied);
1148 port->icount.buf_overrun++; 1146 port->icount.buf_overrun++;
1149 }
1150 1147
1151 port->icount.rx += copied; 1148 port->icount.rx += copied;
1152 1149
@@ -1161,8 +1158,6 @@ static int sci_dma_rx_find_active(struct sci_port *s)
1161 if (s->active_rx == s->cookie_rx[i]) 1158 if (s->active_rx == s->cookie_rx[i])
1162 return i; 1159 return i;
1163 1160
1164 dev_err(s->port.dev, "%s: Rx cookie %d not found!\n", __func__,
1165 s->active_rx);
1166 return -1; 1161 return -1;
1167} 1162}
1168 1163
@@ -1223,9 +1218,9 @@ static void sci_dma_rx_complete(void *arg)
1223 1218
1224 dma_async_issue_pending(chan); 1219 dma_async_issue_pending(chan);
1225 1220
1221 spin_unlock_irqrestore(&port->lock, flags);
1226 dev_dbg(port->dev, "%s: cookie %d #%d, new active cookie %d\n", 1222 dev_dbg(port->dev, "%s: cookie %d #%d, new active cookie %d\n",
1227 __func__, s->cookie_rx[active], active, s->active_rx); 1223 __func__, s->cookie_rx[active], active, s->active_rx);
1228 spin_unlock_irqrestore(&port->lock, flags);
1229 return; 1224 return;
1230 1225
1231fail: 1226fail:
@@ -1273,8 +1268,6 @@ static void sci_submit_rx(struct sci_port *s)
1273 if (dma_submit_error(s->cookie_rx[i])) 1268 if (dma_submit_error(s->cookie_rx[i]))
1274 goto fail; 1269 goto fail;
1275 1270
1276 dev_dbg(s->port.dev, "%s(): cookie %d to #%d\n", __func__,
1277 s->cookie_rx[i], i);
1278 } 1271 }
1279 1272
1280 s->active_rx = s->cookie_rx[0]; 1273 s->active_rx = s->cookie_rx[0];
@@ -1288,7 +1281,6 @@ fail:
1288 for (i = 0; i < 2; i++) 1281 for (i = 0; i < 2; i++)
1289 s->cookie_rx[i] = -EINVAL; 1282 s->cookie_rx[i] = -EINVAL;
1290 s->active_rx = -EINVAL; 1283 s->active_rx = -EINVAL;
1291 dev_warn(s->port.dev, "Failed to re-start Rx DMA, using PIO\n");
1292 sci_rx_dma_release(s, true); 1284 sci_rx_dma_release(s, true);
1293} 1285}
1294 1286
@@ -1358,10 +1350,10 @@ static void rx_timer_fn(unsigned long arg)
1358 int active, count; 1350 int active, count;
1359 u16 scr; 1351 u16 scr;
1360 1352
1361 spin_lock_irqsave(&port->lock, flags);
1362
1363 dev_dbg(port->dev, "DMA Rx timed out\n"); 1353 dev_dbg(port->dev, "DMA Rx timed out\n");
1364 1354
1355 spin_lock_irqsave(&port->lock, flags);
1356
1365 active = sci_dma_rx_find_active(s); 1357 active = sci_dma_rx_find_active(s);
1366 if (active < 0) { 1358 if (active < 0) {
1367 spin_unlock_irqrestore(&port->lock, flags); 1359 spin_unlock_irqrestore(&port->lock, flags);
@@ -1370,9 +1362,9 @@ static void rx_timer_fn(unsigned long arg)
1370 1362
1371 status = dmaengine_tx_status(s->chan_rx, s->active_rx, &state); 1363 status = dmaengine_tx_status(s->chan_rx, s->active_rx, &state);
1372 if (status == DMA_COMPLETE) { 1364 if (status == DMA_COMPLETE) {
1365 spin_unlock_irqrestore(&port->lock, flags);
1373 dev_dbg(port->dev, "Cookie %d #%d has already completed\n", 1366 dev_dbg(port->dev, "Cookie %d #%d has already completed\n",
1374 s->active_rx, active); 1367 s->active_rx, active);
1375 spin_unlock_irqrestore(&port->lock, flags);
1376 1368
1377 /* Let packet complete handler take care of the packet */ 1369 /* Let packet complete handler take care of the packet */
1378 return; 1370 return;
@@ -1396,8 +1388,6 @@ static void rx_timer_fn(unsigned long arg)
1396 /* Handle incomplete DMA receive */ 1388 /* Handle incomplete DMA receive */
1397 dmaengine_terminate_all(s->chan_rx); 1389 dmaengine_terminate_all(s->chan_rx);
1398 read = sg_dma_len(&s->sg_rx[active]) - state.residue; 1390 read = sg_dma_len(&s->sg_rx[active]) - state.residue;
1399 dev_dbg(port->dev, "Read %u bytes with cookie %d\n", read,
1400 s->active_rx);
1401 1391
1402 if (read) { 1392 if (read) {
1403 count = sci_dma_rx_push(s, s->rx_buf[active], read); 1393 count = sci_dma_rx_push(s, s->rx_buf[active], read);
diff --git a/drivers/tty/serial/sunhv.c b/drivers/tty/serial/sunhv.c
index 4e603d060e80..99ef5c6e4766 100644
--- a/drivers/tty/serial/sunhv.c
+++ b/drivers/tty/serial/sunhv.c
@@ -598,7 +598,8 @@ static int hv_remove(struct platform_device *dev)
598 uart_remove_one_port(&sunhv_reg, port); 598 uart_remove_one_port(&sunhv_reg, port);
599 599
600 sunserial_unregister_minors(&sunhv_reg, 1); 600 sunserial_unregister_minors(&sunhv_reg, 1);
601 601 kfree(con_read_page);
602 kfree(con_write_page);
602 kfree(port); 603 kfree(port);
603 sunhv_port = NULL; 604 sunhv_port = NULL;
604 605
diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c
index 9ad98eaa35bf..72df2e1b88af 100644
--- a/drivers/tty/serial/sunsu.c
+++ b/drivers/tty/serial/sunsu.c
@@ -1500,6 +1500,7 @@ static int su_probe(struct platform_device *op)
1500 1500
1501out_unmap: 1501out_unmap:
1502 of_iounmap(&op->resource[0], up->port.membase, up->reg_size); 1502 of_iounmap(&op->resource[0], up->port.membase, up->reg_size);
1503 kfree(up);
1503 return err; 1504 return err;
1504} 1505}
1505 1506
diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
index 9d7ab7b66a8a..71e81406ef71 100644
--- a/drivers/tty/vt/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
@@ -9,6 +9,17 @@
9 * Support for multiple unimaps by Jakub Jelinek <jj@ultra.linux.cz>, July 1998 9 * Support for multiple unimaps by Jakub Jelinek <jj@ultra.linux.cz>, July 1998
10 * 10 *
11 * Fix bug in inverse translation. Stanislav Voronyi <stas@cnti.uanet.kharkov.ua>, Dec 1998 11 * Fix bug in inverse translation. Stanislav Voronyi <stas@cnti.uanet.kharkov.ua>, Dec 1998
12 *
13 * In order to prevent the following circular lock dependency:
14 * &mm->mmap_sem --> cpu_hotplug.lock --> console_lock --> &mm->mmap_sem
15 *
16 * We cannot allow page fault to happen while holding the console_lock.
17 * Therefore, all the userspace copy operations have to be done outside
18 * the console_lock critical sections.
19 *
20 * As all the affected functions are all called directly from vt_ioctl(), we
21 * can allocate some small buffers directly on stack without worrying about
22 * stack overflow.
12 */ 23 */
13 24
14#include <linux/module.h> 25#include <linux/module.h>
@@ -22,6 +33,7 @@
22#include <linux/console.h> 33#include <linux/console.h>
23#include <linux/consolemap.h> 34#include <linux/consolemap.h>
24#include <linux/vt_kern.h> 35#include <linux/vt_kern.h>
36#include <linux/string.h>
25 37
26static unsigned short translations[][256] = { 38static unsigned short translations[][256] = {
27 /* 8-bit Latin-1 mapped to Unicode -- trivial mapping */ 39 /* 8-bit Latin-1 mapped to Unicode -- trivial mapping */
@@ -309,18 +321,19 @@ static void update_user_maps(void)
309int con_set_trans_old(unsigned char __user * arg) 321int con_set_trans_old(unsigned char __user * arg)
310{ 322{
311 int i; 323 int i;
312 unsigned short *p = translations[USER_MAP]; 324 unsigned short inbuf[E_TABSZ];
313 325
314 if (!access_ok(VERIFY_READ, arg, E_TABSZ)) 326 if (!access_ok(VERIFY_READ, arg, E_TABSZ))
315 return -EFAULT; 327 return -EFAULT;
316 328
317 console_lock(); 329 for (i = 0; i < E_TABSZ ; i++) {
318 for (i=0; i<E_TABSZ ; i++) {
319 unsigned char uc; 330 unsigned char uc;
320 __get_user(uc, arg+i); 331 __get_user(uc, arg+i);
321 p[i] = UNI_DIRECT_BASE | uc; 332 inbuf[i] = UNI_DIRECT_BASE | uc;
322 } 333 }
323 334
335 console_lock();
336 memcpy(translations[USER_MAP], inbuf, sizeof(inbuf));
324 update_user_maps(); 337 update_user_maps();
325 console_unlock(); 338 console_unlock();
326 return 0; 339 return 0;
@@ -330,35 +343,37 @@ int con_get_trans_old(unsigned char __user * arg)
330{ 343{
331 int i, ch; 344 int i, ch;
332 unsigned short *p = translations[USER_MAP]; 345 unsigned short *p = translations[USER_MAP];
346 unsigned char outbuf[E_TABSZ];
333 347
334 if (!access_ok(VERIFY_WRITE, arg, E_TABSZ)) 348 if (!access_ok(VERIFY_WRITE, arg, E_TABSZ))
335 return -EFAULT; 349 return -EFAULT;
336 350
337 console_lock(); 351 console_lock();
338 for (i=0; i<E_TABSZ ; i++) 352 for (i = 0; i < E_TABSZ ; i++)
339 { 353 {
340 ch = conv_uni_to_pc(vc_cons[fg_console].d, p[i]); 354 ch = conv_uni_to_pc(vc_cons[fg_console].d, p[i]);
341 __put_user((ch & ~0xff) ? 0 : ch, arg+i); 355 outbuf[i] = (ch & ~0xff) ? 0 : ch;
342 } 356 }
343 console_unlock(); 357 console_unlock();
358
359 for (i = 0; i < E_TABSZ ; i++)
360 __put_user(outbuf[i], arg+i);
344 return 0; 361 return 0;
345} 362}
346 363
347int con_set_trans_new(ushort __user * arg) 364int con_set_trans_new(ushort __user * arg)
348{ 365{
349 int i; 366 int i;
350 unsigned short *p = translations[USER_MAP]; 367 unsigned short inbuf[E_TABSZ];
351 368
352 if (!access_ok(VERIFY_READ, arg, E_TABSZ*sizeof(unsigned short))) 369 if (!access_ok(VERIFY_READ, arg, E_TABSZ*sizeof(unsigned short)))
353 return -EFAULT; 370 return -EFAULT;
354 371
355 console_lock(); 372 for (i = 0; i < E_TABSZ ; i++)
356 for (i=0; i<E_TABSZ ; i++) { 373 __get_user(inbuf[i], arg+i);
357 unsigned short us;
358 __get_user(us, arg+i);
359 p[i] = us;
360 }
361 374
375 console_lock();
376 memcpy(translations[USER_MAP], inbuf, sizeof(inbuf));
362 update_user_maps(); 377 update_user_maps();
363 console_unlock(); 378 console_unlock();
364 return 0; 379 return 0;
@@ -367,16 +382,17 @@ int con_set_trans_new(ushort __user * arg)
367int con_get_trans_new(ushort __user * arg) 382int con_get_trans_new(ushort __user * arg)
368{ 383{
369 int i; 384 int i;
370 unsigned short *p = translations[USER_MAP]; 385 unsigned short outbuf[E_TABSZ];
371 386
372 if (!access_ok(VERIFY_WRITE, arg, E_TABSZ*sizeof(unsigned short))) 387 if (!access_ok(VERIFY_WRITE, arg, E_TABSZ*sizeof(unsigned short)))
373 return -EFAULT; 388 return -EFAULT;
374 389
375 console_lock(); 390 console_lock();
376 for (i=0; i<E_TABSZ ; i++) 391 memcpy(outbuf, translations[USER_MAP], sizeof(outbuf));
377 __put_user(p[i], arg+i);
378 console_unlock(); 392 console_unlock();
379 393
394 for (i = 0; i < E_TABSZ ; i++)
395 __put_user(outbuf[i], arg+i);
380 return 0; 396 return 0;
381} 397}
382 398
@@ -536,10 +552,20 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
536{ 552{
537 int err = 0, err1, i; 553 int err = 0, err1, i;
538 struct uni_pagedir *p, *q; 554 struct uni_pagedir *p, *q;
555 struct unipair *unilist, *plist;
539 556
540 if (!ct) 557 if (!ct)
541 return 0; 558 return 0;
542 559
560 unilist = kmalloc_array(ct, sizeof(struct unipair), GFP_KERNEL);
561 if (!unilist)
562 return -ENOMEM;
563
564 for (i = ct, plist = unilist; i; i--, plist++, list++) {
565 __get_user(plist->unicode, &list->unicode);
566 __get_user(plist->fontpos, &list->fontpos);
567 }
568
543 console_lock(); 569 console_lock();
544 570
545 /* Save original vc_unipagdir_loc in case we allocate a new one */ 571 /* Save original vc_unipagdir_loc in case we allocate a new one */
@@ -557,8 +583,8 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
557 583
558 err1 = con_do_clear_unimap(vc); 584 err1 = con_do_clear_unimap(vc);
559 if (err1) { 585 if (err1) {
560 console_unlock(); 586 err = err1;
561 return err1; 587 goto out_unlock;
562 } 588 }
563 589
564 /* 590 /*
@@ -592,8 +618,8 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
592 *vc->vc_uni_pagedir_loc = p; 618 *vc->vc_uni_pagedir_loc = p;
593 con_release_unimap(q); 619 con_release_unimap(q);
594 kfree(q); 620 kfree(q);
595 console_unlock(); 621 err = err1;
596 return err1; 622 goto out_unlock;
597 } 623 }
598 } 624 }
599 } else { 625 } else {
@@ -617,22 +643,17 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
617 /* 643 /*
618 * Insert user specified unicode pairs into new table. 644 * Insert user specified unicode pairs into new table.
619 */ 645 */
620 while (ct--) { 646 for (plist = unilist; ct; ct--, plist++) {
621 unsigned short unicode, fontpos; 647 err1 = con_insert_unipair(p, plist->unicode, plist->fontpos);
622 __get_user(unicode, &list->unicode); 648 if (err1)
623 __get_user(fontpos, &list->fontpos);
624 if ((err1 = con_insert_unipair(p, unicode,fontpos)) != 0)
625 err = err1; 649 err = err1;
626 list++;
627 } 650 }
628 651
629 /* 652 /*
630 * Merge with fontmaps of any other virtual consoles. 653 * Merge with fontmaps of any other virtual consoles.
631 */ 654 */
632 if (con_unify_unimap(vc, p)) { 655 if (con_unify_unimap(vc, p))
633 console_unlock(); 656 goto out_unlock;
634 return err;
635 }
636 657
637 for (i = 0; i <= 3; i++) 658 for (i = 0; i <= 3; i++)
638 set_inverse_transl(vc, p, i); /* Update inverse translations */ 659 set_inverse_transl(vc, p, i); /* Update inverse translations */
@@ -640,6 +661,7 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
640 661
641out_unlock: 662out_unlock:
642 console_unlock(); 663 console_unlock();
664 kfree(unilist);
643 return err; 665 return err;
644} 666}
645 667
@@ -735,9 +757,15 @@ EXPORT_SYMBOL(con_copy_unimap);
735 */ 757 */
736int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct unipair __user *list) 758int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct unipair __user *list)
737{ 759{
738 int i, j, k, ect; 760 int i, j, k;
761 ushort ect;
739 u16 **p1, *p2; 762 u16 **p1, *p2;
740 struct uni_pagedir *p; 763 struct uni_pagedir *p;
764 struct unipair *unilist, *plist;
765
766 unilist = kmalloc_array(ct, sizeof(struct unipair), GFP_KERNEL);
767 if (!unilist)
768 return -ENOMEM;
741 769
742 console_lock(); 770 console_lock();
743 771
@@ -750,21 +778,26 @@ int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct uni
750 for (j = 0; j < 32; j++) { 778 for (j = 0; j < 32; j++) {
751 p2 = *(p1++); 779 p2 = *(p1++);
752 if (p2) 780 if (p2)
753 for (k = 0; k < 64; k++) { 781 for (k = 0; k < 64; k++, p2++) {
754 if (*p2 < MAX_GLYPH && ect++ < ct) { 782 if (*p2 >= MAX_GLYPH)
755 __put_user((u_short)((i<<11)+(j<<6)+k), 783 continue;
756 &list->unicode); 784 if (ect < ct) {
757 __put_user((u_short) *p2, 785 unilist[ect].unicode =
758 &list->fontpos); 786 (i<<11)+(j<<6)+k;
759 list++; 787 unilist[ect].fontpos = *p2;
760 } 788 }
761 p2++; 789 ect++;
762 } 790 }
763 } 791 }
764 } 792 }
765 } 793 }
766 __put_user(ect, uct);
767 console_unlock(); 794 console_unlock();
795 for (i = min(ect, ct), plist = unilist; i; i--, list++, plist++) {
796 __put_user(plist->unicode, &list->unicode);
797 __put_user(plist->fontpos, &list->fontpos);
798 }
799 __put_user(ect, uct);
800 kfree(unilist);
768 return ((ect <= ct) ? 0 : -ENOMEM); 801 return ((ect <= ct) ? 0 : -ENOMEM);
769} 802}
770 803
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 0f8caae4267d..3dd6a491cdba 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -982,7 +982,7 @@ static void kbd_led_trigger_activate(struct led_classdev *cdev)
982 KBD_LED_TRIGGER((_led_bit) + 8, _name) 982 KBD_LED_TRIGGER((_led_bit) + 8, _name)
983 983
984static struct kbd_led_trigger kbd_led_triggers[] = { 984static struct kbd_led_trigger kbd_led_triggers[] = {
985 KBD_LED_TRIGGER(VC_SCROLLOCK, "kbd-scrollock"), 985 KBD_LED_TRIGGER(VC_SCROLLOCK, "kbd-scrolllock"),
986 KBD_LED_TRIGGER(VC_NUMLOCK, "kbd-numlock"), 986 KBD_LED_TRIGGER(VC_NUMLOCK, "kbd-numlock"),
987 KBD_LED_TRIGGER(VC_CAPSLOCK, "kbd-capslock"), 987 KBD_LED_TRIGGER(VC_CAPSLOCK, "kbd-capslock"),
988 KBD_LED_TRIGGER(VC_KANALOCK, "kbd-kanalock"), 988 KBD_LED_TRIGGER(VC_KANALOCK, "kbd-kanalock"),
@@ -1256,7 +1256,7 @@ static int emulate_raw(struct vc_data *vc, unsigned int keycode,
1256 case KEY_SYSRQ: 1256 case KEY_SYSRQ:
1257 /* 1257 /*
1258 * Real AT keyboards (that's what we're trying 1258 * Real AT keyboards (that's what we're trying
1259 * to emulate here emit 0xe0 0x2a 0xe0 0x37 when 1259 * to emulate here) emit 0xe0 0x2a 0xe0 0x37 when
1260 * pressing PrtSc/SysRq alone, but simply 0x54 1260 * pressing PrtSc/SysRq alone, but simply 0x54
1261 * when pressing Alt+PrtSc/SysRq. 1261 * when pressing Alt+PrtSc/SysRq.
1262 */ 1262 */
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 8c3bf3d613c0..623264445100 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -315,38 +315,27 @@ void schedule_console_callback(void)
315 schedule_work(&console_work); 315 schedule_work(&console_work);
316} 316}
317 317
318static void scrup(struct vc_data *vc, unsigned int t, unsigned int b, int nr) 318static void con_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
319 enum con_scroll dir, unsigned int nr)
319{ 320{
320 unsigned short *d, *s; 321 u16 *clear, *d, *s;
321 322
322 if (t+nr >= b) 323 if (t + nr >= b)
323 nr = b - t - 1; 324 nr = b - t - 1;
324 if (b > vc->vc_rows || t >= b || nr < 1) 325 if (b > vc->vc_rows || t >= b || nr < 1)
325 return; 326 return;
326 if (con_is_visible(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_UP, nr)) 327 if (con_is_visible(vc) && vc->vc_sw->con_scroll(vc, t, b, dir, nr))
327 return; 328 return;
328 d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
329 s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr));
330 scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row);
331 scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_video_erase_char,
332 vc->vc_size_row * nr);
333}
334 329
335static void scrdown(struct vc_data *vc, unsigned int t, unsigned int b, int nr) 330 s = clear = (u16 *)(vc->vc_origin + vc->vc_size_row * t);
336{ 331 d = (u16 *)(vc->vc_origin + vc->vc_size_row * (t + nr));
337 unsigned short *s;
338 unsigned int step;
339 332
340 if (t+nr >= b) 333 if (dir == SM_UP) {
341 nr = b - t - 1; 334 clear = s + (b - t - nr) * vc->vc_cols;
342 if (b > vc->vc_rows || t >= b || nr < 1) 335 swap(s, d);
343 return; 336 }
344 if (con_is_visible(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_DOWN, nr)) 337 scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row);
345 return; 338 scr_memsetw(clear, vc->vc_video_erase_char, vc->vc_size_row * nr);
346 s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
347 step = vc->vc_cols * nr;
348 scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row);
349 scr_memsetw(s, vc->vc_video_erase_char, 2 * step);
350} 339}
351 340
352static void do_update_region(struct vc_data *vc, unsigned long start, int count) 341static void do_update_region(struct vc_data *vc, unsigned long start, int count)
@@ -1120,7 +1109,7 @@ static void lf(struct vc_data *vc)
1120 * if below scrolling region 1109 * if below scrolling region
1121 */ 1110 */
1122 if (vc->vc_y + 1 == vc->vc_bottom) 1111 if (vc->vc_y + 1 == vc->vc_bottom)
1123 scrup(vc, vc->vc_top, vc->vc_bottom, 1); 1112 con_scroll(vc, vc->vc_top, vc->vc_bottom, SM_UP, 1);
1124 else if (vc->vc_y < vc->vc_rows - 1) { 1113 else if (vc->vc_y < vc->vc_rows - 1) {
1125 vc->vc_y++; 1114 vc->vc_y++;
1126 vc->vc_pos += vc->vc_size_row; 1115 vc->vc_pos += vc->vc_size_row;
@@ -1135,7 +1124,7 @@ static void ri(struct vc_data *vc)
1135 * if above scrolling region 1124 * if above scrolling region
1136 */ 1125 */
1137 if (vc->vc_y == vc->vc_top) 1126 if (vc->vc_y == vc->vc_top)
1138 scrdown(vc, vc->vc_top, vc->vc_bottom, 1); 1127 con_scroll(vc, vc->vc_top, vc->vc_bottom, SM_DOWN, 1);
1139 else if (vc->vc_y > 0) { 1128 else if (vc->vc_y > 0) {
1140 vc->vc_y--; 1129 vc->vc_y--;
1141 vc->vc_pos -= vc->vc_size_row; 1130 vc->vc_pos -= vc->vc_size_row;
@@ -1631,7 +1620,7 @@ static void csi_L(struct vc_data *vc, unsigned int nr)
1631 nr = vc->vc_rows - vc->vc_y; 1620 nr = vc->vc_rows - vc->vc_y;
1632 else if (!nr) 1621 else if (!nr)
1633 nr = 1; 1622 nr = 1;
1634 scrdown(vc, vc->vc_y, vc->vc_bottom, nr); 1623 con_scroll(vc, vc->vc_y, vc->vc_bottom, SM_DOWN, nr);
1635 vc->vc_need_wrap = 0; 1624 vc->vc_need_wrap = 0;
1636} 1625}
1637 1626
@@ -1652,7 +1641,7 @@ static void csi_M(struct vc_data *vc, unsigned int nr)
1652 nr = vc->vc_rows - vc->vc_y; 1641 nr = vc->vc_rows - vc->vc_y;
1653 else if (!nr) 1642 else if (!nr)
1654 nr=1; 1643 nr=1;
1655 scrup(vc, vc->vc_y, vc->vc_bottom, nr); 1644 con_scroll(vc, vc->vc_y, vc->vc_bottom, SM_UP, nr);
1656 vc->vc_need_wrap = 0; 1645 vc->vc_need_wrap = 0;
1657} 1646}
1658 1647
@@ -4295,6 +4284,46 @@ void vcs_scr_updated(struct vc_data *vc)
4295 notify_update(vc); 4284 notify_update(vc);
4296} 4285}
4297 4286
4287void vc_scrolldelta_helper(struct vc_data *c, int lines,
4288 unsigned int rolled_over, void *base, unsigned int size)
4289{
4290 unsigned long ubase = (unsigned long)base;
4291 ptrdiff_t scr_end = (void *)c->vc_scr_end - base;
4292 ptrdiff_t vorigin = (void *)c->vc_visible_origin - base;
4293 ptrdiff_t origin = (void *)c->vc_origin - base;
4294 int margin = c->vc_size_row * 4;
4295 int from, wrap, from_off, avail;
4296
4297 /* Turn scrollback off */
4298 if (!lines) {
4299 c->vc_visible_origin = c->vc_origin;
4300 return;
4301 }
4302
4303 /* Do we have already enough to allow jumping from 0 to the end? */
4304 if (rolled_over > scr_end + margin) {
4305 from = scr_end;
4306 wrap = rolled_over + c->vc_size_row;
4307 } else {
4308 from = 0;
4309 wrap = size;
4310 }
4311
4312 from_off = (vorigin - from + wrap) % wrap + lines * c->vc_size_row;
4313 avail = (origin - from + wrap) % wrap;
4314
4315 /* Only a little piece would be left? Show all incl. the piece! */
4316 if (avail < 2 * margin)
4317 margin = 0;
4318 if (from_off < margin)
4319 from_off = 0;
4320 if (from_off > avail - margin)
4321 from_off = avail;
4322
4323 c->vc_visible_origin = ubase + (from + from_off) % wrap;
4324}
4325EXPORT_SYMBOL_GPL(vc_scrolldelta_helper);
4326
4298/* 4327/*
4299 * Visible symbols for modules 4328 * Visible symbols for modules
4300 */ 4329 */