aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/Kconfig34
-rw-r--r--drivers/tty/Makefile1
-rw-r--r--drivers/tty/amiserial.c12
-rw-r--r--drivers/tty/cyclades.c14
-rw-r--r--drivers/tty/ehv_bytechan.c881
-rw-r--r--drivers/tty/hvc/hvc_console.c9
-rw-r--r--drivers/tty/hvc/hvc_irq.c2
-rw-r--r--drivers/tty/hvc/hvcs.c4
-rw-r--r--drivers/tty/hvc/hvsi.c2
-rw-r--r--drivers/tty/isicom.c2
-rw-r--r--drivers/tty/mxser.c13
-rw-r--r--drivers/tty/n_gsm.c70
-rw-r--r--drivers/tty/pty.c26
-rw-r--r--drivers/tty/serial/68328serial.c37
-rw-r--r--drivers/tty/serial/68328serial.h1
-rw-r--r--drivers/tty/serial/68360serial.c2979
-rw-r--r--drivers/tty/serial/8250.c132
-rw-r--r--drivers/tty/serial/8250_dw.c194
-rw-r--r--drivers/tty/serial/8250_pci.c42
-rw-r--r--drivers/tty/serial/Kconfig30
-rw-r--r--drivers/tty/serial/Makefile4
-rw-r--r--drivers/tty/serial/altera_jtaguart.c2
-rw-r--r--drivers/tty/serial/altera_uart.c2
-rw-r--r--drivers/tty/serial/apbuart.c1
-rw-r--r--drivers/tty/serial/atmel_serial.c128
-rw-r--r--drivers/tty/serial/bfin_sport_uart.c2
-rw-r--r--drivers/tty/serial/bfin_uart.c (renamed from drivers/tty/serial/bfin_5xx.c)65
-rw-r--r--drivers/tty/serial/cpm_uart/cpm_uart_core.c1
-rw-r--r--drivers/tty/serial/crisv10.c30
-rw-r--r--drivers/tty/serial/dz.c1
-rw-r--r--drivers/tty/serial/icom.c2
-rw-r--r--drivers/tty/serial/imx.c10
-rw-r--r--drivers/tty/serial/ioc3_serial.c1
-rw-r--r--drivers/tty/serial/ioc4_serial.c1
-rw-r--r--drivers/tty/serial/jsm/jsm.h10
-rw-r--r--drivers/tty/serial/jsm/jsm_driver.c19
-rw-r--r--drivers/tty/serial/jsm/jsm_neo.c29
-rw-r--r--drivers/tty/serial/jsm/jsm_tty.c94
-rw-r--r--drivers/tty/serial/lantiq.c6
-rw-r--r--drivers/tty/serial/m32r_sio.c1
-rw-r--r--drivers/tty/serial/max3100.c2
-rw-r--r--drivers/tty/serial/max3107.c2
-rw-r--r--drivers/tty/serial/mcf.c2
-rw-r--r--drivers/tty/serial/mfd.c49
-rw-r--r--drivers/tty/serial/mpc52xx_uart.c3
-rw-r--r--drivers/tty/serial/mrst_max3110.c115
-rw-r--r--drivers/tty/serial/mrst_max3110.h1
-rw-r--r--drivers/tty/serial/msm_serial.c2
-rw-r--r--drivers/tty/serial/msm_serial_hs.c2
-rw-r--r--drivers/tty/serial/mux.c2
-rw-r--r--drivers/tty/serial/nwpserial.c1
-rw-r--r--drivers/tty/serial/pch_uart.c2
-rw-r--r--drivers/tty/serial/pxa.c20
-rw-r--r--drivers/tty/serial/samsung.c107
-rw-r--r--drivers/tty/serial/samsung.h1
-rw-r--r--drivers/tty/serial/sb1250-duart.c1
-rw-r--r--drivers/tty/serial/serial_core.c72
-rw-r--r--drivers/tty/serial/serial_ks8695.c9
-rw-r--r--drivers/tty/serial/serial_txx9.c2
-rw-r--r--drivers/tty/serial/sh-sci.c2
-rw-r--r--drivers/tty/serial/sn_console.c3
-rw-r--r--drivers/tty/serial/timbuart.c2
-rw-r--r--drivers/tty/serial/uartlite.c1
-rw-r--r--drivers/tty/serial/ucc_uart.c4
-rw-r--r--drivers/tty/serial/xilinx_uartps.c4
-rw-r--r--drivers/tty/serial/zs.c1
-rw-r--r--drivers/tty/synclink.c1
-rw-r--r--drivers/tty/synclinkmp.c6
-rw-r--r--drivers/tty/tty_io.c50
-rw-r--r--drivers/tty/tty_ioctl.c17
-rw-r--r--drivers/tty/tty_ldisc.c1
-rw-r--r--drivers/tty/tty_mutex.c12
-rw-r--r--drivers/tty/tty_port.c2
-rw-r--r--drivers/tty/vt/keyboard.c3
-rw-r--r--drivers/tty/vt/selection.c4
-rw-r--r--drivers/tty/vt/vt.c2
76 files changed, 1848 insertions, 3556 deletions
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 33175504bb39..8816f53e004d 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -354,3 +354,37 @@ config TRACE_SINK
354 354
355 If you select this option, you need to select 355 If you select this option, you need to select
356 "Trace data router for MIPI P1149.7 cJTAG standard". 356 "Trace data router for MIPI P1149.7 cJTAG standard".
357
358config PPC_EPAPR_HV_BYTECHAN
359 tristate "ePAPR hypervisor byte channel driver"
360 depends on PPC
361 help
362 This driver creates /dev entries for each ePAPR hypervisor byte
363 channel, thereby allowing applications to communicate with byte
364 channels as if they were serial ports.
365
366config PPC_EARLY_DEBUG_EHV_BC
367 bool "Early console (udbg) support for ePAPR hypervisors"
368 depends on PPC_EPAPR_HV_BYTECHAN
369 help
370 Select this option to enable early console (a.k.a. "udbg") support
371 via an ePAPR byte channel. You also need to choose the byte channel
372 handle below.
373
374config PPC_EARLY_DEBUG_EHV_BC_HANDLE
375 int "Byte channel handle for early console (udbg)"
376 depends on PPC_EARLY_DEBUG_EHV_BC
377 default 0
378 help
379 If you want early console (udbg) output through a byte channel,
380 specify the handle of the byte channel to use.
381
382 For this to work, the byte channel driver must be compiled
383 in-kernel, not as a module.
384
385 Note that only one early console driver can be enabled, so don't
386 enable any others if you enable this one.
387
388 If the number you specify is not a valid byte channel handle, then
389 there simply will be no early console output. This is true also
390 if you don't boot under a hypervisor at all.
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index ea89b0bd15fe..2953059530e4 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -26,5 +26,6 @@ obj-$(CONFIG_ROCKETPORT) += rocket.o
26obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o 26obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o
27obj-$(CONFIG_SYNCLINKMP) += synclinkmp.o 27obj-$(CONFIG_SYNCLINKMP) += synclinkmp.o
28obj-$(CONFIG_SYNCLINK) += synclink.o 28obj-$(CONFIG_SYNCLINK) += synclink.o
29obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o
29 30
30obj-y += ipwireless/ 31obj-y += ipwireless/
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 220579592c20..b84c83456dcc 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1529,7 +1529,6 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1529{ 1529{
1530 struct async_struct * info = tty->driver_data; 1530 struct async_struct * info = tty->driver_data;
1531 unsigned long orig_jiffies, char_time; 1531 unsigned long orig_jiffies, char_time;
1532 int tty_was_locked = tty_locked();
1533 int lsr; 1532 int lsr;
1534 1533
1535 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent")) 1534 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
@@ -1541,12 +1540,6 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1541 orig_jiffies = jiffies; 1540 orig_jiffies = jiffies;
1542 1541
1543 /* 1542 /*
1544 * tty_wait_until_sent is called from lots of places,
1545 * with or without the BTM.
1546 */
1547 if (!tty_was_locked)
1548 tty_lock();
1549 /*
1550 * Set the check interval to be 1/5 of the estimated time to 1543 * Set the check interval to be 1/5 of the estimated time to
1551 * send a single character, and make it at least 1. The check 1544 * send a single character, and make it at least 1. The check
1552 * interval should also be less than the timeout. 1545 * interval should also be less than the timeout.
@@ -1586,8 +1579,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1586 break; 1579 break;
1587 } 1580 }
1588 __set_current_state(TASK_RUNNING); 1581 __set_current_state(TASK_RUNNING);
1589 if (!tty_was_locked) 1582
1590 tty_unlock();
1591#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 1583#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1592 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); 1584 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1593#endif 1585#endif
@@ -2025,7 +2017,7 @@ static int __init amiga_serial_probe(struct platform_device *pdev)
2025 if (error) 2017 if (error)
2026 goto fail_unregister; 2018 goto fail_unregister;
2027 2019
2028 error = request_irq(IRQ_AMIGA_RBF, ser_rx_int, IRQF_DISABLED, 2020 error = request_irq(IRQ_AMIGA_RBF, ser_rx_int, 0,
2029 "serial RX", state); 2021 "serial RX", state);
2030 if (error) 2022 if (error)
2031 goto fail_free_irq; 2023 goto fail_free_irq;
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index c0e8f2eeb886..c9bf779481d8 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -45,7 +45,6 @@
45#undef CY_DEBUG_IO 45#undef CY_DEBUG_IO
46#undef CY_DEBUG_COUNT 46#undef CY_DEBUG_COUNT
47#undef CY_DEBUG_DTR 47#undef CY_DEBUG_DTR
48#undef CY_DEBUG_WAIT_UNTIL_SENT
49#undef CY_DEBUG_INTERRUPTS 48#undef CY_DEBUG_INTERRUPTS
50#undef CY_16Y_HACK 49#undef CY_16Y_HACK
51#undef CY_ENABLE_MONITORING 50#undef CY_ENABLE_MONITORING
@@ -1678,16 +1677,10 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
1678 */ 1677 */
1679 if (!timeout || timeout > 2 * info->timeout) 1678 if (!timeout || timeout > 2 * info->timeout)
1680 timeout = 2 * info->timeout; 1679 timeout = 2 * info->timeout;
1681#ifdef CY_DEBUG_WAIT_UNTIL_SENT 1680
1682 printk(KERN_DEBUG "In cy_wait_until_sent(%d) check=%d, jiff=%lu...",
1683 timeout, char_time, jiffies);
1684#endif
1685 card = info->card; 1681 card = info->card;
1686 if (!cy_is_Z(card)) { 1682 if (!cy_is_Z(card)) {
1687 while (cyy_readb(info, CySRER) & CyTxRdy) { 1683 while (cyy_readb(info, CySRER) & CyTxRdy) {
1688#ifdef CY_DEBUG_WAIT_UNTIL_SENT
1689 printk(KERN_DEBUG "Not clean (jiff=%lu)...", jiffies);
1690#endif
1691 if (msleep_interruptible(jiffies_to_msecs(char_time))) 1684 if (msleep_interruptible(jiffies_to_msecs(char_time)))
1692 break; 1685 break;
1693 if (timeout && time_after(jiffies, orig_jiffies + 1686 if (timeout && time_after(jiffies, orig_jiffies +
@@ -1697,9 +1690,6 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
1697 } 1690 }
1698 /* Run one more char cycle */ 1691 /* Run one more char cycle */
1699 msleep_interruptible(jiffies_to_msecs(char_time * 5)); 1692 msleep_interruptible(jiffies_to_msecs(char_time * 5));
1700#ifdef CY_DEBUG_WAIT_UNTIL_SENT
1701 printk(KERN_DEBUG "Clean (jiff=%lu)...done\n", jiffies);
1702#endif
1703} 1693}
1704 1694
1705static void cy_flush_buffer(struct tty_struct *tty) 1695static void cy_flush_buffer(struct tty_struct *tty)
@@ -3377,7 +3367,7 @@ static int __init cy_detect_isa(void)
3377 3367
3378 /* allocate IRQ */ 3368 /* allocate IRQ */
3379 if (request_irq(cy_isa_irq, cyy_interrupt, 3369 if (request_irq(cy_isa_irq, cyy_interrupt,
3380 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) { 3370 0, "Cyclom-Y", &cy_card[j])) {
3381 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but " 3371 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but "
3382 "could not allocate IRQ#%d.\n", 3372 "could not allocate IRQ#%d.\n",
3383 (unsigned long)cy_isa_address, cy_isa_irq); 3373 (unsigned long)cy_isa_address, cy_isa_irq);
diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c
new file mode 100644
index 000000000000..1595dba0072c
--- /dev/null
+++ b/drivers/tty/ehv_bytechan.c
@@ -0,0 +1,881 @@
1/* ePAPR hypervisor byte channel device driver
2 *
3 * Copyright 2009-2011 Freescale Semiconductor, Inc.
4 *
5 * Author: Timur Tabi <timur@freescale.com>
6 *
7 * This file is licensed under the terms of the GNU General Public License
8 * version 2. This program is licensed "as is" without any warranty of any
9 * kind, whether express or implied.
10 *
11 * This driver support three distinct interfaces, all of which are related to
12 * ePAPR hypervisor byte channels.
13 *
14 * 1) An early-console (udbg) driver. This provides early console output
15 * through a byte channel. The byte channel handle must be specified in a
16 * Kconfig option.
17 *
18 * 2) A normal console driver. Output is sent to the byte channel designated
19 * for stdout in the device tree. The console driver is for handling kernel
20 * printk calls.
21 *
22 * 3) A tty driver, which is used to handle user-space input and output. The
23 * byte channel used for the console is designated as the default tty.
24 */
25
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/err.h>
30#include <linux/interrupt.h>
31#include <linux/fs.h>
32#include <linux/poll.h>
33#include <asm/epapr_hcalls.h>
34#include <linux/of.h>
35#include <linux/platform_device.h>
36#include <linux/cdev.h>
37#include <linux/console.h>
38#include <linux/tty.h>
39#include <linux/tty_flip.h>
40#include <linux/circ_buf.h>
41#include <asm/udbg.h>
42
43/* The size of the transmit circular buffer. This must be a power of two. */
44#define BUF_SIZE 2048
45
46/* Per-byte channel private data */
47struct ehv_bc_data {
48 struct device *dev;
49 struct tty_port port;
50 uint32_t handle;
51 unsigned int rx_irq;
52 unsigned int tx_irq;
53
54 spinlock_t lock; /* lock for transmit buffer */
55 unsigned char buf[BUF_SIZE]; /* transmit circular buffer */
56 unsigned int head; /* circular buffer head */
57 unsigned int tail; /* circular buffer tail */
58
59 int tx_irq_enabled; /* true == TX interrupt is enabled */
60};
61
62/* Array of byte channel objects */
63static struct ehv_bc_data *bcs;
64
65/* Byte channel handle for stdout (and stdin), taken from device tree */
66static unsigned int stdout_bc;
67
68/* Virtual IRQ for the byte channel handle for stdin, taken from device tree */
69static unsigned int stdout_irq;
70
71/**************************** SUPPORT FUNCTIONS ****************************/
72
73/*
74 * Enable the transmit interrupt
75 *
76 * Unlike a serial device, byte channels have no mechanism for disabling their
77 * own receive or transmit interrupts. To emulate that feature, we toggle
78 * the IRQ in the kernel.
79 *
80 * We cannot just blindly call enable_irq() or disable_irq(), because these
81 * calls are reference counted. This means that we cannot call enable_irq()
82 * if interrupts are already enabled. This can happen in two situations:
83 *
84 * 1. The tty layer makes two back-to-back calls to ehv_bc_tty_write()
85 * 2. A transmit interrupt occurs while executing ehv_bc_tx_dequeue()
86 *
87 * To work around this, we keep a flag to tell us if the IRQ is enabled or not.
88 */
89static void enable_tx_interrupt(struct ehv_bc_data *bc)
90{
91 if (!bc->tx_irq_enabled) {
92 enable_irq(bc->tx_irq);
93 bc->tx_irq_enabled = 1;
94 }
95}
96
97static void disable_tx_interrupt(struct ehv_bc_data *bc)
98{
99 if (bc->tx_irq_enabled) {
100 disable_irq_nosync(bc->tx_irq);
101 bc->tx_irq_enabled = 0;
102 }
103}
104
105/*
106 * find the byte channel handle to use for the console
107 *
108 * The byte channel to be used for the console is specified via a "stdout"
109 * property in the /chosen node.
110 *
111 * For compatible with legacy device trees, we also look for a "stdout" alias.
112 */
113static int find_console_handle(void)
114{
115 struct device_node *np, *np2;
116 const char *sprop = NULL;
117 const uint32_t *iprop;
118
119 np = of_find_node_by_path("/chosen");
120 if (np)
121 sprop = of_get_property(np, "stdout-path", NULL);
122
123 if (!np || !sprop) {
124 of_node_put(np);
125 np = of_find_node_by_name(NULL, "aliases");
126 if (np)
127 sprop = of_get_property(np, "stdout", NULL);
128 }
129
130 if (!sprop) {
131 of_node_put(np);
132 return 0;
133 }
134
135 /* We don't care what the aliased node is actually called. We only
136 * care if it's compatible with "epapr,hv-byte-channel", because that
137 * indicates that it's a byte channel node. We use a temporary
138 * variable, 'np2', because we can't release 'np' until we're done with
139 * 'sprop'.
140 */
141 np2 = of_find_node_by_path(sprop);
142 of_node_put(np);
143 np = np2;
144 if (!np) {
145 pr_warning("ehv-bc: stdout node '%s' does not exist\n", sprop);
146 return 0;
147 }
148
149 /* Is it a byte channel? */
150 if (!of_device_is_compatible(np, "epapr,hv-byte-channel")) {
151 of_node_put(np);
152 return 0;
153 }
154
155 stdout_irq = irq_of_parse_and_map(np, 0);
156 if (stdout_irq == NO_IRQ) {
157 pr_err("ehv-bc: no 'interrupts' property in %s node\n", sprop);
158 of_node_put(np);
159 return 0;
160 }
161
162 /*
163 * The 'hv-handle' property contains the handle for this byte channel.
164 */
165 iprop = of_get_property(np, "hv-handle", NULL);
166 if (!iprop) {
167 pr_err("ehv-bc: no 'hv-handle' property in %s node\n",
168 np->name);
169 of_node_put(np);
170 return 0;
171 }
172 stdout_bc = be32_to_cpu(*iprop);
173
174 of_node_put(np);
175 return 1;
176}
177
178/*************************** EARLY CONSOLE DRIVER ***************************/
179
180#ifdef CONFIG_PPC_EARLY_DEBUG_EHV_BC
181
182/*
183 * send a byte to a byte channel, wait if necessary
184 *
185 * This function sends a byte to a byte channel, and it waits and
186 * retries if the byte channel is full. It returns if the character
187 * has been sent, or if some error has occurred.
188 *
189 */
190static void byte_channel_spin_send(const char data)
191{
192 int ret, count;
193
194 do {
195 count = 1;
196 ret = ev_byte_channel_send(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE,
197 &count, &data);
198 } while (ret == EV_EAGAIN);
199}
200
201/*
202 * The udbg subsystem calls this function to display a single character.
203 * We convert CR to a CR/LF.
204 */
205static void ehv_bc_udbg_putc(char c)
206{
207 if (c == '\n')
208 byte_channel_spin_send('\r');
209
210 byte_channel_spin_send(c);
211}
212
213/*
214 * early console initialization
215 *
216 * PowerPC kernels support an early printk console, also known as udbg.
217 * This function must be called via the ppc_md.init_early function pointer.
218 * At this point, the device tree has been unflattened, so we can obtain the
219 * byte channel handle for stdout.
220 *
221 * We only support displaying of characters (putc). We do not support
222 * keyboard input.
223 */
224void __init udbg_init_ehv_bc(void)
225{
226 unsigned int rx_count, tx_count;
227 unsigned int ret;
228
229 /* Verify the byte channel handle */
230 ret = ev_byte_channel_poll(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE,
231 &rx_count, &tx_count);
232 if (ret)
233 return;
234
235 udbg_putc = ehv_bc_udbg_putc;
236 register_early_udbg_console();
237
238 udbg_printf("ehv-bc: early console using byte channel handle %u\n",
239 CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE);
240}
241
242#endif
243
244/****************************** CONSOLE DRIVER ******************************/
245
246static struct tty_driver *ehv_bc_driver;
247
248/*
249 * Byte channel console sending worker function.
250 *
251 * For consoles, if the output buffer is full, we should just spin until it
252 * clears.
253 */
254static int ehv_bc_console_byte_channel_send(unsigned int handle, const char *s,
255 unsigned int count)
256{
257 unsigned int len;
258 int ret = 0;
259
260 while (count) {
261 len = min_t(unsigned int, count, EV_BYTE_CHANNEL_MAX_BYTES);
262 do {
263 ret = ev_byte_channel_send(handle, &len, s);
264 } while (ret == EV_EAGAIN);
265 count -= len;
266 s += len;
267 }
268
269 return ret;
270}
271
272/*
273 * write a string to the console
274 *
275 * This function gets called to write a string from the kernel, typically from
276 * a printk(). This function spins until all data is written.
277 *
278 * We copy the data to a temporary buffer because we need to insert a \r in
279 * front of every \n. It's more efficient to copy the data to the buffer than
280 * it is to make multiple hcalls for each character or each newline.
281 */
282static void ehv_bc_console_write(struct console *co, const char *s,
283 unsigned int count)
284{
285 char s2[EV_BYTE_CHANNEL_MAX_BYTES];
286 unsigned int i, j = 0;
287 char c;
288
289 for (i = 0; i < count; i++) {
290 c = *s++;
291
292 if (c == '\n')
293 s2[j++] = '\r';
294
295 s2[j++] = c;
296 if (j >= (EV_BYTE_CHANNEL_MAX_BYTES - 1)) {
297 if (ehv_bc_console_byte_channel_send(stdout_bc, s2, j))
298 return;
299 j = 0;
300 }
301 }
302
303 if (j)
304 ehv_bc_console_byte_channel_send(stdout_bc, s2, j);
305}
306
307/*
308 * When /dev/console is opened, the kernel iterates the console list looking
309 * for one with ->device and then calls that method. On success, it expects
310 * the passed-in int* to contain the minor number to use.
311 */
312static struct tty_driver *ehv_bc_console_device(struct console *co, int *index)
313{
314 *index = co->index;
315
316 return ehv_bc_driver;
317}
318
319static struct console ehv_bc_console = {
320 .name = "ttyEHV",
321 .write = ehv_bc_console_write,
322 .device = ehv_bc_console_device,
323 .flags = CON_PRINTBUFFER | CON_ENABLED,
324};
325
326/*
327 * Console initialization
328 *
329 * This is the first function that is called after the device tree is
330 * available, so here is where we determine the byte channel handle and IRQ for
331 * stdout/stdin, even though that information is used by the tty and character
332 * drivers.
333 */
334static int __init ehv_bc_console_init(void)
335{
336 if (!find_console_handle()) {
337 pr_debug("ehv-bc: stdout is not a byte channel\n");
338 return -ENODEV;
339 }
340
341#ifdef CONFIG_PPC_EARLY_DEBUG_EHV_BC
342 /* Print a friendly warning if the user chose the wrong byte channel
343 * handle for udbg.
344 */
345 if (stdout_bc != CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE)
346 pr_warning("ehv-bc: udbg handle %u is not the stdout handle\n",
347 CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE);
348#endif
349
350 /* add_preferred_console() must be called before register_console(),
351 otherwise it won't work. However, we don't want to enumerate all the
352 byte channels here, either, since we only care about one. */
353
354 add_preferred_console(ehv_bc_console.name, ehv_bc_console.index, NULL);
355 register_console(&ehv_bc_console);
356
357 pr_info("ehv-bc: registered console driver for byte channel %u\n",
358 stdout_bc);
359
360 return 0;
361}
362console_initcall(ehv_bc_console_init);
363
364/******************************** TTY DRIVER ********************************/
365
366/*
367 * byte channel receive interupt handler
368 *
369 * This ISR is called whenever data is available on a byte channel.
370 */
371static irqreturn_t ehv_bc_tty_rx_isr(int irq, void *data)
372{
373 struct ehv_bc_data *bc = data;
374 struct tty_struct *ttys = tty_port_tty_get(&bc->port);
375 unsigned int rx_count, tx_count, len;
376 int count;
377 char buffer[EV_BYTE_CHANNEL_MAX_BYTES];
378 int ret;
379
380 /* ttys could be NULL during a hangup */
381 if (!ttys)
382 return IRQ_HANDLED;
383
384 /* Find out how much data needs to be read, and then ask the TTY layer
385 * if it can handle that much. We want to ensure that every byte we
386 * read from the byte channel will be accepted by the TTY layer.
387 */
388 ev_byte_channel_poll(bc->handle, &rx_count, &tx_count);
389 count = tty_buffer_request_room(ttys, rx_count);
390
391 /* 'count' is the maximum amount of data the TTY layer can accept at
392 * this time. However, during testing, I was never able to get 'count'
393 * to be less than 'rx_count'. I'm not sure whether I'm calling it
394 * correctly.
395 */
396
397 while (count > 0) {
398 len = min_t(unsigned int, count, sizeof(buffer));
399
400 /* Read some data from the byte channel. This function will
401 * never return more than EV_BYTE_CHANNEL_MAX_BYTES bytes.
402 */
403 ev_byte_channel_receive(bc->handle, &len, buffer);
404
405 /* 'len' is now the amount of data that's been received. 'len'
406 * can't be zero, and most likely it's equal to one.
407 */
408
409 /* Pass the received data to the tty layer. */
410 ret = tty_insert_flip_string(ttys, buffer, len);
411
412 /* 'ret' is the number of bytes that the TTY layer accepted.
413 * If it's not equal to 'len', then it means the buffer is
414 * full, which should never happen. If it does happen, we can
415 * exit gracefully, but we drop the last 'len - ret' characters
416 * that we read from the byte channel.
417 */
418 if (ret != len)
419 break;
420
421 count -= len;
422 }
423
424 /* Tell the tty layer that we're done. */
425 tty_flip_buffer_push(ttys);
426
427 tty_kref_put(ttys);
428
429 return IRQ_HANDLED;
430}
431
432/*
433 * dequeue the transmit buffer to the hypervisor
434 *
435 * This function, which can be called in interrupt context, dequeues as much
436 * data as possible from the transmit buffer to the byte channel.
437 */
438static void ehv_bc_tx_dequeue(struct ehv_bc_data *bc)
439{
440 unsigned int count;
441 unsigned int len, ret;
442 unsigned long flags;
443
444 do {
445 spin_lock_irqsave(&bc->lock, flags);
446 len = min_t(unsigned int,
447 CIRC_CNT_TO_END(bc->head, bc->tail, BUF_SIZE),
448 EV_BYTE_CHANNEL_MAX_BYTES);
449
450 ret = ev_byte_channel_send(bc->handle, &len, bc->buf + bc->tail);
451
452 /* 'len' is valid only if the return code is 0 or EV_EAGAIN */
453 if (!ret || (ret == EV_EAGAIN))
454 bc->tail = (bc->tail + len) & (BUF_SIZE - 1);
455
456 count = CIRC_CNT(bc->head, bc->tail, BUF_SIZE);
457 spin_unlock_irqrestore(&bc->lock, flags);
458 } while (count && !ret);
459
460 spin_lock_irqsave(&bc->lock, flags);
461 if (CIRC_CNT(bc->head, bc->tail, BUF_SIZE))
462 /*
463 * If we haven't emptied the buffer, then enable the TX IRQ.
464 * We'll get an interrupt when there's more room in the
465 * hypervisor's output buffer.
466 */
467 enable_tx_interrupt(bc);
468 else
469 disable_tx_interrupt(bc);
470 spin_unlock_irqrestore(&bc->lock, flags);
471}
472
473/*
474 * byte channel transmit interupt handler
475 *
476 * This ISR is called whenever space becomes available for transmitting
477 * characters on a byte channel.
478 */
479static irqreturn_t ehv_bc_tty_tx_isr(int irq, void *data)
480{
481 struct ehv_bc_data *bc = data;
482 struct tty_struct *ttys = tty_port_tty_get(&bc->port);
483
484 ehv_bc_tx_dequeue(bc);
485 if (ttys) {
486 tty_wakeup(ttys);
487 tty_kref_put(ttys);
488 }
489
490 return IRQ_HANDLED;
491}
492
493/*
494 * This function is called when the tty layer has data for us send. We store
495 * the data first in a circular buffer, and then dequeue as much of that data
496 * as possible.
497 *
498 * We don't need to worry about whether there is enough room in the buffer for
499 * all the data. The purpose of ehv_bc_tty_write_room() is to tell the tty
500 * layer how much data it can safely send to us. We guarantee that
501 * ehv_bc_tty_write_room() will never lie, so the tty layer will never send us
502 * too much data.
503 */
504static int ehv_bc_tty_write(struct tty_struct *ttys, const unsigned char *s,
505 int count)
506{
507 struct ehv_bc_data *bc = ttys->driver_data;
508 unsigned long flags;
509 unsigned int len;
510 unsigned int written = 0;
511
512 while (1) {
513 spin_lock_irqsave(&bc->lock, flags);
514 len = CIRC_SPACE_TO_END(bc->head, bc->tail, BUF_SIZE);
515 if (count < len)
516 len = count;
517 if (len) {
518 memcpy(bc->buf + bc->head, s, len);
519 bc->head = (bc->head + len) & (BUF_SIZE - 1);
520 }
521 spin_unlock_irqrestore(&bc->lock, flags);
522 if (!len)
523 break;
524
525 s += len;
526 count -= len;
527 written += len;
528 }
529
530 ehv_bc_tx_dequeue(bc);
531
532 return written;
533}
534
535/*
536 * This function can be called multiple times for a given tty_struct, which is
537 * why we initialize bc->ttys in ehv_bc_tty_port_activate() instead.
538 *
539 * The tty layer will still call this function even if the device was not
540 * registered (i.e. tty_register_device() was not called). This happens
541 * because tty_register_device() is optional and some legacy drivers don't
542 * use it. So we need to check for that.
543 */
544static int ehv_bc_tty_open(struct tty_struct *ttys, struct file *filp)
545{
546 struct ehv_bc_data *bc = &bcs[ttys->index];
547
548 if (!bc->dev)
549 return -ENODEV;
550
551 return tty_port_open(&bc->port, ttys, filp);
552}
553
554/*
555 * Amazingly, if ehv_bc_tty_open() returns an error code, the tty layer will
556 * still call this function to close the tty device. So we can't assume that
557 * the tty port has been initialized.
558 */
559static void ehv_bc_tty_close(struct tty_struct *ttys, struct file *filp)
560{
561 struct ehv_bc_data *bc = &bcs[ttys->index];
562
563 if (bc->dev)
564 tty_port_close(&bc->port, ttys, filp);
565}
566
567/*
568 * Return the amount of space in the output buffer
569 *
570 * This is actually a contract between the driver and the tty layer outlining
571 * how much write room the driver can guarantee will be sent OR BUFFERED. This
572 * driver MUST honor the return value.
573 */
574static int ehv_bc_tty_write_room(struct tty_struct *ttys)
575{
576 struct ehv_bc_data *bc = ttys->driver_data;
577 unsigned long flags;
578 int count;
579
580 spin_lock_irqsave(&bc->lock, flags);
581 count = CIRC_SPACE(bc->head, bc->tail, BUF_SIZE);
582 spin_unlock_irqrestore(&bc->lock, flags);
583
584 return count;
585}
586
587/*
588 * Stop sending data to the tty layer
589 *
590 * This function is called when the tty layer's input buffers are getting full,
591 * so the driver should stop sending it data. The easiest way to do this is to
592 * disable the RX IRQ, which will prevent ehv_bc_tty_rx_isr() from being
593 * called.
594 *
595 * The hypervisor will continue to queue up any incoming data. If there is any
596 * data in the queue when the RX interrupt is enabled, we'll immediately get an
597 * RX interrupt.
598 */
599static void ehv_bc_tty_throttle(struct tty_struct *ttys)
600{
601 struct ehv_bc_data *bc = ttys->driver_data;
602
603 disable_irq(bc->rx_irq);
604}
605
606/*
607 * Resume sending data to the tty layer
608 *
609 * This function is called after previously calling ehv_bc_tty_throttle(). The
610 * tty layer's input buffers now have more room, so the driver can resume
611 * sending it data.
612 */
613static void ehv_bc_tty_unthrottle(struct tty_struct *ttys)
614{
615 struct ehv_bc_data *bc = ttys->driver_data;
616
617 /* If there is any data in the queue when the RX interrupt is enabled,
618 * we'll immediately get an RX interrupt.
619 */
620 enable_irq(bc->rx_irq);
621}
622
623static void ehv_bc_tty_hangup(struct tty_struct *ttys)
624{
625 struct ehv_bc_data *bc = ttys->driver_data;
626
627 ehv_bc_tx_dequeue(bc);
628 tty_port_hangup(&bc->port);
629}
630
631/*
632 * TTY driver operations
633 *
634 * If we could ask the hypervisor how much data is still in the TX buffer, or
635 * at least how big the TX buffers are, then we could implement the
636 * .wait_until_sent and .chars_in_buffer functions.
637 */
638static const struct tty_operations ehv_bc_ops = {
639 .open = ehv_bc_tty_open,
640 .close = ehv_bc_tty_close,
641 .write = ehv_bc_tty_write,
642 .write_room = ehv_bc_tty_write_room,
643 .throttle = ehv_bc_tty_throttle,
644 .unthrottle = ehv_bc_tty_unthrottle,
645 .hangup = ehv_bc_tty_hangup,
646};
647
648/*
649 * initialize the TTY port
650 *
651 * This function will only be called once, no matter how many times
652 * ehv_bc_tty_open() is called. That's why we register the ISR here, and also
653 * why we initialize tty_struct-related variables here.
654 */
655static int ehv_bc_tty_port_activate(struct tty_port *port,
656 struct tty_struct *ttys)
657{
658 struct ehv_bc_data *bc = container_of(port, struct ehv_bc_data, port);
659 int ret;
660
661 ttys->driver_data = bc;
662
663 ret = request_irq(bc->rx_irq, ehv_bc_tty_rx_isr, 0, "ehv-bc", bc);
664 if (ret < 0) {
665 dev_err(bc->dev, "could not request rx irq %u (ret=%i)\n",
666 bc->rx_irq, ret);
667 return ret;
668 }
669
670 /* request_irq also enables the IRQ */
671 bc->tx_irq_enabled = 1;
672
673 ret = request_irq(bc->tx_irq, ehv_bc_tty_tx_isr, 0, "ehv-bc", bc);
674 if (ret < 0) {
675 dev_err(bc->dev, "could not request tx irq %u (ret=%i)\n",
676 bc->tx_irq, ret);
677 free_irq(bc->rx_irq, bc);
678 return ret;
679 }
680
681 /* The TX IRQ is enabled only when we can't write all the data to the
682 * byte channel at once, so by default it's disabled.
683 */
684 disable_tx_interrupt(bc);
685
686 return 0;
687}
688
689static void ehv_bc_tty_port_shutdown(struct tty_port *port)
690{
691 struct ehv_bc_data *bc = container_of(port, struct ehv_bc_data, port);
692
693 free_irq(bc->tx_irq, bc);
694 free_irq(bc->rx_irq, bc);
695}
696
697static const struct tty_port_operations ehv_bc_tty_port_ops = {
698 .activate = ehv_bc_tty_port_activate,
699 .shutdown = ehv_bc_tty_port_shutdown,
700};
701
702static int __devinit ehv_bc_tty_probe(struct platform_device *pdev)
703{
704 struct device_node *np = pdev->dev.of_node;
705 struct ehv_bc_data *bc;
706 const uint32_t *iprop;
707 unsigned int handle;
708 int ret;
709 static unsigned int index = 1;
710 unsigned int i;
711
712 iprop = of_get_property(np, "hv-handle", NULL);
713 if (!iprop) {
714 dev_err(&pdev->dev, "no 'hv-handle' property in %s node\n",
715 np->name);
716 return -ENODEV;
717 }
718
719 /* We already told the console layer that the index for the console
720 * device is zero, so we need to make sure that we use that index when
721 * we probe the console byte channel node.
722 */
723 handle = be32_to_cpu(*iprop);
724 i = (handle == stdout_bc) ? 0 : index++;
725 bc = &bcs[i];
726
727 bc->handle = handle;
728 bc->head = 0;
729 bc->tail = 0;
730 spin_lock_init(&bc->lock);
731
732 bc->rx_irq = irq_of_parse_and_map(np, 0);
733 bc->tx_irq = irq_of_parse_and_map(np, 1);
734 if ((bc->rx_irq == NO_IRQ) || (bc->tx_irq == NO_IRQ)) {
735 dev_err(&pdev->dev, "no 'interrupts' property in %s node\n",
736 np->name);
737 ret = -ENODEV;
738 goto error;
739 }
740
741 bc->dev = tty_register_device(ehv_bc_driver, i, &pdev->dev);
742 if (IS_ERR(bc->dev)) {
743 ret = PTR_ERR(bc->dev);
744 dev_err(&pdev->dev, "could not register tty (ret=%i)\n", ret);
745 goto error;
746 }
747
748 tty_port_init(&bc->port);
749 bc->port.ops = &ehv_bc_tty_port_ops;
750
751 dev_set_drvdata(&pdev->dev, bc);
752
753 dev_info(&pdev->dev, "registered /dev/%s%u for byte channel %u\n",
754 ehv_bc_driver->name, i, bc->handle);
755
756 return 0;
757
758error:
759 irq_dispose_mapping(bc->tx_irq);
760 irq_dispose_mapping(bc->rx_irq);
761
762 memset(bc, 0, sizeof(struct ehv_bc_data));
763 return ret;
764}
765
766static int ehv_bc_tty_remove(struct platform_device *pdev)
767{
768 struct ehv_bc_data *bc = dev_get_drvdata(&pdev->dev);
769
770 tty_unregister_device(ehv_bc_driver, bc - bcs);
771
772 irq_dispose_mapping(bc->tx_irq);
773 irq_dispose_mapping(bc->rx_irq);
774
775 return 0;
776}
777
778static const struct of_device_id ehv_bc_tty_of_ids[] = {
779 { .compatible = "epapr,hv-byte-channel" },
780 {}
781};
782
783static struct platform_driver ehv_bc_tty_driver = {
784 .driver = {
785 .owner = THIS_MODULE,
786 .name = "ehv-bc",
787 .of_match_table = ehv_bc_tty_of_ids,
788 },
789 .probe = ehv_bc_tty_probe,
790 .remove = ehv_bc_tty_remove,
791};
792
793/**
794 * ehv_bc_init - ePAPR hypervisor byte channel driver initialization
795 *
796 * This function is called when this module is loaded.
797 */
798static int __init ehv_bc_init(void)
799{
800 struct device_node *np;
801 unsigned int count = 0; /* Number of elements in bcs[] */
802 int ret;
803
804 pr_info("ePAPR hypervisor byte channel driver\n");
805
806 /* Count the number of byte channels */
807 for_each_compatible_node(np, NULL, "epapr,hv-byte-channel")
808 count++;
809
810 if (!count)
811 return -ENODEV;
812
813 /* The array index of an element in bcs[] is the same as the tty index
814 * for that element. If you know the address of an element in the
815 * array, then you can use pointer math (e.g. "bc - bcs") to get its
816 * tty index.
817 */
818 bcs = kzalloc(count * sizeof(struct ehv_bc_data), GFP_KERNEL);
819 if (!bcs)
820 return -ENOMEM;
821
822 ehv_bc_driver = alloc_tty_driver(count);
823 if (!ehv_bc_driver) {
824 ret = -ENOMEM;
825 goto error;
826 }
827
828 ehv_bc_driver->owner = THIS_MODULE;
829 ehv_bc_driver->driver_name = "ehv-bc";
830 ehv_bc_driver->name = ehv_bc_console.name;
831 ehv_bc_driver->type = TTY_DRIVER_TYPE_CONSOLE;
832 ehv_bc_driver->subtype = SYSTEM_TYPE_CONSOLE;
833 ehv_bc_driver->init_termios = tty_std_termios;
834 ehv_bc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
835 tty_set_operations(ehv_bc_driver, &ehv_bc_ops);
836
837 ret = tty_register_driver(ehv_bc_driver);
838 if (ret) {
839 pr_err("ehv-bc: could not register tty driver (ret=%i)\n", ret);
840 goto error;
841 }
842
843 ret = platform_driver_register(&ehv_bc_tty_driver);
844 if (ret) {
845 pr_err("ehv-bc: could not register platform driver (ret=%i)\n",
846 ret);
847 goto error;
848 }
849
850 return 0;
851
852error:
853 if (ehv_bc_driver) {
854 tty_unregister_driver(ehv_bc_driver);
855 put_tty_driver(ehv_bc_driver);
856 }
857
858 kfree(bcs);
859
860 return ret;
861}
862
863
864/**
865 * ehv_bc_exit - ePAPR hypervisor byte channel driver termination
866 *
867 * This function is called when this driver is unloaded.
868 */
869static void __exit ehv_bc_exit(void)
870{
871 tty_unregister_driver(ehv_bc_driver);
872 put_tty_driver(ehv_bc_driver);
873 kfree(bcs);
874}
875
876module_init(ehv_bc_init);
877module_exit(ehv_bc_exit);
878
879MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
880MODULE_DESCRIPTION("ePAPR hypervisor byte channel driver");
881MODULE_LICENSE("GPL v2");
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index e1aaf4f309b3..7430bc3c8d53 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
388 * there is no buffered data otherwise sleeps on a wait queue 388 * there is no buffered data otherwise sleeps on a wait queue
389 * waking periodically to check chars_in_buffer(). 389 * waking periodically to check chars_in_buffer().
390 */ 390 */
391 tty_wait_until_sent(tty, HVC_CLOSE_WAIT); 391 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
392 } else { 392 } else {
393 if (hp->count < 0) 393 if (hp->count < 0)
394 printk(KERN_ERR "hvc_close %X: oops, count is %d\n", 394 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
@@ -852,7 +852,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
852 * find index to use: 852 * find index to use:
853 * see if this vterm id matches one registered for console. 853 * see if this vterm id matches one registered for console.
854 */ 854 */
855 for (i=0; i < MAX_NR_HVC_CONSOLES; i++) 855 for (i = 0; i < MAX_NR_HVC_CONSOLES; i++)
856 if (vtermnos[i] == hp->vtermno && 856 if (vtermnos[i] == hp->vtermno &&
857 cons_ops[i] == hp->ops) 857 cons_ops[i] == hp->ops)
858 break; 858 break;
@@ -862,9 +862,13 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
862 i = ++last_hvc; 862 i = ++last_hvc;
863 863
864 hp->index = i; 864 hp->index = i;
865 hvc_console.index = i;
866 vtermnos[i] = vtermno;
867 cons_ops[i] = ops;
865 868
866 list_add_tail(&(hp->next), &hvc_structs); 869 list_add_tail(&(hp->next), &hvc_structs);
867 spin_unlock(&hvc_structs_lock); 870 spin_unlock(&hvc_structs_lock);
871 register_console(&hvc_console);
868 872
869 return hp; 873 return hp;
870} 874}
@@ -875,6 +879,7 @@ int hvc_remove(struct hvc_struct *hp)
875 unsigned long flags; 879 unsigned long flags;
876 struct tty_struct *tty; 880 struct tty_struct *tty;
877 881
882 unregister_console(&hvc_console);
878 spin_lock_irqsave(&hp->lock, flags); 883 spin_lock_irqsave(&hp->lock, flags);
879 tty = tty_kref_get(hp->tty); 884 tty = tty_kref_get(hp->tty);
880 885
diff --git a/drivers/tty/hvc/hvc_irq.c b/drivers/tty/hvc/hvc_irq.c
index 2623e177e8d6..c9adb0559f61 100644
--- a/drivers/tty/hvc/hvc_irq.c
+++ b/drivers/tty/hvc/hvc_irq.c
@@ -28,7 +28,7 @@ int notifier_add_irq(struct hvc_struct *hp, int irq)
28 hp->irq_requested = 0; 28 hp->irq_requested = 0;
29 return 0; 29 return 0;
30 } 30 }
31 rc = request_irq(irq, hvc_handle_interrupt, IRQF_DISABLED, 31 rc = request_irq(irq, hvc_handle_interrupt, 0,
32 "hvc_console", hp); 32 "hvc_console", hp);
33 if (!rc) 33 if (!rc)
34 hp->irq_requested = 1; 34 hp->irq_requested = 1;
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 4c8b66546930..55882b5930a6 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -1057,7 +1057,7 @@ static int hvcs_enable_device(struct hvcs_struct *hvcsd, uint32_t unit_address,
1057 * the conn was registered and now. 1057 * the conn was registered and now.
1058 */ 1058 */
1059 if (!(rc = request_irq(irq, &hvcs_handle_interrupt, 1059 if (!(rc = request_irq(irq, &hvcs_handle_interrupt,
1060 IRQF_DISABLED, "ibmhvcs", hvcsd))) { 1060 0, "ibmhvcs", hvcsd))) {
1061 /* 1061 /*
1062 * It is possible the vty-server was removed after the irq was 1062 * It is possible the vty-server was removed after the irq was
1063 * requested but before we have time to enable interrupts. 1063 * requested but before we have time to enable interrupts.
@@ -1237,7 +1237,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1237 irq = hvcsd->vdev->irq; 1237 irq = hvcsd->vdev->irq;
1238 spin_unlock_irqrestore(&hvcsd->lock, flags); 1238 spin_unlock_irqrestore(&hvcsd->lock, flags);
1239 1239
1240 tty_wait_until_sent(tty, HVCS_CLOSE_WAIT); 1240 tty_wait_until_sent_from_close(tty, HVCS_CLOSE_WAIT);
1241 1241
1242 /* 1242 /*
1243 * This line is important because it tells hvcs_open that this 1243 * This line is important because it tells hvcs_open that this
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index c94e2f5853d8..cdfa3e02d627 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -1105,7 +1105,7 @@ static int __init hvsi_init(void)
1105 struct hvsi_struct *hp = &hvsi_ports[i]; 1105 struct hvsi_struct *hp = &hvsi_ports[i];
1106 int ret = 1; 1106 int ret = 1;
1107 1107
1108 ret = request_irq(hp->virq, hvsi_interrupt, IRQF_DISABLED, "hvsi", hp); 1108 ret = request_irq(hp->virq, hvsi_interrupt, 0, "hvsi", hp);
1109 if (ret) 1109 if (ret)
1110 printk(KERN_ERR "HVSI: couldn't reserve irq 0x%x (error %i)\n", 1110 printk(KERN_ERR "HVSI: couldn't reserve irq 0x%x (error %i)\n",
1111 hp->virq, ret); 1111 hp->virq, ret);
diff --git a/drivers/tty/isicom.c b/drivers/tty/isicom.c
index db1cf9c328d8..e5c295ab5dec 100644
--- a/drivers/tty/isicom.c
+++ b/drivers/tty/isicom.c
@@ -1598,7 +1598,7 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
1598 } 1598 }
1599 1599
1600 retval = request_irq(board->irq, isicom_interrupt, 1600 retval = request_irq(board->irq, isicom_interrupt,
1601 IRQF_SHARED | IRQF_DISABLED, ISICOM_NAME, board); 1601 IRQF_SHARED, ISICOM_NAME, board);
1602 if (retval < 0) { 1602 if (retval < 0) {
1603 dev_err(&pdev->dev, "Could not install handler at Irq %d. " 1603 dev_err(&pdev->dev, "Could not install handler at Irq %d. "
1604 "Card%d will be disabled.\n", board->irq, index + 1); 1604 "Card%d will be disabled.\n", board->irq, index + 1);
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 7fc8c02fea6c..8998d527232a 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -2005,16 +2005,9 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
2005 */ 2005 */
2006 if (!timeout || timeout > 2 * info->timeout) 2006 if (!timeout || timeout > 2 * info->timeout)
2007 timeout = 2 * info->timeout; 2007 timeout = 2 * info->timeout;
2008#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 2008
2009 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
2010 timeout, char_time);
2011 printk("jiff=%lu...", jiffies);
2012#endif
2013 spin_lock_irqsave(&info->slock, flags); 2009 spin_lock_irqsave(&info->slock, flags);
2014 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) { 2010 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) {
2015#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2016 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
2017#endif
2018 spin_unlock_irqrestore(&info->slock, flags); 2011 spin_unlock_irqrestore(&info->slock, flags);
2019 schedule_timeout_interruptible(char_time); 2012 schedule_timeout_interruptible(char_time);
2020 spin_lock_irqsave(&info->slock, flags); 2013 spin_lock_irqsave(&info->slock, flags);
@@ -2025,10 +2018,6 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
2025 } 2018 }
2026 spin_unlock_irqrestore(&info->slock, flags); 2019 spin_unlock_irqrestore(&info->slock, flags);
2027 set_current_state(TASK_RUNNING); 2020 set_current_state(TASK_RUNNING);
2028
2029#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2030 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
2031#endif
2032} 2021}
2033 2022
2034/* 2023/*
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 8a50e4eebf18..4cb0d0a3e57b 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -21,7 +21,6 @@
21 * Mostly done: ioctls for setting modes/timing 21 * Mostly done: ioctls for setting modes/timing
22 * Partly done: hooks so you can pull off frames to non tty devs 22 * Partly done: hooks so you can pull off frames to non tty devs
23 * Restart DLCI 0 when it closes ? 23 * Restart DLCI 0 when it closes ?
24 * Test basic encoding
25 * Improve the tx engine 24 * Improve the tx engine
26 * Resolve tx side locking by adding a queue_head and routing 25 * Resolve tx side locking by adding a queue_head and routing
27 * all control traffic via it 26 * all control traffic via it
@@ -810,38 +809,41 @@ static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci)
810{ 809{
811 struct gsm_msg *msg; 810 struct gsm_msg *msg;
812 u8 *dp; 811 u8 *dp;
813 int len, size; 812 int len, total_size, size;
814 int h = dlci->adaption - 1; 813 int h = dlci->adaption - 1;
815 814
816 len = kfifo_len(dlci->fifo); 815 total_size = 0;
817 if (len == 0) 816 while(1) {
818 return 0; 817 len = kfifo_len(dlci->fifo);
819 818 if (len == 0)
820 /* MTU/MRU count only the data bits */ 819 return total_size;
821 if (len > gsm->mtu) 820
822 len = gsm->mtu; 821 /* MTU/MRU count only the data bits */
823 822 if (len > gsm->mtu)
824 size = len + h; 823 len = gsm->mtu;
825 824
826 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); 825 size = len + h;
827 /* FIXME: need a timer or something to kick this so it can't 826
828 get stuck with no work outstanding and no buffer free */ 827 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);
829 if (msg == NULL) 828 /* FIXME: need a timer or something to kick this so it can't
830 return -ENOMEM; 829 get stuck with no work outstanding and no buffer free */
831 dp = msg->data; 830 if (msg == NULL)
832 switch (dlci->adaption) { 831 return -ENOMEM;
833 case 1: /* Unstructured */ 832 dp = msg->data;
834 break; 833 switch (dlci->adaption) {
835 case 2: /* Unstructed with modem bits. Always one byte as we never 834 case 1: /* Unstructured */
836 send inline break data */ 835 break;
837 *dp += gsm_encode_modem(dlci); 836 case 2: /* Unstructed with modem bits. Always one byte as we never
838 len--; 837 send inline break data */
839 break; 838 *dp++ = gsm_encode_modem(dlci);
839 break;
840 }
841 WARN_ON(kfifo_out_locked(dlci->fifo, dp , len, &dlci->lock) != len);
842 __gsm_data_queue(dlci, msg);
843 total_size += size;
840 } 844 }
841 WARN_ON(kfifo_out_locked(dlci->fifo, dp , len, &dlci->lock) != len);
842 __gsm_data_queue(dlci, msg);
843 /* Bytes of data we used up */ 845 /* Bytes of data we used up */
844 return size; 846 return total_size;
845} 847}
846 848
847/** 849/**
@@ -2004,6 +2006,7 @@ void gsm_cleanup_mux(struct gsm_mux *gsm)
2004 int i; 2006 int i;
2005 struct gsm_dlci *dlci = gsm->dlci[0]; 2007 struct gsm_dlci *dlci = gsm->dlci[0];
2006 struct gsm_msg *txq; 2008 struct gsm_msg *txq;
2009 struct gsm_control *gc;
2007 2010
2008 gsm->dead = 1; 2011 gsm->dead = 1;
2009 2012
@@ -2017,6 +2020,13 @@ void gsm_cleanup_mux(struct gsm_mux *gsm)
2017 spin_unlock(&gsm_mux_lock); 2020 spin_unlock(&gsm_mux_lock);
2018 WARN_ON(i == MAX_MUX); 2021 WARN_ON(i == MAX_MUX);
2019 2022
2023 /* In theory disconnecting DLCI 0 is sufficient but for some
2024 modems this is apparently not the case. */
2025 if (dlci) {
2026 gc = gsm_control_send(gsm, CMD_CLD, NULL, 0);
2027 if (gc)
2028 gsm_control_wait(gsm, gc);
2029 }
2020 del_timer_sync(&gsm->t2_timer); 2030 del_timer_sync(&gsm->t2_timer);
2021 /* Now we are sure T2 has stopped */ 2031 /* Now we are sure T2 has stopped */
2022 if (dlci) { 2032 if (dlci) {
@@ -2982,7 +2992,7 @@ static int gsmtty_tiocmset(struct tty_struct *tty,
2982 struct gsm_dlci *dlci = tty->driver_data; 2992 struct gsm_dlci *dlci = tty->driver_data;
2983 unsigned int modem_tx = dlci->modem_tx; 2993 unsigned int modem_tx = dlci->modem_tx;
2984 2994
2985 modem_tx &= clear; 2995 modem_tx &= ~clear;
2986 modem_tx |= set; 2996 modem_tx |= set;
2987 2997
2988 if (modem_tx != dlci->modem_tx) { 2998 if (modem_tx != dlci->modem_tx) {
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index e809e9d4683c..e18604b3fc7d 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -670,12 +670,18 @@ static int ptmx_open(struct inode *inode, struct file *filp)
670 670
671 nonseekable_open(inode, filp); 671 nonseekable_open(inode, filp);
672 672
673 retval = tty_alloc_file(filp);
674 if (retval)
675 return retval;
676
673 /* find a device that is not in use. */ 677 /* find a device that is not in use. */
674 tty_lock(); 678 tty_lock();
675 index = devpts_new_index(inode); 679 index = devpts_new_index(inode);
676 tty_unlock(); 680 tty_unlock();
677 if (index < 0) 681 if (index < 0) {
678 return index; 682 retval = index;
683 goto err_file;
684 }
679 685
680 mutex_lock(&tty_mutex); 686 mutex_lock(&tty_mutex);
681 tty_lock(); 687 tty_lock();
@@ -689,27 +695,27 @@ static int ptmx_open(struct inode *inode, struct file *filp)
689 695
690 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 696 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
691 697
692 retval = tty_add_file(tty, filp); 698 tty_add_file(tty, filp);
693 if (retval)
694 goto out;
695 699
696 retval = devpts_pty_new(inode, tty->link); 700 retval = devpts_pty_new(inode, tty->link);
697 if (retval) 701 if (retval)
698 goto out1; 702 goto err_release;
699 703
700 retval = ptm_driver->ops->open(tty, filp); 704 retval = ptm_driver->ops->open(tty, filp);
701 if (retval) 705 if (retval)
702 goto out2; 706 goto err_release;
703out1: 707
704 tty_unlock(); 708 tty_unlock();
705 return retval; 709 return 0;
706out2: 710err_release:
707 tty_unlock(); 711 tty_unlock();
708 tty_release(inode, filp); 712 tty_release(inode, filp);
709 return retval; 713 return retval;
710out: 714out:
711 devpts_kill_index(inode, index); 715 devpts_kill_index(inode, index);
712 tty_unlock(); 716 tty_unlock();
717err_file:
718 tty_free_file(filp);
713 return retval; 719 return retval;
714} 720}
715 721
diff --git a/drivers/tty/serial/68328serial.c b/drivers/tty/serial/68328serial.c
index e0a77540b8ca..a88ef9782a4f 100644
--- a/drivers/tty/serial/68328serial.c
+++ b/drivers/tty/serial/68328serial.c
@@ -235,22 +235,6 @@ static void batten_down_hatches(void)
235 235
236static void status_handle(struct m68k_serial *info, unsigned short status) 236static void status_handle(struct m68k_serial *info, unsigned short status)
237{ 237{
238#if 0
239 if(status & DCD) {
240 if((info->port.tty->termios->c_cflag & CRTSCTS) &&
241 ((info->curregs[3] & AUTO_ENAB)==0)) {
242 info->curregs[3] |= AUTO_ENAB;
243 info->pendregs[3] |= AUTO_ENAB;
244 write_zsreg(info->m68k_channel, 3, info->curregs[3]);
245 }
246 } else {
247 if((info->curregs[3] & AUTO_ENAB)) {
248 info->curregs[3] &= ~AUTO_ENAB;
249 info->pendregs[3] &= ~AUTO_ENAB;
250 write_zsreg(info->m68k_channel, 3, info->curregs[3]);
251 }
252 }
253#endif
254 /* If this is console input and this is a 238 /* If this is console input and this is a
255 * 'break asserted' status change interrupt 239 * 'break asserted' status change interrupt
256 * see if we can drop into the debugger 240 * see if we can drop into the debugger
@@ -340,9 +324,6 @@ static void transmit_chars(struct m68k_serial *info)
340 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1); 324 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
341 info->xmit_cnt--; 325 info->xmit_cnt--;
342 326
343 if (info->xmit_cnt < WAKEUP_CHARS)
344 schedule_work(&info->tqueue);
345
346 if(info->xmit_cnt <= 0) { 327 if(info->xmit_cnt <= 0) {
347 /* All done for now... TX ints off */ 328 /* All done for now... TX ints off */
348 uart->ustcnt &= ~USTCNT_TX_INTR_MASK; 329 uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
@@ -378,21 +359,6 @@ irqreturn_t rs_interrupt(int irq, void *dev_id)
378 return IRQ_HANDLED; 359 return IRQ_HANDLED;
379} 360}
380 361
381static void do_softint(struct work_struct *work)
382{
383 struct m68k_serial *info = container_of(work, struct m68k_serial, tqueue);
384 struct tty_struct *tty;
385
386 tty = info->tty;
387 if (!tty)
388 return;
389#if 0
390 if (clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
391 tty_wakeup(tty);
392 }
393#endif
394}
395
396static int startup(struct m68k_serial * info) 362static int startup(struct m68k_serial * info)
397{ 363{
398 m68328_uart *uart = &uart_addr[info->line]; 364 m68328_uart *uart = &uart_addr[info->line];
@@ -1324,7 +1290,6 @@ rs68328_init(void)
1324 info->event = 0; 1290 info->event = 0;
1325 info->count = 0; 1291 info->count = 0;
1326 info->blocked_open = 0; 1292 info->blocked_open = 0;
1327 INIT_WORK(&info->tqueue, do_softint);
1328 init_waitqueue_head(&info->open_wait); 1293 init_waitqueue_head(&info->open_wait);
1329 init_waitqueue_head(&info->close_wait); 1294 init_waitqueue_head(&info->close_wait);
1330 info->line = i; 1295 info->line = i;
@@ -1341,7 +1306,7 @@ rs68328_init(void)
1341 1306
1342 if (request_irq(uart_irqs[i], 1307 if (request_irq(uart_irqs[i],
1343 rs_interrupt, 1308 rs_interrupt,
1344 IRQF_DISABLED, 1309 0,
1345 "M68328_UART", info)) 1310 "M68328_UART", info))
1346 panic("Unable to attach 68328 serial interrupt\n"); 1311 panic("Unable to attach 68328 serial interrupt\n");
1347 } 1312 }
diff --git a/drivers/tty/serial/68328serial.h b/drivers/tty/serial/68328serial.h
index 8c9c3c0745db..3d2faabd766f 100644
--- a/drivers/tty/serial/68328serial.h
+++ b/drivers/tty/serial/68328serial.h
@@ -158,7 +158,6 @@ struct m68k_serial {
158 int xmit_head; 158 int xmit_head;
159 int xmit_tail; 159 int xmit_tail;
160 int xmit_cnt; 160 int xmit_cnt;
161 struct work_struct tqueue;
162 wait_queue_head_t open_wait; 161 wait_queue_head_t open_wait;
163 wait_queue_head_t close_wait; 162 wait_queue_head_t close_wait;
164}; 163};
diff --git a/drivers/tty/serial/68360serial.c b/drivers/tty/serial/68360serial.c
deleted file mode 100644
index 0a3e8787ed50..000000000000
--- a/drivers/tty/serial/68360serial.c
+++ /dev/null
@@ -1,2979 +0,0 @@
1/*
2 * UART driver for 68360 CPM SCC or SMC
3 * Copyright (c) 2000 D. Jeff Dionne <jeff@uclinux.org>,
4 * Copyright (c) 2000 Michael Leslie <mleslie@lineo.ca>
5 * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
6 *
7 * I used the serial.c driver as the framework for this driver.
8 * Give credit to those guys.
9 * The original code was written for the MBX860 board. I tried to make
10 * it generic, but there may be some assumptions in the structures that
11 * have to be fixed later.
12 * To save porting time, I did not bother to change any object names
13 * that are not accessed outside of this file.
14 * It still needs lots of work........When it was easy, I included code
15 * to support the SCCs, but this has never been tested, nor is it complete.
16 * Only the SCCs support modem control, so that is not complete either.
17 *
18 * This module exports the following rs232 io functions:
19 *
20 * int rs_360_init(void);
21 */
22
23#include <linux/module.h>
24#include <linux/errno.h>
25#include <linux/signal.h>
26#include <linux/sched.h>
27#include <linux/timer.h>
28#include <linux/interrupt.h>
29#include <linux/tty.h>
30#include <linux/tty_flip.h>
31#include <linux/serial.h>
32#include <linux/serialP.h>
33#include <linux/major.h>
34#include <linux/string.h>
35#include <linux/fcntl.h>
36#include <linux/ptrace.h>
37#include <linux/mm.h>
38#include <linux/init.h>
39#include <linux/delay.h>
40#include <asm/irq.h>
41#include <asm/m68360.h>
42#include <asm/commproc.h>
43
44
45#ifdef CONFIG_KGDB
46extern void breakpoint(void);
47extern void set_debug_traps(void);
48extern int kgdb_output_string (const char* s, unsigned int count);
49#endif
50
51
52/* #ifdef CONFIG_SERIAL_CONSOLE */ /* This seems to be a post 2.0 thing - mles */
53#include <linux/console.h>
54#include <linux/jiffies.h>
55
56/* this defines the index into rs_table for the port to use
57 */
58#ifndef CONFIG_SERIAL_CONSOLE_PORT
59#define CONFIG_SERIAL_CONSOLE_PORT 1 /* ie SMC2 - note USE_SMC2 must be defined */
60#endif
61/* #endif */
62
63#if 0
64/* SCC2 for console
65 */
66#undef CONFIG_SERIAL_CONSOLE_PORT
67#define CONFIG_SERIAL_CONSOLE_PORT 2
68#endif
69
70
71#define TX_WAKEUP ASYNC_SHARE_IRQ
72
73static char *serial_name = "CPM UART driver";
74static char *serial_version = "0.03";
75
76static struct tty_driver *serial_driver;
77int serial_console_setup(struct console *co, char *options);
78
79/*
80 * Serial driver configuration section. Here are the various options:
81 */
82#define SERIAL_PARANOIA_CHECK
83#define CONFIG_SERIAL_NOPAUSE_IO
84#define SERIAL_DO_RESTART
85
86/* Set of debugging defines */
87
88#undef SERIAL_DEBUG_INTR
89#undef SERIAL_DEBUG_OPEN
90#undef SERIAL_DEBUG_FLOW
91#undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
92
93#define _INLINE_ inline
94
95#define DBG_CNT(s)
96
97/* We overload some of the items in the data structure to meet our
98 * needs. For example, the port address is the CPM parameter ram
99 * offset for the SCC or SMC. The maximum number of ports is 4 SCCs and
100 * 2 SMCs. The "hub6" field is used to indicate the channel number, with
101 * a flag indicating SCC or SMC, and the number is used as an index into
102 * the CPM parameter area for this device.
103 * The "type" field is currently set to 0, for PORT_UNKNOWN. It is
104 * not currently used. I should probably use it to indicate the port
105 * type of SMC or SCC.
106 * The SMCs do not support any modem control signals.
107 */
108#define smc_scc_num hub6
109#define NUM_IS_SCC ((int)0x00010000)
110#define PORT_NUM(P) ((P) & 0x0000ffff)
111
112
113#if defined (CONFIG_UCQUICC)
114
115volatile extern void *_periph_base;
116/* sipex transceiver
117 * mode bits for are on pins
118 *
119 * SCC2 d16..19
120 * SCC3 d20..23
121 * SCC4 d24..27
122 */
123#define SIPEX_MODE(n,m) ((m & 0x0f)<<(16+4*(n-1)))
124
125static uint sipex_mode_bits = 0x00000000;
126
127#endif
128
129/* There is no `serial_state' defined back here in 2.0.
130 * Try to get by with serial_struct
131 */
132/* #define serial_state serial_struct */
133
134/* 2.4 -> 2.0 portability problem: async_icount in 2.4 has a few
135 * extras: */
136
137#if 0
138struct async_icount_24 {
139 __u32 cts, dsr, rng, dcd, tx, rx;
140 __u32 frame, parity, overrun, brk;
141 __u32 buf_overrun;
142} icount;
143#endif
144
145#if 0
146
147struct serial_state {
148 int magic;
149 int baud_base;
150 unsigned long port;
151 int irq;
152 int flags;
153 int hub6;
154 int type;
155 int line;
156 int revision; /* Chip revision (950) */
157 int xmit_fifo_size;
158 int custom_divisor;
159 int count;
160 u8 *iomem_base;
161 u16 iomem_reg_shift;
162 unsigned short close_delay;
163 unsigned short closing_wait; /* time to wait before closing */
164 struct async_icount_24 icount;
165 int io_type;
166 struct async_struct *info;
167};
168#endif
169
170#define SSTATE_MAGIC 0x5302
171
172
173
174/* SMC2 is sometimes used for low performance TDM interfaces. Define
175 * this as 1 if you want SMC2 as a serial port UART managed by this driver.
176 * Define this as 0 if you wish to use SMC2 for something else.
177 */
178#define USE_SMC2 1
179
180#if 0
181/* Define SCC to ttySx mapping. */
182#define SCC_NUM_BASE (USE_SMC2 + 1) /* SCC base tty "number" */
183
184/* Define which SCC is the first one to use for a serial port. These
185 * are 0-based numbers, i.e. this assumes the first SCC (SCC1) is used
186 * for Ethernet, and the first available SCC for serial UART is SCC2.
187 * NOTE: IF YOU CHANGE THIS, you have to change the PROFF_xxx and
188 * interrupt vectors in the table below to match.
189 */
190#define SCC_IDX_BASE 1 /* table index */
191#endif
192
193
194/* Processors other than the 860 only get SMCs configured by default.
195 * Either they don't have SCCs or they are allocated somewhere else.
196 * Of course, there are now 860s without some SCCs, so we will need to
197 * address that someday.
198 * The Embedded Planet Multimedia I/O cards use TDM interfaces to the
199 * stereo codec parts, and we use SMC2 to help support that.
200 */
201static struct serial_state rs_table[] = {
202/* type line PORT IRQ FLAGS smc_scc_num (F.K.A. hub6) */
203 { 0, 0, PRSLOT_SMC1, CPMVEC_SMC1, 0, 0 } /* SMC1 ttyS0 */
204#if USE_SMC2
205 ,{ 0, 0, PRSLOT_SMC2, CPMVEC_SMC2, 0, 1 } /* SMC2 ttyS1 */
206#endif
207
208#if defined(CONFIG_SERIAL_68360_SCC)
209 ,{ 0, 0, PRSLOT_SCC2, CPMVEC_SCC2, 0, (NUM_IS_SCC | 1) } /* SCC2 ttyS2 */
210 ,{ 0, 0, PRSLOT_SCC3, CPMVEC_SCC3, 0, (NUM_IS_SCC | 2) } /* SCC3 ttyS3 */
211 ,{ 0, 0, PRSLOT_SCC4, CPMVEC_SCC4, 0, (NUM_IS_SCC | 3) } /* SCC4 ttyS4 */
212#endif
213};
214
215#define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
216
217/* The number of buffer descriptors and their sizes.
218 */
219#define RX_NUM_FIFO 4
220#define RX_BUF_SIZE 32
221#define TX_NUM_FIFO 4
222#define TX_BUF_SIZE 32
223
224#define CONSOLE_NUM_FIFO 2
225#define CONSOLE_BUF_SIZE 4
226
227char *console_fifos[CONSOLE_NUM_FIFO * CONSOLE_BUF_SIZE];
228
229/* The async_struct in serial.h does not really give us what we
230 * need, so define our own here.
231 */
232typedef struct serial_info {
233 int magic;
234 int flags;
235
236 struct serial_state *state;
237 /* struct serial_struct *state; */
238 /* struct async_struct *state; */
239
240 struct tty_struct *tty;
241 int read_status_mask;
242 int ignore_status_mask;
243 int timeout;
244 int line;
245 int x_char; /* xon/xoff character */
246 int close_delay;
247 unsigned short closing_wait;
248 unsigned short closing_wait2;
249 unsigned long event;
250 unsigned long last_active;
251 int blocked_open; /* # of blocked opens */
252 struct work_struct tqueue;
253 struct work_struct tqueue_hangup;
254 wait_queue_head_t open_wait;
255 wait_queue_head_t close_wait;
256
257
258/* CPM Buffer Descriptor pointers.
259 */
260 QUICC_BD *rx_bd_base;
261 QUICC_BD *rx_cur;
262 QUICC_BD *tx_bd_base;
263 QUICC_BD *tx_cur;
264} ser_info_t;
265
266
267/* since kmalloc_init() does not get called until much after this initialization: */
268static ser_info_t quicc_ser_info[NR_PORTS];
269static char rx_buf_pool[NR_PORTS * RX_NUM_FIFO * RX_BUF_SIZE];
270static char tx_buf_pool[NR_PORTS * TX_NUM_FIFO * TX_BUF_SIZE];
271
272static void change_speed(ser_info_t *info);
273static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout);
274
275static inline int serial_paranoia_check(ser_info_t *info,
276 char *name, const char *routine)
277{
278#ifdef SERIAL_PARANOIA_CHECK
279 static const char *badmagic =
280 "Warning: bad magic number for serial struct (%s) in %s\n";
281 static const char *badinfo =
282 "Warning: null async_struct for (%s) in %s\n";
283
284 if (!info) {
285 printk(badinfo, name, routine);
286 return 1;
287 }
288 if (info->magic != SERIAL_MAGIC) {
289 printk(badmagic, name, routine);
290 return 1;
291 }
292#endif
293 return 0;
294}
295
296/*
297 * This is used to figure out the divisor speeds and the timeouts,
298 * indexed by the termio value. The generic CPM functions are responsible
299 * for setting and assigning baud rate generators for us.
300 */
301static int baud_table[] = {
302 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
303 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0 };
304
305/* This sucks. There is a better way: */
306#if defined(CONFIG_CONSOLE_9600)
307 #define CONSOLE_BAUDRATE 9600
308#elif defined(CONFIG_CONSOLE_19200)
309 #define CONSOLE_BAUDRATE 19200
310#elif defined(CONFIG_CONSOLE_115200)
311 #define CONSOLE_BAUDRATE 115200
312#else
313 #warning "console baud rate undefined"
314 #define CONSOLE_BAUDRATE 9600
315#endif
316
317/*
318 * ------------------------------------------------------------
319 * rs_stop() and rs_start()
320 *
321 * This routines are called before setting or resetting tty->stopped.
322 * They enable or disable transmitter interrupts, as necessary.
323 * ------------------------------------------------------------
324 */
325static void rs_360_stop(struct tty_struct *tty)
326{
327 ser_info_t *info = (ser_info_t *)tty->driver_data;
328 int idx;
329 unsigned long flags;
330 volatile struct scc_regs *sccp;
331 volatile struct smc_regs *smcp;
332
333 if (serial_paranoia_check(info, tty->name, "rs_stop"))
334 return;
335
336 local_irq_save(flags);
337 idx = PORT_NUM(info->state->smc_scc_num);
338 if (info->state->smc_scc_num & NUM_IS_SCC) {
339 sccp = &pquicc->scc_regs[idx];
340 sccp->scc_sccm &= ~UART_SCCM_TX;
341 } else {
342 /* smcp = &cpmp->cp_smc[idx]; */
343 smcp = &pquicc->smc_regs[idx];
344 smcp->smc_smcm &= ~SMCM_TX;
345 }
346 local_irq_restore(flags);
347}
348
349
350static void rs_360_start(struct tty_struct *tty)
351{
352 ser_info_t *info = (ser_info_t *)tty->driver_data;
353 int idx;
354 unsigned long flags;
355 volatile struct scc_regs *sccp;
356 volatile struct smc_regs *smcp;
357
358 if (serial_paranoia_check(info, tty->name, "rs_stop"))
359 return;
360
361 local_irq_save(flags);
362 idx = PORT_NUM(info->state->smc_scc_num);
363 if (info->state->smc_scc_num & NUM_IS_SCC) {
364 sccp = &pquicc->scc_regs[idx];
365 sccp->scc_sccm |= UART_SCCM_TX;
366 } else {
367 smcp = &pquicc->smc_regs[idx];
368 smcp->smc_smcm |= SMCM_TX;
369 }
370 local_irq_restore(flags);
371}
372
373/*
374 * ----------------------------------------------------------------------
375 *
376 * Here starts the interrupt handling routines. All of the following
377 * subroutines are declared as inline and are folded into
378 * rs_interrupt(). They were separated out for readability's sake.
379 *
380 * Note: rs_interrupt() is a "fast" interrupt, which means that it
381 * runs with interrupts turned off. People who may want to modify
382 * rs_interrupt() should try to keep the interrupt handler as fast as
383 * possible. After you are done making modifications, it is not a bad
384 * idea to do:
385 *
386 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
387 *
388 * and look at the resulting assemble code in serial.s.
389 *
390 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
391 * -----------------------------------------------------------------------
392 */
393
394static _INLINE_ void receive_chars(ser_info_t *info)
395{
396 struct tty_struct *tty = info->port.tty;
397 unsigned char ch, flag, *cp;
398 /*int ignored = 0;*/
399 int i;
400 ushort status;
401 struct async_icount *icount;
402 /* struct async_icount_24 *icount; */
403 volatile QUICC_BD *bdp;
404
405 icount = &info->state->icount;
406
407 /* Just loop through the closed BDs and copy the characters into
408 * the buffer.
409 */
410 bdp = info->rx_cur;
411 for (;;) {
412 if (bdp->status & BD_SC_EMPTY) /* If this one is empty */
413 break; /* we are all done */
414
415 /* The read status mask tell us what we should do with
416 * incoming characters, especially if errors occur.
417 * One special case is the use of BD_SC_EMPTY. If
418 * this is not set, we are supposed to be ignoring
419 * inputs. In this case, just mark the buffer empty and
420 * continue.
421 */
422 if (!(info->read_status_mask & BD_SC_EMPTY)) {
423 bdp->status |= BD_SC_EMPTY;
424 bdp->status &=
425 ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
426
427 if (bdp->status & BD_SC_WRAP)
428 bdp = info->rx_bd_base;
429 else
430 bdp++;
431 continue;
432 }
433
434 /* Get the number of characters and the buffer pointer.
435 */
436 i = bdp->length;
437 /* cp = (unsigned char *)__va(bdp->buf); */
438 cp = (char *)bdp->buf;
439 status = bdp->status;
440
441 while (i-- > 0) {
442 ch = *cp++;
443 icount->rx++;
444
445#ifdef SERIAL_DEBUG_INTR
446 printk("DR%02x:%02x...", ch, status);
447#endif
448 flag = TTY_NORMAL;
449
450 if (status & (BD_SC_BR | BD_SC_FR |
451 BD_SC_PR | BD_SC_OV)) {
452 /*
453 * For statistics only
454 */
455 if (status & BD_SC_BR)
456 icount->brk++;
457 else if (status & BD_SC_PR)
458 icount->parity++;
459 else if (status & BD_SC_FR)
460 icount->frame++;
461 if (status & BD_SC_OV)
462 icount->overrun++;
463
464 /*
465 * Now check to see if character should be
466 * ignored, and mask off conditions which
467 * should be ignored.
468 if (status & info->ignore_status_mask) {
469 if (++ignored > 100)
470 break;
471 continue;
472 }
473 */
474 status &= info->read_status_mask;
475
476 if (status & (BD_SC_BR)) {
477#ifdef SERIAL_DEBUG_INTR
478 printk("handling break....");
479#endif
480 *tty->flip.flag_buf_ptr = TTY_BREAK;
481 if (info->flags & ASYNC_SAK)
482 do_SAK(tty);
483 } else if (status & BD_SC_PR)
484 flag = TTY_PARITY;
485 else if (status & BD_SC_FR)
486 flag = TTY_FRAME;
487 }
488 tty_insert_flip_char(tty, ch, flag);
489 if (status & BD_SC_OV)
490 /*
491 * Overrun is special, since it's
492 * reported immediately, and doesn't
493 * affect the current character
494 */
495 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
496 }
497
498 /* This BD is ready to be used again. Clear status.
499 * Get next BD.
500 */
501 bdp->status |= BD_SC_EMPTY;
502 bdp->status &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
503
504 if (bdp->status & BD_SC_WRAP)
505 bdp = info->rx_bd_base;
506 else
507 bdp++;
508 }
509
510 info->rx_cur = (QUICC_BD *)bdp;
511
512 tty_schedule_flip(tty);
513}
514
515static _INLINE_ void receive_break(ser_info_t *info)
516{
517 struct tty_struct *tty = info->port.tty;
518
519 info->state->icount.brk++;
520 /* Check to see if there is room in the tty buffer for
521 * the break. If not, we exit now, losing the break. FIXME
522 */
523 tty_insert_flip_char(tty, 0, TTY_BREAK);
524 tty_schedule_flip(tty);
525}
526
527static _INLINE_ void transmit_chars(ser_info_t *info)
528{
529
530 if ((info->flags & TX_WAKEUP) ||
531 (info->port.tty->flags & (1 << TTY_DO_WRITE_WAKEUP))) {
532 schedule_work(&info->tqueue);
533 }
534
535#ifdef SERIAL_DEBUG_INTR
536 printk("THRE...");
537#endif
538}
539
540#ifdef notdef
541 /* I need to do this for the SCCs, so it is left as a reminder.
542 */
543static _INLINE_ void check_modem_status(struct async_struct *info)
544{
545 int status;
546 /* struct async_icount *icount; */
547 struct async_icount_24 *icount;
548
549 status = serial_in(info, UART_MSR);
550
551 if (status & UART_MSR_ANY_DELTA) {
552 icount = &info->state->icount;
553 /* update input line counters */
554 if (status & UART_MSR_TERI)
555 icount->rng++;
556 if (status & UART_MSR_DDSR)
557 icount->dsr++;
558 if (status & UART_MSR_DDCD) {
559 icount->dcd++;
560#ifdef CONFIG_HARD_PPS
561 if ((info->flags & ASYNC_HARDPPS_CD) &&
562 (status & UART_MSR_DCD))
563 hardpps();
564#endif
565 }
566 if (status & UART_MSR_DCTS)
567 icount->cts++;
568 wake_up_interruptible(&info->delta_msr_wait);
569 }
570
571 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
572#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
573 printk("ttys%d CD now %s...", info->line,
574 (status & UART_MSR_DCD) ? "on" : "off");
575#endif
576 if (status & UART_MSR_DCD)
577 wake_up_interruptible(&info->open_wait);
578 else {
579#ifdef SERIAL_DEBUG_OPEN
580 printk("scheduling hangup...");
581#endif
582 queue_task(&info->tqueue_hangup,
583 &tq_scheduler);
584 }
585 }
586 if (info->flags & ASYNC_CTS_FLOW) {
587 if (info->port.tty->hw_stopped) {
588 if (status & UART_MSR_CTS) {
589#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
590 printk("CTS tx start...");
591#endif
592 info->port.tty->hw_stopped = 0;
593 info->IER |= UART_IER_THRI;
594 serial_out(info, UART_IER, info->IER);
595 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
596 return;
597 }
598 } else {
599 if (!(status & UART_MSR_CTS)) {
600#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
601 printk("CTS tx stop...");
602#endif
603 info->port.tty->hw_stopped = 1;
604 info->IER &= ~UART_IER_THRI;
605 serial_out(info, UART_IER, info->IER);
606 }
607 }
608 }
609}
610#endif
611
612/*
613 * This is the serial driver's interrupt routine for a single port
614 */
615/* static void rs_360_interrupt(void *dev_id) */ /* until and if we start servicing irqs here */
616static void rs_360_interrupt(int vec, void *dev_id)
617{
618 u_char events;
619 int idx;
620 ser_info_t *info;
621 volatile struct smc_regs *smcp;
622 volatile struct scc_regs *sccp;
623
624 info = dev_id;
625
626 idx = PORT_NUM(info->state->smc_scc_num);
627 if (info->state->smc_scc_num & NUM_IS_SCC) {
628 sccp = &pquicc->scc_regs[idx];
629 events = sccp->scc_scce;
630 if (events & SCCM_RX)
631 receive_chars(info);
632 if (events & SCCM_TX)
633 transmit_chars(info);
634 sccp->scc_scce = events;
635 } else {
636 smcp = &pquicc->smc_regs[idx];
637 events = smcp->smc_smce;
638 if (events & SMCM_BRKE)
639 receive_break(info);
640 if (events & SMCM_RX)
641 receive_chars(info);
642 if (events & SMCM_TX)
643 transmit_chars(info);
644 smcp->smc_smce = events;
645 }
646
647#ifdef SERIAL_DEBUG_INTR
648 printk("rs_interrupt_single(%d, %x)...",
649 info->state->smc_scc_num, events);
650#endif
651#ifdef modem_control
652 check_modem_status(info);
653#endif
654 info->last_active = jiffies;
655#ifdef SERIAL_DEBUG_INTR
656 printk("end.\n");
657#endif
658}
659
660
661/*
662 * -------------------------------------------------------------------
663 * Here ends the serial interrupt routines.
664 * -------------------------------------------------------------------
665 */
666
667
668static void do_softint(void *private_)
669{
670 ser_info_t *info = (ser_info_t *) private_;
671 struct tty_struct *tty;
672
673 tty = info->port.tty;
674 if (!tty)
675 return;
676
677 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
678 tty_wakeup(tty);
679}
680
681
682/*
683 * This routine is called from the scheduler tqueue when the interrupt
684 * routine has signalled that a hangup has occurred. The path of
685 * hangup processing is:
686 *
687 * serial interrupt routine -> (scheduler tqueue) ->
688 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
689 *
690 */
691static void do_serial_hangup(void *private_)
692{
693 struct async_struct *info = (struct async_struct *) private_;
694 struct tty_struct *tty;
695
696 tty = info->port.tty;
697 if (!tty)
698 return;
699
700 tty_hangup(tty);
701}
702
703
704static int startup(ser_info_t *info)
705{
706 unsigned long flags;
707 int retval=0;
708 int idx;
709 /*struct serial_state *state = info->state;*/
710 volatile struct smc_regs *smcp;
711 volatile struct scc_regs *sccp;
712 volatile struct smc_uart_pram *up;
713 volatile struct uart_pram *scup;
714
715
716 local_irq_save(flags);
717
718 if (info->flags & ASYNC_INITIALIZED) {
719 goto errout;
720 }
721
722#ifdef maybe
723 if (!state->port || !state->type) {
724 if (info->port.tty)
725 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
726 goto errout;
727 }
728#endif
729
730#ifdef SERIAL_DEBUG_OPEN
731 printk("starting up ttys%d (irq %d)...", info->line, state->irq);
732#endif
733
734
735#ifdef modem_control
736 info->MCR = 0;
737 if (info->port.tty->termios->c_cflag & CBAUD)
738 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
739#endif
740
741 if (info->port.tty)
742 clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
743
744 /*
745 * and set the speed of the serial port
746 */
747 change_speed(info);
748
749 idx = PORT_NUM(info->state->smc_scc_num);
750 if (info->state->smc_scc_num & NUM_IS_SCC) {
751 sccp = &pquicc->scc_regs[idx];
752 scup = &pquicc->pram[info->state->port].scc.pscc.u;
753
754 scup->mrblr = RX_BUF_SIZE;
755 scup->max_idl = RX_BUF_SIZE;
756
757 sccp->scc_sccm |= (UART_SCCM_TX | UART_SCCM_RX);
758 sccp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
759
760 } else {
761 smcp = &pquicc->smc_regs[idx];
762
763 /* Enable interrupts and I/O.
764 */
765 smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
766 smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
767
768 /* We can tune the buffer length and idle characters
769 * to take advantage of the entire incoming buffer size.
770 * If mrblr is something other than 1, maxidl has to be
771 * non-zero or we never get an interrupt. The maxidl
772 * is the number of character times we wait after reception
773 * of the last character before we decide no more characters
774 * are coming.
775 */
776 /* up = (smc_uart_t *)&pquicc->cp_dparam[state->port]; */
777 /* holy unionized structures, Batman: */
778 up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
779
780 up->mrblr = RX_BUF_SIZE;
781 up->max_idl = RX_BUF_SIZE;
782
783 up->brkcr = 1; /* number of break chars */
784 }
785
786 info->flags |= ASYNC_INITIALIZED;
787 local_irq_restore(flags);
788 return 0;
789
790errout:
791 local_irq_restore(flags);
792 return retval;
793}
794
795/*
796 * This routine will shutdown a serial port; interrupts are disabled, and
797 * DTR is dropped if the hangup on close termio flag is on.
798 */
799static void shutdown(ser_info_t *info)
800{
801 unsigned long flags;
802 struct serial_state *state;
803 int idx;
804 volatile struct smc_regs *smcp;
805 volatile struct scc_regs *sccp;
806
807 if (!(info->flags & ASYNC_INITIALIZED))
808 return;
809
810 state = info->state;
811
812#ifdef SERIAL_DEBUG_OPEN
813 printk("Shutting down serial port %d (irq %d)....", info->line,
814 state->irq);
815#endif
816
817 local_irq_save(flags);
818
819 idx = PORT_NUM(state->smc_scc_num);
820 if (state->smc_scc_num & NUM_IS_SCC) {
821 sccp = &pquicc->scc_regs[idx];
822 sccp->scc_gsmr.w.low &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
823#ifdef CONFIG_SERIAL_CONSOLE
824 /* We can't disable the transmitter if this is the
825 * system console.
826 */
827 if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
828#endif
829 sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
830 } else {
831 smcp = &pquicc->smc_regs[idx];
832
833 /* Disable interrupts and I/O.
834 */
835 smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
836#ifdef CONFIG_SERIAL_CONSOLE
837 /* We can't disable the transmitter if this is the
838 * system console.
839 */
840 if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
841#endif
842 smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
843 }
844
845 if (info->port.tty)
846 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
847
848 info->flags &= ~ASYNC_INITIALIZED;
849 local_irq_restore(flags);
850}
851
852/*
853 * This routine is called to set the UART divisor registers to match
854 * the specified baud rate for a serial port.
855 */
856static void change_speed(ser_info_t *info)
857{
858 int baud_rate;
859 unsigned cflag, cval, scval, prev_mode;
860 int i, bits, sbits, idx;
861 unsigned long flags;
862 struct serial_state *state;
863 volatile struct smc_regs *smcp;
864 volatile struct scc_regs *sccp;
865
866 if (!info->port.tty || !info->port.tty->termios)
867 return;
868 cflag = info->port.tty->termios->c_cflag;
869
870 state = info->state;
871
872 /* Character length programmed into the mode register is the
873 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
874 * 1 or 2 stop bits, minus 1.
875 * The value 'bits' counts this for us.
876 */
877 cval = 0;
878 scval = 0;
879
880 /* byte size and parity */
881 switch (cflag & CSIZE) {
882 case CS5: bits = 5; break;
883 case CS6: bits = 6; break;
884 case CS7: bits = 7; break;
885 case CS8: bits = 8; break;
886 /* Never happens, but GCC is too dumb to figure it out */
887 default: bits = 8; break;
888 }
889 sbits = bits - 5;
890
891 if (cflag & CSTOPB) {
892 cval |= SMCMR_SL; /* Two stops */
893 scval |= SCU_PMSR_SL;
894 bits++;
895 }
896 if (cflag & PARENB) {
897 cval |= SMCMR_PEN;
898 scval |= SCU_PMSR_PEN;
899 bits++;
900 }
901 if (!(cflag & PARODD)) {
902 cval |= SMCMR_PM_EVEN;
903 scval |= (SCU_PMSR_REVP | SCU_PMSR_TEVP);
904 }
905
906 /* Determine divisor based on baud rate */
907 i = cflag & CBAUD;
908 if (i >= (sizeof(baud_table)/sizeof(int)))
909 baud_rate = 9600;
910 else
911 baud_rate = baud_table[i];
912
913 info->timeout = (TX_BUF_SIZE*HZ*bits);
914 info->timeout += HZ/50; /* Add .02 seconds of slop */
915
916#ifdef modem_control
917 /* CTS flow control flag and modem status interrupts */
918 info->IER &= ~UART_IER_MSI;
919 if (info->flags & ASYNC_HARDPPS_CD)
920 info->IER |= UART_IER_MSI;
921 if (cflag & CRTSCTS) {
922 info->flags |= ASYNC_CTS_FLOW;
923 info->IER |= UART_IER_MSI;
924 } else
925 info->flags &= ~ASYNC_CTS_FLOW;
926 if (cflag & CLOCAL)
927 info->flags &= ~ASYNC_CHECK_CD;
928 else {
929 info->flags |= ASYNC_CHECK_CD;
930 info->IER |= UART_IER_MSI;
931 }
932 serial_out(info, UART_IER, info->IER);
933#endif
934
935 /*
936 * Set up parity check flag
937 */
938 info->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
939 if (I_INPCK(info->port.tty))
940 info->read_status_mask |= BD_SC_FR | BD_SC_PR;
941 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
942 info->read_status_mask |= BD_SC_BR;
943
944 /*
945 * Characters to ignore
946 */
947 info->ignore_status_mask = 0;
948 if (I_IGNPAR(info->port.tty))
949 info->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
950 if (I_IGNBRK(info->port.tty)) {
951 info->ignore_status_mask |= BD_SC_BR;
952 /*
953 * If we're ignore parity and break indicators, ignore
954 * overruns too. (For real raw support).
955 */
956 if (I_IGNPAR(info->port.tty))
957 info->ignore_status_mask |= BD_SC_OV;
958 }
959 /*
960 * !!! ignore all characters if CREAD is not set
961 */
962 if ((cflag & CREAD) == 0)
963 info->read_status_mask &= ~BD_SC_EMPTY;
964 local_irq_save(flags);
965
966 /* Start bit has not been added (so don't, because we would just
967 * subtract it later), and we need to add one for the number of
968 * stops bits (there is always at least one).
969 */
970 bits++;
971 idx = PORT_NUM(state->smc_scc_num);
972 if (state->smc_scc_num & NUM_IS_SCC) {
973 sccp = &pquicc->scc_regs[idx];
974 sccp->scc_psmr = (sbits << 12) | scval;
975 } else {
976 smcp = &pquicc->smc_regs[idx];
977
978 /* Set the mode register. We want to keep a copy of the
979 * enables, because we want to put them back if they were
980 * present.
981 */
982 prev_mode = smcp->smc_smcmr;
983 smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
984 smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
985 }
986
987 m360_cpm_setbrg((state - rs_table), baud_rate);
988
989 local_irq_restore(flags);
990}
991
992static void rs_360_put_char(struct tty_struct *tty, unsigned char ch)
993{
994 ser_info_t *info = (ser_info_t *)tty->driver_data;
995 volatile QUICC_BD *bdp;
996
997 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
998 return 0;
999
1000 if (!tty)
1001 return 0;
1002
1003 bdp = info->tx_cur;
1004 while (bdp->status & BD_SC_READY);
1005
1006 /* *((char *)__va(bdp->buf)) = ch; */
1007 *((char *)bdp->buf) = ch;
1008 bdp->length = 1;
1009 bdp->status |= BD_SC_READY;
1010
1011 /* Get next BD.
1012 */
1013 if (bdp->status & BD_SC_WRAP)
1014 bdp = info->tx_bd_base;
1015 else
1016 bdp++;
1017
1018 info->tx_cur = (QUICC_BD *)bdp;
1019 return 1;
1020
1021}
1022
1023static int rs_360_write(struct tty_struct * tty,
1024 const unsigned char *buf, int count)
1025{
1026 int c, ret = 0;
1027 ser_info_t *info = (ser_info_t *)tty->driver_data;
1028 volatile QUICC_BD *bdp;
1029
1030#ifdef CONFIG_KGDB
1031 /* Try to let stub handle output. Returns true if it did. */
1032 if (kgdb_output_string(buf, count))
1033 return ret;
1034#endif
1035
1036 if (serial_paranoia_check(info, tty->name, "rs_write"))
1037 return 0;
1038
1039 if (!tty)
1040 return 0;
1041
1042 bdp = info->tx_cur;
1043
1044 while (1) {
1045 c = min(count, TX_BUF_SIZE);
1046
1047 if (c <= 0)
1048 break;
1049
1050 if (bdp->status & BD_SC_READY) {
1051 info->flags |= TX_WAKEUP;
1052 break;
1053 }
1054
1055 /* memcpy(__va(bdp->buf), buf, c); */
1056 memcpy((void *)bdp->buf, buf, c);
1057
1058 bdp->length = c;
1059 bdp->status |= BD_SC_READY;
1060
1061 buf += c;
1062 count -= c;
1063 ret += c;
1064
1065 /* Get next BD.
1066 */
1067 if (bdp->status & BD_SC_WRAP)
1068 bdp = info->tx_bd_base;
1069 else
1070 bdp++;
1071 info->tx_cur = (QUICC_BD *)bdp;
1072 }
1073 return ret;
1074}
1075
1076static int rs_360_write_room(struct tty_struct *tty)
1077{
1078 ser_info_t *info = (ser_info_t *)tty->driver_data;
1079 int ret;
1080
1081 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1082 return 0;
1083
1084 if ((info->tx_cur->status & BD_SC_READY) == 0) {
1085 info->flags &= ~TX_WAKEUP;
1086 ret = TX_BUF_SIZE;
1087 }
1088 else {
1089 info->flags |= TX_WAKEUP;
1090 ret = 0;
1091 }
1092 return ret;
1093}
1094
1095/* I could track this with transmit counters....maybe later.
1096*/
1097static int rs_360_chars_in_buffer(struct tty_struct *tty)
1098{
1099 ser_info_t *info = (ser_info_t *)tty->driver_data;
1100
1101 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1102 return 0;
1103 return 0;
1104}
1105
1106static void rs_360_flush_buffer(struct tty_struct *tty)
1107{
1108 ser_info_t *info = (ser_info_t *)tty->driver_data;
1109
1110 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1111 return;
1112
1113 /* There is nothing to "flush", whatever we gave the CPM
1114 * is on its way out.
1115 */
1116 tty_wakeup(tty);
1117 info->flags &= ~TX_WAKEUP;
1118}
1119
1120/*
1121 * This function is used to send a high-priority XON/XOFF character to
1122 * the device
1123 */
1124static void rs_360_send_xchar(struct tty_struct *tty, char ch)
1125{
1126 volatile QUICC_BD *bdp;
1127
1128 ser_info_t *info = (ser_info_t *)tty->driver_data;
1129
1130 if (serial_paranoia_check(info, tty->name, "rs_send_char"))
1131 return;
1132
1133 bdp = info->tx_cur;
1134 while (bdp->status & BD_SC_READY);
1135
1136 /* *((char *)__va(bdp->buf)) = ch; */
1137 *((char *)bdp->buf) = ch;
1138 bdp->length = 1;
1139 bdp->status |= BD_SC_READY;
1140
1141 /* Get next BD.
1142 */
1143 if (bdp->status & BD_SC_WRAP)
1144 bdp = info->tx_bd_base;
1145 else
1146 bdp++;
1147
1148 info->tx_cur = (QUICC_BD *)bdp;
1149}
1150
1151/*
1152 * ------------------------------------------------------------
1153 * rs_throttle()
1154 *
1155 * This routine is called by the upper-layer tty layer to signal that
1156 * incoming characters should be throttled.
1157 * ------------------------------------------------------------
1158 */
1159static void rs_360_throttle(struct tty_struct * tty)
1160{
1161 ser_info_t *info = (ser_info_t *)tty->driver_data;
1162#ifdef SERIAL_DEBUG_THROTTLE
1163 char buf[64];
1164
1165 printk("throttle %s: %d....\n", _tty_name(tty, buf),
1166 tty->ldisc.chars_in_buffer(tty));
1167#endif
1168
1169 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
1170 return;
1171
1172 if (I_IXOFF(tty))
1173 rs_360_send_xchar(tty, STOP_CHAR(tty));
1174
1175#ifdef modem_control
1176 if (tty->termios->c_cflag & CRTSCTS)
1177 info->MCR &= ~UART_MCR_RTS;
1178
1179 local_irq_disable();
1180 serial_out(info, UART_MCR, info->MCR);
1181 local_irq_enable();
1182#endif
1183}
1184
1185static void rs_360_unthrottle(struct tty_struct * tty)
1186{
1187 ser_info_t *info = (ser_info_t *)tty->driver_data;
1188#ifdef SERIAL_DEBUG_THROTTLE
1189 char buf[64];
1190
1191 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1192 tty->ldisc.chars_in_buffer(tty));
1193#endif
1194
1195 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1196 return;
1197
1198 if (I_IXOFF(tty)) {
1199 if (info->x_char)
1200 info->x_char = 0;
1201 else
1202 rs_360_send_xchar(tty, START_CHAR(tty));
1203 }
1204#ifdef modem_control
1205 if (tty->termios->c_cflag & CRTSCTS)
1206 info->MCR |= UART_MCR_RTS;
1207 local_irq_disable();
1208 serial_out(info, UART_MCR, info->MCR);
1209 local_irq_enable();
1210#endif
1211}
1212
1213/*
1214 * ------------------------------------------------------------
1215 * rs_ioctl() and friends
1216 * ------------------------------------------------------------
1217 */
1218
1219#ifdef maybe
1220/*
1221 * get_lsr_info - get line status register info
1222 *
1223 * Purpose: Let user call ioctl() to get info when the UART physically
1224 * is emptied. On bus types like RS485, the transmitter must
1225 * release the bus after transmitting. This must be done when
1226 * the transmit shift register is empty, not be done when the
1227 * transmit holding register is empty. This functionality
1228 * allows an RS485 driver to be written in user space.
1229 */
1230static int get_lsr_info(struct async_struct * info, unsigned int *value)
1231{
1232 unsigned char status;
1233 unsigned int result;
1234
1235 local_irq_disable();
1236 status = serial_in(info, UART_LSR);
1237 local_irq_enable();
1238 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1239 return put_user(result,value);
1240}
1241#endif
1242
1243static int rs_360_tiocmget(struct tty_struct *tty)
1244{
1245 ser_info_t *info = (ser_info_t *)tty->driver_data;
1246 unsigned int result = 0;
1247#ifdef modem_control
1248 unsigned char control, status;
1249
1250 if (serial_paranoia_check(info, tty->name, __func__))
1251 return -ENODEV;
1252
1253 if (tty->flags & (1 << TTY_IO_ERROR))
1254 return -EIO;
1255
1256 control = info->MCR;
1257 local_irq_disable();
1258 status = serial_in(info, UART_MSR);
1259 local_irq_enable();
1260 result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1261 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1262#ifdef TIOCM_OUT1
1263 | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
1264 | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
1265#endif
1266 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1267 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1268 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1269 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1270#endif
1271 return result;
1272}
1273
1274static int rs_360_tiocmset(struct tty_struct *tty,
1275 unsigned int set, unsigned int clear)
1276{
1277#ifdef modem_control
1278 ser_info_t *info = (ser_info_t *)tty->driver_data;
1279 unsigned int arg;
1280
1281 if (serial_paranoia_check(info, tty->name, __func__))
1282 return -ENODEV;
1283
1284 if (tty->flags & (1 << TTY_IO_ERROR))
1285 return -EIO;
1286 /* FIXME: locking on info->mcr */
1287 if (set & TIOCM_RTS)
1288 info->mcr |= UART_MCR_RTS;
1289 if (set & TIOCM_DTR)
1290 info->mcr |= UART_MCR_DTR;
1291 if (clear & TIOCM_RTS)
1292 info->MCR &= ~UART_MCR_RTS;
1293 if (clear & TIOCM_DTR)
1294 info->MCR &= ~UART_MCR_DTR;
1295
1296#ifdef TIOCM_OUT1
1297 if (set & TIOCM_OUT1)
1298 info->MCR |= UART_MCR_OUT1;
1299 if (set & TIOCM_OUT2)
1300 info->MCR |= UART_MCR_OUT2;
1301 if (clear & TIOCM_OUT1)
1302 info->MCR &= ~UART_MCR_OUT1;
1303 if (clear & TIOCM_OUT2)
1304 info->MCR &= ~UART_MCR_OUT2;
1305#endif
1306
1307 local_irq_disable();
1308 serial_out(info, UART_MCR, info->MCR);
1309 local_irq_enable();
1310#endif
1311 return 0;
1312}
1313
1314/* Sending a break is a two step process on the SMC/SCC. It is accomplished
1315 * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
1316 * command. We take advantage of the begin/end functions to make this
1317 * happen.
1318 */
1319static ushort smc_chan_map[] = {
1320 CPM_CR_CH_SMC1,
1321 CPM_CR_CH_SMC2
1322};
1323
1324static ushort scc_chan_map[] = {
1325 CPM_CR_CH_SCC1,
1326 CPM_CR_CH_SCC2,
1327 CPM_CR_CH_SCC3,
1328 CPM_CR_CH_SCC4
1329};
1330
1331static void begin_break(ser_info_t *info)
1332{
1333 volatile QUICC *cp;
1334 ushort chan;
1335 int idx;
1336
1337 cp = pquicc;
1338
1339 idx = PORT_NUM(info->state->smc_scc_num);
1340 if (info->state->smc_scc_num & NUM_IS_SCC)
1341 chan = scc_chan_map[idx];
1342 else
1343 chan = smc_chan_map[idx];
1344
1345 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG;
1346 while (cp->cp_cr & CPM_CR_FLG);
1347}
1348
1349static void end_break(ser_info_t *info)
1350{
1351 volatile QUICC *cp;
1352 ushort chan;
1353 int idx;
1354
1355 cp = pquicc;
1356
1357 idx = PORT_NUM(info->state->smc_scc_num);
1358 if (info->state->smc_scc_num & NUM_IS_SCC)
1359 chan = scc_chan_map[idx];
1360 else
1361 chan = smc_chan_map[idx];
1362
1363 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_RESTART_TX) | CPM_CR_FLG;
1364 while (cp->cp_cr & CPM_CR_FLG);
1365}
1366
1367/*
1368 * This routine sends a break character out the serial port.
1369 */
1370static void send_break(ser_info_t *info, unsigned int duration)
1371{
1372#ifdef SERIAL_DEBUG_SEND_BREAK
1373 printk("rs_send_break(%d) jiff=%lu...", duration, jiffies);
1374#endif
1375 begin_break(info);
1376 msleep_interruptible(duration);
1377 end_break(info);
1378#ifdef SERIAL_DEBUG_SEND_BREAK
1379 printk("done jiffies=%lu\n", jiffies);
1380#endif
1381}
1382
1383
1384/*
1385 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1386 * Return: write counters to the user passed counter struct
1387 * NB: both 1->0 and 0->1 transitions are counted except for
1388 * RI where only 0->1 is counted.
1389 */
1390static int rs_360_get_icount(struct tty_struct *tty,
1391 struct serial_icounter_struct *icount)
1392{
1393 ser_info_t *info = (ser_info_t *)tty->driver_data;
1394 struct async_icount cnow;
1395
1396 local_irq_disable();
1397 cnow = info->state->icount;
1398 local_irq_enable();
1399
1400 icount->cts = cnow.cts;
1401 icount->dsr = cnow.dsr;
1402 icount->rng = cnow.rng;
1403 icount->dcd = cnow.dcd;
1404
1405 return 0;
1406}
1407
1408static int rs_360_ioctl(struct tty_struct *tty,
1409 unsigned int cmd, unsigned long arg)
1410{
1411 int error;
1412 ser_info_t *info = (ser_info_t *)tty->driver_data;
1413 int retval;
1414 struct async_icount cnow;
1415 /* struct async_icount_24 cnow;*/ /* kernel counter temps */
1416 struct serial_icounter_struct *p_cuser; /* user space */
1417
1418 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1419 return -ENODEV;
1420
1421 if (cmd != TIOCMIWAIT) {
1422 if (tty->flags & (1 << TTY_IO_ERROR))
1423 return -EIO;
1424 }
1425
1426 switch (cmd) {
1427 case TCSBRK: /* SVID version: non-zero arg --> no break */
1428 retval = tty_check_change(tty);
1429 if (retval)
1430 return retval;
1431 tty_wait_until_sent(tty, 0);
1432 if (signal_pending(current))
1433 return -EINTR;
1434 if (!arg) {
1435 send_break(info, 250); /* 1/4 second */
1436 if (signal_pending(current))
1437 return -EINTR;
1438 }
1439 return 0;
1440 case TCSBRKP: /* support for POSIX tcsendbreak() */
1441 retval = tty_check_change(tty);
1442 if (retval)
1443 return retval;
1444 tty_wait_until_sent(tty, 0);
1445 if (signal_pending(current))
1446 return -EINTR;
1447 send_break(info, arg ? arg*100 : 250);
1448 if (signal_pending(current))
1449 return -EINTR;
1450 return 0;
1451 case TIOCSBRK:
1452 retval = tty_check_change(tty);
1453 if (retval)
1454 return retval;
1455 tty_wait_until_sent(tty, 0);
1456 begin_break(info);
1457 return 0;
1458 case TIOCCBRK:
1459 retval = tty_check_change(tty);
1460 if (retval)
1461 return retval;
1462 end_break(info);
1463 return 0;
1464#ifdef maybe
1465 case TIOCSERGETLSR: /* Get line status register */
1466 return get_lsr_info(info, (unsigned int *) arg);
1467#endif
1468 /*
1469 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1470 * - mask passed in arg for lines of interest
1471 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1472 * Caller should use TIOCGICOUNT to see which one it was
1473 */
1474 case TIOCMIWAIT:
1475#ifdef modem_control
1476 local_irq_disable();
1477 /* note the counters on entry */
1478 cprev = info->state->icount;
1479 local_irq_enable();
1480 while (1) {
1481 interruptible_sleep_on(&info->delta_msr_wait);
1482 /* see if a signal did it */
1483 if (signal_pending(current))
1484 return -ERESTARTSYS;
1485 local_irq_disable();
1486 cnow = info->state->icount; /* atomic copy */
1487 local_irq_enable();
1488 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1489 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1490 return -EIO; /* no change => error */
1491 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1492 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1493 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1494 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
1495 return 0;
1496 }
1497 cprev = cnow;
1498 }
1499 /* NOTREACHED */
1500#else
1501 return 0;
1502#endif
1503
1504
1505 default:
1506 return -ENOIOCTLCMD;
1507 }
1508 return 0;
1509}
1510
1511/* FIX UP modem control here someday......
1512*/
1513static void rs_360_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1514{
1515 ser_info_t *info = (ser_info_t *)tty->driver_data;
1516
1517 change_speed(info);
1518
1519#ifdef modem_control
1520 /* Handle transition to B0 status */
1521 if ((old_termios->c_cflag & CBAUD) &&
1522 !(tty->termios->c_cflag & CBAUD)) {
1523 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1524 local_irq_disable();
1525 serial_out(info, UART_MCR, info->MCR);
1526 local_irq_enable();
1527 }
1528
1529 /* Handle transition away from B0 status */
1530 if (!(old_termios->c_cflag & CBAUD) &&
1531 (tty->termios->c_cflag & CBAUD)) {
1532 info->MCR |= UART_MCR_DTR;
1533 if (!tty->hw_stopped ||
1534 !(tty->termios->c_cflag & CRTSCTS)) {
1535 info->MCR |= UART_MCR_RTS;
1536 }
1537 local_irq_disable();
1538 serial_out(info, UART_MCR, info->MCR);
1539 local_irq_enable();
1540 }
1541
1542 /* Handle turning off CRTSCTS */
1543 if ((old_termios->c_cflag & CRTSCTS) &&
1544 !(tty->termios->c_cflag & CRTSCTS)) {
1545 tty->hw_stopped = 0;
1546 rs_360_start(tty);
1547 }
1548#endif
1549
1550#if 0
1551 /*
1552 * No need to wake up processes in open wait, since they
1553 * sample the CLOCAL flag once, and don't recheck it.
1554 * XXX It's not clear whether the current behavior is correct
1555 * or not. Hence, this may change.....
1556 */
1557 if (!(old_termios->c_cflag & CLOCAL) &&
1558 (tty->termios->c_cflag & CLOCAL))
1559 wake_up_interruptible(&info->open_wait);
1560#endif
1561}
1562
1563/*
1564 * ------------------------------------------------------------
1565 * rs_close()
1566 *
1567 * This routine is called when the serial port gets closed. First, we
1568 * wait for the last remaining data to be sent. Then, we unlink its
1569 * async structure from the interrupt chain if necessary, and we free
1570 * that IRQ if nothing is left in the chain.
1571 * ------------------------------------------------------------
1572 */
1573static void rs_360_close(struct tty_struct *tty, struct file * filp)
1574{
1575 ser_info_t *info = (ser_info_t *)tty->driver_data;
1576 /* struct async_state *state; */
1577 struct serial_state *state;
1578 unsigned long flags;
1579 int idx;
1580 volatile struct smc_regs *smcp;
1581 volatile struct scc_regs *sccp;
1582
1583 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1584 return;
1585
1586 state = info->state;
1587
1588 local_irq_save(flags);
1589
1590 if (tty_hung_up_p(filp)) {
1591 DBG_CNT("before DEC-hung");
1592 local_irq_restore(flags);
1593 return;
1594 }
1595
1596#ifdef SERIAL_DEBUG_OPEN
1597 printk("rs_close ttys%d, count = %d\n", info->line, state->count);
1598#endif
1599 if ((tty->count == 1) && (state->count != 1)) {
1600 /*
1601 * Uh, oh. tty->count is 1, which means that the tty
1602 * structure will be freed. state->count should always
1603 * be one in these conditions. If it's greater than
1604 * one, we've got real problems, since it means the
1605 * serial port won't be shutdown.
1606 */
1607 printk("rs_close: bad serial port count; tty->count is 1, "
1608 "state->count is %d\n", state->count);
1609 state->count = 1;
1610 }
1611 if (--state->count < 0) {
1612 printk("rs_close: bad serial port count for ttys%d: %d\n",
1613 info->line, state->count);
1614 state->count = 0;
1615 }
1616 if (state->count) {
1617 DBG_CNT("before DEC-2");
1618 local_irq_restore(flags);
1619 return;
1620 }
1621 info->flags |= ASYNC_CLOSING;
1622 /*
1623 * Now we wait for the transmit buffer to clear; and we notify
1624 * the line discipline to only process XON/XOFF characters.
1625 */
1626 tty->closing = 1;
1627 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1628 tty_wait_until_sent(tty, info->closing_wait);
1629 /*
1630 * At this point we stop accepting input. To do this, we
1631 * disable the receive line status interrupts, and tell the
1632 * interrupt driver to stop checking the data ready bit in the
1633 * line status register.
1634 */
1635 info->read_status_mask &= ~BD_SC_EMPTY;
1636 if (info->flags & ASYNC_INITIALIZED) {
1637
1638 idx = PORT_NUM(info->state->smc_scc_num);
1639 if (info->state->smc_scc_num & NUM_IS_SCC) {
1640 sccp = &pquicc->scc_regs[idx];
1641 sccp->scc_sccm &= ~UART_SCCM_RX;
1642 sccp->scc_gsmr.w.low &= ~SCC_GSMRL_ENR;
1643 } else {
1644 smcp = &pquicc->smc_regs[idx];
1645 smcp->smc_smcm &= ~SMCM_RX;
1646 smcp->smc_smcmr &= ~SMCMR_REN;
1647 }
1648 /*
1649 * Before we drop DTR, make sure the UART transmitter
1650 * has completely drained; this is especially
1651 * important if there is a transmit FIFO!
1652 */
1653 rs_360_wait_until_sent(tty, info->timeout);
1654 }
1655 shutdown(info);
1656 rs_360_flush_buffer(tty);
1657 tty_ldisc_flush(tty);
1658 tty->closing = 0;
1659 info->event = 0;
1660 info->port.tty = NULL;
1661 if (info->blocked_open) {
1662 if (info->close_delay) {
1663 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1664 }
1665 wake_up_interruptible(&info->open_wait);
1666 }
1667 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1668 wake_up_interruptible(&info->close_wait);
1669 local_irq_restore(flags);
1670}
1671
1672/*
1673 * rs_wait_until_sent() --- wait until the transmitter is empty
1674 */
1675static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
1676{
1677 ser_info_t *info = (ser_info_t *)tty->driver_data;
1678 unsigned long orig_jiffies, char_time;
1679 /*int lsr;*/
1680 volatile QUICC_BD *bdp;
1681
1682 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
1683 return;
1684
1685#ifdef maybe
1686 if (info->state->type == PORT_UNKNOWN)
1687 return;
1688#endif
1689
1690 orig_jiffies = jiffies;
1691 /*
1692 * Set the check interval to be 1/5 of the estimated time to
1693 * send a single character, and make it at least 1. The check
1694 * interval should also be less than the timeout.
1695 *
1696 * Note: we have to use pretty tight timings here to satisfy
1697 * the NIST-PCTS.
1698 */
1699 char_time = 1;
1700 if (timeout)
1701 char_time = min(char_time, (unsigned long)timeout);
1702#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1703 printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
1704 printk("jiff=%lu...", jiffies);
1705#endif
1706
1707 /* We go through the loop at least once because we can't tell
1708 * exactly when the last character exits the shifter. There can
1709 * be at least two characters waiting to be sent after the buffers
1710 * are empty.
1711 */
1712 do {
1713#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1714 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1715#endif
1716/* current->counter = 0; make us low-priority */
1717 msleep_interruptible(jiffies_to_msecs(char_time));
1718 if (signal_pending(current))
1719 break;
1720 if (timeout && (time_after(jiffies, orig_jiffies + timeout)))
1721 break;
1722 /* The 'tx_cur' is really the next buffer to send. We
1723 * have to back up to the previous BD and wait for it
1724 * to go. This isn't perfect, because all this indicates
1725 * is the buffer is available. There are still characters
1726 * in the CPM FIFO.
1727 */
1728 bdp = info->tx_cur;
1729 if (bdp == info->tx_bd_base)
1730 bdp += (TX_NUM_FIFO-1);
1731 else
1732 bdp--;
1733 } while (bdp->status & BD_SC_READY);
1734 current->state = TASK_RUNNING;
1735#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1736 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1737#endif
1738}
1739
1740/*
1741 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1742 */
1743static void rs_360_hangup(struct tty_struct *tty)
1744{
1745 ser_info_t *info = (ser_info_t *)tty->driver_data;
1746 struct serial_state *state = info->state;
1747
1748 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
1749 return;
1750
1751 state = info->state;
1752
1753 rs_360_flush_buffer(tty);
1754 shutdown(info);
1755 info->event = 0;
1756 state->count = 0;
1757 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1758 info->port.tty = NULL;
1759 wake_up_interruptible(&info->open_wait);
1760}
1761
1762/*
1763 * ------------------------------------------------------------
1764 * rs_open() and friends
1765 * ------------------------------------------------------------
1766 */
1767static int block_til_ready(struct tty_struct *tty, struct file * filp,
1768 ser_info_t *info)
1769{
1770#ifdef DO_THIS_LATER
1771 DECLARE_WAITQUEUE(wait, current);
1772#endif
1773 struct serial_state *state = info->state;
1774 int retval;
1775 int do_clocal = 0;
1776
1777 /*
1778 * If the device is in the middle of being closed, then block
1779 * until it's done, and then try again.
1780 */
1781 if (tty_hung_up_p(filp) ||
1782 (info->flags & ASYNC_CLOSING)) {
1783 if (info->flags & ASYNC_CLOSING)
1784 interruptible_sleep_on(&info->close_wait);
1785#ifdef SERIAL_DO_RESTART
1786 if (info->flags & ASYNC_HUP_NOTIFY)
1787 return -EAGAIN;
1788 else
1789 return -ERESTARTSYS;
1790#else
1791 return -EAGAIN;
1792#endif
1793 }
1794
1795 /*
1796 * If non-blocking mode is set, or the port is not enabled,
1797 * then make the check up front and then exit.
1798 * If this is an SMC port, we don't have modem control to wait
1799 * for, so just get out here.
1800 */
1801 if ((filp->f_flags & O_NONBLOCK) ||
1802 (tty->flags & (1 << TTY_IO_ERROR)) ||
1803 !(info->state->smc_scc_num & NUM_IS_SCC)) {
1804 info->flags |= ASYNC_NORMAL_ACTIVE;
1805 return 0;
1806 }
1807
1808 if (tty->termios->c_cflag & CLOCAL)
1809 do_clocal = 1;
1810
1811 /*
1812 * Block waiting for the carrier detect and the line to become
1813 * free (i.e., not in use by the callout). While we are in
1814 * this loop, state->count is dropped by one, so that
1815 * rs_close() knows when to free things. We restore it upon
1816 * exit, either normal or abnormal.
1817 */
1818 retval = 0;
1819#ifdef DO_THIS_LATER
1820 add_wait_queue(&info->open_wait, &wait);
1821#ifdef SERIAL_DEBUG_OPEN
1822 printk("block_til_ready before block: ttys%d, count = %d\n",
1823 state->line, state->count);
1824#endif
1825 local_irq_disable();
1826 if (!tty_hung_up_p(filp))
1827 state->count--;
1828 local_irq_enable();
1829 info->blocked_open++;
1830 while (1) {
1831 local_irq_disable();
1832 if (tty->termios->c_cflag & CBAUD)
1833 serial_out(info, UART_MCR,
1834 serial_inp(info, UART_MCR) |
1835 (UART_MCR_DTR | UART_MCR_RTS));
1836 local_irq_enable();
1837 set_current_state(TASK_INTERRUPTIBLE);
1838 if (tty_hung_up_p(filp) ||
1839 !(info->flags & ASYNC_INITIALIZED)) {
1840#ifdef SERIAL_DO_RESTART
1841 if (info->flags & ASYNC_HUP_NOTIFY)
1842 retval = -EAGAIN;
1843 else
1844 retval = -ERESTARTSYS;
1845#else
1846 retval = -EAGAIN;
1847#endif
1848 break;
1849 }
1850 if (!(info->flags & ASYNC_CLOSING) &&
1851 (do_clocal || (serial_in(info, UART_MSR) &
1852 UART_MSR_DCD)))
1853 break;
1854 if (signal_pending(current)) {
1855 retval = -ERESTARTSYS;
1856 break;
1857 }
1858#ifdef SERIAL_DEBUG_OPEN
1859 printk("block_til_ready blocking: ttys%d, count = %d\n",
1860 info->line, state->count);
1861#endif
1862 tty_unlock();
1863 schedule();
1864 tty_lock();
1865 }
1866 current->state = TASK_RUNNING;
1867 remove_wait_queue(&info->open_wait, &wait);
1868 if (!tty_hung_up_p(filp))
1869 state->count++;
1870 info->blocked_open--;
1871#ifdef SERIAL_DEBUG_OPEN
1872 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1873 info->line, state->count);
1874#endif
1875#endif /* DO_THIS_LATER */
1876 if (retval)
1877 return retval;
1878 info->flags |= ASYNC_NORMAL_ACTIVE;
1879 return 0;
1880}
1881
1882static int get_async_struct(int line, ser_info_t **ret_info)
1883{
1884 struct serial_state *sstate;
1885
1886 sstate = rs_table + line;
1887 if (sstate->info) {
1888 sstate->count++;
1889 *ret_info = (ser_info_t *)sstate->info;
1890 return 0;
1891 }
1892 else {
1893 return -ENOMEM;
1894 }
1895}
1896
1897/*
1898 * This routine is called whenever a serial port is opened. It
1899 * enables interrupts for a serial port, linking in its async structure into
1900 * the IRQ chain. It also performs the serial-specific
1901 * initialization for the tty structure.
1902 */
1903static int rs_360_open(struct tty_struct *tty, struct file * filp)
1904{
1905 ser_info_t *info;
1906 int retval, line;
1907
1908 line = tty->index;
1909 if ((line < 0) || (line >= NR_PORTS))
1910 return -ENODEV;
1911 retval = get_async_struct(line, &info);
1912 if (retval)
1913 return retval;
1914 if (serial_paranoia_check(info, tty->name, "rs_open"))
1915 return -ENODEV;
1916
1917#ifdef SERIAL_DEBUG_OPEN
1918 printk("rs_open %s, count = %d\n", tty->name, info->state->count);
1919#endif
1920 tty->driver_data = info;
1921 info->port.tty = tty;
1922
1923 /*
1924 * Start up serial port
1925 */
1926 retval = startup(info);
1927 if (retval)
1928 return retval;
1929
1930 retval = block_til_ready(tty, filp, info);
1931 if (retval) {
1932#ifdef SERIAL_DEBUG_OPEN
1933 printk("rs_open returning after block_til_ready with %d\n",
1934 retval);
1935#endif
1936 return retval;
1937 }
1938
1939#ifdef SERIAL_DEBUG_OPEN
1940 printk("rs_open %s successful...", tty->name);
1941#endif
1942 return 0;
1943}
1944
1945/*
1946 * /proc fs routines....
1947 */
1948
1949static inline int line_info(char *buf, struct serial_state *state)
1950{
1951#ifdef notdef
1952 struct async_struct *info = state->info, scr_info;
1953 char stat_buf[30], control, status;
1954#endif
1955 int ret;
1956
1957 ret = sprintf(buf, "%d: uart:%s port:%X irq:%d",
1958 state->line,
1959 (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC",
1960 (unsigned int)(state->port), state->irq);
1961
1962 if (!state->port || (state->type == PORT_UNKNOWN)) {
1963 ret += sprintf(buf+ret, "\n");
1964 return ret;
1965 }
1966
1967#ifdef notdef
1968 /*
1969 * Figure out the current RS-232 lines
1970 */
1971 if (!info) {
1972 info = &scr_info; /* This is just for serial_{in,out} */
1973
1974 info->magic = SERIAL_MAGIC;
1975 info->port = state->port;
1976 info->flags = state->flags;
1977 info->quot = 0;
1978 info->port.tty = NULL;
1979 }
1980 local_irq_disable();
1981 status = serial_in(info, UART_MSR);
1982 control = info ? info->MCR : serial_in(info, UART_MCR);
1983 local_irq_enable();
1984
1985 stat_buf[0] = 0;
1986 stat_buf[1] = 0;
1987 if (control & UART_MCR_RTS)
1988 strcat(stat_buf, "|RTS");
1989 if (status & UART_MSR_CTS)
1990 strcat(stat_buf, "|CTS");
1991 if (control & UART_MCR_DTR)
1992 strcat(stat_buf, "|DTR");
1993 if (status & UART_MSR_DSR)
1994 strcat(stat_buf, "|DSR");
1995 if (status & UART_MSR_DCD)
1996 strcat(stat_buf, "|CD");
1997 if (status & UART_MSR_RI)
1998 strcat(stat_buf, "|RI");
1999
2000 if (info->quot) {
2001 ret += sprintf(buf+ret, " baud:%d",
2002 state->baud_base / info->quot);
2003 }
2004
2005 ret += sprintf(buf+ret, " tx:%d rx:%d",
2006 state->icount.tx, state->icount.rx);
2007
2008 if (state->icount.frame)
2009 ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
2010
2011 if (state->icount.parity)
2012 ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
2013
2014 if (state->icount.brk)
2015 ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
2016
2017 if (state->icount.overrun)
2018 ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
2019
2020 /*
2021 * Last thing is the RS-232 status lines
2022 */
2023 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
2024#endif
2025 return ret;
2026}
2027
2028int rs_360_read_proc(char *page, char **start, off_t off, int count,
2029 int *eof, void *data)
2030{
2031 int i, len = 0;
2032 off_t begin = 0;
2033
2034 len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);
2035 for (i = 0; i < NR_PORTS && len < 4000; i++) {
2036 len += line_info(page + len, &rs_table[i]);
2037 if (len+begin > off+count)
2038 goto done;
2039 if (len+begin < off) {
2040 begin += len;
2041 len = 0;
2042 }
2043 }
2044 *eof = 1;
2045done:
2046 if (off >= len+begin)
2047 return 0;
2048 *start = page + (begin-off);
2049 return ((count < begin+len-off) ? count : begin+len-off);
2050}
2051
2052/*
2053 * ---------------------------------------------------------------------
2054 * rs_init() and friends
2055 *
2056 * rs_init() is called at boot-time to initialize the serial driver.
2057 * ---------------------------------------------------------------------
2058 */
2059
2060/*
2061 * This routine prints out the appropriate serial driver version
2062 * number, and identifies which options were configured into this
2063 * driver.
2064 */
2065static _INLINE_ void show_serial_version(void)
2066{
2067 printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
2068}
2069
2070
2071/*
2072 * The serial console driver used during boot. Note that these names
2073 * clash with those found in "serial.c", so we currently can't support
2074 * the 16xxx uarts and these at the same time. I will fix this to become
2075 * an indirect function call from tty_io.c (or something).
2076 */
2077
2078#ifdef CONFIG_SERIAL_CONSOLE
2079
2080/*
2081 * Print a string to the serial port trying not to disturb any possible
2082 * real use of the port...
2083 */
2084static void my_console_write(int idx, const char *s,
2085 unsigned count)
2086{
2087 struct serial_state *ser;
2088 ser_info_t *info;
2089 unsigned i;
2090 QUICC_BD *bdp, *bdbase;
2091 volatile struct smc_uart_pram *up;
2092 volatile u_char *cp;
2093
2094 ser = rs_table + idx;
2095
2096
2097 /* If the port has been initialized for general use, we have
2098 * to use the buffer descriptors allocated there. Otherwise,
2099 * we simply use the single buffer allocated.
2100 */
2101 if ((info = (ser_info_t *)ser->info) != NULL) {
2102 bdp = info->tx_cur;
2103 bdbase = info->tx_bd_base;
2104 }
2105 else {
2106 /* Pointer to UART in parameter ram.
2107 */
2108 /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
2109 up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
2110
2111 /* Get the address of the host memory buffer.
2112 */
2113 bdp = bdbase = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
2114 }
2115
2116 /*
2117 * We need to gracefully shut down the transmitter, disable
2118 * interrupts, then send our bytes out.
2119 */
2120
2121 /*
2122 * Now, do each character. This is not as bad as it looks
2123 * since this is a holding FIFO and not a transmitting FIFO.
2124 * We could add the complexity of filling the entire transmit
2125 * buffer, but we would just wait longer between accesses......
2126 */
2127 for (i = 0; i < count; i++, s++) {
2128 /* Wait for transmitter fifo to empty.
2129 * Ready indicates output is ready, and xmt is doing
2130 * that, not that it is ready for us to send.
2131 */
2132 while (bdp->status & BD_SC_READY);
2133
2134 /* Send the character out.
2135 */
2136 cp = bdp->buf;
2137 *cp = *s;
2138
2139 bdp->length = 1;
2140 bdp->status |= BD_SC_READY;
2141
2142 if (bdp->status & BD_SC_WRAP)
2143 bdp = bdbase;
2144 else
2145 bdp++;
2146
2147 /* if a LF, also do CR... */
2148 if (*s == 10) {
2149 while (bdp->status & BD_SC_READY);
2150 /* cp = __va(bdp->buf); */
2151 cp = bdp->buf;
2152 *cp = 13;
2153 bdp->length = 1;
2154 bdp->status |= BD_SC_READY;
2155
2156 if (bdp->status & BD_SC_WRAP) {
2157 bdp = bdbase;
2158 }
2159 else {
2160 bdp++;
2161 }
2162 }
2163 }
2164
2165 /*
2166 * Finally, Wait for transmitter & holding register to empty
2167 * and restore the IER
2168 */
2169 while (bdp->status & BD_SC_READY);
2170
2171 if (info)
2172 info->tx_cur = (QUICC_BD *)bdp;
2173}
2174
2175static void serial_console_write(struct console *c, const char *s,
2176 unsigned count)
2177{
2178#ifdef CONFIG_KGDB
2179 /* Try to let stub handle output. Returns true if it did. */
2180 if (kgdb_output_string(s, count))
2181 return;
2182#endif
2183 my_console_write(c->index, s, count);
2184}
2185
2186
2187
2188/*void console_print_68360(const char *p)
2189{
2190 const char *cp = p;
2191 int i;
2192
2193 for (i=0;cp[i]!=0;i++);
2194
2195 serial_console_write (p, i);
2196
2197 //Comment this if you want to have a strict interrupt-driven output
2198 //rs_fair_output();
2199
2200 return;
2201}*/
2202
2203
2204
2205
2206
2207
2208#ifdef CONFIG_XMON
2209int
2210xmon_360_write(const char *s, unsigned count)
2211{
2212 my_console_write(0, s, count);
2213 return(count);
2214}
2215#endif
2216
2217#ifdef CONFIG_KGDB
2218void
2219putDebugChar(char ch)
2220{
2221 my_console_write(0, &ch, 1);
2222}
2223#endif
2224
2225/*
2226 * Receive character from the serial port. This only works well
2227 * before the port is initialized for real use.
2228 */
2229static int my_console_wait_key(int idx, int xmon, char *obuf)
2230{
2231 struct serial_state *ser;
2232 u_char c, *cp;
2233 ser_info_t *info;
2234 QUICC_BD *bdp;
2235 volatile struct smc_uart_pram *up;
2236 int i;
2237
2238 ser = rs_table + idx;
2239
2240 /* Get the address of the host memory buffer.
2241 * If the port has been initialized for general use, we must
2242 * use information from the port structure.
2243 */
2244 if ((info = (ser_info_t *)ser->info))
2245 bdp = info->rx_cur;
2246 else
2247 /* bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase]; */
2248 bdp = (QUICC_BD *)((uint)pquicc + (uint)up->tbase);
2249
2250 /* Pointer to UART in parameter ram.
2251 */
2252 /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
2253 up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
2254
2255 /*
2256 * We need to gracefully shut down the receiver, disable
2257 * interrupts, then read the input.
2258 * XMON just wants a poll. If no character, return -1, else
2259 * return the character.
2260 */
2261 if (!xmon) {
2262 while (bdp->status & BD_SC_EMPTY);
2263 }
2264 else {
2265 if (bdp->status & BD_SC_EMPTY)
2266 return -1;
2267 }
2268
2269 cp = (char *)bdp->buf;
2270
2271 if (obuf) {
2272 i = c = bdp->length;
2273 while (i-- > 0)
2274 *obuf++ = *cp++;
2275 }
2276 else {
2277 c = *cp;
2278 }
2279 bdp->status |= BD_SC_EMPTY;
2280
2281 if (info) {
2282 if (bdp->status & BD_SC_WRAP) {
2283 bdp = info->rx_bd_base;
2284 }
2285 else {
2286 bdp++;
2287 }
2288 info->rx_cur = (QUICC_BD *)bdp;
2289 }
2290
2291 return((int)c);
2292}
2293
2294static int serial_console_wait_key(struct console *co)
2295{
2296 return(my_console_wait_key(co->index, 0, NULL));
2297}
2298
2299#ifdef CONFIG_XMON
2300int
2301xmon_360_read_poll(void)
2302{
2303 return(my_console_wait_key(0, 1, NULL));
2304}
2305
2306int
2307xmon_360_read_char(void)
2308{
2309 return(my_console_wait_key(0, 0, NULL));
2310}
2311#endif
2312
2313#ifdef CONFIG_KGDB
2314static char kgdb_buf[RX_BUF_SIZE], *kgdp;
2315static int kgdb_chars;
2316
2317unsigned char
2318getDebugChar(void)
2319{
2320 if (kgdb_chars <= 0) {
2321 kgdb_chars = my_console_wait_key(0, 0, kgdb_buf);
2322 kgdp = kgdb_buf;
2323 }
2324 kgdb_chars--;
2325
2326 return(*kgdp++);
2327}
2328
2329void kgdb_interruptible(int state)
2330{
2331}
2332void kgdb_map_scc(void)
2333{
2334 struct serial_state *ser;
2335 uint mem_addr;
2336 volatile QUICC_BD *bdp;
2337 volatile smc_uart_t *up;
2338
2339 cpmp = (cpm360_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);
2340
2341 /* To avoid data cache CPM DMA coherency problems, allocate a
2342 * buffer in the CPM DPRAM. This will work until the CPM and
2343 * serial ports are initialized. At that time a memory buffer
2344 * will be allocated.
2345 * The port is already initialized from the boot procedure, all
2346 * we do here is give it a different buffer and make it a FIFO.
2347 */
2348
2349 ser = rs_table;
2350
2351 /* Right now, assume we are using SMCs.
2352 */
2353 up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];
2354
2355 /* Allocate space for an input FIFO, plus a few bytes for output.
2356 * Allocate bytes to maintain word alignment.
2357 */
2358 mem_addr = (uint)(&cpmp->cp_dpmem[0x1000]);
2359
2360 /* Set the physical address of the host memory buffers in
2361 * the buffer descriptors.
2362 */
2363 bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase];
2364 bdp->buf = mem_addr;
2365
2366 bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_tbase];
2367 bdp->buf = mem_addr+RX_BUF_SIZE;
2368
2369 up->smc_mrblr = RX_BUF_SIZE; /* receive buffer length */
2370 up->smc_maxidl = RX_BUF_SIZE;
2371}
2372#endif
2373
2374static struct tty_struct *serial_console_device(struct console *c, int *index)
2375{
2376 *index = c->index;
2377 return serial_driver;
2378}
2379
2380
2381struct console sercons = {
2382 .name = "ttyS",
2383 .write = serial_console_write,
2384 .device = serial_console_device,
2385 .wait_key = serial_console_wait_key,
2386 .setup = serial_console_setup,
2387 .flags = CON_PRINTBUFFER,
2388 .index = CONFIG_SERIAL_CONSOLE_PORT,
2389};
2390
2391
2392
2393/*
2394 * Register console.
2395 */
2396long console_360_init(long kmem_start, long kmem_end)
2397{
2398 register_console(&sercons);
2399 /*register_console (console_print_68360); - 2.0.38 only required a write
2400 function pointer. */
2401 return kmem_start;
2402}
2403
2404#endif
2405
2406/* Index in baud rate table of the default console baud rate.
2407*/
2408static int baud_idx;
2409
2410static const struct tty_operations rs_360_ops = {
2411 .owner = THIS_MODULE,
2412 .open = rs_360_open,
2413 .close = rs_360_close,
2414 .write = rs_360_write,
2415 .put_char = rs_360_put_char,
2416 .write_room = rs_360_write_room,
2417 .chars_in_buffer = rs_360_chars_in_buffer,
2418 .flush_buffer = rs_360_flush_buffer,
2419 .ioctl = rs_360_ioctl,
2420 .throttle = rs_360_throttle,
2421 .unthrottle = rs_360_unthrottle,
2422 /* .send_xchar = rs_360_send_xchar, */
2423 .set_termios = rs_360_set_termios,
2424 .stop = rs_360_stop,
2425 .start = rs_360_start,
2426 .hangup = rs_360_hangup,
2427 /* .wait_until_sent = rs_360_wait_until_sent, */
2428 /* .read_proc = rs_360_read_proc, */
2429 .tiocmget = rs_360_tiocmget,
2430 .tiocmset = rs_360_tiocmset,
2431 .get_icount = rs_360_get_icount,
2432};
2433
2434static int __init rs_360_init(void)
2435{
2436 struct serial_state * state;
2437 ser_info_t *info;
2438 void *mem_addr;
2439 uint dp_addr, iobits;
2440 int i, j, idx;
2441 ushort chan;
2442 QUICC_BD *bdp;
2443 volatile QUICC *cp;
2444 volatile struct smc_regs *sp;
2445 volatile struct smc_uart_pram *up;
2446 volatile struct scc_regs *scp;
2447 volatile struct uart_pram *sup;
2448 /* volatile immap_t *immap; */
2449
2450 serial_driver = alloc_tty_driver(NR_PORTS);
2451 if (!serial_driver)
2452 return -1;
2453
2454 show_serial_version();
2455
2456 serial_driver->name = "ttyS";
2457 serial_driver->major = TTY_MAJOR;
2458 serial_driver->minor_start = 64;
2459 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2460 serial_driver->subtype = SERIAL_TYPE_NORMAL;
2461 serial_driver->init_termios = tty_std_termios;
2462 serial_driver->init_termios.c_cflag =
2463 baud_idx | CS8 | CREAD | HUPCL | CLOCAL;
2464 serial_driver->flags = TTY_DRIVER_REAL_RAW;
2465 tty_set_operations(serial_driver, &rs_360_ops);
2466
2467 if (tty_register_driver(serial_driver))
2468 panic("Couldn't register serial driver\n");
2469
2470 cp = pquicc; /* Get pointer to Communication Processor */
2471 /* immap = (immap_t *)IMAP_ADDR; */ /* and to internal registers */
2472
2473
2474 /* Configure SCC2, SCC3, and SCC4 instead of port A parallel I/O.
2475 */
2476 /* The "standard" configuration through the 860.
2477 */
2478/* immap->im_ioport.iop_papar |= 0x00fc; */
2479/* immap->im_ioport.iop_padir &= ~0x00fc; */
2480/* immap->im_ioport.iop_paodr &= ~0x00fc; */
2481 cp->pio_papar |= 0x00fc;
2482 cp->pio_padir &= ~0x00fc;
2483 /* cp->pio_paodr &= ~0x00fc; */
2484
2485
2486 /* Since we don't yet do modem control, connect the port C pins
2487 * as general purpose I/O. This will assert CTS and CD for the
2488 * SCC ports.
2489 */
2490 /* FIXME: see 360um p.7-365 and 860um p.34-12
2491 * I can't make sense of these bits - mleslie*/
2492/* immap->im_ioport.iop_pcdir |= 0x03c6; */
2493/* immap->im_ioport.iop_pcpar &= ~0x03c6; */
2494
2495/* cp->pio_pcdir |= 0x03c6; */
2496/* cp->pio_pcpar &= ~0x03c6; */
2497
2498
2499
2500 /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
2501 * BRG4 to SCC3.
2502 */
2503 cp->si_sicr &= ~0x00ffff00;
2504 cp->si_sicr |= 0x001b1200;
2505
2506#ifdef CONFIG_PP04
2507 /* Frequentis PP04 forced to RS-232 until we know better.
2508 * Port C 12 and 13 low enables RS-232 on SCC3 and SCC4.
2509 */
2510 immap->im_ioport.iop_pcdir |= 0x000c;
2511 immap->im_ioport.iop_pcpar &= ~0x000c;
2512 immap->im_ioport.iop_pcdat &= ~0x000c;
2513
2514 /* This enables the TX driver.
2515 */
2516 cp->cp_pbpar &= ~0x6000;
2517 cp->cp_pbdat &= ~0x6000;
2518#endif
2519
2520 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
2521 state->magic = SSTATE_MAGIC;
2522 state->line = i;
2523 state->type = PORT_UNKNOWN;
2524 state->custom_divisor = 0;
2525 state->close_delay = 5*HZ/10;
2526 state->closing_wait = 30*HZ;
2527 state->icount.cts = state->icount.dsr =
2528 state->icount.rng = state->icount.dcd = 0;
2529 state->icount.rx = state->icount.tx = 0;
2530 state->icount.frame = state->icount.parity = 0;
2531 state->icount.overrun = state->icount.brk = 0;
2532 printk(KERN_INFO "ttyS%d at irq 0x%02x is an %s\n",
2533 i, (unsigned int)(state->irq),
2534 (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC");
2535
2536#ifdef CONFIG_SERIAL_CONSOLE
2537 /* If we just printed the message on the console port, and
2538 * we are about to initialize it for general use, we have
2539 * to wait a couple of character times for the CR/NL to
2540 * make it out of the transmit buffer.
2541 */
2542 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2543 mdelay(8);
2544
2545
2546/* idx = PORT_NUM(info->state->smc_scc_num); */
2547/* if (info->state->smc_scc_num & NUM_IS_SCC) */
2548/* chan = scc_chan_map[idx]; */
2549/* else */
2550/* chan = smc_chan_map[idx]; */
2551
2552/* cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG; */
2553/* while (cp->cp_cr & CPM_CR_FLG); */
2554
2555#endif
2556 /* info = kmalloc(sizeof(ser_info_t), GFP_KERNEL); */
2557 info = &quicc_ser_info[i];
2558 if (info) {
2559 memset (info, 0, sizeof(ser_info_t));
2560 info->magic = SERIAL_MAGIC;
2561 info->line = i;
2562 info->flags = state->flags;
2563 INIT_WORK(&info->tqueue, do_softint, info);
2564 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
2565 init_waitqueue_head(&info->open_wait);
2566 init_waitqueue_head(&info->close_wait);
2567 info->state = state;
2568 state->info = (struct async_struct *)info;
2569
2570 /* We need to allocate a transmit and receive buffer
2571 * descriptors from dual port ram, and a character
2572 * buffer area from host mem.
2573 */
2574 dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * RX_NUM_FIFO);
2575
2576 /* Allocate space for FIFOs in the host memory.
2577 * (for now this is from a static array of buffers :(
2578 */
2579 /* mem_addr = m360_cpm_hostalloc(RX_NUM_FIFO * RX_BUF_SIZE); */
2580 /* mem_addr = kmalloc (RX_NUM_FIFO * RX_BUF_SIZE, GFP_BUFFER); */
2581 mem_addr = &rx_buf_pool[i * RX_NUM_FIFO * RX_BUF_SIZE];
2582
2583 /* Set the physical address of the host memory
2584 * buffers in the buffer descriptors, and the
2585 * virtual address for us to work with.
2586 */
2587 bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
2588 info->rx_cur = info->rx_bd_base = bdp;
2589
2590 /* initialize rx buffer descriptors */
2591 for (j=0; j<(RX_NUM_FIFO-1); j++) {
2592 bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
2593 bdp->status = BD_SC_EMPTY | BD_SC_INTRPT;
2594 mem_addr += RX_BUF_SIZE;
2595 bdp++;
2596 }
2597 bdp->buf = &rx_buf_pool[(i * RX_NUM_FIFO + j ) * RX_BUF_SIZE];
2598 bdp->status = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
2599
2600
2601 idx = PORT_NUM(info->state->smc_scc_num);
2602 if (info->state->smc_scc_num & NUM_IS_SCC) {
2603
2604#if defined (CONFIG_UCQUICC) && 1
2605 /* set the transceiver mode to RS232 */
2606 sipex_mode_bits &= ~(uint)SIPEX_MODE(idx,0x0f); /* clear current mode */
2607 sipex_mode_bits |= (uint)SIPEX_MODE(idx,0x02);
2608 *(uint *)_periph_base = sipex_mode_bits;
2609 /* printk ("sipex bits = 0x%08x\n", sipex_mode_bits); */
2610#endif
2611 }
2612
2613 dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * TX_NUM_FIFO);
2614
2615 /* Allocate space for FIFOs in the host memory.
2616 */
2617 /* mem_addr = m360_cpm_hostalloc(TX_NUM_FIFO * TX_BUF_SIZE); */
2618 /* mem_addr = kmalloc (TX_NUM_FIFO * TX_BUF_SIZE, GFP_BUFFER); */
2619 mem_addr = &tx_buf_pool[i * TX_NUM_FIFO * TX_BUF_SIZE];
2620
2621 /* Set the physical address of the host memory
2622 * buffers in the buffer descriptors, and the
2623 * virtual address for us to work with.
2624 */
2625 /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
2626 bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
2627 info->tx_cur = info->tx_bd_base = (QUICC_BD *)bdp;
2628
2629 /* initialize tx buffer descriptors */
2630 for (j=0; j<(TX_NUM_FIFO-1); j++) {
2631 bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
2632 bdp->status = BD_SC_INTRPT;
2633 mem_addr += TX_BUF_SIZE;
2634 bdp++;
2635 }
2636 bdp->buf = &tx_buf_pool[(i * TX_NUM_FIFO + j ) * TX_BUF_SIZE];
2637 bdp->status = (BD_SC_WRAP | BD_SC_INTRPT);
2638
2639 if (info->state->smc_scc_num & NUM_IS_SCC) {
2640 scp = &pquicc->scc_regs[idx];
2641 sup = &pquicc->pram[info->state->port].scc.pscc.u;
2642 sup->rbase = dp_addr;
2643 sup->tbase = dp_addr;
2644
2645 /* Set up the uart parameters in the
2646 * parameter ram.
2647 */
2648 sup->rfcr = SMC_EB;
2649 sup->tfcr = SMC_EB;
2650
2651 /* Set this to 1 for now, so we get single
2652 * character interrupts. Using idle character
2653 * time requires some additional tuning.
2654 */
2655 sup->mrblr = 1;
2656 sup->max_idl = 0;
2657 sup->brkcr = 1;
2658 sup->parec = 0;
2659 sup->frmer = 0;
2660 sup->nosec = 0;
2661 sup->brkec = 0;
2662 sup->uaddr1 = 0;
2663 sup->uaddr2 = 0;
2664 sup->toseq = 0;
2665 {
2666 int i;
2667 for (i=0;i<8;i++)
2668 sup->cc[i] = 0x8000;
2669 }
2670 sup->rccm = 0xc0ff;
2671
2672 /* Send the CPM an initialize command.
2673 */
2674 chan = scc_chan_map[idx];
2675
2676 /* execute the INIT RX & TX PARAMS command for this channel. */
2677 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
2678 while (cp->cp_cr & CPM_CR_FLG);
2679
2680 /* Set UART mode, 8 bit, no parity, one stop.
2681 * Enable receive and transmit.
2682 */
2683 scp->scc_gsmr.w.high = 0;
2684 scp->scc_gsmr.w.low =
2685 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
2686
2687 /* Disable all interrupts and clear all pending
2688 * events.
2689 */
2690 scp->scc_sccm = 0;
2691 scp->scc_scce = 0xffff;
2692 scp->scc_dsr = 0x7e7e;
2693 scp->scc_psmr = 0x3000;
2694
2695 /* If the port is the console, enable Rx and Tx.
2696 */
2697#ifdef CONFIG_SERIAL_CONSOLE
2698 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2699 scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2700#endif
2701 }
2702 else {
2703 /* Configure SMCs Tx/Rx instead of port B
2704 * parallel I/O.
2705 */
2706 up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;
2707 up->rbase = dp_addr;
2708
2709 iobits = 0xc0 << (idx * 4);
2710 cp->pip_pbpar |= iobits;
2711 cp->pip_pbdir &= ~iobits;
2712 cp->pip_pbodr &= ~iobits;
2713
2714
2715 /* Connect the baud rate generator to the
2716 * SMC based upon index in rs_table. Also
2717 * make sure it is connected to NMSI.
2718 */
2719 cp->si_simode &= ~(0xffff << (idx * 16));
2720 cp->si_simode |= (i << ((idx * 16) + 12));
2721
2722 up->tbase = dp_addr;
2723
2724 /* Set up the uart parameters in the
2725 * parameter ram.
2726 */
2727 up->rfcr = SMC_EB;
2728 up->tfcr = SMC_EB;
2729
2730 /* Set this to 1 for now, so we get single
2731 * character interrupts. Using idle character
2732 * time requires some additional tuning.
2733 */
2734 up->mrblr = 1;
2735 up->max_idl = 0;
2736 up->brkcr = 1;
2737
2738 /* Send the CPM an initialize command.
2739 */
2740 chan = smc_chan_map[idx];
2741
2742 cp->cp_cr = mk_cr_cmd(chan,
2743 CPM_CR_INIT_TRX) | CPM_CR_FLG;
2744#ifdef CONFIG_SERIAL_CONSOLE
2745 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2746 printk("");
2747#endif
2748 while (cp->cp_cr & CPM_CR_FLG);
2749
2750 /* Set UART mode, 8 bit, no parity, one stop.
2751 * Enable receive and transmit.
2752 */
2753 sp = &cp->smc_regs[idx];
2754 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
2755
2756 /* Disable all interrupts and clear all pending
2757 * events.
2758 */
2759 sp->smc_smcm = 0;
2760 sp->smc_smce = 0xff;
2761
2762 /* If the port is the console, enable Rx and Tx.
2763 */
2764#ifdef CONFIG_SERIAL_CONSOLE
2765 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2766 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
2767#endif
2768 }
2769
2770 /* Install interrupt handler.
2771 */
2772 /* cpm_install_handler(IRQ_MACHSPEC | state->irq, rs_360_interrupt, info); */
2773 /*request_irq(IRQ_MACHSPEC | state->irq, rs_360_interrupt, */
2774 request_irq(state->irq, rs_360_interrupt,
2775 IRQ_FLG_LOCK, "ttyS", (void *)info);
2776
2777 /* Set up the baud rate generator.
2778 */
2779 m360_cpm_setbrg(i, baud_table[baud_idx]);
2780
2781 }
2782 }
2783
2784 return 0;
2785}
2786module_init(rs_360_init);
2787
2788/* This must always be called before the rs_360_init() function, otherwise
2789 * it blows away the port control information.
2790 */
2791//static int __init serial_console_setup( struct console *co, char *options)
2792int serial_console_setup( struct console *co, char *options)
2793{
2794 struct serial_state *ser;
2795 uint mem_addr, dp_addr, bidx, idx, iobits;
2796 ushort chan;
2797 QUICC_BD *bdp;
2798 volatile QUICC *cp;
2799 volatile struct smc_regs *sp;
2800 volatile struct scc_regs *scp;
2801 volatile struct smc_uart_pram *up;
2802 volatile struct uart_pram *sup;
2803
2804/* mleslie TODO:
2805 * add something to the 68k bootloader to store a desired initial console baud rate */
2806
2807/* bd_t *bd; */ /* a board info struct used by EPPC-bug */
2808/* bd = (bd_t *)__res; */
2809
2810 for (bidx = 0; bidx < (sizeof(baud_table) / sizeof(int)); bidx++)
2811 /* if (bd->bi_baudrate == baud_table[bidx]) */
2812 if (CONSOLE_BAUDRATE == baud_table[bidx])
2813 break;
2814
2815 /* co->cflag = CREAD|CLOCAL|bidx|CS8; */
2816 baud_idx = bidx;
2817
2818 ser = rs_table + CONFIG_SERIAL_CONSOLE_PORT;
2819
2820 cp = pquicc; /* Get pointer to Communication Processor */
2821
2822 idx = PORT_NUM(ser->smc_scc_num);
2823 if (ser->smc_scc_num & NUM_IS_SCC) {
2824
2825 /* TODO: need to set up SCC pin assignment etc. here */
2826
2827 }
2828 else {
2829 iobits = 0xc0 << (idx * 4);
2830 cp->pip_pbpar |= iobits;
2831 cp->pip_pbdir &= ~iobits;
2832 cp->pip_pbodr &= ~iobits;
2833
2834 /* Connect the baud rate generator to the
2835 * SMC based upon index in rs_table. Also
2836 * make sure it is connected to NMSI.
2837 */
2838 cp->si_simode &= ~(0xffff << (idx * 16));
2839 cp->si_simode |= (idx << ((idx * 16) + 12));
2840 }
2841
2842 /* When we get here, the CPM has been reset, so we need
2843 * to configure the port.
2844 * We need to allocate a transmit and receive buffer descriptor
2845 * from dual port ram, and a character buffer area from host mem.
2846 */
2847
2848 /* Allocate space for two buffer descriptors in the DP ram.
2849 */
2850 dp_addr = m360_cpm_dpalloc(sizeof(QUICC_BD) * CONSOLE_NUM_FIFO);
2851
2852 /* Allocate space for two 2 byte FIFOs in the host memory.
2853 */
2854 /* mem_addr = m360_cpm_hostalloc(8); */
2855 mem_addr = (uint)console_fifos;
2856
2857
2858 /* Set the physical address of the host memory buffers in
2859 * the buffer descriptors.
2860 */
2861 /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
2862 bdp = (QUICC_BD *)((uint)pquicc + dp_addr);
2863 bdp->buf = (char *)mem_addr;
2864 (bdp+1)->buf = (char *)(mem_addr+4);
2865
2866 /* For the receive, set empty and wrap.
2867 * For transmit, set wrap.
2868 */
2869 bdp->status = BD_SC_EMPTY | BD_SC_WRAP;
2870 (bdp+1)->status = BD_SC_WRAP;
2871
2872 /* Set up the uart parameters in the parameter ram.
2873 */
2874 if (ser->smc_scc_num & NUM_IS_SCC) {
2875 scp = &cp->scc_regs[idx];
2876 /* sup = (scc_uart_t *)&cp->cp_dparam[ser->port]; */
2877 sup = &pquicc->pram[ser->port].scc.pscc.u;
2878
2879 sup->rbase = dp_addr;
2880 sup->tbase = dp_addr + sizeof(QUICC_BD);
2881
2882 /* Set up the uart parameters in the
2883 * parameter ram.
2884 */
2885 sup->rfcr = SMC_EB;
2886 sup->tfcr = SMC_EB;
2887
2888 /* Set this to 1 for now, so we get single
2889 * character interrupts. Using idle character
2890 * time requires some additional tuning.
2891 */
2892 sup->mrblr = 1;
2893 sup->max_idl = 0;
2894 sup->brkcr = 1;
2895 sup->parec = 0;
2896 sup->frmer = 0;
2897 sup->nosec = 0;
2898 sup->brkec = 0;
2899 sup->uaddr1 = 0;
2900 sup->uaddr2 = 0;
2901 sup->toseq = 0;
2902 {
2903 int i;
2904 for (i=0;i<8;i++)
2905 sup->cc[i] = 0x8000;
2906 }
2907 sup->rccm = 0xc0ff;
2908
2909 /* Send the CPM an initialize command.
2910 */
2911 chan = scc_chan_map[idx];
2912
2913 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
2914 while (cp->cp_cr & CPM_CR_FLG);
2915
2916 /* Set UART mode, 8 bit, no parity, one stop.
2917 * Enable receive and transmit.
2918 */
2919 scp->scc_gsmr.w.high = 0;
2920 scp->scc_gsmr.w.low =
2921 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
2922
2923 /* Disable all interrupts and clear all pending
2924 * events.
2925 */
2926 scp->scc_sccm = 0;
2927 scp->scc_scce = 0xffff;
2928 scp->scc_dsr = 0x7e7e;
2929 scp->scc_psmr = 0x3000;
2930
2931 scp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2932
2933 }
2934 else {
2935 /* up = (smc_uart_t *)&cp->cp_dparam[ser->port]; */
2936 up = &pquicc->pram[ser->port].scc.pothers.idma_smc.psmc.u;
2937
2938 up->rbase = dp_addr; /* Base of receive buffer desc. */
2939 up->tbase = dp_addr+sizeof(QUICC_BD); /* Base of xmt buffer desc. */
2940 up->rfcr = SMC_EB;
2941 up->tfcr = SMC_EB;
2942
2943 /* Set this to 1 for now, so we get single character interrupts.
2944 */
2945 up->mrblr = 1; /* receive buffer length */
2946 up->max_idl = 0; /* wait forever for next char */
2947
2948 /* Send the CPM an initialize command.
2949 */
2950 chan = smc_chan_map[idx];
2951 cp->cp_cr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
2952 while (cp->cp_cr & CPM_CR_FLG);
2953
2954 /* Set UART mode, 8 bit, no parity, one stop.
2955 * Enable receive and transmit.
2956 */
2957 sp = &cp->smc_regs[idx];
2958 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
2959
2960 /* And finally, enable Rx and Tx.
2961 */
2962 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
2963 }
2964
2965 /* Set up the baud rate generator.
2966 */
2967 /* m360_cpm_setbrg((ser - rs_table), bd->bi_baudrate); */
2968 m360_cpm_setbrg((ser - rs_table), CONSOLE_BAUDRATE);
2969
2970 return 0;
2971}
2972
2973/*
2974 * Local variables:
2975 * c-indent-level: 4
2976 * c-basic-offset: 4
2977 * tab-width: 4
2978 * End:
2979 */
diff --git a/drivers/tty/serial/8250.c b/drivers/tty/serial/8250.c
index 7f50999eebc2..a87a56cb5417 100644
--- a/drivers/tty/serial/8250.c
+++ b/drivers/tty/serial/8250.c
@@ -309,6 +309,13 @@ static const struct serial8250_config uart_config[] = {
309 UART_FCR_T_TRIG_01, 309 UART_FCR_T_TRIG_01,
310 .flags = UART_CAP_FIFO | UART_CAP_RTOIE, 310 .flags = UART_CAP_FIFO | UART_CAP_RTOIE,
311 }, 311 },
312 [PORT_XR17D15X] = {
313 .name = "XR17D15X",
314 .fifo_size = 64,
315 .tx_loadsz = 64,
316 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
317 .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR,
318 },
312}; 319};
313 320
314#if defined(CONFIG_MIPS_ALCHEMY) 321#if defined(CONFIG_MIPS_ALCHEMY)
@@ -461,42 +468,6 @@ static void tsi_serial_out(struct uart_port *p, int offset, int value)
461 writeb(value, p->membase + offset); 468 writeb(value, p->membase + offset);
462} 469}
463 470
464/* Save the LCR value so it can be re-written when a Busy Detect IRQ occurs. */
465static inline void dwapb_save_out_value(struct uart_port *p, int offset,
466 int value)
467{
468 struct uart_8250_port *up =
469 container_of(p, struct uart_8250_port, port);
470
471 if (offset == UART_LCR)
472 up->lcr = value;
473}
474
475/* Read the IER to ensure any interrupt is cleared before returning from ISR. */
476static inline void dwapb_check_clear_ier(struct uart_port *p, int offset)
477{
478 if (offset == UART_TX || offset == UART_IER)
479 p->serial_in(p, UART_IER);
480}
481
482static void dwapb_serial_out(struct uart_port *p, int offset, int value)
483{
484 int save_offset = offset;
485 offset = map_8250_out_reg(p, offset) << p->regshift;
486 dwapb_save_out_value(p, save_offset, value);
487 writeb(value, p->membase + offset);
488 dwapb_check_clear_ier(p, save_offset);
489}
490
491static void dwapb32_serial_out(struct uart_port *p, int offset, int value)
492{
493 int save_offset = offset;
494 offset = map_8250_out_reg(p, offset) << p->regshift;
495 dwapb_save_out_value(p, save_offset, value);
496 writel(value, p->membase + offset);
497 dwapb_check_clear_ier(p, save_offset);
498}
499
500static unsigned int io_serial_in(struct uart_port *p, int offset) 471static unsigned int io_serial_in(struct uart_port *p, int offset)
501{ 472{
502 offset = map_8250_in_reg(p, offset) << p->regshift; 473 offset = map_8250_in_reg(p, offset) << p->regshift;
@@ -509,6 +480,8 @@ static void io_serial_out(struct uart_port *p, int offset, int value)
509 outb(value, p->iobase + offset); 480 outb(value, p->iobase + offset);
510} 481}
511 482
483static int serial8250_default_handle_irq(struct uart_port *port);
484
512static void set_io_from_upio(struct uart_port *p) 485static void set_io_from_upio(struct uart_port *p)
513{ 486{
514 struct uart_8250_port *up = 487 struct uart_8250_port *up =
@@ -540,16 +513,6 @@ static void set_io_from_upio(struct uart_port *p)
540 p->serial_out = tsi_serial_out; 513 p->serial_out = tsi_serial_out;
541 break; 514 break;
542 515
543 case UPIO_DWAPB:
544 p->serial_in = mem_serial_in;
545 p->serial_out = dwapb_serial_out;
546 break;
547
548 case UPIO_DWAPB32:
549 p->serial_in = mem32_serial_in;
550 p->serial_out = dwapb32_serial_out;
551 break;
552
553 default: 516 default:
554 p->serial_in = io_serial_in; 517 p->serial_in = io_serial_in;
555 p->serial_out = io_serial_out; 518 p->serial_out = io_serial_out;
@@ -557,6 +520,7 @@ static void set_io_from_upio(struct uart_port *p)
557 } 520 }
558 /* Remember loaded iotype */ 521 /* Remember loaded iotype */
559 up->cur_iotype = p->iotype; 522 up->cur_iotype = p->iotype;
523 p->handle_irq = serial8250_default_handle_irq;
560} 524}
561 525
562static void 526static void
@@ -567,8 +531,6 @@ serial_out_sync(struct uart_8250_port *up, int offset, int value)
567 case UPIO_MEM: 531 case UPIO_MEM:
568 case UPIO_MEM32: 532 case UPIO_MEM32:
569 case UPIO_AU: 533 case UPIO_AU:
570 case UPIO_DWAPB:
571 case UPIO_DWAPB32:
572 p->serial_out(p, offset, value); 534 p->serial_out(p, offset, value);
573 p->serial_in(p, UART_LCR); /* safe, no side-effects */ 535 p->serial_in(p, UART_LCR); /* safe, no side-effects */
574 break; 536 break;
@@ -1120,6 +1082,14 @@ static void autoconfig_16550a(struct uart_8250_port *up)
1120 serial_outp(up, UART_IER, iersave); 1082 serial_outp(up, UART_IER, iersave);
1121 1083
1122 /* 1084 /*
1085 * Exar uarts have EFR in a weird location
1086 */
1087 if (up->port.flags & UPF_EXAR_EFR) {
1088 up->port.type = PORT_XR17D15X;
1089 up->capabilities |= UART_CAP_AFE | UART_CAP_EFR;
1090 }
1091
1092 /*
1123 * We distinguish between 16550A and U6 16550A by counting 1093 * We distinguish between 16550A and U6 16550A by counting
1124 * how many bytes are in the FIFO. 1094 * how many bytes are in the FIFO.
1125 */ 1095 */
@@ -1621,6 +1591,29 @@ static void serial8250_handle_port(struct uart_8250_port *up)
1621 spin_unlock_irqrestore(&up->port.lock, flags); 1591 spin_unlock_irqrestore(&up->port.lock, flags);
1622} 1592}
1623 1593
1594int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
1595{
1596 struct uart_8250_port *up =
1597 container_of(port, struct uart_8250_port, port);
1598
1599 if (!(iir & UART_IIR_NO_INT)) {
1600 serial8250_handle_port(up);
1601 return 1;
1602 }
1603
1604 return 0;
1605}
1606EXPORT_SYMBOL_GPL(serial8250_handle_irq);
1607
1608static int serial8250_default_handle_irq(struct uart_port *port)
1609{
1610 struct uart_8250_port *up =
1611 container_of(port, struct uart_8250_port, port);
1612 unsigned int iir = serial_in(up, UART_IIR);
1613
1614 return serial8250_handle_irq(port, iir);
1615}
1616
1624/* 1617/*
1625 * This is the serial driver's interrupt routine. 1618 * This is the serial driver's interrupt routine.
1626 * 1619 *
@@ -1648,30 +1641,13 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
1648 l = i->head; 1641 l = i->head;
1649 do { 1642 do {
1650 struct uart_8250_port *up; 1643 struct uart_8250_port *up;
1651 unsigned int iir; 1644 struct uart_port *port;
1652 1645
1653 up = list_entry(l, struct uart_8250_port, list); 1646 up = list_entry(l, struct uart_8250_port, list);
1647 port = &up->port;
1654 1648
1655 iir = serial_in(up, UART_IIR); 1649 if (port->handle_irq(port)) {
1656 if (!(iir & UART_IIR_NO_INT)) {
1657 serial8250_handle_port(up);
1658
1659 handled = 1; 1650 handled = 1;
1660
1661 end = NULL;
1662 } else if ((up->port.iotype == UPIO_DWAPB ||
1663 up->port.iotype == UPIO_DWAPB32) &&
1664 (iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
1665 /* The DesignWare APB UART has an Busy Detect (0x07)
1666 * interrupt meaning an LCR write attempt occurred while the
1667 * UART was busy. The interrupt must be cleared by reading
1668 * the UART status register (USR) and the LCR re-written. */
1669 unsigned int status;
1670 status = *(volatile u32 *)up->port.private_data;
1671 serial_out(up, UART_LCR, up->lcr);
1672
1673 handled = 1;
1674
1675 end = NULL; 1651 end = NULL;
1676 } else if (end == NULL) 1652 } else if (end == NULL)
1677 end = l; 1653 end = l;
@@ -2081,8 +2057,8 @@ static int serial8250_startup(struct uart_port *port)
2081 */ 2057 */
2082 if (!(up->port.flags & UPF_BUGGY_UART) && 2058 if (!(up->port.flags & UPF_BUGGY_UART) &&
2083 (serial_inp(up, UART_LSR) == 0xff)) { 2059 (serial_inp(up, UART_LSR) == 0xff)) {
2084 printk(KERN_INFO "ttyS%d: LSR safety check engaged!\n", 2060 printk_ratelimited(KERN_INFO "ttyS%d: LSR safety check engaged!\n",
2085 serial_index(&up->port)); 2061 serial_index(&up->port));
2086 return -ENODEV; 2062 return -ENODEV;
2087 } 2063 }
2088 2064
@@ -2458,7 +2434,10 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2458 efr |= UART_EFR_CTS; 2434 efr |= UART_EFR_CTS;
2459 2435
2460 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); 2436 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B);
2461 serial_outp(up, UART_EFR, efr); 2437 if (up->port.flags & UPF_EXAR_EFR)
2438 serial_outp(up, UART_XR_EFR, efr);
2439 else
2440 serial_outp(up, UART_EFR, efr);
2462 } 2441 }
2463 2442
2464#ifdef CONFIG_ARCH_OMAP 2443#ifdef CONFIG_ARCH_OMAP
@@ -2570,8 +2549,6 @@ static int serial8250_request_std_resource(struct uart_8250_port *up)
2570 case UPIO_TSI: 2549 case UPIO_TSI:
2571 case UPIO_MEM32: 2550 case UPIO_MEM32:
2572 case UPIO_MEM: 2551 case UPIO_MEM:
2573 case UPIO_DWAPB:
2574 case UPIO_DWAPB32:
2575 if (!up->port.mapbase) 2552 if (!up->port.mapbase)
2576 break; 2553 break;
2577 2554
@@ -2608,8 +2585,6 @@ static void serial8250_release_std_resource(struct uart_8250_port *up)
2608 case UPIO_TSI: 2585 case UPIO_TSI:
2609 case UPIO_MEM32: 2586 case UPIO_MEM32:
2610 case UPIO_MEM: 2587 case UPIO_MEM:
2611 case UPIO_DWAPB:
2612 case UPIO_DWAPB32:
2613 if (!up->port.mapbase) 2588 if (!up->port.mapbase)
2614 break; 2589 break;
2615 2590
@@ -3050,6 +3025,10 @@ int __init early_serial_setup(struct uart_port *port)
3050 p->serial_in = port->serial_in; 3025 p->serial_in = port->serial_in;
3051 if (port->serial_out) 3026 if (port->serial_out)
3052 p->serial_out = port->serial_out; 3027 p->serial_out = port->serial_out;
3028 if (port->handle_irq)
3029 p->handle_irq = port->handle_irq;
3030 else
3031 p->handle_irq = serial8250_default_handle_irq;
3053 3032
3054 return 0; 3033 return 0;
3055} 3034}
@@ -3118,6 +3097,7 @@ static int __devinit serial8250_probe(struct platform_device *dev)
3118 port.type = p->type; 3097 port.type = p->type;
3119 port.serial_in = p->serial_in; 3098 port.serial_in = p->serial_in;
3120 port.serial_out = p->serial_out; 3099 port.serial_out = p->serial_out;
3100 port.handle_irq = p->handle_irq;
3121 port.set_termios = p->set_termios; 3101 port.set_termios = p->set_termios;
3122 port.pm = p->pm; 3102 port.pm = p->pm;
3123 port.dev = &dev->dev; 3103 port.dev = &dev->dev;
@@ -3283,6 +3263,8 @@ int serial8250_register_port(struct uart_port *port)
3283 uart->port.serial_in = port->serial_in; 3263 uart->port.serial_in = port->serial_in;
3284 if (port->serial_out) 3264 if (port->serial_out)
3285 uart->port.serial_out = port->serial_out; 3265 uart->port.serial_out = port->serial_out;
3266 if (port->handle_irq)
3267 uart->port.handle_irq = port->handle_irq;
3286 /* Possibly override set_termios call */ 3268 /* Possibly override set_termios call */
3287 if (port->set_termios) 3269 if (port->set_termios)
3288 uart->port.set_termios = port->set_termios; 3270 uart->port.set_termios = port->set_termios;
diff --git a/drivers/tty/serial/8250_dw.c b/drivers/tty/serial/8250_dw.c
new file mode 100644
index 000000000000..bf1fba640c2d
--- /dev/null
+++ b/drivers/tty/serial/8250_dw.c
@@ -0,0 +1,194 @@
1/*
2 * Synopsys DesignWare 8250 driver.
3 *
4 * Copyright 2011 Picochip, Jamie Iles.
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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * The Synopsys DesignWare 8250 has an extra feature whereby it detects if the
12 * LCR is written whilst busy. If it is, then a busy detect interrupt is
13 * raised, the LCR needs to be rewritten and the uart status register read.
14 */
15#include <linux/device.h>
16#include <linux/init.h>
17#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/serial_8250.h>
20#include <linux/serial_core.h>
21#include <linux/serial_reg.h>
22#include <linux/of.h>
23#include <linux/of_irq.h>
24#include <linux/of_platform.h>
25#include <linux/platform_device.h>
26#include <linux/slab.h>
27
28struct dw8250_data {
29 int last_lcr;
30 int line;
31};
32
33static void dw8250_serial_out(struct uart_port *p, int offset, int value)
34{
35 struct dw8250_data *d = p->private_data;
36
37 if (offset == UART_LCR)
38 d->last_lcr = value;
39
40 offset <<= p->regshift;
41 writeb(value, p->membase + offset);
42}
43
44static unsigned int dw8250_serial_in(struct uart_port *p, int offset)
45{
46 offset <<= p->regshift;
47
48 return readb(p->membase + offset);
49}
50
51static void dw8250_serial_out32(struct uart_port *p, int offset, int value)
52{
53 struct dw8250_data *d = p->private_data;
54
55 if (offset == UART_LCR)
56 d->last_lcr = value;
57
58 offset <<= p->regshift;
59 writel(value, p->membase + offset);
60}
61
62static unsigned int dw8250_serial_in32(struct uart_port *p, int offset)
63{
64 offset <<= p->regshift;
65
66 return readl(p->membase + offset);
67}
68
69/* Offset for the DesignWare's UART Status Register. */
70#define UART_USR 0x1f
71
72static int dw8250_handle_irq(struct uart_port *p)
73{
74 struct dw8250_data *d = p->private_data;
75 unsigned int iir = p->serial_in(p, UART_IIR);
76
77 if (serial8250_handle_irq(p, iir)) {
78 return 1;
79 } else if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
80 /* Clear the USR and write the LCR again. */
81 (void)p->serial_in(p, UART_USR);
82 p->serial_out(p, d->last_lcr, UART_LCR);
83
84 return 1;
85 }
86
87 return 0;
88}
89
90static int __devinit dw8250_probe(struct platform_device *pdev)
91{
92 struct uart_port port = {};
93 struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
94 struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
95 struct device_node *np = pdev->dev.of_node;
96 u32 val;
97 struct dw8250_data *data;
98
99 if (!regs || !irq) {
100 dev_err(&pdev->dev, "no registers/irq defined\n");
101 return -EINVAL;
102 }
103
104 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
105 if (!data)
106 return -ENOMEM;
107 port.private_data = data;
108
109 spin_lock_init(&port.lock);
110 port.mapbase = regs->start;
111 port.irq = irq->start;
112 port.handle_irq = dw8250_handle_irq;
113 port.type = PORT_8250;
114 port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP |
115 UPF_FIXED_PORT | UPF_FIXED_TYPE;
116 port.dev = &pdev->dev;
117
118 port.iotype = UPIO_MEM;
119 port.serial_in = dw8250_serial_in;
120 port.serial_out = dw8250_serial_out;
121 if (!of_property_read_u32(np, "reg-io-width", &val)) {
122 switch (val) {
123 case 1:
124 break;
125 case 4:
126 port.iotype = UPIO_MEM32;
127 port.serial_in = dw8250_serial_in32;
128 port.serial_out = dw8250_serial_out32;
129 break;
130 default:
131 dev_err(&pdev->dev, "unsupported reg-io-width (%u)\n",
132 val);
133 return -EINVAL;
134 }
135 }
136
137 if (!of_property_read_u32(np, "reg-shift", &val))
138 port.regshift = val;
139
140 if (of_property_read_u32(np, "clock-frequency", &val)) {
141 dev_err(&pdev->dev, "no clock-frequency property set\n");
142 return -EINVAL;
143 }
144 port.uartclk = val;
145
146 data->line = serial8250_register_port(&port);
147 if (data->line < 0)
148 return data->line;
149
150 platform_set_drvdata(pdev, data);
151
152 return 0;
153}
154
155static int __devexit dw8250_remove(struct platform_device *pdev)
156{
157 struct dw8250_data *data = platform_get_drvdata(pdev);
158
159 serial8250_unregister_port(data->line);
160
161 return 0;
162}
163
164static const struct of_device_id dw8250_match[] = {
165 { .compatible = "snps,dw-apb-uart" },
166 { /* Sentinel */ }
167};
168MODULE_DEVICE_TABLE(of, dw8250_match);
169
170static struct platform_driver dw8250_platform_driver = {
171 .driver = {
172 .name = "dw-apb-uart",
173 .owner = THIS_MODULE,
174 .of_match_table = dw8250_match,
175 },
176 .probe = dw8250_probe,
177 .remove = __devexit_p(dw8250_remove),
178};
179
180static int __init dw8250_init(void)
181{
182 return platform_driver_register(&dw8250_platform_driver);
183}
184module_init(dw8250_init);
185
186static void __exit dw8250_exit(void)
187{
188 platform_driver_unregister(&dw8250_platform_driver);
189}
190module_exit(dw8250_exit);
191
192MODULE_AUTHOR("Jamie Iles");
193MODULE_LICENSE("GPL");
194MODULE_DESCRIPTION("Synopsys DesignWare 8250 serial port driver");
diff --git a/drivers/tty/serial/8250_pci.c b/drivers/tty/serial/8250_pci.c
index 3abeca2a2a1b..825937a5f210 100644
--- a/drivers/tty/serial/8250_pci.c
+++ b/drivers/tty/serial/8250_pci.c
@@ -1101,6 +1101,15 @@ static int pci_eg20t_init(struct pci_dev *dev)
1101#endif 1101#endif
1102} 1102}
1103 1103
1104static int
1105pci_xr17c154_setup(struct serial_private *priv,
1106 const struct pciserial_board *board,
1107 struct uart_port *port, int idx)
1108{
1109 port->flags |= UPF_EXAR_EFR;
1110 return pci_default_setup(priv, board, port, idx);
1111}
1112
1104/* This should be in linux/pci_ids.h */ 1113/* This should be in linux/pci_ids.h */
1105#define PCI_VENDOR_ID_SBSMODULARIO 0x124B 1114#define PCI_VENDOR_ID_SBSMODULARIO 0x124B
1106#define PCI_SUBVENDOR_ID_SBSMODULARIO 0x124B 1115#define PCI_SUBVENDOR_ID_SBSMODULARIO 0x124B
@@ -1506,6 +1515,30 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
1506 .setup = pci_timedia_setup, 1515 .setup = pci_timedia_setup,
1507 }, 1516 },
1508 /* 1517 /*
1518 * Exar cards
1519 */
1520 {
1521 .vendor = PCI_VENDOR_ID_EXAR,
1522 .device = PCI_DEVICE_ID_EXAR_XR17C152,
1523 .subvendor = PCI_ANY_ID,
1524 .subdevice = PCI_ANY_ID,
1525 .setup = pci_xr17c154_setup,
1526 },
1527 {
1528 .vendor = PCI_VENDOR_ID_EXAR,
1529 .device = PCI_DEVICE_ID_EXAR_XR17C154,
1530 .subvendor = PCI_ANY_ID,
1531 .subdevice = PCI_ANY_ID,
1532 .setup = pci_xr17c154_setup,
1533 },
1534 {
1535 .vendor = PCI_VENDOR_ID_EXAR,
1536 .device = PCI_DEVICE_ID_EXAR_XR17C158,
1537 .subvendor = PCI_ANY_ID,
1538 .subdevice = PCI_ANY_ID,
1539 .setup = pci_xr17c154_setup,
1540 },
1541 /*
1509 * Xircom cards 1542 * Xircom cards
1510 */ 1543 */
1511 { 1544 {
@@ -1558,46 +1591,55 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
1558 .vendor = PCI_VENDOR_ID_INTEL, 1591 .vendor = PCI_VENDOR_ID_INTEL,
1559 .device = 0x8811, 1592 .device = 0x8811,
1560 .init = pci_eg20t_init, 1593 .init = pci_eg20t_init,
1594 .setup = pci_default_setup,
1561 }, 1595 },
1562 { 1596 {
1563 .vendor = PCI_VENDOR_ID_INTEL, 1597 .vendor = PCI_VENDOR_ID_INTEL,
1564 .device = 0x8812, 1598 .device = 0x8812,
1565 .init = pci_eg20t_init, 1599 .init = pci_eg20t_init,
1600 .setup = pci_default_setup,
1566 }, 1601 },
1567 { 1602 {
1568 .vendor = PCI_VENDOR_ID_INTEL, 1603 .vendor = PCI_VENDOR_ID_INTEL,
1569 .device = 0x8813, 1604 .device = 0x8813,
1570 .init = pci_eg20t_init, 1605 .init = pci_eg20t_init,
1606 .setup = pci_default_setup,
1571 }, 1607 },
1572 { 1608 {
1573 .vendor = PCI_VENDOR_ID_INTEL, 1609 .vendor = PCI_VENDOR_ID_INTEL,
1574 .device = 0x8814, 1610 .device = 0x8814,
1575 .init = pci_eg20t_init, 1611 .init = pci_eg20t_init,
1612 .setup = pci_default_setup,
1576 }, 1613 },
1577 { 1614 {
1578 .vendor = 0x10DB, 1615 .vendor = 0x10DB,
1579 .device = 0x8027, 1616 .device = 0x8027,
1580 .init = pci_eg20t_init, 1617 .init = pci_eg20t_init,
1618 .setup = pci_default_setup,
1581 }, 1619 },
1582 { 1620 {
1583 .vendor = 0x10DB, 1621 .vendor = 0x10DB,
1584 .device = 0x8028, 1622 .device = 0x8028,
1585 .init = pci_eg20t_init, 1623 .init = pci_eg20t_init,
1624 .setup = pci_default_setup,
1586 }, 1625 },
1587 { 1626 {
1588 .vendor = 0x10DB, 1627 .vendor = 0x10DB,
1589 .device = 0x8029, 1628 .device = 0x8029,
1590 .init = pci_eg20t_init, 1629 .init = pci_eg20t_init,
1630 .setup = pci_default_setup,
1591 }, 1631 },
1592 { 1632 {
1593 .vendor = 0x10DB, 1633 .vendor = 0x10DB,
1594 .device = 0x800C, 1634 .device = 0x800C,
1595 .init = pci_eg20t_init, 1635 .init = pci_eg20t_init,
1636 .setup = pci_default_setup,
1596 }, 1637 },
1597 { 1638 {
1598 .vendor = 0x10DB, 1639 .vendor = 0x10DB,
1599 .device = 0x800D, 1640 .device = 0x800D,
1600 .init = pci_eg20t_init, 1641 .init = pci_eg20t_init,
1642 .setup = pci_default_setup,
1601 }, 1643 },
1602 /* 1644 /*
1603 * Cronyx Omega PCI (PLX-chip based) 1645 * Cronyx Omega PCI (PLX-chip based)
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 4dcb37bbdf92..5f479dada6f2 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -267,6 +267,13 @@ config SERIAL_8250_RM9K
267 port hardware found on MIPS RM9122 and similar processors. 267 port hardware found on MIPS RM9122 and similar processors.
268 If unsure, say N. 268 If unsure, say N.
269 269
270config SERIAL_8250_DW
271 tristate "Support for Synopsys DesignWare 8250 quirks"
272 depends on SERIAL_8250 && OF
273 help
274 Selecting this option will enable handling of the extra features
275 present in the Synopsys DesignWare APB UART.
276
270comment "Non-8250 serial port support" 277comment "Non-8250 serial port support"
271 278
272config SERIAL_AMBA_PL010 279config SERIAL_AMBA_PL010
@@ -522,8 +529,8 @@ config SERIAL_S3C6400
522 529
523config SERIAL_S5PV210 530config SERIAL_S5PV210
524 tristate "Samsung S5PV210 Serial port support" 531 tristate "Samsung S5PV210 Serial port support"
525 depends on SERIAL_SAMSUNG && (CPU_S5PV210 || CPU_EXYNOS4210) 532 depends on SERIAL_SAMSUNG && (CPU_S5PV210 || CPU_EXYNOS4210 || SOC_EXYNOS4212)
526 select SERIAL_SAMSUNG_UARTS_4 if (CPU_S5PV210 || CPU_EXYNOS4210) 533 select SERIAL_SAMSUNG_UARTS_4 if (CPU_S5PV210 || CPU_EXYNOS4210 || SOC_EXYNOS4212)
527 default y 534 default y
528 help 535 help
529 Serial port support for Samsung's S5P Family of SoC's 536 Serial port support for Samsung's S5P Family of SoC's
@@ -722,7 +729,7 @@ config SERIAL_BFIN
722 Add support for the built-in UARTs on the Blackfin. 729 Add support for the built-in UARTs on the Blackfin.
723 730
724 To compile this driver as a module, choose M here: the 731 To compile this driver as a module, choose M here: the
725 module will be called bfin_5xx. 732 module is named bfin_uart.ko.
726 733
727config SERIAL_BFIN_CONSOLE 734config SERIAL_BFIN_CONSOLE
728 bool "Console on Blackfin serial port" 735 bool "Console on Blackfin serial port"
@@ -1035,23 +1042,6 @@ config SERIAL_MCF_CONSOLE
1035 help 1042 help
1036 Enable a ColdFire internal serial port to be the system console. 1043 Enable a ColdFire internal serial port to be the system console.
1037 1044
1038config SERIAL_68360_SMC
1039 bool "68360 SMC uart support"
1040 depends on M68360
1041 help
1042 This driver supports the SMC serial ports of the Motorola 68360 CPU.
1043
1044config SERIAL_68360_SCC
1045 bool "68360 SCC uart support"
1046 depends on M68360
1047 help
1048 This driver supports the SCC serial ports of the Motorola 68360 CPU.
1049
1050config SERIAL_68360
1051 bool
1052 depends on SERIAL_68360_SMC || SERIAL_68360_SCC
1053 default y
1054
1055config SERIAL_PMACZILOG 1045config SERIAL_PMACZILOG
1056 tristate "Mac or PowerMac z85c30 ESCC support" 1046 tristate "Mac or PowerMac z85c30 ESCC support"
1057 depends on (M68K && MAC) || (PPC_OF && PPC_PMAC) 1047 depends on (M68K && MAC) || (PPC_OF && PPC_PMAC)
diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
index 83b4da6a1062..e10cf5b54b6d 100644
--- a/drivers/tty/serial/Makefile
+++ b/drivers/tty/serial/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_SERIAL_8250_BOCA) += 8250_boca.o
28obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554) += 8250_exar_st16c554.o 28obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554) += 8250_exar_st16c554.o
29obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o 29obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o
30obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o 30obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o
31obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o
31obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o 32obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o
32obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o 33obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o
33obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o 34obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o
@@ -35,7 +36,7 @@ obj-$(CONFIG_SERIAL_PXA) += pxa.o
35obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o 36obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
36obj-$(CONFIG_SERIAL_SA1100) += sa1100.o 37obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
37obj-$(CONFIG_SERIAL_BCM63XX) += bcm63xx_uart.o 38obj-$(CONFIG_SERIAL_BCM63XX) += bcm63xx_uart.o
38obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o 39obj-$(CONFIG_SERIAL_BFIN) += bfin_uart.o
39obj-$(CONFIG_SERIAL_BFIN_SPORT) += bfin_sport_uart.o 40obj-$(CONFIG_SERIAL_BFIN_SPORT) += bfin_sport_uart.o
40obj-$(CONFIG_SERIAL_SAMSUNG) += samsung.o 41obj-$(CONFIG_SERIAL_SAMSUNG) += samsung.o
41obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o 42obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
@@ -49,7 +50,6 @@ obj-$(CONFIG_SERIAL_MAX3107_AAVA) += max3107-aava.o
49obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o 50obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o
50obj-$(CONFIG_SERIAL_MUX) += mux.o 51obj-$(CONFIG_SERIAL_MUX) += mux.o
51obj-$(CONFIG_SERIAL_68328) += 68328serial.o 52obj-$(CONFIG_SERIAL_68328) += 68328serial.o
52obj-$(CONFIG_SERIAL_68360) += 68360serial.o
53obj-$(CONFIG_SERIAL_MCF) += mcf.o 53obj-$(CONFIG_SERIAL_MCF) += mcf.o
54obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o 54obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o
55obj-$(CONFIG_SERIAL_DZ) += dz.o 55obj-$(CONFIG_SERIAL_DZ) += dz.o
diff --git a/drivers/tty/serial/altera_jtaguart.c b/drivers/tty/serial/altera_jtaguart.c
index 60e049b041a7..00a73ecb2dfb 100644
--- a/drivers/tty/serial/altera_jtaguart.c
+++ b/drivers/tty/serial/altera_jtaguart.c
@@ -218,7 +218,7 @@ static int altera_jtaguart_startup(struct uart_port *port)
218 unsigned long flags; 218 unsigned long flags;
219 int ret; 219 int ret;
220 220
221 ret = request_irq(port->irq, altera_jtaguart_interrupt, IRQF_DISABLED, 221 ret = request_irq(port->irq, altera_jtaguart_interrupt, 0,
222 DRV_NAME, port); 222 DRV_NAME, port);
223 if (ret) { 223 if (ret) {
224 pr_err(DRV_NAME ": unable to attach Altera JTAG UART %d " 224 pr_err(DRV_NAME ": unable to attach Altera JTAG UART %d "
diff --git a/drivers/tty/serial/altera_uart.c b/drivers/tty/serial/altera_uart.c
index 50bc5a5ac653..d902558ccfd2 100644
--- a/drivers/tty/serial/altera_uart.c
+++ b/drivers/tty/serial/altera_uart.c
@@ -315,7 +315,7 @@ static int altera_uart_startup(struct uart_port *port)
315 return 0; 315 return 0;
316 } 316 }
317 317
318 ret = request_irq(port->irq, altera_uart_interrupt, IRQF_DISABLED, 318 ret = request_irq(port->irq, altera_uart_interrupt, 0,
319 DRV_NAME, port); 319 DRV_NAME, port);
320 if (ret) { 320 if (ret) {
321 pr_err(DRV_NAME ": unable to attach Altera UART %d " 321 pr_err(DRV_NAME ": unable to attach Altera UART %d "
diff --git a/drivers/tty/serial/apbuart.c b/drivers/tty/serial/apbuart.c
index 19a943693e4c..77554fd68d1f 100644
--- a/drivers/tty/serial/apbuart.c
+++ b/drivers/tty/serial/apbuart.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/tty.h> 18#include <linux/tty.h>
19#include <linux/tty_flip.h>
19#include <linux/ioport.h> 20#include <linux/ioport.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/serial.h> 22#include <linux/serial.h>
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index b922f5d2e61e..9988c0c305c2 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -33,6 +33,8 @@
33#include <linux/sysrq.h> 33#include <linux/sysrq.h>
34#include <linux/tty_flip.h> 34#include <linux/tty_flip.h>
35#include <linux/platform_device.h> 35#include <linux/platform_device.h>
36#include <linux/of.h>
37#include <linux/of_device.h>
36#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
37#include <linux/atmel_pdc.h> 39#include <linux/atmel_pdc.h>
38#include <linux/atmel_serial.h> 40#include <linux/atmel_serial.h>
@@ -157,11 +159,22 @@ struct atmel_uart_port {
157}; 159};
158 160
159static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART]; 161static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
162static unsigned long atmel_ports_in_use;
160 163
161#ifdef SUPPORT_SYSRQ 164#ifdef SUPPORT_SYSRQ
162static struct console atmel_console; 165static struct console atmel_console;
163#endif 166#endif
164 167
168#if defined(CONFIG_OF)
169static const struct of_device_id atmel_serial_dt_ids[] = {
170 { .compatible = "atmel,at91rm9200-usart" },
171 { .compatible = "atmel,at91sam9260-usart" },
172 { /* sentinel */ }
173};
174
175MODULE_DEVICE_TABLE(of, atmel_serial_dt_ids);
176#endif
177
165static inline struct atmel_uart_port * 178static inline struct atmel_uart_port *
166to_atmel_uart_port(struct uart_port *uart) 179to_atmel_uart_port(struct uart_port *uart)
167{ 180{
@@ -339,7 +352,8 @@ static void atmel_stop_tx(struct uart_port *port)
339 /* Disable interrupts */ 352 /* Disable interrupts */
340 UART_PUT_IDR(port, atmel_port->tx_done_mask); 353 UART_PUT_IDR(port, atmel_port->tx_done_mask);
341 354
342 if (atmel_port->rs485.flags & SER_RS485_ENABLED) 355 if ((atmel_port->rs485.flags & SER_RS485_ENABLED) &&
356 !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX))
343 atmel_start_rx(port); 357 atmel_start_rx(port);
344} 358}
345 359
@@ -356,7 +370,8 @@ static void atmel_start_tx(struct uart_port *port)
356 really need this.*/ 370 really need this.*/
357 return; 371 return;
358 372
359 if (atmel_port->rs485.flags & SER_RS485_ENABLED) 373 if ((atmel_port->rs485.flags & SER_RS485_ENABLED) &&
374 !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX))
360 atmel_stop_rx(port); 375 atmel_stop_rx(port);
361 376
362 /* re-enable PDC transmit */ 377 /* re-enable PDC transmit */
@@ -680,7 +695,8 @@ static void atmel_tx_dma(struct uart_port *port)
680 /* Enable interrupts */ 695 /* Enable interrupts */
681 UART_PUT_IER(port, atmel_port->tx_done_mask); 696 UART_PUT_IER(port, atmel_port->tx_done_mask);
682 } else { 697 } else {
683 if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 698 if ((atmel_port->rs485.flags & SER_RS485_ENABLED) &&
699 !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX)) {
684 /* DMA done, stop TX, start RX for RS485 */ 700 /* DMA done, stop TX, start RX for RS485 */
685 atmel_start_rx(port); 701 atmel_start_rx(port);
686 } 702 }
@@ -1407,6 +1423,48 @@ static struct uart_ops atmel_pops = {
1407#endif 1423#endif
1408}; 1424};
1409 1425
1426static void __devinit atmel_of_init_port(struct atmel_uart_port *atmel_port,
1427 struct device_node *np)
1428{
1429 u32 rs485_delay[2];
1430
1431 /* DMA/PDC usage specification */
1432 if (of_get_property(np, "atmel,use-dma-rx", NULL))
1433 atmel_port->use_dma_rx = 1;
1434 else
1435 atmel_port->use_dma_rx = 0;
1436 if (of_get_property(np, "atmel,use-dma-tx", NULL))
1437 atmel_port->use_dma_tx = 1;
1438 else
1439 atmel_port->use_dma_tx = 0;
1440
1441 /* rs485 properties */
1442 if (of_property_read_u32_array(np, "rs485-rts-delay",
1443 rs485_delay, 2) == 0) {
1444 struct serial_rs485 *rs485conf = &atmel_port->rs485;
1445
1446 rs485conf->delay_rts_before_send = rs485_delay[0];
1447 rs485conf->delay_rts_after_send = rs485_delay[1];
1448 rs485conf->flags = 0;
1449
1450 if (rs485conf->delay_rts_before_send == 0 &&
1451 rs485conf->delay_rts_after_send == 0) {
1452 rs485conf->flags |= SER_RS485_RTS_ON_SEND;
1453 } else {
1454 if (rs485conf->delay_rts_before_send)
1455 rs485conf->flags |= SER_RS485_RTS_BEFORE_SEND;
1456 if (rs485conf->delay_rts_after_send)
1457 rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
1458 }
1459
1460 if (of_get_property(np, "rs485-rx-during-tx", NULL))
1461 rs485conf->flags |= SER_RS485_RX_DURING_TX;
1462
1463 if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL))
1464 rs485conf->flags |= SER_RS485_ENABLED;
1465 }
1466}
1467
1410/* 1468/*
1411 * Configure the port from the platform device resource info. 1469 * Configure the port from the platform device resource info.
1412 */ 1470 */
@@ -1414,13 +1472,20 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
1414 struct platform_device *pdev) 1472 struct platform_device *pdev)
1415{ 1473{
1416 struct uart_port *port = &atmel_port->uart; 1474 struct uart_port *port = &atmel_port->uart;
1417 struct atmel_uart_data *data = pdev->dev.platform_data; 1475 struct atmel_uart_data *pdata = pdev->dev.platform_data;
1476
1477 if (pdev->dev.of_node) {
1478 atmel_of_init_port(atmel_port, pdev->dev.of_node);
1479 } else {
1480 atmel_port->use_dma_rx = pdata->use_dma_rx;
1481 atmel_port->use_dma_tx = pdata->use_dma_tx;
1482 atmel_port->rs485 = pdata->rs485;
1483 }
1418 1484
1419 port->iotype = UPIO_MEM; 1485 port->iotype = UPIO_MEM;
1420 port->flags = UPF_BOOT_AUTOCONF; 1486 port->flags = UPF_BOOT_AUTOCONF;
1421 port->ops = &atmel_pops; 1487 port->ops = &atmel_pops;
1422 port->fifosize = 1; 1488 port->fifosize = 1;
1423 port->line = data->num;
1424 port->dev = &pdev->dev; 1489 port->dev = &pdev->dev;
1425 port->mapbase = pdev->resource[0].start; 1490 port->mapbase = pdev->resource[0].start;
1426 port->irq = pdev->resource[1].start; 1491 port->irq = pdev->resource[1].start;
@@ -1430,10 +1495,10 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
1430 1495
1431 memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring)); 1496 memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
1432 1497
1433 if (data->regs) 1498 if (pdata && pdata->regs) {
1434 /* Already mapped by setup code */ 1499 /* Already mapped by setup code */
1435 port->membase = data->regs; 1500 port->membase = pdata->regs;
1436 else { 1501 } else {
1437 port->flags |= UPF_IOREMAP; 1502 port->flags |= UPF_IOREMAP;
1438 port->membase = NULL; 1503 port->membase = NULL;
1439 } 1504 }
@@ -1447,9 +1512,6 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
1447 /* only enable clock when USART is in use */ 1512 /* only enable clock when USART is in use */
1448 } 1513 }
1449 1514
1450 atmel_port->use_dma_rx = data->use_dma_rx;
1451 atmel_port->use_dma_tx = data->use_dma_tx;
1452 atmel_port->rs485 = data->rs485;
1453 /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */ 1515 /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
1454 if (atmel_port->rs485.flags & SER_RS485_ENABLED) 1516 if (atmel_port->rs485.flags & SER_RS485_ENABLED)
1455 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; 1517 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
@@ -1611,10 +1673,14 @@ static int __init atmel_console_init(void)
1611 if (atmel_default_console_device) { 1673 if (atmel_default_console_device) {
1612 struct atmel_uart_data *pdata = 1674 struct atmel_uart_data *pdata =
1613 atmel_default_console_device->dev.platform_data; 1675 atmel_default_console_device->dev.platform_data;
1676 int id = pdata->num;
1677 struct atmel_uart_port *port = &atmel_ports[id];
1678
1679 port->backup_imr = 0;
1680 port->uart.line = id;
1614 1681
1615 add_preferred_console(ATMEL_DEVICENAME, pdata->num, NULL); 1682 add_preferred_console(ATMEL_DEVICENAME, id, NULL);
1616 atmel_init_port(&atmel_ports[pdata->num], 1683 atmel_init_port(port, atmel_default_console_device);
1617 atmel_default_console_device);
1618 register_console(&atmel_console); 1684 register_console(&atmel_console);
1619 } 1685 }
1620 1686
@@ -1711,14 +1777,39 @@ static int atmel_serial_resume(struct platform_device *pdev)
1711static int __devinit atmel_serial_probe(struct platform_device *pdev) 1777static int __devinit atmel_serial_probe(struct platform_device *pdev)
1712{ 1778{
1713 struct atmel_uart_port *port; 1779 struct atmel_uart_port *port;
1780 struct device_node *np = pdev->dev.of_node;
1714 struct atmel_uart_data *pdata = pdev->dev.platform_data; 1781 struct atmel_uart_data *pdata = pdev->dev.platform_data;
1715 void *data; 1782 void *data;
1716 int ret; 1783 int ret = -ENODEV;
1717 1784
1718 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1)); 1785 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
1719 1786
1720 port = &atmel_ports[pdata->num]; 1787 if (np)
1788 ret = of_alias_get_id(np, "serial");
1789 else
1790 if (pdata)
1791 ret = pdata->num;
1792
1793 if (ret < 0)
1794 /* port id not found in platform data nor device-tree aliases:
1795 * auto-enumerate it */
1796 ret = find_first_zero_bit(&atmel_ports_in_use,
1797 sizeof(atmel_ports_in_use));
1798
1799 if (ret > ATMEL_MAX_UART) {
1800 ret = -ENODEV;
1801 goto err;
1802 }
1803
1804 if (test_and_set_bit(ret, &atmel_ports_in_use)) {
1805 /* port already in use */
1806 ret = -EBUSY;
1807 goto err;
1808 }
1809
1810 port = &atmel_ports[ret];
1721 port->backup_imr = 0; 1811 port->backup_imr = 0;
1812 port->uart.line = ret;
1722 1813
1723 atmel_init_port(port, pdev); 1814 atmel_init_port(port, pdev);
1724 1815
@@ -1764,7 +1855,7 @@ err_alloc_ring:
1764 clk_put(port->clk); 1855 clk_put(port->clk);
1765 port->clk = NULL; 1856 port->clk = NULL;
1766 } 1857 }
1767 1858err:
1768 return ret; 1859 return ret;
1769} 1860}
1770 1861
@@ -1784,6 +1875,8 @@ static int __devexit atmel_serial_remove(struct platform_device *pdev)
1784 1875
1785 /* "port" is allocated statically, so we shouldn't free it */ 1876 /* "port" is allocated statically, so we shouldn't free it */
1786 1877
1878 clear_bit(port->line, &atmel_ports_in_use);
1879
1787 clk_put(atmel_port->clk); 1880 clk_put(atmel_port->clk);
1788 1881
1789 return ret; 1882 return ret;
@@ -1797,6 +1890,7 @@ static struct platform_driver atmel_serial_driver = {
1797 .driver = { 1890 .driver = {
1798 .name = "atmel_usart", 1891 .name = "atmel_usart",
1799 .owner = THIS_MODULE, 1892 .owner = THIS_MODULE,
1893 .of_match_table = of_match_ptr(atmel_serial_dt_ids),
1800 }, 1894 },
1801}; 1895};
1802 1896
diff --git a/drivers/tty/serial/bfin_sport_uart.c b/drivers/tty/serial/bfin_sport_uart.c
index 891d194ae754..ee101c0d358f 100644
--- a/drivers/tty/serial/bfin_sport_uart.c
+++ b/drivers/tty/serial/bfin_sport_uart.c
@@ -294,7 +294,7 @@ static int sport_startup(struct uart_port *port)
294 if (request_irq(gpio_to_irq(up->cts_pin), 294 if (request_irq(gpio_to_irq(up->cts_pin),
295 sport_mctrl_cts_int, 295 sport_mctrl_cts_int,
296 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | 296 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
297 IRQF_DISABLED, "BFIN_SPORT_UART_CTS", up)) { 297 0, "BFIN_SPORT_UART_CTS", up)) {
298 up->cts_pin = -1; 298 up->cts_pin = -1;
299 dev_info(port->dev, "Unable to attach BlackFin UART over SPORT CTS interrupt. So, disable it.\n"); 299 dev_info(port->dev, "Unable to attach BlackFin UART over SPORT CTS interrupt. So, disable it.\n");
300 } 300 }
diff --git a/drivers/tty/serial/bfin_5xx.c b/drivers/tty/serial/bfin_uart.c
index ff6979181ac5..66afb98b77b5 100644
--- a/drivers/tty/serial/bfin_5xx.c
+++ b/drivers/tty/serial/bfin_uart.c
@@ -234,8 +234,8 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
234 status = UART_GET_LSR(uart); 234 status = UART_GET_LSR(uart);
235 UART_CLEAR_LSR(uart); 235 UART_CLEAR_LSR(uart);
236 236
237 ch = UART_GET_CHAR(uart); 237 ch = UART_GET_CHAR(uart);
238 uart->port.icount.rx++; 238 uart->port.icount.rx++;
239 239
240#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ 240#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
241 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) 241 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
@@ -667,17 +667,17 @@ static int bfin_serial_startup(struct uart_port *port)
667 kgdboc_break_enabled = 0; 667 kgdboc_break_enabled = 0;
668 else { 668 else {
669# endif 669# endif
670 if (request_irq(uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED, 670 if (request_irq(uart->rx_irq, bfin_serial_rx_int, 0,
671 "BFIN_UART_RX", uart)) { 671 "BFIN_UART_RX", uart)) {
672 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n"); 672 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
673 return -EBUSY; 673 return -EBUSY;
674 } 674 }
675 675
676 if (request_irq 676 if (request_irq
677 (uart->port.irq+1, bfin_serial_tx_int, IRQF_DISABLED, 677 (uart->tx_irq, bfin_serial_tx_int, 0,
678 "BFIN_UART_TX", uart)) { 678 "BFIN_UART_TX", uart)) {
679 printk(KERN_NOTICE "Unable to attach BlackFin UART TX interrupt\n"); 679 printk(KERN_NOTICE "Unable to attach BlackFin UART TX interrupt\n");
680 free_irq(uart->port.irq, uart); 680 free_irq(uart->rx_irq, uart);
681 return -EBUSY; 681 return -EBUSY;
682 } 682 }
683 683
@@ -692,7 +692,7 @@ static int bfin_serial_startup(struct uart_port *port)
692 */ 692 */
693 unsigned uart_dma_ch_rx, uart_dma_ch_tx; 693 unsigned uart_dma_ch_rx, uart_dma_ch_tx;
694 694
695 switch (uart->port.irq) { 695 switch (uart->rx_irq) {
696 case IRQ_UART3_RX: 696 case IRQ_UART3_RX:
697 uart_dma_ch_rx = CH_UART3_RX; 697 uart_dma_ch_rx = CH_UART3_RX;
698 uart_dma_ch_tx = CH_UART3_TX; 698 uart_dma_ch_tx = CH_UART3_TX;
@@ -709,16 +709,16 @@ static int bfin_serial_startup(struct uart_port *port)
709 if (uart_dma_ch_rx && 709 if (uart_dma_ch_rx &&
710 request_dma(uart_dma_ch_rx, "BFIN_UART_RX") < 0) { 710 request_dma(uart_dma_ch_rx, "BFIN_UART_RX") < 0) {
711 printk(KERN_NOTICE"Fail to attach UART interrupt\n"); 711 printk(KERN_NOTICE"Fail to attach UART interrupt\n");
712 free_irq(uart->port.irq, uart); 712 free_irq(uart->rx_irq, uart);
713 free_irq(uart->port.irq + 1, uart); 713 free_irq(uart->tx_irq, uart);
714 return -EBUSY; 714 return -EBUSY;
715 } 715 }
716 if (uart_dma_ch_tx && 716 if (uart_dma_ch_tx &&
717 request_dma(uart_dma_ch_tx, "BFIN_UART_TX") < 0) { 717 request_dma(uart_dma_ch_tx, "BFIN_UART_TX") < 0) {
718 printk(KERN_NOTICE "Fail to attach UART interrupt\n"); 718 printk(KERN_NOTICE "Fail to attach UART interrupt\n");
719 free_dma(uart_dma_ch_rx); 719 free_dma(uart_dma_ch_rx);
720 free_irq(uart->port.irq, uart); 720 free_irq(uart->rx_irq, uart);
721 free_irq(uart->port.irq + 1, uart); 721 free_irq(uart->tx_irq, uart);
722 return -EBUSY; 722 return -EBUSY;
723 } 723 }
724 } 724 }
@@ -734,19 +734,18 @@ static int bfin_serial_startup(struct uart_port *port)
734 if (request_irq(gpio_to_irq(uart->cts_pin), 734 if (request_irq(gpio_to_irq(uart->cts_pin),
735 bfin_serial_mctrl_cts_int, 735 bfin_serial_mctrl_cts_int,
736 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | 736 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
737 IRQF_DISABLED, "BFIN_UART_CTS", uart)) { 737 0, "BFIN_UART_CTS", uart)) {
738 uart->cts_pin = -1; 738 uart->cts_pin = -1;
739 pr_info("Unable to attach BlackFin UART CTS interrupt. So, disable it.\n"); 739 pr_info("Unable to attach BlackFin UART CTS interrupt. So, disable it.\n");
740 } 740 }
741 } 741 }
742 if (uart->rts_pin >= 0) { 742 if (uart->rts_pin >= 0)
743 gpio_direction_output(uart->rts_pin, 0); 743 gpio_direction_output(uart->rts_pin, 0);
744 }
745#endif 744#endif
746#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS 745#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
747 if (uart->cts_pin >= 0 && request_irq(uart->status_irq, 746 if (uart->cts_pin >= 0 && request_irq(uart->status_irq,
748 bfin_serial_mctrl_cts_int, 747 bfin_serial_mctrl_cts_int,
749 IRQF_DISABLED, "BFIN_UART_MODEM_STATUS", uart)) { 748 0, "BFIN_UART_MODEM_STATUS", uart)) {
750 uart->cts_pin = -1; 749 uart->cts_pin = -1;
751 pr_info("Unable to attach BlackFin UART Modem Status interrupt.\n"); 750 pr_info("Unable to attach BlackFin UART Modem Status interrupt.\n");
752 } 751 }
@@ -786,8 +785,8 @@ static void bfin_serial_shutdown(struct uart_port *port)
786 break; 785 break;
787 }; 786 };
788#endif 787#endif
789 free_irq(uart->port.irq, uart); 788 free_irq(uart->rx_irq, uart);
790 free_irq(uart->port.irq+1, uart); 789 free_irq(uart->tx_irq, uart);
791#endif 790#endif
792 791
793#ifdef CONFIG_SERIAL_BFIN_CTSRTS 792#ifdef CONFIG_SERIAL_BFIN_CTSRTS
@@ -1091,10 +1090,18 @@ bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
1091 *parity = 'o'; 1090 *parity = 'o';
1092 } 1091 }
1093 switch (lcr & 0x03) { 1092 switch (lcr & 0x03) {
1094 case 0: *bits = 5; break; 1093 case 0:
1095 case 1: *bits = 6; break; 1094 *bits = 5;
1096 case 2: *bits = 7; break; 1095 break;
1097 case 3: *bits = 8; break; 1096 case 1:
1097 *bits = 6;
1098 break;
1099 case 2:
1100 *bits = 7;
1101 break;
1102 case 3:
1103 *bits = 8;
1104 break;
1098 } 1105 }
1099 /* Set DLAB in LCR to Access DLL and DLH */ 1106 /* Set DLAB in LCR to Access DLL and DLH */
1100 UART_SET_DLAB(uart); 1107 UART_SET_DLAB(uart);
@@ -1183,7 +1190,7 @@ static struct console bfin_serial_console = {
1183 .index = -1, 1190 .index = -1,
1184 .data = &bfin_serial_reg, 1191 .data = &bfin_serial_reg,
1185}; 1192};
1186#define BFIN_SERIAL_CONSOLE &bfin_serial_console 1193#define BFIN_SERIAL_CONSOLE (&bfin_serial_console)
1187#else 1194#else
1188#define BFIN_SERIAL_CONSOLE NULL 1195#define BFIN_SERIAL_CONSOLE NULL
1189#endif /* CONFIG_SERIAL_BFIN_CONSOLE */ 1196#endif /* CONFIG_SERIAL_BFIN_CONSOLE */
@@ -1312,14 +1319,22 @@ static int bfin_serial_probe(struct platform_device *pdev)
1312 } 1319 }
1313 uart->port.mapbase = res->start; 1320 uart->port.mapbase = res->start;
1314 1321
1315 uart->port.irq = platform_get_irq(pdev, 0); 1322 uart->tx_irq = platform_get_irq(pdev, 0);
1316 if (uart->port.irq < 0) { 1323 if (uart->tx_irq < 0) {
1317 dev_err(&pdev->dev, "No uart RX/TX IRQ specified\n"); 1324 dev_err(&pdev->dev, "No uart TX IRQ specified\n");
1325 ret = -ENOENT;
1326 goto out_error_unmap;
1327 }
1328
1329 uart->rx_irq = platform_get_irq(pdev, 1);
1330 if (uart->rx_irq < 0) {
1331 dev_err(&pdev->dev, "No uart RX IRQ specified\n");
1318 ret = -ENOENT; 1332 ret = -ENOENT;
1319 goto out_error_unmap; 1333 goto out_error_unmap;
1320 } 1334 }
1335 uart->port.irq = uart->rx_irq;
1321 1336
1322 uart->status_irq = platform_get_irq(pdev, 1); 1337 uart->status_irq = platform_get_irq(pdev, 2);
1323 if (uart->status_irq < 0) { 1338 if (uart->status_irq < 0) {
1324 dev_err(&pdev->dev, "No uart status IRQ specified\n"); 1339 dev_err(&pdev->dev, "No uart status IRQ specified\n");
1325 ret = -ENOENT; 1340 ret = -ENOENT;
diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
index 9488da74d4f7..b418947b7107 100644
--- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
@@ -31,6 +31,7 @@
31 31
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/tty.h> 33#include <linux/tty.h>
34#include <linux/tty_flip.h>
34#include <linux/ioport.h> 35#include <linux/ioport.h>
35#include <linux/init.h> 36#include <linux/init.h>
36#include <linux/serial.h> 37#include <linux/serial.h>
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c
index 58be715913cd..b7435043f2fe 100644
--- a/drivers/tty/serial/crisv10.c
+++ b/drivers/tty/serial/crisv10.c
@@ -258,7 +258,7 @@ static struct e100_serial rs_table[] = {
258 .dma_out_enabled = 1, 258 .dma_out_enabled = 1,
259 .dma_out_nbr = SER0_TX_DMA_NBR, 259 .dma_out_nbr = SER0_TX_DMA_NBR,
260 .dma_out_irq_nbr = SER0_DMA_TX_IRQ_NBR, 260 .dma_out_irq_nbr = SER0_DMA_TX_IRQ_NBR,
261 .dma_out_irq_flags = IRQF_DISABLED, 261 .dma_out_irq_flags = 0,
262 .dma_out_irq_description = "serial 0 dma tr", 262 .dma_out_irq_description = "serial 0 dma tr",
263#else 263#else
264 .dma_out_enabled = 0, 264 .dma_out_enabled = 0,
@@ -271,7 +271,7 @@ static struct e100_serial rs_table[] = {
271 .dma_in_enabled = 1, 271 .dma_in_enabled = 1,
272 .dma_in_nbr = SER0_RX_DMA_NBR, 272 .dma_in_nbr = SER0_RX_DMA_NBR,
273 .dma_in_irq_nbr = SER0_DMA_RX_IRQ_NBR, 273 .dma_in_irq_nbr = SER0_DMA_RX_IRQ_NBR,
274 .dma_in_irq_flags = IRQF_DISABLED, 274 .dma_in_irq_flags = 0,
275 .dma_in_irq_description = "serial 0 dma rec", 275 .dma_in_irq_description = "serial 0 dma rec",
276#else 276#else
277 .dma_in_enabled = 0, 277 .dma_in_enabled = 0,
@@ -313,7 +313,7 @@ static struct e100_serial rs_table[] = {
313 .dma_out_enabled = 1, 313 .dma_out_enabled = 1,
314 .dma_out_nbr = SER1_TX_DMA_NBR, 314 .dma_out_nbr = SER1_TX_DMA_NBR,
315 .dma_out_irq_nbr = SER1_DMA_TX_IRQ_NBR, 315 .dma_out_irq_nbr = SER1_DMA_TX_IRQ_NBR,
316 .dma_out_irq_flags = IRQF_DISABLED, 316 .dma_out_irq_flags = 0,
317 .dma_out_irq_description = "serial 1 dma tr", 317 .dma_out_irq_description = "serial 1 dma tr",
318#else 318#else
319 .dma_out_enabled = 0, 319 .dma_out_enabled = 0,
@@ -326,7 +326,7 @@ static struct e100_serial rs_table[] = {
326 .dma_in_enabled = 1, 326 .dma_in_enabled = 1,
327 .dma_in_nbr = SER1_RX_DMA_NBR, 327 .dma_in_nbr = SER1_RX_DMA_NBR,
328 .dma_in_irq_nbr = SER1_DMA_RX_IRQ_NBR, 328 .dma_in_irq_nbr = SER1_DMA_RX_IRQ_NBR,
329 .dma_in_irq_flags = IRQF_DISABLED, 329 .dma_in_irq_flags = 0,
330 .dma_in_irq_description = "serial 1 dma rec", 330 .dma_in_irq_description = "serial 1 dma rec",
331#else 331#else
332 .dma_in_enabled = 0, 332 .dma_in_enabled = 0,
@@ -369,7 +369,7 @@ static struct e100_serial rs_table[] = {
369 .dma_out_enabled = 1, 369 .dma_out_enabled = 1,
370 .dma_out_nbr = SER2_TX_DMA_NBR, 370 .dma_out_nbr = SER2_TX_DMA_NBR,
371 .dma_out_irq_nbr = SER2_DMA_TX_IRQ_NBR, 371 .dma_out_irq_nbr = SER2_DMA_TX_IRQ_NBR,
372 .dma_out_irq_flags = IRQF_DISABLED, 372 .dma_out_irq_flags = 0,
373 .dma_out_irq_description = "serial 2 dma tr", 373 .dma_out_irq_description = "serial 2 dma tr",
374#else 374#else
375 .dma_out_enabled = 0, 375 .dma_out_enabled = 0,
@@ -382,7 +382,7 @@ static struct e100_serial rs_table[] = {
382 .dma_in_enabled = 1, 382 .dma_in_enabled = 1,
383 .dma_in_nbr = SER2_RX_DMA_NBR, 383 .dma_in_nbr = SER2_RX_DMA_NBR,
384 .dma_in_irq_nbr = SER2_DMA_RX_IRQ_NBR, 384 .dma_in_irq_nbr = SER2_DMA_RX_IRQ_NBR,
385 .dma_in_irq_flags = IRQF_DISABLED, 385 .dma_in_irq_flags = 0,
386 .dma_in_irq_description = "serial 2 dma rec", 386 .dma_in_irq_description = "serial 2 dma rec",
387#else 387#else
388 .dma_in_enabled = 0, 388 .dma_in_enabled = 0,
@@ -423,7 +423,7 @@ static struct e100_serial rs_table[] = {
423 .dma_out_enabled = 1, 423 .dma_out_enabled = 1,
424 .dma_out_nbr = SER3_TX_DMA_NBR, 424 .dma_out_nbr = SER3_TX_DMA_NBR,
425 .dma_out_irq_nbr = SER3_DMA_TX_IRQ_NBR, 425 .dma_out_irq_nbr = SER3_DMA_TX_IRQ_NBR,
426 .dma_out_irq_flags = IRQF_DISABLED, 426 .dma_out_irq_flags = 0,
427 .dma_out_irq_description = "serial 3 dma tr", 427 .dma_out_irq_description = "serial 3 dma tr",
428#else 428#else
429 .dma_out_enabled = 0, 429 .dma_out_enabled = 0,
@@ -436,7 +436,7 @@ static struct e100_serial rs_table[] = {
436 .dma_in_enabled = 1, 436 .dma_in_enabled = 1,
437 .dma_in_nbr = SER3_RX_DMA_NBR, 437 .dma_in_nbr = SER3_RX_DMA_NBR,
438 .dma_in_irq_nbr = SER3_DMA_RX_IRQ_NBR, 438 .dma_in_irq_nbr = SER3_DMA_RX_IRQ_NBR,
439 .dma_in_irq_flags = IRQF_DISABLED, 439 .dma_in_irq_flags = 0,
440 .dma_in_irq_description = "serial 3 dma rec", 440 .dma_in_irq_description = "serial 3 dma rec",
441#else 441#else
442 .dma_in_enabled = 0, 442 .dma_in_enabled = 0,
@@ -1788,7 +1788,7 @@ static unsigned int handle_descr_data(struct e100_serial *info,
1788 struct etrax_recv_buffer *buffer = phys_to_virt(descr->buf) - sizeof *buffer; 1788 struct etrax_recv_buffer *buffer = phys_to_virt(descr->buf) - sizeof *buffer;
1789 1789
1790 if (info->recv_cnt + recvl > 65536) { 1790 if (info->recv_cnt + recvl > 65536) {
1791 printk(KERN_CRIT 1791 printk(KERN_WARNING
1792 "%s: Too much pending incoming serial data! Dropping %u bytes.\n", __func__, recvl); 1792 "%s: Too much pending incoming serial data! Dropping %u bytes.\n", __func__, recvl);
1793 return 0; 1793 return 0;
1794 } 1794 }
@@ -3813,13 +3813,13 @@ rs_close(struct tty_struct *tty, struct file * filp)
3813 * one, we've got real problems, since it means the 3813 * one, we've got real problems, since it means the
3814 * serial port won't be shutdown. 3814 * serial port won't be shutdown.
3815 */ 3815 */
3816 printk(KERN_CRIT 3816 printk(KERN_ERR
3817 "rs_close: bad serial port count; tty->count is 1, " 3817 "rs_close: bad serial port count; tty->count is 1, "
3818 "info->count is %d\n", info->count); 3818 "info->count is %d\n", info->count);
3819 info->count = 1; 3819 info->count = 1;
3820 } 3820 }
3821 if (--info->count < 0) { 3821 if (--info->count < 0) {
3822 printk(KERN_CRIT "rs_close: bad serial port count for ttyS%d: %d\n", 3822 printk(KERN_ERR "rs_close: bad serial port count for ttyS%d: %d\n",
3823 info->line, info->count); 3823 info->line, info->count);
3824 info->count = 0; 3824 info->count = 0;
3825 } 3825 }
@@ -4452,7 +4452,7 @@ static int __init rs_init(void)
4452#if defined(CONFIG_ETRAX_RS485_ON_PA) 4452#if defined(CONFIG_ETRAX_RS485_ON_PA)
4453 if (cris_io_interface_allocate_pins(if_serial_0, 'a', rs485_pa_bit, 4453 if (cris_io_interface_allocate_pins(if_serial_0, 'a', rs485_pa_bit,
4454 rs485_pa_bit)) { 4454 rs485_pa_bit)) {
4455 printk(KERN_CRIT "ETRAX100LX serial: Could not allocate " 4455 printk(KERN_ERR "ETRAX100LX serial: Could not allocate "
4456 "RS485 pin\n"); 4456 "RS485 pin\n");
4457 put_tty_driver(driver); 4457 put_tty_driver(driver);
4458 return -EBUSY; 4458 return -EBUSY;
@@ -4461,7 +4461,7 @@ static int __init rs_init(void)
4461#if defined(CONFIG_ETRAX_RS485_ON_PORT_G) 4461#if defined(CONFIG_ETRAX_RS485_ON_PORT_G)
4462 if (cris_io_interface_allocate_pins(if_serial_0, 'g', rs485_pa_bit, 4462 if (cris_io_interface_allocate_pins(if_serial_0, 'g', rs485_pa_bit,
4463 rs485_port_g_bit)) { 4463 rs485_port_g_bit)) {
4464 printk(KERN_CRIT "ETRAX100LX serial: Could not allocate " 4464 printk(KERN_ERR "ETRAX100LX serial: Could not allocate "
4465 "RS485 pin\n"); 4465 "RS485 pin\n");
4466 put_tty_driver(driver); 4466 put_tty_driver(driver);
4467 return -EBUSY; 4467 return -EBUSY;
@@ -4494,7 +4494,7 @@ static int __init rs_init(void)
4494 if (info->enabled) { 4494 if (info->enabled) {
4495 if (cris_request_io_interface(info->io_if, 4495 if (cris_request_io_interface(info->io_if,
4496 info->io_if_description)) { 4496 info->io_if_description)) {
4497 printk(KERN_CRIT "ETRAX100LX async serial: " 4497 printk(KERN_ERR "ETRAX100LX async serial: "
4498 "Could not allocate IO pins for " 4498 "Could not allocate IO pins for "
4499 "%s, port %d\n", 4499 "%s, port %d\n",
4500 info->io_if_description, i); 4500 info->io_if_description, i);
@@ -4558,7 +4558,7 @@ static int __init rs_init(void)
4558 /* hook the irq's for DMA channel 6 and 7, serial output and input, and some more... */ 4558 /* hook the irq's for DMA channel 6 and 7, serial output and input, and some more... */
4559 4559
4560 if (request_irq(SERIAL_IRQ_NBR, ser_interrupt, 4560 if (request_irq(SERIAL_IRQ_NBR, ser_interrupt,
4561 IRQF_SHARED | IRQF_DISABLED, "serial ", driver)) 4561 IRQF_SHARED, "serial ", driver))
4562 panic("%s: Failed to request irq8", __func__); 4562 panic("%s: Failed to request irq8", __func__);
4563 4563
4564#endif 4564#endif
diff --git a/drivers/tty/serial/dz.c b/drivers/tty/serial/dz.c
index ddc487a2d42f..e3699a84049f 100644
--- a/drivers/tty/serial/dz.c
+++ b/drivers/tty/serial/dz.c
@@ -47,6 +47,7 @@
47#include <linux/serial_core.h> 47#include <linux/serial_core.h>
48#include <linux/sysrq.h> 48#include <linux/sysrq.h>
49#include <linux/tty.h> 49#include <linux/tty.h>
50#include <linux/tty_flip.h>
50 51
51#include <linux/atomic.h> 52#include <linux/atomic.h>
52#include <asm/bootinfo.h> 53#include <asm/bootinfo.h>
diff --git a/drivers/tty/serial/icom.c b/drivers/tty/serial/icom.c
index 8a869e58f6d7..d55709a7a75a 100644
--- a/drivers/tty/serial/icom.c
+++ b/drivers/tty/serial/icom.c
@@ -1554,7 +1554,7 @@ static int __devinit icom_probe(struct pci_dev *dev,
1554 1554
1555 /* save off irq and request irq line */ 1555 /* save off irq and request irq line */
1556 if ( (retval = request_irq(dev->irq, icom_interrupt, 1556 if ( (retval = request_irq(dev->irq, icom_interrupt,
1557 IRQF_DISABLED | IRQF_SHARED, ICOM_DRIVER_NAME, 1557 IRQF_SHARED, ICOM_DRIVER_NAME,
1558 (void *) icom_adapter))) { 1558 (void *) icom_adapter))) {
1559 goto probe_exit2; 1559 goto probe_exit2;
1560 } 1560 }
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 7e91b3d368cd..54ffdc6243f9 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -508,8 +508,10 @@ static irqreturn_t imx_rxint(int irq, void *dev_id)
508 if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx)) 508 if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
509 continue; 509 continue;
510 510
511 if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) { 511 if (unlikely(rx & URXD_ERR)) {
512 if (rx & URXD_PRERR) 512 if (rx & URXD_BRK)
513 sport->port.icount.brk++;
514 else if (rx & URXD_PRERR)
513 sport->port.icount.parity++; 515 sport->port.icount.parity++;
514 else if (rx & URXD_FRMERR) 516 else if (rx & URXD_FRMERR)
515 sport->port.icount.frame++; 517 sport->port.icount.frame++;
@@ -524,7 +526,9 @@ static irqreturn_t imx_rxint(int irq, void *dev_id)
524 526
525 rx &= sport->port.read_status_mask; 527 rx &= sport->port.read_status_mask;
526 528
527 if (rx & URXD_PRERR) 529 if (rx & URXD_BRK)
530 flg = TTY_BREAK;
531 else if (rx & URXD_PRERR)
528 flg = TTY_PARITY; 532 flg = TTY_PARITY;
529 else if (rx & URXD_FRMERR) 533 else if (rx & URXD_FRMERR)
530 flg = TTY_FRAME; 534 flg = TTY_FRAME;
diff --git a/drivers/tty/serial/ioc3_serial.c b/drivers/tty/serial/ioc3_serial.c
index ee43efc7bdcc..758ff310f7f8 100644
--- a/drivers/tty/serial/ioc3_serial.c
+++ b/drivers/tty/serial/ioc3_serial.c
@@ -13,6 +13,7 @@
13 */ 13 */
14#include <linux/errno.h> 14#include <linux/errno.h>
15#include <linux/tty.h> 15#include <linux/tty.h>
16#include <linux/tty_flip.h>
16#include <linux/serial.h> 17#include <linux/serial.h>
17#include <linux/circ_buf.h> 18#include <linux/circ_buf.h>
18#include <linux/serial_reg.h> 19#include <linux/serial_reg.h>
diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
index fcfe82653ac8..6b36c1554d7e 100644
--- a/drivers/tty/serial/ioc4_serial.c
+++ b/drivers/tty/serial/ioc4_serial.c
@@ -14,6 +14,7 @@
14 */ 14 */
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/tty.h> 16#include <linux/tty.h>
17#include <linux/tty_flip.h>
17#include <linux/serial.h> 18#include <linux/serial.h>
18#include <linux/serialP.h> 19#include <linux/serialP.h>
19#include <linux/circ_buf.h> 20#include <linux/circ_buf.h>
diff --git a/drivers/tty/serial/jsm/jsm.h b/drivers/tty/serial/jsm/jsm.h
index b704c8ce0d71..529bec6edaf8 100644
--- a/drivers/tty/serial/jsm/jsm.h
+++ b/drivers/tty/serial/jsm/jsm.h
@@ -88,7 +88,6 @@ enum {
88 88
89/* 4 extra for alignment play space */ 89/* 4 extra for alignment play space */
90#define WRITEBUFLEN ((4096) + 4) 90#define WRITEBUFLEN ((4096) + 4)
91#define MYFLIPLEN N_TTY_BUF_SIZE
92 91
93#define JSM_VERSION "jsm: 1.2-1-INKERNEL" 92#define JSM_VERSION "jsm: 1.2-1-INKERNEL"
94#define JSM_PARTNUM "40002438_A-INKERNEL" 93#define JSM_PARTNUM "40002438_A-INKERNEL"
@@ -150,7 +149,6 @@ struct jsm_board
150 u32 bd_uart_offset; /* Space between each UART */ 149 u32 bd_uart_offset; /* Space between each UART */
151 150
152 struct jsm_channel *channels[MAXPORTS]; /* array of pointers to our channels. */ 151 struct jsm_channel *channels[MAXPORTS]; /* array of pointers to our channels. */
153 char *flipbuf; /* Our flip buffer, alloced if board is found */
154 152
155 u32 bd_dividend; /* Board/UARTs specific dividend */ 153 u32 bd_dividend; /* Board/UARTs specific dividend */
156 154
@@ -177,16 +175,13 @@ struct jsm_board
177#define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */ 175#define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
178#define CH_BREAK_SENDING 0x1000 /* Break is being sent */ 176#define CH_BREAK_SENDING 0x1000 /* Break is being sent */
179#define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */ 177#define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
180#define CH_FLIPBUF_IN_USE 0x4000 /* Channel's flipbuf is in use */
181#define CH_BAUD0 0x08000 /* Used for checking B0 transitions */ 178#define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
182 179
183/* Our Read/Error/Write queue sizes */ 180/* Our Read/Error/Write queue sizes */
184#define RQUEUEMASK 0x1FFF /* 8 K - 1 */ 181#define RQUEUEMASK 0x1FFF /* 8 K - 1 */
185#define EQUEUEMASK 0x1FFF /* 8 K - 1 */ 182#define EQUEUEMASK 0x1FFF /* 8 K - 1 */
186#define WQUEUEMASK 0x0FFF /* 4 K - 1 */
187#define RQUEUESIZE (RQUEUEMASK + 1) 183#define RQUEUESIZE (RQUEUEMASK + 1)
188#define EQUEUESIZE RQUEUESIZE 184#define EQUEUESIZE RQUEUESIZE
189#define WQUEUESIZE (WQUEUEMASK + 1)
190 185
191 186
192/************************************************************************ 187/************************************************************************
@@ -226,10 +221,6 @@ struct jsm_channel {
226 u16 ch_e_head; /* Head location of the error queue */ 221 u16 ch_e_head; /* Head location of the error queue */
227 u16 ch_e_tail; /* Tail location of the error queue */ 222 u16 ch_e_tail; /* Tail location of the error queue */
228 223
229 u8 *ch_wqueue; /* Our write queue buffer - malloc'ed */
230 u16 ch_w_head; /* Head location of the write queue */
231 u16 ch_w_tail; /* Tail location of the write queue */
232
233 u64 ch_rxcount; /* total of data received so far */ 224 u64 ch_rxcount; /* total of data received so far */
234 u64 ch_txcount; /* total of data transmitted so far */ 225 u64 ch_txcount; /* total of data transmitted so far */
235 226
@@ -378,7 +369,6 @@ extern int jsm_debug;
378 * Prototypes for non-static functions used in more than one module 369 * Prototypes for non-static functions used in more than one module
379 * 370 *
380 *************************************************************************/ 371 *************************************************************************/
381int jsm_tty_write(struct uart_port *port);
382int jsm_tty_init(struct jsm_board *); 372int jsm_tty_init(struct jsm_board *);
383int jsm_uart_port_init(struct jsm_board *); 373int jsm_uart_port_init(struct jsm_board *);
384int jsm_remove_uart_port(struct jsm_board *); 374int jsm_remove_uart_port(struct jsm_board *);
diff --git a/drivers/tty/serial/jsm/jsm_driver.c b/drivers/tty/serial/jsm/jsm_driver.c
index 96da17868cf3..648b6a3efa32 100644
--- a/drivers/tty/serial/jsm/jsm_driver.c
+++ b/drivers/tty/serial/jsm/jsm_driver.c
@@ -160,27 +160,10 @@ static int __devinit jsm_probe_one(struct pci_dev *pdev, const struct pci_device
160 dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n", 160 dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
161 adapter_count, brd->rev, brd->irq); 161 adapter_count, brd->rev, brd->irq);
162 162
163 /*
164 * allocate flip buffer for board.
165 *
166 * Okay to malloc with GFP_KERNEL, we are not at interrupt
167 * context, and there are no locks held.
168 */
169 brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
170 if (!brd->flipbuf) {
171 /* XXX: leaking all resources from jsm_tty_init and
172 jsm_uart_port_init here! */
173 dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
174 rc = -ENOMEM;
175 goto out_free_uart;
176 }
177
178 pci_set_drvdata(pdev, brd); 163 pci_set_drvdata(pdev, brd);
179 pci_save_state(pdev); 164 pci_save_state(pdev);
180 165
181 return 0; 166 return 0;
182 out_free_uart:
183 jsm_remove_uart_port(brd);
184 out_free_irq: 167 out_free_irq:
185 jsm_remove_uart_port(brd); 168 jsm_remove_uart_port(brd);
186 free_irq(brd->irq, brd); 169 free_irq(brd->irq, brd);
@@ -211,14 +194,12 @@ static void __devexit jsm_remove_one(struct pci_dev *pdev)
211 if (brd->channels[i]) { 194 if (brd->channels[i]) {
212 kfree(brd->channels[i]->ch_rqueue); 195 kfree(brd->channels[i]->ch_rqueue);
213 kfree(brd->channels[i]->ch_equeue); 196 kfree(brd->channels[i]->ch_equeue);
214 kfree(brd->channels[i]->ch_wqueue);
215 kfree(brd->channels[i]); 197 kfree(brd->channels[i]);
216 } 198 }
217 } 199 }
218 200
219 pci_release_regions(pdev); 201 pci_release_regions(pdev);
220 pci_disable_device(pdev); 202 pci_disable_device(pdev);
221 kfree(brd->flipbuf);
222 kfree(brd); 203 kfree(brd);
223} 204}
224 205
diff --git a/drivers/tty/serial/jsm/jsm_neo.c b/drivers/tty/serial/jsm/jsm_neo.c
index 4538c3e3646e..81dfafa11b0b 100644
--- a/drivers/tty/serial/jsm/jsm_neo.c
+++ b/drivers/tty/serial/jsm/jsm_neo.c
@@ -496,12 +496,15 @@ static void neo_copy_data_from_queue_to_uart(struct jsm_channel *ch)
496 int s; 496 int s;
497 int qlen; 497 int qlen;
498 u32 len_written = 0; 498 u32 len_written = 0;
499 struct circ_buf *circ;
499 500
500 if (!ch) 501 if (!ch)
501 return; 502 return;
502 503
504 circ = &ch->uart_port.state->xmit;
505
503 /* No data to write to the UART */ 506 /* No data to write to the UART */
504 if (ch->ch_w_tail == ch->ch_w_head) 507 if (uart_circ_empty(circ))
505 return; 508 return;
506 509
507 /* If port is "stopped", don't send any data to the UART */ 510 /* If port is "stopped", don't send any data to the UART */
@@ -517,11 +520,10 @@ static void neo_copy_data_from_queue_to_uart(struct jsm_channel *ch)
517 if (ch->ch_cached_lsr & UART_LSR_THRE) { 520 if (ch->ch_cached_lsr & UART_LSR_THRE) {
518 ch->ch_cached_lsr &= ~(UART_LSR_THRE); 521 ch->ch_cached_lsr &= ~(UART_LSR_THRE);
519 522
520 writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_neo_uart->txrx); 523 writeb(circ->buf[circ->tail], &ch->ch_neo_uart->txrx);
521 jsm_printk(WRITE, INFO, &ch->ch_bd->pci_dev, 524 jsm_printk(WRITE, INFO, &ch->ch_bd->pci_dev,
522 "Tx data: %x\n", ch->ch_wqueue[ch->ch_w_head]); 525 "Tx data: %x\n", circ->buf[circ->tail]);
523 ch->ch_w_tail++; 526 circ->tail = (circ->tail + 1) & (UART_XMIT_SIZE - 1);
524 ch->ch_w_tail &= WQUEUEMASK;
525 ch->ch_txcount++; 527 ch->ch_txcount++;
526 } 528 }
527 return; 529 return;
@@ -536,36 +538,36 @@ static void neo_copy_data_from_queue_to_uart(struct jsm_channel *ch)
536 n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel; 538 n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
537 539
538 /* cache head and tail of queue */ 540 /* cache head and tail of queue */
539 head = ch->ch_w_head & WQUEUEMASK; 541 head = circ->head & (UART_XMIT_SIZE - 1);
540 tail = ch->ch_w_tail & WQUEUEMASK; 542 tail = circ->tail & (UART_XMIT_SIZE - 1);
541 qlen = (head - tail) & WQUEUEMASK; 543 qlen = uart_circ_chars_pending(circ);
542 544
543 /* Find minimum of the FIFO space, versus queue length */ 545 /* Find minimum of the FIFO space, versus queue length */
544 n = min(n, qlen); 546 n = min(n, qlen);
545 547
546 while (n > 0) { 548 while (n > 0) {
547 549
548 s = ((head >= tail) ? head : WQUEUESIZE) - tail; 550 s = ((head >= tail) ? head : UART_XMIT_SIZE) - tail;
549 s = min(s, n); 551 s = min(s, n);
550 552
551 if (s <= 0) 553 if (s <= 0)
552 break; 554 break;
553 555
554 memcpy_toio(&ch->ch_neo_uart->txrxburst, ch->ch_wqueue + tail, s); 556 memcpy_toio(&ch->ch_neo_uart->txrxburst, circ->buf + tail, s);
555 /* Add and flip queue if needed */ 557 /* Add and flip queue if needed */
556 tail = (tail + s) & WQUEUEMASK; 558 tail = (tail + s) & (UART_XMIT_SIZE - 1);
557 n -= s; 559 n -= s;
558 ch->ch_txcount += s; 560 ch->ch_txcount += s;
559 len_written += s; 561 len_written += s;
560 } 562 }
561 563
562 /* Update the final tail */ 564 /* Update the final tail */
563 ch->ch_w_tail = tail & WQUEUEMASK; 565 circ->tail = tail & (UART_XMIT_SIZE - 1);
564 566
565 if (len_written >= ch->ch_t_tlevel) 567 if (len_written >= ch->ch_t_tlevel)
566 ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); 568 ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
567 569
568 if (!jsm_tty_write(&ch->uart_port)) 570 if (uart_circ_empty(circ))
569 uart_write_wakeup(&ch->uart_port); 571 uart_write_wakeup(&ch->uart_port);
570} 572}
571 573
@@ -946,7 +948,6 @@ static void neo_param(struct jsm_channel *ch)
946 if ((ch->ch_c_cflag & (CBAUD)) == 0) { 948 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
947 ch->ch_r_head = ch->ch_r_tail = 0; 949 ch->ch_r_head = ch->ch_r_tail = 0;
948 ch->ch_e_head = ch->ch_e_tail = 0; 950 ch->ch_e_head = ch->ch_e_tail = 0;
949 ch->ch_w_head = ch->ch_w_tail = 0;
950 951
951 neo_flush_uart_write(ch); 952 neo_flush_uart_write(ch);
952 neo_flush_uart_read(ch); 953 neo_flush_uart_read(ch);
diff --git a/drivers/tty/serial/jsm/jsm_tty.c b/drivers/tty/serial/jsm/jsm_tty.c
index 7a4a914ecff0..434bd881fcae 100644
--- a/drivers/tty/serial/jsm/jsm_tty.c
+++ b/drivers/tty/serial/jsm/jsm_tty.c
@@ -118,6 +118,19 @@ static void jsm_tty_set_mctrl(struct uart_port *port, unsigned int mctrl)
118 udelay(10); 118 udelay(10);
119} 119}
120 120
121/*
122 * jsm_tty_write()
123 *
124 * Take data from the user or kernel and send it out to the FEP.
125 * In here exists all the Transparent Print magic as well.
126 */
127static void jsm_tty_write(struct uart_port *port)
128{
129 struct jsm_channel *channel;
130 channel = container_of(port, struct jsm_channel, uart_port);
131 channel->ch_bd->bd_ops->copy_data_from_queue_to_uart(channel);
132}
133
121static void jsm_tty_start_tx(struct uart_port *port) 134static void jsm_tty_start_tx(struct uart_port *port)
122{ 135{
123 struct jsm_channel *channel = (struct jsm_channel *)port; 136 struct jsm_channel *channel = (struct jsm_channel *)port;
@@ -216,14 +229,6 @@ static int jsm_tty_open(struct uart_port *port)
216 return -ENOMEM; 229 return -ENOMEM;
217 } 230 }
218 } 231 }
219 if (!channel->ch_wqueue) {
220 channel->ch_wqueue = kzalloc(WQUEUESIZE, GFP_KERNEL);
221 if (!channel->ch_wqueue) {
222 jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
223 "unable to allocate write queue buf");
224 return -ENOMEM;
225 }
226 }
227 232
228 channel->ch_flags &= ~(CH_OPENING); 233 channel->ch_flags &= ~(CH_OPENING);
229 /* 234 /*
@@ -237,7 +242,6 @@ static int jsm_tty_open(struct uart_port *port)
237 */ 242 */
238 channel->ch_r_head = channel->ch_r_tail = 0; 243 channel->ch_r_head = channel->ch_r_tail = 0;
239 channel->ch_e_head = channel->ch_e_tail = 0; 244 channel->ch_e_head = channel->ch_e_tail = 0;
240 channel->ch_w_head = channel->ch_w_tail = 0;
241 245
242 brd->bd_ops->flush_uart_write(channel); 246 brd->bd_ops->flush_uart_write(channel);
243 brd->bd_ops->flush_uart_read(channel); 247 brd->bd_ops->flush_uart_read(channel);
@@ -836,75 +840,3 @@ void jsm_check_queue_flow_control(struct jsm_channel *ch)
836 } 840 }
837 } 841 }
838} 842}
839
840/*
841 * jsm_tty_write()
842 *
843 * Take data from the user or kernel and send it out to the FEP.
844 * In here exists all the Transparent Print magic as well.
845 */
846int jsm_tty_write(struct uart_port *port)
847{
848 int bufcount;
849 int data_count = 0,data_count1 =0;
850 u16 head;
851 u16 tail;
852 u16 tmask;
853 u32 remain;
854 int temp_tail = port->state->xmit.tail;
855 struct jsm_channel *channel = (struct jsm_channel *)port;
856
857 tmask = WQUEUEMASK;
858 head = (channel->ch_w_head) & tmask;
859 tail = (channel->ch_w_tail) & tmask;
860
861 if ((bufcount = tail - head - 1) < 0)
862 bufcount += WQUEUESIZE;
863
864 bufcount = min(bufcount, 56);
865 remain = WQUEUESIZE - head;
866
867 data_count = 0;
868 if (bufcount >= remain) {
869 bufcount -= remain;
870 while ((port->state->xmit.head != temp_tail) &&
871 (data_count < remain)) {
872 channel->ch_wqueue[head++] =
873 port->state->xmit.buf[temp_tail];
874
875 temp_tail++;
876 temp_tail &= (UART_XMIT_SIZE - 1);
877 data_count++;
878 }
879 if (data_count == remain) head = 0;
880 }
881
882 data_count1 = 0;
883 if (bufcount > 0) {
884 remain = bufcount;
885 while ((port->state->xmit.head != temp_tail) &&
886 (data_count1 < remain)) {
887 channel->ch_wqueue[head++] =
888 port->state->xmit.buf[temp_tail];
889
890 temp_tail++;
891 temp_tail &= (UART_XMIT_SIZE - 1);
892 data_count1++;
893
894 }
895 }
896
897 port->state->xmit.tail = temp_tail;
898
899 data_count += data_count1;
900 if (data_count) {
901 head &= tmask;
902 channel->ch_w_head = head;
903 }
904
905 if (data_count) {
906 channel->ch_bd->bd_ops->copy_data_from_queue_to_uart(channel);
907 }
908
909 return data_count;
910}
diff --git a/drivers/tty/serial/lantiq.c b/drivers/tty/serial/lantiq.c
index bc95f52cad8b..96c1cacc7360 100644
--- a/drivers/tty/serial/lantiq.c
+++ b/drivers/tty/serial/lantiq.c
@@ -338,21 +338,21 @@ lqasc_startup(struct uart_port *port)
338 ASCCON_ROEN, port->membase + LTQ_ASC_CON); 338 ASCCON_ROEN, port->membase + LTQ_ASC_CON);
339 339
340 retval = request_irq(ltq_port->tx_irq, lqasc_tx_int, 340 retval = request_irq(ltq_port->tx_irq, lqasc_tx_int,
341 IRQF_DISABLED, "asc_tx", port); 341 0, "asc_tx", port);
342 if (retval) { 342 if (retval) {
343 pr_err("failed to request lqasc_tx_int\n"); 343 pr_err("failed to request lqasc_tx_int\n");
344 return retval; 344 return retval;
345 } 345 }
346 346
347 retval = request_irq(ltq_port->rx_irq, lqasc_rx_int, 347 retval = request_irq(ltq_port->rx_irq, lqasc_rx_int,
348 IRQF_DISABLED, "asc_rx", port); 348 0, "asc_rx", port);
349 if (retval) { 349 if (retval) {
350 pr_err("failed to request lqasc_rx_int\n"); 350 pr_err("failed to request lqasc_rx_int\n");
351 goto err1; 351 goto err1;
352 } 352 }
353 353
354 retval = request_irq(ltq_port->err_irq, lqasc_err_int, 354 retval = request_irq(ltq_port->err_irq, lqasc_err_int,
355 IRQF_DISABLED, "asc_err", port); 355 0, "asc_err", port);
356 if (retval) { 356 if (retval) {
357 pr_err("failed to request lqasc_err_int\n"); 357 pr_err("failed to request lqasc_err_int\n");
358 goto err2; 358 goto err2;
diff --git a/drivers/tty/serial/m32r_sio.c b/drivers/tty/serial/m32r_sio.c
index 8e07517f8acd..08018934e013 100644
--- a/drivers/tty/serial/m32r_sio.c
+++ b/drivers/tty/serial/m32r_sio.c
@@ -32,6 +32,7 @@
32 32
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/tty.h> 34#include <linux/tty.h>
35#include <linux/tty_flip.h>
35#include <linux/ioport.h> 36#include <linux/ioport.h>
36#include <linux/init.h> 37#include <linux/init.h>
37#include <linux/console.h> 38#include <linux/console.h>
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 7b951adac54b..2af5aa5f3a80 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -47,6 +47,8 @@
47#include <linux/serial.h> 47#include <linux/serial.h>
48#include <linux/spi/spi.h> 48#include <linux/spi/spi.h>
49#include <linux/freezer.h> 49#include <linux/freezer.h>
50#include <linux/tty.h>
51#include <linux/tty_flip.h>
50 52
51#include <linux/serial_max3100.h> 53#include <linux/serial_max3100.h>
52 54
diff --git a/drivers/tty/serial/max3107.c b/drivers/tty/serial/max3107.c
index a8164601c0ea..db00b595cab0 100644
--- a/drivers/tty/serial/max3107.c
+++ b/drivers/tty/serial/max3107.c
@@ -31,6 +31,8 @@
31#include <linux/device.h> 31#include <linux/device.h>
32#include <linux/serial_core.h> 32#include <linux/serial_core.h>
33#include <linux/serial.h> 33#include <linux/serial.h>
34#include <linux/tty.h>
35#include <linux/tty_flip.h>
34#include <linux/gpio.h> 36#include <linux/gpio.h>
35#include <linux/spi/spi.h> 37#include <linux/spi/spi.h>
36#include <linux/freezer.h> 38#include <linux/freezer.h>
diff --git a/drivers/tty/serial/mcf.c b/drivers/tty/serial/mcf.c
index 3394b7cc1722..9afca093d6ec 100644
--- a/drivers/tty/serial/mcf.c
+++ b/drivers/tty/serial/mcf.c
@@ -380,7 +380,7 @@ static void mcf_config_port(struct uart_port *port, int flags)
380 /* Clear mask, so no surprise interrupts. */ 380 /* Clear mask, so no surprise interrupts. */
381 writeb(0, port->membase + MCFUART_UIMR); 381 writeb(0, port->membase + MCFUART_UIMR);
382 382
383 if (request_irq(port->irq, mcf_interrupt, IRQF_DISABLED, "UART", port)) 383 if (request_irq(port->irq, mcf_interrupt, 0, "UART", port))
384 printk(KERN_ERR "MCF: unable to attach ColdFire UART %d " 384 printk(KERN_ERR "MCF: unable to attach ColdFire UART %d "
385 "interrupt vector=%d\n", port->line, port->irq); 385 "interrupt vector=%d\n", port->line, port->irq);
386} 386}
diff --git a/drivers/tty/serial/mfd.c b/drivers/tty/serial/mfd.c
index cab52f4a88b0..286c386d9c46 100644
--- a/drivers/tty/serial/mfd.c
+++ b/drivers/tty/serial/mfd.c
@@ -38,6 +38,7 @@
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/io.h> 39#include <linux/io.h>
40#include <linux/debugfs.h> 40#include <linux/debugfs.h>
41#include <linux/pm_runtime.h>
41 42
42#define HSU_DMA_BUF_SIZE 2048 43#define HSU_DMA_BUF_SIZE 2048
43 44
@@ -764,6 +765,8 @@ static int serial_hsu_startup(struct uart_port *port)
764 container_of(port, struct uart_hsu_port, port); 765 container_of(port, struct uart_hsu_port, port);
765 unsigned long flags; 766 unsigned long flags;
766 767
768 pm_runtime_get_sync(up->dev);
769
767 /* 770 /*
768 * Clear the FIFO buffers and disable them. 771 * Clear the FIFO buffers and disable them.
769 * (they will be reenabled in set_termios()) 772 * (they will be reenabled in set_termios())
@@ -871,6 +874,8 @@ static void serial_hsu_shutdown(struct uart_port *port)
871 UART_FCR_CLEAR_RCVR | 874 UART_FCR_CLEAR_RCVR |
872 UART_FCR_CLEAR_XMIT); 875 UART_FCR_CLEAR_XMIT);
873 serial_out(up, UART_FCR, 0); 876 serial_out(up, UART_FCR, 0);
877
878 pm_runtime_put(up->dev);
874} 879}
875 880
876static void 881static void
@@ -1249,6 +1254,39 @@ static int serial_hsu_resume(struct pci_dev *pdev)
1249#define serial_hsu_resume NULL 1254#define serial_hsu_resume NULL
1250#endif 1255#endif
1251 1256
1257#ifdef CONFIG_PM_RUNTIME
1258static int serial_hsu_runtime_idle(struct device *dev)
1259{
1260 int err;
1261
1262 err = pm_schedule_suspend(dev, 500);
1263 if (err)
1264 return -EBUSY;
1265
1266 return 0;
1267}
1268
1269static int serial_hsu_runtime_suspend(struct device *dev)
1270{
1271 return 0;
1272}
1273
1274static int serial_hsu_runtime_resume(struct device *dev)
1275{
1276 return 0;
1277}
1278#else
1279#define serial_hsu_runtime_idle NULL
1280#define serial_hsu_runtime_suspend NULL
1281#define serial_hsu_runtime_resume NULL
1282#endif
1283
1284static const struct dev_pm_ops serial_hsu_pm_ops = {
1285 .runtime_suspend = serial_hsu_runtime_suspend,
1286 .runtime_resume = serial_hsu_runtime_resume,
1287 .runtime_idle = serial_hsu_runtime_idle,
1288};
1289
1252/* temp global pointer before we settle down on using one or four PCI dev */ 1290/* temp global pointer before we settle down on using one or four PCI dev */
1253static struct hsu_port *phsu; 1291static struct hsu_port *phsu;
1254 1292
@@ -1315,6 +1353,9 @@ static int serial_hsu_probe(struct pci_dev *pdev,
1315 pci_set_drvdata(pdev, uport); 1353 pci_set_drvdata(pdev, uport);
1316 } 1354 }
1317 1355
1356 pm_runtime_put_noidle(&pdev->dev);
1357 pm_runtime_allow(&pdev->dev);
1358
1318 return 0; 1359 return 0;
1319 1360
1320err_disable: 1361err_disable:
@@ -1411,6 +1452,9 @@ static void serial_hsu_remove(struct pci_dev *pdev)
1411 if (!priv) 1452 if (!priv)
1412 return; 1453 return;
1413 1454
1455 pm_runtime_forbid(&pdev->dev);
1456 pm_runtime_get_noresume(&pdev->dev);
1457
1414 /* For port 0/1/2, priv is the address of uart_hsu_port */ 1458 /* For port 0/1/2, priv is the address of uart_hsu_port */
1415 if (pdev->device != 0x081E) { 1459 if (pdev->device != 0x081E) {
1416 up = priv; 1460 up = priv;
@@ -1423,7 +1467,7 @@ static void serial_hsu_remove(struct pci_dev *pdev)
1423} 1467}
1424 1468
1425/* First 3 are UART ports, and the 4th is the DMA */ 1469/* First 3 are UART ports, and the 4th is the DMA */
1426static const struct pci_device_id pci_ids[] __devinitdata = { 1470static const struct pci_device_id pci_ids[] __devinitconst = {
1427 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081B) }, 1471 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081B) },
1428 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081C) }, 1472 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081C) },
1429 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081D) }, 1473 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081D) },
@@ -1438,6 +1482,9 @@ static struct pci_driver hsu_pci_driver = {
1438 .remove = __devexit_p(serial_hsu_remove), 1482 .remove = __devexit_p(serial_hsu_remove),
1439 .suspend = serial_hsu_suspend, 1483 .suspend = serial_hsu_suspend,
1440 .resume = serial_hsu_resume, 1484 .resume = serial_hsu_resume,
1485 .driver = {
1486 .pm = &serial_hsu_pm_ops,
1487 },
1441}; 1488};
1442 1489
1443static int __init hsu_pci_init(void) 1490static int __init hsu_pci_init(void)
diff --git a/drivers/tty/serial/mpc52xx_uart.c b/drivers/tty/serial/mpc52xx_uart.c
index a0bcd8a3758d..1093a88a1fe3 100644
--- a/drivers/tty/serial/mpc52xx_uart.c
+++ b/drivers/tty/serial/mpc52xx_uart.c
@@ -34,6 +34,7 @@
34#include <linux/device.h> 34#include <linux/device.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/tty.h> 36#include <linux/tty.h>
37#include <linux/tty_flip.h>
37#include <linux/serial.h> 38#include <linux/serial.h>
38#include <linux/sysrq.h> 39#include <linux/sysrq.h>
39#include <linux/console.h> 40#include <linux/console.h>
@@ -273,7 +274,7 @@ static unsigned int mpc5200b_psc_set_baudrate(struct uart_port *port,
273 274
274static void mpc52xx_psc_get_irq(struct uart_port *port, struct device_node *np) 275static void mpc52xx_psc_get_irq(struct uart_port *port, struct device_node *np)
275{ 276{
276 port->irqflags = IRQF_DISABLED; 277 port->irqflags = 0;
277 port->irq = irq_of_parse_and_map(np, 0); 278 port->irq = irq_of_parse_and_map(np, 0);
278} 279}
279 280
diff --git a/drivers/tty/serial/mrst_max3110.c b/drivers/tty/serial/mrst_max3110.c
index 492c14d63e99..4c309e869903 100644
--- a/drivers/tty/serial/mrst_max3110.c
+++ b/drivers/tty/serial/mrst_max3110.c
@@ -27,6 +27,10 @@
27 * interrupt for a low speed UART device 27 * interrupt for a low speed UART device
28 */ 28 */
29 29
30#ifdef CONFIG_MAGIC_SYSRQ
31#define SUPPORT_SYSRQ
32#endif
33
30#include <linux/module.h> 34#include <linux/module.h>
31#include <linux/ioport.h> 35#include <linux/ioport.h>
32#include <linux/irq.h> 36#include <linux/irq.h>
@@ -73,9 +77,9 @@ struct uart_max3110 {
73/* global data structure, may need be removed */ 77/* global data structure, may need be removed */
74static struct uart_max3110 *pmax; 78static struct uart_max3110 *pmax;
75 79
76static void receive_chars(struct uart_max3110 *max, 80static int receive_chars(struct uart_max3110 *max,
77 unsigned char *str, int len); 81 unsigned short *str, int len);
78static int max3110_read_multi(struct uart_max3110 *max, u8 *buf); 82static int max3110_read_multi(struct uart_max3110 *max);
79static void max3110_con_receive(struct uart_max3110 *max); 83static void max3110_con_receive(struct uart_max3110 *max);
80 84
81static int max3110_write_then_read(struct uart_max3110 *max, 85static int max3110_write_then_read(struct uart_max3110 *max,
@@ -108,7 +112,6 @@ static int max3110_out(struct uart_max3110 *max, const u16 out)
108{ 112{
109 void *buf; 113 void *buf;
110 u16 *obuf, *ibuf; 114 u16 *obuf, *ibuf;
111 u8 ch;
112 int ret; 115 int ret;
113 116
114 buf = kzalloc(8, GFP_KERNEL | GFP_DMA); 117 buf = kzalloc(8, GFP_KERNEL | GFP_DMA);
@@ -125,11 +128,7 @@ static int max3110_out(struct uart_max3110 *max, const u16 out)
125 goto exit; 128 goto exit;
126 } 129 }
127 130
128 /* If some valid data is read back */ 131 receive_chars(max, ibuf, 1);
129 if (*ibuf & MAX3110_READ_DATA_AVAILABLE) {
130 ch = *ibuf & 0xff;
131 receive_chars(max, &ch, 1);
132 }
133 132
134exit: 133exit:
135 kfree(buf); 134 kfree(buf);
@@ -142,12 +141,11 @@ exit:
142 * 141 *
143 * Return how many valide bytes are read back 142 * Return how many valide bytes are read back
144 */ 143 */
145static int max3110_read_multi(struct uart_max3110 *max, u8 *rxbuf) 144static int max3110_read_multi(struct uart_max3110 *max)
146{ 145{
147 void *buf; 146 void *buf;
148 u16 *obuf, *ibuf; 147 u16 *obuf, *ibuf;
149 u8 *pbuf, valid_str[M3110_RX_FIFO_DEPTH]; 148 int ret, blen;
150 int i, j, blen;
151 149
152 blen = M3110_RX_FIFO_DEPTH * sizeof(u16); 150 blen = M3110_RX_FIFO_DEPTH * sizeof(u16);
153 buf = kzalloc(blen * 2, GFP_KERNEL | GFP_DMA); 151 buf = kzalloc(blen * 2, GFP_KERNEL | GFP_DMA);
@@ -165,19 +163,10 @@ static int max3110_read_multi(struct uart_max3110 *max, u8 *rxbuf)
165 return 0; 163 return 0;
166 } 164 }
167 165
168 /* If caller doesn't provide a buffer, then handle received char */ 166 ret = receive_chars(max, ibuf, M3110_RX_FIFO_DEPTH);
169 pbuf = rxbuf ? rxbuf : valid_str;
170
171 for (i = 0, j = 0; i < M3110_RX_FIFO_DEPTH; i++) {
172 if (ibuf[i] & MAX3110_READ_DATA_AVAILABLE)
173 pbuf[j++] = ibuf[i] & 0xff;
174 }
175
176 if (j && (pbuf == valid_str))
177 receive_chars(max, valid_str, j);
178 167
179 kfree(buf); 168 kfree(buf);
180 return j; 169 return ret;
181} 170}
182 171
183static void serial_m3110_con_putchar(struct uart_port *port, int ch) 172static void serial_m3110_con_putchar(struct uart_port *port, int ch)
@@ -207,7 +196,7 @@ static void serial_m3110_con_write(struct console *co,
207 uart_console_write(&pmax->port, s, count, serial_m3110_con_putchar); 196 uart_console_write(&pmax->port, s, count, serial_m3110_con_putchar);
208 197
209 if (!test_and_set_bit(CON_TX_NEEDED, &pmax->uart_flags)) 198 if (!test_and_set_bit(CON_TX_NEEDED, &pmax->uart_flags))
210 wake_up_process(pmax->main_thread); 199 wake_up(&pmax->wq);
211} 200}
212 201
213static int __init 202static int __init
@@ -276,8 +265,7 @@ static void send_circ_buf(struct uart_max3110 *max,
276{ 265{
277 void *buf; 266 void *buf;
278 u16 *obuf, *ibuf; 267 u16 *obuf, *ibuf;
279 u8 valid_str[WORDS_PER_XFER]; 268 int i, len, blen, dma_size, left, ret = 0;
280 int i, j, len, blen, dma_size, left, ret = 0;
281 269
282 270
283 dma_size = WORDS_PER_XFER * sizeof(u16) * 2; 271 dma_size = WORDS_PER_XFER * sizeof(u16) * 2;
@@ -301,18 +289,13 @@ static void send_circ_buf(struct uart_max3110 *max,
301 } 289 }
302 290
303 /* Fail to send msg to console is not very critical */ 291 /* Fail to send msg to console is not very critical */
292
304 ret = max3110_write_then_read(max, obuf, ibuf, blen, 0); 293 ret = max3110_write_then_read(max, obuf, ibuf, blen, 0);
305 if (ret) 294 if (ret)
306 pr_warning(PR_FMT "%s(): get err msg %d\n", 295 pr_warning(PR_FMT "%s(): get err msg %d\n",
307 __func__, ret); 296 __func__, ret);
308 297
309 for (i = 0, j = 0; i < len; i++) { 298 receive_chars(max, ibuf, len);
310 if (ibuf[i] & MAX3110_READ_DATA_AVAILABLE)
311 valid_str[j++] = ibuf[i] & 0xff;
312 }
313
314 if (j)
315 receive_chars(max, valid_str, j);
316 299
317 max->port.icount.tx += len; 300 max->port.icount.tx += len;
318 left -= len; 301 left -= len;
@@ -349,33 +332,54 @@ static void serial_m3110_start_tx(struct uart_port *port)
349 container_of(port, struct uart_max3110, port); 332 container_of(port, struct uart_max3110, port);
350 333
351 if (!test_and_set_bit(UART_TX_NEEDED, &max->uart_flags)) 334 if (!test_and_set_bit(UART_TX_NEEDED, &max->uart_flags))
352 wake_up_process(max->main_thread); 335 wake_up(&max->wq);
353} 336}
354 337
355static void receive_chars(struct uart_max3110 *max, unsigned char *str, int len) 338static int
339receive_chars(struct uart_max3110 *max, unsigned short *str, int len)
356{ 340{
357 struct uart_port *port = &max->port; 341 struct uart_port *port = &max->port;
358 struct tty_struct *tty; 342 struct tty_struct *tty;
359 int usable; 343 char buf[M3110_RX_FIFO_DEPTH];
344 int r, w, usable;
360 345
361 /* If uart is not opened, just return */ 346 /* If uart is not opened, just return */
362 if (!port->state) 347 if (!port->state)
363 return; 348 return 0;
364 349
365 tty = port->state->port.tty; 350 tty = tty_port_tty_get(&port->state->port);
366 if (!tty) 351 if (!tty)
367 return; 352 return 0;
353
354 for (r = 0, w = 0; r < len; r++) {
355 if (str[r] & MAX3110_BREAK &&
356 uart_handle_break(port))
357 continue;
358
359 if (str[r] & MAX3110_READ_DATA_AVAILABLE) {
360 if (uart_handle_sysrq_char(port, str[r] & 0xff))
361 continue;
362
363 buf[w++] = str[r] & 0xff;
364 }
365 }
366
367 if (!w) {
368 tty_kref_put(tty);
369 return 0;
370 }
368 371
369 while (len) { 372 for (r = 0; w; r += usable, w -= usable) {
370 usable = tty_buffer_request_room(tty, len); 373 usable = tty_buffer_request_room(tty, w);
371 if (usable) { 374 if (usable) {
372 tty_insert_flip_string(tty, str, usable); 375 tty_insert_flip_string(tty, buf + r, usable);
373 str += usable;
374 port->icount.rx += usable; 376 port->icount.rx += usable;
375 } 377 }
376 len -= usable;
377 } 378 }
378 tty_flip_buffer_push(tty); 379 tty_flip_buffer_push(tty);
380 tty_kref_put(tty);
381
382 return r;
379} 383}
380 384
381/* 385/*
@@ -390,28 +394,15 @@ static void receive_chars(struct uart_max3110 *max, unsigned char *str, int len)
390 */ 394 */
391static void max3110_con_receive(struct uart_max3110 *max) 395static void max3110_con_receive(struct uart_max3110 *max)
392{ 396{
393 int loop = 1, num, total = 0; 397 int loop = 1, num;
394 u8 recv_buf[512], *pbuf;
395 398
396 pbuf = recv_buf;
397 do { 399 do {
398 num = max3110_read_multi(max, pbuf); 400 num = max3110_read_multi(max);
399 401
400 if (num) { 402 if (num) {
401 loop = 5; 403 loop = 5;
402 pbuf += num;
403 total += num;
404
405 if (total >= 504) {
406 receive_chars(max, recv_buf, total);
407 pbuf = recv_buf;
408 total = 0;
409 }
410 } 404 }
411 } while (--loop); 405 } while (--loop);
412
413 if (total)
414 receive_chars(max, recv_buf, total);
415} 406}
416 407
417static int max3110_main_thread(void *_max) 408static int max3110_main_thread(void *_max)
@@ -424,7 +415,8 @@ static int max3110_main_thread(void *_max)
424 pr_info(PR_FMT "start main thread\n"); 415 pr_info(PR_FMT "start main thread\n");
425 416
426 do { 417 do {
427 wait_event_interruptible(*wq, max->uart_flags || kthread_should_stop()); 418 wait_event_interruptible(*wq,
419 max->uart_flags || kthread_should_stop());
428 420
429 mutex_lock(&max->thread_mutex); 421 mutex_lock(&max->thread_mutex);
430 422
@@ -452,8 +444,9 @@ static irqreturn_t serial_m3110_irq(int irq, void *dev_id)
452 444
453 /* max3110's irq is a falling edge, not level triggered, 445 /* max3110's irq is a falling edge, not level triggered,
454 * so no need to disable the irq */ 446 * so no need to disable the irq */
447
455 if (!test_and_set_bit(BIT_IRQ_PENDING, &max->uart_flags)) 448 if (!test_and_set_bit(BIT_IRQ_PENDING, &max->uart_flags))
456 wake_up_process(max->main_thread); 449 wake_up(&max->wq);
457 450
458 return IRQ_HANDLED; 451 return IRQ_HANDLED;
459} 452}
diff --git a/drivers/tty/serial/mrst_max3110.h b/drivers/tty/serial/mrst_max3110.h
index c37ea48c825a..35af0739513b 100644
--- a/drivers/tty/serial/mrst_max3110.h
+++ b/drivers/tty/serial/mrst_max3110.h
@@ -7,6 +7,7 @@
7/* status bits for all 4 MAX3110 operate modes */ 7/* status bits for all 4 MAX3110 operate modes */
8#define MAX3110_READ_DATA_AVAILABLE (1 << 15) 8#define MAX3110_READ_DATA_AVAILABLE (1 << 15)
9#define MAX3110_WRITE_BUF_EMPTY (1 << 14) 9#define MAX3110_WRITE_BUF_EMPTY (1 << 14)
10#define MAX3110_BREAK (1 << 10)
10 11
11#define WC_TAG (3 << 14) 12#define WC_TAG (3 << 14)
12#define RC_TAG (1 << 14) 13#define RC_TAG (1 << 14)
diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
index e6ba83876508..29cbfd8c4e7c 100644
--- a/drivers/tty/serial/msm_serial.c
+++ b/drivers/tty/serial/msm_serial.c
@@ -804,8 +804,6 @@ static int __init msm_console_setup(struct console *co, char *options)
804 if (unlikely(!port->membase)) 804 if (unlikely(!port->membase))
805 return -ENXIO; 805 return -ENXIO;
806 806
807 port->cons = co;
808
809 msm_init_clock(port); 807 msm_init_clock(port);
810 808
811 if (options) 809 if (options)
diff --git a/drivers/tty/serial/msm_serial_hs.c b/drivers/tty/serial/msm_serial_hs.c
index 624701f8138a..60c6eb850265 100644
--- a/drivers/tty/serial/msm_serial_hs.c
+++ b/drivers/tty/serial/msm_serial_hs.c
@@ -30,6 +30,8 @@
30 30
31#include <linux/serial.h> 31#include <linux/serial.h>
32#include <linux/serial_core.h> 32#include <linux/serial_core.h>
33#include <linux/tty.h>
34#include <linux/tty_flip.h>
33#include <linux/slab.h> 35#include <linux/slab.h>
34#include <linux/init.h> 36#include <linux/init.h>
35#include <linux/interrupt.h> 37#include <linux/interrupt.h>
diff --git a/drivers/tty/serial/mux.c b/drivers/tty/serial/mux.c
index 9711e06a8374..06f6aefd5ba6 100644
--- a/drivers/tty/serial/mux.c
+++ b/drivers/tty/serial/mux.c
@@ -21,6 +21,8 @@
21#include <linux/ioport.h> 21#include <linux/ioport.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/serial.h> 23#include <linux/serial.h>
24#include <linux/tty.h>
25#include <linux/tty_flip.h>
24#include <linux/console.h> 26#include <linux/console.h>
25#include <linux/delay.h> /* for udelay */ 27#include <linux/delay.h> /* for udelay */
26#include <linux/device.h> 28#include <linux/device.h>
diff --git a/drivers/tty/serial/nwpserial.c b/drivers/tty/serial/nwpserial.c
index de173671e3d0..9beaff1cec24 100644
--- a/drivers/tty/serial/nwpserial.c
+++ b/drivers/tty/serial/nwpserial.c
@@ -15,6 +15,7 @@
15#include <linux/serial_reg.h> 15#include <linux/serial_reg.h>
16#include <linux/serial_core.h> 16#include <linux/serial_core.h>
17#include <linux/tty.h> 17#include <linux/tty.h>
18#include <linux/tty_flip.h>
18#include <linux/irqreturn.h> 19#include <linux/irqreturn.h>
19#include <linux/mutex.h> 20#include <linux/mutex.h>
20#include <linux/of_platform.h> 21#include <linux/of_platform.h>
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index b46218d679e2..21febef926aa 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -20,6 +20,8 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/serial_core.h> 22#include <linux/serial_core.h>
23#include <linux/tty.h>
24#include <linux/tty_flip.h>
23#include <linux/interrupt.h> 25#include <linux/interrupt.h>
24#include <linux/io.h> 26#include <linux/io.h>
25#include <linux/dmi.h> 27#include <linux/dmi.h>
diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c
index 531931c1b250..5c8e3bba6c84 100644
--- a/drivers/tty/serial/pxa.c
+++ b/drivers/tty/serial/pxa.c
@@ -100,6 +100,16 @@ static inline void receive_chars(struct uart_pxa_port *up, int *status)
100 int max_count = 256; 100 int max_count = 256;
101 101
102 do { 102 do {
103 /* work around Errata #20 according to
104 * Intel(R) PXA27x Processor Family
105 * Specification Update (May 2005)
106 *
107 * Step 2
108 * Disable the Reciever Time Out Interrupt via IER[RTOEI]
109 */
110 up->ier &= ~UART_IER_RTOIE;
111 serial_out(up, UART_IER, up->ier);
112
103 ch = serial_in(up, UART_RX); 113 ch = serial_in(up, UART_RX);
104 flag = TTY_NORMAL; 114 flag = TTY_NORMAL;
105 up->port.icount.rx++; 115 up->port.icount.rx++;
@@ -156,6 +166,16 @@ static inline void receive_chars(struct uart_pxa_port *up, int *status)
156 *status = serial_in(up, UART_LSR); 166 *status = serial_in(up, UART_LSR);
157 } while ((*status & UART_LSR_DR) && (max_count-- > 0)); 167 } while ((*status & UART_LSR_DR) && (max_count-- > 0));
158 tty_flip_buffer_push(tty); 168 tty_flip_buffer_push(tty);
169
170 /* work around Errata #20 according to
171 * Intel(R) PXA27x Processor Family
172 * Specification Update (May 2005)
173 *
174 * Step 6:
175 * No more data in FIFO: Re-enable RTO interrupt via IER[RTOIE]
176 */
177 up->ier |= UART_IER_RTOIE;
178 serial_out(up, UART_IER, up->ier);
159} 179}
160 180
161static void transmit_chars(struct uart_pxa_port *up) 181static void transmit_chars(struct uart_pxa_port *up)
diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index 6edafb5ace18..b31f1c3a2c4c 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -83,6 +83,16 @@ static int s3c24xx_serial_txempty_nofifo(struct uart_port *port)
83 return (rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE); 83 return (rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE);
84} 84}
85 85
86/*
87 * s3c64xx and later SoC's include the interrupt mask and status registers in
88 * the controller itself, unlike the s3c24xx SoC's which have these registers
89 * in the interrupt controller. Check if the port type is s3c64xx or higher.
90 */
91static int s3c24xx_serial_has_interrupt_mask(struct uart_port *port)
92{
93 return to_ourport(port)->info->type == PORT_S3C6400;
94}
95
86static void s3c24xx_serial_rx_enable(struct uart_port *port) 96static void s3c24xx_serial_rx_enable(struct uart_port *port)
87{ 97{
88 unsigned long flags; 98 unsigned long flags;
@@ -126,7 +136,11 @@ static void s3c24xx_serial_stop_tx(struct uart_port *port)
126 struct s3c24xx_uart_port *ourport = to_ourport(port); 136 struct s3c24xx_uart_port *ourport = to_ourport(port);
127 137
128 if (tx_enabled(port)) { 138 if (tx_enabled(port)) {
129 disable_irq_nosync(ourport->tx_irq); 139 if (s3c24xx_serial_has_interrupt_mask(port))
140 __set_bit(S3C64XX_UINTM_TXD,
141 portaddrl(port, S3C64XX_UINTM));
142 else
143 disable_irq_nosync(ourport->tx_irq);
130 tx_enabled(port) = 0; 144 tx_enabled(port) = 0;
131 if (port->flags & UPF_CONS_FLOW) 145 if (port->flags & UPF_CONS_FLOW)
132 s3c24xx_serial_rx_enable(port); 146 s3c24xx_serial_rx_enable(port);
@@ -141,19 +155,26 @@ static void s3c24xx_serial_start_tx(struct uart_port *port)
141 if (port->flags & UPF_CONS_FLOW) 155 if (port->flags & UPF_CONS_FLOW)
142 s3c24xx_serial_rx_disable(port); 156 s3c24xx_serial_rx_disable(port);
143 157
144 enable_irq(ourport->tx_irq); 158 if (s3c24xx_serial_has_interrupt_mask(port))
159 __clear_bit(S3C64XX_UINTM_TXD,
160 portaddrl(port, S3C64XX_UINTM));
161 else
162 enable_irq(ourport->tx_irq);
145 tx_enabled(port) = 1; 163 tx_enabled(port) = 1;
146 } 164 }
147} 165}
148 166
149
150static void s3c24xx_serial_stop_rx(struct uart_port *port) 167static void s3c24xx_serial_stop_rx(struct uart_port *port)
151{ 168{
152 struct s3c24xx_uart_port *ourport = to_ourport(port); 169 struct s3c24xx_uart_port *ourport = to_ourport(port);
153 170
154 if (rx_enabled(port)) { 171 if (rx_enabled(port)) {
155 dbg("s3c24xx_serial_stop_rx: port=%p\n", port); 172 dbg("s3c24xx_serial_stop_rx: port=%p\n", port);
156 disable_irq_nosync(ourport->rx_irq); 173 if (s3c24xx_serial_has_interrupt_mask(port))
174 __set_bit(S3C64XX_UINTM_RXD,
175 portaddrl(port, S3C64XX_UINTM));
176 else
177 disable_irq_nosync(ourport->rx_irq);
157 rx_enabled(port) = 0; 178 rx_enabled(port) = 0;
158 } 179 }
159} 180}
@@ -320,6 +341,28 @@ static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
320 return IRQ_HANDLED; 341 return IRQ_HANDLED;
321} 342}
322 343
344/* interrupt handler for s3c64xx and later SoC's.*/
345static irqreturn_t s3c64xx_serial_handle_irq(int irq, void *id)
346{
347 struct s3c24xx_uart_port *ourport = id;
348 struct uart_port *port = &ourport->port;
349 unsigned int pend = rd_regl(port, S3C64XX_UINTP);
350 unsigned long flags;
351 irqreturn_t ret = IRQ_HANDLED;
352
353 spin_lock_irqsave(&port->lock, flags);
354 if (pend & S3C64XX_UINTM_RXD_MSK) {
355 ret = s3c24xx_serial_rx_chars(irq, id);
356 wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_RXD_MSK);
357 }
358 if (pend & S3C64XX_UINTM_TXD_MSK) {
359 ret = s3c24xx_serial_tx_chars(irq, id);
360 wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_TXD_MSK);
361 }
362 spin_unlock_irqrestore(&port->lock, flags);
363 return ret;
364}
365
323static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port) 366static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
324{ 367{
325 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); 368 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
@@ -377,18 +420,25 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
377 struct s3c24xx_uart_port *ourport = to_ourport(port); 420 struct s3c24xx_uart_port *ourport = to_ourport(port);
378 421
379 if (ourport->tx_claimed) { 422 if (ourport->tx_claimed) {
380 free_irq(ourport->tx_irq, ourport); 423 if (!s3c24xx_serial_has_interrupt_mask(port))
424 free_irq(ourport->tx_irq, ourport);
381 tx_enabled(port) = 0; 425 tx_enabled(port) = 0;
382 ourport->tx_claimed = 0; 426 ourport->tx_claimed = 0;
383 } 427 }
384 428
385 if (ourport->rx_claimed) { 429 if (ourport->rx_claimed) {
386 free_irq(ourport->rx_irq, ourport); 430 if (!s3c24xx_serial_has_interrupt_mask(port))
431 free_irq(ourport->rx_irq, ourport);
387 ourport->rx_claimed = 0; 432 ourport->rx_claimed = 0;
388 rx_enabled(port) = 0; 433 rx_enabled(port) = 0;
389 } 434 }
390}
391 435
436 /* Clear pending interrupts and mask all interrupts */
437 if (s3c24xx_serial_has_interrupt_mask(port)) {
438 wr_regl(port, S3C64XX_UINTP, 0xf);
439 wr_regl(port, S3C64XX_UINTM, 0xf);
440 }
441}
392 442
393static int s3c24xx_serial_startup(struct uart_port *port) 443static int s3c24xx_serial_startup(struct uart_port *port)
394{ 444{
@@ -436,6 +486,33 @@ static int s3c24xx_serial_startup(struct uart_port *port)
436 return ret; 486 return ret;
437} 487}
438 488
489static int s3c64xx_serial_startup(struct uart_port *port)
490{
491 struct s3c24xx_uart_port *ourport = to_ourport(port);
492 int ret;
493
494 dbg("s3c64xx_serial_startup: port=%p (%08lx,%p)\n",
495 port->mapbase, port->membase);
496
497 ret = request_irq(port->irq, s3c64xx_serial_handle_irq, IRQF_SHARED,
498 s3c24xx_serial_portname(port), ourport);
499 if (ret) {
500 printk(KERN_ERR "cannot get irq %d\n", port->irq);
501 return ret;
502 }
503
504 /* For compatibility with s3c24xx Soc's */
505 rx_enabled(port) = 1;
506 ourport->rx_claimed = 1;
507 tx_enabled(port) = 0;
508 ourport->tx_claimed = 1;
509
510 /* Enable Rx Interrupt */
511 __clear_bit(S3C64XX_UINTM_RXD, portaddrl(port, S3C64XX_UINTM));
512 dbg("s3c64xx_serial_startup ok\n");
513 return ret;
514}
515
439/* power power management control */ 516/* power power management control */
440 517
441static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level, 518static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
@@ -879,7 +956,6 @@ static struct uart_ops s3c24xx_serial_ops = {
879 .verify_port = s3c24xx_serial_verify_port, 956 .verify_port = s3c24xx_serial_verify_port,
880}; 957};
881 958
882
883static struct uart_driver s3c24xx_uart_drv = { 959static struct uart_driver s3c24xx_uart_drv = {
884 .owner = THIS_MODULE, 960 .owner = THIS_MODULE,
885 .driver_name = "s3c2410_serial", 961 .driver_name = "s3c2410_serial",
@@ -895,7 +971,6 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS
895 .port = { 971 .port = {
896 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock), 972 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock),
897 .iotype = UPIO_MEM, 973 .iotype = UPIO_MEM,
898 .irq = IRQ_S3CUART_RX0,
899 .uartclk = 0, 974 .uartclk = 0,
900 .fifosize = 16, 975 .fifosize = 16,
901 .ops = &s3c24xx_serial_ops, 976 .ops = &s3c24xx_serial_ops,
@@ -907,7 +982,6 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS
907 .port = { 982 .port = {
908 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock), 983 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock),
909 .iotype = UPIO_MEM, 984 .iotype = UPIO_MEM,
910 .irq = IRQ_S3CUART_RX1,
911 .uartclk = 0, 985 .uartclk = 0,
912 .fifosize = 16, 986 .fifosize = 16,
913 .ops = &s3c24xx_serial_ops, 987 .ops = &s3c24xx_serial_ops,
@@ -921,7 +995,6 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS
921 .port = { 995 .port = {
922 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock), 996 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock),
923 .iotype = UPIO_MEM, 997 .iotype = UPIO_MEM,
924 .irq = IRQ_S3CUART_RX2,
925 .uartclk = 0, 998 .uartclk = 0,
926 .fifosize = 16, 999 .fifosize = 16,
927 .ops = &s3c24xx_serial_ops, 1000 .ops = &s3c24xx_serial_ops,
@@ -935,7 +1008,6 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS
935 .port = { 1008 .port = {
936 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[3].port.lock), 1009 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[3].port.lock),
937 .iotype = UPIO_MEM, 1010 .iotype = UPIO_MEM,
938 .irq = IRQ_S3CUART_RX3,
939 .uartclk = 0, 1011 .uartclk = 0,
940 .fifosize = 16, 1012 .fifosize = 16,
941 .ops = &s3c24xx_serial_ops, 1013 .ops = &s3c24xx_serial_ops,
@@ -1077,6 +1149,10 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1077 port->dev = &platdev->dev; 1149 port->dev = &platdev->dev;
1078 ourport->info = info; 1150 ourport->info = info;
1079 1151
1152 /* Startup sequence is different for s3c64xx and higher SoC's */
1153 if (s3c24xx_serial_has_interrupt_mask(port))
1154 s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
1155
1080 /* copy the info in from provided structure */ 1156 /* copy the info in from provided structure */
1081 ourport->port.fifosize = info->fifosize; 1157 ourport->port.fifosize = info->fifosize;
1082 1158
@@ -1116,6 +1192,13 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1116 1192
1117 ourport->clk = clk_get(&platdev->dev, "uart"); 1193 ourport->clk = clk_get(&platdev->dev, "uart");
1118 1194
1195 /* Keep all interrupts masked and cleared */
1196 if (s3c24xx_serial_has_interrupt_mask(port)) {
1197 wr_regl(port, S3C64XX_UINTM, 0xf);
1198 wr_regl(port, S3C64XX_UINTP, 0xf);
1199 wr_regl(port, S3C64XX_UINTSP, 0xf);
1200 }
1201
1119 dbg("port: map=%08x, mem=%08x, irq=%d (%d,%d), clock=%ld\n", 1202 dbg("port: map=%08x, mem=%08x, irq=%d (%d,%d), clock=%ld\n",
1120 port->mapbase, port->membase, port->irq, 1203 port->mapbase, port->membase, port->irq,
1121 ourport->rx_irq, ourport->tx_irq, port->uartclk); 1204 ourport->rx_irq, ourport->tx_irq, port->uartclk);
diff --git a/drivers/tty/serial/samsung.h b/drivers/tty/serial/samsung.h
index a69d9a54be94..8e87b788e5c6 100644
--- a/drivers/tty/serial/samsung.h
+++ b/drivers/tty/serial/samsung.h
@@ -61,6 +61,7 @@ struct s3c24xx_uart_port {
61/* register access controls */ 61/* register access controls */
62 62
63#define portaddr(port, reg) ((port)->membase + (reg)) 63#define portaddr(port, reg) ((port)->membase + (reg))
64#define portaddrl(port, reg) ((unsigned long *)((port)->membase + (reg)))
64 65
65#define rd_regb(port, reg) (__raw_readb(portaddr(port, reg))) 66#define rd_regb(port, reg) (__raw_readb(portaddr(port, reg)))
66#define rd_regl(port, reg) (__raw_readl(portaddr(port, reg))) 67#define rd_regl(port, reg) (__raw_readl(portaddr(port, reg)))
diff --git a/drivers/tty/serial/sb1250-duart.c b/drivers/tty/serial/sb1250-duart.c
index 6bc2e3f876f4..0be8a2f00d0b 100644
--- a/drivers/tty/serial/sb1250-duart.c
+++ b/drivers/tty/serial/sb1250-duart.c
@@ -37,6 +37,7 @@
37#include <linux/spinlock.h> 37#include <linux/spinlock.h>
38#include <linux/sysrq.h> 38#include <linux/sysrq.h>
39#include <linux/tty.h> 39#include <linux/tty.h>
40#include <linux/tty_flip.h>
40#include <linux/types.h> 41#include <linux/types.h>
41 42
42#include <linux/atomic.h> 43#include <linux/atomic.h>
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index a3efbea5dbba..0406d7ff505e 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -57,7 +57,7 @@ static struct lock_class_key port_lock_key;
57 57
58static void uart_change_speed(struct tty_struct *tty, struct uart_state *state, 58static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
59 struct ktermios *old_termios); 59 struct ktermios *old_termios);
60static void __uart_wait_until_sent(struct uart_port *port, int timeout); 60static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
61static void uart_change_pm(struct uart_state *state, int pm_state); 61static void uart_change_pm(struct uart_state *state, int pm_state);
62 62
63/* 63/*
@@ -72,7 +72,7 @@ void uart_write_wakeup(struct uart_port *port)
72 * closed. No cookie for you. 72 * closed. No cookie for you.
73 */ 73 */
74 BUG_ON(!state); 74 BUG_ON(!state);
75 tasklet_schedule(&state->tlet); 75 tty_wakeup(state->port.tty);
76} 76}
77 77
78static void uart_stop(struct tty_struct *tty) 78static void uart_stop(struct tty_struct *tty)
@@ -107,12 +107,6 @@ static void uart_start(struct tty_struct *tty)
107 spin_unlock_irqrestore(&port->lock, flags); 107 spin_unlock_irqrestore(&port->lock, flags);
108} 108}
109 109
110static void uart_tasklet_action(unsigned long data)
111{
112 struct uart_state *state = (struct uart_state *)data;
113 tty_wakeup(state->port.tty);
114}
115
116static inline void 110static inline void
117uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear) 111uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
118{ 112{
@@ -255,9 +249,11 @@ static void uart_shutdown(struct tty_struct *tty, struct uart_state *state)
255 } 249 }
256 250
257 /* 251 /*
258 * kill off our tasklet 252 * It's possible for shutdown to be called after suspend if we get
253 * a DCD drop (hangup) at just the right time. Clear suspended bit so
254 * we don't try to resume a port that has been shutdown.
259 */ 255 */
260 tasklet_kill(&state->tlet); 256 clear_bit(ASYNCB_SUSPENDED, &port->flags);
261 257
262 /* 258 /*
263 * Free the transmit buffer page. 259 * Free the transmit buffer page.
@@ -1261,8 +1257,6 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1261 struct uart_port *uport; 1257 struct uart_port *uport;
1262 unsigned long flags; 1258 unsigned long flags;
1263 1259
1264 BUG_ON(!tty_locked());
1265
1266 if (!state) 1260 if (!state)
1267 return; 1261 return;
1268 1262
@@ -1271,12 +1265,11 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1271 1265
1272 pr_debug("uart_close(%d) called\n", uport->line); 1266 pr_debug("uart_close(%d) called\n", uport->line);
1273 1267
1274 mutex_lock(&port->mutex);
1275 spin_lock_irqsave(&port->lock, flags); 1268 spin_lock_irqsave(&port->lock, flags);
1276 1269
1277 if (tty_hung_up_p(filp)) { 1270 if (tty_hung_up_p(filp)) {
1278 spin_unlock_irqrestore(&port->lock, flags); 1271 spin_unlock_irqrestore(&port->lock, flags);
1279 goto done; 1272 return;
1280 } 1273 }
1281 1274
1282 if ((tty->count == 1) && (port->count != 1)) { 1275 if ((tty->count == 1) && (port->count != 1)) {
@@ -1298,7 +1291,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1298 } 1291 }
1299 if (port->count) { 1292 if (port->count) {
1300 spin_unlock_irqrestore(&port->lock, flags); 1293 spin_unlock_irqrestore(&port->lock, flags);
1301 goto done; 1294 return;
1302 } 1295 }
1303 1296
1304 /* 1297 /*
@@ -1306,19 +1299,13 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1306 * the line discipline to only process XON/XOFF characters by 1299 * the line discipline to only process XON/XOFF characters by
1307 * setting tty->closing. 1300 * setting tty->closing.
1308 */ 1301 */
1302 set_bit(ASYNCB_CLOSING, &port->flags);
1309 tty->closing = 1; 1303 tty->closing = 1;
1310 spin_unlock_irqrestore(&port->lock, flags); 1304 spin_unlock_irqrestore(&port->lock, flags);
1311 1305
1312 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) { 1306 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1313 /* 1307 tty_wait_until_sent_from_close(tty,
1314 * hack: open-coded tty_wait_until_sent to avoid 1308 msecs_to_jiffies(port->closing_wait));
1315 * recursive tty_lock
1316 */
1317 long timeout = msecs_to_jiffies(port->closing_wait);
1318 if (wait_event_interruptible_timeout(tty->write_wait,
1319 !tty_chars_in_buffer(tty), timeout) >= 0)
1320 __uart_wait_until_sent(uport, timeout);
1321 }
1322 1309
1323 /* 1310 /*
1324 * At this point, we stop accepting input. To do this, we 1311 * At this point, we stop accepting input. To do this, we
@@ -1334,9 +1321,10 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1334 * has completely drained; this is especially 1321 * has completely drained; this is especially
1335 * important if there is a transmit FIFO! 1322 * important if there is a transmit FIFO!
1336 */ 1323 */
1337 __uart_wait_until_sent(uport, uport->timeout); 1324 uart_wait_until_sent(tty, uport->timeout);
1338 } 1325 }
1339 1326
1327 mutex_lock(&port->mutex);
1340 uart_shutdown(tty, state); 1328 uart_shutdown(tty, state);
1341 uart_flush_buffer(tty); 1329 uart_flush_buffer(tty);
1342 1330
@@ -1361,15 +1349,18 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1361 * Wake up anyone trying to open this port. 1349 * Wake up anyone trying to open this port.
1362 */ 1350 */
1363 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags); 1351 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
1352 clear_bit(ASYNCB_CLOSING, &port->flags);
1364 spin_unlock_irqrestore(&port->lock, flags); 1353 spin_unlock_irqrestore(&port->lock, flags);
1365 wake_up_interruptible(&port->open_wait); 1354 wake_up_interruptible(&port->open_wait);
1355 wake_up_interruptible(&port->close_wait);
1366 1356
1367done:
1368 mutex_unlock(&port->mutex); 1357 mutex_unlock(&port->mutex);
1369} 1358}
1370 1359
1371static void __uart_wait_until_sent(struct uart_port *port, int timeout) 1360static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1372{ 1361{
1362 struct uart_state *state = tty->driver_data;
1363 struct uart_port *port = state->uart_port;
1373 unsigned long char_time, expire; 1364 unsigned long char_time, expire;
1374 1365
1375 if (port->type == PORT_UNKNOWN || port->fifosize == 0) 1366 if (port->type == PORT_UNKNOWN || port->fifosize == 0)
@@ -1421,16 +1412,6 @@ static void __uart_wait_until_sent(struct uart_port *port, int timeout)
1421 } 1412 }
1422} 1413}
1423 1414
1424static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1425{
1426 struct uart_state *state = tty->driver_data;
1427 struct uart_port *port = state->uart_port;
1428
1429 tty_lock();
1430 __uart_wait_until_sent(port, timeout);
1431 tty_unlock();
1432}
1433
1434/* 1415/*
1435 * This is called with the BKL held in 1416 * This is called with the BKL held in
1436 * linux/drivers/char/tty_io.c:do_tty_hangup() 1417 * linux/drivers/char/tty_io.c:do_tty_hangup()
@@ -1443,7 +1424,6 @@ static void uart_hangup(struct tty_struct *tty)
1443 struct tty_port *port = &state->port; 1424 struct tty_port *port = &state->port;
1444 unsigned long flags; 1425 unsigned long flags;
1445 1426
1446 BUG_ON(!tty_locked());
1447 pr_debug("uart_hangup(%d)\n", state->uart_port->line); 1427 pr_debug("uart_hangup(%d)\n", state->uart_port->line);
1448 1428
1449 mutex_lock(&port->mutex); 1429 mutex_lock(&port->mutex);
@@ -1530,7 +1510,6 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1530 struct tty_port *port; 1510 struct tty_port *port;
1531 int retval, line = tty->index; 1511 int retval, line = tty->index;
1532 1512
1533 BUG_ON(!tty_locked());
1534 pr_debug("uart_open(%d) called\n", line); 1513 pr_debug("uart_open(%d) called\n", line);
1535 1514
1536 /* 1515 /*
@@ -2008,6 +1987,8 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
2008 if (port->tty && port->tty->termios && termios.c_cflag == 0) 1987 if (port->tty && port->tty->termios && termios.c_cflag == 0)
2009 termios = *(port->tty->termios); 1988 termios = *(port->tty->termios);
2010 1989
1990 if (console_suspend_enabled)
1991 uart_change_pm(state, 0);
2011 uport->ops->set_termios(uport, &termios, NULL); 1992 uport->ops->set_termios(uport, &termios, NULL);
2012 if (console_suspend_enabled) 1993 if (console_suspend_enabled)
2013 console_start(uport->cons); 1994 console_start(uport->cons);
@@ -2068,8 +2049,6 @@ uart_report_port(struct uart_driver *drv, struct uart_port *port)
2068 case UPIO_MEM32: 2049 case UPIO_MEM32:
2069 case UPIO_AU: 2050 case UPIO_AU:
2070 case UPIO_TSI: 2051 case UPIO_TSI:
2071 case UPIO_DWAPB:
2072 case UPIO_DWAPB32:
2073 snprintf(address, sizeof(address), 2052 snprintf(address, sizeof(address),
2074 "MMIO 0x%llx", (unsigned long long)port->mapbase); 2053 "MMIO 0x%llx", (unsigned long long)port->mapbase);
2075 break; 2054 break;
@@ -2298,8 +2277,6 @@ int uart_register_driver(struct uart_driver *drv)
2298 port->ops = &uart_port_ops; 2277 port->ops = &uart_port_ops;
2299 port->close_delay = 500; /* .5 seconds */ 2278 port->close_delay = 500; /* .5 seconds */
2300 port->closing_wait = 30000; /* 30 seconds */ 2279 port->closing_wait = 30000; /* 30 seconds */
2301 tasklet_init(&state->tlet, uart_tasklet_action,
2302 (unsigned long)state);
2303 } 2280 }
2304 2281
2305 retval = tty_register_driver(normal); 2282 retval = tty_register_driver(normal);
@@ -2460,11 +2437,6 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport)
2460 */ 2437 */
2461 uport->type = PORT_UNKNOWN; 2438 uport->type = PORT_UNKNOWN;
2462 2439
2463 /*
2464 * Kill the tasklet, and free resources.
2465 */
2466 tasklet_kill(&state->tlet);
2467
2468 state->uart_port = NULL; 2440 state->uart_port = NULL;
2469 mutex_unlock(&port_mutex); 2441 mutex_unlock(&port_mutex);
2470 2442
@@ -2489,8 +2461,6 @@ int uart_match_port(struct uart_port *port1, struct uart_port *port2)
2489 case UPIO_MEM32: 2461 case UPIO_MEM32:
2490 case UPIO_AU: 2462 case UPIO_AU:
2491 case UPIO_TSI: 2463 case UPIO_TSI:
2492 case UPIO_DWAPB:
2493 case UPIO_DWAPB32:
2494 return (port1->mapbase == port2->mapbase); 2464 return (port1->mapbase == port2->mapbase);
2495 } 2465 }
2496 return 0; 2466 return 0;
diff --git a/drivers/tty/serial/serial_ks8695.c b/drivers/tty/serial/serial_ks8695.c
index 2430319f2f52..7c13639c597e 100644
--- a/drivers/tty/serial/serial_ks8695.c
+++ b/drivers/tty/serial/serial_ks8695.c
@@ -13,6 +13,7 @@
13 */ 13 */
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/tty.h> 15#include <linux/tty.h>
16#include <linux/tty_flip.h>
16#include <linux/ioport.h> 17#include <linux/ioport.h>
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/serial.h> 19#include <linux/serial.h>
@@ -336,19 +337,19 @@ static int ks8695uart_startup(struct uart_port *port)
336 /* 337 /*
337 * Allocate the IRQ 338 * Allocate the IRQ
338 */ 339 */
339 retval = request_irq(KS8695_IRQ_UART_TX, ks8695uart_tx_chars, IRQF_DISABLED, "UART TX", port); 340 retval = request_irq(KS8695_IRQ_UART_TX, ks8695uart_tx_chars, 0, "UART TX", port);
340 if (retval) 341 if (retval)
341 goto err_tx; 342 goto err_tx;
342 343
343 retval = request_irq(KS8695_IRQ_UART_RX, ks8695uart_rx_chars, IRQF_DISABLED, "UART RX", port); 344 retval = request_irq(KS8695_IRQ_UART_RX, ks8695uart_rx_chars, 0, "UART RX", port);
344 if (retval) 345 if (retval)
345 goto err_rx; 346 goto err_rx;
346 347
347 retval = request_irq(KS8695_IRQ_UART_LINE_STATUS, ks8695uart_rx_chars, IRQF_DISABLED, "UART LineStatus", port); 348 retval = request_irq(KS8695_IRQ_UART_LINE_STATUS, ks8695uart_rx_chars, 0, "UART LineStatus", port);
348 if (retval) 349 if (retval)
349 goto err_ls; 350 goto err_ls;
350 351
351 retval = request_irq(KS8695_IRQ_UART_MODEM_STATUS, ks8695uart_modem_status, IRQF_DISABLED, "UART ModemStatus", port); 352 retval = request_irq(KS8695_IRQ_UART_MODEM_STATUS, ks8695uart_modem_status, 0, "UART ModemStatus", port);
352 if (retval) 353 if (retval)
353 goto err_ms; 354 goto err_ms;
354 355
diff --git a/drivers/tty/serial/serial_txx9.c b/drivers/tty/serial/serial_txx9.c
index 8e3fc1944e6d..34bd345da775 100644
--- a/drivers/tty/serial/serial_txx9.c
+++ b/drivers/tty/serial/serial_txx9.c
@@ -28,6 +28,8 @@
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/serial_core.h> 29#include <linux/serial_core.h>
30#include <linux/serial.h> 30#include <linux/serial.h>
31#include <linux/tty.h>
32#include <linux/tty_flip.h>
31 33
32#include <asm/io.h> 34#include <asm/io.h>
33 35
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 5ea6ec3442e6..9871c57b348e 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1976,7 +1976,7 @@ static int __devinit sci_init_single(struct platform_device *dev,
1976 * For the muxed case there's nothing more to do. 1976 * For the muxed case there's nothing more to do.
1977 */ 1977 */
1978 port->irq = p->irqs[SCIx_RXI_IRQ]; 1978 port->irq = p->irqs[SCIx_RXI_IRQ];
1979 port->irqflags = IRQF_DISABLED; 1979 port->irqflags = 0;
1980 1980
1981 port->serial_in = sci_serial_in; 1981 port->serial_in = sci_serial_in;
1982 port->serial_out = sci_serial_out; 1982 port->serial_out = sci_serial_out;
diff --git a/drivers/tty/serial/sn_console.c b/drivers/tty/serial/sn_console.c
index 377ae74e7154..238c7df73ef5 100644
--- a/drivers/tty/serial/sn_console.c
+++ b/drivers/tty/serial/sn_console.c
@@ -39,6 +39,7 @@
39 39
40#include <linux/interrupt.h> 40#include <linux/interrupt.h>
41#include <linux/tty.h> 41#include <linux/tty.h>
42#include <linux/tty_flip.h>
42#include <linux/serial.h> 43#include <linux/serial.h>
43#include <linux/console.h> 44#include <linux/console.h>
44#include <linux/module.h> 45#include <linux/module.h>
@@ -737,7 +738,7 @@ static void __init sn_sal_switch_to_interrupts(struct sn_cons_port *port)
737 DPRINTF("sn_console: switching to interrupt driven console\n"); 738 DPRINTF("sn_console: switching to interrupt driven console\n");
738 739
739 if (request_irq(SGI_UART_VECTOR, sn_sal_interrupt, 740 if (request_irq(SGI_UART_VECTOR, sn_sal_interrupt,
740 IRQF_DISABLED | IRQF_SHARED, 741 IRQF_SHARED,
741 "SAL console driver", port) >= 0) { 742 "SAL console driver", port) >= 0) {
742 spin_lock_irqsave(&port->sc_port.lock, flags); 743 spin_lock_irqsave(&port->sc_port.lock, flags);
743 port->sc_port.irq = SGI_UART_VECTOR; 744 port->sc_port.irq = SGI_UART_VECTOR;
diff --git a/drivers/tty/serial/timbuart.c b/drivers/tty/serial/timbuart.c
index 1f36b7eb7351..a4b63bfeaa2f 100644
--- a/drivers/tty/serial/timbuart.c
+++ b/drivers/tty/serial/timbuart.c
@@ -23,6 +23,8 @@
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/serial_core.h> 25#include <linux/serial_core.h>
26#include <linux/tty.h>
27#include <linux/tty_flip.h>
26#include <linux/kernel.h> 28#include <linux/kernel.h>
27#include <linux/platform_device.h> 29#include <linux/platform_device.h>
28#include <linux/ioport.h> 30#include <linux/ioport.h>
diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index 8af1ed83a4c0..b908615ccaaf 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -15,6 +15,7 @@
15#include <linux/serial.h> 15#include <linux/serial.h>
16#include <linux/serial_core.h> 16#include <linux/serial_core.h>
17#include <linux/tty.h> 17#include <linux/tty.h>
18#include <linux/tty_flip.h>
18#include <linux/delay.h> 19#include <linux/delay.h>
19#include <linux/interrupt.h> 20#include <linux/interrupt.h>
20#include <linux/init.h> 21#include <linux/init.h>
diff --git a/drivers/tty/serial/ucc_uart.c b/drivers/tty/serial/ucc_uart.c
index 9af9f0879a24..cea8918b8233 100644
--- a/drivers/tty/serial/ucc_uart.c
+++ b/drivers/tty/serial/ucc_uart.c
@@ -20,8 +20,10 @@
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/serial.h> 22#include <linux/serial.h>
23#include <linux/slab.h>
24#include <linux/serial_core.h> 23#include <linux/serial_core.h>
24#include <linux/slab.h>
25#include <linux/tty.h>
26#include <linux/tty_flip.h>
25#include <linux/io.h> 27#include <linux/io.h>
26#include <linux/of_platform.h> 28#include <linux/of_platform.h>
27#include <linux/dma-mapping.h> 29#include <linux/dma-mapping.h>
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index 19cc1e8149dd..8c03b127fd03 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -12,9 +12,11 @@
12 */ 12 */
13 13
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/serial.h>
15#include <linux/serial_core.h> 16#include <linux/serial_core.h>
17#include <linux/tty.h>
18#include <linux/tty_flip.h>
16#include <linux/console.h> 19#include <linux/console.h>
17#include <linux/serial.h>
18#include <linux/irq.h> 20#include <linux/irq.h>
19#include <linux/io.h> 21#include <linux/io.h>
20#include <linux/of.h> 22#include <linux/of.h>
diff --git a/drivers/tty/serial/zs.c b/drivers/tty/serial/zs.c
index 0aebd7121b56..b7455b526080 100644
--- a/drivers/tty/serial/zs.c
+++ b/drivers/tty/serial/zs.c
@@ -63,6 +63,7 @@
63#include <linux/spinlock.h> 63#include <linux/spinlock.h>
64#include <linux/sysrq.h> 64#include <linux/sysrq.h>
65#include <linux/tty.h> 65#include <linux/tty.h>
66#include <linux/tty_flip.h>
66#include <linux/types.h> 67#include <linux/types.h>
67 68
68#include <linux/atomic.h> 69#include <linux/atomic.h>
diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
index 272e417a9b0d..e67fb20490d2 100644
--- a/drivers/tty/synclink.c
+++ b/drivers/tty/synclink.c
@@ -2124,7 +2124,6 @@ static int mgsl_write(struct tty_struct * tty,
2124 if ( info->params.mode == MGSL_MODE_HDLC || 2124 if ( info->params.mode == MGSL_MODE_HDLC ||
2125 info->params.mode == MGSL_MODE_RAW ) { 2125 info->params.mode == MGSL_MODE_RAW ) {
2126 /* operating in synchronous (frame oriented) mode */ 2126 /* operating in synchronous (frame oriented) mode */
2127 /* operating in synchronous (frame oriented) mode */
2128 if (info->tx_active) { 2127 if (info->tx_active) {
2129 2128
2130 if ( info->params.mode == MGSL_MODE_HDLC ) { 2129 if ( info->params.mode == MGSL_MODE_HDLC ) {
diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
index c77831c7675a..0f6b796c95c5 100644
--- a/drivers/tty/synclinkmp.c
+++ b/drivers/tty/synclinkmp.c
@@ -4950,7 +4950,7 @@ CheckAgain:
4950 4950
4951 if ( debug_level >= DEBUG_LEVEL_DATA ) 4951 if ( debug_level >= DEBUG_LEVEL_DATA )
4952 trace_block(info,info->rx_buf_list_ex[StartIndex].virt_addr, 4952 trace_block(info,info->rx_buf_list_ex[StartIndex].virt_addr,
4953 min_t(int, framesize,SCABUFSIZE),0); 4953 min_t(unsigned int, framesize, SCABUFSIZE), 0);
4954 4954
4955 if (framesize) { 4955 if (framesize) {
4956 if (framesize > info->max_frame_size) 4956 if (framesize > info->max_frame_size)
@@ -5015,14 +5015,14 @@ static void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int co
5015 SCADESC_EX *desc_ex; 5015 SCADESC_EX *desc_ex;
5016 5016
5017 if ( debug_level >= DEBUG_LEVEL_DATA ) 5017 if ( debug_level >= DEBUG_LEVEL_DATA )
5018 trace_block(info,buf, min_t(int, count,SCABUFSIZE), 1); 5018 trace_block(info, buf, min_t(unsigned int, count, SCABUFSIZE), 1);
5019 5019
5020 /* Copy source buffer to one or more DMA buffers, starting with 5020 /* Copy source buffer to one or more DMA buffers, starting with
5021 * the first transmit dma buffer. 5021 * the first transmit dma buffer.
5022 */ 5022 */
5023 for(i=0;;) 5023 for(i=0;;)
5024 { 5024 {
5025 copy_count = min_t(unsigned short,count,SCABUFSIZE); 5025 copy_count = min_t(unsigned int, count, SCABUFSIZE);
5026 5026
5027 desc = &info->tx_buf_list[i]; 5027 desc = &info->tx_buf_list[i];
5028 desc_ex = &info->tx_buf_list_ex[i]; 5028 desc_ex = &info->tx_buf_list_ex[i];
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 4f1fc81112e6..05085beb83db 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -194,8 +194,7 @@ static inline struct tty_struct *file_tty(struct file *file)
194 return ((struct tty_file_private *)file->private_data)->tty; 194 return ((struct tty_file_private *)file->private_data)->tty;
195} 195}
196 196
197/* Associate a new file with the tty structure */ 197int tty_alloc_file(struct file *file)
198int tty_add_file(struct tty_struct *tty, struct file *file)
199{ 198{
200 struct tty_file_private *priv; 199 struct tty_file_private *priv;
201 200
@@ -203,15 +202,36 @@ int tty_add_file(struct tty_struct *tty, struct file *file)
203 if (!priv) 202 if (!priv)
204 return -ENOMEM; 203 return -ENOMEM;
205 204
205 file->private_data = priv;
206
207 return 0;
208}
209
210/* Associate a new file with the tty structure */
211void tty_add_file(struct tty_struct *tty, struct file *file)
212{
213 struct tty_file_private *priv = file->private_data;
214
206 priv->tty = tty; 215 priv->tty = tty;
207 priv->file = file; 216 priv->file = file;
208 file->private_data = priv;
209 217
210 spin_lock(&tty_files_lock); 218 spin_lock(&tty_files_lock);
211 list_add(&priv->list, &tty->tty_files); 219 list_add(&priv->list, &tty->tty_files);
212 spin_unlock(&tty_files_lock); 220 spin_unlock(&tty_files_lock);
221}
213 222
214 return 0; 223/**
224 * tty_free_file - free file->private_data
225 *
226 * This shall be used only for fail path handling when tty_add_file was not
227 * called yet.
228 */
229void tty_free_file(struct file *file)
230{
231 struct tty_file_private *priv = file->private_data;
232
233 file->private_data = NULL;
234 kfree(priv);
215} 235}
216 236
217/* Delete file from its tty */ 237/* Delete file from its tty */
@@ -222,8 +242,7 @@ void tty_del_file(struct file *file)
222 spin_lock(&tty_files_lock); 242 spin_lock(&tty_files_lock);
223 list_del(&priv->list); 243 list_del(&priv->list);
224 spin_unlock(&tty_files_lock); 244 spin_unlock(&tty_files_lock);
225 file->private_data = NULL; 245 tty_free_file(file);
226 kfree(priv);
227} 246}
228 247
229 248
@@ -1811,6 +1830,10 @@ static int tty_open(struct inode *inode, struct file *filp)
1811 nonseekable_open(inode, filp); 1830 nonseekable_open(inode, filp);
1812 1831
1813retry_open: 1832retry_open:
1833 retval = tty_alloc_file(filp);
1834 if (retval)
1835 return -ENOMEM;
1836
1814 noctty = filp->f_flags & O_NOCTTY; 1837 noctty = filp->f_flags & O_NOCTTY;
1815 index = -1; 1838 index = -1;
1816 retval = 0; 1839 retval = 0;
@@ -1823,6 +1846,7 @@ retry_open:
1823 if (!tty) { 1846 if (!tty) {
1824 tty_unlock(); 1847 tty_unlock();
1825 mutex_unlock(&tty_mutex); 1848 mutex_unlock(&tty_mutex);
1849 tty_free_file(filp);
1826 return -ENXIO; 1850 return -ENXIO;
1827 } 1851 }
1828 driver = tty_driver_kref_get(tty->driver); 1852 driver = tty_driver_kref_get(tty->driver);
@@ -1855,6 +1879,7 @@ retry_open:
1855 } 1879 }
1856 tty_unlock(); 1880 tty_unlock();
1857 mutex_unlock(&tty_mutex); 1881 mutex_unlock(&tty_mutex);
1882 tty_free_file(filp);
1858 return -ENODEV; 1883 return -ENODEV;
1859 } 1884 }
1860 1885
@@ -1862,6 +1887,7 @@ retry_open:
1862 if (!driver) { 1887 if (!driver) {
1863 tty_unlock(); 1888 tty_unlock();
1864 mutex_unlock(&tty_mutex); 1889 mutex_unlock(&tty_mutex);
1890 tty_free_file(filp);
1865 return -ENODEV; 1891 return -ENODEV;
1866 } 1892 }
1867got_driver: 1893got_driver:
@@ -1872,6 +1898,8 @@ got_driver:
1872 if (IS_ERR(tty)) { 1898 if (IS_ERR(tty)) {
1873 tty_unlock(); 1899 tty_unlock();
1874 mutex_unlock(&tty_mutex); 1900 mutex_unlock(&tty_mutex);
1901 tty_driver_kref_put(driver);
1902 tty_free_file(filp);
1875 return PTR_ERR(tty); 1903 return PTR_ERR(tty);
1876 } 1904 }
1877 } 1905 }
@@ -1887,15 +1915,11 @@ got_driver:
1887 tty_driver_kref_put(driver); 1915 tty_driver_kref_put(driver);
1888 if (IS_ERR(tty)) { 1916 if (IS_ERR(tty)) {
1889 tty_unlock(); 1917 tty_unlock();
1918 tty_free_file(filp);
1890 return PTR_ERR(tty); 1919 return PTR_ERR(tty);
1891 } 1920 }
1892 1921
1893 retval = tty_add_file(tty, filp); 1922 tty_add_file(tty, filp);
1894 if (retval) {
1895 tty_unlock();
1896 tty_release(inode, filp);
1897 return retval;
1898 }
1899 1923
1900 check_tty_count(tty, "tty_open"); 1924 check_tty_count(tty, "tty_open");
1901 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1925 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
@@ -2716,6 +2740,8 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
2716 ld = tty_ldisc_ref_wait(tty); 2740 ld = tty_ldisc_ref_wait(tty);
2717 if (ld->ops->compat_ioctl) 2741 if (ld->ops->compat_ioctl)
2718 retval = ld->ops->compat_ioctl(tty, file, cmd, arg); 2742 retval = ld->ops->compat_ioctl(tty, file, cmd, arg);
2743 else
2744 retval = n_tty_compat_ioctl_helper(tty, file, cmd, arg);
2719 tty_ldisc_deref(ld); 2745 tty_ldisc_deref(ld);
2720 2746
2721 return retval; 2747 return retval;
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 53f2442c6099..9314d93c1a20 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -19,6 +19,7 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/bitops.h> 20#include <linux/bitops.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/compat.h>
22 23
23#include <asm/io.h> 24#include <asm/io.h>
24#include <asm/uaccess.h> 25#include <asm/uaccess.h>
@@ -1179,3 +1180,19 @@ int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
1179 } 1180 }
1180} 1181}
1181EXPORT_SYMBOL(n_tty_ioctl_helper); 1182EXPORT_SYMBOL(n_tty_ioctl_helper);
1183
1184#ifdef CONFIG_COMPAT
1185long n_tty_compat_ioctl_helper(struct tty_struct *tty, struct file *file,
1186 unsigned int cmd, unsigned long arg)
1187{
1188 switch (cmd) {
1189 case TIOCGLCKTRMIOS:
1190 case TIOCSLCKTRMIOS:
1191 return tty_mode_ioctl(tty, file, cmd, (unsigned long) compat_ptr(arg));
1192 default:
1193 return -ENOIOCTLCMD;
1194 }
1195}
1196EXPORT_SYMBOL(n_tty_compat_ioctl_helper);
1197#endif
1198
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index ef925d581713..512c49f98e85 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -450,7 +450,6 @@ static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
450 if (ld->ops->open) { 450 if (ld->ops->open) {
451 int ret; 451 int ret;
452 /* BTM here locks versus a hangup event */ 452 /* BTM here locks versus a hangup event */
453 WARN_ON(!tty_locked());
454 ret = ld->ops->open(tty); 453 ret = ld->ops->open(tty);
455 if (ret) 454 if (ret)
456 clear_bit(TTY_LDISC_OPEN, &tty->flags); 455 clear_bit(TTY_LDISC_OPEN, &tty->flags);
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
index 3b2bb7719442..9ff986c32a21 100644
--- a/drivers/tty/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
@@ -15,30 +15,18 @@
15 * Don't use in new code. 15 * Don't use in new code.
16 */ 16 */
17static DEFINE_MUTEX(big_tty_mutex); 17static DEFINE_MUTEX(big_tty_mutex);
18struct task_struct *__big_tty_mutex_owner;
19EXPORT_SYMBOL_GPL(__big_tty_mutex_owner);
20 18
21/* 19/*
22 * Getting the big tty mutex. 20 * Getting the big tty mutex.
23 */ 21 */
24void __lockfunc tty_lock(void) 22void __lockfunc tty_lock(void)
25{ 23{
26 struct task_struct *task = current;
27
28 WARN_ON(__big_tty_mutex_owner == task);
29
30 mutex_lock(&big_tty_mutex); 24 mutex_lock(&big_tty_mutex);
31 __big_tty_mutex_owner = task;
32} 25}
33EXPORT_SYMBOL(tty_lock); 26EXPORT_SYMBOL(tty_lock);
34 27
35void __lockfunc tty_unlock(void) 28void __lockfunc tty_unlock(void)
36{ 29{
37 struct task_struct *task = current;
38
39 WARN_ON(__big_tty_mutex_owner != task);
40 __big_tty_mutex_owner = NULL;
41
42 mutex_unlock(&big_tty_mutex); 30 mutex_unlock(&big_tty_mutex);
43} 31}
44EXPORT_SYMBOL(tty_unlock); 32EXPORT_SYMBOL(tty_unlock);
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 33d37d230f8f..ef9dd628ba0b 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -350,7 +350,7 @@ int tty_port_close_start(struct tty_port *port,
350 tty_driver_flush_buffer(tty); 350 tty_driver_flush_buffer(tty);
351 if (test_bit(ASYNCB_INITIALIZED, &port->flags) && 351 if (test_bit(ASYNCB_INITIALIZED, &port->flags) &&
352 port->closing_wait != ASYNC_CLOSING_WAIT_NONE) 352 port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
353 tty_wait_until_sent(tty, port->closing_wait); 353 tty_wait_until_sent_from_close(tty, port->closing_wait);
354 if (port->drain_delay) { 354 if (port->drain_delay) {
355 unsigned int bps = tty_get_baud_rate(tty); 355 unsigned int bps = tty_get_baud_rate(tty);
356 long timeout; 356 long timeout;
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 3761ccf0f340..a605549ee28f 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -33,7 +33,6 @@
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/irq.h>
37 36
38#include <linux/kbd_kern.h> 37#include <linux/kbd_kern.h>
39#include <linux/kbd_diacr.h> 38#include <linux/kbd_diacr.h>
@@ -43,6 +42,8 @@
43#include <linux/notifier.h> 42#include <linux/notifier.h>
44#include <linux/jiffies.h> 43#include <linux/jiffies.h>
45 44
45#include <asm/irq_regs.h>
46
46extern void ctrl_alt_del(void); 47extern void ctrl_alt_del(void);
47 48
48/* 49/*
diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index fb864e7fcd13..7a0a12ae5458 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -301,6 +301,8 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t
301/* Insert the contents of the selection buffer into the 301/* Insert the contents of the selection buffer into the
302 * queue of the tty associated with the current console. 302 * queue of the tty associated with the current console.
303 * Invoked by ioctl(). 303 * Invoked by ioctl().
304 *
305 * Locking: always called with BTM from vt_ioctl
304 */ 306 */
305int paste_selection(struct tty_struct *tty) 307int paste_selection(struct tty_struct *tty)
306{ 308{
@@ -310,8 +312,6 @@ int paste_selection(struct tty_struct *tty)
310 struct tty_ldisc *ld; 312 struct tty_ldisc *ld;
311 DECLARE_WAITQUEUE(wait, current); 313 DECLARE_WAITQUEUE(wait, current);
312 314
313 /* always called with BTM from vt_ioctl */
314 WARN_ON(!tty_locked());
315 315
316 console_lock(); 316 console_lock();
317 poke_blanked_console(); 317 poke_blanked_console();
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index b3915b7ad3e2..e716839fab6e 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier);
259 259
260static void notify_write(struct vc_data *vc, unsigned int unicode) 260static void notify_write(struct vc_data *vc, unsigned int unicode)
261{ 261{
262 struct vt_notifier_param param = { .vc = vc, unicode = unicode }; 262 struct vt_notifier_param param = { .vc = vc, .c = unicode };
263 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param); 263 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
264} 264}
265 265