aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/serial
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/tty/serial')
-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.c7
-rw-r--r--drivers/tty/serial/altera_uart.c6
-rw-r--r--drivers/tty/serial/amba-pl010.c14
-rw-r--r--drivers/tty/serial/amba-pl011.c14
-rw-r--r--drivers/tty/serial/apbuart.c1
-rw-r--r--drivers/tty/serial/atmel_serial.c130
-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.c21
-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.c117
-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/of_serial.c12
-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.c5
-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
56 files changed, 835 insertions, 3469 deletions
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..530181e49f6b 100644
--- a/drivers/tty/serial/altera_jtaguart.c
+++ b/drivers/tty/serial/altera_jtaguart.c
@@ -18,6 +18,7 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/console.h> 20#include <linux/console.h>
21#include <linux/of.h>
21#include <linux/tty.h> 22#include <linux/tty.h>
22#include <linux/tty_flip.h> 23#include <linux/tty_flip.h>
23#include <linux/serial.h> 24#include <linux/serial.h>
@@ -218,7 +219,7 @@ static int altera_jtaguart_startup(struct uart_port *port)
218 unsigned long flags; 219 unsigned long flags;
219 int ret; 220 int ret;
220 221
221 ret = request_irq(port->irq, altera_jtaguart_interrupt, IRQF_DISABLED, 222 ret = request_irq(port->irq, altera_jtaguart_interrupt, 0,
222 DRV_NAME, port); 223 DRV_NAME, port);
223 if (ret) { 224 if (ret) {
224 pr_err(DRV_NAME ": unable to attach Altera JTAG UART %d " 225 pr_err(DRV_NAME ": unable to attach Altera JTAG UART %d "
@@ -472,8 +473,6 @@ static struct of_device_id altera_jtaguart_match[] = {
472 {}, 473 {},
473}; 474};
474MODULE_DEVICE_TABLE(of, altera_jtaguart_match); 475MODULE_DEVICE_TABLE(of, altera_jtaguart_match);
475#else
476#define altera_jtaguart_match NULL
477#endif /* CONFIG_OF */ 476#endif /* CONFIG_OF */
478 477
479static struct platform_driver altera_jtaguart_platform_driver = { 478static struct platform_driver altera_jtaguart_platform_driver = {
@@ -482,7 +481,7 @@ static struct platform_driver altera_jtaguart_platform_driver = {
482 .driver = { 481 .driver = {
483 .name = DRV_NAME, 482 .name = DRV_NAME,
484 .owner = THIS_MODULE, 483 .owner = THIS_MODULE,
485 .of_match_table = altera_jtaguart_match, 484 .of_match_table = of_match_ptr(altera_jtaguart_match),
486 }, 485 },
487}; 486};
488 487
diff --git a/drivers/tty/serial/altera_uart.c b/drivers/tty/serial/altera_uart.c
index 50bc5a5ac653..1d04c5037f25 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 "
@@ -616,8 +616,6 @@ static struct of_device_id altera_uart_match[] = {
616 {}, 616 {},
617}; 617};
618MODULE_DEVICE_TABLE(of, altera_uart_match); 618MODULE_DEVICE_TABLE(of, altera_uart_match);
619#else
620#define altera_uart_match NULL
621#endif /* CONFIG_OF */ 619#endif /* CONFIG_OF */
622 620
623static struct platform_driver altera_uart_platform_driver = { 621static struct platform_driver altera_uart_platform_driver = {
@@ -626,7 +624,7 @@ static struct platform_driver altera_uart_platform_driver = {
626 .driver = { 624 .driver = {
627 .name = DRV_NAME, 625 .name = DRV_NAME,
628 .owner = THIS_MODULE, 626 .owner = THIS_MODULE,
629 .of_match_table = altera_uart_match, 627 .of_match_table = of_match_ptr(altera_uart_match),
630 }, 628 },
631}; 629};
632 630
diff --git a/drivers/tty/serial/amba-pl010.c b/drivers/tty/serial/amba-pl010.c
index c0d10c4ddb73..efdf92c3a352 100644
--- a/drivers/tty/serial/amba-pl010.c
+++ b/drivers/tty/serial/amba-pl010.c
@@ -312,12 +312,16 @@ static int pl010_startup(struct uart_port *port)
312 struct uart_amba_port *uap = (struct uart_amba_port *)port; 312 struct uart_amba_port *uap = (struct uart_amba_port *)port;
313 int retval; 313 int retval;
314 314
315 retval = clk_prepare(uap->clk);
316 if (retval)
317 goto out;
318
315 /* 319 /*
316 * Try to enable the clock producer. 320 * Try to enable the clock producer.
317 */ 321 */
318 retval = clk_enable(uap->clk); 322 retval = clk_enable(uap->clk);
319 if (retval) 323 if (retval)
320 goto out; 324 goto clk_unprep;
321 325
322 uap->port.uartclk = clk_get_rate(uap->clk); 326 uap->port.uartclk = clk_get_rate(uap->clk);
323 327
@@ -343,6 +347,8 @@ static int pl010_startup(struct uart_port *port)
343 347
344 clk_dis: 348 clk_dis:
345 clk_disable(uap->clk); 349 clk_disable(uap->clk);
350 clk_unprep:
351 clk_unprepare(uap->clk);
346 out: 352 out:
347 return retval; 353 return retval;
348} 354}
@@ -370,6 +376,7 @@ static void pl010_shutdown(struct uart_port *port)
370 * Shut down the clock producer 376 * Shut down the clock producer
371 */ 377 */
372 clk_disable(uap->clk); 378 clk_disable(uap->clk);
379 clk_unprepare(uap->clk);
373} 380}
374 381
375static void 382static void
@@ -626,6 +633,7 @@ static int __init pl010_console_setup(struct console *co, char *options)
626 int bits = 8; 633 int bits = 8;
627 int parity = 'n'; 634 int parity = 'n';
628 int flow = 'n'; 635 int flow = 'n';
636 int ret;
629 637
630 /* 638 /*
631 * Check whether an invalid uart number has been specified, and 639 * Check whether an invalid uart number has been specified, and
@@ -638,6 +646,10 @@ static int __init pl010_console_setup(struct console *co, char *options)
638 if (!uap) 646 if (!uap)
639 return -ENODEV; 647 return -ENODEV;
640 648
649 ret = clk_prepare(uap->clk);
650 if (ret)
651 return ret;
652
641 uap->port.uartclk = clk_get_rate(uap->clk); 653 uap->port.uartclk = clk_get_rate(uap->clk);
642 654
643 if (options) 655 if (options)
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index f5f6831b0a64..00233af1acc4 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -1367,12 +1367,16 @@ static int pl011_startup(struct uart_port *port)
1367 unsigned int cr; 1367 unsigned int cr;
1368 int retval; 1368 int retval;
1369 1369
1370 retval = clk_prepare(uap->clk);
1371 if (retval)
1372 goto out;
1373
1370 /* 1374 /*
1371 * Try to enable the clock producer. 1375 * Try to enable the clock producer.
1372 */ 1376 */
1373 retval = clk_enable(uap->clk); 1377 retval = clk_enable(uap->clk);
1374 if (retval) 1378 if (retval)
1375 goto out; 1379 goto clk_unprep;
1376 1380
1377 uap->port.uartclk = clk_get_rate(uap->clk); 1381 uap->port.uartclk = clk_get_rate(uap->clk);
1378 1382
@@ -1446,6 +1450,8 @@ static int pl011_startup(struct uart_port *port)
1446 1450
1447 clk_dis: 1451 clk_dis:
1448 clk_disable(uap->clk); 1452 clk_disable(uap->clk);
1453 clk_unprep:
1454 clk_unprepare(uap->clk);
1449 out: 1455 out:
1450 return retval; 1456 return retval;
1451} 1457}
@@ -1497,6 +1503,7 @@ static void pl011_shutdown(struct uart_port *port)
1497 * Shut down the clock producer 1503 * Shut down the clock producer
1498 */ 1504 */
1499 clk_disable(uap->clk); 1505 clk_disable(uap->clk);
1506 clk_unprepare(uap->clk);
1500 1507
1501 if (uap->port.dev->platform_data) { 1508 if (uap->port.dev->platform_data) {
1502 struct amba_pl011_data *plat; 1509 struct amba_pl011_data *plat;
@@ -1800,6 +1807,7 @@ static int __init pl011_console_setup(struct console *co, char *options)
1800 int bits = 8; 1807 int bits = 8;
1801 int parity = 'n'; 1808 int parity = 'n';
1802 int flow = 'n'; 1809 int flow = 'n';
1810 int ret;
1803 1811
1804 /* 1812 /*
1805 * Check whether an invalid uart number has been specified, and 1813 * Check whether an invalid uart number has been specified, and
@@ -1812,6 +1820,10 @@ static int __init pl011_console_setup(struct console *co, char *options)
1812 if (!uap) 1820 if (!uap)
1813 return -ENODEV; 1821 return -ENODEV;
1814 1822
1823 ret = clk_prepare(uap->clk);
1824 if (ret)
1825 return ret;
1826
1815 if (uap->port.dev->platform_data) { 1827 if (uap->port.dev->platform_data) {
1816 struct amba_pl011_data *plat; 1828 struct amba_pl011_data *plat;
1817 1829
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..4a0f86fa1e90 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>
@@ -46,7 +48,7 @@
46 48
47#ifdef CONFIG_ARM 49#ifdef CONFIG_ARM
48#include <mach/cpu.h> 50#include <mach/cpu.h>
49#include <mach/gpio.h> 51#include <asm/gpio.h>
50#endif 52#endif
51 53
52#define PDC_BUFFER_SIZE 512 54#define PDC_BUFFER_SIZE 512
@@ -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..163fc9021f5a 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;
@@ -1286,17 +1290,20 @@ static int serial_imx_resume(struct platform_device *dev)
1286static int serial_imx_probe_dt(struct imx_port *sport, 1290static int serial_imx_probe_dt(struct imx_port *sport,
1287 struct platform_device *pdev) 1291 struct platform_device *pdev)
1288{ 1292{
1289 static int portnum = 0;
1290 struct device_node *np = pdev->dev.of_node; 1293 struct device_node *np = pdev->dev.of_node;
1291 const struct of_device_id *of_id = 1294 const struct of_device_id *of_id =
1292 of_match_device(imx_uart_dt_ids, &pdev->dev); 1295 of_match_device(imx_uart_dt_ids, &pdev->dev);
1296 int ret;
1293 1297
1294 if (!np) 1298 if (!np)
1295 return -ENODEV; 1299 return -ENODEV;
1296 1300
1297 sport->port.line = portnum++; 1301 ret = of_alias_get_id(np, "serial");
1298 if (sport->port.line >= UART_NR) 1302 if (ret < 0) {
1299 return -EINVAL; 1303 dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
1304 return -ENODEV;
1305 }
1306 sport->port.line = ret;
1300 1307
1301 if (of_get_property(np, "fsl,uart-has-rtscts", NULL)) 1308 if (of_get_property(np, "fsl,uart-has-rtscts", NULL))
1302 sport->have_rtscts = 1; 1309 sport->have_rtscts = 1;
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 23bc743f2a22..4c309e869903 100644
--- a/drivers/tty/serial/mrst_max3110.c
+++ b/drivers/tty/serial/mrst_max3110.c
@@ -23,10 +23,14 @@
23 * 1 word. If SPI master controller doesn't support sclk frequency change, 23 * 1 word. If SPI master controller doesn't support sclk frequency change,
24 * then the char need be sent out one by one with some delay 24 * then the char need be sent out one by one with some delay
25 * 25 *
26 * 2. Currently only RX available interrrupt is used, no need for waiting TXE 26 * 2. Currently only RX available interrupt is used, no need for waiting TXE
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 776790272454..8131e2c28015 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/of_serial.c b/drivers/tty/serial/of_serial.c
index e58cece6f443..e8c9cee07d00 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -200,17 +200,7 @@ static struct platform_driver of_platform_serial_driver = {
200 .remove = of_platform_serial_remove, 200 .remove = of_platform_serial_remove,
201}; 201};
202 202
203static int __init of_platform_serial_init(void) 203module_platform_driver(of_platform_serial_driver);
204{
205 return platform_driver_register(&of_platform_serial_driver);
206}
207module_init(of_platform_serial_init);
208
209static void __exit of_platform_serial_exit(void)
210{
211 return platform_driver_unregister(&of_platform_serial_driver);
212};
213module_exit(of_platform_serial_exit);
214 204
215MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>"); 205MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>");
216MODULE_LICENSE("GPL"); 206MODULE_LICENSE("GPL");
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..6cd414341d5e 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>
@@ -568,8 +569,6 @@ static struct of_device_id ulite_of_match[] __devinitdata = {
568 {} 569 {}
569}; 570};
570MODULE_DEVICE_TABLE(of, ulite_of_match); 571MODULE_DEVICE_TABLE(of, ulite_of_match);
571#else /* CONFIG_OF */
572#define ulite_of_match NULL
573#endif /* CONFIG_OF */ 572#endif /* CONFIG_OF */
574 573
575static int __devinit ulite_probe(struct platform_device *pdev) 574static int __devinit ulite_probe(struct platform_device *pdev)
@@ -609,7 +608,7 @@ static struct platform_driver ulite_platform_driver = {
609 .driver = { 608 .driver = {
610 .owner = THIS_MODULE, 609 .owner = THIS_MODULE,
611 .name = "uartlite", 610 .name = "uartlite",
612 .of_match_table = ulite_of_match, 611 .of_match_table = of_match_ptr(ulite_of_match),
613 }, 612 },
614}; 613};
615 614
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>